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//
4// Tpetra: Templated Linear Algebra Services Package
5// Copyright (2008) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ************************************************************************
40// @HEADER
41
42// clang-format off
43#ifndef TPETRA_MULTIVECTOR_DECL_HPP
44#define TPETRA_MULTIVECTOR_DECL_HPP
45
48
50#include "Tpetra_Vector_fwd.hpp"
52#include "Tpetra_DistObject.hpp"
53#include "Tpetra_Map_fwd.hpp"
55#include "Kokkos_DualView.hpp"
56#include "Teuchos_BLAS_types.hpp"
57#include "Teuchos_DataAccess.hpp"
58#include "Teuchos_Range1D.hpp"
59#include "Kokkos_ArithTraits.hpp"
60#include "Kokkos_InnerProductSpaceTraits.hpp"
61#include "Tpetra_KokkosRefactor_Details_MultiVectorLocalDeepCopy.hpp"
62#include "Tpetra_Access.hpp"
63#include "Tpetra_Details_WrappedDualView.hpp"
64#include <type_traits>
65
66#ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
67#ifndef DOXYGEN_SHOULD_SKIP_THIS
68namespace Teuchos {
69 template<class OrdinalType, class ScalarType>
70 class SerialDenseMatrix; // forward declaration
71}
72#endif // DOXYGEN_SHOULD_SKIP_THIS
73#endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
74
75
76namespace Tpetra {
77
78
99 template <class DS, class DL, class DG, class DN,
100 class SS, class SL, class SG, class SN>
101 void
103 const MultiVector<SS, SL, SG, SN>& src);
104
105#ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
112 template <class ST, class LO, class GO, class NT>
113 void
115 const Teuchos::SerialDenseMatrix<int, ST>& src);
116
123 template <class ST, class LO, class GO, class NT>
124 void
125 deep_copy (Teuchos::SerialDenseMatrix<int, ST>& dst,
126 const MultiVector<ST, LO, GO, NT>& src);
127#endif // HAVE_TPETRACORE_TEUCHOSNUMERICS
128
136 template <class ST, class LO, class GO, class NT>
139
149 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
150 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
152 const size_t numVectors);
153
154 // WARNING NOT FOR USERS
155 // This means we don't need to make MultiVector a friend of
156 // Vector or of itself (with different template parameters).
157 template<class SC, class LO, class GO, class NT>
158 Teuchos::ArrayView<const size_t>
159 getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X);
160
161
381 template <class Scalar,
382 class LocalOrdinal,
383 class GlobalOrdinal,
384 class Node>
386 public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node>
387 {
388 public:
390
391
393 using scalar_type = Scalar;
410 typename Kokkos::ArithTraits<Scalar>::val_type;
411
422
428 using dot_type =
429 typename Kokkos::Details::InnerProductSpaceTraits<impl_scalar_type>::dot_type;
430
437 using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
438
443 using execution_space = typename device_type::execution_space;
444
467 using dual_view_type = Kokkos::DualView<impl_scalar_type**,
468 Kokkos::LayoutLeft,
470 using wrapped_dual_view_type = Details::WrappedDualView<dual_view_type>;
471
472 using host_view_type = typename dual_view_type::t_host;
473 using device_view_type = typename dual_view_type::t_dev;
474
476
478
481
488 MultiVector (const Teuchos::RCP<const map_type>& map,
489 const size_t numVecs,
490 const bool zeroOut = true);
491
503 const Teuchos::DataAccess copyOrView);
504
520 MultiVector (const Teuchos::RCP<const map_type>& map,
521 const Teuchos::ArrayView<const Scalar>& A,
522 const size_t LDA,
523 const size_t NumVectors);
524
538 MultiVector (const Teuchos::RCP<const map_type>& map,
539 const Teuchos::ArrayView<const Teuchos::ArrayView<const Scalar> >&ArrayOfPtrs,
540 const size_t NumVectors);
541
554 MultiVector (const Teuchos::RCP<const map_type>& map,
555 const dual_view_type& view);
556
595 MultiVector (const Teuchos::RCP<const map_type>& map,
596 const typename dual_view_type::t_dev& d_view);
597
620 MultiVector (const Teuchos::RCP<const map_type>& map,
621 const dual_view_type& view,
622 const dual_view_type& origView);
623
632 MultiVector (const Teuchos::RCP<const map_type>& map,
633 const wrapped_dual_view_type& d_view);
634
635
636 protected:
637
643 const size_t j);
644
645 public:
646
664 MultiVector (const Teuchos::RCP<const map_type>& map,
665 const dual_view_type& view,
666 const Teuchos::ArrayView<const size_t>& whichVectors);
667
685 MultiVector (const Teuchos::RCP<const map_type>& map,
686 const wrapped_dual_view_type& view,
687 const Teuchos::ArrayView<const size_t>& whichVectors);
688
689
717 MultiVector (const Teuchos::RCP<const map_type>& map,
718 const dual_view_type& view,
719 const dual_view_type& origView,
720 const Teuchos::ArrayView<const size_t>& whichVectors);
721
783 const Teuchos::RCP<const map_type>& subMap,
784 const local_ordinal_type rowOffset = 0);
785
793 const map_type& subMap,
794 const size_t offset = 0);
795
805
808
816
820
830 virtual ~MultiVector () = default;
831
834
836
838
839 protected:
844 static const bool useAtomicUpdatesByDefault =
845#ifdef KOKKOS_ENABLE_SERIAL
846 ! std::is_same<execution_space, Kokkos::Serial>::value;
847#else
848 true;
849#endif // KOKKOS_ENABLE_SERIAL
850
851 public:
881 void
882 replaceGlobalValue (const GlobalOrdinal gblRow,
883 const size_t col,
884 const impl_scalar_type& value);
885
918 template<typename T>
919 typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
920 replaceGlobalValue (GlobalOrdinal globalRow,
921 size_t col,
922 const T& value)
923 {
924 replaceGlobalValue (globalRow, col, static_cast<impl_scalar_type> (value));
925 }
926
951 void
952 sumIntoGlobalValue (const GlobalOrdinal gblRow,
953 const size_t col,
954 const impl_scalar_type& value,
955 const bool atomic = useAtomicUpdatesByDefault);
956
985 template<typename T>
986 typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
987 sumIntoGlobalValue (const GlobalOrdinal gblRow,
988 const size_t col,
989 const T& val,
990 const bool atomic = useAtomicUpdatesByDefault)
991 {
992 sumIntoGlobalValue (gblRow, col, static_cast<impl_scalar_type> (val), atomic);
993 }
994
1024 void
1025 replaceLocalValue (const LocalOrdinal lclRow,
1026 const size_t col,
1027 const impl_scalar_type& value);
1028
1062 template<typename T>
1063 typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1064 replaceLocalValue (const LocalOrdinal lclRow,
1065 const size_t col,
1066 const T& val)
1067 {
1068 replaceLocalValue (lclRow, col, static_cast<impl_scalar_type> (val));
1069 }
1070
1095 void
1096 sumIntoLocalValue (const LocalOrdinal lclRow,
1097 const size_t col,
1098 const impl_scalar_type& val,
1099 const bool atomic = useAtomicUpdatesByDefault);
1100
1127 template<typename T>
1128 typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1129 sumIntoLocalValue (const LocalOrdinal lclRow,
1130 const size_t col,
1131 const T& val,
1132 const bool atomic = useAtomicUpdatesByDefault)
1133 {
1134 sumIntoLocalValue (lclRow, col, static_cast<impl_scalar_type> (val), atomic);
1135 }
1136
1138 void putScalar (const Scalar& value);
1139
1148 template<typename T>
1149 typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value, void>::type
1150 putScalar (const T& value)
1151 {
1152 putScalar (static_cast<impl_scalar_type> (value));
1153 }
1154
1168
1182 void randomize (const Scalar& minVal, const Scalar& maxVal);
1183
1249 void replaceMap (const Teuchos::RCP<const map_type>& map);
1250
1257 void reduce();
1258
1260
1286
1287
1289 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1290 subCopy (const Teuchos::Range1D& colRng) const;
1291
1293 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1294 subCopy (const Teuchos::ArrayView<const size_t>& cols) const;
1295
1297 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1298 subView (const Teuchos::Range1D& colRng) const;
1299
1301 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1302 subView (const Teuchos::ArrayView<const size_t>& cols) const;
1303
1305 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1306 subViewNonConst (const Teuchos::Range1D& colRng);
1307
1309 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1310 subViewNonConst (const Teuchos::ArrayView<const size_t>& cols);
1311
1374 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1375 offsetView (const Teuchos::RCP<const map_type>& subMap,
1376 const size_t offset) const;
1377
1395 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1396 offsetViewNonConst (const Teuchos::RCP<const map_type>& subMap,
1397 const size_t offset);
1398
1400 Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1401 getVector (const size_t j) const;
1402
1404 Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1405 getVectorNonConst (const size_t j);
1406
1408 Teuchos::ArrayRCP<const Scalar> getData (size_t j) const;
1409
1411 Teuchos::ArrayRCP<Scalar> getDataNonConst (size_t j);
1412
1420 void
1421 get1dCopy (const Teuchos::ArrayView<Scalar>& A,
1422 const size_t LDA) const;
1423
1430 void
1431 get2dCopy (const Teuchos::ArrayView<const Teuchos::ArrayView<Scalar> >& ArrayOfPtrs) const;
1432
1438 Teuchos::ArrayRCP<const Scalar> get1dView () const;
1439
1441 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> > get2dView () const;
1442
1448 Teuchos::ArrayRCP<Scalar> get1dViewNonConst ();
1449
1451 Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> > get2dViewNonConst ();
1452
1455 typename dual_view_type::t_host::const_type getLocalViewHost(Access::ReadOnlyStruct) const;
1456
1459 typename dual_view_type::t_host getLocalViewHost(Access::ReadWriteStruct);
1460
1463 typename dual_view_type::t_host getLocalViewHost(Access::OverwriteAllStruct);
1464
1467 typename dual_view_type::t_dev::const_type getLocalViewDevice(Access::ReadOnlyStruct) const;
1468
1471 typename dual_view_type::t_dev getLocalViewDevice(Access::ReadWriteStruct);
1472
1475 typename dual_view_type::t_dev getLocalViewDevice(Access::OverwriteAllStruct);
1476
1478 template<class TargetDeviceType>
1479 bool need_sync () const {
1480 return view_.getDualView().template need_sync<TargetDeviceType> ();
1481 }
1482
1484 bool need_sync_host () const;
1485
1487 bool need_sync_device () const;
1488
1517 template<class TargetDeviceType>
1518 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type::const_type
1519 getLocalView (Access::ReadOnlyStruct s) const
1520 {
1521 return view_.template getView<TargetDeviceType>(s);
1522 }
1523
1524
1525 template<class TargetDeviceType>
1526 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1527 getLocalView (Access::ReadWriteStruct s)
1528 {
1529 return view_.template getView<TargetDeviceType>(s);
1530 }
1531
1532 template<class TargetDeviceType>
1533 typename std::remove_reference<decltype(std::declval<dual_view_type>().template view<TargetDeviceType>())>::type
1534 getLocalView (Access::OverwriteAllStruct s)
1535 {
1536 return view_.template getView<TargetDeviceType>(s);
1537 }
1538
1540
1542
1556 void
1558 const Teuchos::ArrayView<dot_type>& dots) const;
1559
1571 template <typename T>
1572 typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1574 const Teuchos::ArrayView<T> &dots) const
1575 {
1576 const size_t sz = static_cast<size_t> (dots.size ());
1577 Teuchos::Array<dot_type> dts (sz);
1578 this->dot (A, dts);
1579 for (size_t i = 0; i < sz; ++i) {
1580 // If T and dot_type differ, this does an implicit conversion.
1581 dots[i] = dts[i];
1582 }
1583 }
1584
1586 template <typename T>
1587 typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1589 std::vector<T>& dots) const
1590 {
1591 const size_t sz = dots.size ();
1592 Teuchos::Array<dot_type> dts (sz);
1593 this->dot (A, dts);
1594 for (size_t i = 0; i < sz; ++i) {
1595 // If T and dot_type differ, this does an implicit conversion.
1596 dots[i] = dts[i];
1597 }
1598 }
1599
1617 void
1619 const Kokkos::View<dot_type*, Kokkos::HostSpace>& norms) const;
1620
1621 template<class ViewType>
1622 void
1623 dot (typename std::enable_if<std::is_same<typename ViewType::value_type,dot_type>::value &&
1624 std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value,
1626 const ViewType& dots) const {
1627 const Kokkos::View<dot_type*, Kokkos::HostSpace> h_dots("Tpetra::Dots",dots.extent(0));
1628 this->dot (A, h_dots);
1629 // DEEP_COPY REVIEW - NOT TESTED
1630 Kokkos::deep_copy(dots,h_dots);
1631 }
1632
1645 template <typename T>
1646 typename std::enable_if< ! (std::is_same<dot_type, T>::value), void >::type
1648 const Kokkos::View<T*, device_type>& dots) const
1649 {
1650 const size_t numDots = dots.extent (0);
1651 Kokkos::View<dot_type*, device_type> dts ("MV::dot tmp", numDots);
1652 // Call overload that takes a Kokkos::View<dot_type*, device_type>.
1653 this->dot (A, dts);
1654 // FIXME (mfh 14 Jul 2014) Does this actually work if dot_type
1655 // and T differ? We would need a test for this, but only the
1656 // Sacado and Stokhos packages are likely to care about this use
1657 // case. It could also come up for Kokkos::complex ->
1658 // std::complex conversions, but those two implementations
1659 // should generally be bitwise compatible.
1660 // CT: no this can't possible work .....
1661 // DEEP_COPY REVIEW - NOT TESTED
1662 Kokkos::deep_copy (dots, dts);
1663 }
1664
1667
1670
1678 void scale (const Scalar& alpha);
1679
1688 void scale (const Teuchos::ArrayView<const Scalar>& alpha);
1689
1698 void scale (const Kokkos::View<const impl_scalar_type*, device_type>& alpha);
1699
1708 void
1709 scale (const Scalar& alpha,
1711
1718 void
1719 update (const Scalar& alpha,
1721 const Scalar& beta);
1722
1729 void
1730 update (const Scalar& alpha,
1732 const Scalar& beta,
1734 const Scalar& gamma);
1735
1747 void
1748 norm1 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1749
1750 template<class ViewType>
1751 typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1752 std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1753 norm1 (const ViewType& norms) const {
1754 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1755 // this method to be templated. (It only exists in case
1756 // HostSpace = device_type::memory_space.)
1757 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1758 host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1759 this->norm1 (h_norms);
1760 // DEEP_COPY REVIEW - HOST-TO-DEVICE
1761 Kokkos::deep_copy (execution_space(), norms, h_norms);
1762 }
1763
1779 template <typename T>
1780 typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1781 norm1 (const Kokkos::View<T*, device_type>& norms) const
1782 {
1783 const size_t numNorms = norms.extent (0);
1784 Kokkos::View<mag_type*, device_type> tmpNorms ("MV::norm1 tmp", numNorms);
1785 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1786 this->norm1 (tmpNorms);
1787 // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1788 // and T differ? We would need a test for this, but only the
1789 // Sacado and Stokhos packages are likely to care about this use
1790 // case. It could also come up with Kokkos::complex ->
1791 // std::complex conversion.
1792 // DEEP_COPY REVIEW - NOT TESTED
1793 Kokkos::deep_copy (norms, tmpNorms);
1794 }
1795
1799 void norm1 (const Teuchos::ArrayView<mag_type>& norms) const;
1800
1815 template <typename T>
1816 typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1817 norm1 (const Teuchos::ArrayView<T>& norms) const
1818 {
1819 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1820 const size_type sz = norms.size ();
1821 Teuchos::Array<mag_type> theNorms (sz);
1822 this->norm1 (theNorms);
1823 for (size_type i = 0; i < sz; ++i) {
1824 // If T and mag_type differ, this does an implicit conversion.
1825 norms[i] = theNorms[i];
1826 }
1827 }
1828
1841 void
1842 norm2 (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1843
1844 template<class ViewType>
1845 typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1846 std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1847 norm2 (const ViewType& norms) const {
1848 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1849 // this method to be templated. (It only exists in case
1850 // HostSpace = device_type::memory_space.)
1851 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1852 host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1853 this->norm2 (h_norms);
1854 // DEEP_COPY REVIEW - NOT TESTED
1855 Kokkos::deep_copy (norms, h_norms);
1856 }
1857
1871 template<typename T>
1872 typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1873 norm2 (const Kokkos::View<T*, device_type>& norms) const
1874 {
1875 const size_t numNorms = norms.extent (0);
1876 Kokkos::View<mag_type*, device_type> theNorms ("MV::norm2 tmp", numNorms);
1877 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1878 this->norm2 (theNorms);
1879 // FIXME (mfh 14 Jul 2014) Does this actually work if mag_type
1880 // and T differ? We would need a test for this, but only the
1881 // Sacado and Stokhos packages are likely to care about this use
1882 // case. This could also come up with Kokkos::complex ->
1883 // std::complex conversion.
1884 // DEEP_COPY REVIEW - NOT TESTED
1885 Kokkos::deep_copy (norms, theNorms);
1886 }
1887
1891 void norm2 (const Teuchos::ArrayView<mag_type>& norms) const;
1892
1907 template <typename T>
1908 typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1909 norm2 (const Teuchos::ArrayView<T>& norms) const
1910 {
1911 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1912 const size_type sz = norms.size ();
1913 Teuchos::Array<mag_type> theNorms (sz);
1914 this->norm2 (theNorms);
1915 for (size_type i = 0; i < sz; ++i) {
1916 // If T and mag_type differ, this does an implicit conversion.
1917 norms[i] = theNorms[i];
1918 }
1919 }
1920
1927 void normInf (const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms) const;
1928
1929 template<class ViewType>
1930 typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1931 std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1932 normInf (const ViewType& norms) const {
1933 // FIXME (mfh 11 Apr 2019) The enable_ifs make it useless for
1934 // this method to be templated. (It only exists in case
1935 // HostSpace = device_type::memory_space.)
1936 using host_norms_view_type = Kokkos::View<mag_type*, Kokkos::HostSpace>;
1937 host_norms_view_type h_norms ("Tpetra::MV::h_norms", norms.extent (0));
1938 this->normInf (h_norms);
1939 // DEEP_COPY REVIEW - HOST-TO-DEVICE
1940 Kokkos::deep_copy (execution_space(), norms, h_norms);
1941 }
1942
1956 template<typename T>
1957 typename std::enable_if< ! (std::is_same<mag_type, T>::value), void >::type
1958 normInf (const Kokkos::View<T*, device_type>& norms) const
1959 {
1960 const size_t numNorms = norms.extent (0);
1961 Kokkos::View<mag_type*, device_type> theNorms ("MV::normInf tmp", numNorms);
1962 // Call overload that takes a Kokkos::View<mag_type*, device_type>.
1963 this->normInf (theNorms);
1964 // FIXME (mfh 15 Jul 2014) Does this actually work if mag_type
1965 // and T differ? We would need a test for this, but only the
1966 // Sacado and Stokhos packages are likely to care about this use
1967 // case. This could also come up with Kokkos::complex ->
1968 // std::complex conversion.
1969 // DEEP_COPY REVIEW - NOT TESTED
1970 Kokkos::deep_copy (norms, theNorms);
1971 }
1972
1977 void normInf (const Teuchos::ArrayView<mag_type>& norms) const;
1978
1994 template <typename T>
1995 typename std::enable_if< ! (std::is_same<mag_type,T>::value), void >::type
1996 normInf (const Teuchos::ArrayView<T>& norms) const
1997 {
1998 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1999 const size_type sz = norms.size ();
2000 Teuchos::Array<mag_type> theNorms (sz);
2001 this->norm2 (theNorms);
2002 for (size_type i = 0; i < sz; ++i) {
2003 // If T and mag_type differ, this does an implicit conversion.
2004 norms[i] = theNorms[i];
2005 }
2006 }
2007
2008
2013 void meanValue (const Teuchos::ArrayView<impl_scalar_type>& means) const;
2014
2015 template <typename T>
2016 typename std::enable_if<! std::is_same<impl_scalar_type, T>::value, void>::type
2017 meanValue (const Teuchos::ArrayView<T>& means) const
2018 {
2019 typedef typename Teuchos::Array<T>::size_type size_type;
2020 const size_type numMeans = means.size ();
2021
2022 Teuchos::Array<impl_scalar_type> theMeans (numMeans);
2023 this->meanValue (theMeans ());
2024 for (size_type k = 0; k < numMeans; ++k) {
2025 means[k] = static_cast<T> (theMeans[k]);
2026 }
2027 }
2028
2034 void
2035 multiply (Teuchos::ETransp transA,
2036 Teuchos::ETransp transB,
2037 const Scalar& alpha,
2040 const Scalar& beta);
2041
2062 void
2063 elementWiseMultiply (Scalar scalarAB,
2066 Scalar scalarThis);
2068
2070
2072 size_t getNumVectors() const;
2073
2075 size_t getLocalLength() const;
2076
2079
2085 size_t getStride() const;
2086
2090 bool isConstantStride() const;
2091
2096
2098
2100
2101
2103 virtual std::string description() const override;
2104
2133 virtual void
2134 describe (Teuchos::FancyOStream& out,
2135 const Teuchos::EVerbosityLevel verbLevel =
2136 Teuchos::Describable::verbLevel_default) const override;
2138
2152 virtual void
2153 removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap) override;
2154
2165 void setCopyOrView (const Teuchos::DataAccess copyOrView) {
2166 TEUCHOS_TEST_FOR_EXCEPTION(
2167 copyOrView == Teuchos::Copy, std::invalid_argument,
2168 "Tpetra::MultiVector::setCopyOrView: The Kokkos refactor version of "
2169 "MultiVector _only_ implements view semantics. You may not call this "
2170 "method with copyOrView = Teuchos::Copy. The only valid argument is "
2171 "Teuchos::View.");
2172 }
2173
2177 // This method ONLY exists for the circa 2014 "Kokkos refactor"
2178 // effort. It ALWAYS returns Teuchos::View.
2182 Teuchos::DataAccess getCopyOrView () const {
2183 return Teuchos::View;
2184 }
2185
2200 void
2202
2205 template <class T>
2206 Teuchos::RCP<MultiVector<T, LocalOrdinal, GlobalOrdinal, Node> >
2207 convert () const;
2208
2209
2210 // \brief Checks to see if the local length, number of vectors and size of Scalar type match
2219
2220 private:
2222 using base_type = DistObject<scalar_type, local_ordinal_type,
2224
2225 protected:
2226 template <class DS, class DL, class DG, class DN,
2227 class SS, class SL, class SG, class SN>
2228 friend void
2229 ::Tpetra::deep_copy (MultiVector<DS, DL, DG, DN>& dst,
2230 const MultiVector<SS, SL, SG, SN>& src);
2231
2238 mutable wrapped_dual_view_type view_;
2239
2252 Teuchos::Array<size_t> whichVectors_;
2253
2254 template<class SC, class LO, class GO, class NT>
2255 friend ::Teuchos::ArrayView<const size_t> getMultiVectorWhichVectors (const ::Tpetra::MultiVector<SC, LO, GO, NT>& X);
2256
2258
2260
2267 std::string
2268 descriptionImpl (const std::string& className) const;
2269
2276 std::string
2277 localDescribeToString (const Teuchos::EVerbosityLevel vl) const;
2278
2292 void
2293 describeImpl (Teuchos::FancyOStream& out,
2294 const std::string& className,
2295 const Teuchos::EVerbosityLevel verbLevel =
2296 Teuchos::Describable::verbLevel_default) const;
2297
2298 // Return true if and only if VectorIndex is a valid column index.
2299 bool vectorIndexOutOfRange (const size_t VectorIndex) const;
2300
2305 template <class T>
2306 Teuchos::ArrayRCP<T>
2307 getSubArrayRCP (Teuchos::ArrayRCP<T> arr, size_t j) const;
2308
2310 size_t getOrigNumLocalRows () const;
2311
2313 size_t getOrigNumLocalCols () const;
2314
2316
2318
2324 typename DistObject<scalar_type,
2328
2333 virtual bool
2334 checkSizes (const SrcDistObject& sourceObj) override;
2335
2337 virtual size_t constantNumberOfPackets () const override;
2338
2339 // clang-format on
2340 virtual void copyAndPermute(
2341 const SrcDistObject &sourceObj, const size_t numSameIDs,
2342 const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2343 &permuteToLIDs,
2344 const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2345 &permuteFromLIDs,
2346 const CombineMode CM, const execution_space &space) override;
2347
2348 virtual void copyAndPermute(
2349 const SrcDistObject &sourceObj, const size_t numSameIDs,
2350 const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2351 &permuteToLIDs,
2352 const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
2353 &permuteFromLIDs,
2354 const CombineMode CM) override;
2355 // clang-format off
2356
2357 virtual void
2358 packAndPrepare
2359 (const SrcDistObject& sourceObj,
2360 const Kokkos::DualView<
2361 const local_ordinal_type*,
2362 buffer_device_type>& exportLIDs,
2363 Kokkos::DualView<
2365 buffer_device_type>& exports,
2366 Kokkos::DualView<
2367 size_t*,
2368 buffer_device_type> /* numPacketsPerLID */,
2369 size_t& constantNumPackets,
2370 const execution_space &space) override;
2371
2372 virtual void
2373 packAndPrepare
2374 (const SrcDistObject& sourceObj,
2375 const Kokkos::DualView<
2376 const local_ordinal_type*,
2377 buffer_device_type>& exportLIDs,
2378 Kokkos::DualView<
2380 buffer_device_type>& exports,
2381 Kokkos::DualView<
2382 size_t*,
2383 buffer_device_type> /* numPacketsPerLID */,
2384 size_t& constantNumPackets) override;
2385
2386 virtual void
2387 unpackAndCombine
2388 (const Kokkos::DualView<
2389 const local_ordinal_type*,
2390 buffer_device_type>& importLIDs,
2391 Kokkos::DualView<
2393 buffer_device_type> imports,
2394 Kokkos::DualView<
2395 size_t*,
2396 buffer_device_type> /* numPacketsPerLID */,
2397 const size_t constantNumPackets,
2398 const CombineMode CM,
2399 const execution_space &space) override;
2400
2401 virtual void
2402 unpackAndCombine
2403 (const Kokkos::DualView<
2404 const local_ordinal_type*,
2405 buffer_device_type>& importLIDs,
2406 Kokkos::DualView<
2408 buffer_device_type> imports,
2409 Kokkos::DualView<
2410 size_t*,
2411 buffer_device_type> /* numPacketsPerLID */,
2412 const size_t constantNumPackets,
2413 const CombineMode CM) override;
2414
2415 private:
2416
2417 // If comm buffers can be aliased to the data view, use this
2418 // implementation.
2419 template<class NO=Node>
2420 typename std::enable_if<std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2421 typename NO::device_type::memory_space>::value, bool>::type
2422 reallocImportsIfNeededImpl (const size_t newSize,
2423 const bool verbose,
2424 const std::string* prefix,
2425 const bool areRemoteLIDsContiguous,
2426 const CombineMode CM);
2427
2428 // If comm buffers cannot be aliased to the data view, use this
2429 // implementation. (Just calls DistObject::reallocImportsIfNeeded.)
2430 template<class NO=Node>
2431 typename std::enable_if<!std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
2432 typename NO::device_type::memory_space>::value, bool>::type
2433 reallocImportsIfNeededImpl (const size_t newSize,
2434 const bool verbose,
2435 const std::string* prefix,
2436 const bool areRemoteLIDsContiguous,
2437 const CombineMode CM);
2438 protected:
2439
2440 virtual bool
2441 reallocImportsIfNeeded (const size_t newSize,
2442 const bool verbose,
2443 const std::string* prefix,
2444 const bool areRemoteLIDsContiguous=false,
2445 const CombineMode CM=INSERT) override;
2446
2447
2448 public:
2449 bool importsAreAliased();
2450
2451 protected:
2452 Kokkos::DualView<impl_scalar_type*, buffer_device_type> unaliased_imports_;
2453
2455 }; // class MultiVector
2456
2457 template<class SC, class LO, class GO, class NT>
2458 Teuchos::ArrayView<const size_t>
2459 getMultiVectorWhichVectors (const MultiVector<SC, LO, GO, NT>& X)
2460 {
2461 return X.whichVectors_ ();
2462 }
2463
2464
2467 template <class ST, class LO, class GO, class NT>
2468 void
2470 const MultiVector<ST, LO, GO, NT>& src)
2471 {
2472 // NOTE (mfh 11 Sep 2014) We can't implement deep_copy with
2473 // shallow-copy operator=, because that would invalidate existing
2474 // views of dst!
2475 dst.assign (src);
2476 }
2477
2478 // Implementation of the most generic version of MultiVector deep_copy.
2479 template <class DS, class DL, class DG, class DN,
2480 class SS, class SL, class SG, class SN>
2481 void
2483 const MultiVector<SS, SL, SG, SN>& src)
2484 {
2485 using ::Tpetra::getMultiVectorWhichVectors;
2486
2487 TEUCHOS_TEST_FOR_EXCEPTION(
2488 dst.getGlobalLength () != src.getGlobalLength () ||
2489 dst.getNumVectors () != src.getNumVectors (), std::invalid_argument,
2490 "Tpetra::deep_copy: Global dimensions of the two Tpetra::MultiVector "
2491 "objects do not match. src has dimensions [" << src.getGlobalLength ()
2492 << "," << src.getNumVectors () << "], and dst has dimensions ["
2493 << dst.getGlobalLength () << "," << dst.getNumVectors () << "].");
2494
2495 // FIXME (mfh 28 Jul 2014) Don't throw; just set a local error flag.
2496 TEUCHOS_TEST_FOR_EXCEPTION(
2497 dst.getLocalLength () != src.getLocalLength (), std::invalid_argument,
2498 "Tpetra::deep_copy: The local row counts of the two Tpetra::MultiVector "
2499 "objects do not match. src has " << src.getLocalLength () << " row(s) "
2500 << " and dst has " << dst.getLocalLength () << " row(s).");
2501
2502 const bool srcMostUpToDateOnDevice = ! src.need_sync_device ();
2503
2504 if (src.isConstantStride () && dst.isConstantStride ()) {
2505 if (srcMostUpToDateOnDevice) {
2507 dst.getLocalViewDevice (Access::OverwriteAll),
2508 src.getLocalViewDevice (Access::ReadOnly));
2509 }
2510 else {
2512 dst.getLocalViewDevice (Access::OverwriteAll),
2513 src.getLocalViewHost (Access::ReadOnly));
2514 }
2515 }
2516 else {
2517 auto dstWhichVecs = getMultiVectorWhichVectors (dst);
2518 auto srcWhichVecs = getMultiVectorWhichVectors (src);
2519
2520 if (srcMostUpToDateOnDevice) {
2521 Details::localDeepCopy (dst.getLocalViewDevice (Access::OverwriteAll),
2522 src.getLocalViewDevice (Access::ReadOnly),
2523 dst.isConstantStride (),
2524 src.isConstantStride (),
2525 dstWhichVecs,
2526 srcWhichVecs);
2527 }
2528 else {
2529 Details::localDeepCopy (dst.getLocalViewDevice (Access::OverwriteAll),
2530 src.getLocalViewHost (Access::ReadOnly),
2531 dst.isConstantStride (),
2532 src.isConstantStride (),
2533 dstWhichVecs,
2534 srcWhichVecs);
2535 }
2536 }
2537 }
2538} // namespace Tpetra
2539
2540
2541namespace Teuchos {
2542
2543 // Give Teuchos::TypeNameTraits<Tpetra::MultiVector<...> > a
2544 // human-readable definition.
2545 template<class SC, class LO, class GO, class NT>
2546 class TypeNameTraits<Tpetra::MultiVector<SC, LO, GO, NT> > {
2547 public:
2548 static std::string name () {
2549 return std::string ("Tpetra::MultiVector<") +
2550 TypeNameTraits<SC>::name () + "," +
2551 TypeNameTraits<LO>::name () + "," +
2552 TypeNameTraits<GO>::name () + "," +
2553 TypeNameTraits<NT>::name () + ">";
2554 }
2555
2556 static std::string
2557 concreteName (const Tpetra::MultiVector<SC, LO, GO, NT>&) {
2558 return name ();
2559 }
2560 };
2561} // namespace Teuchos
2562
2563#endif // TPETRA_MULTIVECTOR_DECL_HPP
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Forward declaration of Tpetra::FEMultiVector.
Forward declaration of Tpetra::Map.
Forward declaration of Tpetra::MultiVector.
Forward declaration of Tpetra::Vector.
A wrapper around Kokkos::DualView to safely manage data that might be replicated between host and dev...
A parallel distribution of indices over processes.
typename node_type::device_type device_type
One or more distributed dense vectors.
MultiVector(const Teuchos::RCP< const map_type > &map, const Teuchos::ArrayView< const Scalar > &A, const size_t LDA, const size_t NumVectors)
Create multivector by copying two-dimensional array of local data.
typename map_type::global_ordinal_type global_ordinal_type
void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,...
void normInf(const Kokkos::View< mag_type *, Kokkos::HostSpace > &norms) const
Compute the infinity-norm of each vector (column), storing the result in a host View.
void get1dCopy(const Teuchos::ArrayView< Scalar > &A, const size_t LDA) const
Fill the given array with a copy of this multivector's local values.
typename DistObject< scalar_type, local_ordinal_type, global_ordinal_type, node_type >::buffer_device_type buffer_device_type
size_t getStride() const
Stride between columns in the multivector.
typename Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
void scale(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Scale in place: this = alpha * A.
Teuchos::RCP< const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subView(const Teuchos::ArrayView< const size_t > &cols) const
Return a const MultiVector with const views of selected columns.
virtual bool reallocImportsIfNeeded(const size_t newSize, const bool verbose, const std::string *prefix, const bool areRemoteLIDsContiguous=false, const CombineMode CM=INSERT) override
Reallocate imports_ if needed.
void reduce()
Sum values of a locally replicated multivector across all processes.
virtual bool checkSizes(const SrcDistObject &sourceObj) override
Whether data redistribution between sourceObj and this object is legal.
void randomize()
Set all values in the multivector to pseudorandom numbers.
typename map_type::local_ordinal_type local_ordinal_type
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
void scale(const Scalar &alpha)
Scale in place: this = alpha*this.
Teuchos::RCP< const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subView(const Teuchos::Range1D &colRng) const
Return a const MultiVector with const views of selected columns.
MultiVector(const Teuchos::RCP< const map_type > &map, const dual_view_type &view, const Teuchos::ArrayView< const size_t > &whichVectors)
Expert mode constructor for noncontiguous views.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type replaceGlobalValue(GlobalOrdinal globalRow, size_t col, const T &value)
Like the above replaceGlobalValue, but only enabled if T differs from impl_scalar_type.
void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< dot_type > &dots) const
Compute the dot product of each corresponding pair of vectors (columns) in A and B.
void describeImpl(Teuchos::FancyOStream &out, const std::string &className, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Implementation of describe() for this class, and its subclass Vector.
Teuchos::RCP< const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > offsetView(const Teuchos::RCP< const map_type > &subMap, const size_t offset) const
Return a const view of a subset of rows.
dual_view_type::t_dev getLocalViewDevice(Access::ReadWriteStruct)
Return a mutable, up-to-date view of this MultiVector's local data on device. This requires that ther...
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap) override
Remove processes owning zero rows from the Map and their communicator.
Teuchos::ArrayRCP< Scalar > get1dViewNonConst()
Nonconst persisting (1-D) view of this multivector's local values.
void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &src)
Copy the contents of src into *this (deep copy).
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy assigment (shallow copy).
MultiVector(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Teuchos::DataAccess copyOrView)
Copy constructor, with option to do deep or shallow copy.
Teuchos::RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(const size_t j)
Return a Vector which is a nonconst view of column j.
void meanValue(const Teuchos::ArrayView< impl_scalar_type > &means) const
Compute mean (average) value of each column.
std::string descriptionImpl(const std::string &className) const
Implementation of description() for this class, and its subclass Vector.
void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &beta)
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
bool need_sync_device() const
Whether this MultiVector needs synchronization to the device.
MultiVector(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const map_type &subMap, const size_t offset=0)
"Offset view" constructor, that takes the new Map as a const Map& rather than by RCP.
void replaceLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &value)
Replace value in host memory, using local (row) index.
virtual void copyAndPermute(const SrcDistObject &sourceObj, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM) override
Perform copies and permutations that are local to the calling (MPI) process.
std::remove_reference< decltype(std::declval< dual_view_type >().templateview< TargetDeviceType >())>::type::const_type getLocalView(Access::ReadOnlyStruct s) const
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type putScalar(const T &value)
Set all values in the multivector with the given value.
void swap(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &mv)
Swap contents of mv with contents of *this.
size_t getLocalLength() const
Local number of rows on the calling process.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type sumIntoGlobalValue(const GlobalOrdinal gblRow, const size_t col, const T &val, const bool atomic=useAtomicUpdatesByDefault)
Like the above sumIntoGlobalValue, but only enabled if T differs from impl_scalar_type.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subCopy(const Teuchos::Range1D &colRng) const
Return a MultiVector with copies of selected columns.
Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
bool need_sync_host() const
Whether this MultiVector needs synchronization to the host.
Teuchos::RCP< const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVector(const size_t j) const
Return a Vector which is a const view of column j.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, device_type > dual_view_type
bool need_sync() const
Whether this MultiVector needs synchronization to the given space.
void norm2(const Kokkos::View< mag_type *, Kokkos::HostSpace > &norms) const
Compute the two-norm of each vector (column), storing the result in a host View.
MultiVector(const Teuchos::RCP< const map_type > &map, const wrapped_dual_view_type &d_view)
Expert mode constructor, that takes a WrappedDualView of the MultiVector's data.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
Teuchos::ArrayRCP< const Scalar > get1dView() const
Const persisting (1-D) view of this multivector's local values.
dual_view_type::t_host getLocalViewHost(Access::ReadWriteStruct)
Return a mutable, up-to-date view of this MultiVector's local data on host. This requires that there ...
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
Teuchos::ArrayRCP< T > getSubArrayRCP(Teuchos::ArrayRCP< T > arr, size_t j) const
Persisting view of j-th column in the given ArrayRCP.
void replaceGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value)
Replace value in host memory, using global row index.
void elementWiseMultiply(Scalar scalarAB, const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Scalar scalarThis)
Multiply a Vector A elementwise by a MultiVector B.
void setCopyOrView(const Teuchos::DataAccess copyOrView)
Set whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
size_t getNumVectors() const
Number of columns in the multivector.
MultiVector(const Teuchos::RCP< const map_type > &map, const wrapped_dual_view_type &view, const Teuchos::ArrayView< const size_t > &whichVectors)
Expert mode constructor for noncontiguous views.
virtual size_t constantNumberOfPackets() const override
Number of packets to send per LID.
void sumIntoLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &val, const bool atomic=useAtomicUpdatesByDefault)
Update (+=) a value in host memory, using local row index.
void norm1(const Teuchos::ArrayView< mag_type > &norms) const
Compute the one-norm of each vector (column).
void replaceMap(const Teuchos::RCP< const map_type > &map)
Replace the underlying Map in place.
Teuchos::DataAccess getCopyOrView() const
Get whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
Teuchos::RCP< MultiVector< T, LocalOrdinal, GlobalOrdinal, Node > > convert() const
Return another MultiVector with the same entries, but converted to a different Scalar type T.
MultiVector(const Teuchos::RCP< const map_type > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, const size_t NumVectors)
Create multivector by copying array of views of local data.
void scale(const Kokkos::View< const impl_scalar_type *, device_type > &alpha)
Scale each column in place: this[j] = alpha[j]*this[j].
dual_view_type::t_dev::const_type getLocalViewDevice(Access::ReadOnlyStruct) const
Return a read-only, up-to-date view of this MultiVector's local data on device. This requires that th...
typename device_type::execution_space execution_space
void norm2(const Teuchos::ArrayView< mag_type > &norms) const
Compute the two-norm of each vector (column).
void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this).
MultiVector(const Teuchos::RCP< const map_type > &map, const dual_view_type &view)
Constructor, that takes a Kokkos::DualView of the MultiVector's data, and returns a MultiVector that ...
void norm1(const Kokkos::View< mag_type *, Kokkos::HostSpace > &norms) const
Compute the one-norm of each vector (column), storing the result in a host view.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const override
Print the object with the given verbosity level to a FancyOStream.
void scale(const Teuchos::ArrayView< const Scalar > &alpha)
Scale each column in place: this[j] = alpha[j]*this[j].
void get2dCopy(const Teuchos::ArrayView< const Teuchos::ArrayView< Scalar > > &ArrayOfPtrs) const
Fill the given array with a copy of this multivector's local values.
void sumIntoGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value, const bool atomic=useAtomicUpdatesByDefault)
Update (+=) a value in host memory, using global row index.
void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Kokkos::View< dot_type *, Kokkos::HostSpace > &norms) const
Compute the dot product of each corresponding pair of vectors (columns) in A and B,...
void normInf(const Teuchos::ArrayView< mag_type > &norms) const
Compute the infinity-norm of each vector (column), storing the result in a Teuchos::ArrayView.
bool aliases(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &other) const
Whether this multivector's memory might alias other. This is conservative: if either this or other is...
dual_view_type::t_dev getLocalViewDevice(Access::OverwriteAllStruct)
Return a mutable view of this MultiVector's local data on device, assuming all existing data will be ...
dual_view_type::t_host::const_type getLocalViewHost(Access::ReadOnlyStruct) const
Return a read-only, up-to-date view of this MultiVector's local data on host. This requires that ther...
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subViewNonConst(const Teuchos::Range1D &colRng)
Return a MultiVector with views of selected columns.
MultiVector(const Teuchos::RCP< const map_type > &map, const dual_view_type &view, const dual_view_type &origView)
Expert mode constructor, that takes a Kokkos::DualView of the MultiVector's data and the "original" K...
MultiVector(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &&)=default
Move constructor (shallow move).
MultiVector(const Teuchos::RCP< const map_type > &map, const dual_view_type &view, const dual_view_type &origView, const Teuchos::ArrayView< const size_t > &whichVectors)
Expert mode constructor for noncontiguous views, with original view.
MultiVector(const Teuchos::RCP< const map_type > &map, const size_t numVecs, const bool zeroOut=true)
Basic constuctor.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subCopy(const Teuchos::ArrayView< const size_t > &cols) const
Return a MultiVector with copies of selected columns.
Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
bool isConstantStride() const
Whether this multivector has constant stride between columns.
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
size_t getOrigNumLocalCols() const
"Original" number of columns in the (local) data.
MultiVector(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const Teuchos::RCP< const map_type > &subMap, const local_ordinal_type rowOffset=0)
"Offset view" constructor; make a view of a contiguous subset of rows on each process.
Teuchos::ArrayRCP< Teuchos::ArrayRCP< Scalar > > get2dViewNonConst()
Return non-const persisting pointers to values.
virtual std::string description() const override
A simple one-line description of this object.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type replaceLocalValue(const LocalOrdinal lclRow, const size_t col, const T &val)
Like the above replaceLocalValue, but only enabled if T differs from impl_scalar_type.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subViewNonConst(const Teuchos::ArrayView< const size_t > &cols)
Return a MultiVector with views of selected columns.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > offsetViewNonConst(const Teuchos::RCP< const map_type > &subMap, const size_t offset)
Return a nonconst view of a subset of rows.
MultiVector(const Teuchos::RCP< const map_type > &map, const typename dual_view_type::t_dev &d_view)
Constructor, that takes a Kokkos::View of the MultiVector's data (living in the Device's memory space...
void randomize(const Scalar &minVal, const Scalar &maxVal)
Set all values in the multivector to pseudorandom numbers in the given range.
dual_view_type::t_host getLocalViewHost(Access::OverwriteAllStruct)
Return a mutable view of this MultiVector's local data on host, assuming all existing data will be ov...
std::string localDescribeToString(const Teuchos::EVerbosityLevel vl) const
Print the calling process' verbose describe() information to the returned string.
std::enable_if<!std::is_same< T, impl_scalar_type >::value &&std::is_convertible< T, impl_scalar_type >::value, void >::type sumIntoLocalValue(const LocalOrdinal lclRow, const size_t col, const T &val, const bool atomic=useAtomicUpdatesByDefault)
Like the above sumIntoLocalValue, but only enabled if T differs from impl_scalar_type.
bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
size_t getOrigNumLocalRows() const
"Original" number of rows in the (local) data.
MultiVector(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy constructor (shallow copy).
Teuchos::ArrayRCP< Teuchos::ArrayRCP< const Scalar > > get2dView() const
Return const persisting pointers to values.
virtual ~MultiVector()=default
Destructor (virtual for memory safety of derived classes).
MultiVector(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const size_t j)
Single-column subview constructor, for derived classes ONLY.
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &gamma)
Update: this = gamma*this + alpha*A + beta*B.
void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)
Update: this = beta*this + alpha*A.
Abstract base class for objects that can be the source of an Import or Export operation.
A distributed dense vector.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createMultiVector(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const size_t numVectors)
Nonmember MultiVector "constructor": Create a MultiVector from a given Map.
void localDeepCopyConstStride(const DstViewType &dst, const SrcViewType &src)
Implementation of Tpetra::MultiVector deep copy of local data, for when both the source and destinati...
void localDeepCopy(const DstViewType &dst, const SrcViewType &src, const bool dstConstStride, const bool srcConstStride, const DstWhichVecsType &dstWhichVecs, const SrcWhichVecsType &srcWhichVecs)
Implementation of Tpetra::MultiVector deep copy of local data.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
size_t global_size_t
Global size_t object.
MultiVector< ST, LO, GO, NT > createCopy(const MultiVector< ST, LO, GO, NT > &src)
Return a deep copy of the given MultiVector.
CombineMode
Rule for combining data in an Import or Export.
@ INSERT
Insert new values that don't currently exist.