10 #ifndef THYRA_SPMD_VECTOR_DEFAULT_BASE_DEF_HPP
11 #define THYRA_SPMD_VECTOR_DEFAULT_BASE_DEF_HPP
14 #if defined (__clang__) && !defined (__INTEL_COMPILER)
15 #pragma clang system_header
18 #include "Thyra_SpmdVectorDefaultBase_decl.hpp"
19 #include "Thyra_VectorDefaultBase.hpp"
20 #include "Thyra_SpmdVectorSpaceDefaultBase.hpp"
21 #include "Thyra_apply_op_helper.hpp"
22 #include "Thyra_SpmdLocalDataAccess.hpp"
23 #include "RTOpPack_SPMD_apply_op.hpp"
24 #include "Teuchos_Workspace.hpp"
25 #include "Teuchos_Assert.hpp"
26 #include "Teuchos_dyn_cast.hpp"
27 #include "Teuchos_Assert.hpp"
28 #include "Teuchos_Range1D.hpp"
36 template<
class Scalar>
44 template<
class Scalar>
58 using Teuchos::rcpFromPtr;
60 const int num_vecs = vecs.
size();
61 const int num_targ_vecs = targ_vecs.size();
68 "SpmdVectorDefaultBase<>::applyOp(...)",*space(),
69 op, vecs, targ_vecs, reduct_obj, global_offset_in);
74 comm = Teuchos::rcpFromPtr(comm_in);
82 const Range1D local_rng(localOffset_, localOffset_+localSubDim_-1);
85 Workspace<RTOpPack::ConstSubVectorView<Scalar> > sub_vecs(wss.
get(), num_vecs);
86 Workspace<RTOpPack::SubVectorView<Scalar> > sub_targ_vecs(wss.
get(), num_targ_vecs);
87 for(
int k = 0; k < num_vecs; ++k ) {
88 sub_vecs[k] = getLocalSubVectorView<Scalar>(rcpFromPtr(vecs[k]));
89 sub_vecs[k].setGlobalOffset(localOffset_+global_offset_in);
91 for(
int k = 0; k < num_targ_vecs; ++k ) {
92 sub_targ_vecs[k] = getNonconstLocalSubVectorView<Scalar>(rcpFromPtr(targ_vecs[k]));
93 sub_targ_vecs[k].setGlobalOffset(localOffset_+global_offset_in);
97 RTOpPack::SPMD_apply_op(
98 locallyReplicated ? NULL : &*comm,
101 sub_vecs.getRawPtr(),
103 sub_targ_vecs.getRawPtr(),
108 for (
int k = 0; k < num_vecs; ++k ) {
111 for (
int k = 0; k < num_targ_vecs; ++k ) {
121 template<
class Scalar>
126 std::ostringstream ostr;
127 ostr<<
typeName(*
this)<<
"{spmdSpace="<<this->spmdSpace()->description()<<
"}";
135 template<
class Scalar>
139 return this->spmdSpace();
149 template<
class Scalar>
158 applyOpImplWithComm( Teuchos::null, op, vecs, targ_vecs, reduct_obj,
163 template<
class Scalar>
171 if( rng_in == Range1D::INVALID ) {
177 const Range1D rng = validateRange(rng_in);
178 const bool isLocallyReplicated = this->spmdSpace()->isLocallyReplicated();
181 rng.
lbound() < localOffset_
183 localOffset_+localSubDim_-1 < rng.
ubound()
197 this->getLocalData(Teuchos::outArg(localValues));
207 template<
class Scalar>
216 ,
"SpmdVectorDefaultBase<Scalar>::releaseDetachedVectorViewImpl(...) : Error, this sub vector was not gotten from acquireDetachedView(...)!"
233 template<
class Scalar>
241 if( rng_in == Range1D::INVALID ) {
247 const Range1D rng = validateRange(rng_in);
248 const bool isLocallyReplicated = this->spmdSpace()->isLocallyReplicated();
251 rng.
lbound() < localOffset_
253 localOffset_+localSubDim_-1 < rng.
ubound()
267 this->getNonconstLocalData(Teuchos::outArg(localValues));
277 template<
class Scalar>
286 ,
"SpmdVectorDefaultBase<Scalar>::commitDetachedView(...) : Error, this sub vector was not gotten from acquireDetachedView(...)!"
306 template<
class Scalar>
311 this->getNonconstLocalData(Teuchos::outArg(localValues));
323 template<
class Scalar>
327 using Teuchos::outArg;
329 this->getLocalData(outArg(localValues));
341 template<
class Scalar>
345 this->getNonconstLocalData(localValues);
346 *leadingDim = localValues->size();
350 template<
class Scalar>
354 this->getLocalData(localValues);
355 *leadingDim = localValues->size();
362 template<
class Scalar>
367 this->getNonconstLocalData(Teuchos::outArg(localValues));
377 template<
class Scalar>
382 this->getLocalData(Teuchos::outArg(localValues));
395 template<
class Scalar>
398 if(globalDim_ == 0) {
401 globalDim_ = l_spmdSpace->
dim();
417 template<
class Scalar>
420 const Range1D rng = Teuchos::full_range(rng_in,0,globalDim_-1);
423 !(0 <= rng.
lbound() && rng.
ubound() < globalDim_), std::invalid_argument
424 ,
"SpmdVectorDefaultBase<Scalar>::validateRange(...): Error, the range ["
426 "in the range [0,"<<(globalDim_-1)<<
"]!"
433 #ifdef THYRA_SPMD_VECTOR_BASE_DUMP
434 template<
class Scalar>
435 bool SpmdVectorDefaultBase<Scalar>::show_dump =
false;
436 #endif // THYRA_SPMD_VECTOR_BASE_DUMP
442 #endif // THYRA_SPMD_VECTOR_DEFAULT_BASE_DEF_HPP
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
Calls applyOpImplWithComm(null,op,...).
RTOpPack::SubVectorView< Scalar > getNonconstLocalSubVectorImpl()
Virtual implementation for getNonconstLocalSubVector().
ArrayRCP< T > persistingView(size_type lowerOffset, size_type size) const
void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Implemented through this->getLocalData()
void apply_op_validate_input(const std::string &func_name, const VectorSpaceBase< Scalar > &space, 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)
Validate the inputs to VectorBase::applyOp().
virtual void releaseDetachedVectorViewImpl(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
virtual void applyOpImplWithComm(const Ptr< const Teuchos::Comm< Ordinal > > &comm, 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
Implementation of applyOpImpl(...) that uses an input Comm.
Base class for SPMD vectors that can provide views of contiguous elements in a process.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
T_To & dyn_cast(T_From &from)
std::string description() const
RTOpPack::SubMultiVectorView< Scalar > getNonconstLocalSubMultiVectorImpl()
virtual void updateSpmdSpace()
Subclasses must call this function whenever the structure of the VectorSpaceBase changes.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
void initialize(Ordinal globalOffset_in, Ordinal subDim_in, const ArrayRCP< Scalar > &values_in, ptrdiff_t stride_in)
Abstract interface for finite-dimensional dense vectors.
Teuchos::RCP< const VectorSpaceBase< Scalar > > space() const
Returns this->spmdSpace().
RTOpPack::ConstSubMultiVectorView< Scalar > getLocalSubMultiVectorImpl() const
Ordinal globalOffset() const
void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)
Implemented through this->commitLocalData()
bool nonnull(const boost::shared_ptr< T > &p)
virtual Teuchos::RCP< const Teuchos::Comm< Ordinal > > getComm() const =0
Returns the SPMD communicator.
virtual Ordinal localOffset() const =0
Returns the offset for the local sub-vector stored on this process.
RTOpPack::ConstSubVectorView< Scalar > getLocalSubVectorImpl() const
Virtual implementation for getLocalSubVector().
virtual void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
void getNonconstLocalMultiVectorDataImpl(const Ptr< ArrayRCP< Scalar > > &localValues, const Ptr< Ordinal > &leadingDim)
void getLocalMultiVectorDataImpl(const Ptr< ArrayRCP< const Scalar > > &localValues, const Ptr< Ordinal > &leadingDim) const
#define TEUCHOS_ASSERT(assertion_test)
virtual void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
void releaseDetachedVectorViewImpl(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Implemented through this->freeLocalData()
Base abstract VectorSpaceBase class for all SPMD-based vector spaces.
virtual Ordinal dim() const =0
Return the dimension of the vector space.
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
std::string typeName(const T &t)
virtual bool isLocallyReplicated() const =0
Returns true if vector space is locally replicated space.
void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
Implemented through this->getLocalData()
virtual Ordinal localSubDim() const =0
Returns the number of local elements stored on this process.
void initialize(Ordinal globalOffset_in, Ordinal subDim_in, const ArrayRCP< const Scalar > &values_in, ptrdiff_t stride_in)
virtual void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)