Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out --help from argv when initializing Kokkos #15465

Merged
merged 3 commits into from
Jun 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions source/base/mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -781,22 +781,31 @@ 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);
for (int i = 0; i < argc; ++i)
argv_new[i] = argv[i];
//
// We do get in trouble, though, if a user program is called with
// '--help' as a command line argument. This '--help' gets passed on to
// Kokkos, which promptly responds with a lengthy message that the user
// likely did not intend. As a consequence, filter out this specific
// flag.
std::vector<char *> argv_new;
for (const auto arg : make_array_view(&argv[0], &argv[0] + argc))
if (strcmp(arg, "--help") != 0)
argv_new.push_back(arg);

std::stringstream threads_flag;
#if KOKKOS_VERSION >= 30700
threads_flag << "--kokkos-num-threads=" << MultithreadInfo::n_threads();
#else
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());
}

Expand Down