Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 #ifndef TPETRA_MULTIVECTOR_DECL_HPP
43 #define TPETRA_MULTIVECTOR_DECL_HPP
44 
53 
55 #include "Tpetra_Vector_fwd.hpp"
57 #include "Tpetra_DistObject.hpp"
58 #include "Tpetra_Map_fwd.hpp"
59 #include "Kokkos_DualView.hpp"
60 #include "Teuchos_BLAS_types.hpp"
61 #include "Teuchos_DataAccess.hpp"
62 #include "Teuchos_Range1D.hpp"
63 #include "Kokkos_ArithTraits.hpp"
64 #include "Kokkos_InnerProductSpaceTraits.hpp"
65 #include "Tpetra_KokkosRefactor_Details_MultiVectorLocalDeepCopy.hpp"
66 #include <type_traits>
67 
68 #ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
69 #ifndef DOXYGEN_SHOULD_SKIP_THIS
70 namespace Teuchos {
71  template<class OrdinalType, class ScalarType>
72  class SerialDenseMatrix; // forward declaration
73 }
74 #endif // DOXYGEN_SHOULD_SKIP_THIS
75 #endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
76 
77 namespace Tpetra {
78 
79 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
80  namespace Details {
106  template<class DstMultiVectorType, class SrcMultiVectorType>
107  struct MultiVectorCloner {
108  typedef DstMultiVectorType dst_mv_type;
109  typedef SrcMultiVectorType src_mv_type;
110 
111  static Teuchos::RCP<dst_mv_type>
112  clone (const src_mv_type& X,
113  const Teuchos::RCP<typename dst_mv_type::node_type>& node2);
114  };
115  } // namespace Details
116 #endif // TPETRA_ENABLE_DEPRECATED_CODE
117 
138  template <class DS, class DL, class DG, class DN,
139  class SS, class SL, class SG, class SN>
140  void
141  deep_copy (MultiVector<DS, DL, DG, DN>& dst,
142  const MultiVector<SS, SL, SG, SN>& src);
143 
144 #ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
145  template <class ST, class LO, class GO, class NT>
152  void
153  deep_copy (MultiVector<ST, LO, GO, NT>& dst,
154  const Teuchos::SerialDenseMatrix<int, ST>& src);
155 
162  template <class ST, class LO, class GO, class NT>
163  void
164  deep_copy (Teuchos::SerialDenseMatrix<int, ST>& dst,
165  const MultiVector<ST, LO, GO, NT>& src);
166 #endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
167 
175  template <class ST, class LO, class GO, class NT>
176  MultiVector<ST, LO, GO, NT>
177  createCopy (const MultiVector<ST, LO, GO, NT>& src);
178 
188  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
189  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
190  createMultiVector (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map,
191  const size_t numVectors);
192 
193  // WARNING NOT FOR USERS
194  // This means we don't need to make MultiVector a friend of
195  // Vector or of itself (with different template parameters).
196  template<class SC, class LO, class GO, class NT>
197  Teuchos::ArrayView<const size_t>
198  getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X);
199 
419  template <class Scalar,
420  class LocalOrdinal,
421  class GlobalOrdinal,
422  class Node>
423  class MultiVector :
424  public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node>
425  {
426  public:
428 
429 
431  using scalar_type = Scalar;
447  using impl_scalar_type =
448  typename Kokkos::Details::ArithTraits<Scalar>::val_type;
449 
459  using node_type = typename map_type::node_type;
460 
466  using dot_type =
467  typename Kokkos::Details::InnerProductSpaceTraits<impl_scalar_type>::dot_type;
468 
475  using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
476 
481  using execution_space = typename device_type::execution_space;
482 
505  using dual_view_type = Kokkos::DualView<impl_scalar_type**,
506  Kokkos::LayoutLeft,
508 
510 
512 
514  MultiVector ();
515 
522  MultiVector (const Teuchos::RCP<const map_type>& map,
523  const size_t numVecs,
524  const bool zeroOut = true);
525 
537  const Teuchos::DataAccess copyOrView);
538 
554  MultiVector (const Teuchos::RCP<const map_type>& map,
555  const Teuchos::ArrayView<const Scalar>& A,
556  const size_t LDA,
557  const size_t NumVectors);
558 
572  MultiVector (const Teuchos::RCP<const map_type>& map,
573  const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar> >&ArrayOfPtrs,
574  const size_t NumVectors);
575 
588  MultiVector (const Teuchos::RCP<const map_type>& map,
589  const dual_view_type& view);
590 
629  MultiVector (const Teuchos::RCP<const map_type>& map,
630  const typename dual_view_type::t_dev& d_view);
631 
654  MultiVector (const Teuchos::RCP<const map_type>& map,
655  const dual_view_type& view,
656  const dual_view_type& origView);
657 
658  protected:
659 
665  const size_t j);
666 
667  public:
668 
686  MultiVector (const Teuchos::RCP<const map_type>& map,
687  const dual_view_type& view,
688  const Teuchos::ArrayView<const size_t>& whichVectors);
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 
840 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
841  template <class Node2>
842  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node2> > TPETRA_DEPRECATED
843  clone (const Teuchos::RCP<Node2>& node2) const;
844 #endif
845 
848 
850 
852 
853  protected:
858  static const bool useAtomicUpdatesByDefault =
859 #ifdef KOKKOS_ENABLE_SERIAL
860  ! std::is_same<execution_space, Kokkos::Serial>::value;
861 #else
862  true;
863 #endif // KOKKOS_ENABLE_SERIAL
864 
865  public:
894  void
895  replaceGlobalValue (const GlobalOrdinal gblRow,
896  const size_t col,
897  const impl_scalar_type& value) const;
898 
931  template<typename T>
932  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
933  replaceGlobalValue (GlobalOrdinal globalRow,
934  size_t col,
935  const T& value) const
936  {
937  replaceGlobalValue (globalRow, col, static_cast<impl_scalar_type> (value));
938  }
939 
963  void
964  sumIntoGlobalValue (const GlobalOrdinal gblRow,
965  const size_t col,
966  const impl_scalar_type& value,
967  const bool atomic = useAtomicUpdatesByDefault) const;
968 
996  template<typename T>
997  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
998  sumIntoGlobalValue (const GlobalOrdinal gblRow,
999  const size_t col,
1000  const T& val,
1001  const bool atomic = useAtomicUpdatesByDefault) const
1002  {
1003  sumIntoGlobalValue (gblRow, col, static_cast<impl_scalar_type> (val), atomic);
1004  }
1005 
1034  void
1035  replaceLocalValue (const LocalOrdinal lclRow,
1036  const size_t col,
1037  const impl_scalar_type& value) const;
1038 
1071  template<typename T>
1072  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1073  replaceLocalValue (const LocalOrdinal lclRow,
1074  const size_t col,
1075  const T& val) const
1076  {
1077  replaceLocalValue (lclRow, col, static_cast<impl_scalar_type> (val));
1078  }
1079 
1103  void
1104  sumIntoLocalValue (const LocalOrdinal lclRow,
1105  const size_t col,
1106  const impl_scalar_type& val,
1107  const bool atomic = useAtomicUpdatesByDefault) const;
1108 
1134  template<typename T>
1135  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1136  sumIntoLocalValue (const LocalOrdinal lclRow,
1137  const size_t col,
1138  const T& val,
1139  const bool atomic = useAtomicUpdatesByDefault) const
1140  {
1141  sumIntoLocalValue (lclRow, col, static_cast<impl_scalar_type> (val), atomic);
1142  }
1143 
1145  void putScalar (const Scalar& value);
1146 
1155  template<typename T>
1156  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1157  putScalar (const T& value)
1158  {
1159  putScalar (static_cast<impl_scalar_type> (value));
1160  }
1161 
1174  void randomize();
1175 
1189  void randomize (const Scalar& minVal, const Scalar& maxVal);
1190 
1256  void replaceMap (const Teuchos::RCP<const map_type>& map);
1257 
1264  void reduce();
1265 
1267 
1293 
1294 
1296  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1297  subCopy (const Teuchos::Range1D& colRng) const;
1298 
1300  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1301  subCopy (const Teuchos::ArrayView<const size_t>& cols) const;
1302 
1304  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1305  subView (const Teuchos::Range1D& colRng) const;
1306 
1308  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1309  subView (const Teuchos::ArrayView<const size_t>& cols) const;
1310 
1312  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1313  subViewNonConst (const Teuchos::Range1D& colRng);
1314 
1316  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1317  subViewNonConst (const Teuchos::ArrayView<const size_t>& cols);
1318 
1381  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1382  offsetView (const Teuchos::RCP<const map_type>& subMap,
1383  const size_t offset) const;
1384 
1402  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1403  offsetViewNonConst (const Teuchos::RCP<const map_type>& subMap,
1404  const size_t offset);
1405 
1407  Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1408  getVector (const size_t j) const;
1409 
1411  Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1412  getVectorNonConst (const size_t j);
1413 
1415  Teuchos::ArrayRCP<const Scalar> getData (size_t j) const;
1416 
1418  Teuchos::ArrayRCP<Scalar> getDataNonConst (size_t j);
1419 
1427  void
1428  get1dCopy (const Teuchos::ArrayView<Scalar>& A,
1429  const size_t LDA) const;
1430 
1437  void
1438  get2dCopy (const Teuchos::ArrayView<const Teuchos::ArrayView<Scalar> >& ArrayOfPtrs) const;
1439 
1445  Teuchos::ArrayRCP<const Scalar> get1dView () const;
1446 
1448  Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> > get2dView () const;
1449 
1455  Teuchos::ArrayRCP<Scalar> get1dViewNonConst ();
1456 
1458  Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > get2dViewNonConst ();
1459 
1460 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
1461  dual_view_type TPETRA_DEPRECATED getDualView () const;
1482 #endif // TPETRA_ENABLE_DEPRECATED_CODE
1483 
1485  void clear_sync_state ();
1486 
1505  template<class TargetDeviceType>
1506  void sync () {
1507  view_.template sync<TargetDeviceType> ();
1508  }
1509 
1511  void sync_host ();
1512 
1514  void sync_device ();
1515 
1517  template<class TargetDeviceType>
1518  bool need_sync () const {
1519  return view_.template need_sync<TargetDeviceType> ();
1520  }
1521 
1523  bool need_sync_host () const;
1524 
1526  bool need_sync_device () const;
1527 
1533  template<class TargetDeviceType>
1534  void modify () {
1535  view_.template modify<TargetDeviceType> ();
1536  }
1537 
1539  void modify_device ();
1540 
1542  void modify_host ();
1543 
1575  template<class TargetDeviceType>
1576  typename Kokkos::Impl::if_c<
1577  std::is_same<
1578  typename device_type::memory_space,
1579  typename TargetDeviceType::memory_space>::value,
1580  typename dual_view_type::t_dev,
1581  typename dual_view_type::t_host>::type
1582  getLocalView () const {
1583  return view_.template view<TargetDeviceType> ();
1584  }
1585 
1587  typename dual_view_type::t_host getLocalViewHost () const;
1588 
1590  typename dual_view_type::t_dev getLocalViewDevice () const;
1591 
1593 
1595 
1609  void
1611  const Teuchos::ArrayView<dot_type>& dots) const;
1612 
1624  template <typename T>
1625  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1627  const Teuchos::ArrayView<T> &dots) const
1628  {
1629  const size_t sz = static_cast<size_t> (dots.size ());
1630  Teuchos::Array<dot_type> dts (sz);
1631  this->dot (A, dts);
1632  for (size_t i = 0; i < sz; ++i) {
1633  // If T and dot_type differ, this does an implicit conversion.
1634  dots[i] = dts[i];
1635  }
1636  }
1637 
1639  template <typename T>
1640  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1642  std::vector<T>& dots) const
1643  {
1644  const size_t sz = dots.size ();
1645  Teuchos::Array<dot_type> dts (sz);
1646  this->dot (A, dts);
1647  for (size_t i = 0; i < sz; ++i) {
1648  // If T and dot_type differ, this does an implicit conversion.
1649  dots[i] = dts[i];
1650  }
1651  }
1652 
1670  void
1672  const Kokkos::View<dot_type*, Kokkos::HostSpace>& norms) const;
1673 
1674  template<class ViewType>
1675  void
1676  dot (typename std::enable_if<std::is_same<typename ViewType::value_type,dot_type>::value &&
1677  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value,
1679  const ViewType& dots) const {
1680  const Kokkos::View<dot_type*, Kokkos::HostSpace> h_dots("Tpetra::Dots",dots.extent(0));
1681  this->dot (A, h_dots);
1682  Kokkos::deep_copy(dots,h_dots);
1683  }
1684 
1697  template <typename T>
1698  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1700  const Kokkos::View<T*, device_type>& dots) const
1701  {
1702  const size_t numDots = dots.extent (0);
1703  Kokkos::View<dot_type*, device_type> dts ("MV::dot tmp", numDots);
1704  // Call overload that takes a Kokkos::View<dot_type*, device_type>.
1705  this->dot (A, dts);
1706  // FIXME (mfh 14 Jul 2014) Does this actually work if dot_type
1707  // and T differ? We would need a test for this, but only the
1708  // Sacado and Stokhos packages are likely to care about this use
1709  // case. It could also come up for Kokkos::complex ->
1710  // std::complex conversions, but those two implementations
1711  // should generally be bitwise compatible.
1712  // CT: no this can't possible work .....
1713  Kokkos::deep_copy (dots, dts);
1714  }
1715 
1718 
1721 
1729  void scale (const Scalar& alpha);
1730 
1739  void scale (const Teuchos::ArrayView<const Scalar>& alpha);
1740 
1749  void scale (const Kokkos::View<const impl_scalar_type*, device_type>& alpha);
1750 
1759  void
1760  scale (const Scalar& alpha,
1762 
1769  void
1770  update (const Scalar& alpha,
1772  const Scalar& beta);
1773 
1780  void
1781  update (const Scalar& alpha,
1783  const Scalar& beta,
1785  const Scalar& gamma);
1786 
1798  void
1799  norm1 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1800 
1801  template<class ViewType>
1802  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1803  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1804  norm1 (const ViewType& norms) const {
1805  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1806  // this method to be templated. (It only exists in case
1807  // HostSpace = device_type::memory_space.)
1808  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1809  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1810  this->norm1 (h_norms);
1811  Kokkos::deep_copy (norms, h_norms);
1812  }
1813 
1829  template <typename T>
1830  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1831  norm1 (const Kokkos::View<T*, device_type>& norms) const
1832  {
1833  const size_t numNorms = norms.extent (0);
1834  Kokkos::View<mag_type*, device_type> tmpNorms ("MV::norm1 tmp", numNorms);
1835  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1836  this->norm1 (tmpNorms);
1837  // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1838  // and T differ? We would need a test for this, but only the
1839  // Sacado and Stokhos packages are likely to care about this use
1840  // case. It could also come up with Kokkos::complex ->
1841  // std::complex conversion.
1842  Kokkos::deep_copy (norms, tmpNorms);
1843  }
1844 
1848  void norm1 (const Teuchos::ArrayView<mag_type>& norms) const;
1849 
1864  template <typename T>
1865  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1866  norm1 (const Teuchos::ArrayView<T>& norms) const
1867  {
1868  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1869  const size_type sz = norms.size ();
1870  Teuchos::Array<mag_type> theNorms (sz);
1871  this->norm1 (theNorms);
1872  for (size_type i = 0; i < sz; ++i) {
1873  // If T and mag_type differ, this does an implicit conversion.
1874  norms[i] = theNorms[i];
1875  }
1876  }
1877 
1890  void
1891  norm2 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1892 
1893  template<class ViewType>
1894  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1895  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1896  norm2 (const ViewType& norms) const {
1897  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1898  // this method to be templated. (It only exists in case
1899  // HostSpace = device_type::memory_space.)
1900  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1901  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1902  this->norm2 (h_norms);
1903  Kokkos::deep_copy (norms, h_norms);
1904  }
1905 
1919  template<typename T>
1920  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1921  norm2 (const Kokkos::View<T*, device_type>& norms) const
1922  {
1923  const size_t numNorms = norms.extent (0);
1924  Kokkos::View<mag_type*, device_type> theNorms ("MV::norm2 tmp", numNorms);
1925  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1926  this->norm2 (theNorms);
1927  // FIXME (mfh 14 Jul 2014) Does this actually work if mag_type
1928  // and T differ? We would need a test for this, but only the
1929  // Sacado and Stokhos packages are likely to care about this use
1930  // case. This could also come up with Kokkos::complex ->
1931  // std::complex conversion.
1932  Kokkos::deep_copy (norms, theNorms);
1933  }
1934 
1938  void norm2 (const Teuchos::ArrayView<mag_type>& norms) const;
1939 
1954  template <typename T>
1955  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1956  norm2 (const Teuchos::ArrayView<T>& norms) const
1957  {
1958  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1959  const size_type sz = norms.size ();
1960  Teuchos::Array<mag_type> theNorms (sz);
1961  this->norm2 (theNorms);
1962  for (size_type i = 0; i < sz; ++i) {
1963  // If T and mag_type differ, this does an implicit conversion.
1964  norms[i] = theNorms[i];
1965  }
1966  }
1967 
1974  void normInf (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1975 
1976  template<class ViewType>
1977  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1978  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1979  normInf (const ViewType& norms) const {
1980  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1981  // this method to be templated. (It only exists in case
1982  // HostSpace = device_type::memory_space.)
1983  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1984  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1985  this->normInf (h_norms);
1986  Kokkos::deep_copy (norms, h_norms);
1987  }
1988 
2002  template<typename T>
2003  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
2004  normInf (const Kokkos::View<T*, device_type>& norms) const
2005  {
2006  const size_t numNorms = norms.extent (0);
2007  Kokkos::View<mag_type*, device_type> theNorms ("MV::normInf tmp", numNorms);
2008  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
2009  this->normInf (theNorms);
2010  // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
2011  // and T differ? We would need a test for this, but only the
2012  // Sacado and Stokhos packages are likely to care about this use
2013  // case. This could also come up with Kokkos::complex ->
2014  // std::complex conversion.
2015  Kokkos::deep_copy (norms, theNorms);
2016  }
2017 
2022  void normInf (const Teuchos::ArrayView<mag_type>& norms) const;
2023 
2039  template <typename T>
2040  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
2041  normInf (const Teuchos::ArrayView<T>& norms) const
2042  {
2043  typedef typename Teuchos::ArrayView<T>::size_type size_type;
2044  const size_type sz = norms.size ();
2045  Teuchos::Array<mag_type> theNorms (sz);
2046  this->norm2 (theNorms);
2047  for (size_type i = 0; i < sz; ++i) {
2048  // If T and mag_type differ, this does an implicit conversion.
2049  norms[i] = theNorms[i];
2050  }
2051  }
2052 
2053 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2054  void TPETRA_DEPRECATED
2061  normWeighted (const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& weights,
2062  const Teuchos::ArrayView<mag_type>& norms) const;
2063 
2080  template <typename T>
2081  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
2082  TPETRA_DEPRECATED
2083  normWeighted (const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& weights,
2084  const Teuchos::ArrayView<T>& norms) const
2085  {
2086  typedef typename Teuchos::ArrayView<T>::size_type size_type;
2087  const size_type sz = norms.size ();
2088  Teuchos::Array<mag_type> theNorms (sz);
2089  this->normWeighted (weights, theNorms);
2090  for (size_type i = 0; i < sz; ++i) {
2091  // If T and mag_type differ, this does an implicit conversion.
2092  norms[i] = theNorms[i];
2093  }
2094  }
2095 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2096 
2101  void meanValue (const Teuchos::ArrayView<impl_scalar_type>& means) const;
2102 
2103  template <typename T>
2104  typename std::enable_if<! std::is_same<impl_scalar_type, T>::value, void>::type
2105  meanValue (const Teuchos::ArrayView<T>& means) const
2106  {
2107  typedef typename Teuchos::Array<T>::size_type size_type;
2108  const size_type numMeans = means.size ();
2109 
2110  Teuchos::Array<impl_scalar_type> theMeans (numMeans);
2111  this->meanValue (theMeans ());
2112  for (size_type k = 0; k < numMeans; ++k) {
2113  means[k] = static_cast<T> (theMeans[k]);
2114  }
2115  }
2116 
2122  void
2123  multiply (Teuchos::ETransp transA,
2124  Teuchos::ETransp transB,
2125  const Scalar& alpha,
2126  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2127  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2128  const Scalar& beta);
2129 
2150  void
2151  elementWiseMultiply (Scalar scalarAB,
2152  const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2153  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2154  Scalar scalarThis);
2156 
2158 
2160  size_t getNumVectors() const;
2161 
2163  size_t getLocalLength() const;
2164 
2167 
2173  size_t getStride() const;
2174 
2178  bool isConstantStride() const;
2179 
2181 
2183 
2184 
2186  virtual std::string description() const;
2187 
2216  virtual void
2217  describe (Teuchos::FancyOStream& out,
2218  const Teuchos::EVerbosityLevel verbLevel =
2219  Teuchos::Describable::verbLevel_default) const;
2221 
2235  virtual void
2236  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
2237 
2248  void setCopyOrView (const Teuchos::DataAccess copyOrView) {
2249  TEUCHOS_TEST_FOR_EXCEPTION(
2250  copyOrView == Teuchos::Copy, std::invalid_argument,
2251  "Tpetra::MultiVector::setCopyOrView: The Kokkos refactor version of "
2252  "MultiVector _only_ implements view semantics. You may not call this "
2253  "method with copyOrView = Teuchos::Copy. The only valid argument is "
2254  "Teuchos::View.");
2255  }
2256 
2260  // This method ONLY exists for the circa 2014 "Kokkos refactor"
2261  // effort. It ALWAYS returns Teuchos::View.
2265  Teuchos::DataAccess getCopyOrView () const {
2266  return Teuchos::View;
2267  }
2268 
2283  void
2285 
2286 
2287  // \brief Checks to see if the local length, number of vectors and size of Scalar type match
2296 
2297  private:
2299  using base_type = DistObject<scalar_type, local_ordinal_type,
2301 
2302  protected:
2303  template <class DS, class DL, class DG, class DN,
2304  class SS, class SL, class SG, class SN>
2305  friend void
2307  const MultiVector<SS, SL, SG, SN>& src);
2308 
2316 
2347 
2360  Teuchos::Array<size_t> whichVectors_;
2361 
2362  template<class SC, class LO, class GO, class NT>
2363  friend ::Teuchos::ArrayView<const size_t> getMultiVectorWhichVectors (const ::Tpetra::MultiVector<SC, LO, GO, NT>& X);
2364 
2366 
2368 
2375  std::string
2376  descriptionImpl (const std::string& className) const;
2377 
2384  std::string
2385  localDescribeToString (const Teuchos::EVerbosityLevel vl) const;
2386 
2400  void
2401  describeImpl (Teuchos::FancyOStream& out,
2402  const std::string& className,
2403  const Teuchos::EVerbosityLevel verbLevel =
2404  Teuchos::Describable::verbLevel_default) const;
2405 
2406  // Return true if and only if VectorIndex is a valid column index.
2407  bool vectorIndexOutOfRange (const size_t VectorIndex) const;
2408 
2413  template <class T>
2414  Teuchos::ArrayRCP<T>
2415  getSubArrayRCP (Teuchos::ArrayRCP<T> arr, size_t j) const;
2416 
2418  size_t getOrigNumLocalRows () const;
2419 
2421  size_t getOrigNumLocalCols () const;
2422 
2424 
2426 
2431  using buffer_device_type =
2432  typename DistObject<scalar_type,
2436 
2441  virtual bool
2442  checkSizes (const SrcDistObject& sourceObj);
2443 
2445  virtual size_t constantNumberOfPackets () const;
2446 
2447  virtual void
2448 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2449  copyAndPermuteNew
2450 #else // TPETRA_ENABLE_DEPRECATED_CODE
2451  copyAndPermute
2452 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2453  (const SrcDistObject& sourceObj,
2454  const size_t numSameIDs,
2455  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs,
2456  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs);
2457 
2458  virtual void
2459 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2460  packAndPrepareNew
2461 #else // TPETRA_ENABLE_DEPRECATED_CODE
2462  packAndPrepare
2463 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2464  (const SrcDistObject& sourceObj,
2465  const Kokkos::DualView<
2466  const local_ordinal_type*,
2467  buffer_device_type>& exportLIDs,
2468  Kokkos::DualView<
2470  buffer_device_type>& exports,
2471  Kokkos::DualView<
2472  size_t*,
2473  buffer_device_type> /* numPacketsPerLID */,
2474  size_t& constantNumPackets,
2475  Distributor& /* distor */);
2476 
2477  virtual void
2478 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2479  unpackAndCombineNew
2480 #else // TPETRA_ENABLE_DEPRECATED_CODE
2481  unpackAndCombine
2482 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2483  (const Kokkos::DualView<
2484  const local_ordinal_type*,
2485  buffer_device_type>& importLIDs,
2486  Kokkos::DualView<
2488  buffer_device_type> imports,
2489  Kokkos::DualView<
2490  size_t*,
2491  buffer_device_type> /* numPacketsPerLID */,
2492  const size_t constantNumPackets,
2493  Distributor& /* distor */,
2494  const CombineMode CM);
2496  }; // class MultiVector
2497 
2498  template<class SC, class LO, class GO, class NT>
2499  Teuchos::ArrayView<const size_t>
2500  getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X)
2501  {
2502  return X.whichVectors_ ();
2503  }
2504 
2505 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2506  namespace Details {
2507  template<class DstMultiVectorType,
2508  class SrcMultiVectorType>
2509  Teuchos::RCP<
2510  typename MultiVectorCloner<
2511  DstMultiVectorType,
2512  SrcMultiVectorType>::dst_mv_type>
2513  MultiVectorCloner<DstMultiVectorType, SrcMultiVectorType>::
2514  clone (const src_mv_type& X,
2515  const Teuchos::RCP<typename dst_mv_type::node_type>& node2)
2516  {
2517  using Teuchos::RCP;
2518  typedef typename src_mv_type::map_type src_map_type;
2519  typedef typename dst_mv_type::map_type dst_map_type;
2520  typedef typename dst_mv_type::node_type dst_node_type;
2521  typedef typename dst_mv_type::dual_view_type dst_dual_view_type;
2522 
2523  // Clone X's Map to have the new Node type.
2524  RCP<const src_map_type> map1 = X.getMap ();
2525  RCP<const dst_map_type> map2 = map1.is_null () ?
2526  Teuchos::null : map1->template clone<dst_node_type> (node2);
2527 
2528  const size_t lclNumRows = X.getLocalLength ();
2529  const size_t numCols = X.getNumVectors ();
2530  dst_dual_view_type Y_view ("MV::dual_view", lclNumRows, numCols);
2531 
2532  RCP<dst_mv_type> Y (new dst_mv_type (map2, Y_view));
2533  // Let deep_copy do the work for us, to avoid code duplication.
2534  ::Tpetra::deep_copy (*Y, X);
2535  return Y ;
2536  }
2537  } // namespace Details
2538 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2539 
2542  template <class ST, class LO, class GO, class NT>
2543  void
2545  const MultiVector<ST, LO, GO, NT>& src)
2546  {
2547  // NOTE (mfh 11 Sep 2014) We can't implement deep_copy with
2548  // shallow-copy operator=, because that would invalidate existing
2549  // views of dst!
2550  dst.assign (src);
2551  }
2552 
2553  // Implementation of the most generic version of MultiVector deep_copy.
2554  template <class DS, class DL, class DG, class DN,
2555  class SS, class SL, class SG, class SN>
2556  void
2558  const MultiVector<SS, SL, SG, SN>& src)
2559  {
2560  using ::Tpetra::getMultiVectorWhichVectors;
2561 
2562  TEUCHOS_TEST_FOR_EXCEPTION(
2563  dst.getGlobalLength () != src.getGlobalLength () ||
2564  dst.getNumVectors () != src.getNumVectors (), std::invalid_argument,
2565  "Tpetra::deep_copy: Global dimensions of the two Tpetra::MultiVector "
2566  "objects do not match. src has dimensions [" << src.getGlobalLength ()
2567  << "," << src.getNumVectors () << "], and dst has dimensions ["
2568  << dst.getGlobalLength () << "," << dst.getNumVectors () << "].");
2569 
2570  // FIXME (mfh 28 Jul 2014) Don't throw; just set a local error flag.
2571  TEUCHOS_TEST_FOR_EXCEPTION(
2572  dst.getLocalLength () != src.getLocalLength (), std::invalid_argument,
2573  "Tpetra::deep_copy: The local row counts of the two Tpetra::MultiVector "
2574  "objects do not match. src has " << src.getLocalLength () << " row(s) "
2575  << " and dst has " << dst.getLocalLength () << " row(s).");
2576 
2577  const bool srcMostUpToDateOnDevice = ! src.need_sync_device ();
2578  dst.clear_sync_state ();
2579  dst.modify_device ();
2580 
2581  if (src.isConstantStride () && dst.isConstantStride ()) {
2582  if (srcMostUpToDateOnDevice) {
2584  src.getLocalViewDevice ());
2585  }
2586  else {
2588  src.getLocalViewHost ());
2589  }
2590  }
2591  else {
2592  auto dstWhichVecs = getMultiVectorWhichVectors (dst);
2593  auto srcWhichVecs = getMultiVectorWhichVectors (src);
2594 
2595  if (srcMostUpToDateOnDevice) {
2597  src.getLocalViewDevice (),
2598  dst.isConstantStride (),
2599  src.isConstantStride (),
2600  dstWhichVecs,
2601  srcWhichVecs);
2602  }
2603  else {
2605  src.getLocalViewHost (),
2606  dst.isConstantStride (),
2607  src.isConstantStride (),
2608  dstWhichVecs,
2609  srcWhichVecs);
2610  }
2611  }
2612  }
2613 } // namespace Tpetra
2614 
2615 
2616 namespace Teuchos {
2617 
2618  // Give Teuchos::TypeNameTraits<Tpetra::MultiVector<...> > a
2619  // human-readable definition.
2620  template<class SC, class LO, class GO, class NT>
2621  class TypeNameTraits<Tpetra::MultiVector<SC, LO, GO, NT> > {
2622  public:
2623  static std::string name () {
2624  return std::string ("Tpetra::MultiVector<") +
2625  TypeNameTraits<SC>::name () + "," +
2626  TypeNameTraits<LO>::name () + "," +
2627  TypeNameTraits<GO>::name () + "," +
2628  TypeNameTraits<NT>::name () + ">";
2629  }
2630 
2631  static std::string
2632  concreteName (const Tpetra::MultiVector<SC, LO, GO, NT>&) {
2633  return name ();
2634  }
2635  };
2636 } // namespace Teuchos
2637 
2638 #endif // TPETRA_MULTIVECTOR_DECL_HPP
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.
dual_view_type::t_host getLocalViewHost() const
A local Kokkos::View of host memory.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
LocalOrdinal local_ordinal_type
The type of local indices.
dual_view_type view_
The Kokkos::DualView containing the MultiVector&#39;s data.
Node node_type
The Node type. If you don&#39;t know what this is, don&#39;t use it.
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.
typename map_type::node_type node_type
Legacy thing that you should not use any more.
void clear_sync_state()
Clear &quot;modified&quot; flags on both host and device sides.
void localDeepCopyConstStride(const DstViewType &dst, const SrcViewType &src)
Implementation of Tpetra::MultiVector deep copy of local data, for when both the source and destinati...
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, execution_space > dual_view_type
Kokkos::DualView specialization used by this class.
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.
Teuchos::ArrayRCP< Teuchos::ArrayRCP< Scalar > > get2dViewNonConst()
Return non-const persisting pointers to values.
bool isConstantStride() const
Whether this multivector has constant stride between columns.
std::string localDescribeToString(const Teuchos::EVerbosityLevel vl) const
Print the calling process&#39; verbose describe() information to the returned string. ...
One or more distributed dense vectors.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subCopy(const Teuchos::Range1D &colRng) const
Return a MultiVector with copies of selected columns.
void modify()
Mark data as modified on the given device TargetDeviceType.
void sumIntoGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value, const bool atomic=useAtomicUpdatesByDefault) const
Update (+=) a value in host memory, using global row index.
bool need_sync() const
Whether this MultiVector needs synchronization to the given space.
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.
static const bool useAtomicUpdatesByDefault
Whether sumIntoLocalValue and sumIntoGlobalValue should use atomic updates by default.
MultiVector< ST, LO, GO, NT > createCopy(const MultiVector< ST, LO, GO, NT > &src)
Return a deep copy of the given MultiVector.
Kokkos::Impl::if_c< std::is_same< typename device_type::memory_space, typename TargetDeviceType::memory_space >::value, typename dual_view_type::t_dev, typename dual_view_type::t_host >::type getLocalView() const
Return a view of the local data on a specific device.
void setCopyOrView(const Teuchos::DataAccess copyOrView)
Set whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy assigment (shallow copy).
void sync()
Update data on device or host only if data in the other space has been marked as modified.
typename Node::device_type device_type
The Kokkos Device type.
bool need_sync_device() const
Whether this MultiVector needs synchronization to the device.
GO global_ordinal_type
The type of global indices.
bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
size_t getOrigNumLocalCols() const
&quot;Original&quot; number of columns in the (local) data.
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.
typename device_type::execution_space execution_space
The Kokkos execution space.
void sync_host()
Synchronize to Host.
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.
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).
dual_view_type origView_
The &quot;original view&quot; of the MultiVector&#39;s data.
std::string descriptionImpl(const std::string &className) const
Implementation of description() for this class, and its subclass Vector.
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.
void replaceGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value) const
Replace value in host memory, using global row index.
typename Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner (&quot;dot&quot;) product result.
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.
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Rule for combining data in an Import or Export.
typename DistObject< scalar_type, local_ordinal_type, global_ordinal_type, node_type >::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
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.
virtual ~MultiVector()=default
Destructor (virtual for memory safety of derived classes).
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.
virtual size_t constantNumberOfPackets() const
Number of packets to send per LID.
bool need_sync_host() const
Whether this MultiVector needs synchronization to the host.
void modify_device()
Mark data as modified on the device side.
typename map_type::global_ordinal_type global_ordinal_type
The type of global 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 replaceLocalValue(const LocalOrdinal lclRow, const size_t col, const T &val) const
Like the above replaceLocalValue, but only enabled if T differs from impl_scalar_type.
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
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.
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) const
Like the above sumIntoGlobalValue, but only enabled if T differs from impl_scalar_type.
void swap(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &mv)
Return a deep copy of this MultiVector, with a different Node type.
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.
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.
void modify_host()
Mark data as modified on the host side.
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) const
Like the above replaceGlobalValue, but only enabled if T differs from impl_scalar_type.
MultiVector()
Default constructor: makes a MultiVector with no rows or columns.
Forward declaration of Tpetra::FEMultiVector.
Scalar scalar_type
The type of each entry in the MultiVector.
void replaceLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &value) const
Replace value in host memory, using local (row) index.
typename Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
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.
size_t getStride() const
Stride between columns in the multivector.
virtual std::string description() const
A simple one-line description of this object.
void reduce()
Sum values of a locally replicated multivector across all processes.
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 map_type::local_ordinal_type local_ordinal_type
The type of local indices that this class uses.
virtual bool checkSizes(const SrcDistObject &sourceObj)
Whether data redistribution between sourceObj and this object is legal.
typename Node::device_type device_type
This class&#39; Kokkos::Device specialization.
dual_view_type::t_dev getLocalViewDevice() const
A local Kokkos::View of device memory.
void sumIntoLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &val, const bool atomic=useAtomicUpdatesByDefault) const
Update (+=) a value in host memory, using local row index.
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
Teuchos::DataAccess getCopyOrView() const
Get whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
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.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap)
Remove processes owning zero rows from the Map and their communicator.
void sync_device()
Synchronize to Device.
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) const
Like the above sumIntoLocalValue, but only enabled if T differs from impl_scalar_type.
Teuchos::Array< size_t > whichVectors_
Indices of columns this multivector is viewing.