Tpetra parallel linear algebra  Version of the Day
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 namespace Tpetra {
69 
70  namespace Details {
96  template<class DstMultiVectorType, class SrcMultiVectorType>
98  typedef DstMultiVectorType dst_mv_type;
99  typedef SrcMultiVectorType src_mv_type;
100 
101  static Teuchos::RCP<dst_mv_type>
102  clone (const src_mv_type& X,
103  const Teuchos::RCP<typename dst_mv_type::node_type>& node2);
104  };
105  } // namespace Details
106 
127  template <class DS, class DL, class DG, class DN,
128  class SS, class SL, class SG, class SN>
129  void
131  const MultiVector<SS, SL, SG, SN>& src);
132 
140  template <class ST, class LO, class GO, class NT>
143 
153  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
154  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
155  createMultiVector (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map,
156  const size_t numVectors);
157 
158 namespace Classes {
159  // WARNING NOT FOR USERS
160  // This means we don't need to make MultiVector a friend of
161  // Vector or of itself (with different template parameters).
162  template<class SC, class LO, class GO, class NT>
163  Teuchos::ArrayView<const size_t>
164  getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X);
165 
385  template <class Scalar = ::Tpetra::Details::DefaultTypes::scalar_type,
387  class GlobalOrdinal = ::Tpetra::Details::DefaultTypes::global_ordinal_type,
389  class MultiVector :
390  public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node>
391  {
392  public:
394 
395 
398  typedef Scalar scalar_type;
414  typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
416  typedef LocalOrdinal local_ordinal_type;
418  typedef GlobalOrdinal global_ordinal_type;
420  typedef Node node_type;
421 
423  typedef typename Node::device_type device_type;
424 
425  private:
428 
429  public:
435  typedef typename Kokkos::Details::InnerProductSpaceTraits<impl_scalar_type>::dot_type dot_type;
436 
443  typedef typename Kokkos::Details::ArithTraits<impl_scalar_type>::mag_type mag_type;
444 
451  typedef typename Node::execution_space execution_space;
452 
475  typedef Kokkos::DualView<impl_scalar_type**, Kokkos::LayoutLeft,
476  typename execution_space::execution_space> dual_view_type;
477 
480 
482 
484 
486  MultiVector ();
487 
494  MultiVector (const Teuchos::RCP<const map_type>& map,
495  const size_t numVecs,
496  const bool zeroOut = true);
497 
500 
514  const Teuchos::DataAccess copyOrView);
515 
531  MultiVector (const Teuchos::RCP<const map_type>& map,
532  const Teuchos::ArrayView<const Scalar>& A,
533  const size_t LDA,
534  const size_t NumVectors);
535 
549  MultiVector (const Teuchos::RCP<const map_type>& map,
550  const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar> >&ArrayOfPtrs,
551  const size_t NumVectors);
552 
565  MultiVector (const Teuchos::RCP<const map_type>& map,
566  const dual_view_type& view);
567 
606  MultiVector (const Teuchos::RCP<const map_type>& map,
607  const typename dual_view_type::t_dev& d_view);
608 
631  MultiVector (const Teuchos::RCP<const map_type>& map,
632  const dual_view_type& view,
633  const dual_view_type& origView);
634 
635  protected:
636 
642  const size_t j);
643 
644  public:
645 
663  MultiVector (const Teuchos::RCP<const map_type>& map,
664  const dual_view_type& view,
665  const Teuchos::ArrayView<const size_t>& whichVectors);
666 
694  MultiVector (const Teuchos::RCP<const map_type>& map,
695  const dual_view_type& view,
696  const dual_view_type& origView,
697  const Teuchos::ArrayView<const size_t>& whichVectors);
698 
758  const map_type& subMap,
759  const size_t offset = 0);
760 
769  template <class Node2>
770  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node2> >
771  clone (const Teuchos::RCP<Node2>& node2) const;
772 
778 
780  virtual ~MultiVector ();
781 
783 
785 
786  protected:
791  static const bool useAtomicUpdatesByDefault =
792 #ifdef KOKKOS_ENABLE_SERIAL
793  ! std::is_same<execution_space, Kokkos::Serial>::value;
794 #else
795  true;
796 #endif // KOKKOS_ENABLE_SERIAL
797 
798  public:
827  void
828  replaceGlobalValue (const GlobalOrdinal gblRow,
829  const size_t col,
830  const impl_scalar_type& value) const;
831 
864  template<typename T>
865  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
866  replaceGlobalValue (GlobalOrdinal globalRow,
867  size_t col,
868  const T& value) const
869  {
870  replaceGlobalValue (globalRow, col, static_cast<impl_scalar_type> (value));
871  }
872 
896  void
897  sumIntoGlobalValue (const GlobalOrdinal gblRow,
898  const size_t col,
899  const impl_scalar_type& value,
900  const bool atomic = useAtomicUpdatesByDefault) const;
901 
929  template<typename T>
930  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
931  sumIntoGlobalValue (const GlobalOrdinal gblRow,
932  const size_t col,
933  const T& val,
934  const bool atomic = useAtomicUpdatesByDefault) const
935  {
936  sumIntoGlobalValue (gblRow, col, static_cast<impl_scalar_type> (val), atomic);
937  }
938 
967  void
968  replaceLocalValue (const LocalOrdinal lclRow,
969  const size_t col,
970  const impl_scalar_type& value) const;
971 
1004  template<typename T>
1005  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1006  replaceLocalValue (const LocalOrdinal lclRow,
1007  const size_t col,
1008  const T& val) const
1009  {
1010  replaceLocalValue (lclRow, col, static_cast<impl_scalar_type> (val));
1011  }
1012 
1036  void
1037  sumIntoLocalValue (const LocalOrdinal lclRow,
1038  const size_t col,
1039  const impl_scalar_type& val,
1040  const bool atomic = useAtomicUpdatesByDefault) const;
1041 
1067  template<typename T>
1068  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1069  sumIntoLocalValue (const LocalOrdinal lclRow,
1070  const size_t col,
1071  const T& val,
1072  const bool atomic = useAtomicUpdatesByDefault) const
1073  {
1074  sumIntoLocalValue (lclRow, col, static_cast<impl_scalar_type> (val), atomic);
1075  }
1076 
1078  void putScalar (const Scalar& value);
1079 
1088  template<typename T>
1089  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1090  putScalar (const T& value)
1091  {
1092  putScalar (static_cast<impl_scalar_type> (value));
1093  }
1094 
1107  void randomize();
1108 
1122  void randomize (const Scalar& minVal, const Scalar& maxVal);
1123 
1189  void replaceMap (const Teuchos::RCP<const map_type>& map);
1190 
1197  void reduce();
1198 
1202 
1204 
1230 
1231 
1233  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1234  subCopy (const Teuchos::Range1D& colRng) const;
1235 
1237  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1238  subCopy (const Teuchos::ArrayView<const size_t>& cols) const;
1239 
1241  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1242  subView (const Teuchos::Range1D& colRng) const;
1243 
1245  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1246  subView (const Teuchos::ArrayView<const size_t>& cols) const;
1247 
1249  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1250  subViewNonConst (const Teuchos::Range1D& colRng);
1251 
1253  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1254  subViewNonConst (const Teuchos::ArrayView<const size_t>& cols);
1255 
1318  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1319  offsetView (const Teuchos::RCP<const map_type>& subMap,
1320  const size_t offset) const;
1321 
1339  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1340  offsetViewNonConst (const Teuchos::RCP<const map_type>& subMap,
1341  const size_t offset);
1342 
1344  Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1345  getVector (const size_t j) const;
1346 
1348  Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1349  getVectorNonConst (const size_t j);
1350 
1352  Teuchos::ArrayRCP<const Scalar> getData (size_t j) const;
1353 
1355  Teuchos::ArrayRCP<Scalar> getDataNonConst (size_t j);
1356 
1364  void
1365  get1dCopy (const Teuchos::ArrayView<Scalar>& A,
1366  const size_t LDA) const;
1367 
1374  void
1375  get2dCopy (const Teuchos::ArrayView<const Teuchos::ArrayView<Scalar> >& ArrayOfPtrs) const;
1376 
1382  Teuchos::ArrayRCP<const Scalar> get1dView () const;
1383 
1385  Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> > get2dView () const;
1386 
1392  Teuchos::ArrayRCP<Scalar> get1dViewNonConst ();
1393 
1395  Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > get2dViewNonConst ();
1396 
1411  dual_view_type getDualView () const;
1412 
1431  template<class TargetDeviceType>
1432  void sync () {
1433  getDualView ().template sync<TargetDeviceType> ();
1434  }
1435 
1437  template<class TargetDeviceType>
1438  bool need_sync () const {
1439  return getDualView ().template need_sync<TargetDeviceType> ();
1440  }
1441 
1447  template<class TargetDeviceType>
1448  void modify () {
1449  getDualView ().template modify<TargetDeviceType> ();
1450  }
1451 
1483  template<class TargetDeviceType>
1484  typename Kokkos::Impl::if_c<
1485  std::is_same<
1486  typename device_type::memory_space,
1487  typename TargetDeviceType::memory_space>::value,
1488  typename dual_view_type::t_dev,
1489  typename dual_view_type::t_host>::type
1490  getLocalView () const {
1491  return getDualView ().template view<TargetDeviceType> ();
1492  }
1493 
1495 
1497 
1511  void
1513  const Teuchos::ArrayView<dot_type>& dots) const;
1514 
1526  template <typename T>
1527  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1529  const Teuchos::ArrayView<T> &dots) const
1530  {
1531  const size_t sz = static_cast<size_t> (dots.size ());
1532  Teuchos::Array<dot_type> dts (sz);
1533  this->dot (A, dts);
1534  for (size_t i = 0; i < sz; ++i) {
1535  // If T and dot_type differ, this does an implicit conversion.
1536  dots[i] = dts[i];
1537  }
1538  }
1539 
1541  template <typename T>
1542  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1544  std::vector<T>& dots) const
1545  {
1546  const size_t sz = dots.size ();
1547  Teuchos::Array<dot_type> dts (sz);
1548  this->dot (A, dts);
1549  for (size_t i = 0; i < sz; ++i) {
1550  // If T and dot_type differ, this does an implicit conversion.
1551  dots[i] = dts[i];
1552  }
1553  }
1554 
1572  void
1574  const Kokkos::View<dot_type*, Kokkos::HostSpace>& norms) const;
1575 
1576  template<class ViewType>
1577  void
1578  dot (typename std::enable_if<std::is_same<typename ViewType::value_type,dot_type>::value &&
1579  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value,
1581  const ViewType& dots) const {
1582  const Kokkos::View<dot_type*, Kokkos::HostSpace> h_dots("Tpetra::Dots",dots.extent(0));
1583  this->dot (A, h_dots);
1584  Kokkos::deep_copy(dots,h_dots);
1585  }
1586 
1599  template <typename T>
1600  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1602  const Kokkos::View<T*, device_type>& dots) const
1603  {
1604  const size_t numDots = dots.extent (0);
1605  Kokkos::View<dot_type*, device_type> dts ("MV::dot tmp", numDots);
1606  // Call overload that takes a Kokkos::View<dot_type*, device_type>.
1607  this->dot (A, dts);
1608  // FIXME (mfh 14 Jul 2014) Does this actually work if dot_type
1609  // and T differ? We would need a test for this, but only the
1610  // Sacado and Stokhos packages are likely to care about this use
1611  // case. It could also come up for Kokkos::complex ->
1612  // std::complex conversions, but those two implementations
1613  // should generally be bitwise compatible.
1614  // CT: no this can't possible work .....
1615  Kokkos::deep_copy (dots, dts);
1616  }
1617 
1620 
1622  void reciprocal (const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A);
1623 
1631  void scale (const Scalar& alpha);
1632 
1641  void scale (const Teuchos::ArrayView<const Scalar>& alpha);
1642 
1651  void scale (const Kokkos::View<const impl_scalar_type*, device_type>& alpha);
1652 
1661  void
1662  scale (const Scalar& alpha,
1664 
1671  void
1672  update (const Scalar& alpha,
1674  const Scalar& beta);
1675 
1682  void
1683  update (const Scalar& alpha,
1685  const Scalar& beta,
1687  const Scalar& gamma);
1688 
1706  template<class ViewType>
1707  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1708  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1709  norm1 (const ViewType& norms) const {
1710  typedef typename Kokkos::View<mag_type*, Kokkos::HostSpace> host_norms_view_type;
1711  host_norms_view_type h_norms("Tpetra::MV::h_norms",norms.extent(0));
1712  this->normImpl (h_norms, NORM_ONE);
1713  Kokkos::deep_copy(norms,h_norms);
1714  }
1715  void norm1 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1716 
1732  template <typename T>
1733  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1734  norm1 (const Kokkos::View<T*, device_type>& norms) const
1735  {
1736  const size_t numNorms = norms.extent (0);
1737  Kokkos::View<mag_type*, device_type> tmpNorms ("MV::norm1 tmp", numNorms);
1738  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1739  this->norm1 (tmpNorms);
1740  // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1741  // and T differ? We would need a test for this, but only the
1742  // Sacado and Stokhos packages are likely to care about this use
1743  // case. It could also come up with Kokkos::complex ->
1744  // std::complex conversion.
1745  Kokkos::deep_copy (norms, tmpNorms);
1746  }
1747 
1751  void norm1 (const Teuchos::ArrayView<mag_type>& norms) const;
1752 
1767  template <typename T>
1768  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1769  norm1 (const Teuchos::ArrayView<T>& norms) const
1770  {
1771  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1772  const size_type sz = norms.size ();
1773  Teuchos::Array<mag_type> theNorms (sz);
1774  this->norm1 (theNorms);
1775  for (size_type i = 0; i < sz; ++i) {
1776  // If T and mag_type differ, this does an implicit conversion.
1777  norms[i] = theNorms[i];
1778  }
1779  }
1780 
1799  template<class ViewType>
1800  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1801  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1802  norm2 (const ViewType& norms) const {
1803  typedef typename Kokkos::View<mag_type*, Kokkos::HostSpace> host_norms_view_type;
1804  host_norms_view_type h_norms("Tpetra::MV::h_norms",norms.extent(0));
1805  this->normImpl (h_norms, NORM_TWO);
1806  Kokkos::deep_copy(norms,h_norms);
1807  }
1808  void norm2 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1809 
1823  template<typename T>
1824  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1825  norm2 (const Kokkos::View<T*, device_type>& norms) const
1826  {
1827  const size_t numNorms = norms.extent (0);
1828  Kokkos::View<mag_type*, device_type> theNorms ("MV::norm2 tmp", numNorms);
1829  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1830  this->norm2 (theNorms);
1831  // FIXME (mfh 14 Jul 2014) Does this actually work if mag_type
1832  // and T differ? We would need a test for this, but only the
1833  // Sacado and Stokhos packages are likely to care about this use
1834  // case. This could also come up with Kokkos::complex ->
1835  // std::complex conversion.
1836  Kokkos::deep_copy (norms, theNorms);
1837  }
1838 
1842  void norm2 (const Teuchos::ArrayView<mag_type>& norms) const;
1843 
1858  template <typename T>
1859  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1860  norm2 (const Teuchos::ArrayView<T>& norms) const
1861  {
1862  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1863  const size_type sz = norms.size ();
1864  Teuchos::Array<mag_type> theNorms (sz);
1865  this->norm2 (theNorms);
1866  for (size_type i = 0; i < sz; ++i) {
1867  // If T and mag_type differ, this does an implicit conversion.
1868  norms[i] = theNorms[i];
1869  }
1870  }
1871 
1884  template<class ViewType>
1885  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1886  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1887  normInf (const ViewType& norms) const {
1888  typedef typename Kokkos::View<mag_type*, Kokkos::HostSpace> host_norms_view_type;
1889  host_norms_view_type h_norms("Tpetra::MV::h_norms",norms.extent(0));
1890  this->normImpl (h_norms, NORM_INF);
1891  Kokkos::deep_copy(norms,h_norms);
1892  }
1893  void normInf (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1894 
1908  template<typename T>
1909  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1910  normInf (const Kokkos::View<T*, device_type>& norms) const
1911  {
1912  const size_t numNorms = norms.extent (0);
1913  Kokkos::View<mag_type*, device_type> theNorms ("MV::normInf tmp", numNorms);
1914  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1915  this->normInf (theNorms);
1916  // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1917  // and T differ? We would need a test for this, but only the
1918  // Sacado and Stokhos packages are likely to care about this use
1919  // case. This could also come up with Kokkos::complex ->
1920  // std::complex conversion.
1921  Kokkos::deep_copy (norms, theNorms);
1922  }
1923 
1928  void normInf (const Teuchos::ArrayView<mag_type>& norms) const;
1929 
1945  template <typename T>
1946  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1947  normInf (const Teuchos::ArrayView<T>& norms) const
1948  {
1949  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1950  const size_type sz = norms.size ();
1951  Teuchos::Array<mag_type> theNorms (sz);
1952  this->norm2 (theNorms);
1953  for (size_type i = 0; i < sz; ++i) {
1954  // If T and mag_type differ, this does an implicit conversion.
1955  norms[i] = theNorms[i];
1956  }
1957  }
1958 
1965  void TPETRA_DEPRECATED
1966  normWeighted (const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& weights,
1967  const Teuchos::ArrayView<mag_type>& norms) const;
1968 
1985  template <typename T>
1986  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1987  TPETRA_DEPRECATED
1989  const Teuchos::ArrayView<T>& norms) const
1990  {
1991  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1992  const size_type sz = norms.size ();
1993  Teuchos::Array<mag_type> theNorms (sz);
1994  this->normWeighted (weights, theNorms);
1995  for (size_type i = 0; i < sz; ++i) {
1996  // If T and mag_type differ, this does an implicit conversion.
1997  norms[i] = theNorms[i];
1998  }
1999  }
2000 
2005  void meanValue (const Teuchos::ArrayView<impl_scalar_type>& means) const;
2006 
2007  template <typename T>
2008  typename std::enable_if<! std::is_same<impl_scalar_type, T>::value, void>::type
2009  meanValue (const Teuchos::ArrayView<T>& means) const
2010  {
2011  typedef typename Teuchos::Array<T>::size_type size_type;
2012  const size_type numMeans = means.size ();
2013 
2014  Teuchos::Array<impl_scalar_type> theMeans (numMeans);
2015  this->meanValue (theMeans ());
2016  for (size_type k = 0; k < numMeans; ++k) {
2017  means[k] = static_cast<T> (theMeans[k]);
2018  }
2019  }
2020 
2026  void
2027  multiply (Teuchos::ETransp transA,
2028  Teuchos::ETransp transB,
2029  const Scalar& alpha,
2032  const Scalar& beta);
2033 
2054  void
2055  elementWiseMultiply (Scalar scalarAB,
2058  Scalar scalarThis);
2060 
2062 
2064  size_t getNumVectors() const;
2065 
2067  size_t getLocalLength() const;
2068 
2070  global_size_t getGlobalLength() const;
2071 
2077  size_t getStride() const;
2078 
2082  bool isConstantStride() const;
2083 
2085 
2087 
2088 
2090  virtual std::string description() const;
2091 
2120  virtual void
2121  describe (Teuchos::FancyOStream& out,
2122  const Teuchos::EVerbosityLevel verbLevel =
2123  Teuchos::Describable::verbLevel_default) const;
2125 
2139  virtual void
2140  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
2141 
2152  void setCopyOrView (const Teuchos::DataAccess copyOrView) {
2153  TEUCHOS_TEST_FOR_EXCEPTION(
2154  copyOrView == Teuchos::Copy, std::invalid_argument,
2155  "Tpetra::MultiVector::setCopyOrView: The Kokkos refactor version of "
2156  "MultiVector _only_ implements view semantics. You may not call this "
2157  "method with copyOrView = Teuchos::Copy. The only valid argument is "
2158  "Teuchos::View.");
2159  }
2160 
2164  // This method ONLY exists for the circa 2014 "Kokkos refactor"
2165  // effort. It ALWAYS returns Teuchos::View.
2169  Teuchos::DataAccess getCopyOrView () const {
2170  return Teuchos::View;
2171  }
2172 
2187  void
2189 
2190 
2191  // \brief Checks to see if the local length, number of vectors and size of Scalar type match
2199  bool isSameSize(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> & vec) const;
2200 
2201  protected:
2202  template <class DS, class DL, class DG, class DN,
2203  class SS, class SL, class SG, class SN>
2204  friend void
2206  const MultiVector<SS, SL, SG, SN>& src);
2207 
2214  mutable dual_view_type view_;
2215 
2245  mutable dual_view_type origView_;
2246 
2259  Teuchos::Array<size_t> whichVectors_;
2260 
2261  template<class SC, class LO, class GO, class NT>
2262  friend ::Teuchos::ArrayView<const size_t> getMultiVectorWhichVectors (const ::Tpetra::MultiVector<SC, LO, GO, NT>& X);
2263 
2265 
2266 
2268  enum EWhichNorm {
2269  NORM_ONE, //<! Use the one-norm
2270  NORM_TWO, //<! Use the two-norm
2271  NORM_INF //<! Use the infinity-norm
2272  };
2273 
2281  void
2282  normImpl (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms,
2283  const EWhichNorm whichNorm) const;
2284 
2286 
2288 
2289 
2291 
2293 
2300  std::string
2301  descriptionImpl (const std::string& className) const;
2302 
2309  std::string
2310  localDescribeToString (const Teuchos::EVerbosityLevel vl) const;
2311 
2325  void
2326  describeImpl (Teuchos::FancyOStream& out,
2327  const std::string& className,
2328  const Teuchos::EVerbosityLevel verbLevel =
2329  Teuchos::Describable::verbLevel_default) const;
2330 
2331  // Return true if and only if VectorIndex is a valid column index.
2332  bool vectorIndexOutOfRange (const size_t VectorIndex) const;
2333 
2338  template <class T>
2339  Teuchos::ArrayRCP<T>
2340  getSubArrayRCP (Teuchos::ArrayRCP<T> arr, size_t j) const;
2341 
2343  size_t getOrigNumLocalRows () const;
2344 
2346  size_t getOrigNumLocalCols () const;
2347 
2349 
2351 
2356  virtual bool
2357  checkSizes (const SrcDistObject& sourceObj);
2358 
2360  virtual size_t constantNumberOfPackets () const;
2361 
2363  virtual bool useNewInterface () { return true; }
2364 
2369  typedef typename DistObject<Scalar, LocalOrdinal, GlobalOrdinal,
2371 
2372  virtual void
2373  copyAndPermuteNew (const SrcDistObject& sourceObj,
2374  const size_t numSameIDs,
2375  const Kokkos::DualView<const local_ordinal_type*, device_type>& permuteToLIDs,
2376  const Kokkos::DualView<const local_ordinal_type*, device_type>& permuteFromLIDs);
2377 
2378  virtual void
2379  packAndPrepareNew (const SrcDistObject& sourceObj,
2380  const Kokkos::DualView<const local_ordinal_type*, device_type>& exportLIDs,
2381  Kokkos::DualView<impl_scalar_type*, buffer_device_type>& exports,
2382  const Kokkos::DualView<size_t*, buffer_device_type>& /* numPacketsPerLID */,
2383  size_t& constantNumPackets,
2384  Distributor& /* distor */);
2385 
2386  virtual void
2387  unpackAndCombineNew (const Kokkos::DualView<const LocalOrdinal*, device_type>& importLIDs,
2388  const Kokkos::DualView<const impl_scalar_type*, buffer_device_type>& imports,
2389  const Kokkos::DualView<const size_t*, buffer_device_type>& /* numPacketsPerLID */,
2390  const size_t constantNumPackets,
2391  Distributor& /* distor */,
2392  const CombineMode CM);
2394  }; // class MultiVector
2395 
2396  template<class SC, class LO, class GO, class NT>
2397  Teuchos::ArrayView<const size_t>
2398  getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X)
2399  {
2400  return X.whichVectors_ ();
2401  }
2402 } // namespace Classes
2403 
2404  namespace Details {
2405 
2406  template<class DstMultiVectorType,
2407  class SrcMultiVectorType>
2408  Teuchos::RCP<typename MultiVectorCloner<DstMultiVectorType, SrcMultiVectorType>::dst_mv_type>
2409  MultiVectorCloner<DstMultiVectorType, SrcMultiVectorType>::
2410  clone (const src_mv_type& X,
2411  const Teuchos::RCP<typename dst_mv_type::node_type>& node2)
2412  {
2413  using Teuchos::RCP;
2414  typedef typename src_mv_type::map_type src_map_type;
2415  typedef typename dst_mv_type::map_type dst_map_type;
2416  typedef typename dst_mv_type::node_type dst_node_type;
2417  typedef typename dst_mv_type::dual_view_type dst_dual_view_type;
2418 
2419  // Clone X's Map to have the new Node type.
2420  RCP<const src_map_type> map1 = X.getMap ();
2421  RCP<const dst_map_type> map2 = map1.is_null () ?
2422  Teuchos::null : map1->template clone<dst_node_type> (node2);
2423 
2424  const size_t lclNumRows = X.getLocalLength ();
2425  const size_t numCols = X.getNumVectors ();
2426  dst_dual_view_type Y_view ("MV::dual_view", lclNumRows, numCols);
2427 
2428  RCP<dst_mv_type> Y (new dst_mv_type (map2, Y_view));
2429  // Let deep_copy do the work for us, to avoid code duplication.
2430  ::Tpetra::deep_copy (*Y, X);
2431  return Y ;
2432  }
2433 
2434  } // namespace Details
2435 
2438  template <class ST, class LO, class GO, class NT>
2439  void
2441  const MultiVector<ST, LO, GO, NT>& src)
2442  {
2443  // NOTE (mfh 11 Sep 2014) We can't implement deep_copy with
2444  // shallow-copy operator=, because that would invalidate existing
2445  // views of dst!
2446  dst.assign (src);
2447  }
2448 
2449  // Implementation of the most generic version of MultiVector deep_copy.
2450  template <class DS, class DL, class DG, class DN,
2451  class SS, class SL, class SG, class SN>
2452  void
2454  const MultiVector<SS, SL, SG, SN>& src)
2455  {
2456  typedef typename DN::device_type DD;
2457  //typedef typename SN::device_type SD;
2458  using ::Tpetra::Classes::getMultiVectorWhichVectors;
2459 
2460  TEUCHOS_TEST_FOR_EXCEPTION(
2461  dst.getGlobalLength () != src.getGlobalLength () ||
2462  dst.getNumVectors () != src.getNumVectors (), std::invalid_argument,
2463  "Tpetra::deep_copy: Global dimensions of the two Tpetra::MultiVector "
2464  "objects do not match. src has dimensions [" << src.getGlobalLength ()
2465  << "," << src.getNumVectors () << "], and dst has dimensions ["
2466  << dst.getGlobalLength () << "," << dst.getNumVectors () << "].");
2467 
2468  // FIXME (mfh 28 Jul 2014) Don't throw; just set a local error flag.
2469  TEUCHOS_TEST_FOR_EXCEPTION(
2470  dst.getLocalLength () != src.getLocalLength (), std::invalid_argument,
2471  "Tpetra::deep_copy: The local row counts of the two Tpetra::MultiVector "
2472  "objects do not match. src has " << src.getLocalLength () << " row(s) "
2473  << " and dst has " << dst.getLocalLength () << " row(s).");
2474 
2475  if (src.isConstantStride () && dst.isConstantStride ()) {
2478 
2479  // If we need sync to device, then host has the most recent version.
2480  const bool useHostVersion = src.template need_sync<typename SN::device_type> ();
2481 
2482  if (! useHostVersion) {
2483  // Device memory has the most recent version of src.
2484  dst.template modify<DES> (); // We are about to modify dst on device.
2485  // Copy from src to dst on device.
2486  Details::localDeepCopyConstStride (dst.template getLocalView<DES> (),
2487  src.template getLocalView<typename SN::device_type> ());
2488  dst.template sync<HES> (); // Sync dst from device to host.
2489  }
2490  else { // Host memory has the most recent version of src.
2491  dst.template modify<HES> (); // We are about to modify dst on host.
2492  // Copy from src to dst on host.
2493  Details::localDeepCopyConstStride (dst.template getLocalView<Kokkos::HostSpace> (),
2494  src.template getLocalView<Kokkos::HostSpace> ());
2495  dst.template sync<DES> (); // Sync dst from host to device.
2496  }
2497  }
2498  else {
2499  typedef Kokkos::DualView<SL*, DD> whichvecs_type;
2500  typedef typename whichvecs_type::t_dev::execution_space DES;
2501  typedef typename whichvecs_type::t_host::execution_space HES;
2502 
2503  if (dst.isConstantStride ()) {
2504  const SL numWhichVecs =
2505  static_cast<SL> (getMultiVectorWhichVectors (src).size ());
2506  const std::string whichVecsLabel ("MV::deep_copy::whichVecs");
2507 
2508  // We can't sync src, since it is only an input argument.
2509  // Thus, we have to use the most recently modified version of
2510  // src, which could be either the device or host version.
2511  //
2512  // If we need sync to device, then host has the most recent version.
2513  const bool useHostVersion = src.template need_sync<typename SN::device_type> ();
2514 
2515  if (! useHostVersion) { // Copy from the device version of src.
2516  // whichVecs tells the kernel which vectors (columns) of src
2517  // to copy. Fill whichVecs on the host, and sync to device.
2518  whichvecs_type whichVecs (whichVecsLabel, numWhichVecs);
2519  whichVecs.template modify<HES> ();
2520 
2521  Teuchos::ArrayView<const size_t> src_whichVectors =
2522  getMultiVectorWhichVectors (src);
2523  for (SL i = 0; i < numWhichVecs; ++i) {
2524  whichVecs.h_view(i) = static_cast<SL> (src_whichVectors[i]);
2525  }
2526  // Sync the host version of whichVecs to the device.
2527  whichVecs.template sync<DES> ();
2528 
2529  // Mark the device version of dst's DualView as modified.
2530  dst.template modify<DES> ();
2531  // Copy from the selected vectors of src to dst, on the device.
2532  Details::localDeepCopy (dst.template getLocalView<typename DN::device_type> (),
2533  src.template getLocalView<typename SN::device_type> (),
2534  dst.isConstantStride (),
2535  src.isConstantStride (),
2536  whichVecs.d_view,
2537  whichVecs.d_view);
2538  // Sync dst's DualView to the host. This is cheaper than
2539  // repeating the above copy from src to dst on the host.
2540  dst.template sync<HES> ();
2541  }
2542  else { // host version of src was the most recently modified
2543  // Copy from the host version of src.
2544  //
2545  // whichVecs tells the kernel which vectors (columns) of src
2546  // to copy. Fill whichVecs on the host, and use it there.
2547  typedef Kokkos::View<SL*, HES> the_whichvecs_type;
2548  the_whichvecs_type whichVecs (whichVecsLabel, numWhichVecs);
2549  Teuchos::ArrayView<const size_t> src_whichVectors =
2550  getMultiVectorWhichVectors (src);
2551  for (SL i = 0; i < numWhichVecs; ++i) {
2552  whichVecs(i) = static_cast<SL> (src_whichVectors[i]);
2553  }
2554  // Copy from the selected vectors of src to dst, on the
2555  // host. The function ignores the first instance of
2556  // 'whichVecs' in this case.
2557  Details::localDeepCopy (dst.template getLocalView<Kokkos::HostSpace> (),
2558  src.template getLocalView<Kokkos::HostSpace> (),
2559  dst.isConstantStride (),
2560  src.isConstantStride (),
2561  whichVecs, whichVecs);
2562  // Sync dst back to the device, since we only copied on the host.
2563  dst.template sync<DES> ();
2564  }
2565  }
2566  else { // dst is NOT constant stride
2567  if (src.isConstantStride ()) {
2568 
2569  // If we need sync to device, then host has the most recent version.
2570  const bool useHostVersion = src.template need_sync<typename SN::device_type> ();
2571 
2572  if (! useHostVersion) { // Copy from the device version of src.
2573  // whichVecs tells the kernel which vectors (columns) of dst
2574  // to copy. Fill whichVecs on the host, and sync to device.
2575  typedef Kokkos::DualView<DL*, DES> the_whichvecs_type;
2576  const std::string whichVecsLabel ("MV::deep_copy::whichVecs");
2577  Teuchos::ArrayView<const size_t> dst_whichVectors =
2578  getMultiVectorWhichVectors (dst);
2579  const DL numWhichVecs = static_cast<DL> (dst_whichVectors.size ());
2580  the_whichvecs_type whichVecs (whichVecsLabel, numWhichVecs);
2581  whichVecs.template modify<HES> ();
2582  for (DL i = 0; i < numWhichVecs; ++i) {
2583  whichVecs.h_view(i) = dst_whichVectors[i];
2584  }
2585  // Sync the host version of whichVecs to the device.
2586  whichVecs.template sync<DES> ();
2587 
2588  // Copy src to the selected vectors of dst, on the device.
2589  Details::localDeepCopy (dst.template getLocalView<typename DN::device_type> (),
2590  src.template getLocalView<typename SN::device_type> (),
2591  dst.isConstantStride (),
2592  src.isConstantStride (),
2593  whichVecs.d_view,
2594  whichVecs.d_view);
2595  // We can't sync src and repeat the above copy on the
2596  // host, so sync dst back to the host.
2597  //
2598  // FIXME (mfh 29 Jul 2014) This may overwrite columns that
2599  // don't actually belong to dst's view.
2600  dst.template sync<HES> ();
2601  }
2602  else { // host version of src was the most recently modified
2603  // Copy from the host version of src.
2604  //
2605  // whichVecs tells the kernel which vectors (columns) of src
2606  // to copy. Fill whichVecs on the host, and use it there.
2607  typedef Kokkos::View<DL*, HES> the_whichvecs_type;
2608  Teuchos::ArrayView<const size_t> dst_whichVectors =
2609  getMultiVectorWhichVectors (dst);
2610  const DL numWhichVecs = static_cast<DL> (dst_whichVectors.size ());
2611  the_whichvecs_type whichVecs ("MV::deep_copy::whichVecs",
2612  numWhichVecs);
2613  for (DL i = 0; i < numWhichVecs; ++i) {
2614  whichVecs(i) = static_cast<DL> (dst_whichVectors[i]);
2615  }
2616  // Copy from src to the selected vectors of dst, on the host.
2617  Details::localDeepCopy (dst.template getLocalView<Kokkos::HostSpace> (),
2618  src.template getLocalView<Kokkos::HostSpace> (),
2619  dst.isConstantStride (),
2620  src.isConstantStride (),
2621  whichVecs, whichVecs);
2622  // Sync dst back to the device, since we only copied on the host.
2623  //
2624  // FIXME (mfh 29 Jul 2014) This may overwrite columns that
2625  // don't actually belong to dst's view.
2626  dst.template sync<DES> ();
2627  }
2628  }
2629  else { // neither src nor dst have constant stride
2630 
2631  // If we need sync to device, then host has the most recent version.
2632  const bool useHostVersion = src.template need_sync<typename SN::device_type> ();
2633 
2634  if (! useHostVersion) { // Copy from the device version of src.
2635  // whichVectorsDst tells the kernel which columns of dst
2636  // to copy. Fill it on the host, and sync to device.
2637  Teuchos::ArrayView<const size_t> dst_whichVectors =
2638  getMultiVectorWhichVectors (dst);
2639  const DL dstNumWhichVecs =
2640  static_cast<DL> (dst_whichVectors.size ());
2641  Kokkos::DualView<DL*, DES> whichVecsDst ("MV::deep_copy::whichVecsDst",
2642  dstNumWhichVecs);
2643  whichVecsDst.template modify<HES> ();
2644  for (DL i = 0; i < dstNumWhichVecs; ++i) {
2645  whichVecsDst.h_view(i) = static_cast<DL> (dst_whichVectors[i]);
2646  }
2647  // Sync the host version of whichVecsDst to the device.
2648  whichVecsDst.template sync<DES> ();
2649 
2650  // whichVectorsSrc tells the kernel which vectors
2651  // (columns) of src to copy. Fill it on the host, and
2652  // sync to device. Use the destination MultiVector's
2653  // LocalOrdinal type here.
2654  Teuchos::ArrayView<const size_t> src_whichVectors =
2655  getMultiVectorWhichVectors (src);
2656  const DL srcNumWhichVecs =
2657  static_cast<DL> (src_whichVectors.size ());
2658  Kokkos::DualView<DL*, DES> whichVecsSrc ("MV::deep_copy::whichVecsSrc",
2659  srcNumWhichVecs);
2660  whichVecsSrc.template modify<HES> ();
2661  for (DL i = 0; i < srcNumWhichVecs; ++i) {
2662  whichVecsSrc.h_view(i) = static_cast<DL> (src_whichVectors[i]);
2663  }
2664  // Sync the host version of whichVecsSrc to the device.
2665  whichVecsSrc.template sync<DES> ();
2666 
2667  // Copy from the selected vectors of src to the selected
2668  // vectors of dst, on the device.
2669  Details::localDeepCopy (dst.template getLocalView<typename DN::device_type> (),
2670  src.template getLocalView<typename SN::device_type> (),
2671  dst.isConstantStride (),
2672  src.isConstantStride (),
2673  whichVecsDst.d_view,
2674  whichVecsSrc.d_view);
2675  }
2676  else {
2677  Teuchos::ArrayView<const size_t> dst_whichVectors =
2678  getMultiVectorWhichVectors (dst);
2679  const DL dstNumWhichVecs =
2680  static_cast<DL> (dst_whichVectors.size ());
2681  Kokkos::View<DL*, HES> whichVectorsDst ("dstWhichVecs",
2682  dstNumWhichVecs);
2683  for (DL i = 0; i < dstNumWhichVecs; ++i) {
2684  whichVectorsDst(i) = dst_whichVectors[i];
2685  }
2686 
2687  Teuchos::ArrayView<const size_t> src_whichVectors =
2688  getMultiVectorWhichVectors (src);
2689  // Use the destination MultiVector's LocalOrdinal type here.
2690  const DL srcNumWhichVecs =
2691  static_cast<DL> (src_whichVectors.size ());
2692  Kokkos::View<DL*, HES> whichVectorsSrc ("srcWhichVecs",
2693  srcNumWhichVecs);
2694  for (DL i = 0; i < srcNumWhichVecs; ++i) {
2695  whichVectorsSrc(i) = src_whichVectors[i];
2696  }
2697 
2698  // Copy from the selected vectors of src to the selected
2699  // vectors of dst, on the host.
2700  Details::localDeepCopy (dst.template getLocalView<Kokkos::HostSpace> (),
2701  src.template getLocalView<Kokkos::HostSpace> (),
2702  dst.isConstantStride (),
2703  src.isConstantStride (),
2704  whichVectorsDst, whichVectorsSrc);
2705  // We can't sync src and repeat the above copy on the
2706  // host, so sync dst back to the host.
2707  //
2708  // FIXME (mfh 29 Jul 2014) This may overwrite columns that
2709  // don't actually belong to dst's view.
2710  dst.template sync<HES> ();
2711  }
2712  }
2713  }
2714  }
2715  }
2716 } // namespace Tpetra
2717 
2718 
2719 namespace Teuchos {
2720 
2721  // Give Teuchos::TypeNameTraits<Tpetra::MultiVector<...> > a
2722  // human-readable definition.
2723  template<class SC, class LO, class GO, class NT>
2724  class TypeNameTraits<Tpetra::MultiVector<SC, LO, GO, NT> > {
2725  public:
2726  static std::string name () {
2727  return std::string ("Tpetra::MultiVector<") +
2728  TypeNameTraits<SC>::name () + "," +
2729  TypeNameTraits<LO>::name () + "," +
2730  TypeNameTraits<GO>::name () + "," +
2731  TypeNameTraits<NT>::name () + ">";
2732  }
2733 
2734  static std::string
2735  concreteName (const Tpetra::MultiVector<SC, LO, GO, NT>&) {
2736  return name ();
2737  }
2738  };
2739 } // namespace Teuchos
2740 
2741 #endif // TPETRA_MULTIVECTOR_DECL_HPP
Base class for distributed Tpetra objects that support data redistribution.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createMultiVector(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const size_t numVectors)
Nonmember MultiVector "constructor": Create a MultiVector from a given Map.
Scalar scalar_type
This class&#39; first template parameter; the type of each entry in the MultiVector.
A distributed dense vector.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
Node::device_type device_type
The Kokkos device type.
Teuchos::Array< size_t > whichVectors_
Indices of columns this multivector is viewing.
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.
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.
One or more distributed dense vectors.
DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node >::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
void removeEmptyProcessesInPlace(Teuchos::RCP< DistObjectType > &input, const Teuchos::RCP< const Map< typename DistObjectType::local_ordinal_type, typename DistObjectType::global_ordinal_type, typename DistObjectType::node_type > > &newMap)
Remove processes which contain no elements in this object&#39;s Map.
MultiVector< ST, LO, GO, NT > createCopy(const MultiVector< ST, LO, GO, NT > &src)
Return a deep copy of the given MultiVector.
size_t getLocalLength() const
Local number of rows on the calling process.
int local_ordinal_type
Default value of Scalar template parameter.
size_t getNumVectors() const
Number of columns in the multivector.
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.
Implementation details of Tpetra.
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.
virtual bool useNewInterface()
Whether this class implements the old or new interface of DistObject.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, typename execution_space::execution_space > dual_view_type
Kokkos::DualView specialization used by this class.
std::enable_if< std::is_same< typename ViewType::value_type, mag_type >::value &&std::is_same< typename ViewType::memory_space, typename device_type::memory_space >::value >::type norm2(const ViewType &norms) const
Compute the two-norm of each vector (column), storing the result in a device view.
void sync()
Update data on device or host only if data in the other space has been marked as modified.
Node::execution_space execution_space
Type of the (new) Kokkos execution space.
std::enable_if< std::is_same< typename ViewType::value_type, mag_type >::value &&std::is_same< typename ViewType::memory_space, typename device_type::memory_space >::value >::type normInf(const ViewType &norms) const
Compute the infinity-norm of each vector (column), storing the result in a device view...
bool need_sync() const
Whether this MultiVector needs synchronization to the given space.
GlobalOrdinal global_ordinal_type
This class&#39; third template parameter; the type of global indices.
dual_view_type origView_
The "original view" of the MultiVector&#39;s data.
Node node_type
This class&#39; fourth template parameter; the Kokkos Node type.
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Rule for combining data in an Import or Export.
void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &src)
Copy the contents of src into *this (deep copy).
Forward declaration of Tpetra::MultiVector.
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.
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.
Abstract base class for objects that can be the source of an Import or Export operation.
Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner ("dot") product result.
dual_view_type view_
The Kokkos::DualView containing the MultiVector&#39;s data.
Forward declaration of Tpetra::Vector.
::Kokkos::Compat::KokkosDeviceWrapperNode< execution_space > node_type
Default value of Node template parameter.
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 setCopyOrView(const Teuchos::DataAccess copyOrView)
Set whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
Forward declaration of Tpetra::FEMultiVector.
Implementation of Tpetra::MultiVector::clone().
std::enable_if< std::is_same< typename ViewType::value_type, mag_type >::value &&std::is_same< typename ViewType::memory_space, typename device_type::memory_space >::value >::type norm1(const ViewType &norms) const
Compute the one-norm of each vector (column), storing the result in a device view.
Classes::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > MultiVector
Alias for Tpetra::Classes::MultiVector.
Kokkos::Details::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
Kokkos::Device specialization for communication buffers.
A parallel distribution of indices over processes.
EWhichNorm
Input argument for normImpl() (which see).
void modify()
Mark data as modified on the given device TargetDeviceType.
bool isConstantStride() const
Whether this multivector has constant stride between columns.
Forward declaration of Tpetra::Map.
Map< LocalOrdinal, GlobalOrdinal, Node > map_type
The type of the Map specialization used by this class.
LocalOrdinal local_ordinal_type
This class&#39; second template parameter; the type of local indices.
Teuchos::DataAccess getCopyOrView() const
Get whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
void deep_copy(MultiVector< ST, LO, GO, NT > &dst, const MultiVector< ST, LO, GO, NT > &src)
Specialization of deep_copy for MultiVector objects with the same template parameters.