41#ifndef TPETRA_MULTIVECTOR_DEF_HPP
42#define TPETRA_MULTIVECTOR_DEF_HPP
54#include "Tpetra_Vector.hpp"
66#ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
67# include "Teuchos_SerialDenseMatrix.hpp"
69#include "Tpetra_KokkosRefactor_Details_MultiVectorDistObjectKernels.hpp"
70#include "KokkosCompat_View.hpp"
71#include "KokkosBlas.hpp"
72#include "KokkosKernels_Utils.hpp"
73#include "Kokkos_Random.hpp"
74#include "Kokkos_ArithTraits.hpp"
78#ifdef HAVE_TPETRA_INST_FLOAT128
81 template<
class Generator>
82 struct rand<Generator, __float128> {
83 static KOKKOS_INLINE_FUNCTION __float128 max ()
85 return static_cast<__float128
> (1.0);
87 static KOKKOS_INLINE_FUNCTION __float128
92 const __float128 scalingFactor =
93 static_cast<__float128
> (std::numeric_limits<double>::min ()) /
94 static_cast<__float128
> (2.0);
95 const __float128 higherOrderTerm =
static_cast<__float128
> (gen.drand ());
96 const __float128 lowerOrderTerm =
97 static_cast<__float128
> (gen.drand ()) * scalingFactor;
98 return higherOrderTerm + lowerOrderTerm;
100 static KOKKOS_INLINE_FUNCTION __float128
101 draw (Generator& gen,
const __float128& range)
104 const __float128 scalingFactor =
105 static_cast<__float128
> (std::numeric_limits<double>::min ()) /
106 static_cast<__float128
> (2.0);
107 const __float128 higherOrderTerm =
108 static_cast<__float128
> (gen.drand (range));
109 const __float128 lowerOrderTerm =
110 static_cast<__float128
> (gen.drand (range)) * scalingFactor;
111 return higherOrderTerm + lowerOrderTerm;
113 static KOKKOS_INLINE_FUNCTION __float128
114 draw (Generator& gen,
const __float128& start,
const __float128& end)
117 const __float128 scalingFactor =
118 static_cast<__float128
> (std::numeric_limits<double>::min ()) /
119 static_cast<__float128
> (2.0);
120 const __float128 higherOrderTerm =
121 static_cast<__float128
> (gen.drand (start, end));
122 const __float128 lowerOrderTerm =
123 static_cast<__float128
> (gen.drand (start, end)) * scalingFactor;
124 return higherOrderTerm + lowerOrderTerm;
146 template<
class ST,
class LO,
class GO,
class NT>
148 allocDualView (
const size_t lclNumRows,
149 const size_t numCols,
150 const bool zeroOut =
true,
151 const bool allowPadding =
false)
153 using ::Tpetra::Details::Behavior;
154 using Kokkos::AllowPadding;
155 using Kokkos::view_alloc;
156 using Kokkos::WithoutInitializing;
159 typedef typename dual_view_type::t_dev dev_view_type;
165 const std::string label (
"MV::DualView");
166 const bool debug = Behavior::debug ();
176 dev_view_type d_view;
179 d_view = dev_view_type (view_alloc (label, AllowPadding),
180 lclNumRows, numCols);
183 d_view = dev_view_type (view_alloc (label),
184 lclNumRows, numCols);
189 d_view = dev_view_type (view_alloc (label,
192 lclNumRows, numCols);
195 d_view = dev_view_type (view_alloc (label, WithoutInitializing),
196 lclNumRows, numCols);
207 const ST nan = Kokkos::ArithTraits<ST>::nan ();
208 KokkosBlas::fill (d_view, nan);
212 TEUCHOS_TEST_FOR_EXCEPTION
213 (
static_cast<size_t> (d_view.extent (0)) != lclNumRows ||
214 static_cast<size_t> (d_view.extent (1)) != numCols, std::logic_error,
215 "allocDualView: d_view's dimensions actual dimensions do not match "
216 "requested dimensions. d_view is " << d_view.extent (0) <<
" x " <<
217 d_view.extent (1) <<
"; requested " << lclNumRows <<
" x " << numCols
218 <<
". Please report this bug to the Tpetra developers.");
221 return wrapped_dual_view_type(d_view);
228 template<
class T,
class ExecSpace>
229 struct MakeUnmanagedView {
239 typedef typename std::conditional<
240 Kokkos::SpaceAccessibility<
241 typename ExecSpace::memory_space,
242 Kokkos::HostSpace>::accessible,
243 typename ExecSpace::device_type,
244 typename Kokkos::DualView<T*, ExecSpace>::host_mirror_space>::type host_exec_space;
245 typedef Kokkos::LayoutLeft array_layout;
246 typedef Kokkos::View<T*, array_layout, host_exec_space,
247 Kokkos::MemoryUnmanaged> view_type;
249 static view_type getView (
const Teuchos::ArrayView<T>& x_in)
251 const size_t numEnt =
static_cast<size_t> (x_in.size ());
255 return view_type (x_in.getRawPtr (), numEnt);
261 template<
class WrappedDualViewType>
263 takeSubview (
const WrappedDualViewType& X,
264 const std::pair<size_t, size_t>& rowRng,
265 const Kokkos::ALL_t& colRng)
269 return WrappedDualViewType(X,rowRng,colRng);
272 template<
class WrappedDualViewType>
274 takeSubview (
const WrappedDualViewType& X,
275 const Kokkos::ALL_t& rowRng,
276 const std::pair<size_t, size_t>& colRng)
278 using DualViewType =
typename WrappedDualViewType::DVT;
281 if (X.extent (0) == 0 && X.extent (1) != 0) {
282 return WrappedDualViewType(DualViewType (
"MV::DualView", 0, colRng.second - colRng.first));
285 return WrappedDualViewType(X,rowRng,colRng);
289 template<
class WrappedDualViewType>
291 takeSubview (
const WrappedDualViewType& X,
292 const std::pair<size_t, size_t>& rowRng,
293 const std::pair<size_t, size_t>& colRng)
295 using DualViewType =
typename WrappedDualViewType::DVT;
305 if (X.extent (0) == 0 && X.extent (1) != 0) {
306 return WrappedDualViewType(DualViewType (
"MV::DualView", 0, colRng.second - colRng.first));
309 return WrappedDualViewType(X,rowRng,colRng);
313 template<
class WrappedOrNotDualViewType>
315 getDualViewStride (
const WrappedOrNotDualViewType& dv)
321 size_t strides[WrappedOrNotDualViewType::t_dev::rank+1];
323 const size_t LDA = strides[1];
324 const size_t numRows = dv.extent (0);
327 return (numRows == 0) ? size_t (1) : numRows;
334 template<
class ViewType>
336 getViewStride (
const ViewType& view)
338 const size_t LDA = view.stride (1);
339 const size_t numRows = view.extent (0);
342 return (numRows == 0) ? size_t (1) : numRows;
349 template <
class impl_scalar_type,
class buffer_device_type>
352 Kokkos::DualView<impl_scalar_type*, buffer_device_type> imports
355 if (! imports.need_sync_device ()) {
360 size_t localLengthThreshold =
362 return imports.extent(0) <= localLengthThreshold;
367 template <
class SC,
class LO,
class GO,
class NT>
369 runKernelOnHost (const ::Tpetra::MultiVector<SC, LO, GO, NT>& X)
371 if (! X.need_sync_device ()) {
376 size_t localLengthThreshold =
378 return X.getLocalLength () <= localLengthThreshold;
382 template <
class SC,
class LO,
class GO,
class NT>
384 multiVectorNormImpl (typename ::Tpetra::MultiVector<SC, LO, GO, NT>::mag_type norms[],
386 const ::Tpetra::Details::EWhichNorm whichNorm)
389 using ::Tpetra::Details::normImpl;
391 using val_type =
typename MV::impl_scalar_type;
392 using mag_type =
typename MV::mag_type;
393 using dual_view_type =
typename MV::dual_view_type;
395 auto map =
X.getMap ();
396 auto comm =
map.is_null () ?
nullptr :
map->getComm ().getRawPtr ();
397 auto whichVecs = getMultiVectorWhichVectors (
X);
398 const bool isConstantStride =
X.isConstantStride ();
399 const bool isDistributed =
X.isDistributed ();
403 using view_type =
typename dual_view_type::t_host;
404 using array_layout =
typename view_type::array_layout;
405 using device_type =
typename view_type::device_type;
407 auto X_lcl =
X.getLocalViewHost(Access::ReadOnly);
408 normImpl<val_type, array_layout, device_type,
410 isConstantStride, isDistributed, comm);
413 using view_type =
typename dual_view_type::t_dev;
414 using array_layout =
typename view_type::array_layout;
415 using device_type =
typename view_type::device_type;
417 auto X_lcl =
X.getLocalViewDevice(Access::ReadOnly);
418 normImpl<val_type, array_layout, device_type,
420 isConstantStride, isDistributed, comm);
429 template <
typename DstView,
typename SrcView>
430 struct AddAssignFunctor {
443 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
450 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
456 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
469 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
475 whichVectors_ (
source.whichVectors_)
478 const char tfecfFuncName[] =
"MultiVector(const MultiVector&, "
479 "const Teuchos::DataAccess): ";
487 this->
view_ = cpy.view_;
494 true, std::invalid_argument,
"Second argument 'copyOrView' has an "
495 "invalid value " <<
copyOrView <<
". Valid values include "
496 "Teuchos::Copy = " << Teuchos::Copy <<
" and Teuchos::View = "
497 << Teuchos::View <<
".");
501 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
510 map->getLocalNumElements ();
516 std::invalid_argument,
"Kokkos::DualView does not match Map. "
519 <<
", and getStride() = " <<
LDA <<
".");
521 using ::Tpetra::Details::Behavior;
522 const bool debug = Behavior::debug ();
524 using ::Tpetra::Details::checkGlobalDualViewValidity;
526 const bool verbose = Behavior::verbose ();
527 const auto comm =
map.is_null () ? Teuchos::null :
map->getComm ();
529 checkGlobalDualViewValidity (&
gblErrStrm, view, verbose,
537 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
546 map->getLocalNumElements ();
552 std::invalid_argument,
"Kokkos::DualView does not match Map. "
555 <<
", and getStride() = " <<
LDA <<
".");
557 using ::Tpetra::Details::Behavior;
558 const bool debug = Behavior::debug ();
560 using ::Tpetra::Details::checkGlobalWrappedDualViewValidity;
562 const bool verbose = Behavior::verbose ();
563 const auto comm =
map.is_null () ? Teuchos::null :
map->getComm ();
565 checkGlobalWrappedDualViewValidity (&
gblErrStrm, view, verbose,
574 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
577 const typename dual_view_type::t_dev&
d_view) :
580 using Teuchos::ArrayRCP;
589 (
LDA <
lclNumRows, std::invalid_argument,
"Map does not match "
590 "Kokkos::View. map->getLocalNumElements() = " <<
lclNumRows
591 <<
", View's column stride = " <<
LDA
592 <<
", and View's extent(0) = " <<
d_view.extent (0) <<
".");
598 using ::Tpetra::Details::Behavior;
599 const bool debug = Behavior::debug ();
601 using ::Tpetra::Details::checkGlobalWrappedDualViewValidity;
603 const bool verbose = Behavior::verbose ();
604 const auto comm =
map.is_null () ? Teuchos::null :
map->getComm ();
617 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
625 const char tfecfFuncName[] =
"MultiVector(map,view,origView): ";
628 const size_t lclNumRows = this->getLocalLength ();
630 LDA <
lclNumRows, std::invalid_argument,
"The input Kokkos::DualView's "
631 "column stride LDA = " <<
LDA <<
" < getLocalLength() = " <<
lclNumRows
632 <<
". This may also mean that the input origView's first dimension (number "
633 "of rows = " <<
origView.extent (0) <<
") does not not match the number "
634 "of entries in the Map on the calling process.");
636 using ::Tpetra::Details::Behavior;
637 const bool debug = Behavior::debug ();
639 using ::Tpetra::Details::checkGlobalDualViewValidity;
641 const bool verbose = Behavior::verbose ();
642 const auto comm =
map.is_null () ? Teuchos::null :
map->getComm ();
644 checkGlobalDualViewValidity (&
gblErrStrm, view, verbose,
656 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
666 using Kokkos::subview;
667 const char tfecfFuncName[] =
"MultiVector(map,view,whichVectors): ";
669 using ::Tpetra::Details::Behavior;
670 const bool debug = Behavior::debug ();
672 using ::Tpetra::Details::checkGlobalDualViewValidity;
674 const bool verbose = Behavior::verbose ();
675 const auto comm =
map.is_null () ? Teuchos::null :
map->getComm ();
677 checkGlobalDualViewValidity (&
gblErrStrm, view, verbose,
684 map->getLocalNumElements ();
692 view.extent (1) != 0 &&
static_cast<size_t> (view.extent (0)) <
lclNumRows,
693 std::invalid_argument,
"view.extent(0) = " << view.extent (0)
694 <<
" < map->getLocalNumElements() = " <<
lclNumRows <<
".");
697 view.extent (1) != 0 && view.extent (1) == 0,
698 std::invalid_argument,
"view.extent(1) = 0, but whichVectors.size()"
701 typedef Teuchos::ArrayView<const size_t>::size_type size_type;
704 whichVectors[
k] == Teuchos::OrdinalTraits<size_t>::invalid (),
705 std::invalid_argument,
"whichVectors[" <<
k <<
"] = "
706 "Teuchos::OrdinalTraits<size_t>::invalid().");
710 view.extent (1) != 0 &&
static_cast<size_t> (view.extent (1)) <=
maxColInd,
711 std::invalid_argument,
"view.extent(1) = " << view.extent (1)
712 <<
" <= max(whichVectors) = " <<
maxColInd <<
".");
720 "LDA = " <<
LDA <<
" < this->getLocalLength() = " <<
lclNumRows <<
".");
736 whichVectors_.clear ();
740 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
750 using Kokkos::subview;
751 const char tfecfFuncName[] =
"MultiVector(map,view,whichVectors): ";
753 using ::Tpetra::Details::Behavior;
754 const bool debug = Behavior::debug ();
756 using ::Tpetra::Details::checkGlobalWrappedDualViewValidity;
758 const bool verbose = Behavior::verbose ();
759 const auto comm =
map.is_null () ? Teuchos::null :
map->getComm ();
761 checkGlobalWrappedDualViewValidity (&
gblErrStrm, view, verbose,
768 map->getLocalNumElements ();
776 view.extent (1) != 0 &&
static_cast<size_t> (view.extent (0)) <
lclNumRows,
777 std::invalid_argument,
"view.extent(0) = " << view.extent (0)
778 <<
" < map->getLocalNumElements() = " <<
lclNumRows <<
".");
781 view.extent (1) != 0 && view.extent (1) == 0,
782 std::invalid_argument,
"view.extent(1) = 0, but whichVectors.size()"
785 typedef Teuchos::ArrayView<const size_t>::size_type size_type;
788 whichVectors[
k] == Teuchos::OrdinalTraits<size_t>::invalid (),
789 std::invalid_argument,
"whichVectors[" <<
k <<
"] = "
790 "Teuchos::OrdinalTraits<size_t>::invalid().");
794 view.extent (1) != 0 &&
static_cast<size_t> (view.extent (1)) <=
maxColInd,
795 std::invalid_argument,
"view.extent(1) = " << view.extent (1)
796 <<
" <= max(whichVectors) = " <<
maxColInd <<
".");
804 "LDA = " <<
LDA <<
" < this->getLocalLength() = " <<
lclNumRows <<
".");
825 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
836 using Kokkos::subview;
837 const char tfecfFuncName[] =
"MultiVector(map,view,origView,whichVectors): ";
839 using ::Tpetra::Details::Behavior;
840 const bool debug = Behavior::debug ();
842 using ::Tpetra::Details::checkGlobalDualViewValidity;
844 const bool verbose = Behavior::verbose ();
845 const auto comm =
map.is_null () ? Teuchos::null :
map->getComm ();
847 checkGlobalDualViewValidity (&
gblErrStrm, view, verbose,
857 const size_t lclNumRows = this->getLocalLength ();
865 view.extent (1) != 0 &&
static_cast<size_t> (view.extent (0)) <
lclNumRows,
866 std::invalid_argument,
"view.extent(0) = " << view.extent (0)
867 <<
" < map->getLocalNumElements() = " <<
lclNumRows <<
".");
870 view.extent (1) != 0 && view.extent (1) == 0,
871 std::invalid_argument,
"view.extent(1) = 0, but whichVectors.size()"
874 typedef Teuchos::ArrayView<const size_t>::size_type size_type;
877 whichVectors[
k] == Teuchos::OrdinalTraits<size_t>::invalid (),
878 std::invalid_argument,
"whichVectors[" <<
k <<
"] = "
879 "Teuchos::OrdinalTraits<size_t>::invalid().");
883 view.extent (1) != 0 &&
static_cast<size_t> (view.extent (1)) <=
maxColInd,
884 std::invalid_argument,
"view.extent(1) = " << view.extent (1)
885 <<
" <= max(whichVectors) = " <<
maxColInd <<
".");
892 (
LDA <
lclNumRows, std::invalid_argument,
"Map and DualView origView "
893 "do not match. LDA = " <<
LDA <<
" < this->getLocalLength() = " <<
895 <<
", origView.stride(1) = " <<
origView.d_view.stride(1) <<
".");
911 whichVectors_.clear ();
915 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
918 const Teuchos::ArrayView<const Scalar>&
data,
925 const char tfecfFuncName[] =
"MultiVector(map,data,LDA,numVecs): ";
932 map.is_null () ?
size_t (0) :
map->getLocalNumElements ();
935 "map->getLocalNumElements() = " <<
lclNumRows <<
".");
940 std::invalid_argument,
"Input Teuchos::ArrayView does not have enough "
941 "entries, given the input Map and number of vectors in the MultiVector."
942 " data.size() = " <<
data.size () <<
" < (LDA*(numVecs-1)) + "
974 typedef decltype (Kokkos::subview (
X_out, Kokkos::ALL (), 0))
976 typedef decltype (Kokkos::subview (
X_in, Kokkos::ALL (), 0))
987 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
990 const Teuchos::ArrayView<
const Teuchos::ArrayView<const Scalar> >&
ArrayOfPtrs,
997 const char tfecfFuncName[] =
"MultiVector(map,ArrayOfPtrs,numVecs): ";
1001 map.is_null () ?
size_t (0) :
map->getLocalNumElements ();
1004 std::runtime_error,
"Either numVecs (= " <<
numVecs <<
") < 1, or "
1005 "ArrayOfPtrs.size() (= " <<
ArrayOfPtrs.size () <<
") != numVecs.");
1010 std::invalid_argument,
"ArrayOfPtrs[" <<
j <<
"].size() = "
1020 using array_layout =
typename decltype (
X_out)::array_layout;
1024 Kokkos::MemoryUnmanaged>;
1028 Teuchos::ArrayView<const IST>
X_j_av =
1029 Teuchos::av_reinterpret_cast<const IST> (
ArrayOfPtrs[
j]);
1037 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1040 return whichVectors_.empty ();
1043 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1048 if (this->getMap ().
is_null ()) {
1049 return static_cast<size_t> (0);
1051 return this->getMap ()->getLocalNumElements ();
1055 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1060 if (this->getMap ().
is_null ()) {
1061 return static_cast<size_t> (0);
1063 return this->getMap ()->getGlobalNumElements ();
1067 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1075 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1081 auto thisData = view_.getDualView().h_view.data();
1083 size_t thisSpan = view_.getDualView().h_view.span();
1089 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1098 const MV* src =
dynamic_cast<const MV*
> (&
sourceObj);
1099 if (src ==
nullptr) {
1109 return src->getNumVectors () == this->getNumVectors ();
1113 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1117 return this->getNumVectors ();
1120 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1125 const size_t numSameIDs,
1126 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>&
permuteToLIDs,
1127 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>&
permuteFromLIDs,
1131 using ::Tpetra::Details::Behavior;
1132 using ::Tpetra::Details::getDualViewCopyFromArrayView;
1133 using ::Tpetra::Details::ProfilingRegion;
1135 using KokkosRefactor::Details::permute_array_multi_column;
1136 using KokkosRefactor::Details::permute_array_multi_column_variable_stride;
1137 using Kokkos::Compat::create_const_view;
1140 ProfilingRegion
regionCAP (
"Tpetra::MultiVector::copyAndPermute");
1142 const bool verbose = Behavior::verbose ();
1143 std::unique_ptr<std::string>
prefix;
1145 auto map = this->getMap ();
1146 auto comm =
map.is_null () ? Teuchos::null :
map->getComm ();
1147 const int myRank = comm.is_null () ? -1 : comm->getRank ();
1148 std::ostringstream
os;
1149 os <<
"Proc " <<
myRank <<
": MV::copyAndPermute: ";
1150 prefix = std::unique_ptr<std::string> (
new std::string (
os.str ()));
1152 std::cerr <<
os.str ();
1157 std::logic_error,
"permuteToLIDs.extent(0) = "
1158 <<
permuteToLIDs.extent (0) <<
" != permuteFromLIDs.extent(0) = "
1163 const size_t numCols = this->getNumVectors ();
1169 std::logic_error,
"Input MultiVector needs sync to both host "
1173 std::ostringstream
os;
1175 std::cerr <<
os.str ();
1179 std::ostringstream
os;
1181 std::cerr <<
os.str ();
1206 if (numSameIDs > 0) {
1207 const std::pair<size_t, size_t>
rows (0, numSameIDs);
1209 auto tgt_h = this->getLocalViewHost(Access::ReadWrite);
1212 for (
size_t j = 0;
j < numCols; ++
j) {
1213 const size_t tgtCol = isConstantStride () ?
j : whichVectors_[
j];
1222 Kokkos::RangePolicy<execution_space, size_t>;
1224 Tpetra::Details::AddAssignFunctor<
decltype(
tgt_j),
decltype(
src_j)>
1226 Kokkos::parallel_for(
rp,
aaf);
1237 auto tgt_d = this->getLocalViewDevice(Access::ReadWrite);
1240 for (
size_t j = 0;
j < numCols; ++
j) {
1241 const size_t tgtCol = isConstantStride () ?
j : whichVectors_[
j];
1250 Kokkos::RangePolicy<execution_space, size_t>;
1252 Tpetra::Details::AddAssignFunctor<
decltype(
tgt_j),
decltype(
src_j)>
1254 Kokkos::parallel_for(
rp,
aaf);
1280 std::ostringstream
os;
1282 std::cerr <<
os.str ();
1288 std::ostringstream
os;
1296 ! this->isConstantStride () || !
sourceMV.isConstantStride ();
1299 std::ostringstream
os;
1309 Kokkos::DualView<const size_t*, device_type>
srcWhichVecs;
1312 if (this->whichVectors_.size () == 0) {
1313 Kokkos::DualView<size_t*, device_type>
tmpTgt (
"tgtWhichVecs", numCols);
1315 for (
size_t j = 0;
j < numCols; ++
j) {
1324 Teuchos::ArrayView<const size_t>
tgtWhichVecsT = this->whichVectors_ ();
1332 this->getNumVectors (),
1333 std::logic_error,
"tgtWhichVecs.extent(0) = " <<
1334 tgtWhichVecs.extent (0) <<
" != this->getNumVectors() = " <<
1335 this->getNumVectors () <<
".");
1337 if (
sourceMV.whichVectors_.size () == 0) {
1338 Kokkos::DualView<size_t*, device_type>
tmpSrc (
"srcWhichVecs", numCols);
1340 for (
size_t j = 0;
j < numCols; ++
j) {
1358 sourceMV.getNumVectors (), std::logic_error,
1360 <<
" != sourceMV.getNumVectors() = " <<
sourceMV.getNumVectors ()
1366 std::ostringstream
os;
1367 os << *
prefix <<
"Get permute LIDs on host" << std::endl;
1368 std::cerr <<
os.str ();
1370 auto tgt_h = this->getLocalViewHost(Access::ReadWrite);
1380 std::ostringstream
os;
1382 std::cerr <<
os.str ();
1392 using op_type = KokkosRefactor::Details::AddOp;
1393 permute_array_multi_column_variable_stride (
tgt_h,
src_h,
1401 using op_type = KokkosRefactor::Details::InsertOp;
1402 permute_array_multi_column_variable_stride (
tgt_h,
src_h,
1412 using op_type = KokkosRefactor::Details::AddOp;
1417 using op_type = KokkosRefactor::Details::InsertOp;
1425 std::ostringstream
os;
1427 std::cerr <<
os.str ();
1429 auto tgt_d = this->getLocalViewDevice(Access::ReadWrite);
1439 std::ostringstream
os;
1449 using op_type = KokkosRefactor::Details::AddOp;
1450 permute_array_multi_column_variable_stride (space,
tgt_d,
src_d,
1458 using op_type = KokkosRefactor::Details::InsertOp;
1469 using op_type = KokkosRefactor::Details::AddOp;
1474 using op_type = KokkosRefactor::Details::InsertOp;
1482 std::ostringstream
os;
1489template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1492 const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
1494 const Kokkos::DualView<const local_ordinal_type *, buffer_device_type>
1502 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1507 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>&
exportLIDs,
1508 Kokkos::DualView<impl_scalar_type*, buffer_device_type>& exports,
1509 Kokkos::DualView<size_t*, buffer_device_type> ,
1511 const execution_space &space)
1513 using ::Tpetra::Details::Behavior;
1514 using ::Tpetra::Details::ProfilingRegion;
1515 using ::Tpetra::Details::reallocDualViewIfNeeded;
1516 using Kokkos::Compat::create_const_view;
1517 using Kokkos::Compat::getKokkosViewDeepCopy;
1521 ProfilingRegion
regionPAP (
"Tpetra::MultiVector::packAndPrepare");
1536 std::unique_ptr<std::string>
prefix;
1538 auto map = this->getMap ();
1539 auto comm =
map.is_null () ? Teuchos::null :
map->getComm ();
1540 const int myRank = comm.is_null () ? -1 : comm->getRank ();
1541 std::ostringstream
os;
1542 os <<
"Proc " <<
myRank <<
": MV::packAndPrepare: ";
1543 prefix = std::unique_ptr<std::string> (
new std::string (
os.str ()));
1545 std::cerr <<
os.str ();
1551 const size_t numCols =
sourceMV.getNumVectors ();
1562 std::ostringstream
os;
1563 os << *
prefix <<
"No exports on this proc, DONE" << std::endl;
1564 std::cerr <<
os.str ();
1587 std::ostringstream
os;
1590 <<
", exports.extent(0): " << exports.extent (0)
1592 std::cerr <<
os.str ();
1600 std::logic_error,
"Input MultiVector needs sync to both host "
1604 std::ostringstream
os;
1606 std::cerr <<
os.str ();
1618 exports.clear_sync_state ();
1619 exports.modify_host ();
1627 exports.clear_sync_state ();
1628 exports.modify_device ();
1644 if (
sourceMV.isConstantStride ()) {
1645 using KokkosRefactor::Details::pack_array_single_column;
1647 std::ostringstream
os;
1648 os << *
prefix <<
"Pack numCols=1 const stride" <<
endl;
1649 std::cerr <<
os.str ();
1653 pack_array_single_column (exports.view_host (),
1661 pack_array_single_column (exports.view_device (),
1670 using KokkosRefactor::Details::pack_array_single_column;
1672 std::ostringstream
os;
1673 os << *
prefix <<
"Pack numCols=1 nonconst stride" <<
endl;
1674 std::cerr <<
os.str ();
1678 pack_array_single_column (exports.view_host (),
1686 pack_array_single_column (exports.view_device (),
1696 if (
sourceMV.isConstantStride ()) {
1697 using KokkosRefactor::Details::pack_array_multi_column;
1699 std::ostringstream
os;
1700 os << *
prefix <<
"Pack numCols=" << numCols <<
" const stride" <<
endl;
1701 std::cerr <<
os.str ();
1705 pack_array_multi_column (exports.view_host (),
1713 pack_array_multi_column (exports.view_device (),
1722 using KokkosRefactor::Details::pack_array_multi_column_variable_stride;
1724 std::ostringstream
os;
1725 os << *
prefix <<
"Pack numCols=" << numCols <<
" nonconst stride"
1727 std::cerr <<
os.str ();
1733 using DV = Kokkos::DualView<IST*, device_type>;
1734 using HES =
typename DV::t_host::execution_space;
1735 using DES =
typename DV::t_dev::execution_space;
1739 pack_array_multi_column_variable_stride
1740 (exports.view_host (),
1749 pack_array_multi_column_variable_stride
1750 (exports.view_device (),
1761 std::ostringstream
os;
1763 std::cerr <<
os.str ();
1769 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1774 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>&
exportLIDs,
1775 Kokkos::DualView<impl_scalar_type*, buffer_device_type>& exports,
1782 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1784 typename std::enable_if<std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
1785 typename NO::device_type::memory_space>::value,
1790 const std::string*
prefix,
1791 const bool areRemoteLIDsContiguous,
1800 std::ostringstream
os;
1801 os << *
prefix <<
"Realloc (if needed) imports_ from "
1802 << this->imports_.extent (0) <<
" to " <<
newSize << std::endl;
1803 std::cerr <<
os.str ();
1808 using IST = impl_scalar_type;
1809 using DV = Kokkos::DualView<IST*, Kokkos::LayoutLeft, buffer_device_type>;
1821 if ((dual_view_type::impl_dualview_is_single_device::value ||
1824 areRemoteLIDsContiguous &&
1826 (getNumVectors() == 1) &&
1830 reallocated = this->imports_.d_view.data() != view_.getDualView().d_view.data() +
offset;
1832 typedef std::pair<size_t, size_t> range_type;
1833 this->imports_ =
DV(view_.getDualView(),
1834 range_type (
offset, getLocalLength () ),
1838 std::ostringstream
os;
1839 os << *
prefix <<
"Aliased imports_ to MV.view_" << std::endl;
1840 std::cerr <<
os.str ();
1846 using ::Tpetra::Details::reallocDualViewIfNeeded;
1848 reallocDualViewIfNeeded (this->unaliased_imports_,
newSize,
"imports");
1850 std::ostringstream
os;
1851 os << *
prefix <<
"Finished realloc'ing unaliased_imports_" << std::endl;
1852 std::cerr <<
os.str ();
1854 this->imports_ = this->unaliased_imports_;
1859 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1861 typename std::enable_if<!std::is_same<typename Tpetra::Details::DefaultTypes::CommBufferMemorySpace<typename NO::execution_space>::type,
1862 typename NO::device_type::memory_space>::value,
1867 const std::string*
prefix,
1868 const bool areRemoteLIDsContiguous,
1874 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1879 const std::string*
prefix,
1880 const bool areRemoteLIDsContiguous,
1886 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1890 return (this->imports_.d_view.data() +
this->imports_.d_view.extent(0) ==
1891 view_.getDualView().d_view.data() + view_.getDualView().d_view.extent(0));
1895 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1899 (
const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>&
importLIDs,
1900 Kokkos::DualView<impl_scalar_type*, buffer_device_type> imports,
1901 Kokkos::DualView<size_t*, buffer_device_type> ,
1904 const execution_space &space)
1906 using ::Tpetra::Details::Behavior;
1907 using ::Tpetra::Details::ProfilingRegion;
1908 using KokkosRefactor::Details::unpack_array_multi_column;
1909 using KokkosRefactor::Details::unpack_array_multi_column_variable_stride;
1910 using Kokkos::Compat::getKokkosViewDeepCopy;
1912 const char longFuncName[] =
"Tpetra::MultiVector::unpackAndCombine";
1925 std::unique_ptr<std::string>
prefix;
1928 auto comm =
map.is_null () ? Teuchos::null :
map->getComm ();
1929 const int myRank = comm.is_null () ? -1 : comm->getRank ();
1930 std::ostringstream
os;
1932 prefix = std::unique_ptr<std::string> (
new std::string (
os.str ()));
1934 std::cerr <<
os.str ();
1940 std::ostringstream
os;
1942 std::cerr <<
os.str ();
1948 if (importsAreAliased()) {
1950 std::ostringstream
os;
1951 os << *
prefix <<
"Skipping unpack, since imports_ is aliased to MV.view_. Done!" <<
endl;
1952 std::cerr <<
os.str ();
1958 const size_t numVecs = getNumVectors ();
1961 (
static_cast<size_t> (imports.extent (0)) !=
1964 "imports.extent(0) = " << imports.extent (0)
1965 <<
" != getNumVectors() * importLIDs.extent(0) = " <<
numVecs
1971 "constantNumPackets input argument must be nonzero.");
1974 (
static_cast<size_t> (
numVecs) !=
1976 std::runtime_error,
"constantNumPackets must equal numVecs.");
1986 if (this->imports_.need_sync_host()) this->imports_.sync_host();
1989 if (this->imports_.need_sync_device()) this->imports_.sync_device();
1993 std::ostringstream
os;
1996 std::cerr <<
os.str ();
2001 auto imports_d = imports.view_device ();
2006 Kokkos::DualView<size_t*, device_type>
whichVecs;
2007 if (! isConstantStride ()) {
2008 Kokkos::View<
const size_t*, Kokkos::HostSpace,
2009 Kokkos::MemoryUnmanaged>
whichVecsIn (whichVectors_.getRawPtr (),
2036 using host_exec_space =
typename dual_view_type::t_host::execution_space;
2040 host_exec_space().concurrency () != 1 :
2044 std::ostringstream
os;
2046 std::cerr <<
os.str ();
2053 using op_type = KokkosRefactor::Details::InsertOp;
2054 if (isConstantStride ()) {
2056 auto X_h = this->getLocalViewHost(Access::ReadWrite);
2057 unpack_array_multi_column (host_exec_space (),
2065 auto X_d = this->getLocalViewDevice(Access::ReadWrite);
2066 unpack_array_multi_column (space,
2075 auto X_h = this->getLocalViewHost(Access::ReadWrite);
2076 unpack_array_multi_column_variable_stride (host_exec_space (),
2086 auto X_d = this->getLocalViewDevice(Access::ReadWrite);
2087 unpack_array_multi_column_variable_stride (space,
2099 using op_type = KokkosRefactor::Details::AddOp;
2100 if (isConstantStride ()) {
2102 auto X_h = this->getLocalViewHost(Access::ReadWrite);
2103 unpack_array_multi_column (host_exec_space (),
2110 auto X_d = this->getLocalViewDevice(Access::ReadWrite);
2111 unpack_array_multi_column (space,
2120 auto X_h = this->getLocalViewHost(Access::ReadWrite);
2121 unpack_array_multi_column_variable_stride (host_exec_space (),
2131 auto X_d = this->getLocalViewDevice(Access::ReadWrite);
2132 unpack_array_multi_column_variable_stride (space,
2144 using op_type = KokkosRefactor::Details::AbsMaxOp;
2145 if (isConstantStride ()) {
2147 auto X_h = this->getLocalViewHost(Access::ReadWrite);
2148 unpack_array_multi_column (host_exec_space (),
2155 auto X_d = this->getLocalViewDevice(Access::ReadWrite);
2156 unpack_array_multi_column (space,
2165 auto X_h = this->getLocalViewHost(Access::ReadWrite);
2166 unpack_array_multi_column_variable_stride (host_exec_space (),
2176 auto X_d = this->getLocalViewDevice(Access::ReadWrite);
2177 unpack_array_multi_column_variable_stride (space,
2190 (
true, std::logic_error,
"Invalid CombineMode");
2195 std::ostringstream
os;
2197 std::cerr <<
os.str ();
2202 std::ostringstream
os;
2204 std::cerr <<
os.str ();
2209 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2213 (
const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>&
importLIDs,
2214 Kokkos::DualView<impl_scalar_type*, buffer_device_type> imports,
2222 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2227 if (isConstantStride ()) {
2228 return static_cast<size_t> (view_.extent (1));
2230 return static_cast<size_t> (whichVectors_.size ());
2239 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
2242 using Teuchos::REDUCE_MAX;
2243 using Teuchos::REDUCE_SUM;
2244 using Teuchos::reduceAll;
2245 typedef typename RV::non_const_value_type dot_type;
2265 const int nv =
static_cast<int> (
numVecs);
2272 typename RV::non_const_type
lclDots (Kokkos::ViewAllocateWithoutInitializing (
"tmp"),
numVecs);
2287 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2291 const Kokkos::View<dot_type*, Kokkos::HostSpace>&
dots)
const
2293 using ::Tpetra::Details::Behavior;
2294 using Kokkos::subview;
2295 using Teuchos::Comm;
2296 using Teuchos::null;
2299 typedef Kokkos::View<dot_type*, Kokkos::HostSpace>
RV;
2300 typedef typename dual_view_type::t_dev_const
XMV;
2305 const size_t numVecs = this->getNumVectors ();
2309 const size_t lclNumRows = this->getLocalLength ();
2311 const bool debug = Behavior::debug ();
2314 const bool compat = this->getMap ()->isCompatible (* (
A.getMap ()));
2316 (!
compat, std::invalid_argument,
"'*this' MultiVector is not "
2317 "compatible with the input MultiVector A. We only test for this "
2329 lclNumRows !=
A.getLocalLength (), std::runtime_error,
2330 "MultiVectors do not have the same local length. "
2331 "this->getLocalLength() = " <<
lclNumRows <<
" != "
2332 "A.getLocalLength() = " <<
A.getLocalLength () <<
".");
2335 "MultiVectors must have the same number of columns (vectors). "
2336 "this->getNumVectors() = " <<
numVecs <<
" != "
2337 "A.getNumVectors() = " <<
A.getNumVectors () <<
".");
2340 "The output array 'dots' must have the same number of entries as the "
2341 "number of columns (vectors) in *this and A. dots.extent(0) = " <<
2347 this->getMap ()->getComm ();
2349 auto thisView = this->getLocalViewDevice(Access::ReadOnly);
2350 auto A_view =
A.getLocalViewDevice(Access::ReadOnly);
2353 this->whichVectors_.getRawPtr (),
2354 A.whichVectors_.getRawPtr (),
2355 this->isConstantStride (),
A.isConstantStride ());
2370 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2375 using ::Tpetra::Details::ProfilingRegion;
2377 using dot_type =
typename MV::dot_type;
2378 ProfilingRegion
region (
"Tpetra::multiVectorSingleColumnDot");
2380 auto map =
x.getMap ();
2381 Teuchos::RCP<const Teuchos::Comm<int> > comm =
2382 map.is_null () ? Teuchos::null :
map->getComm ();
2383 if (comm.is_null ()) {
2384 return Kokkos::ArithTraits<dot_type>::zero ();
2391 const LO
lclNumRows =
static_cast<LO
> (std::min (
x.getLocalLength (),
2392 y.getLocalLength ()));
2394 dot_type lclDot = Kokkos::ArithTraits<dot_type>::zero ();
2395 dot_type
gblDot = Kokkos::ArithTraits<dot_type>::zero ();
2401 auto x_2d =
x.getLocalViewDevice(Access::ReadOnly);
2403 auto y_2d =
y.getLocalViewDevice(Access::ReadOnly);
2405 lclDot = KokkosBlas::dot (
x_1d,
y_1d);
2407 if (
x.isDistributed ()) {
2408 using Teuchos::outArg;
2409 using Teuchos::REDUCE_SUM;
2410 using Teuchos::reduceAll;
2423 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2427 const Teuchos::ArrayView<dot_type>&
dots)
const
2432 const size_t numVecs = this->getNumVectors ();
2433 const size_t lclNumRows = this->getLocalLength ();
2434 const size_t numDots =
static_cast<size_t> (
dots.size ());
2445 (
lclNumRows !=
A.getLocalLength (), std::runtime_error,
2446 "MultiVectors do not have the same local length. "
2447 "this->getLocalLength() = " <<
lclNumRows <<
" != "
2448 "A.getLocalLength() = " <<
A.getLocalLength () <<
".");
2450 (
numVecs !=
A.getNumVectors (), std::runtime_error,
2451 "MultiVectors must have the same number of columns (vectors). "
2452 "this->getNumVectors() = " <<
numVecs <<
" != "
2453 "A.getNumVectors() = " <<
A.getNumVectors () <<
".");
2456 "The output array 'dots' must have the same number of entries as the "
2457 "number of columns (vectors) in *this and A. dots.extent(0) = " <<
2460 if (
numVecs == 1 && this->isConstantStride () &&
A.isConstantStride ()) {
2465 this->dot (
A, Kokkos::View<dot_type*, Kokkos::HostSpace>(
dots.getRawPtr (),
numDots));
2469 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2472 norm2 (
const Teuchos::ArrayView<mag_type>&
norms)
const
2475 using ::Tpetra::Details::NORM_TWO;
2476 using ::Tpetra::Details::ProfilingRegion;
2477 ProfilingRegion
region (
"Tpetra::MV::norm2 (host output)");
2480 MV&
X =
const_cast<MV&
> (*this);
2484 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2487 norm2 (
const Kokkos::View<mag_type*, Kokkos::HostSpace>&
norms)
const
2494 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2497 norm1 (
const Teuchos::ArrayView<mag_type>&
norms)
const
2500 using ::Tpetra::Details::NORM_ONE;
2501 using ::Tpetra::Details::ProfilingRegion;
2502 ProfilingRegion
region (
"Tpetra::MV::norm1 (host output)");
2505 MV&
X =
const_cast<MV&
> (*this);
2509 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2512 norm1 (
const Kokkos::View<mag_type*, Kokkos::HostSpace>&
norms)
const
2518 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2521 normInf (
const Teuchos::ArrayView<mag_type>&
norms)
const
2524 using ::Tpetra::Details::NORM_INF;
2525 using ::Tpetra::Details::ProfilingRegion;
2526 ProfilingRegion
region (
"Tpetra::MV::normInf (host output)");
2529 MV&
X =
const_cast<MV&
> (*this);
2533 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2536 normInf (
const Kokkos::View<mag_type*, Kokkos::HostSpace>&
norms)
const
2542 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2545 meanValue (
const Teuchos::ArrayView<impl_scalar_type>&
means)
const
2549 using Kokkos::subview;
2550 using Teuchos::Comm;
2552 using Teuchos::reduceAll;
2553 using Teuchos::REDUCE_SUM;
2554 typedef Kokkos::ArithTraits<impl_scalar_type>
ATS;
2556 const size_t lclNumRows = this->getLocalLength ();
2557 const size_t numVecs = this->getNumVectors ();
2558 const size_t numMeans =
static_cast<size_t> (
means.size ());
2562 "Tpetra::MultiVector::meanValue: means.size() = " <<
numMeans
2563 <<
" != this->getNumVectors() = " <<
numVecs <<
".");
2573 typename local_view_type::HostMirror::array_layout,
2579 this->getMap ()->getComm ();
2585 auto X_lcl =
subview (getLocalViewHost(Access::ReadOnly),
2588 Kokkos::View<impl_scalar_type*, Kokkos::HostSpace>
lclSums (
"MV::meanValue tmp",
numVecs);
2589 if (isConstantStride ()) {
2594 const size_t col = whichVectors_[
j];
2602 if (! comm.is_null () &&
this->isDistributed ()) {
2613 auto X_lcl =
subview (this->getLocalViewDevice(Access::ReadOnly),
2617 Kokkos::View<impl_scalar_type*, Kokkos::HostSpace>
lclSums (
"MV::meanValue tmp",
numVecs);
2618 if (isConstantStride ()) {
2623 const size_t col = whichVectors_[
j];
2640 if (! comm.is_null () &&
this->isDistributed ()) {
2654 ATS::one () /
static_cast<mag_type> (this->getGlobalLength ());
2661 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2667 typedef Kokkos::ArithTraits<IST>
ATS;
2668 typedef Kokkos::Random_XorShift64_Pool<typename device_type::execution_space>
pool_type;
2671 const IST
max = Kokkos::rand<generator_type, IST>::max ();
2672 const IST
min = ATS::is_signed ? IST (-
max) : ATS::zero ();
2678 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2684 typedef Kokkos::Random_XorShift64_Pool<typename device_type::execution_space>
pool_type;
2696 static_cast<uint64_t> (this->getMap ()->getComm ()->getRank ());
2698 unsigned int seed =
static_cast<unsigned int> (
seed64&0xffffffff);
2701 const IST
max =
static_cast<IST
> (maxVal);
2702 const IST
min =
static_cast<IST
> (minVal);
2704 auto thisView = this->getLocalViewDevice(Access::OverwriteAll);
2706 if (isConstantStride ()) {
2710 const size_t numVecs = getNumVectors ();
2712 const size_t col = whichVectors_[
k];
2713 auto X_k = Kokkos::subview (
thisView, Kokkos::ALL (), col);
2719 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2724 using ::Tpetra::Details::ProfilingRegion;
2725 using ::Tpetra::Details::Blas::fill;
2726 using DES =
typename dual_view_type::t_dev::execution_space;
2727 using HES =
typename dual_view_type::t_host::execution_space;
2729 ProfilingRegion
region (
"Tpetra::MultiVector::putScalar");
2734 const LO
lclNumRows =
static_cast<LO
> (this->getLocalLength ());
2735 const LO
numVecs =
static_cast<LO
> (this->getNumVectors ());
2743 auto X = this->getLocalViewDevice(Access::OverwriteAll);
2744 if (this->isConstantStride ()) {
2749 this->whichVectors_.getRawPtr ());
2753 auto X = this->getLocalViewHost(Access::OverwriteAll);
2754 if (this->isConstantStride ()) {
2759 this->whichVectors_.getRawPtr ());
2765 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2770 using Teuchos::ArrayRCP;
2771 using Teuchos::Comm;
2782 ! this->isConstantStride (), std::logic_error,
2783 "Tpetra::MultiVector::replaceMap: This method does not currently work "
2784 "if the MultiVector is a column view of another MultiVector (that is, if "
2785 "isConstantStride() == false).");
2815 if (this->getMap ().
is_null ()) {
2821 newMap.is_null (), std::invalid_argument,
2822 "Tpetra::MultiVector::replaceMap: both current and new Maps are null. "
2823 "This probably means that the input Map is incorrect.");
2829 const size_t numCols = this->getNumVectors ();
2835 else if (
newMap.is_null ()) {
2838 const size_t newNumRows =
static_cast<size_t> (0);
2839 const size_t numCols = this->getNumVectors ();
2846 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2855 if (
theAlpha == Kokkos::ArithTraits<IST>::one ()) {
2859 const size_t numVecs = getNumVectors ();
2871 auto Y_lcl = Kokkos::subview (getLocalViewHost(Access::ReadWrite),
rowRng,
ALL ());
2872 if (isConstantStride ()) {
2877 const size_t Y_col = whichVectors_[
k];
2884 auto Y_lcl = Kokkos::subview (getLocalViewDevice(Access::ReadWrite),
rowRng,
ALL ());
2885 if (isConstantStride ()) {
2890 const size_t Y_col = isConstantStride () ?
k : whichVectors_[
k];
2899 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2902 scale (
const Teuchos::ArrayView<const Scalar>&
alphas)
2904 const size_t numVecs = this->getNumVectors ();
2908 "scale: alphas.size() = " <<
numAlphas <<
" != this->getNumVectors() = "
2912 using k_alphas_type = Kokkos::DualView<impl_scalar_type*, device_type>;
2920 this->scale (
k_alphas.view_device ());
2923 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2926 scale (
const Kokkos::View<const impl_scalar_type*, device_type>&
alphas)
2929 using Kokkos::subview;
2931 const size_t lclNumRows = this->getLocalLength ();
2932 const size_t numVecs = this->getNumVectors ();
2935 std::invalid_argument,
"Tpetra::MultiVector::scale(alphas): "
2936 "alphas.extent(0) = " <<
alphas.extent (0)
2937 <<
" != this->getNumVectors () = " <<
numVecs <<
".");
2958 if (isConstantStride ()) {
2963 const size_t Y_col = this->isConstantStride () ?
k :
2964 this->whichVectors_[
k];
2974 if (isConstantStride ()) {
2987 const size_t Y_col = this->isConstantStride () ?
k :
2988 this->whichVectors_[
k];
2996 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3003 using Kokkos::subview;
3007 const size_t numVecs = getNumVectors ();
3010 lclNumRows !=
A.getLocalLength (), std::invalid_argument,
3011 "this->getLocalLength() = " <<
lclNumRows <<
" != A.getLocalLength() = "
3012 <<
A.getLocalLength () <<
".");
3014 numVecs !=
A.getNumVectors (), std::invalid_argument,
3015 "this->getNumVectors() = " <<
numVecs <<
" != A.getNumVectors() = "
3016 <<
A.getNumVectors () <<
".");
3022 auto Y_lcl_orig = this->getLocalViewDevice(Access::ReadWrite);
3023 auto X_lcl_orig =
A.getLocalViewDevice(Access::ReadOnly);
3027 if (isConstantStride () &&
A.isConstantStride ()) {
3033 const size_t Y_col = this->isConstantStride () ?
k : this->whichVectors_[
k];
3034 const size_t X_col =
A.isConstantStride () ?
k :
A.whichVectors_[
k];
3045 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3053 getLocalLength () !=
A.getLocalLength (), std::runtime_error,
3054 "MultiVectors do not have the same local length. "
3055 "this->getLocalLength() = " << getLocalLength ()
3056 <<
" != A.getLocalLength() = " <<
A.getLocalLength () <<
".");
3058 A.getNumVectors () !=
this->getNumVectors (), std::runtime_error,
3059 ": MultiVectors do not have the same number of columns (vectors). "
3060 "this->getNumVectors() = " << getNumVectors ()
3061 <<
" != A.getNumVectors() = " <<
A.getNumVectors () <<
".");
3063 const size_t numVecs = getNumVectors ();
3065 auto this_view_dev = this->getLocalViewDevice(Access::ReadWrite);
3066 auto A_view_dev =
A.getLocalViewDevice(Access::ReadOnly);
3068 if (isConstantStride () &&
A.isConstantStride ()) {
3073 using Kokkos::subview;
3075 const size_t this_col = isConstantStride () ?
k : whichVectors_[
k];
3077 const size_t A_col = isConstantStride () ?
k :
A.whichVectors_[
k];
3084 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3092 getLocalLength () !=
A.getLocalLength (), std::runtime_error,
3093 ": MultiVectors do not have the same local length. "
3094 "this->getLocalLength() = " << getLocalLength ()
3095 <<
" != A.getLocalLength() = " <<
A.getLocalLength () <<
".");
3097 A.getNumVectors () !=
this->getNumVectors (), std::runtime_error,
3098 ": MultiVectors do not have the same number of columns (vectors). "
3099 "this->getNumVectors() = " << getNumVectors ()
3100 <<
" != A.getNumVectors() = " <<
A.getNumVectors () <<
".");
3101 const size_t numVecs = getNumVectors ();
3103 auto this_view_dev = this->getLocalViewDevice(Access::ReadWrite);
3104 auto A_view_dev =
A.getLocalViewDevice(Access::ReadOnly);
3106 if (isConstantStride () &&
A.isConstantStride ()) {
3111 using Kokkos::subview;
3114 const size_t this_col = isConstantStride () ?
k : whichVectors_[
k];
3116 const size_t A_col = isConstantStride () ?
k :
A.whichVectors_[
k];
3123 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3131 using Kokkos::subview;
3137 const size_t numVecs = getNumVectors ();
3141 lclNumRows !=
A.getLocalLength (), std::invalid_argument,
3142 "this->getLocalLength() = " <<
lclNumRows <<
" != A.getLocalLength() = "
3143 <<
A.getLocalLength () <<
".");
3145 numVecs !=
A.getNumVectors (), std::invalid_argument,
3146 "this->getNumVectors() = " <<
numVecs <<
" != A.getNumVectors() = "
3147 <<
A.getNumVectors () <<
".");
3155 auto Y_lcl_orig = this->getLocalViewDevice(Access::ReadWrite);
3157 auto X_lcl_orig =
A.getLocalViewDevice(Access::ReadOnly);
3161 if (isConstantStride () &&
A.isConstantStride ()) {
3167 const size_t Y_col = this->isConstantStride () ?
k : this->whichVectors_[
k];
3168 const size_t X_col =
A.isConstantStride () ?
k :
A.whichVectors_[
k];
3177 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3187 using Kokkos::subview;
3189 const char tfecfFuncName[] =
"update(alpha,A,beta,B,gamma): ";
3193 const size_t lclNumRows = this->getLocalLength ();
3194 const size_t numVecs = getNumVectors ();
3198 lclNumRows !=
A.getLocalLength (), std::invalid_argument,
3199 "The input MultiVector A has " <<
A.getLocalLength () <<
" local "
3200 "row(s), but this MultiVector has " <<
lclNumRows <<
" local "
3203 lclNumRows !=
B.getLocalLength (), std::invalid_argument,
3204 "The input MultiVector B has " <<
B.getLocalLength () <<
" local "
3205 "row(s), but this MultiVector has " <<
lclNumRows <<
" local "
3208 A.getNumVectors () !=
numVecs, std::invalid_argument,
3209 "The input MultiVector A has " <<
A.getNumVectors () <<
" column(s), "
3210 "but this MultiVector has " <<
numVecs <<
" column(s).");
3212 B.getNumVectors () !=
numVecs, std::invalid_argument,
3213 "The input MultiVector B has " <<
B.getNumVectors () <<
" column(s), "
3214 "but this MultiVector has " <<
numVecs <<
" column(s).");
3231 if (isConstantStride () &&
A.isConstantStride () &&
B.isConstantStride ()) {
3238 const size_t this_col = isConstantStride () ?
k : whichVectors_[
k];
3239 const size_t A_col =
A.isConstantStride () ?
k :
A.whichVectors_[
k];
3240 const size_t B_col =
B.isConstantStride () ?
k :
B.whichVectors_[
k];
3248 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3249 Teuchos::ArrayRCP<const Scalar>
3262 auto hostView = getLocalViewHost(Access::ReadOnly);
3263 const size_t col = isConstantStride () ?
j : whichVectors_[
j];
3266 Kokkos::Compat::persistingView (
hostView_j, 0, getLocalLength ());
3269 (
static_cast<size_t> (
hostView_j.extent (0)) <
3270 static_cast<size_t> (
dataAsArcp.size ()), std::logic_error,
3271 "hostView_j.extent(0) = " <<
hostView_j.extent (0)
3272 <<
" < dataAsArcp.size() = " <<
dataAsArcp.size () <<
". "
3273 "Please report this bug to the Tpetra developers.");
3275 return Teuchos::arcp_reinterpret_cast<const Scalar> (
dataAsArcp);
3278 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3279 Teuchos::ArrayRCP<Scalar>
3284 using Kokkos::subview;
3288 auto hostView = getLocalViewHost(Access::ReadWrite);
3289 const size_t col = isConstantStride () ?
j : whichVectors_[
j];
3292 Kokkos::Compat::persistingView (
hostView_j, 0, getLocalLength ());
3295 (
static_cast<size_t> (
hostView_j.extent (0)) <
3296 static_cast<size_t> (
dataAsArcp.size ()), std::logic_error,
3297 "hostView_j.extent(0) = " <<
hostView_j.extent (0)
3298 <<
" < dataAsArcp.size() = " <<
dataAsArcp.size () <<
". "
3299 "Please report this bug to the Tpetra developers.");
3301 return Teuchos::arcp_reinterpret_cast<Scalar> (
dataAsArcp);
3304 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3305 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3307 subCopy (
const Teuchos::ArrayView<const size_t>&
cols)
const
3317 if (
cols[
j] !=
cols[
j-1] +
static_cast<size_t> (1)) {
3333 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3334 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3342 RCP<MV> Y (
new MV (this->getMap (),
static_cast<size_t> (
colRng.size ()),
false));
3347 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3351 return view_.origExtent(0);
3354 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3358 return view_.origExtent(1);
3361 template <
class Scalar,
class LO,
class GO,
class Node>
3364 const Teuchos::RCP<const map_type>&
subMap,
3369 using Kokkos::subview;
3370 using Teuchos::outArg;
3373 using Teuchos::reduceAll;
3374 using Teuchos::REDUCE_MIN;
3377 const char prefix[] =
"Tpetra::MultiVector constructor (offsetView): ";
3378 const char suffix[] =
"Please report this bug to the Tpetra developers.";
3381 std::unique_ptr<std::ostringstream>
errStrm;
3388 const auto comm =
subMap->getComm ();
3390 const int myRank = comm->getRank ();
3393 const LO numCols =
static_cast<LO
> (
X.getNumVectors ());
3396 std::ostringstream
os;
3399 <<
", origLclNumRows: " <<
X.getOrigNumLocalRows ()
3400 <<
", numCols: " << numCols <<
"}, "
3402 std::cerr <<
os.str ();
3410 errStrm = std::unique_ptr<std::ostringstream> (
new std::ostringstream);
3411 *
errStrm <<
" Proc " <<
myRank <<
": subMap->getLocalNumElements() (="
3413 <<
") > X.getOrigNumLocalRows() (=" <<
X.getOrigNumLocalRows ()
3429 (
true, std::invalid_argument,
gblErrStrm.str ());
3433 using range_type = std::pair<LO, LO>;
3435 (
rowOffset,
static_cast<LO
> (
X.view_.origExtent (0)));
3446 if (
newView.extent (0) == 0 &&
3447 newView.extent (1) !=
X.view_.extent (1)) {
3461 if (
errStrm.get () ==
nullptr) {
3462 errStrm = std::unique_ptr<std::ostringstream> (
new std::ostringstream);
3465 ": subMap.getLocalNumElements(): " <<
newNumRows <<
3467 ", X.getNumVectors(): " << numCols <<
3475 "dimensions on one or more processes:" <<
endl;
3482 (
true, std::invalid_argument,
gblErrStrm.str ());
3487 std::ostringstream
os;
3489 std::cerr <<
os.str ();
3495 std::ostringstream
os;
3497 std::cerr <<
os.str ();
3501 template <
class Scalar,
class LO,
class GO,
class Node>
3510 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3511 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3514 const size_t offset)
const
3520 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3521 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3530 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3531 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3533 subView (
const Teuchos::ArrayView<const size_t>&
cols)
const
3535 using Teuchos::Array;
3541 numViewCols < 1, std::runtime_error,
"Tpetra::MultiVector::subView"
3542 "(const Teuchos::ArrayView<const size_t>&): The input array cols must "
3543 "contain at least one entry, but cols.size() = " <<
cols.size ()
3550 if (
cols[
j] !=
cols[
j-1] +
static_cast<size_t> (1)) {
3565 if (isConstantStride ()) {
3566 return rcp (
new MV (this->getMap (), view_,
cols));
3573 return rcp (
new MV (this->getMap (), view_,
newcols ()));
3578 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3579 Teuchos::RCP<const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3583 using ::Tpetra::Details::Behavior;
3585 using Kokkos::subview;
3586 using Teuchos::Array;
3592 const size_t lclNumRows = this->getLocalLength ();
3593 const size_t numVecs = this->getNumVectors ();
3598 static_cast<size_t> (
colRng.size ()) >
numVecs, std::runtime_error,
3599 "colRng.size() = " <<
colRng.size () <<
" > this->getNumVectors() = "
3603 (
colRng.lbound () <
static_cast<Teuchos::Ordinal
> (0) ||
3605 std::invalid_argument,
"Nonempty input range [" <<
colRng.lbound () <<
3606 "," <<
colRng.ubound () <<
"] exceeds the valid range of column indices "
3620 if (
colRng.size () == 0) {
3621 const std::pair<size_t, size_t>
cols (0, 0);
3627 if (isConstantStride ()) {
3628 const std::pair<size_t, size_t>
cols (
colRng.lbound (),
3634 if (
static_cast<size_t> (
colRng.size ()) ==
static_cast<size_t> (1)) {
3637 const std::pair<size_t, size_t> col (whichVectors_[0] +
colRng.lbound (),
3638 whichVectors_[0] +
colRng.ubound () + 1);
3644 whichVectors_.begin () +
colRng.ubound () + 1);
3650 const bool debug = Behavior::debug ();
3652 using Teuchos::Comm;
3653 using Teuchos::outArg;
3654 using Teuchos::REDUCE_MIN;
3655 using Teuchos::reduceAll;
3658 Teuchos::null : this->getMap ()->getComm ();
3659 if (! comm.is_null ()) {
3663 if (
X_ret.is_null ()) {
3668 (
lclSuccess != 1, std::logic_error,
"X_ret (the subview of this "
3669 "MultiVector; the return value of this method) is null on some MPI "
3670 "process in this MultiVector's communicator. This should never "
3671 "happen. Please report this bug to the Tpetra developers.");
3672 if (!
X_ret.is_null () &&
3673 X_ret->getNumVectors () !=
static_cast<size_t> (
colRng.size ())) {
3679 (
lclSuccess != 1, std::logic_error,
"X_ret->getNumVectors() != "
3680 "colRng.size(), on at least one MPI process in this MultiVector's "
3681 "communicator. This should never happen. "
3682 "Please report this bug to the Tpetra developers.");
3689 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3690 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3695 return Teuchos::rcp_const_cast<MV> (this->subView (
cols));
3699 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3700 Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3705 return Teuchos::rcp_const_cast<MV> (this->subView (
colRng));
3709 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3715 using Kokkos::subview;
3716 typedef std::pair<size_t, size_t> range_type;
3717 const char tfecfFuncName[] =
"MultiVector(const MultiVector&, const size_t): ";
3719 const size_t numCols =
X.getNumVectors ();
3721 (
j >= numCols, std::invalid_argument,
"Input index j (== " <<
j
3722 <<
") exceeds valid column index range [0, " << numCols <<
" - 1].");
3723 const size_t jj =
X.isConstantStride () ?
3724 static_cast<size_t> (
j) :
3725 static_cast<size_t> (
X.whichVectors_[
j]);
3737 const size_t newSize =
X.imports_.extent (0) / numCols;
3747 const size_t newSize =
X.exports_.extent (0) / numCols;
3764 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3765 Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3770 return Teuchos::rcp (
new V (*
this,
j));
3774 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3775 Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3780 return Teuchos::rcp (
new V (*
this,
j));
3784 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3787 get1dCopy (
const Teuchos::ArrayView<Scalar>&
A,
const size_t LDA)
const
3790 using input_view_type = Kokkos::View<IST**, Kokkos::LayoutLeft,
3792 Kokkos::MemoryUnmanaged>;
3795 const size_t numRows = this->getLocalLength ();
3796 const size_t numCols = this->getNumVectors ();
3800 "LDA = " <<
LDA <<
" < numRows = " <<
numRows <<
".");
3802 (
numRows >
size_t (0) && numCols >
size_t (0) &&
3803 size_t (
A.size ()) <
LDA * (numCols - 1) +
numRows,
3805 "A.size() = " <<
A.size () <<
", but its size must be at least "
3806 << (
LDA * (numCols - 1) +
numRows) <<
" to hold all the entries.");
3809 const std::pair<size_t, size_t>
colRange (0, numCols);
3811 input_view_type
A_view_orig (
reinterpret_cast<IST*
> (
A.getRawPtr ()),
3826 if (this->need_sync_host() && this->need_sync_device()) {
3829 throw std::runtime_error(
"Tpetra::MultiVector: A non-const view is alive outside and we cannot give a copy where host or device view can be modified outside");
3832 const bool useHostView = view_.host_view_use_count() >= view_.device_view_use_count();
3833 if (this->isConstantStride ()) {
3835 auto srcView_host = this->getLocalViewHost(Access::ReadOnly);
3839 auto srcView_device = this->getLocalViewDevice(Access::ReadOnly);
3845 for (
size_t j = 0;
j < numCols; ++
j) {
3846 const size_t srcCol = this->whichVectors_[
j];
3850 auto srcView_host = this->getLocalViewHost(Access::ReadOnly);
3855 auto srcView_device = this->getLocalViewDevice(Access::ReadOnly);
3866 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3873 const size_t numRows = this->getLocalLength ();
3874 const size_t numCols = this->getNumVectors ();
3877 static_cast<size_t> (
ArrayOfPtrs.size ()) != numCols,
3878 std::runtime_error,
"Input array of pointers must contain as many "
3879 "entries (arrays) as the MultiVector has columns. ArrayOfPtrs.size() = "
3880 <<
ArrayOfPtrs.size () <<
" != getNumVectors() = " << numCols <<
".");
3882 if (
numRows != 0 && numCols != 0) {
3884 for (
size_t j = 0;
j < numCols; ++
j) {
3887 dstLen <
numRows, std::invalid_argument,
"Array j = " <<
j <<
" of "
3888 "the input array of arrays is not long enough to fit all entries in "
3889 "that column of the MultiVector. ArrayOfPtrs[j].size() = " <<
dstLen
3890 <<
" < getLocalLength() = " <<
numRows <<
".");
3894 for (
size_t j = 0;
j < numCols; ++
j) {
3895 Teuchos::RCP<const V>
X_j = this->getVector (
j);
3903 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3904 Teuchos::ArrayRCP<const Scalar>
3908 if (getLocalLength () == 0 || getNumVectors () == 0) {
3909 return Teuchos::null;
3912 ! isConstantStride (), std::runtime_error,
"Tpetra::MultiVector::"
3913 "get1dView: This MultiVector does not have constant stride, so it is "
3914 "not possible to view its data as a single array. You may check "
3915 "whether a MultiVector has constant stride by calling "
3916 "isConstantStride().");
3920 auto X_lcl = getLocalViewHost(Access::ReadOnly);
3921 Teuchos::ArrayRCP<const impl_scalar_type>
dataAsArcp =
3922 Kokkos::Compat::persistingView (
X_lcl);
3923 return Teuchos::arcp_reinterpret_cast<const Scalar> (
dataAsArcp);
3927 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3928 Teuchos::ArrayRCP<Scalar>
3932 if (this->getLocalLength () == 0 || this->getNumVectors () == 0) {
3933 return Teuchos::null;
3937 (! isConstantStride (), std::runtime_error,
"Tpetra::MultiVector::"
3938 "get1dViewNonConst: This MultiVector does not have constant stride, "
3939 "so it is not possible to view its data as a single array. You may "
3940 "check whether a MultiVector has constant stride by calling "
3941 "isConstantStride().");
3942 auto X_lcl = getLocalViewHost(Access::ReadWrite);
3943 Teuchos::ArrayRCP<impl_scalar_type>
dataAsArcp =
3944 Kokkos::Compat::persistingView (
X_lcl);
3945 return Teuchos::arcp_reinterpret_cast<Scalar> (
dataAsArcp);
3949 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3950 Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> >
3954 auto X_lcl = getLocalViewHost(Access::ReadWrite);
3960 const size_t myNumRows = this->getLocalLength ();
3961 const size_t numCols = this->getNumVectors ();
3964 Teuchos::ArrayRCP<Teuchos::ArrayRCP<Scalar> >
views (numCols);
3965 for (
size_t j = 0;
j < numCols; ++
j) {
3966 const size_t col = this->isConstantStride () ?
j : this->whichVectors_[
j];
3969 Kokkos::Compat::persistingView (
X_lcl_j);
3975 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3980 return view_.getHostView(
s);
3983 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3988 return view_.getHostView(
s);
3991 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
3996 return view_.getHostView(
s);
3999 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4004 return view_.getDeviceView(
s);
4007 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4012 return view_.getDeviceView(
s);
4015 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4020 return view_.getDeviceView(
s);
4023 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4024 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> >
4031 auto X_lcl = getLocalViewHost(Access::ReadOnly);
4037 const size_t myNumRows = this->getLocalLength ();
4038 const size_t numCols = this->getNumVectors ();
4041 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const Scalar> >
views (numCols);
4042 for (
size_t j = 0;
j < numCols; ++
j) {
4043 const size_t col = this->isConstantStride () ?
j : this->whichVectors_[
j];
4045 Teuchos::ArrayRCP<const impl_scalar_type>
X_lcl_j_arcp =
4046 Kokkos::Compat::persistingView (
X_lcl_j);
4052 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4062 using ::Tpetra::Details::ProfilingRegion;
4063 using Teuchos::CONJ_TRANS;
4064 using Teuchos::NO_TRANS;
4065 using Teuchos::TRANS;
4068 using Teuchos::rcpFromRef;
4070 using ATS = Kokkos::ArithTraits<impl_scalar_type>;
4072 using STS = Teuchos::ScalarTraits<Scalar>;
4075 ProfilingRegion
region (
"Tpetra::MV::multiply");
4107 const bool C_is_local = ! this->isDistributed ();
4117 auto myMap = this->getMap ();
4118 if (!
myMap.is_null () && !
myMap->getComm ().is_null ()) {
4119 using Teuchos::REDUCE_MIN;
4120 using Teuchos::reduceAll;
4121 using Teuchos::outArg;
4123 auto comm =
myMap->getComm ();
4136 const int myRank = comm->getRank ();
4138 if (this->getLocalLength () !=
A_nrows) {
4140 << this->getLocalLength () <<
" != A_nrows=" <<
A_nrows
4141 <<
"." << std::endl;
4143 if (this->getNumVectors () !=
B_ncols) {
4145 << this->getNumVectors () <<
" != B_ncols=" <<
B_ncols
4146 <<
"." << std::endl;
4151 <<
"." << std::endl;
4158 std::ostringstream
os;
4162 (
true, std::runtime_error,
"Inconsistent local dimensions on at "
4163 "least one process in this object's communicator." << std::endl
4165 <<
"C(" << (
C_is_local ?
"local" :
"distr") <<
") = "
4167 << (
transA == Teuchos::TRANS ?
"^T" :
4168 (
transA == Teuchos::CONJ_TRANS ?
"^H" :
""))
4169 <<
"(" << (
A_is_local ?
"local" :
"distr") <<
") * "
4171 << (
transA == Teuchos::TRANS ?
"^T" :
4172 (
transA == Teuchos::CONJ_TRANS ?
"^H" :
""))
4173 <<
"(" << (
B_is_local ?
"local" :
"distr") <<
")." << std::endl
4174 <<
"Global dimensions: C(" << this->getGlobalLength () <<
", "
4175 << this->getNumVectors () <<
"), A(" <<
A.getGlobalLength ()
4176 <<
", " <<
A.getNumVectors () <<
"), B(" <<
B.getGlobalLength ()
4177 <<
", " <<
B.getNumVectors () <<
")." << std::endl
4196 "Multiplication of op(A) and op(B) into *this is not a "
4197 "supported use case.");
4205 const int myRank = this->getMap ()->getComm ()->getRank ();
4216 if (! isConstantStride ()) {
4217 C_tmp =
rcp (
new MV (*
this, Teuchos::Copy));
4223 if (!
A.isConstantStride ()) {
4224 A_tmp =
rcp (
new MV (
A, Teuchos::Copy));
4230 if (!
B.isConstantStride ()) {
4231 B_tmp =
rcp (
new MV (
B, Teuchos::Copy));
4237 (!
C_tmp->isConstantStride () || !
B_tmp->isConstantStride () ||
4238 !
A_tmp->isConstantStride (), std::logic_error,
4239 "Failed to make temporary constant-stride copies of MultiVectors.");
4244 auto A_lcl =
A_tmp->getLocalViewDevice(Access::ReadOnly);
4245 auto A_sub = Kokkos::subview (A_lcl,
4252 auto B_lcl =
B_tmp->getLocalViewDevice(Access::ReadOnly);
4253 auto B_sub = Kokkos::subview (B_lcl,
4260 auto C_lcl =
C_tmp->getLocalViewDevice(Access::ReadWrite);
4265 (
transA == Teuchos::TRANS ?
'T' :
'C'));
4267 (
transB == Teuchos::TRANS ?
'T' :
'C'));
4270 ProfilingRegion
regionGemm (
"Tpetra::MV::multiply-call-gemm");
4276 if (! isConstantStride ()) {
4281 A_tmp = Teuchos::null;
4282 B_tmp = Teuchos::null;
4290 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4299 using Kokkos::subview;
4302 const size_t lclNumRows = this->getLocalLength ();
4303 const size_t numVecs = this->getNumVectors ();
4307 std::runtime_error,
"MultiVectors do not have the same local length.");
4309 numVecs !=
B.getNumVectors (), std::runtime_error,
"this->getNumVectors"
4310 "() = " <<
numVecs <<
" != B.getNumVectors() = " <<
B.getNumVectors ()
4313 auto this_view = this->getLocalViewDevice(Access::ReadWrite);
4314 auto A_view =
A.getLocalViewDevice(Access::ReadOnly);
4315 auto B_view =
B.getLocalViewDevice(Access::ReadOnly);
4317 if (isConstantStride () &&
B.isConstantStride ()) {
4331 const size_t C_col = isConstantStride () ?
j : whichVectors_[
j];
4332 const size_t B_col =
B.isConstantStride () ?
j :
B.whichVectors_[
j];
4342 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4347 using ::Tpetra::Details::allReduceView;
4348 using ::Tpetra::Details::ProfilingRegion;
4349 ProfilingRegion
region (
"Tpetra::MV::reduce");
4351 const auto map = this->getMap ();
4352 if (
map.get () ==
nullptr) {
4355 const auto comm =
map->getComm ();
4356 if (comm.get () ==
nullptr) {
4368 auto X_lcl = this->getLocalViewDevice(Access::ReadWrite);
4372 auto X_lcl = this->getLocalViewHost(Access::ReadWrite);
4377 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4390 "Tpetra::MultiVector::replaceLocalValue: row index " <<
lclRow
4391 <<
" is invalid. The range of valid row indices on this process "
4395 vectorIndexOutOfRange(col),
4397 "Tpetra::MultiVector::replaceLocalValue: vector index " << col
4398 <<
" of the multivector is invalid.");
4401 auto view = this->getLocalViewHost(Access::ReadWrite);
4402 const size_t colInd = isConstantStride () ? col : whichVectors_[col];
4407 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4421 "Tpetra::MultiVector::sumIntoLocalValue: row index " <<
lclRow
4422 <<
" is invalid. The range of valid row indices on this process "
4426 vectorIndexOutOfRange(col),
4428 "Tpetra::MultiVector::sumIntoLocalValue: vector index " << col
4429 <<
" of the multivector is invalid.");
4432 const size_t colInd = isConstantStride () ? col : whichVectors_[col];
4434 auto view = this->getLocalViewHost(Access::ReadWrite);
4444 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4458 (
lclRow == Teuchos::OrdinalTraits<LocalOrdinal>::invalid (),
4460 "Global row index " <<
gblRow <<
" is not present on this process "
4461 << this->getMap ()->getComm ()->
getRank () <<
".");
4463 (this->vectorIndexOutOfRange (col), std::runtime_error,
4464 "Vector index " << col <<
" of the MultiVector is invalid.");
4470 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4484 lclRow == Teuchos::OrdinalTraits<LocalOrdinal>::invalid (),
4486 "Tpetra::MultiVector::sumIntoGlobalValue: Global row index " <<
globalRow
4487 <<
" is not present on this process "
4488 << this->getMap ()->getComm ()->
getRank () <<
".");
4490 vectorIndexOutOfRange(col),
4492 "Tpetra::MultiVector::sumIntoGlobalValue: Vector index " << col
4493 <<
" of the multivector is invalid.");
4496 this->sumIntoLocalValue (
lclRow, col, value, atomic);
4499 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4501 Teuchos::ArrayRCP<T>
4507 typename dual_view_type::array_layout,
4509 const size_t col = isConstantStride () ?
j : whichVectors_[
j];
4511 Kokkos::subview (view_, Kokkos::ALL (), col);
4512 return Kokkos::Compat::persistingView (
X_col.d_view);
4515 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4519 return view_.need_sync_host ();
4522 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4526 return view_.need_sync_device ();
4529 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4534 using Teuchos::TypeNameTraits;
4536 std::ostringstream
out;
4541 <<
", Node" << Node::name ()
4546 out <<
", numRows: " << this->getGlobalLength ();
4548 out <<
", numCols: " << this->getNumVectors ()
4549 <<
", isConstantStride: " << this->isConstantStride ();
4551 if (this->isConstantStride ()) {
4552 out <<
", columnStride: " << this->getStride ();
4559 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4564 return this->descriptionImpl (
"Tpetra::MultiVector");
4569 template<
typename ViewType>
4570 void print_vector(Teuchos::FancyOStream &
out,
const char*
prefix,
const ViewType&
v)
4573 static_assert(Kokkos::SpaceAccessibility<Kokkos::HostSpace, typename ViewType::memory_space>::accessible,
4574 "Tpetra::MultiVector::localDescribeToString: Details::print_vector should be given a host-accessible view.");
4575 static_assert(ViewType::rank == 2,
4576 "Tpetra::MultiVector::localDescribeToString: Details::print_vector should be given a rank-2 view.");
4579 out <<
"Values("<<
prefix<<
"): " << std::endl
4581 const size_t numRows =
v.extent(0);
4582 const size_t numCols =
v.extent(1);
4593 for (
size_t j = 0;
j < numCols; ++
j) {
4595 if (
j + 1 < numCols) {
4608 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4616 if (
vl <= Teuchos::VERB_LOW) {
4617 return std::string ();
4619 auto map = this->getMap ();
4620 if (
map.is_null ()) {
4621 return std::string ();
4623 auto outStringP = Teuchos::rcp (
new std::ostringstream ());
4625 Teuchos::FancyOStream&
out = *
outp;
4626 auto comm =
map->getComm ();
4627 const int myRank = comm->getRank ();
4628 const int numProcs = comm->getSize ();
4634 const LO
lclNumRows =
static_cast<LO
> (this->getLocalLength ());
4637 if (
vl > Teuchos::VERB_MEDIUM) {
4640 if (this->getNumVectors () !=
static_cast<size_t> (1)) {
4641 out <<
"isConstantStride: " << this->isConstantStride () <<
endl;
4643 if (this->isConstantStride ()) {
4644 out <<
"Column stride: " << this->getStride () <<
endl;
4655 auto X_dev = view_.getDeviceCopy();
4656 auto X_host = view_.getHostCopy();
4660 Details::print_vector(
out,
"unified",
X_host);
4663 Details::print_vector(
out,
"host",
X_host);
4664 Details::print_vector(
out,
"dev",
X_dev);
4672 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4677 const Teuchos::EVerbosityLevel
verbLevel)
const
4679 using Teuchos::TypeNameTraits;
4680 using Teuchos::VERB_DEFAULT;
4681 using Teuchos::VERB_NONE;
4682 using Teuchos::VERB_LOW;
4684 const Teuchos::EVerbosityLevel
vl =
4694 auto map = this->getMap ();
4695 if (
map.is_null ()) {
4698 auto comm =
map->getComm ();
4699 if (comm.is_null ()) {
4703 const int myRank = comm->getRank ();
4712 Teuchos::RCP<Teuchos::OSTab>
tab0,
tab1;
4716 tab0 = Teuchos::rcp (
new Teuchos::OSTab (
out));
4718 tab1 = Teuchos::rcp (
new Teuchos::OSTab (
out));
4720 out <<
"Template parameters:" <<
endl;
4725 <<
"Node: " << Node::name () <<
endl;
4730 out <<
"Global number of rows: " << this->getGlobalLength () <<
endl;
4732 out <<
"Number of columns: " << this->getNumVectors () <<
endl;
4740 const std::string
lclStr = this->localDescribeToString (
vl);
4745 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4749 const Teuchos::EVerbosityLevel
verbLevel)
const
4751 this->describeImpl (
out,
"Tpetra::MultiVector",
verbLevel);
4754 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4762 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4767 using ::Tpetra::Details::localDeepCopy;
4768 const char prefix[] =
"Tpetra::MultiVector::assign: ";
4771 (this->getGlobalLength () != src.getGlobalLength () ||
4772 this->getNumVectors () != src.getNumVectors (), std::invalid_argument,
4773 prefix <<
"Global dimensions of the two Tpetra::MultiVector "
4774 "objects do not match. src has dimensions [" << src.getGlobalLength ()
4775 <<
"," << src.getNumVectors () <<
"], and *this has dimensions ["
4776 <<
this->getGlobalLength () <<
"," <<
this->getNumVectors () <<
"].");
4779 (this->getLocalLength () != src.getLocalLength (), std::invalid_argument,
4780 prefix <<
"The local row counts of the two Tpetra::MultiVector "
4781 "objects do not match. src has " << src.getLocalLength () <<
" row(s) "
4782 <<
" and *this has " <<
this->getLocalLength () <<
" row(s).");
4798 localDeepCopy (this->getLocalViewHost(Access::ReadWrite),
4799 src.getLocalViewHost(Access::ReadOnly),
4800 this->isConstantStride (),
4801 src.isConstantStride (),
4802 this->whichVectors_ (),
4803 src.whichVectors_ ());
4806 localDeepCopy (this->getLocalViewDevice(Access::ReadWrite),
4807 src.getLocalViewDevice(Access::ReadOnly),
4808 this->isConstantStride (),
4809 src.isConstantStride (),
4810 this->whichVectors_ (),
4811 src.whichVectors_ ());
4815 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4817 Teuchos::RCP<MultiVector<T, LocalOrdinal, GlobalOrdinal, Node> >
4824 this->getNumVectors(),
4830 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
4835 using ::Tpetra::Details::PackTraits;
4837 const size_t l1 = this->getLocalLength();
4838 const size_t l2 =
vec.getLocalLength();
4839 if ((
l1!=
l2) || (this->getNumVectors() !=
vec.getNumVectors())) {
4846 template <
class ST,
class LO,
class GO,
class NT>
4849 std::swap(
mv.map_,
this->map_);
4850 std::swap(
mv.view_,
this->view_);
4851 std::swap(
mv.whichVectors_,
this->whichVectors_);
4854#ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
4855 template <
class ST,
class LO,
class GO,
class NT>
4858 const Teuchos::SerialDenseMatrix<int, ST>& src)
4860 using ::Tpetra::Details::localDeepCopy;
4862 using IST =
typename MV::impl_scalar_type;
4863 using input_view_type =
4864 Kokkos::View<
const IST**, Kokkos::LayoutLeft,
4865 Kokkos::HostSpace, Kokkos::MemoryUnmanaged>;
4866 using pair_type = std::pair<LO, LO>;
4868 const LO
numRows =
static_cast<LO
> (src.numRows ());
4869 const LO numCols =
static_cast<LO
> (src.numCols ());
4872 (
numRows !=
static_cast<LO
> (dst.getLocalLength ()) ||
4873 numCols !=
static_cast<LO
> (dst.getNumVectors ()),
4874 std::invalid_argument,
"Tpetra::deep_copy: On Process "
4875 << dst.getMap ()->getComm ()->getRank () <<
", dst is "
4876 << dst.getLocalLength () <<
" x " << dst.getNumVectors ()
4877 <<
", but src is " <<
numRows <<
" x " << numCols <<
".");
4879 const IST*
src_raw =
reinterpret_cast<const IST*
> (src.values ());
4886 localDeepCopy (dst.getLocalViewHost(Access::ReadWrite),
4888 dst.isConstantStride (),
4890 getMultiVectorWhichVectors (dst),
4894 template <
class ST,
class LO,
class GO,
class NT>
4896 deep_copy (Teuchos::SerialDenseMatrix<int, ST>& dst,
4899 using ::Tpetra::Details::localDeepCopy;
4901 using IST =
typename MV::impl_scalar_type;
4902 using output_view_type =
4903 Kokkos::View<IST**, Kokkos::LayoutLeft,
4904 Kokkos::HostSpace, Kokkos::MemoryUnmanaged>;
4905 using pair_type = std::pair<LO, LO>;
4907 const LO
numRows =
static_cast<LO
> (dst.numRows ());
4908 const LO numCols =
static_cast<LO
> (dst.numCols ());
4913 std::invalid_argument,
"Tpetra::deep_copy: On Process "
4914 << src.
getMap ()->getComm ()->getRank () <<
", src is "
4916 <<
", but dst is " <<
numRows <<
" x " << numCols <<
".");
4918 IST*
dst_raw =
reinterpret_cast<IST*
> (dst.values ());
4932 getMultiVectorWhichVectors (src));
4936 template <
class Scalar,
class LO,
class GO,
class NT>
4937 Teuchos::RCP<MultiVector<Scalar, LO, GO, NT> >
4945 template <
class ST,
class LO,
class GO,
class NT>
4950 MV
cpy (src.getMap (), src.getNumVectors (),
false);
4963#ifdef HAVE_TPETRACORE_TEUCHOSNUMERICS
4964# define TPETRA_MULTIVECTOR_INSTANT(SCALAR,LO,GO,NODE) \
4965 template class MultiVector< SCALAR , LO , GO , NODE >; \
4966 template MultiVector< SCALAR , LO , GO , NODE > createCopy( const MultiVector< SCALAR , LO , GO , NODE >& src); \
4967 template Teuchos::RCP<MultiVector< SCALAR , LO , GO , NODE > > createMultiVector (const Teuchos::RCP<const Map<LO, GO, NODE> >& map, size_t numVectors); \
4968 template void deep_copy (MultiVector<SCALAR, LO, GO, NODE>& dst, const Teuchos::SerialDenseMatrix<int, SCALAR>& src); \
4969 template void deep_copy (Teuchos::SerialDenseMatrix<int, SCALAR>& dst, const MultiVector<SCALAR, LO, GO, NODE>& src);
4972# define TPETRA_MULTIVECTOR_INSTANT(SCALAR,LO,GO,NODE) \
4973 template class MultiVector< SCALAR , LO , GO , NODE >; \
4974 template MultiVector< SCALAR , LO , GO , NODE > createCopy( const MultiVector< SCALAR , LO , GO , NODE >& src);
4979#define TPETRA_MULTIVECTOR_CONVERT_INSTANT(SO,SI,LO,GO,NODE) \
4981 template Teuchos::RCP< MultiVector< SO , LO , GO , NODE > > \
4982 MultiVector< SI , LO , GO , NODE >::convert< SO > () const;
Functions for initializing and finalizing Tpetra.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Declaration and generic definition of traits class that tells Tpetra::CrsMatrix how to pack and unpac...
Declaration of Tpetra::Details::Profiling, a scope guard for Kokkos Profiling.
All-reduce a 1-D or 2-D Kokkos::View.
Declaration of functions for checking whether a given pointer is accessible from a given Kokkos execu...
Declaration and definition of Tpetra::Details::Blas::fill, an implementation detail of Tpetra::MultiV...
Declaration of a function that prints strings from each process.
Declaration of Tpetra::Details::isInterComm.
Declaration and definition of Tpetra::Details::lclDot, an implementation detail of Tpetra::MultiVecto...
Declaration and definition of Tpetra::Details::normImpl, which is an implementation detail of Tpetra:...
Declaration and definition of Tpetra::Details::reallocDualViewIfNeeded, an implementation detail of T...
Stand-alone utility functions and macros.
Struct that holds views of the contents of a CrsMatrix.
static bool assumeMpiIsGPUAware()
Whether to assume that MPI is CUDA aware.
static bool debug()
Whether Tpetra is in debug mode.
static bool verbose()
Whether Tpetra is in verbose mode.
static size_t multivectorKernelLocationThreshold()
the threshold for transitioning from device to host
virtual bool reallocImportsIfNeeded(const size_t newSize, const bool verbose, const std::string *prefix, const bool remoteLIDsContiguous=false, const CombineMode CM=INSERT)
Reallocate imports_ if needed.
Kokkos::DualView< size_t *, buffer_device_type > numImportPacketsPerLID_
Number of packets to receive for each receive operation.
Kokkos::DualView< packet_type *, buffer_device_type > exports_
Buffer from which packed data are exported (sent to other processes).
Kokkos::DualView< packet_type *, buffer_device_type > imports_
Buffer into which packed data are imported (received from other processes).
Kokkos::DualView< size_t *, buffer_device_type > numExportPacketsPerLID_
Number of packets to send for each send operation.
virtual Teuchos::RCP< const map_type > getMap() const
The Map describing the parallel distribution of this object.
A parallel distribution of indices over processes.
One or more distributed dense vectors.
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.
MultiVector< ST, LO, GO, NT > createCopy(const MultiVector< ST, LO, GO, NT > &src)
Return a deep copy of the given MultiVector.
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
The type of local indices that this class uses.
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.
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).
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.
wrapped_dual_view_type view_
The Kokkos::DualView containing the MultiVector's data.
void replaceLocalValue(const LocalOrdinal lclRow, const size_t col, const impl_scalar_type &value)
Replace value in host memory, using local (row) index.
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.
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.
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.
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.
size_t getNumVectors() const
Number of columns in the multivector.
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.
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::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.
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.
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.
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.
bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
size_t getOrigNumLocalRows() const
"Original" number of rows in the (local) data.
Teuchos::ArrayRCP< Teuchos::ArrayRCP< const Scalar > > get2dView() const
Return const persisting pointers to values.
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.
Implementation details of Tpetra.
int local_ordinal_type
Default value of Scalar template parameter.
void normImpl(MagnitudeType norms[], const Kokkos::View< const ValueType **, ArrayLayout, DeviceType > &X, const EWhichNorm whichNorm, const Teuchos::ArrayView< const size_t > &whichVecs, const bool isConstantStride, const bool isDistributed, const Teuchos::Comm< int > *comm)
Implementation of MultiVector norms.
bool isInterComm(const Teuchos::Comm< int > &)
Return true if and only if the input communicator wraps an MPI intercommunicator.
void gathervPrint(std::ostream &out, const std::string &s, const Teuchos::Comm< int > &comm)
On Process 0 in the given communicator, print strings from each process in that communicator,...
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.
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.
size_t global_size_t
Global size_t object.
std::string combineModeToString(const CombineMode combineMode)
Human-readable string representation of the given CombineMode.
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.
@ REPLACE
Replace existing values with new values.
@ ABSMAX
Replace old value with maximum of magnitudes of old and new values.
@ ADD_ASSIGN
Accumulate new values into existing values (may not be supported in all classes)
@ INSERT
Insert new values that don't currently exist.