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.
| Type | Intent | Optional | 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 |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private | :: | best_cost | ||||
| integer, | private | :: | best_px | ||||
| integer, | private | :: | cost | ||||
| integer, | private | :: | p |
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