42 #ifndef TPETRA_VECTOR_DEF_HPP
43 #define TPETRA_VECTOR_DEF_HPP
45 #include <Kokkos_DefaultArithmetic.hpp>
46 #include <Kokkos_NodeTrace.hpp>
47 #include <Tpetra_MultiVector.hpp>
49 #ifdef DOXYGEN_USE_ONLY
50 #include "Tpetra_Vector_decl.hpp"
55 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
57 :
MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(map,1,zeroOut) {
60 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
62 :
MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(source) {
65 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 const ArrayRCP<Scalar> &view, EPrivateHostViewConstructor )
69 :
MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(map,view,view.size(),1,HOST_VIEW_CONSTRUCTOR) {
72 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
75 const ArrayRCP<Scalar> &view, EPrivateComputeViewConstructor )
76 :
MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(map,view,view.size(),1,COMPUTE_VIEW_CONSTRUCTOR) {
79 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
81 :
MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(map,values,values.size(),1) {
84 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
87 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
92 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
97 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
102 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
107 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
109 size_t lda = this->getLocalLength();
110 this->get1dCopy(A,lda);
113 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
115 using Teuchos::outArg;
116 #ifdef HAVE_TPETRA_DEBUG
117 TEUCHOS_TEST_FOR_EXCEPTION( !this->getMap()->isCompatible(*a.
getMap()), std::runtime_error,
118 "Tpetra::Vector::dots(): Vectors do not have compatible Maps:" << std::endl
119 <<
"this->getMap(): " << std::endl << *this->getMap()
120 <<
"a.getMap(): " << std::endl << *a.
getMap() << std::endl);
122 TEUCHOS_TEST_FOR_EXCEPTION( this->getLocalLength() != a.
getLocalLength(), std::runtime_error,
123 "Tpetra::Vector::dots(): Vectors do not have the same local length.");
126 gbldot = MVT::Dot(this->lclMV_,a.
lclMV_);
127 if (this->isDistributed()) {
128 Scalar lcldot = gbldot;
129 Teuchos::reduceAll(*this->getMap()->getComm(),Teuchos::REDUCE_SUM,lcldot,outArg(gbldot));
134 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
137 using Teuchos::outArg;
138 typedef Teuchos::ScalarTraits<Scalar> SCT;
140 Scalar sum = MVT::Sum(this->lclMV_);
141 if (this->isDistributed()) {
143 Teuchos::reduceAll(*this->getMap()->getComm(),Teuchos::REDUCE_SUM,lsum,outArg(sum));
148 return sum / as<typename SCT::magnitudeType> (this->getGlobalLength ());
151 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
153 using Teuchos::outArg;
154 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType Mag;
155 Mag norm = MVT::Norm1(this->lclMV_);
156 if (this->isDistributed()) {
158 Teuchos::reduceAll(*this->getMap()->getComm(),Teuchos::REDUCE_SUM,lnorm,outArg(norm));
163 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
165 using Teuchos::ScalarTraits;
166 using Teuchos::outArg;
167 typedef typename ScalarTraits<Scalar>::magnitudeType Mag;
168 Mag norm = MVT::Norm2Squared(this->lclMV_);
169 if (this->isDistributed()) {
171 Teuchos::reduceAll(*this->getMap()->getComm(),Teuchos::REDUCE_SUM,lnorm,outArg(norm));
173 return ScalarTraits<Mag>::squareroot(norm);
176 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
178 using Teuchos::outArg;
179 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType Mag;
180 Mag norm = MVT::NormInf(this->lclMV_);
181 if (this->isDistributed()) {
183 Teuchos::reduceAll(*this->getMap()->getComm(),Teuchos::REDUCE_MAX,lnorm,outArg(norm));
188 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
190 using Teuchos::ScalarTraits;
191 using Teuchos::outArg;
192 typedef typename ScalarTraits<Scalar>::magnitudeType Mag;
193 #ifdef HAVE_TPETRA_DEBUG
194 TEUCHOS_TEST_FOR_EXCEPTION( !this->getMap()->isCompatible(*weights.
getMap()), std::runtime_error,
195 "Tpetra::Vector::normWeighted(): Vectors do not have compatible Maps:" << std::endl
196 <<
"this->getMap(): " << std::endl << *this->getMap()
197 <<
"weights.getMap(): " << std::endl << *weights.
getMap() << std::endl);
199 TEUCHOS_TEST_FOR_EXCEPTION( this->getLocalLength() != weights.
getLocalLength(), std::runtime_error,
200 "Tpetra::Vector::normWeighted(): Vectors do not have the same local length.");
202 Mag norm = MVT::WeightedNorm(this->lclMV_,weights.
lclMV_);
203 if (this->isDistributed()) {
205 Teuchos::reduceAll(*this->getMap()->getComm(),Teuchos::REDUCE_SUM,lnorm,outArg(norm));
207 return ScalarTraits<Mag>::squareroot(norm / this->getGlobalLength());
210 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
212 std::ostringstream oss;
213 oss << Teuchos::Describable::description();
214 oss <<
"{length="<<this->getGlobalLength()
219 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
223 using Teuchos::VERB_DEFAULT;
224 using Teuchos::VERB_NONE;
225 using Teuchos::VERB_LOW;
226 using Teuchos::VERB_MEDIUM;
227 using Teuchos::VERB_HIGH;
228 using Teuchos::VERB_EXTREME;
229 Teuchos::EVerbosityLevel vl = verbLevel;
230 if (vl == VERB_DEFAULT) vl = VERB_LOW;
231 RCP<const Teuchos::Comm<int> > comm = this->getMap()->getComm();
232 const int myImageID = comm->getRank(),
233 numImages = comm->getSize();
235 for (
size_t dec=10; dec<this->getGlobalLength(); dec *= 10) {
238 Teuchos::OSTab tab(out);
239 if (vl != VERB_NONE) {
241 if (myImageID == 0) out << this->description() << std::endl;
242 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
243 if (myImageID == imageCtr) {
244 if (vl != VERB_LOW) {
246 out <<
"node " << setw(width) << myImageID <<
": local length=" << this->getLocalLength() << endl;
247 if (vl != VERB_MEDIUM) {
249 if (vl == VERB_EXTREME && this->getLocalLength() > 0) {
250 RCP<Node> node = this->lclMV_.getNode();
251 KOKKOS_NODE_TRACE(
"Vector::describe()")
252 ArrayRCP<const Scalar> myview = node->template viewBuffer<Scalar>(
253 this->getLocalLength(),
254 MVT::getValues(this->lclMV_) );
256 for (
size_t i=0; i<this->getLocalLength(); ++i) {
257 out << setw(width) << this->getMap()->getGlobalElement(i)
259 << myview[i] << endl;
261 myview = Teuchos::null;
282 #define TPETRA_VECTOR_INSTANT(SCALAR,LO,GO,NODE) \
284 template class Vector< SCALAR , LO , GO , NODE >; \
287 #endif // TPETRA_VECTOR_DEF_HPP
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to a FancyOStream.
void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using global (row) index.
Teuchos::ScalarTraits< Scalar >::magnitudeType normWeighted(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
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.
void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Replace value, using global (row) index.
One or more distributed dense vectors.
virtual std::string description() const
A simple one-line description of this object.
void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Replace current value at the specified location with specified value.
Teuchos::ScalarTraits< Scalar >::magnitudeType normInf() const
Compute Inf-norm of this Vector.
void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using local (row) index.
virtual ~Vector()
Destructor.
void replaceLocalValue(LocalOrdinal myRow, const Scalar &value)
Replace current value at the specified location with specified values.
Scalar dot(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &a) const
Computes dot product of this Vector against input Vector x.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getMap() const
The Map describing the parallel distribution of this object.
void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Adds specified value to existing value at the specified location.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm2() const
Compute 2-norm of this Vector.
void get1dCopy(ArrayView< Scalar > A) const
Return multi-vector values in user-provided two-dimensional array (using Teuchos memory management cl...
KMV lclMV_
The Kokkos::MultiVector containing the compute buffer of data.
Describes a parallel distribution of objects over processes.
Vector(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, bool zeroOut=true)
Sets all vector entries to zero.
void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value)
Adds specified value to existing value at the specified location.
A distributed dense vector.
Scalar meanValue() const
Compute mean (average) value of this Vector.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm1() const
Return 1-norm of this Vector.