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