Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Communicators Marcirio Silveira Chaves [email_address] Tutorial on Parallel Computing and  Message Passing Model Part II -...
Objectives <ul><li>The basics about communicators </li></ul><ul><li>About two types of communicators that can be defined i...
Communicator Basics <ul><li>The most familiar communicator in MPI is MPI_COMM_WORLD ...  </li></ul><ul><ul><li>…  is prede...
Communicator Basics <ul><li>E.g. </li></ul><ul><li>suppose that you wanted to carry out, in parallel, a matrix-multiplicat...
Communicator Basics <ul><li>In this particular type of parallel computation you can organize your processes in a  n x m  g...
Communicator Basics <ul><li>In order to compute  cij  on process  p(i, j) , you need to distribute: </li></ul><ul><ul><li>...
Types of Communicators <ul><li>- Intracommunicators - Intercommunicators </li></ul><ul><ul><li>A communicator can be of ei...
Types of Communicators <ul><li>All 10 processes created at runtime are associated with the predefined intracommunicator, M...
Types of Communicators <ul><li>In contrast to an intracommunicator, an  intercommunicator  contains two disjoint groups of...
Types of Communicators <ul><li>In our example, each process in  commNew1 , such as  p2 , can communicate with every other ...
Creating Intracommunicators <ul><li>In MPI-1: Multiple methods to create intracommunicators. </li></ul><ul><ul><li>Split  ...
Splitting an Existing Intracommunicator <ul><li>Splitting a communicator into different sub-communicators is a convenient ...
Splitting an Existing Intracommunicator <ul><li>MPI_COMM_SPLIT :  to split a communicator into sub-communicators.  </li></...
Splitting an Existing Intracommunicator <ul><li>MPI_COMM_SPLIT :  to split a communicator into sub-communicators.  </li></...
Splitting an Existing Intracommunicator <ul><li>MPI_COMM_SPLIT :  to split a communicator into sub-communicators.  </li></...
Splitting an Existing Intracommunicator <ul><li>E.g. 1: </li></ul><ul><li>Assume that a call to MPI_COMM_SPLIT is executed...
Duplicating an Existing Intracommunicator <ul><li>When creating a new communicator, it is sometimes convenient to start by...
Modifying a Group of Processes <ul><li>Another method for creating a new intracommunicator is: </li></ul><ul><ul><li>to mo...
Modifying a Group of Processes <ul><li>Since groups can be used to restrict collective communications only between a subse...
Modifying a Group of Processes <ul><li>A group constructor is used to create a new group through the modification of some ...
Modifying a Group of Processes June - 2009 LNEC-DHA-NTI Creating a new intracommunicator based on a modified group of proc...
Modifying a Group of Processes <ul><li>Extracting a Group </li></ul><ul><ul><li>You can access the group of processes asso...
Modifying a Group of Processes <ul><li>Fortran: </li></ul><ul><li>MPI_COMM_GROUP( int comm ,  int group , int ierr) </li><...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Once you have extrac...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Group Constructors <...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Group Constructors <...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Group Constructors <...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Group Constructors <...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Group Constructors <...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Group Constructors <...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Group Constructors <...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Group Constructors <...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Group Constructors <...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Accessing Informatio...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Accessing Informatio...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Accessing Informatio...
Modifying a Group of Processes <ul><li>Modifying and Accessing Extracted Groups </li></ul><ul><ul><li>Destroying a Group <...
Modifying a Group of Processes <ul><li>Creating a Communicator from an Extracted Group </li></ul><ul><ul><li>Communicator ...
Modifying a Group of Processes <ul><li>Creating a Communicator from an Extracted Group </li></ul><ul><ul><li>MPI_COMM_CREA...
Modifying a Group of Processes <ul><li>Creating a Communicator from an Extracted Group </li></ul>June - 2009 LNEC-DHA-NTI ...
Modifying a Group of Processes <ul><li>Creating a Communicator from an Extracted Group </li></ul>June - 2009 LNEC-DHA-NTI ...
Modifying a Group of Processes <ul><li>Creating a Communicator from an Extracted Group </li></ul><ul><ul><li>An intracommu...
Creating Intercommunicators  <ul><li>An intercommunicator contains two disjoint groups of processes and is used for commun...
Creating Intercommunicators  <ul><li>The syntax for point-to-point communication is the same for both intercommunicators a...
Creating Intercommunicators  <ul><li>In contrast to intracommunication, the target process is always specified by its rank...
Creating Intercommunicators  <ul><li>MPI_COMM_TEST_INTER   routine to determine if a communicator is an intracommunicator ...
Creating An Intercommunicator From Two Intracommunicators <ul><li>One method for creating an intercommunicator is to join ...
Creating An Intercommunicator From Two Intracommunicators <ul><ul><li>MPI_INTERCOMM_CREATE(int local_comm, int local_leade...
Creating An Intercommunicator From Two Intracommunicators <ul><li>In terms of the intracommunicator  MPI_COMM_WORLD , the ...
Creating An Intercommunicator From Two Intracommunicators <ul><li>Once the  intercommunicator  is formed, the original gro...
Creating an Intercommunicator from an Existing Intercommunicator <ul><li>A new intercommunicator can also be created from ...
Creating an Intercommunicator from an Existing Intercommunicator <ul><li>Fortran: </li></ul><ul><li>MPI_INTERCOMM_MERGE(in...
Accessing Information from an Intercommunicator <ul><li>The communicator accessors  MPI_COMM_REMOTE_SIZE  and  MPI_COMM_RE...
<ul><li>Any questions, so far? </li></ul>June - 2009 LNEC-DHA-NTI    Nano- Self Test – Communicators   http://ci-tutor.n...
Upcoming SlideShare
Loading in …5
×

Tutorial on Parallel Computing and Message Passing Model - C5

885 views

Published on

  • Be the first to comment

  • Be the first to like this

Tutorial on Parallel Computing and Message Passing Model - C5

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

×