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

MPIHelper only calls MPI if it was not already called before MPIHelper is

constructed. Finalize is however always caused 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.
parent d863ce8f
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