RTOpPack_RTOpC.cpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 // ///////////////////////////////
00030 // RTOpPack_RTOpC.cpp
00031 
00032 #include "RTOpPack_RTOpC.hpp"
00033 
00034 namespace {
00035 
00036 } // namespace
00037 
00038 namespace RTOpPack {
00039 
00040 RTOpC::RTOpC()
00041   :RTOpT<RTOp_value_type>("RTOpC") // Should be unused since op_name() if overridden here!
00042 {
00043   op_.vtbl     = NULL;
00044   op_.obj_data = NULL;
00045 }
00046 
00047 RTOpC::~RTOpC()
00048 {
00049   if(op_.obj_data)
00050     RTOp_free_op( &op_ );
00051 }
00052 
00053 // Overridden from RTOpT
00054 
00055 void RTOpC::get_reduct_type_num_entries(
00056   int*   num_values
00057   ,int*  num_indexes
00058   ,int*  num_chars
00059   ) const
00060 {
00061   TEST_FOR_EXCEPTION(
00062     0!=RTOp_get_reduct_type_num_entries(&op_,num_values,num_indexes,num_chars)
00063     ,UnknownError
00064     ,"RTOpC::get_reduct_type_num_entries(...): Error, "
00065     "RTOp_get_reduct_type_num_entries(...) returned != 0"
00066     );
00067 }
00068 
00069 Teuchos::RefCountPtr<ReductTarget>
00070 RTOpC::reduct_obj_create() const
00071 {
00072   RTOp_ReductTarget reduct_obj_raw = RTOp_REDUCT_OBJ_NULL;
00073   TEST_FOR_EXCEPTION(
00074     0!=RTOp_reduct_obj_create(&op_,&reduct_obj_raw)
00075     ,UnknownError
00076     ,"RTOpC::reduct_obj_create(...): Error, "
00077     "RTOp_reduct_obj_create(...) returned != 0"
00078     );
00079   return Teuchos::rcp(new ReductTargetC(op_,reduct_obj_raw));
00080 }
00081 
00082 void RTOpC::reduce_reduct_objs(
00083   const ReductTarget& in_reduct_obj, ReductTarget* inout_reduct_obj
00084   ) const
00085 {
00086   TEST_FOR_EXCEPTION(
00087     0!=RTOp_reduce_reduct_objs( &op_, (*this)(in_reduct_obj), (*this)(*inout_reduct_obj) )
00088     ,UnknownError
00089     ,"RTOpC::reduce_reduct_objs(...): Error, "
00090     "RTOp_reduce_reduct_objs(...) returned != 0"
00091     );
00092 }
00093 
00094 void RTOpC::reduct_obj_reinit( ReductTarget* reduct_obj ) const
00095 {
00096   TEST_FOR_EXCEPTION(
00097     0!=RTOp_reduct_obj_reinit( &op_, (*this)(*reduct_obj) )
00098     ,UnknownError
00099     ,"RTOpC::reduct_obj_reinit(...): Error, "
00100     "RTOp_reduct_obj_reinit(...) returned != 0"
00101     );
00102 }
00103 
00104 void RTOpC::extract_reduct_obj_state(
00105   const ReductTarget     &reduct_obj
00106   ,int                      num_values
00107   ,primitive_value_type     value_data[]
00108   ,int                      num_indexes
00109   ,index_type               index_data[]
00110   ,int                      num_chars
00111   ,char_type                char_data[]
00112   ) const
00113 {
00114   TEST_FOR_EXCEPTION(
00115     0!=RTOp_extract_reduct_obj_state(
00116       &op_, (*this)(reduct_obj)
00117       ,num_values,  value_data
00118       ,num_indexes, index_data
00119       ,num_chars,   char_data
00120       )
00121     ,UnknownError
00122     ,"RTOpC::extract_reduct_obj_state(...): Error, "
00123     "RTOp_extract_reduct_obj_state(...) returned != 0"
00124     );
00125 }
00126 
00127 void RTOpC::load_reduct_obj_state(
00128   int                            num_values
00129   ,const primitive_value_type    value_data[]
00130   ,int                           num_indexes
00131   ,const index_type              index_data[]
00132   ,int                           num_chars
00133   ,const char_type               char_data[]
00134   ,ReductTarget               *reduct_obj
00135   ) const
00136 {
00137   TEST_FOR_EXCEPTION(
00138     0!=RTOp_load_reduct_obj_state(
00139       &op_
00140       ,num_values,  value_data
00141       ,num_indexes, index_data
00142       ,num_chars,   char_data
00143       ,(*this)(*reduct_obj)
00144       )
00145     ,UnknownError
00146     ,"RTOpC::load_reduct_obj_state(...): Error, "
00147     "RTOp_load_reduct_obj_state(...) returned != 0"
00148     );
00149 }
00150 
00151 void RTOpC::get_op_type_num_entries(
00152   int*  num_values
00153   ,int* num_indexes
00154   ,int* num_chars
00155   ) const
00156 {
00157   TEST_FOR_EXCEPTION(
00158     0!=RTOp_get_op_type_num_entries(&op_,num_values,num_indexes,num_chars)
00159     ,UnknownError
00160     ,"RTOpC::get_op_type_num_entries(...): Error, "
00161     "RTOp_get_op_type_num_entries(...) returned != 0"
00162     );
00163 }
00164 
00165 void RTOpC::extract_op_state(
00166   int                             num_values
00167   ,primitive_value_type           value_data[]
00168   ,int                            num_indexes
00169   ,index_type                     index_data[]
00170   ,int                            num_chars
00171   ,char_type                      char_data[]
00172   ) const
00173 {
00174   TEST_FOR_EXCEPTION(
00175     0!=RTOp_extract_op_state(
00176       &op_
00177       ,num_values,  value_data
00178       ,num_indexes, index_data
00179       ,num_chars,   char_data
00180       )
00181     ,UnknownError
00182     ,"RTOpC::extract_opt_state(...): Error, "
00183     "RTOp_extract_opt_state(...) returned != 0"
00184     );
00185 }
00186 
00187 void RTOpC::load_op_state(
00188   int                           num_values
00189   ,const primitive_value_type   value_data[]
00190   ,int                          num_indexes
00191   ,const index_type             index_data[]
00192   ,int                          num_chars
00193   ,const char_type              char_data[]
00194   )
00195 {
00196   TEST_FOR_EXCEPTION(
00197     0!=RTOp_load_op_state(
00198       num_values,   value_data
00199       ,num_indexes, index_data
00200       ,num_chars,   char_data
00201       ,&op_
00202       )
00203     ,UnknownError
00204     ,"RTOpC::load_opt_state(...): Error, "
00205     "RTOp_load_opt_state(...) returned != 0"
00206     );
00207 }
00208 
00209 bool RTOpC::coord_invariant() const
00210 {
00211   return false; // We have to assume this to be safe!
00212 }
00213 
00214 const char* RTOpC::op_name() const
00215 {
00216   const char* op_name = NULL;
00217   TEST_FOR_EXCEPTION(
00218     0!=RTOp_get_op_name(&op_,&op_name)
00219     ,UnknownError
00220     ,"RTOpC::get_op_name(...): Error, "
00221     "RTOp_op_name(...) returned != 0"
00222     );
00223   return op_name;
00224 }
00225 
00226 void RTOpC::apply_op(
00227   const int   num_vecs,       const ConstSubVectorView<Scalar>         sub_vecs[]
00228   ,const int  num_targ_vecs,  const SubVectorView<Scalar>  targ_sub_vecs[]
00229   ,ReductTarget *_reduct_obj
00230   ) const
00231 {
00232   using Teuchos::Workspace;
00233   Teuchos::WorkspaceStore* wss = Teuchos::get_default_workspace_store().get();
00234 
00235   RTOp_ReductTarget reduct_obj = RTOp_REDUCT_OBJ_NULL;
00236   if(_reduct_obj) reduct_obj = (*this)(*_reduct_obj);
00237 
00238   int k;
00239   Workspace<RTOp_SubVector>        c_sub_vecs(wss,num_vecs,false);
00240   for( k = 0; k < num_vecs; ++k ) {
00241     const SubVector& v = sub_vecs[k];
00242     RTOp_sub_vector(v.globalOffset(),v.subDim(),v.values(),v.stride(),&c_sub_vecs[k]);
00243   }
00244   Workspace<RTOp_MutableSubVector>  c_targ_sub_vecs(wss,num_targ_vecs,false);
00245   for( k = 0; k < num_targ_vecs; ++k ) {
00246     const MutableSubVector& v = targ_sub_vecs[k];
00247     RTOp_mutable_sub_vector(v.globalOffset(),v.subDim(),v.values(),v.stride(),&c_targ_sub_vecs[k]);
00248   }
00249 
00250   const int err = RTOp_apply_op(
00251     &op_
00252     ,num_vecs,       num_vecs       ? &c_sub_vecs[0]      : (RTOp_SubVector*)NULL
00253     ,num_targ_vecs,  num_targ_vecs  ? &c_targ_sub_vecs[0] : (RTOp_MutableSubVector*)NULL
00254     ,reduct_obj
00255     );
00256   TEST_FOR_EXCEPTION(
00257     err==RTOp_ERR_INVALID_NUM_VECS, InvalidNumVecs
00258     ,"RTOpC::apply_op(...): Error, "
00259     "RTOp_apply_op(...) returned RTOp_ERR_INVALID_NUM_VECS" );
00260   TEST_FOR_EXCEPTION(
00261     err==RTOp_ERR_INVALID_NUM_TARG_VECS, InvalidNumTargVecs
00262     ,"RTOpC::apply_op(...): Error, "
00263     "RTOp_apply_op(...) returned RTOp_ERR_INVALID_NUM_TARG_VECS" );
00264   TEST_FOR_EXCEPTION(
00265     err!=0, UnknownError
00266     ,"RTOpC::apply_op(...): Error, "
00267     "RTOp_apply_op(...) returned != 0 with unknown meaning" );
00268 
00269 }
00270 
00271 } // namespace RTOpPack

Generated on Thu Sep 18 12:33:39 2008 for RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators by doxygen 1.3.9.1