subroutine comm_recv_real_dp_array_2d(comm, data, source, tag, status)
!! Receive 2D real(dp) array (must be pre-allocated by receiver)
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
integer :: stat(MPI_STATUS_SIZE)
! Receive dimensions first
call MPI_Recv(dim1, 1_int32, MPI_INTEGER, source, tag, comm%m_comm, stat, ierr)
call MPI_Recv(dim2, 1_int32, MPI_INTEGER, source, tag, comm%m_comm, stat, 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, stat, ierr)
! Convert status
status = status_array_to_type(stat)
end subroutine comm_recv_real_dp_array_2d