18#ifdef DEAL_II_WITH_PETSC
26# define AssertPETSc(code) \
29 PetscErrorCode ierr = (code); \
30 AssertThrow(ierr == 0, ExcPETScError(ierr)); \
53 AssertPETSc(PetscLayoutCreate(communicator, &layout));
54 AssertPETSc(PetscLayoutSetLocalSize(layout, local_size));
58 AssertPETSc(PetscLayoutGetRange(layout, &start, &end));
73 PetscSFSetGraphLayout(
sf, layout, n,
nullptr, PETSC_OWN_POINTER, idxs));
86 std::vector<types::global_dof_index> in_deal;
88 std::vector<PetscInt> in_petsc(in_deal.begin(), in_deal.end());
90 std::vector<types::global_dof_index> out_deal;
92 std::vector<PetscInt> out_petsc(out_deal.begin(), out_deal.end());
94 std::vector<PetscInt> dummy;
96 this->
do_reinit(in_petsc, dummy, out_petsc, dummy, communicator);
101 const std::vector<types::global_dof_index> &indices_has,
102 const std::vector<types::global_dof_index> &indices_want,
106 std::vector<PetscInt> indices_has_clean, indices_has_loc;
107 std::vector<PetscInt> indices_want_clean, indices_want_loc;
108 indices_want_clean.reserve(indices_want.size());
109 indices_want_loc.reserve(indices_want.size());
110 indices_has_clean.reserve(indices_has.size());
111 indices_has_loc.reserve(indices_has.size());
114 bool has_invalid =
false;
115 for (
const auto i : indices_has)
119 indices_has_clean.push_back(
static_cast<PetscInt
>(i));
120 indices_has_loc.push_back(loc);
127 indices_has_loc.clear();
131 for (
const auto i : indices_want)
135 indices_want_clean.push_back(
static_cast<PetscInt
>(i));
136 indices_want_loc.push_back(loc);
143 indices_want_loc.clear();
154 const std::vector<PetscInt> &inloc,
155 const std::vector<PetscInt> &outidx,
156 const std::vector<PetscInt> &outloc,
175 PetscInt n =
static_cast<PetscInt
>(inidx.size());
176 PetscInt lN = n > 0 ? *std::max_element(inidx.begin(), inidx.end()) : -1;
179 Utilities::MPI::internal::all_reduce<PetscInt>(
185 PetscSFNode *remotes;
189 AssertPETSc(PetscLayoutCreate(communicator, &layout));
194 const PetscInt *ranges;
195 AssertPETSc(PetscLayoutGetRanges(layout, &ranges));
198 PetscMPIInt owner = 0;
199 for (
const auto idx : inidx)
202 if (idx < ranges[owner] || ranges[owner + 1] <= idx)
204 AssertPETSc(PetscLayoutFindOwner(layout, idx, &owner));
206 remotes[cnt].rank = owner;
207 remotes[cnt].index = idx - ranges[owner];
215 const_cast<PetscInt *
>(
216 inloc.size() > 0 ? inloc.data() :
nullptr),
226 n =
static_cast<PetscInt
>(outidx.size());
232 const_cast<PetscInt *
>(outloc.size() > 0 ? outloc.data() :
nullptr),
234 const_cast<PetscInt *
>(n > 0 ? outidx.data() :
nullptr)));
255 return PetscObjectComm(
reinterpret_cast<PetscObject
>(
sf));
258 template <
typename Number>
264 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
266# if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
270 PetscSFBcastBegin(
sf, datatype, src.
data(), dst.
data(), MPI_REPLACE));
274 template <
typename Number>
280 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
282# if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
286 PetscSFBcastEnd(
sf, datatype, src.
data(), dst.
data(), MPI_REPLACE));
290 template <
typename Number>
300 template <
typename Number>
308 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
311 PetscSFReduceBegin(
sf, datatype, src.
data(), dst.
data(), mpiop));
314 template <
typename Number>
322 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
327 template <
typename Number>
343 , ghost_indices_data()
344 , n_ghost_indices_data(
numbers::invalid_dof_index)
345 , n_ghost_indices_larger(
numbers::invalid_dof_index)
367 const IndexSet &larger_ghost_indices,
370 std::vector<types::global_dof_index> local_indices;
377 std::vector<types::global_dof_index> expanded_ghost_indices(
382 ExcMessage(
"The given larger ghost index set must contain "
383 "all indices in the actual index set."));
385 expanded_ghost_indices[tmp_index] = index;
400 template <
typename Number>
415 template <
typename Number>
431 template <
typename Number>
440 template <
typename Number>
457 template <
typename Number>
474 template <
typename Number>
487# include "petsc_communication_pattern.inst"
value_type * data() const noexcept
IS make_petsc_is(const MPI_Comm communicator=MPI_COMM_WORLD) const
void fill_index_vector(std::vector< size_type > &indices) const
size_type index_within_set(const size_type global_index) const
size_type n_elements() const
bool is_element(const size_type index) const
void subtract_set(const IndexSet &other)
void add_range(const size_type begin, const size_type end)
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
MPI_Comm get_mpi_communicator() const override
void import_from_ghosted_array(const VectorOperation::values op, const ArrayView< const Number > &ghost_array, const ArrayView< Number > &locally_owned_array) const
virtual ~CommunicationPattern() override
void export_to_ghosted_array_start(const ArrayView< const Number > &locally_owned_array, const ArrayView< Number > &ghost_array) const
void export_to_ghosted_array(const ArrayView< const Number > &locally_owned_array, const ArrayView< Number > &ghost_array) const
void export_to_ghosted_array_finish(const ArrayView< const Number > &locally_owned_array, const ArrayView< Number > &ghost_array) const
void import_from_ghosted_array_finish(const VectorOperation::values op, const ArrayView< const Number > &ghost_array, const ArrayView< Number > &locally_owned_array) const
void do_reinit(const std::vector< PetscInt > &inidx, const std::vector< PetscInt > &inloc, const std::vector< PetscInt > &outidx, const std::vector< PetscInt > &outloc, const MPI_Comm communicator)
virtual void reinit(const IndexSet &locally_owned_indices, const IndexSet &ghost_indices, const MPI_Comm communicator) override
void import_from_ghosted_array_start(const VectorOperation::values op, const ArrayView< const Number > &ghost_array, const ArrayView< Number > &locally_owned_array) const
types::global_dof_index n_ghost_indices_data
CommunicationPattern ghost
IndexSet ghost_indices_data
void import_from_ghosted_array(const VectorOperation::values op, const ArrayView< const Number > &ghost_array, const ArrayView< Number > &locally_owned_array) const
void export_to_ghosted_array_finish(const ArrayView< const Number > &locally_owned_array, const ArrayView< Number > &ghost_array) const
MPI_Comm get_mpi_communicator() const override
void export_to_ghosted_array(const ArrayView< const Number > &locally_owned_array, const ArrayView< Number > &ghost_array) const
const IndexSet & ghost_indices() const
void export_to_ghosted_array_start(const ArrayView< const Number > &locally_owned_array, const ArrayView< Number > &ghost_array) const
void import_from_ghosted_array_start(const VectorOperation::values op, const ArrayView< const Number > &ghost_array, const ArrayView< Number > &locally_owned_array) const
virtual void reinit(const IndexSet &locally_owned_indices, const IndexSet &ghost_indices, const MPI_Comm communicator) override
void import_from_ghosted_array_finish(const VectorOperation::values op, const ArrayView< const Number > &ghost_array, const ArrayView< Number > &locally_owned_array) const
CommunicationPattern larger_ghost
types::global_dof_index n_ghost_indices_larger
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
const types::global_dof_index invalid_dof_index
#define AssertPETSc(code)