RTOp Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
src
support
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
47
#include "
RTOpPack_RTOpSubRangeDecorator_decl.hpp
"
48
49
50
namespace
RTOpPack
{
51
52
53
// Constructors, accessors
54
55
56
template
<
class
Scalar>
57
RTOpSubRangeDecorator<Scalar>::RTOpSubRangeDecorator
()
58
:
first_ele_offset_
(0),
sub_dim_
(-1)
59
{}
60
61
62
template
<
class
Scalar>
63
RTOpSubRangeDecorator<Scalar>::RTOpSubRangeDecorator
(
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>
75
RTOpSubRangeDecorator<Scalar>::RTOpSubRangeDecorator
(
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
88
RTOpSubRangeDecorator<Scalar>::nonconstInitialize
(
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
102
RTOpSubRangeDecorator<Scalar>::initialize
(
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>
115
RCP<RTOpT<Scalar> >
116
RTOpSubRangeDecorator<Scalar>::getNonconstOp
()
117
{
118
return
op_
.getNonconstObj();
119
}
120
121
122
template
<
class
Scalar>
123
RCP<const RTOpT<Scalar> >
124
RTOpSubRangeDecorator<Scalar>::getOp
()
const
125
{
126
return
op_
.getConstObj();
127
}
128
129
130
// Overridden from RTOpT
131
132
133
template
<
class
Scalar>
134
void
RTOpSubRangeDecorator<Scalar>::get_reduct_type_num_entries_impl
(
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>
145
Teuchos::RCP<ReductTarget>
146
RTOpSubRangeDecorator<Scalar>::reduct_obj_create_impl
()
const
147
{
148
return
op_
->reduct_obj_create();
149
}
150
151
152
template
<
class
Scalar>
153
void
RTOpSubRangeDecorator<Scalar>::reduce_reduct_objs_impl
(
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>
162
void
RTOpSubRangeDecorator<Scalar>::reduct_obj_reinit_impl
(
163
const
Ptr<ReductTarget> &reduct_obj )
const
164
{
165
op_
->reduct_obj_reinit(reduct_obj);
166
}
167
168
169
template
<
class
Scalar>
170
void
RTOpSubRangeDecorator<Scalar>::extract_reduct_obj_state_impl
(
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>
182
void
RTOpSubRangeDecorator<Scalar>::load_reduct_obj_state_impl
(
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>
194
std::string
RTOpSubRangeDecorator<Scalar>::op_name_impl
()
const
195
{
196
return
(std::string(
"RTOpSubRangeDecorator{"
)+
op_
->op_name()+
"}"
);
197
}
198
199
200
template
<
class
Scalar>
201
bool
RTOpSubRangeDecorator<Scalar>::coord_invariant_impl
()
const
202
{
203
return
op_
->coord_invariant();
204
}
205
206
207
template
<
class
Scalar>
208
void
RTOpSubRangeDecorator<Scalar>::apply_op_impl
(
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
RTOpPack_RTOpSubRangeDecorator_decl.hpp
RTOpPack::ConstSubVectorView
Class for a non-changeable sub-vector.
Definition
RTOpPack_Types.hpp:144
RTOpPack::RTOpSubRangeDecorator::op_
Teuchos::ConstNonconstObjectContainer< RTOpT< Scalar > > op_
Definition
RTOpPack_RTOpSubRangeDecorator_decl.hpp:183
RTOpPack::RTOpSubRangeDecorator::load_reduct_obj_state_impl
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
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:182
RTOpPack::RTOpSubRangeDecorator::reduce_reduct_objs_impl
void reduce_reduct_objs_impl(const ReductTarget &in_reduct_obj, const Ptr< ReductTarget > &inout_reduct_obj) const
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:153
RTOpPack::RTOpSubRangeDecorator::initialize
void initialize(const RCP< const RTOpT< Scalar > > &op, const Ordinal first_ele_offset=0, const Ordinal sub_dim=-1)
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:102
RTOpPack::RTOpSubRangeDecorator::RTOpSubRangeDecorator
RTOpSubRangeDecorator()
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:57
RTOpPack::RTOpSubRangeDecorator::getNonconstOp
RCP< RTOpT< Scalar > > getNonconstOp()
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:116
RTOpPack::RTOpSubRangeDecorator::getOp
RCP< const RTOpT< Scalar > > getOp() const
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:124
RTOpPack::RTOpSubRangeDecorator::op_name_impl
std::string op_name_impl() const
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:194
RTOpPack::RTOpSubRangeDecorator::apply_op_impl
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
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:208
RTOpPack::RTOpSubRangeDecorator::sub_dim_
Ordinal sub_dim_
Definition
RTOpPack_RTOpSubRangeDecorator_decl.hpp:185
RTOpPack::RTOpSubRangeDecorator::coord_invariant_impl
bool coord_invariant_impl() const
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:201
RTOpPack::RTOpSubRangeDecorator::reduct_obj_reinit_impl
void reduct_obj_reinit_impl(const Ptr< ReductTarget > &reduct_obj) const
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:162
RTOpPack::RTOpSubRangeDecorator::first_ele_offset_
Ordinal first_ele_offset_
Definition
RTOpPack_RTOpSubRangeDecorator_decl.hpp:184
RTOpPack::RTOpSubRangeDecorator::get_reduct_type_num_entries_impl
void get_reduct_type_num_entries_impl(const Ptr< int > &num_values, const Ptr< int > &num_indexes, const Ptr< int > &num_chars) const
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:134
RTOpPack::RTOpSubRangeDecorator::extract_reduct_obj_state_impl
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
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:170
RTOpPack::RTOpSubRangeDecorator::nonconstInitialize
void nonconstInitialize(const RCP< RTOpT< Scalar > > &op, const Ordinal first_ele_offset=0, const Ordinal sub_dim=-1)
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:88
RTOpPack::RTOpSubRangeDecorator::reduct_obj_create_impl
Teuchos::RCP< ReductTarget > reduct_obj_create_impl() const
Definition
RTOpPack_RTOpSubRangeDecorator_def.hpp:146
RTOpPack::RTOpT::RTOpT
RTOpT(const std::string &op_name_base="")
Constructor that creates an operator name appended with the type.
Definition
RTOpPack_RTOpT_def.hpp:145
RTOpPack::ReductTarget
Abstract base class for all reduction objects.
Definition
RTOpPack_RTOpT_decl.hpp:58
RTOpPack::SubVectorView
Class for a changeable sub-vector.
Definition
RTOpPack_Types.hpp:247
RTOpPack
Definition
RTOpPack_RTOpT_decl.hpp:52
RTOpPack::Ordinal
Teuchos_Ordinal Ordinal
Definition
RTOpPack_Types.hpp:68
Generated by
1.17.0