Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Vector_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TPETRA_VECTOR_DEF_HPP
11 #define TPETRA_VECTOR_DEF_HPP
12 
15 
16 #include "Tpetra_MultiVector.hpp"
18 #include "KokkosCompat_View.hpp"
19 #include "KokkosBlas1_nrm2w_squared.hpp"
20 #include "Teuchos_CommHelpers.hpp"
21 
22 namespace Tpetra {
23 
24  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
27  : base_type ()
28  {}
29 
30  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
32  Vector (const Teuchos::RCP<const map_type>& map,
33  const bool zeroOut)
34  : base_type (map, 1, zeroOut)
35  {}
36 
37  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
40  const Teuchos::DataAccess copyOrView)
41  : base_type (source, copyOrView)
42  {}
43 
44  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
47  const Teuchos::RCP<const map_type>& map,
48  const local_ordinal_type rowOffset) :
49  base_type (source, map, rowOffset)
50  {}
51 
52  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
54  Vector (const Teuchos::RCP<const map_type>& map,
55  const Teuchos::ArrayView<const Scalar>& values)
56  : base_type (map, values, values.size (), 1)
57  {}
58 
59  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
61  Vector (const Teuchos::RCP<const map_type>& map,
62  const dual_view_type& view)
63  : base_type (map, view)
64  {}
65 
66  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
68  Vector (const Teuchos::RCP<const map_type>& map,
69  const dual_view_type& view,
70  const dual_view_type& origView)
71  : base_type (map, view, origView)
72  {}
73 
74 
75  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
77  Vector (const Teuchos::RCP<const map_type>& map,
78  const wrapped_dual_view_type& view)
79  : base_type (map, view)
80  {}
81 
82  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
85  const size_t j)
86  : base_type (X, j)
87  {}
88 
89  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
90  void
92  replaceGlobalValue (const GlobalOrdinal globalRow, const Scalar& value) {
93  this->base_type::replaceGlobalValue (globalRow, 0, value);
94  }
95 
96  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
97  void
99  sumIntoGlobalValue (const GlobalOrdinal globalRow,
100  const Scalar& value,
101  const bool atomic)
102  {
103  this->base_type::sumIntoGlobalValue (globalRow, 0, value, atomic);
104  }
105 
106  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
107  void
109  replaceLocalValue (const LocalOrdinal myRow, const Scalar& value) {
110  this->base_type::replaceLocalValue (myRow, 0, value);
111  }
112 
113  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
114  void
116  sumIntoLocalValue (const LocalOrdinal globalRow,
117  const Scalar& value,
118  const bool atomic)
119  {
120  this->base_type::sumIntoLocalValue (globalRow, 0, value, atomic);
121  }
122 
123  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
124  void
126  get1dCopy (const Teuchos::ArrayView<Scalar>& A) const {
127  const size_t lda = this->getLocalLength ();
128  this->get1dCopy (A, lda);
129  }
130 
131  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
135  {
136  dot_type result;
137  this->dot (y, Teuchos::arrayView (&result, 1));
138  return result;
139  }
140 
141  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
142  Scalar
144  meanValue () const
145  {
146  Scalar mean;
147  this->meanValue (Teuchos::arrayView (&mean, 1));
148  return mean;
149  }
150 
151  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
154  norm1 () const
155  {
156  mag_type norm;
157  this->norm1 (Teuchos::arrayView (&norm, 1));
158  return norm;
159  }
160 
161  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
164  norm2 () const
165  {
166  mag_type norm;
167  this->norm2 (Teuchos::arrayView (&norm, 1));
168  return norm;
169  }
170 
171  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
174  normInf () const
175  {
176  mag_type norm;
177  this->normInf (Teuchos::arrayView (&norm, 1));
178  return norm;
179  }
180 
181 
182  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
184  description () const
185  {
186  return this->descriptionImpl ("Tpetra::Vector");
187  }
188 
189  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
191  describe (Teuchos::FancyOStream& out,
192  const Teuchos::EVerbosityLevel verbLevel) const
193  {
194  this->describeImpl (out, "Tpetra::Vector", verbLevel);
195  }
196 
197  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
198  Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
200  offsetView (const Teuchos::RCP<const map_type>& subMap,
201  const size_t offset) const
202  {
203  using Kokkos::ALL;
204  using Kokkos::subview;
205  using Teuchos::rcp;
207 
208  const size_t newNumRows = subMap->getLocalNumElements ();
209  const bool tooManyElts = newNumRows + offset > this->getOrigNumLocalRows ();
210  if (tooManyElts) {
211  const int myRank = this->getMap ()->getComm ()->getRank ();
212  TEUCHOS_TEST_FOR_EXCEPTION(
213  newNumRows + offset > this->getLocalLength (), std::runtime_error,
214  "Tpetra::Vector::offsetView(NonConst): Invalid input Map. The input "
215  "Map owns " << newNumRows << " entries on process " << myRank << ". "
216  "offset = " << offset << ". Yet, the Vector contains only "
217  << this->getOrigNumLocalRows () << " rows on this process.");
218  }
219 
220  // Need 'this->' to get view_ from parent class.
221  return rcp (new V (subMap, wrapped_dual_view_type(this->view_,Kokkos::pair<int,int>(offset,offset+newNumRows),ALL())));
222  }
223 
224  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
225  Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
226  Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
227  offsetViewNonConst (const Teuchos::RCP<const map_type>& subMap,
228  const size_t offset)
229  {
230  typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
231  return Teuchos::rcp_const_cast<V> (this->offsetView (subMap, offset));
232  }
233 
234  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
235  Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>
237  {
239  // The 2-argument copy constructor with second argument =
240  // Teuchos::Copy does a deep copy of its input.
241  vec_type dst (src, Teuchos::Copy);
242 
243  // The Kokkos refactor version of Vector has view semantics, so
244  // returning the Vector directly, rather than through RCP, only
245  // does a shallow copy.
246  return dst;
247  }
248 
249 } // namespace Tpetra
250 
259 #define TPETRA_VECTOR_INSTANT(SCALAR,LO,GO,NODE) \
260  template class Vector< SCALAR , LO , GO , NODE >; \
261  template Vector< SCALAR , LO , GO , NODE > createCopy (const Vector< SCALAR , LO , GO , NODE >& src);
262 
263 #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&#39; 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 (&quot;dot&quot;) product result.
mag_type norm1() const
Return the one-norm of this Vector.