42 #ifndef TPETRA_VECTOR_DEF_HPP
43 #define TPETRA_VECTOR_DEF_HPP
48 #include "Tpetra_MultiVector.hpp"
50 #include "KokkosCompat_View.hpp"
51 #include "KokkosBlas1_nrm2w_squared.hpp"
52 #include "Teuchos_CommHelpers.hpp"
56 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
62 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
64 Vector (
const Teuchos::RCP<const map_type>& map,
69 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 const Teuchos::DataAccess copyOrView)
76 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 const Teuchos::RCP<const map_type>& map,
84 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
86 Vector (
const Teuchos::RCP<const map_type>& map,
87 const Teuchos::ArrayView<const Scalar>& values)
88 :
base_type (map, values, values.size (), 1)
91 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
93 Vector (
const Teuchos::RCP<const map_type>& map,
98 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
100 Vector (
const Teuchos::RCP<const map_type>& map,
107 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
109 Vector (
const Teuchos::RCP<const map_type>& map,
114 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
121 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
125 this->base_type::replaceGlobalValue (globalRow, 0, value);
128 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
135 this->base_type::sumIntoGlobalValue (globalRow, 0, value, atomic);
138 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
142 this->base_type::replaceLocalValue (myRow, 0, value);
145 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
152 this->base_type::sumIntoLocalValue (globalRow, 0, value, atomic);
155 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
159 const size_t lda = this->getLocalLength ();
160 this->get1dCopy (A, lda);
163 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
169 this->dot (y, Teuchos::arrayView (&result, 1));
173 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
179 this->meanValue (Teuchos::arrayView (&mean, 1));
183 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
189 this->norm1 (Teuchos::arrayView (&norm, 1));
193 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
199 this->norm2 (Teuchos::arrayView (&norm, 1));
203 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
209 this->normInf (Teuchos::arrayView (&norm, 1));
214 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
218 return this->descriptionImpl (
"Tpetra::Vector");
221 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
224 const Teuchos::EVerbosityLevel verbLevel)
const
226 this->describeImpl (out,
"Tpetra::Vector", verbLevel);
229 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
230 Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
232 offsetView (
const Teuchos::RCP<const map_type>& subMap,
233 const size_t offset)
const
236 using Kokkos::subview;
240 const size_t newNumRows = subMap->getLocalNumElements ();
241 const bool tooManyElts = newNumRows + offset > this->getOrigNumLocalRows ();
243 const int myRank = this->getMap ()->getComm ()->getRank ();
244 TEUCHOS_TEST_FOR_EXCEPTION(
245 newNumRows + offset > this->getLocalLength (), std::runtime_error,
246 "Tpetra::Vector::offsetView(NonConst): Invalid input Map. The input "
247 "Map owns " << newNumRows <<
" entries on process " << myRank <<
". "
248 "offset = " << offset <<
". Yet, the Vector contains only "
249 << this->getOrigNumLocalRows () <<
" rows on this process.");
253 return rcp (
new V (subMap, wrapped_dual_view_type(this->view_,Kokkos::pair<int,int>(offset,offset+newNumRows),ALL())));
256 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
257 Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
258 Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
259 offsetViewNonConst (
const Teuchos::RCP<const map_type>& subMap,
262 typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
263 return Teuchos::rcp_const_cast<V> (this->offsetView (subMap, offset));
266 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
267 Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>
273 vec_type dst (src, Teuchos::Copy);
291 #define TPETRA_VECTOR_INSTANT(SCALAR,LO,GO,NODE) \
292 template class Vector< SCALAR , LO , GO , NODE >; \
293 template Vector< SCALAR , LO , GO , NODE > createCopy (const Vector< SCALAR , LO , GO , NODE >& src);
295 #endif // TPETRA_VECTOR_DEF_HPP
Vector()
Default constructor: makes a Vector with no rows or columns.
mag_type norm2() const
Return the two-norm of this Vector.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Describe this object in a human-readable way to the given output stream.
base_type::mag_type mag_type
Type of a norm result.
Declaration of a function that prints strings from each process.
void get1dCopy(const Teuchos::ArrayView< Scalar > &A) const
Return multi-vector values in user-provided two-dimensional array (using Teuchos memory management cl...
void sumIntoLocalValue(const LocalOrdinal myRow, const Scalar &value, const bool atomic=base_type::useAtomicUpdatesByDefault)
Add value to existing value, using local (row) index.
virtual std::string description() const
Return a one-line description of this object.
MultiVector< ST, LO, GO, NT > createCopy(const MultiVector< ST, LO, GO, NT > &src)
Return a deep copy of the given MultiVector.
dot_type dot(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &y) const
Return the dot product of this Vector and the input Vector x.
void sumIntoGlobalValue(const GlobalOrdinal globalRow, const Scalar &value, const bool atomic=base_type::useAtomicUpdatesByDefault)
Add value to existing value, using global (row) index.
void replaceLocalValue(const LocalOrdinal myRow, const Scalar &value)
Replace current value at the specified location with specified values.
void replaceGlobalValue(const GlobalOrdinal globalRow, const Scalar &value)
Replace current value at the specified location with specified value.
LocalOrdinal local_ordinal_type
This class' second template parameter; the type of local indices.
A distributed dense vector.
base_type::dual_view_type dual_view_type
Kokkos::DualView specialization used by this class.
Scalar meanValue() const
Compute mean (average) value of this Vector.
mag_type normInf() const
Return the infinity-norm of this Vector.
base_type::dot_type dot_type
Type of an inner ("dot") product result.
mag_type norm1() const
Return the one-norm of this Vector.