5.5.4. Example #4


Up: Motivating Examples Next: Library Example #1 Previous: (Approximate) Current Practice #3

The following 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.

#define TAG_ARBITRARY 12345 
   #define SOME_COUNT       50 

main(int argc, char **argv) { int me; MPI_Request request[2]; MPI_Status status[2]; MPI_Group MPI_GROUP_WORLD, subgroup; int ranks[] = {2, 4, 6, 8}; MPI_Comm the_comm; ... MPI_Init(&argc, &argv); MPI_Comm_group(MPI_COMM_WORLD, &MPI_GROUP_WORLD);

MPI_Group_incl(MPI_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(t&he_comm); MPI_Group_free(&MPI_GROUP_WORLD); MPI_Group_free(&subgroup); MPI_Finalize(); }



Up: Motivating Examples Next: Library Example #1 Previous: (Approximate) Current Practice #3


Return to MPI Standard Index
Return to MPI home page