82 [[maybe_unused]]
char **&argv,
84 const unsigned int max_num_threads)
85 : libraries(libraries)
87 static bool constructor_has_already_run =
false;
88 Assert(constructor_has_already_run ==
false,
89 ExcMessage(
"You can only create a single object of this class "
90 "in a program since it initializes the MPI system."));
93 [[maybe_unused]]
int ierr = 0;
94#ifdef DEAL_II_WITH_MPI
97# ifdef DEAL_II_HAVE_FP_EXCEPTIONS
109 ierr = fegetenv(&fe_state);
112 fedisableexcept(FE_DIVBYZERO | FE_INVALID);
117 int MPI_has_been_started = 0;
118 ierr = MPI_Initialized(&MPI_has_been_started);
121 ExcMessage(
"MPI error. You can only start MPI once!"));
128 int wanted = MPI_THREAD_SERIALIZED;
129 ierr = MPI_Init_thread(&argc, &argv, wanted, &provided);
138# ifdef DEAL_II_HAVE_FP_EXCEPTIONS
139 ierr = fesetenv(&fe_state);
147#ifdef DEAL_II_WITH_PETSC
148 PetscErrorCode pierr;
149# ifdef DEAL_II_WITH_SLEPC
154 pierr = SlepcInitialize(&argc, &argv,
nullptr,
nullptr);
162 pierr = PetscInitialize(&argc, &argv,
nullptr,
nullptr);
172 pierr = PetscPopSignalHandler();
178#ifdef DEAL_II_TRILINOS_WITH_ZOLTAN
182 Zoltan_Initialize(argc, argv, &version);
187#ifdef DEAL_II_WITH_P4EST
190# if DEAL_II_P4EST_VERSION_GTE(2, 5, 0, 0)
195 sc_init(MPI_COMM_WORLD, 0, 0,
nullptr, SC_LP_SILENT);
197 p4est_init(
nullptr, SC_LP_SILENT);
202#ifdef DEAL_II_WITH_PSBLAS
205 cctxt = psb_c_new_ctxt();
208 "Failed to create PSBLAS context during MPI initialization."));
210 psb_c_set_index_base(0);
215#ifdef DEAL_II_GMSH_WITH_API
220 constructor_has_already_run =
true;
235#ifdef DEAL_II_WITH_MPI
238 int MPI_has_been_started = 0;
239 int ierr = MPI_Initialized(&MPI_has_been_started);
251 int my_hostname_size = hostname.size() + 1;
252 int max_hostname_size = -1;
253 ierr = MPI_Allreduce(&my_hostname_size,
260 std::vector<char> hostname_array(max_hostname_size);
261 std::copy(hostname.c_str(),
262 hostname.c_str() + hostname.size() + 1,
263 hostname_array.begin());
265 int n_mpi_processes = 1;
266 if (MPI_has_been_started)
268 ierr = MPI_Comm_size(MPI_COMM_WORLD, &n_mpi_processes);
271 std::vector<char> all_hostnames(max_hostname_size * n_mpi_processes);
272 ierr = MPI_Allgather(hostname_array.data(),
275 all_hostnames.data(),
283 unsigned int n_local_processes = 0;
284 unsigned int nth_process_on_host = 0;
286 if (MPI_has_been_started)
288 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
291 for (
int i = 0; i < n_mpi_processes; ++i)
292 if (std::string(all_hostnames.data() + i * max_hostname_size) ==
297 ++nth_process_on_host;
310 (nth_process_on_host <=
334 std::vector<char *> argv_new;
336 if (std::strcmp(arg,
"--help") != 0)
337 argv_new.push_back(arg);
339 std::stringstream threads_flag;
340#if DEAL_II_KOKKOS_VERSION_GTE(3, 7, 0)
345 const std::string threads_flag_string = threads_flag.str();
346 argv_new.push_back(
const_cast<char *
>(threads_flag_string.c_str()));
347 argv_new.push_back(
nullptr);
352 int argc_new = argv_new.size() - 1;
353 Kokkos::initialize(argc_new, argv_new.data());
410#ifdef DEAL_II_WITH_MPI
414 const int ierr = MPI_Wait(request, MPI_STATUS_IGNORE);
422 release_unused_memory();
426 release_unused_memory();
429# ifdef DEAL_II_TRILINOS_WITH_EPETRA
440#ifdef DEAL_II_WITH_PETSC
441 if (!PetscFinalizeCalled)
448# ifdef DEAL_II_WITH_SLEPC
453 PetscErrorCode ierr = SlepcFinalize();
462 PetscErrorCode ierr = PetscFinalize();
468#ifdef DEAL_II_WITH_P4EST
475#ifdef DEAL_II_WITH_PSBLAS
478 psb_c_exit_ctxt(*cctxt);
490#ifdef DEAL_II_WITH_MPI
491 int MPI_has_been_started = 0;
492 const int ierr = MPI_Initialized(&MPI_has_been_started);
495 (MPI_has_been_started))
497 if (std::uncaught_exceptions() > 0)
512#ifdef DEAL_II_GMSH_WITH_API