MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RTOp_ROp_combined_nu_comp_err.c
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
6 // Copyright (2003) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 /* */
45 /* Note: This file was created automatically by 'new_rtop.pl' */
46 /* on 6/27/2002 at 15:7 */
47 /* */
48 
49 #define max(a,b) ( (a) > (b) ? (a) : (b) )
50 #define min(a,b) ( (a) < (b) ? (a) : (b) )
51 
53 #include "RTOp_obj_null_vtbl.h" /* vtbl for operator object instance data */
54 #include "RTOp_reduct_max_value.h"
55 
56 
57 /* Implementation functions for RTOp_RTOp */
58 
60  const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
61  , const int num_vecs, const struct RTOp_SubVector vecs[]
62  , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
63  , RTOp_ReductTarget reduct_obj )
64 {
65  /* */
66  /* Declare local variables */
67  /* */
68 
69  /* Access to the reduction object data */
70  RTOp_value_type *comp_err = (RTOp_value_type*)reduct_obj;
71  /* Vector data */
72  RTOp_index_type sub_dim;
73  /* v0 */
74  const RTOp_value_type *v0_val;
75  ptrdiff_t v0_val_s;
76  /* v1 */
77  const RTOp_value_type *v1_val;
78  ptrdiff_t v1_val_s;
79  /* v2 */
80  const RTOp_value_type *v2_val;
81  ptrdiff_t v2_val_s;
82  /* v3 */
83  const RTOp_value_type *v3_val;
84  ptrdiff_t v3_val_s;
85 
86  register RTOp_index_type k;
87 
88  /* */
89  /* Validate the input */
90  /* */
91  if( num_vecs != 4 || ( num_vecs && vecs == NULL ) )
93  if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
95  if( /* Validate sub_dim */
96  vecs[1].sub_dim != vecs[0].sub_dim
97  || vecs[2].sub_dim != vecs[0].sub_dim
98  || vecs[3].sub_dim != vecs[0].sub_dim
99  )
101  assert(reduct_obj);
102 
103 
104  /* */
105  /* Get pointers to data */
106  /* */
107  sub_dim = vecs[0].sub_dim;
108  /* v0 */
109  v0_val = vecs[0].values;
110  v0_val_s = vecs[0].values_stride;
111  /* v1 */
112  v1_val = vecs[1].values;
113  v1_val_s = vecs[1].values_stride;
114  /* v2 */
115  v2_val = vecs[2].values;
116  v2_val_s = vecs[2].values_stride;
117  /* v3 */
118  v3_val = vecs[3].values;
119  v3_val_s = vecs[3].values_stride;
120 
121 
122  /* */
123  /* Apply the operator: */
124  /* */
125  /* element-wise reduction : if (v0(i) < 0) */
126  /* */
127  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 )
128  {
129  /* Element-wise reduction */
130  (*comp_err) = max( *comp_err, (*v0_val) * ((*v3_val) - (*v1_val)));
131  (*comp_err) = max( *comp_err, -(*v0_val) * ((*v1_val) - (*v2_val)));
132  }
133 
134  return 0; /* success? */
135 }
136 
137 /* Virtual function table */
139 {
142  ,"ROp_combined_nu_comp_err"
143  ,NULL
147 };
148 
149 /* Class specific functions */
150 
152 {
153 #ifdef RTOp_DEBUG
154  assert(op);
155 #endif
156  op->obj_data = NULL;
158  op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
159  return 0;
160 }
161 
163 {
164  op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
165  op->obj_data = NULL;
166  op->vtbl = NULL;
167  return 0;
168 }
169 
170 
172 {
173  return *((RTOp_value_type*)reduct_obj);
174 }
175 
176 
177 
178 /* Implementation functions for RTOp_RTOp */
179 
181  const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
182  , const int num_vecs, const struct RTOp_SubVector vecs[]
183  , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
184  , RTOp_ReductTarget reduct_obj )
185 {
186  /* */
187  /* Declare local variables */
188  /* */
189 
190  /* Access to the reduction object data */
191  RTOp_value_type *comp_err = (RTOp_value_type*)reduct_obj;
192  /* Vector data */
193  RTOp_index_type sub_dim;
194  /* v0 */
195  const RTOp_value_type *v0_val;
196  ptrdiff_t v0_val_s;
197  /* v1 */
198  const RTOp_value_type *v1_val;
199  ptrdiff_t v1_val_s;
200  /* v2 */
201  const RTOp_value_type *v2_val;
202  ptrdiff_t v2_val_s;
203 
204  register RTOp_index_type k;
205 
206  /* */
207  /* Validate the input */
208  /* */
209  if( num_vecs != 3 || ( num_vecs && vecs == NULL ) )
211  if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
213  if( /* Validate sub_dim */
214  vecs[1].sub_dim != vecs[0].sub_dim
215  || vecs[2].sub_dim != vecs[0].sub_dim
216  )
218  assert(reduct_obj);
219 
220 
221  /* */
222  /* Get pointers to data */
223  /* */
224  sub_dim = vecs[0].sub_dim;
225  /* v0 */
226  v0_val = vecs[0].values;
227  v0_val_s = vecs[0].values_stride;
228  /* v1 */
229  v1_val = vecs[1].values;
230  v1_val_s = vecs[1].values_stride;
231  /* v2 */
232  v2_val = vecs[2].values;
233  v2_val_s = vecs[2].values_stride;
234 
235 
236  /* */
237  /* Apply the operator: */
238  /* */
239  /* element-wise reduction : comp_err = max(comp_err, v0(i)*(v1(i)-v2(i))); */
240  /* */
241  for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, v2_val += v2_val_s )
242  {
243  /* Element-wise reduction */
244  (*comp_err) = max((*comp_err), (*v0_val)*((*v1_val)-(*v2_val)));
245  }
246 
247  return 0; /* success? */
248 }
249 
250 /* Virtual function table */
252 {
255  ,"ROp_combined_nu_comp_err_one_only"
256  ,NULL
260 };
261 
262 /* Class specific functions */
263 
265 {
266 #ifdef RTOp_DEBUG
267  assert(op);
268 #endif
269  op->obj_data = NULL;
271  op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
272  return 0;
273 }
274 
276 {
277  op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
278  op->obj_data = NULL;
279  op->vtbl = NULL;
280  return 0;
281 }
282 
283 
285 {
286  return *((RTOp_value_type*)reduct_obj);
287 }
288 
ptrdiff_t values_stride
Definition: RTOp.h:305
double RTOp_value_type
Definition: RTOp.h:69
const struct RTOp_RTOp_vtbl_t RTOp_ROp_combined_nu_comp_err_one_only_vtbl
void * RTOp_ReductTarget
Definition: RTOp.h:191
RTOp_value_type RTOp_ROp_combined_nu_comp_err_val(RTOp_ReductTarget reduct_obj)
RTOp_value_type RTOp_ROp_combined_nu_comp_err_one_only_val(RTOp_ReductTarget reduct_obj)
int(* obj_create)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)
Definition: RTOp.h:941
const struct RTOp_obj_type_vtbl_t * obj_data_vtbl
Definition: RTOp.h:819
#define RTOp_ERR_INCOMPATIBLE_VECS
Definition: RTOp.h:270
int RTOp_ROp_combined_nu_comp_err_destroy(struct RTOp_RTOp *op)
const RTOp_value_type * values
Definition: RTOp.h:303
int RTOp_ROp_combined_nu_comp_err_construct(struct RTOp_RTOp *op)
#define max(a, b)
int RTOp_get_reduct_max_value_op(const struct RTOp_RTOp_vtbl_t *vtbl, const void *obj_data, RTOp_reduct_op_func_ptr_t *reduct_op_func_ptr)
const struct RTOp_RTOp_vtbl_t RTOp_ROp_combined_nu_comp_err_vtbl
int RTOp_ROp_combined_nu_comp_err_one_only_construct(struct RTOp_RTOp *op)
#define RTOp_ERR_INVALID_NUM_VECS
Definition: RTOp.h:266
int(* obj_free)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)
Definition: RTOp.h:1019
const struct RTOp_obj_type_vtbl_t RTOp_obj_null_vtbl
static int RTOp_ROp_combined_nu_comp_err_apply_op(const struct RTOp_RTOp_vtbl_t *vtbl, const void *obj_data, const int num_vecs, const struct RTOp_SubVector vecs[], const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[], RTOp_ReductTarget reduct_obj)
void * obj_data
Definition: RTOp.h:800
const struct RTOp_RTOp_vtbl_t * vtbl
Definition: RTOp.h:802
int RTOp_reduct_max_value(const struct RTOp_RTOp_vtbl_t *vtbl, const void *obj_data, RTOp_ReductTarget in_targ_obj, RTOp_ReductTarget inout_targ_obj)
int RTOp_ROp_combined_nu_comp_err_one_only_destroy(struct RTOp_RTOp *op)
RTOp_index_type sub_dim
Definition: RTOp.h:301
static int RTOp_ROp_combined_nu_comp_err_one_only_apply_op(const struct RTOp_RTOp_vtbl_t *vtbl, const void *obj_data, const int num_vecs, const struct RTOp_SubVector vecs[], const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[], RTOp_ReductTarget reduct_obj)
#define RTOp_ERR_INVALID_NUM_TARG_VECS
Definition: RTOp.h:268
const struct RTOp_obj_type_vtbl_t RTOp_obj_value_vtbl
Teuchos_Ordinal RTOp_index_type
Definition: RTOp.h:68