module gryffin_layouts ! ! (c) Copyright 1991 to 1998 by Michael A. Beer, William D. Dorland, ! P. B. Snyder, Q. P. Liu, and Gregory W. Hammett. ALL RIGHTS RESERVED. ! implicit none private public :: init_gryffin_layouts public :: proc_id, idx_local public :: m_layout_type public :: m_lo public :: m_low, m_high, n_low, n_high, m_alloc, n_alloc type :: m_layout_type integer :: iproc, m_block, n_block, Nx, Ny integer :: md, ml_proc, mu_proc, mu_alloc, ml_world, mu_world integer :: nd, nl_proc, nu_proc, nu_alloc, nl_world, nu_world end type m_layout_type type (m_layout_type) :: m_lo integer :: m_low, m_high, n_low, n_high, m_alloc, n_alloc contains subroutine init_gryffin_layouts (md, nd) use mp, only: iproc, nproc integer, intent (in) :: md, nd integer :: Nx, Ny, n m_lo%iproc = iproc m_lo%md = md m_lo%nd = nd m_lo%ml_world = 1 m_lo%mu_world = md m_lo%nl_world = 1 m_lo%nu_world = nd Nx = max(nproc / md, 1) m_lo%Nx = Nx m_lo%n_block = (nd-1)/Nx + 1 m_lo%nl_proc = m_lo%n_block*mod(iproc, Nx) + 1 m_lo%nu_proc = min(m_lo%nu_world, m_lo%nl_proc + m_lo%n_block - 1) m_lo%nu_alloc = max(m_lo%nl_proc, m_lo%nu_proc) Ny = nproc / Nx m_lo%Ny = Ny m_lo%m_block = (md-1)/Ny + 1 m_lo%ml_proc = iproc/Nx*m_lo%m_block + 1 m_lo%mu_proc = min(m_lo%mu_world, m_lo%ml_proc + m_lo%m_block - 1) m_lo%mu_alloc = max(m_lo%ml_proc, m_lo%mu_proc) ! shorthand names that are easier to remember m_low = m_lo%ml_proc m_high = m_lo%mu_proc m_alloc= m_lo%mu_alloc n_low = m_lo%nl_proc n_high = m_lo%nu_proc n_alloc= m_lo%nu_alloc end subroutine init_gryffin_layouts pure function proc_id (mlo, m, n) implicit none integer :: proc_id type (m_layout_type), intent (in) :: mlo integer, intent (in) :: m, n proc_id = (n-1)/mlo%n_block + (m-1)/mlo%m_block * m_lo%Nx if (n == 0 .or. m == 0) proc_id = -1 end function proc_id pure function idx_local (mlo, m, n) implicit none logical :: idx_local type (m_layout_type), intent (in) :: mlo integer, intent (in) :: m, n idx_local = mlo%iproc == proc_id(mlo, m, n) end function idx_local end module gryffin_layouts