Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_MultiVector_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_MULTIVECTOR_DECL_HPP
47 #define XPETRA_MULTIVECTOR_DECL_HPP
48 
49 #include <Teuchos_LabeledObject.hpp>
50 #include <Teuchos_DataAccess.hpp>
51 #include <Teuchos_BLAS_types.hpp>
52 #include <Teuchos_Range1D.hpp>
53 
54 #include "Xpetra_ConfigDefs.hpp"
55 #include "Xpetra_DistObject.hpp"
56 #include "Xpetra_Map_decl.hpp"
57 
58 #include "Xpetra_Access.hpp"
59 
60 #include <Kokkos_Core.hpp>
61 #include <Kokkos_DualView.hpp>
62 #include <Kokkos_ArithTraits.hpp>
63 
64 namespace Xpetra {
65 
66 #ifndef DOXYGEN_SHOULD_SKIP_THIS
67 // forward declaration of Vector, needed to prevent circular inclusions
68 template <class S, class LO, class GO, class N>
69 class Vector;
70 #endif
71 
72 template <class Scalar,
73  class LocalOrdinal,
74  class GlobalOrdinal,
75  class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
77  : public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
78  public:
79  typedef Scalar scalar_type;
80  typedef LocalOrdinal local_ordinal_type;
81  typedef GlobalOrdinal global_ordinal_type;
82  typedef Node node_type;
83 
85 
86 
88  virtual ~MultiVector();
89 
102 
104 
106 
108  virtual void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar& value) = 0;
109 
111  virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar& value) = 0;
112 
114  virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar& value) = 0;
115 
117  virtual void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar& value) = 0;
118 
120  virtual void putScalar(const Scalar& value) = 0;
121 
123 
125 
126 
128  virtual Teuchos::RCP<const Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> getVector(size_t j) const = 0;
129 
131  virtual Teuchos::RCP<Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> getVectorNonConst(size_t j) = 0;
132 
134  virtual Teuchos::ArrayRCP<const Scalar> getData(size_t j) const = 0;
135 
137  virtual Teuchos::ArrayRCP<Scalar> getDataNonConst(size_t j) = 0;
138 
140 
142 
143 
145  virtual void dot(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A, const Teuchos::ArrayView<Scalar>& dots) const = 0;
146 
149 
152 
154  virtual void scale(const Scalar& alpha) = 0;
155 
157  virtual void scale(Teuchos::ArrayView<const Scalar> alpha) = 0;
158 
160  virtual void update(const Scalar& alpha, const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A, const Scalar& beta) = 0;
161 
163  virtual void update(const Scalar& alpha, const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
164  const Scalar& beta, const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
165  const Scalar& gamma) = 0;
166 
168  virtual void norm1(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms) const = 0;
169 
171  virtual void norm2(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms) const = 0;
172 
174  virtual void normInf(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms) const = 0;
175 
178  virtual void meanValue(const Teuchos::ArrayView<Scalar>& means) const = 0;
179 
181  virtual void multiply(Teuchos::ETransp transA,
182  Teuchos::ETransp transB,
183  const Scalar& alpha,
186  const Scalar& beta) = 0;
187 
215  virtual void elementWiseMultiply(Scalar scalarAB,
218  Scalar scalarThis) = 0;
219 
221 
223 
224 
226  virtual size_t getNumVectors() const = 0;
227 
229  virtual size_t getLocalLength() const = 0;
230 
232  virtual global_size_t getGlobalLength() const = 0;
233 
234  // \brief Checks to see if the local length, number of vectors and size of Scalar type match
235  virtual bool isSameSize(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& vec) const = 0;
236 
238 
240 
241 
243  virtual std::string description() const = 0;
244 
246  virtual void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const = 0;
247 
248  virtual void replaceMap(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>& map) = 0;
249 
251 
253 
254 
256  virtual void setSeed(unsigned int seed) = 0;
257 
259  virtual void randomize(bool bUseXpetraImplementation = false) = 0;
260 
262  virtual void randomize(const Scalar& minVal, const Scalar& maxVal, bool bUseXpetraImplementation = false) = 0;
263 
265  virtual void Xpetra_randomize();
266 
268  virtual void Xpetra_randomize(const Scalar& minVal, const Scalar& maxVal);
269 
270  using impl_scalar_type = typename Kokkos::ArithTraits<Scalar>::val_type;
271  using dual_view_type = Kokkos::DualView<impl_scalar_type**, Kokkos::LayoutStride, typename node_type::device_type, Kokkos::MemoryUnmanaged>;
272  using dual_view_type_const = Kokkos::DualView<const impl_scalar_type**, Kokkos::LayoutStride, typename node_type::device_type, Kokkos::MemoryUnmanaged>;
273  using host_execution_space = typename dual_view_type::host_mirror_space;
274  using dev_execution_space = typename dual_view_type::t_dev::execution_space;
275 
276  virtual typename dual_view_type::t_host_const_um getHostLocalView(Access::ReadOnlyStruct) const {
277  throw std::runtime_error("Dummy function getHostLocalView(Access::ReadOnlyStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
278 #ifndef __NVCC__
279  typename dual_view_type::t_host_um test;
280 #endif
281  TEUCHOS_UNREACHABLE_RETURN(test);
282  }
283 
284  virtual typename dual_view_type::t_dev_const_um getDeviceLocalView(Access::ReadOnlyStruct) const {
285  throw std::runtime_error("Dummy function getDeviceLocalView(Access::ReadOnlyStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
286 #ifndef __NVCC__
287  typename dual_view_type::t_dev_um test;
288 #endif
289  TEUCHOS_UNREACHABLE_RETURN(test);
290  }
291 
292  virtual typename dual_view_type::t_host_um getHostLocalView(Access::OverwriteAllStruct) const {
293  throw std::runtime_error("Dummy function getHostLocalView(Access::OverwriteAllStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
294 #ifndef __NVCC__
295  typename dual_view_type::t_host_um test;
296 #endif
297  TEUCHOS_UNREACHABLE_RETURN(test);
298  }
299 
300  virtual typename dual_view_type::t_dev_um getDeviceLocalView(Access::OverwriteAllStruct) const {
301  throw std::runtime_error("Dummy function getDeviceLocalView(Access::OverwriteAllStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
302 #ifndef __NVCC__
303  typename dual_view_type::t_dev_um test;
304 #endif
305  TEUCHOS_UNREACHABLE_RETURN(test);
306  }
307 
308  virtual typename dual_view_type::t_host_um getHostLocalView(Access::ReadWriteStruct) const {
309  throw std::runtime_error("Dummy function getHostLocalView(Access::ReadWriteStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
310 #ifndef __NVCC__
311  typename dual_view_type::t_host_um test;
312 #endif
313  TEUCHOS_UNREACHABLE_RETURN(test);
314  }
315 
316  virtual typename dual_view_type::t_dev_um getDeviceLocalView(Access::ReadWriteStruct) const {
317  throw std::runtime_error("Dummy function getDeviceLocalView(Access::ReadWriteStruct), should be overwritten at" + std::string(__FILE__) + ":" + std::to_string(__LINE__));
318 #ifndef __NVCC__
319  typename dual_view_type::t_dev_um test;
320 #endif
321  TEUCHOS_UNREACHABLE_RETURN(test);
322  }
323 
325 
326  protected:
333 
334 }; // MultiVector class
335 
336 } // namespace Xpetra
337 
338 #define XPETRA_MULTIVECTOR_SHORT
339 
340 #endif // XPETRA_MULTIVECTOR_DECL_HPP
virtual void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map)=0
virtual void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const =0
virtual dual_view_type::t_dev_const_um getDeviceLocalView(Access::ReadOnlyStruct) const
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_um getHostLocalView(Access::ReadWriteStruct) const
virtual std::string description() const =0
A simple one-line description of this object.
virtual void randomize(bool bUseXpetraImplementation=false)=0
Set multi-vector values to random numbers.
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 void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)=0
Add value to existing value, using global (row) index.
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 setSeed(unsigned int seed)=0
Set seed for Random function.
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)
Assignment operator: Does a deep copy.
virtual void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)=0
Implementation of the assignment operator (operator=); does a deep copy.
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,j).
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 sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)=0
Add value to existing value, using local (row) index.
virtual dual_view_type::t_dev_um getDeviceLocalView(Access::ReadWriteStruct) const
virtual bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const =0
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 ~MultiVector()
Destructor.
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 scale(const Scalar &alpha)=0
Scale the current values of a multi-vector, this = alpha*this.
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.
typename dual_view_type::t_dev::execution_space dev_execution_space
virtual void norm1(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const =0
Compute 1-norm of each vector in multi-vector.
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 size_t getLocalLength() const =0
Local number of rows on the calling process.
virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)=0
View of the local values in a particular vector of this multivector.
size_t global_size_t
Global size_t object.
virtual global_size_t getGlobalLength() const =0
Global number of rows in the multivector.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutStride, typename node_type::device_type, Kokkos::MemoryUnmanaged > dual_view_type
virtual void meanValue(const Teuchos::ArrayView< Scalar > &means) const =0
virtual dual_view_type::t_host_um getHostLocalView(Access::OverwriteAllStruct) const
typename dual_view_type::host_mirror_space host_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 dual_view_type::t_dev_um getDeviceLocalView(Access::OverwriteAllStruct) const
virtual dual_view_type::t_host_const_um getHostLocalView(Access::ReadOnlyStruct) const
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]).
typename Kokkos::ArithTraits< int >::val_type impl_scalar_type
virtual void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)=0
Replace value, using global (row) index.
virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)=0
Replace value, using local (row) index.
virtual size_t getNumVectors() const =0
Number of columns in the multivector.
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.