Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_Vector_def.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Tpetra: Templated Linear Algebra Services Package
5// Copyright (2008) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ************************************************************************
40// @HEADER
41
42#ifndef TPETRA_VECTOR_DEF_HPP
43#define TPETRA_VECTOR_DEF_HPP
44
47
48#include "Tpetra_MultiVector.hpp"
50#include "KokkosCompat_View.hpp"
51#include "KokkosBlas1_nrm2w_squared.hpp"
52#include "Teuchos_CommHelpers.hpp"
53
54namespace Tpetra {
55
56 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
58 Vector ()
59 : base_type ()
60 {}
61
62 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
64 Vector (const Teuchos::RCP<const map_type>& map,
65 const bool zeroOut)
66 : base_type (map, 1, zeroOut)
67 {}
68
69 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
72 const Teuchos::DataAccess copyOrView)
73 : base_type (source, copyOrView)
74 {}
75
76 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
79 const Teuchos::RCP<const map_type>& map,
80 const local_ordinal_type rowOffset) :
81 base_type (source, map, rowOffset)
82 {}
83
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)
89 {}
90
91 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
93 Vector (const Teuchos::RCP<const map_type>& map,
94 const dual_view_type& view)
95 : base_type (map, view)
96 {}
97
98 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
100 Vector (const Teuchos::RCP<const map_type>& map,
101 const dual_view_type& view,
102 const dual_view_type& origView)
103 : base_type (map, view, origView)
104 {}
105
106
107 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
109 Vector (const Teuchos::RCP<const map_type>& map,
110 const wrapped_dual_view_type& view)
111 : base_type (map, view)
112 {}
113
114 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
117 const size_t j)
118 : base_type (X, j)
119 {}
120
121 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
122 void
124 replaceGlobalValue (const GlobalOrdinal globalRow, const Scalar& value) {
125 this->base_type::replaceGlobalValue (globalRow, 0, value);
126 }
127
128 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
129 void
131 sumIntoGlobalValue (const GlobalOrdinal globalRow,
132 const Scalar& value,
133 const bool atomic)
134 {
135 this->base_type::sumIntoGlobalValue (globalRow, 0, value, atomic);
136 }
137
138 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
139 void
141 replaceLocalValue (const LocalOrdinal myRow, const Scalar& value) {
142 this->base_type::replaceLocalValue (myRow, 0, value);
143 }
144
145 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
146 void
148 sumIntoLocalValue (const LocalOrdinal globalRow,
149 const Scalar& value,
150 const bool atomic)
151 {
152 this->base_type::sumIntoLocalValue (globalRow, 0, value, atomic);
153 }
154
155 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
156 void
158 get1dCopy (const Teuchos::ArrayView<Scalar>& A) const {
159 const size_t lda = this->getLocalLength ();
160 this->get1dCopy (A, lda);
161 }
162
163 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
167 {
168 dot_type result;
169 this->dot (y, Teuchos::arrayView (&result, 1));
170 return result;
171 }
172
173 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
174 Scalar
176 meanValue () const
177 {
178 Scalar mean;
179 this->meanValue (Teuchos::arrayView (&mean, 1));
180 return mean;
181 }
182
183 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
186 norm1 () const
187 {
188 mag_type norm;
189 this->norm1 (Teuchos::arrayView (&norm, 1));
190 return norm;
191 }
192
193 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
196 norm2 () const
197 {
198 mag_type norm;
199 this->norm2 (Teuchos::arrayView (&norm, 1));
200 return norm;
201 }
202
203 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
206 normInf () const
207 {
208 mag_type norm;
209 this->normInf (Teuchos::arrayView (&norm, 1));
210 return norm;
211 }
212
213
214 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
216 description () const
217 {
218 return this->descriptionImpl ("Tpetra::Vector");
219 }
220
221 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
223 describe (Teuchos::FancyOStream& out,
224 const Teuchos::EVerbosityLevel verbLevel) const
225 {
226 this->describeImpl (out, "Tpetra::Vector", verbLevel);
227 }
228
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
234 {
235 using Kokkos::ALL;
236 using Kokkos::subview;
237 using Teuchos::rcp;
239
240 const size_t newNumRows = subMap->getLocalNumElements ();
241 const bool tooManyElts = newNumRows + offset > this->getOrigNumLocalRows ();
242 if (tooManyElts) {
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.");
250 }
251
252 // Need 'this->' to get view_ from parent class.
253 return rcp (new V (subMap, wrapped_dual_view_type(this->view_,Kokkos::pair<int,int>(offset,offset+newNumRows),ALL())));
254 }
255
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,
260 const size_t offset)
261 {
262 typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
263 return Teuchos::rcp_const_cast<V> (this->offsetView (subMap, offset));
264 }
265
266 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
267 Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>
269 {
271 // The 2-argument copy constructor with second argument =
272 // Teuchos::Copy does a deep copy of its input.
273 vec_type dst (src, Teuchos::Copy);
274
275 // The Kokkos refactor version of Vector has view semantics, so
276 // returning the Vector directly, rather than through RCP, only
277 // does a shallow copy.
278 return dst;
279 }
280
281} // namespace Tpetra
282
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);
294
295#endif // TPETRA_VECTOR_DEF_HPP
Declaration of a function that prints strings from each process.
One or more distributed dense vectors.
A distributed dense vector.
void replaceGlobalValue(const GlobalOrdinal globalRow, const Scalar &value)
Replace current value at the specified location with specified value.
void sumIntoLocalValue(const LocalOrdinal myRow, const Scalar &value, const bool atomic=base_type::useAtomicUpdatesByDefault)
Add value to existing value, using local (row) index.
mag_type normInf() const
Return the infinity-norm of this Vector.
Scalar meanValue() const
Compute mean (average) value of this Vector.
base_type::mag_type mag_type
Type of a norm result.
void replaceLocalValue(const LocalOrdinal myRow, const Scalar &value)
Replace current value at the specified location with specified values.
mag_type norm2() const
Return the two-norm of this Vector.
base_type::dot_type dot_type
Type of an inner ("dot") product result.
LocalOrdinal local_ordinal_type
This class' second template parameter; the type of local indices.
void sumIntoGlobalValue(const GlobalOrdinal globalRow, const Scalar &value, const bool atomic=base_type::useAtomicUpdatesByDefault)
Add value to existing value, using global (row) index.
base_type::wrapped_dual_view_type wrapped_dual_view_type
WrappedDualView specialization used by this class.
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.
Vector()
Default constructor: makes a Vector with no rows or columns.
virtual std::string description() const
Return a one-line description of this object.
void get1dCopy(const Teuchos::ArrayView< Scalar > &A) const
Return multi-vector values in user-provided two-dimensional array (using Teuchos memory management cl...
base_type::dual_view_type dual_view_type
Kokkos::DualView specialization used by this class.
dot_type dot(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &y) const
Return the dot product of this Vector and the input Vector x.
mag_type norm1() const
Return the one-norm of this Vector.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
MultiVector< ST, LO, GO, NT > createCopy(const MultiVector< ST, LO, GO, NT > &src)
Return a deep copy of the given MultiVector.