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