Skip to content
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

mpir_pmi: Move PMI(x)_Finalize to atexit handler to enable re-init. #6534

Merged
merged 1 commit into from
Jun 8, 2023
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
5 changes: 5 additions & 0 deletions src/pmi/errnames.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@
**pmix_resolve_nodes %d: PMIx_Resolve_nodes returned %d
**pmix_resolve_peers: PMIx_Resolve_peers failed
**pmix_resolve_peers %d: PMIx_Resolve_peers returned %d
#
# PMI finalize exit handler registration
#
**atexit_pmi_finalize: Registration of PMI finalize function in exit handler failed
**atexit_pmi_finalize %d: Registration of PMI finalize function in exit handler failed with %d
26 changes: 23 additions & 3 deletions src/util/mpir_pmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,22 @@ static pmix_proc_t pmix_wcproc;

static char *hwloc_topology_xmlfile;

static void MPIR_pmi_finalize_on_exit(void)
{
#ifdef USE_PMI1_API
PMI_Finalize();
#elif defined USE_PMI2_API
PMI2_Finalize();
#elif defined USE_PMIX_API
PMIx_Finalize(NULL, 0);
#endif
}

int MPIR_pmi_init(void)
{
int mpi_errno = MPI_SUCCESS;
int pmi_errno;
static bool pmi_connected = false;

/* See if the user wants to override our default values */
MPL_env2int("PMI_VERSION", &pmi_version);
Expand Down Expand Up @@ -212,6 +224,15 @@ int MPIR_pmi_init(void)
world_id = 0;

#endif
if (!pmi_connected) {
/* Register finalization of PM connection in exit handler */
mpi_errno = atexit(MPIR_pmi_finalize_on_exit);
MPIR_ERR_CHKANDJUMP1(mpi_errno != 0, mpi_errno, MPI_ERR_OTHER,
"**atexit_pmi_finalize", "**atexit_pmi_finalize %d", mpi_errno);

pmi_connected = true;
}

MPIR_Process.has_parent = has_parent;
MPIR_Process.rank = rank;
MPIR_Process.size = size;
Expand All @@ -234,14 +255,13 @@ int MPIR_pmi_init(void)

void MPIR_pmi_finalize(void)
{
/* Finalize of PM interface happens in exit handler,
* here: free allocated memory */
#ifdef USE_PMI1_API
PMI_Finalize();
MPL_free(pmi_kvs_name);
#elif defined(USE_PMI2_API)
PMI2_Finalize();
MPL_free(pmi_jobid);
#elif defined(USE_PMIX_API)
PMIx_Finalize(NULL, 0);
/* pmix_proc does not need free */
#endif

Expand Down