68 [[maybe_unused]]
char **&argv,
70 const unsigned int max_num_threads)
71 : libraries(libraries)
73 [[maybe_unused]]
static bool constructor_has_already_run =
false;
74 Assert(constructor_has_already_run ==
false,
75 ExcMessage(
"You can only create a single object of this class "
76 "in a program since it initializes the MPI system."));
79 [[maybe_unused]]
int ierr = 0;
80#ifdef DEAL_II_WITH_MPI
85 int MPI_has_been_started = 0;
86 ierr = MPI_Initialized(&MPI_has_been_started);
89 ExcMessage(
"MPI error. You can only start MPI once!"));
96 int wanted = MPI_THREAD_SERIALIZED;
97 ierr = MPI_Init_thread(&argc, &argv, wanted, &provided);
110#ifdef DEAL_II_WITH_PETSC
111 PetscErrorCode pierr;
112# ifdef DEAL_II_WITH_SLEPC
117 pierr = SlepcInitialize(&argc, &argv,
nullptr,
nullptr);
125 pierr = PetscInitialize(&argc, &argv,
nullptr,
nullptr);
135 pierr = PetscPopSignalHandler();
141#ifdef DEAL_II_TRILINOS_WITH_ZOLTAN
145 Zoltan_Initialize(argc, argv, &version);
150#ifdef DEAL_II_WITH_P4EST
153# if DEAL_II_P4EST_VERSION_GTE(2, 5, 0, 0)
158 sc_init(MPI_COMM_WORLD, 0, 0,
nullptr, SC_LP_SILENT);
160 p4est_init(
nullptr, SC_LP_SILENT);
164 constructor_has_already_run =
true;
179#ifdef DEAL_II_WITH_MPI
182 int MPI_has_been_started = 0;
183 int ierr = MPI_Initialized(&MPI_has_been_started);
195 int my_hostname_size = hostname.size() + 1;
196 int max_hostname_size = -1;
197 ierr = MPI_Allreduce(&my_hostname_size,
204 std::vector<char> hostname_array(max_hostname_size);
205 std::copy(hostname.c_str(),
206 hostname.c_str() + hostname.size() + 1,
207 hostname_array.begin());
209 int n_mpi_processes = 1;
210 if (MPI_has_been_started)
212 ierr = MPI_Comm_size(MPI_COMM_WORLD, &n_mpi_processes);
215 std::vector<char> all_hostnames(max_hostname_size * n_mpi_processes);
216 ierr = MPI_Allgather(hostname_array.data(),
219 all_hostnames.data(),
227 unsigned int n_local_processes = 0;
228 unsigned int nth_process_on_host = 0;
230 if (MPI_has_been_started)
232 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
235 for (
int i = 0; i < n_mpi_processes; ++i)
236 if (std::string(all_hostnames.data() + i * max_hostname_size) ==
241 ++nth_process_on_host;
254 (nth_process_on_host <=
278 std::vector<char *> argv_new;
280 if (std::strcmp(arg,
"--help") != 0)
281 argv_new.push_back(arg);
283 std::stringstream threads_flag;
284#if DEAL_II_KOKKOS_VERSION_GTE(3, 7, 0)
289 const std::string threads_flag_string = threads_flag.str();
290 argv_new.push_back(
const_cast<char *
>(threads_flag_string.c_str()));
291 argv_new.push_back(
nullptr);
296 int argc_new = argv_new.size() - 1;
297 Kokkos::initialize(argc_new, argv_new.data());
344#ifdef DEAL_II_WITH_MPI
348 const int ierr = MPI_Wait(request, MPI_STATUS_IGNORE);
356 release_unused_memory();
360 release_unused_memory();
363# ifdef DEAL_II_WITH_TRILINOS
374#ifdef DEAL_II_WITH_PETSC
375 if (!PetscFinalizeCalled)
382# ifdef DEAL_II_WITH_SLEPC
387 PetscErrorCode ierr = SlepcFinalize();
396 PetscErrorCode ierr = PetscFinalize();
402#ifdef DEAL_II_WITH_P4EST
417#ifdef DEAL_II_WITH_MPI
418 int MPI_has_been_started = 0;
419 const int ierr = MPI_Initialized(&MPI_has_been_started);
422 (MPI_has_been_started))
424 if (std::uncaught_exceptions() > 0)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)