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#ifndef TPETRA_MULTIVECTOR_DECL_HPP
11#define TPETRA_MULTIVECTOR_DECL_HPP
12
15
17#include "Tpetra_Vector_fwd.hpp"
19#include "Tpetra_DistObject.hpp"
20#include "Tpetra_Map_fwd.hpp"
22#include "Kokkos_DualView.hpp"
23#include "Teuchos_BLAS_types.hpp"
24#include "Teuchos_DataAccess.hpp"
25#include "Teuchos_Range1D.hpp"
26#include "KokkosKernels_ArithTraits.hpp"
27#ifndef KOKKOS_ENABLE_DEPRECATED_CODE_5
28#include "KokkosKernels_InnerProductSpaceTraits.hpp"
29#else
30#include "Kokkos_InnerProductSpaceTraits.hpp"
31#endif
32#include "Tpetra_KokkosRefactor_Details_MultiVectorLocalDeepCopy.hpp"
33#include "Tpetra_Access.hpp"
34#include "Tpetra_Details_WrappedDualView.hpp"
35#include <type_traits>
36
37#ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
38#ifndef DOXYGEN_SHOULD_SKIP_THIS
39namespace Teuchos {
40template <class OrdinalType, class ScalarType>
41class SerialDenseMatrix; // forward declaration
42}
43#endif // DOXYGEN_SHOULD_SKIP_THIS
44#endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
45
46namespace Tpetra {
47
68template <class DS, class DL, class DG, class DN,
69 class SS, class SL, class SG, class SN>
72
73#ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
80template <class ST, class LO, class GO, class NT>
82 const Teuchos::SerialDenseMatrix<int, ST>& src);
83
90template <class ST, class LO, class GO, class NT>
91void deep_copy(Teuchos::SerialDenseMatrix<int, ST>& dst,
93#endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
94
102template <class ST, class LO, class GO, class NT>
105
115template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
116Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
118 const size_t numVectors);
119
120// WARNING NOT FOR USERS
121// This means we don't need to make MultiVector a friend of
122// Vector or of itself (with different template parameters).
123template <class SC, class LO, class GO, class NT>
124Teuchos::ArrayView<const size_t>
125getMultiVectorWhichVectors(const MultiVector<SC, LO, GO, NT>& X);
126
346template <class Scalar,
347 class LocalOrdinal,
348 class GlobalOrdinal,
349 class Node>
350class MultiVector : public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
351 public:
353
354
373 typename KokkosKernels::ArithTraits<Scalar>::val_type;
374
385
391#ifndef KOKKOS_ENABLE_DEPRECATED_CODE_5
392 using dot_type =
393 typename KokkosKernels::Details::InnerProductSpaceTraits<impl_scalar_type>::dot_type;
394#else
395 using dot_type =
396 typename Kokkos::Details::InnerProductSpaceTraits<impl_scalar_type>::dot_type;
397#endif
398
405 using mag_type = typename KokkosKernels::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,
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
448 MultiVector();
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,
602
603 protected:
609 const size_t j);
610
611 public:
629 MultiVector(const Teuchos::RCP<const map_type>& map,
630 const dual_view_type& view,
631 const Teuchos::ArrayView<const size_t>& whichVectors);
632
650 MultiVector(const Teuchos::RCP<const map_type>& map,
651 const wrapped_dual_view_type& view,
652 const Teuchos::ArrayView<const size_t>& whichVectors);
653
681 MultiVector(const Teuchos::RCP<const map_type>& map,
682 const dual_view_type& view,
684 const Teuchos::ArrayView<const size_t>& whichVectors);
685
747 const Teuchos::RCP<const map_type>& subMap,
748 const local_ordinal_type rowOffset = 0);
749
757 const map_type& subMap,
758 const size_t offset = 0);
759
769
772
780
784
794 virtual ~MultiVector() = default;
795
798
800
802
803 protected:
808 static const bool useAtomicUpdatesByDefault =
809#ifdef KOKKOS_ENABLE_SERIAL
810 !std::is_same<execution_space, Kokkos::Serial>::value;
811#else
812 true;
813#endif // KOKKOS_ENABLE_SERIAL
814
815 public:
845 void
847 const size_t col,
848 const impl_scalar_type& value);
849
882 template <typename T>
883 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
885 size_t col,
886 const T& value) {
887 replaceGlobalValue(globalRow, col, static_cast<impl_scalar_type>(value));
888 }
889
914 void
916 const size_t col,
917 const impl_scalar_type& value,
918 const bool atomic = useAtomicUpdatesByDefault);
919
948 template <typename T>
949 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
951 const size_t col,
952 const T& val,
953 const bool atomic = useAtomicUpdatesByDefault) {
954 sumIntoGlobalValue(gblRow, col, static_cast<impl_scalar_type>(val), atomic);
955 }
956
986 void
988 const size_t col,
989 const impl_scalar_type& value);
990
1024 template <typename T>
1025 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1027 const size_t col,
1028 const T& val) {
1029 replaceLocalValue(lclRow, col, static_cast<impl_scalar_type>(val));
1030 }
1031
1056 void
1058 const size_t col,
1059 const impl_scalar_type& val,
1060 const bool atomic = useAtomicUpdatesByDefault);
1061
1088 template <typename T>
1089 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1091 const size_t col,
1092 const T& val,
1093 const bool atomic = useAtomicUpdatesByDefault) {
1094 sumIntoLocalValue(lclRow, col, static_cast<impl_scalar_type>(val), atomic);
1095 }
1096
1098 void putScalar(const Scalar& value);
1099
1108 template <typename T>
1109 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1110 putScalar(const T& value) {
1111 putScalar(static_cast<impl_scalar_type>(value));
1112 }
1113
1126 void randomize();
1127
1141 void randomize(const Scalar& minVal, const Scalar& maxVal);
1142
1208 void replaceMap(const Teuchos::RCP<const map_type>& map);
1209
1216 void reduce();
1217
1219
1245
1246
1248 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1249 subCopy(const Teuchos::Range1D& colRng) const;
1250
1252 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1253 subCopy(const Teuchos::ArrayView<const size_t>& cols) const;
1254
1256 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1257 subView(const Teuchos::Range1D& colRng) const;
1258
1260 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1261 subView(const Teuchos::ArrayView<const size_t>& cols) const;
1262
1264 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1265 subViewNonConst(const Teuchos::Range1D& colRng);
1266
1268 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1269 subViewNonConst(const Teuchos::ArrayView<const size_t>& cols);
1270
1333 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1334 offsetView(const Teuchos::RCP<const map_type>& subMap,
1335 const size_t offset) const;
1336
1354 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1355 offsetViewNonConst(const Teuchos::RCP<const map_type>& subMap,
1356 const size_t offset);
1357
1359 Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1360 getVector(const size_t j) const;
1361
1363 Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1364 getVectorNonConst(const size_t j);
1365
1367 Teuchos::ArrayRCP<const Scalar> getData(size_t j) const;
1368
1370 Teuchos::ArrayRCP<Scalar> getDataNonConst(size_t j);
1371
1379 void
1380 get1dCopy(const Teuchos::ArrayView<Scalar>& A,
1381 const size_t LDA) const;
1382
1389 void
1390 get2dCopy(const Teuchos::ArrayView<const Teuchos::ArrayView<Scalar>>& ArrayOfPtrs) const;
1391
1397 Teuchos::ArrayRCP<const Scalar> get1dView() const;
1398
1400 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar>> get2dView() const;
1401
1407 Teuchos::ArrayRCP<Scalar> get1dViewNonConst();
1408
1410 Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar>> get2dViewNonConst();
1411
1414 typename dual_view_type::t_host::const_type getLocalViewHost(Access::ReadOnlyStruct) const;
1415
1418 typename dual_view_type::t_host getLocalViewHost(Access::ReadWriteStruct);
1419
1422 typename dual_view_type::t_host getLocalViewHost(Access::OverwriteAllStruct);
1423
1426 typename dual_view_type::t_dev::const_type getLocalViewDevice(Access::ReadOnlyStruct) const;
1427
1430 typename dual_view_type::t_dev getLocalViewDevice(Access::ReadWriteStruct);
1431
1434 typename dual_view_type::t_dev getLocalViewDevice(Access::OverwriteAllStruct);
1435
1440 wrapped_dual_view_type getWrappedDualView() const;
1441
1443 template <class TargetDeviceType>
1444 bool need_sync() const {
1445 return view_.getDualView().template need_sync<TargetDeviceType>();
1446 }
1447
1449 bool need_sync_host() const;
1450
1452 bool need_sync_device() const;
1453
1482 template <class TargetDeviceType>
1483 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type::const_type
1484 getLocalView(Access::ReadOnlyStruct s) const {
1485 return view_.template getView<TargetDeviceType>(s);
1486 }
1487
1488 template <class TargetDeviceType>
1489 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1490 getLocalView(Access::ReadWriteStruct s) {
1491 return view_.template getView<TargetDeviceType>(s);
1492 }
1493
1494 template <class TargetDeviceType>
1495 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1496 getLocalView(Access::OverwriteAllStruct s) {
1497 return view_.template getView<TargetDeviceType>(s);
1498 }
1499
1501
1503
1517 void
1518 dot(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
1519 const Teuchos::ArrayView<dot_type>& dots) const;
1520
1532 template <typename T>
1533 typename std::enable_if<!(std::is_same<dot_type, T>::value), void>::type
1535 const Teuchos::ArrayView<T>& dots) const {
1536 const size_t sz = static_cast<size_t>(dots.size());
1537 Teuchos::Array<dot_type> dts(sz);
1538 this->dot(A, dts);
1539 for (size_t i = 0; i < sz; ++i) {
1540 // If T and dot_type differ, this does an implicit conversion.
1541 dots[i] = dts[i];
1542 }
1543 }
1544
1546 template <typename T>
1547 typename std::enable_if<!(std::is_same<dot_type, T>::value), void>::type
1549 std::vector<T>& dots) const {
1550 const size_t sz = 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
1576 void
1578 const Kokkos::View<dot_type*, Kokkos::HostSpace>& dots) const;
1579
1580 template <class ViewType>
1581 void
1582 dot(typename std::enable_if<std::is_same<typename ViewType::value_type, dot_type>::value &&
1583 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value,
1585 const ViewType& dots) const {
1586 const Kokkos::View<dot_type*, Kokkos::HostSpace> h_dots("Tpetra::Dots", dots.extent(0));
1587 this->dot(A, h_dots);
1588 // DEEP_COPY REVIEW - NOT TESTED
1589 Kokkos::deep_copy(dots, h_dots);
1590 }
1591
1604 template <typename T>
1605 typename std::enable_if<!(std::is_same<dot_type, T>::value), void>::type
1607 const Kokkos::View<T*, device_type>& dots) const {
1608 const size_t numDots = dots.extent(0);
1609 Kokkos::View<dot_type*, device_type> dts("MV::dot tmp", numDots);
1610 // Call overload that takes a Kokkos::View<dot_type*, device_type>.
1611 this->dot(A, dts);
1612 // FIXME (mfh 14 Jul 2014) Does this actually work if dot_type
1613 // and T differ? We would need a test for this, but only the
1614 // Sacado and Stokhos packages are likely to care about this use
1615 // case. It could also come up for Kokkos::complex ->
1616 // std::complex conversions, but those two implementations
1617 // should generally be bitwise compatible.
1618 // CT: no this can't possible work .....
1619 // DEEP_COPY REVIEW - NOT TESTED
1620 Kokkos::deep_copy(dots, dts);
1621 }
1622
1625
1628
1636 void scale(const Scalar& alpha);
1637
1646 void scale(const Teuchos::ArrayView<const Scalar>& alpha);
1647
1656 void scale(const Kokkos::View<const impl_scalar_type*, device_type>& alpha);
1657
1666 void
1667 scale(const Scalar& alpha,
1669
1676 void
1677 update(const Scalar& alpha,
1679 const Scalar& beta);
1680
1687 void
1688 update(const Scalar& alpha,
1690 const Scalar& beta,
1692 const Scalar& gamma);
1693
1705 void
1706 norm1(const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1707
1708 template <class ViewType>
1709 typename std::enable_if<std::is_same<typename ViewType::value_type, mag_type>::value &&
1710 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value>::type
1711 norm1(const ViewType& norms) const {
1712 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1713 // this method to be templated. (It only exists in case
1714 // HostSpace = device_type::memory_space.)
1715 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1716 host_norms_view_type h_norms("Tpetra::MV::h_norms", norms.extent(0));
1717 this->norm1(h_norms);
1718 // DEEP_COPY REVIEW - HOST-TO-DEVICE
1719 Kokkos::deep_copy(execution_space(), norms, h_norms);
1720 }
1721
1737 template <typename T>
1738 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1739 norm1(const Kokkos::View<T*, device_type>& norms) const {
1740 const size_t numNorms = norms.extent(0);
1741 Kokkos::View<mag_type*, device_type> tmpNorms("MV::norm1 tmp", numNorms);
1742 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1743 this->norm1(tmpNorms);
1744 // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1745 // and T differ? We would need a test for this, but only the
1746 // Sacado and Stokhos packages are likely to care about this use
1747 // case. It could also come up with Kokkos::complex ->
1748 // std::complex conversion.
1749 // DEEP_COPY REVIEW - NOT TESTED
1750 Kokkos::deep_copy(norms, tmpNorms);
1751 }
1752
1756 void norm1(const Teuchos::ArrayView<mag_type>& norms) const;
1757
1772 template <typename T>
1773 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1774 norm1(const Teuchos::ArrayView<T>& norms) const {
1775 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1776 const size_type sz = norms.size();
1777 Teuchos::Array<mag_type> theNorms(sz);
1778 this->norm1(theNorms);
1779 for (size_type i = 0; i < sz; ++i) {
1780 // If T and mag_type differ, this does an implicit conversion.
1781 norms[i] = theNorms[i];
1782 }
1783 }
1784
1797 void
1798 norm2(const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1799
1800 template <class ViewType>
1801 typename std::enable_if<std::is_same<typename ViewType::value_type, mag_type>::value &&
1802 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value>::type
1803 norm2(const ViewType& norms) const {
1804 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1805 // this method to be templated. (It only exists in case
1806 // HostSpace = device_type::memory_space.)
1807 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1808 host_norms_view_type h_norms("Tpetra::MV::h_norms", norms.extent(0));
1809 this->norm2(h_norms);
1810 // DEEP_COPY REVIEW - NOT TESTED
1811 Kokkos::deep_copy(norms, h_norms);
1812 }
1813
1827 template <typename T>
1828 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1829 norm2(const Kokkos::View<T*, device_type>& norms) const {
1830 const size_t numNorms = norms.extent(0);
1831 Kokkos::View<mag_type*, device_type> theNorms("MV::norm2 tmp", numNorms);
1832 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1833 this->norm2(theNorms);
1834 // FIXME (mfh 14 Jul 2014) Does this actually work if mag_type
1835 // and T differ? We would need a test for this, but only the
1836 // Sacado and Stokhos packages are likely to care about this use
1837 // case. This could also come up with Kokkos::complex ->
1838 // std::complex conversion.
1839 // DEEP_COPY REVIEW - NOT TESTED
1840 Kokkos::deep_copy(norms, theNorms);
1841 }
1842
1846 void norm2(const Teuchos::ArrayView<mag_type>& norms) const;
1847
1862 template <typename T>
1863 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1864 norm2(const Teuchos::ArrayView<T>& norms) const {
1865 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1866 const size_type sz = norms.size();
1867 Teuchos::Array<mag_type> theNorms(sz);
1868 this->norm2(theNorms);
1869 for (size_type i = 0; i < sz; ++i) {
1870 // If T and mag_type differ, this does an implicit conversion.
1871 norms[i] = theNorms[i];
1872 }
1873 }
1874
1881 void normInf(const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1882
1883 template <class ViewType>
1884 typename std::enable_if<std::is_same<typename ViewType::value_type, mag_type>::value &&
1885 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value>::type
1886 normInf(const ViewType& norms) const {
1887 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1888 // this method to be templated. (It only exists in case
1889 // HostSpace = device_type::memory_space.)
1890 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1891 host_norms_view_type h_norms("Tpetra::MV::h_norms", norms.extent(0));
1892 this->normInf(h_norms);
1893 // DEEP_COPY REVIEW - HOST-TO-DEVICE
1894 Kokkos::deep_copy(execution_space(), norms, h_norms);
1895 }
1896
1910 template <typename T>
1911 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1912 normInf(const Kokkos::View<T*, device_type>& norms) const {
1913 const size_t numNorms = norms.extent(0);
1914 Kokkos::View<mag_type*, device_type> theNorms("MV::normInf tmp", numNorms);
1915 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1916 this->normInf(theNorms);
1917 // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1918 // and T differ? We would need a test for this, but only the
1919 // Sacado and Stokhos packages are likely to care about this use
1920 // case. This could also come up with Kokkos::complex ->
1921 // std::complex conversion.
1922 // DEEP_COPY REVIEW - NOT TESTED
1923 Kokkos::deep_copy(norms, theNorms);
1924 }
1925
1930 void normInf(const Teuchos::ArrayView<mag_type>& norms) const;
1931
1947 template <typename T>
1948 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1949 normInf(const Teuchos::ArrayView<T>& norms) const {
1950 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1951 const size_type sz = norms.size();
1952 Teuchos::Array<mag_type> theNorms(sz);
1953 this->norm2(theNorms);
1954 for (size_type i = 0; i < sz; ++i) {
1955 // If T and mag_type differ, this does an implicit conversion.
1956 norms[i] = theNorms[i];
1957 }
1958 }
1959
1964 void meanValue(const Teuchos::ArrayView<impl_scalar_type>& means) const;
1965
1966 template <typename T>
1967 typename std::enable_if<!std::is_same<impl_scalar_type, T>::value, void>::type
1968 meanValue(const Teuchos::ArrayView<T>& means) const {
1969 typedef typename Teuchos::Array<T>::size_type size_type;
1970 const size_type numMeans = means.size();
1971
1972 Teuchos::Array<impl_scalar_type> theMeans(numMeans);
1973 this->meanValue(theMeans());
1974 for (size_type k = 0; k < numMeans; ++k) {
1975 means[k] = static_cast<T>(theMeans[k]);
1976 }
1977 }
1978
1984 void
1985 multiply(Teuchos::ETransp transA,
1986 Teuchos::ETransp transB,
1987 const Scalar& alpha,
1988 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
1989 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
1990 const Scalar& beta);
1991
2012 void
2013 elementWiseMultiply(Scalar scalarAB,
2014 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2015 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2016 Scalar scalarThis);
2018
2020
2022 size_t getNumVectors() const;
2023
2025 size_t getLocalLength() const;
2026
2029
2035 size_t getStride() const;
2036
2040 bool isConstantStride() const;
2041
2045 bool aliases(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& other) const;
2046
2048
2050
2051
2053 virtual std::string description() const override;
2054
2083 virtual void
2084 describe(Teuchos::FancyOStream& out,
2085 const Teuchos::EVerbosityLevel verbLevel =
2086 Teuchos::Describable::verbLevel_default) const override;
2088
2102 virtual void
2103 removeEmptyProcessesInPlace(const Teuchos::RCP<const map_type>& newMap) override;
2104
2115 void setCopyOrView(const Teuchos::DataAccess copyOrView) {
2117 copyOrView == Teuchos::Copy, std::invalid_argument,
2118 "Tpetra::MultiVector::setCopyOrView: The Kokkos refactor version of "
2119 "MultiVector _only_ implements view semantics. You may not call this "
2120 "method with copyOrView = Teuchos::Copy. The only valid argument is "
2121 "Teuchos::View.");
2122 }
2123
2127 // This method ONLY exists for the circa 2014 "Kokkos refactor"
2128 // effort. It ALWAYS returns Teuchos::View.
2132 Teuchos::DataAccess getCopyOrView() const {
2133 return Teuchos::View;
2134 }
2135
2150 void
2152
2155 template <class T>
2156 Teuchos::RCP<MultiVector<T, LocalOrdinal, GlobalOrdinal, Node>>
2157 convert() const;
2158
2159 // \brief Checks to see if the local length, number of vectors and size of Scalar type match
2168
2169 private:
2171 using base_type = DistObject<scalar_type, local_ordinal_type,
2173
2174 protected:
2175 template <class DS, class DL, class DG, class DN,
2176 class SS, class SL, class SG, class SN>
2177 friend void ::Tpetra::deep_copy(MultiVector<DS, DL, DG, DN>& dst,
2178 const MultiVector<SS, SL, SG, SN>& src);
2179
2187
2200 Teuchos::Array<size_t> whichVectors_;
2201
2202 template <class SC, class LO, class GO, class NT>
2203 friend ::Teuchos::ArrayView<const size_t> getMultiVectorWhichVectors(const ::Tpetra::MultiVector<SC, LO, GO, NT>& X);
2204
2206
2208
2215 std::string
2216 descriptionImpl(const std::string& className) const;
2217
2224 std::string
2225 localDescribeToString(const Teuchos::EVerbosityLevel vl) const;
2226
2240 void
2241 describeImpl(Teuchos::FancyOStream& out,
2242 const std::string& className,
2243 const Teuchos::EVerbosityLevel verbLevel =
2244 Teuchos::Describable::verbLevel_default) const;
2245
2246 // Return true if and only if VectorIndex is a valid column index.
2247 bool vectorIndexOutOfRange(const size_t VectorIndex) const;
2248
2253 template <class T>
2254 Teuchos::ArrayRCP<T>
2255 getSubArrayRCP(Teuchos::ArrayRCP<T> arr, size_t j) const;
2256
2258 size_t getOrigNumLocalRows() const;
2259
2261 size_t getOrigNumLocalCols() const;
2262
2264
2266
2272 typename DistObject<scalar_type,
2276
2281 virtual bool
2282 checkSizes(const SrcDistObject& sourceObj) override;
2283
2285 virtual size_t constantNumberOfPackets() const override;
2286
2287 virtual void copyAndPermute(
2288 const SrcDistObject& sourceObj, const size_t numSameIDs,
2289 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs,
2290 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs,
2291 const CombineMode CM, const execution_space& space) override;
2292
2293 virtual void copyAndPermute(
2294 const SrcDistObject& sourceObj, const size_t numSameIDs,
2295 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs,
2296 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs,
2297 const CombineMode CM) override;
2298
2299 virtual void
2300 packAndPrepare(const SrcDistObject& sourceObj,
2301 const Kokkos::DualView<
2302 const local_ordinal_type*,
2304 Kokkos::DualView<
2306 buffer_device_type>& exports,
2307 Kokkos::DualView<
2308 size_t*,
2309 buffer_device_type> /* numPacketsPerLID */,
2310 size_t& constantNumPackets,
2311 const execution_space& space) override;
2312
2313 virtual void
2314 packAndPrepare(const SrcDistObject& sourceObj,
2315 const Kokkos::DualView<
2316 const local_ordinal_type*,
2318 Kokkos::DualView<
2320 buffer_device_type>& exports,
2321 Kokkos::DualView<
2322 size_t*,
2323 buffer_device_type> /* numPacketsPerLID */,
2324 size_t& constantNumPackets) override;
2325
2326 virtual void
2327 unpackAndCombine(const Kokkos::DualView<
2328 const local_ordinal_type*,
2330 Kokkos::DualView<
2333 imports,
2334 Kokkos::DualView<
2335 size_t*,
2336 buffer_device_type> /* numPacketsPerLID */,
2337 const size_t constantNumPackets,
2338 const CombineMode CM,
2339 const execution_space& space) override;
2340
2341 virtual void
2342 unpackAndCombine(const Kokkos::DualView<
2343 const local_ordinal_type*,
2345 Kokkos::DualView<
2348 imports,
2349 Kokkos::DualView<
2350 size_t*,
2351 buffer_device_type> /* numPacketsPerLID */,
2352 const size_t constantNumPackets,
2353 const CombineMode CM) override;
2354
2355 private:
2356 // If comm buffers can be aliased to the data view, use this
2357 // implementation.
2358 template <class NO = Node>
2359 typename std::enable_if<std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2360 typename NO::device_type::memory_space>::value,
2361 bool>::type
2362 reallocImportsIfNeededImpl(const size_t newSize,
2363 const bool verbose,
2364 const std::string* prefix,
2365 const bool areRemoteLIDsContiguous,
2366 const CombineMode CM);
2367
2368 // If comm buffers cannot be aliased to the data view, use this
2369 // implementation. (Just calls DistObject::reallocImportsIfNeeded.)
2370 template <class NO = Node>
2371 typename std::enable_if<!std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2372 typename NO::device_type::memory_space>::value,
2373 bool>::type
2374 reallocImportsIfNeededImpl(const size_t newSize,
2375 const bool verbose,
2376 const std::string* prefix,
2377 const bool areRemoteLIDsContiguous,
2378 const CombineMode CM);
2379
2380 protected:
2381 virtual bool
2382 reallocImportsIfNeeded(const size_t newSize,
2383 const bool verbose,
2384 const std::string* prefix,
2385 const bool areRemoteLIDsContiguous = false,
2386 const CombineMode CM = INSERT) override;
2387
2388 public:
2389 bool importsAreAliased();
2390
2391 protected:
2392 Kokkos::DualView<impl_scalar_type*, buffer_device_type> unaliased_imports_;
2393
2395}; // class MultiVector
2396
2397template <class SC, class LO, class GO, class NT>
2398Teuchos::ArrayView<const size_t>
2399getMultiVectorWhichVectors(const MultiVector<SC, LO, GO, NT>& X) {
2400 return X.whichVectors_();
2401}
2402
2405template <class ST, class LO, class GO, class NT>
2407 const MultiVector<ST, LO, GO, NT>& src) {
2408 // NOTE (mfh 11 Sep 2014) We can't implement deep_copy with
2409 // shallow-copy operator=, because that would invalidate existing
2410 // views of dst!
2411 dst.assign(src);
2412}
2413
2414// Implementation of the most generic version of MultiVector deep_copy.
2415template <class DS, class DL, class DG, class DN,
2416 class SS, class SL, class SG, class SN>
2418 const MultiVector<SS, SL, SG, SN>& src) {
2419 using ::Tpetra::getMultiVectorWhichVectors;
2420
2422 dst.getGlobalLength() != src.getGlobalLength() ||
2423 dst.getNumVectors() != src.getNumVectors(),
2424 std::invalid_argument,
2425 "Tpetra::deep_copy: Global dimensions of the two Tpetra::MultiVector "
2426 "objects do not match. src has dimensions ["
2427 << src.getGlobalLength()
2428 << "," << src.getNumVectors() << "], and dst has dimensions ["
2429 << dst.getGlobalLength() << "," << dst.getNumVectors() << "].");
2430
2431 // FIXME (mfh 28 Jul 2014) Don't throw; just set a local error flag.
2433 dst.getLocalLength() != src.getLocalLength(), std::invalid_argument,
2434 "Tpetra::deep_copy: The local row counts of the two Tpetra::MultiVector "
2435 "objects do not match. src has "
2436 << src.getLocalLength() << " row(s) "
2437 << " and dst has " << dst.getLocalLength() << " row(s).");
2438
2439 const bool srcMostUpToDateOnDevice = !src.need_sync_device();
2440
2441 if (src.isConstantStride() && dst.isConstantStride()) {
2444 dst.getLocalViewDevice(Access::OverwriteAll),
2445 src.getLocalViewDevice(Access::ReadOnly));
2446 } else {
2448 dst.getLocalViewDevice(Access::OverwriteAll),
2449 src.getLocalViewHost(Access::ReadOnly));
2450 }
2451 } else {
2452 auto dstWhichVecs = getMultiVectorWhichVectors(dst);
2453 auto srcWhichVecs = getMultiVectorWhichVectors(src);
2454
2456 Details::localDeepCopy(dst.getLocalViewDevice(Access::OverwriteAll),
2457 src.getLocalViewDevice(Access::ReadOnly),
2458 dst.isConstantStride(),
2459 src.isConstantStride(),
2461 srcWhichVecs);
2462 } else {
2463 Details::localDeepCopy(dst.getLocalViewDevice(Access::OverwriteAll),
2464 src.getLocalViewHost(Access::ReadOnly),
2465 dst.isConstantStride(),
2466 src.isConstantStride(),
2468 srcWhichVecs);
2469 }
2470 }
2471}
2472} // namespace Tpetra
2473
2474namespace Teuchos {
2475
2476// Give Teuchos::TypeNameTraits<Tpetra::MultiVector<...> > a
2477// human-readable definition.
2478template <class SC, class LO, class GO, class NT>
2479class TypeNameTraits<Tpetra::MultiVector<SC, LO, GO, NT>> {
2480 public:
2481 static std::string name() {
2482 return std::string("Tpetra::MultiVector<") +
2483 TypeNameTraits<SC>::name() + "," +
2484 TypeNameTraits<LO>::name() + "," +
2485 TypeNameTraits<GO>::name() + "," +
2486 TypeNameTraits<NT>::name() + ">";
2487 }
2488
2489 static std::string
2490 concreteName(const Tpetra::MultiVector<SC, LO, GO, NT>&) {
2491 return name();
2492 }
2493};
2494} // namespace Teuchos
2495
2496#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.
Struct that holds views of the contents of a CrsMatrix.
Base class for distributed Tpetra objects that support data redistribution.
A parallel distribution of indices over processes.
Node node_type
Legacy typedef that will go away at some point.
GlobalOrdinal global_ordinal_type
The type of global indices.
LocalOrdinal local_ordinal_type
The type of local indices.
typename Node::device_type device_type
This class' Kokkos::Device specialization.
One or more distributed dense vectors.
typename map_type::global_ordinal_type global_ordinal_type
The type of global indices that this class uses.
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &&)=default
Move assigment (shallow move).
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.
typename map_type::node_type node_type
Legacy thing that you should not use any more.
typename KokkosKernels::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner ("dot") product result.
std::enable_if<!(std::is_same< dot_type, T >::value), void >::type dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< T > &dots) const
Compute the dot product of each corresponding pair of vectors (columns) in A and B.
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.
std::enable_if<!(std::is_same< mag_type, T >::value), void >::type norm1(const Teuchos::ArrayView< T > &norms) const
Compute the one-norm of each vector (column).
std::enable_if<!(std::is_same< mag_type, T >::value), void >::type norm2(const Kokkos::View< T *, device_type > &norms) const
Compute the two-norm of each vector (column), storing the result in a device view.
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
The type of local indices that this class uses.
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.
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.
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).
std::enable_if<!(std::is_same< mag_type, T >::value), void >::type normInf(const Teuchos::ArrayView< T > &norms) const
Compute the infinity-norm of each vector (column), storing the result in a Teuchos::ArrayView.
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy assigment (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).
std::enable_if<!(std::is_same< mag_type, T >::value), void >::type normInf(const Kokkos::View< T *, device_type > &norms) const
Compute the infinity-norm of each vector (column), storing the result in a device view.
bool need_sync_device() const
Whether this MultiVector needs synchronization to the device.
wrapped_dual_view_type view_
The Kokkos::DualView containing the MultiVector's data.
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.
std::remove_reference< decltype(std::declval< dual_view_type >().templateview< 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 ...
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.
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.
typename DistObject< scalar_type, local_ordinal_type, global_ordinal_type, node_type >::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
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.
Scalar scalar_type
The type of each entry in the MultiVector.
bool need_sync() const
Whether this MultiVector needs synchronization to the given space.
std::enable_if<!(std::is_same< mag_type, T >::value), void >::type norm1(const Kokkos::View< T *, device_type > &norms) const
Compute the one-norm of each vector (column), storing the result in a device view.
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.
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.
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.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, device_type > dual_view_type
Kokkos::DualView specialization used by this class.
typename map_type::device_type device_type
This class' preferred Kokkos device type.
typename KokkosKernels::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
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.
std::enable_if<!(std::is_same< mag_type, T >::value), void >::type norm2(const Teuchos::ArrayView< T > &norms) const
Compute the two-norm of each vector (column).
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.
std::enable_if<!(std::is_same< dot_type, T >::value), void >::type dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Kokkos::View< T *, device_type > &dots) const
Compute the dot product of each corresponding pair of vectors (columns) in A and B,...
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 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()
Default constructor: makes a MultiVector with no rows or columns.
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
Type of the (new) Kokkos execution space.
void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this)
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 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.
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_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(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &&)=default
Move constructor (shallow move).
Teuchos::Array< size_t > whichVectors_
Indices of columns this multivector is viewing.
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.
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< dot_type, T >::value), void >::type dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, std::vector< T > &dots) const
Like the above dot() overload, but for std::vector output.
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 > > offsetViewNonConst(const Teuchos::RCP< const map_type > &subMap, const size_t offset)
Return a nonconst view of a subset of rows.
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).
static const bool useAtomicUpdatesByDefault
Whether sumIntoLocalValue and sumIntoGlobalValue should use atomic updates by default.
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.
typename KokkosKernels::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
Abstract base class for objects that can be the source of an Import or Export operation.
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.