42 #ifndef THYRA_DEFAULT_SPMD_MULTI_VECTOR_DEF_HPP
43 #define THYRA_DEFAULT_SPMD_MULTI_VECTOR_DEF_HPP
48 #include "Thyra_DefaultSpmdMultiVector_decl.hpp"
49 #include "Thyra_SpmdMultiVectorDefaultBase.hpp"
50 #include "Thyra_VectorSpaceFactoryBase.hpp"
51 #include "Thyra_DefaultSpmdVector.hpp"
52 #include "Teuchos_Assert.hpp"
63 template<
class Scalar>
64 class CopyBackSpmdMultiVectorEntries {
66 CopyBackSpmdMultiVectorEntries(
67 const ArrayView<const int> &cols,
68 const ArrayRCP<const Scalar> &localValuesView,
const Ordinal localSubDim,
69 const ArrayRCP<Scalar> &localValues,
const Ordinal leadingDim
71 : cols_(cols), localValuesView_(localValuesView), localSubDim_(localSubDim),
72 localValues_(localValues), leadingDim_(leadingDim)
74 ~CopyBackSpmdMultiVectorEntries()
79 if (localValues_.strong_count()) {
80 const int numCols = cols_.size();
81 const const_itr_t lvv = localValuesView_.begin();
82 const itr_t lv = localValues_.begin();
83 for (
int k = 0; k < numCols; ++k) {
84 const int col_k = cols_[k];
85 const const_itr_t lvv_k = lvv + localSubDim_*k;
86 const itr_t lv_k = lv + leadingDim_*col_k;
87 std::copy( lvv_k, lvv_k + localSubDim_, lv_k );
92 ++DefaultSpmdMultiVector<Scalar>::numSkipCopyBack;
98 ArrayRCP<const Scalar> localValuesView_;
100 ArrayRCP<Scalar> localValues_;
103 CopyBackSpmdMultiVectorEntries();
104 CopyBackSpmdMultiVectorEntries(
const CopyBackSpmdMultiVectorEntries&);
105 CopyBackSpmdMultiVectorEntries& operator=(
const CopyBackSpmdMultiVectorEntries&);
109 template<
class Scalar>
110 RCP<CopyBackSpmdMultiVectorEntries<Scalar> >
111 copyBackSpmdMultiVectorEntries(
112 const ArrayView<const int> &cols,
113 const ArrayRCP<const Scalar> &localValuesView,
const Ordinal localSubDim,
114 const ArrayRCP<Scalar> &localValues,
const Ordinal leadingDim
118 new CopyBackSpmdMultiVectorEntries<Scalar>(
119 cols, localValuesView, localSubDim, localValues, leadingDim
131 template<
class Scalar>
132 int DefaultSpmdMultiVector<Scalar>::numSkipCopyBack(0);
139 template<
class Scalar>
145 template<
class Scalar>
151 initialize(spmdRangeSpace,domainSpace);
155 template<
class Scalar>
163 initialize(spmdRangeSpace,domainSpace,localValues,leadingDim);
167 template<
class Scalar>
173 const Ordinal localSubDim = spmdRangeSpace->localSubDim();
176 values = Teuchos::arcp<Scalar>(localSubDim * domainSpace->dim());
177 initialize(spmdRangeSpace, domainSpace, values, localSubDim);
181 template<
class Scalar>
189 const Ordinal localSubDim = spmdRangeSpace->localSubDim();
190 const Ordinal leadingDim = (leadingDim_in >= 0 ? leadingDim_in : localSubDim);
194 if (spmdRangeSpace->dim() && localSubDim) {
199 spmdRangeSpace_ = spmdRangeSpace;
200 domainSpace_ = domainSpace;
201 localValues_ = localValues;
202 leadingDim_ = leadingDim;
203 this->updateSpmdSpace();
207 template<
class Scalar>
215 if(spmdRangeSpace) *spmdRangeSpace = spmdRangeSpace_;
216 if(domainSpace) *domainSpace = domainSpace_;
217 if(localValues) *localValues = localValues_;
218 if(leadingDim) *leadingDim = leadingDim_;
220 spmdRangeSpace_ = Teuchos::null;
221 domainSpace_ = Teuchos::null;
222 localValues_ = Teuchos::null;
225 this->updateSpmdSpace();
229 template<
class Scalar>
233 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
234 std::cerr <<
"\nSpmdMultiVectorStd<Scalar>::domainScalarProdVecSpc() const called!\n";
243 template<
class Scalar>
247 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
248 std::cerr <<
"\nSpmdMultiVectorStd<Scalar>::col() called!\n";
256 localValues_.persistingView(j*leadingDim_,spmdRangeSpace_->localSubDim()),
264 template<
class Scalar>
270 const Range1D colRng = this->validateColRange(col_rng_in);
275 spmdRangeSpace_->smallVecSpcFcty()->createVecSpc(colRng.
size())
278 localValues_.persistingView(colRng.
lbound()*leadingDim_,colRng.
size()*spmdRangeSpace_->localSubDim()),
285 template<
class Scalar>
292 this->contigSubViewImpl(col_rng_in));
302 template<
class Scalar>
308 THYRA_DEBUG_ASSERT_MV_COLS(
"nonContigSubViewImpl(cols)", cols);
309 const int numCols = cols.
size();
311 return defaultSpmdMultiVector<Scalar>(
313 createSmallScalarProdVectorSpaceBase<Scalar>(spmdRangeSpace_, numCols),
319 template<
class Scalar>
324 THYRA_DEBUG_ASSERT_MV_COLS(
"nonContigSubViewImpl(cols)", cols);
325 const int numCols = cols.
size();
327 const Ordinal localSubDim = spmdRangeSpace_->localSubDim();
329 copyBackSpmdMultiVectorEntries<Scalar>(cols, localValuesView.
getConst(),
330 localSubDim, localValues_.
create_weak(), leadingDim_);
331 return Teuchos::rcpWithEmbeddedObjPreDestroy(
334 createSmallScalarProdVectorSpaceBase<Scalar>(spmdRangeSpace_, numCols),
344 template<
class Scalar>
348 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
349 std::cerr <<
"\nSpmdMultiVectorStd<Scalar>::spmdSpace() const called!\n";
351 return spmdRangeSpace_;
355 template<
class Scalar>
360 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
361 std::cerr <<
"\nSpmdMultiVectorStd<Scalar>::getLocalMultiVectorDataImpl() called!\n";
363 *localValues = localValues_;
364 *leadingDim = leadingDim_;
368 template<
class Scalar>
373 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
374 std::cerr <<
"\nSpmdMultiVectorStd<Scalar>::getLocalData() called!\n";
376 *localValues = localValues_;
377 *leadingDim = leadingDim_;
384 template<
class Scalar>
391 const int numCols = cols.
size();
392 const Ordinal localSubDim = spmdRangeSpace_->localSubDim();
393 ArrayRCP<Scalar> localValuesView = Teuchos::arcp<Scalar>(numCols*localSubDim);
395 const const_itr_t lv = localValues_.
begin();
396 const itr_t lvv = localValuesView.
begin();
397 for (
int k = 0; k < numCols; ++k) {
398 const int col_k = cols[k];
399 const const_itr_t lv_k = lv + leadingDim_*col_k;
400 const itr_t lvv_k = lvv + localSubDim*k;
401 std::copy(lv_k, lv_k+localSubDim, lvv_k);
403 return localValuesView;
410 #endif // THYRA_DEFAULT_SPMD_MULTI_VECTOR_DEF_HPP
const const Scalar * const_iterator
RCP< MultiVectorBase< Scalar > > nonconstContigSubViewImpl(const Range1D &colRng)
ArrayRCP< T > create_weak() const
bool is_null(const boost::shared_ptr< T > &p)
RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpaceImpl() const
#define TEUCHOS_ASSERT_INEQUALITY(val1, comp, val2)
ArrayRCP< const T > getConst() const
RCP< VectorBase< Scalar > > nonconstColImpl(Ordinal j)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
void getLocalMultiVectorDataImpl(const Ptr< ArrayRCP< const Scalar > > &localValues, const Ptr< Ordinal > &leadingDim) const
Interface for a collection of column vectors called a multi-vector.
void getNonconstLocalMultiVectorDataImpl(const Ptr< ArrayRCP< Scalar > > &localValues, const Ptr< Ordinal > &leadingDim)
Efficient concrete implementation subclass for SPMD vectors.
RCP< MultiVectorBase< Scalar > > nonconstNonContigSubViewImpl(const ArrayView< const int > &cols)
bool nonnull(const boost::shared_ptr< T > &p)
RCP< const ScalarProdVectorSpaceBase< Scalar > > domainScalarProdVecSpc() const
void uninitialize(RCP< const SpmdVectorSpaceBase< Scalar > > *spmdRangeSpace=NULL, RCP< const ScalarProdVectorSpaceBase< Scalar > > *domainSpace=NULL, ArrayRCP< Scalar > *localValues=NULL, Ordinal *leadingDim=NULL)
Set to an uninitialized state.
RCP< const MultiVectorBase< Scalar > > nonContigSubViewImpl(const ArrayView< const int > &cols) const
Efficient concrete implementation subclass for SPMD multi-vectors.
DefaultSpmdMultiVector()
Construct to uninitialized.
void initialize(const RCP< const SpmdVectorSpaceBase< Scalar > > &spmdRangeSpace, const RCP< const ScalarProdVectorSpaceBase< Scalar > > &domainSpace)
Initialize only with vector spaces where storage is allocated internally..
#define TEUCHOS_ASSERT(assertion_test)
Base abstract VectorSpaceBase class for all SPMD-based vector spaces.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
RCP< const MultiVectorBase< Scalar > > contigSubViewImpl(const Range1D &colRng) const