15#ifdef DEAL_II_WITH_PETSC
26#ifdef DEAL_II_WITH_PETSC
28# define AssertPETSc(code) \
31 PetscErrorCode ierr = (code); \
32 AssertThrow(ierr == 0, ExcPETScError(ierr)); \
61 static_cast<PetscInt
>(ghost_indices.
size()));
64 AssertPETSc(PetscLayoutCreate(communicator, &layout));
65 const auto petsc_local_size =
static_cast<PetscInt
>(local_size);
67 AssertPETSc(PetscLayoutSetLocalSize(layout, petsc_local_size));
86 PetscSFSetGraphLayout(
sf, layout, n,
nullptr, PETSC_OWN_POINTER, idxs));
104 locally_owned_indices.
size()),
105 locally_owned_indices.
size());
107 ghost_indices.
size());
110 std::vector<PetscInt> in_petsc(in_deal.begin(), in_deal.end());
113 std::vector<PetscInt> out_petsc(out_deal.begin(), out_deal.end());
115 std::vector<PetscInt> dummy;
117 this->
do_reinit(in_petsc, dummy, out_petsc, dummy, communicator);
124 const std::vector<types::global_dof_index> &indices_has,
125 const std::vector<types::global_dof_index> &indices_want,
129 std::vector<PetscInt> indices_has_clean, indices_has_loc;
130 std::vector<PetscInt> indices_want_clean, indices_want_loc;
131 indices_want_clean.reserve(indices_want.size());
132 indices_want_loc.reserve(indices_want.size());
133 indices_has_clean.reserve(indices_has.size());
134 indices_has_loc.reserve(indices_has.size());
137 bool has_invalid =
false;
138 for (
const auto i : indices_has)
142 const auto petsc_i =
static_cast<PetscInt
>(i);
144 indices_has_clean.push_back(petsc_i);
145 indices_has_loc.push_back(loc);
152 indices_has_loc.clear();
156 for (
const auto i : indices_want)
160 const auto petsc_i =
static_cast<PetscInt
>(i);
162 indices_want_clean.push_back(petsc_i);
163 indices_want_loc.push_back(loc);
170 indices_want_loc.clear();
183 const std::vector<PetscInt> &inloc,
184 const std::vector<PetscInt> &outidx,
185 const std::vector<PetscInt> &outloc,
204 PetscInt n =
static_cast<PetscInt
>(inidx.size());
205 PetscInt lN = n > 0 ? *std::max_element(inidx.begin(), inidx.end()) : -1;
208 Utilities::MPI::internal::all_reduce<PetscInt>(
214 PetscSFNode *remotes;
218 AssertPETSc(PetscLayoutCreate(communicator, &layout));
223 const PetscInt *ranges;
224 AssertPETSc(PetscLayoutGetRanges(layout, &ranges));
227# if DEAL_II_PETSC_VERSION_GTE(3, 13, 0)
228 PetscMPIInt owner = 0;
232 for (
const auto idx : inidx)
235 if (idx < ranges[owner] || ranges[owner + 1] <= idx)
237 AssertPETSc(PetscLayoutFindOwner(layout, idx, &owner));
239 remotes[cnt].rank = owner;
240 remotes[cnt].index = idx - ranges[owner];
248 const_cast<PetscInt *
>(
249 inloc.size() > 0 ? inloc.data() :
nullptr),
259 n =
static_cast<PetscInt
>(outidx.size());
265 const_cast<PetscInt *
>(outloc.size() > 0 ? outloc.data() :
nullptr),
267 const_cast<PetscInt *
>(n > 0 ? outidx.data() :
nullptr)));
292 return PetscObjectComm(
reinterpret_cast<PetscObject
>(
sf));
297 template <
typename Number>
303 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
305# if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
309 PetscSFBcastBegin(
sf, datatype, src.
data(), dst.
data(), MPI_REPLACE));
315 template <
typename Number>
321 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
323# if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
327 PetscSFBcastEnd(
sf, datatype, src.
data(), dst.
data(), MPI_REPLACE));
333 template <
typename Number>
345 template <
typename Number>
353 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
356 PetscSFReduceBegin(
sf, datatype, src.
data(), dst.
data(), mpiop));
361 template <
typename Number>
369 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
376 template <
typename Number>
394 , ghost_indices_data()
395 , n_ghost_indices_data(
numbers::invalid_dof_index)
396 , n_ghost_indices_larger(
numbers::invalid_dof_index)
420 const IndexSet &larger_ghost_indices,
427 std::vector<types::global_dof_index> expanded_ghost_indices(
432 ExcMessage(
"The given larger ghost index set must contain "
433 "all indices in the actual index set."));
435 expanded_ghost_indices[tmp_index] =
index;
440 expanded_ghost_indices,
452 template <
typename Number>
467 template <
typename Number>
483 template <
typename Number>
492 template <
typename Number>
509 template <
typename Number>
526 template <
typename Number>
539# include "lac/petsc_communication_pattern.inst"
value_type * data() const noexcept
IS make_petsc_is(const MPI_Comm communicator=MPI_COMM_WORLD) 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)
std::vector< size_type > get_index_vector() const
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 AssertThrowIntegerConversion(index1, index2)
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcMessage(std::string arg1)
constexpr types::global_dof_index invalid_dof_index
#define AssertPETSc(code)