|
RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators
Version of the Day
|
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 // /////////////////////////////// 00043 // RTOpPack_RTOpC.cpp 00044 00045 #include "RTOpPack_RTOpC.hpp" 00046 #include "Teuchos_Workspace.hpp" 00047 00048 00049 namespace RTOpPack { 00050 00051 00052 RTOpC::RTOpC() 00053 :RTOpT<RTOp_value_type>("RTOpC") // Should be unused since op_name() if overridden here! 00054 { 00055 op_.vtbl = NULL; 00056 op_.obj_data = NULL; 00057 } 00058 00059 00060 RTOpC::~RTOpC() 00061 { 00062 if(op_.obj_data) 00063 RTOp_free_op( &op_ ); 00064 } 00065 00066 00067 // Overridden from RTOpT 00068 00069 00070 void RTOpC::get_reduct_type_num_entries_impl( 00071 const Teuchos::Ptr<int> &num_values, 00072 const Teuchos::Ptr<int> &num_indexes, 00073 const Teuchos::Ptr<int> &num_chars 00074 ) const 00075 { 00076 TEUCHOS_TEST_FOR_EXCEPTION( 00077 0!=RTOp_get_reduct_type_num_entries(&op_,&*num_values,&*num_indexes,&*num_chars) 00078 ,UnknownError 00079 ,"RTOpC::get_reduct_type_num_entries(...): Error, " 00080 "RTOp_get_reduct_type_num_entries(...) returned != 0" 00081 ); 00082 } 00083 00084 00085 Teuchos::RCP<ReductTarget> 00086 RTOpC::reduct_obj_create_impl() const 00087 { 00088 RTOp_ReductTarget reduct_obj_raw = RTOp_REDUCT_OBJ_NULL; 00089 TEUCHOS_TEST_FOR_EXCEPTION( 00090 0!=RTOp_reduct_obj_create(&op_,&reduct_obj_raw) 00091 ,UnknownError 00092 ,"RTOpC::reduct_obj_create(...): Error, " 00093 "RTOp_reduct_obj_create(...) returned != 0" 00094 ); 00095 return Teuchos::rcp(new ReductTargetC(op_,reduct_obj_raw)); 00096 } 00097 00098 00099 void RTOpC::reduce_reduct_objs_impl( 00100 const ReductTarget &in_reduct_obj, 00101 const Teuchos::Ptr<ReductTarget> &inout_reduct_obj 00102 ) const 00103 { 00104 TEUCHOS_TEST_FOR_EXCEPTION( 00105 0!=RTOp_reduce_reduct_objs( &op_, (*this)(in_reduct_obj), (*this)(*inout_reduct_obj) ) 00106 ,UnknownError 00107 ,"RTOpC::reduce_reduct_objs(...): Error, " 00108 "RTOp_reduce_reduct_objs(...) returned != 0" 00109 ); 00110 } 00111 00112 00113 void RTOpC::reduct_obj_reinit_impl( 00114 const Teuchos::Ptr<ReductTarget> &reduct_obj ) const 00115 { 00116 TEUCHOS_TEST_FOR_EXCEPTION( 00117 0!=RTOp_reduct_obj_reinit( &op_, (*this)(*reduct_obj) ) 00118 ,UnknownError 00119 ,"RTOpC::reduct_obj_reinit(...): Error, " 00120 "RTOp_reduct_obj_reinit(...) returned != 0" 00121 ); 00122 } 00123 00124 00125 void RTOpC::extract_reduct_obj_state_impl( 00126 const ReductTarget &reduct_obj, 00127 const Teuchos::ArrayView<primitive_value_type> &value_data, 00128 const Teuchos::ArrayView<index_type> &index_data, 00129 const Teuchos::ArrayView<char_type> &char_data 00130 ) const 00131 { 00132 TEUCHOS_TEST_FOR_EXCEPTION( 00133 0!=RTOp_extract_reduct_obj_state( 00134 &op_, (*this)(reduct_obj), 00135 value_data.size(), value_data.getRawPtr(), 00136 index_data.size(), index_data.getRawPtr(), 00137 char_data.size(), char_data.getRawPtr() 00138 ), 00139 UnknownError, 00140 "RTOpC::extract_reduct_obj_state(...): Error, " 00141 "RTOp_extract_reduct_obj_state(...) returned != 0" 00142 ); 00143 } 00144 00145 00146 void RTOpC::load_reduct_obj_state_impl( 00147 const Teuchos::ArrayView<const primitive_value_type> &value_data, 00148 const Teuchos::ArrayView<const index_type> &index_data, 00149 const Teuchos::ArrayView<const char_type> &char_data, 00150 const Teuchos::Ptr<ReductTarget> &reduct_obj 00151 ) const 00152 { 00153 TEUCHOS_TEST_FOR_EXCEPTION( 00154 0!=RTOp_load_reduct_obj_state( 00155 &op_, 00156 value_data.size(), value_data.getRawPtr(), 00157 index_data.size(), index_data.getRawPtr(), 00158 char_data.size(), char_data.getRawPtr(), 00159 (*this)(*reduct_obj) 00160 ), 00161 UnknownError, 00162 "RTOpC::load_reduct_obj_state(...): Error, " 00163 "RTOp_load_reduct_obj_state(...) returned != 0" 00164 ); 00165 } 00166 00167 00168 bool RTOpC::coord_invariant_impl() const 00169 { 00170 return false; // We have to assume this to be safe! 00171 } 00172 00173 00174 std::string RTOpC::op_name_impl() const 00175 { 00176 const char* op_name = NULL; 00177 TEUCHOS_TEST_FOR_EXCEPTION( 00178 0!=RTOp_get_op_name(&op_,&op_name) 00179 ,UnknownError 00180 ,"RTOpC::get_op_name(...): Error, " 00181 "RTOp_op_name(...) returned != 0" 00182 ); 00183 return op_name; 00184 } 00185 00186 00187 void RTOpC::apply_op_impl( 00188 const Teuchos::ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs, 00189 const Teuchos::ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs, 00190 const Teuchos::Ptr<ReductTarget> &_reduct_obj 00191 ) const 00192 { 00193 00194 using Teuchos::Workspace; 00195 Teuchos::WorkspaceStore* wss = 00196 Teuchos::get_default_workspace_store().get(); 00197 00198 const int num_vecs = sub_vecs.size(); 00199 const int num_targ_vecs = targ_sub_vecs.size(); 00200 00201 RTOp_ReductTarget reduct_obj = RTOp_REDUCT_OBJ_NULL; 00202 if(!is_null(_reduct_obj)) 00203 reduct_obj = (*this)(*_reduct_obj); 00204 00205 int k; 00206 Workspace<RTOp_SubVector> c_sub_vecs(wss,num_vecs,false); 00207 for( k = 0; k < num_vecs; ++k ) { 00208 const SubVector& v = sub_vecs[k]; 00209 RTOp_sub_vector(v.globalOffset(),v.subDim(),v.values(),v.stride(),&c_sub_vecs[k]); 00210 } 00211 Workspace<RTOp_MutableSubVector> c_targ_sub_vecs(wss,num_targ_vecs,false); 00212 for( k = 0; k < num_targ_vecs; ++k ) { 00213 const MutableSubVector& v = targ_sub_vecs[k]; 00214 RTOp_mutable_sub_vector(v.globalOffset(),v.subDim(),v.values(),v.stride(),&c_targ_sub_vecs[k]); 00215 } 00216 00217 const int err = RTOp_apply_op( 00218 &op_ 00219 ,num_vecs, num_vecs ? &c_sub_vecs[0] : (RTOp_SubVector*)NULL 00220 ,num_targ_vecs, num_targ_vecs ? &c_targ_sub_vecs[0] : (RTOp_MutableSubVector*)NULL 00221 ,reduct_obj 00222 ); 00223 TEUCHOS_TEST_FOR_EXCEPTION( 00224 err==RTOp_ERR_INVALID_NUM_VECS, InvalidNumVecs 00225 ,"RTOpC::apply_op(...): Error, " 00226 "RTOp_apply_op(...) returned RTOp_ERR_INVALID_NUM_VECS" ); 00227 TEUCHOS_TEST_FOR_EXCEPTION( 00228 err==RTOp_ERR_INVALID_NUM_TARG_VECS, InvalidNumTargVecs 00229 ,"RTOpC::apply_op(...): Error, " 00230 "RTOp_apply_op(...) returned RTOp_ERR_INVALID_NUM_TARG_VECS" ); 00231 TEUCHOS_TEST_FOR_EXCEPTION( 00232 err!=0, UnknownError 00233 ,"RTOpC::apply_op(...): Error, " 00234 "RTOp_apply_op(...) returned != 0 with unknown meaning" ); 00235 00236 } 00237 00238 00239 } // namespace RTOpPack
1.7.6.1