66 const unsigned int max_num_threads)
67 : libraries(libraries)
69 static bool constructor_has_already_run =
false;
70 (void)constructor_has_already_run;
71 Assert(constructor_has_already_run ==
false,
72 ExcMessage(
"You can only create a single object of this class "
73 "in a program since it initializes the MPI system."));
77#ifdef DEAL_II_WITH_MPI
82 int MPI_has_been_started = 0;
83 ierr = MPI_Initialized(&MPI_has_been_started);
86 ExcMessage(
"MPI error. You can only start MPI once!"));
93 int wanted = MPI_THREAD_SERIALIZED;
94 ierr = MPI_Init_thread(&argc, &argv, wanted, &provided);
112#ifdef DEAL_II_WITH_PETSC
113 PetscErrorCode pierr;
114# ifdef DEAL_II_WITH_SLEPC
119 pierr = SlepcInitialize(&argc, &argv,
nullptr,
nullptr);
127 pierr = PetscInitialize(&argc, &argv,
nullptr,
nullptr);
137 pierr = PetscPopSignalHandler();
143#ifdef DEAL_II_TRILINOS_WITH_ZOLTAN
147 Zoltan_Initialize(argc, argv, &version);
152#ifdef DEAL_II_WITH_P4EST
155# if DEAL_II_P4EST_VERSION_GTE(2, 5, 0, 0)
160 sc_init(MPI_COMM_WORLD, 0, 0,
nullptr, SC_LP_SILENT);
162 p4est_init(
nullptr, SC_LP_SILENT);
166 constructor_has_already_run =
true;
181#ifdef DEAL_II_WITH_MPI
184 int MPI_has_been_started = 0;
185 int ierr = MPI_Initialized(&MPI_has_been_started);
197 int my_hostname_size = hostname.size() + 1;
198 int max_hostname_size = -1;
199 ierr = MPI_Allreduce(&my_hostname_size,
206 std::vector<char> hostname_array(max_hostname_size);
207 std::copy(hostname.c_str(),
208 hostname.c_str() + hostname.size() + 1,
209 hostname_array.begin());
211 int n_mpi_processes = 1;
212 if (MPI_has_been_started)
214 ierr = MPI_Comm_size(MPI_COMM_WORLD, &n_mpi_processes);
217 std::vector<char> all_hostnames(max_hostname_size * n_mpi_processes);
218 ierr = MPI_Allgather(hostname_array.data(),
221 all_hostnames.data(),
229 unsigned int n_local_processes = 0;
230 unsigned int nth_process_on_host = 0;
232 if (MPI_has_been_started)
234 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
237 for (
int i = 0; i < n_mpi_processes; ++i)
238 if (std::string(all_hostnames.data() + i * max_hostname_size) ==
243 ++nth_process_on_host;
256 (nth_process_on_host <=
280 std::vector<char *> argv_new;
282 if (strcmp(arg,
"--help") != 0)
283 argv_new.push_back(arg);
285 std::stringstream threads_flag;
286#if KOKKOS_VERSION >= 30700
291 const std::string threads_flag_string = threads_flag.str();
292 argv_new.push_back(
const_cast<char *
>(threads_flag_string.c_str()));
293 argv_new.push_back(
nullptr);
298 int argc_new = argv_new.size() - 1;
299 Kokkos::initialize(argc_new, argv_new.data());
346#ifdef DEAL_II_WITH_MPI
350 const int ierr = MPI_Wait(request, MPI_STATUS_IGNORE);
358 release_unused_memory();
362 release_unused_memory();
365# ifdef DEAL_II_WITH_TRILINOS
376#ifdef DEAL_II_WITH_PETSC
377 if (!PetscFinalizeCalled)
384# ifdef DEAL_II_WITH_SLEPC
389 PetscErrorCode ierr = SlepcFinalize();
398 PetscErrorCode ierr = PetscFinalize();
404#ifdef DEAL_II_WITH_P4EST
419#ifdef DEAL_II_WITH_MPI
420 int MPI_has_been_started = 0;
421 const int ierr = MPI_Initialized(&MPI_has_been_started);
424 (MPI_has_been_started))
426# if __cpp_lib_uncaught_exceptions >= 201411
428 if (std::uncaught_exceptions() > 0)
430 if (std::uncaught_exception() ==
true)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)