Xpetra Version of the Day
Loading...
Searching...
No Matches
Xpetra_MultiVector_decl.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Xpetra: A linear algebra interface package
4//
5// Copyright 2012 NTESS and the Xpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef XPETRA_MULTIVECTOR_DECL_HPP
11#define XPETRA_MULTIVECTOR_DECL_HPP
12
13#include <Teuchos_LabeledObject.hpp>
16#include <Teuchos_Range1D.hpp>
17
18#include "Xpetra_ConfigDefs.hpp"
19#include "Xpetra_DistObject.hpp"
20#include "Xpetra_Map_decl.hpp"
21
22#include "Xpetra_Access.hpp"
23
24#include <Kokkos_Core.hpp>
25#include <Kokkos_DualView.hpp>
26#if KOKKOS_VERSION >= 40799
27#include <KokkosKernels_ArithTraits.hpp>
28#else
29#include <Kokkos_ArithTraits.hpp>
30#endif
31
32namespace Xpetra {
33
34#ifndef DOXYGEN_SHOULD_SKIP_THIS
35// forward declaration of Vector, needed to prevent circular inclusions
36template <class S, class LO, class GO, class N>
37class Vector;
38#endif
39
40template <class Scalar,
41 class LocalOrdinal,
42 class GlobalOrdinal,
43 class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
45 : public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
46 public:
47 typedef Scalar scalar_type;
48 typedef LocalOrdinal local_ordinal_type;
49 typedef GlobalOrdinal global_ordinal_type;
50 typedef Node node_type;
51
53
54
56 virtual ~MultiVector();
57
70
72
74
76 virtual void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar& value) = 0;
77
79 virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar& value) = 0;
80
82 virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar& value) = 0;
83
85 virtual void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar& value) = 0;
86
88 virtual void putScalar(const Scalar& value) = 0;
89
91
93
94
97
100
102 virtual Teuchos::ArrayRCP<const Scalar> getData(size_t j) const = 0;
103
106
108
110
111
114
117
120
122 virtual void scale(const Scalar& alpha) = 0;
123
126
128 virtual void update(const Scalar& alpha, const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A, const Scalar& beta) = 0;
129
131 virtual void update(const Scalar& alpha, const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
133 const Scalar& gamma) = 0;
134
136 virtual void norm1(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms) const = 0;
137
139 virtual void norm2(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms) const = 0;
140
142 virtual void normInf(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms) const = 0;
143
146 virtual void meanValue(const Teuchos::ArrayView<Scalar>& means) const = 0;
147
149 virtual void multiply(Teuchos::ETransp transA,
150 Teuchos::ETransp transB,
151 const Scalar& alpha,
154 const Scalar& beta) = 0;
155
183 virtual void elementWiseMultiply(Scalar scalarAB,
186 Scalar scalarThis) = 0;
187
189
191
192
194 virtual size_t getNumVectors() const = 0;
195
197 virtual size_t getLocalLength() const = 0;
198
200 virtual global_size_t getGlobalLength() const = 0;
201
202 // \brief Checks to see if the local length, number of vectors and size of Scalar type match
204
206
208
209
211 virtual std::string description() const = 0;
212
215
216 virtual void replaceMap(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>& map) = 0;
217
219
221
222
224 virtual void setSeed(unsigned int seed) = 0;
225
227 virtual void randomize(bool bUseXpetraImplementation = false) = 0;
228
230 virtual void randomize(const Scalar& minVal, const Scalar& maxVal, bool bUseXpetraImplementation = false) = 0;
231
233 virtual void Xpetra_randomize();
234
236 virtual void Xpetra_randomize(const Scalar& minVal, const Scalar& maxVal);
237
238#if KOKKOS_VERSION >= 40799
239 using impl_scalar_type = typename KokkosKernels::ArithTraits<Scalar>::val_type;
240#else
241 using impl_scalar_type = typename Kokkos::ArithTraits<Scalar>::val_type;
242#endif
243 using dual_view_type = Kokkos::DualView<impl_scalar_type**, Kokkos::LayoutStride, typename node_type::device_type, Kokkos::MemoryUnmanaged>;
244 using dual_view_type_const = Kokkos::DualView<const impl_scalar_type**, Kokkos::LayoutStride, typename node_type::device_type, Kokkos::MemoryUnmanaged>;
245 using host_execution_space = typename dual_view_type::host_mirror_space;
246 using dev_execution_space = typename dual_view_type::t_dev::execution_space;
247
248 virtual typename dual_view_type::t_host_const_um getLocalViewHost(Access::ReadOnlyStruct) const {
249 throw std::runtime_error("Dummy function getLocalViewHost(Access::ReadOnlyStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
250#ifndef __NVCC__
251 typename dual_view_type::t_host_um test;
252#endif
254 }
255
256 virtual typename dual_view_type::t_dev_const_um getLocalViewDevice(Access::ReadOnlyStruct) const {
257 throw std::runtime_error("Dummy function getLocalViewDevice(Access::ReadOnlyStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
258#ifndef __NVCC__
259 typename dual_view_type::t_dev_um test;
260#endif
262 }
263
264 virtual typename dual_view_type::t_host_um getLocalViewHost(Access::OverwriteAllStruct) const {
265 throw std::runtime_error("Dummy function getLocalViewHost(Access::OverwriteAllStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
266#ifndef __NVCC__
267 typename dual_view_type::t_host_um test;
268#endif
270 }
271
272 virtual typename dual_view_type::t_dev_um getLocalViewDevice(Access::OverwriteAllStruct) const {
273 throw std::runtime_error("Dummy function getLocalViewDevice(Access::OverwriteAllStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
274#ifndef __NVCC__
275 typename dual_view_type::t_dev_um test;
276#endif
278 }
279
280 virtual typename dual_view_type::t_host_um getLocalViewHost(Access::ReadWriteStruct) const {
281 throw std::runtime_error("Dummy function getLocalViewHost(Access::ReadWriteStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
282#ifndef __NVCC__
283 typename dual_view_type::t_host_um test;
284#endif
286 }
287
288 virtual typename dual_view_type::t_dev_um getLocalViewDevice(Access::ReadWriteStruct) const {
289 throw std::runtime_error("Dummy function getLocalViewDevice(Access::ReadWriteStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
290#ifndef __NVCC__
291 typename dual_view_type::t_dev_um test;
292#endif
294 }
295
297
298 protected:
305
306}; // MultiVector class
307
308} // namespace Xpetra
309
310#define XPETRA_MULTIVECTOR_SHORT
311
312#endif // XPETRA_MULTIVECTOR_DECL_HPP
static const EVerbosityLevel verbLevel_default
virtual void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)=0
Replace value, using global (row) index.
virtual void randomize(const Scalar &minVal, const Scalar &maxVal, bool bUseXpetraImplementation=false)=0
Set multi-vector values to random numbers.
virtual size_t getNumVectors() const =0
Number of columns in the multivector.
virtual dual_view_type::t_dev_um getLocalViewDevice(Access::OverwriteAllStruct) const
Kokkos::DualView< const impl_scalar_type **, Kokkos::LayoutStride, typename node_type::device_type, Kokkos::MemoryUnmanaged > dual_view_type_const
virtual void putScalar(const Scalar &value)=0
Set all values in the multivector with the given value.
virtual void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)=0
virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const =0
Const view of the local values in a particular vector of this multivector.
virtual void norm1(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const =0
Compute 1-norm of each vector in multi-vector.
typename dual_view_type::t_dev::execution_space dev_execution_space
virtual void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)=0
Put element-wise absolute values of input Multi-vector in target: A = abs(this).
virtual void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)=0
Put element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,...
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
typename dual_view_type::host_mirror_space host_execution_space
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)
Assignment operator: Does a deep copy.
virtual void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &beta)=0
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
virtual void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)=0
Add value to existing value, using local (row) index.
virtual Teuchos::RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(size_t j)=0
Return a Vector which is a nonconst view of column j.
virtual dual_view_type::t_dev_um getLocalViewDevice(Access::ReadWriteStruct) const
virtual size_t getLocalLength() const =0
Local number of rows on the calling process.
virtual void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &gamma)=0
Update multi-vector with scaled values of A and B, this = gamma*this + alpha*A + beta*B.
virtual Teuchos::RCP< const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVector(size_t j) const =0
Return a Vector which is a const view of column j.
virtual void scale(Teuchos::ArrayView< const Scalar > alpha)=0
Scale the current values of a multi-vector, this[j] = alpha[j]*this[j].
virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)=0
Add value to existing value, using global (row) index.
virtual void randomize(bool bUseXpetraImplementation=false)=0
Set multi-vector values to random numbers.
virtual void normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const =0
Compute Inf-norm of each vector in multi-vector.
virtual dual_view_type::t_host_const_um getLocalViewHost(Access::ReadOnlyStruct) const
virtual void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const =0
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
virtual dual_view_type::t_dev_const_um getLocalViewDevice(Access::ReadOnlyStruct) const
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutStride, typename node_type::device_type, Kokkos::MemoryUnmanaged > dual_view_type
virtual void scale(const Scalar &alpha)=0
Scale the current values of a multi-vector, this = alpha*this.
virtual std::string description() const =0
A simple one-line description of this object.
virtual void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)=0
Implementation of the assignment operator (operator=); does a deep copy.
virtual void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< Scalar > &dots) const =0
Compute dot product of each corresponding pair of vectors, dots[i] = this[i].dot(A[i]).
virtual void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)=0
Update multi-vector values with scaled values of A, this = beta*this + alpha*A.
virtual void meanValue(const Teuchos::ArrayView< Scalar > &means) const =0
virtual void elementWiseMultiply(Scalar scalarAB, const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Scalar scalarThis)=0
Multiply a Vector A elementwise by a MultiVector B.
virtual ~MultiVector()
Destructor.
virtual void setSeed(unsigned int seed)=0
Set seed for Random function.
virtual dual_view_type::t_host_um getLocalViewHost(Access::ReadWriteStruct) const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const =0
Print the object with the given verbosity level to a FancyOStream.
virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)=0
View of the local values in a particular vector of this multivector.
virtual global_size_t getGlobalLength() const =0
Global number of rows in the multivector.
virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)=0
Replace value, using local (row) index.
virtual dual_view_type::t_host_um getLocalViewHost(Access::OverwriteAllStruct) const
virtual bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const =0
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
size_t global_size_t
Global size_t object.