]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Minor clean-up to the Kokkos initialization.
authorWolfgang Bangerth <bangerth@colostate.edu>
Sat, 24 Jun 2023 22:32:01 +0000 (16:32 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 24 Jun 2023 22:32:01 +0000 (16:32 -0600)
source/base/mpi.cc

index 87307b1074ab6cc75ef7ce98d240fd3fa0342a20..179f7515f260d954bd3e5aec62ab5f33b03dddc5 100644 (file)
@@ -781,9 +781,10 @@ namespace Utilities
         // argv has argc+1 elements and the last one is a nullptr. For appending
         // one element we thus create a new argv by copying the first argc
         // elements, append the new option, and then a nullptr.
-        std::vector<char *> argv_new(argc + 2);
+        std::vector<char *> argv_new;
         for (int i = 0; i < argc; ++i)
-          argv_new[i] = argv[i];
+          argv_new.push_back(argv[i]);
+
         std::stringstream threads_flag;
 #if KOKKOS_VERSION >= 30700
         threads_flag << "--kokkos-num-threads=" << MultithreadInfo::n_threads();
@@ -791,12 +792,13 @@ namespace Utilities
         threads_flag << "--kokkos-threads=" << MultithreadInfo::n_threads();
 #endif
         const std::string threads_flag_string = threads_flag.str();
-        argv_new[argc]     = const_cast<char *>(threads_flag_string.c_str());
-        argv_new[argc + 1] = nullptr;
+        argv_new.push_back(const_cast<char *>(threads_flag_string.c_str()));
+        argv_new.push_back(nullptr);
+
         // The first argument in Kokkos::initialize is of type int&. Hence, we
         // need to define a new variable to pass to it (instead of using argc+1
         // inline).
-        int argc_new = argc + 1;
+        int argc_new = argv_new.size() - 1;
         Kokkos::initialize(argc_new, argv_new.data());
       }
 

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.