From c95cd5b147b7a7028b02584c77216441078bdec8 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 19 Dec 2023 10:34:24 +0100 Subject: [PATCH] added: bool param to flag that Main.hpp should not initialize/finalize MPI needed for tests --- opm/simulators/flow/Main.cpp | 16 +++++++++++----- opm/simulators/flow/Main.hpp | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/opm/simulators/flow/Main.cpp b/opm/simulators/flow/Main.cpp index c75fef642..a9de12950 100644 --- a/opm/simulators/flow/Main.cpp +++ b/opm/simulators/flow/Main.cpp @@ -40,10 +40,12 @@ namespace Opm { -Main::Main(int argc, char** argv) - : argc_(argc), argv_(argv) +Main::Main(int argc, char** argv, bool ownMPI) + : argc_(argc), argv_(argv), ownMPI_(ownMPI) { - initMPI(); + if (ownMPI_) { + initMPI(); + } } Main::Main(const std::string& filename) @@ -83,7 +85,9 @@ Main::~Main() } #endif // HAVE_MPI - EclGenericVanguard::setCommunication(nullptr); + if (ownMPI_) { + EclGenericVanguard::setCommunication(nullptr); + } #if HAVE_DAMARIS if (enableDamarisOutput_) { @@ -102,7 +106,9 @@ Main::~Main() #endif // HAVE_DAMARIS #if HAVE_MPI && !HAVE_DUNE_FEM - MPI_Finalize(); + if (ownMPI_) { + MPI_Finalize(); + } #endif } diff --git a/opm/simulators/flow/Main.hpp b/opm/simulators/flow/Main.hpp index 9b0487376..13125825d 100644 --- a/opm/simulators/flow/Main.hpp +++ b/opm/simulators/flow/Main.hpp @@ -127,7 +127,7 @@ int flowEbosMain(int argc, char** argv, bool outputCout, bool outputFiles) class Main { public: - Main(int argc, char** argv); + Main(int argc, char** argv, bool ownMPI = true); // This constructor can be called from Python Main(const std::string& filename); @@ -727,6 +727,7 @@ private: int argc_{0}; char** argv_{nullptr}; + bool ownMPI_{true}; //!< True if we "own" MPI and should init / finalize bool outputCout_{false}; bool outputFiles_{false}; double setupTime_{0.0};