Initialize/Finalize: Pop Hooks Before Calling Them - #5648
Conversation
`amrex::Initialize` and `amrex::Finalize` drained their hook stacks with `top()()` followed by `pop()`. A hook that registers another one with `ExecOnInitialize`/`ExecOnFinalize` therefore left the *calling* hook on top of the stack: it ran a second time, and the following `pop()` silently discarded the newly registered hook without ever running it. Move the hook off the stack before calling it, so that a hook which registers another one runs exactly once and the newly registered hook runs as well. Found while making the ABLASTR warn manager state per AMReX cycle in BLAST-WarpX/warpx#7186: a warning recorded from a finalize hook resurrects the warn manager singleton and loses the teardown hook that would have released it again.
|
/run-hpsf-gitlab-ci |
|
GitLab CI has started at https://gitlab.spack.io/amrex/amrex/-/pipelines/1779961. |
|
GitLab CI 1779961 finished with status: failed. See details at https://gitlab.spack.io/amrex/amrex/-/pipelines/1779961. |
|
|
|
HPSF issue analyzed by Claude: Unrelated to this PR — confirmed by bisecting the GitLab pipeline history. What actually failedPipeline 1779961: all three GPU jobs (Nvidia-H100 SP, AMD-MI300A, Intel-PVC) died at exactly
Why it is not this PR
Root cause of the test itself
That is pure launch-latency work with no arithmetic to hide it. On CPU it is fine — GitHub's It only bites HPSF because Suggested fixThe fix likely belongs in the test rather than in CI timeouts: a CI-sized inputs file (e.g. |
Summary
amrex::Initializeandamrex::Finalizedrained their hook stacks withtop()()followed bypop(). A hook that registers another one withExecOnInitialize/ExecOnFinalizetherefore left the calling hook on top of the stack: it ran a second time, and the followingpop()silently discarded the newly registered hook without ever running it.Move the hook off the stack before calling it, so that a hook which registers another one runs exactly once and the newly registered hook runs as well.
Additional background
Found while making the ABLASTR warn manager state per AMReX cycle in BLAST-WarpX/warpx#7186: a warning recorded from a finalize hook resurrects the warn manager singleton and loses the teardown hook that would have released it again.
Checklist
The proposed changes: