17#ifdef DEAL_II_WITH_PETSC
25# define AssertPETSc(code) \
28 PetscErrorCode ierr = (code); \
29 AssertThrow(ierr == 0, ExcPETScError(ierr)); \
58 static_cast<PetscInt
>(ghost_indices.
size()));
61 AssertPETSc(PetscLayoutCreate(communicator, &layout));
62 const auto petsc_local_size =
static_cast<PetscInt
>(local_size);
64 AssertPETSc(PetscLayoutSetLocalSize(layout, petsc_local_size));
68 AssertPETSc(PetscLayoutGetRange(layout, &start, &end));
83 PetscSFSetGraphLayout(
sf, layout, n,
nullptr, PETSC_OWN_POINTER, idxs));
101 locally_owned_indices.
size()),
102 locally_owned_indices.
size());
104 ghost_indices.
size());
107 std::vector<PetscInt> in_petsc(in_deal.begin(), in_deal.end());
110 std::vector<PetscInt> out_petsc(out_deal.begin(), out_deal.end());
112 std::vector<PetscInt> dummy;
114 this->
do_reinit(in_petsc, dummy, out_petsc, dummy, communicator);
121 const std::vector<types::global_dof_index> &indices_has,
122 const std::vector<types::global_dof_index> &indices_want,
126 std::vector<PetscInt> indices_has_clean, indices_has_loc;
127 std::vector<PetscInt> indices_want_clean, indices_want_loc;
128 indices_want_clean.reserve(indices_want.size());
129 indices_want_loc.reserve(indices_want.size());
130 indices_has_clean.reserve(indices_has.size());
131 indices_has_loc.reserve(indices_has.size());
134 bool has_invalid =
false;
135 for (
const auto i : indices_has)
139 const auto petsc_i =
static_cast<PetscInt
>(i);
141 indices_has_clean.push_back(petsc_i);
142 indices_has_loc.push_back(loc);
149 indices_has_loc.clear();
153 for (
const auto i : indices_want)
157 const auto petsc_i =
static_cast<PetscInt
>(i);
159 indices_want_clean.push_back(petsc_i);
160 indices_want_loc.push_back(loc);
167 indices_want_loc.clear();
180 const std::vector<PetscInt> &inloc,
181 const std::vector<PetscInt> &outidx,
182 const std::vector<PetscInt> &outloc,
201 PetscInt n =
static_cast<PetscInt
>(inidx.size());
202 PetscInt lN = n > 0 ? *std::max_element(inidx.begin(), inidx.end()) : -1;
205 Utilities::MPI::internal::all_reduce<PetscInt>(
211 PetscSFNode *remotes;
215 AssertPETSc(PetscLayoutCreate(communicator, &layout));
220 const PetscInt *ranges;
221 AssertPETSc(PetscLayoutGetRanges(layout, &ranges));
224# if DEAL_II_PETSC_VERSION_GTE(3, 13, 0)
225 PetscMPIInt owner = 0;
229 for (
const auto idx : inidx)
232 if (idx < ranges[owner] || ranges[owner + 1] <= idx)
234 AssertPETSc(PetscLayoutFindOwner(layout, idx, &owner));
236 remotes[cnt].rank = owner;
237 remotes[cnt].index = idx - ranges[owner];
245 const_cast<PetscInt *
>(
246 inloc.size() > 0 ? inloc.data() :
nullptr),
256 n =
static_cast<PetscInt
>(outidx.size());
262 const_cast<PetscInt *
>(outloc.size() > 0 ? outloc.data() :
nullptr),
264 const_cast<PetscInt *
>(n > 0 ? outidx.data() :
nullptr)));
289 return PetscObjectComm(
reinterpret_cast<PetscObject
>(
sf));
294 template <
typename Number>
300 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
302# if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
306 PetscSFBcastBegin(
sf, datatype, src.
data(), dst.
data(), MPI_REPLACE));
312 template <
typename Number>
318 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
320# if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
324 PetscSFBcastEnd(
sf, datatype, src.
data(), dst.
data(), MPI_REPLACE));
330 template <
typename Number>
342 template <
typename Number>
350 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
353 PetscSFReduceBegin(
sf, datatype, src.
data(), dst.
data(), mpiop));
358 template <
typename Number>
366 auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
373 template <
typename Number>
391 , ghost_indices_data()
392 , n_ghost_indices_data(
numbers::invalid_dof_index)
393 , n_ghost_indices_larger(
numbers::invalid_dof_index)
417 const IndexSet &larger_ghost_indices,
424 std::vector<types::global_dof_index> expanded_ghost_indices(
429 ExcMessage(
"The given larger ghost index set must contain "
430 "all indices in the actual index set."));
432 expanded_ghost_indices[tmp_index] =
index;
437 expanded_ghost_indices,
449 template <
typename Number>
464 template <
typename Number>
480 template <
typename Number>
489 template <
typename Number>
506 template <
typename Number>
523 template <
typename Number>
536# include "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 Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrowIntegerConversion(index1, index2)
const types::global_dof_index invalid_dof_index
#define AssertPETSc(code)