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#include "Kokkos_InnerProductSpaceTraits.hpp"
28#include "Tpetra_KokkosRefactor_Details_MultiVectorLocalDeepCopy.hpp"
29#include "Tpetra_Access.hpp"
30#include "Tpetra_Details_WrappedDualView.hpp"
31#include <type_traits>
32
33#ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
34#ifndef DOXYGEN_SHOULD_SKIP_THIS
35namespace Teuchos {
36template <class OrdinalType, class ScalarType>
37class SerialDenseMatrix; // forward declaration
38}
39#endif // DOXYGEN_SHOULD_SKIP_THIS
40#endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
41
42namespace Tpetra {
43
64template <class DS, class DL, class DG, class DN,
65 class SS, class SL, class SG, class SN>
68
69#ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
76template <class ST, class LO, class GO, class NT>
78 const Teuchos::SerialDenseMatrix<int, ST>& src);
79
86template <class ST, class LO, class GO, class NT>
87void deep_copy(Teuchos::SerialDenseMatrix<int, ST>& dst,
89#endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
90
98template <class ST, class LO, class GO, class NT>
101
111template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
112Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
114 const size_t numVectors);
115
116// WARNING NOT FOR USERS
117// This means we don't need to make MultiVector a friend of
118// Vector or of itself (with different template parameters).
119template <class SC, class LO, class GO, class NT>
120Teuchos::ArrayView<const size_t>
121getMultiVectorWhichVectors(const MultiVector<SC, LO, GO, NT>& X);
122
342template <class Scalar,
343 class LocalOrdinal,
344 class GlobalOrdinal,
345 class Node>
346class MultiVector : public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
347 public:
349
350
369 typename KokkosKernels::ArithTraits<Scalar>::val_type;
370
381
387 using dot_type =
388 typename Kokkos::Details::InnerProductSpaceTraits<impl_scalar_type>::dot_type;
389
396 using mag_type = typename KokkosKernels::ArithTraits<impl_scalar_type>::mag_type;
397
402 using execution_space = typename device_type::execution_space;
403
426 using dual_view_type = Kokkos::DualView<impl_scalar_type**,
427 Kokkos::LayoutLeft,
430
431 using host_view_type = typename dual_view_type::t_host;
432 using device_view_type = typename dual_view_type::t_dev;
433
435
437
439 MultiVector();
440
447 MultiVector(const Teuchos::RCP<const map_type>& map,
448 const size_t numVecs,
449 const bool zeroOut = true);
450
462 const Teuchos::DataAccess copyOrView);
463
479 MultiVector(const Teuchos::RCP<const map_type>& map,
480 const Teuchos::ArrayView<const Scalar>& A,
481 const size_t LDA,
482 const size_t NumVectors);
483
497 MultiVector(const Teuchos::RCP<const map_type>& map,
498 const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar>>& ArrayOfPtrs,
499 const size_t NumVectors);
500
513 MultiVector(const Teuchos::RCP<const map_type>& map,
514 const dual_view_type& view);
515
554 MultiVector(const Teuchos::RCP<const map_type>& map,
555 const typename dual_view_type::t_dev& d_view);
556
579 MultiVector(const Teuchos::RCP<const map_type>& map,
580 const dual_view_type& view,
581 const dual_view_type& origView);
582
591 MultiVector(const Teuchos::RCP<const map_type>& map,
593
594 protected:
600 const size_t j);
601
602 public:
620 MultiVector(const Teuchos::RCP<const map_type>& map,
621 const dual_view_type& view,
622 const Teuchos::ArrayView<const size_t>& whichVectors);
623
641 MultiVector(const Teuchos::RCP<const map_type>& map,
642 const wrapped_dual_view_type& view,
643 const Teuchos::ArrayView<const size_t>& whichVectors);
644
672 MultiVector(const Teuchos::RCP<const map_type>& map,
673 const dual_view_type& view,
675 const Teuchos::ArrayView<const size_t>& whichVectors);
676
738 const Teuchos::RCP<const map_type>& subMap,
739 const local_ordinal_type rowOffset = 0);
740
748 const map_type& subMap,
749 const size_t offset = 0);
750
760
763
771
775
785 virtual ~MultiVector() = default;
786
789
791
793
794 protected:
799 static const bool useAtomicUpdatesByDefault =
800#ifdef KOKKOS_ENABLE_SERIAL
801 !std::is_same<execution_space, Kokkos::Serial>::value;
802#else
803 true;
804#endif // KOKKOS_ENABLE_SERIAL
805
806 public:
836 void
838 const size_t col,
839 const impl_scalar_type& value);
840
873 template <typename T>
874 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
876 size_t col,
877 const T& value) {
878 replaceGlobalValue(globalRow, col, static_cast<impl_scalar_type>(value));
879 }
880
905 void
907 const size_t col,
908 const impl_scalar_type& value,
909 const bool atomic = useAtomicUpdatesByDefault);
910
939 template <typename T>
940 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
942 const size_t col,
943 const T& val,
944 const bool atomic = useAtomicUpdatesByDefault) {
945 sumIntoGlobalValue(gblRow, col, static_cast<impl_scalar_type>(val), atomic);
946 }
947
977 void
979 const size_t col,
980 const impl_scalar_type& value);
981
1015 template <typename T>
1016 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1018 const size_t col,
1019 const T& val) {
1020 replaceLocalValue(lclRow, col, static_cast<impl_scalar_type>(val));
1021 }
1022
1047 void
1049 const size_t col,
1050 const impl_scalar_type& val,
1051 const bool atomic = useAtomicUpdatesByDefault);
1052
1079 template <typename T>
1080 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1082 const size_t col,
1083 const T& val,
1084 const bool atomic = useAtomicUpdatesByDefault) {
1085 sumIntoLocalValue(lclRow, col, static_cast<impl_scalar_type>(val), atomic);
1086 }
1087
1089 void putScalar(const Scalar& value);
1090
1099 template <typename T>
1100 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1101 putScalar(const T& value) {
1102 putScalar(static_cast<impl_scalar_type>(value));
1103 }
1104
1117 void randomize();
1118
1132 void randomize(const Scalar& minVal, const Scalar& maxVal);
1133
1199 void replaceMap(const Teuchos::RCP<const map_type>& map);
1200
1207 void reduce();
1208
1210
1236
1237
1239 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1240 subCopy(const Teuchos::Range1D& colRng) const;
1241
1243 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1244 subCopy(const Teuchos::ArrayView<const size_t>& cols) const;
1245
1247 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1248 subView(const Teuchos::Range1D& colRng) const;
1249
1251 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1252 subView(const Teuchos::ArrayView<const size_t>& cols) const;
1253
1255 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1256 subViewNonConst(const Teuchos::Range1D& colRng);
1257
1259 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1260 subViewNonConst(const Teuchos::ArrayView<const size_t>& cols);
1261
1324 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1325 offsetView(const Teuchos::RCP<const map_type>& subMap,
1326 const size_t offset) const;
1327
1345 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1346 offsetViewNonConst(const Teuchos::RCP<const map_type>& subMap,
1347 const size_t offset);
1348
1350 Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1351 getVector(const size_t j) const;
1352
1354 Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1355 getVectorNonConst(const size_t j);
1356
1358 Teuchos::ArrayRCP<const Scalar> getData(size_t j) const;
1359
1361 Teuchos::ArrayRCP<Scalar> getDataNonConst(size_t j);
1362
1370 void
1371 get1dCopy(const Teuchos::ArrayView<Scalar>& A,
1372 const size_t LDA) const;
1373
1380 void
1381 get2dCopy(const Teuchos::ArrayView<const Teuchos::ArrayView<Scalar>>& ArrayOfPtrs) const;
1382
1388 Teuchos::ArrayRCP<const Scalar> get1dView() const;
1389
1391 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar>> get2dView() const;
1392
1398 Teuchos::ArrayRCP<Scalar> get1dViewNonConst();
1399
1401 Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar>> get2dViewNonConst();
1402
1405 typename dual_view_type::t_host::const_type getLocalViewHost(Access::ReadOnlyStruct) const;
1406
1409 typename dual_view_type::t_host getLocalViewHost(Access::ReadWriteStruct);
1410
1413 typename dual_view_type::t_host getLocalViewHost(Access::OverwriteAllStruct);
1414
1417 typename dual_view_type::t_dev::const_type getLocalViewDevice(Access::ReadOnlyStruct) const;
1418
1421 typename dual_view_type::t_dev getLocalViewDevice(Access::ReadWriteStruct);
1422
1425 typename dual_view_type::t_dev getLocalViewDevice(Access::OverwriteAllStruct);
1426
1431 wrapped_dual_view_type getWrappedDualView() const;
1432
1434 template <class TargetDeviceType>
1435 bool need_sync() const {
1436 return view_.getDualView().template need_sync<TargetDeviceType>();
1437 }
1438
1440 bool need_sync_host() const;
1441
1443 bool need_sync_device() const;
1444
1473 template <class TargetDeviceType>
1474 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type::const_type
1475 getLocalView(Access::ReadOnlyStruct s) const {
1476 return view_.template getView<TargetDeviceType>(s);
1477 }
1478
1479 template <class TargetDeviceType>
1480 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1481 getLocalView(Access::ReadWriteStruct s) {
1482 return view_.template getView<TargetDeviceType>(s);
1483 }
1484
1485 template <class TargetDeviceType>
1486 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1487 getLocalView(Access::OverwriteAllStruct s) {
1488 return view_.template getView<TargetDeviceType>(s);
1489 }
1490
1492
1494
1508 void
1509 dot(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
1510 const Teuchos::ArrayView<dot_type>& dots) const;
1511
1523 template <typename T>
1524 typename std::enable_if<!(std::is_same<dot_type, T>::value), void>::type
1526 const Teuchos::ArrayView<T>& dots) const {
1527 const size_t sz = static_cast<size_t>(dots.size());
1528 Teuchos::Array<dot_type> dts(sz);
1529 this->dot(A, dts);
1530 for (size_t i = 0; i < sz; ++i) {
1531 // If T and dot_type differ, this does an implicit conversion.
1532 dots[i] = dts[i];
1533 }
1534 }
1535
1537 template <typename T>
1538 typename std::enable_if<!(std::is_same<dot_type, T>::value), void>::type
1540 std::vector<T>& dots) const {
1541 const size_t sz = dots.size();
1542 Teuchos::Array<dot_type> dts(sz);
1543 this->dot(A, dts);
1544 for (size_t i = 0; i < sz; ++i) {
1545 // If T and dot_type differ, this does an implicit conversion.
1546 dots[i] = dts[i];
1547 }
1548 }
1549
1567 void
1569 const Kokkos::View<dot_type*, Kokkos::HostSpace>& norms) const;
1570
1571 template <class ViewType>
1572 void
1573 dot(typename std::enable_if<std::is_same<typename ViewType::value_type, dot_type>::value &&
1574 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value,
1576 const ViewType& dots) const {
1577 const Kokkos::View<dot_type*, Kokkos::HostSpace> h_dots("Tpetra::Dots", dots.extent(0));
1578 this->dot(A, h_dots);
1579 // DEEP_COPY REVIEW - NOT TESTED
1580 Kokkos::deep_copy(dots, h_dots);
1581 }
1582
1595 template <typename T>
1596 typename std::enable_if<!(std::is_same<dot_type, T>::value), void>::type
1598 const Kokkos::View<T*, device_type>& dots) const {
1599 const size_t numDots = dots.extent(0);
1600 Kokkos::View<dot_type*, device_type> dts("MV::dot tmp", numDots);
1601 // Call overload that takes a Kokkos::View<dot_type*, device_type>.
1602 this->dot(A, dts);
1603 // FIXME (mfh 14 Jul 2014) Does this actually work if dot_type
1604 // and T differ? We would need a test for this, but only the
1605 // Sacado and Stokhos packages are likely to care about this use
1606 // case. It could also come up for Kokkos::complex ->
1607 // std::complex conversions, but those two implementations
1608 // should generally be bitwise compatible.
1609 // CT: no this can't possible work .....
1610 // DEEP_COPY REVIEW - NOT TESTED
1611 Kokkos::deep_copy(dots, dts);
1612 }
1613
1616
1619
1627 void scale(const Scalar& alpha);
1628
1637 void scale(const Teuchos::ArrayView<const Scalar>& alpha);
1638
1647 void scale(const Kokkos::View<const impl_scalar_type*, device_type>& alpha);
1648
1657 void
1658 scale(const Scalar& alpha,
1660
1667 void
1668 update(const Scalar& alpha,
1670 const Scalar& beta);
1671
1678 void
1679 update(const Scalar& alpha,
1681 const Scalar& beta,
1683 const Scalar& gamma);
1684
1696 void
1697 norm1(const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1698
1699 template <class ViewType>
1700 typename std::enable_if<std::is_same<typename ViewType::value_type, mag_type>::value &&
1701 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value>::type
1702 norm1(const ViewType& norms) const {
1703 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1704 // this method to be templated. (It only exists in case
1705 // HostSpace = device_type::memory_space.)
1706 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1707 host_norms_view_type h_norms("Tpetra::MV::h_norms", norms.extent(0));
1708 this->norm1(h_norms);
1709 // DEEP_COPY REVIEW - HOST-TO-DEVICE
1710 Kokkos::deep_copy(execution_space(), norms, h_norms);
1711 }
1712
1728 template <typename T>
1729 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1730 norm1(const Kokkos::View<T*, device_type>& norms) const {
1731 const size_t numNorms = norms.extent(0);
1732 Kokkos::View<mag_type*, device_type> tmpNorms("MV::norm1 tmp", numNorms);
1733 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1734 this->norm1(tmpNorms);
1735 // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1736 // and T differ? We would need a test for this, but only the
1737 // Sacado and Stokhos packages are likely to care about this use
1738 // case. It could also come up with Kokkos::complex ->
1739 // std::complex conversion.
1740 // DEEP_COPY REVIEW - NOT TESTED
1741 Kokkos::deep_copy(norms, tmpNorms);
1742 }
1743
1747 void norm1(const Teuchos::ArrayView<mag_type>& norms) const;
1748
1763 template <typename T>
1764 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1765 norm1(const Teuchos::ArrayView<T>& norms) const {
1766 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1767 const size_type sz = norms.size();
1768 Teuchos::Array<mag_type> theNorms(sz);
1769 this->norm1(theNorms);
1770 for (size_type i = 0; i < sz; ++i) {
1771 // If T and mag_type differ, this does an implicit conversion.
1772 norms[i] = theNorms[i];
1773 }
1774 }
1775
1788 void
1789 norm2(const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1790
1791 template <class ViewType>
1792 typename std::enable_if<std::is_same<typename ViewType::value_type, mag_type>::value &&
1793 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value>::type
1794 norm2(const ViewType& norms) const {
1795 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1796 // this method to be templated. (It only exists in case
1797 // HostSpace = device_type::memory_space.)
1798 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1799 host_norms_view_type h_norms("Tpetra::MV::h_norms", norms.extent(0));
1800 this->norm2(h_norms);
1801 // DEEP_COPY REVIEW - NOT TESTED
1802 Kokkos::deep_copy(norms, h_norms);
1803 }
1804
1818 template <typename T>
1819 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1820 norm2(const Kokkos::View<T*, device_type>& norms) const {
1821 const size_t numNorms = norms.extent(0);
1822 Kokkos::View<mag_type*, device_type> theNorms("MV::norm2 tmp", numNorms);
1823 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1824 this->norm2(theNorms);
1825 // FIXME (mfh 14 Jul 2014) Does this actually work if mag_type
1826 // and T differ? We would need a test for this, but only the
1827 // Sacado and Stokhos packages are likely to care about this use
1828 // case. This could also come up with Kokkos::complex ->
1829 // std::complex conversion.
1830 // DEEP_COPY REVIEW - NOT TESTED
1831 Kokkos::deep_copy(norms, theNorms);
1832 }
1833
1837 void norm2(const Teuchos::ArrayView<mag_type>& norms) const;
1838
1853 template <typename T>
1854 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1855 norm2(const Teuchos::ArrayView<T>& norms) const {
1856 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1857 const size_type sz = norms.size();
1858 Teuchos::Array<mag_type> theNorms(sz);
1859 this->norm2(theNorms);
1860 for (size_type i = 0; i < sz; ++i) {
1861 // If T and mag_type differ, this does an implicit conversion.
1862 norms[i] = theNorms[i];
1863 }
1864 }
1865
1872 void normInf(const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1873
1874 template <class ViewType>
1875 typename std::enable_if<std::is_same<typename ViewType::value_type, mag_type>::value &&
1876 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value>::type
1877 normInf(const ViewType& norms) const {
1878 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1879 // this method to be templated. (It only exists in case
1880 // HostSpace = device_type::memory_space.)
1881 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1882 host_norms_view_type h_norms("Tpetra::MV::h_norms", norms.extent(0));
1883 this->normInf(h_norms);
1884 // DEEP_COPY REVIEW - HOST-TO-DEVICE
1885 Kokkos::deep_copy(execution_space(), norms, h_norms);
1886 }
1887
1901 template <typename T>
1902 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1903 normInf(const Kokkos::View<T*, device_type>& norms) const {
1904 const size_t numNorms = norms.extent(0);
1905 Kokkos::View<mag_type*, device_type> theNorms("MV::normInf tmp", numNorms);
1906 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1907 this->normInf(theNorms);
1908 // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1909 // and T differ? We would need a test for this, but only the
1910 // Sacado and Stokhos packages are likely to care about this use
1911 // case. This could also come up with Kokkos::complex ->
1912 // std::complex conversion.
1913 // DEEP_COPY REVIEW - NOT TESTED
1914 Kokkos::deep_copy(norms, theNorms);
1915 }
1916
1921 void normInf(const Teuchos::ArrayView<mag_type>& norms) const;
1922
1938 template <typename T>
1939 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1940 normInf(const Teuchos::ArrayView<T>& norms) const {
1941 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1942 const size_type sz = norms.size();
1943 Teuchos::Array<mag_type> theNorms(sz);
1944 this->norm2(theNorms);
1945 for (size_type i = 0; i < sz; ++i) {
1946 // If T and mag_type differ, this does an implicit conversion.
1947 norms[i] = theNorms[i];
1948 }
1949 }
1950
1955 void meanValue(const Teuchos::ArrayView<impl_scalar_type>& means) const;
1956
1957 template <typename T>
1958 typename std::enable_if<!std::is_same<impl_scalar_type, T>::value, void>::type
1959 meanValue(const Teuchos::ArrayView<T>& means) const {
1960 typedef typename Teuchos::Array<T>::size_type size_type;
1961 const size_type numMeans = means.size();
1962
1963 Teuchos::Array<impl_scalar_type> theMeans(numMeans);
1964 this->meanValue(theMeans());
1965 for (size_type k = 0; k < numMeans; ++k) {
1966 means[k] = static_cast<T>(theMeans[k]);
1967 }
1968 }
1969
1975 void
1976 multiply(Teuchos::ETransp transA,
1977 Teuchos::ETransp transB,
1978 const Scalar& alpha,
1979 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
1980 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
1981 const Scalar& beta);
1982
2003 void
2004 elementWiseMultiply(Scalar scalarAB,
2005 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2006 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2007 Scalar scalarThis);
2009
2011
2013 size_t getNumVectors() const;
2014
2016 size_t getLocalLength() const;
2017
2020
2026 size_t getStride() const;
2027
2031 bool isConstantStride() const;
2032
2036 bool aliases(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& other) const;
2037
2039
2041
2042
2044 virtual std::string description() const override;
2045
2074 virtual void
2075 describe(Teuchos::FancyOStream& out,
2076 const Teuchos::EVerbosityLevel verbLevel =
2077 Teuchos::Describable::verbLevel_default) const override;
2079
2093 virtual void
2094 removeEmptyProcessesInPlace(const Teuchos::RCP<const map_type>& newMap) override;
2095
2106 void setCopyOrView(const Teuchos::DataAccess copyOrView) {
2108 copyOrView == Teuchos::Copy, std::invalid_argument,
2109 "Tpetra::MultiVector::setCopyOrView: The Kokkos refactor version of "
2110 "MultiVector _only_ implements view semantics. You may not call this "
2111 "method with copyOrView = Teuchos::Copy. The only valid argument is "
2112 "Teuchos::View.");
2113 }
2114
2118 // This method ONLY exists for the circa 2014 "Kokkos refactor"
2119 // effort. It ALWAYS returns Teuchos::View.
2123 Teuchos::DataAccess getCopyOrView() const {
2124 return Teuchos::View;
2125 }
2126
2141 void
2143
2146 template <class T>
2147 Teuchos::RCP<MultiVector<T, LocalOrdinal, GlobalOrdinal, Node>>
2148 convert() const;
2149
2150 // \brief Checks to see if the local length, number of vectors and size of Scalar type match
2159
2160 private:
2162 using base_type = DistObject<scalar_type, local_ordinal_type,
2164
2165 protected:
2166 template <class DS, class DL, class DG, class DN,
2167 class SS, class SL, class SG, class SN>
2168 friend void ::Tpetra::deep_copy(MultiVector<DS, DL, DG, DN>& dst,
2169 const MultiVector<SS, SL, SG, SN>& src);
2170
2178
2191 Teuchos::Array<size_t> whichVectors_;
2192
2193 template <class SC, class LO, class GO, class NT>
2194 friend ::Teuchos::ArrayView<const size_t> getMultiVectorWhichVectors(const ::Tpetra::MultiVector<SC, LO, GO, NT>& X);
2195
2197
2199
2206 std::string
2207 descriptionImpl(const std::string& className) const;
2208
2215 std::string
2216 localDescribeToString(const Teuchos::EVerbosityLevel vl) const;
2217
2231 void
2232 describeImpl(Teuchos::FancyOStream& out,
2233 const std::string& className,
2234 const Teuchos::EVerbosityLevel verbLevel =
2235 Teuchos::Describable::verbLevel_default) const;
2236
2237 // Return true if and only if VectorIndex is a valid column index.
2238 bool vectorIndexOutOfRange(const size_t VectorIndex) const;
2239
2244 template <class T>
2245 Teuchos::ArrayRCP<T>
2246 getSubArrayRCP(Teuchos::ArrayRCP<T> arr, size_t j) const;
2247
2249 size_t getOrigNumLocalRows() const;
2250
2252 size_t getOrigNumLocalCols() const;
2253
2255
2257
2263 typename DistObject<scalar_type,
2267
2272 virtual bool
2273 checkSizes(const SrcDistObject& sourceObj) override;
2274
2276 virtual size_t constantNumberOfPackets() const override;
2277
2278 virtual void copyAndPermute(
2279 const SrcDistObject& sourceObj, const size_t numSameIDs,
2280 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs,
2281 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs,
2282 const CombineMode CM, const execution_space& space) override;
2283
2284 virtual void copyAndPermute(
2285 const SrcDistObject& sourceObj, const size_t numSameIDs,
2286 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs,
2287 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs,
2288 const CombineMode CM) override;
2289
2290 virtual void
2291 packAndPrepare(const SrcDistObject& sourceObj,
2292 const Kokkos::DualView<
2293 const local_ordinal_type*,
2295 Kokkos::DualView<
2297 buffer_device_type>& exports,
2298 Kokkos::DualView<
2299 size_t*,
2300 buffer_device_type> /* numPacketsPerLID */,
2301 size_t& constantNumPackets,
2302 const execution_space& space) override;
2303
2304 virtual void
2305 packAndPrepare(const SrcDistObject& sourceObj,
2306 const Kokkos::DualView<
2307 const local_ordinal_type*,
2309 Kokkos::DualView<
2311 buffer_device_type>& exports,
2312 Kokkos::DualView<
2313 size_t*,
2314 buffer_device_type> /* numPacketsPerLID */,
2315 size_t& constantNumPackets) override;
2316
2317 virtual void
2318 unpackAndCombine(const Kokkos::DualView<
2319 const local_ordinal_type*,
2321 Kokkos::DualView<
2324 imports,
2325 Kokkos::DualView<
2326 size_t*,
2327 buffer_device_type> /* numPacketsPerLID */,
2328 const size_t constantNumPackets,
2329 const CombineMode CM,
2330 const execution_space& space) override;
2331
2332 virtual void
2333 unpackAndCombine(const Kokkos::DualView<
2334 const local_ordinal_type*,
2336 Kokkos::DualView<
2339 imports,
2340 Kokkos::DualView<
2341 size_t*,
2342 buffer_device_type> /* numPacketsPerLID */,
2343 const size_t constantNumPackets,
2344 const CombineMode CM) override;
2345
2346 private:
2347 // If comm buffers can be aliased to the data view, use this
2348 // implementation.
2349 template <class NO = Node>
2350 typename std::enable_if<std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2351 typename NO::device_type::memory_space>::value,
2352 bool>::type
2353 reallocImportsIfNeededImpl(const size_t newSize,
2354 const bool verbose,
2355 const std::string* prefix,
2356 const bool areRemoteLIDsContiguous,
2357 const CombineMode CM);
2358
2359 // If comm buffers cannot be aliased to the data view, use this
2360 // implementation. (Just calls DistObject::reallocImportsIfNeeded.)
2361 template <class NO = Node>
2362 typename std::enable_if<!std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2363 typename NO::device_type::memory_space>::value,
2364 bool>::type
2365 reallocImportsIfNeededImpl(const size_t newSize,
2366 const bool verbose,
2367 const std::string* prefix,
2368 const bool areRemoteLIDsContiguous,
2369 const CombineMode CM);
2370
2371 protected:
2372 virtual bool
2373 reallocImportsIfNeeded(const size_t newSize,
2374 const bool verbose,
2375 const std::string* prefix,
2376 const bool areRemoteLIDsContiguous = false,
2377 const CombineMode CM = INSERT) override;
2378
2379 public:
2380 bool importsAreAliased();
2381
2382 protected:
2383 Kokkos::DualView<impl_scalar_type*, buffer_device_type> unaliased_imports_;
2384
2386}; // class MultiVector
2387
2388template <class SC, class LO, class GO, class NT>
2389Teuchos::ArrayView<const size_t>
2390getMultiVectorWhichVectors(const MultiVector<SC, LO, GO, NT>& X) {
2391 return X.whichVectors_();
2392}
2393
2396template <class ST, class LO, class GO, class NT>
2398 const MultiVector<ST, LO, GO, NT>& src) {
2399 // NOTE (mfh 11 Sep 2014) We can't implement deep_copy with
2400 // shallow-copy operator=, because that would invalidate existing
2401 // views of dst!
2402 dst.assign(src);
2403}
2404
2405// Implementation of the most generic version of MultiVector deep_copy.
2406template <class DS, class DL, class DG, class DN,
2407 class SS, class SL, class SG, class SN>
2409 const MultiVector<SS, SL, SG, SN>& src) {
2410 using ::Tpetra::getMultiVectorWhichVectors;
2411
2413 dst.getGlobalLength() != src.getGlobalLength() ||
2414 dst.getNumVectors() != src.getNumVectors(),
2415 std::invalid_argument,
2416 "Tpetra::deep_copy: Global dimensions of the two Tpetra::MultiVector "
2417 "objects do not match. src has dimensions ["
2418 << src.getGlobalLength()
2419 << "," << src.getNumVectors() << "], and dst has dimensions ["
2420 << dst.getGlobalLength() << "," << dst.getNumVectors() << "].");
2421
2422 // FIXME (mfh 28 Jul 2014) Don't throw; just set a local error flag.
2424 dst.getLocalLength() != src.getLocalLength(), std::invalid_argument,
2425 "Tpetra::deep_copy: The local row counts of the two Tpetra::MultiVector "
2426 "objects do not match. src has "
2427 << src.getLocalLength() << " row(s) "
2428 << " and dst has " << dst.getLocalLength() << " row(s).");
2429
2430 const bool srcMostUpToDateOnDevice = !src.need_sync_device();
2431
2432 if (src.isConstantStride() && dst.isConstantStride()) {
2435 dst.getLocalViewDevice(Access::OverwriteAll),
2436 src.getLocalViewDevice(Access::ReadOnly));
2437 } else {
2439 dst.getLocalViewDevice(Access::OverwriteAll),
2440 src.getLocalViewHost(Access::ReadOnly));
2441 }
2442 } else {
2443 auto dstWhichVecs = getMultiVectorWhichVectors(dst);
2444 auto srcWhichVecs = getMultiVectorWhichVectors(src);
2445
2447 Details::localDeepCopy(dst.getLocalViewDevice(Access::OverwriteAll),
2448 src.getLocalViewDevice(Access::ReadOnly),
2449 dst.isConstantStride(),
2450 src.isConstantStride(),
2452 srcWhichVecs);
2453 } else {
2454 Details::localDeepCopy(dst.getLocalViewDevice(Access::OverwriteAll),
2455 src.getLocalViewHost(Access::ReadOnly),
2456 dst.isConstantStride(),
2457 src.isConstantStride(),
2459 srcWhichVecs);
2460 }
2461 }
2462}
2463} // namespace Tpetra
2464
2465namespace Teuchos {
2466
2467// Give Teuchos::TypeNameTraits<Tpetra::MultiVector<...> > a
2468// human-readable definition.
2469template <class SC, class LO, class GO, class NT>
2470class TypeNameTraits<Tpetra::MultiVector<SC, LO, GO, NT>> {
2471 public:
2472 static std::string name() {
2473 return std::string("Tpetra::MultiVector<") +
2474 TypeNameTraits<SC>::name() + "," +
2475 TypeNameTraits<LO>::name() + "," +
2476 TypeNameTraits<GO>::name() + "," +
2477 TypeNameTraits<NT>::name() + ">";
2478 }
2479
2480 static std::string
2481 concreteName(const Tpetra::MultiVector<SC, LO, GO, NT>&) {
2482 return name();
2483 }
2484};
2485} // namespace Teuchos
2486
2487#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.
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.
typename Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner ("dot") product result.
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.