Skip to content

comm/cid: fix for edge case with intercomm creation #12465

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

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion ompi/communicator/comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,7 @@ int ompi_comm_free( ompi_communicator_t **comm )
* makes sure that the pointer to the dependent communicator
* still contains a valid object.
*/
ompi_communicator_t *tmpcomm = (ompi_communicator_t *) opal_pointer_array_get_item(&ompi_mpi_communicators, cid);
ompi_communicator_t *tmpcomm = ompi_comm_lookup(cid);
if ( NULL != tmpcomm ){
ompi_comm_free(&tmpcomm);
}
Expand Down
7 changes: 3 additions & 4 deletions ompi/communicator/comm_cid.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ static int ompi_comm_allreduce_getnextcid (ompi_comm_request_t *request)
context->nextlocal_cid = mca_pml.pml_max_contextid;
for (unsigned int i = context->start ; i < mca_pml.pml_max_contextid ; ++i) {
flag = opal_pointer_array_test_and_set_item (&ompi_mpi_communicators, i,
context->comm);
OMPI_COMM_SENTINEL);
if (true == flag) {
context->nextlocal_cid = i;
break;
Expand Down Expand Up @@ -664,7 +664,7 @@ static int ompi_comm_checkcid (ompi_comm_request_t *request)
opal_pointer_array_set_item(&ompi_mpi_communicators, context->nextlocal_cid, NULL);

context->flag = opal_pointer_array_test_and_set_item (&ompi_mpi_communicators,
context->nextcid, context->comm);
context->nextcid, OMPI_COMM_SENTINEL);
}
}

Expand Down Expand Up @@ -716,7 +716,7 @@ static int ompi_comm_nextcid_check_flag (ompi_comm_request_t *request)
for (unsigned int i = context->start ; i < mca_pml.pml_max_contextid ; ++i) {
bool flag;
flag = opal_pointer_array_test_and_set_item (&ompi_mpi_communicators, i,
context->comm);
OMPI_COMM_SENTINEL);
if (true == flag) {
context->nextlocal_cid = i;
break;
Expand Down Expand Up @@ -1588,4 +1588,3 @@ static int ompi_comm_ft_allreduce_intra_pmix_nb(int *inbuf, int *outbuf, int cou
}

#endif /* OPAL_ENABLE_FT_MPI */

6 changes: 3 additions & 3 deletions ompi/communicator/comm_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,13 @@ static int ompi_comm_finalize (void)
OBJ_DESTRUCT( &ompi_mpi_comm_null );

/* Check whether we have some communicators left */
max = opal_pointer_array_get_size(&ompi_mpi_communicators);
max = ompi_comm_get_num_communicators();
for ( i=3; i<max; i++ ) {
comm = (ompi_communicator_t *)opal_pointer_array_get_item(&ompi_mpi_communicators, i);
comm = ompi_comm_lookup(i);
if ( NULL != comm ) {
/* Communicator has not been freed before finalize */
OBJ_RELEASE(comm);
comm=(ompi_communicator_t *)opal_pointer_array_get_item(&ompi_mpi_communicators, i);
comm = ompi_comm_lookup(i);
if ( NULL != comm ) {
/* Still here ? */
if ( !OMPI_COMM_IS_EXTRA_RETAIN(comm)) {
Expand Down
26 changes: 25 additions & 1 deletion ompi/communicator/communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ OMPI_DECLSPEC OBJ_CLASS_DECLARATION(ompi_communicator_t);
#define OMPI_COMM_BLOCK_WORLD 16
#define OMPI_COMM_BLOCK_OTHERS 8

/**
* Placeholder to use in array of ompi communicators during CID allocation
*/
#define OMPI_COMM_SENTINEL 0x00000001

/* A macro comparing two CIDs */
#define OMPI_COMM_CID_IS_LOWER(comm1,comm2) ( ((comm1)->c_index < (comm2)->c_index)? 1:0)

Expand Down Expand Up @@ -552,8 +557,27 @@ static inline bool ompi_comm_compare_cids (const ompi_communicator_t *comm1, con
* No error checking is done*/
static inline ompi_communicator_t *ompi_comm_lookup (const uint32_t c_index)
{
ompi_communicator_t *comm = NULL;
/* array of pointers to communicators, indexed by context ID */
return (ompi_communicator_t *) opal_pointer_array_get_item (&ompi_mpi_communicators, c_index);
comm = (ompi_communicator_t *) opal_pointer_array_get_item (&ompi_mpi_communicators, c_index);
/*
* OMPI_COMM_SENTINEL indicates the slot is being used for CID allocation
* and is not a valid communicator
*/
if ((ompi_communicator_t *)OMPI_COMM_SENTINEL == comm) {
comm = NULL;
}

return comm;
}

/**
* Number of entries in the ompi_mpi_communicators pointer array.
* Note this includes entries which may have NULL or OMPI_COMM_SENTINEL values.
*/
static inline int ompi_comm_get_num_communicators(void)
{
return opal_pointer_array_get_size(&ompi_mpi_communicators);
}

static inline ompi_communicator_t *ompi_comm_lookup_cid (const ompi_comm_extended_cid_t cid)
Expand Down
4 changes: 2 additions & 2 deletions ompi/dpm/dpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1769,9 +1769,9 @@ int ompi_dpm_dyn_finalize(void)
return OMPI_ERR_OUT_OF_RESOURCE;
}

max = opal_pointer_array_get_size(&ompi_mpi_communicators);
max = ompi_comm_get_num_communicators();
for (i=3; i<max; i++) {
comm = (ompi_communicator_t*)opal_pointer_array_get_item(&ompi_mpi_communicators,i);
comm = ompi_comm_lookup(i);
if (NULL != comm && OMPI_COMM_IS_DYNAMIC(comm)) {
objs[j++] = disconnect_init(comm);
}
Expand Down
4 changes: 2 additions & 2 deletions ompi/errhandler/errhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ int ompi_errhandler_proc_failed_internal(ompi_proc_t* ompi_proc, int status, boo

/* Communicator State:
* Let them know about the failure. */
max_num_comm = opal_pointer_array_get_size(&ompi_mpi_communicators);
max_num_comm = ompi_comm_get_num_communicators();
for( i = 0; i < max_num_comm; ++i ) {
comm = (ompi_communicator_t *)opal_pointer_array_get_item(&ompi_mpi_communicators, i);
comm = ompi_comm_lookup(i);
if( NULL == comm ) {
continue;
}
Expand Down
Loading