All MPI routines have some similarities in their naming and in the parameters that they require. However, there are differences between C and Fortran, so let's look at these separately.

C bindings

For C, the general type signature is

Note that case is important here, as it is with all C code. For example, MPI must be capitalized, as must the first character after the underscore. Everything after that must be lower case. All C MPI functions return an integer return code, which can be used to determine if the call succeeded. If , then the call was successful.

C programs should include the file "mpi.h". This contains definitions for MPI functions and constants like .

Fortran bindings

For Fortran, the general type signature is

Note that case is not important here. So, an equivalent form would be

Instead of having a function that returns an error code, as in C, the Fortran versions of MPI calls are subroutines that usually have one additional parameter in the argument list, , which is the return code. Upon success, is set to .

In Fortran programs with recent compilers and MPI versions, it is preferred to have or in each program unit that does MPI calls. If supported on your system and by your code, choose because it is the only Fortran support method that is consistent with the Fortran 2008+ standard and it offers better compiler optimization. For older compilers and MPI implementations, include "mpif.h" (see note below). This contains definitions for MPI constants and functions.

Note

A Fortran compiler may produce warning messages when a program calls or with buffers of different types at different places, even though this is perfectly valid with MPI. While such messages from the compiler seem to be only warnings, the executable may fail to run. The solution is to replace the statement with the Fortran 90 statement prior to the declaration section(s). If the compiler says it cannot find the MPI module, you will have to compile the implementation-specific file "mpif.f90" in your project or makefile, making sure the compiler is aware of the location of the include directory for the MPI implementation you are using. This may be necessary in order to create the module "MPI.mod" that is invoked by .

For both C and Fortran

The exceptions to the above signatures are the timing routines (MPI_Wtime and MPI_Wtick) which are functions in both C and Fortran. They return double-precision real numbers. Case considerations are the same as for the other MPI calls.

 
©   Cornell University  |  Center for Advanced Computing  |  Copyright Statement  |  Inclusivity Statement