exchange_boundaries Subroutine

public subroutine exchange_boundaries(board, local_nrows, local_ncols, domainDecomp)

Subroutine to exchange boundaries between neighboring ranks

Arguments

Type IntentOptional Attributes Name
integer, intent(inout), dimension(:,:) :: board

The board to be exchanged

integer, intent(in) :: local_nrows

The number of rows in the local board

integer, intent(in) :: local_ncols

The number of columns in the local board

type(DomainDecomposition), intent(in) :: domainDecomp

The domain decomposition object


Calls

proc~~exchange_boundaries~~CallsGraph proc~exchange_boundaries exchange_boundaries mpi_isend mpi_isend proc~exchange_boundaries->mpi_isend mpi_recv mpi_recv proc~exchange_boundaries->mpi_recv

Called by

proc~~exchange_boundaries~~CalledByGraph proc~exchange_boundaries exchange_boundaries proc~find_steady_state find_steady_state proc~find_steady_state->proc~exchange_boundaries program~main main program~main->proc~find_steady_state

Source Code

    subroutine exchange_boundaries(board, local_nrows, local_ncols, domainDecomp)
        !> The board to be exchanged
        integer, dimension(:,:), intent(inout) :: board
        !> The number of rows in the local board
        integer, intent(in) :: local_nrows
        !> The number of columns in the local board
        integer, intent(in) :: local_ncols
        !> The domain decomposition object
        type(DomainDecomposition), intent(in) :: domainDecomp

        integer :: ierr, rank, mpi_req

        ! Vertical exchange
        if (domainDecomp%neighbours(UP) >= 0) then
            ! Send top halo up
            call MPI_ISEND(board(local_nrows+1,:), local_ncols+2, MPI_INTEGER, domainDecomp%neighbours(UP), 0, &
                domainDecomp%communicator, mpi_req, ierr)

            ! Receive top halo from the above rank
            CALL MPI_RECV(board(local_nrows+2,:), local_ncols+2, MPI_INTEGER, domainDecomp%neighbours(UP), 1, &
                domainDecomp%communicator, MPI_STATUS_IGNORE, ierr)
        endif
        if (domainDecomp%neighbours(DOWN) >= 0) then
            ! Send the bottom halo down
            call MPI_ISEND(board(2,:), local_ncols+2, MPI_INTEGER, domainDecomp%neighbours(DOWN), 1, &
                domainDecomp%communicator, mpi_req, ierr)

            ! Receive the bottom halo from the below rank
            CALL MPI_RECV(board(1,:), local_ncols+2, MPI_INTEGER, domainDecomp%neighbours(DOWN), 0, &
                domainDecomp%communicator, MPI_STATUS_IGNORE, ierr)
        endif

        ! Horizontal exchange
        if (domainDecomp%neighbours(LEFT) >= 0) then
            ! Send the left halo left
            call MPI_ISEND(board(:,2), local_nrows+2, MPI_INTEGER, domainDecomp%neighbours(LEFT), 2, &
                domainDecomp%communicator, mpi_req, ierr)

            ! Receive the left halo from the left
            CALL MPI_RECV(board(:,1), local_nrows+2, MPI_INTEGER, domainDecomp%neighbours(LEFT), 3, &
                domainDecomp%communicator, MPI_STATUS_IGNORE, ierr)
        endif
        if (domainDecomp%neighbours(RIGHT) >= 0) then
            ! Send the right halo right
            call MPI_ISEND(board(:,local_ncols+1), local_nrows+2, MPI_INTEGER, domainDecomp%neighbours(RIGHT), 3, &
                domainDecomp%communicator, mpi_req, ierr)

            ! Receive the right halo from the right
            CALL MPI_RECV(board(:,local_ncols+2), local_nrows+2, MPI_INTEGER, domainDecomp%neighbours(RIGHT), 2, &
                domainDecomp%communicator, MPI_STATUS_IGNORE, ierr)
        endif
    end subroutine exchange_boundaries