|
RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators Version of the Day
|
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 /* If the macro RTOp_USE_MPI is defined, then these */ 00032 /* declarations will be MPI compatible. If not then */ 00033 /* dummy MPI declarations will be used. */ 00034 /* */ 00035 00036 #ifndef REDUCT_TRANS_VECTOR_OPERATORS_H 00037 #define REDUCT_TRANS_VECTOR_OPERATORS_H 00038 00039 #include <stddef.h> 00040 #include <stdio.h> 00041 #include <assert.h> 00042 00043 #include "RTOp_MPI_config.h" 00044 00045 #ifdef __cplusplus 00046 extern "C" { 00047 #endif 00048 00049 #ifdef MPIAPI 00050 #define CALL_API MPIAPI 00051 #else 00052 #define CALL_API 00053 #endif 00054 00055 typedef Teuchos_Index RTOp_index_type; 00056 typedef double RTOp_value_type; 00057 typedef char RTOp_char_type; 00058 00169 00176 00178 typedef void* RTOp_ReductTarget; /*< The type for reduction target objects. */ 00179 #define RTOp_REDUCT_OBJ_NULL 0 /*< Value given to a a \c NULL reduction target object */ 00180 #define RTOp_NUM_DATA_TYPES 3 /*< Number of primative data types used in \c RTOp */ 00181 /* */ 00245 typedef void (CALL_API *RTOp_reduct_op_func_ptr_t) ( void *, void *, int *, RTOp_Datatype * ); 00246 00249 00250 /* */ 00251 #define RTOp_ERR_INVALID_USAGE -1 00252 /* */ 00253 #define RTOp_ERR_INVALID_NUM_VECS -2 00254 /* */ 00255 #define RTOp_ERR_INVALID_NUM_TARG_VECS -3 00256 /* */ 00257 #define RTOp_ERR_INCOMPATIBLE_VECS -5 00258 /* */ 00259 #define RTOp_SERVER_INCOMPATIBLE_OPS -6 00260 /* */ 00261 #define RTOp_SERVER_OP_NAME_TOO_LONG -7 00262 00263 /* */ 00284 struct RTOp_SubVector { 00285 /* Offset for the sub-vector into the global vector */ 00286 RTOp_index_type global_offset; 00287 /* Dimension of the sub-vector */ 00288 RTOp_index_type sub_dim; 00289 /* Array (size min{|<tt>value_stride*sub_nz</tt>|,1}) for the values in the vector */ 00290 const RTOp_value_type *values; 00291 /* Stride between elements in <tt>values[]</tt> */ 00292 ptrdiff_t values_stride; 00293 }; 00294 /* */ 00317 struct RTOp_MutableSubVector { 00318 /* Offset for the sub-vector into the global vector */ 00319 RTOp_index_type global_offset; 00320 /* Dimension of the sub-vector */ 00321 RTOp_index_type sub_dim; 00322 /* Array (size min{|<tt>value_stride*sub_dim</tt>|,1}) for the values in the vector */ 00323 RTOp_value_type *values; 00324 /* Stride between elements in <tt>values[]</tt> */ 00325 ptrdiff_t values_stride; 00326 }; 00327 /* */ 00330 void RTOp_sub_vector( 00331 RTOp_index_type global_offset, RTOp_index_type sub_dim 00332 ,const RTOp_value_type values[], ptrdiff_t values_stride 00333 ,struct RTOp_SubVector *sub_vec 00334 ); 00335 /* */ 00338 void RTOp_sub_vector_null( struct RTOp_SubVector *sub_vec ); 00339 /* */ 00342 void RTOp_mutable_sub_vector( 00343 RTOp_index_type global_offset, RTOp_index_type sub_dim 00344 ,RTOp_value_type values[], ptrdiff_t values_stride 00345 ,struct RTOp_MutableSubVector *sub_vec 00346 ); 00347 /* */ 00350 void RTOp_mutable_sub_vector_null( struct RTOp_MutableSubVector *sub_vec ); 00351 00394 00396 struct RTOp_RTOp; 00397 00398 /* */ 00411 int RTOp_get_op_name( 00412 const struct RTOp_RTOp* op 00413 ,const char** op_name 00414 ); 00415 00416 /* */ 00428 int RTOp_get_op_type_num_entries( 00429 const struct RTOp_RTOp* op 00430 ,int* num_values 00431 ,int* num_indexes 00432 ,int* num_chars 00433 ); 00434 00435 /* */ 00446 int RTOp_extract_op_state( 00447 const struct RTOp_RTOp *op 00448 ,int num_values 00449 ,RTOp_value_type value_data[] 00450 ,int num_indexes 00451 ,RTOp_index_type index_data[] 00452 ,int num_chars 00453 ,RTOp_char_type char_data[] 00454 ); 00455 /* */ 00469 int RTOp_load_op_state( 00470 int num_values 00471 ,const RTOp_value_type value_data[] 00472 ,int num_indexes 00473 ,const RTOp_index_type index_data[] 00474 ,int num_chars 00475 ,const RTOp_char_type char_data[] 00476 ,struct RTOp_RTOp* op 00477 ); 00478 /* */ 00489 int RTOp_free_op( struct RTOp_RTOp* op ); 00490 /* */ 00502 int RTOp_get_reduct_type_num_entries( 00503 const struct RTOp_RTOp *op 00504 ,int *num_values 00505 ,int *num_indexes 00506 ,int *num_chars 00507 ); 00508 /* */ 00528 int RTOp_reduct_obj_create( 00529 const struct RTOp_RTOp *op 00530 ,RTOp_ReductTarget *reduct_obj 00531 ); 00532 /* */ 00551 int RTOp_reduct_obj_reinit( 00552 const struct RTOp_RTOp *op 00553 ,RTOp_ReductTarget reduct_obj 00554 ); 00555 /* */ 00575 int RTOp_reduct_obj_free( const struct RTOp_RTOp* op 00576 , RTOp_ReductTarget* reduct_obj ); 00577 /* */ 00588 int RTOp_extract_reduct_obj_state( 00589 const struct RTOp_RTOp *op 00590 ,const RTOp_ReductTarget reduct_obj 00591 ,int num_values 00592 ,RTOp_value_type value_data[] 00593 ,int num_indexes 00594 ,RTOp_index_type index_data[] 00595 ,int num_chars 00596 ,RTOp_char_type char_data[] 00597 ); 00598 /* */ 00608 int RTOp_load_reduct_obj_state( 00609 const struct RTOp_RTOp *op 00610 ,int num_values 00611 ,const RTOp_value_type value_data[] 00612 ,int num_indexes 00613 ,const RTOp_index_type index_data[] 00614 ,int num_chars 00615 ,const RTOp_char_type char_data[] 00616 ,RTOp_ReductTarget reduct_obj 00617 ); 00618 /* */ 00626 int RTOp_coord_invariant( 00627 const struct RTOp_RTOp *op 00628 ,int *coord_invariant 00629 ); 00630 /* */ 00694 int RTOp_apply_op( 00695 const struct RTOp_RTOp *op 00696 ,const int num_vecs 00697 ,const struct RTOp_SubVector sub_vecs[] 00698 ,const int num_targ_vecs 00699 ,const struct RTOp_MutableSubVector targ_sub_vecs[] 00700 ,RTOp_ReductTarget reduct_obj 00701 ); 00702 /* */ 00727 int RTOp_reduce_reduct_objs( 00728 const struct RTOp_RTOp *op 00729 ,RTOp_ReductTarget in_reduct_obj 00730 ,RTOp_ReductTarget inout_reduct_obj 00731 ); 00732 /* */ 00755 int RTOp_get_reduct_op( 00756 const struct RTOp_RTOp *op 00757 ,RTOp_reduct_op_func_ptr_t *reduct_op_func_ptr 00758 ); 00759 00767 00769 struct RTOp_RTOp_vtbl_t; 00770 00771 /* */ 00785 struct RTOp_RTOp { 00786 /* Pointer to the object data for an instantiation */ 00787 void *obj_data; 00788 /* Pointer to the virtual function table */ 00789 const struct RTOp_RTOp_vtbl_t *vtbl; 00790 }; 00791 00792 /* */ 00804 struct RTOp_RTOp_vtbl_t { 00805 /* Pointer to the virtual function table for the operator object instance data. */ 00806 const struct RTOp_obj_type_vtbl_t *obj_data_vtbl; 00807 /* Pointer to the virtual function table for the manipulation of the reduction object. */ 00808 const struct RTOp_obj_type_vtbl_t *reduct_vtbl; 00809 /* */ 00812 const char* op_name; 00813 /* */ 00821 int (*reduct_obj_reinit)( 00822 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00823 ,RTOp_ReductTarget reduct_obj ); 00824 /* /// Called by <tt>RTOp_coord_invariant()</tt> */ 00825 /* int (*coord_invariant) ( */ 00826 /* const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data */ 00827 /* ,int *coord_invariant ); */ 00828 /* Called by <tt>RTOp_apply_op()</tt> */ 00829 int (*apply_op)( 00830 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00831 ,const int num_vecs, const struct RTOp_SubVector sub_vecs[] 00832 ,const int num_targ_vecs, const struct RTOp_MutableSubVector targ_sub_vecs[] 00833 ,RTOp_ReductTarget reduct_obj ); 00834 /* Called by <tt>RTOp_reduce_reduct_objs()</tt> */ 00835 int (*reduce_reduct_objs)( 00836 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00837 ,RTOp_ReductTarget in_reduct_obj, RTOp_ReductTarget inout_reduct_obj ); 00838 /* Called by <tt>RTOp_get_reduct_op()</tt> */ 00839 int (*get_reduct_op)( 00840 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00841 ,RTOp_reduct_op_func_ptr_t* reduct_op_func_ptr ); 00842 }; 00843 00844 /* */ 00859 struct RTOp_obj_type_vtbl_t { 00860 /* */ 00894 int (*get_obj_type_num_entries)( 00895 const struct RTOp_obj_type_vtbl_t *vtbl 00896 ,const void* instance_data 00897 ,int* num_values 00898 ,int* num_indexes 00899 ,int* num_chars 00900 ); 00901 /* */ 00928 int (*obj_create)( 00929 const struct RTOp_obj_type_vtbl_t *vtbl 00930 ,const void *instance_data 00931 ,void ** obj 00932 ); 00933 /* */ 00966 int (*obj_reinit)( 00967 const struct RTOp_obj_type_vtbl_t *vtbl 00968 ,const void *instance_data 00969 ,void *obj 00970 ); 00971 /* */ 01006 int (*obj_free)( 01007 const struct RTOp_obj_type_vtbl_t *vtbl 01008 ,const void *instance_data 01009 ,void **obj 01010 ); 01011 /* */ 01039 int (*extract_state)( 01040 const struct RTOp_obj_type_vtbl_t *vtbl 01041 ,const void *instance_data 01042 ,void *obj 01043 ,int num_values 01044 ,RTOp_value_type value_data[] 01045 ,int num_indexes 01046 ,RTOp_index_type index_data[] 01047 ,int num_chars 01048 ,RTOp_char_type char_data[] 01049 ); 01050 /* */ 01084 int (*load_state)( 01085 const struct RTOp_obj_type_vtbl_t *vtbl 01086 ,const void *instance_data 01087 ,int num_values 01088 ,const RTOp_value_type value_data[] 01089 ,int num_indexes 01090 ,const RTOp_index_type index_data[] 01091 ,int num_chars 01092 ,const RTOp_char_type char_data[] 01093 ,void **obj 01094 ); 01095 }; 01096 01121 01123 /* */ 01167 int RTOp_Server_add_op_name_vtbl( 01168 const char op_class_name[] 01169 ,const struct RTOp_RTOp_vtbl_t *op_class_vtbl 01170 ); 01171 01172 /* */ 01195 int RTOp_Server_lookup_op_name( 01196 const struct RTOp_RTOp_vtbl_t *op_class_vtbl 01197 ,char op_class_name[] 01198 ); 01199 01200 /* */ 01225 int RTOp_Server_construct_op( 01226 const char op_class_name[] 01227 ,int num_values 01228 ,const RTOp_value_type value_data[] 01229 ,int num_indexes 01230 ,const RTOp_index_type index_data[] 01231 ,int num_chars 01232 ,const RTOp_char_type char_data[] 01233 ,struct RTOp_RTOp *op 01234 ); 01235 01236 /* */ 01240 void RTOp_Server_dump( FILE* file ); 01241 01244 01246 #ifdef __cplusplus 01247 } 01248 #endif 01249 01250 #endif /* REDUCT_TRANS_VECTOR_OPERATORS_H */
1.7.4