Example #1a:
int main(int argc, char *argv[]) { int me, size; ... MPI_Init ( &argc, &argv ); MPI_Comm_rank (MPI_COMM_WORLD, &me); MPI_Comm_size (MPI_COMM_WORLD, &size); (void)printf ("Process %d size %d\n", me, size); ... MPI_Finalize(); return 0; }Example #1a is a do-nothing program that initializes itself, and refers to the ``all'' communicator, and prints a message. It terminates itself too. This example does not imply that MPI supports printf-like communication itself.
Example #1b (supposing that size is even):
int main(int argc, char *argv[]) { int me, size; int SOME_TAG = 0; ... MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &me); /* local */ MPI_Comm_size(MPI_COMM_WORLD, &size); /* local */ if((me % 2) == 0) { /* send unless highest-numbered process */ if((me + 1) < size) MPI_Send(..., me + 1, SOME_TAG, MPI_COMM_WORLD); } else MPI_Recv(..., me - 1, SOME_TAG, MPI_COMM_WORLD, &status); ... MPI_Finalize(); return 0; }Example #1b schematically illustrates message exchanges between ``even'' and ``odd'' processes in the ``all'' communicator.