Reference documentation for deal.II version Git bef661081b 2019-09-23 12:55:27 -0400
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
la_parallel_vector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2011 - 2019 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 
21 #include <deal.II/base/memory_space.h>
22 #include <deal.II/base/mpi.h>
23 #include <deal.II/base/numbers.h>
24 #include <deal.II/base/partitioner.h>
25 #include <deal.II/base/thread_management.h>
26 
27 #include <deal.II/lac/vector_operation.h>
28 #include <deal.II/lac/vector_space_vector.h>
29 #include <deal.II/lac/vector_type_traits.h>
30 
31 #include <iomanip>
32 #include <memory>
33 
34 DEAL_II_NAMESPACE_OPEN
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:
230  using memory_space = MemorySpace;
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 *;
236  using reference = value_type &;
237  using const_reference = const value_type &;
238  using size_type = types::global_dof_index;
239  using real_type = typename numbers::NumberTraits<Number>::real_type;
240 
241  static_assert(
242  std::is_same<MemorySpace, ::MemorySpace::Host>::value ||
243  std::is_same<MemorySpace, ::MemorySpace::CUDA>::value,
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 
414 #ifdef DEAL_II_WITH_PETSC
415 
425  DEAL_II_DEPRECATED
427  operator=(const PETScWrappers::MPI::Vector &petsc_vec);
428 #endif
429 
430 #ifdef DEAL_II_WITH_TRILINOS
431 
442  DEAL_II_DEPRECATED
444  operator=(const TrilinosWrappers::MPI::Vector &trilinos_vec);
445 #endif
446 
447 
487  virtual void
488  compress(::VectorOperation::values operation) override;
489 
511  void
512  update_ghost_values() const;
513 
528  void
529  compress_start(
530  const unsigned int communication_channel = 0,
532 
548  void
549  compress_finish(::VectorOperation::values operation);
550 
565  void
566  update_ghost_values_start(
567  const unsigned int communication_channel = 0) const;
568 
569 
577  void
578  update_ghost_values_finish() const;
579 
588  void
589  zero_out_ghosts() const;
590 
602  bool
603  has_ghost_elements() const;
604 
619  template <typename Number2>
620  void
621  copy_locally_owned_data_from(const Vector<Number2, MemorySpace> &src);
622 
633  template <typename MemorySpace2>
634  void
635  import(const Vector<Number, MemorySpace2> &src,
636  VectorOperation::values operation);
637 
639 
644 
649  virtual void
650  reinit(const VectorSpaceVector<Number> &V,
651  const bool omit_zeroing_entries = false) override;
652 
657  operator*=(const Number factor) override;
658 
663  operator/=(const Number factor) override;
664 
669  operator+=(const VectorSpaceVector<Number> &V) override;
670 
675  operator-=(const VectorSpaceVector<Number> &V) override;
676 
688  virtual void
689  import(
691  VectorOperation::values operation,
692  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
693  std::shared_ptr<const CommunicationPatternBase>()) override;
694 
698  virtual Number
699  operator*(const VectorSpaceVector<Number> &V) const override;
700 
704  virtual void
705  add(const Number a) override;
706 
710  virtual void
711  add(const Number a, const VectorSpaceVector<Number> &V) override;
712 
716  virtual void
717  add(const Number a,
718  const VectorSpaceVector<Number> &V,
719  const Number b,
720  const VectorSpaceVector<Number> &W) override;
721 
726  virtual void
727  add(const std::vector<size_type> &indices,
728  const std::vector<Number> & values);
729 
734  virtual void
735  sadd(const Number s,
736  const Number a,
737  const VectorSpaceVector<Number> &V) override;
738 
744  virtual void
745  scale(const VectorSpaceVector<Number> &scaling_factors) override;
746 
750  virtual void
751  equ(const Number a, const VectorSpaceVector<Number> &V) override;
752 
757  virtual real_type
758  l1_norm() const override;
759 
764  virtual real_type
765  l2_norm() const override;
766 
770  real_type
771  norm_sqr() const;
772 
777  virtual real_type
778  linfty_norm() const override;
779 
800  virtual Number
801  add_and_dot(const Number a,
802  const VectorSpaceVector<Number> &V,
803  const VectorSpaceVector<Number> &W) override;
804 
809  virtual size_type
810  size() const override;
811 
823  virtual ::IndexSet
824  locally_owned_elements() const override;
825 
829  virtual void
830  print(std::ostream & out,
831  const unsigned int precision = 3,
832  const bool scientific = true,
833  const bool across = true) const override;
834 
838  virtual std::size_t
839  memory_consumption() const override;
841 
846 
853  operator=(const Number s) override;
854 
859  template <typename OtherNumber>
860  void
861  add(const std::vector<size_type> & indices,
862  const ::Vector<OtherNumber> &values);
863 
868  template <typename OtherNumber>
869  void
870  add(const size_type n_elements,
871  const size_type * indices,
872  const OtherNumber *values);
873 
878  void
879  sadd(const Number s, const Vector<Number, MemorySpace> &V);
880 
886  DEAL_II_DEPRECATED
887  void
888  sadd(const Number s,
889  const Number a,
891  const Number b,
892  const Vector<Number, MemorySpace> &W);
893 
899  DEAL_II_DEPRECATED
900  void
901  equ(const Number a,
903  const Number b,
904  const Vector<Number, MemorySpace> &v);
905 
907 
908 
913 
918  size_type
919  local_size() const;
920 
928  DEAL_II_DEPRECATED
929  std::pair<size_type, size_type>
930  local_range() const;
931 
938  DEAL_II_DEPRECATED
939  bool
940  in_local_range(const size_type global_index) const;
941 
947  DEAL_II_DEPRECATED
948  size_type
949  n_ghost_entries() const;
950 
958  DEAL_II_DEPRECATED
959  const IndexSet &
960  ghost_elements() const;
961 
969  DEAL_II_DEPRECATED
970  bool
971  is_ghost_entry(const types::global_dof_index global_index) const;
972 
983  iterator
984  begin();
985 
993  const_iterator
994  begin() const;
995 
1003  iterator
1004  end();
1005 
1013  const_iterator
1014  end() const;
1015 
1025  Number
1026  operator()(const size_type global_index) const;
1027 
1037  Number &
1038  operator()(const size_type global_index);
1039 
1047  Number operator[](const size_type global_index) const;
1055  Number &operator[](const size_type global_index);
1056 
1065  Number
1066  local_element(const size_type local_index) const;
1067 
1076  Number &
1077  local_element(const size_type local_index);
1078 
1085  Number *
1086  get_values() const;
1087 
1105  template <typename OtherNumber>
1106  void
1107  extract_subvector_to(const std::vector<size_type> &indices,
1108  std::vector<OtherNumber> & values) const;
1109 
1137  template <typename ForwardIterator, typename OutputIterator>
1138  void
1139  extract_subvector_to(ForwardIterator indices_begin,
1140  const ForwardIterator indices_end,
1141  OutputIterator values_begin) const;
1147  virtual bool
1148  all_zero() const override;
1149 
1153  virtual Number
1154  mean_value() const override;
1155 
1160  real_type
1161  lp_norm(const real_type p) const;
1163 
1168 
1173  const MPI_Comm &
1174  get_mpi_communicator() const;
1175 
1182  const std::shared_ptr<const Utilities::MPI::Partitioner> &
1183  get_partitioner() const;
1184 
1194  bool
1195  partitioners_are_compatible(
1196  const Utilities::MPI::Partitioner &part) const;
1197 
1211  bool
1212  partitioners_are_globally_compatible(
1213  const Utilities::MPI::Partitioner &part) const;
1214 
1218  void
1219  set_ghost_state(const bool ghosted) const;
1220 
1222 
1228  DeclException0(ExcVectorTypeNotCompatible);
1229 
1235  DeclException0(ExcNotAllowedForCuda);
1236 
1240  DeclException3(ExcNonMatchingElements,
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 
1254  DeclException4(ExcAccessToNonLocalElement,
1255  size_type,
1256  size_type,
1257  size_type,
1258  size_type,
1259  << "You tried to access element " << arg1
1260  << " of a distributed vector, but this element is not "
1261  << "stored on the current processor. Note: The range of "
1262  << "locally owned elements is " << arg2 << " to " << arg3
1263  << ", and there are " << arg4 << " ghost elements "
1264  << "that this vector can access.");
1265 
1266  private:
1271  void
1272  add_local(const Number a, const VectorSpaceVector<Number> &V);
1273 
1278  void
1279  sadd_local(const Number s,
1280  const Number a,
1281  const VectorSpaceVector<Number> &V);
1282 
1286  template <typename Number2>
1287  Number
1288  inner_product_local(const Vector<Number2, MemorySpace> &V) const;
1289 
1293  real_type
1294  norm_sqr_local() const;
1295 
1299  Number
1300  mean_value_local() const;
1301 
1305  real_type
1306  l1_norm_local() const;
1307 
1311  real_type
1312  lp_norm_local(const real_type p) const;
1313 
1317  real_type
1318  linfty_norm_local() const;
1319 
1325  Number
1326  add_and_dot_local(const Number a,
1327  const Vector<Number, MemorySpace> &V,
1328  const Vector<Number, MemorySpace> &W);
1329 
1335  std::shared_ptr<const Utilities::MPI::Partitioner> partitioner;
1336 
1340  size_type allocated_size;
1341 
1345  mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace> data;
1346 
1351  mutable std::shared_ptr<::parallel::internal::TBBPartitioner>
1353 
1359  mutable ::MemorySpace::MemorySpaceData<Number, MemorySpace>
1361 
1369  mutable bool vector_is_ghosted;
1370 
1371 #ifdef DEAL_II_WITH_MPI
1372 
1380  std::vector<MPI_Request> compress_requests;
1381 
1386  mutable std::vector<MPI_Request> update_ghost_values_requests;
1387 #endif
1388 
1395 
1400  void
1401  clear_mpi_requests();
1402 
1406  void
1407  resize_val(const size_type new_allocated_size);
1408 
1409  // Make all other vector types friends.
1410  template <typename Number2, typename MemorySpace2>
1411  friend class Vector;
1412 
1413  // Make BlockVector type friends.
1414  template <typename Number2>
1415  friend class BlockVector;
1416  };
1420  /*-------------------- Inline functions ---------------------------------*/
1421 
1422 #ifndef DOXYGEN
1423 
1424  namespace internal
1425  {
1426  template <typename Number, typename MemorySpace>
1427  struct Policy
1428  {
1429  static inline typename Vector<Number, MemorySpace>::iterator
1431  {
1432  return nullptr;
1433  }
1434 
1435  static inline typename Vector<Number, MemorySpace>::const_iterator
1436  begin(
1437  const ::MemorySpace::MemorySpaceData<Number, MemorySpace> &)
1438  {
1439  return nullptr;
1440  }
1441 
1442  static inline Number *
1443  get_values(
1445  {
1446  return nullptr;
1447  }
1448  };
1449 
1450 
1451 
1452  template <typename Number>
1453  struct Policy<Number, ::MemorySpace::Host>
1454  {
1455  static inline
1456  typename Vector<Number, ::MemorySpace::Host>::iterator
1457  begin(::MemorySpace::
1458  MemorySpaceData<Number, ::MemorySpace::Host> &data)
1459  {
1460  return data.values.get();
1461  }
1462 
1463  static inline
1464  typename Vector<Number, ::MemorySpace::Host>::const_iterator
1465  begin(const ::MemorySpace::
1466  MemorySpaceData<Number, ::MemorySpace::Host> &data)
1467  {
1468  return data.values.get();
1469  }
1470 
1471  static inline Number *
1472  get_values(::MemorySpace::
1473  MemorySpaceData<Number, ::MemorySpace::Host> &data)
1474  {
1475  return data.values.get();
1476  }
1477  };
1478 
1479 
1480 
1481  template <typename Number>
1482  struct Policy<Number, ::MemorySpace::CUDA>
1483  {
1484  static inline
1485  typename Vector<Number, ::MemorySpace::CUDA>::iterator
1486  begin(::MemorySpace::
1487  MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1488  {
1489  return data.values_dev.get();
1490  }
1491 
1492  static inline
1493  typename Vector<Number, ::MemorySpace::CUDA>::const_iterator
1494  begin(const ::MemorySpace::
1495  MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1496  {
1497  return data.values_dev.get();
1498  }
1499 
1500  static inline Number *
1501  get_values(::MemorySpace::
1502  MemorySpaceData<Number, ::MemorySpace::CUDA> &data)
1503  {
1504  return data.values_dev.get();
1505  }
1506  };
1507  } // namespace internal
1508 
1509 
1510  template <typename Number, typename MemorySpace>
1511  inline bool
1513  {
1514  return vector_is_ghosted;
1515  }
1516 
1517 
1518 
1519  template <typename Number, typename MemorySpace>
1520  inline typename Vector<Number, MemorySpace>::size_type
1522  {
1523  return partitioner->size();
1524  }
1525 
1526 
1527 
1528  template <typename Number, typename MemorySpace>
1529  inline typename Vector<Number, MemorySpace>::size_type
1531  {
1532  return partitioner->local_size();
1533  }
1534 
1535 
1536 
1537  template <typename Number, typename MemorySpace>
1538  inline std::pair<typename Vector<Number, MemorySpace>::size_type,
1539  typename Vector<Number, MemorySpace>::size_type>
1541  {
1542  return partitioner->local_range();
1543  }
1544 
1545 
1546 
1547  template <typename Number, typename MemorySpace>
1548  inline bool
1550  const size_type global_index) const
1551  {
1552  return partitioner->in_local_range(global_index);
1553  }
1554 
1555 
1556 
1557  template <typename Number, typename MemorySpace>
1558  inline IndexSet
1560  {
1561  IndexSet is(size());
1562 
1563  is.add_range(partitioner->local_range().first,
1564  partitioner->local_range().second);
1565 
1566  return is;
1567  }
1568 
1569 
1570 
1571  template <typename Number, typename MemorySpace>
1572  inline typename Vector<Number, MemorySpace>::size_type
1574  {
1575  return partitioner->n_ghost_indices();
1576  }
1577 
1578 
1579 
1580  template <typename Number, typename MemorySpace>
1581  inline const IndexSet &
1583  {
1584  return partitioner->ghost_indices();
1585  }
1586 
1587 
1588 
1589  template <typename Number, typename MemorySpace>
1590  inline bool
1592  const size_type global_index) const
1593  {
1594  return partitioner->is_ghost_entry(global_index);
1595  }
1596 
1597 
1598 
1599  template <typename Number, typename MemorySpace>
1600  inline typename Vector<Number, MemorySpace>::iterator
1602  {
1603  return internal::Policy<Number, MemorySpace>::begin(data);
1604  }
1605 
1606 
1607 
1608  template <typename Number, typename MemorySpace>
1609  inline typename Vector<Number, MemorySpace>::const_iterator
1611  {
1612  return internal::Policy<Number, MemorySpace>::begin(data);
1613  }
1614 
1615 
1616 
1617  template <typename Number, typename MemorySpace>
1618  inline typename Vector<Number, MemorySpace>::iterator
1620  {
1621  return internal::Policy<Number, MemorySpace>::begin(data) +
1622  partitioner->local_size();
1623  }
1624 
1625 
1626 
1627  template <typename Number, typename MemorySpace>
1628  inline typename Vector<Number, MemorySpace>::const_iterator
1630  {
1631  return internal::Policy<Number, MemorySpace>::begin(data) +
1632  partitioner->local_size();
1633  }
1634 
1635 
1636 
1637  template <typename Number, typename MemorySpace>
1638  inline Number
1639  Vector<Number, MemorySpace>::operator()(const size_type global_index) const
1640  {
1641  Assert((std::is_same<MemorySpace, ::MemorySpace::Host>::value),
1642  ExcMessage(
1643  "This function is only implemented for the Host memory space"));
1644  Assert(
1645  partitioner->in_local_range(global_index) ||
1646  partitioner->ghost_indices().is_element(global_index),
1647  ExcAccessToNonLocalElement(global_index,
1648  partitioner->local_range().first,
1649  partitioner->local_range().second,
1650  partitioner->ghost_indices().n_elements()));
1651  // do not allow reading a vector which is not in ghost mode
1652  Assert(partitioner->in_local_range(global_index) ||
1653  vector_is_ghosted == true,
1654  ExcMessage("You tried to read a ghost element of this vector, "
1655  "but it has not imported its ghost values."));
1656  return data.values[partitioner->global_to_local(global_index)];
1657  }
1658 
1659 
1660 
1661  template <typename Number, typename MemorySpace>
1662  inline Number &
1663  Vector<Number, MemorySpace>::operator()(const size_type global_index)
1664  {
1665  Assert((std::is_same<MemorySpace, ::MemorySpace::Host>::value),
1666  ExcMessage(
1667  "This function is only implemented for the Host memory space"));
1668  Assert(
1669  partitioner->in_local_range(global_index) ||
1670  partitioner->ghost_indices().is_element(global_index),
1671  ExcAccessToNonLocalElement(global_index,
1672  partitioner->local_range().first,
1673  partitioner->local_range().second,
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 Vector<Number, MemorySpace>::
1688  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 &Vector<Number, MemorySpace>::
1697  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->local_size() +
1714  partitioner->n_ghost_indices());
1715  // do not allow reading a vector which is not in ghost mode
1716  Assert(local_index < local_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->local_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 
1860 template <typename Number, typename MemorySpace>
1861 inline void
1864 {
1865  u.swap(v);
1866 }
1867 
1868 
1874 template <typename Number, typename MemorySpace>
1876  : std::false_type
1877 {};
1878 
1879 
1880 
1881 namespace internal
1882 {
1883  namespace LinearOperatorImplementation
1884  {
1885  template <typename>
1886  class ReinitHelper;
1887 
1892  template <typename Number>
1893  class ReinitHelper<LinearAlgebra::distributed::Vector<Number>>
1894  {
1895  public:
1896  template <typename Matrix>
1897  static void
1898  reinit_range_vector(const Matrix & matrix,
1900  bool omit_zeroing_entries)
1901  {
1902  matrix.initialize_dof_vector(v);
1903  if (!omit_zeroing_entries)
1904  v = Number();
1905  }
1906 
1907  template <typename Matrix>
1908  static void
1909  reinit_domain_vector(const Matrix & matrix,
1911  bool omit_zeroing_entries)
1912  {
1913  matrix.initialize_dof_vector(v);
1914  if (!omit_zeroing_entries)
1915  v = Number();
1916  }
1917  };
1918 
1919  } // namespace LinearOperatorImplementation
1920 } /* namespace internal */
1921 
1922 
1923 DEAL_II_NAMESPACE_CLOSE
1924 
1925 #endif
bool in_local_range(const size_type global_index) const
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1567
DEAL_II_CONSTEXPR SymmetricTensor< rank_, dim, Number > operator*(const SymmetricTensor< rank_, dim, Number > &t, const Number &factor)
std::vector< MPI_Request > update_ghost_values_requests
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner
#define AssertIndexRange(index, range)
Definition: exceptions.h:1637
__global__ void add_and_dot(Number *res, Number *v1, const Number *v2, const Number *v3, const Number a, const size_type N)
LinearAlgebra::distributed::Vector< Number > Vector
bool is_finite(const double x)
Definition: numbers.h:555
bool is_ghost_entry(const types::global_dof_index global_index) const
__global__ void scale(Number *val, const Number *V_val, const size_type N)
Number local_element(const size_type local_index) const
void set_ghost_state(const bool ghosted) const
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1407
#define DeclException0(Exception0)
Definition: exceptions.h:473
std::shared_ptr<::parallel::internal::TBBPartitioner > thread_loop_partitioner
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)
void swap(Vector< Number > &u, Vector< Number > &v)
Definition: vector.h:1376
unsigned int global_dof_index
Definition: types.h:89
virtual ::IndexSet locally_owned_elements() const override
virtual size_type size() const override
std::pair< size_type, size_type > local_range() const
void swap(Vector< Number, MemorySpace > &v)
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_partitioner() const
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
Definition: exceptions.h:587
Number operator()(const size_type global_index) const
virtual void add(const Number a) override
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:564
void swap(LinearAlgebra::distributed::Vector< Number, MemorySpace > &u, LinearAlgebra::distributed::Vector< Number, MemorySpace > &v)
const MPI_Comm & get_mpi_communicator() const
std::vector< MPI_Request > compress_requests
const IndexSet & ghost_elements() const
void extract_subvector_to(const std::vector< size_type > &indices, std::vector< OtherNumber > &values) const
Number operator[](const size_type global_index) const