|
RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators
Version of the Day
|
00001 /* 00002 // @HEADER 00003 // *********************************************************************** 00004 // 00005 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00006 // Copyright (2003) 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 00044 /* */ 00045 /* Note: This file was created automatically by 'new_rtop.pl' */ 00046 /* on 6/27/2002 at 15:7 */ 00047 /* */ 00048 00049 #define max(a,b) ( (a) > (b) ? (a) : (b) ) 00050 #define min(a,b) ( (a) < (b) ? (a) : (b) ) 00051 00052 #include "RTOp_ROp_combined_nu_comp_err.h" 00053 #include "RTOp_obj_null_vtbl.h" /* vtbl for operator object instance data */ 00054 #include "RTOp_reduct_max_value.h" 00055 00056 00057 /* Implementation functions for RTOp_RTOp */ 00058 00059 static int RTOp_ROp_combined_nu_comp_err_apply_op( 00060 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00061 , const int num_vecs, const struct RTOp_SubVector vecs[] 00062 , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[] 00063 , RTOp_ReductTarget reduct_obj ) 00064 { 00065 /* */ 00066 /* Declare local variables */ 00067 /* */ 00068 00069 /* Access to the reduction object data */ 00070 RTOp_value_type *comp_err = (RTOp_value_type*)reduct_obj; 00071 /* Vector data */ 00072 RTOp_index_type sub_dim; 00073 /* v0 */ 00074 const RTOp_value_type *v0_val; 00075 ptrdiff_t v0_val_s; 00076 /* v1 */ 00077 const RTOp_value_type *v1_val; 00078 ptrdiff_t v1_val_s; 00079 /* v2 */ 00080 const RTOp_value_type *v2_val; 00081 ptrdiff_t v2_val_s; 00082 /* v3 */ 00083 const RTOp_value_type *v3_val; 00084 ptrdiff_t v3_val_s; 00085 00086 register RTOp_index_type k; 00087 00088 /* */ 00089 /* Validate the input */ 00090 /* */ 00091 if( num_vecs != 4 || ( num_vecs && vecs == NULL ) ) 00092 return RTOp_ERR_INVALID_NUM_VECS; 00093 if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) ) 00094 return RTOp_ERR_INVALID_NUM_TARG_VECS; 00095 if( /* Validate sub_dim */ 00096 vecs[1].sub_dim != vecs[0].sub_dim 00097 || vecs[2].sub_dim != vecs[0].sub_dim 00098 || vecs[3].sub_dim != vecs[0].sub_dim 00099 ) 00100 return RTOp_ERR_INCOMPATIBLE_VECS; 00101 assert(reduct_obj); 00102 00103 00104 /* */ 00105 /* Get pointers to data */ 00106 /* */ 00107 sub_dim = vecs[0].sub_dim; 00108 /* v0 */ 00109 v0_val = vecs[0].values; 00110 v0_val_s = vecs[0].values_stride; 00111 /* v1 */ 00112 v1_val = vecs[1].values; 00113 v1_val_s = vecs[1].values_stride; 00114 /* v2 */ 00115 v2_val = vecs[2].values; 00116 v2_val_s = vecs[2].values_stride; 00117 /* v3 */ 00118 v3_val = vecs[3].values; 00119 v3_val_s = vecs[3].values_stride; 00120 00121 00122 /* */ 00123 /* Apply the operator: */ 00124 /* */ 00125 /* element-wise reduction : if (v0(i) < 0) */ 00126 /* */ 00127 for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, v2_val += v2_val_s, v3_val += v3_val_s ) 00128 { 00129 /* Element-wise reduction */ 00130 (*comp_err) = max( *comp_err, (*v0_val) * ((*v3_val) - (*v1_val))); 00131 (*comp_err) = max( *comp_err, -(*v0_val) * ((*v1_val) - (*v2_val))); 00132 } 00133 00134 return 0; /* success? */ 00135 } 00136 00137 /* Virtual function table */ 00138 const struct RTOp_RTOp_vtbl_t RTOp_ROp_combined_nu_comp_err_vtbl = 00139 { 00140 &RTOp_obj_null_vtbl 00141 ,&RTOp_obj_value_vtbl 00142 ,"ROp_combined_nu_comp_err" 00143 ,NULL 00144 ,RTOp_ROp_combined_nu_comp_err_apply_op 00145 ,RTOp_reduct_max_value 00146 ,RTOp_get_reduct_max_value_op 00147 }; 00148 00149 /* Class specific functions */ 00150 00151 int RTOp_ROp_combined_nu_comp_err_construct( struct RTOp_RTOp* op ) 00152 { 00153 #ifdef RTOp_DEBUG 00154 assert(op); 00155 #endif 00156 op->obj_data = NULL; 00157 op->vtbl = &RTOp_ROp_combined_nu_comp_err_vtbl; 00158 op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data); 00159 return 0; 00160 } 00161 00162 int RTOp_ROp_combined_nu_comp_err_destroy( struct RTOp_RTOp* op ) 00163 { 00164 op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data); 00165 op->obj_data = NULL; 00166 op->vtbl = NULL; 00167 return 0; 00168 } 00169 00170 00171 RTOp_value_type RTOp_ROp_combined_nu_comp_err_val(RTOp_ReductTarget reduct_obj) 00172 { 00173 return *((RTOp_value_type*)reduct_obj); 00174 } 00175 00176 00177 00178 /* Implementation functions for RTOp_RTOp */ 00179 00180 static int RTOp_ROp_combined_nu_comp_err_one_only_apply_op( 00181 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00182 , const int num_vecs, const struct RTOp_SubVector vecs[] 00183 , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[] 00184 , RTOp_ReductTarget reduct_obj ) 00185 { 00186 /* */ 00187 /* Declare local variables */ 00188 /* */ 00189 00190 /* Access to the reduction object data */ 00191 RTOp_value_type *comp_err = (RTOp_value_type*)reduct_obj; 00192 /* Vector data */ 00193 RTOp_index_type sub_dim; 00194 /* v0 */ 00195 const RTOp_value_type *v0_val; 00196 ptrdiff_t v0_val_s; 00197 /* v1 */ 00198 const RTOp_value_type *v1_val; 00199 ptrdiff_t v1_val_s; 00200 /* v2 */ 00201 const RTOp_value_type *v2_val; 00202 ptrdiff_t v2_val_s; 00203 00204 register RTOp_index_type k; 00205 00206 /* */ 00207 /* Validate the input */ 00208 /* */ 00209 if( num_vecs != 3 || ( num_vecs && vecs == NULL ) ) 00210 return RTOp_ERR_INVALID_NUM_VECS; 00211 if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) ) 00212 return RTOp_ERR_INVALID_NUM_TARG_VECS; 00213 if( /* Validate sub_dim */ 00214 vecs[1].sub_dim != vecs[0].sub_dim 00215 || vecs[2].sub_dim != vecs[0].sub_dim 00216 ) 00217 return RTOp_ERR_INCOMPATIBLE_VECS; 00218 assert(reduct_obj); 00219 00220 00221 /* */ 00222 /* Get pointers to data */ 00223 /* */ 00224 sub_dim = vecs[0].sub_dim; 00225 /* v0 */ 00226 v0_val = vecs[0].values; 00227 v0_val_s = vecs[0].values_stride; 00228 /* v1 */ 00229 v1_val = vecs[1].values; 00230 v1_val_s = vecs[1].values_stride; 00231 /* v2 */ 00232 v2_val = vecs[2].values; 00233 v2_val_s = vecs[2].values_stride; 00234 00235 00236 /* */ 00237 /* Apply the operator: */ 00238 /* */ 00239 /* element-wise reduction : comp_err = max(comp_err, v0(i)*(v1(i)-v2(i))); */ 00240 /* */ 00241 for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, v2_val += v2_val_s ) 00242 { 00243 /* Element-wise reduction */ 00244 (*comp_err) = max((*comp_err), (*v0_val)*((*v1_val)-(*v2_val))); 00245 } 00246 00247 return 0; /* success? */ 00248 } 00249 00250 /* Virtual function table */ 00251 const struct RTOp_RTOp_vtbl_t RTOp_ROp_combined_nu_comp_err_one_only_vtbl = 00252 { 00253 &RTOp_obj_null_vtbl 00254 ,&RTOp_obj_value_vtbl 00255 ,"ROp_combined_nu_comp_err_one_only" 00256 ,NULL 00257 ,RTOp_ROp_combined_nu_comp_err_one_only_apply_op 00258 ,RTOp_reduct_max_value 00259 ,RTOp_get_reduct_max_value_op 00260 }; 00261 00262 /* Class specific functions */ 00263 00264 int RTOp_ROp_combined_nu_comp_err_one_only_construct( struct RTOp_RTOp* op ) 00265 { 00266 #ifdef RTOp_DEBUG 00267 assert(op); 00268 #endif 00269 op->obj_data = NULL; 00270 op->vtbl = &RTOp_ROp_combined_nu_comp_err_one_only_vtbl; 00271 op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data); 00272 return 0; 00273 } 00274 00275 int RTOp_ROp_combined_nu_comp_err_one_only_destroy( struct RTOp_RTOp* op ) 00276 { 00277 op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data); 00278 op->obj_data = NULL; 00279 op->vtbl = NULL; 00280 return 0; 00281 } 00282 00283 00284 RTOp_value_type RTOp_ROp_combined_nu_comp_err_one_only_val(RTOp_ReductTarget reduct_obj) 00285 { 00286 return *((RTOp_value_type*)reduct_obj); 00287 } 00288
1.7.6.1