RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators Version of the Day
RTOp_get_reduct_op.hpp
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 #ifndef RTOP_GET_REDUCT_OP_H
00032 #define RTOP_GET_REDUCT_OP_H
00033 
00034 #define INSERT_GET_REDUCT_OP_FUNCS(                                                                                   \
00035     num_values,num_indexes,num_chars,reduct_obj_t,reduce_reduct_obj,targ_load_state,targ_extract_state                \
00036     ,external_reduct_op,get_reduct_op                                                                                 \
00037     )                                                                                                                 \
00038 static void CALL_API external_reduct_op( void* in_targ_array, void* inout_targ_array                                           \
00039   , int* len, RTOp_Datatype* datatype )                                                                             \
00040 {                                                                                                                     \
00041   struct reduct_obj_t                                                                                               \
00042     in_obj, *in_obj_p = &in_obj, inout_obj, *inout_obj_p = &inout_obj;                                            \
00043     const int                                                                                                         \
00044         values_off  = 3*sizeof(RTOp_value_type),                                                                      \
00045         indexes_off = values_off + num_values*sizeof(RTOp_value_type),                                                \
00046         chars_off   = indexes_off + num_indexes*sizeof(RTOp_index_type);                                              \
00047   const int size_obj = chars_off + (num_chars)*sizeof(RTOp_index_type);                                             \
00048   char                                                                                                              \
00049      *in_array    = in_targ_array,                                                                                 \
00050     *inout_array = inout_targ_array;                                                                              \
00051   int i;                                                                                                            \
00052   for( i = 0; i < *len; ++i, in_array += size_obj, inout_array += size_obj ) {                                      \
00053     targ_load_state(                                                                                              \
00054       NULL, NULL                                                                                                \
00055       ,num_values,  num_values  ? (RTOp_value_type*)(in_array + values_off) : NULL                              \
00056       ,num_indexes, num_indexes ? (RTOp_index_type*)(in_array + values_off) : NULL                              \
00057       ,num_chars,   num_chars   ? (RTOp_char_type*) (in_array + values_off) : NULL                              \
00058       ,(void**)&in_obj_p );                                                                                     \
00059     targ_load_state(                                                                                              \
00060       NULL, NULL                                                                                                \
00061       ,num_values,  num_values  ? (RTOp_value_type*)(inout_array + values_off) : NULL                           \
00062       ,num_indexes, num_indexes ? (RTOp_index_type*)(inout_array + values_off) : NULL                           \
00063       ,num_chars,   num_chars   ? (RTOp_char_type*) (inout_array + values_off) : NULL                           \
00064       ,(void**)&inout_obj_p );                                                                                  \
00065     reduce_reduct_objs( NULL, NULL, &in_obj, &inout_obj );                                                        \
00066     targ_extract_state(                                                                                           \
00067       NULL, NULL, &inout_obj                                                                                    \
00068       ,num_values,  num_values  ? (RTOp_value_type*)(inout_array + values_off) : NULL                           \
00069       ,num_indexes, num_indexes ? (RTOp_index_type*)(inout_array + values_off) : NULL                           \
00070       ,num_chars,   num_chars   ? (RTOp_char_type*) (inout_array + values_off) : NULL                           \
00071       );                                                                                                        \
00072   }                                                                                                                 \
00073 }                                                                                                                     \
00074 static int get_reduct_op(                                                                                             \
00075   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data                                                         \
00076   , RTOp_reduct_op_func_ptr_t* reduct_op_func_ptr )                                                                 \
00077 {                                                                                                                     \
00078   *reduct_op_func_ptr = external_reduct_op;                                                                         \
00079   return 0;                                                                                                         \
00080 }
00081 
00082 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends