1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5 
6 #include "mpiimpl.h"
7 
8 /* -- Begin Profiling Symbol Block for routine MPI_Imrecv */
9 #if defined(HAVE_PRAGMA_WEAK)
10 #pragma weak MPI_Imrecv = PMPI_Imrecv
11 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
12 #pragma _HP_SECONDARY_DEF PMPI_Imrecv  MPI_Imrecv
13 #elif defined(HAVE_PRAGMA_CRI_DUP)
14 #pragma _CRI duplicate MPI_Imrecv as PMPI_Imrecv
15 #elif defined(HAVE_WEAK_ATTRIBUTE)
16 int MPI_Imrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message * message,
17                MPI_Request * request) __attribute__ ((weak, alias("PMPI_Imrecv")));
18 #endif
19 /* -- End Profiling Symbol Block */
20 
21 /* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
22    the MPI routines */
23 #ifndef MPICH_MPI_FROM_PMPI
24 #undef MPI_Imrecv
25 #define MPI_Imrecv PMPI_Imrecv
26 
27 /* any non-MPI functions go here, especially non-static ones */
28 
29 #endif /* MPICH_MPI_FROM_PMPI */
30 
31 /*@
32 MPI_Imrecv - Nonblocking receive of message matched by MPI_Mprobe or MPI_Improbe.
33 
34 Input/Output Parameters:
35 . message - message (handle)
36 
37 Input Parameters:
38 + count - number of elements in the receive buffer (non-negative integer)
39 - datatype - datatype of each receive buffer element (handle)
40 
41 Output Parameters:
42 + buf - initial address of the receive buffer (choice)
43 - request - communication request (handle)
44 
45 .N ThreadSafe
46 
47 .N Fortran
48 
49 .N Errors
50 @*/
MPI_Imrecv(void * buf,int count,MPI_Datatype datatype,MPI_Message * message,MPI_Request * request)51 int MPI_Imrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message * message,
52                MPI_Request * request)
53 {
54     int mpi_errno = MPI_SUCCESS;
55     MPIR_Request *rreq = NULL;
56     MPIR_Request *msgp = NULL;
57     MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_IMRECV);
58 
59     MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
60     MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_IMRECV);
61 
62     /* Validate parameters, especially handles needing to be converted */
63 #ifdef HAVE_ERROR_CHECKING
64     {
65         MPID_BEGIN_ERROR_CHECKS;
66         {
67             MPIR_ERRTEST_DATATYPE(datatype, "datatype", mpi_errno);
68 
69             /* TODO more checks may be appropriate */
70         }
71         MPID_END_ERROR_CHECKS;
72     }
73 #endif /* HAVE_ERROR_CHECKING */
74 
75     /* Convert MPI object handles to object pointers */
76     MPIR_Request_get_ptr(*message, msgp);
77 
78     /* Validate parameters and objects (post conversion) */
79 #ifdef HAVE_ERROR_CHECKING
80     {
81         MPID_BEGIN_ERROR_CHECKS;
82         {
83             if (!HANDLE_IS_BUILTIN(datatype)) {
84                 MPIR_Datatype *datatype_ptr = NULL;
85                 MPIR_Datatype_get_ptr(datatype, datatype_ptr);
86                 MPIR_Datatype_valid_ptr(datatype_ptr, mpi_errno);
87                 if (mpi_errno != MPI_SUCCESS)
88                     goto fn_fail;
89                 MPIR_Datatype_committed_ptr(datatype_ptr, mpi_errno);
90                 if (mpi_errno != MPI_SUCCESS)
91                     goto fn_fail;
92             }
93 
94             /* MPI_MESSAGE_NO_PROC should yield a "proc null" status */
95             if (*message != MPI_MESSAGE_NO_PROC) {
96                 MPIR_Request_valid_ptr(msgp, mpi_errno);
97                 MPIR_ERR_CHECK(mpi_errno);
98                 MPIR_ERR_CHKANDJUMP((msgp->kind != MPIR_REQUEST_KIND__MPROBE),
99                                     mpi_errno, MPI_ERR_ARG, "**reqnotmsg");
100             }
101 
102             MPIR_ERRTEST_ARGNULL(request, "request", mpi_errno);
103             /* TODO more checks may be appropriate (counts, in_place, buffer aliasing, etc) */
104         }
105         MPID_END_ERROR_CHECKS;
106     }
107 #endif /* HAVE_ERROR_CHECKING */
108 
109     /* ... body of routine ...  */
110 
111     mpi_errno = MPID_Imrecv(buf, count, datatype, msgp, &rreq);
112     MPIR_ERR_CHECK(mpi_errno);
113 
114     MPIR_Assert(rreq != NULL);
115     *request = rreq->handle;
116     *message = MPI_MESSAGE_NULL;
117 
118     /* ... end of body of routine ... */
119 
120   fn_exit:
121     MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPI_IMRECV);
122     MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
123     return mpi_errno;
124 
125   fn_fail:
126     /* --BEGIN ERROR HANDLING-- */
127 #ifdef HAVE_ERROR_CHECKING
128     {
129         mpi_errno =
130             MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, __func__, __LINE__, MPI_ERR_OTHER,
131                                  "**mpi_imrecv", "**mpi_imrecv %p %d %D %p %p", buf, count,
132                                  datatype, message, request);
133     }
134 #endif
135     mpi_errno = MPIR_Err_return_comm(NULL, __func__, mpi_errno);
136     goto fn_exit;
137     /* --END ERROR HANDLING-- */
138 }
139