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);
122 std::vector<char *> argv_new;
124 if (strcmp(arg,
"--help") != 0)
125 argv_new.push_back(arg);
127 std::stringstream threads_flag;
128#if KOKKOS_VERSION >= 30700
133 const std::string threads_flag_string = threads_flag.str();
134 argv_new.push_back(
const_cast<char *
>(threads_flag_string.c_str()));
135 argv_new.push_back(
nullptr);
140 int argc_new = argv_new.size() - 1;
141 Kokkos::initialize(argc_new, argv_new.data());
146#ifdef DEAL_II_WITH_PETSC
147 PetscErrorCode pierr;
148# ifdef DEAL_II_WITH_SLEPC
153 pierr = SlepcInitialize(&argc, &argv,
nullptr,
nullptr);
161 pierr = PetscInitialize(&argc, &argv,
nullptr,
nullptr);
171 pierr = PetscPopSignalHandler();
177#ifdef DEAL_II_TRILINOS_WITH_ZOLTAN
181 Zoltan_Initialize(argc, argv, &version);
186#ifdef DEAL_II_WITH_P4EST
189# if DEAL_II_P4EST_VERSION_GTE(2, 5, 0, 0)
194 sc_init(MPI_COMM_WORLD, 0, 0,
nullptr, SC_LP_SILENT);
196 p4est_init(
nullptr, SC_LP_SILENT);
200 constructor_has_already_run =
true;
215#ifdef DEAL_II_WITH_MPI
218 int MPI_has_been_started = 0;
219 int ierr = MPI_Initialized(&MPI_has_been_started);
231 int my_hostname_size = hostname.size() + 1;
232 int max_hostname_size = -1;
233 ierr = MPI_Allreduce(&my_hostname_size,
240 std::vector<char> hostname_array(max_hostname_size);
241 std::copy(hostname.c_str(),
242 hostname.c_str() + hostname.size() + 1,
243 hostname_array.begin());
245 int n_mpi_processes = 1;
246 if (MPI_has_been_started)
248 ierr = MPI_Comm_size(MPI_COMM_WORLD, &n_mpi_processes);
251 std::vector<char> all_hostnames(max_hostname_size * n_mpi_processes);
252 ierr = MPI_Allgather(hostname_array.data(),
255 all_hostnames.data(),
263 unsigned int n_local_processes = 0;
264 unsigned int nth_process_on_host = 0;
266 if (MPI_has_been_started)
268 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
271 for (
int i = 0; i < n_mpi_processes; ++i)
272 if (std::string(all_hostnames.data() + i * max_hostname_size) ==
277 ++nth_process_on_host;
290 (nth_process_on_host <=
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 > &)