RTOp_ROp_log_bound_barrier.c

Go to the documentation of this file.
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 /* Note: This file was created automatically by 'new_rtop.pl' */
00033 /*       on 6/26/2002 at 21:9 */
00034 /* */
00035 
00036 #define max(a,b) ( (a) > (b) ? (a) : (b) )
00037 #define min(a,b) ( (a) < (b) ? (a) : (b) )
00038 
00039 #include "RTOp_ROp_log_bound_barrier.h"
00040 #include "RTOp_obj_null_vtbl.h"  /* vtbl for operator object instance data */
00041 #include "RTOp_reduct_sum_value.h"  /* Reduction of intermediate reduction objects */
00042 
00043 
00044 
00045 /* Implementation functions for RTOp_RTOp */
00046 
00047 static int RTOp_ROp_log_bound_barrier_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 reduction object data */
00058     RTOp_value_type *log_result = (RTOp_value_type*)reduct_obj;
00059     /* Vector data */
00060     RTOp_index_type           sub_dim;
00061     /* v0 */
00062     const RTOp_value_type     *v0_val;
00063     ptrdiff_t                 v0_val_s;
00064     /* v1 */
00065     const RTOp_value_type     *v1_val;
00066     ptrdiff_t                 v1_val_s;
00067     /* v2 */
00068     const RTOp_value_type     *v2_val;
00069     ptrdiff_t                 v2_val_s;
00070 
00071     register RTOp_index_type  k;
00072 
00073   /* */
00074   /* Validate the input */
00075   /* */
00076     if( num_vecs != 3 || ( num_vecs && vecs == NULL ) )
00077         return RTOp_ERR_INVALID_NUM_VECS;
00078     if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
00079         return RTOp_ERR_INVALID_NUM_TARG_VECS;
00080     if( /* Validate sub_dim */
00081         vecs[1].sub_dim != vecs[0].sub_dim
00082         || vecs[2].sub_dim != vecs[0].sub_dim
00083         )
00084         return RTOp_ERR_INCOMPATIBLE_VECS;
00085     assert(reduct_obj);
00086 
00087 
00088   /* */
00089   /* Get pointers to data */
00090   /* */
00091     sub_dim       = vecs[0].sub_dim;
00092     /* v0 */
00093     v0_val        = vecs[0].values;
00094     v0_val_s      = vecs[0].values_stride;
00095     /* v1 */
00096     v1_val        = vecs[1].values;
00097     v1_val_s      = vecs[1].values_stride;
00098     /* v2 */
00099     v2_val        = vecs[2].values;
00100     v2_val_s      = vecs[2].values_stride;
00101 
00102 
00103   /* */
00104   /* Apply the operator: */
00105   /* */
00106     /*    element-wise reduction      : log_result += log(v0 - v1) + log(v2 - v0); */
00107     /* */
00108     for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, v2_val += v2_val_s )
00109     {
00110         /* Element-wise reduction */
00111         (*log_result) += log((*v0_val) - (*v1_val)) + log((*v2_val) - (*v0_val));
00112     }
00113 
00114   return 0; /* success? */
00115 }
00116 
00117 /* Virtual function table */
00118 const struct RTOp_RTOp_vtbl_t RTOp_ROp_log_bound_barrier_vtbl =
00119 {
00120   &RTOp_obj_null_vtbl
00121   ,&RTOp_obj_value_vtbl
00122   ,"ROp_log_bound_barrier"
00123   ,NULL
00124   ,RTOp_ROp_log_bound_barrier_apply_op
00125   ,RTOp_reduct_sum_value
00126   ,RTOp_get_reduct_sum_value_op
00127 };
00128 
00129 /* Class specific functions */
00130 
00131 int RTOp_ROp_log_bound_barrier_construct(  struct RTOp_RTOp* op )
00132 {
00133 #ifdef RTOp_DEBUG
00134   assert(op);
00135 #endif
00136   op->obj_data  = NULL;
00137   op->vtbl      = &RTOp_ROp_log_bound_barrier_vtbl;
00138   op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
00139   return 0;
00140 }
00141 
00142 int RTOp_ROp_log_bound_barrier_destroy( struct RTOp_RTOp* op )
00143 {
00144   op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
00145   op->obj_data  = NULL;
00146   op->vtbl      = NULL;
00147   return 0;
00148 }
00149 
00150 
00151 RTOp_value_type RTOp_ROp_log_bound_barrier_val(RTOp_ReductTarget reduct_obj)
00152 {
00153     return *((RTOp_value_type*)reduct_obj);
00154 }
00155 

Generated on Thu Sep 18 12:35:19 2008 for MOOCHO (Single Doxygen Collection) by doxygen 1.3.9.1