|
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 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00039 // 00040 // *********************************************************************** 00041 // @HEADER 00042 */ 00043 00044 /* If the macro RTOp_USE_MPI is defined, then these */ 00045 /* declarations will be MPI compatible. If not then */ 00046 /* dummy MPI declarations will be used. */ 00047 /* */ 00048 00049 #ifndef REDUCT_TRANS_VECTOR_OPERATORS_H 00050 #define REDUCT_TRANS_VECTOR_OPERATORS_H 00051 00052 #include <stddef.h> 00053 #include <stdio.h> 00054 #include <assert.h> 00055 00056 #include "RTOp_MPI_config.h" 00057 00058 #ifdef __cplusplus 00059 extern "C" { 00060 #endif 00061 00062 #ifdef MPIAPI 00063 #define CALL_API MPIAPI 00064 #else 00065 #define CALL_API 00066 #endif 00067 00068 typedef Teuchos_Ordinal RTOp_index_type; 00069 typedef double RTOp_value_type; 00070 typedef char RTOp_char_type; 00071 00182 00189 00191 typedef void* RTOp_ReductTarget; /*< The type for reduction target objects. */ 00192 #define RTOp_REDUCT_OBJ_NULL 0 /*< Value given to a a \c NULL reduction target object */ 00193 #define RTOp_NUM_DATA_TYPES 3 /*< Number of primative data types used in \c RTOp */ 00194 /* */ 00258 typedef void (CALL_API *RTOp_reduct_op_func_ptr_t) ( void *, void *, int *, RTOp_Datatype * ); 00259 00262 00263 /* */ 00264 #define RTOp_ERR_INVALID_USAGE -1 00265 /* */ 00266 #define RTOp_ERR_INVALID_NUM_VECS -2 00267 /* */ 00268 #define RTOp_ERR_INVALID_NUM_TARG_VECS -3 00269 /* */ 00270 #define RTOp_ERR_INCOMPATIBLE_VECS -5 00271 /* */ 00272 #define RTOp_SERVER_INCOMPATIBLE_OPS -6 00273 /* */ 00274 #define RTOp_SERVER_OP_NAME_TOO_LONG -7 00275 00276 /* */ 00297 struct RTOp_SubVector { 00298 /* Offset for the sub-vector into the global vector */ 00299 RTOp_index_type global_offset; 00300 /* Dimension of the sub-vector */ 00301 RTOp_index_type sub_dim; 00302 /* Array (size min{|<tt>value_stride*sub_nz</tt>|,1}) for the values in the vector */ 00303 const RTOp_value_type *values; 00304 /* Stride between elements in <tt>values[]</tt> */ 00305 ptrdiff_t values_stride; 00306 }; 00307 /* */ 00330 struct RTOp_MutableSubVector { 00331 /* Offset for the sub-vector into the global vector */ 00332 RTOp_index_type global_offset; 00333 /* Dimension of the sub-vector */ 00334 RTOp_index_type sub_dim; 00335 /* Array (size min{|<tt>value_stride*sub_dim</tt>|,1}) for the values in the vector */ 00336 RTOp_value_type *values; 00337 /* Stride between elements in <tt>values[]</tt> */ 00338 ptrdiff_t values_stride; 00339 }; 00340 /* */ 00343 void RTOp_sub_vector( 00344 RTOp_index_type global_offset, RTOp_index_type sub_dim 00345 ,const RTOp_value_type values[], ptrdiff_t values_stride 00346 ,struct RTOp_SubVector *sub_vec 00347 ); 00348 /* */ 00351 void RTOp_sub_vector_null( struct RTOp_SubVector *sub_vec ); 00352 /* */ 00355 void RTOp_mutable_sub_vector( 00356 RTOp_index_type global_offset, RTOp_index_type sub_dim 00357 ,RTOp_value_type values[], ptrdiff_t values_stride 00358 ,struct RTOp_MutableSubVector *sub_vec 00359 ); 00360 /* */ 00363 void RTOp_mutable_sub_vector_null( struct RTOp_MutableSubVector *sub_vec ); 00364 00407 00409 struct RTOp_RTOp; 00410 00411 /* */ 00424 int RTOp_get_op_name( 00425 const struct RTOp_RTOp* op 00426 ,const char** op_name 00427 ); 00428 00429 /* */ 00441 int RTOp_get_op_type_num_entries( 00442 const struct RTOp_RTOp* op 00443 ,int* num_values 00444 ,int* num_indexes 00445 ,int* num_chars 00446 ); 00447 00448 /* */ 00459 int RTOp_extract_op_state( 00460 const struct RTOp_RTOp *op 00461 ,int num_values 00462 ,RTOp_value_type value_data[] 00463 ,int num_indexes 00464 ,RTOp_index_type index_data[] 00465 ,int num_chars 00466 ,RTOp_char_type char_data[] 00467 ); 00468 /* */ 00482 int RTOp_load_op_state( 00483 int num_values 00484 ,const RTOp_value_type value_data[] 00485 ,int num_indexes 00486 ,const RTOp_index_type index_data[] 00487 ,int num_chars 00488 ,const RTOp_char_type char_data[] 00489 ,struct RTOp_RTOp* op 00490 ); 00491 /* */ 00502 int RTOp_free_op( struct RTOp_RTOp* op ); 00503 /* */ 00515 int RTOp_get_reduct_type_num_entries( 00516 const struct RTOp_RTOp *op 00517 ,int *num_values 00518 ,int *num_indexes 00519 ,int *num_chars 00520 ); 00521 /* */ 00541 int RTOp_reduct_obj_create( 00542 const struct RTOp_RTOp *op 00543 ,RTOp_ReductTarget *reduct_obj 00544 ); 00545 /* */ 00564 int RTOp_reduct_obj_reinit( 00565 const struct RTOp_RTOp *op 00566 ,RTOp_ReductTarget reduct_obj 00567 ); 00568 /* */ 00588 int RTOp_reduct_obj_free( const struct RTOp_RTOp* op 00589 , RTOp_ReductTarget* reduct_obj ); 00590 /* */ 00601 int RTOp_extract_reduct_obj_state( 00602 const struct RTOp_RTOp *op 00603 ,const RTOp_ReductTarget reduct_obj 00604 ,int num_values 00605 ,RTOp_value_type value_data[] 00606 ,int num_indexes 00607 ,RTOp_index_type index_data[] 00608 ,int num_chars 00609 ,RTOp_char_type char_data[] 00610 ); 00611 /* */ 00621 int RTOp_load_reduct_obj_state( 00622 const struct RTOp_RTOp *op 00623 ,int num_values 00624 ,const RTOp_value_type value_data[] 00625 ,int num_indexes 00626 ,const RTOp_index_type index_data[] 00627 ,int num_chars 00628 ,const RTOp_char_type char_data[] 00629 ,RTOp_ReductTarget reduct_obj 00630 ); 00631 /* */ 00639 int RTOp_coord_invariant( 00640 const struct RTOp_RTOp *op 00641 ,int *coord_invariant 00642 ); 00643 /* */ 00707 int RTOp_apply_op( 00708 const struct RTOp_RTOp *op 00709 ,const int num_vecs 00710 ,const struct RTOp_SubVector sub_vecs[] 00711 ,const int num_targ_vecs 00712 ,const struct RTOp_MutableSubVector targ_sub_vecs[] 00713 ,RTOp_ReductTarget reduct_obj 00714 ); 00715 /* */ 00740 int RTOp_reduce_reduct_objs( 00741 const struct RTOp_RTOp *op 00742 ,RTOp_ReductTarget in_reduct_obj 00743 ,RTOp_ReductTarget inout_reduct_obj 00744 ); 00745 /* */ 00768 int RTOp_get_reduct_op( 00769 const struct RTOp_RTOp *op 00770 ,RTOp_reduct_op_func_ptr_t *reduct_op_func_ptr 00771 ); 00772 00780 00782 struct RTOp_RTOp_vtbl_t; 00783 00784 /* */ 00798 struct RTOp_RTOp { 00799 /* Pointer to the object data for an instantiation */ 00800 void *obj_data; 00801 /* Pointer to the virtual function table */ 00802 const struct RTOp_RTOp_vtbl_t *vtbl; 00803 }; 00804 00805 /* */ 00817 struct RTOp_RTOp_vtbl_t { 00818 /* Pointer to the virtual function table for the operator object instance data. */ 00819 const struct RTOp_obj_type_vtbl_t *obj_data_vtbl; 00820 /* Pointer to the virtual function table for the manipulation of the reduction object. */ 00821 const struct RTOp_obj_type_vtbl_t *reduct_vtbl; 00822 /* */ 00825 const char* op_name; 00826 /* */ 00834 int (*reduct_obj_reinit)( 00835 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00836 ,RTOp_ReductTarget reduct_obj ); 00837 /* /// Called by <tt>RTOp_coord_invariant()</tt> */ 00838 /* int (*coord_invariant) ( */ 00839 /* const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data */ 00840 /* ,int *coord_invariant ); */ 00841 /* Called by <tt>RTOp_apply_op()</tt> */ 00842 int (*apply_op)( 00843 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00844 ,const int num_vecs, const struct RTOp_SubVector sub_vecs[] 00845 ,const int num_targ_vecs, const struct RTOp_MutableSubVector targ_sub_vecs[] 00846 ,RTOp_ReductTarget reduct_obj ); 00847 /* Called by <tt>RTOp_reduce_reduct_objs()</tt> */ 00848 int (*reduce_reduct_objs)( 00849 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00850 ,RTOp_ReductTarget in_reduct_obj, RTOp_ReductTarget inout_reduct_obj ); 00851 /* Called by <tt>RTOp_get_reduct_op()</tt> */ 00852 int (*get_reduct_op)( 00853 const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data 00854 ,RTOp_reduct_op_func_ptr_t* reduct_op_func_ptr ); 00855 }; 00856 00857 /* */ 00872 struct RTOp_obj_type_vtbl_t { 00873 /* */ 00907 int (*get_obj_type_num_entries)( 00908 const struct RTOp_obj_type_vtbl_t *vtbl 00909 ,const void* instance_data 00910 ,int* num_values 00911 ,int* num_indexes 00912 ,int* num_chars 00913 ); 00914 /* */ 00941 int (*obj_create)( 00942 const struct RTOp_obj_type_vtbl_t *vtbl 00943 ,const void *instance_data 00944 ,void ** obj 00945 ); 00946 /* */ 00979 int (*obj_reinit)( 00980 const struct RTOp_obj_type_vtbl_t *vtbl 00981 ,const void *instance_data 00982 ,void *obj 00983 ); 00984 /* */ 01019 int (*obj_free)( 01020 const struct RTOp_obj_type_vtbl_t *vtbl 01021 ,const void *instance_data 01022 ,void **obj 01023 ); 01024 /* */ 01052 int (*extract_state)( 01053 const struct RTOp_obj_type_vtbl_t *vtbl 01054 ,const void *instance_data 01055 ,void *obj 01056 ,int num_values 01057 ,RTOp_value_type value_data[] 01058 ,int num_indexes 01059 ,RTOp_index_type index_data[] 01060 ,int num_chars 01061 ,RTOp_char_type char_data[] 01062 ); 01063 /* */ 01097 int (*load_state)( 01098 const struct RTOp_obj_type_vtbl_t *vtbl 01099 ,const void *instance_data 01100 ,int num_values 01101 ,const RTOp_value_type value_data[] 01102 ,int num_indexes 01103 ,const RTOp_index_type index_data[] 01104 ,int num_chars 01105 ,const RTOp_char_type char_data[] 01106 ,void **obj 01107 ); 01108 }; 01109 01134 01136 /* */ 01180 int RTOp_Server_add_op_name_vtbl( 01181 const char op_class_name[] 01182 ,const struct RTOp_RTOp_vtbl_t *op_class_vtbl 01183 ); 01184 01185 /* */ 01208 int RTOp_Server_lookup_op_name( 01209 const struct RTOp_RTOp_vtbl_t *op_class_vtbl 01210 ,char op_class_name[] 01211 ); 01212 01213 /* */ 01238 int RTOp_Server_construct_op( 01239 const char op_class_name[] 01240 ,int num_values 01241 ,const RTOp_value_type value_data[] 01242 ,int num_indexes 01243 ,const RTOp_index_type index_data[] 01244 ,int num_chars 01245 ,const RTOp_char_type char_data[] 01246 ,struct RTOp_RTOp *op 01247 ); 01248 01249 /* */ 01253 void RTOp_Server_dump( FILE* file ); 01254 01257 01259 #ifdef __cplusplus 01260 } 01261 #endif 01262 01263 #endif /* REDUCT_TRANS_VECTOR_OPERATORS_H */
1.7.6.1