16 #ifndef dealii_la_parallel_vector_h 17 #define dealii_la_parallel_vector_h 19 #include <deal.II/base/config.h> 20 #include <deal.II/base/mpi.h> 21 #include <deal.II/base/numbers.h> 22 #include <deal.II/base/partitioner.h> 23 #include <deal.II/base/thread_management.h> 24 #include <deal.II/lac/vector_operation.h> 25 #include <deal.II/lac/vector_space_vector.h> 26 #include <deal.II/lac/vector_type_traits.h> 31 DEAL_II_NAMESPACE_OPEN
46 #ifdef DEAL_II_WITH_PETSC 56 #ifdef DEAL_II_WITH_TRILINOS 176 template <
typename Number>
181 typedef Number value_type;
182 typedef value_type *pointer;
183 typedef const value_type *const_pointer;
184 typedef value_type *iterator;
185 typedef const value_type *const_iterator;
186 typedef value_type &reference;
187 typedef const value_type &const_reference;
229 const MPI_Comm communicator);
235 const MPI_Comm communicator);
255 const bool omit_zeroing_entries =
false);
267 template <
typename Number2>
269 const bool omit_zeroing_entries =
false);
289 const MPI_Comm communicator);
295 const MPI_Comm communicator);
303 void reinit (
const std::shared_ptr<const Utilities::MPI::Partitioner> &
partitioner);
347 template <
typename Number2>
351 #ifdef DEAL_II_WITH_PETSC 367 #ifdef DEAL_II_WITH_TRILINOS 450 void compress_start (
const unsigned int communication_channel = 0,
533 template <
typename Number2>
548 const bool omit_zeroing_entries =
false)
override;
580 std::shared_ptr<const CommunicationPatternBase> communication_pattern =
581 std::shared_ptr<const CommunicationPatternBase> ())
override;
591 virtual void add(
const Number a)
override;
608 virtual void add (
const std::vector<size_type> &indices,
609 const std::vector<Number> &
values);
615 virtual void sadd(
const Number s,
const Number a,
634 virtual real_type
l1_norm()
const override;
640 virtual real_type
l2_norm()
const override;
680 virtual size_type
size()
const override;
698 virtual void print(std::ostream &out,
699 const unsigned int precision=3,
700 const bool scientific=
true,
701 const bool across=
true)
const override;
725 template <
typename OtherNumber>
726 void add (
const std::vector<size_type> &indices,
727 const ::Vector<OtherNumber> &
values);
733 template <
typename OtherNumber>
734 void add (
const size_type n_elements,
735 const size_type *indices,
736 const OtherNumber *
values);
742 void sadd (
const Number s,
751 void sadd (
const Number s,
788 std::pair<size_type, size_type>
local_range ()
const;
840 const_iterator
begin ()
const;
852 const_iterator
end ()
const;
863 Number
operator () (
const size_type global_index)
const;
874 Number &
operator () (
const size_type global_index);
883 Number
operator [] (
const size_type global_index)
const;
891 Number &
operator [] (
const size_type global_index);
928 template <
typename OtherNumber>
930 std::vector<OtherNumber> &
values)
const;
959 template <
typename ForwardIterator,
typename OutputIterator>
961 const ForwardIterator indices_end,
962 OutputIterator values_begin)
const;
968 virtual bool all_zero ()
const override;
979 real_type
lp_norm (
const real_type p)
const;
999 const std::shared_ptr<const Utilities::MPI::Partitioner> &
1042 Number, Number,
unsigned int,
1043 <<
"Called compress(VectorOperation::insert), but" 1044 <<
" the element received from a remote processor, value " 1045 << std::setprecision(16) << arg1
1046 <<
", does not match with the value " 1047 << std::setprecision(16) << arg2
1048 <<
" on the owner processor " << arg3);
1054 size_type, size_type, size_type, size_type,
1055 <<
"You tried to access element " << arg1
1056 <<
" of a distributed vector, but this element is not " 1057 <<
"stored on the current processor. Note: The range of " 1058 <<
"locally owned elements is " << arg2 <<
" to " 1059 << arg3 <<
", and there are " << arg4 <<
" ghost elements " 1060 <<
"that this vector can access.");
1074 void sadd_local(
const Number s,
const Number a,
1085 template <
typename Number2>
1141 std::unique_ptr<Number[], decltype(&free)>
values;
1165 #ifdef DEAL_II_WITH_MPI 1199 void resize_val (
const size_type new_allocated_size);
1204 template <
typename Number2>
friend class Vector;
1219 template <
typename Number>
1224 return vector_is_ghosted;
1229 template <
typename Number>
1231 typename Vector<Number>::size_type
1234 return partitioner->size();
1239 template <
typename Number>
1241 typename Vector<Number>::size_type
1244 return partitioner->local_size();
1249 template <
typename Number>
1251 std::pair<typename Vector<Number>::size_type,
1252 typename Vector<Number>::size_type>
1255 return partitioner->local_range();
1260 template <
typename Number>
1264 (
const size_type global_index)
const 1266 return partitioner->in_local_range (global_index);
1271 template <
typename Number>
1278 is.add_range (partitioner->local_range().first,
1279 partitioner->local_range().second);
1286 template <
typename Number>
1288 typename Vector<Number>::size_type
1291 return partitioner->n_ghost_indices();
1296 template <
typename Number>
1301 return partitioner->ghost_indices();
1306 template <
typename Number>
1311 return partitioner->is_ghost_entry (global_index);
1316 template <
typename Number>
1318 typename Vector<Number>::iterator
1321 return values.get();
1326 template <
typename Number>
1328 typename Vector<Number>::const_iterator
1331 return values.get();
1336 template <
typename Number>
1338 typename Vector<Number>::iterator
1341 return values.get()+partitioner->local_size();
1346 template <
typename Number>
1348 typename Vector<Number>::const_iterator
1351 return values.get()+partitioner->local_size();
1356 template <
typename Number>
1361 Assert (partitioner->in_local_range (global_index) ||
1362 partitioner->ghost_indices().is_element(global_index),
1363 ExcAccessToNonLocalElement(global_index, partitioner->local_range().first,
1364 partitioner->local_range().second,
1365 partitioner->ghost_indices().n_elements()));
1367 Assert (partitioner->in_local_range (global_index) || vector_is_ghosted ==
true,
1368 ExcMessage(
"You tried to read a ghost element of this vector, " 1369 "but it has not imported its ghost values."));
1370 return values[partitioner->global_to_local(global_index)];
1375 template <
typename Number>
1380 Assert (partitioner->in_local_range (global_index) ||
1381 partitioner->ghost_indices().is_element(global_index),
1382 ExcAccessToNonLocalElement(global_index, partitioner->local_range().first,
1383 partitioner->local_range().second,
1384 partitioner->ghost_indices().n_elements()));
1391 return values[partitioner->global_to_local (global_index)];
1396 template <
typename Number>
1406 template <
typename Number>
1416 template <
typename Number>
1422 partitioner->local_size()+
1423 partitioner->n_ghost_indices());
1425 Assert (local_index < local_size() || vector_is_ghosted ==
true,
1426 ExcMessage(
"You tried to read a ghost element of this vector, " 1427 "but it has not imported its ghost values."));
1428 return values[local_index];
1433 template <
typename Number>
1439 partitioner->local_size()+
1440 partitioner->n_ghost_indices());
1441 return values[local_index];
1446 template <
typename Number>
1447 template <
typename OtherNumber>
1450 std::vector<OtherNumber> &values)
const 1452 for (size_type i = 0; i < indices.size(); ++i)
1453 values[i] =
operator()(indices[i]);
1458 template <
typename Number>
1459 template <
typename ForwardIterator,
typename OutputIterator>
1462 const ForwardIterator indices_end,
1463 OutputIterator values_begin)
const 1465 while (indices_begin != indices_end)
1475 template <
typename Number>
1476 template <
typename OtherNumber>
1480 const ::Vector<OtherNumber> &values)
1483 for (size_type i=0; i<indices.size(); ++i)
1486 ExcMessage(
"The given value is not finite but either infinite or Not A Number (NaN)"));
1493 template <
typename Number>
1494 template <
typename OtherNumber>
1498 const size_type *indices,
1499 const OtherNumber *values)
1501 for (size_type i=0; i<n_elements; ++i, ++indices, ++values)
1504 ExcMessage(
"The given value is not finite but either infinite or Not A Number (NaN)"));
1511 template <
typename Number>
1516 return partitioner->get_mpi_communicator();
1521 template <
typename Number>
1523 const std::shared_ptr<const Utilities::MPI::Partitioner> &
1543 template <
typename Number>
1557 template <
typename Number>
1565 namespace LinearOperatorImplementation
1567 template <
typename>
class ReinitHelper;
1573 template <
typename Number>
1577 template <
typename Matrix>
1581 bool omit_zeroing_entries)
1583 matrix.initialize_dof_vector(v);
1584 if (!omit_zeroing_entries)
1588 template <
typename Matrix>
1592 bool omit_zeroing_entries)
1594 matrix.initialize_dof_vector(v);
1595 if (!omit_zeroing_entries)
1604 DEAL_II_NAMESPACE_CLOSE
void reinit(const size_type size, const bool omit_zeroing_entries=false)
#define AssertDimension(dim1, dim2)
const IndexSet & ghost_elements() const
std::vector< MPI_Request > compress_requests
void copy_locally_owned_data_from(const Vector< Number2 > &src)
Number inner_product_local(const Vector< Number2 > &V) const
virtual Vector< Number > & operator*=(const Number factor) override
real_type lp_norm(const real_type p) const
real_type l1_norm_local() const
void swap(LinearAlgebra::distributed::Vector< Number > &u, LinearAlgebra::distributed::Vector< Number > &v)
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
std::unique_ptr< Number[]> import_data
#define AssertIndexRange(index, range)
void add_local(const Number a, const VectorSpaceVector< Number > &V)
virtual void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const override
virtual Vector< Number > & operator-=(const VectorSpaceVector< Number > &V) override
Number mean_value_local() const
static ::ExceptionBase & ExcVectorTypeNotCompatible()
void clear_mpi_requests()
void update_ghost_values() const
static void reinit_range_vector(const Matrix &matrix, Vector &v, bool omit_zeroing_entries)
bool is_finite(const double x)
std::vector< MPI_Request > update_ghost_values_requests
static void reinit_domain_vector(const Matrix &matrix, Vector &v, bool omit_zeroing_entries)
bool in_local_range(const size_type global_index) const
virtual Vector< Number > & operator/=(const Number factor) override
virtual real_type l1_norm() const override
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
void swap(Vector< Number > &v)
static ::ExceptionBase & ExcMessage(std::string arg1)
bool has_ghost_elements() const
unsigned int global_dof_index
virtual size_type size() const override
void zero_out_ghosts() const
#define Assert(cond, exc)
void resize_val(const size_type new_allocated_size)
virtual std::size_t memory_consumption() const override
std::unique_ptr< Number[], decltype(&free)> values
virtual void add(const Number a) override
real_type linfty_norm_local() const
Number operator[](const size_type global_index) const
#define DeclException0(Exception0)
virtual ::IndexSet locally_owned_elements() const override
size_type local_size() const
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_partitioner() const
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< OtherNumber > &values) const
virtual void compress(::VectorOperation::values operation) override
const MPI_Comm & get_mpi_communicator() const
bool all_zero_local() const
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
virtual Number mean_value() const override
Number add_and_dot_local(const Number a, const Vector< Number > &V, const Vector< Number > &W)
Vector< Number > & operator=(const Vector< Number > &in_vector)
void compress_start(const unsigned int communication_channel=0, ::VectorOperation::values operation=VectorOperation::add)
virtual bool all_zero() const override
real_type norm_sqr() const
std::pair< size_type, size_type > local_range() const
void compress_finish(::VectorOperation::values operation)
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner
Number operator()(const size_type global_index) const
bool partitioners_are_globally_compatible(const Utilities::MPI::Partitioner &part) const
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
static ::ExceptionBase & ExcNonMatchingElements(Number arg1, Number arg2, unsigned int arg3)
value_type operator()(const size_type i) const
bool partitioners_are_compatible(const Utilities::MPI::Partitioner &part) const
real_type lp_norm_local(const real_type p) const
Number local_element(const size_type local_index) const
bool is_ghost_entry(const types::global_dof_index global_index) const
size_type n_ghost_entries() const
virtual real_type l2_norm() const override
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
real_type norm_sqr_local() const
virtual real_type linfty_norm() const override
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
virtual Vector< Number > & operator+=(const VectorSpaceVector< Number > &V) override
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
virtual ~Vector() override
void sadd_local(const Number s, const Number a, const VectorSpaceVector< Number > &V)
std::shared_ptr< ::parallel::internal::TBBPartitioner > thread_loop_partitioner
void update_ghost_values_start(const unsigned int communication_channel=0) const
void update_ghost_values_finish() const