42 #ifndef THYRA_TPETRA_VECTOR_HPP
43 #define THYRA_TPETRA_VECTOR_HPP
55 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
60 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
63 const RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector
66 initializeImpl(tpetraVectorSpace, tpetraVector);
70 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
73 const RCP<
const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector
76 initializeImpl(tpetraVectorSpace, tpetraVector);
80 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 return tpetraVector_.getNonconstObj();
88 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
97 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
101 if (domainSpace_.is_null()) {
102 domainSpace_ = tpetraVectorSpace<Scalar>(
103 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
105 tpetraVector_.getConstObj()->getMap()->getComm()
116 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
120 return tpetraVectorSpace_;
127 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
129 const Ptr<ArrayRCP<Scalar> > &localValues )
131 *localValues = tpetraVector_.getNonconstObj()->get1dViewNonConst();
135 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
137 const Ptr<ArrayRCP<const Scalar> > &localValues )
const
139 *localValues = tpetraVector_->get1dView();
146 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
154 if (!tpetraVector_.getNonconstObj()->isDistributed()) {
155 auto comm = tpetraVector_.getNonconstObj()->getMap()->getComm();
156 if (tpetraVector_.getConstObj()->getMap()->getComm()->getRank() == 0)
157 tpetraVector_.getNonconstObj()->randomize(l, u);
160 tpetraVector_.getNonconstObj()->reduce();
162 tpetraVector_.getNonconstObj()->randomize(l, u);
167 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
169 const VectorBase<Scalar>& x
172 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
177 tpetraVector_.getNonconstObj()->abs(*tx);
180 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
181 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
182 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
184 tpetraVector_.getNonconstObj()->sync_host ();
185 tpetraVector_.getNonconstObj()->modify_host ();
187 VectorDefaultBase<Scalar>::absImpl(x);
192 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
194 const VectorBase<Scalar>& x
197 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
202 tpetraVector_.getNonconstObj()->reciprocal(*tx);
205 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
206 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
207 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
209 tpetraVector_.getNonconstObj()->sync_host ();
210 tpetraVector_.getNonconstObj()->modify_host ();
212 VectorDefaultBase<Scalar>::reciprocalImpl(x);
217 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
219 const VectorBase<Scalar>& x
222 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
228 tpetraVector_.getNonconstObj()->elementWiseMultiply(
229 ST::one(), *tx, *tpetraVector_.getConstObj(), ST::zero());
232 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
233 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
234 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
236 tpetraVector_.getNonconstObj()->sync_host ();
237 tpetraVector_.getNonconstObj()->modify_host ();
239 VectorDefaultBase<Scalar>::eleWiseScaleImpl(x);
244 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
247 const VectorBase<Scalar>& x
250 auto tx = this->getConstTpetraVector(Teuchos::rcpFromRef(x));
258 = Tpetra::createVector<Scalar>(tx->getMap());
259 temp->elementWiseMultiply(
260 ST::one(), *tx, *tpetraVector_.getConstObj(), ST::zero());
261 return ST::magnitude(ST::squareroot(tpetraVector_.getConstObj()->dot(*temp)));
264 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
265 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
267 tpetraVector_.getNonconstObj()->sync_host ();
269 return VectorDefaultBase<Scalar>::norm2WeightedImpl(x);
274 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
277 const ArrayView<
const Ptr<
const VectorBase<Scalar> > > &vecs,
278 const ArrayView<
const Ptr<VectorBase<Scalar> > > &targ_vecs,
279 const Ptr<RTOpPack::ReductTarget> &reduct_obj,
284 for (
auto itr = vecs.begin(); itr != vecs.end(); ++itr) {
285 auto tv = this->getConstTpetraVector(Teuchos::rcpFromPtr(*itr));
287 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
288 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
289 Teuchos::rcp_const_cast<TV>(tv)->
template sync<Kokkos::HostSpace>();
291 Teuchos::rcp_const_cast<TV>(tv)->sync_host ();
297 for (
auto itr = targ_vecs.begin(); itr != targ_vecs.end(); ++itr) {
298 auto tv = this->getTpetraVector(Teuchos::rcpFromPtr(*itr));
300 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
301 tv->template sync<Kokkos::HostSpace>();
302 tv->template modify<Kokkos::HostSpace>();
310 SpmdVectorDefaultBase<Scalar>::applyOpImpl(op, vecs, targ_vecs, reduct_obj, global_offset);
314 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
322 typedef typename Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
323 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
324 Teuchos::rcp_const_cast<TV>(
325 tpetraVector_.getConstObj())->
template sync<Kokkos::HostSpace>();
327 Teuchos::rcp_const_cast<TV>(
328 tpetraVector_.getConstObj())->sync_host ();
331 SpmdVectorDefaultBase<Scalar>::acquireDetachedVectorViewImpl(rng, sub_vec);
335 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
343 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
344 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
345 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
347 tpetraVector_.getNonconstObj()->sync_host ();
348 tpetraVector_.getNonconstObj()->modify_host ();
351 SpmdVectorDefaultBase<Scalar>::acquireNonconstDetachedVectorViewImpl(rng, sub_vec);
355 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
361 SpmdVectorDefaultBase<Scalar>::commitNonconstDetachedVectorViewImpl(sub_vec);
364 typedef typename Tpetra::Vector<
365 Scalar,LocalOrdinal,GlobalOrdinal,Node>::execution_space execution_space;
366 tpetraVector_.getNonconstObj()->template sync<execution_space>();
373 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
376 tpetraVector_.getNonconstObj()->putScalar(alpha);
380 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
384 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
389 tpetraVector_.getNonconstObj()->assign(*tmv);
392 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
393 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
394 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
396 tpetraVector_.getNonconstObj()->sync_host ();
397 tpetraVector_.getNonconstObj()->modify_host ();
399 MultiVectorDefaultBase<Scalar>::assignMultiVecImpl(mv);
404 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
407 tpetraVector_.getNonconstObj()->scale(alpha);
411 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
414 const MultiVectorBase<Scalar>& mv
417 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
423 tpetraVector_.getNonconstObj()->update(alpha, *tmv, ST::one());
426 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
427 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
428 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
430 tpetraVector_.getNonconstObj()->sync_host();
431 tpetraVector_.getNonconstObj()->modify_host();
433 MultiVectorDefaultBase<Scalar>::updateImpl(alpha, mv);
438 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
441 const ArrayView<
const Ptr<
const MultiVectorBase<Scalar> > >& mv,
452 bool allCastsSuccessful =
true;
454 auto mvIter = mv.begin();
455 auto tmvIter = tmvs.begin();
456 for (; mvIter != mv.end(); ++mvIter, ++tmvIter) {
457 tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromPtr(*mvIter));
461 allCastsSuccessful =
false;
469 auto len = mv.size();
471 tpetraVector_.getNonconstObj()->scale(beta);
472 }
else if (len == 1 && allCastsSuccessful) {
473 tpetraVector_.getNonconstObj()->update(alpha[0], *tmvs[0], beta);
474 }
else if (len == 2 && allCastsSuccessful) {
475 tpetraVector_.getNonconstObj()->update(alpha[0], *tmvs[0], alpha[1], *tmvs[1], beta);
476 }
else if (allCastsSuccessful) {
478 auto tmvIter = tmvs.begin();
479 auto alphaIter = alpha.
begin();
484 for (; tmvIter != tmvs.end(); ++tmvIter) {
485 if (tmvIter->getRawPtr() == tpetraVector_.getConstObj().getRawPtr()) {
493 tmvIter = tmvs.begin();
497 if ((tmvs.size() % 2) == 0) {
498 tpetraVector_.getNonconstObj()->scale(beta);
500 tpetraVector_.getNonconstObj()->update(*alphaIter, *(*tmvIter), beta);
504 for (; tmvIter != tmvs.end(); tmvIter+=2, alphaIter+=2) {
505 tpetraVector_.getNonconstObj()->update(
506 *alphaIter, *(*tmvIter), *(alphaIter+1), *(*(tmvIter+1)), ST::one());
510 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
511 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
512 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
514 tpetraVector_.getNonconstObj()->sync_host ();
515 tpetraVector_.getNonconstObj()->modify_host ();
517 MultiVectorDefaultBase<Scalar>::linearCombinationImpl(alpha, mv, beta);
522 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
524 const MultiVectorBase<Scalar>& mv,
528 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
533 tpetraVector_.getConstObj()->dot(*tmv, prods);
536 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
537 tpetraVector_.getNonconstObj()->template sync<Kokkos::HostSpace>();
538 tpetraVector_.getNonconstObj()->template modify<Kokkos::HostSpace>();
540 tpetraVector_.getNonconstObj()->sync_host ();
541 tpetraVector_.getNonconstObj()->modify_host ();
543 MultiVectorDefaultBase<Scalar>::dotsImpl(mv, prods);
548 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
550 const ArrayView<
typename ScalarTraits<Scalar>::magnitudeType>& norms
553 tpetraVector_.getConstObj()->norm1(norms);
557 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
559 const ArrayView<
typename ScalarTraits<Scalar>::magnitudeType>& norms
562 tpetraVector_.getConstObj()->norm2(norms);
566 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
568 const ArrayView<
typename ScalarTraits<Scalar>::magnitudeType>& norms
571 tpetraVector_.getConstObj()->normInf(norms);
575 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
577 const EOpTransp M_trans,
578 const MultiVectorBase<Scalar> &X,
579 const Ptr<MultiVectorBase<Scalar> > &Y,
585 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
586 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TV;
594 typedef typename TMV::execution_space execution_space;
595 Teuchos::rcp_const_cast<TMV>(X_tpetra)->
template sync<execution_space>();
596 Y_tpetra->template sync<execution_space>();
597 Teuchos::rcp_const_cast<TV>(tpetraVector_.getConstObj())->
template sync<execution_space>();
602 "Error, conjugation without transposition is not allowed for complex scalar types!");
620 Y_tpetra->template modify<execution_space>();
621 Y_tpetra->multiply(trans,
Teuchos::NO_TRANS, alpha, *tpetraVector_.getConstObj(), *X_tpetra, beta);
623 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
624 Teuchos::rcp_const_cast<TV>(tpetraVector_.getConstObj())->
template sync<Kokkos::HostSpace>();
626 Teuchos::rcp_const_cast<TV>(tpetraVector_.getConstObj())->sync_host ();
628 VectorDefaultBase<Scalar>::applyImpl(M_trans, X, Y, alpha, beta);
637 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
638 template<
class TpetraVector_t>
648 tpetraVectorSpace_ = tpetraVectorSpace;
649 tpetraVector_.initialize(tpetraVector);
650 this->updateSpmdSpace();
654 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
659 using Teuchos::rcp_dynamic_cast;
663 RCP<TMV> tmv = rcp_dynamic_cast<TMV>(mv);
665 return tmv->getTpetraMultiVector();
668 RCP<TV> tv = rcp_dynamic_cast<TV>(mv);
670 return tv->getTpetraVector();
677 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
682 using Teuchos::rcp_dynamic_cast;
688 return tmv->getConstTpetraMultiVector();
693 return tv->getConstTpetraVector();
700 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
706 RCP<TV> tv = Teuchos::rcp_dynamic_cast<TV>(v);
708 return tv->getTpetraVector();
715 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
723 return tv->getConstTpetraVector();
733 #endif // THYRA_TPETRA_VECTOR_HPP
void constInitialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Initialize.
Concrete implementation of Thyra::MultiVector in terms of Tpetra::MultiVector.
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraMultiVector(const RCP< MultiVectorBase< Scalar > > &mv) const
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Concrete implementation of an SPMD vector space for Tpetra.
void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)
void initialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Initialize.
RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraMultiVector(const RCP< const MultiVectorBase< Scalar > > &mv) const
TpetraVector()
Construct to uninitialized.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
virtual void applyOpImpl(const RTOpPack::RTOpT< Scalar > &op, const ArrayView< const Ptr< const VectorBase< Scalar > > > &vecs, const ArrayView< const Ptr< VectorBase< Scalar > > > &targ_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal global_offset) const
virtual void norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
void getLocalVectorDataImpl(const Ptr< ArrayRCP< const Scalar > > &localValues) const
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
RCP< const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraVector() const
Get the embedded non-const Tpetra::Vector.
virtual void reciprocalImpl(const VectorBase< Scalar > &x)
void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const
virtual void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
virtual void absImpl(const VectorBase< Scalar > &x)
void getNonconstLocalVectorDataImpl(const Ptr< ArrayRCP< Scalar > > &localValues)
Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > TpetraMultiVector_t
RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpaceImpl() const
void initializeImpl(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< TpetraVector_t > &tpetraVector)
Concrete Thyra::SpmdVectorBase using Tpetra::Vector.
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraVector()
Get the embedded non-const Tpetra::Vector.
bool nonnull(const boost::shared_ptr< T > &p)
virtual void assignImpl(Scalar alpha)
virtual void eleWiseScaleImpl(const VectorBase< Scalar > &x)
virtual void normsInfImpl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
RCP< const VectorSpaceBase< Scalar > > domain() const
virtual void randomizeImpl(Scalar l, Scalar u)
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
virtual void scaleImpl(Scalar alpha)
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)