[Mirror] [Tpetra] Revisit "initialize Kokkos if needed" pattern [rebase]#83
[Mirror] [Tpetra] Revisit "initialize Kokkos if needed" pattern [rebase]#83
Conversation
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>
…roscoe 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>
|
CDash for AT1 results [Only accessible from Sandia networks] |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
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.