Skip to content

Commit aed5b80

Browse files
committed
Don't retain/release the ompi instance for predefined attributes
Predefined attributes are created during creation of the ompi instance. By not retaining the instance during predefined attribute construction we break the cycle that prevents the instance from being released properly. Signed-off-by: Joseph Schuchart <schuchart@icl.utk.edu>
1 parent 02d91b5 commit aed5b80

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

ompi/attribute/attribute.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -692,17 +692,22 @@ int ompi_attr_create_keyval(ompi_attribute_type_t type,
692692
{
693693
ompi_attribute_fortran_ptr_t es_tmp;
694694
int rc;
695-
696-
rc = ompi_mpi_instance_retain ();
697-
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
698-
return rc;
695+
bool is_predefined = flags & OMPI_KEYVAL_PREDEFINED;
696+
697+
/* Predefined attributes are created as part of the instance creation,
698+
* so do not retain the instance to avoid a circular dependency */
699+
if (!is_predefined) {
700+
rc = ompi_mpi_instance_retain ();
701+
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
702+
return rc;
703+
}
699704
}
700705

701706
es_tmp.c_ptr = extra_state;
702707
rc = ompi_attr_create_keyval_impl(type, copy_attr_fn, delete_attr_fn,
703708
key, &es_tmp, flags,
704709
bindings_extra_state);
705-
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
710+
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc) && !is_predefined) {
706711
ompi_mpi_instance_release ();
707712
}
708713

@@ -786,8 +791,12 @@ int ompi_attr_free_keyval(ompi_attribute_type_t type, int *key,
786791
opal_atomic_wmb();
787792
OPAL_THREAD_UNLOCK(&attribute_lock);
788793

789-
/* balance out retain in keyval_create */
790-
ompi_mpi_instance_release ();
794+
/* balance out retain in keyval_create
795+
* predefined attributes do not retain the instance so do not release it either
796+
*/
797+
if (!predefined) {
798+
ompi_mpi_instance_release ();
799+
}
791800

792801
return MPI_SUCCESS;
793802
}

0 commit comments

Comments
 (0)