15#ifndef dealii_la_parallel_vector_h
16#define dealii_la_parallel_vector_h
52 class ReadWriteVector;
55# ifdef DEAL_II_WITH_PETSC
65# ifdef DEAL_II_WITH_TRILINOS
248 template <
typename Number,
typename MemorySpace = MemorySpace::Host>
264 std::is_same_v<MemorySpace, ::MemorySpace::Host> ||
265 std::is_same_v<MemorySpace, ::MemorySpace::Default>,
266 "MemorySpace should be Host or Default");
332 const std::shared_ptr<const Utilities::MPI::Partitioner> &
partitioner);
356 template <
typename Number2>
359 const bool omit_zeroing_entries =
false);
402 const std::shared_ptr<const Utilities::MPI::Partitioner> &
partitioner,
413 const std::shared_ptr<const Utilities::MPI::Partitioner> &
partitioner,
414 const bool make_ghosted,
508 template <
typename Number2>
641 const unsigned int communication_channel = 0)
const;
693 template <
typename Number2>
707 template <
typename MemorySpace2>
715 template <
typename MemorySpace2>
769 const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
770 &communication_pattern = {});
778 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
779 communication_pattern = {})
816 add(
const std::vector<size_type> &indices,
817 const std::vector<Number> &values);
920 const unsigned int precision = 3,
921 const bool scientific =
true,
922 const bool across =
true)
const;
948 template <
typename OtherNumber>
950 add(
const std::vector<size_type> &indices,
951 const ::Vector<OtherNumber> &values);
957 template <
typename OtherNumber>
961 const OtherNumber *values);
1126 template <
typename OtherNumber>
1129 std::vector<OtherNumber> &values)
const;
1166 template <
typename ForwardIterator,
typename OutputIterator>
1169 const ForwardIterator indices_end,
1170 OutputIterator values_begin)
const;
1210 const std::shared_ptr<const Utilities::MPI::Partitioner> &
1253 const std::vector<ArrayView<const Number>> &
1272 <<
"Called compress(VectorOperation::insert), but"
1273 <<
" the element received from a remote processor, value "
1274 << std::setprecision(16) << arg1
1275 <<
", does not match with the value "
1276 << std::setprecision(16) << arg2
1277 <<
" on the owner processor " << arg3);
1288 <<
"You tried to access element " << arg1
1289 <<
" of a distributed vector, but this element is not "
1290 <<
"stored on the current processor. Note: The range of "
1291 <<
"locally owned elements is [" << arg2 <<
',' << arg3
1292 <<
"], and there are " << arg4 <<
" ghost elements "
1293 <<
"that this vector can access."
1295 <<
"A common source for this kind of problem is that you "
1296 <<
"are passing a 'fully distributed' vector into a function "
1297 <<
"that needs read access to vector elements that correspond "
1298 <<
"to degrees of freedom on ghost cells (or at least to "
1299 <<
"'locally active' degrees of freedom that are not also "
1300 <<
"'locally owned'). You need to pass a vector that has these "
1301 <<
"elements as ghost entries.");
1323 template <
typename Number2>
1382 mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace>
data;
1388 mutable std::shared_ptr<::parallel::internal::TBBPartitioner>
1395 mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace>
1407#ifdef DEAL_II_WITH_MPI
1454 template <
typename Number2,
typename MemorySpace2>
1458 template <
typename Number2>
1468 template <
typename Number,
typename MemorySpace>
1472 return vector_is_ghosted;
1477 template <
typename Number,
typename MemorySpace>
1481 return partitioner->size();
1486 template <
typename Number,
typename MemorySpace>
1490 return partitioner->locally_owned_size();
1495 template <
typename Number,
typename MemorySpace>
1498 const size_type global_index)
const
1500 return partitioner->in_local_range(global_index);
1505 template <
typename Number,
typename MemorySpace>
1511 is.add_range(partitioner->local_range().first,
1512 partitioner->local_range().second);
1519 template <
typename Number,
typename MemorySpace>
1523 return data.values.data();
1528 template <
typename Number,
typename MemorySpace>
1532 return data.values.data();
1537 template <
typename Number,
typename MemorySpace>
1541 return data.values.data() + partitioner->locally_owned_size();
1546 template <
typename Number,
typename MemorySpace>
1550 return data.values.data() + partitioner->locally_owned_size();
1555 template <
typename Number,
typename MemorySpace>
1556 const std::vector<ArrayView<const Number>> &
1559 return data.values_sm;
1564 template <
typename Number,
typename MemorySpace>
1568 Assert((std::is_same_v<MemorySpace, ::MemorySpace::Host>),
1570 "This function is only implemented for the Host memory space"));
1572 partitioner->in_local_range(global_index) ||
1573 partitioner->ghost_indices().is_element(global_index),
1574 ExcAccessToNonLocalElement(global_index,
1575 partitioner->local_range().first,
1576 partitioner->local_range().second == 0 ?
1578 (partitioner->local_range().
second - 1),
1579 partitioner->ghost_indices().n_elements()));
1581 Assert(partitioner->in_local_range(global_index) ||
1582 vector_is_ghosted ==
true,
1583 ExcMessage(
"You tried to read a ghost element of this vector, "
1584 "but it has not imported its ghost values."));
1585 return data.values[partitioner->global_to_local(global_index)];
1590 template <
typename Number,
typename MemorySpace>
1594 Assert((std::is_same_v<MemorySpace, ::MemorySpace::Host>),
1596 "This function is only implemented for the Host memory space"));
1598 partitioner->in_local_range(global_index) ||
1599 partitioner->ghost_indices().is_element(global_index),
1600 ExcAccessToNonLocalElement(global_index,
1601 partitioner->local_range().first,
1602 partitioner->local_range().second == 0 ?
1604 (partitioner->local_range().
second - 1),
1605 partitioner->ghost_indices().n_elements()));
1612 return data.values[partitioner->global_to_local(global_index)];
1617 template <
typename Number,
typename MemorySpace>
1621 return operator()(global_index);
1626 template <
typename Number,
typename MemorySpace>
1630 return operator()(global_index);
1635 template <
typename Number,
typename MemorySpace>
1638 const size_type local_index)
const
1640 Assert((std::is_same_v<MemorySpace, ::MemorySpace::Host>),
1642 "This function is only implemented for the Host memory space"));
1644 partitioner->locally_owned_size() +
1645 partitioner->n_ghost_indices());
1647 Assert(local_index < locally_owned_size() || vector_is_ghosted ==
true,
1648 ExcMessage(
"You tried to read a ghost element of this vector, "
1649 "but it has not imported its ghost values."));
1651 return data.values[local_index];
1656 template <
typename Number,
typename MemorySpace>
1660 Assert((std::is_same_v<MemorySpace, ::MemorySpace::Host>),
1662 "This function is only implemented for the Host memory space"));
1665 partitioner->locally_owned_size() +
1666 partitioner->n_ghost_indices());
1668 return data.values[local_index];
1673 template <
typename Number,
typename MemorySpace>
1677 return data.values.data();
1682 template <
typename Number,
typename MemorySpace>
1683 template <
typename OtherNumber>
1686 const std::vector<size_type> &indices,
1687 std::vector<OtherNumber> &values)
const
1689 for (size_type i = 0; i < indices.size(); ++i)
1690 values[i] =
operator()(indices[i]);
1695 template <
typename Number,
typename MemorySpace>
1696 template <
typename ForwardIterator,
typename OutputIterator>
1699 ForwardIterator indices_begin,
1700 const ForwardIterator indices_end,
1701 OutputIterator values_begin)
const
1703 while (indices_begin != indices_end)
1705 *values_begin = operator()(*indices_begin);
1713 template <
typename Number,
typename MemorySpace>
1714 template <
typename OtherNumber>
1717 const std::vector<size_type> &indices,
1718 const ::Vector<OtherNumber> &values)
1721 for (size_type i = 0; i < indices.size(); ++i)
1726 "The given value is not finite but either infinite or Not A Number (NaN)"));
1727 this->operator()(indices[i]) += values(i);
1733 template <
typename Number,
typename MemorySpace>
1734 template <
typename OtherNumber>
1737 const size_type *indices,
1738 const OtherNumber *values)
1740 for (size_type i = 0; i < n_elements; ++i, ++indices, ++values)
1745 "The given value is not finite but either infinite or Not A Number (NaN)"));
1746 this->operator()(*indices) += *values;
1752 template <
typename Number,
typename MemorySpace>
1756 return partitioner->get_mpi_communicator();
1761 template <
typename Number,
typename MemorySpace>
1762 inline const std::shared_ptr<const Utilities::MPI::Partitioner> &
1770 template <
typename Number,
typename MemorySpace>
1774 vector_is_ghosted = ghosted;
1790template <
typename Number,
typename MemorySpace>
1802template <
typename Number,
typename MemorySpace>
1811 namespace LinearOperatorImplementation
1820 template <
typename Number>
1826 template <
typename T>
1828 decltype(std::declval<T>().get_mpi_communicator());
1830 template <
typename T>
1831 static constexpr bool has_get_mpi_communicator =
1836 template <
typename T>
1838 decltype(std::declval<T>().locally_owned_domain_indices());
1840 template <
typename T>
1841 static constexpr bool has_locally_owned_domain_indices =
1846 template <
typename T>
1848 decltype(std::declval<T>().locally_owned_range_indices());
1850 template <
typename T>
1851 static constexpr bool has_locally_owned_range_indices =
1856 template <
typename T>
1858 decltype(std::declval<T>().initialize_dof_vector(
1861 template <
typename T>
1862 static constexpr bool has_initialize_dof_vector =
1866 template <
typename MatrixType,
1867#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1868 std::enable_if_t<has_get_mpi_communicator<MatrixType> &&
1869 has_locally_owned_domain_indices<MatrixType>,
1877 MatrixType> * =
nullptr>
1883 vec.
reinit(mat.locally_owned_domain_indices(),
1884 mat.get_mpi_communicator());
1888 template <
typename MatrixType,
1889#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1890 std::enable_if_t<has_initialize_dof_vector<MatrixType>,
1896 MatrixType> * =
nullptr>
1900 bool omit_zeroing_entries)
1902 mat.initialize_dof_vector(vec);
1903 if (!omit_zeroing_entries)
1908 template <
typename MatrixType,
1909#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1910 std::enable_if_t<has_get_mpi_communicator<MatrixType> &&
1911 has_locally_owned_range_indices<MatrixType>,
1919 MatrixType> * =
nullptr>
1925 vec.
reinit(mat.locally_owned_range_indices(),
1926 mat.get_mpi_communicator());
1930 template <
typename MatrixType,
1931#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1932 std::enable_if_t<has_initialize_dof_vector<MatrixType>,
1938 MatrixType> * =
nullptr>
1942 bool omit_zeroing_entries)
1944 mat.initialize_dof_vector(vec);
1945 if (!omit_zeroing_entries)
Number & operator()(const size_type global_index)
void zero_out_ghost_values() const
real_type linfty_norm() const
Number mean_value_local() const
bool partitioners_are_compatible(const Utilities::MPI::Partitioner &part) const
void sadd(const Number s, const Number a, const Vector< Number, MemorySpace > &V)
bool has_ghost_elements() const
const value_type & const_reference
Number local_element(const size_type local_index) const
void reinit(const IndexSet &local_range, const MPI_Comm communicator)
Number add_and_dot_local(const Number a, const Vector< Number, MemorySpace > &V, const Vector< Number, MemorySpace > &W)
Number mean_value() const
real_type linfty_norm_local() const
void compress_finish(VectorOperation::values operation)
Number * get_values() const
void update_ghost_values() const
mutable ::MemorySpace::MemorySpaceData< Number, MemorySpace > import_data
real_type l1_norm_local() const
mutable ::MemorySpace::MemorySpaceData< Number, MemorySpace > data
void equ(const Number a, const Vector< Number, MemorySpace > &V)
types::global_dof_index size_type
Vector< Number, MemorySpace > & operator=(Vector< Number, MemorySpace > &&in_vector)
void sadd_local(const Number s, const Number a, const Vector< Number, MemorySpace > &V)
typename numbers::NumberTraits< Number >::real_type real_type
const_iterator end() const
Vector(const IndexSet &local_range, const MPI_Comm communicator)
Vector(const size_type size)
Vector(Vector< Number, MemorySpace > &&in_vector)
size_type locally_owned_size() const
void reinit(const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner, const MPI_Comm comm_sm=MPI_COMM_SELF)
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner
void add(const size_type n_elements, const size_type *indices, const OtherNumber *values)
void sadd(const Number s, const Vector< Number, MemorySpace > &V)
Vector< Number, MemorySpace > & operator=(const Vector< Number, MemorySpace > &in_vector)
real_type norm_sqr_local() const
void reinit(const IndexSet &local_range, const IndexSet &ghost_indices, const MPI_Comm communicator)
void swap(Vector< Number, MemorySpace > &v) noexcept
const value_type * const_iterator
void clear_mpi_requests()
Number operator[](const size_type global_index) const
Vector(const Vector< Number, MemorySpace > &in_vector)
void add(const Number a, const Vector< Number, MemorySpace > &V)
void set_ghost_state(const bool ghosted) const
void add(const std::vector< size_type > &indices, const std::vector< Number > &values)
::IndexSet locally_owned_elements() const
virtual void extract_subvector_to(const ArrayView< const types::global_dof_index > &indices, ArrayView< Number > &elements) const override
real_type l2_norm() const
void compress(VectorOperation::values operation)
Vector(const IndexSet &local_range, const IndexSet &ghost_indices, const MPI_Comm communicator)
Vector< Number, MemorySpace > & operator*=(const Number factor)
Vector< Number, MemorySpace > & operator+=(const Vector< Number, MemorySpace > &V)
void add(const std::vector< size_type > &indices, const ::Vector< OtherNumber > &values)
void import_elements(const Vector< Number, MemorySpace2 > &src, VectorOperation::values operation)
Number & operator[](const size_type global_index)
void add(const Number a, const Vector< Number, MemorySpace > &V, const Number b, const Vector< Number, MemorySpace > &W)
const value_type * const_pointer
void reinit(const Vector< Number2, MemorySpace > &in_vector, const bool omit_zeroing_entries=false)
real_type lp_norm(const real_type p) const
bool partitioners_are_globally_compatible(const Utilities::MPI::Partitioner &part) const
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_partitioner() const
virtual size_type size() const override
std::shared_ptr<::parallel::internal::TBBPartitioner > thread_loop_partitioner
Number add_and_dot(const Number a, const Vector< Number, MemorySpace > &V, const Vector< Number, MemorySpace > &W)
std::size_t memory_consumption() const
void update_ghost_values_finish() const
const std::vector< ArrayView< const Number > > & shared_vector_data() const
void update_ghost_values_start(const unsigned int communication_channel=0) const
void import_elements(const LinearAlgebra::ReadWriteVector< Number > &V, const VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
void copy_locally_owned_data_from(const Vector< Number2, MemorySpace > &src)
Vector< Number, MemorySpace > & operator=(const Vector< Number2, MemorySpace > &in_vector)
Vector< Number, MemorySpace > & operator=(const Number s)
Number operator()(const size_type global_index) const
real_type lp_norm_local(const real_type p) const
Vector< Number, MemorySpace > & operator-=(const Vector< Number, MemorySpace > &V)
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
void reinit(const size_type size, const bool omit_zeroing_entries=false)
MPI_Comm get_mpi_communicator() const
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< OtherNumber > &values) const
void compress_start(const unsigned int communication_channel=0, VectorOperation::values operation=VectorOperation::add)
std::vector< MPI_Request > update_ghost_values_requests
void scale(const Vector< Number, MemorySpace > &scaling_factors)
const_iterator begin() const
std::vector< MPI_Request > compress_requests
void add_local(const Number a, const Vector< Number, MemorySpace > &V)
Number operator*(const Vector< Number, MemorySpace > &V) const
bool in_local_range(const size_type global_index) const
Vector< Number, MemorySpace > & operator/=(const Number factor)
void extract_subvector_to(ForwardIterator indices_begin, const ForwardIterator indices_end, OutputIterator values_begin) const
Number inner_product_local(const Vector< Number2, MemorySpace > &V) const
Number & local_element(const size_type local_index)
void reinit(const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner, const bool make_ghosted, const MPI_Comm &comm_sm=MPI_COMM_SELF)
real_type norm_sqr() const
real_type l1_norm() const
void resize_val(const size_type new_allocated_size, const MPI_Comm comm_sm=MPI_COMM_SELF)
void reinit(const types::global_dof_index local_size, const types::global_dof_index ghost_size, const MPI_Comm comm, const MPI_Comm comm_sm=MPI_COMM_SELF)
Vector(const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner)
const value_type * const_iterator
void swap(LinearAlgebra::distributed::Vector< Number, MemorySpace > &u, LinearAlgebra::distributed::Vector< Number, MemorySpace > &v) noexcept
decltype(std::declval< T >().locally_owned_range_indices()) locally_owned_range_indices_t
static void reinit_range_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool)
decltype(std::declval< T >().locally_owned_domain_indices()) locally_owned_domain_indices_t
static void reinit_range_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool omit_zeroing_entries)
decltype(std::declval< T >().initialize_dof_vector( std::declval< LinearAlgebra::distributed::Vector< Number > & >())) initialize_dof_vector_t
static void reinit_domain_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool omit_zeroing_entries)
decltype(std::declval< T >().get_mpi_communicator()) get_mpi_communicator_t
static void reinit_domain_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool)
#define DEAL_II_DEPRECATED
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
#define DeclException0(Exception0)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
static ::ExceptionBase & ExcVectorTypeNotCompatible()
static ::ExceptionBase & ExcNonMatchingElements(Number arg1, Number arg2, unsigned int arg3)
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
static ::ExceptionBase & ExcMessage(std::string arg1)
constexpr bool is_supported_operation
bool is_finite(const double x)
unsigned int global_dof_index
*braid_SplitCommworld & comm