The following Fortran program is an adaptation of the hello_rpi.c
application from Chapter 3, Parallel Computing – MPI on the Raspberry Pi
.
Create a new file called hello_rpi.f
in the Fortran directory that you created earlier as follows:
vim /home/pi/Fortran/hello_rpi.f
Next add the following code to the file:
program hellorpi include 'mpif.h' integer rpi, totalrpi, ierr call MPI_INIT(ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, rpi, ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD, totalrpi, ierr) print *, 'This is Raspberry Pi ',(rpi+1),' of ',totalrpi call MPI_FINALIZE(ierr) end
You can see this program is very similar to the C one.
To start with, we include the mpif.h
header. Following this we declare a number of integer variables to store the current Raspberry Pi executing the program, the total number of RPi's in the cluster, and an additional variable for an error code.
After this are the three MPI calls we made in the hello_rpi.c
application...