RTOp_ROp_sum_abs.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 #include <math.h>
00032 
00033 /* ///////////////////////////////////////////// */
00034 /* RTOp_ROp_sum_abs.c */
00035 
00036 /* */
00037 /* Note: This file was created automatically by 'new_rtop.pl' */
00038 /*       on 8/12/2003 at 19:31 */
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_sum_abs.h"
00045 #include "RTOp_obj_null_vtbl.h"     /* vtbl for operator object instance data */
00046 #include "RTOp_reduct_sum_value.h"  /* Reduction of intermediate reduction objects */
00047 
00048 /* Implementation functions for RTOp_RTOp */
00049 
00050 static int RTOp_ROp_sum_abs_apply_op(
00051   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00052   , const int num_vecs, const struct RTOp_SubVector vecs[]
00053   , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
00054   , RTOp_ReductTarget reduct_obj )
00055 {
00056   /* */
00057   /* Declare local variables */
00058   /* */
00059 
00060   /* Access to the reduction object data */
00061   RTOp_value_type *abs_sum = (RTOp_value_type*)reduct_obj;
00062   /* Vector data */
00063   RTOp_index_type           sub_dim;
00064   /* v0 */
00065   const RTOp_value_type     *v0_val;
00066   ptrdiff_t                 v0_val_s;
00067 
00068   /* Automatic temporary variables */
00069   register RTOp_index_type  k;
00070   /* Temporary element-wise reduction object */
00071   RTOp_value_type abs_sum_ith;
00072 
00073   /* */
00074   /* Validate the input */
00075   /* */
00076   if( num_vecs != 1 || ( 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   assert(reduct_obj);
00081 
00082   /* */
00083   /* Get pointers to data */
00084   /* */
00085   sub_dim       = vecs[0].sub_dim;
00086   /* v0 */
00087   v0_val        = vecs[0].values;
00088   v0_val_s      = vecs[0].values_stride;
00089 
00090   /* */
00091   /* Apply the operator: */
00092   /* */
00093   for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s )
00094   {
00095     /* Element-wise reduction */
00096     abs_sum_ith = fabs((*v0_val));
00097     /* Reduction of intermediates */
00098     (*abs_sum) += abs_sum_ith;
00099   }
00100 
00101   return 0; /* success? */
00102 }
00103 
00104 /* Virtual function table */
00105 const struct RTOp_RTOp_vtbl_t RTOp_ROp_sum_abs_vtbl =
00106 {
00107   &RTOp_obj_null_vtbl
00108   ,&RTOp_obj_value_vtbl
00109   ,"ROp_sum_abs"
00110   ,NULL
00111   ,RTOp_ROp_sum_abs_apply_op
00112   ,RTOp_reduct_sum_value
00113   ,RTOp_get_reduct_sum_value_op
00114 };
00115 
00116 /* Class specific functions */
00117 
00118 int RTOp_ROp_sum_abs_construct(  struct RTOp_RTOp* op )
00119 {
00120 #ifdef RTOp_DEBUG
00121   assert(op);
00122 #endif
00123   op->obj_data  = NULL;
00124   op->vtbl      = &RTOp_ROp_sum_abs_vtbl;
00125   op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
00126   return 0;
00127 }
00128 
00129 int RTOp_ROp_sum_abs_destroy( struct RTOp_RTOp* op )
00130 {
00131   op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
00132   op->obj_data  = NULL;
00133   op->vtbl      = NULL;
00134   return 0;
00135 }
00136 
00137 
00138 RTOp_value_type RTOp_ROp_sum_abs_val(RTOp_ReductTarget reduct_obj)
00139 {
00140   return *((RTOp_value_type*)reduct_obj);
00141 }
00142 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:11:01 2011 for MOOCHO (Single Doxygen Collection) by  doxygen 1.6.3