|
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 /* ///////////////////////////////////////////// */ 00032 /* RTOp_TOp_max_vec_scalar.c */ 00033 00034 /* */ 00035 /* Note: This file was created automatically by 'new_rtop.pl' */ 00036 /* on 7/13/2002 at 13:44 */ 00037 /* */ 00038 00039 #define max(a,b) ( (a) > (b) ? (a) : (b) ) 00040 #define min(a,b) ( (a) < (b) ? (a) : (b) ) 00041 00042 #include "RTOp_TOp_max_vec_scalar.h" 00043 #include "RTOp_obj_value_vtbl.h" /* vtbl for operator object instance data */ 00044 00045 /* Implementation functions for RTOp_RTOp */ 00046 00047 static int RTOp_TOp_max_vec_scalar_apply_op( 00048 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00049 , const int num_vecs, const struct RTOp_SubVector vecs[] 00050 , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[] 00051 , RTOp_ReductTarget reduct_obj ) 00052 { 00053 /* */ 00054 /* Declare local variables */ 00055 /* */ 00056 00057 /* Access to the operator object instance data */ 00058 RTOp_value_type *min_ele = (RTOp_value_type*)obj_data; 00059 /* Vector data */ 00060 RTOp_index_type sub_dim; 00061 /* z0 */ 00062 RTOp_value_type *z0_val; 00063 ptrdiff_t z0_val_s; 00064 00065 /* Automatic temporary variables */ 00066 register RTOp_index_type k; 00067 00068 /* */ 00069 /* Validate the input */ 00070 /* */ 00071 if( num_vecs != 0 || ( num_vecs && vecs == NULL ) ) 00072 return RTOp_ERR_INVALID_NUM_VECS; 00073 if( num_targ_vecs != 1 || ( num_targ_vecs && targ_vecs == NULL ) ) 00074 return RTOp_ERR_INVALID_NUM_TARG_VECS; 00075 assert(obj_data); 00076 00077 /* */ 00078 /* Get pointers to data */ 00079 /* */ 00080 sub_dim = targ_vecs[0].sub_dim; 00081 /* z0 */ 00082 z0_val = targ_vecs[0].values; 00083 z0_val_s = targ_vecs[0].values_stride; 00084 00085 /* */ 00086 /* Apply the operator: */ 00087 /* */ 00088 for( k = 0; k < sub_dim; ++k, z0_val += z0_val_s ) 00089 { 00090 /* Element-wise transformation */ 00091 (*z0_val) = max((*z0_val),(*min_ele)); 00092 } 00093 00094 return 0; /* success? */ 00095 } 00096 00097 /* Virtual function table */ 00098 const struct RTOp_RTOp_vtbl_t RTOp_TOp_max_vec_scalar_vtbl = 00099 { 00100 &RTOp_obj_value_vtbl 00101 ,&RTOp_obj_null_vtbl 00102 ,"TOp_max_vec_scalar" 00103 ,NULL 00104 ,RTOp_TOp_max_vec_scalar_apply_op 00105 ,NULL 00106 ,NULL 00107 }; 00108 00109 /* Class specific functions */ 00110 00111 int RTOp_TOp_max_vec_scalar_construct( RTOp_value_type min_ele, struct RTOp_RTOp* op ) 00112 { 00113 #ifdef RTOp_DEBUG 00114 assert(op); 00115 #endif 00116 op->obj_data = NULL; 00117 op->vtbl = &RTOp_TOp_max_vec_scalar_vtbl; 00118 op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data); 00119 return RTOp_TOp_max_vec_scalar_init(min_ele,op); 00120 } 00121 00122 int RTOp_TOp_max_vec_scalar_destroy( struct RTOp_RTOp* op ) 00123 { 00124 op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data); 00125 op->obj_data = NULL; 00126 op->vtbl = NULL; 00127 return 0; 00128 } 00129 00130 int RTOp_TOp_max_vec_scalar_init( RTOp_value_type min_ele, struct RTOp_RTOp* op ) 00131 { 00132 RTOp_value_type *ptr_min_ele = (RTOp_value_type*)op->obj_data; 00133 *ptr_min_ele = min_ele; 00134 return 0; 00135 } 00136
1.7.4