42 #ifndef TPETRA_MULTIVECTOR_DECL_HPP 43 #define TPETRA_MULTIVECTOR_DECL_HPP 57 #include "Tpetra_DistObject.hpp" 59 #include "Kokkos_DualView.hpp" 60 #include "Teuchos_BLAS_types.hpp" 61 #include "Teuchos_DataAccess.hpp" 62 #include "Teuchos_Range1D.hpp" 63 #include "Kokkos_ArithTraits.hpp" 64 #include "Kokkos_InnerProductSpaceTraits.hpp" 65 #include "Tpetra_KokkosRefactor_Details_MultiVectorLocalDeepCopy.hpp" 66 #include <type_traits> 96 template<
class DstMultiVectorType,
class SrcMultiVectorType>
98 typedef DstMultiVectorType dst_mv_type;
99 typedef SrcMultiVectorType src_mv_type;
101 static Teuchos::RCP<dst_mv_type>
102 clone (
const src_mv_type& X,
103 const Teuchos::RCP<typename dst_mv_type::node_type>& node2);
127 template <
class DS,
class DL,
class DG,
class DN,
128 class SS,
class SL,
class SG,
class SN>
140 template <
class ST,
class LO,
class GO,
class NT>
153 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
154 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
156 const size_t numVectors);
162 template<
class SC,
class LO,
class GO,
class NT>
163 Teuchos::ArrayView<const size_t>
385 template <
class Scalar = ::Tpetra::Details::DefaultTypes::scalar_type,
387 class GlobalOrdinal = ::Tpetra::Details::DefaultTypes::global_ordinal_type,
390 public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node>
435 typedef typename Kokkos::Details::InnerProductSpaceTraits<impl_scalar_type>::dot_type
dot_type;
443 typedef typename Kokkos::Details::ArithTraits<impl_scalar_type>::mag_type
mag_type;
494 MultiVector (
const Teuchos::RCP<const map_type>& map,
495 const size_t numVecs,
496 const bool zeroOut =
true);
514 const Teuchos::DataAccess copyOrView);
531 MultiVector (
const Teuchos::RCP<const map_type>& map,
532 const Teuchos::ArrayView<const Scalar>& A,
534 const size_t NumVectors);
549 MultiVector (
const Teuchos::RCP<const map_type>& map,
550 const Teuchos::ArrayView<
const Teuchos::ArrayView<const Scalar> >&ArrayOfPtrs,
551 const size_t NumVectors);
565 MultiVector (
const Teuchos::RCP<const map_type>& map,
606 MultiVector (
const Teuchos::RCP<const map_type>& map,
607 const typename dual_view_type::t_dev& d_view);
631 MultiVector (
const Teuchos::RCP<const map_type>& map,
663 MultiVector (
const Teuchos::RCP<const map_type>& map,
665 const Teuchos::ArrayView<const size_t>& whichVectors);
694 MultiVector (
const Teuchos::RCP<const map_type>& map,
697 const Teuchos::ArrayView<const size_t>& whichVectors);
759 const size_t offset = 0);
769 template <
class Node2>
770 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node2> >
771 clone (
const Teuchos::RCP<Node2>& node2)
const;
792 #ifdef KOKKOS_ENABLE_SERIAL 793 ! std::is_same<execution_space, Kokkos::Serial>::value;
796 #endif // KOKKOS_ENABLE_SERIAL 865 typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value,
void>::type
868 const T& value)
const 930 typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value,
void>::type
1004 template<
typename T>
1005 typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value,
void>::type
1067 template<
typename T>
1068 typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value,
void>::type
1088 template<
typename T>
1089 typename std::enable_if<! std::is_same<T, impl_scalar_type>::value && std::is_convertible<T, impl_scalar_type>::value,
void>::type
1092 putScalar (static_cast<impl_scalar_type> (value));
1122 void randomize (
const Scalar& minVal,
const Scalar& maxVal);
1189 void replaceMap (
const Teuchos::RCP<const map_type>& map);
1233 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1234 subCopy (
const Teuchos::Range1D& colRng)
const;
1237 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1238 subCopy (
const Teuchos::ArrayView<const size_t>& cols)
const;
1241 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1242 subView (
const Teuchos::Range1D& colRng)
const;
1245 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1246 subView (
const Teuchos::ArrayView<const size_t>& cols)
const;
1249 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1253 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1318 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1319 offsetView (
const Teuchos::RCP<const map_type>& subMap,
1320 const size_t offset)
const;
1339 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1341 const size_t offset);
1344 Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1348 Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1352 Teuchos::ArrayRCP<const Scalar>
getData (
size_t j)
const;
1365 get1dCopy (
const Teuchos::ArrayView<Scalar>& A,
1366 const size_t LDA)
const;
1375 get2dCopy (
const Teuchos::ArrayView<
const Teuchos::ArrayView<Scalar> >& ArrayOfPtrs)
const;
1382 Teuchos::ArrayRCP<const Scalar>
get1dView ()
const;
1385 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> >
get2dView ()
const;
1431 template<
class TargetDeviceType>
1433 getDualView ().template sync<TargetDeviceType> ();
1437 template<
class TargetDeviceType>
1439 return getDualView ().template need_sync<TargetDeviceType> ();
1447 template<
class TargetDeviceType>
1449 getDualView ().template modify<TargetDeviceType> ();
1483 template<
class TargetDeviceType>
1484 typename Kokkos::Impl::if_c<
1486 typename device_type::memory_space,
1487 typename TargetDeviceType::memory_space>::value,
1488 typename dual_view_type::t_dev,
1489 typename dual_view_type::t_host>::type
1491 return getDualView ().template view<TargetDeviceType> ();
1513 const Teuchos::ArrayView<dot_type>& dots)
const;
1526 template <
typename T>
1527 typename std::enable_if< ! (std::is_same<dot_type, T>::value),
void >::type
1529 const Teuchos::ArrayView<T> &dots)
const 1531 const size_t sz =
static_cast<size_t> (dots.size ());
1532 Teuchos::Array<dot_type> dts (sz);
1534 for (
size_t i = 0; i < sz; ++i) {
1541 template <
typename T>
1542 typename std::enable_if< ! (std::is_same<dot_type, T>::value),
void >::type
1544 std::vector<T>& dots)
const 1546 const size_t sz = dots.size ();
1547 Teuchos::Array<dot_type> dts (sz);
1549 for (
size_t i = 0; i < sz; ++i) {
1574 const Kokkos::View<dot_type*, Kokkos::HostSpace>& norms)
const;
1576 template<
class ViewType>
1578 dot (
typename std::enable_if<std::is_same<typename ViewType::value_type,dot_type>::value &&
1579 std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value,
1581 const ViewType& dots)
const {
1582 const Kokkos::View<dot_type*, Kokkos::HostSpace> h_dots(
"Tpetra::Dots",dots.extent(0));
1583 this->
dot (A, h_dots);
1599 template <
typename T>
1600 typename std::enable_if< ! (std::is_same<dot_type, T>::value),
void >::type
1602 const Kokkos::View<T*, device_type>& dots)
const 1604 const size_t numDots = dots.extent (0);
1605 Kokkos::View<dot_type*, device_type> dts (
"MV::dot tmp", numDots);
1631 void scale (
const Scalar& alpha);
1641 void scale (
const Teuchos::ArrayView<const Scalar>& alpha);
1651 void scale (
const Kokkos::View<const impl_scalar_type*, device_type>& alpha);
1662 scale (
const Scalar& alpha,
1672 update (
const Scalar& alpha,
1674 const Scalar& beta);
1683 update (
const Scalar& alpha,
1687 const Scalar& gamma);
1706 template<
class ViewType>
1707 typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1708 std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1710 typedef typename Kokkos::View<mag_type*, Kokkos::HostSpace> host_norms_view_type;
1711 host_norms_view_type h_norms(
"Tpetra::MV::h_norms",norms.extent(0));
1712 this->
normImpl (h_norms, NORM_ONE);
1715 void norm1 (
const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms)
const;
1732 template <
typename T>
1733 typename std::enable_if< ! (std::is_same<mag_type, T>::value),
void >::type
1734 norm1 (
const Kokkos::View<T*, device_type>& norms)
const 1736 const size_t numNorms = norms.extent (0);
1737 Kokkos::View<mag_type*, device_type> tmpNorms (
"MV::norm1 tmp", numNorms);
1739 this->
norm1 (tmpNorms);
1751 void norm1 (
const Teuchos::ArrayView<mag_type>& norms)
const;
1767 template <
typename T>
1768 typename std::enable_if< ! (std::is_same<mag_type,T>::value),
void >::type
1769 norm1 (
const Teuchos::ArrayView<T>& norms)
const 1771 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1772 const size_type sz = norms.size ();
1773 Teuchos::Array<mag_type> theNorms (sz);
1774 this->
norm1 (theNorms);
1775 for (size_type i = 0; i < sz; ++i) {
1777 norms[i] = theNorms[i];
1799 template<
class ViewType>
1800 typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1801 std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1803 typedef typename Kokkos::View<mag_type*, Kokkos::HostSpace> host_norms_view_type;
1804 host_norms_view_type h_norms(
"Tpetra::MV::h_norms",norms.extent(0));
1805 this->
normImpl (h_norms, NORM_TWO);
1808 void norm2 (
const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms)
const;
1823 template<
typename T>
1824 typename std::enable_if< ! (std::is_same<mag_type, T>::value),
void >::type
1825 norm2 (
const Kokkos::View<T*, device_type>& norms)
const 1827 const size_t numNorms = norms.extent (0);
1828 Kokkos::View<mag_type*, device_type> theNorms (
"MV::norm2 tmp", numNorms);
1830 this->
norm2 (theNorms);
1842 void norm2 (
const Teuchos::ArrayView<mag_type>& norms)
const;
1858 template <
typename T>
1859 typename std::enable_if< ! (std::is_same<mag_type,T>::value),
void >::type
1860 norm2 (
const Teuchos::ArrayView<T>& norms)
const 1862 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1863 const size_type sz = norms.size ();
1864 Teuchos::Array<mag_type> theNorms (sz);
1865 this->
norm2 (theNorms);
1866 for (size_type i = 0; i < sz; ++i) {
1868 norms[i] = theNorms[i];
1884 template<
class ViewType>
1885 typename std::enable_if<std::is_same<typename ViewType::value_type,mag_type>::value &&
1886 std::is_same<typename ViewType::memory_space,typename device_type::memory_space>::value>::type
1888 typedef typename Kokkos::View<mag_type*, Kokkos::HostSpace> host_norms_view_type;
1889 host_norms_view_type h_norms(
"Tpetra::MV::h_norms",norms.extent(0));
1890 this->
normImpl (h_norms, NORM_INF);
1893 void normInf (
const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms)
const;
1908 template<
typename T>
1909 typename std::enable_if< ! (std::is_same<mag_type, T>::value),
void >::type
1910 normInf (
const Kokkos::View<T*, device_type>& norms)
const 1912 const size_t numNorms = norms.extent (0);
1913 Kokkos::View<mag_type*, device_type> theNorms (
"MV::normInf tmp", numNorms);
1928 void normInf (
const Teuchos::ArrayView<mag_type>& norms)
const;
1945 template <
typename T>
1946 typename std::enable_if< ! (std::is_same<mag_type,T>::value),
void >::type
1947 normInf (
const Teuchos::ArrayView<T>& norms)
const 1949 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1950 const size_type sz = norms.size ();
1951 Teuchos::Array<mag_type> theNorms (sz);
1952 this->
norm2 (theNorms);
1953 for (size_type i = 0; i < sz; ++i) {
1955 norms[i] = theNorms[i];
1965 void TPETRA_DEPRECATED
1967 const Teuchos::ArrayView<mag_type>& norms)
const;
1985 template <
typename T>
1986 typename std::enable_if< ! (std::is_same<mag_type,T>::value),
void >::type
1989 const Teuchos::ArrayView<T>& norms)
const 1991 typedef typename Teuchos::ArrayView<T>::size_type size_type;
1992 const size_type sz = norms.size ();
1993 Teuchos::Array<mag_type> theNorms (sz);
1995 for (size_type i = 0; i < sz; ++i) {
1997 norms[i] = theNorms[i];
2005 void meanValue (
const Teuchos::ArrayView<impl_scalar_type>& means)
const;
2007 template <
typename T>
2008 typename std::enable_if<! std::is_same<impl_scalar_type, T>::value,
void>::type
2009 meanValue (
const Teuchos::ArrayView<T>& means)
const 2011 typedef typename Teuchos::Array<T>::size_type size_type;
2012 const size_type numMeans = means.size ();
2014 Teuchos::Array<impl_scalar_type> theMeans (numMeans);
2016 for (size_type k = 0; k < numMeans; ++k) {
2017 means[k] =
static_cast<T
> (theMeans[k]);
2028 Teuchos::ETransp transB,
2029 const Scalar& alpha,
2030 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2031 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2032 const Scalar& beta);
2056 const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
2057 const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
2121 describe (Teuchos::FancyOStream& out,
2122 const Teuchos::EVerbosityLevel verbLevel =
2123 Teuchos::Describable::verbLevel_default)
const;
2153 TEUCHOS_TEST_FOR_EXCEPTION(
2154 copyOrView == Teuchos::Copy, std::invalid_argument,
2155 "Tpetra::MultiVector::setCopyOrView: The Kokkos refactor version of " 2156 "MultiVector _only_ implements view semantics. You may not call this " 2157 "method with copyOrView = Teuchos::Copy. The only valid argument is " 2170 return Teuchos::View;
2202 template <
class DS,
class DL,
class DG,
class DN,
2203 class SS,
class SL,
class SG,
class SN>
2261 template<
class SC,
class LO,
class GO,
class NT>
2262 friend ::Teuchos::ArrayView<const size_t> getMultiVectorWhichVectors (const ::Tpetra::MultiVector<SC, LO, GO, NT>& X);
2282 normImpl (
const Kokkos::View<mag_type*, Kokkos::HostSpace>& norms,
2327 const std::string& className,
2328 const Teuchos::EVerbosityLevel verbLevel =
2329 Teuchos::Describable::verbLevel_default)
const;
2332 bool vectorIndexOutOfRange (
const size_t VectorIndex)
const;
2339 Teuchos::ArrayRCP<T>
2369 typedef typename DistObject<Scalar, LocalOrdinal, GlobalOrdinal,
2374 const size_t numSameIDs,
2375 const Kokkos::DualView<const local_ordinal_type*, device_type>& permuteToLIDs,
2376 const Kokkos::DualView<const local_ordinal_type*, device_type>& permuteFromLIDs);
2380 const Kokkos::DualView<const local_ordinal_type*, device_type>& exportLIDs,
2381 Kokkos::DualView<impl_scalar_type*, buffer_device_type>& exports,
2382 const Kokkos::DualView<size_t*, buffer_device_type>& ,
2383 size_t& constantNumPackets,
2387 unpackAndCombineNew (
const Kokkos::DualView<const LocalOrdinal*, device_type>& importLIDs,
2388 const Kokkos::DualView<const impl_scalar_type*, buffer_device_type>& imports,
2389 const Kokkos::DualView<const size_t*, buffer_device_type>& ,
2390 const size_t constantNumPackets,
2396 template<
class SC,
class LO,
class GO,
class NT>
2397 Teuchos::ArrayView<const size_t>
2406 template<
class DstMultiVectorType,
2407 class SrcMultiVectorType>
2408 Teuchos::RCP<typename MultiVectorCloner<DstMultiVectorType, SrcMultiVectorType>::dst_mv_type>
2409 MultiVectorCloner<DstMultiVectorType, SrcMultiVectorType>::
2410 clone (
const src_mv_type& X,
2411 const Teuchos::RCP<typename dst_mv_type::node_type>& node2)
2414 typedef typename src_mv_type::map_type src_map_type;
2415 typedef typename dst_mv_type::map_type dst_map_type;
2416 typedef typename dst_mv_type::node_type dst_node_type;
2417 typedef typename dst_mv_type::dual_view_type dst_dual_view_type;
2420 RCP<const src_map_type> map1 = X.getMap ();
2421 RCP<const dst_map_type> map2 = map1.is_null () ?
2422 Teuchos::null : map1->template clone<dst_node_type> (node2);
2424 const size_t lclNumRows = X.getLocalLength ();
2425 const size_t numCols = X.getNumVectors ();
2426 dst_dual_view_type Y_view (
"MV::dual_view", lclNumRows, numCols);
2428 RCP<dst_mv_type> Y (
new dst_mv_type (map2, Y_view));
2438 template <
class ST,
class LO,
class GO,
class NT>
2450 template <
class DS,
class DL,
class DG,
class DN,
2451 class SS,
class SL,
class SG,
class SN>
2456 typedef typename DN::device_type DD;
2458 using ::Tpetra::Classes::getMultiVectorWhichVectors;
2460 TEUCHOS_TEST_FOR_EXCEPTION(
2463 "Tpetra::deep_copy: Global dimensions of the two Tpetra::MultiVector " 2464 "objects do not match. src has dimensions [" << src.
getGlobalLength ()
2465 <<
"," << src.
getNumVectors () <<
"], and dst has dimensions [" 2469 TEUCHOS_TEST_FOR_EXCEPTION(
2471 "Tpetra::deep_copy: The local row counts of the two Tpetra::MultiVector " 2472 "objects do not match. src has " << src.
getLocalLength () <<
" row(s) " 2480 const bool useHostVersion = src.template need_sync<typename SN::device_type> ();
2482 if (! useHostVersion) {
2484 dst.template modify<DES> ();
2486 Details::localDeepCopyConstStride (dst.template getLocalView<DES> (),
2487 src.template getLocalView<typename SN::device_type> ());
2488 dst.template sync<HES> ();
2491 dst.template modify<HES> ();
2493 Details::localDeepCopyConstStride (dst.template getLocalView<Kokkos::HostSpace> (),
2494 src.template getLocalView<Kokkos::HostSpace> ());
2495 dst.template sync<DES> ();
2499 typedef Kokkos::DualView<SL*, DD> whichvecs_type;
2500 typedef typename whichvecs_type::t_dev::execution_space DES;
2501 typedef typename whichvecs_type::t_host::execution_space HES;
2504 const SL numWhichVecs =
2505 static_cast<SL
> (getMultiVectorWhichVectors (src).size ());
2506 const std::string whichVecsLabel (
"MV::deep_copy::whichVecs");
2513 const bool useHostVersion = src.template need_sync<typename SN::device_type> ();
2515 if (! useHostVersion) {
2518 whichvecs_type whichVecs (whichVecsLabel, numWhichVecs);
2519 whichVecs.template modify<HES> ();
2521 Teuchos::ArrayView<const size_t> src_whichVectors =
2522 getMultiVectorWhichVectors (src);
2523 for (SL i = 0; i < numWhichVecs; ++i) {
2524 whichVecs.h_view(i) =
static_cast<SL
> (src_whichVectors[i]);
2527 whichVecs.template sync<DES> ();
2530 dst.template modify<DES> ();
2532 Details::localDeepCopy (dst.template getLocalView<typename DN::device_type> (),
2533 src.template getLocalView<typename SN::device_type> (),
2540 dst.template sync<HES> ();
2547 typedef Kokkos::View<SL*, HES> the_whichvecs_type;
2548 the_whichvecs_type whichVecs (whichVecsLabel, numWhichVecs);
2549 Teuchos::ArrayView<const size_t> src_whichVectors =
2550 getMultiVectorWhichVectors (src);
2551 for (SL i = 0; i < numWhichVecs; ++i) {
2552 whichVecs(i) =
static_cast<SL
> (src_whichVectors[i]);
2557 Details::localDeepCopy (dst.template getLocalView<Kokkos::HostSpace> (),
2558 src.template getLocalView<Kokkos::HostSpace> (),
2561 whichVecs, whichVecs);
2563 dst.template sync<DES> ();
2570 const bool useHostVersion = src.template need_sync<typename SN::device_type> ();
2572 if (! useHostVersion) {
2575 typedef Kokkos::DualView<DL*, DES> the_whichvecs_type;
2576 const std::string whichVecsLabel (
"MV::deep_copy::whichVecs");
2577 Teuchos::ArrayView<const size_t> dst_whichVectors =
2578 getMultiVectorWhichVectors (dst);
2579 const DL numWhichVecs =
static_cast<DL
> (dst_whichVectors.size ());
2580 the_whichvecs_type whichVecs (whichVecsLabel, numWhichVecs);
2581 whichVecs.template modify<HES> ();
2582 for (DL i = 0; i < numWhichVecs; ++i) {
2583 whichVecs.h_view(i) = dst_whichVectors[i];
2586 whichVecs.template sync<DES> ();
2589 Details::localDeepCopy (dst.template getLocalView<typename DN::device_type> (),
2590 src.template getLocalView<typename SN::device_type> (),
2600 dst.template sync<HES> ();
2607 typedef Kokkos::View<DL*, HES> the_whichvecs_type;
2608 Teuchos::ArrayView<const size_t> dst_whichVectors =
2609 getMultiVectorWhichVectors (dst);
2610 const DL numWhichVecs =
static_cast<DL
> (dst_whichVectors.size ());
2611 the_whichvecs_type whichVecs (
"MV::deep_copy::whichVecs",
2613 for (DL i = 0; i < numWhichVecs; ++i) {
2614 whichVecs(i) =
static_cast<DL
> (dst_whichVectors[i]);
2617 Details::localDeepCopy (dst.template getLocalView<Kokkos::HostSpace> (),
2618 src.template getLocalView<Kokkos::HostSpace> (),
2621 whichVecs, whichVecs);
2626 dst.template sync<DES> ();
2632 const bool useHostVersion = src.template need_sync<typename SN::device_type> ();
2634 if (! useHostVersion) {
2637 Teuchos::ArrayView<const size_t> dst_whichVectors =
2638 getMultiVectorWhichVectors (dst);
2639 const DL dstNumWhichVecs =
2640 static_cast<DL
> (dst_whichVectors.size ());
2641 Kokkos::DualView<DL*, DES> whichVecsDst (
"MV::deep_copy::whichVecsDst",
2643 whichVecsDst.template modify<HES> ();
2644 for (DL i = 0; i < dstNumWhichVecs; ++i) {
2645 whichVecsDst.h_view(i) =
static_cast<DL
> (dst_whichVectors[i]);
2648 whichVecsDst.template sync<DES> ();
2654 Teuchos::ArrayView<const size_t> src_whichVectors =
2655 getMultiVectorWhichVectors (src);
2656 const DL srcNumWhichVecs =
2657 static_cast<DL
> (src_whichVectors.size ());
2658 Kokkos::DualView<DL*, DES> whichVecsSrc (
"MV::deep_copy::whichVecsSrc",
2660 whichVecsSrc.template modify<HES> ();
2661 for (DL i = 0; i < srcNumWhichVecs; ++i) {
2662 whichVecsSrc.h_view(i) =
static_cast<DL
> (src_whichVectors[i]);
2665 whichVecsSrc.template sync<DES> ();
2669 Details::localDeepCopy (dst.template getLocalView<typename DN::device_type> (),
2670 src.template getLocalView<typename SN::device_type> (),
2673 whichVecsDst.d_view,
2674 whichVecsSrc.d_view);
2677 Teuchos::ArrayView<const size_t> dst_whichVectors =
2678 getMultiVectorWhichVectors (dst);
2679 const DL dstNumWhichVecs =
2680 static_cast<DL
> (dst_whichVectors.size ());
2681 Kokkos::View<DL*, HES> whichVectorsDst (
"dstWhichVecs",
2683 for (DL i = 0; i < dstNumWhichVecs; ++i) {
2684 whichVectorsDst(i) = dst_whichVectors[i];
2687 Teuchos::ArrayView<const size_t> src_whichVectors =
2688 getMultiVectorWhichVectors (src);
2690 const DL srcNumWhichVecs =
2691 static_cast<DL
> (src_whichVectors.size ());
2692 Kokkos::View<DL*, HES> whichVectorsSrc (
"srcWhichVecs",
2694 for (DL i = 0; i < srcNumWhichVecs; ++i) {
2695 whichVectorsSrc(i) = src_whichVectors[i];
2700 Details::localDeepCopy (dst.template getLocalView<Kokkos::HostSpace> (),
2701 src.template getLocalView<Kokkos::HostSpace> (),
2704 whichVectorsDst, whichVectorsSrc);
2710 dst.template sync<HES> ();
2723 template<
class SC,
class LO,
class GO,
class NT>
2726 static std::string name () {
2727 return std::string (
"Tpetra::MultiVector<") +
2728 TypeNameTraits<SC>::name () +
"," +
2729 TypeNameTraits<LO>::name () +
"," +
2730 TypeNameTraits<GO>::name () +
"," +
2731 TypeNameTraits<NT>::name () +
">";
2741 #endif // TPETRA_MULTIVECTOR_DECL_HPP virtual size_t constantNumberOfPackets() const
Number of packets to send per LID.
Base class for distributed Tpetra objects that support data redistribution.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
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.
virtual ~MultiVector()
Destructor (virtual for memory safety of derived classes).
Teuchos::ArrayRCP< const Scalar > get1dView() const
Const persisting (1-D) view of this multivector's local values.
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 replaceLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &value) const
Replace value in host memory, using local (row) index.
void sumIntoGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value, const bool atomic=useAtomicUpdatesByDefault) const
Update (+=) a value in host memory, using global row index.
Scalar scalar_type
This class' first template parameter; the type of each entry in the MultiVector.
void meanValue(const Teuchos::ArrayView< impl_scalar_type > &means) const
Compute mean (average) value of each column.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
Node::device_type device_type
The Kokkos device type.
Teuchos::Array< size_t > whichVectors_
Indices of columns this multivector is viewing.
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) const
Like the above replaceLocalValue, but only enabled if T differs from impl_scalar_type.
Kokkos::Impl::if_c< std::is_same< typename device_type::memory_space, typename TargetDeviceType::memory_space >::value, typename dual_view_type::t_dev, typename dual_view_type::t_host >::type getLocalView() const
Return a view of the local data on a specific device.
One or more distributed dense vectors.
DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node >::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
Teuchos::ArrayRCP< Scalar > get1dViewNonConst()
Nonconst persisting (1-D) view of this multivector's local values.
virtual std::string description() const
A simple one-line description of this object.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subViewNonConst(const Teuchos::Range1D &colRng)
Return a MultiVector with views of selected columns.
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.
MultiVector< ST, LO, GO, NT > createCopy(const MultiVector< ST, LO, GO, NT > &src)
Return a deep copy of the given MultiVector.
size_t getLocalLength() const
Local number of rows on the calling process.
int local_ordinal_type
Default value of Scalar template parameter.
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.
size_t getNumVectors() const
Number of columns in the multivector.
void normImpl(const Kokkos::View< mag_type *, Kokkos::HostSpace > &norms, const EWhichNorm whichNorm) const
Compute the norm of each vector (column), storing the result in a device View.
size_t getOrigNumLocalRows() const
"Original" number of rows in the (local) data.
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.
Implementation details of Tpetra.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node2 > > clone(const Teuchos::RCP< Node2 > &node2) const
Return a deep copy of this MultiVector, with a different Node type.
Teuchos::ArrayRCP< Teuchos::ArrayRCP< Scalar > > get2dViewNonConst()
Return non-const persisting pointers to values.
size_t global_size_t
Global size_t object.
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 deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap)
Remove processes owning zero rows from the Map and their communicator.
virtual bool useNewInterface()
Whether this class implements the old or new interface of DistObject.
void scale(const Scalar &alpha)
Scale in place: this = alpha*this.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, typename execution_space::execution_space > dual_view_type
Kokkos::DualView specialization used by this class.
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< typename ViewType::value_type, mag_type >::value &&std::is_same< typename ViewType::memory_space, typename device_type::memory_space >::value >::type norm2(const ViewType &norms) const
Compute the two-norm of each vector (column), storing the result in a device view.
void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this)
void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
void sync()
Update data on device or host only if data in the other space has been marked as modified.
Node::execution_space execution_space
Type of the (new) Kokkos execution space.
Teuchos::ArrayRCP< T > getSubArrayRCP(Teuchos::ArrayRCP< T > arr, size_t j) const
Persisting view of j-th column in the given ArrayRCP.
Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
std::enable_if< std::is_same< typename ViewType::value_type, mag_type >::value &&std::is_same< typename ViewType::memory_space, typename device_type::memory_space >::value >::type normInf(const ViewType &norms) const
Compute the infinity-norm of each vector (column), storing the result in a device view...
bool need_sync() const
Whether this MultiVector needs synchronization to the given space.
GlobalOrdinal global_ordinal_type
This class' third template parameter; the type of global indices.
dual_view_type origView_
The "original view" of the MultiVector's data.
Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
size_t getOrigNumLocalCols() const
"Original" number of columns in the (local) data.
Node node_type
This class' fourth template parameter; the Kokkos Node type.
Teuchos::ArrayRCP< Teuchos::ArrayRCP< const Scalar > > get2dView() const
Return const persisting pointers to values.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Rule for combining data in an Import or Export.
void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &src)
Copy the contents of src into *this (deep copy).
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subCopy(const Teuchos::Range1D &colRng) const
Return a MultiVector with copies of selected columns.
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.
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)
Update: this = beta*this + alpha*A.
Forward declaration of Tpetra::MultiVector.
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) const
Like the above replaceGlobalValue, but only enabled if T differs from impl_scalar_type.
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) const
Like the above sumIntoLocalValue, but only enabled if T differs from impl_scalar_type.
MultiVector()
Default constructor: makes a MultiVector with no rows or columns.
std::string localDescribeToString(const Teuchos::EVerbosityLevel vl) const
Print the calling process' verbose describe() information to the returned string. ...
Abstract base class for objects that can be the source of an Import or Export operation.
Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner ("dot") product result.
dual_view_type view_
The Kokkos::DualView containing the MultiVector's data.
Teuchos::RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(const size_t j)
Return a Vector which is a nonconst view of column j.
Forward declaration of Tpetra::Vector.
void replaceGlobalValue(const GlobalOrdinal gblRow, const size_t col, const impl_scalar_type &value) const
Replace value in host memory, using global row index.
virtual bool checkSizes(const SrcDistObject &sourceObj)
Whether data redistribution between sourceObj and this object is legal.
::Kokkos::Compat::KokkosDeviceWrapperNode< execution_space > node_type
Default value of Node template parameter.
void swap(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &mv)
Swaps the data from *this with the data and maps from mv.
bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
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.
dual_view_type getDualView() const
Get the Kokkos::DualView which implements local storage.
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) const
Like the above sumIntoGlobalValue, but only enabled if T differs from impl_scalar_type.
void setCopyOrView(const Teuchos::DataAccess copyOrView)
Set whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
Forward declaration of Tpetra::FEMultiVector.
Implementation of Tpetra::MultiVector::clone().
size_t getStride() const
Stride between columns in the multivector.
void replaceMap(const Teuchos::RCP< const map_type > &map)
Replace the underlying Map in place.
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,j).
void randomize()
Set all values in the multivector to pseudorandom numbers.
std::enable_if< std::is_same< typename ViewType::value_type, mag_type >::value &&std::is_same< typename ViewType::memory_space, typename device_type::memory_space >::value >::type norm1(const ViewType &norms) const
Compute the one-norm of each vector (column), storing the result in a device view.
Classes::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > MultiVector
Alias for Tpetra::Classes::MultiVector.
void TPETRA_DEPRECATED normWeighted(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &weights, const Teuchos::ArrayView< mag_type > &norms) const
Compute Weighted 2-norm (RMS Norm) of each column.
Kokkos::Details::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
Kokkos::Device specialization for communication buffers.
A parallel distribution of indices over processes.
static const bool useAtomicUpdatesByDefault
Whether sumIntoLocalValue and sumIntoGlobalValue should use atomic updates by default.
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source)
Shallow copy: assign source to *this.
std::string descriptionImpl(const std::string &className) const
Implementation of description() for this class, and its subclass Vector.
EWhichNorm
Input argument for normImpl() (which see).
void reduce()
Sum values of a locally replicated multivector across all processes.
void modify()
Mark data as modified on the given device TargetDeviceType.
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.
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).
void sumIntoLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &val, const bool atomic=useAtomicUpdatesByDefault) const
Update (+=) a value in host memory, using local row index.
bool isConstantStride() const
Whether this multivector has constant stride between columns.
Forward declaration of Tpetra::Map.
Map< LocalOrdinal, GlobalOrdinal, Node > map_type
The type of the Map specialization used by this class.
LocalOrdinal local_ordinal_type
This class' second template parameter; the type of local indices.
Teuchos::DataAccess getCopyOrView() const
Get whether this has copy (copyOrView = Teuchos::Copy) or view (copyOrView = Teuchos::View) semantics...
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 deep_copy(MultiVector< ST, LO, GO, NT > &dst, const MultiVector< ST, LO, GO, NT > &src)
Specialization of deep_copy for MultiVector objects with the same template parameters.