comm_irecv_real_sp_array Subroutine

private subroutine comm_irecv_real_sp_array(comm, data, source, tag, request)

Initiates a non-blocking receive operation. The request must be waited on using wait() or test() before the buffer can be used.

data is allocated here when it arrives unallocated, to the size the incoming message actually carries. Passing an unallocated buffer is therefore how a caller that cannot know the size asks for one, and matches what the blocking recv and the 2-D irecv already do.

Arguments

Type IntentOptional Attributes Name
type(comm_t), intent(in) :: comm
real(kind=sp), intent(inout), allocatable :: data(:)
integer(kind=int32), intent(in) :: source
integer(kind=int32), intent(in) :: tag
type(request_t), intent(out) :: request

Calls

proc~~comm_irecv_real_sp_array~~CallsGraph proc~comm_irecv_real_sp_array comm_irecv_real_sp_array mpi_get_count mpi_get_count proc~comm_irecv_real_sp_array->mpi_get_count mpi_irecv mpi_irecv proc~comm_irecv_real_sp_array->mpi_irecv mpi_probe mpi_probe proc~comm_irecv_real_sp_array->mpi_probe

Called by

proc~~comm_irecv_real_sp_array~~CalledByGraph proc~comm_irecv_real_sp_array comm_irecv_real_sp_array interface~irecv irecv interface~irecv->proc~comm_irecv_real_sp_array

Variables

Type Visibility Attributes Name Initial
integer(kind=int32), private :: count
integer(kind=int32), private :: ierr
integer(kind=int32), private :: msg_source
integer(kind=int32), private :: msg_tag
type(MPI_Status), private :: probe_status

Source Code

   subroutine comm_irecv_real_sp_array(comm, data, source, tag, request)
      !! Initiates a non-blocking receive operation. The request must be
      !! waited on using wait() or test() before the buffer can be used.
      !!
      !! `data` is allocated here when it arrives unallocated, to the size
      !! the incoming message actually carries. Passing an unallocated
      !! buffer is therefore how a caller that cannot know the size asks
      !! for one, and matches what the blocking `recv` and the 2-D
      !! `irecv` already do.
      type(comm_t), intent(in) :: comm
      real(sp), allocatable, intent(inout) :: data(:)
      integer(int32), intent(in) :: source
      integer(int32), intent(in) :: tag
      type(request_t), intent(out) :: request
      integer(int32) :: ierr
      integer(int32) :: count
      integer(int32) :: msg_source, msg_tag
      type(MPI_Status) :: probe_status

      msg_source = source
      msg_tag = tag

      ! Sizing an unallocated buffer needs the message to have been matched,
      ! so probe first. That blocks until the envelope arrives, not until the
      ! data does, and the receive below is still the non-blocking one. The
      ! probed source and tag are what the receive then asks for, so that a
      ! wildcard cannot match a second, differently sized message between the
      ! two calls; for a fixed pair MPI's non-overtaking rule already gives
      ! the receive the message that was probed.
      if (.not. allocated(data)) then
         call MPI_Probe(source, tag, comm%m_comm, probe_status, ierr)
         call MPI_Get_count(probe_status, MPI_REAL, count, ierr)
         msg_source = probe_status%MPI_SOURCE
         msg_tag = probe_status%MPI_TAG
         allocate (data(count))
      end if

      call MPI_Irecv(data, size(data), MPI_REAL, msg_source, msg_tag, comm%m_comm, &
                     request%m_request, ierr)
      request%is_valid = .true.
   end subroutine comm_irecv_real_sp_array