10 #ifndef THYRA_DEFAULT_SPMD_MULTI_VECTOR_DEF_HPP
11 #define THYRA_DEFAULT_SPMD_MULTI_VECTOR_DEF_HPP
16 #include "Thyra_DefaultSpmdMultiVector_decl.hpp"
17 #include "Thyra_SpmdMultiVectorDefaultBase.hpp"
18 #include "Thyra_VectorSpaceFactoryBase.hpp"
19 #include "Thyra_DefaultSpmdVector.hpp"
20 #include "Teuchos_Assert.hpp"
31 template<
class Scalar>
32 class CopyBackSpmdMultiVectorEntries {
34 CopyBackSpmdMultiVectorEntries(
35 const ArrayView<const int> &cols,
36 const ArrayRCP<const Scalar> &localValuesView,
const Ordinal localSubDim,
37 const ArrayRCP<Scalar> &localValues,
const Ordinal leadingDim
39 : cols_(cols), localValuesView_(localValuesView), localSubDim_(localSubDim),
40 localValues_(localValues), leadingDim_(leadingDim)
42 ~CopyBackSpmdMultiVectorEntries()
47 if (localValues_.strong_count()) {
48 const int numCols = cols_.size();
49 const const_itr_t lvv = localValuesView_.begin();
50 const itr_t lv = localValues_.begin();
51 for (
int k = 0; k < numCols; ++k) {
52 const int col_k = cols_[k];
53 const const_itr_t lvv_k = lvv + localSubDim_*k;
54 const itr_t lv_k = lv + leadingDim_*col_k;
55 std::copy( lvv_k, lvv_k + localSubDim_, lv_k );
60 ++DefaultSpmdMultiVector<Scalar>::numSkipCopyBack;
66 ArrayRCP<const Scalar> localValuesView_;
68 ArrayRCP<Scalar> localValues_;
71 CopyBackSpmdMultiVectorEntries();
72 CopyBackSpmdMultiVectorEntries(
const CopyBackSpmdMultiVectorEntries&);
73 CopyBackSpmdMultiVectorEntries& operator=(
const CopyBackSpmdMultiVectorEntries&);
77 template<
class Scalar>
78 RCP<CopyBackSpmdMultiVectorEntries<Scalar> >
79 copyBackSpmdMultiVectorEntries(
80 const ArrayView<const int> &cols,
81 const ArrayRCP<const Scalar> &localValuesView,
const Ordinal localSubDim,
82 const ArrayRCP<Scalar> &localValues,
const Ordinal leadingDim
86 new CopyBackSpmdMultiVectorEntries<Scalar>(
87 cols, localValuesView, localSubDim, localValues, leadingDim
99 template<
class Scalar>
100 int DefaultSpmdMultiVector<Scalar>::numSkipCopyBack(0);
107 template<
class Scalar>
113 template<
class Scalar>
123 template<
class Scalar>
131 initialize(spmdRangeSpace,domainSpace,localValues,leadingDim);
135 template<
class Scalar>
141 const Ordinal localSubDim = spmdRangeSpace->localSubDim();
144 values = Teuchos::arcp<Scalar>(localSubDim * domainSpace->dim());
145 initialize(spmdRangeSpace, domainSpace, values, localSubDim);
149 template<
class Scalar>
157 const Ordinal localSubDim = spmdRangeSpace->localSubDim();
158 const Ordinal leadingDim = (leadingDim_in >= 0 ? leadingDim_in : localSubDim);
162 if (spmdRangeSpace->dim() && localSubDim) {
167 spmdRangeSpace_ = spmdRangeSpace;
168 domainSpace_ = domainSpace;
169 localValues_ = localValues;
170 leadingDim_ = leadingDim;
171 this->updateSpmdSpace();
175 template<
class Scalar>
183 if(spmdRangeSpace) *spmdRangeSpace = spmdRangeSpace_;
184 if(domainSpace) *domainSpace = domainSpace_;
185 if(localValues) *localValues = localValues_;
186 if(leadingDim) *leadingDim = leadingDim_;
188 spmdRangeSpace_ = Teuchos::null;
189 domainSpace_ = Teuchos::null;
190 localValues_ = Teuchos::null;
193 this->updateSpmdSpace();
197 template<
class Scalar>
201 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
202 std::cerr <<
"\nSpmdMultiVectorStd<Scalar>::domainScalarProdVecSpc() const called!\n";
211 template<
class Scalar>
215 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
216 std::cerr <<
"\nSpmdMultiVectorStd<Scalar>::col() called!\n";
224 localValues_.persistingView(j*leadingDim_,spmdRangeSpace_->localSubDim()),
232 template<
class Scalar>
238 const Range1D colRng = this->validateColRange(col_rng_in);
243 spmdRangeSpace_->smallVecSpcFcty()->createVecSpc(colRng.
size())
246 localValues_.persistingView(colRng.
lbound()*leadingDim_,colRng.
size()*spmdRangeSpace_->localSubDim()),
253 template<
class Scalar>
260 this->contigSubViewImpl(col_rng_in));
270 template<
class Scalar>
276 THYRA_DEBUG_ASSERT_MV_COLS(
"nonContigSubViewImpl(cols)", cols);
277 const int numCols = cols.
size();
279 return defaultSpmdMultiVector<Scalar>(
281 createSmallScalarProdVectorSpaceBase<Scalar>(spmdRangeSpace_, numCols),
287 template<
class Scalar>
292 THYRA_DEBUG_ASSERT_MV_COLS(
"nonContigSubViewImpl(cols)", cols);
293 const int numCols = cols.
size();
295 const Ordinal localSubDim = spmdRangeSpace_->localSubDim();
297 copyBackSpmdMultiVectorEntries<Scalar>(cols, localValuesView.
getConst(),
298 localSubDim, localValues_.
create_weak(), leadingDim_);
299 return Teuchos::rcpWithEmbeddedObjPreDestroy(
302 createSmallScalarProdVectorSpaceBase<Scalar>(spmdRangeSpace_, numCols),
312 template<
class Scalar>
316 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
317 std::cerr <<
"\nSpmdMultiVectorStd<Scalar>::spmdSpace() const called!\n";
319 return spmdRangeSpace_;
323 template<
class Scalar>
328 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
329 std::cerr <<
"\nSpmdMultiVectorStd<Scalar>::getLocalMultiVectorDataImpl() called!\n";
331 *localValues = localValues_;
332 *leadingDim = leadingDim_;
336 template<
class Scalar>
341 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
342 std::cerr <<
"\nSpmdMultiVectorStd<Scalar>::getLocalData() called!\n";
344 *localValues = localValues_;
345 *leadingDim = leadingDim_;
352 template<
class Scalar>
359 const int numCols = cols.
size();
360 const Ordinal localSubDim = spmdRangeSpace_->localSubDim();
361 ArrayRCP<Scalar> localValuesView = Teuchos::arcp<Scalar>(numCols*localSubDim);
363 const const_itr_t lv = localValues_.
begin();
364 const itr_t lvv = localValuesView.
begin();
365 for (
int k = 0; k < numCols; ++k) {
366 const int col_k = cols[k];
367 const const_itr_t lv_k = lv + leadingDim_*col_k;
368 const itr_t lvv_k = lvv + localSubDim*k;
369 std::copy(lv_k, lv_k+localSubDim, lvv_k);
371 return localValuesView;
378 #endif // THYRA_DEFAULT_SPMD_MULTI_VECTOR_DEF_HPP
const const Scalar * const_iterator
void initialize(int *argc, char ***argv)
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