Skip to content
Snippets Groups Projects
Commit 96f9f7f0 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

Gmsh should call MPI_Finalize only if Gmsh performed MPI_Init

parent efeed359
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,7 @@
int Msg::_commRank = 0;
int Msg::_commSize = 1;
bool Msg::_mpiInit = false;
int Msg::_verbosity = 5;
int Msg::_progressMeterStep = 10;
std::atomic<int> Msg::_progressMeterCurrent(-1);
......@@ -128,7 +129,10 @@ void Msg::Initialize(int argc, char **argv)
#if defined(HAVE_MPI)
int flag;
MPI_Initialized(&flag);
if(!flag) MPI_Init(&argc, &argv);
if(!flag) {
MPI_Init(&argc, &argv);
_mpiInit = true;
}
MPI_Comm_rank(MPI_COMM_WORLD, &_commRank);
MPI_Comm_size(MPI_COMM_WORLD, &_commSize);
MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
......@@ -208,10 +212,12 @@ void Msg::Finalize()
//PetscFinalize();
#endif
#if defined(HAVE_MPI)
int finalized; // Some PETSc versions call MPI_FINALIZE
if(_mpiInit) {
int finalized;
MPI_Finalized(&finalized);
if (!finalized)
MPI_Finalize();
}
#endif
FinalizeOnelab();
}
......
......
......@@ -32,6 +32,8 @@ class Msg {
private:
// current cpu number and total number of cpus
static int _commRank, _commSize;
// did Gmsh initialize MPI?
static bool _mpiInit;
// verbosity level (0: silent except fatal errors, 1: +errors, 2: +warnings,
// 3: +direct, 4: +info, 5 (=normal): +statusbar, 99: debug)
static int _verbosity;
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment