|
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 // 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 00031 #include <math.h> 00032 00033 /* ///////////////////////////////////////////// */ 00034 /* RTOp_ROp_comp_err_with_mu.c */ 00035 00036 /* */ 00037 /* Note: This file was created automatically by 'new_rtop.pl' */ 00038 /* on 7/24/2002 at 23:46 */ 00039 /* */ 00040 00041 #define max(a,b) ( (a) > (b) ? (a) : (b) ) 00042 #define min(a,b) ( (a) < (b) ? (a) : (b) ) 00043 00044 #include "RTOp_ROp_comp_err_with_mu.h" 00045 #include "RTOp_obj_value_value_vtbl.h" /* vtbl for operator object instance data */ 00046 #include "RTOp_reduct_max_value.h" 00047 00048 00049 /* Implementation functions for RTOp_RTOp */ 00050 00051 static int RTOp_ROp_comp_err_with_mu_apply_op( 00052 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00053 , const int num_vecs, const struct RTOp_SubVector vecs[] 00054 , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[] 00055 , RTOp_ReductTarget reduct_obj ) 00056 { 00057 /* */ 00058 /* Declare local variables */ 00059 /* */ 00060 00061 /* Access to the operator object instance data */ 00062 struct RTOp_value_value_type *data_cntr = (struct RTOp_value_value_type*)obj_data; 00063 RTOp_value_type *mu = &data_cntr->value1; 00064 RTOp_value_type *inf_bound = &data_cntr->value2; 00065 /* Access to the reduction object data */ 00066 RTOp_value_type *comp_err = (RTOp_value_type*)reduct_obj; 00067 /* Vector data */ 00068 RTOp_index_type sub_dim; 00069 /* v0 */ 00070 const RTOp_value_type *v0_val; 00071 ptrdiff_t v0_val_s; 00072 /* v1 */ 00073 const RTOp_value_type *v1_val; 00074 ptrdiff_t v1_val_s; 00075 /* v2 */ 00076 const RTOp_value_type *v2_val; 00077 ptrdiff_t v2_val_s; 00078 /* v3 */ 00079 const RTOp_value_type *v3_val; 00080 ptrdiff_t v3_val_s; 00081 /* v4 */ 00082 const RTOp_value_type *v4_val; 00083 ptrdiff_t v4_val_s; 00084 00085 /* Automatic temporary variables */ 00086 register RTOp_index_type k; 00087 /* Temporary element-wise reduction object */ 00088 RTOp_value_type comp_err_ith; 00089 00090 /* */ 00091 /* Validate the input */ 00092 /* */ 00093 if( num_vecs != 5 || ( num_vecs && vecs == NULL ) ) 00094 return RTOp_ERR_INVALID_NUM_VECS; 00095 if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) ) 00096 return RTOp_ERR_INVALID_NUM_TARG_VECS; 00097 if( /* Validate sub_dim */ 00098 vecs[1].sub_dim != vecs[0].sub_dim 00099 || vecs[2].sub_dim != vecs[0].sub_dim 00100 || vecs[3].sub_dim != vecs[0].sub_dim 00101 || vecs[4].sub_dim != vecs[0].sub_dim 00102 ) 00103 return RTOp_ERR_INCOMPATIBLE_VECS; 00104 assert(obj_data); 00105 assert(reduct_obj); 00106 00107 00108 /* */ 00109 /* Get pointers to data */ 00110 /* */ 00111 sub_dim = vecs[0].sub_dim; 00112 /* v0 */ 00113 v0_val = vecs[0].values; 00114 v0_val_s = vecs[0].values_stride; 00115 /* v1 */ 00116 v1_val = vecs[1].values; 00117 v1_val_s = vecs[1].values_stride; 00118 /* v2 */ 00119 v2_val = vecs[2].values; 00120 v2_val_s = vecs[2].values_stride; 00121 /* v3 */ 00122 v3_val = vecs[3].values; 00123 v3_val_s = vecs[3].values_stride; 00124 /* v4 */ 00125 v4_val = vecs[4].values; 00126 v4_val_s = vecs[4].values_stride; 00127 00128 00129 /* */ 00130 /* Apply the operator: */ 00131 /* */ 00132 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, v4_val += v4_val_s ) 00133 { 00134 /* Element-wise reduction */ 00135 comp_err_ith = 0; 00136 if ((*v1_val) > -(*inf_bound)) 00137 { comp_err_ith = fabs((*v3_val)*((*v0_val)-(*v1_val))-(*mu)); } 00138 00139 if ((*v2_val) < (*inf_bound)) 00140 { comp_err_ith = max(comp_err_ith, fabs((*v4_val)*((*v2_val)-(*v0_val))-(*mu))); } 00141 00142 /* Reduction of intermediates */ 00143 (*comp_err) = max( (*comp_err), comp_err_ith ); 00144 } 00145 00146 return 0; /* success? */ 00147 } 00148 00149 /* Virtual function table */ 00150 const struct RTOp_RTOp_vtbl_t RTOp_ROp_comp_err_with_mu_vtbl = 00151 { 00152 &RTOp_obj_value_value_vtbl 00153 ,&RTOp_obj_value_vtbl 00154 ,"ROp_comp_err_with_mu" 00155 ,NULL 00156 ,RTOp_ROp_comp_err_with_mu_apply_op 00157 ,RTOp_reduct_max_value 00158 ,RTOp_get_reduct_max_value_op 00159 }; 00160 00161 /* Class specific functions */ 00162 00163 int RTOp_ROp_comp_err_with_mu_construct( RTOp_value_type mu, RTOp_value_type inf_bound, struct RTOp_RTOp* op ) 00164 { 00165 #ifdef RTOp_DEBUG 00166 assert(op); 00167 #endif 00168 op->obj_data = NULL; 00169 op->vtbl = &RTOp_ROp_comp_err_with_mu_vtbl; 00170 op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data); 00171 return RTOp_ROp_comp_err_with_mu_init(mu,inf_bound,op); 00172 } 00173 00174 int RTOp_ROp_comp_err_with_mu_destroy( struct RTOp_RTOp* op ) 00175 { 00176 op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data); 00177 op->obj_data = NULL; 00178 op->vtbl = NULL; 00179 return 0; 00180 } 00181 00182 int RTOp_ROp_comp_err_with_mu_init( RTOp_value_type mu, RTOp_value_type inf_bound, struct RTOp_RTOp* op ) 00183 { 00184 struct RTOp_value_value_type *ptr_data_cntr = (struct RTOp_value_value_type*)op->obj_data; 00185 RTOp_value_type *ptr_mu = &ptr_data_cntr->value1; 00186 RTOp_value_type *ptr_inf_bound = &ptr_data_cntr->value2; 00187 *ptr_mu = mu; 00188 *ptr_inf_bound = inf_bound; 00189 return 0; 00190 } 00191 RTOp_value_type RTOp_ROp_comp_err_with_mu_val(RTOp_ReductTarget reduct_obj) 00192 { 00193 return *((RTOp_value_type*)reduct_obj); 00194 } 00195
1.7.4