Example #1a:
2.2
Example #1b (supposing that size is even):
2.2
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();
}
Example #1a is a do-nothing program that initializes itself legally,
and refers to the ``all'' communicator, and prints a message. It
terminates itself legally too. This example does not imply that MPI
supports printf-like communication itself.
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();
}
Example #1b schematically illustrates
message exchanges between ``even'' and ``odd'' processes in the ``all''
communicator.
Up: Motivating Examples
Next: Current Practice #2
Previous: Motivating Examples
Return to MPI-2.2 Standard Index
Return to MPI Forum Home Page
(Unofficial) MPI-2.2 of September 4, 2009
HTML Generated on September 10, 2009