Reference documentation for deal.II version Git 6c3defc1fd 2020-06-02 18:18:21 -0400
\(\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 - 2020 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 
22 #include <deal.II/base/mpi.h>
23 #include <deal.II/base/numbers.h>
26 
30 
31 #include <iomanip>
32 #include <memory>
33 
35 
36 // Forward declarations
37 #ifndef DOXYGEN
38 namespace LinearAlgebra
39 {
43  namespace distributed
44  {
45  template <typename>
46  class BlockVector;
47  }
48 
49  template <typename>
50  class ReadWriteVector;
51 } // namespace LinearAlgebra
52 
53 # ifdef DEAL_II_WITH_PETSC
54 namespace PETScWrappers
55 {
56  namespace MPI
57  {
58  class Vector;
59  }
60 } // namespace PETScWrappers
61 # endif
62 
63 # ifdef DEAL_II_WITH_TRILINOS
64 namespace TrilinosWrappers
65 {
66  namespace MPI
67  {
68  class Vector;
69  }
70 } // namespace TrilinosWrappers
71 # endif
72 #endif
73 
74 namespace LinearAlgebra
75 {
76  namespace distributed
77  {
225  template <typename Number, typename MemorySpace = MemorySpace::Host>
227  public Subscriptor
228  {
229  public:
231  using value_type = Number;
232  using pointer = value_type *;
233  using const_pointer = const value_type *;
234  using iterator = value_type *;
235  using const_iterator = const value_type *;
237  using const_reference = const value_type &;
240 
241  static_assert(
244  "MemorySpace should be Host or CUDA");
245 
253  Vector();
254 
261  Vector(const Vector<Number, MemorySpace> &in_vector);
262 
267  Vector(const size_type size);
268 
285  Vector(const IndexSet &local_range,
286  const IndexSet &ghost_indices,
287  const MPI_Comm communicator);
288 
292  Vector(const IndexSet &local_range, const MPI_Comm communicator);
293 
300  Vector(
301  const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner);
302 
306  virtual ~Vector() override;
307 
312  void
313  reinit(const size_type size, const bool omit_zeroing_entries = false);
314 
325  template <typename Number2>
326  void
327  reinit(const Vector<Number2, MemorySpace> &in_vector,
328  const bool omit_zeroing_entries = false);
329 
346  void
347  reinit(const IndexSet &local_range,
348  const IndexSet &ghost_indices,
349  const MPI_Comm communicator);
350 
354  void
355  reinit(const IndexSet &local_range, const MPI_Comm communicator);
356 
363  void
364  reinit(
365  const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner);
366 
382  void
384 
397  operator=(const Vector<Number, MemorySpace> &in_vector);
398 
410  template <typename Number2>
412  operator=(const Vector<Number2, MemorySpace> &in_vector);
413 
415 
455  virtual void
456  compress(::VectorOperation::values operation) override;
457 
479  void
480  update_ghost_values() const;
481 
499  void
500  compress_start(
501  const unsigned int communication_channel = 0,
503 
522  void
523  compress_finish(::VectorOperation::values operation);
524 
542  void
543  update_ghost_values_start(
544  const unsigned int communication_channel = 0) const;
545 
546 
554  void
555  update_ghost_values_finish() const;
556 
565  void
566  zero_out_ghosts() const;
567 
579  bool
580  has_ghost_elements() const;
581 
596  template <typename Number2>
597  void
598  copy_locally_owned_data_from(const Vector<Number2, MemorySpace> &src);
599 
610  template <typename MemorySpace2>
611  void
612  import(const Vector<Number, MemorySpace2> &src,
613  VectorOperation::values operation);
614 
616 
621 
626  virtual void
628  const bool omit_zeroing_entries = false) override;
629 
634  operator*=(const Number factor) override;
635 
640  operator/=(const Number factor) override;
641 
646  operator+=(const VectorSpaceVector<Number> &V) override;
647 
652  operator-=(const VectorSpaceVector<Number> &V) override;
653 
665  virtual void
666  import(
668  VectorOperation::values operation,
669  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
670  std::shared_ptr<const CommunicationPatternBase>()) override;
671 
675  virtual Number
676  operator*(const VectorSpaceVector<Number> &V) const override;
677 
681  virtual void
682  add(const Number a) override;
683 
687  virtual void
688  add(const Number a, const VectorSpaceVector<Number> &V) override;
689 
693  virtual void
694  add(const Number a,
696  const Number b,
697  const VectorSpaceVector<Number> &W) override;
698 
703  virtual void
704  add(const std::vector<size_type> &indices,
705  const std::vector<Number> & values);
706 
711  virtual void
712  sadd(const Number s,
713  const Number a,
714  const VectorSpaceVector<Number> &V) override;
715 
721  virtual void
722  scale(const VectorSpaceVector<Number> &scaling_factors) override;
723 
727  virtual void
728  equ(const Number a, const VectorSpaceVector<Number> &V) override;
729 
734  virtual real_type
735  l1_norm() const override;
736 
741  virtual real_type
742  l2_norm() const override;
743 
747  real_type
748  norm_sqr() const;
749 
754  virtual real_type
755  linfty_norm() const override;
756 
777  virtual Number
778  add_and_dot(const Number a,
780  const VectorSpaceVector<Number> &W) override;
781 
786  virtual size_type
787  size() const override;
788 
800  virtual ::IndexSet
801  locally_owned_elements() const override;
802 
806  virtual void
807  print(std::ostream & out,
808  const unsigned int precision = 3,
809  const bool scientific = true,
810  const bool across = true) const override;
811 
815  virtual std::size_t
816  memory_consumption() const override;
818 
823 
830  operator=(const Number s) override;
831 
836  template <typename OtherNumber>
837  void
838  add(const std::vector<size_type> & indices,
839  const ::Vector<OtherNumber> &values);
840 
845  template <typename OtherNumber>
846  void
847  add(const size_type n_elements,
848  const size_type * indices,
849  const OtherNumber *values);
850 
855  void
856  sadd(const Number s, const Vector<Number, MemorySpace> &V);
857 
859 
860 
865 
870  size_type
871  local_size() const;
872 
877  bool
878  in_local_range(const size_type global_index) const;
879 
890  iterator
891  begin();
892 
901  begin() const;
902 
910  iterator
911  end();
912 
921  end() const;
922 
932  Number
933  operator()(const size_type global_index) const;
934 
944  Number &
945  operator()(const size_type global_index);
946 
954  Number operator[](const size_type global_index) const;
962  Number &operator[](const size_type global_index);
963 
972  Number
973  local_element(const size_type local_index) const;
974 
983  Number &
984  local_element(const size_type local_index);
985 
992  Number *
993  get_values() const;
994 
1012  template <typename OtherNumber>
1013  void
1014  extract_subvector_to(const std::vector<size_type> &indices,
1015  std::vector<OtherNumber> & values) const;
1016 
1044  template <typename ForwardIterator, typename OutputIterator>
1045  void
1046  extract_subvector_to(ForwardIterator indices_begin,
1047  const ForwardIterator indices_end,
1048  OutputIterator values_begin) const;
1054  virtual bool
1055  all_zero() const override;
1056 
1060  virtual Number
1061  mean_value() const override;
1062 
1067  real_type
1068  lp_norm(const real_type p) const;
1070 
1075 
1080  const MPI_Comm &
1081  get_mpi_communicator() const;
1082 
1089  const std::shared_ptr<const Utilities::MPI::Partitioner> &
1090  get_partitioner() const;
1091 
1101  bool
1102  partitioners_are_compatible(
1103  const Utilities::MPI::Partitioner &part) const;
1104 
1118  bool
1119  partitioners_are_globally_compatible(
1120  const Utilities::MPI::Partitioner &part) const;
1121 
1125  void
1126  set_ghost_state(const bool ghosted) const;
1127 
1129 
1135  DeclException0(ExcVectorTypeNotCompatible);
1136 
1142  DeclException0(ExcNotAllowedForCuda);
1143 
1147  DeclException3(ExcNonMatchingElements,
1148  Number,
1149  Number,
1150  unsigned int,
1151  << "Called compress(VectorOperation::insert), but"
1152  << " the element received from a remote processor, value "
1153  << std::setprecision(16) << arg1
1154  << ", does not match with the value "
1155  << std::setprecision(16) << arg2
1156  << " on the owner processor " << arg3);
1157 
1161  DeclException4(ExcAccessToNonLocalElement,
1162  size_type,
1163  size_type,
1164  size_type,
1165  size_type,
1166  << "You tried to access element " << arg1
1167  << " of a distributed vector, but this element is not "
1168  << "stored on the current processor. Note: The range of "
1169  << "locally owned elements is " << arg2 << " to " << arg3
1170  << ", and there are " << arg4 << " ghost elements "
1171  << "that this vector can access.");
1172 
1173  private:
1178  void
1179  add_local(const Number a, const VectorSpaceVector<Number> &V);
1180 
1185  void
1186  sadd_local(const Number s,
1187  const Number a,
1188  const VectorSpaceVector<Number> &V);
1189 
1193  template <typename Number2>
1194  Number
1195  inner_product_local(const Vector<Number2, MemorySpace> &V) const;
1196 
1200  real_type
1201  norm_sqr_local() const;
1202 
1206  Number
1207  mean_value_local() const;
1208 
1212  real_type
1213  l1_norm_local() const;
1214 
1218  real_type
1219  lp_norm_local(const real_type p) const;
1220 
1224  real_type
1225  linfty_norm_local() const;
1226 
1232  Number
1233  add_and_dot_local(const Number a,
1235  const Vector<Number, MemorySpace> &W);
1236 
1242  std::shared_ptr<const Utilities::MPI::Partitioner> partitioner;
1243 
1248 
1252  mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace> data;
1253 
1258  mutable std::shared_ptr<::parallel::internal::TBBPartitioner>
1260 
1266  mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace>
1268 
1276  mutable bool vector_is_ghosted;
1277 
1278 #ifdef DEAL_II_WITH_MPI
1279 
1287  std::vector<MPI_Request> compress_requests;
1288 
1293  mutable std::vector<MPI_Request> update_ghost_values_requests;
1294 #endif
1295 
1301  mutable std::mutex mutex;
1302 
1307  void
1308  clear_mpi_requests();
1309 
1313  void
1314  resize_val(const size_type new_allocated_size);
1315 
1316  // Make all other vector types friends.
1317  template <typename Number2, typename MemorySpace2>
1318  friend class Vector;
1319 
1320  // Make BlockVector type friends.
1321  template <typename Number2>
1322  friend class BlockVector;
1323  };
1327  /*-------------------- Inline functions ---------------------------------*/
1328 
1329 #ifndef DOXYGEN
1330 
1331  namespace internal
1332  {
1333  template <typename Number, typename MemorySpace>
1334  struct Policy
1335  {
1336  static inline typename Vector<Number, MemorySpace>::iterator
1338  {
1339  return nullptr;
1340  }
1341 
1342  static inline typename Vector<Number, MemorySpace>::const_iterator
1343  begin(
1344  const ::MemorySpace::MemorySpaceData<Number, MemorySpace> &)
1345  {
1346  return nullptr;
1347  }
1348 
1349  static inline Number *
1350  get_values(
1352  {
1353  return nullptr;
1354  }
1355  };
1356 
1357 
1358 
1359  template <typename Number>
1360  struct Policy<Number, ::MemorySpace::Host>
1361  {
1362  static inline
1364  begin(::MemorySpace::
1365  MemorySpaceData<Number, ::MemorySpace::Host> &data)
1366  {
1367  return data.values.get();
1368  }
1369 
1370  static inline
1372  begin(const ::MemorySpace::
1373  MemorySpaceData<Number, ::MemorySpace::Host> &data)
1374  {
1375  return data.values.get();
1376  }
1377 
1378  static inline Number *
1379  get_values(::MemorySpace::
1380  MemorySpaceData<Number, ::MemorySpace::Host> &data)
1381  {
1382  return data.values.get();
1383  }
1384  };
1385 
1386 
1387 
1388  template <typename Number>
1389  struct Policy<Number, ::MemorySpace::CUDA>
1390  {
1391  static inline
1393  begin(::MemorySpace::
1394  MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1395  {
1396  return data.values_dev.get();
1397  }
1398 
1399  static inline
1401  begin(const ::MemorySpace::
1402  MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1403  {
1404  return data.values_dev.get();
1405  }
1406 
1407  static inline Number *
1408  get_values(::MemorySpace::
1409  MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1410  {
1411  return data.values_dev.get();
1412  }
1413  };
1414  } // namespace internal
1415 
1416 
1417  template <typename Number, typename MemorySpace>
1418  inline bool
1420  {
1421  return vector_is_ghosted;
1422  }
1423 
1424 
1425 
1426  template <typename Number, typename MemorySpace>
1429  {
1430  return partitioner->size();
1431  }
1432 
1433 
1434 
1435  template <typename Number, typename MemorySpace>
1438  {
1439  return partitioner->local_size();
1440  }
1441 
1442 
1443 
1444  template <typename Number, typename MemorySpace>
1445  inline bool
1447  const size_type global_index) const
1448  {
1449  return partitioner->in_local_range(global_index);
1450  }
1451 
1452 
1453 
1454  template <typename Number, typename MemorySpace>
1455  inline IndexSet
1457  {
1458  IndexSet is(size());
1459 
1460  is.add_range(partitioner->local_range().first,
1461  partitioner->local_range().second);
1462 
1463  return is;
1464  }
1465 
1466 
1467 
1468  template <typename Number, typename MemorySpace>
1471  {
1473  }
1474 
1475 
1476 
1477  template <typename Number, typename MemorySpace>
1480  {
1482  }
1483 
1484 
1485 
1486  template <typename Number, typename MemorySpace>
1489  {
1491  partitioner->local_size();
1492  }
1493 
1494 
1495 
1496  template <typename Number, typename MemorySpace>
1499  {
1501  partitioner->local_size();
1502  }
1503 
1504 
1505 
1506  template <typename Number, typename MemorySpace>
1507  inline Number
1508  Vector<Number, MemorySpace>::operator()(const size_type global_index) const
1509  {
1511  ExcMessage(
1512  "This function is only implemented for the Host memory space"));
1513  Assert(
1514  partitioner->in_local_range(global_index) ||
1515  partitioner->ghost_indices().is_element(global_index),
1516  ExcAccessToNonLocalElement(global_index,
1517  partitioner->local_range().first,
1518  partitioner->local_range().second,
1519  partitioner->ghost_indices().n_elements()));
1520  // do not allow reading a vector which is not in ghost mode
1521  Assert(partitioner->in_local_range(global_index) ||
1522  vector_is_ghosted == true,
1523  ExcMessage("You tried to read a ghost element of this vector, "
1524  "but it has not imported its ghost values."));
1525  return data.values[partitioner->global_to_local(global_index)];
1526  }
1527 
1528 
1529 
1530  template <typename Number, typename MemorySpace>
1531  inline Number &
1533  {
1535  ExcMessage(
1536  "This function is only implemented for the Host memory space"));
1537  Assert(
1538  partitioner->in_local_range(global_index) ||
1539  partitioner->ghost_indices().is_element(global_index),
1540  ExcAccessToNonLocalElement(global_index,
1541  partitioner->local_range().first,
1542  partitioner->local_range().second,
1543  partitioner->ghost_indices().n_elements()));
1544  // we would like to prevent reading ghosts from a vector that does not
1545  // have them imported, but this is not possible because we might be in a
1546  // part of the code where the vector has enabled ghosts but is non-const
1547  // (then, the compiler picks this method according to the C++ rule book
1548  // even if a human would pick the const method when this subsequent use
1549  // is just a read)
1550  return data.values[partitioner->global_to_local(global_index)];
1551  }
1552 
1553 
1554 
1555  template <typename Number, typename MemorySpace>
1556  inline Number Vector<Number, MemorySpace>::
1557  operator[](const size_type global_index) const
1558  {
1559  return operator()(global_index);
1560  }
1561 
1562 
1563 
1564  template <typename Number, typename MemorySpace>
1565  inline Number &Vector<Number, MemorySpace>::
1566  operator[](const size_type global_index)
1567  {
1568  return operator()(global_index);
1569  }
1570 
1571 
1572 
1573  template <typename Number, typename MemorySpace>
1574  inline Number
1576  const size_type local_index) const
1577  {
1579  ExcMessage(
1580  "This function is only implemented for the Host memory space"));
1581  AssertIndexRange(local_index,
1582  partitioner->local_size() +
1583  partitioner->n_ghost_indices());
1584  // do not allow reading a vector which is not in ghost mode
1585  Assert(local_index < local_size() || vector_is_ghosted == true,
1586  ExcMessage("You tried to read a ghost element of this vector, "
1587  "but it has not imported its ghost values."));
1588 
1589  return data.values[local_index];
1590  }
1591 
1592 
1593 
1594  template <typename Number, typename MemorySpace>
1595  inline Number &
1597  {
1599  ExcMessage(
1600  "This function is only implemented for the Host memory space"));
1601 
1602  AssertIndexRange(local_index,
1603  partitioner->local_size() +
1604  partitioner->n_ghost_indices());
1605 
1606  return data.values[local_index];
1607  }
1608 
1609 
1610 
1611  template <typename Number, typename MemorySpace>
1612  inline Number *
1614  {
1615  return internal::Policy<Number, MemorySpace>::get_values(data);
1616  }
1617 
1618 
1619 
1620  template <typename Number, typename MemorySpace>
1621  template <typename OtherNumber>
1622  inline void
1624  const std::vector<size_type> &indices,
1625  std::vector<OtherNumber> & values) const
1626  {
1627  for (size_type i = 0; i < indices.size(); ++i)
1628  values[i] = operator()(indices[i]);
1629  }
1630 
1631 
1632 
1633  template <typename Number, typename MemorySpace>
1634  template <typename ForwardIterator, typename OutputIterator>
1635  inline void
1637  ForwardIterator indices_begin,
1638  const ForwardIterator indices_end,
1639  OutputIterator values_begin) const
1640  {
1641  while (indices_begin != indices_end)
1642  {
1643  *values_begin = operator()(*indices_begin);
1644  indices_begin++;
1645  values_begin++;
1646  }
1647  }
1648 
1649 
1650 
1651  template <typename Number, typename MemorySpace>
1652  template <typename OtherNumber>
1653  inline void
1655  const std::vector<size_type> & indices,
1656  const ::Vector<OtherNumber> &values)
1657  {
1658  AssertDimension(indices.size(), values.size());
1659  for (size_type i = 0; i < indices.size(); ++i)
1660  {
1661  Assert(
1662  numbers::is_finite(values[i]),
1663  ExcMessage(
1664  "The given value is not finite but either infinite or Not A Number (NaN)"));
1665  this->operator()(indices[i]) += values(i);
1666  }
1667  }
1668 
1669 
1670 
1671  template <typename Number, typename MemorySpace>
1672  template <typename OtherNumber>
1673  inline void
1675  const size_type * indices,
1676  const OtherNumber *values)
1677  {
1678  for (size_type i = 0; i < n_elements; ++i, ++indices, ++values)
1679  {
1680  Assert(
1681  numbers::is_finite(*values),
1682  ExcMessage(
1683  "The given value is not finite but either infinite or Not A Number (NaN)"));
1684  this->operator()(*indices) += *values;
1685  }
1686  }
1687 
1688 
1689 
1690  template <typename Number, typename MemorySpace>
1691  inline const MPI_Comm &
1693  {
1694  return partitioner->get_mpi_communicator();
1695  }
1696 
1697 
1698 
1699  template <typename Number, typename MemorySpace>
1700  inline const std::shared_ptr<const Utilities::MPI::Partitioner> &
1702  {
1703  return partitioner;
1704  }
1705 
1706 
1707 
1708  template <typename Number, typename MemorySpace>
1709  inline void
1710  Vector<Number, MemorySpace>::set_ghost_state(const bool ghosted) const
1711  {
1712  vector_is_ghosted = ghosted;
1713  }
1714 
1715 #endif
1716 
1717  } // namespace distributed
1718 } // namespace LinearAlgebra
1719 
1720 
1729 template <typename Number, typename MemorySpace>
1730 inline void
1733 {
1734  u.swap(v);
1735 }
1736 
1737 
1743 template <typename Number, typename MemorySpace>
1745  : std::false_type
1746 {};
1747 
1748 
1749 
1750 namespace internal
1751 {
1752  namespace LinearOperatorImplementation
1753  {
1754  template <typename>
1755  class ReinitHelper;
1756 
1761  template <typename Number>
1762  class ReinitHelper<LinearAlgebra::distributed::Vector<Number>>
1763  {
1764  public:
1765  // A helper type-trait that leverage SFINAE to figure out if type T has
1766  // void T::get_mpi_communicator()
1767  template <typename T>
1768  struct has_get_mpi_communicator
1769  {
1770  private:
1771  static bool
1772  detect(...);
1773 
1774  template <typename U>
1775  static decltype(std::declval<U>().get_mpi_communicator())
1776  detect(const U &);
1777 
1778  public:
1779  static const bool value =
1780  !std::is_same<bool, decltype(detect(std::declval<T>()))>::value;
1781  };
1782 
1783  // A helper type-trait that leverage SFINAE to figure out if type T has
1784  // void T::locally_owned_domain_indices()
1785  template <typename T>
1786  struct has_locally_owned_domain_indices
1787  {
1788  private:
1789  static bool
1790  detect(...);
1791 
1792  template <typename U>
1793  static decltype(std::declval<U>().locally_owned_domain_indices())
1794  detect(const U &);
1795 
1796  public:
1797  static const bool value =
1798  !std::is_same<bool, decltype(detect(std::declval<T>()))>::value;
1799  };
1800 
1801  // A helper type-trait that leverage SFINAE to figure out if type T has
1802  // void T::locally_owned_range_indices()
1803  template <typename T>
1804  struct has_locally_owned_range_indices
1805  {
1806  private:
1807  static bool
1808  detect(...);
1809 
1810  template <typename U>
1811  static decltype(std::declval<U>().locally_owned_range_indices())
1812  detect(const U &);
1813 
1814  public:
1815  static const bool value =
1816  !std::is_same<bool, decltype(detect(std::declval<T>()))>::value;
1817  };
1818 
1819  // A helper type-trait that leverage SFINAE to figure out if type T has
1820  // void T::initialize_dof_vector(VectorType v)
1821  template <typename T>
1822  struct has_initialize_dof_vector
1823  {
1824  private:
1825  static bool
1826  detect(...);
1827 
1828  template <typename U>
1829  static decltype(std::declval<U>().initialize_dof_vector(
1830  std::declval<LinearAlgebra::distributed::Vector<Number> &>()))
1831  detect(const U &);
1832 
1833  public:
1834  static const bool value =
1835  !std::is_same<bool, decltype(detect(std::declval<T>()))>::value;
1836  };
1837 
1838  // Used for (Trilinos/PETSc)Wrappers::SparseMatrix
1839  template <typename MatrixType,
1840  typename std::enable_if<
1843  MatrixType>::type * = nullptr>
1844  static void
1845  reinit_domain_vector(MatrixType & mat,
1847  bool /*omit_zeroing_entries*/)
1848  {
1849  vec.reinit(mat.locally_owned_domain_indices(),
1850  mat.get_mpi_communicator());
1851  }
1852 
1853  // Used for MatrixFree and DiagonalMatrix
1854  template <
1855  typename MatrixType,
1857  MatrixType>::type * = nullptr>
1858  static void
1859  reinit_domain_vector(MatrixType & mat,
1861  bool omit_zeroing_entries)
1862  {
1863  mat.initialize_dof_vector(vec);
1864  if (!omit_zeroing_entries)
1865  vec = Number();
1866  }
1867 
1868  // Used for (Trilinos/PETSc)Wrappers::SparseMatrix
1869  template <typename MatrixType,
1870  typename std::enable_if<
1873  MatrixType>::type * = nullptr>
1874  static void
1875  reinit_range_vector(MatrixType & mat,
1877  bool /*omit_zeroing_entries*/)
1878  {
1879  vec.reinit(mat.locally_owned_range_indices(),
1880  mat.get_mpi_communicator());
1881  }
1882 
1883  // Used for MatrixFree and DiagonalMatrix
1884  template <
1885  typename MatrixType,
1886  typename std::enable_if<has_initialize_dof_vector<MatrixType>::value,
1887  MatrixType>::type * = nullptr>
1888  static void
1889  reinit_range_vector(MatrixType & mat,
1891  bool omit_zeroing_entries)
1892  {
1893  mat.initialize_dof_vector(vec);
1894  if (!omit_zeroing_entries)
1895  vec = Number();
1896  }
1897  };
1898 
1899  } // namespace LinearOperatorImplementation
1900 } /* namespace internal */
1901 
1902 
1904 
1905 #endif
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:621
bool in_local_range(const size_type global_index) const
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1568
std::vector< MPI_Request > update_ghost_values_requests
std::vector< value_type > l2_norm(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const value_type parent_value)
void scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
Definition: grid_tools.cc:837
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner
#define AssertIndexRange(index, range)
Definition: exceptions.h:1638
__global__ void add_and_dot(Number *res, Number *v1, const Number *v2, const Number *v3, const Number a, const size_type N)
static const char V
void reinit(const size_type size, const bool omit_zeroing_entries=false)
static const char U
static void reinit_range_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool omit_zeroing_entries)
bool is_finite(const double x)
Definition: numbers.h:537
Number local_element(const size_type local_index) const
void set_ghost_state(const bool ghosted) const
static ::ExceptionBase & ExcMessage(std::string arg1)
static void reinit_domain_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool)
std::string compress(const std::string &input)
Definition: utilities.cc:392
#define Assert(cond, exc)
Definition: exceptions.h:1408
static void reinit_range_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool)
Number linfty_norm(const Tensor< 2, dim, Number > &t)
Definition: tensor.h:2732
#define DeclException0(Exception0)
Definition: exceptions.h:473
void swap(LinearAlgebra::distributed::Vector< Number, MemorySpace > &u, LinearAlgebra::distributed::Vector< Number, MemorySpace > &v)
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:361
std::shared_ptr<::parallel::internal::TBBPartitioner > thread_loop_partitioner
VectorType::value_type * end(VectorType &V)
mutable ::MemorySpace::MemorySpaceData< Number, MemorySpace > import_data
__global__ void equ(Number *val, const Number a, const Number *V_val, const size_type N)
mutable ::MemorySpace::MemorySpaceData< Number, MemorySpace > data
__global__ void sadd(const Number s, Number *val, const Number a, const Number *V_val, const size_type N)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
typename numbers::NumberTraits< Number >::real_type real_type
unsigned int global_dof_index
Definition: types.h:76
virtual ::IndexSet locally_owned_elements() const override
virtual size_type size() const override
void swap(Vector< Number, MemorySpace > &v)
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:360
VectorType::value_type * begin(VectorType &V)
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_partitioner() const
static void reinit_domain_vector(MatrixType &mat, LinearAlgebra::distributed::Vector< Number > &vec, bool omit_zeroing_entries)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
Definition: exceptions.h:587
Number l1_norm(const Tensor< 2, dim, Number > &t)
Definition: tensor.h:2705
Number operator()(const size_type global_index) const
virtual void add(const Number a) override
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:564
std::enable_if< std::is_floating_point< T >::value &&std::is_floating_point< U >::value, typename ProductType< std::complex< T >, std::complex< U > >::type >::type operator*(const std::complex< T > &left, const std::complex< U > &right)
const MPI_Comm & get_mpi_communicator() const
std::vector< MPI_Request > compress_requests
static const bool value
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< OtherNumber > &values) const
Number operator[](const size_type global_index) const
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)