Skip to content

Commit 8e318a5

Browse files
authored
Merge pull request #8578 from markalle/grequest_fortran
grequest callback return values and Fortran status
2 parents 5257cc3 + 64b7ae0 commit 8e318a5

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

ompi/request/grequest.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* All rights reserved.
1212
* Copyright (c) 2006-2012 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
14+
* Copyright (c) 2021 IBM Corporation. All rights reserved.
1415
* $COPYRIGHT$
1516
*
1617
* Additional copyrights may follow
@@ -121,16 +122,24 @@ static void ompi_grequest_construct(ompi_grequest_t* greq)
121122
*/
122123
static void ompi_grequest_destruct(ompi_grequest_t* greq)
123124
{
125+
int rc;
124126
MPI_Fint ierr;
125127

126128
if (greq->greq_free.c_free != NULL) {
127129
if (greq->greq_funcs_are_c) {
128-
greq->greq_free.c_free(greq->greq_state);
130+
rc = greq->greq_free.c_free(greq->greq_state);
129131
} else {
130132
greq->greq_free.f_free((MPI_Aint*)greq->greq_state, &ierr);
133+
rc = OMPI_FINT_2_INT(ierr);
131134
}
132135
}
133136

137+
/* We were already putting query_fn()'s return value into
138+
* status.MPI_ERROR but for MPI_{Wait,Test}* the standard
139+
* says use the free_fn() callback too.
140+
*/
141+
greq->greq_base.req_status.MPI_ERROR = rc;
142+
134143
OMPI_REQUEST_FINI(&greq->greq_base);
135144
}
136145

@@ -214,8 +223,21 @@ int ompi_grequest_invoke_query(ompi_request_t *request,
214223
if (g->greq_funcs_are_c) {
215224
rc = g->greq_query.c_query(g->greq_state, status);
216225
} else {
226+
/* request->req_status.MPI_ERROR was initialized to success
227+
* and it's meant to be unmodified in the case of callback
228+
* success, and set when callbacks return a failure. But
229+
* if we leave fstatus uninitialized this sets
230+
* req_status.MPI_ERROR to whatever happened to be on the
231+
* stack at fstatus (f_query isn't supposed to directly set
232+
* its status.MPI_ERROR, according to the standard)
233+
*
234+
* So the Status_c2f below only really cares about transferring
235+
* the MPI_ERROR setting into fstatus so that when it's transferred
236+
* back in the f2c call, it has the starting value.
237+
*/
217238
MPI_Fint ierr;
218239
MPI_Fint fstatus[sizeof(MPI_Status) / sizeof(int)];
240+
MPI_Status_c2f(status, fstatus);
219241
g->greq_query.f_query((MPI_Aint*)g->greq_state, fstatus, &ierr);
220242
MPI_Status_f2c(fstatus, status);
221243
rc = OMPI_FINT_2_INT(ierr);

0 commit comments

Comments
 (0)