RTOp Package Browser (Single Doxygen Collection) Version of the Day
RTOpPack_RTOpSubRangeDecorator_def.hpp
Go to the documentation of this file.
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 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 
00030 #ifndef RTOPPACK_RTOP_SUB_RANGE_DECORATOR_DEF_HPP
00031 #define RTOPPACK_RTOP_SUB_RANGE_DECORATOR_DEF_HPP
00032 
00033 
00034 #include "RTOpPack_RTOpSubRangeDecorator_decl.hpp"
00035 
00036 
00037 namespace RTOpPack {
00038 
00039 
00040 // Constructors, accessors
00041 
00042 
00043 template<class Scalar>
00044 RTOpSubRangeDecorator<Scalar>::RTOpSubRangeDecorator()
00045   : first_ele_offset_(0), sub_dim_(-1)
00046 {}
00047 
00048 
00049 template<class Scalar>
00050 RTOpSubRangeDecorator<Scalar>::RTOpSubRangeDecorator(
00051   const RCP<RTOpT<Scalar> > &op,
00052   const Ordinal first_ele_offset,
00053   const Ordinal sub_dim
00054   )
00055   : first_ele_offset_(0), sub_dim_(-1)
00056 {
00057   nonconstInitialize(op, first_ele_offset, sub_dim);
00058 }
00059 
00060 
00061 template<class Scalar>
00062 RTOpSubRangeDecorator<Scalar>::RTOpSubRangeDecorator(
00063   const RCP<const RTOpT<Scalar> > &op,
00064   const Ordinal first_ele_offset,
00065   const Ordinal sub_dim
00066   )
00067   : first_ele_offset_(0), sub_dim_(-1)
00068 {
00069   initialize(op, first_ele_offset, sub_dim);
00070 }
00071 
00072 
00073 template<class Scalar>
00074 void
00075 RTOpSubRangeDecorator<Scalar>::nonconstInitialize(
00076   const RCP<RTOpT<Scalar> > &op,
00077   const Ordinal first_ele_offset,
00078   const Ordinal sub_dim
00079   )
00080 {
00081   op_.initialize(op);
00082   first_ele_offset_ = first_ele_offset;
00083   sub_dim_ = sub_dim;
00084 }
00085 
00086 
00087 template<class Scalar>
00088 void
00089 RTOpSubRangeDecorator<Scalar>::initialize(
00090   const RCP<const RTOpT<Scalar> > &op,
00091   const Ordinal first_ele_offset,
00092   const Ordinal sub_dim
00093   )
00094 {
00095   op_.initialize(op);
00096   first_ele_offset_ = first_ele_offset;
00097   sub_dim_ = sub_dim;
00098 }
00099 
00100 
00101 template<class Scalar>
00102 RCP<RTOpT<Scalar> >
00103 RTOpSubRangeDecorator<Scalar>::getNonconstOp()
00104 {
00105   return op_.getNonconstObj();
00106 }
00107 
00108 
00109 template<class Scalar>
00110 RCP<const RTOpT<Scalar> >
00111 RTOpSubRangeDecorator<Scalar>::getOp() const
00112 {
00113   return op_.getConstObj();
00114 }
00115 
00116 
00117 // Overridden from RTOpT
00118 
00119 
00120 template<class Scalar>
00121 void RTOpSubRangeDecorator<Scalar>::get_reduct_type_num_entries_impl(
00122   const Ptr<int> &num_values,
00123   const Ptr<int> &num_indexes,
00124   const Ptr<int> &num_chars
00125   ) const
00126 {
00127   op_->get_reduct_type_num_entries(num_values, num_indexes, num_chars);
00128 }
00129 
00130 
00131 template<class Scalar>
00132 Teuchos::RCP<ReductTarget>
00133 RTOpSubRangeDecorator<Scalar>::reduct_obj_create_impl() const
00134 {
00135   return op_->reduct_obj_create();
00136 }
00137 
00138 
00139 template<class Scalar>
00140 void RTOpSubRangeDecorator<Scalar>::reduce_reduct_objs_impl(
00141   const ReductTarget &in_reduct_obj, const Ptr<ReductTarget> &inout_reduct_obj
00142   ) const
00143 {
00144   op_->reduce_reduct_objs(in_reduct_obj, inout_reduct_obj);
00145 }
00146 
00147 
00148 template<class Scalar>
00149 void RTOpSubRangeDecorator<Scalar>::reduct_obj_reinit_impl(
00150   const Ptr<ReductTarget> &reduct_obj ) const
00151 {
00152   op_->reduct_obj_reinit(reduct_obj);
00153 }
00154 
00155 
00156 template<class Scalar>
00157 void RTOpSubRangeDecorator<Scalar>::extract_reduct_obj_state_impl(
00158   const ReductTarget &reduct_obj,
00159   const ArrayView<primitive_value_type> &value_data,
00160   const ArrayView<index_type> &index_data,
00161   const ArrayView<char_type> &char_data
00162   ) const
00163 {
00164   op_->extract_reduct_obj_state(reduct_obj, value_data, index_data, char_data);
00165 }
00166 
00167 
00168 template<class Scalar>
00169 void RTOpSubRangeDecorator<Scalar>::load_reduct_obj_state_impl(
00170   const ArrayView<const primitive_value_type> &value_data,
00171   const ArrayView<const index_type> &index_data,
00172   const ArrayView<const char_type> &char_data,
00173   const Ptr<ReductTarget> &reduct_obj
00174   ) const
00175 {
00176   op_->load_reduct_obj_state(value_data, index_data, char_data, reduct_obj);
00177 }
00178 
00179 
00180 template<class Scalar>
00181 std::string RTOpSubRangeDecorator<Scalar>::op_name_impl() const
00182 {
00183   return (std::string("RTOpSubRangeDecorator{")+op_->op_name()+"}");
00184 }
00185 
00186 
00187 template<class Scalar>
00188 bool RTOpSubRangeDecorator<Scalar>::coord_invariant_impl() const
00189 {
00190   return op_->coord_invariant();
00191 }
00192 
00193 
00194 template<class Scalar>
00195 void RTOpSubRangeDecorator<Scalar>::apply_op_impl(
00196   const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
00197   const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
00198   const Ptr<ReductTarget> &reduct_obj
00199   ) const
00200 {
00201   
00202   // Check for full overlap
00203   if (first_ele_offset_ == 0 && sub_dim_ < 0) {
00204     // Entire range, just fall through
00205     op_->apply_op(sub_vecs, targ_sub_vecs, reduct_obj);
00206     return;
00207   }
00208 
00209   const Ordinal globalOffset =
00210     (sub_vecs.size() ? sub_vecs[0].globalOffset(): targ_sub_vecs[0].globalOffset());
00211   const Ordinal subDim = 
00212     (sub_vecs.size() ? sub_vecs[0].subDim(): targ_sub_vecs[0].subDim());
00213 
00214   // Check for no overlap
00215   if (globalOffset >= first_ele_offset_ + sub_dim_) {
00216     // No overlap
00217     return;
00218   }
00219   if (globalOffset + subDim <= first_ele_offset_) {
00220     // NO overlap
00221     return;
00222   }
00223 
00224   const Ordinal localOffset = 
00225     (first_ele_offset_ > globalOffset
00226       ? first_ele_offset_ - globalOffset
00227       : 0);
00228 
00229   const Ordinal localSubDim =
00230     std::min(globalOffset + subDim, first_ele_offset_ + sub_dim_)
00231     - (globalOffset + localOffset);
00232   
00233   Array<ConstSubVectorView<Scalar> > sub_sub_vecs(sub_vecs.size());
00234   for (int k = 0; k < sub_vecs.size(); ++k) {
00235     const Ordinal stride = sub_vecs[k].stride(); 
00236     sub_sub_vecs[k].initialize(
00237       globalOffset+ localOffset,
00238       localSubDim,
00239       sub_vecs[k].values().persistingView(localOffset*stride, localSubDim*stride),
00240       stride
00241       );
00242   }
00243 
00244   Array<SubVectorView<Scalar> > targ_sub_sub_vecs(targ_sub_vecs.size());
00245   for (int k = 0; k < targ_sub_vecs.size(); ++k) {
00246     const Ordinal stride = targ_sub_vecs[k].stride(); 
00247     targ_sub_sub_vecs[k].initialize(
00248       globalOffset+ localOffset,
00249       localSubDim,
00250       targ_sub_vecs[k].values().persistingView(localOffset*stride, localSubDim*stride),
00251       stride
00252       );
00253   }
00254 
00255   op_->apply_op(sub_sub_vecs(), targ_sub_sub_vecs(), reduct_obj);
00256 
00257 }
00258 
00259 
00260 } // namespace RTOpPack
00261 
00262 
00263 #endif // RTOPPACK_RTOP_SUB_RANGE_DECORATOR_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines