46 #ifndef XPETRA_MULTIVECTOR_HPP 47 #define XPETRA_MULTIVECTOR_HPP 51 #include <Teuchos_LabeledObject.hpp> 52 #include <Teuchos_DataAccess.hpp> 53 #include <Teuchos_BLAS_types.hpp> 54 #include <Teuchos_Range1D.hpp> 59 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR 60 #include <Kokkos_Core.hpp> 61 #include <Kokkos_DualView.hpp> 62 #include <Kokkos_ArithTraits.hpp> 67 #ifndef DOXYGEN_SHOULD_SKIP_THIS 69 template<
class S,
class LO,
class GO,
class N>
class Vector;
72 template <
class Scalar = double,
77 :
public DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node >
112 virtual void replaceGlobalValue(GlobalOrdinal globalRow,
size_t vectorIndex,
const Scalar &value)= 0;
115 virtual void sumIntoGlobalValue(GlobalOrdinal globalRow,
size_t vectorIndex,
const Scalar &value)= 0;
118 virtual void replaceLocalValue(LocalOrdinal myRow,
size_t vectorIndex,
const Scalar &value)= 0;
121 virtual void sumIntoLocalValue(LocalOrdinal myRow,
size_t vectorIndex,
const Scalar &value)= 0;
124 virtual void putScalar(
const Scalar &value)= 0;
132 virtual Teuchos::RCP< const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > >
getVector(
size_t j)
const = 0;
135 virtual Teuchos::RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > >
getVectorNonConst(
size_t j)= 0;
138 virtual Teuchos::ArrayRCP< const Scalar >
getData(
size_t j)
const = 0;
158 virtual void scale(
const Scalar &alpha)= 0;
161 virtual void scale (Teuchos::ArrayView< const Scalar > alpha) = 0;
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;
170 virtual void norm1(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms)
const = 0;
173 virtual void norm2(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms)
const = 0;
176 virtual void normInf(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms)
const = 0;
179 virtual void meanValue(
const Teuchos::ArrayView< Scalar > &means)
const = 0;
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;
210 virtual void describe(Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default)
const = 0;
220 virtual void setSeed(
unsigned int seed)= 0;
223 virtual void randomize(
bool bUseXpetraImplementation =
false)= 0;
228 typedef Teuchos::ScalarTraits<Scalar> SCT;
231 for (
size_t i = 0; i < numVectors; i++)
236 for(
size_t j=0; j<myLength; j++)
238 datai[j] = SCT::random();
243 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR 244 typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
245 typedef Kokkos::DualView<impl_scalar_type**, Kokkos::LayoutStride,
246 typename node_type::execution_space,
247 Kokkos::MemoryUnmanaged> dual_view_type;
248 typedef typename dual_view_type::host_mirror_space host_execution_space;
249 typedef typename dual_view_type::t_dev::execution_space dev_execution_space;
266 template<
class TargetDeviceType>
267 typename Kokkos::Impl::if_c<
268 Kokkos::Impl::is_same<
269 typename dev_execution_space::memory_space,
270 typename TargetDeviceType::memory_space>::value,
271 typename dual_view_type::t_dev_um,
272 typename dual_view_type::t_host_um>::type
273 getLocalView ()
const {
274 if(Kokkos::Impl::is_same<
275 typename host_execution_space::memory_space,
276 typename TargetDeviceType::memory_space
278 return getHostLocalView();
280 return getDeviceLocalView();
284 virtual typename dual_view_type::t_host_um getHostLocalView ()
const {
285 typename dual_view_type::t_host_um test;
288 virtual typename dual_view_type::t_dev_um getDeviceLocalView()
const {
289 typename dual_view_type::t_dev_um test;
303 virtual void assign (
const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& rhs) = 0;
309 #define XPETRA_MULTIVECTOR_SHORT 310 #endif // XPETRA_MULTIVECTOR_HPP MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)
Assignment operator: Does a deep copy.
virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)=0
View of the local values in a particular vector of this multivector.
virtual void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const =0
virtual void normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const =0
Compute Inf-norm of each vector in multi-vector.
LocalOrdinal local_ordinal_type
GlobalOrdinal global_ordinal_type
virtual std::string description() const =0
A simple one-line description of this object.
virtual void randomize(bool bUseXpetraImplementation=false)=0
virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)=0
Add value to existing value, using global (row) index.
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
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 assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)=0
Implementation of the assignment operator (operator=); does a deep copy.
virtual void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)=0
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 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 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
Element-wise multiply of a Vector A with a MultiVector B.
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).
LocalOrdinal local_ordinal_type
virtual size_t getLocalLength() const =0
Local number of rows on the calling process.
size_t global_size_t
Global size_t object.
virtual global_size_t getGlobalLength() const =0
Global number of rows in the multivector.
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...
GlobalOrdinal global_ordinal_type
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 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 replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)=0
Replace value, using global (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 ~MultiVector()
Destructor.
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::ArrayRCP< const Scalar > getData(size_t j) const =0
Const view of the local values in a particular vector of this 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.