47 #ifndef XPETRA_BLOCKEDVECTOR_HPP 48 #define XPETRA_BLOCKEDVECTOR_HPP 60 #ifndef DOXYGEN_SHOULD_SKIP_THIS 62 template<
class S,
class LO,
class GO,
class N>
class Vector;
63 template<
class S,
class LO,
class GO,
class N>
class MapExtractor;
64 template<
class S,
class LO,
class GO,
class N>
class VectorFactory;
67 template <
class Scalar = double,
72 :
public virtual Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node >,
93 #undef XPETRA_BLOCKEDVECTOR_SHORT 125 Teuchos::RCP<const Vector> v) :
140 Teuchos::RCP<Vector> v) :
155 Teuchos::RCP<const Vector> v) :
170 Teuchos::RCP<Vector> v) :
245 virtual Teuchos::RCP< const Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
getVector(
size_t j)
const {
250 virtual Teuchos::RCP< Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
getVectorNonConst(
size_t j) {
255 virtual Teuchos::ArrayRCP< const Scalar >
getData(
size_t j)
const {
270 virtual void dot(
const MultiVector&A,
const Teuchos::ArrayView< Scalar > &dots)
const {
276 Teuchos::Array< Scalar > dots = Teuchos::Array<Scalar>(1);
295 virtual void scale(
const Scalar &alpha) {
301 virtual void scale (Teuchos::ArrayView< const Scalar > alpha) {
319 virtual typename Teuchos::ScalarTraits< Scalar >::magnitudeType
norm1()
const {
320 Teuchos::Array< typename Teuchos::ScalarTraits< Scalar>::magnitudeType > norm =
321 Teuchos::Array< typename Teuchos::ScalarTraits< Scalar>::magnitudeType >(1);
327 virtual typename Teuchos::ScalarTraits< Scalar >::magnitudeType
norm2()
const {
328 Teuchos::Array< typename Teuchos::ScalarTraits< Scalar>::magnitudeType > norm =
329 Teuchos::Array< typename Teuchos::ScalarTraits< Scalar>::magnitudeType >(1);
335 virtual typename Teuchos::ScalarTraits< Scalar >::magnitudeType
normInf()
const {
336 Teuchos::Array< typename Teuchos::ScalarTraits< Scalar>::magnitudeType > norm =
337 Teuchos::Array< typename Teuchos::ScalarTraits< Scalar>::magnitudeType >(1);
343 virtual void norm1(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms)
const {
348 virtual void norm2(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms)
const {
353 virtual void normInf(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms)
const {
358 virtual void meanValue(
const Teuchos::ArrayView< Scalar > &means)
const {
367 virtual void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB,
const Scalar &alpha,
const Vector&A,
const Vector&B,
const Scalar &beta) {
383 TEUCHOS_TEST_FOR_EXCEPTION(A.
getMap()->getNodeNumElements() != B.
getMap()->getNodeNumElements(),
Xpetra::Exceptions::RuntimeError,
"BlockedVector::elementWiseMultipy: A has " << A.
getMap()->getNodeNumElements() <<
" elements, B has " << B.
getMap()->getNodeNumElements() <<
".");
384 TEUCHOS_TEST_FOR_EXCEPTION(A.
getMap()->getGlobalNumElements() != B.
getMap()->getGlobalNumElements(),
Xpetra::Exceptions::RuntimeError,
"BlockedVector::elementWiseMultipy: A has " << A.
getMap()->getGlobalNumElements() <<
" elements, B has " << B.
getMap()->getGlobalNumElements() <<
".");
387 RCP<const Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>> rcpA = Teuchos::rcpFromRef(A);
388 RCP<const Vector> bmvec = Teuchos::rcpFromRef(B);
389 RCP<const BlockedVector> bbmvec = Teuchos::rcp_dynamic_cast<
const BlockedVector>(bmvec);
415 throw Xpetra::Exceptions::RuntimeError(
"BlockedVector::getLocalLength: routine not implemented. It has no value as one must iterate on the partial vectors.");
416 TEUCHOS_UNREACHABLE_RETURN(0);
421 return this->
getBlockedMap()->getFullMap()->getGlobalNumElements();
427 TEUCHOS_UNREACHABLE_RETURN(0);
437 return std::string(
"BlockedVector");
441 virtual void describe(Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default)
const {
443 for(
size_t r = 0; r < this->
getBlockedMap()->getNumMaps(); r++)
478 for(
size_t r = 0; r < this->
getBlockedMap()->getNumMaps(); ++r) {
484 virtual void randomize(
bool bUseXpetraImplementation =
false) {
485 for(
size_t r = 0; r < this->
getBlockedMap()->getNumMaps(); ++r) {
496 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR 497 typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
498 typedef Kokkos::DualView<impl_scalar_type**, Kokkos::LayoutStride,
499 typename node_type::execution_space,
500 Kokkos::MemoryUnmanaged> dual_view_type;
501 typedef typename dual_view_type::host_mirror_space host_execution_space;
502 typedef typename dual_view_type::t_dev::execution_space dev_execution_space;
509 template<
class TargetDeviceType>
510 typename Kokkos::Impl::if_c<
511 Kokkos::Impl::is_same<
512 typename dev_execution_space::memory_space,
513 typename TargetDeviceType::memory_space>::value,
514 typename dual_view_type::t_dev_um,
515 typename dual_view_type::t_host_um>::type
516 getLocalView ()
const {
517 if(Kokkos::Impl::is_same<
518 typename host_execution_space::memory_space,
519 typename TargetDeviceType::memory_space
521 return getHostLocalView();
523 return getDeviceLocalView();
527 virtual typename dual_view_type::t_host_um getHostLocalView ()
const {
528 typename dual_view_type::t_host_um test;
531 virtual typename dual_view_type::t_dev_um getDeviceLocalView()
const {
532 typename dual_view_type::t_dev_um test;
560 Teuchos::RCP<MultiVector>
Merge()
const {
587 #define XPETRA_BLOCKEDVECTOR_SHORT 588 #endif // XPETRA_BLOCKEDVECTOR_HPP virtual void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Export &exporter, CombineMode CM)
Import (using an Exporter).
virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Replace value, using local (row) index.
virtual void putScalar(const Scalar &value)
Set all values in the vector with the given value.
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2() const
Compute 2-norm of vector.
LocalOrdinal local_ordinal_type
virtual size_t getLocalLength() const
Local number of rows on the calling process.
virtual void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Teuchos::RCP< const Xpetra::BlockedMap< LocalOrdinal, GlobalOrdinal, Node > > getBlockedMap() const
Access function for the underlying Map this DistObject was constructed with.
virtual void norm1(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
virtual void dot(const MultiVector &A, const Teuchos::ArrayView< Scalar > &dots) const
Compute dot product of each corresponding pair of vectors, dots[i] = this[i].dot(A[i]).
GlobalOrdinal global_ordinal_type
virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this vector.
virtual void norm1(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
virtual void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Replace value, using global (row) index.
virtual void abs(const MultiVector &A)
Put element-wise absolute values of input vector in target: A = abs(this).
virtual Teuchos::RCP< const Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVector(size_t j) const
Return a Vector which is a const view of column j.
void setMultiVector(size_t r, Teuchos::RCP< const Vector > v, bool bThyraMode)
set partial Vector associated with block row r
GlobalOrdinal global_ordinal_type
virtual void normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute Inf-norm of each vector in multi-vector.
virtual void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value)
Add value to existing value, using local (row) index.
BlockedVector(Teuchos::RCP< const Xpetra::BlockedMap< LocalOrdinal, GlobalOrdinal, Node > > bmap, Teuchos::RCP< Vector > v)
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
virtual void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export &exporter, CombineMode CM)
Export (using an Importer).
virtual void scale(Teuchos::ArrayView< const Scalar > alpha)
Scale the current values of a vector, this[j] = alpha[j]*this[j].
Exception throws to report errors in the internal logical of the program.
virtual void replaceLocalValue(LocalOrdinal myRow, const Scalar &value)
Replace value, using local (row) index.
virtual void Xpetra_randomize()
Set vector values to random numbers. XPetra implementation.
virtual void reciprocal(const MultiVector &A)
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 &A, const Scalar &beta)
Update multi-vector values with scaled values of A, this = beta*this + alpha*A.
virtual void scale(const Scalar &alpha)
Scale the current values of a multi-vector, this = alpha*this.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
Teuchos::RCP< MultiVector > getMultiVector(size_t r) const
return partial multivector associated with block row r
virtual void replaceMap(const RCP< const Map > &map)
virtual void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using local (row) index.
virtual void update(const Scalar &alpha, const MultiVector &A, const Scalar &beta)
Update multi-vector values with scaled values of A, this = beta*this + alpha*A.
virtual bool isSameSize(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
Local number of rows on the calling process.
virtual void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using local (row) index.
virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
virtual void elementWiseMultiply(Scalar scalarAB, const Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Vector &B, Scalar scalarThis)
Element-wise multiply of a Vector A with a Vector B.
virtual void assign(const MultiVector &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Add value to existing value, using global (row) index.
virtual void dot(const MultiVector &A, const Teuchos::ArrayView< Scalar > &dots) const
Compute dot product of each corresponding pair of vectors, dots[i] = this[i].dot(A[i]).
BlockedVector(Teuchos::RCP< const Xpetra::MapExtractor< Scalar, LocalOrdinal, GlobalOrdinal, Node > > mapExtractor, Teuchos::RCP< Vector > v)
Teuchos::RCP< MultiVector > getMultiVector(size_t r, bool bThyraMode) const
return partial Vector associated with block row r
BlockedVector(Teuchos::RCP< const Xpetra::MapExtractor< Scalar, LocalOrdinal, GlobalOrdinal, Node > > mapExtractor, Teuchos::RCP< const Vector > v)
virtual void setSeed(unsigned int seed)
Set seed for Random function.
Teuchos::RCP< MultiVector > Merge() const
merge BlockedVector blocks to a single Vector
virtual void randomize(bool bUseXpetraImplementation=false)
Teuchos::RCP< MultiVector > getMultiVector(size_t r) const
return partial Vector associated with block row r
virtual Scalar dot(const Vector &A) const
Computes dot product of this Vector against input Vector x.
Teuchos::RCP< const Map > getMap() const
Access function for the underlying Map this DistObject was constructed with.
virtual void abs(const MultiVector &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this).
virtual size_t getNumVectors() const
Number of columns in the Vector.
virtual void replaceMap(const RCP< const Map > &map)
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
LocalOrdinal local_ordinal_type
virtual void assign(const MultiVector &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
virtual void normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute Inf-norm of each vector in multi-vector.
virtual void elementWiseMultiply(Scalar scalarAB, const Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector &B, Scalar scalarThis)
Element-wise multiply of a Vector A with a MultiVector B.
virtual Teuchos::RCP< const Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVector(size_t j) const
Return a Vector which is a const view of column j.
virtual Scalar meanValue() const
Compute mean (average) value of this Vector.
virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this vector.
void setMultiVector(size_t r, Teuchos::RCP< const MultiVector > v, bool bThyraMode)
set partial multivector associated with block row r
BlockedVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector &rhs)
Assignment operator: Does a deep copy.
virtual void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Import &importer, CombineMode CM)
Import.
virtual void scale(const Scalar &alpha)
Scale the current values of a vector, this = alpha*this.
size_t global_size_t
Global size_t object.
Teuchos::RCP< MultiVector > Merge() const
merge BlockedMultiVector blocks to a single MultiVector
virtual Teuchos::RCP< Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(size_t j)
Return a Vector which is a nonconst view of column j.
virtual global_size_t getGlobalLength() const
Global number of rows in the Vector.
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType normInf() const
Compute Inf-norm in vector.
BlockedVector(const Teuchos::RCP< const BlockedMap > &map, bool zeroOut=true)
Constructor.
virtual void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Replace value, using global (row) index.
virtual void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import &importer, CombineMode CM)
Export.
virtual void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
virtual void update(const Scalar &alpha, const MultiVector &A, const Scalar &beta, const MultiVector &B, const Scalar &gamma)
Update vector with scaled values of A and B, this = gamma*this + alpha*A + beta*B.
#define XPETRA_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Replace value, using local (row) index.
virtual void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
virtual void meanValue(const Teuchos::ArrayView< Scalar > &means) const
Compute mean (average) value of each vector in vector. The outcome of this routine is undefined for n...
virtual void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector &A, const MultiVector &B, const Scalar &beta)
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
virtual void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const Vector &A, const Vector &B, const Scalar &beta)
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
CombineMode
Xpetra::Combine Mode enumerable type.
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm1() const
Compute 1-norm of vector.
virtual ~BlockedVector()
Destructor.
#define XPETRA_MONITOR(funcName)
virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using global (row) index.
virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
virtual void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Replace value, using global (row) index.
BlockedVector(Teuchos::RCP< const Xpetra::BlockedMap< LocalOrdinal, GlobalOrdinal, Node > > bmap, Teuchos::RCP< const Vector > v)
virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using global (row) index.
virtual Teuchos::RCP< Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(size_t j)
Return a Vector which is a nonconst view of column j.
virtual std::string description() const
A simple one-line description of this object.
virtual void reciprocal(const MultiVector &A)
Put element-wise reciprocal values of input vector in target, this(i,j) = 1/A(i,j).