Xpetra_MultiVector.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_HPP
47 #define XPETRA_MULTIVECTOR_HPP
48 
49 /* this file is automatically generated - do not edit (see script/interfaces.py) */
50 
51 #include <Teuchos_LabeledObject.hpp>
52 #include <Teuchos_DataAccess.hpp>
53 #include <Teuchos_BLAS_types.hpp>
54 #include <Teuchos_Range1D.hpp>
55 #include "Xpetra_ConfigDefs.hpp"
56 #include "Xpetra_DistObject.hpp"
57 #include "Xpetra_Map.hpp"
58 
59 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
60 #include <Kokkos_Core.hpp>
61 #include <Kokkos_DualView.hpp>
62 #include <Kokkos_ArithTraits.hpp>
63 #endif
64 
65 namespace Xpetra {
66 
67 #ifndef DOXYGEN_SHOULD_SKIP_THIS
68  // forward declaration of Vector, needed to prevent circular inclusions
69  template<class S, class LO, class GO, class N> class Vector;
70 #endif
71 
72  template <class Scalar = double,
73  class LocalOrdinal = Map<>::local_ordinal_type,
74  class GlobalOrdinal = typename Map<LocalOrdinal>::global_ordinal_type,
75  class Node = typename Map<LocalOrdinal, GlobalOrdinal>::node_type>
77  : public DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node >
78  {
79  public:
80  typedef Scalar scalar_type;
81  typedef LocalOrdinal local_ordinal_type;
82  typedef GlobalOrdinal global_ordinal_type;
83  typedef Node node_type;
84 
86 
87 
89  virtual ~MultiVector() { }
90 
103  assign (rhs); // dispatch to protected virtual method
104  return *this;
105  }
106 
108 
110 
112  virtual void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)= 0;
113 
115  virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)= 0;
116 
118  virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)= 0;
119 
121  virtual void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)= 0;
122 
124  virtual void putScalar(const Scalar &value)= 0;
125 
127 
129 
130 
133 
136 
138  virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const = 0;
139 
141  virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)= 0;
142 
144 
146 
147 
150 
153 
156 
158  virtual void scale(const Scalar &alpha)= 0;
159 
161  virtual void scale (Teuchos::ArrayView< const Scalar > alpha) = 0;
162 
164  virtual void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)= 0;
165 
167  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;
168 
170  virtual void norm1(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const = 0;
171 
173  virtual void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const = 0;
174 
176  virtual void normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const = 0;
177 
179  virtual void meanValue(const Teuchos::ArrayView< Scalar > &means) const = 0;
180 
182  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;
183 
186 
188 
190 
191 
193  virtual size_t getNumVectors() const = 0;
194 
196  virtual size_t getLocalLength() const = 0;
197 
199  virtual global_size_t getGlobalLength() const = 0;
200 
201  // \brief Checks to see if the local length, number of vectors and size of Scalar type match
202  virtual bool isSameSize(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> & vec) const =0;
203 
205 
207 
208 
210  virtual std::string description() const = 0;
211 
214 
215  virtual void replaceMap(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& map) = 0;
216 
218 
220 
221 
223  virtual void setSeed(unsigned int seed)= 0;
224 
225 
226  virtual void randomize(bool bUseXpetraImplementation = false)= 0;
227 
229  virtual void Xpetra_randomize()
230  {
231  typedef Teuchos::ScalarTraits<Scalar> SCT;
232 
233  const size_t numVectors = getNumVectors();
234  for (size_t i = 0; i < numVectors; i++)
235  {
237 
238  const size_t myLength = getLocalLength();
239  for(size_t j=0; j<myLength; j++)
240  {
241  datai[j] = SCT::random();
242  }
243  }
244  }
245 
246 
247 
248 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
249  typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
250  typedef Kokkos::DualView<impl_scalar_type**, Kokkos::LayoutStride,
251  typename node_type::execution_space,
252  Kokkos::MemoryUnmanaged> dual_view_type;
253  typedef typename dual_view_type::host_mirror_space host_execution_space;
254  typedef typename dual_view_type::t_dev::execution_space dev_execution_space;
255 
256  /*typedef Kokkos::View<impl_scalar_type**,
257  Kokkos::LayoutStride,
258  typename node_type::execution_space,
259  Kokkos::MemoryUnmanaged> unmanaged_host_view_type;
260 
261  typedef Kokkos::View<impl_scalar_type**,
262  Kokkos::LayoutStride,
263  typename node_type::execution_space,
264  Kokkos::MemoryUnmanaged> unmanaged_device_view_type;*/
265 
271  template<class TargetDeviceType>
272  typename Kokkos::Impl::if_c<
273  Kokkos::Impl::is_same<
274  typename dev_execution_space::memory_space,
275  typename TargetDeviceType::memory_space>::value,
276  typename dual_view_type::t_dev_um,
277  typename dual_view_type::t_host_um>::type
278  getLocalView () const {
279  if(Kokkos::Impl::is_same<
280  typename host_execution_space::memory_space,
281  typename TargetDeviceType::memory_space
282  >::value) {
283  return getHostLocalView();
284  } else {
285  return getDeviceLocalView();
286  }
287  }
288 
289  virtual typename dual_view_type::t_host_um getHostLocalView () const {
290  typename dual_view_type::t_host_um test;
291  return test;
292  }
293  virtual typename dual_view_type::t_dev_um getDeviceLocalView() const {
294  typename dual_view_type::t_dev_um test;
295  return test;
296  }
297 
298 #endif
299 
301 
302  protected:
308  virtual void assign (const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& rhs) = 0;
309 
310  }; // MultiVector class
311 
312 } // Xpetra namespace
313 
314 #define XPETRA_MULTIVECTOR_SHORT
315 #endif // XPETRA_MULTIVECTOR_HPP
Xpetra::MultiVector::getLocalLength
virtual size_t getLocalLength() const =0
Local number of rows on the calling process.
Xpetra::MultiVector::operator=
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)
Assignment operator: Does a deep copy.
Definition: Xpetra_MultiVector.hpp:102
Xpetra::MultiVector::getDataNonConst
virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)=0
View of the local values in a particular vector of this multivector.
Teuchos_DataAccess.hpp
Xpetra
Xpetra namespace
Definition: Xpetra_BlockedCrsMatrix.hpp:86
Xpetra::global_size_t
size_t global_size_t
Global size_t object.
Definition: Xpetra_ConfigDefs.hpp:170
Xpetra::MultiVector::elementWiseMultiply
virtual void elementWiseMultiply(Scalar scalarAB, const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Scalar scalarThis)=0
Element-wise multiply of a Vector A with a MultiVector B.
Xpetra::MultiVector::global_ordinal_type
GlobalOrdinal global_ordinal_type
Definition: Xpetra_MultiVector.hpp:82
Xpetra::MultiVector::assign
virtual void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)=0
Implementation of the assignment operator (operator=); does a deep copy.
Xpetra::DistObject
Definition: Xpetra_DistObject.hpp:64
Xpetra::MultiVector
Definition: Xpetra_MultiVector.hpp:76
Xpetra::Map::local_ordinal_type
LocalOrdinal local_ordinal_type
Definition: Xpetra_Map.hpp:94
Xpetra::MultiVector::multiply
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).
Xpetra::MultiVector::putScalar
virtual void putScalar(const Scalar &value)=0
Set all values in the multivector with the given value.
Xpetra::MultiVector::sumIntoGlobalValue
virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)=0
Add value to existing value, using global (row) index.
Xpetra::MultiVector::Xpetra_randomize
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
Definition: Xpetra_MultiVector.hpp:229
Xpetra::MultiVector::getGlobalLength
virtual global_size_t getGlobalLength() const =0
Global number of rows in the multivector.
Xpetra::MultiVector::dot
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]).
Xpetra::MultiVector::getVectorNonConst
virtual Teuchos::RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(size_t j)=0
Return a Vector which is a nonconst view of column j.
Teuchos_Range1D.hpp
Xpetra::MultiVector::describe
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.
Xpetra::MultiVector::replaceMap
virtual void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)=0
Xpetra::MultiVector::scalar_type
Scalar scalar_type
Definition: Xpetra_MultiVector.hpp:80
Teuchos::EVerbosityLevel
EVerbosityLevel
Xpetra::MultiVector::getNumVectors
virtual size_t getNumVectors() const =0
Number of columns in the multivector.
Xpetra::MultiVector::node_type
Node node_type
Definition: Xpetra_MultiVector.hpp:83
Xpetra::MultiVector::sumIntoLocalValue
virtual void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)=0
Add value to existing value, using local (row) index.
Xpetra::MultiVector::getData
virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const =0
Const view of the local values in a particular vector of this multivector.
Teuchos::ArrayView
Xpetra::Map
Definition: Xpetra_Map.hpp:90
Teuchos::RCP
Xpetra::MultiVector::replaceGlobalValue
virtual void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)=0
Replace value, using global (row) index.
Xpetra::MultiVector::~MultiVector
virtual ~MultiVector()
Destructor.
Definition: Xpetra_MultiVector.hpp:89
Xpetra::MultiVector::abs
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).
Xpetra::MultiVector::isSameSize
virtual bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const =0
Xpetra::MultiVector::norm2
virtual void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const =0
Xpetra::MultiVector::scale
virtual void scale(const Scalar &alpha)=0
Scale the current values of a multi-vector, this = alpha*this.
Xpetra::Vector
Definition: Xpetra_Vector_fwd.hpp:51
Teuchos::ArrayRCP
Xpetra::MultiVector::reciprocal
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,...
Xpetra::MultiVector::update
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.
Xpetra::MultiVector::meanValue
virtual void meanValue(const Teuchos::ArrayView< Scalar > &means) const =0
Compute mean (average) value of each vector in multi-vector. The outcome of this routine is undefined...
Teuchos::basic_FancyOStream
Xpetra::MultiVector::getVector
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.
Teuchos::ScalarTraits
Xpetra::MultiVector::local_ordinal_type
LocalOrdinal local_ordinal_type
Definition: Xpetra_MultiVector.hpp:81
Xpetra_ConfigDefs.hpp
Xpetra::MultiVector::setSeed
virtual void setSeed(unsigned int seed)=0
Set seed for Random function.
Xpetra::Map::global_ordinal_type
GlobalOrdinal global_ordinal_type
Definition: Xpetra_Map.hpp:95
Teuchos_BLAS_types.hpp
Xpetra_DistObject.hpp
Xpetra::MultiVector::description
virtual std::string description() const =0
A simple one-line description of this object.
Xpetra::MultiVector::norm1
virtual void norm1(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const =0
Compute 1-norm of each vector in multi-vector.
Xpetra::MultiVector::randomize
virtual void randomize(bool bUseXpetraImplementation=false)=0
Xpetra::MultiVector::replaceLocalValue
virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)=0
Replace value, using local (row) index.
Teuchos::ScalarTraits::magnitudeType
T magnitudeType
Xpetra::Map::node_type
Node node_type
Definition: Xpetra_Map.hpp:96
Xpetra::MultiVector::normInf
virtual void normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const =0
Compute Inf-norm of each vector in multi-vector.
Teuchos::Describable::verbLevel_default
static const EVerbosityLevel verbLevel_default
Teuchos::ETransp
ETransp
Xpetra_Map.hpp