Skip to content
Snippets Groups Projects

MPIHelper should only finalize MPI if it called init

Merged Andreas Dedner requested to merge feature/fix-call-MPIfinalize-onlyif-MPIInit-called into master
+ 8
4
Compare changes
  • Side-by-side
  • Inline
@@ -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);
    • Maybe unrelated, but what is this weird static int is_initialized doing here? If anything, we should check its value and throw an exception on error...

      • Why throw an exception when we just want to discard subequent calls to MPI_Init? But we might be overprotective here as instance should already take care of this with the static MPIHelper singleton variable.

      • Not necessarily. It might be that it is already initialized via some other part of the code. E.g. in my python code I initialize via mpi4py and thus DUNE should avoid a second initialization.

      • Please register or sign in to reply
Please register or sign in to reply
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&);
Loading