17#ifdef DEAL_II_WITH_PETSC
25# define AssertPETSc(code) \
28 PetscErrorCode ierr = (code); \
29 AssertThrow(ierr == 0, ExcPETScError(ierr)); \
56 AssertPETSc(PetscLayoutCreate(communicator, &layout));
57 AssertPETSc(PetscLayoutSetLocalSize(layout, local_size));
61 AssertPETSc(PetscLayoutGetRange(layout, &start, &end));
76 PetscSFSetGraphLayout(
sf, layout, n,
nullptr, PETSC_OWN_POINTER, idxs));
91 std::vector<types::global_dof_index> in_deal;
93 std::vector<PetscInt> in_petsc(in_deal.begin(), in_deal.end());
95 std::vector<types::global_dof_index> out_deal;
97 std::vector<PetscInt> out_petsc(out_deal.begin(), out_deal.end());
99 std::vector<PetscInt> dummy;
101 this->
do_reinit(in_petsc, dummy, out_petsc, dummy, communicator);
108 const std::vector<types::global_dof_index> &indices_has,
109 const std::vector<types::global_dof_index> &indices_want,
113 std::vector<PetscInt> indices_has_clean, indices_has_loc;
114 std::vector<PetscInt> indices_want_clean, indices_want_loc;
115 indices_want_clean.reserve(indices_want.size());
116 indices_want_loc.reserve(indices_want.size());
117 indices_has_clean.reserve(indices_has.size());
118 indices_has_loc.reserve(indices_has.size());
121 bool has_invalid =
false;
122 for (
const auto i : indices_has)
126 indices_has_clean.push_back(
static_cast<PetscInt
>(i));
127 indices_has_loc.push_back(loc);
134 indices_has_loc.clear();
138 for (
const auto i : indices_want)
142 indices_want_clean.push_back(
static_cast<PetscInt
>(i));
143 indices_want_loc.push_back(loc);
150 indices_want_loc.clear();
163 const std::vector<PetscInt> &inloc,
164 const std::vector<PetscInt> &outidx,
165 const std::vector<PetscInt> &outloc,
184 PetscInt n =
static_cast<PetscInt
>(inidx.size());
185 PetscInt lN = n > 0 ? *std::max_element(inidx.begin(), inidx.end()) : -1;
188 Utilities::MPI::internal::all_reduce<PetscInt>(
194 PetscSFNode *remotes;
198 AssertPETSc(PetscLayoutCreate(communicator, &layout));
203 const PetscInt *ranges;
204 AssertPETSc(PetscLayoutGetRanges(layout, &ranges));
207# if DEAL_II_PETSC_VERSION_GTE(3, 13, 0)
208 PetscMPIInt owner = 0;
212 for (
const auto idx : inidx)
215 if (idx < ranges[owner] || ranges[owner + 1] <= idx)
217 AssertPETSc(PetscLayoutFindOwner(layout, idx, &owner));
219 remotes[cnt].rank = owner;
220 remotes[cnt].index = idx - ranges[owner];
228 const_cast<PetscInt *
>(
229 inloc.size() > 0 ? inloc.data() :
nullptr),
239 n =
static_cast<PetscInt
>(outidx.size());
245 const_cast<PetscInt *
>(outloc.size() > 0 ? outloc.data() :
nullptr),
247 const_cast<PetscInt *
>(n > 0 ? outidx.data() :
nullptr)));
272 return PetscObjectComm(
reinterpret_cast<PetscObject
>(
sf));
277 template <
typename Number>
285# if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
289 PetscSFBcastBegin(
sf, datatype, src.
data(), dst.
data(), MPI_REPLACE));
295 template <
typename Number>
303# if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
307 PetscSFBcastEnd(
sf, datatype, src.
data(), dst.
data(), MPI_REPLACE));
313 template <
typename Number>
325 template <
typename Number>
336 PetscSFReduceBegin(
sf, datatype, src.
data(), dst.
data(), mpiop));
341 template <
typename Number>
356 template <
typename Number>
374 , ghost_indices_data()
375 , n_ghost_indices_data(
numbers::invalid_dof_index)
376 , n_ghost_indices_larger(
numbers::invalid_dof_index)
400 const IndexSet &larger_ghost_indices,
403 std::vector<types::global_dof_index> local_indices;
410 std::vector<types::global_dof_index> expanded_ghost_indices(
415 ExcMessage(
"The given larger ghost index set must contain "
416 "all indices in the actual index set."));
418 expanded_ghost_indices[tmp_index] =
index;
433 template <
typename Number>
448 template <
typename Number>
464 template <
typename Number>
473 template <
typename Number>
490 template <
typename Number>
507 template <
typename Number>
520# 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
virtual void reinit(const IndexSet &locally_owned_indices, const IndexSet &ghost_indices, const MPI_Comm communicator) override
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
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 MPI_Datatype mpi_type_id_for_type
const types::global_dof_index invalid_dof_index
#define AssertPETSc(code)