This page imported from: /afs/bu.edu/cwis/webuser/web/s/c/scv/documentation/tutorials/MPI/alliance/communicators/codes/comm_split_example.html

Example on Usages of MPI_Comm_split

Example on Usages of MPI_Comm_split

The objectives of this example is to demonstrate the usage of MPI_Comm_split.




Output


 Example of MPI_Comm_split Usage
 Split 3x2 grid into 2 different communicators
 which correspond to 3 rows and 2 columns.

     Iam    irow    jcol   group    rank
       0       0       0       0       0
       2       1       0       0       1
       3       1       1       1       1
       5       2       1       1       2
       1       0       1       1       0
       4       2       0       0       2

 Next, create more general communicator
 which consists of two groups :
 Rows 1 and 2 belongs to group 1 and row 3 is group 2

             new
     Iam    rank
       0       0
       3       3
       2       2
       1       1
       5       1
       4       0

 If two processes have same key, the ranks
 of these two processes in the new
 communicator will be ordered according
 to their order in the old communicator
  key = map(Iam); map = (2,1,2,1,0,1)

             new
     Iam    rank
       1       0
       0       2
       4       0
       5       1
       3       1
       2       3

Graphically, the last two examples yield he following:

(0)
(0)
(1)
(1)
(2)
(2)
(3)
(3)
(4)
(0)
(5)
(1)
(0)
(2)
(1)
(0)
(2)
(3)
(3)
(1)
(4)
(0)
(5)
(1)

where the numbers in black denote MPI_COMM_WORLD rank number
while the numbers in green represent the rank number of the
two respective new groups.