]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Reintegrate do_init into constructor of MPI_InitFinalize.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 5 Jan 2015 15:17:20 +0000 (09:17 -0600)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 9 Jan 2015 06:56:07 +0000 (00:56 -0600)
This is possible now that we have only one constructor left.

include/deal.II/base/mpi.h
source/base/mpi.cc

index e48796095a103f34d3c873089c912ee01f4f8d4a..9b1d4900d435dfc66dfbb19cc48fdfc981201610 100644 (file)
@@ -323,13 +323,6 @@ namespace Utilities
        * be called at destruction.
        */
       const bool owns_mpi;
-
-
-      /**
-       * A common function called by all of the constructors.
-       */
-      void do_init(int    &argc,
-                   char ** &argv);
     };
 
     namespace internal
index 0abcc758e8cda6657c2d9fdbe0a7d0b62e0bf6ae..7f25575378b74d3bea75f7dcaeb5b5bd85bbf781 100644 (file)
@@ -320,8 +320,58 @@ namespace Utilities
       :
       owns_mpi (true)
     {
-      do_init(argc, argv);
+      static bool constructor_has_already_run = false;
+      Assert (constructor_has_already_run == false,
+              ExcMessage ("You can only create a single object of this class "
+                          "in a program since it initializes the MPI system."));
+
+
+
+#ifdef DEAL_II_WITH_MPI
+      // if we have PETSc, we will initialize it and let it handle MPI.
+      // Otherwise, we will do it.
+      int MPI_has_been_started = 0;
+      MPI_Initialized(&MPI_has_been_started);
+      AssertThrow (MPI_has_been_started == 0,
+                   ExcMessage ("MPI error. You can only start MPI once!"));
+
+      int mpi_err, provided;
+      // this works likempi_err = MPI_Init (&argc, &argv); but tells MPI that
+      // we might use several threads but never call two MPI functions at the
+      // same time. For an explanation see on why we do this see
+      // http://www.open-mpi.org/community/lists/users/2010/03/12244.php
+      int wanted = MPI_THREAD_SERIALIZED;
+      mpi_err = MPI_Init_thread(&argc, &argv, wanted, &provided);
+      AssertThrow (mpi_err == 0,
+                   ExcMessage ("MPI could not be initialized."));
+
+      // disable for now because at least some implementations always return MPI_THREAD_SINGLE.
+      //Assert(max_num_threads==1 || provided != MPI_THREAD_SINGLE,
+      //    ExcMessage("MPI reports that we are not allowed to use multiple threads."));
+#else
+      // make sure the compiler doesn't warn
+      // about these variables
+      (void)argc;
+      (void)argv;
+      (void)owns_mpi;
+#endif
+
+      // we are allowed to call MPI_Init ourselves and PETScInitialize will
+      // detect this. This allows us to use MPI_Init_thread instead.
+#ifdef DEAL_II_WITH_PETSC
+#  ifdef DEAL_II_WITH_SLEPC
+      // Initialize SLEPc (with PETSc):
+      SlepcInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
+#  else
+      // or just initialize PETSc alone:
+      PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
+#  endif
+#endif
+
+      constructor_has_already_run = true;
 
+
+      // Now also see how many threads we'd like to run
       if (max_num_threads != numbers::invalid_unsigned_int)
         {
           // set maximum number of threads (also respecting the environment
@@ -393,63 +443,6 @@ namespace Utilities
     }
 
 
-
-    void
-    MPI_InitFinalize::do_init(int    &argc,
-                              char ** &argv)
-    {
-      static bool constructor_has_already_run = false;
-      Assert (constructor_has_already_run == false,
-              ExcMessage ("You can only create a single object of this class "
-                          "in a program since it initializes the MPI system."));
-
-
-
-#ifdef DEAL_II_WITH_MPI
-      // if we have PETSc, we will initialize it and let it handle MPI.
-      // Otherwise, we will do it.
-      int MPI_has_been_started = 0;
-      MPI_Initialized(&MPI_has_been_started);
-      AssertThrow (MPI_has_been_started == 0,
-                   ExcMessage ("MPI error. You can only start MPI once!"));
-
-      int mpi_err, provided;
-      // this works likempi_err = MPI_Init (&argc, &argv); but tells MPI that
-      // we might use several threads but never call two MPI functions at the
-      // same time. For an explanation see on why we do this see
-      // http://www.open-mpi.org/community/lists/users/2010/03/12244.php
-      int wanted = MPI_THREAD_SERIALIZED;
-      mpi_err = MPI_Init_thread(&argc, &argv, wanted, &provided);
-      AssertThrow (mpi_err == 0,
-                   ExcMessage ("MPI could not be initialized."));
-
-      // disable for now because at least some implementations always return MPI_THREAD_SINGLE.
-      //Assert(max_num_threads==1 || provided != MPI_THREAD_SINGLE,
-      //    ExcMessage("MPI reports that we are not allowed to use multiple threads."));
-#else
-      // make sure the compiler doesn't warn
-      // about these variables
-      (void)argc;
-      (void)argv;
-      (void)owns_mpi;
-#endif
-
-      // we are allowed to call MPI_Init ourselves and PETScInitialize will
-      // detect this. This allows us to use MPI_Init_thread instead.
-#ifdef DEAL_II_WITH_PETSC
-#  ifdef DEAL_II_WITH_SLEPC
-      // Initialize SLEPc (with PETSc):
-      SlepcInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
-#  else
-      // or just initialize PETSc alone:
-      PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
-#  endif
-#endif
-
-      constructor_has_already_run = true;
-    }
-
-
     MPI_InitFinalize::~MPI_InitFinalize()
     {
       // make memory pool release all PETSc/Trilinos/MPI-based vectors that are no

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.