The following example (Communication Safety Example) is meant to illustrate ``safety'' between
point-to-point and collective communication. MPI guarantees that a single
communicator can do safe point-to-point and collective communication.
Example
#define TAG_ARBITRARY 12345
#define SOME_COUNT 50
int main(int argc, char *argv[])
{
int me;
MPI_Request request[2];
MPI_Status status[2];
MPI_Group group_world, subgroup;
int ranks[] = {2, 4, 6, 8};
MPI_Comm the_comm;
...
MPI_Init(&argc, &argv);
MPI_Comm_group(MPI_COMM_WORLD, &group_world);
MPI_Group_incl(group_world, 4, ranks, &subgroup); /* local */
MPI_Group_rank(subgroup, &me); /* local */
MPI_Comm_create(MPI_COMM_WORLD, subgroup, &the_comm);
if(me != MPI_UNDEFINED)
{
MPI_Irecv(buff1, count, MPI_DOUBLE, MPI_ANY_SOURCE,
TAG_ARBITRARY, the_comm, request);
MPI_Isend(buff2, count, MPI_DOUBLE, (me+1)%4, TAG_ARBITRARY,
the_comm, request+1);
for(i = 0; i < SOME_COUNT; i++)
MPI_Reduce(..., the_comm);
MPI_Waitall(2, request, status);
MPI_Comm_free(&the_comm);
}
MPI_Group_free(&group_world);
MPI_Group_free(&subgroup);
MPI_Finalize();
return 0;
}