source: trunk/ADOL-C/include/adolc/externfcts2.h @ 735

Last change on this file since 735 was 735, checked in by kulshres, 2 years ago

add a flag in edfs to avoid memory internally and use only user allocated

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

File size: 7.0 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     externfcts.h
4 Revision: $Id$
5 Contents: public functions and data types for extern (differentiated)
6           functions.
7
8 Copyright (c) Kshitij Kulshreshtha
9
10 This file is part of ADOL-C. This software is provided as open source.
11 Any use, reproduction, or distribution of the software constitutes
12 recipient's acceptance of the terms of the accompanying license file.
13
14----------------------------------------------------------------------------*/
15
16#if !defined(ADOLC_EXTERNFCTS2_H)
17#define ADOLC_EXTERNFCTS2_H 1
18
19#include <adolc/internal/common.h>
20#include <adolc/adouble.h>
21
22BEGIN_C_DECLS
23
24typedef int (ADOLC_ext_fct_v2) (int iArrLen, int *iArr, int nin, int nout, int *insz, double **x, int *outsz, double **y, void* ctx);
25typedef int (ADOLC_ext_fct_v2_fos_forward)(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, double **xp, int *outsz, double **y, double **yp, void *ctx);
26typedef int (ADOLC_ext_fct_v2_fov_forward)(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, int ndir, double ***Xp, int *outsz, double **y, double ***Yp, void* ctx);
27typedef int (ADOLC_ext_fct_v2_fos_reverse)(int iArrLen, int* iArr, int nout, int nin, int *outsz, double **up, int *insz, double **zp, double **x, double **y, void *ctx);
28typedef int (ADOLC_ext_fct_v2_fov_reverse)(int iArrLen, int* iArr, int nout, int nin, int *outsz, int dir, double ***Up, int *insz, double ***Zp, double **x, double **y, void* ctx);
29
30/* The following two aren't implemented */
31typedef int (ADOLC_ext_fct_v2_hos_forward)(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, int degree, double ***Xp, int *outsz, double **y, double ***Yp, void* ctx);
32typedef int (ADOLC_ext_fct_v2_hov_forward)(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, int degree, int ndir, double ****Xp, int *outsz, double **y, double ****Yp, void *ctx);
33
34typedef struct {
35 /**
36   * DO NOT touch - the function pointer is set through reg_ext_fct
37   */
38  ADOLC_ext_fct_v2 *function;
39  /**
40   * DO NOT touch - the index is set through reg_ext_fct
41   */
42  locint index;
43
44  /**
45   * below are function pointers used for call back from the corresponding ADOL-C trace interpreters;
46   * these function pointers are initialized to 0 by reg_ext_fct;
47   * the  user needs to set eplicitly the function pointers for the trace interpreters called in the
48   * application driver
49   */
50
51  /**
52   * this points to a  method implementing a forward execution of the externally differentiated function y=f(x);
53   * the pointer would typically be set to the same function pointer supplied in the call to reg_ext_fct,
54   * i.e. zos_forward would be equal to function (above)
55   * but there are cases when it makes sense for this to be different as illustrated
56   * in examples/additional_examples/ext_diff_func/ext_diff_func.cpp
57   */
58  ADOLC_ext_fct_v2 *zos_forward;
59
60  /**
61   * this points to a  method implementing a forward execution of the externally differentiated function y=f(x)
62   * and computing the projection yp=Jacobian*xp
63   * see also the explanation of the xp,yp members below.
64   */
65  ADOLC_ext_fct_v2_fos_forward *fos_forward;
66
67  /**
68   * this points to a  method implementing a forward execution of the externally differentiated function y=f(x)
69   * and computing the projection Yp=Jacobian*Xp
70   * see also the explanation of the Xp/Yp  members below.
71   */
72  ADOLC_ext_fct_v2_fov_forward *fov_forward;
73
74   /**
75   * this points to a  method computing the projection zp=transpose(zp) * Jacobian
76   * see also the explanation of the up/zp  members below.
77   */
78  ADOLC_ext_fct_v2_fos_reverse *fos_reverse;
79
80  /**
81   * this points to a  method computing the projection Zp=transpose(Up) * Jacobian
82   * see also the explanation of the Up/Zp  members below.
83   */
84  ADOLC_ext_fct_v2_fov_reverse *fov_reverse;
85
86  /**
87   * The names of the variables below correspond to the formal parameters names in the call back
88   * functions above;
89   */
90
91  /**
92   * function and all _forward calls: function argument, dimension nin*insz[0..nin]
93   */
94  double **x;
95
96  /**
97   * fos_forward: tangent direction, dimension nin*insz[0..nin]
98   */
99  double **xp;
100
101  /**
102   * fov_forward: seed matrix for p directions, dimensions nin*insz[0..nin]*p (p=nin*insz[0..nin])
103   */
104  double ***Xp;
105
106  /**
107   * function and all _forward calls: function result, dimension nout*outsz[0..nout]
108   */
109  double **y;
110
111  /**
112   * fos_forward: Jacobian projection, dimension nout*outsz[0..nout]
113   */
114  double **yp;
115
116  /**
117   * fov_forward: Jacobian projection in p directions, dimension nout*outsz[0..nout]*p (p=nin*insz[0..nin])
118   */
119  double ***Yp;
120
121  /**
122   * fos_reverse and hos_reverse:  weight vector, dimension nout*outsz[0..nout]
123   */
124  double **up;
125
126  /**
127   * fov_reverse and hov_reverse: q weight vectors, dimensions (q=nout*outsz[0..nout]) q*nout*outsz[0..nout]
128   */
129  double ***Up;
130
131  /**
132   * fos_reverse: Jacobian projection, dimension nin*insz[0..nin]
133   */
134  double **zp;
135
136  /**
137   * fov_reverse: Jacobian projection for q weight vectors, dimensions (q=nout*outsz[0..nout]) q*nin*insz[0..nin]
138   */
139  double ***Zp;
140
141  /**
142   * track maximal dimensions when function is invoked
143   */
144  locint max_nin, max_nout, max_insz, max_outsz;
145
146  /**
147   * make the call such that Adol-C may be used inside
148   * of the externally differentiated function;
149   * defaults to 0;
150   * this implies certain storage duplication that can
151   * be avoided if no nested use of Adol-C takes place
152   */
153  char nestedAdolc;
154
155  /**
156   * if 0, then the 'function' does not change dp_x;
157   * defaults to non-0 which implies dp_x values are saved in taylors
158   */
159  char dp_x_changes;
160
161  /**
162   * if 0, then the value of dp_y prior to calling 'function'
163   * is not required for reverse;
164   * defaults to non-0 which implies  dp_y values are saved in taylors
165   */
166  char dp_y_priorRequired;
167  /**
168   * This is a opaque context pointer that the user may set and use
169   * in his implementation of the above functions
170   */
171  void* context;
172  /**
173   * This is an all-memory pointer for allocating and deallocating
174   * all other pointers can point to memory within here.
175   */
176  char* allmem;
177  /**
178   * This is a reference to an object for the C++ object-oriented
179   * implementation of the external function ** do not touch **
180   */
181  void* obj;
182  /**
183   * This flag indicates that user allocates memory and internally no
184   * memory should be allocated
185   */
186  char user_allocated_mem;
187}
188ext_diff_fct_v2;
189
190END_C_DECLS
191#if defined(__cplusplus)
192
193ADOLC_DLL_EXPORT ext_diff_fct_v2 *reg_ext_fct(ADOLC_ext_fct_v2 ext_fct);
194ADOLC_DLL_EXPORT int call_ext_fct (ext_diff_fct_v2 *edfct,
195                                   int iArrLen, int* iArr,
196                                   int nin, int nout,
197                                   int *insz, adouble **x,
198                                   int *outsz, adouble **y);
199
200ADOLC_DLL_EXPORT void edf_zero(ext_diff_fct_v2 *edfct);
201
202inline void edf_set_opaque_context(ext_diff_fct_v2 *edfct, void *ctx) {
203    edfct->context = ctx;
204}
205
206#endif
207#endif
Note: See TracBrowser for help on using the repository browser.