Reference documentation for deal.II version 9.4.1
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
la_parallel_vector.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2011 - 2022 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_la_parallel_vector_h
17#define dealii_la_parallel_vector_h
18
19#include <deal.II/base/config.h>
20
24#include <deal.II/base/mpi.h>
30
34
35#include <iomanip>
36#include <memory>
37
39
40// Forward declarations
41#ifndef DOXYGEN
42namespace LinearAlgebra
43{
47 namespace distributed
48 {
49 template <typename>
50 class BlockVector;
51 }
52
53 template <typename>
54 class ReadWriteVector;
55} // namespace LinearAlgebra
56
57# ifdef DEAL_II_WITH_PETSC
58namespace PETScWrappers
59{
60 namespace MPI
61 {
62 class Vector;
63 }
64} // namespace PETScWrappers
65# endif
66
67# ifdef DEAL_II_WITH_TRILINOS
68namespace TrilinosWrappers
69{
70 namespace MPI
71 {
72 class Vector;
73 }
74} // namespace TrilinosWrappers
75# endif
76#endif
77
78namespace LinearAlgebra
79{
80 namespace distributed
81 {
249 template <typename Number, typename MemorySpace = MemorySpace::Host>
251 public Subscriptor
252 {
253 public:
255 using value_type = Number;
257 using const_pointer = const value_type *;
259 using const_iterator = const value_type *;
264
265 static_assert(
266 std::is_same<MemorySpace, ::MemorySpace::Host>::value ||
267 std::is_same<MemorySpace, ::MemorySpace::CUDA>::value,
268 "MemorySpace should be Host or CUDA");
269
278
286
294 Vector(Vector<Number, MemorySpace> &&in_vector); // NOLINT
295
301
318 Vector(const IndexSet &local_range,
319 const IndexSet &ghost_indices,
320 const MPI_Comm &communicator);
321
325 Vector(const IndexSet &local_range, const MPI_Comm &communicator);
326
334 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner);
335
339 virtual ~Vector() override;
340
345 void
346 reinit(const size_type size, const bool omit_zeroing_entries = false);
347
358 template <typename Number2>
359 void
361 const bool omit_zeroing_entries = false);
362
379 void
380 reinit(const IndexSet &local_range,
381 const IndexSet &ghost_indices,
382 const MPI_Comm &communicator);
383
387 void
388 reinit(const IndexSet &local_range, const MPI_Comm &communicator);
389
402 void
404 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
405 const MPI_Comm &comm_sm = MPI_COMM_SELF);
406
426 void
428 const types::global_dof_index ghost_size,
429 const MPI_Comm & comm,
430 const MPI_Comm & comm_sm = MPI_COMM_SELF);
431
444 void
446
460
472 template <typename Number2>
475
477
517 virtual void
519
541 void
543
561 void
563 const unsigned int communication_channel = 0,
565
584 void
586
604 void
606 const unsigned int communication_channel = 0) const;
607
608
616 void
618
631
640 void
642
654 bool
656
671 template <typename Number2>
672 void
674
685 template <typename MemorySpace2>
686 void
688 VectorOperation::values operation);
689
691
696
701 virtual void
703 const bool omit_zeroing_entries = false) override;
704
709 operator*=(const Number factor) override;
710
715 operator/=(const Number factor) override;
716
722
728
740 virtual void
742 VectorOperation::values operation,
743 std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
744 communication_pattern = {}) override;
745
749 virtual Number
750 operator*(const VectorSpaceVector<Number> &V) const override;
751
755 virtual void
756 add(const Number a) override;
757
761 virtual void
762 add(const Number a, const VectorSpaceVector<Number> &V) override;
763
767 virtual void
768 add(const Number a,
770 const Number b,
771 const VectorSpaceVector<Number> &W) override;
772
777 virtual void
778 add(const std::vector<size_type> &indices,
779 const std::vector<Number> & values);
780
785 virtual void
786 sadd(const Number s,
787 const Number a,
788 const VectorSpaceVector<Number> &V) override;
789
795 virtual void
796 scale(const VectorSpaceVector<Number> &scaling_factors) override;
797
801 virtual void
802 equ(const Number a, const VectorSpaceVector<Number> &V) override;
803
808 virtual real_type
809 l1_norm() const override;
810
815 virtual real_type
816 l2_norm() const override;
817
822 norm_sqr() const;
823
828 virtual real_type
829 linfty_norm() const override;
830
851 virtual Number
852 add_and_dot(const Number a,
854 const VectorSpaceVector<Number> &W) override;
855
860 virtual size_type
861 size() const override;
862
874 virtual ::IndexSet
875 locally_owned_elements() const override;
876
880 virtual void
881 print(std::ostream & out,
882 const unsigned int precision = 3,
883 const bool scientific = true,
884 const bool across = true) const override;
885
889 virtual std::size_t
890 memory_consumption() const override;
892
897
904 operator=(const Number s) override;
905
910 template <typename OtherNumber>
911 void
912 add(const std::vector<size_type> & indices,
913 const ::Vector<OtherNumber> &values);
914
919 template <typename OtherNumber>
920 void
921 add(const size_type n_elements,
922 const size_type * indices,
923 const OtherNumber *values);
924
929 void
930 sadd(const Number s, const Vector<Number, MemorySpace> &V);
931
933
934
939
948 local_size() const;
949
956
961 bool
962 in_local_range(const size_type global_index) const;
963
976
985 begin() const;
986
996
1005 end() const;
1006
1016 Number
1017 operator()(const size_type global_index) const;
1018
1028 Number &
1029 operator()(const size_type global_index);
1030
1038 Number
1039 operator[](const size_type global_index) const;
1047 Number &
1048 operator[](const size_type global_index);
1049
1058 Number
1059 local_element(const size_type local_index) const;
1060
1069 Number &
1070 local_element(const size_type local_index);
1071
1078 Number *
1079 get_values() const;
1080
1098 template <typename OtherNumber>
1099 void
1100 extract_subvector_to(const std::vector<size_type> &indices,
1101 std::vector<OtherNumber> & values) const;
1102
1130 template <typename ForwardIterator, typename OutputIterator>
1131 void
1132 extract_subvector_to(ForwardIterator indices_begin,
1133 const ForwardIterator indices_end,
1134 OutputIterator values_begin) const;
1140 virtual bool
1141 all_zero() const override;
1142
1146 virtual Number
1147 mean_value() const override;
1148
1153 real_type
1154 lp_norm(const real_type p) const;
1156
1161
1166 const MPI_Comm &
1168
1175 const std::shared_ptr<const Utilities::MPI::Partitioner> &
1177
1187 bool
1189 const Utilities::MPI::Partitioner &part) const;
1190
1204 bool
1206 const Utilities::MPI::Partitioner &part) const;
1207
1211 void
1212 set_ghost_state(const bool ghosted) const;
1213
1218 const std::vector<ArrayView<const Number>> &
1220
1222
1229
1236
1241 Number,
1242 Number,
1243 unsigned int,
1244 << "Called compress(VectorOperation::insert), but"
1245 << " the element received from a remote processor, value "
1246 << std::setprecision(16) << arg1
1247 << ", does not match with the value "
1248 << std::setprecision(16) << arg2
1249 << " on the owner processor " << arg3);
1250
1256 size_type,
1257 size_type,
1258 size_type,
1259 size_type,
1260 << "You tried to access element " << arg1
1261 << " of a distributed vector, but this element is not "
1262 << "stored on the current processor. Note: The range of "
1263 << "locally owned elements is [" << arg2 << ',' << arg3
1264 << "], and there are " << arg4 << " ghost elements "
1265 << "that this vector can access."
1266 << "\n\n"
1267 << "A common source for this kind of problem is that you "
1268 << "are passing a 'fully distributed' vector into a function "
1269 << "that needs read access to vector elements that correspond "
1270 << "to degrees of freedom on ghost cells (or at least to "
1271 << "'locally active' degrees of freedom that are not also "
1272 << "'locally owned'). You need to pass a vector that has these "
1273 << "elements as ghost entries.");
1274
1275 private:
1280 void
1281 add_local(const Number a, const VectorSpaceVector<Number> &V);
1282
1287 void
1288 sadd_local(const Number s,
1289 const Number a,
1290 const VectorSpaceVector<Number> &V);
1291
1295 template <typename Number2>
1296 Number
1298
1302 real_type
1304
1308 Number
1310
1314 real_type
1316
1320 real_type
1321 lp_norm_local(const real_type p) const;
1322
1326 real_type
1328
1334 Number
1335 add_and_dot_local(const Number a,
1338
1344 std::shared_ptr<const Utilities::MPI::Partitioner> partitioner;
1345
1350
1354 mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace> data;
1355
1360 mutable std::shared_ptr<::parallel::internal::TBBPartitioner>
1362
1367 mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace>
1369
1377 mutable bool vector_is_ghosted;
1378
1379#ifdef DEAL_II_WITH_MPI
1388 std::vector<MPI_Request> compress_requests;
1389
1394 mutable std::vector<MPI_Request> update_ghost_values_requests;
1395#endif
1396
1402 mutable std::mutex mutex;
1403
1410
1415 void
1417
1421 void
1422 resize_val(const size_type new_allocated_size,
1423 const MPI_Comm &comm_sm = MPI_COMM_SELF);
1424
1425 // Make all other vector types friends.
1426 template <typename Number2, typename MemorySpace2>
1427 friend class Vector;
1428
1429 // Make BlockVector type friends.
1430 template <typename Number2>
1431 friend class BlockVector;
1432 };
1436 /*-------------------- Inline functions ---------------------------------*/
1437
1438#ifndef DOXYGEN
1439
1440 namespace internal
1441 {
1442 template <typename Number, typename MemorySpace>
1443 struct Policy
1444 {
1445 static inline typename Vector<Number, MemorySpace>::iterator
1447 {
1448 return nullptr;
1449 }
1450
1451 static inline typename Vector<Number, MemorySpace>::const_iterator
1452 begin(
1453 const ::MemorySpace::MemorySpaceData<Number, MemorySpace> &)
1454 {
1455 return nullptr;
1456 }
1457
1458 static inline Number *
1459 get_values(
1461 {
1462 return nullptr;
1463 }
1464 };
1465
1466
1467
1468 template <typename Number>
1469 struct Policy<Number, ::MemorySpace::Host>
1470 {
1471 static inline
1473 begin(::MemorySpace::
1474 MemorySpaceData<Number, ::MemorySpace::Host> &data)
1475 {
1476 return data.values.get();
1477 }
1478
1479 static inline
1481 begin(const ::MemorySpace::
1482 MemorySpaceData<Number, ::MemorySpace::Host> &data)
1483 {
1484 return data.values.get();
1485 }
1486
1487 static inline Number *
1488 get_values(::MemorySpace::
1489 MemorySpaceData<Number, ::MemorySpace::Host> &data)
1490 {
1491 return data.values.get();
1492 }
1493 };
1494
1495
1496
1497 template <typename Number>
1498 struct Policy<Number, ::MemorySpace::CUDA>
1499 {
1500 static inline
1502 begin(::MemorySpace::
1503 MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1504 {
1505 return data.values_dev.get();
1506 }
1507
1508 static inline
1510 begin(const ::MemorySpace::
1511 MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1512 {
1513 return data.values_dev.get();
1514 }
1515
1516 static inline Number *
1517 get_values(::MemorySpace::
1518 MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1519 {
1520 return data.values_dev.get();
1521 }
1522 };
1523 } // namespace internal
1524
1525
1526 template <typename Number, typename MemorySpace>
1527 inline bool
1529 {
1530 return vector_is_ghosted;
1531 }
1532
1533
1534
1535 template <typename Number, typename MemorySpace>
1538 {
1539 return partitioner->size();
1540 }
1541
1542
1543
1544 template <typename Number, typename MemorySpace>
1547 {
1548 return locally_owned_size();
1549 }
1550
1551
1552
1553 template <typename Number, typename MemorySpace>
1556 {
1557 return partitioner->locally_owned_size();
1558 }
1559
1560
1561
1562 template <typename Number, typename MemorySpace>
1563 inline bool
1565 const size_type global_index) const
1566 {
1567 return partitioner->in_local_range(global_index);
1568 }
1569
1570
1571
1572 template <typename Number, typename MemorySpace>
1573 inline IndexSet
1575 {
1576 IndexSet is(size());
1577
1578 is.add_range(partitioner->local_range().first,
1579 partitioner->local_range().second);
1580
1581 return is;
1582 }
1583
1584
1585
1586 template <typename Number, typename MemorySpace>
1589 {
1590 return internal::Policy<Number, MemorySpace>::begin(data);
1591 }
1592
1593
1594
1595 template <typename Number, typename MemorySpace>
1598 {
1599 return internal::Policy<Number, MemorySpace>::begin(data);
1600 }
1601
1602
1603
1604 template <typename Number, typename MemorySpace>
1607 {
1608 return internal::Policy<Number, MemorySpace>::begin(data) +
1609 partitioner->locally_owned_size();
1610 }
1611
1612
1613
1614 template <typename Number, typename MemorySpace>
1617 {
1618 return internal::Policy<Number, MemorySpace>::begin(data) +
1619 partitioner->locally_owned_size();
1620 }
1621
1622
1623
1624 template <typename Number, typename MemorySpace>
1625 const std::vector<ArrayView<const Number>> &
1627 {
1628 return data.values_sm;
1629 }
1630
1631
1632
1633 template <typename Number, typename MemorySpace>
1634 inline Number
1635 Vector<Number, MemorySpace>::operator()(const size_type global_index) const
1636 {
1637 Assert((std::is_same<MemorySpace, ::MemorySpace::Host>::value),
1638 ExcMessage(
1639 "This function is only implemented for the Host memory space"));
1640 Assert(
1641 partitioner->in_local_range(global_index) ||
1642 partitioner->ghost_indices().is_element(global_index),
1643 ExcAccessToNonLocalElement(global_index,
1644 partitioner->local_range().first,
1645 partitioner->local_range().second == 0 ?
1646 0 :
1647 (partitioner->local_range().second - 1),
1648 partitioner->ghost_indices().n_elements()));
1649 // do not allow reading a vector which is not in ghost mode
1650 Assert(partitioner->in_local_range(global_index) ||
1651 vector_is_ghosted == true,
1652 ExcMessage("You tried to read a ghost element of this vector, "
1653 "but it has not imported its ghost values."));
1654 return data.values[partitioner->global_to_local(global_index)];
1655 }
1656
1657
1658
1659 template <typename Number, typename MemorySpace>
1660 inline Number &
1661 Vector<Number, MemorySpace>::operator()(const size_type global_index)
1662 {
1663 Assert((std::is_same<MemorySpace, ::MemorySpace::Host>::value),
1664 ExcMessage(
1665 "This function is only implemented for the Host memory space"));
1666 Assert(
1667 partitioner->in_local_range(global_index) ||
1668 partitioner->ghost_indices().is_element(global_index),
1669 ExcAccessToNonLocalElement(global_index,
1670 partitioner->local_range().first,
1671 partitioner->local_range().second == 0 ?
1672 0 :
1673 (partitioner->local_range().second - 1),
1674 partitioner->ghost_indices().n_elements()));
1675 // we would like to prevent reading ghosts from a vector that does not
1676 // have them imported, but this is not possible because we might be in a
1677 // part of the code where the vector has enabled ghosts but is non-const
1678 // (then, the compiler picks this method according to the C++ rule book
1679 // even if a human would pick the const method when this subsequent use
1680 // is just a read)
1681 return data.values[partitioner->global_to_local(global_index)];
1682 }
1683
1684
1685
1686 template <typename Number, typename MemorySpace>
1687 inline Number
1688 Vector<Number, MemorySpace>::operator[](const size_type global_index) const
1689 {
1690 return operator()(global_index);
1691 }
1692
1693
1694
1695 template <typename Number, typename MemorySpace>
1696 inline Number &
1697 Vector<Number, MemorySpace>::operator[](const size_type global_index)
1698 {
1699 return operator()(global_index);
1700 }
1701
1702
1703
1704 template <typename Number, typename MemorySpace>
1705 inline Number
1707 const size_type local_index) const
1708 {
1709 Assert((std::is_same<MemorySpace, ::MemorySpace::Host>::value),
1710 ExcMessage(
1711 "This function is only implemented for the Host memory space"));
1712 AssertIndexRange(local_index,
1713 partitioner->locally_owned_size() +
1714 partitioner->n_ghost_indices());
1715 // do not allow reading a vector which is not in ghost mode
1716 Assert(local_index < locally_owned_size() || vector_is_ghosted == true,
1717 ExcMessage("You tried to read a ghost element of this vector, "
1718 "but it has not imported its ghost values."));
1719
1720 return data.values[local_index];
1721 }
1722
1723
1724
1725 template <typename Number, typename MemorySpace>
1726 inline Number &
1727 Vector<Number, MemorySpace>::local_element(const size_type local_index)
1728 {
1729 Assert((std::is_same<MemorySpace, ::MemorySpace::Host>::value),
1730 ExcMessage(
1731 "This function is only implemented for the Host memory space"));
1732
1733 AssertIndexRange(local_index,
1734 partitioner->locally_owned_size() +
1735 partitioner->n_ghost_indices());
1736
1737 return data.values[local_index];
1738 }
1739
1740
1741
1742 template <typename Number, typename MemorySpace>
1743 inline Number *
1745 {
1746 return internal::Policy<Number, MemorySpace>::get_values(data);
1747 }
1748
1749
1750
1751 template <typename Number, typename MemorySpace>
1752 template <typename OtherNumber>
1753 inline void
1755 const std::vector<size_type> &indices,
1756 std::vector<OtherNumber> & values) const
1757 {
1758 for (size_type i = 0; i < indices.size(); ++i)
1759 values[i] = operator()(indices[i]);
1760 }
1761
1762
1763
1764 template <typename Number, typename MemorySpace>
1765 template <typename ForwardIterator, typename OutputIterator>
1766 inline void
1768 ForwardIterator indices_begin,
1769 const ForwardIterator indices_end,
1770 OutputIterator values_begin) const
1771 {
1772 while (indices_begin != indices_end)
1773 {
1774 *values_begin = operator()(*indices_begin);
1775 indices_begin++;
1776 values_begin++;
1777 }
1778 }
1779
1780
1781
1782 template <typename Number, typename MemorySpace>
1783 template <typename OtherNumber>
1784 inline void
1786 const std::vector<size_type> & indices,
1787 const ::Vector<OtherNumber> &values)
1788 {
1789 AssertDimension(indices.size(), values.size());
1790 for (size_type i = 0; i < indices.size(); ++i)
1791 {
1792 Assert(
1793 numbers::is_finite(values[i]),
1794 ExcMessage(
1795 "The given value is not finite but either infinite or Not A Number (NaN)"));
1796 this->operator()(indices[i]) += values(i);
1797 }
1798 }
1799
1800
1801
1802 template <typename Number, typename MemorySpace>
1803 template <typename OtherNumber>
1804 inline void
1805 Vector<Number, MemorySpace>::add(const size_type n_elements,
1806 const size_type * indices,
1807 const OtherNumber *values)
1808 {
1809 for (size_type i = 0; i < n_elements; ++i, ++indices, ++values)
1810 {
1811 Assert(
1812 numbers::is_finite(*values),
1813 ExcMessage(
1814 "The given value is not finite but either infinite or Not A Number (NaN)"));
1815 this->operator()(*indices) += *values;
1816 }
1817 }
1818
1819
1820
1821 template <typename Number, typename MemorySpace>
1822 inline const MPI_Comm &
1824 {
1825 return partitioner->get_mpi_communicator();
1826 }
1827
1828
1829
1830 template <typename Number, typename MemorySpace>
1831 inline const std::shared_ptr<const Utilities::MPI::Partitioner> &
1833 {
1834 return partitioner;
1835 }
1836
1837
1838
1839 template <typename Number, typename MemorySpace>
1840 inline void
1841 Vector<Number, MemorySpace>::set_ghost_state(const bool ghosted) const
1842 {
1843 vector_is_ghosted = ghosted;
1844 }
1845
1846#endif
1847
1848 } // namespace distributed
1849} // namespace LinearAlgebra
1850
1851
1859template <typename Number, typename MemorySpace>
1860inline void
1863{
1864 u.swap(v);
1865}
1866
1867
1871template <typename Number, typename MemorySpace>
1872struct is_serial_vector<LinearAlgebra::distributed::Vector<Number, MemorySpace>>
1873 : std::false_type
1874{};
1875
1876
1877
1878namespace internal
1879{
1880 namespace LinearOperatorImplementation
1881 {
1882 template <typename>
1883 class ReinitHelper;
1884
1889 template <typename Number>
1890 class ReinitHelper<LinearAlgebra::distributed::Vector<Number>>
1891 {
1892 public:
1893 // A helper type-trait that leverage SFINAE to figure out if type T has
1894 // void T::get_mpi_communicator()
1895 template <typename T>
1897 decltype(std::declval<T>().get_mpi_communicator());
1898
1899 template <typename T>
1900 static constexpr bool has_get_mpi_communicator =
1901 is_supported_operation<get_mpi_communicator_t, T>;
1902
1903 // A helper type-trait that leverage SFINAE to figure out if type T has
1904 // void T::locally_owned_domain_indices()
1905 template <typename T>
1907 decltype(std::declval<T>().locally_owned_domain_indices());
1908
1909 template <typename T>
1910 static constexpr bool has_locally_owned_domain_indices =
1911 is_supported_operation<locally_owned_domain_indices_t, T>;
1912
1913 // A helper type-trait that leverage SFINAE to figure out if type T has
1914 // void T::locally_owned_range_indices()
1915 template <typename T>
1917 decltype(std::declval<T>().locally_owned_range_indices());
1918
1919 template <typename T>
1920 static constexpr bool has_locally_owned_range_indices =
1921 is_supported_operation<locally_owned_range_indices_t, T>;
1922
1923 // A helper type-trait that leverage SFINAE to figure out if type T has
1924 // void T::initialize_dof_vector(VectorType v)
1925 template <typename T>
1927 decltype(std::declval<T>().initialize_dof_vector(
1929
1930 template <typename T>
1931 static constexpr bool has_initialize_dof_vector =
1932 is_supported_operation<initialize_dof_vector_t, T>;
1933
1934 // Used for (Trilinos/PETSc)Wrappers::SparseMatrix
1935 template <
1936 typename MatrixType,
1937#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1938 typename std::enable_if<has_get_mpi_communicator<MatrixType> &&
1939 has_locally_owned_domain_indices<MatrixType>,
1940#else
1941 // workaround for Intel 18
1942 typename std::enable_if<
1943 is_supported_operation<get_mpi_communicator_t, MatrixType> &&
1944 is_supported_operation<locally_owned_domain_indices_t, MatrixType>,
1945#endif
1946 MatrixType>::type * = nullptr>
1947 static void
1948 reinit_domain_vector(MatrixType & mat,
1950 bool /*omit_zeroing_entries*/)
1951 {
1952 vec.reinit(mat.locally_owned_domain_indices(),
1953 mat.get_mpi_communicator());
1954 }
1955
1956 // Used for MatrixFree and DiagonalMatrix
1957 template <typename MatrixType,
1958#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1959 typename std::enable_if<has_initialize_dof_vector<MatrixType>,
1960#else
1961 // workaround for Intel 18
1962 typename std::enable_if<
1963 is_supported_operation<initialize_dof_vector_t, MatrixType>,
1964#endif
1965 MatrixType>::type * = nullptr>
1966 static void
1967 reinit_domain_vector(MatrixType & mat,
1969 bool omit_zeroing_entries)
1970 {
1971 mat.initialize_dof_vector(vec);
1972 if (!omit_zeroing_entries)
1973 vec = Number();
1974 }
1975
1976 // Used for (Trilinos/PETSc)Wrappers::SparseMatrix
1977 template <
1978 typename MatrixType,
1979#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1980 typename std::enable_if<has_get_mpi_communicator<MatrixType> &&
1981 has_locally_owned_range_indices<MatrixType>,
1982#else
1983 // workaround for Intel 18
1984 typename std::enable_if<
1985 is_supported_operation<get_mpi_communicator_t, MatrixType> &&
1986 is_supported_operation<locally_owned_range_indices_t, MatrixType>,
1987#endif
1988 MatrixType>::type * = nullptr>
1989 static void
1990 reinit_range_vector(MatrixType & mat,
1992 bool /*omit_zeroing_entries*/)
1993 {
1994 vec.reinit(mat.locally_owned_range_indices(),
1995 mat.get_mpi_communicator());
1996 }
1997
1998 // Used for MatrixFree and DiagonalMatrix
1999 template <typename MatrixType,
2000#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
2001 typename std::enable_if<has_initialize_dof_vector<MatrixType>,
2002#else
2003 // workaround for Intel 18
2004 typename std::enable_if<
2005 is_supported_operation<initialize_dof_vector_t, MatrixType>,
2006#endif
2007 MatrixType>::type * = nullptr>
2008 static void
2009 reinit_range_vector(MatrixType & mat,
2011 bool omit_zeroing_entries)
2012 {
2013 mat.initialize_dof_vector(vec);
2014 if (!omit_zeroing_entries)
2015 vec = Number();
2016 }
2017 };
2018
2019 } // namespace LinearOperatorImplementation
2020} /* namespace internal */
2021
2022
2024
2025#endif
Definition: vector.h:109
void swap(LinearAlgebra::distributed::Vector< Number, MemorySpace > &u, LinearAlgebra::distributed::Vector< Number, MemorySpace > &v)
static void reinit_range_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 omit_zeroing_entries)
#define DEAL_II_DEPRECATED
Definition: config.h:164
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
#define DeclException0(Exception0)
Definition: exceptions.h:464
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
Definition: exceptions.h:578
#define Assert(cond, exc)
Definition: exceptions.h:1473
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1667
#define AssertIndexRange(index, range)
Definition: exceptions.h:1732
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:555
static ::ExceptionBase & ExcMessage(std::string arg1)
Number & operator()(const size_type global_index)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
virtual real_type l1_norm() const override
void resize_val(const size_type new_allocated_size, const MPI_Comm &comm_sm=MPI_COMM_SELF)
bool partitioners_are_compatible(const Utilities::MPI::Partitioner &part) const
decltype(std::declval< T >().initialize_dof_vector(std::declval< LinearAlgebra::distributed::Vector< Number > & >())) initialize_dof_vector_t
virtual Vector< Number, MemorySpace > & operator*=(const Number factor) override
void reinit(const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner, const MPI_Comm &comm_sm=MPI_COMM_SELF)
Number local_element(const size_type local_index) const
Number add_and_dot_local(const Number a, const Vector< Number, MemorySpace > &V, const Vector< Number, MemorySpace > &W)
virtual void add(const Number a, const VectorSpaceVector< Number > &V, const Number b, const VectorSpaceVector< Number > &W) override
mutable ::MemorySpace::MemorySpaceData< Number, MemorySpace > import_data
void swap(Vector< Number, MemorySpace > &v)
virtual real_type linfty_norm() const override
mutable ::MemorySpace::MemorySpaceData< Number, MemorySpace > data
Vector(const IndexSet &local_range, const IndexSet &ghost_indices, const MPI_Comm &communicator)
const value_type * const_iterator
Definition: vector.h:125
typename numbers::NumberTraits< Number >::real_type real_type
const_iterator end() const
Vector(const size_type size)
Vector(Vector< Number, MemorySpace > &&in_vector)
size_type locally_owned_size() const
static void reinit_range_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool)
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner
void add(const size_type n_elements, const size_type *indices, const OtherNumber *values)
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
void sadd(const Number s, const Vector< Number, MemorySpace > &V)
Vector(const IndexSet &local_range, const MPI_Comm &communicator)
Vector< Number, MemorySpace > & operator=(const Vector< Number, MemorySpace > &in_vector)
virtual std::size_t memory_consumption() const override
static ::ExceptionBase & ExcVectorTypeNotCompatible()
Number operator[](const size_type global_index) const
virtual bool all_zero() const override
Vector(const Vector< Number, MemorySpace > &in_vector)
virtual Number mean_value() const override
void set_ghost_state(const bool ghosted) const
static ::ExceptionBase & ExcNonMatchingElements(Number arg1, Number arg2, unsigned int arg3)
virtual Vector< Number, MemorySpace > & operator=(const Number s) override
void reinit(const IndexSet &local_range, const IndexSet &ghost_indices, const MPI_Comm &communicator)
void add(const std::vector< size_type > &indices, const ::Vector< OtherNumber > &values)
virtual void reinit(const VectorSpaceVector< Number > &V, const bool omit_zeroing_entries=false) override
Number & operator[](const size_type global_index)
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
static ::ExceptionBase & ExcNotAllowedForCuda()
virtual void add(const std::vector< size_type > &indices, const std::vector< Number > &values)
virtual void compress(::VectorOperation::values operation) override
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
virtual Vector< Number, MemorySpace > & operator-=(const VectorSpaceVector< Number > &V) override
void add_local(const Number a, const VectorSpaceVector< Number > &V)
std::shared_ptr<::parallel::internal::TBBPartitioner > thread_loop_partitioner
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
void compress_start(const unsigned int communication_channel=0, ::VectorOperation::values operation=VectorOperation::add)
const MPI_Comm & get_mpi_communicator() const
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
virtual void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const override
const std::vector< ArrayView< const Number > > & shared_vector_data() const
void update_ghost_values_start(const unsigned int communication_channel=0) const
void copy_locally_owned_data_from(const Vector< Number2, MemorySpace > &src)
Vector< Number, MemorySpace > & operator=(const Vector< Number2, MemorySpace > &in_vector)
virtual void add(const Number a, const VectorSpaceVector< Number > &V) override
virtual Vector< Number, MemorySpace > & operator/=(const Number factor) override
virtual void add(const Number a) override
Number operator()(const size_type global_index) const
virtual Vector< Number, MemorySpace > & operator+=(const VectorSpaceVector< Number > &V) override
real_type lp_norm_local(const real_type p) const
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)
void sadd_local(const Number s, const Number a, const VectorSpaceVector< Number > &V)
void reinit(const IndexSet &local_range, const MPI_Comm &communicator)
value_type * iterator
Definition: vector.h:124
void reinit(const size_type size, const bool omit_zeroing_entries=false)
static void reinit_domain_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool)
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< OtherNumber > &values) const
void compress_finish(::VectorOperation::values operation)
std::vector< MPI_Request > update_ghost_values_requests
const_iterator begin() const
std::vector< MPI_Request > compress_requests
bool in_local_range(const size_type global_index) const
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)
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
virtual real_type l2_norm() const override
Vector(const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner)
virtual ::IndexSet locally_owned_elements() const override
VectorType::value_type * begin(VectorType &V)
bool is_finite(const double x)
Definition: numbers.h:539
unsigned int global_dof_index
Definition: types.h:76
const MPI_Comm & comm