43 #ifndef THYRA_TPETRA_VECTOR_SPACE_HPP
44 #define THYRA_TPETRA_VECTOR_SPACE_HPP
52 #include "Tpetra_Details_StaticView.hpp"
57 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
58 RCP<TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
67 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 const RCP<
const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > &tpetraMap
73 tpetraMap_ = tpetraMap;
74 this->updateState(tpetraMap->getGlobalNumElements(),
75 !tpetraMap->isDistributed());
76 this->setScalarProd(tpetraEuclideanScalarProd<Scalar,LocalOrdinal,GlobalOrdinal,Node>());
83 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
88 return tpetraVectorSpace<Scalar>(
89 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
90 size, tpetraMap_->getComm() ) );
97 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
101 return tpetraVector<Scalar>(
102 weakSelfPtr_.create_strong().getConst(),
104 new Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_,
false)
110 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
114 return tpetraMultiVector<Scalar>(
115 weakSelfPtr_.create_strong().getConst(),
116 this->createLocallyReplicatedVectorSpace(numMembers),
118 new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
119 tpetraMap_, numMembers,
false)
125 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
132 bool inUse = Teuchos::get_extra_data<bool>(tmv,
"inUse");
135 "Cannot use the cached vector simultaneously more than once.");
142 mv_->acquireDetachedView(Range1D(),Range1D(),&smv);
143 RTOpPack::assign_entries<Scalar>( Teuchos::outArg(
raw_mv_), smv );
144 mv_->releaseDetachedView(&smv);
155 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
159 const bool initialize)
const
167 if (!tpetraMap_->isDistributed()) {
169 if (tpetraMV_.is_null() || (tpetraMV_->getNumVectors() != size_t (raw_mv.
numSubCols()))) {
170 if (!tpetraMV_.is_null())
174 "Cannot use the cached vector simultaneously more than once.");
175 using IST =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::impl_scalar_type;
176 using DT =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::device_type;
177 auto dv = ::Tpetra::Details::getStatic2dDualView<IST, DT> (tpetraMap_->getGlobalNumElements(), raw_mv.
numSubCols());
178 tpetraMV_ =
Teuchos::rcp(
new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_, dv));
180 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tpetraMV_));
183 if (tpetraDomainSpace_.is_null() || raw_mv.
numSubCols() != tpetraDomainSpace_->localSubDim())
184 tpetraDomainSpace_ = tpetraVectorSpace<Scalar>(Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(raw_mv.
numSubCols(), tpetraMap_->getComm()));
186 mv = tpetraMultiVector<Scalar>(weakSelfPtr_.create_strong().getConst(), tpetraDomainSpace_, tpetraMV_);
188 mv = this->createMembers(raw_mv.
numSubCols());
191 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv));
196 mv->acquireDetachedView(Range1D(),Range1D(),&smv);
197 RTOpPack::assign_entries<Scalar>(
198 Ptr<const RTOpPack::SubMultiVectorView<Scalar> >(Teuchos::outArg(smv)),
201 mv->commitDetachedView(&smv);
204 Teuchos::set_extra_data(
207 "CopyTpetraMultiVectorViewBack",
215 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
225 if (!tpetraMap_->isDistributed()) {
226 if (tpetraMV_.is_null() || (tpetraMV_->getNumVectors() != size_t (raw_mv.
numSubCols()))) {
227 if (!tpetraMV_.is_null())
231 "Cannot use the cached vector simultaneously more than once.");
232 using IST =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::impl_scalar_type;
233 using DT =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::device_type;
234 auto dv = ::Tpetra::Details::getStatic2dDualView<IST, DT> (tpetraMap_->getGlobalNumElements(), raw_mv.
numSubCols());
235 tpetraMV_ =
Teuchos::rcp(
new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_, dv));
237 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tpetraMV_));
240 if (tpetraDomainSpace_.is_null() || raw_mv.
numSubCols() != tpetraDomainSpace_->localSubDim())
241 tpetraDomainSpace_ = tpetraVectorSpace<Scalar>(Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(raw_mv.
numSubCols(), tpetraMap_->getComm()));
243 mv = tpetraMultiVector<Scalar>(weakSelfPtr_.create_strong().getConst(), tpetraDomainSpace_, tpetraMV_);
245 mv = this->createMembers(raw_mv.
numSubCols());
248 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv));
252 mv->acquireDetachedView(Range1D(),Range1D(),&smv);
253 RTOpPack::assign_entries<Scalar>(
254 Ptr<const RTOpPack::SubMultiVectorView<Scalar> >(Teuchos::outArg(smv)),
256 mv->commitDetachedView(&smv);
261 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
263 const Range1D& rng_in,
const EViewType viewType,
const EStrideType strideType
266 const Range1D rng = full_range(rng_in,0,this->dim()-1);
267 const Ordinal l_localOffset = this->localOffset();
269 const Ordinal myLocalSubDim = tpetraMap_.is_null () ?
270 static_cast<Ordinal> (0) : tpetraMap_->getLocalNumElements ();
272 return ( l_localOffset<=rng.lbound() && rng.ubound()<l_localOffset+myLocalSubDim );
276 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
280 return tpetraVectorSpace<Scalar>(tpetraMap_);
283 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
293 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
301 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
304 return tpetraMap_.is_null () ?
static_cast<Ordinal> (0) :
305 static_cast<Ordinal> (tpetraMap_->getLocalNumElements ());
311 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
322 #endif // THYRA_TPETRA_VECTOR_SPACE_HPP
Concrete implementation of Thyra::MultiVector in terms of Tpetra::MultiVector.
Ordinal localSubDim() const
Concrete implementation of an SPMD vector space for Tpetra.
Ordinal numSubCols() const
RCP< const VectorSpaceBase< Scalar > > clone() const
RCP< T > create_weak() const
RCP< TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createLocallyReplicatedVectorSpace(int size) const
Create Tpetra locally replicated vector space.
static RCP< TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > create()
Create with weak ownership to self.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void initialize(const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &tpetraMap)
Initialize a serial space.
RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getTpetraMap() const
Get the embedded Tpetra::Map.
CopyTpetraMultiVectorViewBack(RCP< MultiVectorBase< Scalar > > mv, const RTOpPack::SubMultiVectorView< Scalar > &raw_mv)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
const RTOpPack::SubMultiVectorView< Scalar > raw_mv_
~CopyTpetraMultiVectorViewBack()
bool hasInCoreView(const Range1D &rng, const EViewType viewType, const EStrideType strideType) const
Returns true if all the elements in rng are in this process.
RCP< VectorBase< Scalar > > createMember() const
RCP< MultiVectorBase< Scalar > > createMembers(int numMembers) const
RCP< const Teuchos::Comm< Ordinal > > getComm() const
RCP< MultiVectorBase< Scalar > > mv_
RCP< const Teuchos::Comm< Ordinal > > convertTpetraToThyraComm(const RCP< const Teuchos::Comm< int > > &tpetraComm)
Given an Tpetra Teuchos::Comm<int> object, return an equivalent Teuchos::Comm<Ordinal> object...
RCP< MultiVectorBase< Scalar > > createCachedMembersView(const RTOpPack::SubMultiVectorView< Scalar > &raw_mv, bool initialize=true) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)