From 29ee79b0d2e4060a4009859973bd7731efecd207 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 183d141db2..e13d84a9ea 100644 --- a/include/deal.II/base/mpi.h +++ b/include/deal.II/base/mpi.h @@ -348,10 +348,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 ea24b30826..f5c403711f 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 @@ -386,6 +390,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; @@ -517,6 +527,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 calling diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index f8b7009a10..21f75414bb 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -2098,59 +2098,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 @@ -2179,11 +2126,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