Commit a3f0cf9e authored by RudolfWeeber's avatar RudolfWeeber Committed by Michael Kuron
Browse files

Only call MPI_Finalize if we actually called MPI_Init

parent b6c6e2dd
...@@ -103,6 +103,7 @@ void MPIManager::initializeMPI( int* argc, char*** argv, bool abortOnException ) ...@@ -103,6 +103,7 @@ void MPIManager::initializeMPI( int* argc, char*** argv, bool abortOnException )
MPI_Initialized( &mpiAlreadyInitialized ); MPI_Initialized( &mpiAlreadyInitialized );
if ( ! mpiAlreadyInitialized ) { if ( ! mpiAlreadyInitialized ) {
MPI_Init( argc, argv ); MPI_Init( argc, argv );
finalizeOnDestruction_ = true;
} }
isMPIInitialized_ = true; isMPIInitialized_ = true;
...@@ -122,7 +123,10 @@ void MPIManager::finalizeMPI() ...@@ -122,7 +123,10 @@ void MPIManager::finalizeMPI()
if( isMPIInitialized_ && !currentlyAborting_ ) if( isMPIInitialized_ && !currentlyAborting_ )
{ {
isMPIInitialized_ = false; isMPIInitialized_ = false;
MPI_Finalize(); if (finalizeOnDestruction_)
{
MPI_Finalize();
}
} }
} }
} }
......
...@@ -156,9 +156,12 @@ private: ...@@ -156,9 +156,12 @@ private:
bool currentlyAborting_; bool currentlyAborting_;
bool finalizeOnDestruction_;
// Singleton // Singleton
MPIManager() : worldRank_(0), rank_(-1), numProcesses_(1), comm_(MPI_COMM_NULL), MPIManager() : worldRank_(0), rank_(-1), numProcesses_(1), comm_(MPI_COMM_NULL),
isMPIInitialized_(false), cartesianSetup_(false), currentlyAborting_(false) isMPIInitialized_(false), cartesianSetup_(false), currentlyAborting_(false),
finalizeOnDestruction_(false)
{ WALBERLA_NON_MPI_SECTION() { rank_ = 0; } } { WALBERLA_NON_MPI_SECTION() { rank_ = 0; } }
}; // class MPIManager }; // class MPIManager
......
Markdown is supported
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