Skip to content

add support for request_get_status_any/all/some #13279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ompi/include/mpi.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,15 @@ OMPI_DECLSPEC MPI_Request MPI_Request_f2c(MPI_Fint request);
OMPI_DECLSPEC int MPI_Request_free(MPI_Request *request);
OMPI_DECLSPEC int MPI_Request_get_status(MPI_Request request, int *flag,
MPI_Status *status);
/* should be 'const MPI_Request array_of_requests[]' */
OMPI_DECLSPEC int MPI_Request_get_status_all(int count, MPI_Request array_of_requests[], int *flag,
MPI_Status array_of_statuses[]);
/* should be 'const MPI_Request array_of_requests[]' */
OMPI_DECLSPEC int MPI_Request_get_status_any(int count, MPI_Request array_of_requests[], int *index,
int *flag, MPI_Status *status);
/* should be 'const MPI_Request array_of_requests[]' */
OMPI_DECLSPEC int MPI_Request_get_status_some(int incount, MPI_Request array_of_requests[], int *outcount,
int array_of_indices[], MPI_Status array_of_statuses[]);
OMPI_DECLSPEC int MPI_Rget(void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype,
MPI_Win win, MPI_Request *request);
Expand Down Expand Up @@ -3385,6 +3394,15 @@ OMPI_DECLSPEC MPI_Request PMPI_Request_f2c(MPI_Fint request);
OMPI_DECLSPEC int PMPI_Request_free(MPI_Request *request);
OMPI_DECLSPEC int PMPI_Request_get_status(MPI_Request request, int *flag,
MPI_Status *status);
/* should be 'const MPI_Request array_of_requests[]' */
OMPI_DECLSPEC int PMPI_Request_get_status_all(int count, MPI_Request array_of_requests[], int *flag,
MPI_Status array_of_statuses[]);
/* should be 'const MPI_Request array_of_requests[]' */
OMPI_DECLSPEC int PMPI_Request_get_status_any(int count, MPI_Request array_of_requests[], int *index,
int *flag, MPI_Status *status);
/* should be 'const MPI_Request array_of_requests[]' */
OMPI_DECLSPEC int PMPI_Request_get_status_some(int incount, MPI_Request array_of_requests[], int *outcount,
int array_of_indices[], MPI_Status array_of_statuses[]);
OMPI_DECLSPEC int PMPI_Rget(void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype,
MPI_Win win, MPI_Request *request);
Expand Down
3 changes: 3 additions & 0 deletions ompi/mpi/c/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ prototype_sources = \
request_f2c.c.in \
request_free.c.in \
request_get_status.c.in \
request_get_status_all.c.in \
request_get_status_any.c.in \
request_get_status_some.c.in \
rget_accumulate.c.in \
rget.c.in \
rput.c.in \
Expand Down
131 changes: 131 additions & 0 deletions ompi/mpi/c/request_get_status_all.c.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2021 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006-2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2024 Triad National Security, LLC. All rights
* reserved.
* Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include <stdio.h>

#include "ompi/mpi/c/bindings.h"
#include "ompi/runtime/params.h"
#include "ompi/communicator/communicator.h"
#include "ompi/errhandler/errhandler.h"
#include "ompi/request/request.h"
#include "ompi/request/grequest.h"
#include "ompi/memchecker.h"

/* Non blocking test for the request status. Upon completion, the request will
* not be freed (unlike the test function). A subsequent call to test, wait
* or free should be executed on the request.
*/
PROTOTYPE ERROR_CLASS request_get_status_all(INT count, REQUEST_INOUT requests:count, INT_OUT flag,
STATUS_OUT statuses:count)
{
MEMCHECKER(
int j;
for (j = 0; j< count; j++) {
memchecker_request(&requests[j]);
}
);

if( MPI_PARAM_CHECK ) {
int rc = MPI_SUCCESS;

OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
if (NULL == requests) {
rc = MPI_ERR_REQUEST;
} else {
if(!ompi_request_check_same_instance(requests, count) ) {
rc = MPI_ERR_REQUEST;
}
}
if ((NULL == flag) || (count < 0)) {
rc = MPI_ERR_ARG;
}
OMPI_ERRHANDLER_NOHANDLE_CHECK(rc, rc, FUNC_NAME);
}

if (OPAL_UNLIKELY(0 == count)) {
*flag = true;
return MPI_SUCCESS;
}

bool all_done;
bool one_done;

#if OPAL_ENABLE_PROGRESS_THREADS == 0
int do_it_once = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to make this an int instead of bool?

recheck_request_status:
#endif

opal_atomic_mb();
int i;
all_done = true;
for (i = 0; i < count; i++) {
one_done = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is one_done ever set to true? I think the "if" conditional below is incorrect.

if( (requests[i] == MPI_REQUEST_NULL) || (requests[i]->req_state == OMPI_REQUEST_INACTIVE) ||
(requests[i]->req_complete) ) {
continue;
}
if (!one_done) {
all_done = false;
break;
}
}

if (!all_done) {
#if OPAL_ENABLE_PROGRESS_THREADS == 0
if( 0 == do_it_once ) {
/* If we run the opal_progress then check the status of the
request before leaving. We will call the opal_progress only
once per call. */
opal_progress();
do_it_once++;
goto recheck_request_status;
}
#endif
*flag = false;
return MPI_SUCCESS;
}

for (i = 0; i < count; i++) {
if( (requests[i] == MPI_REQUEST_NULL) || (requests[i]->req_state == OMPI_REQUEST_INACTIVE) ) {
if (MPI_STATUS_IGNORE != statuses) {
OMPI_COPY_STATUS(&statuses[i], ompi_status_empty, false);
}
}
if (requests[i]->req_complete ) {
/* If this is a generalized request, we *always* have to call
the query function to get the status (MPI-2:8.2), even if
the user passed STATUS_IGNORE. */
if (OMPI_REQUEST_GEN == requests[i]->req_type) {
ompi_grequest_invoke_query(requests[i], &requests[i]->req_status);
}
if (MPI_STATUS_IGNORE != statuses) {
OMPI_COPY_STATUS(&statuses[i], requests[i]->req_status, false);
}
}
}

*flag = true;
return MPI_SUCCESS;
}
132 changes: 132 additions & 0 deletions ompi/mpi/c/request_get_status_any.c.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2021 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006-2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2024 Triad National Security, LLC. All rights
* reserved.
* Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include <stdio.h>

#include "ompi/mpi/c/bindings.h"
#include "ompi/runtime/params.h"
#include "ompi/communicator/communicator.h"
#include "ompi/errhandler/errhandler.h"
#include "ompi/request/request.h"
#include "ompi/request/grequest.h"
#include "ompi/memchecker.h"

/* Non blocking test for the request status. Upon completion, the request will
* not be freed (unlike the test function). A subsequent call to test, wait
* or free should be executed on the request.
*/
PROTOTYPE ERROR_CLASS request_get_status_any(INT count, REQUEST_INOUT requests:count, INT_OUT indx,
INT_OUT flag, STATUS_OUT status)
{

MEMCHECKER(
int j;
for (j = 0; j< count; j++) {
memchecker_request(&requests[j]);
}
);

if( MPI_PARAM_CHECK ) {
int rc = MPI_SUCCESS;

OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
if (NULL == requests) {
rc = MPI_ERR_REQUEST;
} else {
if(!ompi_request_check_same_instance(requests, count) ) {
rc = MPI_ERR_REQUEST;
}
}
if ((NULL == flag) || (count < 0) || (NULL == indx) ) {
rc = MPI_ERR_ARG;
}
OMPI_ERRHANDLER_NOHANDLE_CHECK(rc, rc, FUNC_NAME);
}

if (OPAL_UNLIKELY(0 == count)) {
*flag = true;
*indx = MPI_UNDEFINED;
if (MPI_STATUS_IGNORE != status) {
OMPI_COPY_STATUS(status, ompi_status_empty, false);
}
return MPI_SUCCESS;
}

bool all_inactive;

#if OPAL_ENABLE_PROGRESS_THREADS == 0
int do_it_once = 0;
recheck_request_status:
#endif

opal_atomic_mb();
all_inactive = true;
int i;
for (i = 0; i < count; i++) {
if ( (requests[i] == MPI_REQUEST_NULL) || (requests[i]->req_state == OMPI_REQUEST_INACTIVE) ) {
continue;
}
if (requests[i]->req_complete ) {
*flag = true;
*indx = i;
/* If this is a generalized request, we *always* have to call
the query function to get the status (MPI-2:8.2), even if
the user passed STATUS_IGNORE. */
if (OMPI_REQUEST_GEN == requests[i]->req_type) {
ompi_grequest_invoke_query(requests[i], &requests[i]->req_status);
}
if (MPI_STATUS_IGNORE != status) {
OMPI_COPY_STATUS(status, requests[i]->req_status, false);
}
return MPI_SUCCESS;
} else {
/* regular request but not complete */
all_inactive = false;
}
}

if (all_inactive) {
*flag = true;
*indx = MPI_UNDEFINED;
if (MPI_STATUS_IGNORE != status) {
OMPI_COPY_STATUS(status, ompi_status_empty, false);
}
return MPI_SUCCESS;
}

#if OPAL_ENABLE_PROGRESS_THREADS == 0
if( 0 == do_it_once ) {
/* If we run the opal_progress then check the status of the
request before leaving. We will call the opal_progress only
once per call. */
opal_progress();
do_it_once++;
goto recheck_request_status;
}
#endif
*flag = false;
*indx = MPI_UNDEFINED;
return MPI_SUCCESS;
}
Loading