Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_MultiVector_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_MULTIVECTOR_DECL_HPP
43 #define TPETRA_MULTIVECTOR_DECL_HPP
44 
47 
49 #include "Tpetra_Vector_fwd.hpp"
51 #include "Tpetra_DistObject.hpp"
52 #include "Tpetra_Map_fwd.hpp"
54 #include "Kokkos_DualView.hpp"
55 #include "Teuchos_BLAS_types.hpp"
56 #include "Teuchos_DataAccess.hpp"
57 #include "Teuchos_Range1D.hpp"
58 #include "Kokkos_ArithTraits.hpp"
59 #include "Kokkos_InnerProductSpaceTraits.hpp"
60 #include "Tpetra_KokkosRefactor_Details_MultiVectorLocalDeepCopy.hpp"
61 #include "Tpetra_Access.hpp"
62 #include "Tpetra_Details_WrappedDualView.hpp"
63 #include <type_traits>
64 
65 #ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
66 #ifndef DOXYGEN_SHOULD_SKIP_THIS
67 namespace Teuchos {
68  template<class OrdinalType, class ScalarType>
69  class SerialDenseMatrix; // forward declaration
70 }
71 #endif // DOXYGEN_SHOULD_SKIP_THIS
72 #endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
73 
74 
75 namespace Tpetra {
76 
77 
98  template <class DS, class DL, class DG, class DN,
99  class SS, class SL, class SG, class SN>
100  void
101  deep_copy (MultiVector<DS, DL, DG, DN>& dst,
102  const MultiVector<SS, SL, SG, SN>& src);
103 
104 #ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
105  template <class ST, class LO, class GO, class NT>
112  void
113  deep_copy (MultiVector<ST, LO, GO, NT>& dst,
114  const Teuchos::SerialDenseMatrix<int, ST>& src);
115 
122  template <class ST, class LO, class GO, class NT>
123  void
124  deep_copy (Teuchos::SerialDenseMatrix<int, ST>& dst,
125  const MultiVector<ST, LO, GO, NT>& src);
126 #endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
127 
135  template <class ST, class LO, class GO, class NT>
136  MultiVector<ST, LO, GO, NT>
137  createCopy (const MultiVector<ST, LO, GO, NT>& src);
138 
148  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
149  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
150  createMultiVector (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map,
151  const size_t numVectors);
152 
153  // WARNING NOT FOR USERS
154  // This means we don't need to make MultiVector a friend of
155  // Vector or of itself (with different template parameters).
156  template<class SC, class LO, class GO, class NT>
157  Teuchos::ArrayView<const size_t>
158  getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X);
159 
160 
380  template <class Scalar,
381  class LocalOrdinal,
382  class GlobalOrdinal,
383  class Node>
384  class MultiVector :
385  public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node>
386  {
387  public:
389 
390 
392  using scalar_type = Scalar;
408  using impl_scalar_type =
409  typename Kokkos::Details::ArithTraits<Scalar>::val_type;
410 
420  using node_type = typename map_type::node_type;
421 
427  using dot_type =
428  typename Kokkos::Details::InnerProductSpaceTraits<impl_scalar_type>::dot_type;
429 
436  using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
437 
442  using execution_space = typename device_type::execution_space;
443 
466  using dual_view_type = Kokkos::DualView<impl_scalar_type**,
467  Kokkos::LayoutLeft,
469  using wrapped_dual_view_type = Details::WrappedDualView<dual_view_type>;
470 
471  using host_view_type = typename dual_view_type::t_host;
472  using device_view_type = typename dual_view_type::t_dev;
473 
475 
477 
479  MultiVector ();
480 
487  MultiVector (const Teuchos::RCP<const map_type>& map,
488  const size_t numVecs,
489  const bool zeroOut = true);
490 
502  const Teuchos::DataAccess copyOrView);
503 
519  MultiVector (const Teuchos::RCP<const map_type>& map,
520  const Teuchos::ArrayView<const Scalar>& A,
521  const size_t LDA,
522  const size_t NumVectors);
523 
537  MultiVector (const Teuchos::RCP<const map_type>& map,
538  const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar> >&ArrayOfPtrs,
539  const size_t NumVectors);
540 
553  MultiVector (const Teuchos::RCP<const map_type>& map,
554  const dual_view_type& view);
555 
594  MultiVector (const Teuchos::RCP<const map_type>& map,
595  const typename dual_view_type::t_dev& d_view);
596 
619  MultiVector (const Teuchos::RCP<const map_type>& map,
620  const dual_view_type& view,
621  const dual_view_type& origView);
622 
631  MultiVector (const Teuchos::RCP<const map_type>& map,
632  const wrapped_dual_view_type& d_view);
633 
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 
684  MultiVector (const Teuchos::RCP<const map_type>& map,
685  const wrapped_dual_view_type& view,
686  const Teuchos::ArrayView<const size_t>& whichVectors);
687 
688 
716  MultiVector (const Teuchos::RCP<const map_type>& map,
717  const dual_view_type& view,
718  const dual_view_type& origView,
719  const Teuchos::ArrayView<const size_t>& whichVectors);
720 
782  const Teuchos::RCP<const map_type>& subMap,
783  const local_ordinal_type rowOffset = 0);
784 
792  const map_type& subMap,
793  const size_t offset = 0);
794 
804 
807 
815 
819 
829  virtual ~MultiVector () = default;
830 
833 
835 
837 
838  protected:
843  static const bool useAtomicUpdatesByDefault =
844 #ifdef KOKKOS_ENABLE_SERIAL
845  ! std::is_same<execution_space, Kokkos::Serial>::value;
846 #else
847  true;
848 #endif // KOKKOS_ENABLE_SERIAL
849 
850  public:
880  void
881  replaceGlobalValue (const GlobalOrdinal gblRow,
882  const size_t col,
883  const impl_scalar_type& value);
884 
917  template<typename T>
918  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
919  replaceGlobalValue (GlobalOrdinal globalRow,
920  size_t col,
921  const T& value)
922  {
923  replaceGlobalValue (globalRow, col, static_cast<impl_scalar_type> (value));
924  }
925 
950  void
951  sumIntoGlobalValue (const GlobalOrdinal gblRow,
952  const size_t col,
953  const impl_scalar_type& value,
954  const bool atomic = useAtomicUpdatesByDefault);
955 
984  template<typename T>
985  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
986  sumIntoGlobalValue (const GlobalOrdinal gblRow,
987  const size_t col,
988  const T& val,
989  const bool atomic = useAtomicUpdatesByDefault)
990  {
991  sumIntoGlobalValue (gblRow, col, static_cast<impl_scalar_type> (val), atomic);
992  }
993 
1023  void
1024  replaceLocalValue (const LocalOrdinal lclRow,
1025  const size_t col,
1026  const impl_scalar_type& value);
1027 
1061  template<typename T>
1062  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1063  replaceLocalValue (const LocalOrdinal lclRow,
1064  const size_t col,
1065  const T& val)
1066  {
1067  replaceLocalValue (lclRow, col, static_cast<impl_scalar_type> (val));
1068  }
1069 
1094  void
1095  sumIntoLocalValue (const LocalOrdinal lclRow,
1096  const size_t col,
1097  const impl_scalar_type& val,
1098  const bool atomic = useAtomicUpdatesByDefault);
1099 
1126  template<typename T>
1127  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1128  sumIntoLocalValue (const LocalOrdinal lclRow,
1129  const size_t col,
1130  const T& val,
1131  const bool atomic = useAtomicUpdatesByDefault)
1132  {
1133  sumIntoLocalValue (lclRow, col, static_cast<impl_scalar_type> (val), atomic);
1134  }
1135 
1137  void putScalar (const Scalar& value);
1138 
1147  template<typename T>
1148  typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1149  putScalar (const T& value)
1150  {
1151  putScalar (static_cast<impl_scalar_type> (value));
1152  }
1153 
1166  void randomize();
1167 
1181  void randomize (const Scalar& minVal, const Scalar& maxVal);
1182 
1248  void replaceMap (const Teuchos::RCP<const map_type>& map);
1249 
1256  void reduce();
1257 
1259 
1285 
1286 
1288  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1289  subCopy (const Teuchos::Range1D& colRng) const;
1290 
1292  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1293  subCopy (const Teuchos::ArrayView<const size_t>& cols) const;
1294 
1296  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1297  subView (const Teuchos::Range1D& colRng) const;
1298 
1300  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1301  subView (const Teuchos::ArrayView<const size_t>& cols) const;
1302 
1304  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1305  subViewNonConst (const Teuchos::Range1D& colRng);
1306 
1308  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1309  subViewNonConst (const Teuchos::ArrayView<const size_t>& cols);
1310 
1373  Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1374  offsetView (const Teuchos::RCP<const map_type>& subMap,
1375  const size_t offset) const;
1376 
1394  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1395  offsetViewNonConst (const Teuchos::RCP<const map_type>& subMap,
1396  const size_t offset);
1397 
1399  Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1400  getVector (const size_t j) const;
1401 
1403  Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1404  getVectorNonConst (const size_t j);
1405 
1407  Teuchos::ArrayRCP<const Scalar> getData (size_t j) const;
1408 
1410  Teuchos::ArrayRCP<Scalar> getDataNonConst (size_t j);
1411 
1419  void
1420  get1dCopy (const Teuchos::ArrayView<Scalar>& A,
1421  const size_t LDA) const;
1422 
1429  void
1430  get2dCopy (const Teuchos::ArrayView<const Teuchos::ArrayView<Scalar> >& ArrayOfPtrs) const;
1431 
1437  Teuchos::ArrayRCP<const Scalar> get1dView () const;
1438 
1440  Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> > get2dView () const;
1441 
1447  Teuchos::ArrayRCP<Scalar> get1dViewNonConst ();
1448 
1450  Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > get2dViewNonConst ();
1451 
1454  typename dual_view_type::t_host::const_type getLocalViewHost(Access::ReadOnlyStruct) const;
1455 
1458  typename dual_view_type::t_host getLocalViewHost(Access::ReadWriteStruct);
1459 
1462  typename dual_view_type::t_host getLocalViewHost(Access::OverwriteAllStruct);
1463 
1466  typename dual_view_type::t_dev::const_type getLocalViewDevice(Access::ReadOnlyStruct) const;
1467 
1470  typename dual_view_type::t_dev getLocalViewDevice(Access::ReadWriteStruct);
1471 
1474  typename dual_view_type::t_dev getLocalViewDevice(Access::OverwriteAllStruct);
1475 
1477  template<class TargetDeviceType>
1478  bool need_sync () const {
1479  return view_.getDualView().template need_sync<TargetDeviceType> ();
1480  }
1481 
1483  bool need_sync_host () const;
1484 
1486  bool need_sync_device () const;
1487 
1516  template<class TargetDeviceType>
1517  typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type::const_type
1518  getLocalView (Access::ReadOnlyStruct s) const
1519  {
1520  return view_.template getView<TargetDeviceType>(s);
1521  }
1522 
1523 
1524  template<class TargetDeviceType>
1525  typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1526  getLocalView (Access::ReadWriteStruct s)
1527  {
1528  return view_.template getView<TargetDeviceType>(s);
1529  }
1530 
1531  template<class TargetDeviceType>
1532  typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1533  getLocalView (Access::OverwriteAllStruct s)
1534  {
1535  return view_.template getView<TargetDeviceType>(s);
1536  }
1537 
1539 
1541 
1555  void
1556  dot (const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
1557  const Teuchos::ArrayView<dot_type>& dots) const;
1558 
1570  template <typename T>
1571  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1573  const Teuchos::ArrayView<T> &dots) const
1574  {
1575  const size_t sz = static_cast<size_t> (dots.size ());
1576  Teuchos::Array<dot_type> dts (sz);
1577  this->dot (A, dts);
1578  for (size_t i = 0; i < sz; ++i) {
1579  // If T and dot_type differ, this does an implicit conversion.
1580  dots[i] = dts[i];
1581  }
1582  }
1583 
1585  template <typename T>
1586  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1588  std::vector<T>& dots) const
1589  {
1590  const size_t sz = dots.size ();
1591  Teuchos::Array<dot_type> dts (sz);
1592  this->dot (A, dts);
1593  for (size_t i = 0; i < sz; ++i) {
1594  // If T and dot_type differ, this does an implicit conversion.
1595  dots[i] = dts[i];
1596  }
1597  }
1598 
1616  void
1618  const Kokkos::View<dot_type*, Kokkos::HostSpace>& norms) const;
1619 
1620  template<class ViewType>
1621  void
1622  dot (typename std::enable_if<std::is_same<typename ViewType::value_type,dot_type>::value &&
1623  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value,
1625  const ViewType& dots) const {
1626  const Kokkos::View<dot_type*, Kokkos::HostSpace> h_dots("Tpetra::Dots",dots.extent(0));
1627  this->dot (A, h_dots);
1628  // DEEP_COPY REVIEW - NOT TESTED
1629  Kokkos::deep_copy(dots,h_dots);
1630  }
1631 
1644  template <typename T>
1645  typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1647  const Kokkos::View<T*, device_type>& dots) const
1648  {
1649  const size_t numDots = dots.extent (0);
1650  Kokkos::View<dot_type*, device_type> dts ("MV::dot tmp", numDots);
1651  // Call overload that takes a Kokkos::View<dot_type*, device_type>.
1652  this->dot (A, dts);
1653  // FIXME (mfh 14 Jul 2014) Does this actually work if dot_type
1654  // and T differ? We would need a test for this, but only the
1655  // Sacado and Stokhos packages are likely to care about this use
1656  // case. It could also come up for Kokkos::complex ->
1657  // std::complex conversions, but those two implementations
1658  // should generally be bitwise compatible.
1659  // CT: no this can't possible work .....
1660  // DEEP_COPY REVIEW - NOT TESTED
1661  Kokkos::deep_copy (dots, dts);
1662  }
1663 
1666 
1669 
1677  void scale (const Scalar& alpha);
1678 
1687  void scale (const Teuchos::ArrayView<const Scalar>& alpha);
1688 
1697  void scale (const Kokkos::View<const impl_scalar_type*, device_type>& alpha);
1698 
1707  void
1708  scale (const Scalar& alpha,
1710 
1717  void
1718  update (const Scalar& alpha,
1720  const Scalar& beta);
1721 
1728  void
1729  update (const Scalar& alpha,
1731  const Scalar& beta,
1733  const Scalar& gamma);
1734 
1746  void
1747  norm1 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1748 
1749  template<class ViewType>
1750  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1751  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1752  norm1 (const ViewType& norms) const {
1753  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1754  // this method to be templated. (It only exists in case
1755  // HostSpace = device_type::memory_space.)
1756  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1757  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1758  this->norm1 (h_norms);
1759  // DEEP_COPY REVIEW - HOST-TO-DEVICE
1760  Kokkos::deep_copy (execution_space(), norms, h_norms);
1761  }
1762 
1778  template <typename T>
1779  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1780  norm1 (const Kokkos::View<T*, device_type>& norms) const
1781  {
1782  const size_t numNorms = norms.extent (0);
1783  Kokkos::View<mag_type*, device_type> tmpNorms ("MV::norm1 tmp", numNorms);
1784  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1785  this->norm1 (tmpNorms);
1786  // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1787  // and T differ? We would need a test for this, but only the
1788  // Sacado and Stokhos packages are likely to care about this use
1789  // case. It could also come up with Kokkos::complex ->
1790  // std::complex conversion.
1791  // DEEP_COPY REVIEW - NOT TESTED
1792  Kokkos::deep_copy (norms, tmpNorms);
1793  }
1794 
1798  void norm1 (const Teuchos::ArrayView<mag_type>& norms) const;
1799 
1814  template <typename T>
1815  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1816  norm1 (const Teuchos::ArrayView<T>& norms) const
1817  {
1818  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1819  const size_type sz = norms.size ();
1820  Teuchos::Array<mag_type> theNorms (sz);
1821  this->norm1 (theNorms);
1822  for (size_type i = 0; i < sz; ++i) {
1823  // If T and mag_type differ, this does an implicit conversion.
1824  norms[i] = theNorms[i];
1825  }
1826  }
1827 
1840  void
1841  norm2 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1842 
1843  template<class ViewType>
1844  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1845  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1846  norm2 (const ViewType& norms) const {
1847  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1848  // this method to be templated. (It only exists in case
1849  // HostSpace = device_type::memory_space.)
1850  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1851  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1852  this->norm2 (h_norms);
1853  // DEEP_COPY REVIEW - NOT TESTED
1854  Kokkos::deep_copy (norms, h_norms);
1855  }
1856 
1870  template<typename T>
1871  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1872  norm2 (const Kokkos::View<T*, device_type>& norms) const
1873  {
1874  const size_t numNorms = norms.extent (0);
1875  Kokkos::View<mag_type*, device_type> theNorms ("MV::norm2 tmp", numNorms);
1876  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1877  this->norm2 (theNorms);
1878  // FIXME (mfh 14 Jul 2014) Does this actually work if mag_type
1879  // and T differ? We would need a test for this, but only the
1880  // Sacado and Stokhos packages are likely to care about this use
1881  // case. This could also come up with Kokkos::complex ->
1882  // std::complex conversion.
1883  // DEEP_COPY REVIEW - NOT TESTED
1884  Kokkos::deep_copy (norms, theNorms);
1885  }
1886 
1890  void norm2 (const Teuchos::ArrayView<mag_type>& norms) const;
1891 
1906  template <typename T>
1907  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1908  norm2 (const Teuchos::ArrayView<T>& norms) const
1909  {
1910  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1911  const size_type sz = norms.size ();
1912  Teuchos::Array<mag_type> theNorms (sz);
1913  this->norm2 (theNorms);
1914  for (size_type i = 0; i < sz; ++i) {
1915  // If T and mag_type differ, this does an implicit conversion.
1916  norms[i] = theNorms[i];
1917  }
1918  }
1919 
1926  void normInf (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1927 
1928  template<class ViewType>
1929  typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1930  std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1931  normInf (const ViewType& norms) const {
1932  // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1933  // this method to be templated. (It only exists in case
1934  // HostSpace = device_type::memory_space.)
1935  using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1936  host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1937  this->normInf (h_norms);
1938  // DEEP_COPY REVIEW - HOST-TO-DEVICE
1939  Kokkos::deep_copy (execution_space(), norms, h_norms);
1940  }
1941 
1955  template<typename T>
1956  typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1957  normInf (const Kokkos::View<T*, device_type>& norms) const
1958  {
1959  const size_t numNorms = norms.extent (0);
1960  Kokkos::View<mag_type*, device_type> theNorms ("MV::normInf tmp", numNorms);
1961  // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1962  this->normInf (theNorms);
1963  // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1964  // and T differ? We would need a test for this, but only the
1965  // Sacado and Stokhos packages are likely to care about this use
1966  // case. This could also come up with Kokkos::complex ->
1967  // std::complex conversion.
1968  // DEEP_COPY REVIEW - NOT TESTED
1969  Kokkos::deep_copy (norms, theNorms);
1970  }
1971 
1976  void normInf (const Teuchos::ArrayView<mag_type>& norms) const;
1977 
1993  template <typename T>
1994  typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1995  normInf (const Teuchos::ArrayView<T>& norms) const
1996  {
1997  typedef typename Teuchos::ArrayView<T>::size_type size_type;
1998  const size_type sz = norms.size ();
1999  Teuchos::Array<mag_type> theNorms (sz);
2000  this->norm2 (theNorms);
2001  for (size_type i = 0; i < sz; ++i) {
2002  // If T and mag_type differ, this does an implicit conversion.
2003  norms[i] = theNorms[i];
2004  }
2005  }
2006 
2007 
2012  void meanValue (const Teuchos::ArrayView<impl_scalar_type>& means) const;
2013 
2014  template <typename T>
2015  typename std::enable_if<! std::is_same<impl_scalar_type, T>::value, void>::type
2016  meanValue (const Teuchos::ArrayView<T>& means) const
2017  {
2018  typedef typename Teuchos::Array<T>::size_type size_type;
2019  const size_type numMeans = means.size ();
2020 
2021  Teuchos::Array<impl_scalar_type> theMeans (numMeans);
2022  this->meanValue (theMeans ());
2023  for (size_type k = 0; k < numMeans; ++k) {
2024  means[k] = static_cast<T> (theMeans[k]);
2025  }
2026  }
2027 
2033  void
2034  multiply (Teuchos::ETransp transA,
2035  Teuchos::ETransp transB,
2036  const Scalar& alpha,
2037  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2038  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2039  const Scalar& beta);
2040 
2061  void
2062  elementWiseMultiply (Scalar scalarAB,
2063  const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2064  const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2065  Scalar scalarThis);
2067 
2069 
2071  size_t getNumVectors() const;
2072 
2074  size_t getLocalLength() const;
2075 
2078 
2084  size_t getStride() const;
2085 
2089  bool isConstantStride() const;
2090 
2094  bool aliases(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& other) const;
2095 
2097 
2099 
2100 
2102  virtual std::string description() const;
2103 
2132  virtual void
2133  describe (Teuchos::FancyOStream& out,
2134  const Teuchos::EVerbosityLevel verbLevel =
2135  Teuchos::Describable::verbLevel_default) const;
2137 
2151  virtual void
2152  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
2153 
2164  void setCopyOrView (const Teuchos::DataAccess copyOrView) {
2165  TEUCHOS_TEST_FOR_EXCEPTION(
2166  copyOrView == Teuchos::Copy, std::invalid_argument,
2167  "Tpetra::MultiVector::setCopyOrView: The Kokkos refactor version of "
2168  "MultiVector _only_ implements view semantics. You may not call this "
2169  "method with copyOrView = Teuchos::Copy. The only valid argument is "
2170  "Teuchos::View.");
2171  }
2172 
2176  // This method ONLY exists for the circa 2014 "Kokkos refactor"
2177  // effort. It ALWAYS returns Teuchos::View.
2181  Teuchos::DataAccess getCopyOrView () const {
2182  return Teuchos::View;
2183  }
2184 
2199  void
2201 
2204  template <class T>
2205  Teuchos::RCP<MultiVector<T, LocalOrdinal, GlobalOrdinal, Node> >
2206  convert () const;
2207 
2208 
2209  // \brief Checks to see if the local length, number of vectors and size of Scalar type match
2218 
2219  private:
2221  using base_type = DistObject<scalar_type, local_ordinal_type,
2223 
2224  protected:
2225  template <class DS, class DL, class DG, class DN,
2226  class SS, class SL, class SG, class SN>
2227  friend void
2229  const MultiVector<SS, SL, SG, SN>& src);
2230 
2237  mutable wrapped_dual_view_type view_;
2238 
2251  Teuchos::Array<size_t> whichVectors_;
2252 
2253  template<class SC, class LO, class GO, class NT>
2254  friend ::Teuchos::ArrayView<const size_t> getMultiVectorWhichVectors (const ::Tpetra::MultiVector<SC, LO, GO, NT>& X);
2255 
2257 
2259 
2266  std::string
2267  descriptionImpl (const std::string& className) const;
2268 
2275  std::string
2276  localDescribeToString (const Teuchos::EVerbosityLevel vl) const;
2277 
2291  void
2292  describeImpl (Teuchos::FancyOStream& out,
2293  const std::string& className,
2294  const Teuchos::EVerbosityLevel verbLevel =
2295  Teuchos::Describable::verbLevel_default) const;
2296 
2297  // Return true if and only if VectorIndex is a valid column index.
2298  bool vectorIndexOutOfRange (const size_t VectorIndex) const;
2299 
2304  template <class T>
2305  Teuchos::ArrayRCP<T>
2306  getSubArrayRCP (Teuchos::ArrayRCP<T> arr, size_t j) const;
2307 
2309  size_t getOrigNumLocalRows () const;
2310 
2312  size_t getOrigNumLocalCols () const;
2313 
2315 
2317 
2322  using buffer_device_type =
2323  typename DistObject<scalar_type,
2327 
2332  virtual bool
2333  checkSizes (const SrcDistObject& sourceObj);
2334 
2336  virtual size_t constantNumberOfPackets () const;
2337 
2338  virtual void
2339  copyAndPermute
2340  (const SrcDistObject& sourceObj,
2341  const size_t numSameIDs,
2342  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs,
2343  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs,
2344  const CombineMode CM);
2345 
2346  virtual void
2347  packAndPrepare
2348  (const SrcDistObject& sourceObj,
2349  const Kokkos::DualView<
2350  const local_ordinal_type*,
2351  buffer_device_type>& exportLIDs,
2352  Kokkos::DualView<
2354  buffer_device_type>& exports,
2355  Kokkos::DualView<
2356  size_t*,
2357  buffer_device_type> /* numPacketsPerLID */,
2358  size_t& constantNumPackets);
2359 
2360  virtual void
2361  unpackAndCombine
2362  (const Kokkos::DualView<
2363  const local_ordinal_type*,
2364  buffer_device_type>& importLIDs,
2365  Kokkos::DualView<
2367  buffer_device_type> imports,
2368  Kokkos::DualView<
2369  size_t*,
2370  buffer_device_type> /* numPacketsPerLID */,
2371  const size_t constantNumPackets,
2372  const CombineMode CM);
2373 
2374  private:
2375 
2376  // If comm buffers can be aliased to the data view, use this
2377  // implementation.
2378  template<class NO=Node>
2379  typename std::enable_if<std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2380  typename NO::device_type::memory_space>::value, bool>::type
2381  reallocImportsIfNeededImpl (const size_t newSize,
2382  const bool verbose,
2383  const std::string* prefix,
2384  const bool areRemoteLIDsContiguous,
2385  const CombineMode CM);
2386 
2387  // If comm buffers cannot be aliased to the data view, use this
2388  // implementation. (Just calls DistObject::reallocImportsIfNeeded.)
2389  template<class NO=Node>
2390  typename std::enable_if<!std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2391  typename NO::device_type::memory_space>::value, bool>::type
2392  reallocImportsIfNeededImpl (const size_t newSize,
2393  const bool verbose,
2394  const std::string* prefix,
2395  const bool areRemoteLIDsContiguous,
2396  const CombineMode CM);
2397  protected:
2398 
2399  virtual bool
2400  reallocImportsIfNeeded (const size_t newSize,
2401  const bool verbose,
2402  const std::string* prefix,
2403  const bool areRemoteLIDsContiguous=false,
2404  const CombineMode CM=INSERT);
2405 
2406 
2407  public:
2408  bool importsAreAliased();
2409 
2410  protected:
2411  Kokkos::DualView<impl_scalar_type*, buffer_device_type> unaliased_imports_;
2412 
2414  }; // class MultiVector
2415 
2416  template<class SC, class LO, class GO, class NT>
2417  Teuchos::ArrayView<const size_t>
2418  getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X)
2419  {
2420  return X.whichVectors_ ();
2421  }
2422 
2423 
2426  template <class ST, class LO, class GO, class NT>
2427  void
2429  const MultiVector<ST, LO, GO, NT>& src)
2430  {
2431  // NOTE (mfh 11 Sep 2014) We can't implement deep_copy with
2432  // shallow-copy operator=, because that would invalidate existing
2433  // views of dst!
2434  dst.assign (src);
2435  }
2436 
2437  // Implementation of the most generic version of MultiVector deep_copy.
2438  template <class DS, class DL, class DG, class DN,
2439  class SS, class SL, class SG, class SN>
2440  void
2442  const MultiVector<SS, SL, SG, SN>& src)
2443  {
2444  using ::Tpetra::getMultiVectorWhichVectors;
2445 
2446  TEUCHOS_TEST_FOR_EXCEPTION(
2447  dst.getGlobalLength () != src.getGlobalLength () ||
2448  dst.getNumVectors () != src.getNumVectors (), std::invalid_argument,
2449  "Tpetra::deep_copy: Global dimensions of the two Tpetra::MultiVector "
2450  "objects do not match. src has dimensions [" << src.getGlobalLength ()
2451  << "," << src.getNumVectors () << "], and dst has dimensions ["
2452  << dst.getGlobalLength () << "," << dst.getNumVectors () << "].");
2453 
2454  // FIXME (mfh 28 Jul 2014) Don't throw; just set a local error flag.
2455  TEUCHOS_TEST_FOR_EXCEPTION(
2456  dst.getLocalLength () != src.getLocalLength (), std::invalid_argument,
2457  "Tpetra::deep_copy: The local row counts of the two Tpetra::MultiVector "
2458  "objects do not match. src has " << src.getLocalLength () << " row(s) "
2459  << " and dst has " << dst.getLocalLength () << " row(s).");
2460 
2461  const bool srcMostUpToDateOnDevice = ! src.need_sync_device ();
2462 
2463  if (src.isConstantStride () && dst.isConstantStride ()) {
2464  if (srcMostUpToDateOnDevice) {
2466  dst.getLocalViewDevice (Access::OverwriteAll),
2467  src.getLocalViewDevice (Access::ReadOnly));
2468  }
2469  else {
2471  dst.getLocalViewDevice (Access::OverwriteAll),
2472  src.getLocalViewHost (Access::ReadOnly));
2473  }
2474  }
2475  else {
2476  auto dstWhichVecs = getMultiVectorWhichVectors (dst);
2477  auto srcWhichVecs = getMultiVectorWhichVectors (src);
2478 
2479  if (srcMostUpToDateOnDevice) {
2480  Details::localDeepCopy (dst.getLocalViewDevice (Access::OverwriteAll),
2481  src.getLocalViewDevice (Access::ReadOnly),
2482  dst.isConstantStride (),
2483  src.isConstantStride (),
2484  dstWhichVecs,
2485  srcWhichVecs);
2486  }
2487  else {
2488  Details::localDeepCopy (dst.getLocalViewDevice (Access::OverwriteAll),
2489  src.getLocalViewHost (Access::ReadOnly),
2490  dst.isConstantStride (),
2491  src.isConstantStride (),
2492  dstWhichVecs,
2493  srcWhichVecs);
2494  }
2495  }
2496  }
2497 } // namespace Tpetra
2498 
2499 
2500 namespace Teuchos {
2501 
2502  // Give Teuchos::TypeNameTraits<Tpetra::MultiVector<...> > a
2503  // human-readable definition.
2504  template<class SC, class LO, class GO, class NT>
2505  class TypeNameTraits<Tpetra::MultiVector<SC, LO, GO, NT> > {
2506  public:
2507  static std::string name () {
2508  return std::string ("Tpetra::MultiVector<") +
2509  TypeNameTraits<SC>::name () + "," +
2510  TypeNameTraits<LO>::name () + "," +
2511  TypeNameTraits<GO>::name () + "," +
2512  TypeNameTraits<NT>::name () + ">";
2513  }
2514 
2515  static std::string
2516  concreteName (const Tpetra::MultiVector<SC, LO, GO, NT>&) {
2517  return name ();
2518  }
2519  };
2520 } // namespace Teuchos
2521 
2522 #endif // TPETRA_MULTIVECTOR_DECL_HPP
typename map_type::global_ordinal_type global_ordinal_type
The type of global indices that this class uses.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createMultiVector(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const size_t numVectors)
Nonmember MultiVector &quot;constructor&quot;: Create a MultiVector from a given Map.
Teuchos::RCP< const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subView(const Teuchos::Range1D &colRng) const
Return a const MultiVector with const views of selected columns.
typename map_type::local_ordinal_type local_ordinal_type
The type of local indices that this class uses.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type sumIntoLocalValue(const LocalOrdinal lclRow, const size_t col, const T &val, const bool atomic=useAtomicUpdatesByDefault)
Like the above sumIntoLocalValue, but only enabled if T differs from impl_scalar_type.
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.
typename device_type::execution_space execution_space
Type of the (new) Kokkos execution space.
void sumIntoLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &val, const bool atomic=useAtomicUpdatesByDefault)
Update (+=) a value in host memory, using local row index.
GlobalOrdinal global_ordinal_type
The type of global indices.
Teuchos::ArrayRCP< Scalar > get1dViewNonConst()
Nonconst persisting (1-D) view of this multivector&#39;s local values.
void meanValue(const Teuchos::ArrayView< impl_scalar_type > &means) const
Compute mean (average) value of each column.
virtual bool reallocImportsIfNeeded(const size_t newSize, const bool verbose, const std::string *prefix, const bool areRemoteLIDsContiguous=false, const CombineMode CM=INSERT)
Reallocate imports_ if needed.
Teuchos::RCP< const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > offsetView(const Teuchos::RCP< const map_type > &subMap, const size_t offset) const
Return a const view of a subset of rows.
void get2dCopy(const Teuchos::ArrayView< const Teuchos::ArrayView< Scalar > > &ArrayOfPtrs) const
Fill the given array with a copy of this multivector&#39;s local values.
void localDeepCopyConstStride(const DstViewType &dst, const SrcViewType &src)
Implementation of Tpetra::MultiVector deep copy of local data, for when both the source and destinati...
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
size_t getNumVectors() const
Number of columns in the multivector.
size_t getLocalLength() const
Local number of rows on the calling process.
void replaceMap(const Teuchos::RCP< const map_type > &map)
Replace the underlying Map in place.
Teuchos::ArrayRCP< Teuchos::ArrayRCP< Scalar > > get2dViewNonConst()
Return non-const persisting pointers to values.
bool isConstantStride() const
Whether this multivector has constant stride between columns.
typename map_type::device_type device_type
This class&#39; preferred Kokkos device type.
std::string localDescribeToString(const Teuchos::EVerbosityLevel vl) const
Print the calling process&#39; verbose describe() information to the returned string. ...
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subCopy(const Teuchos::Range1D &colRng) const
Return a MultiVector with copies of selected columns.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type replaceLocalValue(const LocalOrdinal lclRow, const size_t col, const T &val)
Like the above replaceLocalValue, but only enabled if T differs from impl_scalar_type.
typename Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
void get1dCopy(const Teuchos::ArrayView< Scalar > &A, const size_t LDA) const
Fill the given array with a copy of this multivector&#39;s local values.
MultiVector< ST, LO, GO, NT > createCopy(const MultiVector< ST, LO, GO, NT > &src)
Return a deep copy of the given MultiVector.
void replaceLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &value)
Replace value in host memory, using local (row) index.
static const bool useAtomicUpdatesByDefault
Whether sumIntoLocalValue and sumIntoGlobalValue should use atomic updates by default.
Teuchos::Array< size_t > whichVectors_
Indices of columns this multivector is viewing.
std::remove_reference< decltype(std::declval< dual_view_type >).template view< TargetDeviceType >))>::type::const_type getLocalView(Access::ReadOnlyStruct s) const
Return a view of the local data on a specific device, with the given access mode. The return type is ...
bool need_sync_device() const
Whether this MultiVector needs synchronization to the device.
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy assigment (shallow copy).
bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
size_t getOrigNumLocalCols() const
&quot;Original&quot; number of columns in the (local) data.
Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
size_t global_size_t
Global size_t object.
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
dual_view_type::t_host::const_type getLocalViewHost(Access::ReadOnlyStruct) const
Return a read-only, up-to-date view of this MultiVector&#39;s local data on host. This requires that ther...
Insert new values that don&#39;t currently exist.
void scale(const Scalar &alpha)
Scale in place: this = alpha*this.
void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &beta)
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)
Update: this = beta*this + alpha*A.
wrapped_dual_view_type view_
The Kokkos::DualView containing the MultiVector&#39;s data.
void elementWiseMultiply(Scalar scalarAB, const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Scalar scalarThis)
Multiply a Vector A elementwise by a MultiVector B.
Teuchos::RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(const size_t j)
Return a Vector which is a nonconst view of column j.
void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &src)
Copy the contents of src into *this (deep copy).
std::string descriptionImpl(const std::string &className) const
Implementation of description() for this class, and its subclass Vector.
void normInf(const Kokkos::View< mag_type *, Kokkos::HostSpace > &norms) const
Compute the infinity-norm of each vector (column), storing the result in a host View.
CombineMode
Rule for combining data in an Import or Export.
Forward declaration of Tpetra::MultiVector.
void norm2(const Kokkos::View< mag_type *, Kokkos::HostSpace > &norms) const
Compute the two-norm of each vector (column), storing the result in a host View.
Scalar scalar_type
The type of each entry in the MultiVector.
Teuchos::RCP< MultiVector< T, LocalOrdinal, GlobalOrdinal, Node > > convert() const
Return another MultiVector with the same entries, but converted to a different Scalar type T...
void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< dot_type > &dots) const
Compute the dot product of each corresponding pair of vectors (columns) in A and B.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subViewNonConst(const Teuchos::Range1D &colRng)
Return a MultiVector with views of selected columns.
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.
Abstract base class for objects that can be the source of an Import or Export operation.
Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
bool need_sync() const
Whether this MultiVector needs synchronization to the given space.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, device_type > dual_view_type
Kokkos::DualView specialization used by this class.
void swap(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &mv)
Swap contents of mv with contents of *this.
void replaceGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value)
Replace value in host memory, using global row index.
void randomize()
Set all values in the multivector to pseudorandom numbers.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > offsetViewNonConst(const Teuchos::RCP< const map_type > &subMap, const size_t offset)
Return a nonconst view of a subset of rows.
dual_view_type::t_dev::const_type getLocalViewDevice(Access::ReadOnlyStruct) const
Return a read-only, up-to-date view of this MultiVector&#39;s local data on device. This requires that th...
Teuchos::ArrayRCP< T > getSubArrayRCP(Teuchos::ArrayRCP< T > arr, size_t j) const
Persisting view of j-th column in the given ArrayRCP.
Forward declaration of Tpetra::Vector.
Teuchos::RCP< const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVector(const size_t j) const
Return a Vector which is a const view of column j.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type replaceGlobalValue(GlobalOrdinal globalRow, size_t col, const T &value)
Like the above replaceGlobalValue, but only enabled if T differs from impl_scalar_type.
typename map_type::node_type node_type
Legacy thing that you should not use any more.
MultiVector()
Default constructor: makes a MultiVector with no rows or columns.
bool aliases(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &other) const
Whether this multivector&#39;s memory might alias other. This is conservative: if either this or other is...
Forward declaration of Tpetra::FEMultiVector.
Teuchos::DataAccess getCopyOrView() const
Get whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type sumIntoGlobalValue(const GlobalOrdinal gblRow, const size_t col, const T &val, const bool atomic=useAtomicUpdatesByDefault)
Like the above sumIntoGlobalValue, but only enabled if T differs from impl_scalar_type.
void setCopyOrView(const Teuchos::DataAccess copyOrView)
Set whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
void norm1(const Kokkos::View< mag_type *, Kokkos::HostSpace > &norms) const
Compute the one-norm of each vector (column), storing the result in a host view.
A parallel distribution of indices over processes.
virtual ~MultiVector()=default
Destructor (virtual for memory safety of derived classes).
size_t getStride() const
Stride between columns in the multivector.
typename Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner (&quot;dot&quot;) product result.
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.
virtual bool checkSizes(const SrcDistObject &sourceObj)
Whether data redistribution between sourceObj and this object is legal.
typename DistObject< scalar_type, local_ordinal_type, global_ordinal_type, node_type >::buffer_device_type buffer_device_type
typename Node::device_type device_type
This class&#39; Kokkos::Device specialization.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type putScalar(const T &value)
Set all values in the multivector with the given value.
void sumIntoGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value, const bool atomic=useAtomicUpdatesByDefault)
Update (+=) a value in host memory, using global row index.
Teuchos::ArrayRCP< Teuchos::ArrayRCP< const Scalar > > get2dView() const
Return const persisting pointers to values.
void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,j).
Base class for distributed Tpetra objects that support data redistribution.
void localDeepCopy(const DstViewType &dst, const SrcViewType &src, const bool dstConstStride, const bool srcConstStride, const DstWhichVecsType &dstWhichVecs, const SrcWhichVecsType &srcWhichVecs)
Implementation of Tpetra::MultiVector deep copy of local data.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this)
Node node_type
Legacy typedef that will go away at some point.
Teuchos::ArrayRCP< const Scalar > get1dView() const
Const persisting (1-D) view of this multivector&#39;s local values.
Forward declaration of Tpetra::Map.
size_t getOrigNumLocalRows() const
&quot;Original&quot; number of rows in the (local) data.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap)
Remove processes owning zero rows from the Map and their communicator.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra&#39;s behavior.