RTOp_apply_op_serial.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 /* RTOp_apply_op_serial.c */
00033 
00034 #include "RTOp_apply_op_serial.h"
00035 
00036 #include <stdlib.h>
00037 
00038 int RTOp_apply_op_serial(
00039   RTOp_index_type full_dim
00040   ,const int      num_vecs,  const RTOp_value_type*      vec_ptrs[],  const ptrdiff_t      vec_strides[]
00041   ,const int num_targ_vecs,  RTOp_value_type*       targ_vec_ptrs[],  const ptrdiff_t targ_vec_strides[]
00042   ,const RTOp_index_type first_ele_in, const RTOp_index_type sub_dim_in, const RTOp_index_type global_offset_in
00043   ,const struct RTOp_RTOp* op
00044   ,RTOp_ReductTarget reduct_obj
00045   )
00046 {
00047   int                          err            = 0;
00048   RTOp_index_type              sub_dim        = 0;
00049   struct RTOp_SubVector        *sub_vecs      = NULL;
00050   struct RTOp_MutableSubVector *targ_sub_vecs = NULL;
00051   int                          k;
00052   /* Sort out the input and get the number of vector elements to operator over */
00053 #ifdef RTOp_DEBUG
00054   assert( num_vecs || num_targ_vecs );
00055   if(num_vecs)
00056     assert( vec_ptrs != NULL );
00057   if(num_targ_vecs)
00058     assert( targ_vec_ptrs != NULL );
00059   assert( 0 <= sub_dim_in && sub_dim_in <= full_dim );
00060 #endif
00061   sub_dim = sub_dim_in ? sub_dim_in : full_dim - (first_ele_in - 1); /* Dimension of logical vectors */
00062   /* Create the sub-vector data structures */
00063   if(num_vecs) {
00064     sub_vecs = malloc( sizeof(struct RTOp_SubVector) * num_vecs );
00065     for( k = 0; k < num_vecs; ++k ) {
00066 #ifdef RTOp_DEBUG
00067       assert( vec_ptrs[k] != NULL );
00068 #endif
00069       RTOp_sub_vector(
00070         global_offset_in
00071         ,sub_dim
00072         ,vec_ptrs[k] + (first_ele_in -1) * vec_strides[k]
00073         ,vec_strides[k]
00074         ,&sub_vecs[k]
00075         );
00076     }
00077   }
00078   if(num_targ_vecs) {
00079     targ_sub_vecs = malloc( sizeof(struct RTOp_MutableSubVector) * num_targ_vecs );
00080     for( k = 0; k < num_targ_vecs; ++k ) {
00081 #ifdef RTOp_DEBUG
00082       assert( targ_vec_ptrs[k] != NULL );
00083 #endif
00084       RTOp_mutable_sub_vector(
00085         global_offset_in
00086         ,sub_dim
00087         ,targ_vec_ptrs[k] + (first_ele_in -1) * targ_vec_strides[k]
00088         ,targ_vec_strides[k]
00089         ,&targ_sub_vecs[k]
00090         );
00091     }
00092   }
00093   /* Apply the reduction/transformation operator in one chunk */
00094   err = RTOp_apply_op( op, num_vecs, sub_vecs, num_targ_vecs, targ_sub_vecs, reduct_obj );
00095   /* Free the sub-vector data structures */
00096   if(      sub_vecs ) free(      sub_vecs );
00097   if( targ_sub_vecs ) free( targ_sub_vecs );
00098 
00099   return err;  /* This could be an error code! */
00100 }

Generated on Wed May 12 21:52:32 2010 for MOOCHO (Single Doxygen Collection) by  doxygen 1.4.7