85 [[maybe_unused]]
char **&argv,
87 const unsigned int max_num_threads)
88 : libraries(libraries)
90 static bool constructor_has_already_run =
false;
91 Assert(constructor_has_already_run ==
false,
92 ExcMessage(
"You can only create a single object of this class "
93 "in a program since it initializes the MPI system."));
96 [[maybe_unused]]
int ierr = 0;
97#ifdef DEAL_II_WITH_MPI
100# ifdef DEAL_II_HAVE_FP_EXCEPTIONS
112 ierr = fegetenv(&fe_state);
115 fedisableexcept(FE_DIVBYZERO | FE_INVALID);
120 int MPI_has_been_started = 0;
121 ierr = MPI_Initialized(&MPI_has_been_started);
124 ExcMessage(
"MPI error. You can only start MPI once!"));
131 int wanted = MPI_THREAD_SERIALIZED;
132 ierr = MPI_Init_thread(&argc, &argv, wanted, &provided);
141# ifdef DEAL_II_HAVE_FP_EXCEPTIONS
142 ierr = fesetenv(&fe_state);
150#ifdef DEAL_II_WITH_PETSC
151 PetscErrorCode pierr;
152# ifdef DEAL_II_WITH_SLEPC
157 pierr = SlepcInitialize(&argc, &argv,
nullptr,
nullptr);
165 pierr = PetscInitialize(&argc, &argv,
nullptr,
nullptr);
175 pierr = PetscPopSignalHandler();
181#ifdef DEAL_II_TRILINOS_WITH_ZOLTAN
185 Zoltan_Initialize(argc, argv, &version);
190#ifdef DEAL_II_WITH_P4EST
193# if DEAL_II_P4EST_VERSION_GTE(2, 5, 0, 0)
198 sc_init(MPI_COMM_WORLD, 0, 0,
nullptr, SC_LP_SILENT);
200 p4est_init(
nullptr, SC_LP_SILENT);
205#ifdef DEAL_II_WITH_PSBLAS
208 cctxt = psb_c_new_ctxt();
211 "Failed to create PSBLAS context during MPI initialization."));
213 psb_c_set_index_base(0);
218#ifdef DEAL_II_GMSH_WITH_API
223 constructor_has_already_run =
true;
238#ifdef DEAL_II_WITH_MPI
241 int MPI_has_been_started = 0;
242 int ierr = MPI_Initialized(&MPI_has_been_started);
254 int my_hostname_size = hostname.size() + 1;
255 int max_hostname_size = -1;
256 ierr = MPI_Allreduce(&my_hostname_size,
263 std::vector<char> hostname_array(max_hostname_size);
264 std::copy(hostname.c_str(),
265 hostname.c_str() + hostname.size() + 1,
266 hostname_array.begin());
268 int n_mpi_processes = 1;
269 if (MPI_has_been_started)
271 ierr = MPI_Comm_size(MPI_COMM_WORLD, &n_mpi_processes);
274 std::vector<char> all_hostnames(max_hostname_size * n_mpi_processes);
275 ierr = MPI_Allgather(hostname_array.data(),
278 all_hostnames.data(),
286 unsigned int n_local_processes = 0;
287 unsigned int nth_process_on_host = 0;
289 if (MPI_has_been_started)
291 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
294 for (
int i = 0; i < n_mpi_processes; ++i)
295 if (std::string(all_hostnames.data() + i * max_hostname_size) ==
300 ++nth_process_on_host;
313 (nth_process_on_host <=
337 std::vector<char *> argv_new;
339 if (std::strcmp(arg,
"--help") != 0)
340 argv_new.push_back(arg);
342 std::stringstream threads_flag;
343#if DEAL_II_KOKKOS_VERSION_GTE(3, 7, 0)
348 const std::string threads_flag_string = threads_flag.str();
349 argv_new.push_back(
const_cast<char *
>(threads_flag_string.c_str()));
350 argv_new.push_back(
nullptr);
355 int argc_new = argv_new.size() - 1;
356 Kokkos::initialize(argc_new, argv_new.data());
413#ifdef DEAL_II_WITH_MPI
417 const int ierr = MPI_Wait(request, MPI_STATUS_IGNORE);
425 release_unused_memory();
429 release_unused_memory();
432# ifdef DEAL_II_TRILINOS_WITH_EPETRA
443#ifdef DEAL_II_WITH_PETSC
444 if (!PetscFinalizeCalled)
451# ifdef DEAL_II_WITH_SLEPC
456 PetscErrorCode ierr = SlepcFinalize();
465 PetscErrorCode ierr = PetscFinalize();
471#ifdef DEAL_II_WITH_P4EST
478#ifdef DEAL_II_WITH_PSBLAS
481 psb_c_exit_ctxt(*cctxt);
493#ifdef DEAL_II_WITH_MPI
494 int MPI_has_been_started = 0;
495 const int ierr = MPI_Initialized(&MPI_has_been_started);
498 (MPI_has_been_started))
500 if (std::uncaught_exceptions() > 0)
515#ifdef DEAL_II_GMSH_WITH_API