From eeebee4d78b9e45c828c178b4bfb5a13523fe212 Mon Sep 17 00:00:00 2001 From: Jonathan Perry-Houts Date: Wed, 31 Aug 2016 11:08:29 -0700 Subject: [PATCH] Ensure that MPI_Comm_free is called before MPI_Finalize --- include/deal.II/base/mpi.h | 6 +++- source/base/mpi.cc | 16 +++++++++++ source/distributed/tria.cc | 58 -------------------------------------- 3 files changed, 21 insertions(+), 59 deletions(-) diff --git a/include/deal.II/base/mpi.h b/include/deal.II/base/mpi.h index 2673b7c6e6..8838d94029 100644 --- a/include/deal.II/base/mpi.h +++ b/include/deal.II/base/mpi.h @@ -332,10 +332,14 @@ namespace Utilities * program and to shut it down again at the end. It also allows you to * control the number threads used in each MPI task. * - * If deal.II is configured with PETSc, the library will also be + * If deal.II is configured with PETSc, the library will be * initialized in the beginning and destroyed at the end automatically * (internally by calling PetscInitialize() and PetscFinalize()). * + * If deal.II is configured with p4est, that library will also be + * initialized in the beginning, and destroyed at the end automatically + * (internally by calling sc_init(), p4est_init(), and sc_finalize()). + * * If a program uses MPI one would typically just create an object of this * type at the beginning of main(). The constructor of this * class then runs MPI_Init() with the given arguments. At diff --git a/source/base/mpi.cc b/source/base/mpi.cc index 5d7b098277..2e3d95a7fd 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -50,6 +50,10 @@ # endif #endif +#ifdef DEAL_II_WITH_P4EST +# include +#endif + DEAL_II_NAMESPACE_OPEN @@ -356,6 +360,12 @@ namespace Utilities # endif #endif +#ifdef DEAL_II_WITH_P4EST + //Initialize p4est and libsc components + sc_init(MPI_COMM_WORLD, 0, 0, NULL, SC_LP_SILENT); + p4est_init (0, SC_LP_SILENT); +#endif + constructor_has_already_run = true; @@ -485,6 +495,12 @@ namespace Utilities } #endif +#ifdef DEAL_II_WITH_P4EST + // now end p4est and libsc + // Note: p4est has no finalize function + sc_finalize (); +#endif + // only MPI_Finalize if we are running with MPI. We also need to do this // when running PETSc, because we initialize MPI ourselves before diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index e3c2104b21..356ee3c52c 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -2137,59 +2137,6 @@ namespace } -// initialize p4est -namespace internal -{ - namespace p4est - { - struct InitFinalize - { - private: - struct Singleton - { - Singleton () - { - // ensure that the initialization code is run only once, even if we - // link with 1d, 2d, and 3d libraries - static bool initialized = false; - - if (initialized == false) - { - sc_init (MPI_COMM_WORLD, - 0, 0, 0, SC_LP_SILENT); - p4est_init (0, SC_LP_SILENT); - - initialized = true; - } - } - - ~Singleton () - { - // same here - static bool deinitialized = false; - - if (deinitialized == false) - { - // p4est has no p4est_finalize function - sc_finalize (); - - deinitialized = true; - } - } - }; - - public: - // do run the initialization code, at least the first time around we get - // to this function - static void do_initialize () - { - static Singleton singleton; - } - }; - } -} - - namespace parallel { namespace distributed @@ -2218,11 +2165,6 @@ namespace parallel n_attached_datas(0), n_attached_deserialize(0) { - // initialize p4est. do this in a separate function since it has to - // happen only once, even if we have triangulation objects for several - // different space dimensions - dealii::internal::p4est::InitFinalize::do_initialize (); - parallel_ghost = 0; } -- 2.39.5