module parallel use mpi implicit none !== rank informations ==! type ranks_ integer :: me integer :: xin, xout, yin, yout, zin, zout end type ranks_ type(ranks_) :: ranks !== 3-D domain decomposition ==! integer, parameter :: ndim = 3 type process_topology_ integer :: comm integer, dimension(ndim) :: dims integer, dimension(ndim) :: coords end type process_topology_ type(process_topology_) :: cart3d integer :: nprocs contains subroutine init_parallel logical, dimension(ndim) :: is_periodic logical :: reorder integer :: ierr call mpi_init (ierr) call mpi_comm_size (MPI_COMM_WORLD, nprocs, ierr) cart3d%dims(:) = 0 call mpi_dims_create (nprocs, ndim, cart3d%dims, ierr) is_periodic(1) = .true. is_periodic(2) = .true. is_periodic(3) = .true. reorder = .true. call mpi_cart_create (MPI_COMM_WORLD, ndim, cart3d%dims, & & is_periodic, reorder, cart3d%comm, ierr) call mpi_comm_rank (cart3d%comm, ranks%me, ierr) call mpi_cart_shift (cart3d%comm, 0, 1, ranks%xin, ranks%xout, ierr) call mpi_cart_shift (cart3d%comm, 1, 1, ranks%yin, ranks%yout, ierr) call mpi_cart_shift (cart3d%comm, 2, 1, ranks%zin, ranks%zout, ierr) call mpi_cart_coords (cart3d%comm, ranks%me, ndim, cart3d%coords, ierr) return end subroutine init_parallel subroutine fin_parallel integer :: ierr call mpi_finalize (ierr) return end subroutine fin_parallel end module parallel