156. Example #4

PreviousUpNext
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 
 
   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; 
   } 


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


Return to MPI-3.1 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-3.1 of June 4, 2015
HTML Generated on June 4, 2015