RTOp_TOp_set_ele.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 "RTOp_TOp_set_ele.h"
00032 #include "RTOp_obj_value_index_vtbl.h"
00033 #include "RTOp_obj_null_vtbl.h"
00034 
00035 /* Implementation functions for RTOp_RTOp */
00036 
00037 static int RTOp_TOp_set_ele_apply_op(
00038   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00039   , const int num_vecs, const struct RTOp_SubVector vecs[]
00040   , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
00041   , RTOp_ReductTarget targ_obj )
00042 {
00043   const struct RTOp_value_index_type  *val_ind  = NULL;
00044   RTOp_value_type                     alpha;
00045   RTOp_value_type                     i;
00046   RTOp_index_type  global_offset;
00047   RTOp_index_type  z_sub_dim;
00048   RTOp_value_type  *z_val = NULL;
00049   ptrdiff_t        z_val_s;
00050 
00051   /* */
00052   /* Validate the input */
00053   /* */
00054   if( num_vecs != 0 || vecs != NULL )
00055     return RTOp_ERR_INVALID_NUM_VECS;
00056   if( num_targ_vecs != 1 || targ_vecs == NULL )
00057     return RTOp_ERR_INVALID_NUM_TARG_VECS;
00058 
00059   /* */
00060   /* Get pointers to data */
00061   /* */
00062 
00063   /* alpha, i */
00064   val_ind  = (const struct RTOp_value_index_type*)obj_data;
00065   alpha    = val_ind->value;
00066   i        = val_ind->index;
00067 
00068   /* z */
00069   global_offset = targ_vecs[0].global_offset;
00070   z_sub_dim     = targ_vecs[0].sub_dim;
00071   z_val         = targ_vecs[0].values;
00072   z_val_s       = targ_vecs[0].values_stride;
00073 
00074   /* */
00075   /* Set the element? */
00076   /* */
00077 
00078   if( i < global_offset + 1 || global_offset + z_sub_dim < i )
00079     return 0; /* The element we are looking for is not here. */
00080 
00081   /* It is not hard to find the element */
00082   z_val[(ptrdiff_t)(z_val_s * (i-global_offset-1))] = alpha;
00083 
00084   return 0; /* success? */
00085 }
00086 
00087 /* Virtual function table */
00088 const struct RTOp_RTOp_vtbl_t RTOp_TOp_set_ele_vtbl =
00089 {
00090   &RTOp_obj_value_index_vtbl
00091   ,&RTOp_obj_null_vtbl /* use null type for reduction target object */
00092   ,"TOp_set_ele"
00093   ,NULL /* use default from reduct_vtbl */
00094   ,RTOp_TOp_set_ele_apply_op
00095   ,NULL
00096   ,NULL
00097 };
00098 
00099 
00100 /* Class specific functions */
00101 
00102 int RTOp_TOp_set_ele_construct( RTOp_index_type i, RTOp_value_type alpha
00103   , struct RTOp_RTOp* op )
00104 {
00105   struct RTOp_value_index_type *val_ind = NULL;
00106   op->vtbl = &RTOp_TOp_set_ele_vtbl;
00107   op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
00108   val_ind = (struct RTOp_value_index_type*)op->obj_data;
00109   val_ind->value  = alpha;
00110   val_ind->index  = i;
00111   return 0; /* success? */
00112 }
00113 
00114 int RTOp_TOp_set_ele_destroy( struct RTOp_RTOp* op )
00115 {
00116   op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
00117   op->vtbl      = NULL;
00118   return 0; /* success? */
00119 }
00120 
00121 int RTOp_TOp_set_ele_set_i_alpha( RTOp_index_type i, RTOp_value_type alpha
00122   , struct RTOp_RTOp* op )
00123 {
00124   struct RTOp_value_index_type
00125     *val_ind = (struct RTOp_value_index_type*)op->obj_data;
00126   val_ind->value  = alpha;
00127   val_ind->index  = i;
00128   return 0; /* success? */
00129 }

Generated on Tue Jul 13 09:30:54 2010 for MOOCHO (Single Doxygen Collection) by  doxygen 1.4.7