|
RTOp Package Browser (Single Doxygen Collection)
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // RTOp: Interfaces and Support Software for Vector Reduction Transformation 00005 // Operations 00006 // Copyright (2006) Sandia Corporation 00007 // 00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00009 // license for use of this work by or on behalf of the U.S. Government. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00039 // 00040 // *********************************************************************** 00041 // @HEADER 00042 00043 #ifndef RTOPPACK_RTOP_SUB_RANGE_DECORATOR_DEF_HPP 00044 #define RTOPPACK_RTOP_SUB_RANGE_DECORATOR_DEF_HPP 00045 00046 00047 #include "RTOpPack_RTOpSubRangeDecorator_decl.hpp" 00048 00049 00050 namespace RTOpPack { 00051 00052 00053 // Constructors, accessors 00054 00055 00056 template<class Scalar> 00057 RTOpSubRangeDecorator<Scalar>::RTOpSubRangeDecorator() 00058 : first_ele_offset_(0), sub_dim_(-1) 00059 {} 00060 00061 00062 template<class Scalar> 00063 RTOpSubRangeDecorator<Scalar>::RTOpSubRangeDecorator( 00064 const RCP<RTOpT<Scalar> > &op, 00065 const Ordinal first_ele_offset, 00066 const Ordinal sub_dim 00067 ) 00068 : first_ele_offset_(0), sub_dim_(-1) 00069 { 00070 nonconstInitialize(op, first_ele_offset, sub_dim); 00071 } 00072 00073 00074 template<class Scalar> 00075 RTOpSubRangeDecorator<Scalar>::RTOpSubRangeDecorator( 00076 const RCP<const RTOpT<Scalar> > &op, 00077 const Ordinal first_ele_offset, 00078 const Ordinal sub_dim 00079 ) 00080 : first_ele_offset_(0), sub_dim_(-1) 00081 { 00082 initialize(op, first_ele_offset, sub_dim); 00083 } 00084 00085 00086 template<class Scalar> 00087 void 00088 RTOpSubRangeDecorator<Scalar>::nonconstInitialize( 00089 const RCP<RTOpT<Scalar> > &op, 00090 const Ordinal first_ele_offset, 00091 const Ordinal sub_dim 00092 ) 00093 { 00094 op_.initialize(op); 00095 first_ele_offset_ = first_ele_offset; 00096 sub_dim_ = sub_dim; 00097 } 00098 00099 00100 template<class Scalar> 00101 void 00102 RTOpSubRangeDecorator<Scalar>::initialize( 00103 const RCP<const RTOpT<Scalar> > &op, 00104 const Ordinal first_ele_offset, 00105 const Ordinal sub_dim 00106 ) 00107 { 00108 op_.initialize(op); 00109 first_ele_offset_ = first_ele_offset; 00110 sub_dim_ = sub_dim; 00111 } 00112 00113 00114 template<class Scalar> 00115 RCP<RTOpT<Scalar> > 00116 RTOpSubRangeDecorator<Scalar>::getNonconstOp() 00117 { 00118 return op_.getNonconstObj(); 00119 } 00120 00121 00122 template<class Scalar> 00123 RCP<const RTOpT<Scalar> > 00124 RTOpSubRangeDecorator<Scalar>::getOp() const 00125 { 00126 return op_.getConstObj(); 00127 } 00128 00129 00130 // Overridden from RTOpT 00131 00132 00133 template<class Scalar> 00134 void RTOpSubRangeDecorator<Scalar>::get_reduct_type_num_entries_impl( 00135 const Ptr<int> &num_values, 00136 const Ptr<int> &num_indexes, 00137 const Ptr<int> &num_chars 00138 ) const 00139 { 00140 op_->get_reduct_type_num_entries(num_values, num_indexes, num_chars); 00141 } 00142 00143 00144 template<class Scalar> 00145 Teuchos::RCP<ReductTarget> 00146 RTOpSubRangeDecorator<Scalar>::reduct_obj_create_impl() const 00147 { 00148 return op_->reduct_obj_create(); 00149 } 00150 00151 00152 template<class Scalar> 00153 void RTOpSubRangeDecorator<Scalar>::reduce_reduct_objs_impl( 00154 const ReductTarget &in_reduct_obj, const Ptr<ReductTarget> &inout_reduct_obj 00155 ) const 00156 { 00157 op_->reduce_reduct_objs(in_reduct_obj, inout_reduct_obj); 00158 } 00159 00160 00161 template<class Scalar> 00162 void RTOpSubRangeDecorator<Scalar>::reduct_obj_reinit_impl( 00163 const Ptr<ReductTarget> &reduct_obj ) const 00164 { 00165 op_->reduct_obj_reinit(reduct_obj); 00166 } 00167 00168 00169 template<class Scalar> 00170 void RTOpSubRangeDecorator<Scalar>::extract_reduct_obj_state_impl( 00171 const ReductTarget &reduct_obj, 00172 const ArrayView<primitive_value_type> &value_data, 00173 const ArrayView<index_type> &index_data, 00174 const ArrayView<char_type> &char_data 00175 ) const 00176 { 00177 op_->extract_reduct_obj_state(reduct_obj, value_data, index_data, char_data); 00178 } 00179 00180 00181 template<class Scalar> 00182 void RTOpSubRangeDecorator<Scalar>::load_reduct_obj_state_impl( 00183 const ArrayView<const primitive_value_type> &value_data, 00184 const ArrayView<const index_type> &index_data, 00185 const ArrayView<const char_type> &char_data, 00186 const Ptr<ReductTarget> &reduct_obj 00187 ) const 00188 { 00189 op_->load_reduct_obj_state(value_data, index_data, char_data, reduct_obj); 00190 } 00191 00192 00193 template<class Scalar> 00194 std::string RTOpSubRangeDecorator<Scalar>::op_name_impl() const 00195 { 00196 return (std::string("RTOpSubRangeDecorator{")+op_->op_name()+"}"); 00197 } 00198 00199 00200 template<class Scalar> 00201 bool RTOpSubRangeDecorator<Scalar>::coord_invariant_impl() const 00202 { 00203 return op_->coord_invariant(); 00204 } 00205 00206 00207 template<class Scalar> 00208 void RTOpSubRangeDecorator<Scalar>::apply_op_impl( 00209 const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs, 00210 const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs, 00211 const Ptr<ReductTarget> &reduct_obj 00212 ) const 00213 { 00214 00215 // Check for full overlap 00216 if (first_ele_offset_ == 0 && sub_dim_ < 0) { 00217 // Entire range, just fall through 00218 op_->apply_op(sub_vecs, targ_sub_vecs, reduct_obj); 00219 return; 00220 } 00221 00222 const Ordinal globalOffset = 00223 (sub_vecs.size() ? sub_vecs[0].globalOffset(): targ_sub_vecs[0].globalOffset()); 00224 const Ordinal subDim = 00225 (sub_vecs.size() ? sub_vecs[0].subDim(): targ_sub_vecs[0].subDim()); 00226 00227 // Check for no overlap 00228 if (globalOffset >= first_ele_offset_ + sub_dim_) { 00229 // No overlap 00230 return; 00231 } 00232 if (globalOffset + subDim <= first_ele_offset_) { 00233 // NO overlap 00234 return; 00235 } 00236 00237 const Ordinal localOffset = 00238 (first_ele_offset_ > globalOffset 00239 ? first_ele_offset_ - globalOffset 00240 : 0); 00241 00242 const Ordinal localSubDim = 00243 std::min(globalOffset + subDim, first_ele_offset_ + sub_dim_) 00244 - (globalOffset + localOffset); 00245 00246 Array<ConstSubVectorView<Scalar> > sub_sub_vecs(sub_vecs.size()); 00247 for (int k = 0; k < sub_vecs.size(); ++k) { 00248 const Ordinal stride = sub_vecs[k].stride(); 00249 sub_sub_vecs[k].initialize( 00250 globalOffset+ localOffset, 00251 localSubDim, 00252 sub_vecs[k].values().persistingView(localOffset*stride, localSubDim*stride), 00253 stride 00254 ); 00255 } 00256 00257 Array<SubVectorView<Scalar> > targ_sub_sub_vecs(targ_sub_vecs.size()); 00258 for (int k = 0; k < targ_sub_vecs.size(); ++k) { 00259 const Ordinal stride = targ_sub_vecs[k].stride(); 00260 targ_sub_sub_vecs[k].initialize( 00261 globalOffset+ localOffset, 00262 localSubDim, 00263 targ_sub_vecs[k].values().persistingView(localOffset*stride, localSubDim*stride), 00264 stride 00265 ); 00266 } 00267 00268 op_->apply_op(sub_sub_vecs(), targ_sub_sub_vecs(), reduct_obj); 00269 00270 } 00271 00272 00273 } // namespace RTOpPack 00274 00275 00276 #endif // RTOPPACK_RTOP_SUB_RANGE_DECORATOR_DEF_HPP
1.7.6.1