1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3 * (C) 2012 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
5 */
6
7 #include "mpidimpl.h"
8
9 #undef FUNCNAME
10 #define FUNCNAME MPID_Imrecv
11 #undef FCNAME
12 #define FCNAME MPIU_QUOTE(FUNCNAME)
MPID_Mrecv(void * buf,int count,MPI_Datatype datatype,MPID_Request * message,MPI_Status * status)13 int MPID_Mrecv(void *buf, int count, MPI_Datatype datatype,
14 MPID_Request *message, MPI_Status *status)
15 {
16 int mpi_errno = MPI_SUCCESS;
17 MPI_Request req_handle; /* dummy for MPIR_Request_complete */
18 int active_flag; /* dummy for MPIR_Request_complete */
19 MPID_Request *rreq = NULL;
20
21 if (message == NULL) {
22 /* treat as though MPIX_MESSAGE_NO_PROC was passed */
23 MPIR_Status_set_procnull(status);
24 goto fn_exit;
25 }
26
27 /* There is no optimized MPID_Mrecv at this time because there is no real
28 * optimization potential in that case. MPID_Recv exists to prevent
29 * creating a request unnecessarily for messages that are already present
30 * and eligible for immediate completion. */
31 mpi_errno = MPID_Imrecv(buf, count, datatype, message, &rreq);
32 if (mpi_errno) MPIU_ERR_POP(mpi_errno);
33
34 if (!MPID_Request_is_complete(rreq)) {
35 MPID_Progress_state progress_state;
36
37 MPID_Progress_start(&progress_state);
38 while (!MPID_Request_is_complete(rreq))
39 {
40 mpi_errno = MPID_Progress_wait(&progress_state);
41 if (mpi_errno) {
42 /* --BEGIN ERROR HANDLING-- */
43 MPID_Progress_end(&progress_state);
44 MPIU_ERR_POP(mpi_errno);
45 /* --END ERROR HANDLING-- */
46 }
47 }
48 MPID_Progress_end(&progress_state);
49 }
50 mpi_errno = MPIR_Request_complete(&req_handle, rreq, status, &active_flag);
51 if (mpi_errno) MPIU_ERR_POP(mpi_errno);
52
53 fn_exit:
54 return mpi_errno;
55 fn_fail:
56 goto fn_exit;
57 }
58
59