Basics of MPI Programming

2.1 MPI Program Outline

The basic outline of an MPI program follows these general steps:

  1. Initialize communications
  2. Communicate to share data between processes
  3. Exit in a "clean" fashion from the message-passing system when done communicating
MPI has more than 125 functions. However, a beginning programmer can usually make do with only six of these functions. A beginning programmer can usually make do with only six functions.These functions, illustrated and discussed in our sample program are:

  • Initialize communications
    MPI_INIT initializes the MPI environment
    MPI_COMM_SIZE returns the number of processes
    MPI_COMM_RANK returns this process's number (rank)

  • Communicate to share data between processes
    MPI_SEND sends a message
    MPI_RECV receives a message

  • Exit from the message-passing system
    MPI_FINALIZE