Skip to content

[Mirror] [Tpetra] Revisit "initialize Kokkos if needed" pattern [rebase]#83

Open
csiefer2 wants to merge 9 commits intodevelopfrom
pr-mirror-15136
Open

[Mirror] [Tpetra] Revisit "initialize Kokkos if needed" pattern [rebase]#83
csiefer2 wants to merge 9 commits intodevelopfrom
pr-mirror-15136

Conversation

@csiefer2
Copy link
Copy Markdown
Owner

Automated mirror of upstream PR trilinos#15136 @trilinos/tpetra

Motivation

Rebase of PR trilinos#14435 onto develop. With trilinos#15128 merged, let's see if this now passes the AT.

dalg24 and others added 9 commits April 15, 2026 10:18
Signed-off-by: Damien L-G <dalg24@gmail.com>
Signed-off-by: Chris Siefert <csiefer@sandia.gov>
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Signed-off-by: Chris Siefert <csiefer2@users.noreply.github.com>
…s since it doesn't initialize Kokkos

Signed-off-by: Chris Siefert <csiefer@sandia.gov>
Signed-off-by: Chris Siefert <csiefer@sandia.gov>
Signed-off-by: Chris Siefert <csiefer@sandia.gov>
Signed-off-by: Chris Siefert <csiefer@sandia.gov>
Signed-off-by: Chris Siefert <csiefer@sandia.gov>
@github-actions
Copy link
Copy Markdown

CDash for AT1 results [Only accessible from Sandia networks]
CDash for AT2 results [Currently only accessible from Sandia networks]

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes conditional compilation guards for Kokkos-related argument tracking in GlobalMPISession and refactors Tpetra::Details::initializeKokkos to use a static initialization pattern. A critical issue was identified regarding the use of std::atexit(Kokkos::finalize), which may lead to an incorrect finalization order where Kokkos is finalized after MPI_Finalize has already been called by the GlobalMPISession destructor, potentially causing undefined behavior in MPI environments.

Kokkos::initialize(narg, args_c.data());
checkOldCudaLaunchBlocking();

std::atexit(Kokkos::finalize);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using std::atexit(Kokkos::finalize) to finalize Kokkos can lead to an incorrect finalization order when Teuchos::GlobalMPISession is used. In typical Trilinos applications, GlobalMPISession is instantiated on the stack in main(). Its destructor, which calls MPI_Finalize(), will execute when main() returns, which is before any functions registered with std::atexit() are called. This results in Kokkos::finalize() being called after MPI_Finalize(). This is generally considered unsafe in MPI environments and can lead to crashes or undefined behavior, especially with MPI-aware Kokkos backends or when Kokkos cleanup tasks (such as releasing memory in certain execution spaces) depend on a valid MPI state.

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