subroutine comm_recv_real_dp_array_2d(comm, data, source, tag, status)
!! Blocking receive of a 2D allocatable double precision real array
type(comm_t), intent(in) :: comm
real(dp), intent(inout), allocatable :: data(:, :)
integer(int32), intent(in) :: source
integer(int32), intent(in) :: tag
type(MPI_Status), intent(out) :: status
integer(int32) :: ierr, count, dim1, dim2
! Receive dimensions first
call MPI_Recv(dim1, 1, MPI_INTEGER, source, tag, comm%m_comm, MPI_STATUS_IGNORE, ierr)
call MPI_Recv(dim2, 1, MPI_INTEGER, source, tag, comm%m_comm, MPI_STATUS_IGNORE, ierr)
! Allocate array with received dimensions
if (.not. allocated(data)) then
allocate (data(dim1, dim2))
end if
! Receive data
count = dim1*dim2
call MPI_Recv(data, count, MPI_DOUBLE_PRECISION, source, tag, comm%m_comm, status, ierr)
end subroutine comm_recv_real_dp_array_2d