Skip to content

init: use MPIR_CVAR_FINALIZE_ATEXIT to bypass re-init - #7933

Open
hzhou wants to merge 8 commits into
pmodels:mainfrom
hzhou:2608_reinit
Open

hzhou wants to merge 8 commits into
pmodels:mainfrom
hzhou:2608_reinit

Conversation

@hzhou

@hzhou hzhou commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Pull Request Description

As cc91750#r3758517489 show, we can't rely on local init_counter to collectively resolve conflicts between session re-init epochs. In fact, after a full-day's effort, I concluded there is no way to create a solution for

  1. pmix can't work with duplicate KVS key for business card exchange
  2. shared memory communication will corrupt between re-init epochs.

We just can't have a collective synchronization when we can't establish collective assumptions.

This PR reverts the previous attempts and add MPIR_CVAR_FINALIZE_ATEXIT to workaround. When the cvar is set, we delay the final MPII_Finalize to atexit, avoiding the necessity of re-initialize both shm and netmod.

Author Checklist

  • Provide Description
    Particularly focus on why, not what. Reference background, issues, test failures, xfail entries, etc.
  • Commits Follow Good Practice
    Commits are self-contained and do not do two things at once.
    Commit message is of the form: module: short description
    Commit message explains what's in the commit.
  • Passes All Tests
    Whitespace checker. Warnings test. Additional tests via comments.
  • Contribution Agreement
    For non-Argonne authors, check contribution agreement.
    If necessary, request an explicit comment from your companies PR approval manager.

@hzhou

hzhou commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

test:mpich/ch4/ofi
test:mpich/pmi

@sonjahapp sonjahapp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this PR!

Just found a few minor typo fixes for the testlist. 😉

Comment thread test/mpi/session/testlist Resolved
Comment thread test/mpi/session/testlist Resolved
Comment thread test/mpi/session/testlist Resolved
@hzhou

hzhou commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for this PR!

Just found a few minor typo fixes for the testlist. 😉

Thanks for the catch. I will fix them in the next push.

By the way, do you think we can remove the PMI atexit hook completely now we have the CVAR option?

@sonjahapp

Copy link
Copy Markdown
Collaborator

By the way, do you think we can remove the PMI atexit hook completely now we have the CVAR option?

Hmm... I would keep it.

It leaves freedom to the device to enable more "fine grained" solutions for re-init. The new CVAR is quite the "hammer" since it postpones almost the entire MPI cleanup to an atexit handler. For example, in the psp device we offer the ability to finalize most parts in MPID_Finalize but keep the connections alive. This will only continue to work if the PMI(x)_Finalize remains in an atexit handler as is.

Comment thread src/mpi/init/mpir_init.c Resolved
@hzhou
hzhou force-pushed the 2608_reinit branch 3 times, most recently from 04a2a79 to 641af69 Compare September 6, 2026 15:48
@hzhou

hzhou commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

test:mpich/ch4/ofi
test:mpich/pmi

@sonjahapp

Copy link
Copy Markdown
Collaborator

I think now with the new CVAR set in the tests, on re-init the MPIDI_POSIX_comm_bootstrap hook might try to init (again) a shmem segment that has not been freed before in the MPI finalize hook - because this hook is deferred to atexit. This leads to errors.

Perhaps the comm bootstrap hook needs to check if the shmem segment is already there and then reuse it in case of re-init instead of attempting to init it again?

@hzhou

hzhou commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

I think now with the new CVAR set in the tests, on re-init the MPIDI_POSIX_comm_bootstrap hook might try to init (again) a shmem segment that has not been freed before in the MPI finalize hook - because this hook is deferred to atexit. This leads to errors.

Perhaps the comm bootstrap hook needs to check if the shmem segment is already there and then reuse it in case of re-init instead of attempting to init it again?

There is no shmem reinitialization if the finalize is delayed. I am not sure what is causing the pmix test failures yet.

@hzhou

hzhou commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

test:mpich/ch4/ofi
test:mpich/pmi

@hzhou

hzhou commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

test:mpich/ch4/ofi
test:mpich/pmi

hzhou added 8 commits November 8, 2026 20:52
Add this cvar as a work-around for sessions re-init. There is no good
solution to synchronize shared memory over re-init now that we switched
to total asynchronous initialization. Consider the following case:

* Process A and B both initialized shm and both re-initialize.
* B re-init shm while A delays.
* B send a message to A via shm.
* A (still in the previous epoch) either discards the message or error.
* A re-init.
* A never receives the message B send.

Delay the final finalize via atexit avoids the re-init altogether.
In case device runtime also register atexit hooks during MPID_Init,
register finalize_atexit at the end of Init so finalize_atexit runs
first, before potential device atexit hooks.
Putting MPII_Finalize in atexit obviates the need for pmi atexit hook.
Since **atexit is also used in mpir_init.c, move it to
src/mpi/errhan/errnames.txt instead of src/pmi/errnames.txt.
@hzhou

hzhou commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

test:mpich/ch4/ofi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants