11 #ifndef RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP
12 #define RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP
15 #include "RTOpPack_ROpGetSubVector_decl.hpp"
21 template<
class Scalar>
25 :
RTOpT<Scalar>(
"ROpGetSubVector"), l_(l), u_(u)
29 template<
class Scalar>
39 template<
class Scalar>
51 template<
class Scalar>
53 const Ptr<int> &num_values,
54 const Ptr<int> &num_indexes,
55 const Ptr<int> &num_chars
59 const int num_prim_objs_per_scalar = PTT::numPrimitiveObjs();
60 *num_values = (u_-l_+1)*num_prim_objs_per_scalar;
66 template<
class Scalar>
70 const index_type subDim = u_ - l_ + 1;
71 const ArrayRCP<Scalar> values = Teuchos::arcp<Scalar>(subDim);
72 std::fill(values.begin(), values.end(), ScalarTraits<Scalar>::zero());
73 return defaultReductTarget(
79 template<
class Scalar>
81 const ReductTarget &in_reduct_obj,
const Ptr<ReductTarget> &inout_reduct_obj
88 DRTSVV &drtsvv_inout_reduct_obj =
dyn_cast<DRTSVV>(*inout_reduct_obj);
91 dyn_cast<
const DRTSVV>(in_reduct_obj).
get();
101 || sub_vec_inout.
stride()!=1
103 #endif // TEUCHOS_DEBUG
105 typedef typename ArrayRCP<const Scalar>::const_iterator const_iter_t;
106 typedef typename ArrayRCP<Scalar>::iterator iter_t;
108 const_iter_t in_iter = sub_vec_in.
values().begin();
109 iter_t inout_iter = sub_vec_inout.
values().begin();
111 for(
int k = 0; k < sub_vec_in.
subDim(); ++k ) {
112 *inout_iter++ += *in_iter++;
115 drtsvv_inout_reduct_obj.set(sub_vec_inout);
120 template<
class Scalar>
122 const Ptr<ReductTarget> &reduct_obj )
const
126 DRTSVV &drtsvv_inout_reduct_obj =
dyn_cast<DRTSVV>(*reduct_obj);
128 std::fill( sub_vec.
values().begin(), sub_vec.
values().end(),
129 ScalarTraits<Scalar>::zero() );
133 template<
class Scalar>
136 const ArrayView<primitive_value_type> &value_data,
137 const ArrayView<index_type> &,
138 const ArrayView<char_type> &
144 const int num_prim_objs_per_scalar = PTT::numPrimitiveObjs();
147 int value_data_off = 0;
151 ++k, value_data_off += num_prim_objs_per_scalar
154 PTT::extractPrimitiveObjs( sub_vec[k],
155 value_data(value_data_off, num_prim_objs_per_scalar),
161 template<
class Scalar>
163 const ArrayView<const primitive_value_type> &value_data,
164 const ArrayView<const index_type> &,
165 const ArrayView<const char_type> &,
166 const Ptr<ReductTarget> &reduct_obj
170 using Teuchos::outArg;
172 using Teuchos::arcp_const_cast;
175 const int num_prim_objs_per_scalar = PTT::numPrimitiveObjs();
176 DRTSVV &drtsvv_reduct_obj =
dyn_cast<DRTSVV>(*reduct_obj);
178 const ArrayRCP<Scalar> sv_values =
179 arcp_const_cast<Scalar>(const_sub_vec.
values());
180 int value_data_off = 0;
183 k < const_sub_vec.
subDim();
184 ++k, value_data_off += num_prim_objs_per_scalar
187 PTT::loadPrimitiveObjs(
188 value_data(value_data_off, num_prim_objs_per_scalar), null, null,
189 outArg(sv_values[k]) );
194 template<
class Scalar>
201 template<
class Scalar>
205 const Ptr<ReductTarget> &reduct_obj
212 validate_apply_op( *
this, 1, 0,
true,
213 sub_vecs, targ_sub_vecs, reduct_obj.getConst() );
216 const index_type subDim = sub_vecs[0].subDim();
217 const index_type globalOffset = sub_vecs[0].globalOffset();
219 const_iter_t v0_val = sub_vecs[0].values().begin();
220 const ptrdiff_t v0_s = sub_vecs[0].stride();
222 if( u_ < globalOffset || globalOffset + subDim - 1 < l_ ) {
229 i_l = ( l_ <= globalOffset ? 0 : l_ - globalOffset ),
230 i_u = ( u_ >= globalOffset+subDim-1 ? subDim-1 : u_ - globalOffset );
232 DRTSVV &drtsvv_reduct_obj =
dyn_cast<DRTSVV>(*reduct_obj);
235 const ArrayRCP<Scalar> svt_values = sub_vec_targ.
values();
237 for( index_type i = i_l; i <= i_u; ++i ) {
238 svt_values[i+(globalOffset-l_)] = v0_val[i*v0_s];
241 drtsvv_reduct_obj.set(sub_vec_targ);
249 #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