19#ifdef DEAL_II_WITH_PETSC
34# ifdef DEAL_II_HAVE_CXX20
134 ierr = VecGhostUpdateBegin(
vector, INSERT_VALUES, SCATTER_FORWARD);
136 ierr = VecGhostUpdateEnd(
vector, INSERT_VALUES, SCATTER_FORWARD);
158 const bool omit_zeroing_entries)
166 MPI_Allreduce(&k, &k_global, 1, MPI_INT, MPI_LOR, communicator);
181 const PetscErrorCode ierr = VecDestroy(&
vector);
189 if (omit_zeroing_entries ==
false)
203 if (!omit_zeroing_entries)
205 const PetscErrorCode ierr = VecSet(
vector, 0.0);
213 omit_zeroing_entries);
223 const PetscErrorCode ierr = VecDestroy(&
vector);
237 const PetscErrorCode ierr = VecDestroy(&
vector);
247 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
248 const bool make_ghosted)
252 Assert(partitioner->ghost_indices_initialized(),
253 ExcMessage(
"You asked to create a ghosted vector, but the "
254 "partitioner does not provide ghost indices."));
256 this->
reinit(partitioner->locally_owned_range(),
257 partitioner->ghost_indices(),
258 partitioner->get_mpi_communicator());
262 this->
reinit(partitioner->locally_owned_range(),
263 partitioner->get_mpi_communicator());
277 const PetscErrorCode ierr = VecCreateMPI(communicator,
303 std::vector<PetscInt> petsc_ghost_indices(ghostnodes.
n_elements());
304 for (
const auto &index : ghostnodes)
306 petsc_ghost_indices[i] =
static_cast<PetscInt
>(index);
310 PetscErrorCode ierr = VecCreateGhost(communicator,
313 petsc_ghost_indices.size(),
314 petsc_ghost_indices.data(),
325 ierr = VecGetOwnershipRange(
vector, &begin, &end);
332 ierr = VecGhostGetLocalForm(
vector, &l);
336 ierr = VecGetSize(l, &lsize);
339 ierr = VecGhostRestoreLocalForm(
vector, &l);
357 unsigned int num_nonzero =
359 return num_nonzero == 0;
365 const unsigned int precision,
366 const bool scientific,
367 const bool across)
const
373 const PetscScalar *val;
374 PetscInt nlocal, istart, iend;
376 PetscErrorCode ierr = VecGetArrayRead(
vector, &val);
379 ierr = VecGetLocalSize(
vector, &nlocal);
382 ierr = VecGetOwnershipRange(
vector, &istart, &iend);
386 std::ios::fmtflags old_flags = out.flags();
387 unsigned int old_precision = out.precision(precision);
389 out.precision(precision);
391 out.setf(std::ios::scientific, std::ios::floatfield);
393 out.setf(std::ios::fixed, std::ios::floatfield);
401 for (
unsigned int i = 0;
405 const int mpi_ierr = MPI_Barrier(communicator);
412 out <<
"[Proc" << i <<
" " << istart <<
"-" << iend - 1 <<
"]"
414 for (PetscInt i = 0; i < nlocal; ++i)
415 out << val[i] <<
' ';
419 out <<
"[Proc " << i <<
" " << istart <<
"-" << iend - 1
421 for (PetscInt i = 0; i < nlocal; ++i)
422 out << val[i] << std::endl;
428 out.flags(old_flags);
429 out.precision(old_precision);
433 ierr = VecRestoreArrayRead(
vector, &val);
bool is_ascending_and_one_to_one(const MPI_Comm communicator) const
size_type n_elements() const
void subtract_set(const IndexSet &other)
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
virtual void clear() override
Vector & operator=(const Vector &v)
virtual void create_vector(const MPI_Comm comm, const size_type n, const size_type locally_owned_size)
void reinit(const MPI_Comm communicator, const size_type N, const size_type locally_owned_size, const bool omit_zeroing_entries=false)
VectorOperation::values last_action
IndexSet locally_owned_elements() const
MPI_Comm get_mpi_communicator() const
bool has_ghost_elements() const
size_type locally_owned_size() const
size_type size() const override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
#define AssertThrowIntegerConversion(index1, index2)
types::global_dof_index locally_owned_size
T sum(const T &t, const MPI_Comm mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)