Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_MultiVector_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 // clang-format off
11 #ifndef TPETRA_MULTIVECTOR_DECL_HPP
12 #define TPETRA_MULTIVECTOR_DECL_HPP
13 
16 
18 #include "Tpetra_Vector_fwd.hpp"
20 #include "Tpetra_DistObject.hpp"
21 #include "Tpetra_Map_fwd.hpp"
23 #include "Kokkos_DualView.hpp"
24 #include "Teuchos_BLAS_types.hpp"
25 #include "Teuchos_DataAccess.hpp"
26 #include "Teuchos_Range1D.hpp"
27 #include "Kokkos_ArithTraits.hpp"
28 #include "Kokkos_InnerProductSpaceTraits.hpp"
29 #include "Tpetra_KokkosRefactor_Details_MultiVectorLocalDeepCopy.hpp"
30 #include "Tpetra_Access.hpp"
31 #include "Tpetra_Details_WrappedDualView.hpp"
32 #include <type_traits>
33 
34 #ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
35 #ifndef DOXYGEN_SHOULD_SKIP_THIS
36 namespace Teuchos {
37  template<class OrdinalType, class ScalarType>
38  class SerialDenseMatrix; // forward declaration
39 }
40 #endif // DOXYGEN_SHOULD_SKIP_THIS
41 #endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
42 
43 
44 namespace Tpetra {
45 
46 
67  template <class DS, class DL, class DG, class DN,
68  class SS, class SL, class SG, class SN>
69  void
70  deep_copy (MultiVector<DS, DL, DG, DN>& dst,
71  const MultiVector<SS, SL, SG, SN>& src);
72 
73 #ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
74  template <class ST, class LO, class GO, class NT>
81  void
82  deep_copy (MultiVector<ST, LO, GO, NT>& dst,
83  const Teuchos::SerialDenseMatrix<int, ST>& src);
84 
91  template <class ST, class LO, class GO, class NT>
92  void
93  deep_copy (Teuchos::SerialDenseMatrix<int, ST>& dst,
94  const MultiVector<ST, LO, GO, NT>& src);
95 #endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
96 
104  template <class ST, class LO, class GO, class NT>
105  MultiVector<ST, LO, GO, NT>
106  createCopy (const MultiVector<ST, LO, GO, NT>& src);
107 
117  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
118  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
119  createMultiVector (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map,
120  const size_t numVectors);
121 
122  // WARNING NOT FOR USERS
123  // This means we don't need to make MultiVector a friend of
124  // Vector or of itself (with different template parameters).
125  template<class SC, class LO, class GO, class NT>
126  Teuchos::ArrayView<const size_t>
127  getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X);
128 
129 
349  template <class Scalar,
350  class LocalOrdinal,
351  class GlobalOrdinal,
352  class Node>
353  class MultiVector :
354  public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node>
355  {
356  public:
358 
359 
361  using scalar_type = Scalar;
377  using impl_scalar_type =
378  typename Kokkos::ArithTraits<Scalar>::val_type;
379 
389  using node_type = typename map_type::node_type;
390 
396  using dot_type =
397  typename Kokkos::Details::InnerProductSpaceTraits<impl_scalar_type>::dot_type;
398 
405  using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
406 
411  using execution_space = typename device_type::execution_space;
412 
435  using dual_view_type = Kokkos::DualView<impl_scalar_type**,
436  Kokkos::LayoutLeft,
439 
440  using host_view_type = typename dual_view_type::t_host;
441  using device_view_type = typename dual_view_type::t_dev;
442 
444 
446 
448  MultiVector ();
449 
456  MultiVector (const Teuchos::RCP<const map_type>& map,
457  const size_t numVecs,
458  const bool zeroOut = true);
459 
471  const Teuchos::DataAccess copyOrView);
472 
488  MultiVector (const Teuchos::RCP<const map_type>& map,
489  const Teuchos::ArrayView<const Scalar>& A,
490  const size_t LDA,
491  const size_t NumVectors);
492 
506  MultiVector (const Teuchos::RCP<const map_type>& map,
507  const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar> >&ArrayOfPtrs,
508  const size_t NumVectors);
509 
522  MultiVector (const Teuchos::RCP<const map_type>& map,
523  const dual_view_type& view);
524 
563  MultiVector (const Teuchos::RCP<const map_type>& map,
564  const typename dual_view_type::t_dev& d_view);
565 
588  MultiVector (const Teuchos::RCP<const map_type>& map,
589  const dual_view_type& view,
590  const dual_view_type& origView);
591 
600  MultiVector (const Teuchos::RCP<const map_type>& map,
601  const wrapped_dual_view_type& d_view);
602 
603 
604  protected:
605 
611  const size_t j);
612 
613  public:
614 
632  MultiVector (const Teuchos::RCP<const map_type>& map,
633  const dual_view_type& view,
634  const Teuchos::ArrayView<const size_t>& whichVectors);
635 
653  MultiVector (const Teuchos::RCP<const map_type>& map,
654  const wrapped_dual_view_type& view,
655  const Teuchos::ArrayView<const size_t>& whichVectors);
656 
657 
685  MultiVector (const Teuchos::RCP<const map_type>& map,
686  const dual_view_type& view,
687  const dual_view_type& origView,
688  const Teuchos::ArrayView<const size_t>& whichVectors);
689 
751  const Teuchos::RCP<const map_type>& subMap,
752  const local_ordinal_type rowOffset = 0);
753 
761  const map_type& subMap,
762  const size_t offset = 0);
763 
773 
776 
784 
788 
798  virtual ~MultiVector () = default;
799 
802 
804 
806 
807  protected:
812  static const bool useAtomicUpdatesByDefault =
813 #ifdef KOKKOS_ENABLE_SERIAL
814  ! std::is_same<execution_space, Kokkos::Serial>::value;
815 #else
816  true;
817 #endif // KOKKOS_ENABLE_SERIAL
818 
819  public:
849  void
850  replaceGlobalValue (const GlobalOrdinal gblRow,
851  const size_t col,
852  const impl_scalar_type& value);
853 
886  template<typename T>
887  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
888  replaceGlobalValue (GlobalOrdinal globalRow,
889  size_t col,
890  const T& value)
891  {
892  replaceGlobalValue (globalRow, col, static_cast<impl_scalar_type> (value));
893  }
894 
919  void
920  sumIntoGlobalValue (const GlobalOrdinal gblRow,
921  const size_t col,
922  const impl_scalar_type& value,
923  const bool atomic = useAtomicUpdatesByDefault);
924 
953  template<typename T>
954  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
955  sumIntoGlobalValue (const GlobalOrdinal gblRow,
956  const size_t col,
957  const T& val,
958  const bool atomic = useAtomicUpdatesByDefault)
959  {
960  sumIntoGlobalValue (gblRow, col, static_cast<impl_scalar_type> (val), atomic);
961  }
962 
992  void
993  replaceLocalValue (const LocalOrdinal lclRow,
994  const size_t col,
995  const impl_scalar_type& value);
996 
1030  template<typename T>
1031  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1032  replaceLocalValue (const LocalOrdinal lclRow,
1033  const size_t col,
1034  const T& val)
1035  {
1036  replaceLocalValue (lclRow, col, static_cast<impl_scalar_type> (val));
1037  }
1038 
1063  void
1064  sumIntoLocalValue (const LocalOrdinal lclRow,
1065  const size_t col,
1066  const impl_scalar_type& val,
1067  const bool atomic = useAtomicUpdatesByDefault);
1068 
1095  template<typename T>
1096  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1097  sumIntoLocalValue (const LocalOrdinal lclRow,
1098  const size_t col,
1099  const T& val,
1100  const bool atomic = useAtomicUpdatesByDefault)
1101  {
1102  sumIntoLocalValue (lclRow, col, static_cast<impl_scalar_type> (val), atomic);
1103  }
1104 
1106  void putScalar (const Scalar& value);
1107 
1116  template<typename T>
1117  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1118  putScalar (const T& value)
1119  {
1120  putScalar (static_cast<impl_scalar_type> (value));
1121  }
1122 
1135  void randomize();
1136 
1150  void randomize (const Scalar& minVal, const Scalar& maxVal);
1151 
1217  void replaceMap (const Teuchos::RCP<const map_type>& map);
1218 
1225  void reduce();
1226 
1228 
1254 
1255 
1257  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1258  subCopy (const Teuchos::Range1D& colRng) const;
1259 
1261  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1262  subCopy (const Teuchos::ArrayView<const size_t>& cols) const;
1263 
1265  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1266  subView (const Teuchos::Range1D& colRng) const;
1267 
1269  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1270  subView (const Teuchos::ArrayView<const size_t>& cols) const;
1271 
1273  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1274  subViewNonConst (const Teuchos::Range1D& colRng);
1275 
1277  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1278  subViewNonConst (const Teuchos::ArrayView<const size_t>& cols);
1279 
1342  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1343  offsetView (const Teuchos::RCP<const map_type>& subMap,
1344  const size_t offset) const;
1345 
1363  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1364  offsetViewNonConst (const Teuchos::RCP<const map_type>& subMap,
1365  const size_t offset);
1366 
1368  Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1369  getVector (const size_t j) const;
1370 
1372  Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1373  getVectorNonConst (const size_t j);
1374 
1376  Teuchos::ArrayRCP<const Scalar> getData (size_t j) const;
1377 
1379  Teuchos::ArrayRCP<Scalar> getDataNonConst (size_t j);
1380 
1388  void
1389  get1dCopy (const Teuchos::ArrayView<Scalar>& A,
1390  const size_t LDA) const;
1391 
1398  void
1399  get2dCopy (const Teuchos::ArrayView<const Teuchos::ArrayView<Scalar> >& ArrayOfPtrs) const;
1400 
1406  Teuchos::ArrayRCP<const Scalar> get1dView () const;
1407 
1409  Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> > get2dView () const;
1410 
1416  Teuchos::ArrayRCP<Scalar> get1dViewNonConst ();
1417 
1419  Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > get2dViewNonConst ();
1420 
1423  typename dual_view_type::t_host::const_type getLocalViewHost(Access::ReadOnlyStruct) const;
1424 
1427  typename dual_view_type::t_host getLocalViewHost(Access::ReadWriteStruct);
1428 
1431  typename dual_view_type::t_host getLocalViewHost(Access::OverwriteAllStruct);
1432 
1435  typename dual_view_type::t_dev::const_type getLocalViewDevice(Access::ReadOnlyStruct) const;
1436 
1439  typename dual_view_type::t_dev getLocalViewDevice(Access::ReadWriteStruct);
1440 
1443  typename dual_view_type::t_dev getLocalViewDevice(Access::OverwriteAllStruct);
1444 
1449  wrapped_dual_view_type getWrappedDualView() const;
1450 
1452  template<class TargetDeviceType>
1453  bool need_sync () const {
1454  return view_.getDualView().template need_sync<TargetDeviceType> ();
1455  }
1456 
1458  bool need_sync_host () const;
1459 
1461  bool need_sync_device () const;
1462 
1491  template<class TargetDeviceType>
1492  typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type::const_type
1493  getLocalView (Access::ReadOnlyStruct s) const
1494  {
1495  return view_.template getView<TargetDeviceType>(s);
1496  }
1497 
1498 
1499  template<class TargetDeviceType>
1500  typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1501  getLocalView (Access::ReadWriteStruct s)
1502  {
1503  return view_.template getView<TargetDeviceType>(s);
1504  }
1505 
1506  template<class TargetDeviceType>
1507  typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1508  getLocalView (Access::OverwriteAllStruct s)
1509  {
1510  return view_.template getView<TargetDeviceType>(s);
1511  }
1512 
1514 
1516 
1530  void
1531  dot (const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
1532  const Teuchos::ArrayView<dot_type>& dots) const;
1533 
1545  template <typename T>
1546  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1548  const Teuchos::ArrayView<T> &dots) const
1549  {
1550  const size_t sz = static_cast<size_t> (dots.size ());
1551  Teuchos::Array<dot_type> dts (sz);
1552  this->dot (A, dts);
1553  for (size_t i = 0; i < sz; ++i) {
1554  // If T and dot_type differ, this does an implicit conversion.
1555  dots[i] = dts[i];
1556  }
1557  }
1558 
1560  template <typename T>
1561  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1563  std::vector<T>& dots) const
1564  {
1565  const size_t sz = dots.size ();
1566  Teuchos::Array<dot_type> dts (sz);
1567  this->dot (A, dts);
1568  for (size_t i = 0; i < sz; ++i) {
1569  // If T and dot_type differ, this does an implicit conversion.
1570  dots[i] = dts[i];
1571  }
1572  }
1573 
1591  void
1593  const Kokkos::View<dot_type*, Kokkos::HostSpace>& norms) const;
1594 
1595  template<class ViewType>
1596  void
1597  dot (typename std::enable_if<std::is_same<typename ViewType::value_type,dot_type>::value &&
1598  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value,
1600  const ViewType& dots) const {
1601  const Kokkos::View<dot_type*, Kokkos::HostSpace> h_dots("Tpetra::Dots",dots.extent(0));
1602  this->dot (A, h_dots);
1603  // DEEP_COPY REVIEW - NOT TESTED
1604  Kokkos::deep_copy(dots,h_dots);
1605  }
1606 
1619  template <typename T>
1620  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1622  const Kokkos::View<T*, device_type>& dots) const
1623  {
1624  const size_t numDots = dots.extent (0);
1625  Kokkos::View<dot_type*, device_type> dts ("MV::dot tmp", numDots);
1626  // Call overload that takes a Kokkos::View<dot_type*, device_type>.
1627  this->dot (A, dts);
1628  // FIXME (mfh 14 Jul 2014) Does this actually work if dot_type
1629  // and T differ? We would need a test for this, but only the
1630  // Sacado and Stokhos packages are likely to care about this use
1631  // case. It could also come up for Kokkos::complex ->
1632  // std::complex conversions, but those two implementations
1633  // should generally be bitwise compatible.
1634  // CT: no this can't possible work .....
1635  // DEEP_COPY REVIEW - NOT TESTED
1636  Kokkos::deep_copy (dots, dts);
1637  }
1638 
1641 
1644 
1652  void scale (const Scalar& alpha);
1653 
1662  void scale (const Teuchos::ArrayView<const Scalar>& alpha);
1663 
1672  void scale (const Kokkos::View<const impl_scalar_type*, device_type>& alpha);
1673 
1682  void
1683  scale (const Scalar& alpha,
1685 
1692  void
1693  update (const Scalar& alpha,
1695  const Scalar& beta);
1696 
1703  void
1704  update (const Scalar& alpha,
1706  const Scalar& beta,
1708  const Scalar& gamma);
1709 
1721  void
1722  norm1 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1723 
1724  template<class ViewType>
1725  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1726  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1727  norm1 (const ViewType& norms) const {
1728  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1729  // this method to be templated. (It only exists in case
1730  // HostSpace = device_type::memory_space.)
1731  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1732  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1733  this->norm1 (h_norms);
1734  // DEEP_COPY REVIEW - HOST-TO-DEVICE
1735  Kokkos::deep_copy (execution_space(), norms, h_norms);
1736  }
1737 
1753  template <typename T>
1754  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1755  norm1 (const Kokkos::View<T*, device_type>& norms) const
1756  {
1757  const size_t numNorms = norms.extent (0);
1758  Kokkos::View<mag_type*, device_type> tmpNorms ("MV::norm1 tmp", numNorms);
1759  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1760  this->norm1 (tmpNorms);
1761  // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1762  // and T differ? We would need a test for this, but only the
1763  // Sacado and Stokhos packages are likely to care about this use
1764  // case. It could also come up with Kokkos::complex ->
1765  // std::complex conversion.
1766  // DEEP_COPY REVIEW - NOT TESTED
1767  Kokkos::deep_copy (norms, tmpNorms);
1768  }
1769 
1773  void norm1 (const Teuchos::ArrayView<mag_type>& norms) const;
1774 
1789  template <typename T>
1790  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1791  norm1 (const Teuchos::ArrayView<T>& norms) const
1792  {
1793  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1794  const size_type sz = norms.size ();
1795  Teuchos::Array<mag_type> theNorms (sz);
1796  this->norm1 (theNorms);
1797  for (size_type i = 0; i < sz; ++i) {
1798  // If T and mag_type differ, this does an implicit conversion.
1799  norms[i] = theNorms[i];
1800  }
1801  }
1802 
1815  void
1816  norm2 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1817 
1818  template<class ViewType>
1819  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1820  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1821  norm2 (const ViewType& norms) const {
1822  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1823  // this method to be templated. (It only exists in case
1824  // HostSpace = device_type::memory_space.)
1825  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1826  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1827  this->norm2 (h_norms);
1828  // DEEP_COPY REVIEW - NOT TESTED
1829  Kokkos::deep_copy (norms, h_norms);
1830  }
1831 
1845  template<typename T>
1846  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1847  norm2 (const Kokkos::View<T*, device_type>& norms) const
1848  {
1849  const size_t numNorms = norms.extent (0);
1850  Kokkos::View<mag_type*, device_type> theNorms ("MV::norm2 tmp", numNorms);
1851  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1852  this->norm2 (theNorms);
1853  // FIXME (mfh 14 Jul 2014) Does this actually work if mag_type
1854  // and T differ? We would need a test for this, but only the
1855  // Sacado and Stokhos packages are likely to care about this use
1856  // case. This could also come up with Kokkos::complex ->
1857  // std::complex conversion.
1858  // DEEP_COPY REVIEW - NOT TESTED
1859  Kokkos::deep_copy (norms, theNorms);
1860  }
1861 
1865  void norm2 (const Teuchos::ArrayView<mag_type>& norms) const;
1866 
1881  template <typename T>
1882  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1883  norm2 (const Teuchos::ArrayView<T>& norms) const
1884  {
1885  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1886  const size_type sz = norms.size ();
1887  Teuchos::Array<mag_type> theNorms (sz);
1888  this->norm2 (theNorms);
1889  for (size_type i = 0; i < sz; ++i) {
1890  // If T and mag_type differ, this does an implicit conversion.
1891  norms[i] = theNorms[i];
1892  }
1893  }
1894 
1901  void normInf (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1902 
1903  template<class ViewType>
1904  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1905  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1906  normInf (const ViewType& norms) const {
1907  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1908  // this method to be templated. (It only exists in case
1909  // HostSpace = device_type::memory_space.)
1910  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1911  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1912  this->normInf (h_norms);
1913  // DEEP_COPY REVIEW - HOST-TO-DEVICE
1914  Kokkos::deep_copy (execution_space(), norms, h_norms);
1915  }
1916 
1930  template<typename T>
1931  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1932  normInf (const Kokkos::View<T*, device_type>& norms) const
1933  {
1934  const size_t numNorms = norms.extent (0);
1935  Kokkos::View<mag_type*, device_type> theNorms ("MV::normInf tmp", numNorms);
1936  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1937  this->normInf (theNorms);
1938  // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1939  // and T differ? We would need a test for this, but only the
1940  // Sacado and Stokhos packages are likely to care about this use
1941  // case. This could also come up with Kokkos::complex ->
1942  // std::complex conversion.
1943  // DEEP_COPY REVIEW - NOT TESTED
1944  Kokkos::deep_copy (norms, theNorms);
1945  }
1946 
1951  void normInf (const Teuchos::ArrayView<mag_type>& norms) const;
1952 
1968  template <typename T>
1969  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1970  normInf (const Teuchos::ArrayView<T>& norms) const
1971  {
1972  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1973  const size_type sz = norms.size ();
1974  Teuchos::Array<mag_type> theNorms (sz);
1975  this->norm2 (theNorms);
1976  for (size_type i = 0; i < sz; ++i) {
1977  // If T and mag_type differ, this does an implicit conversion.
1978  norms[i] = theNorms[i];
1979  }
1980  }
1981 
1982 
1987  void meanValue (const Teuchos::ArrayView<impl_scalar_type>& means) const;
1988 
1989  template <typename T>
1990  typename std::enable_if<! std::is_same<impl_scalar_type, T>::value, void>::type
1991  meanValue (const Teuchos::ArrayView<T>& means) const
1992  {
1993  typedef typename Teuchos::Array<T>::size_type size_type;
1994  const size_type numMeans = means.size ();
1995 
1996  Teuchos::Array<impl_scalar_type> theMeans (numMeans);
1997  this->meanValue (theMeans ());
1998  for (size_type k = 0; k < numMeans; ++k) {
1999  means[k] = static_cast<T> (theMeans[k]);
2000  }
2001  }
2002 
2008  void
2009  multiply (Teuchos::ETransp transA,
2010  Teuchos::ETransp transB,
2011  const Scalar& alpha,
2012  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2013  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2014  const Scalar& beta);
2015 
2036  void
2037  elementWiseMultiply (Scalar scalarAB,
2038  const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2039  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2040  Scalar scalarThis);
2042 
2044 
2046  size_t getNumVectors() const;
2047 
2049  size_t getLocalLength() const;
2050 
2053 
2059  size_t getStride() const;
2060 
2064  bool isConstantStride() const;
2065 
2069  bool aliases(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& other) const;
2070 
2072 
2074 
2075 
2077  virtual std::string description() const override;
2078 
2107  virtual void
2108  describe (Teuchos::FancyOStream& out,
2109  const Teuchos::EVerbosityLevel verbLevel =
2110  Teuchos::Describable::verbLevel_default) const override;
2112 
2126  virtual void
2127  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap) override;
2128 
2139  void setCopyOrView (const Teuchos::DataAccess copyOrView) {
2140  TEUCHOS_TEST_FOR_EXCEPTION(
2141  copyOrView == Teuchos::Copy, std::invalid_argument,
2142  "Tpetra::MultiVector::setCopyOrView: The Kokkos refactor version of "
2143  "MultiVector _only_ implements view semantics. You may not call this "
2144  "method with copyOrView = Teuchos::Copy. The only valid argument is "
2145  "Teuchos::View.");
2146  }
2147 
2151  // This method ONLY exists for the circa 2014 "Kokkos refactor"
2152  // effort. It ALWAYS returns Teuchos::View.
2156  Teuchos::DataAccess getCopyOrView () const {
2157  return Teuchos::View;
2158  }
2159 
2174  void
2176 
2179  template <class T>
2180  Teuchos::RCP<MultiVector<T, LocalOrdinal, GlobalOrdinal, Node> >
2181  convert () const;
2182 
2183 
2184  // \brief Checks to see if the local length, number of vectors and size of Scalar type match
2193 
2194  private:
2196  using base_type = DistObject<scalar_type, local_ordinal_type,
2198 
2199  protected:
2200  template <class DS, class DL, class DG, class DN,
2201  class SS, class SL, class SG, class SN>
2202  friend void
2204  const MultiVector<SS, SL, SG, SN>& src);
2205 
2213 
2226  Teuchos::Array<size_t> whichVectors_;
2227 
2228  template<class SC, class LO, class GO, class NT>
2229  friend ::Teuchos::ArrayView<const size_t> getMultiVectorWhichVectors (const ::Tpetra::MultiVector<SC, LO, GO, NT>& X);
2230 
2232 
2234 
2241  std::string
2242  descriptionImpl (const std::string& className) const;
2243 
2250  std::string
2251  localDescribeToString (const Teuchos::EVerbosityLevel vl) const;
2252 
2266  void
2267  describeImpl (Teuchos::FancyOStream& out,
2268  const std::string& className,
2269  const Teuchos::EVerbosityLevel verbLevel =
2270  Teuchos::Describable::verbLevel_default) const;
2271 
2272  // Return true if and only if VectorIndex is a valid column index.
2273  bool vectorIndexOutOfRange (const size_t VectorIndex) const;
2274 
2279  template <class T>
2280  Teuchos::ArrayRCP<T>
2281  getSubArrayRCP (Teuchos::ArrayRCP<T> arr, size_t j) const;
2282 
2284  size_t getOrigNumLocalRows () const;
2285 
2287  size_t getOrigNumLocalCols () const;
2288 
2290 
2292 
2297  using buffer_device_type =
2298  typename DistObject<scalar_type,
2302 
2307  virtual bool
2308  checkSizes (const SrcDistObject& sourceObj) override;
2309 
2311  virtual size_t constantNumberOfPackets () const override;
2312 
2313  // clang-format on
2314  virtual void copyAndPermute(
2315  const SrcDistObject &sourceObj, const size_t numSameIDs,
2316  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2317  &permuteToLIDs,
2318  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2319  &permuteFromLIDs,
2320  const CombineMode CM, const execution_space &space) override;
2321 
2322  virtual void copyAndPermute(
2323  const SrcDistObject &sourceObj, const size_t numSameIDs,
2324  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2325  &permuteToLIDs,
2326  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2327  &permuteFromLIDs,
2328  const CombineMode CM) override;
2329  // clang-format off
2330 
2331  virtual void
2332  packAndPrepare
2333  (const SrcDistObject& sourceObj,
2334  const Kokkos::DualView<
2335  const local_ordinal_type*,
2336  buffer_device_type>& exportLIDs,
2337  Kokkos::DualView<
2339  buffer_device_type>& exports,
2340  Kokkos::DualView<
2341  size_t*,
2342  buffer_device_type> /* numPacketsPerLID */,
2343  size_t& constantNumPackets,
2344  const execution_space &space) override;
2345 
2346  virtual void
2347  packAndPrepare
2348  (const SrcDistObject& sourceObj,
2349  const Kokkos::DualView<
2350  const local_ordinal_type*,
2351  buffer_device_type>& exportLIDs,
2352  Kokkos::DualView<
2354  buffer_device_type>& exports,
2355  Kokkos::DualView<
2356  size_t*,
2357  buffer_device_type> /* numPacketsPerLID */,
2358  size_t& constantNumPackets) override;
2359 
2360  virtual void
2361  unpackAndCombine
2362  (const Kokkos::DualView<
2363  const local_ordinal_type*,
2364  buffer_device_type>& importLIDs,
2365  Kokkos::DualView<
2367  buffer_device_type> imports,
2368  Kokkos::DualView<
2369  size_t*,
2370  buffer_device_type> /* numPacketsPerLID */,
2371  const size_t constantNumPackets,
2372  const CombineMode CM,
2373  const execution_space &space) override;
2374 
2375  virtual void
2376  unpackAndCombine
2377  (const Kokkos::DualView<
2378  const local_ordinal_type*,
2379  buffer_device_type>& importLIDs,
2380  Kokkos::DualView<
2382  buffer_device_type> imports,
2383  Kokkos::DualView<
2384  size_t*,
2385  buffer_device_type> /* numPacketsPerLID */,
2386  const size_t constantNumPackets,
2387  const CombineMode CM) override;
2388 
2389  private:
2390 
2391  // If comm buffers can be aliased to the data view, use this
2392  // implementation.
2393  template<class NO=Node>
2394  typename std::enable_if<std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2395  typename NO::device_type::memory_space>::value, bool>::type
2396  reallocImportsIfNeededImpl (const size_t newSize,
2397  const bool verbose,
2398  const std::string* prefix,
2399  const bool areRemoteLIDsContiguous,
2400  const CombineMode CM);
2401 
2402  // If comm buffers cannot be aliased to the data view, use this
2403  // implementation. (Just calls DistObject::reallocImportsIfNeeded.)
2404  template<class NO=Node>
2405  typename std::enable_if<!std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2406  typename NO::device_type::memory_space>::value, bool>::type
2407  reallocImportsIfNeededImpl (const size_t newSize,
2408  const bool verbose,
2409  const std::string* prefix,
2410  const bool areRemoteLIDsContiguous,
2411  const CombineMode CM);
2412  protected:
2413 
2414  virtual bool
2415  reallocImportsIfNeeded (const size_t newSize,
2416  const bool verbose,
2417  const std::string* prefix,
2418  const bool areRemoteLIDsContiguous=false,
2419  const CombineMode CM=INSERT) override;
2420 
2421 
2422  public:
2423  bool importsAreAliased();
2424 
2425  protected:
2426  Kokkos::DualView<impl_scalar_type*, buffer_device_type> unaliased_imports_;
2427 
2429  }; // class MultiVector
2430 
2431  template<class SC, class LO, class GO, class NT>
2432  Teuchos::ArrayView<const size_t>
2433  getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X)
2434  {
2435  return X.whichVectors_ ();
2436  }
2437 
2438 
2441  template <class ST, class LO, class GO, class NT>
2442  void
2444  const MultiVector<ST, LO, GO, NT>& src)
2445  {
2446  // NOTE (mfh 11 Sep 2014) We can't implement deep_copy with
2447  // shallow-copy operator=, because that would invalidate existing
2448  // views of dst!
2449  dst.assign (src);
2450  }
2451 
2452  // Implementation of the most generic version of MultiVector deep_copy.
2453  template <class DS, class DL, class DG, class DN,
2454  class SS, class SL, class SG, class SN>
2455  void
2457  const MultiVector<SS, SL, SG, SN>& src)
2458  {
2459  using ::Tpetra::getMultiVectorWhichVectors;
2460 
2461  TEUCHOS_TEST_FOR_EXCEPTION(
2462  dst.getGlobalLength () != src.getGlobalLength () ||
2463  dst.getNumVectors () != src.getNumVectors (), std::invalid_argument,
2464  "Tpetra::deep_copy: Global dimensions of the two Tpetra::MultiVector "
2465  "objects do not match. src has dimensions [" << src.getGlobalLength ()
2466  << "," << src.getNumVectors () << "], and dst has dimensions ["
2467  << dst.getGlobalLength () << "," << dst.getNumVectors () << "].");
2468 
2469  // FIXME (mfh 28 Jul 2014) Don't throw; just set a local error flag.
2470  TEUCHOS_TEST_FOR_EXCEPTION(
2471  dst.getLocalLength () != src.getLocalLength (), std::invalid_argument,
2472  "Tpetra::deep_copy: The local row counts of the two Tpetra::MultiVector "
2473  "objects do not match. src has " << src.getLocalLength () << " row(s) "
2474  << " and dst has " << dst.getLocalLength () << " row(s).");
2475 
2476  const bool srcMostUpToDateOnDevice = ! src.need_sync_device ();
2477 
2478  if (src.isConstantStride () && dst.isConstantStride ()) {
2479  if (srcMostUpToDateOnDevice) {
2481  dst.getLocalViewDevice (Access::OverwriteAll),
2482  src.getLocalViewDevice (Access::ReadOnly));
2483  }
2484  else {
2486  dst.getLocalViewDevice (Access::OverwriteAll),
2487  src.getLocalViewHost (Access::ReadOnly));
2488  }
2489  }
2490  else {
2491  auto dstWhichVecs = getMultiVectorWhichVectors (dst);
2492  auto srcWhichVecs = getMultiVectorWhichVectors (src);
2493 
2494  if (srcMostUpToDateOnDevice) {
2495  Details::localDeepCopy (dst.getLocalViewDevice (Access::OverwriteAll),
2496  src.getLocalViewDevice (Access::ReadOnly),
2497  dst.isConstantStride (),
2498  src.isConstantStride (),
2499  dstWhichVecs,
2500  srcWhichVecs);
2501  }
2502  else {
2503  Details::localDeepCopy (dst.getLocalViewDevice (Access::OverwriteAll),
2504  src.getLocalViewHost (Access::ReadOnly),
2505  dst.isConstantStride (),
2506  src.isConstantStride (),
2507  dstWhichVecs,
2508  srcWhichVecs);
2509  }
2510  }
2511  }
2512 } // namespace Tpetra
2513 
2514 
2515 namespace Teuchos {
2516 
2517  // Give Teuchos::TypeNameTraits<Tpetra::MultiVector<...> > a
2518  // human-readable definition.
2519  template<class SC, class LO, class GO, class NT>
2520  class TypeNameTraits<Tpetra::MultiVector<SC, LO, GO, NT> > {
2521  public:
2522  static std::string name () {
2523  return std::string ("Tpetra::MultiVector<") +
2524  TypeNameTraits<SC>::name () + "," +
2525  TypeNameTraits<LO>::name () + "," +
2526  TypeNameTraits<GO>::name () + "," +
2527  TypeNameTraits<NT>::name () + ">";
2528  }
2529 
2530  static std::string
2531  concreteName (const Tpetra::MultiVector<SC, LO, GO, NT>&) {
2532  return name ();
2533  }
2534  };
2535 } // namespace Teuchos
2536 
2537 #endif // TPETRA_MULTIVECTOR_DECL_HPP
typename map_type::global_ordinal_type global_ordinal_type
The type of global indices that this class uses.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createMultiVector(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const size_t numVectors)
Nonmember MultiVector &quot;constructor&quot;: Create a MultiVector from a given Map.
Teuchos::RCP< const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subView(const Teuchos::Range1D &colRng) const
Return a const MultiVector with const views of selected columns.
typename map_type::local_ordinal_type local_ordinal_type
The type of local indices that this class uses.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type sumIntoLocalValue(const LocalOrdinal lclRow, const size_t col, const T &val, const bool atomic=useAtomicUpdatesByDefault)
Like the above sumIntoLocalValue, but only enabled if T differs from impl_scalar_type.
LocalOrdinal local_ordinal_type
The type of local indices.
typename device_type::execution_space execution_space
Type of the (new) Kokkos execution space.
void sumIntoLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &val, const bool atomic=useAtomicUpdatesByDefault)
Update (+=) a value in host memory, using local row index.
GlobalOrdinal global_ordinal_type
The type of global indices.
Teuchos::ArrayRCP< Scalar > get1dViewNonConst()
Nonconst persisting (1-D) view of this multivector&#39;s local values.
void meanValue(const Teuchos::ArrayView< impl_scalar_type > &means) const
Compute mean (average) value of each column.
Teuchos::RCP< const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > offsetView(const Teuchos::RCP< const map_type > &subMap, const size_t offset) const
Return a const view of a subset of rows.
void get2dCopy(const Teuchos::ArrayView< const Teuchos::ArrayView< Scalar > > &ArrayOfPtrs) const
Fill the given array with a copy of this multivector&#39;s local values.
void localDeepCopyConstStride(const DstViewType &dst, const SrcViewType &src)
Implementation of Tpetra::MultiVector deep copy of local data, for when both the source and destinati...
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
size_t getNumVectors() const
Number of columns in the multivector.
size_t getLocalLength() const
Local number of rows on the calling process.
void replaceMap(const Teuchos::RCP< const map_type > &map)
Replace the underlying Map in place.
virtual size_t constantNumberOfPackets() const override
Number of packets to send per LID.
Teuchos::ArrayRCP< Teuchos::ArrayRCP< Scalar > > get2dViewNonConst()
Return non-const persisting pointers to values.
bool isConstantStride() const
Whether this multivector has constant stride between columns.
typename map_type::device_type device_type
This class&#39; preferred Kokkos device type.
std::string localDescribeToString(const Teuchos::EVerbosityLevel vl) const
Print the calling process&#39; verbose describe() information to the returned string. ...
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subCopy(const Teuchos::Range1D &colRng) const
Return a MultiVector with copies of selected columns.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type replaceLocalValue(const LocalOrdinal lclRow, const size_t col, const T &val)
Like the above replaceLocalValue, but only enabled if T differs from impl_scalar_type.
void get1dCopy(const Teuchos::ArrayView< Scalar > &A, const size_t LDA) const
Fill the given array with a copy of this multivector&#39;s local values.
MultiVector< ST, LO, GO, NT > createCopy(const MultiVector< ST, LO, GO, NT > &src)
Return a deep copy of the given MultiVector.
void replaceLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &value)
Replace value in host memory, using local (row) index.
static const bool useAtomicUpdatesByDefault
Whether sumIntoLocalValue and sumIntoGlobalValue should use atomic updates by default.
Teuchos::Array< size_t > whichVectors_
Indices of columns this multivector is viewing.
std::remove_reference< decltype(std::declval< dual_view_type >).template view< TargetDeviceType >))>::type::const_type getLocalView(Access::ReadOnlyStruct s) const
Return a view of the local data on a specific device, with the given access mode. The return type is ...
bool need_sync_device() const
Whether this MultiVector needs synchronization to the device.
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy assigment (shallow copy).
bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
size_t getOrigNumLocalCols() const
&quot;Original&quot; number of columns in the (local) data.
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
size_t global_size_t
Global size_t object.
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
dual_view_type::t_host::const_type getLocalViewHost(Access::ReadOnlyStruct) const
Return a read-only, up-to-date view of this MultiVector&#39;s local data on host. This requires that ther...
Insert new values that don&#39;t currently exist.
void scale(const Scalar &alpha)
Scale in place: this = alpha*this.
void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &beta)
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)
Update: this = beta*this + alpha*A.
wrapped_dual_view_type view_
The Kokkos::DualView containing the MultiVector&#39;s data.
void elementWiseMultiply(Scalar scalarAB, const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Scalar scalarThis)
Multiply a Vector A elementwise by a MultiVector B.
Teuchos::RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(const size_t j)
Return a Vector which is a nonconst view of column j.
void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &src)
Copy the contents of src into *this (deep copy).
std::string descriptionImpl(const std::string &className) const
Implementation of description() for this class, and its subclass Vector.
virtual bool reallocImportsIfNeeded(const size_t newSize, const bool verbose, const std::string *prefix, const bool areRemoteLIDsContiguous=false, const CombineMode CM=INSERT) override
Reallocate imports_ if needed.
void normInf(const Kokkos::View< mag_type *, Kokkos::HostSpace > &norms) const
Compute the infinity-norm of each vector (column), storing the result in a host View.
CombineMode
Rule for combining data in an Import or Export.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const override
Print the object with the given verbosity level to a FancyOStream.
Forward declaration of Tpetra::MultiVector.
void norm2(const Kokkos::View< mag_type *, Kokkos::HostSpace > &norms) const
Compute the two-norm of each vector (column), storing the result in a host View.
Scalar scalar_type
The type of each entry in the MultiVector.
Teuchos::RCP< MultiVector< T, LocalOrdinal, GlobalOrdinal, Node > > convert() const
Return another MultiVector with the same entries, but converted to a different Scalar type T...
void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< dot_type > &dots) const
Compute the dot product of each corresponding pair of vectors (columns) in A and B.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subViewNonConst(const Teuchos::Range1D &colRng)
Return a MultiVector with views of selected columns.
bool need_sync_host() const
Whether this MultiVector needs synchronization to the host.
Abstract base class for objects that can be the source of an Import or Export operation.
Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
bool need_sync() const
Whether this MultiVector needs synchronization to the given space.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, device_type > dual_view_type
Kokkos::DualView specialization used by this class.
virtual bool checkSizes(const SrcDistObject &sourceObj) override
Whether data redistribution between sourceObj and this object is legal.
void swap(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &mv)
Swap contents of mv with contents of *this.
void replaceGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value)
Replace value in host memory, using global row index.
void randomize()
Set all values in the multivector to pseudorandom numbers.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > offsetViewNonConst(const Teuchos::RCP< const map_type > &subMap, const size_t offset)
Return a nonconst view of a subset of rows.
dual_view_type::t_dev::const_type getLocalViewDevice(Access::ReadOnlyStruct) const
Return a read-only, up-to-date view of this MultiVector&#39;s local data on device. This requires that th...
virtual std::string description() const override
A simple one-line description of this object.
Teuchos::ArrayRCP< T > getSubArrayRCP(Teuchos::ArrayRCP< T > arr, size_t j) const
Persisting view of j-th column in the given ArrayRCP.
Forward declaration of Tpetra::Vector.
Teuchos::RCP< const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVector(const size_t j) const
Return a Vector which is a const view of column j.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type replaceGlobalValue(GlobalOrdinal globalRow, size_t col, const T &value)
Like the above replaceGlobalValue, but only enabled if T differs from impl_scalar_type.
typename map_type::node_type node_type
Legacy thing that you should not use any more.
MultiVector()
Default constructor: makes a MultiVector with no rows or columns.
bool aliases(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &other) const
Whether this multivector&#39;s memory might alias other. This is conservative: if either this or other is...
Forward declaration of Tpetra::FEMultiVector.
Teuchos::DataAccess getCopyOrView() const
Get whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type sumIntoGlobalValue(const GlobalOrdinal gblRow, const size_t col, const T &val, const bool atomic=useAtomicUpdatesByDefault)
Like the above sumIntoGlobalValue, but only enabled if T differs from impl_scalar_type.
void setCopyOrView(const Teuchos::DataAccess copyOrView)
Set whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
void norm1(const Kokkos::View< mag_type *, Kokkos::HostSpace > &norms) const
Compute the one-norm of each vector (column), storing the result in a host view.
A parallel distribution of indices over processes.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap) override
Remove processes owning zero rows from the Map and their communicator.
virtual ~MultiVector()=default
Destructor (virtual for memory safety of derived classes).
size_t getStride() const
Stride between columns in the multivector.
typename Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner (&quot;dot&quot;) product result.
void reduce()
Sum values of a locally replicated multivector across all processes.
wrapped_dual_view_type getWrappedDualView() const
Return the wrapped dual view holding this MultiVector&#39;s local data.
void describeImpl(Teuchos::FancyOStream &out, const std::string &className, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Implementation of describe() for this class, and its subclass Vector.
typename DistObject< scalar_type, local_ordinal_type, global_ordinal_type, node_type >::buffer_device_type buffer_device_type
typename Node::device_type device_type
This class&#39; Kokkos::Device specialization.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type putScalar(const T &value)
Set all values in the multivector with the given value.
void sumIntoGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value, const bool atomic=useAtomicUpdatesByDefault)
Update (+=) a value in host memory, using global row index.
Teuchos::ArrayRCP< Teuchos::ArrayRCP< const Scalar > > get2dView() const
Return const persisting pointers to values.
void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,j).
Base class for distributed Tpetra objects that support data redistribution.
void localDeepCopy(const DstViewType &dst, const SrcViewType &src, const bool dstConstStride, const bool srcConstStride, const DstWhichVecsType &dstWhichVecs, const SrcWhichVecsType &srcWhichVecs)
Implementation of Tpetra::MultiVector deep copy of local data.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this)
Node node_type
Legacy typedef that will go away at some point.
Teuchos::ArrayRCP< const Scalar > get1dView() const
Const persisting (1-D) view of this multivector&#39;s local values.
Forward declaration of Tpetra::Map.
size_t getOrigNumLocalRows() const
&quot;Original&quot; number of rows in the (local) data.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra&#39;s behavior.