c In this subroutine below, the first call to MPI_COMM_SPLIT divides c MPI_COMM_WORLD into three communicators corresponding to the three rows c in the 3x4 grid. c One communicator includes all processes for which color = 1 (row 1), c another includes all processes for which color = 2 (row 2), c and a third includes all processes for which color = 3 (row 3). c Within the new communicators, processes are ranked in order of c increasing key value (in this case, according to c increasing rank in the original communicator MPI_COMM_WORLD). subroutine set_group(row_comm,col_comm) include 'mpif.h' parameter (NROW=3, NCOL=4) integer row_comm, coll_comm, color, key c ------------------------------------------------------------- c Establish the row and column to which this processor belongs c ------------------------------------------------------------- c call MPI_COMM_RANK(MPI_COMM_WORLD,irank,ierr) irow = MOD(irank,NROW) + 1 icol = INT(irank/NROW) + 1 c c ------------------------- c Build row communicators c ------------------------- c color = irow key = irank call MPI_COMM_SPLIT (MPI_COMM_WORLD, color, key, row_comm, ierr) c c --------------------------- c Build column communicators c --------------------------- c color = icol call MPI_COMM_SPLIT (MPI_COMM_WORLD, color, key, col_comm, ierr) return end