From: Daniel Arndt Date: Fri, 10 Mar 2023 21:28:39 +0000 (-0500) Subject: Add comments and avoid a temporary std::string X-Git-Tag: v9.5.0-rc1~495^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46e174034b1c0b2aae616fe72922c746b274c738;p=dealii.git Add comments and avoid a temporary std::string --- diff --git a/source/base/mpi.cc b/source/base/mpi.cc index f4642bc077..93322d5fe1 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -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 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(threads_flag.str().c_str()); + std::string threads_flag_string = threads_flag.str(); + argv_new[argc] = const_cast(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()); }