64 [[maybe_unused]]
char **&argv,
66 const unsigned int max_num_threads)
67 : libraries(libraries)
69 [[maybe_unused]]
static bool constructor_has_already_run =
false;
70 Assert(constructor_has_already_run ==
false,
71 ExcMessage(
"You can only create a single object of this class "
72 "in a program since it initializes the MPI system."));
75 [[maybe_unused]]
int ierr = 0;
76#ifdef DEAL_II_WITH_MPI
81 int MPI_has_been_started = 0;
82 ierr = MPI_Initialized(&MPI_has_been_started);
85 ExcMessage(
"MPI error. You can only start MPI once!"));
92 int wanted = MPI_THREAD_SERIALIZED;
93 ierr = MPI_Init_thread(&argc, &argv, wanted, &provided);
106#ifdef DEAL_II_WITH_PETSC
107 PetscErrorCode pierr;
108# ifdef DEAL_II_WITH_SLEPC
113 pierr = SlepcInitialize(&argc, &argv,
nullptr,
nullptr);
121 pierr = PetscInitialize(&argc, &argv,
nullptr,
nullptr);
131 pierr = PetscPopSignalHandler();
137#ifdef DEAL_II_TRILINOS_WITH_ZOLTAN
141 Zoltan_Initialize(argc, argv, &version);
146#ifdef DEAL_II_WITH_P4EST
149# if DEAL_II_P4EST_VERSION_GTE(2, 5, 0, 0)
154 sc_init(MPI_COMM_WORLD, 0, 0,
nullptr, SC_LP_SILENT);
156 p4est_init(
nullptr, SC_LP_SILENT);
160 constructor_has_already_run =
true;
175#ifdef DEAL_II_WITH_MPI
178 int MPI_has_been_started = 0;
179 int ierr = MPI_Initialized(&MPI_has_been_started);
191 int my_hostname_size = hostname.size() + 1;
192 int max_hostname_size = -1;
193 ierr = MPI_Allreduce(&my_hostname_size,
200 std::vector<char> hostname_array(max_hostname_size);
201 std::copy(hostname.c_str(),
202 hostname.c_str() + hostname.size() + 1,
203 hostname_array.begin());
205 int n_mpi_processes = 1;
206 if (MPI_has_been_started)
208 ierr = MPI_Comm_size(MPI_COMM_WORLD, &n_mpi_processes);
211 std::vector<char> all_hostnames(max_hostname_size * n_mpi_processes);
212 ierr = MPI_Allgather(hostname_array.data(),
215 all_hostnames.data(),
223 unsigned int n_local_processes = 0;
224 unsigned int nth_process_on_host = 0;
226 if (MPI_has_been_started)
228 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
231 for (
int i = 0; i < n_mpi_processes; ++i)
232 if (std::string(all_hostnames.data() + i * max_hostname_size) ==
237 ++nth_process_on_host;
250 (nth_process_on_host <=
274 std::vector<char *> argv_new;
276 if (strcmp(arg,
"--help") != 0)
277 argv_new.push_back(arg);
279 std::stringstream threads_flag;
280#if KOKKOS_VERSION >= 30700
285 const std::string threads_flag_string = threads_flag.str();
286 argv_new.push_back(
const_cast<char *
>(threads_flag_string.c_str()));
287 argv_new.push_back(
nullptr);
292 int argc_new = argv_new.size() - 1;
293 Kokkos::initialize(argc_new, argv_new.data());
340#ifdef DEAL_II_WITH_MPI
344 const int ierr = MPI_Wait(request, MPI_STATUS_IGNORE);
352 release_unused_memory();
356 release_unused_memory();
359# ifdef DEAL_II_WITH_TRILINOS
370#ifdef DEAL_II_WITH_PETSC
371 if (!PetscFinalizeCalled)
378# ifdef DEAL_II_WITH_SLEPC
383 PetscErrorCode ierr = SlepcFinalize();
392 PetscErrorCode ierr = PetscFinalize();
398#ifdef DEAL_II_WITH_P4EST
413#ifdef DEAL_II_WITH_MPI
414 int MPI_has_been_started = 0;
415 const int ierr = MPI_Initialized(&MPI_has_been_started);
418 (MPI_has_been_started))
420 if (std::uncaught_exceptions() > 0)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)