16 #ifndef dealii_la_parallel_vector_h 17 #define dealii_la_parallel_vector_h 19 #include <deal.II/base/config.h> 21 #include <deal.II/base/mpi.h> 22 #include <deal.II/base/numbers.h> 23 #include <deal.II/base/partitioner.h> 24 #include <deal.II/base/thread_management.h> 26 #include <deal.II/lac/vector_operation.h> 27 #include <deal.II/lac/vector_space_vector.h> 28 #include <deal.II/lac/vector_type_traits.h> 33 DEAL_II_NAMESPACE_OPEN
50 #ifdef DEAL_II_WITH_PETSC 60 #ifdef DEAL_II_WITH_TRILINOS 180 template <
typename Number>
185 using value_type = Number;
186 using pointer = value_type *;
187 using const_pointer =
const value_type *;
188 using iterator = value_type *;
189 using const_iterator =
const value_type *;
190 using reference = value_type &;
191 using const_reference =
const value_type &;
213 Vector(
const size_type size);
233 const MPI_Comm communicator);
247 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner);
252 virtual ~
Vector()
override;
259 reinit(
const size_type size,
const bool omit_zeroing_entries =
false);
271 template <
typename Number2>
274 const bool omit_zeroing_entries =
false);
295 const MPI_Comm communicator);
301 reinit(
const IndexSet &local_range,
const MPI_Comm communicator);
311 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner);
356 template <
typename Number2>
360 #ifdef DEAL_II_WITH_PETSC 376 #ifdef DEAL_II_WITH_TRILINOS 458 update_ghost_values()
const;
476 const unsigned int communication_channel = 0,
512 update_ghost_values_start(
513 const unsigned int communication_channel = 0)
const;
524 update_ghost_values_finish()
const;
535 zero_out_ghosts()
const;
549 has_ghost_elements()
const;
565 template <
typename Number2>
582 const bool omit_zeroing_entries =
false)
override;
588 operator*=(
const Number factor)
override;
594 operator/=(
const Number factor)
override;
620 std::shared_ptr<const CommunicationPatternBase> communication_pattern =
621 std::shared_ptr<const CommunicationPatternBase>())
override;
633 add(
const Number a)
override;
655 add(
const std::vector<size_type> &indices,
656 const std::vector<Number> & values);
686 l1_norm()
const override;
693 l2_norm()
const override;
706 linfty_norm()
const override;
729 add_and_dot(
const Number a,
738 size()
const override;
752 locally_owned_elements()
const override;
758 print(std::ostream & out,
759 const unsigned int precision = 3,
760 const bool scientific =
true,
761 const bool across =
true)
const override;
767 memory_consumption()
const override;
781 operator=(
const Number s)
override;
787 template <
typename OtherNumber>
789 add(
const std::vector<size_type> & indices,
790 const ::Vector<OtherNumber> &values);
796 template <
typename OtherNumber>
798 add(
const size_type n_elements,
799 const size_type * indices,
800 const OtherNumber *values);
857 std::pair<size_type, size_type>
868 in_local_range(
const size_type global_index)
const;
877 n_ghost_entries()
const;
888 ghost_elements()
const;
942 operator()(
const size_type global_index)
const;
954 operator()(
const size_type global_index);
963 Number operator[](
const size_type global_index)
const;
971 Number &operator[](
const size_type global_index);
982 local_element(
const size_type local_index)
const;
993 local_element(
const size_type local_index);
1010 template <
typename OtherNumber>
1012 extract_subvector_to(
const std::vector<size_type> &indices,
1013 std::vector<OtherNumber> & values)
const;
1042 template <
typename ForwardIterator,
typename OutputIterator>
1044 extract_subvector_to(ForwardIterator indices_begin,
1045 const ForwardIterator indices_end,
1046 OutputIterator values_begin)
const;
1053 all_zero()
const override;
1059 mean_value()
const override;
1066 lp_norm(
const real_type p)
const;
1079 get_mpi_communicator()
const;
1087 const std::shared_ptr<const Utilities::MPI::Partitioner> &
1088 get_partitioner()
const;
1100 partitioners_are_compatible(
1117 partitioners_are_globally_compatible(
1135 <<
"Called compress(VectorOperation::insert), but" 1136 <<
" the element received from a remote processor, value " 1137 << std::setprecision(16) << arg1
1138 <<
", does not match with the value " 1139 << std::setprecision(16) << arg2
1140 <<
" on the owner processor " << arg3);
1150 <<
"You tried to access element " << arg1
1151 <<
" of a distributed vector, but this element is not " 1152 <<
"stored on the current processor. Note: The range of " 1153 <<
"locally owned elements is " << arg2 <<
" to " << arg3
1154 <<
", and there are " << arg4 <<
" ghost elements " 1155 <<
"that this vector can access.");
1170 sadd_local(
const Number s,
1178 all_zero_local()
const;
1183 template <
typename Number2>
1191 norm_sqr_local()
const;
1197 mean_value_local()
const;
1203 l1_norm_local()
const;
1209 lp_norm_local(
const real_type p)
const;
1215 linfty_norm_local()
const;
1223 add_and_dot_local(
const Number a,
1246 std::unique_ptr<Number[], decltype(&free)>
values;
1252 mutable std::shared_ptr<::parallel::internal::TBBPartitioner>
1271 #ifdef DEAL_II_WITH_MPI 1301 clear_mpi_requests();
1307 resize_val(
const size_type new_allocated_size);
1312 template <
typename Number2>
1318 template <
typename Number2>
1329 template <
typename Number>
1333 return vector_is_ghosted;
1338 template <
typename Number>
1339 inline typename Vector<Number>::size_type
1342 return partitioner->size();
1347 template <
typename Number>
1348 inline typename Vector<Number>::size_type
1351 return partitioner->local_size();
1356 template <
typename Number>
1357 inline std::pair<typename Vector<Number>::size_type,
1358 typename Vector<Number>::size_type>
1361 return partitioner->local_range();
1366 template <
typename Number>
1370 return partitioner->in_local_range(global_index);
1375 template <
typename Number>
1381 is.add_range(partitioner->local_range().first,
1382 partitioner->local_range().second);
1389 template <
typename Number>
1390 inline typename Vector<Number>::size_type
1393 return partitioner->n_ghost_indices();
1398 template <
typename Number>
1402 return partitioner->ghost_indices();
1407 template <
typename Number>
1411 return partitioner->is_ghost_entry(global_index);
1416 template <
typename Number>
1417 inline typename Vector<Number>::iterator
1420 return values.get();
1425 template <
typename Number>
1426 inline typename Vector<Number>::const_iterator
1429 return values.get();
1434 template <
typename Number>
1435 inline typename Vector<Number>::iterator
1438 return values.get() + partitioner->local_size();
1443 template <
typename Number>
1444 inline typename Vector<Number>::const_iterator
1447 return values.get() + partitioner->local_size();
1452 template <
typename Number>
1457 partitioner->in_local_range(global_index) ||
1458 partitioner->ghost_indices().is_element(global_index),
1459 ExcAccessToNonLocalElement(global_index,
1460 partitioner->local_range().first,
1461 partitioner->local_range().second,
1462 partitioner->ghost_indices().n_elements()));
1464 Assert(partitioner->in_local_range(global_index) ||
1465 vector_is_ghosted ==
true,
1466 ExcMessage(
"You tried to read a ghost element of this vector, " 1467 "but it has not imported its ghost values."));
1468 return values[partitioner->global_to_local(global_index)];
1473 template <
typename Number>
1478 partitioner->in_local_range(global_index) ||
1479 partitioner->ghost_indices().is_element(global_index),
1480 ExcAccessToNonLocalElement(global_index,
1481 partitioner->local_range().first,
1482 partitioner->local_range().second,
1483 partitioner->ghost_indices().n_elements()));
1490 return values[partitioner->global_to_local(global_index)];
1495 template <
typename Number>
1503 template <
typename Number>
1511 template <
typename Number>
1516 partitioner->local_size() +
1517 partitioner->n_ghost_indices());
1519 Assert(local_index < local_size() || vector_is_ghosted ==
true,
1520 ExcMessage(
"You tried to read a ghost element of this vector, " 1521 "but it has not imported its ghost values."));
1522 return values[local_index];
1527 template <
typename Number>
1532 partitioner->local_size() +
1533 partitioner->n_ghost_indices());
1534 return values[local_index];
1539 template <
typename Number>
1540 template <
typename OtherNumber>
1543 std::vector<OtherNumber> &values)
const 1545 for (size_type i = 0; i < indices.size(); ++i)
1546 values[i] =
operator()(indices[i]);
1551 template <
typename Number>
1552 template <
typename ForwardIterator,
typename OutputIterator>
1555 const ForwardIterator indices_end,
1556 OutputIterator values_begin)
const 1558 while (indices_begin != indices_end)
1568 template <
typename Number>
1569 template <
typename OtherNumber>
1572 const ::Vector<OtherNumber> &values)
1575 for (size_type i = 0; i < indices.size(); ++i)
1580 "The given value is not finite but either infinite or Not A Number (NaN)"));
1587 template <
typename Number>
1588 template <
typename OtherNumber>
1591 const size_type * indices,
1592 const OtherNumber *values)
1594 for (size_type i = 0; i < n_elements; ++i, ++indices, ++values)
1599 "The given value is not finite but either infinite or Not A Number (NaN)"));
1606 template <
typename Number>
1607 inline const MPI_Comm &
1610 return partitioner->get_mpi_communicator();
1615 template <
typename Number>
1616 inline const std::shared_ptr<const Utilities::MPI::Partitioner> &
1636 template <
typename Number>
1650 template <
typename Number>
1658 namespace LinearOperatorImplementation
1667 template <
typename Number>
1671 template <
typename Matrix>
1673 reinit_range_vector(
const Matrix & matrix,
1675 bool omit_zeroing_entries)
1677 matrix.initialize_dof_vector(v);
1678 if (!omit_zeroing_entries)
1682 template <
typename Matrix>
1684 reinit_domain_vector(
const Matrix & matrix,
1686 bool omit_zeroing_entries)
1688 matrix.initialize_dof_vector(v);
1689 if (!omit_zeroing_entries)
1698 DEAL_II_NAMESPACE_CLOSE
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_partitioner() const
#define AssertDimension(dim1, dim2)
Number local_element(const size_type local_index) const
std::vector< MPI_Request > compress_requests
void swap(LinearAlgebra::distributed::Vector< Number > &u, LinearAlgebra::distributed::Vector< Number > &v)
std::unique_ptr< Number[]> import_data
#define AssertIndexRange(index, range)
SymmetricTensor< rank_, dim, Number > operator*(const SymmetricTensor< rank_, dim, Number > &t, const Number &factor)
size_type local_size() const
unsigned long long int global_dof_index
bool is_finite(const double x)
std::vector< MPI_Request > update_ghost_values_requests
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< OtherNumber > &values) const
value_type operator()(const size_type i) const
void swap(Vector< Number > &v)
static::ExceptionBase & ExcMessage(std::string arg1)
Number operator()(const size_type global_index) const
size_type n_ghost_entries() const
virtual size_type size() const override
std::shared_ptr<::parallel::internal::TBBPartitioner > thread_loop_partitioner
#define Assert(cond, exc)
std::unique_ptr< Number[], decltype(&free)> values
virtual void add(const Number a) override
#define DeclException0(Exception0)
virtual ::IndexSet locally_owned_elements() const override
bool has_ghost_elements() const
bool is_ghost_entry(const types::global_dof_index global_index) const
const MPI_Comm & get_mpi_communicator() const
std::pair< size_type, size_type > local_range() const
void swap(Vector< Number > &u, Vector< Number > &v)
const IndexSet & ghost_elements() const
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner
Number operator[](const size_type global_index) const
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
bool in_local_range(const size_type global_index) const