Skip to content

Commit ef53524

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

File tree

5 files changed

+412
-0
lines changed

5 files changed

+412
-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: 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_all(INT count, REQUEST_INOUT requests:count, INT_OUT flag,
41+
STATUS_OUT statuses:count)
42+
{
43+
#if OPAL_ENABLE_PROGRESS_THREADS == 0
44+
int do_it_once = 0;
45+
#endif
46+
47+
MEMCHECKER(
48+
int j;
49+
for (j = 0; j< count; j++) {
50+
memchecker_request(&requests[j]);
51+
}
52+
);
53+
54+
if( MPI_PARAM_CHECK ) {
55+
int rc = MPI_SUCCESS;
56+
57+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
58+
if (NULL == requests) {
59+
rc = MPI_ERR_REQUEST;
60+
} else {
61+
if(!ompi_request_check_same_instance(requests, count) ) {
62+
rc = MPI_ERR_REQUEST;
63+
}
64+
}
65+
if ((NULL == flag) || (count < 0)) {
66+
rc = MPI_ERR_ARG;
67+
}
68+
OMPI_ERRHANDLER_NOHANDLE_CHECK(rc, rc, FUNC_NAME);
69+
}
70+
71+
if (OPAL_UNLIKELY(0 == count)) {
72+
*flag = true;
73+
return MPI_SUCCESS;
74+
}
75+
76+
#if OPAL_ENABLE_PROGRESS_THREADS == 0
77+
recheck_request_status:
78+
#endif
79+
bool all_done = true;
80+
bool one_done;
81+
82+
opal_atomic_mb();
83+
int i;
84+
for (i = 0; i < count; i++) {
85+
one_done = false;
86+
if( (requests[i] == MPI_REQUEST_NULL) || (requests[i]->req_state == OMPI_REQUEST_INACTIVE) ||
87+
(requests[i]->req_complete) ) {
88+
continue;
89+
}
90+
if (!one_done) {
91+
all_done = false;
92+
break;
93+
}
94+
}
95+
96+
if (!all_done) {
97+
#if OPAL_ENABLE_PROGRESS_THREADS == 0
98+
if( 0 == do_it_once ) {
99+
/* If we run the opal_progress then check the status of the
100+
request before leaving. We will call the opal_progress only
101+
once per call. */
102+
opal_progress();
103+
do_it_once++;
104+
goto recheck_request_status;
105+
}
106+
#endif
107+
*flag = false;
108+
return MPI_SUCCESS;
109+
}
110+
111+
for (i = 0; i < count; i++) {
112+
if( (requests[i] == MPI_REQUEST_NULL) || (requests[i]->req_state == OMPI_REQUEST_INACTIVE) ) {
113+
if (MPI_STATUS_IGNORE != statuses) {
114+
OMPI_COPY_STATUS(&statuses[i], ompi_status_empty, false);
115+
}
116+
}
117+
if (requests[i]->req_complete ) {
118+
/* If this is a generalized request, we *always* have to call
119+
the query function to get the status (MPI-2:8.2), even if
120+
the user passed STATUS_IGNORE. */
121+
if (OMPI_REQUEST_GEN == requests[i]->req_type) {
122+
ompi_grequest_invoke_query(requests[i], &requests[i]->req_status);
123+
}
124+
if (MPI_STATUS_IGNORE != statuses) {
125+
OMPI_COPY_STATUS(&statuses[i], requests[i]->req_status, false);
126+
}
127+
}
128+
}
129+
130+
*flag = true;
131+
return MPI_SUCCESS;
132+
}
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+
#if OPAL_ENABLE_PROGRESS_THREADS == 0
44+
int do_it_once = 0;
45+
#endif
46+
47+
MEMCHECKER(
48+
int j;
49+
for (j = 0; j< count; j++) {
50+
memchecker_request(&requests[j]);
51+
}
52+
);
53+
54+
if( MPI_PARAM_CHECK ) {
55+
int rc = MPI_SUCCESS;
56+
57+
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
58+
if (NULL == requests) {
59+
rc = MPI_ERR_REQUEST;
60+
} else {
61+
if(!ompi_request_check_same_instance(requests, count) ) {
62+
rc = MPI_ERR_REQUEST;
63+
}
64+
}
65+
if ((NULL == flag) || (count < 0) || (NULL == indx) ) {
66+
rc = MPI_ERR_ARG;
67+
}
68+
OMPI_ERRHANDLER_NOHANDLE_CHECK(rc, rc, FUNC_NAME);
69+
}
70+
71+
if (OPAL_UNLIKELY(0 == count)) {
72+
*flag = true;
73+
*indx = MPI_UNDEFINED;
74+
if (MPI_STATUS_IGNORE != status) {
75+
OMPI_COPY_STATUS(status, ompi_status_empty, false);
76+
}
77+
return MPI_SUCCESS;
78+
}
79+
80+
#if OPAL_ENABLE_PROGRESS_THREADS == 0
81+
recheck_request_status:
82+
#endif
83+
bool all_inactive = true;
84+
85+
opal_atomic_mb();
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)