42 #ifndef THYRA_SPMD_VECTOR_DEFAULT_BASE_DEF_HPP
43 #define THYRA_SPMD_VECTOR_DEFAULT_BASE_DEF_HPP
46 #if defined (__clang__) && !defined (__INTEL_COMPILER)
47 #pragma clang system_header
50 #include "Thyra_SpmdVectorDefaultBase_decl.hpp"
51 #include "Thyra_VectorDefaultBase.hpp"
52 #include "Thyra_SpmdVectorSpaceDefaultBase.hpp"
53 #include "Thyra_apply_op_helper.hpp"
54 #include "Thyra_SpmdLocalDataAccess.hpp"
55 #include "RTOpPack_SPMD_apply_op.hpp"
56 #include "Teuchos_Workspace.hpp"
57 #include "Teuchos_Assert.hpp"
58 #include "Teuchos_dyn_cast.hpp"
59 #include "Teuchos_Assert.hpp"
68 template<
class Scalar>
76 template<
class Scalar>
90 using Teuchos::rcpFromPtr;
92 const int num_vecs = vecs.
size();
93 const int num_targ_vecs = targ_vecs.size();
100 "SpmdVectorDefaultBase<>::applyOp(...)",*space(),
101 op, vecs, targ_vecs, reduct_obj, global_offset_in);
106 comm = Teuchos::rcpFromPtr(comm_in);
114 const Range1D local_rng(localOffset_, localOffset_+localSubDim_-1);
117 Workspace<RTOpPack::ConstSubVectorView<Scalar> > sub_vecs(wss.
get(), num_vecs);
118 Workspace<RTOpPack::SubVectorView<Scalar> > sub_targ_vecs(wss.
get(), num_targ_vecs);
119 for(
int k = 0; k < num_vecs; ++k ) {
120 sub_vecs[k] = getLocalSubVectorView<Scalar>(rcpFromPtr(vecs[k]));
121 sub_vecs[k].setGlobalOffset(localOffset_+global_offset_in);
123 for(
int k = 0; k < num_targ_vecs; ++k ) {
124 sub_targ_vecs[k] = getNonconstLocalSubVectorView<Scalar>(rcpFromPtr(targ_vecs[k]));
125 sub_targ_vecs[k].setGlobalOffset(localOffset_+global_offset_in);
129 RTOpPack::SPMD_apply_op(
130 locallyReplicated ? NULL : &*comm,
133 sub_vecs.getRawPtr(),
135 sub_targ_vecs.getRawPtr(),
140 for (
int k = 0; k < num_vecs; ++k ) {
143 for (
int k = 0; k < num_targ_vecs; ++k ) {
153 template<
class Scalar>
158 std::ostringstream ostr;
159 ostr<<
typeName(*
this)<<
"{spmdSpace="<<this->spmdSpace()->description()<<
"}";
167 template<
class Scalar>
171 return this->spmdSpace();
181 template<
class Scalar>
190 applyOpImplWithComm( Teuchos::null, op, vecs, targ_vecs, reduct_obj,
195 template<
class Scalar>
209 const Range1D rng = validateRange(rng_in);
210 const bool isLocallyReplicated = this->spmdSpace()->isLocallyReplicated();
213 rng.
lbound() < localOffset_
215 localOffset_+localSubDim_-1 < rng.
ubound()
229 this->getLocalData(Teuchos::outArg(localValues));
239 template<
class Scalar>
248 ,
"SpmdVectorDefaultBase<Scalar>::releaseDetachedVectorViewImpl(...) : Error, this sub vector was not gotten from acquireDetachedView(...)!"
265 template<
class Scalar>
279 const Range1D rng = validateRange(rng_in);
280 const bool isLocallyReplicated = this->spmdSpace()->isLocallyReplicated();
283 rng.
lbound() < localOffset_
285 localOffset_+localSubDim_-1 < rng.
ubound()
299 this->getNonconstLocalData(Teuchos::outArg(localValues));
309 template<
class Scalar>
318 ,
"SpmdVectorDefaultBase<Scalar>::commitDetachedView(...) : Error, this sub vector was not gotten from acquireDetachedView(...)!"
338 template<
class Scalar>
343 this->getNonconstLocalData(Teuchos::outArg(localValues));
355 template<
class Scalar>
359 using Teuchos::outArg;
361 this->getLocalData(outArg(localValues));
373 template<
class Scalar>
377 this->getNonconstLocalData(localValues);
378 *leadingDim = localValues->size();
382 template<
class Scalar>
386 this->getLocalData(localValues);
387 *leadingDim = localValues->size();
394 template<
class Scalar>
399 this->getNonconstLocalData(Teuchos::outArg(localValues));
409 template<
class Scalar>
414 this->getLocalData(Teuchos::outArg(localValues));
427 template<
class Scalar>
430 if(globalDim_ == 0) {
433 globalDim_ = l_spmdSpace->
dim();
449 template<
class Scalar>
452 const Range1D rng = Teuchos::full_range(rng_in,0,globalDim_-1);
455 !(0 <= rng.
lbound() && rng.
ubound() < globalDim_), std::invalid_argument
456 ,
"SpmdVectorDefaultBase<Scalar>::validateRange(...): Error, the range ["
458 "in the range [0,"<<(globalDim_-1)<<
"]!"
465 #ifdef THYRA_SPMD_VECTOR_BASE_DUMP
466 template<
class Scalar>
467 bool SpmdVectorDefaultBase<Scalar>::show_dump =
false;
468 #endif // THYRA_SPMD_VECTOR_BASE_DUMP
474 #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().
static const Range1D Invalid
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)