Xpetra  Version of the Day
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 
50 #include <Teuchos_LabeledObject.hpp>
51 #include <Teuchos_DataAccess.hpp>
52 #include <Teuchos_BLAS_types.hpp>
53 #include <Teuchos_Range1D.hpp>
54 
55 #include "Xpetra_ConfigDefs.hpp"
56 #include "Xpetra_DistObject.hpp"
57 #include "Xpetra_Map_decl.hpp"
58 
59 #include "Xpetra_Access.hpp"
60 
61 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
62  #include <Kokkos_Core.hpp>
63  #include <Kokkos_DualView.hpp>
64  #include <Kokkos_ArithTraits.hpp>
65 #endif
66 
67 namespace Xpetra {
68 
69 
70 #ifndef DOXYGEN_SHOULD_SKIP_THIS
71 // forward declaration of Vector, needed to prevent circular inclusions
72 template<class S, class LO, class GO, class N> class Vector;
73 #endif
74 
75 
76 template<class Scalar,
77  class LocalOrdinal,
78  class GlobalOrdinal,
81  : public DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node>
82 {
83 
84  public:
85 
86  typedef Scalar scalar_type;
87  typedef LocalOrdinal local_ordinal_type;
88  typedef GlobalOrdinal global_ordinal_type;
89  typedef Node node_type;
90 
92 
93 
95  virtual ~MultiVector();
96 
97 
110 
111 
113 
115 
116 
118  virtual void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar& value) = 0;
119 
120 
122  virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar& value) = 0;
123 
124 
126  virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar& value) = 0;
127 
128 
130  virtual void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar& value) = 0;
131 
132 
134  virtual void putScalar(const Scalar& value) = 0;
135 
136 
138 
140 
141 
142 
145 
146 
149 
150 
152  virtual Teuchos::ArrayRCP<const Scalar> getData(size_t j) const = 0;
153 
154 
157 
158 
160 
162 
163 
164 
167 
168 
171 
172 
175 
176 
178  virtual void scale(const Scalar& alpha) = 0;
179 
180 
182  virtual void scale(Teuchos::ArrayView<const Scalar> alpha) = 0;
183 
184 
186  virtual void update(const Scalar& alpha, const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A, const Scalar& beta) = 0;
187 
188 
190  virtual void update(const Scalar& alpha, const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
191  const Scalar& beta, const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& B,
192  const Scalar& gamma) = 0;
193 
194 
196  virtual void norm1(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms) const = 0;
197 
198 
200  virtual void norm2(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms) const = 0;
201 
202 
204  virtual void normInf(const Teuchos::ArrayView<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms) const = 0;
205 
206 
209  virtual void meanValue(const Teuchos::ArrayView<Scalar>& means) const = 0;
210 
211 
213  virtual void multiply(Teuchos::ETransp transA,
214  Teuchos::ETransp transB,
215  const Scalar& alpha,
218  const Scalar& beta) = 0;
219 
220 
248  virtual void elementWiseMultiply(Scalar scalarAB,
251  Scalar scalarThis) = 0;
252 
253 
255 
257 
258 
259 
261  virtual size_t getNumVectors() const = 0;
262 
263 
265  virtual size_t getLocalLength() const = 0;
266 
267 
269  virtual global_size_t getGlobalLength() const = 0;
270 
271 
272  // \brief Checks to see if the local length, number of vectors and size of Scalar type match
274 
275 
277 
279 
280 
281 
283  virtual std::string description() const = 0;
284 
285 
288 
289 
290  virtual void replaceMap(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>& map) = 0;
291 
292 
294 
296 
297 
298 
300  virtual void setSeed(unsigned int seed) = 0;
301 
302 
304  virtual void randomize(bool bUseXpetraImplementation = false) = 0;
305 
306 
308  virtual void Xpetra_randomize();
309 
310 
311 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
312 
313  using impl_scalar_type = typename Kokkos::Details::ArithTraits<Scalar>::val_type;
314  using dual_view_type = Kokkos::DualView<impl_scalar_type**, Kokkos::LayoutStride, typename node_type::device_type, Kokkos::MemoryUnmanaged>;
315  using dual_view_type_const = Kokkos::DualView<const impl_scalar_type**, Kokkos::LayoutStride, typename node_type::device_type, Kokkos::MemoryUnmanaged>;
316  using host_execution_space = typename dual_view_type::host_mirror_space;
317  using dev_execution_space = typename dual_view_type::t_dev::execution_space;
318 
319 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
325  template<class TargetDeviceType>
326  typename Kokkos::Impl::if_c<std::is_same<typename dev_execution_space::memory_space, typename TargetDeviceType::memory_space>::value,
327  typename dual_view_type::t_dev_um,
328  typename dual_view_type::t_host_um>::type
329  getLocalView() const
330  {
331  if(std::is_same<
332  typename host_execution_space::memory_space,
333  typename TargetDeviceType::memory_space
334  >::value)
335  {
336  return getHostLocalView();
337  } else {
338  return getDeviceLocalView();
339  }
340  }
341 
342 
343  typename dual_view_type::t_host_um getHostLocalView () const
344  {
345  return getHostLocalView(Access::ReadWrite);
346  }
347 
348 
349  typename dual_view_type::t_dev_um getDeviceLocalView() const
350  {
351  return getDeviceLocalView(Access::ReadWrite);
352  }
353 
354 #endif
355 
356  virtual typename dual_view_type::t_host_const_um getHostLocalView (Access::ReadOnlyStruct) const
357  {
358  throw std::runtime_error("Dummy function getHostLocalView, should be overwritten at"+std::string(__FILE__)+":"+std::to_string(__LINE__));
359 #ifndef __NVCC__
360  typename dual_view_type::t_host_um test;
361 #endif
363  }
364 
365 
366  virtual typename dual_view_type::t_dev_const_um getDeviceLocalView(Access::ReadOnlyStruct) const
367  {
368  throw std::runtime_error("Dummy function getHostLocalView, should be overwritten at"+std::string(__FILE__)+":"+std::to_string(__LINE__));
369 #ifndef __NVCC__
370  typename dual_view_type::t_dev_um test;
371 #endif
373  }
374 
375  virtual typename dual_view_type::t_host_um getHostLocalView (Access::OverwriteAllStruct) const
376  {
377  throw std::runtime_error("Dummy function getHostLocalView, should be overwritten at"+std::string(__FILE__)+":"+std::to_string(__LINE__));
378 #ifndef __NVCC__
379  typename dual_view_type::t_host_um test;
380 #endif
382  }
383 
384 
385  virtual typename dual_view_type::t_dev_um getDeviceLocalView(Access::OverwriteAllStruct) const
386  {
387  throw std::runtime_error("Dummy function getHostLocalView, should be overwritten at"+std::string(__FILE__)+":"+std::to_string(__LINE__));
388 #ifndef __NVCC__
389  typename dual_view_type::t_dev_um test;
390 #endif
392  }
393 
394  virtual typename dual_view_type::t_host_um getHostLocalView (Access::ReadWriteStruct) const
395  {
396  throw std::runtime_error("Dummy function getHostLocalView, should be overwritten at"+std::string(__FILE__)+":"+std::to_string(__LINE__));
397 #ifndef __NVCC__
398  typename dual_view_type::t_host_um test;
399 #endif
401  }
402 
403 
404  virtual typename dual_view_type::t_dev_um getDeviceLocalView(Access::ReadWriteStruct) const
405  {
406  throw std::runtime_error("Dummy function getHostLocalView, should be overwritten at"+std::string(__FILE__)+":"+std::to_string(__LINE__));
407 #ifndef __NVCC__
408  typename dual_view_type::t_dev_um test;
409 #endif
411  }
412 
413 #endif // HAVE_XPETRA_KOKKOS_REFACTOR
414 
415 
417 
418 
419  protected:
420 
421 
428 
429 
430 }; // MultiVector class
431 
432 } // namespace Xpetra
433 
434 #define XPETRA_MULTIVECTOR_SHORT
435 
436 #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 size_t getNumVectors() const =0
Number of columns in the multivector.
virtual void putScalar(const Scalar &value)=0
Set all values in the multivector with the given value.
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 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,...
virtual Teuchos::RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(size_t j)=0
Return a Vector which is a nonconst view of column j.
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 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 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 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 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 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 global_size_t getGlobalLength() const =0
Global number of rows in the multivector.
virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)=0
View of the local values in a particular vector of this multivector.
virtual void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map)=0
virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)=0
Replace value, using local (row) index.
virtual bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const =0
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
constexpr struct ReadWriteStruct ReadWrite
Xpetra namespace
size_t global_size_t
Global size_t object.