Skip to content
Snippets Groups Projects
Commit 5d1b7f16 authored by Martin Bauer's avatar Martin Bauer
Browse files

Merge branch 'mpifinalize' into 'master'

Only call MPI_Finalize if we actually called MPI_Init

See merge request walberla/walberla!166
parents 9c32d3e5 a3f0cf9e
Branches
Tags
No related merge requests found
...@@ -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
......
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