:
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
}
-
- 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