42 #ifndef TPETRA_VECTOR_DEF_HPP 43 #define TPETRA_VECTOR_DEF_HPP 53 #include "Tpetra_MultiVector.hpp" 54 #include "KokkosCompat_View.hpp" 58 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
60 Vector (
const Teuchos::RCP<const map_type>& map,
65 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
71 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
74 const Teuchos::DataAccess copyOrView)
78 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
80 Vector (
const Teuchos::RCP<const map_type>& map,
81 const Teuchos::ArrayView<const Scalar>& values)
82 :
base_type (map, values, values.size (), 1)
85 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
87 Vector (
const Teuchos::RCP<const map_type>& map,
92 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
94 Vector (
const Teuchos::RCP<const map_type>& map,
100 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
105 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
112 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
119 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
126 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
133 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
141 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
147 this->
dot (y, Teuchos::arrayView (&result, 1));
151 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
157 this->
meanValue (Teuchos::arrayView (&mean, 1));
161 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
167 this->
norm1 (Teuchos::arrayView (&norm, 1));
171 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
177 this->
norm2 (Teuchos::arrayView (&norm, 1));
181 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
187 this->
normInf (Teuchos::arrayView (&norm, 1));
191 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
197 this->
normWeighted (weights, Teuchos::arrayView (&norm, 1));
201 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
205 using Teuchos::TypeNameTraits;
207 std::ostringstream out;
208 out <<
"\"Tpetra::Vector\": {";
209 out <<
"Template parameters: {Scalar: " << TypeNameTraits<Scalar>::name ()
210 <<
", LocalOrdinal: " << TypeNameTraits<LocalOrdinal>::name ()
211 <<
", GlobalOrdinal: " << TypeNameTraits<GlobalOrdinal>::name ()
212 <<
", Node" << Node::name ()
214 if (this->getObjectLabel () !=
"") {
215 out <<
"Label: \"" << this->getObjectLabel () <<
"\", ";
223 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
226 const Teuchos::EVerbosityLevel verbLevel)
const 230 using Teuchos::VERB_DEFAULT;
231 using Teuchos::VERB_NONE;
232 using Teuchos::VERB_LOW;
233 using Teuchos::VERB_MEDIUM;
234 using Teuchos::VERB_HIGH;
235 using Teuchos::VERB_EXTREME;
237 const Teuchos::EVerbosityLevel vl =
238 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
239 const Teuchos::Comm<int>& comm = * (this->
getMap ()->getComm ());
240 const int myImageID = comm.getRank ();
241 const int numImages = comm.getSize ();
247 Teuchos::OSTab tab(out);
248 if (vl != VERB_NONE) {
250 if (myImageID == 0) out << this->
description() << std::endl;
251 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
252 if (myImageID == imageCtr) {
253 if (vl != VERB_LOW) {
255 out <<
"Process " << setw(width) << myImageID <<
":" << endl;
256 Teuchos::OSTab tab1 (out);
259 out <<
"Local length: " << lclNumRows << endl;
260 if (vl != VERB_MEDIUM) {
262 if (vl == VERB_EXTREME && lclNumRows > 0) {
273 typedef typename dual_view_type::t_host::execution_space HES;
274 X_lcl.template sync<HES> ();
275 typename dual_view_type::t_host X_host = X_lcl.h_view;
276 for (
size_t i = 0; i < lclNumRows; ++i) {
277 out << setw(width) << this->
getMap ()->getGlobalElement (i)
278 <<
": " << X_host(i,0) << endl;
292 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
306 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
307 Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >
309 offsetView (
const Teuchos::RCP<const map_type>& subMap,
310 const size_t offset)
const 313 using Kokkos::subview;
317 const size_t newNumRows = subMap->getNodeNumElements ();
320 const int myRank = this->
getMap ()->getComm ()->getRank ();
321 TEUCHOS_TEST_FOR_EXCEPTION(
322 newNumRows + offset > this->
getLocalLength (), std::runtime_error,
323 "Tpetra::Vector::offsetView(NonConst): Invalid input Map. The input " 324 "Map owns " << newNumRows <<
" entries on process " << myRank <<
". " 325 "offset = " << offset <<
". Yet, the Vector contains only " 326 << this->getOrigNumLocalRows () <<
" rows on this process.");
329 const std::pair<size_t, size_t> offsetPair (offset, offset + newNumRows);
331 return rcp (
new V (subMap,
332 subview (this->
view_, offsetPair, ALL ()),
336 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
337 Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >
343 return Teuchos::rcp_const_cast<V> (this->offsetView (subMap, offset));
356 #define TPETRA_VECTOR_INSTANT(SCALAR,LO,GO,NODE) \ 357 template class Vector< SCALAR , LO , GO , NODE >; \ 358 template Vector< SCALAR , LO , GO , NODE > createCopy (const Vector< SCALAR , LO , GO , NODE >& src); 360 #endif // TPETRA_VECTOR_DEF_HPP size_t getLocalLength() const
Local number of rows on the calling process.
void sumIntoLocalValue(LocalOrdinal localRow, size_t col, const impl_scalar_type &value)
Add value to existing value, using local (row) index.
Vector(const Teuchos::RCP< const map_type > &map, const bool zeroOut=true)
Basic constructor.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Scalar meanValue() const
Compute mean (average) value of this Vector.
void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t col, const impl_scalar_type &value)
Add value to existing value, using global (row) index.
void replaceLocalValue(LocalOrdinal localRow, size_t col, const impl_scalar_type &value)
Replace value, using local (row) index.
mag_type normWeighted(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
base_type::dot_type dot_type
Type of an inner ("dot") product result.
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.
mag_type norm2() const
Compute 2-norm of this Vector.
dual_view_type view_
The Kokkos::DualView containing the MultiVector's data.
Kokkos::Details::InnerProductSpaceTraits< impl_scalar_type >::dot_type dot_type
Type of an inner ("dot") product result.
void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Replace current value at the specified location with specified value.
base_type::mag_type mag_type
Type of a norm result.
void replaceGlobalValue(GlobalOrdinal globalRow, size_t col, const impl_scalar_type &value)
Replace value, using global (row) index.
dual_view_type getDualView() const
Get the Kokkos::DualView which implements local storage.
dot_type dot(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &y) const
Computes dot product of this Vector against input Vector x.
virtual ~Vector()
Destructor.
void get1dCopy(const Teuchos::ArrayView< Scalar > &A) const
Return multi-vector values in user-provided two-dimensional array (using Teuchos memory management cl...
void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Adds specified value to existing value at the specified location.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
size_t getOrigNumLocalRows() const
"Original" number of rows in the (local) data.
void replaceLocalValue(LocalOrdinal myRow, const Scalar &value)
Replace current value at the specified location with specified values.
Kokkos::Details::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
mag_type normInf() const
Compute Inf-norm of this Vector.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, typename execution_space::execution_space > dual_view_type
Kokkos::DualView specialization used by this class.
void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value)
Adds specified value to existing value at the specified location.
Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > createCopy(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &src)
Return a deep copy of the given Vector.
A distributed dense vector.
virtual Teuchos::RCP< const map_type > getMap() const
The Map describing the parallel distribution of this object.
virtual std::string description() const
A simple one-line description of this object.
mag_type norm1() const
Return 1-norm of this Vector.
dual_view_type origView_
The "original view" of the MultiVector's data.