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#if KOKKOS_VERSION >= 40799
27#include "KokkosKernels_ArithTraits.hpp"
28#else
29#include "Kokkos_ArithTraits.hpp"
30#endif
31#include "Kokkos_InnerProductSpaceTraits.hpp"
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#if KOKKOS_VERSION >= 40799
374 typename KokkosKernels::ArithTraits<Scalar>::val_type;
375#else
376 typename Kokkos::ArithTraits<Scalar>::val_type;
377#endif
378
389
395 using dot_type =
396 typename Kokkos::Details::InnerProductSpaceTraits<impl_scalar_type>::dot_type;
397
404#if KOKKOS_VERSION >= 40799
405 using mag_type = typename KokkosKernels::ArithTraits<impl_scalar_type>::mag_type;
406#else
407 using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
408#endif
409
414 using execution_space = typename device_type::execution_space;
415
438 using dual_view_type = Kokkos::DualView<impl_scalar_type**,
439 Kokkos::LayoutLeft,
442
443 using host_view_type = typename dual_view_type::t_host;
444 using device_view_type = typename dual_view_type::t_dev;
445
447
449
451 MultiVector();
452
459 MultiVector(const Teuchos::RCP<const map_type>& map,
460 const size_t numVecs,
461 const bool zeroOut = true);
462
474 const Teuchos::DataAccess copyOrView);
475
491 MultiVector(const Teuchos::RCP<const map_type>& map,
492 const Teuchos::ArrayView<const Scalar>& A,
493 const size_t LDA,
494 const size_t NumVectors);
495
509 MultiVector(const Teuchos::RCP<const map_type>& map,
510 const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar>>& ArrayOfPtrs,
511 const size_t NumVectors);
512
525 MultiVector(const Teuchos::RCP<const map_type>& map,
526 const dual_view_type& view);
527
566 MultiVector(const Teuchos::RCP<const map_type>& map,
567 const typename dual_view_type::t_dev& d_view);
568
591 MultiVector(const Teuchos::RCP<const map_type>& map,
592 const dual_view_type& view,
593 const dual_view_type& origView);
594
603 MultiVector(const Teuchos::RCP<const map_type>& map,
605
606 protected:
612 const size_t j);
613
614 public:
632 MultiVector(const Teuchos::RCP<const map_type>& map,
633 const dual_view_type& view,
634 const Teuchos::ArrayView<const size_t>& whichVectors);
635
653 MultiVector(const Teuchos::RCP<const map_type>& map,
654 const wrapped_dual_view_type& view,
655 const Teuchos::ArrayView<const size_t>& whichVectors);
656
684 MultiVector(const Teuchos::RCP<const map_type>& map,
685 const dual_view_type& view,
687 const Teuchos::ArrayView<const size_t>& whichVectors);
688
750 const Teuchos::RCP<const map_type>& subMap,
751 const local_ordinal_type rowOffset = 0);
752
760 const map_type& subMap,
761 const size_t offset = 0);
762
772
775
783
787
797 virtual ~MultiVector() = default;
798
801
803
805
806 protected:
811 static const bool useAtomicUpdatesByDefault =
812#ifdef KOKKOS_ENABLE_SERIAL
813 !std::is_same<execution_space, Kokkos::Serial>::value;
814#else
815 true;
816#endif // KOKKOS_ENABLE_SERIAL
817
818 public:
848 void
850 const size_t col,
851 const impl_scalar_type& value);
852
885 template <typename T>
886 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
888 size_t col,
889 const T& value) {
890 replaceGlobalValue(globalRow, col, static_cast<impl_scalar_type>(value));
891 }
892
917 void
919 const size_t col,
920 const impl_scalar_type& value,
921 const bool atomic = useAtomicUpdatesByDefault);
922
951 template <typename T>
952 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
954 const size_t col,
955 const T& val,
956 const bool atomic = useAtomicUpdatesByDefault) {
957 sumIntoGlobalValue(gblRow, col, static_cast<impl_scalar_type>(val), atomic);
958 }
959
989 void
991 const size_t col,
992 const impl_scalar_type& value);
993
1027 template <typename T>
1028 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1030 const size_t col,
1031 const T& val) {
1032 replaceLocalValue(lclRow, col, static_cast<impl_scalar_type>(val));
1033 }
1034
1059 void
1061 const size_t col,
1062 const impl_scalar_type& val,
1063 const bool atomic = useAtomicUpdatesByDefault);
1064
1091 template <typename T>
1092 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1094 const size_t col,
1095 const T& val,
1096 const bool atomic = useAtomicUpdatesByDefault) {
1097 sumIntoLocalValue(lclRow, col, static_cast<impl_scalar_type>(val), atomic);
1098 }
1099
1101 void putScalar(const Scalar& value);
1102
1111 template <typename T>
1112 typename std::enable_if<!std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1113 putScalar(const T& value) {
1114 putScalar(static_cast<impl_scalar_type>(value));
1115 }
1116
1129 void randomize();
1130
1144 void randomize(const Scalar& minVal, const Scalar& maxVal);
1145
1211 void replaceMap(const Teuchos::RCP<const map_type>& map);
1212
1219 void reduce();
1220
1222
1248
1249
1251 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1252 subCopy(const Teuchos::Range1D& colRng) const;
1253
1255 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1256 subCopy(const Teuchos::ArrayView<const size_t>& cols) const;
1257
1259 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1260 subView(const Teuchos::Range1D& colRng) const;
1261
1263 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1264 subView(const Teuchos::ArrayView<const size_t>& cols) const;
1265
1267 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1268 subViewNonConst(const Teuchos::Range1D& colRng);
1269
1271 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1272 subViewNonConst(const Teuchos::ArrayView<const size_t>& cols);
1273
1336 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1337 offsetView(const Teuchos::RCP<const map_type>& subMap,
1338 const size_t offset) const;
1339
1357 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1358 offsetViewNonConst(const Teuchos::RCP<const map_type>& subMap,
1359 const size_t offset);
1360
1362 Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1363 getVector(const size_t j) const;
1364
1366 Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1367 getVectorNonConst(const size_t j);
1368
1370 Teuchos::ArrayRCP<const Scalar> getData(size_t j) const;
1371
1373 Teuchos::ArrayRCP<Scalar> getDataNonConst(size_t j);
1374
1382 void
1383 get1dCopy(const Teuchos::ArrayView<Scalar>& A,
1384 const size_t LDA) const;
1385
1392 void
1393 get2dCopy(const Teuchos::ArrayView<const Teuchos::ArrayView<Scalar>>& ArrayOfPtrs) const;
1394
1400 Teuchos::ArrayRCP<const Scalar> get1dView() const;
1401
1403 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar>> get2dView() const;
1404
1410 Teuchos::ArrayRCP<Scalar> get1dViewNonConst();
1411
1413 Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar>> get2dViewNonConst();
1414
1417 typename dual_view_type::t_host::const_type getLocalViewHost(Access::ReadOnlyStruct) const;
1418
1421 typename dual_view_type::t_host getLocalViewHost(Access::ReadWriteStruct);
1422
1425 typename dual_view_type::t_host getLocalViewHost(Access::OverwriteAllStruct);
1426
1429 typename dual_view_type::t_dev::const_type getLocalViewDevice(Access::ReadOnlyStruct) const;
1430
1433 typename dual_view_type::t_dev getLocalViewDevice(Access::ReadWriteStruct);
1434
1437 typename dual_view_type::t_dev getLocalViewDevice(Access::OverwriteAllStruct);
1438
1443 wrapped_dual_view_type getWrappedDualView() const;
1444
1446 template <class TargetDeviceType>
1447 bool need_sync() const {
1448 return view_.getDualView().template need_sync<TargetDeviceType>();
1449 }
1450
1452 bool need_sync_host() const;
1453
1455 bool need_sync_device() const;
1456
1485 template <class TargetDeviceType>
1486 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type::const_type
1487 getLocalView(Access::ReadOnlyStruct s) const {
1488 return view_.template getView<TargetDeviceType>(s);
1489 }
1490
1491 template <class TargetDeviceType>
1492 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1493 getLocalView(Access::ReadWriteStruct s) {
1494 return view_.template getView<TargetDeviceType>(s);
1495 }
1496
1497 template <class TargetDeviceType>
1498 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1499 getLocalView(Access::OverwriteAllStruct s) {
1500 return view_.template getView<TargetDeviceType>(s);
1501 }
1502
1504
1506
1520 void
1521 dot(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
1522 const Teuchos::ArrayView<dot_type>& dots) const;
1523
1535 template <typename T>
1536 typename std::enable_if<!(std::is_same<dot_type, T>::value), void>::type
1538 const Teuchos::ArrayView<T>& dots) const {
1539 const size_t sz = static_cast<size_t>(dots.size());
1540 Teuchos::Array<dot_type> dts(sz);
1541 this->dot(A, dts);
1542 for (size_t i = 0; i < sz; ++i) {
1543 // If T and dot_type differ, this does an implicit conversion.
1544 dots[i] = dts[i];
1545 }
1546 }
1547
1549 template <typename T>
1550 typename std::enable_if<!(std::is_same<dot_type, T>::value), void>::type
1552 std::vector<T>& dots) const {
1553 const size_t sz = dots.size();
1554 Teuchos::Array<dot_type> dts(sz);
1555 this->dot(A, dts);
1556 for (size_t i = 0; i < sz; ++i) {
1557 // If T and dot_type differ, this does an implicit conversion.
1558 dots[i] = dts[i];
1559 }
1560 }
1561
1579 void
1581 const Kokkos::View<dot_type*, Kokkos::HostSpace>& norms) const;
1582
1583 template <class ViewType>
1584 void
1585 dot(typename std::enable_if<std::is_same<typename ViewType::value_type, dot_type>::value &&
1586 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value,
1588 const ViewType& dots) const {
1589 const Kokkos::View<dot_type*, Kokkos::HostSpace> h_dots("Tpetra::Dots", dots.extent(0));
1590 this->dot(A, h_dots);
1591 // DEEP_COPY REVIEW - NOT TESTED
1592 Kokkos::deep_copy(dots, h_dots);
1593 }
1594
1607 template <typename T>
1608 typename std::enable_if<!(std::is_same<dot_type, T>::value), void>::type
1610 const Kokkos::View<T*, device_type>& dots) const {
1611 const size_t numDots = dots.extent(0);
1612 Kokkos::View<dot_type*, device_type> dts("MV::dot tmp", numDots);
1613 // Call overload that takes a Kokkos::View<dot_type*, device_type>.
1614 this->dot(A, dts);
1615 // FIXME (mfh 14 Jul 2014) Does this actually work if dot_type
1616 // and T differ? We would need a test for this, but only the
1617 // Sacado and Stokhos packages are likely to care about this use
1618 // case. It could also come up for Kokkos::complex ->
1619 // std::complex conversions, but those two implementations
1620 // should generally be bitwise compatible.
1621 // CT: no this can't possible work .....
1622 // DEEP_COPY REVIEW - NOT TESTED
1623 Kokkos::deep_copy(dots, dts);
1624 }
1625
1628
1631
1639 void scale(const Scalar& alpha);
1640
1649 void scale(const Teuchos::ArrayView<const Scalar>& alpha);
1650
1659 void scale(const Kokkos::View<const impl_scalar_type*, device_type>& alpha);
1660
1669 void
1670 scale(const Scalar& alpha,
1672
1679 void
1680 update(const Scalar& alpha,
1682 const Scalar& beta);
1683
1690 void
1691 update(const Scalar& alpha,
1693 const Scalar& beta,
1695 const Scalar& gamma);
1696
1708 void
1709 norm1(const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1710
1711 template <class ViewType>
1712 typename std::enable_if<std::is_same<typename ViewType::value_type, mag_type>::value &&
1713 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value>::type
1714 norm1(const ViewType& norms) const {
1715 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1716 // this method to be templated. (It only exists in case
1717 // HostSpace = device_type::memory_space.)
1718 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1719 host_norms_view_type h_norms("Tpetra::MV::h_norms", norms.extent(0));
1720 this->norm1(h_norms);
1721 // DEEP_COPY REVIEW - HOST-TO-DEVICE
1722 Kokkos::deep_copy(execution_space(), norms, h_norms);
1723 }
1724
1740 template <typename T>
1741 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1742 norm1(const Kokkos::View<T*, device_type>& norms) const {
1743 const size_t numNorms = norms.extent(0);
1744 Kokkos::View<mag_type*, device_type> tmpNorms("MV::norm1 tmp", numNorms);
1745 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1746 this->norm1(tmpNorms);
1747 // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1748 // and T differ? We would need a test for this, but only the
1749 // Sacado and Stokhos packages are likely to care about this use
1750 // case. It could also come up with Kokkos::complex ->
1751 // std::complex conversion.
1752 // DEEP_COPY REVIEW - NOT TESTED
1753 Kokkos::deep_copy(norms, tmpNorms);
1754 }
1755
1759 void norm1(const Teuchos::ArrayView<mag_type>& norms) const;
1760
1775 template <typename T>
1776 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1777 norm1(const Teuchos::ArrayView<T>& norms) const {
1778 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1779 const size_type sz = norms.size();
1780 Teuchos::Array<mag_type> theNorms(sz);
1781 this->norm1(theNorms);
1782 for (size_type i = 0; i < sz; ++i) {
1783 // If T and mag_type differ, this does an implicit conversion.
1784 norms[i] = theNorms[i];
1785 }
1786 }
1787
1800 void
1801 norm2(const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1802
1803 template <class ViewType>
1804 typename std::enable_if<std::is_same<typename ViewType::value_type, mag_type>::value &&
1805 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value>::type
1806 norm2(const ViewType& norms) const {
1807 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1808 // this method to be templated. (It only exists in case
1809 // HostSpace = device_type::memory_space.)
1810 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1811 host_norms_view_type h_norms("Tpetra::MV::h_norms", norms.extent(0));
1812 this->norm2(h_norms);
1813 // DEEP_COPY REVIEW - NOT TESTED
1814 Kokkos::deep_copy(norms, h_norms);
1815 }
1816
1830 template <typename T>
1831 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1832 norm2(const Kokkos::View<T*, device_type>& norms) const {
1833 const size_t numNorms = norms.extent(0);
1834 Kokkos::View<mag_type*, device_type> theNorms("MV::norm2 tmp", numNorms);
1835 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1836 this->norm2(theNorms);
1837 // FIXME (mfh 14 Jul 2014) Does this actually work if mag_type
1838 // and T differ? We would need a test for this, but only the
1839 // Sacado and Stokhos packages are likely to care about this use
1840 // case. This could also come up with Kokkos::complex ->
1841 // std::complex conversion.
1842 // DEEP_COPY REVIEW - NOT TESTED
1843 Kokkos::deep_copy(norms, theNorms);
1844 }
1845
1849 void norm2(const Teuchos::ArrayView<mag_type>& norms) const;
1850
1865 template <typename T>
1866 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1867 norm2(const Teuchos::ArrayView<T>& norms) const {
1868 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1869 const size_type sz = norms.size();
1870 Teuchos::Array<mag_type> theNorms(sz);
1871 this->norm2(theNorms);
1872 for (size_type i = 0; i < sz; ++i) {
1873 // If T and mag_type differ, this does an implicit conversion.
1874 norms[i] = theNorms[i];
1875 }
1876 }
1877
1884 void normInf(const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1885
1886 template <class ViewType>
1887 typename std::enable_if<std::is_same<typename ViewType::value_type, mag_type>::value &&
1888 std::is_same<typename ViewType::memory_space, typename device_type::memory_space>::value>::type
1889 normInf(const ViewType& norms) const {
1890 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1891 // this method to be templated. (It only exists in case
1892 // HostSpace = device_type::memory_space.)
1893 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1894 host_norms_view_type h_norms("Tpetra::MV::h_norms", norms.extent(0));
1895 this->normInf(h_norms);
1896 // DEEP_COPY REVIEW - HOST-TO-DEVICE
1897 Kokkos::deep_copy(execution_space(), norms, h_norms);
1898 }
1899
1913 template <typename T>
1914 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1915 normInf(const Kokkos::View<T*, device_type>& norms) const {
1916 const size_t numNorms = norms.extent(0);
1917 Kokkos::View<mag_type*, device_type> theNorms("MV::normInf tmp", numNorms);
1918 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1919 this->normInf(theNorms);
1920 // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1921 // and T differ? We would need a test for this, but only the
1922 // Sacado and Stokhos packages are likely to care about this use
1923 // case. This could also come up with Kokkos::complex ->
1924 // std::complex conversion.
1925 // DEEP_COPY REVIEW - NOT TESTED
1926 Kokkos::deep_copy(norms, theNorms);
1927 }
1928
1933 void normInf(const Teuchos::ArrayView<mag_type>& norms) const;
1934
1950 template <typename T>
1951 typename std::enable_if<!(std::is_same<mag_type, T>::value), void>::type
1952 normInf(const Teuchos::ArrayView<T>& norms) const {
1953 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1954 const size_type sz = norms.size();
1955 Teuchos::Array<mag_type> theNorms(sz);
1956 this->norm2(theNorms);
1957 for (size_type i = 0; i < sz; ++i) {
1958 // If T and mag_type differ, this does an implicit conversion.
1959 norms[i] = theNorms[i];
1960 }
1961 }
1962
1967 void meanValue(const Teuchos::ArrayView<impl_scalar_type>& means) const;
1968
1969 template <typename T>
1970 typename std::enable_if<!std::is_same<impl_scalar_type, T>::value, void>::type
1971 meanValue(const Teuchos::ArrayView<T>& means) const {
1972 typedef typename Teuchos::Array<T>::size_type size_type;
1973 const size_type numMeans = means.size();
1974
1975 Teuchos::Array<impl_scalar_type> theMeans(numMeans);
1976 this->meanValue(theMeans());
1977 for (size_type k = 0; k < numMeans; ++k) {
1978 means[k] = static_cast<T>(theMeans[k]);
1979 }
1980 }
1981
1987 void
1988 multiply(Teuchos::ETransp transA,
1989 Teuchos::ETransp transB,
1990 const Scalar& alpha,
1991 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
1992 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
1993 const Scalar& beta);
1994
2015 void
2016 elementWiseMultiply(Scalar scalarAB,
2017 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2018 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2019 Scalar scalarThis);
2021
2023
2025 size_t getNumVectors() const;
2026
2028 size_t getLocalLength() const;
2029
2032
2038 size_t getStride() const;
2039
2043 bool isConstantStride() const;
2044
2048 bool aliases(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& other) const;
2049
2051
2053
2054
2056 virtual std::string description() const override;
2057
2086 virtual void
2087 describe(Teuchos::FancyOStream& out,
2088 const Teuchos::EVerbosityLevel verbLevel =
2089 Teuchos::Describable::verbLevel_default) const override;
2091
2105 virtual void
2106 removeEmptyProcessesInPlace(const Teuchos::RCP<const map_type>& newMap) override;
2107
2118 void setCopyOrView(const Teuchos::DataAccess copyOrView) {
2120 copyOrView == Teuchos::Copy, std::invalid_argument,
2121 "Tpetra::MultiVector::setCopyOrView: The Kokkos refactor version of "
2122 "MultiVector _only_ implements view semantics. You may not call this "
2123 "method with copyOrView = Teuchos::Copy. The only valid argument is "
2124 "Teuchos::View.");
2125 }
2126
2130 // This method ONLY exists for the circa 2014 "Kokkos refactor"
2131 // effort. It ALWAYS returns Teuchos::View.
2135 Teuchos::DataAccess getCopyOrView() const {
2136 return Teuchos::View;
2137 }
2138
2153 void
2155
2158 template <class T>
2159 Teuchos::RCP<MultiVector<T, LocalOrdinal, GlobalOrdinal, Node>>
2160 convert() const;
2161
2162 // \brief Checks to see if the local length, number of vectors and size of Scalar type match
2171
2172 private:
2174 using base_type = DistObject<scalar_type, local_ordinal_type,
2176
2177 protected:
2178 template <class DS, class DL, class DG, class DN,
2179 class SS, class SL, class SG, class SN>
2180 friend void ::Tpetra::deep_copy(MultiVector<DS, DL, DG, DN>& dst,
2181 const MultiVector<SS, SL, SG, SN>& src);
2182
2190
2203 Teuchos::Array<size_t> whichVectors_;
2204
2205 template <class SC, class LO, class GO, class NT>
2206 friend ::Teuchos::ArrayView<const size_t> getMultiVectorWhichVectors(const ::Tpetra::MultiVector<SC, LO, GO, NT>& X);
2207
2209
2211
2218 std::string
2219 descriptionImpl(const std::string& className) const;
2220
2227 std::string
2228 localDescribeToString(const Teuchos::EVerbosityLevel vl) const;
2229
2243 void
2244 describeImpl(Teuchos::FancyOStream& out,
2245 const std::string& className,
2246 const Teuchos::EVerbosityLevel verbLevel =
2247 Teuchos::Describable::verbLevel_default) const;
2248
2249 // Return true if and only if VectorIndex is a valid column index.
2250 bool vectorIndexOutOfRange(const size_t VectorIndex) const;
2251
2256 template <class T>
2257 Teuchos::ArrayRCP<T>
2258 getSubArrayRCP(Teuchos::ArrayRCP<T> arr, size_t j) const;
2259
2261 size_t getOrigNumLocalRows() const;
2262
2264 size_t getOrigNumLocalCols() const;
2265
2267
2269
2275 typename DistObject<scalar_type,
2279
2284 virtual bool
2285 checkSizes(const SrcDistObject& sourceObj) override;
2286
2288 virtual size_t constantNumberOfPackets() const override;
2289
2290 virtual void copyAndPermute(
2291 const SrcDistObject& sourceObj, const size_t numSameIDs,
2292 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs,
2293 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs,
2294 const CombineMode CM, const execution_space& space) override;
2295
2296 virtual void copyAndPermute(
2297 const SrcDistObject& sourceObj, const size_t numSameIDs,
2298 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs,
2299 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs,
2300 const CombineMode CM) override;
2301
2302 virtual void
2303 packAndPrepare(const SrcDistObject& sourceObj,
2304 const Kokkos::DualView<
2305 const local_ordinal_type*,
2307 Kokkos::DualView<
2309 buffer_device_type>& exports,
2310 Kokkos::DualView<
2311 size_t*,
2312 buffer_device_type> /* numPacketsPerLID */,
2313 size_t& constantNumPackets,
2314 const execution_space& space) override;
2315
2316 virtual void
2317 packAndPrepare(const SrcDistObject& sourceObj,
2318 const Kokkos::DualView<
2319 const local_ordinal_type*,
2321 Kokkos::DualView<
2323 buffer_device_type>& exports,
2324 Kokkos::DualView<
2325 size_t*,
2326 buffer_device_type> /* numPacketsPerLID */,
2327 size_t& constantNumPackets) override;
2328
2329 virtual void
2330 unpackAndCombine(const Kokkos::DualView<
2331 const local_ordinal_type*,
2333 Kokkos::DualView<
2336 imports,
2337 Kokkos::DualView<
2338 size_t*,
2339 buffer_device_type> /* numPacketsPerLID */,
2340 const size_t constantNumPackets,
2341 const CombineMode CM,
2342 const execution_space& space) override;
2343
2344 virtual void
2345 unpackAndCombine(const Kokkos::DualView<
2346 const local_ordinal_type*,
2348 Kokkos::DualView<
2351 imports,
2352 Kokkos::DualView<
2353 size_t*,
2354 buffer_device_type> /* numPacketsPerLID */,
2355 const size_t constantNumPackets,
2356 const CombineMode CM) override;
2357
2358 private:
2359 // If comm buffers can be aliased to the data view, use this
2360 // implementation.
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 // If comm buffers cannot be aliased to the data view, use this
2372 // implementation. (Just calls DistObject::reallocImportsIfNeeded.)
2373 template <class NO = Node>
2374 typename std::enable_if<!std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2375 typename NO::device_type::memory_space>::value,
2376 bool>::type
2377 reallocImportsIfNeededImpl(const size_t newSize,
2378 const bool verbose,
2379 const std::string* prefix,
2380 const bool areRemoteLIDsContiguous,
2381 const CombineMode CM);
2382
2383 protected:
2384 virtual bool
2385 reallocImportsIfNeeded(const size_t newSize,
2386 const bool verbose,
2387 const std::string* prefix,
2388 const bool areRemoteLIDsContiguous = false,
2389 const CombineMode CM = INSERT) override;
2390
2391 public:
2392 bool importsAreAliased();
2393
2394 protected:
2395 Kokkos::DualView<impl_scalar_type*, buffer_device_type> unaliased_imports_;
2396
2398}; // class MultiVector
2399
2400template <class SC, class LO, class GO, class NT>
2401Teuchos::ArrayView<const size_t>
2402getMultiVectorWhichVectors(const MultiVector<SC, LO, GO, NT>& X) {
2403 return X.whichVectors_();
2404}
2405
2408template <class ST, class LO, class GO, class NT>
2410 const MultiVector<ST, LO, GO, NT>& src) {
2411 // NOTE (mfh 11 Sep 2014) We can't implement deep_copy with
2412 // shallow-copy operator=, because that would invalidate existing
2413 // views of dst!
2414 dst.assign(src);
2415}
2416
2417// Implementation of the most generic version of MultiVector deep_copy.
2418template <class DS, class DL, class DG, class DN,
2419 class SS, class SL, class SG, class SN>
2421 const MultiVector<SS, SL, SG, SN>& src) {
2422 using ::Tpetra::getMultiVectorWhichVectors;
2423
2425 dst.getGlobalLength() != src.getGlobalLength() ||
2426 dst.getNumVectors() != src.getNumVectors(),
2427 std::invalid_argument,
2428 "Tpetra::deep_copy: Global dimensions of the two Tpetra::MultiVector "
2429 "objects do not match. src has dimensions ["
2430 << src.getGlobalLength()
2431 << "," << src.getNumVectors() << "], and dst has dimensions ["
2432 << dst.getGlobalLength() << "," << dst.getNumVectors() << "].");
2433
2434 // FIXME (mfh 28 Jul 2014) Don't throw; just set a local error flag.
2436 dst.getLocalLength() != src.getLocalLength(), std::invalid_argument,
2437 "Tpetra::deep_copy: The local row counts of the two Tpetra::MultiVector "
2438 "objects do not match. src has "
2439 << src.getLocalLength() << " row(s) "
2440 << " and dst has " << dst.getLocalLength() << " row(s).");
2441
2442 const bool srcMostUpToDateOnDevice = !src.need_sync_device();
2443
2444 if (src.isConstantStride() && dst.isConstantStride()) {
2447 dst.getLocalViewDevice(Access::OverwriteAll),
2448 src.getLocalViewDevice(Access::ReadOnly));
2449 } else {
2451 dst.getLocalViewDevice(Access::OverwriteAll),
2452 src.getLocalViewHost(Access::ReadOnly));
2453 }
2454 } else {
2455 auto dstWhichVecs = getMultiVectorWhichVectors(dst);
2456 auto srcWhichVecs = getMultiVectorWhichVectors(src);
2457
2459 Details::localDeepCopy(dst.getLocalViewDevice(Access::OverwriteAll),
2460 src.getLocalViewDevice(Access::ReadOnly),
2461 dst.isConstantStride(),
2462 src.isConstantStride(),
2464 srcWhichVecs);
2465 } else {
2466 Details::localDeepCopy(dst.getLocalViewDevice(Access::OverwriteAll),
2467 src.getLocalViewHost(Access::ReadOnly),
2468 dst.isConstantStride(),
2469 src.isConstantStride(),
2471 srcWhichVecs);
2472 }
2473 }
2474}
2475} // namespace Tpetra
2476
2477namespace Teuchos {
2478
2479// Give Teuchos::TypeNameTraits<Tpetra::MultiVector<...> > a
2480// human-readable definition.
2481template <class SC, class LO, class GO, class NT>
2482class TypeNameTraits<Tpetra::MultiVector<SC, LO, GO, NT>> {
2483 public:
2484 static std::string name() {
2485 return std::string("Tpetra::MultiVector<") +
2486 TypeNameTraits<SC>::name() + "," +
2487 TypeNameTraits<LO>::name() + "," +
2488 TypeNameTraits<GO>::name() + "," +
2489 TypeNameTraits<NT>::name() + ">";
2490 }
2491
2492 static std::string
2493 concreteName(const Tpetra::MultiVector<SC, LO, GO, NT>&) {
2494 return name();
2495 }
2496};
2497} // namespace Teuchos
2498
2499#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.
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,...
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
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.
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
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.
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.