Click here to go to the TACC Home Page

TACC

Parameters

MPI uses an include file to set parameters (in PARAMETER statements) that are required for certain calls. These parameters always begin with the string "mpi_" and you should refrain from using variables with the mpi_ prefix to avoid namespace collisions. Throughout this document, all MPI parameters will be in upper case to remind you of their status but remember that FORTRAN compilers make no distinction between upper and lower case names.

   Message-Passing Interface

The MPI_COMM_WORLD parameter is a communicator (value) that is defined for all processes that are initialized for MPI. A communicator gives a message an identifying context to distinguish it from messages of other communicators. In many programs only a single communicator is needed but in more complicated situations and library development, multiple contexts may be required. A communicator is analogous to a channel of a citizen's band transceiver: chatter on one channel does not interfere (cannot be heard) on any of the other channels. The MPI_COMM_WORLD parameter might have just as well been named mpi_comm_original because it is a pre-defined communicator assigned to the initial group of all processes.

There are two information subprograms that you will probably want to use at the beginning of a program; and both require the world communicator. MPI_COMM_SIZE and MPI_COMM_RANK return the number of processors and a process number, respectively. In MPI jargon, the unique number assigned to a process is its rank. The world communicator ranks range from 0 to NPES-1, the number of processors less one. The syntax for these two subroutines is:

call mpi_comm_size (icomm, inpes, ierr)
call mpi_comm_rank (icomm, irank, ierr)

where:

Parameter Description Status
icomm communicator (use parameter MPI_COMM_WORLD as predefined context for initial processes) [IN]
inpes number of processes [OUT]
irank process number, numbered between 0 and inpes-1 [OUT]
ierr MPI error number (0 = no error) [OUT]

In the following code the number of processes and the rank of each process are reported. The first argument of the size and rank subroutines is the communicator; the second is the respective returned value; and the third is a returned error value for the call.

Program param
include 'mpif.h'
call mpi_init(ierr)
call mpi_comm_size(MPI_COMM_WORLD,npes, ierr)
call mpi_comm_rank(MPI_COMM_WORLD,irank,ierr)
print*,npes,irank,' = number of procs and process rank'
call mpi_finalize(ierr)
end