Example
int main(int argc, char *argv[]) { int me, count, count2; void *send_buf, *recv_buf, *send_buf2, *recv_buf2; MPI_Group group_world, grprem; MPI_Comm commWorker; static int ranks[] = {0}; ... MPI_Init(&argc, &argv); MPI_Comm_group(MPI_COMM_WORLD, &group_world); MPI_Comm_rank(MPI_COMM_WORLD, &me); /* local */ MPI_Group_excl(group_world, 1, ranks, &grprem); /* local */ MPI_Comm_create(MPI_COMM_WORLD, grprem, &commWorker); if(me != 0) { /* compute on worker */ ... MPI_Reduce(send_buf,recv_buf,count, MPI_INT, MPI_SUM, 1, commWorker); ... MPI_Comm_free(&commWorker); } /* zero falls through immediately to this reduce, others do later... */ MPI_Reduce(send_buf2, recv_buf2, count2, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Group_free(&group_world); MPI_Group_free(&grprem); MPI_Finalize(); return 0; }Example (Approximate) Current Practice #3 illustrates how a group consisting of all but the zeroth MPI process of the ``all'' group is created, and then how a communicator is formed (commWorker) for that new group. The new communicator is used in a collective call, and all MPI processes execute a collective call in the MPI_COMM_WORLD context. This example illustrates how the two communicators (that inherently possess distinct contexts) protect communication. That is, communication in MPI_COMM_WORLD is insulated from communication in commWorker, and vice versa.
In summary, ``group safety'' is achieved via communicators because distinct contexts within communicators are enforced to be unique on any MPI process.