Skip to content

Don't retain/release the ompi instance for predefined attributes #10350

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
May 23, 2022
Merged
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
23 changes: 16 additions & 7 deletions ompi/attribute/attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,17 +692,22 @@ int ompi_attr_create_keyval(ompi_attribute_type_t type,
{
ompi_attribute_fortran_ptr_t es_tmp;
int rc;

rc = ompi_mpi_instance_retain ();
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
return rc;
bool is_predefined = flags & OMPI_KEYVAL_PREDEFINED;

/* Predefined attributes are created as part of the instance creation,
* so do not retain the instance to avoid a circular dependency */
if (!is_predefined) {
rc = ompi_mpi_instance_retain ();
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
return rc;
}
}

es_tmp.c_ptr = extra_state;
rc = ompi_attr_create_keyval_impl(type, copy_attr_fn, delete_attr_fn,
key, &es_tmp, flags,
bindings_extra_state);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc) && !is_predefined) {
ompi_mpi_instance_release ();
}

Expand Down Expand Up @@ -786,8 +791,12 @@ int ompi_attr_free_keyval(ompi_attribute_type_t type, int *key,
opal_atomic_wmb();
OPAL_THREAD_UNLOCK(&attribute_lock);

/* balance out retain in keyval_create */
ompi_mpi_instance_release ();
/* balance out retain in keyval_create
* predefined attributes do not retain the instance so do not release it either
*/
if (!predefined) {
ompi_mpi_instance_release ();
}

return MPI_SUCCESS;
}
Expand Down