Collection of Concrete Vector Reduction/Transformation Operator Implementations
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
src
ops_lib
RTOpPack_ROpGetSubVector_def.hpp
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_ROP_GET_SUB_VECTOR_DEF_HPP
44
#define RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP
45
46
47
#include "RTOpPack_ROpGetSubVector_decl.hpp"
48
49
50
namespace
RTOpPack {
51
52
53
template
<
class
Scalar>
54
ROpGetSubVector<Scalar>::ROpGetSubVector
(
const
index_type l,
55
const
index_type u
56
)
57
:
RTOpT
<Scalar>(
"ROpGetSubVector"
), l_(l), u_(u)
58
{}
59
60
61
template
<
class
Scalar>
62
void
ROpGetSubVector<Scalar>::set_range
(
const
index_type l,
63
const
index_type u
64
)
65
{
66
l_ = l;
67
u_ = u;
68
}
69
70
71
template
<
class
Scalar>
72
const
ConstSubVectorView<Scalar>
73
ROpGetSubVector<Scalar>::operator()
(
const
ReductTarget
& reduct_obj )
const
74
{
75
using
Teuchos::dyn_cast;
76
return
dyn_cast<const DefaultReductTarget<SubVectorView< Scalar> > >(reduct_obj).get();
77
}
78
79
80
// Overridden from RTOpT
81
82
83
template
<
class
Scalar>
84
void
ROpGetSubVector<Scalar>::get_reduct_type_num_entries_impl
(
85
const
Ptr<int> &num_values,
86
const
Ptr<int> &num_indexes,
87
const
Ptr<int> &num_chars
88
)
const
89
{
90
typedef
PrimitiveTypeTraits<Scalar,Scalar>
PTT;
91
const
int
num_prim_objs_per_scalar = PTT::numPrimitiveObjs();
92
*num_values = (u_-l_+1)*num_prim_objs_per_scalar;
93
*num_indexes = 0;
94
*num_chars = 0;
95
}
96
97
98
template
<
class
Scalar>
99
Teuchos::RCP<ReductTarget>
100
ROpGetSubVector<Scalar>::reduct_obj_create_impl
()
const
101
{
102
const
index_type subDim = u_ - l_ + 1;
103
const
ArrayRCP<Scalar> values = Teuchos::arcp<Scalar>(subDim);
104
std::fill(values.begin(), values.end(), ScalarTraits<Scalar>::zero());
105
return
defaultReductTarget(
106
SubVectorView<Scalar>
( l_, subDim, values, 1 )
107
);
108
}
109
110
111
template
<
class
Scalar>
112
void
ROpGetSubVector<Scalar>::reduce_reduct_objs_impl
(
113
const
ReductTarget
&in_reduct_obj,
const
Ptr<ReductTarget> &inout_reduct_obj
114
)
const
115
{
116
117
using
Teuchos::dyn_cast;
118
typedef
DefaultReductTarget<SubVectorView<Scalar>
> DRTSVV;
119
120
DRTSVV &drtsvv_inout_reduct_obj = dyn_cast<DRTSVV>(*inout_reduct_obj);
121
122
const
ConstSubVectorView<Scalar>
sub_vec_in =
123
dyn_cast<const DRTSVV>(in_reduct_obj).get();
124
SubVectorView<Scalar>
sub_vec_inout = drtsvv_inout_reduct_obj.get();
125
126
#ifdef TEUCHOS_DEBUG
127
TEUCHOS_TEST_FOR_EXCEPT(
128
sub_vec_in.
subDim
()!=sub_vec_inout.
subDim
()
129
|| sub_vec_in.
globalOffset
()!=sub_vec_inout.
globalOffset
()
130
|| is_null(sub_vec_in.
values
())
131
|| is_null(sub_vec_inout.
values
())
132
|| sub_vec_in.
stride
()!=1
133
|| sub_vec_inout.
stride
()!=1
134
);
135
#endif
// TEUCHOS_DEBUG
136
137
typedef
typename
ArrayRCP<const Scalar>::const_iterator const_iter_t;
138
typedef
typename
ArrayRCP<Scalar>::iterator iter_t;
139
140
const_iter_t in_iter = sub_vec_in.
values
().begin();
141
iter_t inout_iter = sub_vec_inout.
values
().begin();
142
143
for
(
int
k = 0; k < sub_vec_in.
subDim
(); ++k ) {
144
*inout_iter++ += *in_iter++;
145
}
146
147
drtsvv_inout_reduct_obj.set(sub_vec_inout);
148
149
}
150
151
152
template
<
class
Scalar>
153
void
ROpGetSubVector<Scalar>::reduct_obj_reinit_impl
(
154
const
Ptr<ReductTarget> &reduct_obj )
const
155
{
156
using
Teuchos::dyn_cast;
157
typedef
DefaultReductTarget<SubVectorView<Scalar>
> DRTSVV;
158
DRTSVV &drtsvv_inout_reduct_obj = dyn_cast<DRTSVV>(*reduct_obj);
159
SubVectorView<Scalar>
sub_vec = drtsvv_inout_reduct_obj.get();
160
std::fill( sub_vec.
values
().begin(), sub_vec.
values
().end(),
161
ScalarTraits<Scalar>::zero() );
162
}
163
164
165
template
<
class
Scalar>
166
void
ROpGetSubVector<Scalar>::extract_reduct_obj_state_impl
(
167
const
ReductTarget
&reduct_obj,
168
const
ArrayView<primitive_value_type> &value_data,
169
const
ArrayView<index_type> &
/* index_data */
,
170
const
ArrayView<char_type> &
/* char_data */
171
)
const
172
{
173
using
Teuchos::null;
174
using
Teuchos::dyn_cast;
175
typedef
PrimitiveTypeTraits<Scalar,Scalar>
PTT;
176
const
int
num_prim_objs_per_scalar = PTT::numPrimitiveObjs();
177
const
ConstSubVectorView<Scalar>
sub_vec =
178
dyn_cast<const DefaultReductTarget<SubVectorView<Scalar> > >(reduct_obj).get();
179
int
value_data_off = 0;
180
for
(
181
int
k = 0;
182
k < sub_vec.
subDim
();
183
++k, value_data_off += num_prim_objs_per_scalar
184
)
185
{
186
PTT::extractPrimitiveObjs( sub_vec[k],
187
value_data(value_data_off, num_prim_objs_per_scalar),
188
null, null );
189
}
190
}
191
192
193
template
<
class
Scalar>
194
void
ROpGetSubVector<Scalar>::load_reduct_obj_state_impl
(
195
const
ArrayView<const primitive_value_type> &value_data,
196
const
ArrayView<const index_type> &
/* index_data */
,
197
const
ArrayView<const char_type> &
/* char_data */
,
198
const
Ptr<ReductTarget> &reduct_obj
199
)
const
200
{
201
using
Teuchos::null;
202
using
Teuchos::outArg;
203
using
Teuchos::dyn_cast;
204
using
Teuchos::arcp_const_cast;
205
typedef
PrimitiveTypeTraits<Scalar,Scalar>
PTT;
206
typedef
DefaultReductTarget<SubVectorView<Scalar>
> DRTSVV;
207
const
int
num_prim_objs_per_scalar = PTT::numPrimitiveObjs();
208
DRTSVV &drtsvv_reduct_obj = dyn_cast<DRTSVV>(*reduct_obj);
209
const
ConstSubVectorView<Scalar>
const_sub_vec = drtsvv_reduct_obj.get();
210
const
ArrayRCP<Scalar> sv_values =
211
arcp_const_cast<Scalar>(const_sub_vec.
values
());
212
int
value_data_off = 0;
213
for
(
214
int
k = 0;
215
k < const_sub_vec.
subDim
();
216
++k, value_data_off += num_prim_objs_per_scalar
217
)
218
{
219
PTT::loadPrimitiveObjs(
220
value_data(value_data_off, num_prim_objs_per_scalar), null, null,
221
outArg(sv_values[k]) );
222
}
223
}
224
225
226
template
<
class
Scalar>
227
bool
ROpGetSubVector<Scalar>::coord_invariant_impl
()
const
228
{
229
return
false
;
230
}
231
232
233
template
<
class
Scalar>
234
void
ROpGetSubVector<Scalar>::apply_op_impl
(
235
const
ArrayView<
const
ConstSubVectorView<Scalar>
> &sub_vecs,
236
const
ArrayView<
const
SubVectorView<Scalar>
> &targ_sub_vecs,
237
const
Ptr<ReductTarget> &reduct_obj
238
)
const
239
{
240
241
using
Teuchos::dyn_cast;
242
typedef
DefaultReductTarget<SubVectorView<Scalar>
> DRTSVV;
243
244
validate_apply_op( *
this
, 1, 0,
true
,
245
sub_vecs, targ_sub_vecs, reduct_obj.getConst() );
246
247
typedef
typename
Teuchos::ArrayRCP<const Scalar>::iterator const_iter_t;
248
const
index_type subDim = sub_vecs[0].subDim();
249
const
index_type globalOffset = sub_vecs[0].globalOffset();
250
TEUCHOS_TEST_FOR_EXCEPT(globalOffset<0);
251
const_iter_t v0_val = sub_vecs[0].values().begin();
252
const
ptrdiff_t v0_s = sub_vecs[0].stride();
253
254
if
( u_ < globalOffset || globalOffset + subDim - 1 < l_ ) {
255
// None of the sub-vector elements that we are looking for is in this
256
// vector chunk!
257
return
;
258
}
259
260
index_type
261
i_l = ( l_ <= globalOffset ? 0 : l_ - globalOffset ),
262
i_u = ( u_ >= globalOffset+subDim-1 ? subDim-1 : u_ - globalOffset );
263
264
DRTSVV &drtsvv_reduct_obj = dyn_cast<DRTSVV>(*reduct_obj);
265
SubVectorView<Scalar>
sub_vec_targ = drtsvv_reduct_obj.get();
266
267
const
ArrayRCP<Scalar> svt_values = sub_vec_targ.
values
();
268
269
for
( index_type i = i_l; i <= i_u; ++i ) {
270
svt_values[i+(globalOffset-l_)] = v0_val[i*v0_s];
271
}
272
273
drtsvv_reduct_obj.set(sub_vec_targ);
274
275
}
276
277
278
}
// namespace RTOpPack
279
280
281
#endif
// RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP
RTOpPack::ConstSubVectorView
RTOpPack::ConstSubVectorView::globalOffset
Ordinal globalOffset() const
RTOpPack::ConstSubVectorView::values
const ArrayRCP< const Scalar > values() const
RTOpPack::ConstSubVectorView::stride
ptrdiff_t stride() const
RTOpPack::ConstSubVectorView::subDim
Ordinal subDim() const
RTOpPack::DefaultReductTarget
RTOpPack::PrimitiveTypeTraits
RTOpPack::ROpGetSubVector::coord_invariant_impl
bool coord_invariant_impl() const
Definition
RTOpPack_ROpGetSubVector_def.hpp:227
RTOpPack::ROpGetSubVector::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_ROpGetSubVector_def.hpp:84
RTOpPack::ROpGetSubVector::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_ROpGetSubVector_def.hpp:194
RTOpPack::ROpGetSubVector::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_ROpGetSubVector_def.hpp:166
RTOpPack::ROpGetSubVector::reduct_obj_create_impl
Teuchos::RCP< ReductTarget > reduct_obj_create_impl() const
Definition
RTOpPack_ROpGetSubVector_def.hpp:100
RTOpPack::ROpGetSubVector::reduct_obj_reinit_impl
void reduct_obj_reinit_impl(const Ptr< ReductTarget > &reduct_obj) const
Definition
RTOpPack_ROpGetSubVector_def.hpp:153
RTOpPack::ROpGetSubVector::ROpGetSubVector
ROpGetSubVector(const index_type l=0, const index_type u=0)
Definition
RTOpPack_ROpGetSubVector_def.hpp:54
RTOpPack::ROpGetSubVector::set_range
void set_range(const index_type l, const index_type u)
Set the range of global indexes to extract elements for.
Definition
RTOpPack_ROpGetSubVector_def.hpp:62
RTOpPack::ROpGetSubVector::operator()
const ConstSubVectorView< Scalar > operator()(const ReductTarget &reduct_obj) const
Extract the subvector after all of the reductions are completed.
Definition
RTOpPack_ROpGetSubVector_def.hpp:73
RTOpPack::ROpGetSubVector::reduce_reduct_objs_impl
void reduce_reduct_objs_impl(const ReductTarget &in_reduct_obj, const Ptr< ReductTarget > &inout_reduct_obj) const
Definition
RTOpPack_ROpGetSubVector_def.hpp:112
RTOpPack::ROpGetSubVector::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_ROpGetSubVector_def.hpp:234
RTOpPack::RTOpT< Scalar >::RTOpT
RTOpT(const std::string &op_name_base="")
RTOpPack::ReductTarget
RTOpPack::SubVectorView
RTOpPack::SubVectorView::values
const ArrayRCP< Scalar > values() const
Generated by
1.17.0