In many parallel algorithms, communication operations need to be restricted to certain subsets of processes.
A general method for partitioning a graph of processes is to use MPI_Comm_split that is defined as follows:
int MPI_Comm_split(MPI_Comm comm, int color, int key,
MPI_Comm *newcomm)
This function is a collective operation, and thus needs to be called by all the processes in the communicator comm.
A new communicator for each subgroup is returned in the newcomm parameter.
The function takes color and key as input parameters in addition to the communicator, and partitions the group of processes in the communicator comm into disjoint subgroups.
Each subgroup contains all processes that have supplied the same value for the color parameter.
Within each subgroup, the processes are ranked in the order defined by the value of the key parameter.
Figure 5.7 shows an example of splitting a communicator using the MPI_Comm_split function.
If each process called MPI_Comm_split using the values of parameters color and key as shown in Fig 5.7, then three communicators will be created, containing processes 0, 1, 2, 3, 4, 5, 6, and 7, respectively.
Figure 5.7:
Using MPI_Comm_split to split a group of processes in a communicator into subgroups.