From 9fd4578b66a0263600b9e8c10a52faf2ee6adeab Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Fri, 13 Sep 2024 00:53:25 +0200 Subject: [PATCH] Add --threads option to control the number of threads for tests --- tests/mpi_test_main.cpp | 14 ++++++++++---- tests/test_main.cpp | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/mpi_test_main.cpp b/tests/mpi_test_main.cpp index 68b5e0deb..728845ac4 100644 --- a/tests/mpi_test_main.cpp +++ b/tests/mpi_test_main.cpp @@ -28,7 +28,16 @@ main(int argc, char* argv[]) parallel::Messenger::create(argc, argv); const int nb_max_threads = std::max(std::thread::hardware_concurrency(), 1u); - const int nb_threads = std::max(nb_max_threads / parallel::Messenger::getInstance().size(), 1ul); + int nb_threads = std::max(nb_max_threads / parallel::Messenger::getInstance().size(), 1ul); + + Catch::Session session; + + auto cli = session.cli() | Catch::Clara::Opt(nb_threads, "number of threads")["--threads"]( + "number of threads (default: max logical threads)"); + + session.cli(cli); + + int result = session.applyCommandLine(argc, argv); { Kokkos::InitializationSettings args; @@ -54,9 +63,6 @@ main(int argc, char* argv[]) } }(); - Catch::Session session; - int result = session.applyCommandLine(argc, argv); - // disable file locking to avoid mess in tests setenv("HDF5_USE_FILE_LOCKING", "FALSE", 1); diff --git a/tests/test_main.cpp b/tests/test_main.cpp index fe5e8eea3..84b15f758 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -23,7 +23,16 @@ int main(int argc, char* argv[]) { parallel::Messenger::create(argc, argv); - const int nb_threads = std::max(std::thread::hardware_concurrency() / 2, 1u); + int nb_threads = std::max(std::thread::hardware_concurrency() / 2, 1u); + + Catch::Session session; + + auto cli = session.cli() | Catch::Clara::Opt(nb_threads, "number of threads")["--threads"]( + "number of threads (default: max logical threads)"); + + session.cli(cli); + + int result = session.applyCommandLine(argc, argv); { Kokkos::InitializationSettings args; @@ -40,9 +49,6 @@ main(int argc, char* argv[]) PETScWrapper::initialize(argc, argv); SLEPcWrapper::initialize(argc, argv); - Catch::Session session; - int result = session.applyCommandLine(argc, argv); - if (result == 0) { const auto& config = session.config(); if (config.listReporters() or config.listTags() or config.listTests()) { -- GitLab