42 #ifndef THYRA_TPETRA_MULTIVECTOR_HPP
43 #define THYRA_TPETRA_MULTIVECTOR_HPP
45 #include "Thyra_TpetraMultiVector_decl.hpp"
46 #include "Thyra_TpetraVectorSpace.hpp"
47 #include "Thyra_TpetraVector.hpp"
48 #include "Teuchos_Assert.hpp"
57 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
62 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
66 const RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector
69 initializeImpl(tpetraVectorSpace, domainSpace, tpetraMultiVector);
73 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
77 const RCP<
const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector
80 initializeImpl(tpetraVectorSpace, domainSpace, tpetraMultiVector);
84 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
88 return tpetraMultiVector_.getNonconstObj();
92 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
96 return tpetraMultiVector_;
103 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
114 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
118 tpetraMultiVector_.getNonconstObj()->putScalar(alpha);
122 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
126 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
131 tpetraMultiVector_.getNonconstObj()->assign(*tmv);
134 tpetraMultiVector_.getNonconstObj()->sync_host ();
135 tpetraMultiVector_.getNonconstObj()->modify_host ();
141 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
145 tpetraMultiVector_.getNonconstObj()->scale(alpha);
149 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
155 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
161 tpetraMultiVector_.getNonconstObj()->update(alpha, *tmv, ST::one());
164 tpetraMultiVector_.getNonconstObj()->sync_host ();
165 tpetraMultiVector_.getNonconstObj()->modify_host ();
171 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
183 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
186 bool allCastsSuccessful =
true;
188 auto mvIter = mv.begin();
189 auto tmvIter = tmvs.begin();
190 for (; mvIter != mv.end(); ++mvIter, ++tmvIter) {
191 tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromPtr(*mvIter));
195 allCastsSuccessful =
false;
203 auto len = tmvs.
size();
205 tpetraMultiVector_.getNonconstObj()->scale(beta);
206 }
else if (len == 1 && allCastsSuccessful) {
207 tpetraMultiVector_.getNonconstObj()->update(alpha[0], *tmvs[0], beta);
208 }
else if (len == 2 && allCastsSuccessful) {
209 tpetraMultiVector_.getNonconstObj()->update(alpha[0], *tmvs[0], alpha[1], *tmvs[1], beta);
210 }
else if (allCastsSuccessful) {
212 auto tmvIter = tmvs.begin();
213 auto alphaIter = alpha.
begin();
218 for (; tmvIter != tmvs.end(); ++tmvIter) {
219 if (tmvIter->getRawPtr() == tpetraMultiVector_.getConstObj().getRawPtr()) {
226 tmvIter = tmvs.
begin();
230 if ((tmvs.size() % 2) == 0) {
231 tpetraMultiVector_.getNonconstObj()->scale(beta);
233 tpetraMultiVector_.getNonconstObj()->update(*alphaIter, *(*tmvIter), beta);
237 for (; tmvIter != tmvs.end(); tmvIter+=2, alphaIter+=2) {
238 tpetraMultiVector_.getNonconstObj()->update(
239 *alphaIter, *(*tmvIter), *(alphaIter+1), *(*(tmvIter+1)), ST::one());
243 tpetraMultiVector_.getNonconstObj()->sync_host ();
244 tpetraMultiVector_.getNonconstObj()->modify_host ();
250 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
256 auto tmv = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(mv));
261 tpetraMultiVector_.getConstObj()->dot(*tmv, prods);
264 tpetraMultiVector_.getNonconstObj()->sync_host ();
265 tpetraMultiVector_.getNonconstObj()->modify_host ();
271 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
276 tpetraMultiVector_.getConstObj()->norm1(norms);
280 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
285 tpetraMultiVector_.getConstObj()->norm2(norms);
289 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
294 tpetraMultiVector_.getConstObj()->normInf(norms);
298 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
305 return constTpetraVector<Scalar>(
307 tpetraMultiVector_->getVector(j)
312 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
319 return tpetraVector<Scalar>(
321 tpetraMultiVector_.getNonconstObj()->getVectorNonConst(j)
326 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
332 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
333 std::cerr <<
"\nTpetraMultiVector::subView(Range1D) const called!\n";
335 const Range1D colRng = this->validateColRange(col_rng_in);
338 this->getConstTpetraMultiVector()->subView(colRng);
341 tpetraVectorSpace<Scalar>(
342 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
343 tpetraView->getNumVectors(),
344 tpetraView->getMap()->getComm()
348 return constTpetraMultiVector(
356 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
362 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
363 std::cerr <<
"\nTpetraMultiVector::subView(Range1D) called!\n";
365 const Range1D colRng = this->validateColRange(col_rng_in);
368 this->getTpetraMultiVector()->subViewNonConst(colRng);
371 tpetraVectorSpace<Scalar>(
372 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
373 tpetraView->getNumVectors(),
374 tpetraView->getMap()->getComm()
378 return tpetraMultiVector(
386 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
392 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
393 std::cerr <<
"\nTpetraMultiVector::subView(ArrayView) const called!\n";
398 cols[i] = static_cast<std::size_t>(cols_in[i]);
401 this->getConstTpetraMultiVector()->subView(cols());
404 tpetraVectorSpace<Scalar>(
405 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
406 tpetraView->getNumVectors(),
407 tpetraView->getMap()->getComm()
411 return constTpetraMultiVector(
419 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
425 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
426 std::cerr <<
"\nTpetraMultiVector::subView(ArrayView) called!\n";
431 cols[i] = static_cast<std::size_t>(cols_in[i]);
434 this->getTpetraMultiVector()->subViewNonConst(cols());
437 tpetraVectorSpace<Scalar>(
438 Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
439 tpetraView->getNumVectors(),
440 tpetraView->getMap()->getComm()
444 return tpetraMultiVector(
452 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
459 const Ordinal primary_global_offset
465 for (
auto itr = multi_vecs.begin(); itr != multi_vecs.end(); ++itr) {
468 Teuchos::rcp_const_cast<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(
469 tmv->getConstTpetraMultiVector())-> sync_host ();
474 for (
auto itr = targ_multi_vecs.begin(); itr != targ_multi_vecs.end(); ++itr) {
475 Ptr<TMV> tmv = Teuchos::ptr_dynamic_cast<TMV>(*itr);
477 tmv->getTpetraMultiVector()->sync_host ();
478 tmv->getTpetraMultiVector()->modify_host ();
483 primary_op, multi_vecs, targ_multi_vecs, reduct_objs, primary_global_offset);
487 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
496 typedef typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
497 Teuchos::rcp_const_cast<TMV>(
498 tpetraMultiVector_.getConstObj())->sync_host ();
505 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
514 tpetraMultiVector_.getNonconstObj()->sync_host ();
515 tpetraMultiVector_.getNonconstObj()->modify_host ();
522 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
532 typedef typename Tpetra::MultiVector<
533 Scalar,LocalOrdinal,GlobalOrdinal,Node>::execution_space execution_space;
534 tpetraMultiVector_.getNonconstObj()->template sync<execution_space>();
585 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
589 return tpetraVectorSpace_;
593 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
598 *localValues = tpetraMultiVector_.getNonconstObj()->get1dViewNonConst();
599 *leadingDim = tpetraMultiVector_->getStride();
603 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
608 *localValues = tpetraMultiVector_->get1dView();
609 *leadingDim = tpetraMultiVector_->getStride();
613 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
623 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
631 typedef typename TMV::execution_space execution_space;
632 Teuchos::rcp_const_cast<TMV>(X_tpetra)->
template sync<execution_space>();
633 Y_tpetra->template sync<execution_space>();
634 Teuchos::rcp_const_cast<TMV>(
635 tpetraMultiVector_.getConstObj())->
template sync<execution_space>();
640 "Error, conjugation without transposition is not allowed for complex scalar types!");
658 Y_tpetra->template modify<execution_space>();
659 Y_tpetra->multiply(trans,
Teuchos::NO_TRANS, alpha, *tpetraMultiVector_.getConstObj(), *X_tpetra, beta);
661 Teuchos::rcp_const_cast<TMV>(
662 tpetraMultiVector_.getConstObj())->sync_host ();
671 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
672 template<
class TpetraMultiVector_t>
686 tpetraVectorSpace_ = tpetraVectorSpace;
687 domainSpace_ = domainSpace;
688 tpetraMultiVector_.initialize(tpetraMultiVector);
689 this->updateSpmdSpace();
693 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
694 RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
698 using Teuchos::rcp_dynamic_cast;
702 RCP<TMV> tmv = rcp_dynamic_cast<TMV>(mv);
704 return tmv->getTpetraMultiVector();
707 RCP<TV> tv = rcp_dynamic_cast<TV>(mv);
709 return tv->getTpetraVector();
712 return Teuchos::null;
715 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
716 RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
720 using Teuchos::rcp_dynamic_cast;
724 RCP<const TMV> tmv = rcp_dynamic_cast<
const TMV>(mv);
726 return tmv->getConstTpetraMultiVector();
729 RCP<const TV> tv = rcp_dynamic_cast<
const TV>(mv);
731 return tv->getConstTpetraVector();
734 return Teuchos::null;
741 #endif // THYRA_TPETRA_MULTIVECTOR_HPP
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
Concrete implementation of Thyra::MultiVector in terms of Tpetra::MultiVector.
TpetraMultiVector()
Construct to uninitialized.
RCP< const VectorBase< Scalar > > colImpl(Ordinal j) const
void getNonconstLocalMultiVectorDataImpl(const Ptr< ArrayRCP< Scalar > > &localValues, const Ptr< Ordinal > &leadingDim)
Concrete implementation of an SPMD vector space for Tpetra.
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraMultiVector()
Extract the underlying non-const Tpetra::MultiVector object.
virtual void assignImpl(Scalar alpha)
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
RCP< MultiVectorBase< Scalar > > nonconstContigSubViewImpl(const Range1D &colRng)
void euclideanApply(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Uses GEMM() and Teuchos::reduceAll() to implement.
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
Default implementation of assign(MV) using RTOps.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Use the non-transposed operator.
virtual void euclideanApply(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
virtual void mvMultiReductApplyOpImpl(const RTOpPack::RTOpT< Scalar > &primary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const ArrayView< const Ptr< RTOpPack::ReductTarget > > &reduct_objs, const Ordinal primary_global_offset) const
virtual void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
Default implementation of linear_combination using RTOps.
Use the transposed operator with complex-conjugate clements (same as TRANS for real scalar types)...
RCP< const MultiVectorBase< Scalar > > nonContigSubViewImpl(const ArrayView< const int > &cols_in) const
Use the non-transposed operator with complex-conjugate elements (same as NOTRANS for real scalar type...
void initialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const ScalarProdVectorSpaceBase< Scalar > > &domainSpace, const RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraMultiVector)
Initialize.
Use the transposed operator.
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
virtual void scaleImpl(Scalar alpha)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
RCP< const MultiVectorBase< Scalar > > contigSubViewImpl(const Range1D &colRng) const
virtual void mvMultiReductApplyOpImpl(const RTOpPack::RTOpT< Scalar > &primary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const ArrayView< const Ptr< RTOpPack::ReductTarget > > &reduct_objs, const Ordinal primary_global_offset) const
Interface for a collection of column vectors called a multi-vector.
RCP< MultiVectorBase< Scalar > > nonconstNonContigSubViewImpl(const ArrayView< const int > &cols_in)
void constInitialize(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const ScalarProdVectorSpaceBase< Scalar > > &domainSpace, const RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraMultiVector)
Initialize.
virtual void norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
virtual void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
Concrete Thyra::SpmdVectorBase using Tpetra::Vector.
void acquireDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
RCP< VectorBase< Scalar > > nonconstColImpl(Ordinal j)
void commitNonconstDetachedMultiVectorViewImpl(RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
bool nonnull(const boost::shared_ptr< T > &p)
void getLocalMultiVectorDataImpl(const Ptr< ArrayRCP< const Scalar > > &localValues, const Ptr< Ordinal > &leadingDim) const
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
virtual void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraMultiVector() const
Extract the underlying const Tpetra::MultiVector object.
RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpaceImpl() const
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
void acquireNonconstDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
virtual void normsInfImpl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
RCP< const ScalarProdVectorSpaceBase< Scalar > > domainScalarProdVecSpc() const
void acquireNonconstDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
void acquireDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
Default implementation of dots using RTOps.
void commitNonconstDetachedMultiVectorViewImpl(RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
Default implementation of update using RTOps.