Sample program with links: C version or Fortran version. Click on the name of each MPI routine to read a detailed description of that routine's purpose and syntax.
Note the programs only use six basic calls to MPI routines.
This program is a SPMD code (single program/multiple data). Copies of this program will run on multiple processors. Each process initializes itself with MPI (MPI_INIT), determines the number of processes (MPI_COMM_SIZE), and learns its rank (MPI_COMM_RANK). Then one process (rank 0 in this example) sends messages in a loop (MPI_SEND), setting the destination argument to the loop index to ensure that each of the other processes is sent one message. The remaining processes receive one message (MPI_RECV). All processes then print the message, and exit from MPI (MPI_FINALIZE).
It is worth noting what doesn't happen in this program. There is no routine that causes additional copies of the program to run. This is accomplished when you the submit the job to the batch system using mpirun.
In the lab exercise at the end of this module, you willl be asked to enhance this program with some additional calls to MPI routines.