RTOp Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RTOpPack_RTOpSubRangeDecorator_def.hpp
Go to the documentation of this file.
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_RTOP_SUB_RANGE_DECORATOR_DEF_HPP
12 #define RTOPPACK_RTOP_SUB_RANGE_DECORATOR_DEF_HPP
13 
14 
16 
17 
18 namespace RTOpPack {
19 
20 
21 // Constructors, accessors
22 
23 
24 template<class Scalar>
26  : first_ele_offset_(0), sub_dim_(-1)
27 {}
28 
29 
30 template<class Scalar>
32  const RCP<RTOpT<Scalar> > &op,
33  const Ordinal first_ele_offset,
34  const Ordinal sub_dim
35  )
36  : first_ele_offset_(0), sub_dim_(-1)
37 {
38  nonconstInitialize(op, first_ele_offset, sub_dim);
39 }
40 
41 
42 template<class Scalar>
44  const RCP<const RTOpT<Scalar> > &op,
45  const Ordinal first_ele_offset,
46  const Ordinal sub_dim
47  )
48  : first_ele_offset_(0), sub_dim_(-1)
49 {
50  initialize(op, first_ele_offset, sub_dim);
51 }
52 
53 
54 template<class Scalar>
55 void
57  const RCP<RTOpT<Scalar> > &op,
58  const Ordinal first_ele_offset,
59  const Ordinal sub_dim
60  )
61 {
62  op_.initialize(op);
63  first_ele_offset_ = first_ele_offset;
64  sub_dim_ = sub_dim;
65 }
66 
67 
68 template<class Scalar>
69 void
71  const RCP<const RTOpT<Scalar> > &op,
72  const Ordinal first_ele_offset,
73  const Ordinal sub_dim
74  )
75 {
76  op_.initialize(op);
77  first_ele_offset_ = first_ele_offset;
78  sub_dim_ = sub_dim;
79 }
80 
81 
82 template<class Scalar>
85 {
86  return op_.getNonconstObj();
87 }
88 
89 
90 template<class Scalar>
93 {
94  return op_.getConstObj();
95 }
96 
97 
98 // Overridden from RTOpT
99 
100 
101 template<class Scalar>
103  const Ptr<int> &num_values,
104  const Ptr<int> &num_indexes,
105  const Ptr<int> &num_chars
106  ) const
107 {
108  op_->get_reduct_type_num_entries(num_values, num_indexes, num_chars);
109 }
110 
111 
112 template<class Scalar>
115 {
116  return op_->reduct_obj_create();
117 }
118 
119 
120 template<class Scalar>
122  const ReductTarget &in_reduct_obj, const Ptr<ReductTarget> &inout_reduct_obj
123  ) const
124 {
125  op_->reduce_reduct_objs(in_reduct_obj, inout_reduct_obj);
126 }
127 
128 
129 template<class Scalar>
131  const Ptr<ReductTarget> &reduct_obj ) const
132 {
133  op_->reduct_obj_reinit(reduct_obj);
134 }
135 
136 
137 template<class Scalar>
139  const ReductTarget &reduct_obj,
140  const ArrayView<primitive_value_type> &value_data,
141  const ArrayView<index_type> &index_data,
142  const ArrayView<char_type> &char_data
143  ) const
144 {
145  op_->extract_reduct_obj_state(reduct_obj, value_data, index_data, char_data);
146 }
147 
148 
149 template<class Scalar>
151  const ArrayView<const primitive_value_type> &value_data,
152  const ArrayView<const index_type> &index_data,
153  const ArrayView<const char_type> &char_data,
154  const Ptr<ReductTarget> &reduct_obj
155  ) const
156 {
157  op_->load_reduct_obj_state(value_data, index_data, char_data, reduct_obj);
158 }
159 
160 
161 template<class Scalar>
163 {
164  return (std::string("RTOpSubRangeDecorator{")+op_->op_name()+"}");
165 }
166 
167 
168 template<class Scalar>
170 {
171  return op_->coord_invariant();
172 }
173 
174 
175 template<class Scalar>
177  const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
178  const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
179  const Ptr<ReductTarget> &reduct_obj
180  ) const
181 {
182 
183  // Check for full overlap
184  if (first_ele_offset_ == 0 && sub_dim_ < 0) {
185  // Entire range, just fall through
186  op_->apply_op(sub_vecs, targ_sub_vecs, reduct_obj);
187  return;
188  }
189 
190  const Ordinal globalOffset =
191  (sub_vecs.size() ? sub_vecs[0].globalOffset(): targ_sub_vecs[0].globalOffset());
192  const Ordinal subDim =
193  (sub_vecs.size() ? sub_vecs[0].subDim(): targ_sub_vecs[0].subDim());
194 
195  // Check for no overlap
196  if (globalOffset >= first_ele_offset_ + sub_dim_) {
197  // No overlap
198  return;
199  }
200  if (globalOffset + subDim <= first_ele_offset_) {
201  // NO overlap
202  return;
203  }
204 
205  const Ordinal localOffset =
206  (first_ele_offset_ > globalOffset
207  ? first_ele_offset_ - globalOffset
208  : 0);
209 
210  const Ordinal localSubDim =
211  std::min(globalOffset + subDim, first_ele_offset_ + sub_dim_)
212  - (globalOffset + localOffset);
213 
214  Array<ConstSubVectorView<Scalar> > sub_sub_vecs(sub_vecs.size());
215  for (int k = 0; k < sub_vecs.size(); ++k) {
216  const Ordinal stride = sub_vecs[k].stride();
217  sub_sub_vecs[k].initialize(
218  globalOffset+ localOffset,
219  localSubDim,
220  sub_vecs[k].values().persistingView(localOffset*stride, localSubDim*stride),
221  stride
222  );
223  }
224 
225  Array<SubVectorView<Scalar> > targ_sub_sub_vecs(targ_sub_vecs.size());
226  for (int k = 0; k < targ_sub_vecs.size(); ++k) {
227  const Ordinal stride = targ_sub_vecs[k].stride();
228  targ_sub_sub_vecs[k].initialize(
229  globalOffset+ localOffset,
230  localSubDim,
231  targ_sub_vecs[k].values().persistingView(localOffset*stride, localSubDim*stride),
232  stride
233  );
234  }
235 
236  op_->apply_op(sub_sub_vecs(), targ_sub_sub_vecs(), reduct_obj);
237 
238 }
239 
240 
241 } // namespace RTOpPack
242 
243 
244 #endif // RTOPPACK_RTOP_SUB_RANGE_DECORATOR_DEF_HPP
void reduct_obj_reinit_impl(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 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
Class for a changeable sub-vector.
void nonconstInitialize(const RCP< RTOpT< Scalar > > &op, const Ordinal first_ele_offset=0, const Ordinal sub_dim=-1)
void reduce_reduct_objs_impl(const ReductTarget &in_reduct_obj, const Ptr< ReductTarget > &inout_reduct_obj) const
Class for a non-changeable sub-vector.
Templated interface to vector reduction/transformation operators {abstract}.
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
Abstract base class for all reduction objects.
Teuchos::RCP< ReductTarget > reduct_obj_create_impl() const
void initialize(const RCP< const RTOpT< Scalar > > &op, const Ordinal first_ele_offset=0, const Ordinal sub_dim=-1)
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
RCP< const RTOpT< Scalar > > getOp() const
Teuchos_Ordinal Ordinal