]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add comments and avoid a temporary std::string 14869/head
authorDaniel Arndt <arndtd@ornl.gov>
Fri, 10 Mar 2023 21:28:39 +0000 (16:28 -0500)
committerDaniel Arndt <arndtd@ornl.gov>
Fri, 10 Mar 2023 21:36:31 +0000 (16:36 -0500)
source/base/mpi.cc

index f4642bc077c576e08cdba035a9dca9ae6ca53d23..93322d5fe1460f5cff95b50a533a656aa284056b 100644 (file)
@@ -777,6 +777,9 @@ namespace Utilities
 
       // Initialize Kokkos
       {
+        // 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);
         for (int i = 0; i < argc; ++i)
           argv_new[i] = argv[i];
@@ -786,9 +789,13 @@ namespace Utilities
 #else
         threads_flag << "--kokkos-threads=" << MultithreadInfo::n_threads();
 #endif
-        argv_new[argc]     = const_cast<char *>(threads_flag.str().c_str());
+        std::string threads_flag_string = threads_flag.str();
+        argv_new[argc]     = const_cast<char *>(threads_flag_string.c_str());
         argv_new[argc + 1] = nullptr;
-        int argc_new       = argc + 1;
+        // The first argument in Kokkos::initialzie is of type int&. Hence, we
+        // need to define a new variable to pass to it (insted of using argc+1
+        // inline).
+        int argc_new = argc + 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.