Subroutine to get local grid information for a rank
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(DomainDecomposition), | intent(inout) | :: | domainDecomp |
The MPI communication domain decomposition object |
||
| integer, | intent(in) | :: | rank |
The rank of the current process |
||
| integer, | intent(in) | :: | global_nrows |
The number of columns in the global board |
||
| integer, | intent(in) | :: | global_ncols |
The number of rows in the global board |
||
| integer, | intent(out) | :: | nrows_per_rank |
The number of columns per rank |
||
| integer, | intent(out) | :: | ncols_per_rank |
The number of rows per rank |
||
| integer, | intent(out) | :: | coords(2) |
The coordinates of the current rank in the Cartesian grid |
||
| integer, | intent(out) | :: | row_start |
The starting column index for the local grid |
||
| integer, | intent(out) | :: | col_start |
The starting row index for the local grid |
||
| integer, | intent(out) | :: | local_nrows |
The number of columns in the local grid |
||
| integer, | intent(out) | :: | local_ncols |
The number of rows in the local grid |
subroutine get_local_grid_info(domainDecomp, rank, global_nrows, global_ncols, nrows_per_rank, ncols_per_rank, coords, & row_start, col_start, local_nrows, local_ncols) !> The MPI communication domain decomposition object type(DomainDecomposition), intent(inout) :: domainDecomp !> The rank of the current process integer, intent(in) :: rank !> The number of columns in the global board integer, intent(in) :: global_nrows !> The number of rows in the global board integer, intent(in) :: global_ncols !> The number of columns per rank integer, intent(out) :: nrows_per_rank !> The number of rows per rank integer, intent(out) :: ncols_per_rank !> The coordinates of the current rank in the Cartesian grid integer, intent(out) :: coords(2) !> The starting column index for the local grid integer, intent(out) :: row_start !> The starting row index for the local grid integer, intent(out) :: col_start !> The number of columns in the local grid integer, intent(out) :: local_nrows !> The number of rows in the local grid integer, intent(out) :: local_ncols integer :: mpierr, num_ranks_col, num_ranks_row call MPI_Cart_coords(domainDecomp%communicator, rank, 2, coords, mpierr) call MPI_Cart_shift(domainDecomp%communicator, 0, 1, domainDecomp%neighbours(DOWN), domainDecomp%neighbours(UP), mpierr) call MPI_Cart_shift(domainDecomp%communicator, 1, 1, domainDecomp%neighbours(LEFT), domainDecomp%neighbours(RIGHT), mpierr) nrows_per_rank = global_nrows / domainDecomp%dims(1) ncols_per_rank = global_ncols / domainDecomp%dims(2) row_start = coords(1)*nrows_per_rank + 1 col_start = coords(2)*ncols_per_rank + 1 num_ranks_row = domainDecomp%dims(1) num_ranks_col = domainDecomp%dims(2) ! Add remainders if on the top or right of the grid local_ncols = ncols_per_rank local_nrows = nrows_per_rank if (domainDecomp%neighbours(RIGHT) == MPI_PROC_NULL) local_ncols = local_ncols + modulo(global_ncols, ncols_per_rank) if (domainDecomp%neighbours(UP) == MPI_PROC_NULL) local_nrows = local_nrows + modulo(global_nrows, nrows_per_rank) end subroutine get_local_grid_info