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 //
4 // RTOp: Interfaces and Support Software for Vector Reduction Transformation
5 // Operations
6 // Copyright (2006) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 
43 #ifndef RTOPPACK_RTOP_SUB_RANGE_DECORATOR_DEF_HPP
44 #define RTOPPACK_RTOP_SUB_RANGE_DECORATOR_DEF_HPP
45 
46 
48 
49 
50 namespace RTOpPack {
51 
52 
53 // Constructors, accessors
54 
55 
56 template<class Scalar>
58  : first_ele_offset_(0), sub_dim_(-1)
59 {}
60 
61 
62 template<class Scalar>
64  const RCP<RTOpT<Scalar> > &op,
65  const Ordinal first_ele_offset,
66  const Ordinal sub_dim
67  )
68  : first_ele_offset_(0), sub_dim_(-1)
69 {
70  nonconstInitialize(op, first_ele_offset, sub_dim);
71 }
72 
73 
74 template<class Scalar>
76  const RCP<const RTOpT<Scalar> > &op,
77  const Ordinal first_ele_offset,
78  const Ordinal sub_dim
79  )
80  : first_ele_offset_(0), sub_dim_(-1)
81 {
82  initialize(op, first_ele_offset, sub_dim);
83 }
84 
85 
86 template<class Scalar>
87 void
89  const RCP<RTOpT<Scalar> > &op,
90  const Ordinal first_ele_offset,
91  const Ordinal sub_dim
92  )
93 {
94  op_.initialize(op);
95  first_ele_offset_ = first_ele_offset;
96  sub_dim_ = sub_dim;
97 }
98 
99 
100 template<class Scalar>
101 void
103  const RCP<const RTOpT<Scalar> > &op,
104  const Ordinal first_ele_offset,
105  const Ordinal sub_dim
106  )
107 {
108  op_.initialize(op);
109  first_ele_offset_ = first_ele_offset;
110  sub_dim_ = sub_dim;
111 }
112 
113 
114 template<class Scalar>
117 {
118  return op_.getNonconstObj();
119 }
120 
121 
122 template<class Scalar>
125 {
126  return op_.getConstObj();
127 }
128 
129 
130 // Overridden from RTOpT
131 
132 
133 template<class Scalar>
135  const Ptr<int> &num_values,
136  const Ptr<int> &num_indexes,
137  const Ptr<int> &num_chars
138  ) const
139 {
140  op_->get_reduct_type_num_entries(num_values, num_indexes, num_chars);
141 }
142 
143 
144 template<class Scalar>
147 {
148  return op_->reduct_obj_create();
149 }
150 
151 
152 template<class Scalar>
154  const ReductTarget &in_reduct_obj, const Ptr<ReductTarget> &inout_reduct_obj
155  ) const
156 {
157  op_->reduce_reduct_objs(in_reduct_obj, inout_reduct_obj);
158 }
159 
160 
161 template<class Scalar>
163  const Ptr<ReductTarget> &reduct_obj ) const
164 {
165  op_->reduct_obj_reinit(reduct_obj);
166 }
167 
168 
169 template<class Scalar>
171  const ReductTarget &reduct_obj,
172  const ArrayView<primitive_value_type> &value_data,
173  const ArrayView<index_type> &index_data,
174  const ArrayView<char_type> &char_data
175  ) const
176 {
177  op_->extract_reduct_obj_state(reduct_obj, value_data, index_data, char_data);
178 }
179 
180 
181 template<class Scalar>
183  const ArrayView<const primitive_value_type> &value_data,
184  const ArrayView<const index_type> &index_data,
185  const ArrayView<const char_type> &char_data,
186  const Ptr<ReductTarget> &reduct_obj
187  ) const
188 {
189  op_->load_reduct_obj_state(value_data, index_data, char_data, reduct_obj);
190 }
191 
192 
193 template<class Scalar>
195 {
196  return (std::string("RTOpSubRangeDecorator{")+op_->op_name()+"}");
197 }
198 
199 
200 template<class Scalar>
202 {
203  return op_->coord_invariant();
204 }
205 
206 
207 template<class Scalar>
209  const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
210  const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
211  const Ptr<ReductTarget> &reduct_obj
212  ) const
213 {
214 
215  // Check for full overlap
216  if (first_ele_offset_ == 0 && sub_dim_ < 0) {
217  // Entire range, just fall through
218  op_->apply_op(sub_vecs, targ_sub_vecs, reduct_obj);
219  return;
220  }
221 
222  const Ordinal globalOffset =
223  (sub_vecs.size() ? sub_vecs[0].globalOffset(): targ_sub_vecs[0].globalOffset());
224  const Ordinal subDim =
225  (sub_vecs.size() ? sub_vecs[0].subDim(): targ_sub_vecs[0].subDim());
226 
227  // Check for no overlap
228  if (globalOffset >= first_ele_offset_ + sub_dim_) {
229  // No overlap
230  return;
231  }
232  if (globalOffset + subDim <= first_ele_offset_) {
233  // NO overlap
234  return;
235  }
236 
237  const Ordinal localOffset =
238  (first_ele_offset_ > globalOffset
239  ? first_ele_offset_ - globalOffset
240  : 0);
241 
242  const Ordinal localSubDim =
243  std::min(globalOffset + subDim, first_ele_offset_ + sub_dim_)
244  - (globalOffset + localOffset);
245 
246  Array<ConstSubVectorView<Scalar> > sub_sub_vecs(sub_vecs.size());
247  for (int k = 0; k < sub_vecs.size(); ++k) {
248  const Ordinal stride = sub_vecs[k].stride();
249  sub_sub_vecs[k].initialize(
250  globalOffset+ localOffset,
251  localSubDim,
252  sub_vecs[k].values().persistingView(localOffset*stride, localSubDim*stride),
253  stride
254  );
255  }
256 
257  Array<SubVectorView<Scalar> > targ_sub_sub_vecs(targ_sub_vecs.size());
258  for (int k = 0; k < targ_sub_vecs.size(); ++k) {
259  const Ordinal stride = targ_sub_vecs[k].stride();
260  targ_sub_sub_vecs[k].initialize(
261  globalOffset+ localOffset,
262  localSubDim,
263  targ_sub_vecs[k].values().persistingView(localOffset*stride, localSubDim*stride),
264  stride
265  );
266  }
267 
268  op_->apply_op(sub_sub_vecs(), targ_sub_sub_vecs(), reduct_obj);
269 
270 }
271 
272 
273 } // namespace RTOpPack
274 
275 
276 #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