Communicators Marcirio Silveira Chaves [email_address] Tutorial on Parallel Computing and  Message Passing Model Part II - Day 5
Objectives The basics about communicators About two types of communicators that can be defined in MPI — intracommunicators and intercommunicators How to create and use different groups of processors and communicators How to modify a group of processes How to create both intercommunicators and intracommunicators How to access information from each of these types of communicators June - 2009 LNEC-DHA-NTI
Communicator Basics The most familiar communicator in MPI is MPI_COMM_WORLD ...  …  is predefined and includes the entire set of processes created when an MPI program begins execution.  It is through this communicator that any process can  communicate  with any other individual process by using  point-to-point communication  or with all other processes within MPI_COMM_WORLD by using a collective communication call.  For certain types of computation it turns out to be more advantageous to restrict communication to a subset of the processes created at runtime. E.g. suppose that you wanted to carry out, in parallel, a matrix-multiplication computation,  C  =  A × B. June - 2009 LNEC-DHA-NTI
Communicator Basics E.g. suppose that you wanted to carry out, in parallel, a matrix-multiplication computation,  C  =  A × B. June - 2009 LNEC-DHA-NTI A matrix-multiplication problem that is to be computed in parallel.
Communicator Basics In this particular type of parallel computation you can organize your processes in a  n x m  grid of rows and columns June - 2009 LNEC-DHA-NTI A 2-dimensional grid of processes arranged in rows and columns corresponding to the rows and columns of the matrices A and B.  wherein element  cij  of matrix  C  is to be computed on process  p(i, j) , where
Communicator Basics In order to compute  cij  on process  p(i, j) , you need to distribute: all  k  elements in the  i th row of matrix  A  and  all  k  elements in the  j th column of matrix  B  to process  p(i, j) .  Instead   of  using  a single communicator  that includes all  n x m  processes in MPI_COMM_WORLD create  a set of separate communicators  that more naturally reflects the structure of communication along the rows and columns of the 2-dimensional grid of processes (viz.,  one communicator for each row and column of this topology ).  June - 2009 LNEC-DHA-NTI
Types of Communicators - Intracommunicators - Intercommunicators A communicator can be of either type, but never both. An  intracommunicator  contains a single group of processes, within which all of the processes have a unique rank.  The 10 processes split into two separate intracommunicators, MPI_COMM_WORLD and commNew1.  Two separate groups of processes associated with different intracommunicators, MPI_COMM_WORLD and commNew1.  June - 2009 LNEC-DHA-NTI
Types of Communicators All 10 processes created at runtime are associated with the predefined intracommunicator, MPI_COMM_WORLD.  A subset of these processes ( p1 ,  p2 ,  p3 , and  p4 ) is also associated with an intracommunicator,  commNew1 , that is distinct from MPI_COMM_WORLD.  Although the ranks of these four processes in MPI_COMM_WORLD are 1, 2, 3, and 4, these same four processes may have entirely different ranks (e.g., 0, 1, 2, and 3, respectively) in  commNew1 .  June - 2009 LNEC-DHA-NTI
Types of Communicators In contrast to an intracommunicator, an  intercommunicator  contains two disjoint groups of processes and is used for communication between two distinct intracommunicators. In MPI-1 intercommunicators only allow point-to-point communications between processes belonging to different communicators.  On the other hand, MPI-2 allows both point-to-point and collective communicators between processes belonging to two disjoint communicators.  June - 2009 LNEC-DHA-NTI
Types of Communicators In our example, each process in  commNew1 , such as  p2 , can communicate with every other process in  commNew1  by using either point-to-point or collective communications.  Process  p2  can also communicate with process  p5  in either of two ways.  First,  p1  can use the intracommunicator MPI_COMM_WORLD, since both  p2  and  p5  are members of this communicator.  Second, you can construct an  inter communicator,  commNew2 , that will allow all process in  commNew1  to communicate with all processes in MPI_COMM_WORLD across these two intracommunicators.  June - 2009 LNEC-DHA-NTI
Creating Intracommunicators In MPI-1: Multiple methods to create intracommunicators. Split  an existing intracommunicator into two or more sub-communicators  Duplicate  an existing intracommunicator  Modify  a group of processes from an existing intracommunicator, and create a new communicator based on this modified group  Reorder  the processes in an existing group based on some type of specific topology  MPI-2 provides the following two additional methods: Connecting two separate applications and merging their communicators  Spawning new processes  June - 2009 LNEC-DHA-NTI
Splitting an Existing Intracommunicator Splitting a communicator into different sub-communicators is a convenient method for mapping processes onto a 2-dimensional topology corresponding to the rows and columns of a matrix or a set of coordinates distributed onto a Cartesian grid.  Useful in scientific applications involving matrix multiplication and other linear algebra computations.  June - 2009 LNEC-DHA-NTI
Splitting an Existing Intracommunicator MPI_COMM_SPLIT :  to split a communicator into sub-communicators.  Fortran: MPI_COMM_SPLIT(int  comm , int  color , int  key , int  newcomm , int IERR)  All processes that have the same  color  will belong to the same unique sub-communicator  All processes of a given  color  will be ordered according to the value of  key .  June - 2009 LNEC-DHA-NTI This routine  partitions  the group associated with the original communicator  comm   into  disjoint subgroups , with  one subgroup for each different value of color .  A new communicator is created for each subgroup and a handle to this communicator is returned in  newcomm .
Splitting an Existing Intracommunicator MPI_COMM_SPLIT :  to split a communicator into sub-communicators.  Fortran: MPI_COMM_SPLIT(int  comm , int  color , int  key , int  newcomm , int IERR)  If the value of  key  is the same for two or more processes, these processes will be ordered according to their relative ranks in the original communicator.  If a process is not to be included within any of the resulting sub-communicators its color is set to MPI_UNDEFINED, in which case  newcomm  will return MPI_COMM_NULL.  MPI_COMM_NULL represents an invalid communicator and any MPI routine that is passed MPI_COMM_NULL as an argument will return an error.  June - 2009 LNEC-DHA-NTI
Splitting an Existing Intracommunicator MPI_COMM_SPLIT :  to split a communicator into sub-communicators.  Fortran: MPI_COMM_SPLIT(int  comm , int  color , int  key , int  newcomm , int IERR)  MPI_COMM_SPLIT is a collective communications routine that must be called by all processes in the original communicator,  comm .  In contrast to other collective routines, which require that all arguments be identical on all processes calling the routine,  for MPI_COMM_SPLIT each process can specify a different value both for  color  and for  key .  June - 2009 LNEC-DHA-NTI
Splitting an Existing Intracommunicator E.g. 1: Assume that a call to MPI_COMM_SPLIT is executed on a group of 8 processes with the following arguments: This call to MPI_COMM_SPLIT will generate three sub-communicators whose processes will be rank ordered as shown below.  June - 2009 LNEC-DHA-NTI Creating 3 new intracommunicators by splitting an existing intracommunicator containing 8 processes.  process  p0  p1  p2  p3  p4  p5  p6  p7 rank  0  1  2  3  4  5  6  7 color  1  2  2  4  1  1  2  1 key  3  5  5  2  2  1  2  3
Duplicating an Existing Intracommunicator When creating a new communicator, it is sometimes convenient to start by duplicating an existing communicator.  You can do this with the MPI routine for duplicating an existing intracommunicator —  MPI_COMM_DUP .  Fortran: MPI_COMM_DUP(int comm, int newcomm, int IERR)  The new communicator,  newcomm , will have exactly the same fixed attributes (group(s) and topology) as the input communicator,  comm .  Although  newcomm  is a duplicate of  comm , the communication domains of these two communicators are distinct. June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes Another method for creating a new intracommunicator is: to modify a group of processes from an existing communicator and create the new communicator based on this modified group.  Group : any ordered set of  N  processes wherein  each  process is associated with a  unique   number  or  rank  running  contiguously  from zero to ( N - 1 ).  June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes Since groups can be used to restrict collective communications only between a subset of processes, maintaining separate, disjoint groups can be useful in many applications (e.g., for dual-level parallelism).  Groups can be created, accessed, modified, and destroyed but  can only be used for message passing within a communicator . When a group is created, it is not associated with any communicator.  The communicator must be created in a separate operation based on some specified pre-existing group.  June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes A group constructor is used to create a new group through the modification of some existing group.  Group creation is a local operation and, therefore, requires no communication between processes.  However, each process that is to be included in a group that is being created must create the same group.  Following its creation, a group cannot be used for communication since it will not be associated with any communicator.  A modified group becomes associated with a communicator through a call to a separate communicator-creation operation.  June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes June - 2009 LNEC-DHA-NTI Creating a new intracommunicator based on a modified group of processes.
Modifying a Group of Processes Extracting a Group You can access the group of processes associated with a given  communicator  by using the  MPI_COMM_GROUP  command to extract them.  Associated with a communicator is its  group identity , or handle.  MPI_COMM_GROUP  is used to  obtain the group handle of the communicator , which can be used as input to the MPI routines for accessing and modifying the extracted groups.  Fortran: MPI_COMM_GROUP( int comm ,  int group , int ierr) where MPI_COMM_GROUP  extracts a group of processes  associated with some original communicator, comm, into group. June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes Fortran: MPI_COMM_GROUP( int comm ,  int group , int ierr) where MPI_COMM_GROUP  extracts a group of processes  associated with some original communicator, comm, into group. June - 2009 LNEC-DHA-NTI Fortran: include "mpif.h" integer comm_world, ierr, group_world comm_world = MPI_COMM_WORLD call MPI_Comm_group(comm_world, group_world, ierr)
Modifying a Group of Processes Modifying and Accessing Extracted Groups Once you have extracted a group of proccesses from an existing intracommunicator, you can modify it and access information about it using MPI routines.  When you are finished with the group you can call a routine to destroy it.  June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes Modifying and Accessing Extracted Groups Group Constructors Once a group of processes has been extracted from an existing intracommunicator, it can be modified using any one of the MPI group-modification routines or 'group constructors.'  MPI_GROUP_INCL  MPI_GROUP_EXCL  MPI_GROUP_UNION  MPI_GROUP_INTERSECTION  MPI_GROUP_DIFFERENCE  Examples: Two separate groups of processes have been extracted from an existing communicator that contain the following sets of processes ranked in the order indicated below. group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]  June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_INCL :  creates a  new group  by reordering a  specified number of the processes  from an  existing group .  Fortran MPI_GROUP_INCL(int  group , int  n , int rank, int  newgroup , int ierr)  If n = 0,  newgroup  will be identical to group. Using the  existing group ,  group1 , we create a new group by calling: MPI_GROUP_INCL( group1 ,  5 , rank,  newgroup , ierr)  where rank[5] = [0 4 6 5 2].  The resulting group, newgroup, contains 5 processes, [p0, p4, p6, p5, p2], from group1 in the order defined by rank. June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
Modifying a Group of Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_EXCL :  creates a new group from an original group that  contains all processes left after deleting those with specified ranks.  The relative rank order of the remaining processes will be the same as that in the original group.  Fortran MPI_GROUP_ EXCL (int  group , int  n , int rank, int  newgroup , int IERR)  If  n = 0 ,  newgroup  will be identical to  group . Using the existing group,  group1 , we create a new group by calling:  MPI_Group_EXCL(group1, 5, rank, newgroup, ierr);  where  rank[5]  = [0 4 6 5 2].  The resulting group,  newgroup , contains: [p1, p3].  June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
Modifying a Group of Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_UNION :  creates a new group that contains all processes in the first group followed by all processes in the second group with no duplication of processes.  Fortran: MPI_GROUP_UNION(int group1, int group2, int newgroup, int IERR)  Using the existing groups,  group1  and  group2 , we create a new group by calling:   MPI_Group_union(group1, group2, &newgroup);   June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
Modifying a Group of Processes Modifying and Accessing Extracted Groups Group Constructors The resulting group,  newgroup , contains:  newgroup: [ p0, p1, p2, p3, p4, p5, p6, p7, p8 ]  We now reverse the order of the groups in the function call:  MPI_Group_union(group2, group1, &newgroup); resulting in:  newgroup: [ p3, p6, p0, p2, p7, p8, p1, p4, p5 ]  June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
Modifying a Group of Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_INTERSECTION :  creates a new group from two groups that contains all processes that are in both of the groups with rank order the same as that in the first group.  Fortran: MPI_GROUP_INTERSECTION(int group1, int group2, int newgroup, int IERR)  Using the existing groups, group1 and group2, we create a new group by calling:  MPI_Group_intersection(group1, group2, &newgroup);   June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
Modifying a Group of Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_INTERSECTION The resulting group, newgroup, contains:  newgroup: [  p0, p2 , p3, p6 ]  To reverse the order of the groups in the function call:  MPI_Group_intersection(group2,  group1 , &newgroup); resulting in:  newgroup: [ p3, p6,  p0, p2  ]  June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
Modifying a Group of Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_DIFFERENCE:  creates a new group from two groups that contains all processes in the first group that are not in the second group with rank order the same as that in the first group.  Fortran: MPI_GROUP_DIFFERENCE(int group1, int group2, int newgroup, int IERR)  Using the existing groups,  group1  and  group2 , we create a new group by calling:  MPI_Group_difference(group1, group2, &newgroup);  June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
Modifying a Group of Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_DIFFERENCE: The resulting group,  newgroup , contains:  newgroup: [ p1, p4, p5 ]  We now reverse the order of the groups in the function call:  MPI_Group_difference(group2, group1, &newgroup); resulting in:  newgroup: [ p7, p8 ]  June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
Modifying a Group of Processes Modifying and Accessing Extracted Groups Accessing Information from a Group Once a group has been modified, information about the original group of processes or the modified group of processes can be accessed using one of the following group accessor commands: MPI_GROUP_SIZE   MPI_GROUP_RANK MPI_GROUP_TRANSLATE_RANKS   MPI_GROUP_COMPARE MPI_GROUP_SIZE  returns the size of a group where size is the number of processes in the group.  Fortran: MPI_GROUP_SIZE(int group, int size, int IERR)  June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes Modifying and Accessing Extracted Groups Accessing Information from a Group MPI_GROUP_RANK returns the rank of each calling process within a group.  MPI_GROUP_RANK(int group, int rank, int IERR)   If the calling process does not belong to the group, then the returned group rank is MPI_UNDEFINED.  MPI_GROUP_TRANSLATE_RANKS  takes an array of  n  ranks of the processes and translates them to the corresponding ranks of the processes in another group.  MPI_GROUP_TRANSLATE_RANKS(int group1, int  n , int rank1, int group2, int rank2, int IERR)  June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes Modifying and Accessing Extracted Groups Accessing Information from a Group MPI_GROUP_COMPARE  compares the relationship between two groups of processes.  MPI_GROUP_COMPARE(int group1, int group2, int result, int IERR)  MPI_GROUP_COMPARE returns MPI_IDENT if the processes in the two groups are identical and are ranked in the same way, MPI_SIMILAR if the processes in the two groups are identical but ranked differently, and MPI_UNEQUAL for any other relationship between the two groups.  June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes Modifying and Accessing Extracted Groups Destroying a Group A group can be destroyed (marked for deallocation) using the group destructor command  MPI_GROUP_FREE . Fortran: MPI_GROUP_FREE(int group, int ierr)  Notes: Freeing a group does not free the communicator to which it belongs.  The MPI_COMM_FREE routine described in the next section exists to free a communicator. June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes Creating a Communicator from an Extracted Group Communicator creation is a collective operation and, therefore, may require communication between different processes.  Since a communicator constructor routine is collective, it must be called by all processes in the group that will be contained in the new communicator.  You can create a new communicator from an extracted group using the  MPI_COMM_CREATE  command. June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes Creating a Communicator from an Extracted Group MPI_COMM_CREATE(int comm, int group, int newcomm, int ierr)  This routine must be called by all processes in  group  associated with  comm  and that all arguments in the routine must be identical on all calling processes.  Group  must be a subset of the group associated with the communicator  comm .  For processes in  comm  that are not included in  group , this routine will return MPI_COMM_NULL to those processes.  June - 2009 LNEC-DHA-NTI
Modifying a Group of Processes Creating a Communicator from an Extracted Group June - 2009 LNEC-DHA-NTI include "mpif.h" integer comm_world, group_world, comm_worker, group_worker, ierr ... comm_world = MPI_COMM_WORLD call MPI_Comm_group(comm_world, group_world, ierr) call MPI_Group_excl(group_world, 1, ranks, group_worker, ierr)  ! process 0 not member call MPI_Comm_create(comm_world, group_worker, comm_worker, ierr) MPI_COMM_WORLD communicator's group handle is identified.  A new group,  group_worker , is created.  This group is defined to include all but process 0 of MPI_COMM_WORLD as members by way of MPI_GROUP_EXCL.  MPI_COMM_CREATE is used to create a new communicator whose member processes are those of the new group just created.  With this new communicator, message passing can now proceed among its member processes.
Modifying a Group of Processes Creating a Communicator from an Extracted Group June - 2009 LNEC-DHA-NTI include "mpif.h" integer comm_world, group_world, comm_worker, group_worker, ierr ... comm_world = MPI_COMM_WORLD call MPI_Comm_group(comm_world, group_world, ierr) call MPI_Group_excl(group_world, 1, ranks, group_worker, ierr)  ! process 0 not member call MPI_Comm_create(comm_world, group_worker, comm_worker, ierr) Notes  MPI_COMM_CREATE is a collective communication routine; it must be called by all processes of old_comm and all arguments in the call must be the same for all processes. Otherwise, error results.  MPI_COMM_CREATE returns MPI_COMM_NULL to processes that are not in group.  Upon completion of its task, the created communicator may be released by calling MPI_COMM_FREE.
Modifying a Group of Processes Creating a Communicator from an Extracted Group An intracommunicator can be destroyed (marked for deallocation) using the following communicator destructor:  MPI_COMM_FREE(int comm, int IERR)  This MPI routine is a collective operation and must be called by all processes in  comm . June - 2009 LNEC-DHA-NTI
Creating Intercommunicators  An intercommunicator contains two disjoint groups of processes and is used for communication between two distinct intracommunicators.  This communicator structure distinguishes between a  local  group and a  remote  group.  If you have two disjoint groups  A  and  B , for the processes in group  A , group  A  is local and group  B  is remote.  This structure is symmetric such that for processes in group  B , group  B  is local and group  A  is remote.  June - 2009 LNEC-DHA-NTI
Creating Intercommunicators  The syntax for point-to-point communication is the same for both intercommunicators and intracommunicators.  E.g. A process in group  A  can execute a call to MPI_SEND and another process in group  B  can execute a matching call to MPI_RECV. As in intra-group communication, the matching process (i.e., the destination of the send and the source of the receive) is specified using a pair of values corresponding to  communicator  and  rank , where  rank  is always specified relative to the  local  group.  June - 2009 LNEC-DHA-NTI
Creating Intercommunicators  In contrast to intracommunication, the target process is always specified by its rank in the  remote  group for both sends and receives.  E.g.: Process p0 ( rank  = 0) in group  A  would send a message to process p3 ( rank  = 3) in group  B  with a call to MPI_Send( . . . , 3, tag, comm), while process p3 would receive this message with a call to MPI_Recv( . . . , 0, tag, comm).  Conversely, process p3 in group  B  would send a message to process p0 in group  A  with a call to MPI_Send( . . . , 0, tag, comm), while process p0 would receive this message with a call to MPI_Recv( . . . , 3, tag, comm).  June - 2009 LNEC-DHA-NTI
Creating Intercommunicators  MPI_COMM_TEST_INTER   routine to determine if a communicator is an intracommunicator or an intercommunicator.  Fortran: MPI_COMM_TEST_INTER(int comm, int flag, int IERR)  June - 2009 LNEC-DHA-NTI
Creating An Intercommunicator From Two Intracommunicators One method for creating an intercommunicator is to join two intracommunicators i.e.: generate a pair of communicating groups from two disjoint groups.  Requires that there is one process in each of the two groups that can communicate with each other through a communication domain that acts as a bridge between the two groups.  MPI_INTERCOMM_CREATE:   to create an intercommunicator.  MPI_INTERCOMM_CREATE(int local_comm, int local_leader, int bridge_comm, int remote_leader, int tag, int intercomm, int IERR)  June - 2009 LNEC-DHA-NTI
Creating An Intercommunicator From Two Intracommunicators MPI_INTERCOMM_CREATE(int local_comm, int local_leader, int bridge_comm, int remote_leader, int tag, int intercomm, int IERR)  This routine is a collective communication operation within each of the separate groups and requires communication across the two groups. E.g.: Suppose that the  intracommunicator   comm1  contains  three processes  and the  intracommunicator   comm2  contains  four processes. June - 2009 LNEC-DHA-NTI Creating an intercommunicator by joining two existing intracommunicators.
Creating An Intercommunicator From Two Intracommunicators In terms of the intracommunicator  MPI_COMM_WORLD , the processes in  comm1  have (world) ranks 0, 1, and 2 (local ranks are 0, 1, and 2), whereas those in  comm2  have (world) ranks 3, 4, 5, and 6 (local ranks are 0, 1, 2, and 3).  Assume that the local process 0 in each intracommunicator form the bridge between the two disjoint groups of processes.  These two processes can communicate through MPI_COMM_WORLD where process 0 in comm1 has rank 0 and process 0 in comm2 has rank 3 (these ranks are both world ranks). June - 2009 LNEC-DHA-NTI Creating an intercommunicator by joining two existing intracommunicators.
Creating An Intercommunicator From Two Intracommunicators Once the  intercommunicator  is formed, the original group in each intracommunicator becomes the local group in the intercomunicator, whereas the other intracommunicator becomes the remote group. It is the rank in the remote group that must be used for communication within the new intercommunicator. For example, if one of the processes in  comm1  sends a message to process 2 in  comm2  (world rank = 5 in MPI_COMM_WORLD), then it must use a rank of 2 in MPI_Send.  June - 2009 LNEC-DHA-NTI Creating an intercommunicator by joining two existing intracommunicators.
Creating an Intercommunicator from an Existing Intercommunicator A new intercommunicator can also be created from some existing intercommunicator.  This method involves the union of two groups associated with an existing intercommunicator,  intercomm .  MPI_INTERCOMM_MERGE :  to create a new intercommunicator from some existing intercommunicator. Fortran: MPI_INTERCOMM_MERGE(int intercomm, logical high, int newintercom, int IERR)  June - 2009 LNEC-DHA-NTI
Creating an Intercommunicator from an Existing Intercommunicator Fortran: MPI_INTERCOMM_MERGE(int intercomm, logical high, int newintercom, int IERR)  The value of argument high determines the order within the union of the two groups.  All processes within a given group must provide the same value for high.  If processes in one group provide the value high = false and processes in the other group provide the value high = true, the union will order the 'low' (high = false) group before the 'high' group.  If the same value for high is provided by all processes in both groups, the order in the union of the two groups will be arbitrary.  June - 2009 LNEC-DHA-NTI
Accessing Information from an Intercommunicator The communicator accessors  MPI_COMM_REMOTE_SIZE  and  MPI_COMM_REMOTE_GROUP  can be used to access information from an intercommunicator. MPI_COMM_REMOTE_SIZE returns the number of processes in the remote group associated with the communicator.  Fortran: MPI_COMM_REMOTE_SIZE(int comm, int size, int ierr)  The MPI routine MPI_COMM_REMOTE_GROUP returns the group underlying the intercommunicator.  Fortran: MPI_COMM_REMOTE_GROUP(int comm, int group, int ierr  June - 2009 LNEC-DHA-NTI
Any questions, so far? June - 2009 LNEC-DHA-NTI    Nano- Self Test – Communicators   http://ci-tutor.ncsa.uiuc.edu/content.php?cid=1317 Practical Section

Tutorial on Parallel Computing and Message Passing Model - C5

  • 1.
    Communicators Marcirio SilveiraChaves [email_address] Tutorial on Parallel Computing and Message Passing Model Part II - Day 5
  • 2.
    Objectives The basicsabout communicators About two types of communicators that can be defined in MPI — intracommunicators and intercommunicators How to create and use different groups of processors and communicators How to modify a group of processes How to create both intercommunicators and intracommunicators How to access information from each of these types of communicators June - 2009 LNEC-DHA-NTI
  • 3.
    Communicator Basics Themost familiar communicator in MPI is MPI_COMM_WORLD ... … is predefined and includes the entire set of processes created when an MPI program begins execution. It is through this communicator that any process can communicate with any other individual process by using point-to-point communication or with all other processes within MPI_COMM_WORLD by using a collective communication call. For certain types of computation it turns out to be more advantageous to restrict communication to a subset of the processes created at runtime. E.g. suppose that you wanted to carry out, in parallel, a matrix-multiplication computation, C = A × B. June - 2009 LNEC-DHA-NTI
  • 4.
    Communicator Basics E.g.suppose that you wanted to carry out, in parallel, a matrix-multiplication computation, C = A × B. June - 2009 LNEC-DHA-NTI A matrix-multiplication problem that is to be computed in parallel.
  • 5.
    Communicator Basics Inthis particular type of parallel computation you can organize your processes in a n x m grid of rows and columns June - 2009 LNEC-DHA-NTI A 2-dimensional grid of processes arranged in rows and columns corresponding to the rows and columns of the matrices A and B. wherein element cij of matrix C is to be computed on process p(i, j) , where
  • 6.
    Communicator Basics Inorder to compute cij on process p(i, j) , you need to distribute: all k elements in the i th row of matrix A and all k elements in the j th column of matrix B to process p(i, j) . Instead of using a single communicator that includes all n x m processes in MPI_COMM_WORLD create a set of separate communicators that more naturally reflects the structure of communication along the rows and columns of the 2-dimensional grid of processes (viz., one communicator for each row and column of this topology ). June - 2009 LNEC-DHA-NTI
  • 7.
    Types of Communicators- Intracommunicators - Intercommunicators A communicator can be of either type, but never both. An intracommunicator contains a single group of processes, within which all of the processes have a unique rank. The 10 processes split into two separate intracommunicators, MPI_COMM_WORLD and commNew1. Two separate groups of processes associated with different intracommunicators, MPI_COMM_WORLD and commNew1. June - 2009 LNEC-DHA-NTI
  • 8.
    Types of CommunicatorsAll 10 processes created at runtime are associated with the predefined intracommunicator, MPI_COMM_WORLD. A subset of these processes ( p1 , p2 , p3 , and p4 ) is also associated with an intracommunicator, commNew1 , that is distinct from MPI_COMM_WORLD. Although the ranks of these four processes in MPI_COMM_WORLD are 1, 2, 3, and 4, these same four processes may have entirely different ranks (e.g., 0, 1, 2, and 3, respectively) in commNew1 . June - 2009 LNEC-DHA-NTI
  • 9.
    Types of CommunicatorsIn contrast to an intracommunicator, an intercommunicator contains two disjoint groups of processes and is used for communication between two distinct intracommunicators. In MPI-1 intercommunicators only allow point-to-point communications between processes belonging to different communicators. On the other hand, MPI-2 allows both point-to-point and collective communicators between processes belonging to two disjoint communicators. June - 2009 LNEC-DHA-NTI
  • 10.
    Types of CommunicatorsIn our example, each process in commNew1 , such as p2 , can communicate with every other process in commNew1 by using either point-to-point or collective communications. Process p2 can also communicate with process p5 in either of two ways. First, p1 can use the intracommunicator MPI_COMM_WORLD, since both p2 and p5 are members of this communicator. Second, you can construct an inter communicator, commNew2 , that will allow all process in commNew1 to communicate with all processes in MPI_COMM_WORLD across these two intracommunicators. June - 2009 LNEC-DHA-NTI
  • 11.
    Creating Intracommunicators InMPI-1: Multiple methods to create intracommunicators. Split an existing intracommunicator into two or more sub-communicators Duplicate an existing intracommunicator Modify a group of processes from an existing intracommunicator, and create a new communicator based on this modified group Reorder the processes in an existing group based on some type of specific topology MPI-2 provides the following two additional methods: Connecting two separate applications and merging their communicators Spawning new processes June - 2009 LNEC-DHA-NTI
  • 12.
    Splitting an ExistingIntracommunicator Splitting a communicator into different sub-communicators is a convenient method for mapping processes onto a 2-dimensional topology corresponding to the rows and columns of a matrix or a set of coordinates distributed onto a Cartesian grid. Useful in scientific applications involving matrix multiplication and other linear algebra computations. June - 2009 LNEC-DHA-NTI
  • 13.
    Splitting an ExistingIntracommunicator MPI_COMM_SPLIT : to split a communicator into sub-communicators. Fortran: MPI_COMM_SPLIT(int comm , int color , int key , int newcomm , int IERR) All processes that have the same color will belong to the same unique sub-communicator All processes of a given color will be ordered according to the value of key . June - 2009 LNEC-DHA-NTI This routine partitions the group associated with the original communicator comm into disjoint subgroups , with one subgroup for each different value of color . A new communicator is created for each subgroup and a handle to this communicator is returned in newcomm .
  • 14.
    Splitting an ExistingIntracommunicator MPI_COMM_SPLIT : to split a communicator into sub-communicators. Fortran: MPI_COMM_SPLIT(int comm , int color , int key , int newcomm , int IERR) If the value of key is the same for two or more processes, these processes will be ordered according to their relative ranks in the original communicator. If a process is not to be included within any of the resulting sub-communicators its color is set to MPI_UNDEFINED, in which case newcomm will return MPI_COMM_NULL. MPI_COMM_NULL represents an invalid communicator and any MPI routine that is passed MPI_COMM_NULL as an argument will return an error. June - 2009 LNEC-DHA-NTI
  • 15.
    Splitting an ExistingIntracommunicator MPI_COMM_SPLIT : to split a communicator into sub-communicators. Fortran: MPI_COMM_SPLIT(int comm , int color , int key , int newcomm , int IERR) MPI_COMM_SPLIT is a collective communications routine that must be called by all processes in the original communicator, comm . In contrast to other collective routines, which require that all arguments be identical on all processes calling the routine, for MPI_COMM_SPLIT each process can specify a different value both for color and for key . June - 2009 LNEC-DHA-NTI
  • 16.
    Splitting an ExistingIntracommunicator E.g. 1: Assume that a call to MPI_COMM_SPLIT is executed on a group of 8 processes with the following arguments: This call to MPI_COMM_SPLIT will generate three sub-communicators whose processes will be rank ordered as shown below. June - 2009 LNEC-DHA-NTI Creating 3 new intracommunicators by splitting an existing intracommunicator containing 8 processes. process p0 p1 p2 p3 p4 p5 p6 p7 rank 0 1 2 3 4 5 6 7 color 1 2 2 4 1 1 2 1 key 3 5 5 2 2 1 2 3
  • 17.
    Duplicating an ExistingIntracommunicator When creating a new communicator, it is sometimes convenient to start by duplicating an existing communicator. You can do this with the MPI routine for duplicating an existing intracommunicator — MPI_COMM_DUP . Fortran: MPI_COMM_DUP(int comm, int newcomm, int IERR) The new communicator, newcomm , will have exactly the same fixed attributes (group(s) and topology) as the input communicator, comm . Although newcomm is a duplicate of comm , the communication domains of these two communicators are distinct. June - 2009 LNEC-DHA-NTI
  • 18.
    Modifying a Groupof Processes Another method for creating a new intracommunicator is: to modify a group of processes from an existing communicator and create the new communicator based on this modified group. Group : any ordered set of N processes wherein each process is associated with a unique number or rank running contiguously from zero to ( N - 1 ). June - 2009 LNEC-DHA-NTI
  • 19.
    Modifying a Groupof Processes Since groups can be used to restrict collective communications only between a subset of processes, maintaining separate, disjoint groups can be useful in many applications (e.g., for dual-level parallelism). Groups can be created, accessed, modified, and destroyed but can only be used for message passing within a communicator . When a group is created, it is not associated with any communicator. The communicator must be created in a separate operation based on some specified pre-existing group. June - 2009 LNEC-DHA-NTI
  • 20.
    Modifying a Groupof Processes A group constructor is used to create a new group through the modification of some existing group. Group creation is a local operation and, therefore, requires no communication between processes. However, each process that is to be included in a group that is being created must create the same group. Following its creation, a group cannot be used for communication since it will not be associated with any communicator. A modified group becomes associated with a communicator through a call to a separate communicator-creation operation. June - 2009 LNEC-DHA-NTI
  • 21.
    Modifying a Groupof Processes June - 2009 LNEC-DHA-NTI Creating a new intracommunicator based on a modified group of processes.
  • 22.
    Modifying a Groupof Processes Extracting a Group You can access the group of processes associated with a given communicator by using the MPI_COMM_GROUP command to extract them. Associated with a communicator is its group identity , or handle. MPI_COMM_GROUP is used to obtain the group handle of the communicator , which can be used as input to the MPI routines for accessing and modifying the extracted groups. Fortran: MPI_COMM_GROUP( int comm , int group , int ierr) where MPI_COMM_GROUP extracts a group of processes associated with some original communicator, comm, into group. June - 2009 LNEC-DHA-NTI
  • 23.
    Modifying a Groupof Processes Fortran: MPI_COMM_GROUP( int comm , int group , int ierr) where MPI_COMM_GROUP extracts a group of processes associated with some original communicator, comm, into group. June - 2009 LNEC-DHA-NTI Fortran: include "mpif.h" integer comm_world, ierr, group_world comm_world = MPI_COMM_WORLD call MPI_Comm_group(comm_world, group_world, ierr)
  • 24.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Once you have extracted a group of proccesses from an existing intracommunicator, you can modify it and access information about it using MPI routines. When you are finished with the group you can call a routine to destroy it. June - 2009 LNEC-DHA-NTI
  • 25.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Group Constructors Once a group of processes has been extracted from an existing intracommunicator, it can be modified using any one of the MPI group-modification routines or 'group constructors.' MPI_GROUP_INCL MPI_GROUP_EXCL MPI_GROUP_UNION MPI_GROUP_INTERSECTION MPI_GROUP_DIFFERENCE Examples: Two separate groups of processes have been extracted from an existing communicator that contain the following sets of processes ranked in the order indicated below. group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ] June - 2009 LNEC-DHA-NTI
  • 26.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_INCL : creates a new group by reordering a specified number of the processes from an existing group . Fortran MPI_GROUP_INCL(int group , int n , int rank, int newgroup , int ierr) If n = 0, newgroup will be identical to group. Using the existing group , group1 , we create a new group by calling: MPI_GROUP_INCL( group1 , 5 , rank, newgroup , ierr) where rank[5] = [0 4 6 5 2]. The resulting group, newgroup, contains 5 processes, [p0, p4, p6, p5, p2], from group1 in the order defined by rank. June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
  • 27.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_EXCL : creates a new group from an original group that contains all processes left after deleting those with specified ranks. The relative rank order of the remaining processes will be the same as that in the original group. Fortran MPI_GROUP_ EXCL (int group , int n , int rank, int newgroup , int IERR) If n = 0 , newgroup will be identical to group . Using the existing group, group1 , we create a new group by calling: MPI_Group_EXCL(group1, 5, rank, newgroup, ierr); where rank[5] = [0 4 6 5 2]. The resulting group, newgroup , contains: [p1, p3]. June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
  • 28.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_UNION : creates a new group that contains all processes in the first group followed by all processes in the second group with no duplication of processes. Fortran: MPI_GROUP_UNION(int group1, int group2, int newgroup, int IERR) Using the existing groups, group1 and group2 , we create a new group by calling: MPI_Group_union(group1, group2, &newgroup); June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
  • 29.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Group Constructors The resulting group, newgroup , contains: newgroup: [ p0, p1, p2, p3, p4, p5, p6, p7, p8 ] We now reverse the order of the groups in the function call: MPI_Group_union(group2, group1, &newgroup); resulting in: newgroup: [ p3, p6, p0, p2, p7, p8, p1, p4, p5 ] June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
  • 30.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_INTERSECTION : creates a new group from two groups that contains all processes that are in both of the groups with rank order the same as that in the first group. Fortran: MPI_GROUP_INTERSECTION(int group1, int group2, int newgroup, int IERR) Using the existing groups, group1 and group2, we create a new group by calling: MPI_Group_intersection(group1, group2, &newgroup); June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
  • 31.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_INTERSECTION The resulting group, newgroup, contains: newgroup: [ p0, p2 , p3, p6 ] To reverse the order of the groups in the function call: MPI_Group_intersection(group2, group1 , &newgroup); resulting in: newgroup: [ p3, p6, p0, p2 ] June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
  • 32.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_DIFFERENCE: creates a new group from two groups that contains all processes in the first group that are not in the second group with rank order the same as that in the first group. Fortran: MPI_GROUP_DIFFERENCE(int group1, int group2, int newgroup, int IERR) Using the existing groups, group1 and group2 , we create a new group by calling: MPI_Group_difference(group1, group2, &newgroup); June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
  • 33.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Group Constructors MPI_GROUP_DIFFERENCE: The resulting group, newgroup , contains: newgroup: [ p1, p4, p5 ] We now reverse the order of the groups in the function call: MPI_Group_difference(group2, group1, &newgroup); resulting in: newgroup: [ p7, p8 ] June - 2009 LNEC-DHA-NTI group1 : [ p0, p1, p2, p3, p4, p5, p6 ] group2 : [ p3, p6, p0, p2, p7, p8 ]
  • 34.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Accessing Information from a Group Once a group has been modified, information about the original group of processes or the modified group of processes can be accessed using one of the following group accessor commands: MPI_GROUP_SIZE MPI_GROUP_RANK MPI_GROUP_TRANSLATE_RANKS MPI_GROUP_COMPARE MPI_GROUP_SIZE returns the size of a group where size is the number of processes in the group. Fortran: MPI_GROUP_SIZE(int group, int size, int IERR) June - 2009 LNEC-DHA-NTI
  • 35.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Accessing Information from a Group MPI_GROUP_RANK returns the rank of each calling process within a group. MPI_GROUP_RANK(int group, int rank, int IERR) If the calling process does not belong to the group, then the returned group rank is MPI_UNDEFINED. MPI_GROUP_TRANSLATE_RANKS takes an array of n ranks of the processes and translates them to the corresponding ranks of the processes in another group. MPI_GROUP_TRANSLATE_RANKS(int group1, int n , int rank1, int group2, int rank2, int IERR) June - 2009 LNEC-DHA-NTI
  • 36.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Accessing Information from a Group MPI_GROUP_COMPARE compares the relationship between two groups of processes. MPI_GROUP_COMPARE(int group1, int group2, int result, int IERR) MPI_GROUP_COMPARE returns MPI_IDENT if the processes in the two groups are identical and are ranked in the same way, MPI_SIMILAR if the processes in the two groups are identical but ranked differently, and MPI_UNEQUAL for any other relationship between the two groups. June - 2009 LNEC-DHA-NTI
  • 37.
    Modifying a Groupof Processes Modifying and Accessing Extracted Groups Destroying a Group A group can be destroyed (marked for deallocation) using the group destructor command MPI_GROUP_FREE . Fortran: MPI_GROUP_FREE(int group, int ierr) Notes: Freeing a group does not free the communicator to which it belongs. The MPI_COMM_FREE routine described in the next section exists to free a communicator. June - 2009 LNEC-DHA-NTI
  • 38.
    Modifying a Groupof Processes Creating a Communicator from an Extracted Group Communicator creation is a collective operation and, therefore, may require communication between different processes. Since a communicator constructor routine is collective, it must be called by all processes in the group that will be contained in the new communicator. You can create a new communicator from an extracted group using the MPI_COMM_CREATE command. June - 2009 LNEC-DHA-NTI
  • 39.
    Modifying a Groupof Processes Creating a Communicator from an Extracted Group MPI_COMM_CREATE(int comm, int group, int newcomm, int ierr) This routine must be called by all processes in group associated with comm and that all arguments in the routine must be identical on all calling processes. Group must be a subset of the group associated with the communicator comm . For processes in comm that are not included in group , this routine will return MPI_COMM_NULL to those processes. June - 2009 LNEC-DHA-NTI
  • 40.
    Modifying a Groupof Processes Creating a Communicator from an Extracted Group June - 2009 LNEC-DHA-NTI include "mpif.h" integer comm_world, group_world, comm_worker, group_worker, ierr ... comm_world = MPI_COMM_WORLD call MPI_Comm_group(comm_world, group_world, ierr) call MPI_Group_excl(group_world, 1, ranks, group_worker, ierr) ! process 0 not member call MPI_Comm_create(comm_world, group_worker, comm_worker, ierr) MPI_COMM_WORLD communicator's group handle is identified. A new group, group_worker , is created. This group is defined to include all but process 0 of MPI_COMM_WORLD as members by way of MPI_GROUP_EXCL. MPI_COMM_CREATE is used to create a new communicator whose member processes are those of the new group just created. With this new communicator, message passing can now proceed among its member processes.
  • 41.
    Modifying a Groupof Processes Creating a Communicator from an Extracted Group June - 2009 LNEC-DHA-NTI include "mpif.h" integer comm_world, group_world, comm_worker, group_worker, ierr ... comm_world = MPI_COMM_WORLD call MPI_Comm_group(comm_world, group_world, ierr) call MPI_Group_excl(group_world, 1, ranks, group_worker, ierr) ! process 0 not member call MPI_Comm_create(comm_world, group_worker, comm_worker, ierr) Notes MPI_COMM_CREATE is a collective communication routine; it must be called by all processes of old_comm and all arguments in the call must be the same for all processes. Otherwise, error results. MPI_COMM_CREATE returns MPI_COMM_NULL to processes that are not in group. Upon completion of its task, the created communicator may be released by calling MPI_COMM_FREE.
  • 42.
    Modifying a Groupof Processes Creating a Communicator from an Extracted Group An intracommunicator can be destroyed (marked for deallocation) using the following communicator destructor: MPI_COMM_FREE(int comm, int IERR) This MPI routine is a collective operation and must be called by all processes in comm . June - 2009 LNEC-DHA-NTI
  • 43.
    Creating Intercommunicators An intercommunicator contains two disjoint groups of processes and is used for communication between two distinct intracommunicators. This communicator structure distinguishes between a local group and a remote group. If you have two disjoint groups A and B , for the processes in group A , group A is local and group B is remote. This structure is symmetric such that for processes in group B , group B is local and group A is remote. June - 2009 LNEC-DHA-NTI
  • 44.
    Creating Intercommunicators The syntax for point-to-point communication is the same for both intercommunicators and intracommunicators. E.g. A process in group A can execute a call to MPI_SEND and another process in group B can execute a matching call to MPI_RECV. As in intra-group communication, the matching process (i.e., the destination of the send and the source of the receive) is specified using a pair of values corresponding to communicator and rank , where rank is always specified relative to the local group. June - 2009 LNEC-DHA-NTI
  • 45.
    Creating Intercommunicators In contrast to intracommunication, the target process is always specified by its rank in the remote group for both sends and receives. E.g.: Process p0 ( rank = 0) in group A would send a message to process p3 ( rank = 3) in group B with a call to MPI_Send( . . . , 3, tag, comm), while process p3 would receive this message with a call to MPI_Recv( . . . , 0, tag, comm). Conversely, process p3 in group B would send a message to process p0 in group A with a call to MPI_Send( . . . , 0, tag, comm), while process p0 would receive this message with a call to MPI_Recv( . . . , 3, tag, comm). June - 2009 LNEC-DHA-NTI
  • 46.
    Creating Intercommunicators MPI_COMM_TEST_INTER routine to determine if a communicator is an intracommunicator or an intercommunicator. Fortran: MPI_COMM_TEST_INTER(int comm, int flag, int IERR) June - 2009 LNEC-DHA-NTI
  • 47.
    Creating An IntercommunicatorFrom Two Intracommunicators One method for creating an intercommunicator is to join two intracommunicators i.e.: generate a pair of communicating groups from two disjoint groups. Requires that there is one process in each of the two groups that can communicate with each other through a communication domain that acts as a bridge between the two groups. MPI_INTERCOMM_CREATE: to create an intercommunicator. MPI_INTERCOMM_CREATE(int local_comm, int local_leader, int bridge_comm, int remote_leader, int tag, int intercomm, int IERR) June - 2009 LNEC-DHA-NTI
  • 48.
    Creating An IntercommunicatorFrom Two Intracommunicators MPI_INTERCOMM_CREATE(int local_comm, int local_leader, int bridge_comm, int remote_leader, int tag, int intercomm, int IERR) This routine is a collective communication operation within each of the separate groups and requires communication across the two groups. E.g.: Suppose that the intracommunicator comm1 contains three processes and the intracommunicator comm2 contains four processes. June - 2009 LNEC-DHA-NTI Creating an intercommunicator by joining two existing intracommunicators.
  • 49.
    Creating An IntercommunicatorFrom Two Intracommunicators In terms of the intracommunicator MPI_COMM_WORLD , the processes in comm1 have (world) ranks 0, 1, and 2 (local ranks are 0, 1, and 2), whereas those in comm2 have (world) ranks 3, 4, 5, and 6 (local ranks are 0, 1, 2, and 3). Assume that the local process 0 in each intracommunicator form the bridge between the two disjoint groups of processes. These two processes can communicate through MPI_COMM_WORLD where process 0 in comm1 has rank 0 and process 0 in comm2 has rank 3 (these ranks are both world ranks). June - 2009 LNEC-DHA-NTI Creating an intercommunicator by joining two existing intracommunicators.
  • 50.
    Creating An IntercommunicatorFrom Two Intracommunicators Once the intercommunicator is formed, the original group in each intracommunicator becomes the local group in the intercomunicator, whereas the other intracommunicator becomes the remote group. It is the rank in the remote group that must be used for communication within the new intercommunicator. For example, if one of the processes in comm1 sends a message to process 2 in comm2 (world rank = 5 in MPI_COMM_WORLD), then it must use a rank of 2 in MPI_Send. June - 2009 LNEC-DHA-NTI Creating an intercommunicator by joining two existing intracommunicators.
  • 51.
    Creating an Intercommunicatorfrom an Existing Intercommunicator A new intercommunicator can also be created from some existing intercommunicator. This method involves the union of two groups associated with an existing intercommunicator, intercomm . MPI_INTERCOMM_MERGE : to create a new intercommunicator from some existing intercommunicator. Fortran: MPI_INTERCOMM_MERGE(int intercomm, logical high, int newintercom, int IERR) June - 2009 LNEC-DHA-NTI
  • 52.
    Creating an Intercommunicatorfrom an Existing Intercommunicator Fortran: MPI_INTERCOMM_MERGE(int intercomm, logical high, int newintercom, int IERR) The value of argument high determines the order within the union of the two groups. All processes within a given group must provide the same value for high. If processes in one group provide the value high = false and processes in the other group provide the value high = true, the union will order the 'low' (high = false) group before the 'high' group. If the same value for high is provided by all processes in both groups, the order in the union of the two groups will be arbitrary. June - 2009 LNEC-DHA-NTI
  • 53.
    Accessing Information froman Intercommunicator The communicator accessors MPI_COMM_REMOTE_SIZE and MPI_COMM_REMOTE_GROUP can be used to access information from an intercommunicator. MPI_COMM_REMOTE_SIZE returns the number of processes in the remote group associated with the communicator. Fortran: MPI_COMM_REMOTE_SIZE(int comm, int size, int ierr) The MPI routine MPI_COMM_REMOTE_GROUP returns the group underlying the intercommunicator. Fortran: MPI_COMM_REMOTE_GROUP(int comm, int group, int ierr June - 2009 LNEC-DHA-NTI
  • 54.
    Any questions, sofar? June - 2009 LNEC-DHA-NTI  Nano- Self Test – Communicators  http://ci-tutor.ncsa.uiuc.edu/content.php?cid=1317 Practical Section

Editor's Notes

  • #6 P(1,0) = linha A1 x coluna B0
  • #12 The remainder of this section describes how to create new intracommunicators using the first three MPI-1 methods listed above.
  • #15 Self-Test: question 7
  • #27 Self-test: question 2
  • #28 Self-test: question 3,4,5
  • #36 Selt-Test: question 6