RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators Version of the Day
RTOp_TOp_assign_vectors.c
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_assign_vectors.h"
00032 #include "RTOp_obj_null_vtbl.h"
00033 
00034 /* Implementation functions for RTOp_RTOp */
00035 
00036 static int RTOp_TOp_assign_vectors_apply_op(
00037   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00038   , const int num_vecs, const struct RTOp_SubVector vecs[]
00039   , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
00040   , RTOp_ReductTarget targ_obj )
00041 {
00042   RTOp_index_type        z_sub_dim;
00043   RTOp_value_type        *z_val = NULL;
00044   ptrdiff_t              z_val_s;
00045   RTOp_index_type        v0_sub_dim;
00046   const RTOp_value_type  *v0_val;
00047   ptrdiff_t              v0_val_s;
00048 
00049   register RTOp_index_type k;
00050   RTOp_value_type *z_val_tmp = NULL;
00051 #ifdef RTOp_DEBUG
00052   RTOp_index_type i;
00053 #endif
00054 
00055   /* */
00056   /* Validate the input */
00057   /* */
00058   if( num_vecs != 1 || vecs == NULL )
00059     return RTOp_ERR_INVALID_NUM_VECS;
00060   if( num_targ_vecs != 1 || targ_vecs == NULL )
00061     return RTOp_ERR_INVALID_NUM_TARG_VECS;
00062   if( targ_vecs[0].sub_dim != vecs[0].sub_dim )
00063     return RTOp_ERR_INCOMPATIBLE_VECS;
00064 
00065   /* */
00066   /* Get pointers to data */
00067   /* */
00068 
00069   /* z */
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   /* v0 */
00075   v0_sub_dim     = vecs[0].sub_dim;
00076   v0_val         = vecs[0].values;
00077   v0_val_s       = vecs[0].values_stride;
00078 
00079   z_val_tmp = z_val;
00080 
00081   /* */
00082   /* Assign the elements */
00083   /* */
00084 
00085   if( z_val_s == 1 && v0_val_s == 1 ) {
00086     /* Slightly faster loop for unit stride vectors */
00087     for( k = 0; k < z_sub_dim; ++k )
00088       *z_val++ = *v0_val++;
00089   }
00090   else {
00091     /* More general implementation for one or both non-unit strides */
00092     for( k = 0; k < z_sub_dim; ++k, z_val += z_val_s, v0_val += v0_val_s )
00093       *z_val = *v0_val;
00094   }
00095 
00096   return 0; /* success? */
00097 }
00098 
00099 /* Virtual function table */
00100 const struct RTOp_RTOp_vtbl_t RTOp_TOp_assign_vectors_vtbl =
00101 {
00102   &RTOp_obj_null_vtbl  /* Use a null object for instance data */
00103   ,&RTOp_obj_null_vtbl /* use null type for target object */
00104   ,"TOp_assign_vectors"
00105   ,NULL /* use default from reduct_vtbl */
00106   ,RTOp_TOp_assign_vectors_apply_op
00107   ,NULL
00108   ,NULL
00109 };
00110 
00111 /* Class specific functions */
00112 
00113 int RTOp_TOp_assign_vectors_construct( struct RTOp_RTOp* op )
00114 {
00115   op->obj_data  = NULL;
00116   op->vtbl      = &RTOp_TOp_assign_vectors_vtbl;
00117   return 0; /* success? */
00118 }
00119 
00120 int RTOp_TOp_assign_vectors_destroy( struct RTOp_RTOp* op )
00121 {
00122   op->obj_data  = NULL;
00123   op->vtbl      = NULL;
00124   return 0; /* success? */
00125 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends