From ffc2e491a7996fad6ed69040b5578756669fb93c Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 23 Jan 2023 23:10:16 -0500 Subject: [PATCH] Make ensure_kokkos_initialized thread-safe --- source/base/kokkos.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/base/kokkos.cc b/source/base/kokkos.cc index 7cf0a34d6a..5ea3b374c1 100644 --- a/source/base/kokkos.cc +++ b/source/base/kokkos.cc @@ -31,9 +31,14 @@ namespace internal { if (!Kokkos::is_initialized()) { - dealii_initialized_kokkos = true; - Kokkos::initialize(); - std::atexit(Kokkos::finalize); + // only execute once + static bool dummy = [] { + dealii_initialized_kokkos = true; + Kokkos::initialize(); + std::atexit(Kokkos::finalize); + return true; + }(); + (void)dummy; } } } // namespace internal -- 2.39.5