The include file always comes before any MPI calls; its location is system dependent. MPI INIT is the rst genuine MPI call and does initialization. MPI FINALIZE is called at the end when MPI is no longer needed, usually near the end of the program. The integer ierr is used as a return code for the subroutine call. The simplest MPI program in FORTRAN is:
To do something useful with MPI, make calls to MPI_COMM SIZE and MPI_COMM_RANK within the communicating group MPI_COMM_WORLD.
The call to MPI_COMM_SIZE returns the number of total processors that the job is running on and stores that value as an integer in the variable nprocs. The call to MPI_COMM_RANK returns the value of the rank, between 0 and nprocs − 1, and stores it into the local copy of the variable myrank. Here is also an example of the communicating group in action. All processors belong to MPI COMM WORLD by default, so the MPI_COMM_SIZE and MPI_COMM_RANK calls happen globally over all processors.