Writing MPI programs III

Another Example (Again hello and again no messsage-passing) ( hello2.c):
    1 #include "mpi.h"
    2 #include <stdio.h>
    3 #include <unistd.h>
    4 
    5 int main( argc, argv )
    6 int argc; 
    7 char **argv;
    8 {
    9     int rank, size;
   10     MPI_Init( &argc, &argv );
   11     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
   12     MPI_Comm_size( MPI_COMM_WORLD, &size );
   13     printf( "Hello world! I'm %d of %d\n", rank, size );
   14     sleep(10);
   15     MPI_Finalize();
   16     return 0;
   17 }
Two of the first questions asked in a parallel program are:
  1. How many processes are there? Answered with MPI_Comm_size
  2. Who am I? Answered with MPI_Comm_rank. The rank is a number between zero and size-1.