Collection of Concrete Vector Reduction/Transformation Operator Implementations  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RTOpPack_ROpGetSubVector_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // RTOp: Interfaces and Support Software for Vector Reduction Transformation
4 // Operations
5 //
6 // Copyright 2006 NTESS and the RTOp contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #ifndef RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP
12 #define RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP
13 
14 
15 #include "RTOpPack_ROpGetSubVector_decl.hpp"
16 
17 
18 namespace RTOpPack {
19 
20 
21 template<class Scalar>
23  const index_type u
24  )
25  :RTOpT<Scalar>("ROpGetSubVector"), l_(l), u_(u)
26 {}
27 
28 
29 template<class Scalar>
30 void ROpGetSubVector<Scalar>::set_range( const index_type l,
31  const index_type u
32  )
33 {
34  l_ = l;
35  u_ = u;
36 }
37 
38 
39 template<class Scalar>
42 {
43  using Teuchos::dyn_cast;
44  return dyn_cast<const DefaultReductTarget<SubVectorView< Scalar> > >(reduct_obj).get();
45 }
46 
47 
48 // Overridden from RTOpT
49 
50 
51 template<class Scalar>
53  const Ptr<int> &num_values,
54  const Ptr<int> &num_indexes,
55  const Ptr<int> &num_chars
56  ) const
57 {
59  const int num_prim_objs_per_scalar = PTT::numPrimitiveObjs();
60  *num_values = (u_-l_+1)*num_prim_objs_per_scalar;
61  *num_indexes = 0;
62  *num_chars = 0;
63 }
64 
65 
66 template<class Scalar>
69 {
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(
74  SubVectorView<Scalar>( l_, subDim, values, 1 )
75  );
76 }
77 
78 
79 template<class Scalar>
81  const ReductTarget &in_reduct_obj, const Ptr<ReductTarget> &inout_reduct_obj
82  ) const
83 {
84 
85  using Teuchos::dyn_cast;
87 
88  DRTSVV &drtsvv_inout_reduct_obj = dyn_cast<DRTSVV>(*inout_reduct_obj);
89 
90  const ConstSubVectorView<Scalar> sub_vec_in =
91  dyn_cast<const DRTSVV>(in_reduct_obj).get();
92  SubVectorView<Scalar> sub_vec_inout = drtsvv_inout_reduct_obj.get();
93 
94 #ifdef TEUCHOS_DEBUG
96  sub_vec_in.subDim()!=sub_vec_inout.subDim()
97  || sub_vec_in.globalOffset()!=sub_vec_inout.globalOffset()
98  || is_null(sub_vec_in.values())
99  || is_null(sub_vec_inout.values())
100  || sub_vec_in.stride()!=1
101  || sub_vec_inout.stride()!=1
102  );
103 #endif // TEUCHOS_DEBUG
104 
105  typedef typename ArrayRCP<const Scalar>::const_iterator const_iter_t;
106  typedef typename ArrayRCP<Scalar>::iterator iter_t;
107 
108  const_iter_t in_iter = sub_vec_in.values().begin();
109  iter_t inout_iter = sub_vec_inout.values().begin();
110 
111  for( int k = 0; k < sub_vec_in.subDim(); ++k ) {
112  *inout_iter++ += *in_iter++;
113  }
114 
115  drtsvv_inout_reduct_obj.set(sub_vec_inout);
116 
117 }
118 
119 
120 template<class Scalar>
122  const Ptr<ReductTarget> &reduct_obj ) const
123 {
124  using Teuchos::dyn_cast;
126  DRTSVV &drtsvv_inout_reduct_obj = dyn_cast<DRTSVV>(*reduct_obj);
127  SubVectorView<Scalar> sub_vec = drtsvv_inout_reduct_obj.get();
128  std::fill( sub_vec.values().begin(), sub_vec.values().end(),
129  ScalarTraits<Scalar>::zero() );
130 }
131 
132 
133 template<class Scalar>
135  const ReductTarget &reduct_obj,
136  const ArrayView<primitive_value_type> &value_data,
137  const ArrayView<index_type> &/* index_data */,
138  const ArrayView<char_type> &/* char_data */
139  ) const
140 {
141  using Teuchos::null;
142  using Teuchos::dyn_cast;
144  const int num_prim_objs_per_scalar = PTT::numPrimitiveObjs();
145  const ConstSubVectorView<Scalar> sub_vec =
146  dyn_cast<const DefaultReductTarget<SubVectorView<Scalar> > >(reduct_obj).get();
147  int value_data_off = 0;
148  for(
149  int k = 0;
150  k < sub_vec.subDim();
151  ++k, value_data_off += num_prim_objs_per_scalar
152  )
153  {
154  PTT::extractPrimitiveObjs( sub_vec[k],
155  value_data(value_data_off, num_prim_objs_per_scalar),
156  null, null );
157  }
158 }
159 
160 
161 template<class Scalar>
163  const ArrayView<const primitive_value_type> &value_data,
164  const ArrayView<const index_type> &/* index_data */,
165  const ArrayView<const char_type> &/* char_data */,
166  const Ptr<ReductTarget> &reduct_obj
167  ) const
168 {
169  using Teuchos::null;
170  using Teuchos::outArg;
171  using Teuchos::dyn_cast;
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);
177  const ConstSubVectorView<Scalar> const_sub_vec = drtsvv_reduct_obj.get();
178  const ArrayRCP<Scalar> sv_values =
179  arcp_const_cast<Scalar>(const_sub_vec.values());
180  int value_data_off = 0;
181  for(
182  int k = 0;
183  k < const_sub_vec.subDim();
184  ++k, value_data_off += num_prim_objs_per_scalar
185  )
186  {
187  PTT::loadPrimitiveObjs(
188  value_data(value_data_off, num_prim_objs_per_scalar), null, null,
189  outArg(sv_values[k]) );
190  }
191 }
192 
193 
194 template<class Scalar>
196 {
197  return false;
198 }
199 
200 
201 template<class Scalar>
203  const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
204  const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
205  const Ptr<ReductTarget> &reduct_obj
206  ) const
207 {
208 
209  using Teuchos::dyn_cast;
211 
212  validate_apply_op( *this, 1, 0, true,
213  sub_vecs, targ_sub_vecs, reduct_obj.getConst() );
214 
215  typedef typename Teuchos::ArrayRCP<const Scalar>::iterator const_iter_t;
216  const index_type subDim = sub_vecs[0].subDim();
217  const index_type globalOffset = sub_vecs[0].globalOffset();
218  TEUCHOS_TEST_FOR_EXCEPT(globalOffset<0);
219  const_iter_t v0_val = sub_vecs[0].values().begin();
220  const ptrdiff_t v0_s = sub_vecs[0].stride();
221 
222  if( u_ < globalOffset || globalOffset + subDim - 1 < l_ ) {
223  // None of the sub-vector elements that we are looking for is in this
224  // vector chunk!
225  return;
226  }
227 
228  index_type
229  i_l = ( l_ <= globalOffset ? 0 : l_ - globalOffset ),
230  i_u = ( u_ >= globalOffset+subDim-1 ? subDim-1 : u_ - globalOffset );
231 
232  DRTSVV &drtsvv_reduct_obj = dyn_cast<DRTSVV>(*reduct_obj);
233  SubVectorView<Scalar> sub_vec_targ = drtsvv_reduct_obj.get();
234 
235  const ArrayRCP<Scalar> svt_values = sub_vec_targ.values();
236 
237  for( index_type i = i_l; i <= i_u; ++i ) {
238  svt_values[i+(globalOffset-l_)] = v0_val[i*v0_s];
239  }
240 
241  drtsvv_reduct_obj.set(sub_vec_targ);
242 
243 }
244 
245 
246 } // namespace RTOpPack
247 
248 
249 #endif // RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP
ptrdiff_t stride() const
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
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