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 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 // clang-format off
43 #ifndef TPETRA_MULTIVECTOR_DECL_HPP
44 #define TPETRA_MULTIVECTOR_DECL_HPP
45 
48 
50 #include "Tpetra_Vector_fwd.hpp"
52 #include "Tpetra_DistObject.hpp"
53 #include "Tpetra_Map_fwd.hpp"
55 #include "Kokkos_DualView.hpp"
56 #include "Teuchos_BLAS_types.hpp"
57 #include "Teuchos_DataAccess.hpp"
58 #include "Teuchos_Range1D.hpp"
59 #include "Kokkos_ArithTraits.hpp"
60 #include "Kokkos_InnerProductSpaceTraits.hpp"
61 #include "Tpetra_KokkosRefactor_Details_MultiVectorLocalDeepCopy.hpp"
62 #include "Tpetra_Access.hpp"
63 #include "Tpetra_Details_WrappedDualView.hpp"
64 #include <type_traits>
65 
66 #ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
67 #ifndef DOXYGEN_SHOULD_SKIP_THIS
68 namespace Teuchos {
69  template<class OrdinalType, class ScalarType>
70  class SerialDenseMatrix; // forward declaration
71 }
72 #endif // DOXYGEN_SHOULD_SKIP_THIS
73 #endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
74 
75 
76 namespace Tpetra {
77 
78 
99  template <class DS, class DL, class DG, class DN,
100  class SS, class SL, class SG, class SN>
101  void
102  deep_copy (MultiVector<DS, DL, DG, DN>& dst,
103  const MultiVector<SS, SL, SG, SN>& src);
104 
105 #ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
106  template <class ST, class LO, class GO, class NT>
113  void
114  deep_copy (MultiVector<ST, LO, GO, NT>& dst,
115  const Teuchos::SerialDenseMatrix<int, ST>& src);
116 
123  template <class ST, class LO, class GO, class NT>
124  void
125  deep_copy (Teuchos::SerialDenseMatrix<int, ST>& dst,
126  const MultiVector<ST, LO, GO, NT>& src);
127 #endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
128 
136  template <class ST, class LO, class GO, class NT>
137  MultiVector<ST, LO, GO, NT>
138  createCopy (const MultiVector<ST, LO, GO, NT>& src);
139 
149  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
150  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
151  createMultiVector (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map,
152  const size_t numVectors);
153 
154  // WARNING NOT FOR USERS
155  // This means we don't need to make MultiVector a friend of
156  // Vector or of itself (with different template parameters).
157  template<class SC, class LO, class GO, class NT>
158  Teuchos::ArrayView<const size_t>
159  getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X);
160 
161 
381  template <class Scalar,
382  class LocalOrdinal,
383  class GlobalOrdinal,
384  class Node>
385  class MultiVector :
386  public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node>
387  {
388  public:
390 
391 
393  using scalar_type = Scalar;
409  using impl_scalar_type =
410  typename Kokkos::ArithTraits<Scalar>::val_type;
411 
421  using node_type = typename map_type::node_type;
422 
428  using dot_type =
429  typename Kokkos::Details::InnerProductSpaceTraits<impl_scalar_type>::dot_type;
430 
437  using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
438 
443  using execution_space = typename device_type::execution_space;
444 
467  using dual_view_type = Kokkos::DualView<impl_scalar_type**,
468  Kokkos::LayoutLeft,
471 
472  using host_view_type = typename dual_view_type::t_host;
473  using device_view_type = typename dual_view_type::t_dev;
474 
476 
478 
480  MultiVector ();
481 
488  MultiVector (const Teuchos::RCP<const map_type>& map,
489  const size_t numVecs,
490  const bool zeroOut = true);
491 
503  const Teuchos::DataAccess copyOrView);
504 
520  MultiVector (const Teuchos::RCP<const map_type>& map,
521  const Teuchos::ArrayView<const Scalar>& A,
522  const size_t LDA,
523  const size_t NumVectors);
524 
538  MultiVector (const Teuchos::RCP<const map_type>& map,
539  const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar> >&ArrayOfPtrs,
540  const size_t NumVectors);
541 
554  MultiVector (const Teuchos::RCP<const map_type>& map,
555  const dual_view_type& view);
556 
595  MultiVector (const Teuchos::RCP<const map_type>& map,
596  const typename dual_view_type::t_dev& d_view);
597 
620  MultiVector (const Teuchos::RCP<const map_type>& map,
621  const dual_view_type& view,
622  const dual_view_type& origView);
623 
632  MultiVector (const Teuchos::RCP<const map_type>& map,
633  const wrapped_dual_view_type& d_view);
634 
635 
636  protected:
637 
643  const size_t j);
644 
645  public:
646 
664  MultiVector (const Teuchos::RCP<const map_type>& map,
665  const dual_view_type& view,
666  const Teuchos::ArrayView<const size_t>& whichVectors);
667 
685  MultiVector (const Teuchos::RCP<const map_type>& map,
686  const wrapped_dual_view_type& view,
687  const Teuchos::ArrayView<const size_t>& whichVectors);
688 
689 
717  MultiVector (const Teuchos::RCP<const map_type>& map,
718  const dual_view_type& view,
719  const dual_view_type& origView,
720  const Teuchos::ArrayView<const size_t>& whichVectors);
721 
783  const Teuchos::RCP<const map_type>& subMap,
784  const local_ordinal_type rowOffset = 0);
785 
793  const map_type& subMap,
794  const size_t offset = 0);
795 
805 
808 
816 
820 
830  virtual ~MultiVector () = default;
831 
834 
836 
838 
839  protected:
844  static const bool useAtomicUpdatesByDefault =
845 #ifdef KOKKOS_ENABLE_SERIAL
846  ! std::is_same<execution_space, Kokkos::Serial>::value;
847 #else
848  true;
849 #endif // KOKKOS_ENABLE_SERIAL
850 
851  public:
881  void
882  replaceGlobalValue (const GlobalOrdinal gblRow,
883  const size_t col,
884  const impl_scalar_type& value);
885 
918  template<typename T>
919  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
920  replaceGlobalValue (GlobalOrdinal globalRow,
921  size_t col,
922  const T& value)
923  {
924  replaceGlobalValue (globalRow, col, static_cast<impl_scalar_type> (value));
925  }
926 
951  void
952  sumIntoGlobalValue (const GlobalOrdinal gblRow,
953  const size_t col,
954  const impl_scalar_type& value,
955  const bool atomic = useAtomicUpdatesByDefault);
956 
985  template<typename T>
986  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
987  sumIntoGlobalValue (const GlobalOrdinal gblRow,
988  const size_t col,
989  const T& val,
990  const bool atomic = useAtomicUpdatesByDefault)
991  {
992  sumIntoGlobalValue (gblRow, col, static_cast<impl_scalar_type> (val), atomic);
993  }
994 
1024  void
1025  replaceLocalValue (const LocalOrdinal lclRow,
1026  const size_t col,
1027  const impl_scalar_type& value);
1028 
1062  template<typename T>
1063  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1064  replaceLocalValue (const LocalOrdinal lclRow,
1065  const size_t col,
1066  const T& val)
1067  {
1068  replaceLocalValue (lclRow, col, static_cast<impl_scalar_type> (val));
1069  }
1070 
1095  void
1096  sumIntoLocalValue (const LocalOrdinal lclRow,
1097  const size_t col,
1098  const impl_scalar_type& val,
1099  const bool atomic = useAtomicUpdatesByDefault);
1100 
1127  template<typename T>
1128  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1129  sumIntoLocalValue (const LocalOrdinal lclRow,
1130  const size_t col,
1131  const T& val,
1132  const bool atomic = useAtomicUpdatesByDefault)
1133  {
1134  sumIntoLocalValue (lclRow, col, static_cast<impl_scalar_type> (val), atomic);
1135  }
1136 
1138  void putScalar (const Scalar& value);
1139 
1148  template<typename T>
1149  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1150  putScalar (const T& value)
1151  {
1152  putScalar (static_cast<impl_scalar_type> (value));
1153  }
1154 
1167  void randomize();
1168 
1182  void randomize (const Scalar& minVal, const Scalar& maxVal);
1183 
1249  void replaceMap (const Teuchos::RCP<const map_type>& map);
1250 
1257  void reduce();
1258 
1260 
1286 
1287 
1289  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1290  subCopy (const Teuchos::Range1D& colRng) const;
1291 
1293  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1294  subCopy (const Teuchos::ArrayView<const size_t>& cols) const;
1295 
1297  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1298  subView (const Teuchos::Range1D& colRng) const;
1299 
1301  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1302  subView (const Teuchos::ArrayView<const size_t>& cols) const;
1303 
1305  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1306  subViewNonConst (const Teuchos::Range1D& colRng);
1307 
1309  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1310  subViewNonConst (const Teuchos::ArrayView<const size_t>& cols);
1311 
1374  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1375  offsetView (const Teuchos::RCP<const map_type>& subMap,
1376  const size_t offset) const;
1377 
1395  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1396  offsetViewNonConst (const Teuchos::RCP<const map_type>& subMap,
1397  const size_t offset);
1398 
1400  Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1401  getVector (const size_t j) const;
1402 
1404  Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1405  getVectorNonConst (const size_t j);
1406 
1408  Teuchos::ArrayRCP<const Scalar> getData (size_t j) const;
1409 
1411  Teuchos::ArrayRCP<Scalar> getDataNonConst (size_t j);
1412 
1420  void
1421  get1dCopy (const Teuchos::ArrayView<Scalar>& A,
1422  const size_t LDA) const;
1423 
1430  void
1431  get2dCopy (const Teuchos::ArrayView<const Teuchos::ArrayView<Scalar> >& ArrayOfPtrs) const;
1432 
1438  Teuchos::ArrayRCP<const Scalar> get1dView () const;
1439 
1441  Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> > get2dView () const;
1442 
1448  Teuchos::ArrayRCP<Scalar> get1dViewNonConst ();
1449 
1451  Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > get2dViewNonConst ();
1452 
1455  typename dual_view_type::t_host::const_type getLocalViewHost(Access::ReadOnlyStruct) const;
1456 
1459  typename dual_view_type::t_host getLocalViewHost(Access::ReadWriteStruct);
1460 
1463  typename dual_view_type::t_host getLocalViewHost(Access::OverwriteAllStruct);
1464 
1467  typename dual_view_type::t_dev::const_type getLocalViewDevice(Access::ReadOnlyStruct) const;
1468 
1471  typename dual_view_type::t_dev getLocalViewDevice(Access::ReadWriteStruct);
1472 
1475  typename dual_view_type::t_dev getLocalViewDevice(Access::OverwriteAllStruct);
1476 
1481  wrapped_dual_view_type getWrappedDualView() const;
1482 
1484  template<class TargetDeviceType>
1485  bool need_sync () const {
1486  return view_.getDualView().template need_sync<TargetDeviceType> ();
1487  }
1488 
1490  bool need_sync_host () const;
1491 
1493  bool need_sync_device () const;
1494 
1523  template<class TargetDeviceType>
1524  typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type::const_type
1525  getLocalView (Access::ReadOnlyStruct s) const
1526  {
1527  return view_.template getView<TargetDeviceType>(s);
1528  }
1529 
1530 
1531  template<class TargetDeviceType>
1532  typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1533  getLocalView (Access::ReadWriteStruct s)
1534  {
1535  return view_.template getView<TargetDeviceType>(s);
1536  }
1537 
1538  template<class TargetDeviceType>
1539  typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1540  getLocalView (Access::OverwriteAllStruct s)
1541  {
1542  return view_.template getView<TargetDeviceType>(s);
1543  }
1544 
1546 
1548 
1562  void
1563  dot (const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
1564  const Teuchos::ArrayView<dot_type>& dots) const;
1565 
1577  template <typename T>
1578  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1580  const Teuchos::ArrayView<T> &dots) const
1581  {
1582  const size_t sz = static_cast<size_t> (dots.size ());
1583  Teuchos::Array<dot_type> dts (sz);
1584  this->dot (A, dts);
1585  for (size_t i = 0; i < sz; ++i) {
1586  // If T and dot_type differ, this does an implicit conversion.
1587  dots[i] = dts[i];
1588  }
1589  }
1590 
1592  template <typename T>
1593  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1595  std::vector<T>& dots) const
1596  {
1597  const size_t sz = dots.size ();
1598  Teuchos::Array<dot_type> dts (sz);
1599  this->dot (A, dts);
1600  for (size_t i = 0; i < sz; ++i) {
1601  // If T and dot_type differ, this does an implicit conversion.
1602  dots[i] = dts[i];
1603  }
1604  }
1605 
1623  void
1625  const Kokkos::View<dot_type*, Kokkos::HostSpace>& norms) const;
1626 
1627  template<class ViewType>
1628  void
1629  dot (typename std::enable_if<std::is_same<typename ViewType::value_type,dot_type>::value &&
1630  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value,
1632  const ViewType& dots) const {
1633  const Kokkos::View<dot_type*, Kokkos::HostSpace> h_dots("Tpetra::Dots",dots.extent(0));
1634  this->dot (A, h_dots);
1635  // DEEP_COPY REVIEW - NOT TESTED
1636  Kokkos::deep_copy(dots,h_dots);
1637  }
1638 
1651  template <typename T>
1652  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1654  const Kokkos::View<T*, device_type>& dots) const
1655  {
1656  const size_t numDots = dots.extent (0);
1657  Kokkos::View<dot_type*, device_type> dts ("MV::dot tmp", numDots);
1658  // Call overload that takes a Kokkos::View<dot_type*, device_type>.
1659  this->dot (A, dts);
1660  // FIXME (mfh 14 Jul 2014) Does this actually work if dot_type
1661  // and T differ? We would need a test for this, but only the
1662  // Sacado and Stokhos packages are likely to care about this use
1663  // case. It could also come up for Kokkos::complex ->
1664  // std::complex conversions, but those two implementations
1665  // should generally be bitwise compatible.
1666  // CT: no this can't possible work .....
1667  // DEEP_COPY REVIEW - NOT TESTED
1668  Kokkos::deep_copy (dots, dts);
1669  }
1670 
1673 
1676 
1684  void scale (const Scalar& alpha);
1685 
1694  void scale (const Teuchos::ArrayView<const Scalar>& alpha);
1695 
1704  void scale (const Kokkos::View<const impl_scalar_type*, device_type>& alpha);
1705 
1714  void
1715  scale (const Scalar& alpha,
1717 
1724  void
1725  update (const Scalar& alpha,
1727  const Scalar& beta);
1728 
1735  void
1736  update (const Scalar& alpha,
1738  const Scalar& beta,
1740  const Scalar& gamma);
1741 
1753  void
1754  norm1 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1755 
1756  template<class ViewType>
1757  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1758  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1759  norm1 (const ViewType& norms) const {
1760  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1761  // this method to be templated. (It only exists in case
1762  // HostSpace = device_type::memory_space.)
1763  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1764  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1765  this->norm1 (h_norms);
1766  // DEEP_COPY REVIEW - HOST-TO-DEVICE
1767  Kokkos::deep_copy (execution_space(), norms, h_norms);
1768  }
1769 
1785  template <typename T>
1786  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1787  norm1 (const Kokkos::View<T*, device_type>& norms) const
1788  {
1789  const size_t numNorms = norms.extent (0);
1790  Kokkos::View<mag_type*, device_type> tmpNorms ("MV::norm1 tmp", numNorms);
1791  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1792  this->norm1 (tmpNorms);
1793  // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1794  // and T differ? We would need a test for this, but only the
1795  // Sacado and Stokhos packages are likely to care about this use
1796  // case. It could also come up with Kokkos::complex ->
1797  // std::complex conversion.
1798  // DEEP_COPY REVIEW - NOT TESTED
1799  Kokkos::deep_copy (norms, tmpNorms);
1800  }
1801 
1805  void norm1 (const Teuchos::ArrayView<mag_type>& norms) const;
1806 
1821  template <typename T>
1822  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1823  norm1 (const Teuchos::ArrayView<T>& norms) const
1824  {
1825  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1826  const size_type sz = norms.size ();
1827  Teuchos::Array<mag_type> theNorms (sz);
1828  this->norm1 (theNorms);
1829  for (size_type i = 0; i < sz; ++i) {
1830  // If T and mag_type differ, this does an implicit conversion.
1831  norms[i] = theNorms[i];
1832  }
1833  }
1834 
1847  void
1848  norm2 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1849 
1850  template<class ViewType>
1851  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1852  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1853  norm2 (const ViewType& norms) const {
1854  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1855  // this method to be templated. (It only exists in case
1856  // HostSpace = device_type::memory_space.)
1857  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1858  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1859  this->norm2 (h_norms);
1860  // DEEP_COPY REVIEW - NOT TESTED
1861  Kokkos::deep_copy (norms, h_norms);
1862  }
1863 
1877  template<typename T>
1878  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1879  norm2 (const Kokkos::View<T*, device_type>& norms) const
1880  {
1881  const size_t numNorms = norms.extent (0);
1882  Kokkos::View<mag_type*, device_type> theNorms ("MV::norm2 tmp", numNorms);
1883  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1884  this->norm2 (theNorms);
1885  // FIXME (mfh 14 Jul 2014) Does this actually work if mag_type
1886  // and T differ? We would need a test for this, but only the
1887  // Sacado and Stokhos packages are likely to care about this use
1888  // case. This could also come up with Kokkos::complex ->
1889  // std::complex conversion.
1890  // DEEP_COPY REVIEW - NOT TESTED
1891  Kokkos::deep_copy (norms, theNorms);
1892  }
1893 
1897  void norm2 (const Teuchos::ArrayView<mag_type>& norms) const;
1898 
1913  template <typename T>
1914  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1915  norm2 (const Teuchos::ArrayView<T>& norms) const
1916  {
1917  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1918  const size_type sz = norms.size ();
1919  Teuchos::Array<mag_type> theNorms (sz);
1920  this->norm2 (theNorms);
1921  for (size_type i = 0; i < sz; ++i) {
1922  // If T and mag_type differ, this does an implicit conversion.
1923  norms[i] = theNorms[i];
1924  }
1925  }
1926 
1933  void normInf (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1934 
1935  template<class ViewType>
1936  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1937  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1938  normInf (const ViewType& norms) const {
1939  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1940  // this method to be templated. (It only exists in case
1941  // HostSpace = device_type::memory_space.)
1942  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1943  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1944  this->normInf (h_norms);
1945  // DEEP_COPY REVIEW - HOST-TO-DEVICE
1946  Kokkos::deep_copy (execution_space(), norms, h_norms);
1947  }
1948 
1962  template<typename T>
1963  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1964  normInf (const Kokkos::View<T*, device_type>& norms) const
1965  {
1966  const size_t numNorms = norms.extent (0);
1967  Kokkos::View<mag_type*, device_type> theNorms ("MV::normInf tmp", numNorms);
1968  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1969  this->normInf (theNorms);
1970  // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1971  // and T differ? We would need a test for this, but only the
1972  // Sacado and Stokhos packages are likely to care about this use
1973  // case. This could also come up with Kokkos::complex ->
1974  // std::complex conversion.
1975  // DEEP_COPY REVIEW - NOT TESTED
1976  Kokkos::deep_copy (norms, theNorms);
1977  }
1978 
1983  void normInf (const Teuchos::ArrayView<mag_type>& norms) const;
1984 
2000  template <typename T>
2001  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
2002  normInf (const Teuchos::ArrayView<T>& norms) const
2003  {
2004  typedef typename Teuchos::ArrayView<T>::size_type size_type;
2005  const size_type sz = norms.size ();
2006  Teuchos::Array<mag_type> theNorms (sz);
2007  this->norm2 (theNorms);
2008  for (size_type i = 0; i < sz; ++i) {
2009  // If T and mag_type differ, this does an implicit conversion.
2010  norms[i] = theNorms[i];
2011  }
2012  }
2013 
2014 
2019  void meanValue (const Teuchos::ArrayView<impl_scalar_type>& means) const;
2020 
2021  template <typename T>
2022  typename std::enable_if<! std::is_same<impl_scalar_type, T>::value, void>::type
2023  meanValue (const Teuchos::ArrayView<T>& means) const
2024  {
2025  typedef typename Teuchos::Array<T>::size_type size_type;
2026  const size_type numMeans = means.size ();
2027 
2028  Teuchos::Array<impl_scalar_type> theMeans (numMeans);
2029  this->meanValue (theMeans ());
2030  for (size_type k = 0; k < numMeans; ++k) {
2031  means[k] = static_cast<T> (theMeans[k]);
2032  }
2033  }
2034 
2040  void
2041  multiply (Teuchos::ETransp transA,
2042  Teuchos::ETransp transB,
2043  const Scalar& alpha,
2044  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2045  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2046  const Scalar& beta);
2047 
2068  void
2069  elementWiseMultiply (Scalar scalarAB,
2070  const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2071  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2072  Scalar scalarThis);
2074 
2076 
2078  size_t getNumVectors() const;
2079 
2081  size_t getLocalLength() const;
2082 
2085 
2091  size_t getStride() const;
2092 
2096  bool isConstantStride() const;
2097 
2101  bool aliases(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& other) const;
2102 
2104 
2106 
2107 
2109  virtual std::string description() const override;
2110 
2139  virtual void
2140  describe (Teuchos::FancyOStream& out,
2141  const Teuchos::EVerbosityLevel verbLevel =
2142  Teuchos::Describable::verbLevel_default) const override;
2144 
2158  virtual void
2159  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap) override;
2160 
2171  void setCopyOrView (const Teuchos::DataAccess copyOrView) {
2172  TEUCHOS_TEST_FOR_EXCEPTION(
2173  copyOrView == Teuchos::Copy, std::invalid_argument,
2174  "Tpetra::MultiVector::setCopyOrView: The Kokkos refactor version of "
2175  "MultiVector _only_ implements view semantics. You may not call this "
2176  "method with copyOrView = Teuchos::Copy. The only valid argument is "
2177  "Teuchos::View.");
2178  }
2179 
2183  // This method ONLY exists for the circa 2014 "Kokkos refactor"
2184  // effort. It ALWAYS returns Teuchos::View.
2188  Teuchos::DataAccess getCopyOrView () const {
2189  return Teuchos::View;
2190  }
2191 
2206  void
2208 
2211  template <class T>
2212  Teuchos::RCP<MultiVector<T, LocalOrdinal, GlobalOrdinal, Node> >
2213  convert () const;
2214 
2215 
2216  // \brief Checks to see if the local length, number of vectors and size of Scalar type match
2225 
2226  private:
2228  using base_type = DistObject<scalar_type, local_ordinal_type,
2230 
2231  protected:
2232  template <class DS, class DL, class DG, class DN,
2233  class SS, class SL, class SG, class SN>
2234  friend void
2236  const MultiVector<SS, SL, SG, SN>& src);
2237 
2245 
2258  Teuchos::Array<size_t> whichVectors_;
2259 
2260  template<class SC, class LO, class GO, class NT>
2261  friend ::Teuchos::ArrayView<const size_t> getMultiVectorWhichVectors (const ::Tpetra::MultiVector<SC, LO, GO, NT>& X);
2262 
2264 
2266 
2273  std::string
2274  descriptionImpl (const std::string& className) const;
2275 
2282  std::string
2283  localDescribeToString (const Teuchos::EVerbosityLevel vl) const;
2284 
2298  void
2299  describeImpl (Teuchos::FancyOStream& out,
2300  const std::string& className,
2301  const Teuchos::EVerbosityLevel verbLevel =
2302  Teuchos::Describable::verbLevel_default) const;
2303 
2304  // Return true if and only if VectorIndex is a valid column index.
2305  bool vectorIndexOutOfRange (const size_t VectorIndex) const;
2306 
2311  template <class T>
2312  Teuchos::ArrayRCP<T>
2313  getSubArrayRCP (Teuchos::ArrayRCP<T> arr, size_t j) const;
2314 
2316  size_t getOrigNumLocalRows () const;
2317 
2319  size_t getOrigNumLocalCols () const;
2320 
2322 
2324 
2329  using buffer_device_type =
2330  typename DistObject<scalar_type,
2334 
2339  virtual bool
2340  checkSizes (const SrcDistObject& sourceObj) override;
2341 
2343  virtual size_t constantNumberOfPackets () const override;
2344 
2345  // clang-format on
2346  virtual void copyAndPermute(
2347  const SrcDistObject &sourceObj, const size_t numSameIDs,
2348  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2349  &permuteToLIDs,
2350  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2351  &permuteFromLIDs,
2352  const CombineMode CM, const execution_space &space) override;
2353 
2354  virtual void copyAndPermute(
2355  const SrcDistObject &sourceObj, const size_t numSameIDs,
2356  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2357  &permuteToLIDs,
2358  const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2359  &permuteFromLIDs,
2360  const CombineMode CM) override;
2361  // clang-format off
2362 
2363  virtual void
2364  packAndPrepare
2365  (const SrcDistObject& sourceObj,
2366  const Kokkos::DualView<
2367  const local_ordinal_type*,
2368  buffer_device_type>& exportLIDs,
2369  Kokkos::DualView<
2371  buffer_device_type>& exports,
2372  Kokkos::DualView<
2373  size_t*,
2374  buffer_device_type> /* numPacketsPerLID */,
2375  size_t& constantNumPackets,
2376  const execution_space &space) override;
2377 
2378  virtual void
2379  packAndPrepare
2380  (const SrcDistObject& sourceObj,
2381  const Kokkos::DualView<
2382  const local_ordinal_type*,
2383  buffer_device_type>& exportLIDs,
2384  Kokkos::DualView<
2386  buffer_device_type>& exports,
2387  Kokkos::DualView<
2388  size_t*,
2389  buffer_device_type> /* numPacketsPerLID */,
2390  size_t& constantNumPackets) override;
2391 
2392  virtual void
2393  unpackAndCombine
2394  (const Kokkos::DualView<
2395  const local_ordinal_type*,
2396  buffer_device_type>& importLIDs,
2397  Kokkos::DualView<
2399  buffer_device_type> imports,
2400  Kokkos::DualView<
2401  size_t*,
2402  buffer_device_type> /* numPacketsPerLID */,
2403  const size_t constantNumPackets,
2404  const CombineMode CM,
2405  const execution_space &space) override;
2406 
2407  virtual void
2408  unpackAndCombine
2409  (const Kokkos::DualView<
2410  const local_ordinal_type*,
2411  buffer_device_type>& importLIDs,
2412  Kokkos::DualView<
2414  buffer_device_type> imports,
2415  Kokkos::DualView<
2416  size_t*,
2417  buffer_device_type> /* numPacketsPerLID */,
2418  const size_t constantNumPackets,
2419  const CombineMode CM) override;
2420 
2421  private:
2422 
2423  // If comm buffers can be aliased to the data view, use this
2424  // implementation.
2425  template<class NO=Node>
2426  typename std::enable_if<std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2427  typename NO::device_type::memory_space>::value, bool>::type
2428  reallocImportsIfNeededImpl (const size_t newSize,
2429  const bool verbose,
2430  const std::string* prefix,
2431  const bool areRemoteLIDsContiguous,
2432  const CombineMode CM);
2433 
2434  // If comm buffers cannot be aliased to the data view, use this
2435  // implementation. (Just calls DistObject::reallocImportsIfNeeded.)
2436  template<class NO=Node>
2437  typename std::enable_if<!std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2438  typename NO::device_type::memory_space>::value, bool>::type
2439  reallocImportsIfNeededImpl (const size_t newSize,
2440  const bool verbose,
2441  const std::string* prefix,
2442  const bool areRemoteLIDsContiguous,
2443  const CombineMode CM);
2444  protected:
2445 
2446  virtual bool
2447  reallocImportsIfNeeded (const size_t newSize,
2448  const bool verbose,
2449  const std::string* prefix,
2450  const bool areRemoteLIDsContiguous=false,
2451  const CombineMode CM=INSERT) override;
2452 
2453 
2454  public:
2455  bool importsAreAliased();
2456 
2457  protected:
2458  Kokkos::DualView<impl_scalar_type*, buffer_device_type> unaliased_imports_;
2459 
2461  }; // class MultiVector
2462 
2463  template<class SC, class LO, class GO, class NT>
2464  Teuchos::ArrayView<const size_t>
2465  getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X)
2466  {
2467  return X.whichVectors_ ();
2468  }
2469 
2470 
2473  template <class ST, class LO, class GO, class NT>
2474  void
2476  const MultiVector<ST, LO, GO, NT>& src)
2477  {
2478  // NOTE (mfh 11 Sep 2014) We can't implement deep_copy with
2479  // shallow-copy operator=, because that would invalidate existing
2480  // views of dst!
2481  dst.assign (src);
2482  }
2483 
2484  // Implementation of the most generic version of MultiVector deep_copy.
2485  template <class DS, class DL, class DG, class DN,
2486  class SS, class SL, class SG, class SN>
2487  void
2489  const MultiVector<SS, SL, SG, SN>& src)
2490  {
2491  using ::Tpetra::getMultiVectorWhichVectors;
2492 
2493  TEUCHOS_TEST_FOR_EXCEPTION(
2494  dst.getGlobalLength () != src.getGlobalLength () ||
2495  dst.getNumVectors () != src.getNumVectors (), std::invalid_argument,
2496  "Tpetra::deep_copy: Global dimensions of the two Tpetra::MultiVector "
2497  "objects do not match. src has dimensions [" << src.getGlobalLength ()
2498  << "," << src.getNumVectors () << "], and dst has dimensions ["
2499  << dst.getGlobalLength () << "," << dst.getNumVectors () << "].");
2500 
2501  // FIXME (mfh 28 Jul 2014) Don't throw; just set a local error flag.
2502  TEUCHOS_TEST_FOR_EXCEPTION(
2503  dst.getLocalLength () != src.getLocalLength (), std::invalid_argument,
2504  "Tpetra::deep_copy: The local row counts of the two Tpetra::MultiVector "
2505  "objects do not match. src has " << src.getLocalLength () << " row(s) "
2506  << " and dst has " << dst.getLocalLength () << " row(s).");
2507 
2508  const bool srcMostUpToDateOnDevice = ! src.need_sync_device ();
2509 
2510  if (src.isConstantStride () && dst.isConstantStride ()) {
2511  if (srcMostUpToDateOnDevice) {
2513  dst.getLocalViewDevice (Access::OverwriteAll),
2514  src.getLocalViewDevice (Access::ReadOnly));
2515  }
2516  else {
2518  dst.getLocalViewDevice (Access::OverwriteAll),
2519  src.getLocalViewHost (Access::ReadOnly));
2520  }
2521  }
2522  else {
2523  auto dstWhichVecs = getMultiVectorWhichVectors (dst);
2524  auto srcWhichVecs = getMultiVectorWhichVectors (src);
2525 
2526  if (srcMostUpToDateOnDevice) {
2527  Details::localDeepCopy (dst.getLocalViewDevice (Access::OverwriteAll),
2528  src.getLocalViewDevice (Access::ReadOnly),
2529  dst.isConstantStride (),
2530  src.isConstantStride (),
2531  dstWhichVecs,
2532  srcWhichVecs);
2533  }
2534  else {
2535  Details::localDeepCopy (dst.getLocalViewDevice (Access::OverwriteAll),
2536  src.getLocalViewHost (Access::ReadOnly),
2537  dst.isConstantStride (),
2538  src.isConstantStride (),
2539  dstWhichVecs,
2540  srcWhichVecs);
2541  }
2542  }
2543  }
2544 } // namespace Tpetra
2545 
2546 
2547 namespace Teuchos {
2548 
2549  // Give Teuchos::TypeNameTraits<Tpetra::MultiVector<...> > a
2550  // human-readable definition.
2551  template<class SC, class LO, class GO, class NT>
2552  class TypeNameTraits<Tpetra::MultiVector<SC, LO, GO, NT> > {
2553  public:
2554  static std::string name () {
2555  return std::string ("Tpetra::MultiVector<") +
2556  TypeNameTraits<SC>::name () + "," +
2557  TypeNameTraits<LO>::name () + "," +
2558  TypeNameTraits<GO>::name () + "," +
2559  TypeNameTraits<NT>::name () + ">";
2560  }
2561 
2562  static std::string
2563  concreteName (const Tpetra::MultiVector<SC, LO, GO, NT>&) {
2564  return name ();
2565  }
2566  };
2567 } // namespace Teuchos
2568 
2569 #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.