Process Groups
Along with playing a role in the development of parallel libraries, communicators can be used for organizing communication within an application. The programmer can define a subset of processes, called a process group, and attach one or more communicators to the process group. Communication specifying that communicator will now be restricted to those processes.
In the example diagrammed below, the communication pattern is a 2-D mesh. The boxes, each representing a process, are arranged into a grid with 2 rows and three columns. Each process must exchange data with its upper, lower, right, and left neighbors. Programming this communication is simpler if the processes are grouped by column (for up/down communication) and row (for right/left communication).
So, each process belongs to three communicators:
- one communicator for all processes (the default world communicator)
- one communicator for its row
- one communicator for its column
In this case comm1 and comm2 represent row 1 and row 2, respectively. Comm 3, 4 and 5 represent the columns. For example, the bottom right grid cell is occupied by a process with world rank 5. It is also rank 2 in the comm2 communicator and rank 1 in comm5 communicator. In other words, a message sent to this node using the world communicator should be directed to rank 5; a message sent using the comm5 communicator should be directed to rank 1.
To revisit the bill collection analogy: one person may have an account with the electric and phone companies (2 communicators) but not with the water company. The electric communicator may contain different people than the phone communicator. A person's ID number (rank) may vary with the utility (communicator). So, it is critical to note that the rank given as message source or destination is the rank in the specified communicator.