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;
63 template<
class S,
class LO,
class GO,
class N>
class BlockedVector;
64 template<
class S,
class LO,
class GO,
class N>
class MapExtractor;
65 template<
class S,
class LO,
class GO,
class N>
class MultiVectorFactory;
68 template <
class Scalar = double,
69 class LocalOrdinal = Map<>::local_ordinal_type,
70 class GlobalOrdinal =
typename Map<LocalOrdinal>::global_ordinal_type,
71 class Node =
typename Map<LocalOrdinal, GlobalOrdinal>::node_type>
73 :
public MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >
82 #undef XPETRA_BLOCKEDMULTIVECTOR_SHORT
106 vv_.reserve(map->getNumMaps());
109 for (
size_t r = 0; r < map->getNumMaps(); ++r)
126 XPETRA_TEST_FOR_EXCEPTION(bmap->getMap()->getNodeNumElements() != v->getMap()->getNodeNumElements(),
Xpetra::Exceptions::RuntimeError,
"BlockedMultiVector: inconsistent number of local elements of MultiVector and BlockedMap. The BlockedMap has " << bmap->getMap()->getNodeNumElements() <<
" local elements. The vector has " << v->getMap()->getNodeNumElements() <<
".");
127 XPETRA_TEST_FOR_EXCEPTION(bmap->getMap()->getGlobalNumElements() != v->getMap()->getGlobalNumElements(),
Xpetra::Exceptions::RuntimeError,
"BlockedMultiVector: inconsistent number of global elements of MultiVector and BlockedMap. The BlockedMap has " << bmap->getMap()->getGlobalNumElements() <<
" local elements. The vector has " << v->getMap()->getGlobalNumElements() <<
".");
136 vv_.reserve(bmap->getNumMaps());
139 for (
size_t r = 0; r < bmap->getNumMaps(); ++r)
140 vv_.push_back(this->ExtractVector(v, r, bmap->getThyraMode()));
164 vv_.reserve(bmap->getNumMaps());
167 for (
size_t r = 0; r < bmap->getNumMaps(); ++r)
168 vv_.push_back(this->ExtractVector(v, r, bmap->getThyraMode()));
187 std::vector<RCP<const Map> > maps;
188 maps.reserve(mapExtractor->NumMaps());
189 for (
size_t r = 0; r < mapExtractor->NumMaps(); ++r)
190 maps.push_back(mapExtractor->getMap(r,mapExtractor->getThyraMode()));
194 vv_.reserve(mapExtractor->NumMaps());
197 for (
size_t r = 0; r < mapExtractor->NumMaps(); ++r)
198 vv_.push_back(this->ExtractVector(v, r, mapExtractor->getThyraMode()));
217 std::vector<RCP<const Map> > maps;
218 maps.reserve(mapExtractor->NumMaps());
219 for (
size_t r = 0; r < mapExtractor->NumMaps(); ++r)
220 maps.push_back(mapExtractor->getMap(r,mapExtractor->getThyraMode()));
223 vv_.reserve(mapExtractor->NumMaps());
226 for (
size_t r = 0; r < mapExtractor->NumMaps(); ++r)
227 vv_.push_back(this->ExtractVector(v, r, mapExtractor->getThyraMode()));
241 vv_.resize(vin.size());
242 for(
size_t i=0; i<
vv_.size(); i++)
248 for (
size_t r = 0; r <
vv_.size(); ++r)
249 vv_[r] = Teuchos::null;
250 map_ = Teuchos::null;
294 for(
size_t r = 0; r <
map_->getNumMaps(); r++) {
312 ret->setMultiVector(r,subvec,this->
getBlockedMap()->getThyraMode());
326 if(
map_->getNumMaps() == 1) {
327 return vv_[0]->getData(j);
335 if(
map_->getNumMaps() == 1) {
336 return vv_[0]->getDataNonConst(j);
363 virtual void scale(
const Scalar &alpha) {
365 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
375 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
388 if(bA != Teuchos::null) {
393 for(
size_t r = 0; r <
map_->getNumMaps(); r++) {
410 if(blmv.
is_null() ==
true && brmv.is_null() ==
false) {
413 lmv->update(alpha, *(brmv->getMultiVector(0)), beta);
415 lmv->update(alpha, *rmv, beta);
430 for(
size_t r = 0; r <
map_->getNumMaps(); r++) {
449 if(bA != Teuchos::null && bB != Teuchos::null) {
457 for(
size_t r = 0; r <
map_->getNumMaps(); r++) {
459 getMultiVector(r)->update(alpha, *(bA->getMultiVector(r)), beta, *(bB->getMultiVector(r)), gamma);
473 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
477 norms[c] += temp_norms[c];
491 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
495 results[c] += temp_norms[c] * temp_norms[c];
509 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
513 norms[c] = std::max(norms[c],temp_norms[c]);
547 for(
size_t m = 0; m < bmap->getNumMaps(); m++) {
549 bA->getMultiVector(m, bmap->getThyraMode())->
getVector(0);
551 bB->getMultiVector(m, bmap->getThyraMode());
555 thisPart->elementWiseMultiply(scalarAB,*partA,*partB,scalarThis);
572 return map_->getFullMap()->getNodeNumElements();
578 return map_->getFullMap()->getGlobalNumElements();
584 if(!Vb)
return false;
585 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
588 if((a==Teuchos::null && b != Teuchos::null) ||
589 (a!=Teuchos::null && b == Teuchos::null))
591 if(a!=Teuchos::null && b !=Teuchos::null && !a->isSameSize(*b))
604 return std::string(
"BlockedMultiVector");
610 for(
size_t r = 0; r <
map_->getNumMaps(); r++)
625 std::vector<Teuchos::RCP<const Map> > subMaps (1, map);
634 for(
size_t r = 0; r < map_->getNumMaps(); r++)
635 getMultiVector(r)->replaceMap(bmap->getMap(r,map_->getThyraMode()));
665 for(
size_t r = 0; r <
map_->getNumMaps(); ++r) {
671 virtual void randomize(
bool bUseXpetraImplementation =
false) {
672 for(
size_t r = 0; r <
map_->getNumMaps(); ++r) {
683 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
684 typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
685 typedef Kokkos::DualView<impl_scalar_type**, Kokkos::LayoutStride,
686 typename node_type::execution_space,
687 Kokkos::MemoryUnmanaged> dual_view_type;
688 typedef typename dual_view_type::host_mirror_space host_execution_space;
689 typedef typename dual_view_type::t_dev::execution_space dev_execution_space;
696 template<
class TargetDeviceType>
697 typename Kokkos::Impl::if_c<
698 Kokkos::Impl::is_same<
699 typename dev_execution_space::memory_space,
700 typename TargetDeviceType::memory_space>::value,
701 typename dual_view_type::t_dev_um,
702 typename dual_view_type::t_host_um>::type
703 getLocalView ()
const {
704 if(Kokkos::Impl::is_same<
705 typename host_execution_space::memory_space,
706 typename TargetDeviceType::memory_space
708 return getHostLocalView();
710 return getDeviceLocalView();
714 virtual typename dual_view_type::t_host_um getHostLocalView ()
const {
715 typename dual_view_type::t_host_um test;
718 virtual typename dual_view_type::t_dev_um getDeviceLocalView()
const {
719 typename dual_view_type::t_dev_um test;
736 TEUCHOS_TEST_FOR_EXCEPTION(r >
map_->getNumMaps(), std::out_of_range,
"Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " <<
map_->getNumMaps() <<
" partial blocks.");
742 XPETRA_MONITOR(
"BlockedMultiVector::getMultiVector(r,bThyraMode)");
743 TEUCHOS_TEST_FOR_EXCEPTION(r >
map_->getNumMaps(), std::out_of_range,
"Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " <<
map_->getNumMaps() <<
" partial blocks.");
756 XPETRA_TEST_FOR_EXCEPTION(r >=
map_->getNumMaps(), std::out_of_range,
"Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " <<
map_->getNumMaps() <<
" partial blocks.");
771 for(
size_t r = 0; r <
map_->getNumMaps(); ++r) {
798 if(bRhs == Teuchos::null)
802 vv_ = std::vector<Teuchos::RCP<MultiVector> >(
map_->getNumMaps());
803 for(
size_t r = 0; r <
map_->getNumMaps(); ++r) {
813 if(bsrc.is_null() ==
true && bvv.is_null() ==
true) {
815 }
else if (bsrc.is_null() ==
true && bvv.is_null() ==
false) {
818 }
else if (bsrc.is_null() ==
false && bvv.is_null() ==
true) {
821 if(bsrc->getBlockedMap()->getNumMaps() > 1) {
822 throw Xpetra::Exceptions::RuntimeError(
"BlockedMultiVector::assign: source vector is of type BlockedMultiVector (with more than 1 blocks) and target is a MultiVector.");
846 XPETRA_TEST_FOR_EXCEPTION(block >=
map_->getNumMaps(), std::out_of_range,
"ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " <<
map_->getNumMaps() <<
" partial blocks.");
848 "ExtractVector: map_->getmap(" << block <<
",false) is null");
850 if(bfull.is_null() ==
true) {
860 rcpNonConstFull->replaceMap(
map_->getImporter(block)->getSourceMap());
863 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been created using Thyra-style numbered submaps.");
864 if(bThyraMode ==
true)
865 vv->replaceMap(
map_->getMap(block,
true));
866 rcpNonConstFull->replaceMap(oldThyMapFull);
872 "ExtractVector: Number of blocks in map extractor is " <<
map_->getNumMaps() <<
" but should be " << bfull->getBlockedMap()->getNumMaps() <<
" (number of blocks in BlockedMultiVector)");
873 return bfull->getMultiVector(block,bThyraMode);
877 XPETRA_TEST_FOR_EXCEPTION(block >=
map_->getNumMaps(), std::out_of_range,
"ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " <<
map_->getNumMaps() <<
" partial blocks.");
879 "ExtractVector: map_->getmap(" << block <<
",false) is null");
881 if(bfull.is_null() ==
true) {
890 full->replaceMap(
map_->getImporter(block)->getSourceMap());
893 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been created using Thyra-style numbered submaps.");
894 if(bThyraMode ==
true)
895 vv->replaceMap(
map_->getMap(block,
true));
896 full->replaceMap(oldThyMapFull);
902 "ExtractVector: Number of blocks in map extractor is " <<
map_->getNumMaps() <<
" but should be " << bfull->getBlockedMap()->getNumMaps() <<
" (number of blocks in BlockedMultiVector)");
903 return bfull->getMultiVector(block,bThyraMode);
907 XPETRA_TEST_FOR_EXCEPTION(block >=
map_->getNumMaps(), std::out_of_range,
"ExtractVector: Error, block = " << block <<
" is too big. The BlockedMultiVector only contains " <<
map_->getNumMaps() <<
" partial blocks.");
909 "ExtractVector: maps_[" << block <<
"] is null");
914 XPETRA_TEST_FOR_EXCEPTION(block >=
map_->getNumMaps(), std::out_of_range,
"ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " <<
map_->getNumMaps() <<
" partial blocks.");
916 "ExtractVector: map_->getmap(" << block <<
",false) is null");
918 "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created using Thyra-style numbered submaps.");
939 rcpNonConstPartial->replaceMap(
map_->getMap(block,
false));
947 rcpNonConstPartial->replaceMap(oldThyMapPartial);
959 "InsertVector: maps_[" << block <<
"] is null");
960 full->setMultiVector(block, partial, bThyraMode);
969 "InsertVector: maps_[" << block <<
"] is null");
970 bfull->setMultiVector(block, partial, bThyraMode);
976 std::vector<Teuchos::RCP<MultiVector> >
vv_;
982 #define XPETRA_BLOCKEDMULTIVECTOR_SHORT
983 #endif // XPETRA_BLOCKEDMULTIVECTOR_HPP
virtual void replaceGlobalValue(GlobalOrdinal, size_t, const Scalar &)
Replace value, using global (row) index.
Teuchos::RCP< MultiVector > getMultiVector(size_t r) const
return partial multivector associated with block row r
void ExtractVector(RCP< MultiVector > &full, size_t block, RCP< MultiVector > &partial) const
virtual void reciprocal(const MultiVector &)
Put element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,j).
virtual void setSeed(unsigned int seed)
Set seed for Random function.
virtual void sumIntoGlobalValue(GlobalOrdinal, size_t, const Scalar &)
Add value to existing value, using global (row) index.
virtual void doExport(const DistObject< Packet, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)=0
Export data into this object using an Export object ("forward mode").
virtual void replaceLocalValue(LocalOrdinal, size_t, const Scalar &)
Replace value, using local (row) index.
virtual std::string description() const
A simple one-line description of this object.
RCP< MultiVector > ExtractVector(RCP< const MultiVector > &full, size_t block, bool bThyraMode=false) const
virtual void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &, const Export &, CombineMode)
Export (using an Importer).
std::vector< Teuchos::RCP< MultiVector > > vv_
array containing RCPs of the partial vectors
virtual void multiply(Teuchos::ETransp, Teuchos::ETransp, const Scalar &, const MultiVector &, const MultiVector &, const Scalar &)
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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 Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
BlockedMultiVector(const Teuchos::RCP< const BlockedMap > &map, size_t NumVectors, bool zeroOut=true)
Constructor.
Teuchos::RCP< const Map > getMap() const
Access function for the underlying Map this DistObject was constructed with.
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.
void InsertVector(RCP< MultiVector > partial, size_t block, RCP< MultiVector > full, bool bThyraMode=false) const
virtual void scale(const Scalar &alpha)
Scale the current values of a multi-vector, this = alpha*this.
virtual void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)=0
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 doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &, const Import &, CombineMode)
Import.
virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
virtual void abs(const MultiVector &)
Put element-wise absolute values of input Multi-vector in target: A = abs(this).
BlockedMultiVector(Teuchos::RCP< const Xpetra::BlockedMap< LocalOrdinal, GlobalOrdinal, Node > > bmap, Teuchos::RCP< MultiVector > v)
virtual void doImport(const DistObject< Packet, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)=0
Import data into this object using an Import object ("forward mode").
virtual ~BlockedMultiVector()
Destructor.
size_t numVectors_
number of vectors (columns in multi vector)
RCP< MultiVector > ExtractVector(RCP< MultiVector > &full, size_t block, bool bThyraMode=false) const
virtual global_size_t getGlobalLength() const
Global number of rows in the multivector.
void ExtractVector(const MultiVector &full, size_t block, MultiVector &partial) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< MultiVector > getMultiVector(size_t r, bool bThyraMode) const
return partial multivector associated with block row r
GlobalOrdinal global_ordinal_type
virtual bool isSameSize(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
Local number of rows on the calling process.
LocalOrdinal local_ordinal_type
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
BlockedMultiVector(const Teuchos::RCP< const BlockedMap > &map, std::vector< Teuchos::RCP< MultiVector > > &vin)
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 void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &, const Export &, CombineMode)
Import (using an Exporter).
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.
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 void assign(const MultiVector &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
void setMultiVector(size_t r, Teuchos::RCP< const MultiVector > v, bool bThyraMode)
set partial multivector associated with block row r
virtual void sumIntoLocalValue(LocalOrdinal, size_t, const Scalar &)
Add value to existing value, using local (row) index.
BlockedMultiVector(Teuchos::RCP< const Xpetra::MapExtractor< Scalar, LocalOrdinal, GlobalOrdinal, Node > > mapExtractor, Teuchos::RCP< MultiVector > v)
virtual void randomize(bool bUseXpetraImplementation=false)
Set multi-vector values to random numbers.
size_t global_size_t
Global size_t object.
static const EVerbosityLevel verbLevel_default
BlockedMultiVector(Teuchos::RCP< const Xpetra::BlockedMap< LocalOrdinal, GlobalOrdinal, Node > > bmap, Teuchos::RCP< const MultiVector > v)
virtual void scale(Teuchos::ArrayView< const Scalar > alpha)
Scale the current values of a multi-vector, this[j] = alpha[j]*this[j].
void InsertVector(const MultiVector &partial, size_t block, MultiVector &full, bool bThyraMode=false) const
Teuchos::RCP< MultiVector > Merge() const
merge BlockedMultiVector blocks to a single MultiVector
virtual void normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute Inf-norm of each vector in multi-vector.
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
#define XPETRA_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const BlockedMap > map_
blocked map containing the sub block maps (either thyra or xpetra mode)
virtual void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
virtual void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
void ExtractVector(RCP< const MultiVector > &full, size_t block, RCP< MultiVector > &partial) const
virtual void meanValue(const Teuchos::ArrayView< Scalar > &) const
Compute mean (average) value of each vector in multi-vector. The outcome of this routine is undefined...
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.
virtual void norm1(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
virtual size_t getLocalLength() const
Local number of rows on the calling process.
CombineMode
Xpetra::Combine Mode enumerable type.
#define XPETRA_MONITOR(funcName)
void InsertVector(RCP< const MultiVector > partial, size_t block, RCP< MultiVector > full, bool bThyraMode=false) const
virtual void dot(const MultiVector &, const Teuchos::ArrayView< Scalar > &) const
Compute dot product of each corresponding pair of vectors, dots[i] = this[i].dot(A[i]).
virtual void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &, const Import &, CombineMode)
Export.
BlockedMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector &rhs)
Assignment operator: Does a deep copy.
BlockedMultiVector(Teuchos::RCP< const Xpetra::MapExtractor< Scalar, LocalOrdinal, GlobalOrdinal, Node > > mapExtractor, Teuchos::RCP< const MultiVector > v)
virtual size_t getNumVectors() const
Number of columns in the multivector.
Teuchos::RCP< const Xpetra::BlockedMap< LocalOrdinal, GlobalOrdinal, Node > > getBlockedMap() const
Access function for the underlying Map this DistObject was constructed with.
virtual Teuchos::RCP< Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(size_t j)
Return a Vector which is a nonconst view of column j.