RTOpPack_RTOpTHelpers_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_T_HELPERS_DEF_HPP
00031 #define RTOPPACK_RTOP_T_HELPERS_DEF_HPP
00032 
00033 
00034 #include "RTOpPack_RTOpTHelpers_decl.hpp"
00035 
00036 
00037 namespace RTOpPack {
00038 
00039 
00040 //
00041 // DefaultReductTarget
00042 //
00043 
00044 
00045 template<class ConcreteReductObj>
00046 std::string DefaultReductTarget<ConcreteReductObj>::description() const
00047 {
00048   std::ostringstream oss;
00049   oss
00050     << "RTOpPack::DefaultReductTarget<"
00051     <<TypeNameTraits<ConcreteReductObj>::name()<<">"
00052     << "{concreteReductObj="<<concreteReductObj_<<"}";
00053   return oss.str();
00054 }
00055 
00056 
00057 } // namespace RTOpPack
00058 
00059 
00060 template<class Scalar>
00061 void RTOpPack::validate_apply_op(
00062   const RTOpT<Scalar> &op,
00063   const int allowed_num_sub_vecs,
00064   const int allowed_num_targ_sub_vecs,
00065   const bool expect_reduct_obj,
00066   const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
00067   const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
00068   const Ptr<const ReductTarget> &reduct_obj
00069   )
00070 {
00071 
00072   using Teuchos::as;
00073 
00074   const int num_sub_vecs = sub_vecs.size();
00075   const int num_targ_sub_vecs = targ_sub_vecs.size();
00076 
00077   const std::string op_name_str = "op.name() = " + op.op_name();
00078 
00079   if (allowed_num_sub_vecs >= 0) {
00080     TEST_FOR_EXCEPTION( allowed_num_sub_vecs != as<int>(sub_vecs.size()),
00081       InvalidNumVecs,
00082       op_name_str<<": Error, sub_vecs.size()="<<sub_vecs.size()
00083       <<" != allowed_num_sub_vecs="<<allowed_num_sub_vecs<<"!" );
00084   }
00085 
00086   if (allowed_num_targ_sub_vecs >= 0) {
00087     TEST_FOR_EXCEPTION( allowed_num_targ_sub_vecs != as<int>(targ_sub_vecs.size()),
00088       InvalidNumTargVecs,
00089       op_name_str<<": Error, targ_sub_vecs.size()="<<targ_sub_vecs.size()
00090       <<" != allowed_num_targ_sub_vecs="<<allowed_num_targ_sub_vecs<<"!" );
00091   }
00092   
00093   TEST_FOR_EXCEPTION( sub_vecs.size() == 0 && targ_sub_vecs.size() == 0,
00094     InvalidNumVecs,
00095     op_name_str<<": Error, apply_op(...) must be passed some vectors!"
00096     );
00097   
00098   const index_type subDim =
00099     (sub_vecs.size() ? sub_vecs[0].subDim() : targ_sub_vecs[0].subDim());
00100   
00101   const index_type globalOffset =
00102     (sub_vecs.size() ? sub_vecs[0].globalOffset() : targ_sub_vecs[0].globalOffset());
00103   
00104   for (int k = 0; k < num_sub_vecs; ++k ) {
00105     TEST_FOR_EXCEPTION(
00106       sub_vecs[k].subDim() != subDim || sub_vecs[k].globalOffset() != globalOffset,
00107       IncompatibleVecs,
00108       op_name_str<<": Error, sub_vec["<<k<<"] "
00109       "(subDim="<<sub_vecs[k].subDim()<<",globalOffset="<<sub_vecs[k].globalOffset()<<")"
00110       " is not compatible with (subDim="<<subDim<<",globalOffset="<<globalOffset<<")!"
00111       );
00112   }
00113   
00114   for (int k = 0; k < num_targ_sub_vecs; ++k ) {
00115     TEST_FOR_EXCEPTION(
00116       targ_sub_vecs[k].subDim() != subDim || targ_sub_vecs[k].globalOffset() != globalOffset,
00117       IncompatibleVecs,
00118       op_name_str<<": Error, sub_vec["<<k<<"] "
00119       "(subDim="<<targ_sub_vecs[k].subDim()<<",globalOffset="<<targ_sub_vecs[k].globalOffset()<<")"
00120       " is not compatible with (subDim="<<subDim<<",globalOffset="<<globalOffset<<")!"
00121       );
00122   }
00123   
00124   if (expect_reduct_obj) {
00125     
00126     TEST_FOR_EXCEPTION( is_null(reduct_obj),
00127       IncompatibleReductObj,
00128       op_name_str<<": Error, expected a reduction target object!"
00129       );
00130     
00131     const RCP<ReductTarget> dummy_reduct_obj = op.reduct_obj_create();
00132     
00133     const std::type_info &reduct_obj_type = typeid(*reduct_obj);
00134     const std::type_info &dummy_reduct_obj_type = typeid(*dummy_reduct_obj);
00135     
00136     TEST_FOR_EXCEPTION( reduct_obj_type != dummy_reduct_obj_type,
00137       IncompatibleReductObj,
00138       op_name_str<<": Error, the type of the input reduct_obj = "
00139       <<Teuchos::demangleName(reduct_obj_type.name())<<" is not equal to"
00140       " the expected type "<<Teuchos::demangleName(dummy_reduct_obj_type.name())
00141       <<"!"
00142       );
00143 
00144   }
00145       
00146 }
00147 
00148 
00149 
00150 //
00151 // Explicit Instantiation Macro
00152 //
00153 
00154 
00155 #define RTOPPACK_RTOPT_HELPERS_DEFAULTREDUCTTARGET_INSTANT(SCALAR) \
00156   \
00157   template std::string DefaultReductTarget<SCALAR >::description() const;
00158 
00159 
00160 #define RTOPPACK_RTOPT_HELPERS_INSTANT_SCALAR(SCALAR) \
00161   \
00162   RTOPPACK_RTOPT_HELPERS_DEFAULTREDUCTTARGET_INSTANT(SCALAR) \
00163   \
00164   RTOPPACK_RTOPT_HELPERS_DEFAULTREDUCTTARGET_INSTANT(ScalarIndex<SCALAR >) \
00165   \
00166   RTOPPACK_RTOPT_HELPERS_DEFAULTREDUCTTARGET_INSTANT(SubVectorView<SCALAR >) \
00167   \
00168   template void validate_apply_op<SCALAR >( \
00169     const RTOpT<SCALAR > &op, \
00170     const int allowed_num_sub_vecs, \
00171     const int allowed_num_targ_sub_vecs, \
00172     const bool expect_reduct_obj, \
00173     const ArrayView<const ConstSubVectorView<SCALAR > > &sub_vecs, \
00174     const ArrayView<const SubVectorView<SCALAR > > &targ_sub_vecs, \
00175     const Ptr<const ReductTarget> &reduct_obj \
00176     ); \
00177   \
00178 
00179 
00180 
00181 #endif // RTOPPACK_RTOP_T_HELPERS_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 09:59:06 2011 for RTOp Package Browser (Single Doxygen Collection) by  doxygen 1.6.3