From 859ea43c0188ac1340eacf516741e322a58faf06 Mon Sep 17 00:00:00 2001 From: Hugo Taboada Date: Tue, 18 Jun 2024 23:27:42 +0200 Subject: [PATCH] Replace MPI_Init to MPI_Init_thread when needed --- perf_tests/test_main.cpp | 8 ++++++-- unit_tests/test_main.cpp | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/perf_tests/test_main.cpp b/perf_tests/test_main.cpp index 4898d6e4..e69f617e 100644 --- a/perf_tests/test_main.cpp +++ b/perf_tests/test_main.cpp @@ -32,7 +32,11 @@ class NullReporter : public ::benchmark::BenchmarkReporter { // The main is rewritten to allow for MPI initializing and for selecting a // reporter according to the process rank int main(int argc, char **argv) { - MPI_Init(&argc, &argv); + int provided; + MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); + if (provided != MPI_THREAD_MULTIPLE) { + throw std::runtime_error("MPI_THREAD_MULTIPLE is needed"); + } int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -54,4 +58,4 @@ int main(int argc, char **argv) { Kokkos::finalize(); MPI_Finalize(); return 0; -} \ No newline at end of file +} diff --git a/unit_tests/test_main.cpp b/unit_tests/test_main.cpp index d5dea47a..b175642f 100644 --- a/unit_tests/test_main.cpp +++ b/unit_tests/test_main.cpp @@ -81,7 +81,11 @@ int main(int argc, char *argv[]) { // Intialize google test ::testing::InitGoogleTest(&argc, argv); - MPI_Init(&argc, &argv); + int provided; + MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); + if (provided != MPI_THREAD_MULTIPLE) { + throw std::runtime_error("MPI_THREAD_MULTIPLE is needed"); + } int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size);