]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make ensure_kokkos_initialized thread-safe 14714/head
authorDaniel Arndt <arndtd@ornl.gov>
Tue, 24 Jan 2023 04:10:16 +0000 (23:10 -0500)
committerDaniel Arndt <arndtd@ornl.gov>
Tue, 24 Jan 2023 04:11:30 +0000 (23:11 -0500)
source/base/kokkos.cc

index 7cf0a34d6ad62d77cf4c756786c9c8fd49b5a834..5ea3b374c15a86b7fb3a1d115402be89e7d36e23 100644 (file)
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.