Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/onqtam/doctest.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBerengerBerthoul <56256655+BerengerBerthoul@users.noreply.github.com>2022-03-05 02:10:19 +0300
committerGitHub <noreply@github.com>2022-03-05 02:10:19 +0300
commit3e1011c6957570a5eba37c0e42d4202045bef1d9 (patch)
treec34497e3a240f6a072b8604b677b49864fa48882
parent302f158c607e91c10cb684271455a6caa1afb700 (diff)
Fix MPI extension to work with no parallel tests (#623)
Instead of initializing world_size_before_init at 1 and then at every MPI_TEST_CASE (consequently always getting 1 if there is no MPI_TEST_CASE), we initialize it immediately with the value of mpi_comm_world_size()
-rw-r--r--doctest/extensions/doctest_mpi.h16
1 files changed, 7 insertions, 9 deletions
diff --git a/doctest/extensions/doctest_mpi.h b/doctest/extensions/doctest_mpi.h
index 1552458e..5f1ed139 100644
--- a/doctest/extensions/doctest_mpi.h
+++ b/doctest/extensions/doctest_mpi.h
@@ -18,11 +18,6 @@ std::unordered_map<int,mpi_sub_comm> sub_comms_by_size;
// because there is not enought procs to execute it
int nb_test_cases_skipped_insufficient_procs = 0;
-// Record size of MPI_COMM_WORLD with mpi_comm_world_size()
-// so that it can be compared to the MPI_Comm_size value
-// once MPI_Init_thread has been called
-int world_size_before_init = 1;
-
std::string thread_level_to_string(int thread_lvl);
int mpi_init_thread(int argc, char *argv[], int required_thread_support);
@@ -42,10 +37,13 @@ int mpi_comm_world_size() {
#error "Unknown MPI implementation: please submit an issue or a PR to doctest. Meanwhile, you can look at the output of e.g. `mpirun -np 3 env` to search for an environnement variable that contains the size of MPI_COMM_WORLD and extend this code accordingly"
#endif
if (size_str==nullptr) return 1; // not launched with mpirun/mpiexec, so assume only one process
- world_size_before_init = std::stoi(size_str);
- return world_size_before_init;
+ return std::stoi(size_str);
}
+// Record size of MPI_COMM_WORLD with mpi_comm_world_size()
+int world_size_before_init = mpi_comm_world_size();
+
+
std::string thread_level_to_string(int thread_lvl) {
switch (thread_lvl) {
case MPI_THREAD_SINGLE: return "MPI_THREAD_SINGLE";
@@ -94,8 +92,8 @@ namespace doctest {
extern std::unordered_map<int,mpi_sub_comm> sub_comms_by_size;
extern int nb_test_cases_skipped_insufficient_procs;
+extern int world_size_before_init;
-int mpi_comm_world_size();
int mpi_init_thread(int argc, char *argv[], int required_thread_support);
void mpi_finalize();
@@ -115,7 +113,7 @@ void execute_mpi_test_case(F func) {
inline bool
insufficient_procs(int test_nb_procs) {
- bool insufficient = test_nb_procs>mpi_comm_world_size();
+ bool insufficient = test_nb_procs>world_size_before_init;
if (insufficient) {
++nb_test_cases_skipped_insufficient_procs;
}