Skip to content
Snippets Groups Projects
Commit 9af12b69 authored by Andreas Dedner's avatar Andreas Dedner
Browse files

Merge branch 'feature/fix-call-MPIfinalize-onlyif-MPIInit-called' into 'master'

MPIHelper should only finalize MPI if it called init

MPIHelper only calls MPI if it was not already called before MPIHelper is constructed. Finalize is however always called on destruction leading to
problems with other packages calling init/finalize before/after MPIHelper
is setup. Added a bool storing the information if MPIInit was called by the
MPIHelper so that finalize is only called in that case.

See merge request !58
parents 4f193672 973ae43b
No related branches found
No related tags found
No related merge requests found
......@@ -233,10 +233,12 @@ namespace Dune
private:
int rank_;
int size_;
bool initializedHere_;
void prevent_warning(int){}
//! \brief calls MPI_Init with argc and argv as parameters
MPIHelper(int& argc, char**& argv)
: initializedHere_(false)
{
int wasInitialized = -1;
MPI_Initialized( &wasInitialized );
......@@ -246,6 +248,7 @@ namespace Dune
size_ = -1;
static int is_initialized = MPI_Init(&argc, &argv);
prevent_warning(is_initialized);
initializedHere_ = true;
}
MPI_Comm_rank(MPI_COMM_WORLD,&rank_);
......@@ -261,10 +264,11 @@ namespace Dune
{
int wasFinalized = -1;
MPI_Finalized( &wasFinalized );
if(!wasFinalized) {
MPI_Finalize();
dverb << "Called MPI_Finalize on p=" << rank_ << "!" <<std::endl;
}
if(!wasFinalized && initializedHere_)
{
MPI_Finalize();
dverb << "Called MPI_Finalize on p=" << rank_ << "!" <<std::endl;
}
}
MPIHelper(const MPIHelper&);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment