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

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