RTOp Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
50namespace RTOpPack {
51
52
53// Constructors, accessors
54
55
56template<class Scalar>
58 : first_ele_offset_(0), sub_dim_(-1)
59{}
60
61
62template<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
74template<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
86template<class Scalar>
87void
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
100template<class Scalar>
101void
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
114template<class Scalar>
115RCP<RTOpT<Scalar> >
117{
118 return op_.getNonconstObj();
119}
120
121
122template<class Scalar>
123RCP<const RTOpT<Scalar> >
125{
126 return op_.getConstObj();
127}
128
129
130// Overridden from RTOpT
131
132
133template<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
144template<class Scalar>
145Teuchos::RCP<ReductTarget>
150
151
152template<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
161template<class Scalar>
163 const Ptr<ReductTarget> &reduct_obj ) const
164{
165 op_->reduct_obj_reinit(reduct_obj);
166}
167
168
169template<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
181template<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
193template<class Scalar>
195{
196 return (std::string("RTOpSubRangeDecorator{")+op_->op_name()+"}");
197}
198
199
200template<class Scalar>
205
206
207template<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
Decorator subclass that restricts the range of elements to apply the underlying RTOpT object to.
void initialize(const RCP< const RTOpT< Scalar > > &op, const Ordinal first_ele_offset=0, const Ordinal sub_dim=-1)
void nonconstInitialize(const RCP< RTOpT< Scalar > > &op, const Ordinal first_ele_offset=0, const Ordinal sub_dim=-1)
Teuchos::RCP< ReductTarget > reduct_obj_create() const
Creates a new reduction target object initialized and ready to be used in a reduction.
bool coord_invariant() const
Returns true if this operator is coordinate invariant.
void apply_op(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj) const
Apply the reduction/transformation operator to a set of sub-vectors.
void extract_reduct_obj_state(const ReductTarget &reduct_obj, const ArrayView< primitive_value_type > &value_data, const ArrayView< index_type > &index_data, const ArrayView< char_type > &char_data) const
Extract the state of an already created reduction object.
void get_reduct_type_num_entries(const Ptr< int > &num_values, const Ptr< int > &num_indexes, const Ptr< int > &num_chars) const
Get the number of entries of each basic data type in the externalized state for a reduction object fo...
void load_reduct_obj_state(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
Load the state of an already created reduction object given arrays of primitive objects.
void reduce_reduct_objs(const ReductTarget &in_reduct_obj, const Ptr< ReductTarget > &inout_reduct_obj) const
Reduce intermediate reduction target objects.
void reduct_obj_reinit(const Ptr< ReductTarget > &reduct_obj) const
Reinitialize an already created reduction object.
Abstract base class for all reduction objects.
Teuchos_Ordinal Ordinal