42 #ifndef TPETRA_MULTIVECTOR_DEF_HPP 43 #define TPETRA_MULTIVECTOR_DEF_HPP 45 #include <Kokkos_DefaultArithmetic.hpp> 46 #include <Kokkos_NodeTrace.hpp> 47 #include <Teuchos_Assert.hpp> 50 #include <Tpetra_Vector.hpp> 52 #ifdef DOXYGEN_USE_ONLY 53 #include "Tpetra_MultiVector_decl.hpp" 58 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
60 MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
61 vectorIndexOutOfRange(
size_t VectorIndex)
const {
62 return (VectorIndex < 1 && VectorIndex != 0) || VectorIndex >= getNumVectors();
65 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map),
71 lclMV_ (map->getNode ()),
72 releaseViewsRaisedEfficiencyWarning_ (false),
73 createViewsRaisedEfficiencyWarning_ (false),
74 createViewsNonConstRaisedEfficiencyWarning_ (false)
80 "Tpetra::MultiVector::MultiVector(): NumVectors must be strictly positive.");
88 ArrayRCP<Scalar> data = node->template allocBuffer<Scalar>(myLen*NumVectors);
89 MVT::initializeValues(
lclMV_,myLen,NumVectors,data,myLen);
97 MVT::initializeValues(
lclMV_,0,NumVectors,Teuchos::null,0);
101 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
104 DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> (source),
123 node->template allocBuffer<Scalar> (myLen * numVecs) :
125 const size_t stride = (myLen > 0) ? myLen :
size_t (0);
128 MVT::initializeValues (
lclMV_, myLen, numVecs, data, stride);
140 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
143 const Kokkos::MultiVector<Scalar,Node>& localMultiVector,
144 EPrivateComputeViewConstructor ) :
145 DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map),
146 lclMV_ (localMultiVector),
151 const size_t localNumElts = map->getNodeNumElements ();
153 localMultiVector.getNumRows () < localNumElts,
154 std::invalid_argument,
155 "Tpetra::MultiVector constructor: The Map contains " << localNumElts
156 <<
" on process " << map->getComm ()->getRank () <<
", but the given " 157 "Kokkos::MultiVector only has " << localMultiVector.getNumRows ()
161 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
167 EPrivateHostViewConstructor ) :
168 DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map),
178 const char tfecfFuncName[] =
"MultiVector(view,LDA,NumVector)";
180 ": NumVectors must be strictly positive, but you specified NumVectors = " 181 << NumVectors <<
".");
184 ": LDA must be large enough to accomodate the local entries.");
186 as<size_t> (view.
size ()) < LDA*(NumVectors - 1) + myLen,
187 std::invalid_argument,
188 ": view does not contain enough data to specify the entries in this.");
189 MVT::initializeValues (
lclMV_, myLen, NumVectors, view, myLen);
192 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
198 EPrivateComputeViewConstructor ) :
199 DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map),
209 const char tfecfFuncName[] =
"MultiVector(data,LDA,NumVector)";
211 ": NumVectors must be strictly positive.");
213 #ifdef HAVE_TPETRA_DEBUG 215 as<size_t> (data.
size ()) < LDA*(NumVectors - 1) + myLen,
217 ": data does not contain enough data to specify the entries in this.");
219 MVT::initializeValues(
lclMV_,myLen,NumVectors,data,LDA);
222 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
228 EPrivateComputeViewConstructor ) :
229 DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map),
240 const char tfecfFuncName[] =
"MultiVector(data,LDA,WhichVectors)";
242 size_t maxVector = *std::max_element(WhichVectors.
begin(), WhichVectors.
end());
244 ": LDA must be large enough to accomodate the local entries.");
245 #ifdef HAVE_TPETRA_DEBUG 246 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
247 as<size_t> (data.
size ()) < LDA * maxVector + myLen, std::runtime_error,
248 ": data does not contain enough data to specify the entries in this.");
250 if (WhichVectors.
size () == 1) {
253 data += LDA * WhichVectors[0];
258 MVT::initializeValues(
lclMV_,myLen,maxVector+1,data,LDA);
261 MVT::initializeValues(
lclMV_,0,WhichVectors.
size(),Teuchos::null,0);
266 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
269 const Kokkos::MultiVector<Scalar,Node>& localMultiVector,
271 EPrivateComputeViewConstructor ) :
272 DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map),
273 lclMV_ (localMultiVector),
279 const size_t localNumElts = map->getNodeNumElements ();
281 localMultiVector.getNumRows () < localNumElts,
282 std::invalid_argument,
283 "Tpetra::MultiVector constructor: The Map contains " << localNumElts
284 <<
" on process " << map->getComm ()->getRank () <<
", but the given " 285 "Kokkos::MultiVector only has " << localMultiVector.getNumRows ()
288 WhichVectors.
size () == 0,
289 std::invalid_argument,
290 "Tpetra::MultiVector constructor: WhichVectors.size() == 0. " 291 "The noncontiguous column view constructor only makes sense for a " 292 "nonzero number of columns to view.");
296 if (WhichVectors.
size () == 1) {
297 const size_t offsetRow = 0;
298 const size_t offsetCol = WhichVectors[0];
299 lclMV_ =
lclMV_.offsetViewNonConst (localNumElts, 1, offsetRow, offsetCol);
305 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
311 DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map),
322 const char tfecfFuncName[] =
"MultiVector(A,LDA)";
324 ": NumVectors must be strictly positive.");
327 ": LDA must be large enough to accomodate the local entries.");
328 #ifdef HAVE_TPETRA_DEBUG 330 as<size_t> (A.
size ()) < LDA*(NumVectors - 1) + myLen,
332 ": A does not contain enough data to specify the entries in this.");
336 ArrayRCP<Scalar> mydata = node->template allocBuffer<Scalar>(myLen*NumVectors);
337 MVT::initializeValues(
lclMV_,myLen,NumVectors,mydata,myLen);
344 KOKKOS_NODE_TRACE(
"MultiVector::MultiVector(1D)")
345 ArrayRCP<Scalar> myview = node->template viewBufferNonConst<Scalar>(Kokkos::WriteOnly,myLen*NumVectors,mydata);
347 for (
size_t j = 0; j < NumVectors; ++j) {
348 std::copy(srcit,srcit+myLen,myview);
352 mydata = Teuchos::null;
353 myview = Teuchos::null;
356 MVT::initializeValues(
lclMV_,0,NumVectors,Teuchos::null,0);
360 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
365 DistObject<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map),
376 const char tfecfFuncName[] =
"MultiVector(ArrayOfPtrs)";
378 NumVectors < 1 || NumVectors != as<size_t>(ArrayOfPtrs.size()),
380 ": ArrayOfPtrs.size() must be strictly positive and as large as ArrayOfPtrs.");
384 ArrayRCP<Scalar> mydata = node->template allocBuffer<Scalar>(myLen*NumVectors);
385 MVT::initializeValues(
lclMV_,myLen,NumVectors,mydata,myLen);
386 KOKKOS_NODE_TRACE(
"MultiVector::MultiVector(2D)")
387 ArrayRCP<Scalar> myview = node->template viewBufferNonConst<Scalar>(Kokkos::WriteOnly,myLen*NumVectors,mydata);
388 for (
size_t j = 0; j < NumVectors; ++j) {
389 #ifdef HAVE_TPETRA_DEBUG 393 ": ArrayOfPtrs[" << j <<
"].size() (== " << ArrayOfPtrs[j].size()
394 <<
") is not equal to getLocalLength() (== " <<
getLocalLength());
397 std::copy(src,src+myLen,myview);
400 myview = Teuchos::null;
401 mydata = Teuchos::null;
404 MVT::initializeValues(
lclMV_,0,NumVectors,Teuchos::null,0);
409 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
414 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
420 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
422 return this->
getMap()->getNodeNumElements();
426 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
428 return this->
getMap()->getGlobalNumElements();
432 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
435 return MVT::getStride(
lclMV_);
441 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
450 const this_type* src =
dynamic_cast<const this_type*
> (&sourceObj);
465 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
478 const char tfecfFuncName[] =
"copyAndPermute";
481 permuteToLIDs.
size() != permuteFromLIDs.
size(), std::runtime_error,
482 ": permuteToLIDs and permuteFromLIDs must have the same size." 483 << std::endl <<
"permuteToLIDs.size() = " << permuteToLIDs.
size ()
484 <<
" != permuteFromLIDs.size() = " << permuteFromLIDs.
size () <<
".");
487 const MV& sourceMV =
dynamic_cast<const MV&
> (sourceObj);
503 if (Node::isHostNode) {
505 const size_t numSrcCols = MVT::getNumCols (sourceMV.lclMV_);
506 const size_t numDestCols = MVT::getNumCols (
lclMV_);
508 const KMV src = sourceMV.lclMV_.offsetView (numSameIDs, numSrcCols, 0, 0);
509 KMV dest =
lclMV_.offsetViewNonConst (numSameIDs, numDestCols, 0, 0);
510 if (sourceMV.isConstantStride ()) {
511 MVT::Assign (dest, src);
514 MVT::Assign (dest, src, sourceMV.whichVectors_ ());
521 for (
size_t j = 0; j < numCols; ++j) {
523 const size_t srcCol = sourceMV.isConstantStride () ?
524 j : sourceMV.whichVectors_[j];
525 KMV dest_j =
lclMV_.offsetViewNonConst (numSameIDs, 1, 0, destCol);
526 const KMV src_j = sourceMV.lclMV_.offsetView (numSameIDs, 1, 0, srcCol);
527 MVT::Assign (dest_j, src_j);
534 for (
size_t j = 0; j < numCols; ++j) {
541 sourceMV.getSubArrayRCP (sourceMV.cview_, j) ();
544 if (! Node::isHostNode) {
548 std::copy (srcView.
begin (), srcView.
begin () + numSameIDs,
563 const size_type numPermuteLIDs =
564 std::min (permuteToLIDs.
size (), permuteFromLIDs.
size ());
565 for (size_type k = 0; k < numPermuteLIDs; ++k) {
566 dstView[permuteToLIDs[k]] = srcView[permuteFromLIDs[k]];
572 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
580 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
587 size_t& constantNumPackets,
597 const MV& sourceMV =
dynamic_cast<const MV&
> (sourceObj);
601 (void) numExportPacketsPerLID;
611 const size_t numCols = sourceMV.getNumVectors ();
612 const size_t stride = MVT::getStride (sourceMV.lclMV_);
616 constantNumPackets = numCols;
618 const size_type numExportLIDs = exportLIDs.
size ();
619 const size_type newExportsSize = numCols * numExportLIDs;
620 if (exports.
size () != newExportsSize) {
621 exports.
resize (newExportsSize);
628 if (sourceMV.isConstantStride ()) {
629 for (size_type k = 0; k < numExportLIDs; ++k) {
630 exports[k] = srcView[exportLIDs[k]];
634 const size_t offset = sourceMV.whichVectors_[0] * stride;
635 for (size_type k = 0; k < numExportLIDs; ++k) {
636 exports[k] = srcView[exportLIDs[k] + offset];
642 if (sourceMV.isConstantStride ()) {
643 for (size_type k = 0; k < numExportLIDs; ++k) {
644 const size_t localRow = as<size_t> (exportLIDs[k]);
645 for (
size_t j = 0; j < numCols; ++j) {
646 *expptr++ = srcView[localRow + j*stride];
652 for (size_type k = 0; k < numExportLIDs; ++k) {
653 const size_t localRow = as<size_t> (exportLIDs[k]);
654 for (
size_t j = 0; j < numCols; ++j) {
655 *expptr++ = srcView[localRow + srcWhichVectors[j]*stride];
663 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
669 size_t constantNumPackets,
677 const char tfecfFuncName[] =
"unpackAndCombine";
681 (void) numPacketsPerLID;
693 #ifdef HAVE_TPETRA_DEBUG 697 ": 'imports' buffer size must be consistent with the amount of data to " 698 "be sent. " << std::endl <<
"imports.size() = " << imports.
size()
699 <<
" != getNumVectors()*importLIDs.size() = " <<
getNumVectors() <<
"*" 704 as<size_t> (constantNumPackets) == as<size_t> (0), std::runtime_error,
705 ": constantNumPackets input argument must be nonzero.");
707 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
708 as<size_t> (numVecs) != as<size_t> (constantNumPackets),
709 std::runtime_error,
": constantNumPackets must equal numVecs.");
710 #endif // HAVE_TPETRA_DEBUG 712 if (numVecs > 0 && importLIDs.
size () > 0) {
715 const size_type numImportLIDs = importLIDs.
size ();
716 const size_t myStride = MVT::getStride (
lclMV_);
726 for (size_type k = 0; k < numImportLIDs; ++k) {
727 const size_t localRow = as<size_t> (importLIDs[k]);
728 for (
size_t j = 0; j < numVecs; ++j) {
729 destView[localRow + myStride*j] = *impptr++;
734 for (size_type k = 0; k < numImportLIDs; ++k) {
735 const size_t localRow = as<size_t> (importLIDs[k]);
736 for (
size_t j = 0; j < numVecs; ++j) {
742 else if (CM ==
ADD) {
744 for (size_type k = 0; k < numImportLIDs; ++k) {
745 const size_t localRow = as<size_t> (importLIDs[k]);
746 for (
size_t j = 0; j < numVecs; ++j) {
747 destView[localRow + myStride*j] += *impptr++;
752 for (size_type k = 0; k < numImportLIDs; ++k) {
753 const size_t localRow = as<size_t> (importLIDs[k]);
754 for (
size_t j = 0; j < numVecs; ++j) {
762 for (size_type k = 0; k < numImportLIDs; ++k) {
763 const size_t localRow = as<size_t> (importLIDs[k]);
764 for (
size_t j = 0; j < numVecs; ++j) {
765 Scalar &curval = destView[localRow + myStride*j];
766 const Scalar &newval = *impptr++;
767 curval = std::max( SCT::magnitude(curval), SCT::magnitude(newval) );
772 for (size_type k = 0; k < numImportLIDs; ++k) {
773 const size_t localRow = as<size_t> (importLIDs[k]);
774 for (
size_t j = 0; j < numVecs; ++j) {
775 Scalar &curval = destView[localRow + myStride*
whichVectors_[j]];
776 const Scalar &newval = *impptr++;
777 curval = std::max( SCT::magnitude(curval), SCT::magnitude(newval) );
783 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
785 std::invalid_argument,
": Invalid CombineMode: " << CM <<
". Valid " 786 "CombineMode values are ADD, REPLACE, INSERT, and ABSMAX.");
792 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
795 return MVT::getNumCols(
lclMV_);
803 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
812 using Teuchos::arcp_const_cast;
814 const char tfecfFuncName[] =
"dot()";
817 #ifdef HAVE_TPETRA_DEBUG 819 ": MultiVectors do not have compatible Maps:" << std::endl
820 <<
"this->getMap(): " << std::endl << *this->
getMap()
821 <<
"A.getMap(): " << std::endl << *A.
getMap() << std::endl);
824 ": MultiVectors do not have the same local length.");
827 ": MultiVectors must have the same number of vectors.");
829 ": dots.size() must be as large as the number of vectors in *this and A.");
837 for (
size_t j=0; j < numVecs; ++j) {
840 MVT::initializeValues(a,myLen, 1, avj, myLen);
841 MVT::initializeValues(v,myLen, 1, vj, myLen);
842 dots[j] = MVT::Dot((
const KMV&)v,(
const KMV &)a);
852 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
857 using Teuchos::arcp_const_cast;
863 using Teuchos::REDUCE_SUM;
871 "Tpetra::MultiVector::norm2(norms): norms.size() must be as large as the number of vectors in *this.");
873 MVT::Norm2Squared (
lclMV_,norms);
876 KMV v (MVT::getNode (
lclMV_));
878 for (
size_t i=0; i < numVecs; ++i) {
880 MVT::initializeValues (v, MVT::getNumRows (
lclMV_), 1, vi, MVT::getStride (
lclMV_));
881 norms[i] = MVT::Norm2Squared (v);
889 reduceAll (*this->
getMap ()->getComm (), REDUCE_SUM, as<int> (numVecs),
890 lnorms.
getRawPtr (), norms.getRawPtr ());
893 (*n) = STM::squareroot (*n);
898 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
904 using Teuchos::arcp_const_cast;
910 using Teuchos::REDUCE_SUM;
913 typedef typename SCT::magnitudeType Mag;
915 const char tfecfFuncName[] =
"normWeighted()";
925 ": MultiVector of weights must contain either one vector or the same number of vectors as this.");
927 #ifdef HAVE_TPETRA_DEBUG 929 ": MultiVectors do not have compatible Maps:" << std::endl
930 <<
"this->getMap(): " << std::endl << *this->
getMap()
931 <<
"weights.getMap(): " << std::endl << *weights.
getMap() << std::endl);
934 ": MultiVectors do not have the same local length.");
939 ": norms.size() must be as large as the number of vectors in *this.");
948 MVT::initializeValues (w,myLen, 1, wj, myLen);
949 for (
size_t j=0; j < numVecs; ++j) {
951 MVT::initializeValues(v,myLen, 1, vj, myLen);
954 MVT::initializeValues (w, myLen, 1, wj, myLen);
956 norms[j] = MVT::WeightedNorm ((
const KMV&)v, (
const KMV &)w);
961 reduceAll (*this->
getMap ()->getComm (), REDUCE_SUM, as<int>(numVecs),
962 lnorms.
getRawPtr (), norms.getRawPtr ());
970 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
977 using Teuchos::arcp_const_cast;
980 using Teuchos::REDUCE_SUM;
985 "Tpetra::MultiVector::norm1(norms): norms.size() must be as large as the number of vectors in *this.");
990 KMV v(MVT::getNode(
lclMV_));
992 for (
size_t j=0; j < numVecs; ++j) {
994 MVT::initializeValues (v, MVT::getNumRows(
lclMV_), 1, vj, MVT::getStride (
lclMV_));
995 norms[j] = MVT::Norm1 ((
const KMV&)v);
1000 reduceAll (*this->
getMap ()->getComm (), REDUCE_SUM, as<int> (numVecs), lnorms.
getRawPtr (), norms.getRawPtr ());
1005 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1012 using Teuchos::arcp_const_cast;
1015 using Teuchos::REDUCE_MAX;
1020 "Tpetra::MultiVector::normInf(norms): norms.size() must be as large as the number of vectors in *this.");
1022 MVT::NormInf(
lclMV_,norms);
1025 KMV v(MVT::getNode(
lclMV_));
1027 for (
size_t j=0; j < numVecs; ++j) {
1029 MVT::initializeValues(v,MVT::getNumRows(
lclMV_), 1, vj, MVT::getStride(
lclMV_));
1030 norms[j] = MVT::NormInf((
const KMV&)v);
1035 reduceAll (*this->
getMap ()->getComm (), REDUCE_MAX, as<int> (numVecs), lnorms.
getRawPtr (), norms.getRawPtr ());
1040 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1047 using Teuchos::arcp_const_cast;
1049 using Teuchos::arcp_const_cast;
1051 using Teuchos::REDUCE_SUM;
1057 "Tpetra::MultiVector::meanValue(): means.size() must be as large as the number of vectors in *this.");
1064 KMV v(MVT::getNode(
lclMV_));
1066 for (
size_t j=0; j < numVecs; ++j) {
1068 MVT::initializeValues(v,myLen, 1, vj, myLen);
1069 means[j] = MVT::Sum((
const KMV &)v);
1075 reduceAll (*this->
getMap ()->getComm (), REDUCE_SUM, as<int> (numVecs),
1081 const Scalar OneOverN =
1084 i != means.
begin() + numVecs;
1087 (*i) = (*i) * OneOverN;
1092 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1102 KMV v (MVT::getNode (
lclMV_));
1104 for (
size_t j = 0; j < numVecs; ++j) {
1106 MVT::initializeValues (v, MVT::getNumRows (
lclMV_), 1, vj, MVT::getStride (
lclMV_));
1113 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1123 KMV v(MVT::getNode(
lclMV_));
1125 for (
size_t j=0; j < numVecs; ++j) {
1127 MVT::initializeValues(v,MVT::getNumRows(
lclMV_), 1, vj, MVT::getStride(
lclMV_));
1134 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1149 "Tpetra::MultiVector::replaceMap: This method does not currently work " 1150 "if the MultiVector is a column view of another MultiVector (that is, if " 1151 "isConstantStride() == false).");
1181 #ifdef HAVE_TEUCHOS_DEBUG 1195 #endif // HAVE_TEUCHOS_DEBUG 1199 newMap.is_null (), std::invalid_argument,
1200 "Tpetra::MultiVector::replaceMap: both current and new Maps are null. " 1201 "This probably means that the input Map is incorrect.");
1203 const size_t newNumRows = newMap->getNodeNumElements ();
1204 const size_t origNumRows =
lclMV_.getNumRows ();
1207 if (origNumRows != newNumRows) {
1210 node->template allocBuffer<Scalar> (newNumRows * numCols);
1211 const size_t stride = newNumRows;
1212 MVT::initializeValues (
lclMV_, newNumRows, numCols, data, stride);
1213 if (newNumRows > 0) {
1218 else if (newMap.is_null ()) {
1222 MVT::initializeValues (
lclMV_, 0, numVecs, Teuchos::null, 0);
1224 this->
map_ = newMap;
1228 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1233 using Teuchos::arcp_const_cast;
1244 MVT::Scale(
lclMV_,alpha);
1247 KMV v(MVT::getNode(
lclMV_));
1249 for (
size_t j=0; j < numVecs; ++j) {
1251 MVT::initializeValues (v, MVT::getNumRows (
lclMV_), 1, vj, MVT::getStride (
lclMV_));
1252 MVT::Scale (v, alpha);
1258 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1263 using Teuchos::arcp_const_cast;
1269 "Tpetra::MultiVector::scale(alphas): alphas.size() must be as large as the number of vectors in *this.");
1270 KMV vec(MVT::getNode(
lclMV_));
1271 const size_t myLen = MVT::getNumRows(
lclMV_);
1272 if (myLen == 0)
return;
1274 for (
size_t j = 0; j < numVecs; ++j) {
1280 MVT::initializeValues(vec,myLen,1,mybufj,myLen);
1281 MVT::Scale(vec,alphas[j]);
1287 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1292 using Teuchos::arcp_const_cast;
1296 const char tfecfFuncName[] =
"scale(alpha,A)";
1300 #ifdef HAVE_TPETRA_DEBUG 1302 std::runtime_error,
": MultiVectors do not have compatible Maps:" << std::endl
1303 <<
"this->getMap(): " << std::endl << *(this->
getMap ())
1304 <<
"A.getMap(): " << std::endl << *(A.
getMap ()) << std::endl);
1307 ": MultiVectors do not have the same local length.");
1310 ": MultiVectors must have the same number of vectors.");
1319 for (
size_t j=0; j < numVecs; ++j) {
1322 MVT::initializeValues (a,myLen, 1, avj, myLen);
1323 MVT::initializeValues (v,myLen, 1, vj, myLen);
1324 MVT::Scale (v, alpha, (
const KMV &)a);
1330 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1335 using Teuchos::arcp_const_cast;
1339 const char tfecfFuncName[] =
"reciprocal()";
1341 #ifdef HAVE_TPETRA_DEBUG 1343 ": MultiVectors do not have compatible Maps:" << std::endl
1344 <<
"this->getMap(): " << std::endl << *this->
getMap()
1345 <<
"A.getMap(): " << std::endl << *A.
getMap() << std::endl);
1348 ": MultiVectors do not have the same local length.");
1351 ": MultiVectors must have the same number of vectors.");
1361 avptr = arcp_const_cast<Scalar>(MVT::getValues(A.
lclMV_));
1362 for (
size_t j=0; j < numVecs; ++j) {
1365 MVT::initializeValues(a,myLen, 1, avj, myLen);
1366 MVT::initializeValues(v,myLen, 1, vj, myLen);
1367 MVT::Recip(v,(
const KMV &)a);
1371 catch (std::runtime_error &e) {
1373 ": caught exception from Kokkos:" << std::endl
1374 << e.what() << std::endl);
1379 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1381 using Teuchos::arcp_const_cast;
1385 const char tfecfFuncName[] =
"abs()";
1386 #ifdef HAVE_TPETRA_DEBUG 1388 ": MultiVectors do not have compatible Maps:" << std::endl
1389 <<
"this->getMap(): " << std::endl << *this->
getMap()
1390 <<
"A.getMap(): " << std::endl << *A.
getMap() << std::endl);
1393 ": MultiVectors do not have the same local length.");
1396 ": MultiVectors must have the same number of vectors.");
1405 avptr = arcp_const_cast<Scalar>(MVT::getValues(A.
lclMV_));
1406 for (
size_t j=0; j < numVecs; ++j) {
1409 MVT::initializeValues(a,myLen, 1, avj, myLen);
1410 MVT::initializeValues(v,myLen, 1, vj, myLen);
1411 MVT::Abs(v,(
const KMV &)a);
1417 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1422 using Teuchos::arcp_const_cast;
1426 const char tfecfFuncName[] =
"update()";
1430 #ifdef HAVE_TPETRA_DEBUG 1432 ": MultiVectors do not have compatible Maps:" << std::endl
1433 <<
"this->getMap(): " << std::endl << this->
getMap()
1434 <<
"A.getMap(): " << std::endl << *A.
getMap() << std::endl);
1437 ": MultiVectors do not have the same local length.");
1442 ": MultiVectors must have the same number of vectors.");
1449 avptr = arcp_const_cast<Scalar>(MVT::getValues(A.
lclMV_));
1450 for (
size_t j=0; j < numVecs; ++j) {
1453 MVT::initializeValues(a,myLen, 1, avj, myLen);
1454 MVT::initializeValues(v,myLen, 1, vj, myLen);
1455 MVT::GESUM(v,alpha,(
const KMV &)a,beta);
1461 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1465 const Scalar &gamma)
1467 using Teuchos::arcp_const_cast;
1471 const char tfecfFuncName[] =
"update()";
1475 #ifdef HAVE_TPETRA_DEBUG 1478 ": MultiVectors do not have compatible Maps:" << std::endl
1479 <<
"this->getMap(): " << std::endl << *this->
getMap()
1480 <<
"A.getMap(): " << std::endl << *A.
getMap() << std::endl
1481 <<
"B.getMap(): " << std::endl << *B.
getMap() << std::endl);
1484 ": MultiVectors do not have the same local length.");
1487 ": MultiVectors must have the same number of vectors.");
1496 avptr = arcp_const_cast<Scalar>(MVT::getValues(A.
lclMV_)),
1497 bvptr = arcp_const_cast<Scalar>(MVT::getValues(B.
lclMV_));
1498 for (
size_t j=0; j < numVecs; ++j) {
1502 MVT::initializeValues(b,myLen, 1, bvj, myLen);
1503 MVT::initializeValues(a,myLen, 1, avj, myLen);
1504 MVT::initializeValues(v,myLen, 1, vj, myLen);
1505 MVT::GESUM(v,alpha,(
const KMV&)a,beta,(
const KMV&)b,gamma);
1511 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1517 KOKKOS_NODE_TRACE(
"MultiVector::getData()")
1522 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1528 KOKKOS_NODE_TRACE(
"MultiVector::getDataNonConst()")
1533 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1538 const char tfecfFuncName[] =
"operator=()";
1540 if (
this != &source) {
1541 #ifdef HAVE_TPETRA_DEBUG 1543 ": MultiVectors do not have compatible Maps:" << std::endl
1544 <<
"this->getMap(): " << std::endl << *this->
getMap()
1545 <<
"source.getMap(): " << std::endl << *source.
getMap() << std::endl);
1548 ": MultiVectors do not have the same local length.");
1551 ": MultiVectors must have the same number of vectors.");
1557 KOKKOS_NODE_TRACE(
"MultiVector::operator=()")
1558 node->template copyBuffers<Scalar>(
getLocalLength()*numVecs, MVT::getValues(source.
lclMV_), MVT::getValuesNonConst(
lclMV_) );
1562 for (
size_t j=0; j < numVecs; ++j) {
1563 KOKKOS_NODE_TRACE(
"MultiVector::operator=()")
1573 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1582 "Tpetra::MultiVector::subCopy(cols): cols must contain at least one column.");
1583 size_t numCopyVecs = cols.
size();
1584 const bool zeroData =
false;
1590 for (
size_t j=0; j<numCopyVecs; ++j) {
1591 KOKKOS_NODE_TRACE(
"MultiVector::subCopy()")
1594 MVT::getValuesNonConst (mv->lclMV_, j));
1600 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1609 "Tpetra::MultiVector::subCopy(Range1D): range must include at least one vector.");
1610 size_t numCopyVecs = colRng.
size();
1611 const bool zeroData =
false;
1617 for (
size_t js=colRng.
lbound(), jd=0; jd<numCopyVecs; ++jd, ++js) {
1618 KOKKOS_NODE_TRACE(
"MultiVector::subCopy()")
1621 MVT::getValuesNonConst (mv->lclMV_, jd));
1627 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1631 size_t offset)
const 1637 const size_t newNumRows = subMap->getNodeNumElements();
1638 const bool tooManyElts = newNumRows + offset >
lclMV_.getOrigNumRows ();
1640 const int myRank = this->
getMap ()->getComm ()->getRank ();
1642 newNumRows + offset > MVT::getNumRows (
lclMV_),
1644 "Tpetra::MultiVector::offsetView: Invalid input Map. Input Map owns " 1645 << subMap->getNodeNumElements() <<
" elements on process " << myRank
1646 <<
". offset = " << offset <<
". Yet, the MultiVector contains only " 1647 <<
lclMV_.getOrigNumRows () <<
" on this process.");
1651 Kokkos::MultiVector<Scalar, Node> newLocalMV =
1652 lclMV_.offsetView (newNumRows,
lclMV_.getNumCols (), offset, 0);
1653 constViewMV =
rcp (
new MV (subMap, newLocalMV, COMPUTE_VIEW_CONSTRUCTOR));
1658 Kokkos::MultiVector<Scalar, Node> newLocalMV =
1659 lclMV_.offsetView (newNumRows, maxCol+1, offset, 0);
1660 constViewMV =
rcp (
new MV (subMap, newLocalMV,
whichVectors_, COMPUTE_VIEW_CONSTRUCTOR));
1666 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1676 const size_t newNumRows = subMap->getNodeNumElements();
1677 const bool tooManyElts = newNumRows + offset >
lclMV_.getOrigNumRows ();
1679 const int myRank = this->
getMap ()->getComm ()->getRank ();
1681 newNumRows + offset > MVT::getNumRows (
lclMV_),
1683 "Tpetra::MultiVector::offsetViewNonconst: Invalid input Map. Input Map owns " 1684 << subMap->getNodeNumElements() <<
" elements on process " << myRank
1685 <<
". offset = " << offset <<
". Yet, the MultiVector contains only " 1686 <<
lclMV_.getOrigNumRows () <<
" on this process.");
1690 Kokkos::MultiVector<Scalar, Node> newLocalMV =
1691 lclMV_.offsetViewNonConst (newNumRows,
lclMV_.getNumCols (), offset, 0);
1692 subViewMV =
rcp (
new MV (subMap, newLocalMV, COMPUTE_VIEW_CONSTRUCTOR));
1697 Kokkos::MultiVector<Scalar, Node> newLocalMV =
1698 lclMV_.offsetViewNonConst (newNumRows, maxCol+1, offset, 0);
1699 subViewMV =
rcp (
new MV (subMap, newLocalMV,
whichVectors_, COMPUTE_VIEW_CONSTRUCTOR));
1705 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1710 using Teuchos::arcp_const_cast;
1715 using Teuchos::rcp_const_cast;
1719 "Tpetra::MultiVector::subView(ArrayView): range must include at least one vector.");
1724 const size_t myStride = MVT::getStride(
lclMV_),
1725 myLen = MVT::getNumRows(
lclMV_),
1726 numViewCols = cols.
size();
1736 for (
size_t j=0; j < numViewCols; ++j) {
1737 newCols[j] = cols[j];
1738 if (newCols[j] < minInd) minInd = newCols[j];
1739 if (maxInd < newCols[j]) maxInd = newCols[j];
1743 for (
size_t j=0; j < numViewCols; ++j) {
1745 if (newCols[j] < minInd) minInd = newCols[j];
1746 if (maxInd < newCols[j]) maxInd = newCols[j];
1750 for (
size_t j=0; j < numViewCols; ++j) {
1751 newCols[j] -= minInd;
1754 return rcp_const_cast<
const MV> (
rcp (
new MV (this->
getMap (), minbuf, myStride, newCols (), COMPUTE_VIEW_CONSTRUCTOR)));
1758 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1763 using Teuchos::arcp_const_cast;
1771 "Tpetra::MultiVector::subView(Range1D): range must include at least one vector.");
1772 size_t numViewVecs = colRng.
size();
1784 return rcp (
new MV (this->
getMap (), subdata, MVT::getStride (
lclMV_), numViewVecs, COMPUTE_VIEW_CONSTRUCTOR));
1788 return rcp (
new MV (this->
getMap (), ncbuf, MVT::getStride (
lclMV_), whchvecs, COMPUTE_VIEW_CONSTRUCTOR));
1792 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1798 using Teuchos::arcp_const_cast;
1806 "Tpetra::MultiVector::subViewNonConst(ArrayView): range must include at least one vector.");
1808 return rcp (
new MV (this->
getMap (), MVT::getValuesNonConst (
lclMV_), MVT::getStride (
lclMV_), cols, COMPUTE_VIEW_CONSTRUCTOR));
1812 for (
size_t j = 0; j < as<size_t> (cols.
size ()); ++j) {
1815 return rcp (
new MV (this->
getMap (), MVT::getValuesNonConst (
lclMV_), MVT::getStride (
lclMV_), newcols (), COMPUTE_VIEW_CONSTRUCTOR));
1819 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1825 using Teuchos::arcp_const_cast;
1833 "Tpetra::MultiVector::subViewNonConst(Range1D): range must include at least one vector.");
1834 size_t numViewVecs = colRng.
size();
1838 const size_t stride = MVT::getStride(
lclMV_);
1842 return rcp (
new MV (this->
getMap (), subdata, stride, numViewVecs, COMPUTE_VIEW_CONSTRUCTOR));
1846 const size_t stride = MVT::getStride(
lclMV_);
1848 return rcp (
new MV (this->
getMap (), data, stride, whchvecs, COMPUTE_VIEW_CONSTRUCTOR));
1852 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1857 using Teuchos::arcp_const_cast;
1860 using Teuchos::rcp_const_cast;
1863 #ifdef HAVE_TPETRA_DEBUG 1865 "Tpetra::MultiVector::getVector(j): index j (== " << j <<
") exceeds valid column range for this multivector.");
1872 ncbuff = arcp_const_cast<Scalar>(cbuff);
1874 return rcp_const_cast<
const V> (
rcp (
new V (this->
getMap (), ncbuff, COMPUTE_VIEW_CONSTRUCTOR)));
1878 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1886 #ifdef HAVE_TPETRA_DEBUG 1888 "Tpetra::MultiVector::getVectorNonConst(j): index j (== " << j <<
") exceeds valid column range for this multivector.");
1894 return rcp (
new V (this->
getMap (), ncbuff, COMPUTE_VIEW_CONSTRUCTOR));
1898 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1908 const char tfecfFuncName[] =
"get1dCopy(A,LDA)";
1910 ": specified stride is not large enough for local vector length.");
1912 ": specified stride/storage is not large enough for the number of vectors.");
1914 const size_t myStride = MVT::getStride(
lclMV_),
1919 KOKKOS_NODE_TRACE(
"MultiVector::getVectorNonConst()")
1922 for (
size_t j=0; j<numCols; j++) {
1924 std::copy(myviewj,myviewj+myLen,Aptr);
1927 myview = Teuchos::null;
1928 mydata = Teuchos::null;
1933 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1944 const char tfecfFuncName[] =
"get2dCopy(ArrayOfPtrs)";
1946 ": Array of pointers must contain as many pointers as the MultiVector has rows.");
1952 KOKKOS_NODE_TRACE(
"MultiVector::get2dCopy()")
1954 for (
size_t j=0; j<numCols; ++j) {
1955 #ifdef HAVE_TPETRA_DEBUG 1957 ": The ArrayView provided in ArrayOfPtrs[" << j <<
"] was not large enough to contain the local entries.");
1960 std::copy(myviewj,myviewj+myLen,ArrayOfPtrs[j].begin());
1962 myview = Teuchos::null;
1963 mybuff = Teuchos::null;
1968 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1973 "Tpetra::MultiVector::get1dView() requires that this MultiVector have constant stride.");
1975 KOKKOS_NODE_TRACE(
"MultiVector::get1dView()")
1980 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1985 "Tpetra::MultiVector::get1dViewNonConst(): requires that this MultiVector have constant stride.");
1987 KOKKOS_NODE_TRACE(
"MultiVector::get1dViewNonConst()")
1992 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1996 using Teuchos::arcp;
2003 const size_t myStride = MVT::getStride(
lclMV_),
2007 KOKKOS_NODE_TRACE(
"MultiVector::get2dViewNonConst()")
2008 ArrayRCP<Scalar> myview = node->template viewBufferNonConst<Scalar>(Kokkos::ReadWrite,myStride*(numCols-1)+myLen,MVT::getValuesNonConst(
lclMV_));
2009 for (
size_t j=0; j<numCols; ++j) {
2016 const size_t myStride = MVT::getStride(
lclMV_),
2017 numCols = MVT::getNumCols(
lclMV_),
2019 myLen = MVT::getNumRows(
lclMV_);
2021 KOKKOS_NODE_TRACE(
"MultiVector::get2dViewNonConst()")
2022 ArrayRCP<Scalar> myview = node->template viewBufferNonConst<Scalar>(Kokkos::ReadWrite,myStride*(numCols-1)+myLen,MVT::getValuesNonConst(
lclMV_));
2023 for (
size_t j=0; j<myCols; ++j) {
2032 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2036 using Teuchos::arcp;
2043 const size_t myStride = MVT::getStride(
lclMV_),
2047 KOKKOS_NODE_TRACE(
"MultiVector::get2dView()")
2049 for (
size_t j=0; j<numCols; ++j) {
2056 const size_t myStride = MVT::getStride(
lclMV_),
2057 numCols = MVT::getNumCols(
lclMV_),
2059 myLen = MVT::getNumRows(
lclMV_);
2061 KOKKOS_NODE_TRACE(
"MultiVector::get2dView()")
2063 for (
size_t j=0; j<myCols; ++j) {
2072 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2077 const Scalar &alpha,
2085 using Teuchos::null;
2116 const char errPrefix[] =
"Tpetra::MultiVector::multiply(transOpA,transOpB,alpha,A,B,beta): ";
2119 errPrefix <<
"non-conjugate transpose not supported for complex types.");
2129 Scalar beta_local = beta;
2132 errPrefix <<
"dimension of *this, op(A) and op(B) must be consistent.");
2137 bool Case1 = ( C_is_local && A_is_local && B_is_local);
2138 bool Case2 = ( C_is_local && !A_is_local && !B_is_local && transA==
CONJ_TRANS && transB==
NO_TRANS);
2139 bool Case3 = (!C_is_local && !A_is_local && B_is_local && transA==
NO_TRANS );
2143 errPrefix <<
"multiplication of op(A) and op(B) into *this is not a supported use case.");
2151 int MyPID = this->
getMap()->getComm()->getRank();
2159 else Ctmp =
rcp(
this,
false);
2162 else Atmp =
rcp(&A,
false);
2165 else Btmp =
rcp(&B,
false);
2167 #ifdef HAVE_TEUCHOS_DEBUG 2168 TEUCHOS_TEST_FOR_EXCEPTION(!Ctmp->isConstantStride() || !Btmp->isConstantStride() || !Atmp->isConstantStride(), std::logic_error,
2169 errPrefix <<
"failed making temporary strided copies of input multivectors.");
2172 KMV &C_mv = Ctmp->lclMV_;
2175 const KMV &A_mv = Atmp->lclMV_;
2176 const KMV &B_mv = Btmp->lclMV_;
2178 MVT::GEMM(C_mv,transA,transB,alpha,A_mv,B_mv,beta_local);
2190 const size_t numVecs = MVT::getNumCols(
lclMV_);
2191 for (
size_t j=0; j < numVecs; ++j) {
2192 KOKKOS_NODE_TRACE(
"MultiVector::multiply()")
2203 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2211 using Teuchos::arcp_const_cast;
2212 const char tfecfFuncName[] =
"elementWiseMultiply()";
2214 #ifdef HAVE_TPETRA_DEBUG 2217 ! this->
getMap()->isCompatible(*B.
getMap()), std::runtime_error,
2218 ": MultiVectors do not have compatible Maps:" << std::endl
2219 <<
"this->getMap(): " << std::endl << *this->
getMap()
2220 <<
"A.getMap(): " << std::endl << *A.
getMap() << std::endl
2221 <<
"B.getMap(): " << std::endl << *B.
getMap() << std::endl);
2226 ": MultiVectors do not have the same local length.");
2230 ": MultiVectors 'this' and B must have the same number of vectors.");
2232 MVT::ElemMult (
lclMV_, scalarThis, scalarAB, (
const KMV&) A.
lclMV_,
2235 catch (std::runtime_error &e) {
2237 ": caught exception from Kokkos:" << std::endl
2238 << e.what() << std::endl);
2242 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2252 using Teuchos::REDUCE_SUM;
2257 "Tpetra::MultiVector::reduce() should only be called with locally " 2258 "replicated or otherwise not distributed MultiVector objects.");
2260 if (comm->getSize() == 1)
return;
2267 const size_t myStride = MVT::getStride(
lclMV_),
2268 numCols = MVT::getNumCols(
lclMV_),
2269 myLen = MVT::getNumRows(
lclMV_);
2272 KOKKOS_NODE_TRACE(
"MultiVector::reduce()")
2274 Kokkos::ReadWrite,myStride*(numCols-1)+myLen,
2275 MVT::getValuesNonConst(
lclMV_) );
2278 target = bufView(0,myLen*numCols);
2279 std::copy(target.
begin(),target.
end(),sourceBuffer.begin());
2283 tmparr.
resize(myLen*numCols);
2284 Scalar *sptr = sourceBuffer.getRawPtr();
2286 for (
size_t j=0; j<numCols; ++j) {
2287 std::copy(vptr,vptr+myLen,sptr);
2294 reduceAll<int,Scalar> (*comm, REDUCE_SUM, as<int> (numCols*myLen),
2298 const Scalar *sptr = tmparr.
getRawPtr();
2300 for (
size_t j=0; j<numCols; ++j) {
2301 std::copy (sptr, sptr+myLen, vptr);
2306 bufView = Teuchos::null;
2310 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2315 const Scalar &ScalarValue)
2317 #ifdef HAVE_TPETRA_DEBUG 2318 const LocalOrdinal minLocalIndex = this->
getMap()->getMinLocalIndex();
2319 const LocalOrdinal maxLocalIndex = this->
getMap()->getMaxLocalIndex();
2321 MyRow < minLocalIndex || MyRow > maxLocalIndex,
2323 "Tpetra::MultiVector::replaceLocalValue: row index " << MyRow
2324 <<
" is invalid. The range of valid row indices on this process " 2325 << this->
getMap()->getComm()->getRank() <<
" is [" << minLocalIndex
2326 <<
", " << maxLocalIndex <<
"].");
2328 vectorIndexOutOfRange(VectorIndex),
2330 "Tpetra::MultiVector::replaceLocalValue: vector index " << VectorIndex
2331 <<
" of the multivector is invalid.");
2335 lclMV_.replaceLocalValue (Teuchos::as<size_t> (MyRow), colInd, ScalarValue);
2339 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2344 const Scalar &ScalarValue)
2346 #ifdef HAVE_TPETRA_DEBUG 2347 const LocalOrdinal minLocalIndex = this->
getMap()->getMinLocalIndex();
2348 const LocalOrdinal maxLocalIndex = this->
getMap()->getMaxLocalIndex();
2350 MyRow < minLocalIndex || MyRow > maxLocalIndex,
2352 "Tpetra::MultiVector::sumIntoLocalValue: row index " << MyRow
2353 <<
" is invalid. The range of valid row indices on this process " 2354 << this->
getMap()->getComm()->getRank() <<
" is [" << minLocalIndex
2355 <<
", " << maxLocalIndex <<
"].");
2357 vectorIndexOutOfRange(VectorIndex),
2359 "Tpetra::MultiVector::sumIntoLocalValue: vector index " << VectorIndex
2360 <<
" of the multivector is invalid.");
2364 lclMV_.sumIntoLocalValue (Teuchos::as<size_t> (MyRow), colInd, ScalarValue);
2368 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2373 const Scalar &ScalarValue)
2375 LocalOrdinal MyRow = this->
getMap()->getLocalElement(GlobalRow);
2376 #ifdef HAVE_TPETRA_DEBUG 2380 "Tpetra::MultiVector::replaceGlobalValue: global row index " << GlobalRow
2381 <<
"is not present on this process " << this->
getMap()->getComm()->getRank()
2384 vectorIndexOutOfRange(VectorIndex),
2386 "Tpetra::MultiVector::replaceGlobalValue: vector index " << VectorIndex
2387 <<
" of the multivector is invalid.");
2392 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2397 const Scalar &ScalarValue)
2399 LocalOrdinal MyRow = this->
getMap()->getLocalElement(GlobalRow);
2400 #ifdef HAVE_TEUCHOS_DEBUG 2404 "Tpetra::MultiVector::sumIntoGlobalValue: global row index " << GlobalRow
2405 <<
"is not present on this process " << this->
getMap()->getComm()->getRank()
2408 vectorIndexOutOfRange(VectorIndex),
2410 "Tpetra::MultiVector::sumIntoGlobalValue: vector index " << VectorIndex
2411 <<
" of the multivector is invalid.");
2416 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2423 const size_t stride = MVT::getStride (
lclMV_);
2435 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2436 const Kokkos::MultiVector<Scalar,Node>&
2441 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2442 Kokkos::MultiVector<Scalar,Node>&
2447 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2452 std::ostringstream oss;
2459 oss <<
" columnStride: " <<
getStride () << endl;
2465 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2487 const int myImageID = comm->getRank();
2488 const int numImages = comm->getSize();
2494 if (myImageID == 0) {
2497 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2498 if (myImageID == imageCtr) {
2501 out <<
"Process " << myImageID <<
":" << endl;
2509 out <<
", constant stride=" <<
getStride() << endl;
2512 out <<
", not constant stride" << endl;
2516 out <<
"Values:" << endl;
2539 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2546 "::createViews(): The const view " 2547 "has already been created and is therefore not null. (For" 2550 "means that MultiVector is either creating a view unnecessarily, or " 2551 "hanging on to a view beyond its needed scope (since releaseViews() " 2552 "should always release both the const and nonconst views). This probably " 2553 "does not affect correctness, it but does affect total memory use. " 2554 "We will only report this warning once per (Multi)Vector instance. " 2555 "Please report this performance bug to the Tpetra developers.");
2562 KOKKOS_NODE_TRACE(
"MultiVector::createViews()")
2563 cview_ = node->template viewBuffer<Scalar> (buff.
size (), buff);
2567 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2574 "::createViewsNonConst(): The nonconst view " 2575 "has already been created and is therefore not null. (For" 2577 <<
". This means that MultiVector is either creating a view " 2578 "unnecessarily, or hanging on to a view beyond its needed scope (since " 2579 "releaseViews() should always release both the const and nonconst " 2580 "views). This probably does not affect correctness, it but does affect " 2581 "total memory use. " 2582 "Please report this performance bug to the Tpetra developers.");
2589 KOKKOS_NODE_TRACE(
"MultiVector::createViewsNonConst()")
2590 ncview_ = node->template viewBufferNonConst<Scalar> (rwo, buff.
size (), buff);
2594 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2603 (void) constViewCount;
2604 (void) nonconstViewCount;
2606 const bool viewWontGetReleased = constViewCount > 1 || nonconstViewCount > 1;
2608 const bool both = constViewCount > 1 && nonconstViewCount > 1;
2609 const char*
const text = both ?
"Both the const view and the nonconst view have" :
2610 ((constViewCount > 1) ?
"The const view has" :
"The nonconst view has");
2616 "::releaseViews(): " << text <<
" a reference count greater than 1. " 2617 "For Tpetra developers: cview_.total_count() = " << constViewCount
2618 <<
" and ncview_.total_count() = " << nonconstViewCount <<
". This " 2619 "means that releaseViews() won't actually free memory. This probably " 2620 "does not affect correctness, it but does affect total memory use. " 2621 "We will only report this warning once per (Multi)Vector instance. " 2622 "Please report this performance bug to the Tpetra developers.");
2632 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2648 #define TPETRA_MULTIVECTOR_INSTANT(SCALAR,LO,GO,NODE) \ 2650 template class MultiVector< SCALAR , LO , GO , NODE >; \ 2653 #endif // TPETRA_MULTIVECTOR_DEF_HPP Teuchos::RCP< const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subView(const Teuchos::Range1D &colRng) const
Return a const MultiVector with const views of selected columns.
Teuchos::RCP< const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > offsetView(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &subMap, size_t offset) const
Return a const MultiVector view of a subset of rows.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
ArrayRCP< Scalar > ncview_
Nonconst host view created in createViewsNonConst().
void releaseViews() const
Hook for releasing views.
virtual std::string getObjectLabel() const
void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
bool is_null(const boost::shared_ptr< T > &p)
ArrayRCP< T > persistingView(size_type lowerOffset, size_type size) const
Teuchos::ArrayRCP< Scalar > get1dViewNonConst()
Nonconst persisting (1-D) view of this multivector's local values.
void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using global (row) index.
void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
size_t getNumVectors() const
Number of columns in the multivector.
size_t getLocalLength() const
Local number of rows on the calling process.
void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Replace value, using local (row) index.
#define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg)
Teuchos::ArrayRCP< Teuchos::ArrayRCP< Scalar > > get2dViewNonConst()
Return non-const persisting pointers to values.
void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Replace value, using global (row) index.
bool isConstantStride() const
Whether this multivector has constant stride between columns.
One or more distributed dense vectors.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subCopy(const Teuchos::Range1D &colRng) const
Return a MultiVector with copies of selected columns.
bool createViewsNonConstRaisedEfficiencyWarning_
Whether createViewsNonConst() has yet raised an efficiency warning.
bool isDistributed() const
Whether this is a globally distributed object.
void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
Replace the underlying Map in place.
virtual ~MultiVector()
Destructor (virtual for memory safety of derived classes).
void get1dCopy(Teuchos::ArrayView< Scalar > A, size_t LDA) const
Fill the given array with a copy of this multivector's local values.
void get2dCopy(Teuchos::ArrayView< const Teuchos::ArrayView< Scalar > > ArrayOfPtrs) const
Fill the given array with a copy of this multivector's local values.
void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using local (row) index.
Teuchos::RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(size_t j)
Return a Vector which is a nonconst view of column j.
bool createViewsRaisedEfficiencyWarning_
Whether createViews() has yet raised an efficiency warning.
void createViewsNonConst(Kokkos::ReadWriteOption rwo)
Hook for creating a nonconst view.
virtual void copyAndPermute(const SrcDistObject &sourceObj, size_t numSameIDs, const ArrayView< const LocalOrdinal > &permuteToLIDs, const ArrayView< const LocalOrdinal > &permuteFromLIDs)
Perform copies and permutations that are local to this process.
Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
Teuchos::RCP< const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVector(size_t j) const
Return a Vector which is a const view of column j.
size_t global_size_t
Global size_t object.
void normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute Inf-norm of each vector in multi-vector.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void scale(const Scalar &alpha)
Scale in place: this = alpha*this.
void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &beta)
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)
Update: this = beta*this + alpha*A.
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.
ArrayRCP< T > getSubArrayRCP(ArrayRCP< T > arr, size_t j) const
Persisting view of j-th column in the given ArrayRCP.
void norm1(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
void normWeighted(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &weights, const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Tpetra::Combine Mode enumerable type.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getMap() const
The Map describing the parallel distribution of this object.
bool releaseViewsRaisedEfficiencyWarning_
Whether releaseViews() has yet raised an efficiency warning.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > subViewNonConst(const Teuchos::Range1D &colRng)
Return a MultiVector with views of selected columns.
virtual size_t constantNumberOfPackets() const
Number of packets to send per LID.
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
ArrayRCP< const Scalar > cview_
Const host view created in createViews().
void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< Scalar > &dots) const
Compute dot product of each corresponding pair of vectors, dots[i] = this[i].dot(A[i]) ...
Abstract base class for objects that can be the source of an Import or Export operation.
Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
void resize(size_type new_size, const value_type &x=value_type())
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source)
Assign the contents of source to this multivector (deep copy).
#define TPETRA_EFFICIENCY_WARNING(throw_exception_test, Exception, msg)
Print or throw an efficency warning.
void randomize()
Set all values in the multivector to pseudorandom numbers.
virtual void unpackAndCombine(const ArrayView< const LocalOrdinal > &importLIDs, const ArrayView< const Scalar > &imports, const ArrayView< size_t > &numPacketsPerLID, size_t constantNumPackets, Distributor &distor, CombineMode CM)
Perform any unpacking and combining after communication.
const Kokkos::MultiVector< Scalar, Node > & getLocalMV() const
Return a const reference to the underlying Kokkos::MultiVector object (advanced use only) ...
KMV lclMV_
The Kokkos::MultiVector containing the compute buffer of data.
Describes a parallel distribution of objects over processes.
void meanValue(const Teuchos::ArrayView< Scalar > &means) const
Compute mean (average) value of each vector in multi-vector. The outcome of this routine is undefined...
TypeTo as(const TypeFrom &t)
size_t getStride() const
Stride between columns in the multivector.
MultiVector(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Basic constuctor.
A distributed dense vector.
Stand-alone utility functions and macros.
virtual std::string description() const
A simple one-line description of this object.
void reduce()
Sum values of a locally replicated multivector across all processes.
virtual bool checkSizes(const SrcDistObject &sourceObj)
Whether data redistribution between sourceObj and this object is legal.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > offsetViewNonConst(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &subMap, size_t offset)
Return a non-const MultiVector view of a subset of rows.
Teuchos::ArrayRCP< Teuchos::ArrayRCP< const Scalar > > get2dView() const
Return const persisting pointers to values.
void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,j).
Base class for distributed Tpetra objects that support data redistribution.
Array< size_t > whichVectors_
Indices of columns this multivector is viewing.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this)
Teuchos::ArrayRCP< const Scalar > get1dView() const
Const persisting (1-D) view of this multivector's local values.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
std::string typeName(const T &t)
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > map_
The Map over which this object is distributed.
Kokkos::MultiVector< Scalar, Node > & getLocalMVNonConst()
Return a non-const reference to the underlying Kokkos::MultiVector object (advanced use only) ...
virtual void packAndPrepare(const SrcDistObject &sourceObj, const ArrayView< const LocalOrdinal > &exportLIDs, Array< Scalar > &exports, const ArrayView< size_t > &numExportPacketsPerLID, size_t &constantNumPackets, Distributor &distor)
Perform any packing or preparation required for communication.
void createViews() const
Hook for creating a const view.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
Remove processes owning zero rows from the Map and their communicator.