Reference documentation for deal.II version GIT 194dd8bb02 2022-12-03 08:20:02+00:00
\(\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\}}\)
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_stub.h>
25 #include <deal.II/base/numbers.h>
26 #include <deal.II/base/parallel.h>
29 
33 
34 #include <iomanip>
35 #include <memory>
36 
38 
39 // Forward declarations
40 #ifndef DOXYGEN
41 namespace LinearAlgebra
42 {
46  namespace distributed
47  {
48  template <typename>
49  class BlockVector;
50  }
51 
52  template <typename>
53  class ReadWriteVector;
54 } // namespace LinearAlgebra
55 
56 # ifdef DEAL_II_WITH_PETSC
57 namespace PETScWrappers
58 {
59  namespace MPI
60  {
61  class Vector;
62  }
63 } // namespace PETScWrappers
64 # endif
65 
66 # ifdef DEAL_II_WITH_TRILINOS
67 namespace TrilinosWrappers
68 {
69  namespace MPI
70  {
71  class Vector;
72  }
73 } // namespace TrilinosWrappers
74 # endif
75 #endif
76 
77 namespace LinearAlgebra
78 {
79  namespace distributed
80  {
250  template <typename Number, typename MemorySpace = MemorySpace::Host>
252  public Subscriptor
253  {
254  public:
256  using value_type = Number;
257  using pointer = value_type *;
258  using const_pointer = const value_type *;
259  using iterator = value_type *;
260  using const_iterator = const value_type *;
262  using const_reference = const value_type &;
265 
266  static_assert(
267  std::is_same<MemorySpace, ::MemorySpace::Host>::value ||
268  std::is_same<MemorySpace, ::MemorySpace::CUDA>::value,
269  "MemorySpace should be Host or CUDA");
270 
279 
287 
295  Vector(Vector<Number, MemorySpace> &&in_vector); // NOLINT
296 
302 
319  Vector(const IndexSet &local_range,
320  const IndexSet &ghost_indices,
321  const MPI_Comm &communicator);
322 
326  Vector(const IndexSet &local_range, const MPI_Comm &communicator);
327 
335  const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner);
336 
340  virtual ~Vector() override;
341 
346  void
347  reinit(const size_type size, const bool omit_zeroing_entries = false);
348 
359  template <typename Number2>
360  void
362  const bool omit_zeroing_entries = false);
363 
380  void
381  reinit(const IndexSet &local_range,
382  const IndexSet &ghost_indices,
383  const MPI_Comm &communicator);
384 
388  void
389  reinit(const IndexSet &local_range, const MPI_Comm &communicator);
390 
403  void
405  const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
406  const MPI_Comm &comm_sm = MPI_COMM_SELF);
407 
427  void
429  const types::global_dof_index ghost_size,
430  const MPI_Comm & comm,
431  const MPI_Comm & comm_sm = MPI_COMM_SELF);
432 
445  void
447 
461 
473  template <typename Number2>
476 
518  virtual void
519  compress(::VectorOperation::values operation) override;
520 
542  void
544 
562  void
564  const unsigned int communication_channel = 0,
566 
585  void
587 
605  void
607  const unsigned int communication_channel = 0) const;
608 
609 
617  void
619 
630  DEAL_II_DEPRECATED void
632 
641  void
643 
655  bool
657 
672  template <typename Number2>
673  void
675 
686  template <typename MemorySpace2>
687  void
688  import(const Vector<Number, MemorySpace2> &src,
689  VectorOperation::values operation);
690 
702  virtual void
704  const bool omit_zeroing_entries = false) override;
705 
710  operator*=(const Number factor) override;
711 
716  operator/=(const Number factor) override;
717 
723 
729 
741  virtual void
743  VectorOperation::values operation,
744  std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
745  communication_pattern = {}) override;
746 
750  virtual Number
751  operator*(const VectorSpaceVector<Number> &V) const override;
752 
756  virtual void
757  add(const Number a) override;
758 
762  virtual void
763  add(const Number a, const VectorSpaceVector<Number> &V) override;
764 
768  virtual void
769  add(const Number a,
771  const Number b,
772  const VectorSpaceVector<Number> &W) override;
773 
778  virtual void
779  add(const std::vector<size_type> &indices,
780  const std::vector<Number> & values);
781 
786  virtual void
787  sadd(const Number s,
788  const Number a,
789  const VectorSpaceVector<Number> &V) override;
790 
796  virtual void
797  scale(const VectorSpaceVector<Number> &scaling_factors) override;
798 
802  virtual void
803  equ(const Number a, const VectorSpaceVector<Number> &V) override;
804 
809  virtual real_type
810  l1_norm() const override;
811 
816  virtual real_type
817  l2_norm() const override;
818 
822  real_type
823  norm_sqr() const;
824 
829  virtual real_type
830  linfty_norm() const override;
831 
852  virtual Number
853  add_and_dot(const Number a,
855  const VectorSpaceVector<Number> &W) override;
856 
861  virtual size_type
862  size() const override;
863 
875  virtual ::IndexSet
876  locally_owned_elements() const override;
877 
881  virtual void
882  print(std::ostream & out,
883  const unsigned int precision = 3,
884  const bool scientific = true,
885  const bool across = true) const override;
886 
890  virtual std::size_t
891  memory_consumption() const override;
905  operator=(const Number s) override;
906 
911  template <typename OtherNumber>
912  void
913  add(const std::vector<size_type> & indices,
914  const ::Vector<OtherNumber> &values);
915 
920  template <typename OtherNumber>
921  void
922  add(const size_type n_elements,
923  const size_type * indices,
924  const OtherNumber *values);
925 
930  void
931  sadd(const Number s, const Vector<Number, MemorySpace> &V);
932 
948  size_type
949  local_size() const;
950 
955  size_type
957 
962  bool
964 
975  iterator
976  begin();
977 
986  begin() const;
987 
995  iterator
996  end();
997 
1006  end() const;
1007 
1017  Number
1019 
1029  Number &
1031 
1039  Number
1048  Number &
1050 
1059  Number
1060  local_element(const size_type local_index) const;
1061 
1070  Number &
1071  local_element(const size_type local_index);
1072 
1079  Number *
1080  get_values() const;
1081 
1099  template <typename OtherNumber>
1100  void
1101  extract_subvector_to(const std::vector<size_type> &indices,
1102  std::vector<OtherNumber> & values) const;
1103 
1131  template <typename ForwardIterator, typename OutputIterator>
1132  void
1133  extract_subvector_to(ForwardIterator indices_begin,
1134  const ForwardIterator indices_end,
1135  OutputIterator values_begin) const;
1141  virtual bool
1142  all_zero() const override;
1143 
1147  virtual Number
1148  mean_value() const override;
1149 
1154  real_type
1155  lp_norm(const real_type p) const;
1167  const MPI_Comm &
1169 
1176  const std::shared_ptr<const Utilities::MPI::Partitioner> &
1178 
1188  bool
1190  const Utilities::MPI::Partitioner &part) const;
1191 
1205  bool
1207  const Utilities::MPI::Partitioner &part) const;
1208 
1212  void
1213  set_ghost_state(const bool ghosted) const;
1214 
1219  const std::vector<ArrayView<const Number>> &
1221 
1230 
1237 
1242  Number,
1243  Number,
1244  unsigned int,
1245  << "Called compress(VectorOperation::insert), but"
1246  << " the element received from a remote processor, value "
1247  << std::setprecision(16) << arg1
1248  << ", does not match with the value "
1249  << std::setprecision(16) << arg2
1250  << " on the owner processor " << arg3);
1251 
1257  size_type,
1258  size_type,
1259  size_type,
1260  size_type,
1261  << "You tried to access element " << arg1
1262  << " of a distributed vector, but this element is not "
1263  << "stored on the current processor. Note: The range of "
1264  << "locally owned elements is [" << arg2 << ',' << arg3
1265  << "], and there are " << arg4 << " ghost elements "
1266  << "that this vector can access."
1267  << "\n\n"
1268  << "A common source for this kind of problem is that you "
1269  << "are passing a 'fully distributed' vector into a function "
1270  << "that needs read access to vector elements that correspond "
1271  << "to degrees of freedom on ghost cells (or at least to "
1272  << "'locally active' degrees of freedom that are not also "
1273  << "'locally owned'). You need to pass a vector that has these "
1274  << "elements as ghost entries.");
1275 
1276  private:
1281  void
1282  add_local(const Number a, const VectorSpaceVector<Number> &V);
1283 
1288  void
1289  sadd_local(const Number s,
1290  const Number a,
1291  const VectorSpaceVector<Number> &V);
1292 
1296  template <typename Number2>
1297  Number
1299 
1303  real_type
1305 
1309  Number
1311 
1315  real_type
1316  l1_norm_local() const;
1317 
1321  real_type
1322  lp_norm_local(const real_type p) const;
1323 
1327  real_type
1329 
1335  Number
1336  add_and_dot_local(const Number a,
1338  const Vector<Number, MemorySpace> &W);
1339 
1345  std::shared_ptr<const Utilities::MPI::Partitioner> partitioner;
1346 
1351 
1355  mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace> data;
1356 
1361  mutable std::shared_ptr<::parallel::internal::TBBPartitioner>
1363 
1368  mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace>
1370 
1378  mutable bool vector_is_ghosted;
1379 
1380 #ifdef DEAL_II_WITH_MPI
1389  std::vector<MPI_Request> compress_requests;
1390 
1395  mutable std::vector<MPI_Request> update_ghost_values_requests;
1396 #endif
1397 
1403  mutable std::mutex mutex;
1404 
1410  MPI_Comm comm_sm;
1411 
1416  void
1418 
1422  void
1423  resize_val(const size_type new_allocated_size,
1424  const MPI_Comm &comm_sm = MPI_COMM_SELF);
1425 
1426  // Make all other vector types friends.
1427  template <typename Number2, typename MemorySpace2>
1428  friend class Vector;
1429 
1430  // Make BlockVector type friends.
1431  template <typename Number2>
1432  friend class BlockVector;
1433  };
1437  /*-------------------- Inline functions ---------------------------------*/
1438 
1439 #ifndef DOXYGEN
1440 
1441  namespace internal
1442  {
1443  template <typename Number, typename MemorySpace>
1444  struct Policy
1445  {
1446  static inline typename Vector<Number, MemorySpace>::iterator
1448  {
1449  return nullptr;
1450  }
1451 
1452  static inline typename Vector<Number, MemorySpace>::const_iterator
1453  begin(
1454  const ::MemorySpace::MemorySpaceData<Number, MemorySpace> &)
1455  {
1456  return nullptr;
1457  }
1458 
1459  static inline Number *
1460  get_values(
1462  {
1463  return nullptr;
1464  }
1465  };
1466 
1467 
1468 
1469  template <typename Number>
1470  struct Policy<Number, ::MemorySpace::Host>
1471  {
1472  static inline
1474  begin(::MemorySpace::
1475  MemorySpaceData<Number, ::MemorySpace::Host> &data)
1476  {
1477  return data.values.get();
1478  }
1479 
1480  static inline
1482  begin(const ::MemorySpace::
1483  MemorySpaceData<Number, ::MemorySpace::Host> &data)
1484  {
1485  return data.values.get();
1486  }
1487 
1488  static inline Number *
1489  get_values(::MemorySpace::
1490  MemorySpaceData<Number, ::MemorySpace::Host> &data)
1491  {
1492  return data.values.get();
1493  }
1494  };
1495 
1496 
1497 
1498  template <typename Number>
1499  struct Policy<Number, ::MemorySpace::CUDA>
1500  {
1501  static inline
1503  begin(::MemorySpace::
1504  MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1505  {
1506  return data.values_dev.get();
1507  }
1508 
1509  static inline
1511  begin(const ::MemorySpace::
1512  MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1513  {
1514  return data.values_dev.get();
1515  }
1516 
1517  static inline Number *
1518  get_values(::MemorySpace::
1519  MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1520  {
1521  return data.values_dev.get();
1522  }
1523  };
1524  } // namespace internal
1525 
1526 
1527  template <typename Number, typename MemorySpace>
1528  inline bool
1530  {
1531  return vector_is_ghosted;
1532  }
1533 
1534 
1535 
1536  template <typename Number, typename MemorySpace>
1539  {
1540  return partitioner->size();
1541  }
1542 
1543 
1544 
1545  template <typename Number, typename MemorySpace>
1548  {
1549  return locally_owned_size();
1550  }
1551 
1552 
1553 
1554  template <typename Number, typename MemorySpace>
1557  {
1558  return partitioner->locally_owned_size();
1559  }
1560 
1561 
1562 
1563  template <typename Number, typename MemorySpace>
1564  inline bool
1566  const size_type global_index) const
1567  {
1568  return partitioner->in_local_range(global_index);
1569  }
1570 
1571 
1572 
1573  template <typename Number, typename MemorySpace>
1574  inline IndexSet
1576  {
1577  IndexSet is(size());
1578 
1579  is.add_range(partitioner->local_range().first,
1580  partitioner->local_range().second);
1581 
1582  return is;
1583  }
1584 
1585 
1586 
1587  template <typename Number, typename MemorySpace>
1590  {
1592  }
1593 
1594 
1595 
1596  template <typename Number, typename MemorySpace>
1599  {
1601  }
1602 
1603 
1604 
1605  template <typename Number, typename MemorySpace>
1608  {
1610  partitioner->locally_owned_size();
1611  }
1612 
1613 
1614 
1615  template <typename Number, typename MemorySpace>
1618  {
1620  partitioner->locally_owned_size();
1621  }
1622 
1623 
1624 
1625  template <typename Number, typename MemorySpace>
1626  const std::vector<ArrayView<const Number>> &
1628  {
1629  return data.values_sm;
1630  }
1631 
1632 
1633 
1634  template <typename Number, typename MemorySpace>
1635  inline Number
1637  {
1638  Assert((std::is_same<MemorySpace, ::MemorySpace::Host>::value),
1639  ExcMessage(
1640  "This function is only implemented for the Host memory space"));
1641  Assert(
1642  partitioner->in_local_range(global_index) ||
1643  partitioner->ghost_indices().is_element(global_index),
1644  ExcAccessToNonLocalElement(global_index,
1645  partitioner->local_range().first,
1646  partitioner->local_range().second == 0 ?
1647  0 :
1648  (partitioner->local_range().second - 1),
1649  partitioner->ghost_indices().n_elements()));
1650  // do not allow reading a vector which is not in ghost mode
1651  Assert(partitioner->in_local_range(global_index) ||
1652  vector_is_ghosted == true,
1653  ExcMessage("You tried to read a ghost element of this vector, "
1654  "but it has not imported its ghost values."));
1655  return data.values[partitioner->global_to_local(global_index)];
1656  }
1657 
1658 
1659 
1660  template <typename Number, typename MemorySpace>
1661  inline Number &
1663  {
1664  Assert((std::is_same<MemorySpace, ::MemorySpace::Host>::value),
1665  ExcMessage(
1666  "This function is only implemented for the Host memory space"));
1667  Assert(
1668  partitioner->in_local_range(global_index) ||
1669  partitioner->ghost_indices().is_element(global_index),
1670  ExcAccessToNonLocalElement(global_index,
1671  partitioner->local_range().first,
1672  partitioner->local_range().second == 0 ?
1673  0 :
1674  (partitioner->local_range().second - 1),
1675  partitioner->ghost_indices().n_elements()));
1676  // we would like to prevent reading ghosts from a vector that does not
1677  // have them imported, but this is not possible because we might be in a
1678  // part of the code where the vector has enabled ghosts but is non-const
1679  // (then, the compiler picks this method according to the C++ rule book
1680  // even if a human would pick the const method when this subsequent use
1681  // is just a read)
1682  return data.values[partitioner->global_to_local(global_index)];
1683  }
1684 
1685 
1686 
1687  template <typename Number, typename MemorySpace>
1688  inline Number
1690  {
1691  return operator()(global_index);
1692  }
1693 
1694 
1695 
1696  template <typename Number, typename MemorySpace>
1697  inline Number &
1699  {
1700  return operator()(global_index);
1701  }
1702 
1703 
1704 
1705  template <typename Number, typename MemorySpace>
1706  inline Number
1708  const size_type local_index) const
1709  {
1710  Assert((std::is_same<MemorySpace, ::MemorySpace::Host>::value),
1711  ExcMessage(
1712  "This function is only implemented for the Host memory space"));
1713  AssertIndexRange(local_index,
1714  partitioner->locally_owned_size() +
1715  partitioner->n_ghost_indices());
1716  // do not allow reading a vector which is not in ghost mode
1717  Assert(local_index < locally_owned_size() || vector_is_ghosted == true,
1718  ExcMessage("You tried to read a ghost element of this vector, "
1719  "but it has not imported its ghost values."));
1720 
1721  return data.values[local_index];
1722  }
1723 
1724 
1725 
1726  template <typename Number, typename MemorySpace>
1727  inline Number &
1729  {
1730  Assert((std::is_same<MemorySpace, ::MemorySpace::Host>::value),
1731  ExcMessage(
1732  "This function is only implemented for the Host memory space"));
1733 
1734  AssertIndexRange(local_index,
1735  partitioner->locally_owned_size() +
1736  partitioner->n_ghost_indices());
1737 
1738  return data.values[local_index];
1739  }
1740 
1741 
1742 
1743  template <typename Number, typename MemorySpace>
1744  inline Number *
1746  {
1747  return internal::Policy<Number, MemorySpace>::get_values(data);
1748  }
1749 
1750 
1751 
1752  template <typename Number, typename MemorySpace>
1753  template <typename OtherNumber>
1754  inline void
1756  const std::vector<size_type> &indices,
1757  std::vector<OtherNumber> & values) const
1758  {
1759  for (size_type i = 0; i < indices.size(); ++i)
1760  values[i] = operator()(indices[i]);
1761  }
1762 
1763 
1764 
1765  template <typename Number, typename MemorySpace>
1766  template <typename ForwardIterator, typename OutputIterator>
1767  inline void
1769  ForwardIterator indices_begin,
1770  const ForwardIterator indices_end,
1771  OutputIterator values_begin) const
1772  {
1773  while (indices_begin != indices_end)
1774  {
1775  *values_begin = operator()(*indices_begin);
1776  indices_begin++;
1777  values_begin++;
1778  }
1779  }
1780 
1781 
1782 
1783  template <typename Number, typename MemorySpace>
1784  template <typename OtherNumber>
1785  inline void
1787  const std::vector<size_type> & indices,
1788  const ::Vector<OtherNumber> &values)
1789  {
1790  AssertDimension(indices.size(), values.size());
1791  for (size_type i = 0; i < indices.size(); ++i)
1792  {
1793  Assert(
1795  ExcMessage(
1796  "The given value is not finite but either infinite or Not A Number (NaN)"));
1797  this->operator()(indices[i]) += values(i);
1798  }
1799  }
1800 
1801 
1802 
1803  template <typename Number, typename MemorySpace>
1804  template <typename OtherNumber>
1805  inline void
1807  const size_type * indices,
1808  const OtherNumber *values)
1809  {
1810  for (size_type i = 0; i < n_elements; ++i, ++indices, ++values)
1811  {
1812  Assert(
1814  ExcMessage(
1815  "The given value is not finite but either infinite or Not A Number (NaN)"));
1816  this->operator()(*indices) += *values;
1817  }
1818  }
1819 
1820 
1821 
1822  template <typename Number, typename MemorySpace>
1823  inline const MPI_Comm &
1825  {
1826  return partitioner->get_mpi_communicator();
1827  }
1828 
1829 
1830 
1831  template <typename Number, typename MemorySpace>
1832  inline const std::shared_ptr<const Utilities::MPI::Partitioner> &
1834  {
1835  return partitioner;
1836  }
1837 
1838 
1839 
1840  template <typename Number, typename MemorySpace>
1841  inline void
1842  Vector<Number, MemorySpace>::set_ghost_state(const bool ghosted) const
1843  {
1844  vector_is_ghosted = ghosted;
1845  }
1846 
1847 #endif
1848 
1849  } // namespace distributed
1850 } // namespace LinearAlgebra
1851 
1852 
1860 template <typename Number, typename MemorySpace>
1861 inline void
1864 {
1865  u.swap(v);
1866 }
1867 
1868 
1872 template <typename Number, typename MemorySpace>
1874  : std::false_type
1875 {};
1876 
1877 
1878 
1879 namespace internal
1880 {
1881  namespace LinearOperatorImplementation
1882  {
1883  template <typename>
1884  class ReinitHelper;
1885 
1890  template <typename Number>
1892  {
1893  public:
1894  // A helper type-trait that leverage SFINAE to figure out if type T has
1895  // void T::get_mpi_communicator()
1896  template <typename T>
1898  decltype(std::declval<T>().get_mpi_communicator());
1899 
1900  template <typename T>
1901  static constexpr bool has_get_mpi_communicator =
1902  is_supported_operation<get_mpi_communicator_t, T>;
1903 
1904  // A helper type-trait that leverage SFINAE to figure out if type T has
1905  // void T::locally_owned_domain_indices()
1906  template <typename T>
1908  decltype(std::declval<T>().locally_owned_domain_indices());
1909 
1910  template <typename T>
1911  static constexpr bool has_locally_owned_domain_indices =
1912  is_supported_operation<locally_owned_domain_indices_t, T>;
1913 
1914  // A helper type-trait that leverage SFINAE to figure out if type T has
1915  // void T::locally_owned_range_indices()
1916  template <typename T>
1918  decltype(std::declval<T>().locally_owned_range_indices());
1919 
1920  template <typename T>
1921  static constexpr bool has_locally_owned_range_indices =
1922  is_supported_operation<locally_owned_range_indices_t, T>;
1923 
1924  // A helper type-trait that leverage SFINAE to figure out if type T has
1925  // void T::initialize_dof_vector(VectorType v)
1926  template <typename T>
1928  decltype(std::declval<T>().initialize_dof_vector(
1929  std::declval<LinearAlgebra::distributed::Vector<Number> &>()));
1930 
1931  template <typename T>
1932  static constexpr bool has_initialize_dof_vector =
1933  is_supported_operation<initialize_dof_vector_t, T>;
1934 
1935  // Used for (Trilinos/PETSc)Wrappers::SparseMatrix
1936  template <typename MatrixType,
1937 #if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1938  std::enable_if_t<has_get_mpi_communicator<MatrixType> &&
1939  has_locally_owned_domain_indices<MatrixType>,
1940 #else
1941  // workaround for Intel 18
1942  std::enable_if_t<
1943  is_supported_operation<get_mpi_communicator_t, MatrixType> &&
1945  MatrixType>,
1946 #endif
1947  MatrixType> * = nullptr>
1948  static void
1949  reinit_domain_vector(MatrixType & mat,
1951  bool /*omit_zeroing_entries*/)
1952  {
1953  vec.reinit(mat.locally_owned_domain_indices(),
1954  mat.get_mpi_communicator());
1955  }
1956 
1957  // Used for MatrixFree and DiagonalMatrix
1958  template <typename MatrixType,
1959 #if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1960  std::enable_if_t<has_initialize_dof_vector<MatrixType>,
1961 #else
1962  // workaround for Intel 18
1963  std::enable_if_t<
1964  is_supported_operation<initialize_dof_vector_t, MatrixType>,
1965 #endif
1966  MatrixType> * = nullptr>
1967  static void
1968  reinit_domain_vector(MatrixType & mat,
1970  bool omit_zeroing_entries)
1971  {
1972  mat.initialize_dof_vector(vec);
1973  if (!omit_zeroing_entries)
1974  vec = Number();
1975  }
1976 
1977  // Used for (Trilinos/PETSc)Wrappers::SparseMatrix
1978  template <typename MatrixType,
1979 #if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
1980  std::enable_if_t<has_get_mpi_communicator<MatrixType> &&
1981  has_locally_owned_range_indices<MatrixType>,
1982 #else
1983  // workaround for Intel 18
1984  std::enable_if_t<
1985  is_supported_operation<get_mpi_communicator_t, MatrixType> &&
1986  is_supported_operation<locally_owned_range_indices_t,
1987  MatrixType>,
1988 #endif
1989  MatrixType> * = nullptr>
1990  static void
1991  reinit_range_vector(MatrixType & mat,
1993  bool /*omit_zeroing_entries*/)
1994  {
1995  vec.reinit(mat.locally_owned_range_indices(),
1996  mat.get_mpi_communicator());
1997  }
1998 
1999  // Used for MatrixFree and DiagonalMatrix
2000  template <typename MatrixType,
2001 #if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
2002  std::enable_if_t<has_initialize_dof_vector<MatrixType>,
2003 #else
2004  // workaround for Intel 18
2005  std::enable_if_t<
2006  is_supported_operation<initialize_dof_vector_t, MatrixType>,
2007 #endif
2008  MatrixType> * = nullptr>
2009  static void
2010  reinit_range_vector(MatrixType & mat,
2012  bool omit_zeroing_entries)
2013  {
2014  mat.initialize_dof_vector(vec);
2015  if (!omit_zeroing_entries)
2016  vec = Number();
2017  }
2018  };
2019 
2020  } // namespace LinearOperatorImplementation
2021 } /* namespace internal */
2022 
2023 
2025 
2026 #endif
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
virtual Vector< Number, MemorySpace > & operator-=(const VectorSpaceVector< Number > &V) override
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 & operator[](const size_type global_index)
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)
typename numbers::NumberTraits< Number >::real_type real_type
const_iterator end() const
Number & local_element(const size_type local_index)
Vector(const size_type size)
Vector(Vector< Number, MemorySpace > &&in_vector)
size_type locally_owned_size() const
virtual Vector< Number, MemorySpace > & operator+=(const VectorSpaceVector< Number > &V) override
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)
virtual std::size_t memory_consumption() const override
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_partitioner() const
Number & operator()(const size_type global_index)
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
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
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
virtual Vector< Number, MemorySpace > & operator=(const Number s) override
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
virtual size_type size() const override
const MPI_Comm & get_mpi_communicator() const
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)
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
void update_ghost_values_start(const unsigned int communication_channel=0) const
void copy_locally_owned_data_from(const Vector< Number2, MemorySpace > &src)
virtual void add(const Number a, const VectorSpaceVector< Number > &V) override
Vector< Number, MemorySpace > & operator=(const Vector< Number, MemorySpace > &in_vector)
virtual void add(const Number a) override
Number operator()(const size_type global_index) const
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)
void reinit(const size_type size, const bool omit_zeroing_entries=false)
const std::vector< ArrayView< const Number > > & shared_vector_data() const
Vector< Number, MemorySpace > & operator=(const Vector< Number2, MemorySpace > &in_vector)
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< OtherNumber > &values) const
virtual Vector< Number, MemorySpace > & operator*=(const Number factor) override
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
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
Definition: vector.h:109
void swap(LinearAlgebra::distributed::Vector< Number, MemorySpace > &u, LinearAlgebra::distributed::Vector< Number, MemorySpace > &v)
const value_type * const_iterator
Definition: vector.h:132
types::global_dof_index size_type
Definition: vector.h:135
value_type * iterator
Definition: vector.h:131
decltype(std::declval< T >().initialize_dof_vector(std::declval< LinearAlgebra::distributed::Vector< Number > & >())) initialize_dof_vector_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)
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
Definition: config.h:164
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:458
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:459
#define DeclException0(Exception0)
Definition: exceptions.h:464
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
Definition: exceptions.h:578
static ::ExceptionBase & ExcVectorTypeNotCompatible()
static ::ExceptionBase & ExcNonMatchingElements(Number arg1, Number arg2, unsigned int arg3)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
#define Assert(cond, exc)
Definition: exceptions.h:1501
static ::ExceptionBase & ExcNotAllowedForCuda()
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1695
#define AssertIndexRange(index, range)
Definition: exceptions.h:1760
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:555
static ::ExceptionBase & ExcMessage(std::string arg1)
static const char V
types::global_dof_index size_type
Definition: cuda_kernels.h:45
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
VectorType::value_type * begin(VectorType &V)
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
constexpr bool is_supported_operation
bool is_finite(const double x)
Definition: numbers.h:553
unsigned int global_dof_index
Definition: types.h:81
const MPI_Comm & comm