]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Initialize Kokkos with MultithreadInfo::n_threads()
authorDaniel Arndt <arndtd@ornl.gov>
Thu, 9 Mar 2023 18:50:19 +0000 (13:50 -0500)
committerDaniel Arndt <arndtd@ornl.gov>
Thu, 9 Mar 2023 18:50:39 +0000 (13:50 -0500)
source/base/kokkos.cc
source/base/mpi.cc

index 5ea3b374c15a86b7fb3a1d115402be89e7d36e23..18f41861fab2667e329b17b981d6a120d4f3e2dd 100644 (file)
@@ -14,6 +14,7 @@
 // ---------------------------------------------------------------------
 
 #include <deal.II/base/kokkos.h>
+#include <deal.II/base/multithread_info.h>
 
 #include <deal.II/lac/la_parallel_vector.h>
 #include <deal.II/lac/vector_memory.h>
@@ -34,7 +35,10 @@ namespace internal
         // only execute once
         static bool dummy = [] {
           dealii_initialized_kokkos = true;
-          Kokkos::initialize();
+          const auto settings =
+            Kokkos::InitializationSettings().set_num_threads(
+              MultithreadInfo::n_threads());
+          Kokkos::initialize(settings);
           std::atexit(Kokkos::finalize);
           return true;
         }();
index cd1d1ea8d1ce4a4c25ffd6c5aa160246da9ba5c3..cd06ceaadd81575296203b6676f078dc3b884412 100644 (file)
@@ -776,7 +776,17 @@ namespace Utilities
 #endif
 
       // Initialize Kokkos
-      Kokkos::initialize(argc, argv);
+      {
+        std::vector<char *> argv_new;
+        for (int i = 0; i < argc; ++i)
+          argv_new.push_back(argv[i]);
+        std::stringstream threads_flag;
+        threads_flag << "--kokkos-threads=" << MultithreadInfo::n_threads();
+        argv_new.push_back(const_cast<char *>(threads_flag.str().c_str()));
+        argv_new.push_back(nullptr);
+        int argc_new = argc + 1;
+        Kokkos::initialize(argc_new, argv_new.data());
+      }
 
       // we are allowed to call MPI_Init ourselves and PETScInitialize will
       // detect this. This allows us to use MPI_Init_thread instead.

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.