decomp_auto_factor Subroutine

public pure subroutine decomp_auto_factor(nprocs, nx, ny, px, py)

Choose px, py to minimise halo communication cost

Tries all factorisations nprocs = px * py and picks the one that minimises the total halo perimeter: pxny + pynx. This produces roughly square subdomains matched to the grid aspect ratio.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: nprocs

Total number of MPI ranks

integer, intent(in) :: nx

Global physical cells in x

integer, intent(in) :: ny

Global physical cells in y

integer, intent(out) :: px

Chosen process grid size in x

integer, intent(out) :: py

Chosen process grid size in y


Called by

proc~~decomp_auto_factor~~CalledByGraph proc~decomp_auto_factor decomp_auto_factor proc~decomp_init_from_config decomp_init_from_config proc~decomp_init_from_config->proc~decomp_auto_factor proc~engine_setup engine_setup proc~engine_setup->proc~decomp_auto_factor proc~engine_setup->proc~decomp_init_from_config proc~complete_ocean_create complete_ocean_create proc~complete_ocean_create->proc~engine_setup proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_setup proc~driver_validate driver_validate proc~driver_validate->proc~engine_setup proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean proc~rdb_ocean_create_finalize rdb_ocean_create_finalize proc~rdb_ocean_create_finalize->proc~complete_ocean_create proc~rdb_ocean_create_from_string rdb_ocean_create_from_string proc~rdb_ocean_create_from_string->proc~complete_ocean_create

Variables

Type Visibility Attributes Name Initial
integer, private :: best_cost
integer, private :: best_px
integer, private :: cost
integer, private :: p

Source Code

   pure subroutine decomp_auto_factor(nprocs, nx, ny, px, py)
      !! Choose px, py to minimise halo communication cost
      !!
      !! Tries all factorisations nprocs = px * py and picks the one
      !! that minimises the total halo perimeter: px*ny + py*nx.
      !! This produces roughly square subdomains matched to the grid
      !! aspect ratio.
      integer, intent(in) :: nprocs
         !! Total number of MPI ranks
      integer, intent(in) :: nx
         !! Global physical cells in x
      integer, intent(in) :: ny
         !! Global physical cells in y
      integer, intent(out) :: px
         !! Chosen process grid size in x
      integer, intent(out) :: py
         !! Chosen process grid size in y

      integer :: p, best_px
      integer :: cost, best_cost

      best_px = nprocs
      best_cost = huge(0)

      do p = 1, nprocs
         if (mod(nprocs, p) /= 0) cycle
         cost = p*ny + (nprocs/p)*nx
         if (cost < best_cost) then
            best_cost = cost
            best_px = p
         end if
      end do

      px = best_px
      py = nprocs/best_px

   end subroutine decomp_auto_factor