RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RTOp.h
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
6 // Copyright (2003) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 /* If the macro RTOp_USE_MPI is defined, then these */
45 /* declarations will be MPI compatible. If not then */
46 /* dummy MPI declarations will be used. */
47 /* */
48 
49 #ifndef REDUCT_TRANS_VECTOR_OPERATORS_H
50 #define REDUCT_TRANS_VECTOR_OPERATORS_H
51 
52 #include <stddef.h>
53 #include <stdio.h>
54 #include <assert.h>
55 
56 #include "RTOp_MPI_config.h"
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 #ifdef MPIAPI
63 #define CALL_API MPIAPI
64 #else
65 #define CALL_API
66 #endif
67 
68 typedef Teuchos_Ordinal RTOp_index_type;
69 typedef double RTOp_value_type;
70 typedef char RTOp_char_type;
71 
182 
189 
191 typedef void* RTOp_ReductTarget; /*< The type for reduction target objects. */
192 #define RTOp_REDUCT_OBJ_NULL 0 /*< Value given to a a \c NULL reduction target object */
193 #define RTOp_NUM_DATA_TYPES 3 /*< Number of primative data types used in \c RTOp */
194 /* */
258 typedef void (CALL_API *RTOp_reduct_op_func_ptr_t) ( void *, void *, int *, RTOp_Datatype * );
259 
262 
263 /* */
264 #define RTOp_ERR_INVALID_USAGE -1
265 /* */
266 #define RTOp_ERR_INVALID_NUM_VECS -2
267 /* */
268 #define RTOp_ERR_INVALID_NUM_TARG_VECS -3
269 /* */
270 #define RTOp_ERR_INCOMPATIBLE_VECS -5
271 /* */
272 #define RTOp_SERVER_INCOMPATIBLE_OPS -6
273 /* */
274 #define RTOp_SERVER_OP_NAME_TOO_LONG -7
275 
276 /* */
298  /* Offset for the sub-vector into the global vector */
299  RTOp_index_type global_offset;
300  /* Dimension of the sub-vector */
301  RTOp_index_type sub_dim;
302  /* Array (size min{|<tt>value_stride*sub_nz</tt>|,1}) for the values in the vector */
303  const RTOp_value_type *values;
304  /* Stride between elements in <tt>values[]</tt> */
305  ptrdiff_t values_stride;
306 };
307 /* */
331  /* Offset for the sub-vector into the global vector */
332  RTOp_index_type global_offset;
333  /* Dimension of the sub-vector */
334  RTOp_index_type sub_dim;
335  /* Array (size min{|<tt>value_stride*sub_dim</tt>|,1}) for the values in the vector */
336  RTOp_value_type *values;
337  /* Stride between elements in <tt>values[]</tt> */
338  ptrdiff_t values_stride;
339 };
340 /* */
343 void RTOp_sub_vector(
344  RTOp_index_type global_offset, RTOp_index_type sub_dim
345  ,const RTOp_value_type values[], ptrdiff_t values_stride
346  ,struct RTOp_SubVector *sub_vec
347  );
348 /* */
351 void RTOp_sub_vector_null( struct RTOp_SubVector *sub_vec );
352 /* */
356  RTOp_index_type global_offset, RTOp_index_type sub_dim
357  ,RTOp_value_type values[], ptrdiff_t values_stride
358  ,struct RTOp_MutableSubVector *sub_vec
359  );
360 /* */
364 
407 
409 struct RTOp_RTOp;
410 
411 /* */
424 int RTOp_get_op_name(
425  const struct RTOp_RTOp* op
426  ,const char** op_name
427  );
428 
429 /* */
442  const struct RTOp_RTOp* op
443  ,int* num_values
444  ,int* num_indexes
445  ,int* num_chars
446  );
447 
448 /* */
460  const struct RTOp_RTOp *op
461  ,int num_values
462  ,RTOp_value_type value_data[]
463  ,int num_indexes
464  ,RTOp_index_type index_data[]
465  ,int num_chars
466  ,RTOp_char_type char_data[]
467  );
468 /* */
483  int num_values
484  ,const RTOp_value_type value_data[]
485  ,int num_indexes
486  ,const RTOp_index_type index_data[]
487  ,int num_chars
488  ,const RTOp_char_type char_data[]
489  ,struct RTOp_RTOp* op
490  );
491 /* */
502 int RTOp_free_op( struct RTOp_RTOp* op );
503 /* */
516  const struct RTOp_RTOp *op
517  ,int *num_values
518  ,int *num_indexes
519  ,int *num_chars
520  );
521 /* */
542  const struct RTOp_RTOp *op
543  ,RTOp_ReductTarget *reduct_obj
544  );
545 /* */
565  const struct RTOp_RTOp *op
566  ,RTOp_ReductTarget reduct_obj
567  );
568 /* */
588 int RTOp_reduct_obj_free( const struct RTOp_RTOp* op
589  , RTOp_ReductTarget* reduct_obj );
590 /* */
602  const struct RTOp_RTOp *op
603  ,const RTOp_ReductTarget reduct_obj
604  ,int num_values
605  ,RTOp_value_type value_data[]
606  ,int num_indexes
607  ,RTOp_index_type index_data[]
608  ,int num_chars
609  ,RTOp_char_type char_data[]
610  );
611 /* */
622  const struct RTOp_RTOp *op
623  ,int num_values
624  ,const RTOp_value_type value_data[]
625  ,int num_indexes
626  ,const RTOp_index_type index_data[]
627  ,int num_chars
628  ,const RTOp_char_type char_data[]
629  ,RTOp_ReductTarget reduct_obj
630  );
631 /* */
640  const struct RTOp_RTOp *op
641  ,int *coord_invariant
642  );
643 /* */
707 int RTOp_apply_op(
708  const struct RTOp_RTOp *op
709  ,const int num_vecs
710  ,const struct RTOp_SubVector sub_vecs[]
711  ,const int num_targ_vecs
712  ,const struct RTOp_MutableSubVector targ_sub_vecs[]
713  ,RTOp_ReductTarget reduct_obj
714  );
715 /* */
741  const struct RTOp_RTOp *op
742  ,RTOp_ReductTarget in_reduct_obj
743  ,RTOp_ReductTarget inout_reduct_obj
744  );
745 /* */
769  const struct RTOp_RTOp *op
770  ,RTOp_reduct_op_func_ptr_t *reduct_op_func_ptr
771  );
772 
780 
782 struct RTOp_RTOp_vtbl_t;
783 
784 /* */
798 struct RTOp_RTOp {
799  /* Pointer to the object data for an instantiation */
800  void *obj_data;
801  /* Pointer to the virtual function table */
802  const struct RTOp_RTOp_vtbl_t *vtbl;
803 };
804 
805 /* */
818  /* Pointer to the virtual function table for the operator object instance data. */
819  const struct RTOp_obj_type_vtbl_t *obj_data_vtbl;
820  /* Pointer to the virtual function table for the manipulation of the reduction object. */
821  const struct RTOp_obj_type_vtbl_t *reduct_vtbl;
822  /* */
825  const char* op_name;
826  /* */
835  const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
836  ,RTOp_ReductTarget reduct_obj );
837 /* /// Called by <tt>RTOp_coord_invariant()</tt> */
838 /* int (*coord_invariant) ( */
839 /* const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data */
840 /* ,int *coord_invariant ); */
841  /* Called by <tt>RTOp_apply_op()</tt> */
842  int (*apply_op)(
843  const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
844  ,const int num_vecs, const struct RTOp_SubVector sub_vecs[]
845  ,const int num_targ_vecs, const struct RTOp_MutableSubVector targ_sub_vecs[]
846  ,RTOp_ReductTarget reduct_obj );
847  /* Called by <tt>RTOp_reduce_reduct_objs()</tt> */
848  int (*reduce_reduct_objs)(
849  const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
850  ,RTOp_ReductTarget in_reduct_obj, RTOp_ReductTarget inout_reduct_obj );
851  /* Called by <tt>RTOp_get_reduct_op()</tt> */
852  int (*get_reduct_op)(
853  const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
854  ,RTOp_reduct_op_func_ptr_t* reduct_op_func_ptr );
855 };
856 
857 /* */
873  /* */
908  const struct RTOp_obj_type_vtbl_t *vtbl
909  ,const void* instance_data
910  ,int* num_values
911  ,int* num_indexes
912  ,int* num_chars
913  );
914  /* */
941  int (*obj_create)(
942  const struct RTOp_obj_type_vtbl_t *vtbl
943  ,const void *instance_data
944  ,void ** obj
945  );
946  /* */
979  int (*obj_reinit)(
980  const struct RTOp_obj_type_vtbl_t *vtbl
981  ,const void *instance_data
982  ,void *obj
983  );
984  /* */
1019  int (*obj_free)(
1020  const struct RTOp_obj_type_vtbl_t *vtbl
1021  ,const void *instance_data
1022  ,void **obj
1023  );
1024  /* */
1053  const struct RTOp_obj_type_vtbl_t *vtbl
1054  ,const void *instance_data
1055  ,void *obj
1056  ,int num_values
1057  ,RTOp_value_type value_data[]
1058  ,int num_indexes
1059  ,RTOp_index_type index_data[]
1060  ,int num_chars
1061  ,RTOp_char_type char_data[]
1062  );
1063  /* */
1097  int (*load_state)(
1098  const struct RTOp_obj_type_vtbl_t *vtbl
1099  ,const void *instance_data
1100  ,int num_values
1101  ,const RTOp_value_type value_data[]
1102  ,int num_indexes
1103  ,const RTOp_index_type index_data[]
1104  ,int num_chars
1105  ,const RTOp_char_type char_data[]
1106  ,void **obj
1107  );
1108 };
1109 
1134 
1136 /* */
1181  const char op_class_name[]
1182  ,const struct RTOp_RTOp_vtbl_t *op_class_vtbl
1183  );
1184 
1185 /* */
1209  const struct RTOp_RTOp_vtbl_t *op_class_vtbl
1210  ,char op_class_name[]
1211  );
1212 
1213 /* */
1239  const char op_class_name[]
1240  ,int num_values
1241  ,const RTOp_value_type value_data[]
1242  ,int num_indexes
1243  ,const RTOp_index_type index_data[]
1244  ,int num_chars
1245  ,const RTOp_char_type char_data[]
1246  ,struct RTOp_RTOp *op
1247  );
1248 
1249 /* */
1253 void RTOp_Server_dump( FILE* file );
1254 
1257 
1259 #ifdef __cplusplus
1260 }
1261 #endif
1262 
1263 #endif /* REDUCT_TRANS_VECTOR_OPERATORS_H */
int RTOp_get_reduct_type_num_entries(const struct RTOp_RTOp *op, int *num_values, int *num_indexes, int *num_chars)
Definition: RTOp.c:209
int RTOp_load_op_state(int num_values, const RTOp_value_type value_data[], int num_indexes, const RTOp_index_type index_data[], int num_chars, const RTOp_char_type char_data[], struct RTOp_RTOp *op)
Definition: RTOp.c:170
int(* get_obj_type_num_entries)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, int *num_values, int *num_indexes, int *num_chars)
Definition: RTOp.h:907
int RTOp_load_reduct_obj_state(const struct RTOp_RTOp *op, int num_values, const RTOp_value_type value_data[], int num_indexes, const RTOp_index_type index_data[], int num_chars, const RTOp_char_type char_data[], RTOp_ReductTarget reduct_obj)
Definition: RTOp.c:307
int RTOp_reduct_obj_create(const struct RTOp_RTOp *op, RTOp_ReductTarget *reduct_obj)
Definition: RTOp.c:230
void RTOp_mutable_sub_vector(RTOp_index_type global_offset, RTOp_index_type sub_dim, RTOp_value_type values[], ptrdiff_t values_stride, struct RTOp_MutableSubVector *sub_vec)
Definition: RTOp.c:77
int RTOp_reduce_reduct_objs(const struct RTOp_RTOp *op, RTOp_ReductTarget in_reduct_obj, RTOp_ReductTarget inout_reduct_obj)
Definition: RTOp.c:374
int(* obj_create)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)
Definition: RTOp.h:941
typedef void(CALL_API *RTOp_reduct_op_func_ptr_t)(void *
int RTOp_extract_reduct_obj_state(const struct RTOp_RTOp *op, const RTOp_ReductTarget reduct_obj, int num_values, RTOp_value_type value_data[], int num_indexes, RTOp_index_type index_data[], int num_chars, RTOp_char_type char_data[])
Definition: RTOp.c:280
int(* extract_state)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void *obj, int num_values, RTOp_value_type value_data[], int num_indexes, RTOp_index_type index_data[], int num_chars, RTOp_char_type char_data[])
Definition: RTOp.h:1052
void RTOp_sub_vector(RTOp_index_type global_offset, RTOp_index_type sub_dim, const RTOp_value_type values[], ptrdiff_t values_stride, struct RTOp_SubVector *sub_vec)
Definition: RTOp.c:52
int RTOp_reduct_obj_free(const struct RTOp_RTOp *op, RTOp_ReductTarget *reduct_obj)
Definition: RTOp.c:267
int RTOp_get_op_type_num_entries(const struct RTOp_RTOp *op, int *num_values, int *num_indexes, int *num_chars)
Definition: RTOp.c:123
int RTOp_get_op_name(const struct RTOp_RTOp *op, const char **op_name)
Definition: RTOp.c:108
int RTOp_apply_op(const struct RTOp_RTOp *op, const int num_vecs, const struct RTOp_SubVector sub_vecs[], const int num_targ_vecs, const struct RTOp_MutableSubVector targ_sub_vecs[], RTOp_ReductTarget reduct_obj)
Definition: RTOp.c:357
int RTOp_Server_lookup_op_name(const struct RTOp_RTOp_vtbl_t *op_class_vtbl, char op_class_name[])
Definition: RTOp.c:472
int RTOp_Server_add_op_name_vtbl(const char op_class_name[], const struct RTOp_RTOp_vtbl_t *op_class_vtbl)
Definition: RTOp.c:453
const char * op_name
Definition: RTOp.h:825
int RTOp_free_op(struct RTOp_RTOp *op)
Definition: RTOp.c:197
int RTOp_extract_op_state(const struct RTOp_RTOp *op, int num_values, RTOp_value_type value_data[], int num_indexes, RTOp_index_type index_data[], int num_chars, RTOp_char_type char_data[])
Definition: RTOp.c:144
int(* obj_free)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)
Definition: RTOp.h:1019
int(* obj_reinit)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void *obj)
Definition: RTOp.h:979
int(* reduct_obj_reinit)(const struct RTOp_RTOp_vtbl_t *vtbl, const void *obj_data, RTOp_ReductTarget reduct_obj)
Definition: RTOp.h:834
int RTOp_Server_construct_op(const char op_class_name[], int num_values, const RTOp_value_type value_data[], int num_indexes, const RTOp_index_type index_data[], int num_chars, const RTOp_char_type char_data[], struct RTOp_RTOp *op)
Definition: RTOp.c:484
int(* load_state)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, int num_values, const RTOp_value_type value_data[], int num_indexes, const RTOp_index_type index_data[], int num_chars, const RTOp_char_type char_data[], void **obj)
Definition: RTOp.h:1097
void RTOp_mutable_sub_vector_null(struct RTOp_MutableSubVector *sub_vec)
Definition: RTOp.c:95
int RTOp_reduct_obj_reinit(const struct RTOp_RTOp *op, RTOp_ReductTarget reduct_obj)
Definition: RTOp.c:249
int RTOp_get_reduct_op(const struct RTOp_RTOp *op, RTOp_reduct_op_func_ptr_t *reduct_op_func_ptr)
Definition: RTOp.c:385
void RTOp_Server_dump(FILE *file)
Definition: RTOp.c:511
void RTOp_sub_vector_null(struct RTOp_SubVector *sub_vec)
Definition: RTOp.c:69
int RTOp_coord_invariant(const struct RTOp_RTOp *op, int *coord_invariant)
Definition: RTOp.c:341