16 #include <deal.II/lac/petsc_parallel_vector.h> 18 #ifdef DEAL_II_WITH_PETSC 20 # include <deal.II/lac/petsc_vector.h> 24 DEAL_II_NAMESPACE_OPEN
37 = VecCreateSeq (PETSC_COMM_SELF, n, &
vector);
48 communicator (communicator)
59 communicator (communicator)
72 communicator (communicator)
87 communicator (communicator)
105 int ierr = VecCreateSeq (PETSC_COMM_SELF, n, &
vector);
115 const bool omit_zeroing_entries)
123 MPI_Allreduce (&k, &k_global, 1,
138 #if DEAL_II_PETSC_VERSION_LT(3,2,0) 139 ierr = VecDestroy (
vector);
141 ierr = VecDestroy (&
vector);
151 if (omit_zeroing_entries ==
false)
159 const bool omit_zeroing_entries)
164 if (!omit_zeroing_entries)
166 int ierr = VecSet(
vector, 0.0);
179 const MPI_Comm &comm)
182 #if DEAL_II_PETSC_VERSION_LT(3,2,0) 183 ierr = VecDestroy (
vector);
185 ierr = VecDestroy (&
vector);
201 const MPI_Comm &comm)
204 #if DEAL_II_PETSC_VERSION_LT(3,2,0) 205 ierr = VecDestroy (
vector);
207 ierr = VecDestroy (&
vector);
223 ExcMessage(
"Call to compress() required before calling operator=."));
231 PetscScalar *dest_array;
232 ierr = VecGetArray (
vector, &dest_array);
237 PetscScalar *src_array;
238 ierr = VecGetArray (static_cast<const Vec &>(v), &src_array);
242 const std::pair<size_type, size_type>
244 std::copy (src_array + local_elements.first,
245 src_array + local_elements.second,
249 ierr = VecRestoreArray (
vector, &dest_array);
252 ierr = VecRestoreArray (static_cast<const Vec &>(v), &src_array);
257 ierr = VecGhostUpdateBegin(
vector, INSERT_VALUES, SCATTER_FORWARD);
259 ierr = VecGhostUpdateEnd(
vector, INSERT_VALUES, SCATTER_FORWARD);
271 Assert (local_size <= n, ExcIndexRange (local_size, 0, n));
275 = VecCreateMPI (
communicator, local_size, PETSC_DETERMINE,
280 ExcDimensionMismatch (
size(), n));
291 Assert (local_size <= n, ExcIndexRange (local_size, 0, n));
295 std::vector<size_type> ghostindices;
299 = (ghostindices.size() > 0
301 (
const PetscInt *)(&(ghostindices[0]))
316 ExcDimensionMismatch (
size(), n));
323 ierr = VecGetOwnershipRange (
vector, &begin, &end);
328 ierr = VecGhostGetLocalForm(
vector, &l);
332 ierr = VecGetSize(l, &lsize);
335 ierr = VecGhostRestoreLocalForm(
vector, &l);
349 #if DEAL_II_PETSC_VERSION_LT(3,6,0) 363 #ifdef DEAL_II_WITH_MPI 367 return num_nonzero == 0;
369 return has_nonzero == 0;
376 const unsigned int precision,
377 const bool scientific,
378 const bool across)
const 385 PetscInt nlocal, istart, iend;
387 int ierr = VecGetArray (
vector, &val);
391 ierr = VecGetLocalSize (
vector, &nlocal);
395 ierr = VecGetOwnershipRange (
vector, &istart, &iend);
400 std::ios::fmtflags old_flags = out.flags();
401 unsigned int old_precision = out.precision (precision);
403 out.precision (precision);
405 out.setf (std::ios::scientific, std::ios::floatfield);
407 out.setf (std::ios::fixed, std::ios::floatfield);
409 for (
unsigned int i = 0;
419 out <<
"[Proc" << i <<
" " << istart <<
"-" << iend-1 <<
"]" <<
' ';
420 for (PetscInt i=0; i<nlocal; ++i)
421 out << val[i] <<
' ';
425 out <<
"[Proc " << i <<
" " << istart <<
"-" << iend-1 <<
"]" << std::endl;
426 for (PetscInt i=0; i<nlocal; ++i)
427 out << val[i] << std::endl;
433 out.flags (old_flags);
434 out.precision(old_precision);
438 ierr = VecRestoreArray (
vector, &val);
448 DEAL_II_NAMESPACE_CLOSE
450 #endif // DEAL_II_WITH_PETSC
types::global_dof_index size_type
Vector & operator=(const Vector &v)
::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
VectorBase & operator=(const PetscScalar s)
std::pair< size_type, size_type > local_range() const
size_type local_size() const
T sum(const T &t, const MPI_Comm &mpi_communicator)
void subtract_set(const IndexSet &other)
VectorOperation::values last_action
#define Assert(cond, exc)
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
void fill_index_vector(std::vector< size_type > &indices) const
bool has_ghost_elements() const
bool is_contiguous() const
void reinit(const MPI_Comm &communicator, const size_type N, const size_type local_size, const bool omit_zeroing_entries=false)
IndexSet locally_owned_elements() const
virtual void create_vector(const size_type n, const size_type local_size)
unsigned int this_mpi_process(const MPI_Comm &mpi_communicator)
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
size_type n_elements() const