47 #ifndef XPETRA_BLOCKEDMULTIVECTOR_HPP 48 #define XPETRA_BLOCKEDMULTIVECTOR_HPP 60 #ifndef DOXYGEN_SHOULD_SKIP_THIS 62 template<
class S,
class LO,
class GO,
class N>
class Vector;
65 template <
class Scalar = double,
70 :
public MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >
79 #undef XPETRA_BLOCKEDMULTIVECTOR_SHORT 99 Teuchos::RCP<const MultiVector> v)
104 vv_.reserve(mapExtractor->NumMaps());
107 for (
size_t r = 0; r < mapExtractor->NumMaps(); ++r)
125 Teuchos::RCP<MultiVector> v)
130 vv_.reserve(mapExtractor->NumMaps());
133 for (
size_t r = 0; r < mapExtractor->NumMaps(); ++r)
192 virtual Teuchos::RCP< const Vector >
getVector(
size_t j)
const {
194 return Teuchos::null;
200 return Teuchos::null;
204 virtual Teuchos::ArrayRCP< const Scalar >
getData(
size_t j)
const {
206 return Teuchos::null;
212 return Teuchos::null;
221 virtual void dot(
const MultiVector&A,
const Teuchos::ArrayView< Scalar > &dots)
const {
236 virtual void scale(
const Scalar &alpha) {
245 virtual void scale (Teuchos::ArrayView< const Scalar > alpha) {
255 Teuchos::RCP<const MultiVector> rcpA = Teuchos::rcpFromRef(A);
256 Teuchos::RCP<const BlockedMultiVector> bA = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpA);
258 if(bA != Teuchos::null) {
276 Teuchos::RCP<const MultiVector> rcpA = Teuchos::rcpFromRef(A);
277 Teuchos::RCP<const MultiVector> rcpB = Teuchos::rcpFromRef(B);
278 Teuchos::RCP<const BlockedMultiVector> bA = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpA);
279 Teuchos::RCP<const BlockedMultiVector> bB = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpB);
280 if(bA != Teuchos::null && bB != Teuchos::null) {
281 TEUCHOS_TEST_FOR_EXCEPTION(
bThyraMode_ != bA->getMapExtractor()->getThyraMode(),
Xpetra::Exceptions::RuntimeError,
"BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector A).");
282 TEUCHOS_TEST_FOR_EXCEPTION(
getMapExtractor()->NumMaps() != bA->getMapExtractor()->NumMaps(),
Xpetra::Exceptions::RuntimeError,
"BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector A).");
283 TEUCHOS_TEST_FOR_EXCEPTION(
numVectors_ != bA->getNumVectors(),
Xpetra::Exceptions::RuntimeError,
"BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector in vector A).");
284 TEUCHOS_TEST_FOR_EXCEPTION(
bThyraMode_ != bB->getMapExtractor()->getThyraMode(),
Xpetra::Exceptions::RuntimeError,
"BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector B).");
285 TEUCHOS_TEST_FOR_EXCEPTION(
getMapExtractor()->NumMaps() != bB->getMapExtractor()->NumMaps(),
Xpetra::Exceptions::RuntimeError,
"BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector B).");
286 TEUCHOS_TEST_FOR_EXCEPTION(
numVectors_ != bB->getNumVectors(),
Xpetra::Exceptions::RuntimeError,
"BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector in vector B).");
290 getMultiVector(r)->update(alpha, *(bA->getMultiVector(r)), beta, *(bB->getMultiVector(r)), gamma);
298 virtual void norm1(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms)
const {
299 typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
301 std::fill(temp_norms.begin(),temp_norms.end(),ScalarTraits<Magnitude>::zero());
306 norms[c] += temp_norms[c];
312 virtual void norm2(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms)
const {
313 typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
316 std::fill(results.begin(),results.end(),ScalarTraits<Magnitude>::zero());
317 std::fill(temp_norms.begin(),temp_norms.end(),ScalarTraits<Magnitude>::zero());
322 results[c] += temp_norms[c] * temp_norms[c];
326 norms[c] = Teuchos::ScalarTraits<Magnitude >::squareroot(results[c]);
330 virtual void normInf(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms)
const {
331 typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
333 std::fill(temp_norms.begin(),temp_norms.end(),ScalarTraits<Magnitude>::zero());
338 norms[c] = std::max(norms[c],temp_norms[c]);
344 virtual void meanValue(
const Teuchos::ArrayView< Scalar > &means)
const {
370 throw Xpetra::Exceptions::RuntimeError(
"BlockedMultiVector::getLocalLength: routine not implemented. It has no value as one must iterate on the partial vectors.");
386 return std::string(
"BlockedMultiVector");
390 virtual void describe(Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default)
const {
391 out <<
"BlockedMultiVector: " << std::endl;
431 virtual void randomize(
bool bUseXpetraImplementation =
false) {
441 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR 442 typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
443 typedef Kokkos::DualView<impl_scalar_type**, Kokkos::LayoutStride,
444 typename node_type::execution_space,
445 Kokkos::MemoryUnmanaged> dual_view_type;
446 typedef typename dual_view_type::host_mirror_space host_execution_space;
447 typedef typename dual_view_type::t_dev::execution_space dev_execution_space;
454 template<
class TargetDeviceType>
455 typename Kokkos::Impl::if_c<
456 Kokkos::Impl::is_same<
457 typename dev_execution_space::memory_space,
458 typename TargetDeviceType::memory_space>::value,
459 typename dual_view_type::t_dev_um,
460 typename dual_view_type::t_host_um>::type
461 getLocalView ()
const {
462 if(Kokkos::Impl::is_same<
463 typename host_execution_space::memory_space,
464 typename TargetDeviceType::memory_space
466 return getHostLocalView();
468 return getDeviceLocalView();
472 virtual typename dual_view_type::t_host_um getHostLocalView ()
const {
473 typename dual_view_type::t_host_um test;
476 virtual typename dual_view_type::t_dev_um getDeviceLocalView()
const {
477 typename dual_view_type::t_dev_um test;
491 TEUCHOS_TEST_FOR_EXCEPTION(r >
getMapExtractor()->NumMaps(), std::out_of_range,
"Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " <<
getMapExtractor()->NumMaps() <<
" partial blocks.");
497 XPETRA_MONITOR(
"BlockedMultiVector::getMultiVector(r,bThyraMode)");
498 TEUCHOS_TEST_FOR_EXCEPTION(r >
getMapExtractor()->NumMaps(), std::out_of_range,
"Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " <<
getMapExtractor()->NumMaps() <<
" partial blocks.");
499 Teuchos::RCP<MultiVector> ret =
vv_[r];
502 size_t localLength = ret->getLocalLength();
503 size_t numVecs =
vv_[r]->getNumVectors();
506 for(
size_t k=0; k < numVecs; k++) {
507 Teuchos::ArrayRCP<const Scalar> srcVecData =
vv_[r]->getData(k);
508 Teuchos::ArrayRCP<Scalar> targetVecData = ret->getDataNonConst(k);
509 for(
size_t i=0; i < localLength; i++) {
510 targetVecData[i] = srcVecData[i];
526 void setMultiVector(
size_t r, Teuchos::RCP<const MultiVector> v,
bool bThyraMode) {
529 TEUCHOS_TEST_FOR_EXCEPTION(r >= me->NumMaps(), std::out_of_range,
"Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " <<
getMapExtractor()->NumMaps() <<
" partial blocks.");
532 Teuchos::RCP<MultiVector> vv = Teuchos::rcp_const_cast<
MultiVector>(v);
535 TEUCHOS_TEST_FOR_EXCEPTION(
bThyraMode_ ==
true && v->getMap()->getMinAllGlobalIndex() > 0,
Xpetra::Exceptions::RuntimeError,
"BlockedMultiVector is in Thyra mode but partial map starts with GIDs " << v->getMap()->getMinAllGlobalIndex() <<
" > 0!");
541 XPETRA_TEST_FOR_EXCEPTION(me->getMap(r,bThyraMode)->isSameAs(*(v->getMap()))==
false,
Xpetra::Exceptions::RuntimeError,
"Map of provided partial map and map extractor are not compatible. The size of the provided map is " << v->getMap()->getGlobalNumElements() <<
" and the expected size is " <<
getMapExtractor()->getMap(r,
bThyraMode_)->getGlobalNumElements() <<
" or the GIDs are not correct (Thyra versus non-Thyra?)");
543 size_t numVecs = v->getNumVectors();
544 Teuchos::RCP<MultiVector> target = me->getVector(r,numVecs,
bThyraMode_);
545 size_t localLength = target->getLocalLength();
546 for(
size_t k=0; k < numVecs; k++) {
547 Teuchos::ArrayRCP<const Scalar> srcVecData = v->getData(k);
548 Teuchos::ArrayRCP<Scalar> targetVecData = target->getDataNonConst(k);
549 for(
size_t i=0; i < localLength; i++) {
550 targetVecData[i] = srcVecData[i];
569 Teuchos::RCP<MultiVector>
Merge()
const {
572 using Teuchos::rcp_dynamic_cast;
598 std::vector<Teuchos::RCP<MultiVector> >
vv_;
605 #define XPETRA_BLOCKEDMULTIVECTOR_SHORT 606 #endif // XPETRA_BLOCKEDMULTIVECTOR_HPP virtual void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Export &exporter, CombineMode CM)
Import (using an Exporter).
Teuchos::RCP< const MapExtractor > mapextractor_
virtual void elementWiseMultiply(Scalar scalarAB, const Vector &A, const MultiVector &B, Scalar scalarThis)
Element-wise multiply of a Vector A with a MultiVector B.
virtual void setSeed(unsigned int seed)
Set seed for Random function.
virtual std::string description() const
A simple one-line description of this object.
LocalOrdinal local_ordinal_type
Teuchos::RCP< MultiVector > getMultiVector(size_t r, bool bThyraMode) const
return partial multivector associated with block row r
virtual void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
virtual void norm1(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
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.
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
std::vector< Teuchos::RCP< MultiVector > > vv_
array containing RCPs of the partial vectors
virtual Teuchos::RCP< const Vector > getVector(size_t j) const
Return a Vector which is a const view of column j.
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 Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
BlockedMultiVector(Teuchos::RCP< const MapExtractor > mapExtractor, Teuchos::RCP< const MultiVector > v)
Constructor.
virtual void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import &importer, CombineMode CM)
Export.
virtual global_size_t getGlobalLength() const
Global number of rows in the multivector.
virtual void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Import &importer, CombineMode CM)
Import.
virtual void update(const Scalar &alpha, const MultiVector &A, const Scalar &beta, const MultiVector &B, const Scalar &gamma)
Update multi-vector with scaled values of A and B, this = gamma*this + alpha*A + beta*B.
Exception throws to report errors in the internal logical of the program.
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 scale(const Scalar &alpha)
Scale the current values of a multi-vector, this = alpha*this.
Teuchos::RCP< MultiVector > getMultiVector(size_t r) const
return partial multivector associated with block row r
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 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.
Teuchos::RCP< const Map > getMap() const
Access function for the underlying Map this DistObject was constructed with.
virtual ~BlockedMultiVector()
Destructor.
size_t numVectors_
number of vectors (columns in multi vector)
virtual Teuchos::RCP< Vector > getVectorNonConst(size_t j)
Return a Vector which is a nonconst view of column j.
GlobalOrdinal global_ordinal_type
virtual void abs(const MultiVector &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this).
LocalOrdinal local_ordinal_type
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
virtual void replaceMap(const RCP< const Map > &map)
virtual size_t getLocalLength() const
Local number of rows on the calling process.
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.
void setMultiVector(size_t r, Teuchos::RCP< const MultiVector > v, bool bThyraMode)
set partial multivector associated with block row r
virtual void randomize(bool bUseXpetraImplementation=false)
size_t global_size_t
Global size_t object.
Teuchos::RCP< MultiVector > Merge() const
merge BlockedMultiVector blocks to a single MultiVector
virtual size_t getNumVectors() const
Number of columns in the multivector.
virtual void scale(Teuchos::ArrayView< const Scalar > alpha)
Scale the current values of a multi-vector, this[j] = alpha[j]*this[j].
#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.
RCP< const MapExtractor > getMapExtractor() const
access to underlying MapExtractor object
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
CombineMode
Xpetra::Combine Mode enumerable type.
virtual void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export &exporter, CombineMode CM)
Export (using an Importer).
#define XPETRA_MONITOR(funcName)
BlockedMultiVector(Teuchos::RCP< const MapExtractor > mapExtractor, Teuchos::RCP< MultiVector > v)
virtual void meanValue(const Teuchos::ArrayView< Scalar > &means) const
Compute mean (average) value of each vector in multi-vector. The outcome of this routine is undefined...
BlockedMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector &rhs)
Assignment operator: Does a deep copy.
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.
virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using global (row) index.
bool bThyraMode_
boolean flag, which is true, if BlockedCrsMatrix has been created using Thyra-style numbering for sub...