20#include <deal.II/base/mpi.templates.h>
33#include <boost/serialization/utility.hpp>
35#include <Kokkos_Core.hpp>
43#ifdef DEAL_II_WITH_TRILINOS
44# ifdef DEAL_II_WITH_MPI
48# include <Epetra_MpiComm.h>
52#ifdef DEAL_II_WITH_PETSC
59#ifdef DEAL_II_WITH_SLEPC
65#ifdef DEAL_II_WITH_P4EST
66# include <p4est_bits.h>
69#ifdef DEAL_II_TRILINOS_WITH_ZOLTAN
70# include <zoltan_cpp.h>
85 std::is_same<types::global_dof_index, IndexSet::size_type>::value,
86 "IndexSet::size_type must match types::global_dof_index for "
87 "using this function");
97 result.add_range(begin, end);
103#ifdef DEAL_II_WITH_MPI
136 std::vector<MinMaxAvg>
148#ifdef DEAL_II_WITH_MPI
172 const std::vector<unsigned int>
177 return std::vector<unsigned int>{0};
182 std::vector<unsigned int>
ranks(size);
226 std::vector<IndexSet>
232 std::is_same<types::global_dof_index, IndexSet::size_type>::value,
233 "IndexSet::size_type must match types::global_dof_index for "
234 "using this function");
236 const std::vector<IndexSet::size_type> sizes =
238 const auto total_size =
244 for (
unsigned int i = 0; i <
n_proc; ++i)
246 res[i].add_range(begin, begin + sizes[i]);
247 begin = begin + sizes[i];
307 return std::unique_ptr<MPI_Datatype, void (*)(MPI_Datatype *)>(
313 std::vector<unsigned int>
355 return ConsensusAlgorithms::nbx<char, char>(
418 send_requests.data(),
451 return ConsensusAlgorithms::nbx<char, char>(
457 const unsigned int n_procs =
466 "There is no point in communicating with ourselves."));
502 const MinMaxAvg *
in_lhs =
static_cast<const MinMaxAvg *
>(
in_lhs_);
505 for (
int i = 0; i < *
len; ++i)
602 static_cast<int>(
true),
624 std::numeric_limits<double>::max(),
625 std::numeric_limits<double>::lowest(),
633 const unsigned int my_id =
642 in[i].sum = in[i].min = in[i].max =
my_values[i];
643 in[i].min_index = in[i].max_index = my_id;
673 const std::vector<unsigned int>
676 return std::vector<unsigned int>{0};
681 std::vector<IndexSet>
702 return mpi_communicator;
734 MPI_InitFinalize::Signals();
744 ExcMessage(
"You can only create a single object of this class "
745 "in a program since it initializes the MPI system."));
749#ifdef DEAL_II_WITH_MPI
756 ExcMessage(
"MPI error. You can only start MPI once!"));
796#if KOKKOS_VERSION >= 30700
814#ifdef DEAL_II_WITH_PETSC
815# ifdef DEAL_II_WITH_SLEPC
833#ifdef DEAL_II_TRILINOS_WITH_ZOLTAN
838#ifdef DEAL_II_WITH_P4EST
840# if DEAL_II_P4EST_VERSION_GTE(2, 5, 0, 0)
864#ifdef DEAL_II_WITH_MPI
913 const unsigned int n_threads =
949 "You tried to call unregister_request() with an invalid request."));
970#ifdef DEAL_II_WITH_MPI
989# ifdef DEAL_II_WITH_TRILINOS
1000#ifdef DEAL_II_WITH_PETSC
1008# ifdef DEAL_II_WITH_SLEPC
1019#ifdef DEAL_II_WITH_P4EST
1032#ifdef DEAL_II_WITH_MPI
1035# if __cpp_lib_uncaught_exceptions >= 201411
1037 if (std::uncaught_exceptions() > 0)
1039 if (std::uncaught_exception() ==
true)
1059#ifdef DEAL_II_WITH_MPI
1072 std::vector<unsigned int>
1074 const IndexSet &indices_to_look_up,
1078 ExcMessage(
"IndexSets have to have the same sizes."));
1082 ExcMessage(
"IndexSets have to have the same size on all processes."));
1084 std::vector<unsigned int> owning_ranks(indices_to_look_up.
n_elements());
1092 owned_indices, indices_to_look_up,
comm, owning_ranks);
1100 std::pair<types::global_dof_index, types::global_dof_index>>,
1101 std::vector<unsigned int>>
1105 return owning_ranks;
1112 namespace CollectiveMutexImplementation
1121#ifdef DEAL_II_WITH_MPI
1122# if __cpp_lib_uncaught_exceptions >= 201411
1124 if (std::uncaught_exceptions() != 0)
1126 if (std::uncaught_exception() ==
true)
1130 <<
"---------------------------------------------------------\n"
1131 <<
"An exception was thrown inside a section of the program\n"
1132 <<
"guarded by a CollectiveMutex.\n"
1133 <<
"Because a CollectiveMutex guards critical communication\n"
1134 <<
"handling the exception would likely\n"
1135 <<
"deadlock because only the current process is aware of the\n"
1136 <<
"exception. To prevent this deadlock, the program will be\n"
1138 <<
"---------------------------------------------------------"
1168 "Error: MPI::CollectiveMutex is still locked while being destroyed!"));
1183 "Error: MPI::CollectiveMutex needs to be unlocked before lock()"));
1185#ifdef DEAL_II_WITH_MPI
1221 "Error: MPI::CollectiveMutex needs to be locked before unlock()"));
1223#ifdef DEAL_II_WITH_MPI
1248 const std::function<
bool(
const bool &,
const bool &)> &,
1249 const unsigned int);
1251 template std::vector<bool>
1252 reduce(
const std::vector<bool> &,
1254 const std::function<std::vector<bool>(
const std::vector<bool> &,
1255 const std::vector<bool> &)> &,
1256 const unsigned int);
1261 const std::function<
bool(
const bool &,
const bool &)> &);
1263 template std::vector<bool>
1265 const std::vector<bool> &,
1267 const std::function<std::vector<bool>(
const std::vector<bool> &,
1268 const std::vector<bool> &)> &);
1273 internal::all_reduce<bool>(
const MPI_Op &,
1289 template std::vector<unsigned int>
1294 template std::set<unsigned int>
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
value_type * data() const noexcept
size_type n_elements() const
static unsigned int n_cores()
static unsigned int n_threads()
static void set_thread_limit(const unsigned int max_threads=numbers::invalid_unsigned_int)
void lock(const MPI_Comm comm)
void unlock(const MPI_Comm comm)
static void unregister_request(MPI_Request &request)
static std::set< MPI_Request * > requests
MPI_InitFinalize(int &argc, char **&argv, const unsigned int max_num_threads=numbers::invalid_unsigned_int)
static void register_request(MPI_Request &request)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcSLEPcError(int arg1)
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertNothrow(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
IndexSet complete_index_set(const IndexSet::size_type N)
int Type_contiguous_c(MPI_Count count, MPI_Datatype oldtype, MPI_Datatype *newtype)
std::vector< IndexSet > create_ascending_partitioning(const MPI_Comm comm, const types::global_dof_index locally_owned_size)
std::unique_ptr< MPI_Datatype, void(*)(MPI_Datatype *)> create_mpi_data_type_n_bytes(const std::size_t n_bytes)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
T max(const T &t, const MPI_Comm mpi_communicator)
T min(const T &t, const MPI_Comm mpi_communicator)
std::vector< T > all_gather(const MPI_Comm comm, const T &object_to_send)
std::vector< unsigned int > compute_index_owner(const IndexSet &owned_indices, const IndexSet &indices_to_look_up, const MPI_Comm comm)
std::vector< T > compute_set_union(const std::vector< T > &vec, const MPI_Comm comm)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
T all_reduce(const T &local_value, const MPI_Comm comm, const std::function< T(const T &, const T &)> &combiner)
IndexSet create_evenly_distributed_partitioning(const MPI_Comm comm, const types::global_dof_index total_size)
std::vector< unsigned int > compute_point_to_point_communication_pattern(const MPI_Comm mpi_comm, const std::vector< unsigned int > &destinations)
int create_group(const MPI_Comm comm, const MPI_Group &group, const int tag, MPI_Comm *new_comm)
MPI_Comm duplicate_communicator(const MPI_Comm mpi_communicator)
const std::vector< unsigned int > mpi_processes_within_communicator(const MPI_Comm comm_large, const MPI_Comm comm_small)
T reduce(const T &local_value, const MPI_Comm comm, const std::function< T(const T &, const T &)> &combiner, const unsigned int root_process=0)
void free_communicator(MPI_Comm mpi_communicator)
unsigned int compute_n_point_to_point_communications(const MPI_Comm mpi_comm, const std::vector< unsigned int > &destinations)
MinMaxAvg min_max_avg(const double my_value, const MPI_Comm mpi_communicator)
std::string get_hostname()
IndexSet create_evenly_distributed_partitioning(const unsigned int my_partition_id, const unsigned int n_partitions, const types::global_dof_index total_size)
static const unsigned int invalid_unsigned_int
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)