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>
87 return tpetraVector<Scalar>(
88 weakSelfPtr_.create_strong().getConst(),
90 new Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_,
false)
96 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
100 return tpetraMultiVector<Scalar>(
101 weakSelfPtr_.create_strong().getConst(),
102 tpetraVectorSpace<Scalar>(
103 Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(
104 numMembers, tpetraMap_->getComm()
108 new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
109 tpetraMap_, numMembers,
false)
117 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
124 bool inUse = Teuchos::get_extra_data<bool>(tmv,
"inUse");
127 "Cannot use the cached vector simultaneously more than once.");
134 mv_->acquireDetachedView(Range1D(),Range1D(),&smv);
135 RTOpPack::assign_entries<Scalar>( Teuchos::outArg(
raw_mv_), smv );
136 mv_->releaseDetachedView(&smv);
147 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
158 if (!tpetraMap_->isDistributed()) {
160 if (tpetraMV_.is_null() || (tpetraMV_->getNumVectors() != size_t (raw_mv.
numSubCols()))) {
161 if (!tpetraMV_.is_null())
165 "Cannot use the cached vector simultaneously more than once.");
166 using IST =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::impl_scalar_type;
167 using DT =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::device_type;
168 auto dv = ::Tpetra::Details::getStatic2dDualView<IST, DT> (tpetraMap_->getGlobalNumElements(), raw_mv.
numSubCols());
169 tpetraMV_ =
Teuchos::rcp(
new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_, dv));
171 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tpetraMV_));
174 if (tpetraDomainSpace_.is_null() || raw_mv.
numSubCols() != tpetraDomainSpace_->localSubDim())
175 tpetraDomainSpace_ = tpetraVectorSpace<Scalar>(Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(raw_mv.
numSubCols(), tpetraMap_->getComm()));
177 mv = tpetraMultiVector<Scalar>(weakSelfPtr_.create_strong().getConst(), tpetraDomainSpace_, tpetraMV_);
179 mv = this->createMembers(raw_mv.
numSubCols());
182 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv));
186 mv->acquireDetachedView(Range1D(),Range1D(),&smv);
187 RTOpPack::assign_entries<Scalar>(
188 Ptr<const RTOpPack::SubMultiVectorView<Scalar> >(Teuchos::outArg(smv)),
191 mv->commitDetachedView(&smv);
193 Teuchos::set_extra_data(
196 "CopyTpetraMultiVectorViewBack",
204 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
214 if (!tpetraMap_->isDistributed()) {
215 if (tpetraMV_.is_null() || (tpetraMV_->getNumVectors() != size_t (raw_mv.
numSubCols()))) {
216 if (!tpetraMV_.is_null())
220 "Cannot use the cached vector simultaneously more than once.");
221 using IST =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::impl_scalar_type;
222 using DT =
typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::device_type;
223 auto dv = ::Tpetra::Details::getStatic2dDualView<IST, DT> (tpetraMap_->getGlobalNumElements(), raw_mv.
numSubCols());
224 tpetraMV_ =
Teuchos::rcp(
new Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(tpetraMap_, dv));
226 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tpetraMV_));
229 if (tpetraDomainSpace_.is_null() || raw_mv.
numSubCols() != tpetraDomainSpace_->localSubDim())
230 tpetraDomainSpace_ = tpetraVectorSpace<Scalar>(Tpetra::createLocalMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(raw_mv.
numSubCols(), tpetraMap_->getComm()));
232 mv = tpetraMultiVector<Scalar>(weakSelfPtr_.create_strong().getConst(), tpetraDomainSpace_, tpetraMV_);
234 mv = this->createMembers(raw_mv.
numSubCols());
237 Teuchos::set_extra_data(inUse,
"inUse",Teuchos::outArg(tmv));
241 mv->acquireDetachedView(Range1D(),Range1D(),&smv);
242 RTOpPack::assign_entries<Scalar>(
243 Ptr<const RTOpPack::SubMultiVectorView<Scalar> >(Teuchos::outArg(smv)),
245 mv->commitDetachedView(&smv);
250 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
252 const Range1D& rng_in,
const EViewType viewType,
const EStrideType strideType
255 const Range1D rng = full_range(rng_in,0,this->dim()-1);
256 const Ordinal l_localOffset = this->localOffset();
258 const Ordinal myLocalSubDim = tpetraMap_.is_null () ?
259 static_cast<Ordinal> (0) : tpetraMap_->getNodeNumElements ();
261 return ( l_localOffset<=rng.lbound() && rng.ubound()<l_localOffset+myLocalSubDim );
265 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
269 return tpetraVectorSpace<Scalar>(tpetraMap_);
272 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
282 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
290 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
293 return tpetraMap_.is_null () ?
static_cast<Ordinal> (0) :
294 static_cast<Ordinal> (tpetraMap_->getNodeNumElements ());
300 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
311 #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.
RCP< MultiVectorBase< Scalar > > createCachedMembersView(const RTOpPack::SubMultiVectorView< Scalar > &raw_mv) const
Ordinal numSubCols() const
RCP< const VectorSpaceBase< Scalar > > clone() const
RCP< T > create_weak() const
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...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)