]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Ensure that MPI_Comm_free is called before MPI_Finalize
authorJonathan Perry-Houts <jperryh2@uoregon.edu>
Wed, 31 Aug 2016 18:08:29 +0000 (11:08 -0700)
committerMatthias Maier <tamiko@43-1.org>
Thu, 1 Sep 2016 23:54:16 +0000 (18:54 -0500)
include/deal.II/base/mpi.h
source/base/mpi.cc
source/distributed/tria.cc

index 183d141db24dbddcefe6c62f701f724af5bf378a..e13d84a9eac00aad467de1ece166790361ec91c6 100644 (file)
@@ -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 <code>main()</code>. The constructor of this
      * class then runs <code>MPI_Init()</code> with the given arguments. At
index ea24b30826614effa692224f48b6e669d07fa29e..f5c403711f0959f5428f8666be88b8fd62e21a9d 100644 (file)
 #  endif
 #endif
 
+#ifdef DEAL_II_WITH_P4EST
+#   include <p4est_bits.h>
+#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
index f8b7009a106c3359365bc6ec8b5c7c97ab7df9d9..21f75414bb3671f33504a2484c1908e49cdaa9b6 100644 (file)
@@ -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;
     }
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.