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>
265 std::is_same_v<MemorySpace, ::MemorySpace::Host> ||
266 std::is_same_v<MemorySpace, ::MemorySpace::Default>,
267 "MemorySpace should be Host or Default");
333 const std::shared_ptr<const Utilities::MPI::Partitioner> &
partitioner);
357 template <
typename Number2>
360 const bool omit_zeroing_entries =
false);
403 const std::shared_ptr<const Utilities::MPI::Partitioner> &
partitioner,
414 const std::shared_ptr<const Utilities::MPI::Partitioner> &
partitioner,
415 const bool make_ghosted,
509 template <
typename Number2>
642 const unsigned int communication_channel = 0)
const;
694 template <
typename Number2>
708 template <
typename MemorySpace2>
716 template <
typename MemorySpace2>
770 const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
771 &communication_pattern = {});
779 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
780 communication_pattern = {})
817 add(
const std::vector<size_type> &indices,
818 const std::vector<Number> &values);
921 const unsigned int precision = 3,
922 const bool scientific =
true,
923 const bool across =
true)
const;
949 template <
typename OtherNumber>
951 add(
const std::vector<size_type> &indices,
952 const ::Vector<OtherNumber> &values);
958 template <
typename OtherNumber>
962 const OtherNumber *values);
1127 template <
typename OtherNumber>
1130 std::vector<OtherNumber> &values)
const;
1167 template <
typename ForwardIterator,
typename OutputIterator>
1170 const ForwardIterator indices_end,
1171 OutputIterator values_begin)
const;
1211 const std::shared_ptr<const Utilities::MPI::Partitioner> &
1254 const std::vector<ArrayView<const Number>> &
1273 <<
"Called compress(VectorOperation::insert), but"
1274 <<
" the element received from a remote processor, value "
1275 << std::setprecision(16) << arg1
1276 <<
", does not match with the value "
1277 << std::setprecision(16) << arg2
1278 <<
" on the owner processor " << arg3);
1289 <<
"You tried to access element " << arg1
1290 <<
" of a distributed vector, but this element is not "
1291 <<
"stored on the current processor. Note: The range of "
1292 <<
"locally owned elements is [" << arg2 <<
',' << arg3
1293 <<
"], and there are " << arg4 <<
" ghost elements "
1294 <<
"that this vector can access."
1296 <<
"A common source for this kind of problem is that you "
1297 <<
"are passing a 'fully distributed' vector into a function "
1298 <<
"that needs read access to vector elements that correspond "
1299 <<
"to degrees of freedom on ghost cells (or at least to "
1300 <<
"'locally active' degrees of freedom that are not also "
1301 <<
"'locally owned'). You need to pass a vector that has these "
1302 <<
"elements as ghost entries.");
1324 template <
typename Number2>
1383 mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace>
data;
1389 mutable std::shared_ptr<::parallel::internal::TBBPartitioner>
1396 mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace>
1408#ifdef DEAL_II_WITH_MPI
1455 template <
typename Number2,
typename MemorySpace2>
1459 template <
typename Number2>
1469 template <
typename Number,
typename MemorySpace>
1473 return vector_is_ghosted;
1478 template <
typename Number,
typename MemorySpace>
1482 return partitioner->size();
1487 template <
typename Number,
typename MemorySpace>
1491 return partitioner->locally_owned_size();
1496 template <
typename Number,
typename MemorySpace>
1499 const size_type global_index)
const
1501 return partitioner->in_local_range(global_index);
1506 template <
typename Number,
typename MemorySpace>
1512 is.add_range(partitioner->local_range().first,
1513 partitioner->local_range().second);
1520 template <
typename Number,
typename MemorySpace>
1524 return data.values.data();
1529 template <
typename Number,
typename MemorySpace>
1533 return data.values.data();
1538 template <
typename Number,
typename MemorySpace>
1542 return data.values.data() + partitioner->locally_owned_size();
1547 template <
typename Number,
typename MemorySpace>
1551 return data.values.data() + partitioner->locally_owned_size();
1556 template <
typename Number,
typename MemorySpace>
1557 const std::vector<ArrayView<const Number>> &
1560 return data.values_sm;
1565 template <
typename Number,
typename MemorySpace>
1569 Assert((std::is_same_v<MemorySpace, ::MemorySpace::Host>),
1571 "This function is only implemented for the Host memory space"));
1573 partitioner->in_local_range(global_index) ||
1574 partitioner->ghost_indices().is_element(global_index),
1575 ExcAccessToNonLocalElement(global_index,
1576 partitioner->local_range().first,
1577 partitioner->local_range().second == 0 ?
1579 (partitioner->local_range().
second - 1),
1580 partitioner->ghost_indices().n_elements()));
1582 Assert(partitioner->in_local_range(global_index) ||
1583 vector_is_ghosted ==
true,
1584 ExcMessage(
"You tried to read a ghost element of this vector, "
1585 "but it has not imported its ghost values."));
1586 return data.values[partitioner->global_to_local(global_index)];
1591 template <
typename Number,
typename MemorySpace>
1595 Assert((std::is_same_v<MemorySpace, ::MemorySpace::Host>),
1597 "This function is only implemented for the Host memory space"));
1599 partitioner->in_local_range(global_index) ||
1600 partitioner->ghost_indices().is_element(global_index),
1601 ExcAccessToNonLocalElement(global_index,
1602 partitioner->local_range().first,
1603 partitioner->local_range().second == 0 ?
1605 (partitioner->local_range().
second - 1),
1606 partitioner->ghost_indices().n_elements()));
1613 return data.values[partitioner->global_to_local(global_index)];
1618 template <
typename Number,
typename MemorySpace>
1622 return operator()(global_index);
1627 template <
typename Number,
typename MemorySpace>
1631 return operator()(global_index);
1636 template <
typename Number,
typename MemorySpace>
1639 const size_type local_index)
const
1641 Assert((std::is_same_v<MemorySpace, ::MemorySpace::Host>),
1643 "This function is only implemented for the Host memory space"));
1645 partitioner->locally_owned_size() +
1646 partitioner->n_ghost_indices());
1648 Assert(local_index < locally_owned_size() || vector_is_ghosted ==
true,
1649 ExcMessage(
"You tried to read a ghost element of this vector, "
1650 "but it has not imported its ghost values."));
1652 return data.values[local_index];
1657 template <
typename Number,
typename MemorySpace>
1661 Assert((std::is_same_v<MemorySpace, ::MemorySpace::Host>),
1663 "This function is only implemented for the Host memory space"));
1666 partitioner->locally_owned_size() +
1667 partitioner->n_ghost_indices());
1669 return data.values[local_index];
1674 template <
typename Number,
typename MemorySpace>
1678 return data.values.data();
1683 template <
typename Number,
typename MemorySpace>
1684 template <
typename OtherNumber>
1687 const std::vector<size_type> &indices,
1688 std::vector<OtherNumber> &values)
const
1690 for (size_type i = 0; i < indices.size(); ++i)
1691 values[i] =
operator()(indices[i]);
1696 template <
typename Number,
typename MemorySpace>
1697 template <
typename ForwardIterator,
typename OutputIterator>
1700 ForwardIterator indices_begin,
1701 const ForwardIterator indices_end,
1702 OutputIterator values_begin)
const
1704 while (indices_begin != indices_end)
1706 *values_begin = operator()(*indices_begin);
1714 template <
typename Number,
typename MemorySpace>
1715 template <
typename OtherNumber>
1718 const std::vector<size_type> &indices,
1719 const ::Vector<OtherNumber> &values)
1722 for (size_type i = 0; i < indices.size(); ++i)
1727 "The given value is not finite but either infinite or Not A Number (NaN)"));
1728 this->operator()(indices[i]) +=
values(i);
1734 template <
typename Number,
typename MemorySpace>
1735 template <
typename OtherNumber>
1738 const size_type *indices,
1739 const OtherNumber *values)
1741 for (size_type i = 0; i < n_elements; ++i, ++indices, ++
values)
1746 "The given value is not finite but either infinite or Not A Number (NaN)"));
1747 this->operator()(*indices) += *
values;
1753 template <
typename Number,
typename MemorySpace>
1757 return partitioner->get_mpi_communicator();
1762 template <
typename Number,
typename MemorySpace>
1763 inline const std::shared_ptr<const Utilities::MPI::Partitioner> &
1771 template <
typename Number,
typename MemorySpace>
1775 vector_is_ghosted = ghosted;
1791template <
typename Number,
typename MemorySpace>
1803template <
typename Number,
typename MemorySpace>
1812 namespace LinearOperatorImplementation
1821 template <
typename Number>
1827 template <
typename T>
1829 decltype(std::declval<T>().get_mpi_communicator());
1831 template <
typename T>
1832 static constexpr bool has_get_mpi_communicator =
1833 is_supported_operation<get_mpi_communicator_t, T>;
1837 template <
typename T>
1839 decltype(std::declval<T>().locally_owned_domain_indices());
1841 template <
typename T>
1842 static constexpr bool has_locally_owned_domain_indices =
1843 is_supported_operation<locally_owned_domain_indices_t, T>;
1847 template <
typename T>
1849 decltype(std::declval<T>().locally_owned_range_indices());
1851 template <
typename T>
1852 static constexpr bool has_locally_owned_range_indices =
1853 is_supported_operation<locally_owned_range_indices_t, T>;
1857 template <
typename T>
1859 decltype(std::declval<T>().initialize_dof_vector(
1862 template <
typename T>
1863 static constexpr bool has_initialize_dof_vector =
1864 is_supported_operation<initialize_dof_vector_t, T>;
1867 template <
typename MatrixType,
1868#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1869 std::enable_if_t<has_get_mpi_communicator<MatrixType> &&
1870 has_locally_owned_domain_indices<MatrixType>,
1874 is_supported_operation<get_mpi_communicator_t, MatrixType> &&
1878 MatrixType> * =
nullptr>
1884 vec.
reinit(mat.locally_owned_domain_indices(),
1885 mat.get_mpi_communicator());
1889 template <
typename MatrixType,
1890#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1891 std::enable_if_t<has_initialize_dof_vector<MatrixType>,
1895 is_supported_operation<initialize_dof_vector_t, MatrixType>,
1897 MatrixType> * =
nullptr>
1901 bool omit_zeroing_entries)
1903 mat.initialize_dof_vector(vec);
1904 if (!omit_zeroing_entries)
1909 template <
typename MatrixType,
1910#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1911 std::enable_if_t<has_get_mpi_communicator<MatrixType> &&
1912 has_locally_owned_range_indices<MatrixType>,
1916 is_supported_operation<get_mpi_communicator_t, MatrixType> &&
1920 MatrixType> * =
nullptr>
1926 vec.
reinit(mat.locally_owned_range_indices(),
1927 mat.get_mpi_communicator());
1931 template <
typename MatrixType,
1932#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1933 std::enable_if_t<has_initialize_dof_vector<MatrixType>,
1937 is_supported_operation<initialize_dof_vector_t, MatrixType>,
1939 MatrixType> * =
nullptr>
1943 bool omit_zeroing_entries)
1945 mat.initialize_dof_vector(vec);
1946 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)
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 >().initialize_dof_vector(std::declval< LinearAlgebra::distributed::Vector< Number > & >())) initialize_dof_vector_t
decltype(std::declval< T >().get_mpi_communicator()) get_mpi_communicator_t
static void reinit_range_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool)
static void reinit_range_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool omit_zeroing_entries)
decltype(std::declval< T >().locally_owned_domain_indices()) locally_owned_domain_indices_t
decltype(std::declval< T >().locally_owned_range_indices()) locally_owned_range_indices_t
static void reinit_domain_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool omit_zeroing_entries)
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