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>
117 const bool atomic)
const 122 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
129 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
134 const bool atomic)
const 139 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
147 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
153 this->
dot (y, Teuchos::arrayView (&result, 1));
157 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
163 this->
meanValue (Teuchos::arrayView (&mean, 1));
167 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
173 this->
norm1 (Teuchos::arrayView (&norm, 1));
177 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
183 this->
norm2 (Teuchos::arrayView (&norm, 1));
187 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
193 this->
normInf (Teuchos::arrayView (&norm, 1));
197 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
204 this->
normWeighted (weights, Teuchos::arrayView (&norm, 1));
208 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
212 using Teuchos::TypeNameTraits;
214 std::ostringstream out;
215 out <<
"\"Tpetra::Vector\": {";
216 out <<
"Template parameters: {Scalar: " << TypeNameTraits<Scalar>::name ()
217 <<
", LocalOrdinal: " << TypeNameTraits<LocalOrdinal>::name ()
218 <<
", GlobalOrdinal: " << TypeNameTraits<GlobalOrdinal>::name ()
219 <<
", Node" << Node::name ()
221 if (this->getObjectLabel () !=
"") {
222 out <<
"Label: \"" << this->getObjectLabel () <<
"\", ";
230 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
233 const Teuchos::EVerbosityLevel verbLevel)
const 237 using Teuchos::VERB_DEFAULT;
238 using Teuchos::VERB_NONE;
239 using Teuchos::VERB_LOW;
240 using Teuchos::VERB_MEDIUM;
241 using Teuchos::VERB_HIGH;
242 using Teuchos::VERB_EXTREME;
244 const Teuchos::EVerbosityLevel vl =
245 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
246 const Teuchos::Comm<int>& comm = * (this->
getMap ()->getComm ());
247 const int myImageID = comm.getRank ();
248 const int numImages = comm.getSize ();
254 Teuchos::OSTab tab(out);
255 if (vl != VERB_NONE) {
257 if (myImageID == 0) out << this->
description() << std::endl;
258 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
259 if (myImageID == imageCtr) {
260 if (vl != VERB_LOW) {
262 out <<
"Process " << setw(width) << myImageID <<
":" << endl;
263 Teuchos::OSTab tab1 (out);
266 out <<
"Local length: " << lclNumRows << endl;
267 if (vl != VERB_MEDIUM) {
269 if (vl == VERB_EXTREME && lclNumRows > 0) {
280 typedef typename dual_view_type::t_host::execution_space HES;
281 X_lcl.template sync<HES> ();
282 typename dual_view_type::t_host X_host = X_lcl.h_view;
283 for (
size_t i = 0; i < lclNumRows; ++i) {
284 out << setw(width) << this->
getMap ()->getGlobalElement (i)
285 <<
": " << X_host(i,0) << endl;
299 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
313 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
314 Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >
316 offsetView (
const Teuchos::RCP<const map_type>& subMap,
317 const size_t offset)
const 320 using Kokkos::subview;
324 const size_t newNumRows = subMap->getNodeNumElements ();
327 const int myRank = this->
getMap ()->getComm ()->getRank ();
328 TEUCHOS_TEST_FOR_EXCEPTION(
329 newNumRows + offset > this->
getLocalLength (), std::runtime_error,
330 "Tpetra::Vector::offsetView(NonConst): Invalid input Map. The input " 331 "Map owns " << newNumRows <<
" entries on process " << myRank <<
". " 332 "offset = " << offset <<
". Yet, the Vector contains only " 333 << this->getOrigNumLocalRows () <<
" rows on this process.");
336 const std::pair<size_t, size_t> offsetPair (offset, offset + newNumRows);
338 return rcp (
new V (subMap,
339 subview (this->
view_, offsetPair, ALL ()),
343 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic>
344 Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >
350 return Teuchos::rcp_const_cast<V> (this->offsetView (subMap, offset));
363 #define TPETRA_VECTOR_INSTANT(SCALAR,LO,GO,NODE) \ 364 template class Vector< SCALAR , LO , GO , NODE >; \ 365 template Vector< SCALAR , LO , GO , NODE > createCopy (const Vector< SCALAR , LO , GO , NODE >& src); 367 #endif // TPETRA_VECTOR_DEF_HPP size_t getLocalLength() const
Local number of rows on the calling process.
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.
void replaceLocalValue(const LocalOrdinal myRow, const Scalar &value) const
Replace current value at the specified location with specified values.
Scalar meanValue() const
Compute mean (average) value 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.
void replaceGlobalValue(GlobalOrdinal globalRow, size_t col, const impl_scalar_type &value) const
Replace value, using global (row) index.
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.
base_type::mag_type mag_type
Type of a norm result.
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 sumIntoGlobalValue(const GlobalOrdinal globalRow, const size_t col, const impl_scalar_type &value, const bool atomic=useAtomicUpdatesByDefault) const
Add value to existing value, using global (row) index.
mag_type TPETRA_DEPRECATED normWeighted(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
void sumIntoLocalValue(const LocalOrdinal myRow, const Scalar &value, const bool atomic=base_type::useAtomicUpdatesByDefault) const
Add value to existing value, using local (row) index.
void get1dCopy(const Teuchos::ArrayView< Scalar > &A) const
Return multi-vector values in user-provided two-dimensional array (using Teuchos memory management cl...
global_size_t getGlobalLength() const
Global number of rows in the multivector.
size_t getOrigNumLocalRows() const
"Original" number of rows in the (local) data.
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.
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.
void sumIntoGlobalValue(const GlobalOrdinal globalRow, const Scalar &value, const bool atomic=base_type::useAtomicUpdatesByDefault) const
Add value to existing value, using global (row) index.
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.
void replaceGlobalValue(const GlobalOrdinal globalRow, const Scalar &value) const
Replace current value at the specified location with specified value.
void sumIntoLocalValue(const LocalOrdinal localRow, const size_t col, const impl_scalar_type &value, const bool atomic=useAtomicUpdatesByDefault) const
Add value to existing value, using local (row) index.
void replaceLocalValue(LocalOrdinal localRow, size_t col, const impl_scalar_type &value) const
Replace value, using local (row) index.