Commit 70f9ecfc authored by Rudolf Weeber's avatar Rudolf Weeber
Browse files

Make calling MPI_Finalize() at destruciotn of MPIManager switchable

parent 44357ad6
......@@ -48,8 +48,8 @@ int main( int argc, char ** argv )
class Environment
{
public:
Environment( int & argc, char ** & argv, bool abortOnException = true ) {
MPIManager::instance()->initializeMPI( &argc, &argv, abortOnException );
Environment( int & argc, char ** & argv, bool abortOnException = true, bool finalizeOnDestruction=true ) {
MPIManager::instance()->initializeMPI( &argc, &argv, abortOnException, finalizeOnDestruction);
}
~Environment() {
MPIManager::instance()->finalizeMPI();
......
......@@ -90,7 +90,7 @@ void MPIManager::abort()
}
void MPIManager::initializeMPI( int* argc, char*** argv, bool abortOnException )
void MPIManager::initializeMPI( int* argc, char*** argv, bool abortOnException, bool finalizeOnDestruction )
{
WALBERLA_MPI_SECTION()
{
......@@ -111,6 +111,7 @@ void MPIManager::initializeMPI( int* argc, char*** argv, bool abortOnException )
if( abortOnException )
std::set_terminate( customTerminateHandler );
finalizeOnDestruction_ = finalizeOnDestruction;
}
}
......@@ -122,7 +123,8 @@ void MPIManager::finalizeMPI()
if( isMPIInitialized_ && !currentlyAborting_ )
{
isMPIInitialized_ = false;
MPI_Finalize();
if (finalizeOnDestruction_)
MPI_Finalize();
}
}
}
......
......@@ -63,8 +63,9 @@ public:
* Configures the class, initializes numProcesses, worldRank
* the rank and comm variables are still invalid, until custom communicator is set up
* @param abortOnException if true, MPI_Abort is called in case of an uncaught exception
* @param finalizeOnDestruction if true, MPI_Finalize is called, when the instance is destructed.
*/
void initializeMPI( int* argc, char*** argv, bool abortOnException = true );
void initializeMPI( int* argc, char*** argv, bool abortOnException = true, bool finalizeOnDestruction=true);
void finalizeMPI();
......@@ -156,6 +157,8 @@ private:
bool currentlyAborting_;
bool finalizeOnDestruction_;
// Singleton
MPIManager() : worldRank_(0), rank_(-1), numProcesses_(1), comm_(MPI_COMM_NULL),
isMPIInitialized_(false), cartesianSetup_(false), currentlyAborting_(false)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment