subroutine init2decomp use decomp_2d use modglobal, only : itot, jtot, ktot, BCxm, BCym, BCxm_periodic, Bcym_periodic use modmpi, only : comm3d, comm1dx, comm1dy, & myid, myidx, myidy, myid1dx, myid1dy, & cmyidx, cmyidy, nprocx, nprocy, & nbreast, nbrwest, nbrnorth, nbrsouth, & nbrbotx, nbrtopx, nbrboty, nbrtopy, & nproc_total, mpierr implicit none logical, dimension(3) :: periodic_bc integer, dimension(2) :: myids ! Set periodic boundary conditions based on namelists if (BCxm .eq. BCxm_periodic .and. nprocx > 1) then periodic_bc(1) = .true. else periodic_bc(1) = .false. end if if (BCym .eq. BCym_periodic .and. nprocy > 1) then periodic_bc(2) = .true. else periodic_bc(2) = .false. end if periodic_bc(3) = .false. ! Initialize 2decomp library call decomp_2d_init(itot,jtot,ktot,nprocx,nprocy,periodic_bc) ! Get the 2D Cartesian communicator comm3d = DECOMP_2D_COMM_CART_Z ! Get total number of processes call MPI_COMM_SIZE(comm3d, nproc_total, mpierr) ! Get my coordinates in 2D grid call MPI_CART_COORDS(comm3d, myid, 2, myids, mpierr) myidx = myids(1) myidy = myids(2) ! Generate string IDs for file naming write(cmyidx,'(i3.3)') myidx write(cmyidy,'(i3.3)') myidy ! Get neighbors in 2D grid (x and y directions) call MPI_CART_SHIFT(comm3d, 0, 1, nbrwest, nbreast, mpierr) call MPI_CART_SHIFT(comm3d, 1, 1, nbrsouth, nbrnorth, mpierr) ! Create 1D sub-communicators for specialized operations ! comm1dx: communication in x-direction only (y is collapsed) ! comm1dy: communication in y-direction only (x is collapsed) call MPI_CART_SUB(comm3d, (/.true., .false./), comm1dx, mpierr) call MPI_CART_SUB(comm3d, (/.false., .true./), comm1dy, mpierr) ! Get my rank in each 1D communicator call MPI_COMM_RANK(comm1dx, myid1dx, mpierr) call MPI_COMM_RANK(comm1dy, myid1dy, mpierr) ! Get neighbors in 1D directions ! These should be consistent with 2D neighbors: ! nbrbotx = nbrwest, nbrtopx = nbreast ! nbrboty = nbrsouth, nbrtopy = nbrnorth call MPI_CART_SHIFT(comm1dx, 0, 1, nbrbotx, nbrtopx, mpierr) call MPI_CART_SHIFT(comm1dy, 0, 1, nbrboty, nbrtopy, mpierr) end subroutine init2decomp