43 #ifndef RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP
44 #define RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP
47 #include "RTOpPack_ROpGetSubVector_decl.hpp"
53 template<
class Scalar>
57 :
RTOpT<Scalar>(
"ROpGetSubVector"), l_(l), u_(u)
61 template<
class Scalar>
71 template<
class Scalar>
83 template<
class Scalar>
85 const Ptr<int> &num_values,
86 const Ptr<int> &num_indexes,
87 const Ptr<int> &num_chars
91 const int num_prim_objs_per_scalar = PTT::numPrimitiveObjs();
92 *num_values = (u_-l_+1)*num_prim_objs_per_scalar;
98 template<
class Scalar>
102 const index_type subDim = u_ - l_ + 1;
103 const ArrayRCP<Scalar> values = Teuchos::arcp<Scalar>(subDim);
104 std::fill(values.begin(), values.end(), ScalarTraits<Scalar>::zero());
105 return defaultReductTarget(
111 template<
class Scalar>
113 const ReductTarget &in_reduct_obj,
const Ptr<ReductTarget> &inout_reduct_obj
120 DRTSVV &drtsvv_inout_reduct_obj =
dyn_cast<DRTSVV>(*inout_reduct_obj);
123 dyn_cast<
const DRTSVV>(in_reduct_obj).
get();
133 || sub_vec_inout.
stride()!=1
135 #endif // TEUCHOS_DEBUG
137 typedef typename ArrayRCP<const Scalar>::const_iterator const_iter_t;
138 typedef typename ArrayRCP<Scalar>::iterator iter_t;
140 const_iter_t in_iter = sub_vec_in.
values().begin();
141 iter_t inout_iter = sub_vec_inout.
values().begin();
143 for(
int k = 0; k < sub_vec_in.
subDim(); ++k ) {
144 *inout_iter++ += *in_iter++;
147 drtsvv_inout_reduct_obj.set(sub_vec_inout);
152 template<
class Scalar>
154 const Ptr<ReductTarget> &reduct_obj )
const
158 DRTSVV &drtsvv_inout_reduct_obj =
dyn_cast<DRTSVV>(*reduct_obj);
160 std::fill( sub_vec.
values().begin(), sub_vec.
values().end(),
161 ScalarTraits<Scalar>::zero() );
165 template<
class Scalar>
168 const ArrayView<primitive_value_type> &value_data,
169 const ArrayView<index_type> &,
170 const ArrayView<char_type> &
176 const int num_prim_objs_per_scalar = PTT::numPrimitiveObjs();
179 int value_data_off = 0;
183 ++k, value_data_off += num_prim_objs_per_scalar
186 PTT::extractPrimitiveObjs( sub_vec[k],
187 value_data(value_data_off, num_prim_objs_per_scalar),
193 template<
class Scalar>
195 const ArrayView<const primitive_value_type> &value_data,
196 const ArrayView<const index_type> &,
197 const ArrayView<const char_type> &,
198 const Ptr<ReductTarget> &reduct_obj
202 using Teuchos::outArg;
204 using Teuchos::arcp_const_cast;
207 const int num_prim_objs_per_scalar = PTT::numPrimitiveObjs();
208 DRTSVV &drtsvv_reduct_obj =
dyn_cast<DRTSVV>(*reduct_obj);
210 const ArrayRCP<Scalar> sv_values =
211 arcp_const_cast<Scalar>(const_sub_vec.
values());
212 int value_data_off = 0;
215 k < const_sub_vec.
subDim();
216 ++k, value_data_off += num_prim_objs_per_scalar
219 PTT::loadPrimitiveObjs(
220 value_data(value_data_off, num_prim_objs_per_scalar), null, null,
221 outArg(sv_values[k]) );
226 template<
class Scalar>
233 template<
class Scalar>
237 const Ptr<ReductTarget> &reduct_obj
244 validate_apply_op( *
this, 1, 0,
true,
245 sub_vecs, targ_sub_vecs, reduct_obj.getConst() );
248 const index_type subDim = sub_vecs[0].subDim();
249 const index_type globalOffset = sub_vecs[0].globalOffset();
251 const_iter_t v0_val = sub_vecs[0].values().begin();
252 const ptrdiff_t v0_s = sub_vecs[0].stride();
254 if( u_ < globalOffset || globalOffset + subDim - 1 < l_ ) {
261 i_l = ( l_ <= globalOffset ? 0 : l_ - globalOffset ),
262 i_u = ( u_ >= globalOffset+subDim-1 ? subDim-1 : u_ - globalOffset );
264 DRTSVV &drtsvv_reduct_obj =
dyn_cast<DRTSVV>(*reduct_obj);
267 const ArrayRCP<Scalar> svt_values = sub_vec_targ.
values();
269 for( index_type i = i_l; i <= i_u; ++i ) {
270 svt_values[i+(globalOffset-l_)] = v0_val[i*v0_s];
273 drtsvv_reduct_obj.set(sub_vec_targ);
281 #endif // RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP
void load_reduct_obj_state_impl(const ArrayView< const primitive_value_type > &value_data, const ArrayView< const index_type > &index_data, const ArrayView< const char_type > &char_data, const Ptr< ReductTarget > &reduct_obj) const
bool is_null(const boost::shared_ptr< T > &p)
void reduce_reduct_objs_impl(const ReductTarget &in_reduct_obj, const Ptr< ReductTarget > &inout_reduct_obj) const
T_To & dyn_cast(T_From &from)
void set_range(const index_type l, const index_type u)
Set the range of global indexes to extract elements for.
void extract_reduct_obj_state_impl(const ReductTarget &reduct_obj, const ArrayView< primitive_value_type > &value_data, const ArrayView< index_type > &index_data, const ArrayView< char_type > &char_data) const
const ArrayRCP< Scalar > values() const
ROpGetSubVector(const index_type l=0, const index_type u=0)
Teuchos::RCP< ReductTarget > reduct_obj_create_impl() const
Ordinal globalOffset() const
void apply_op_impl(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj) const
bool coord_invariant_impl() const
void get_reduct_type_num_entries_impl(const Ptr< int > &num_values, const Ptr< int > &num_indexes, const Ptr< int > &num_chars) const
void reduct_obj_reinit_impl(const Ptr< ReductTarget > &reduct_obj) const
const ConstSubVectorView< Scalar > operator()(const ReductTarget &reduct_obj) const
Extract the subvector after all of the reductions are completed.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
const ArrayRCP< const Scalar > values() const