Main navigation

MPI API

For complete information about using MPI see the MPI standard.

A number of good MPI tutorials and reference materials on the web are linked from the introductory page on parallel computing. If you are unfamiliar with MPI, you should start with one of these tutorials.

IDRE gives classes in MPI programming every quarter. The dates of the classes are announced on the News and Announcements page and in the class schedule.

Required Header Files

To use MPI, you need to include the following header file in your program:

Fortran 77:
include ‘mpif.h’
Fortran 90:
use mpi
C/C++:
#include “mpi.h”

Commonly used MPI Environment-Management Functions

To use MPI, you need to include the following header file in your program:

  • To Initialize the MPI execution environment. Must be called only once.
    Fortran:
    MPI_INIT(ierror)Where:

    • integer ierror
    C:
    int MPI_Init(int *argc, char ***argv);
    C++:
    int MPI::Init(int *argc, char ***argv);
  • To determine the number of processors Associated with a communicator such as MPI_COMM_WORLD:
    Fortran:
    MPI_COMM_SIZE(comm, size, ierror)Where:

    • integer comm, rank, ierror
    C:
    int MPI_Comm_size (MPI_Comm comm, int *size);
    C++:
    int MPI::COMM_WORLD.Get_size( );
  • To determine the rank of the calling process within a communicator such as MPI_COMM_WORLD:
    Fortran:
    MPI_COMM_RANK(comm, rank, ierror)Where:

    • integer comm, rank, ierror
    C:
    int MPI_Comm_rank(MPI_Comm comm, int *rank);
    C++:
    int MPI::COMM_WORLD.Get_rank( );
  • To terminate all MPI process within the commmunicator:
    Fortran:
    MPI_ABORT(comm, errorcode, ierror)Where:

    • integer comm, errorcode, ierror
    C:
    int MPI_Abort(MPI_Comm comm int errorcode );
    C++:
    void MPI::COMM_WORLD.Abort( int errorcode );
  • To return the elapsed wall clock time in seconds
    Fortran:
    double precision MPI_WTIME()
    C:
    double MPI_Wtime( );
    C++:
    double MPI::Wtime( );
  • To terminate MPI:
    Fortran:
    MPI_FINALIZE(ierror)Where:

    • integer ierror
    C:
    int MPI_Finalize();
    C++:
    MPI::Finalize( );

Basic MPI Data Types

Data Types for C

C data type

MPI data type

char MPI_CHAR
short int MPI_SHORT
int MPI_INT
long int MPI_LONG
float MPI_FLOAT
double MPI_DOUBLE
long double MPI_LONG_DOUBLE

Data Types for Fortran

Fortran data type

MPI data type

INTEGER MPI_INTEGER
REAL MPI_REAL
REAL*8 MPI_REAL8
DOUBLE PRECISION MPI_DOUBLE_PRECISION
COMPLEX MPI_COMPLEX
LOGICAL MPI_LOGICAL
CHARACTER MPI_CHARACTER

MPI Examples

Report Typos and Errors
UCLA OIT

© 2016 UC REGENTS TERMS OF USE & PRIVACY POLICY