Skip to content

Commit 8d42701

Browse files
committed
mpi: add request_get_status_all/any/some
Signed-off-by: Edgar Gabriel <[email protected]>
1 parent 4453cf3 commit 8d42701

File tree

5 files changed

+411
-0
lines changed

5 files changed

+411
-0
lines changed

ompi/include/mpi.h.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,15 @@ OMPI_DECLSPEC MPI_Request MPI_Request_f2c(MPI_Fint request);
22262226
OMPI_DECLSPEC int MPI_Request_free(MPI_Request *request);
22272227
OMPI_DECLSPEC int MPI_Request_get_status(MPI_Request request, int *flag,
22282228
MPI_Status *status);
2229+
/* should be 'const MPI_Request array_of_requests[]' */
2230+
OMPI_DECLSPEC int MPI_Request_get_status_all(int count, MPI_Request array_of_requests[], int *flag,
2231+
MPI_Status array_of_statuses[]);
2232+
/* should be 'const MPI_Request array_of_requests[]' */
2233+
OMPI_DECLSPEC int MPI_Request_get_status_any(int count, MPI_Request array_of_requests[], int *index,
2234+
int *flag, MPI_Status *status);
2235+
/* should be 'const MPI_Request array_of_requests[]' */
2236+
OMPI_DECLSPEC int MPI_Request_get_status_some(int incount, MPI_Request array_of_requests[], int *outcount,
2237+
int array_of_indices[], MPI_Status array_of_statuses[]);
22292238
OMPI_DECLSPEC int MPI_Rget(void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
22302239
int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype,
22312240
MPI_Win win, MPI_Request *request);
@@ -3385,6 +3394,15 @@ OMPI_DECLSPEC MPI_Request PMPI_Request_f2c(MPI_Fint request);
33853394
OMPI_DECLSPEC int PMPI_Request_free(MPI_Request *request);
33863395
OMPI_DECLSPEC int PMPI_Request_get_status(MPI_Request request, int *flag,
33873396
MPI_Status *status);
3397+
/* should be 'const MPI_Request array_of_requests[]' */
3398+
OMPI_DECLSPEC int PMPI_Request_get_status_all(int count, MPI_Request array_of_requests[], int *flag,
3399+
MPI_Status array_of_statuses[]);
3400+
/* should be 'const MPI_Request array_of_requests[]' */
3401+
OMPI_DECLSPEC int PMPI_Request_get_status_any(int count, MPI_Request array_of_requests[], int *index,
3402+
int *flag, MPI_Status *status);
3403+
/* should be 'const MPI_Request array_of_requests[]' */
3404+
OMPI_DECLSPEC int PMPI_Request_get_status_some(int incount, MPI_Request array_of_requests[], int *outcount,
3405+
int array_of_indices[], MPI_Status array_of_statuses[]);
33883406
OMPI_DECLSPEC int PMPI_Rget(void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
33893407
int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype,
33903408
MPI_Win win, MPI_Request *request);

ompi/mpi/c/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ prototype_sources = \
345345
request_f2c.c.in \
346346
request_free.c.in \
347347
request_get_status.c.in \
348+
request_get_status_all.c.in \
349+
request_get_status_any.c.in \
350+
request_get_status_some.c.in \
348351
rget_accumulate.c.in \
349352
rget.c.in \
350353
rput.c.in \
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
3+
* University Research and Technology
4+
* Corporation. All rights reserved.
5+
* Copyright (c) 2004-2021 The University of Tennessee and The University
6+
* of Tennessee Research Foundation. All rights
7+
* reserved.
8+
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
9+
* University of Stuttgart. All rights reserved.
10+
* Copyright (c) 2004-2005 The Regents of the University of California.
11+
* All rights reserved.
12+
* Copyright (c) 2006-2010 Cisco Systems, Inc. All rights reserved.
13+
* Copyright (c) 2015 Research Organization for Information Science
14+
* and Technology (RIST). All rights reserved.
15+
* Copyright (c) 2024 Triad National Security, LLC. All rights
16+
* reserved.
17+
* Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved
18+
*
19+
* $COPYRIGHT$
20+
*
21+
* Additional copyrights may follow
22+
*
23+
* $HEADER$
24+
*/
25+
#include "ompi_config.h"
26+
#include <stdio.h>
27+
28+
#include "ompi/mpi/c/bindings.h"
29+
#include "ompi/runtime/params.h"
30+
#include "ompi/communicator/communicator.h"
31+
#include "ompi/errhandler/errhandler.h"
32+
#include "ompi/request/request.h"
33+
#include "ompi/request/grequest.h"
34+
#include "ompi/memchecker.h"
35+
36+
/* Non blocking test for the request status. Upon completion, the request will
37+
* not be freed (unlike the test function). A subsequent call to test, wait
38+
* or free should be executed on the request.
39+
*/
40+
PROTOTYPE ERROR_CLASS request_get_status_all(INT count, REQUEST_INOUT requests:count, INT_OUT flag,
41+
STATUS_OUT statuses:count)
42+
{
43+
MEMCHECKER(
44+
int j;
45+
for (j = 0; j< count; j++) {
46+
memchecker_request(&requests[j]);
47+
}
48+
);
49+
50+
if( MPI_PARAM_CHECK ) {
51+
int rc = MPI_SUCCESS;
52+
53+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
54+
if (NULL == requests) {
55+
rc = MPI_ERR_REQUEST;
56+
} else {
57+
if(!ompi_request_check_same_instance(requests, count) ) {
58+
rc = MPI_ERR_REQUEST;
59+
}
60+
}
61+
if ((NULL == flag) || (count < 0)) {
62+
rc = MPI_ERR_ARG;
63+
}
64+
OMPI_ERRHANDLER_NOHANDLE_CHECK(rc, rc, FUNC_NAME);
65+
}
66+
67+
if (OPAL_UNLIKELY(0 == count)) {
68+
*flag = true;
69+
return MPI_SUCCESS;
70+
}
71+
72+
bool all_done;
73+
bool one_done;
74+
75+
#if OPAL_ENABLE_PROGRESS_THREADS == 0
76+
int do_it_once = 0;
77+
recheck_request_status:
78+
#endif
79+
80+
opal_atomic_mb();
81+
int i;
82+
all_done = true;
83+
for (i = 0; i < count; i++) {
84+
one_done = false;
85+
if( (requests[i] == MPI_REQUEST_NULL) || (requests[i]->req_state == OMPI_REQUEST_INACTIVE) ||
86+
(requests[i]->req_complete) ) {
87+
continue;
88+
}
89+
if (!one_done) {
90+
all_done = false;
91+
break;
92+
}
93+
}
94+
95+
if (!all_done) {
96+
#if OPAL_ENABLE_PROGRESS_THREADS == 0
97+
if( 0 == do_it_once ) {
98+
/* If we run the opal_progress then check the status of the
99+
request before leaving. We will call the opal_progress only
100+
once per call. */
101+
opal_progress();
102+
do_it_once++;
103+
goto recheck_request_status;
104+
}
105+
#endif
106+
*flag = false;
107+
return MPI_SUCCESS;
108+
}
109+
110+
for (i = 0; i < count; i++) {
111+
if( (requests[i] == MPI_REQUEST_NULL) || (requests[i]->req_state == OMPI_REQUEST_INACTIVE) ) {
112+
if (MPI_STATUS_IGNORE != statuses) {
113+
OMPI_COPY_STATUS(&statuses[i], ompi_status_empty, false);
114+
}
115+
}
116+
if (requests[i]->req_complete ) {
117+
/* If this is a generalized request, we *always* have to call
118+
the query function to get the status (MPI-2:8.2), even if
119+
the user passed STATUS_IGNORE. */
120+
if (OMPI_REQUEST_GEN == requests[i]->req_type) {
121+
ompi_grequest_invoke_query(requests[i], &requests[i]->req_status);
122+
}
123+
if (MPI_STATUS_IGNORE != statuses) {
124+
OMPI_COPY_STATUS(&statuses[i], requests[i]->req_status, false);
125+
}
126+
}
127+
}
128+
129+
*flag = true;
130+
return MPI_SUCCESS;
131+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
3+
* University Research and Technology
4+
* Corporation. All rights reserved.
5+
* Copyright (c) 2004-2021 The University of Tennessee and The University
6+
* of Tennessee Research Foundation. All rights
7+
* reserved.
8+
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
9+
* University of Stuttgart. All rights reserved.
10+
* Copyright (c) 2004-2005 The Regents of the University of California.
11+
* All rights reserved.
12+
* Copyright (c) 2006-2010 Cisco Systems, Inc. All rights reserved.
13+
* Copyright (c) 2015 Research Organization for Information Science
14+
* and Technology (RIST). All rights reserved.
15+
* Copyright (c) 2024 Triad National Security, LLC. All rights
16+
* reserved.
17+
* Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved
18+
*
19+
* $COPYRIGHT$
20+
*
21+
* Additional copyrights may follow
22+
*
23+
* $HEADER$
24+
*/
25+
#include "ompi_config.h"
26+
#include <stdio.h>
27+
28+
#include "ompi/mpi/c/bindings.h"
29+
#include "ompi/runtime/params.h"
30+
#include "ompi/communicator/communicator.h"
31+
#include "ompi/errhandler/errhandler.h"
32+
#include "ompi/request/request.h"
33+
#include "ompi/request/grequest.h"
34+
#include "ompi/memchecker.h"
35+
36+
/* Non blocking test for the request status. Upon completion, the request will
37+
* not be freed (unlike the test function). A subsequent call to test, wait
38+
* or free should be executed on the request.
39+
*/
40+
PROTOTYPE ERROR_CLASS request_get_status_any(INT count, REQUEST_INOUT requests:count, INT_OUT indx,
41+
INT_OUT flag, STATUS_OUT status)
42+
{
43+
44+
MEMCHECKER(
45+
int j;
46+
for (j = 0; j< count; j++) {
47+
memchecker_request(&requests[j]);
48+
}
49+
);
50+
51+
if( MPI_PARAM_CHECK ) {
52+
int rc = MPI_SUCCESS;
53+
54+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
55+
if (NULL == requests) {
56+
rc = MPI_ERR_REQUEST;
57+
} else {
58+
if(!ompi_request_check_same_instance(requests, count) ) {
59+
rc = MPI_ERR_REQUEST;
60+
}
61+
}
62+
if ((NULL == flag) || (count < 0) || (NULL == indx) ) {
63+
rc = MPI_ERR_ARG;
64+
}
65+
OMPI_ERRHANDLER_NOHANDLE_CHECK(rc, rc, FUNC_NAME);
66+
}
67+
68+
if (OPAL_UNLIKELY(0 == count)) {
69+
*flag = true;
70+
*indx = MPI_UNDEFINED;
71+
if (MPI_STATUS_IGNORE != status) {
72+
OMPI_COPY_STATUS(status, ompi_status_empty, false);
73+
}
74+
return MPI_SUCCESS;
75+
}
76+
77+
bool all_inactive;
78+
79+
#if OPAL_ENABLE_PROGRESS_THREADS == 0
80+
int do_it_once = 0;
81+
recheck_request_status:
82+
#endif
83+
84+
opal_atomic_mb();
85+
all_inactive = true;
86+
int i;
87+
for (i = 0; i < count; i++) {
88+
if ( (requests[i] == MPI_REQUEST_NULL) || (requests[i]->req_state == OMPI_REQUEST_INACTIVE) ) {
89+
continue;
90+
}
91+
if (requests[i]->req_complete ) {
92+
*flag = true;
93+
*indx = i;
94+
/* If this is a generalized request, we *always* have to call
95+
the query function to get the status (MPI-2:8.2), even if
96+
the user passed STATUS_IGNORE. */
97+
if (OMPI_REQUEST_GEN == requests[i]->req_type) {
98+
ompi_grequest_invoke_query(requests[i], &requests[i]->req_status);
99+
}
100+
if (MPI_STATUS_IGNORE != status) {
101+
OMPI_COPY_STATUS(status, requests[i]->req_status, false);
102+
}
103+
return MPI_SUCCESS;
104+
} else {
105+
/* regular request but not complete */
106+
all_inactive = false;
107+
}
108+
}
109+
110+
if (all_inactive) {
111+
*flag = true;
112+
*indx = MPI_UNDEFINED;
113+
if (MPI_STATUS_IGNORE != status) {
114+
OMPI_COPY_STATUS(status, ompi_status_empty, false);
115+
}
116+
return MPI_SUCCESS;
117+
}
118+
119+
#if OPAL_ENABLE_PROGRESS_THREADS == 0
120+
if( 0 == do_it_once ) {
121+
/* If we run the opal_progress then check the status of the
122+
request before leaving. We will call the opal_progress only
123+
once per call. */
124+
opal_progress();
125+
do_it_once++;
126+
goto recheck_request_status;
127+
}
128+
#endif
129+
*flag = false;
130+
*indx = MPI_UNDEFINED;
131+
return MPI_SUCCESS;
132+
}

0 commit comments

Comments
 (0)