source: trunk/ADOL-C/include/adolc/externfcts.h @ 595

Last change on this file since 595 was 595, checked in by kulshres, 5 years ago

Merge changes from 'master' branch of 'gitclone'

The following changesets have been merged:

commit 3931a4393e4003928eed197011a8dc75aab95514
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Feb 13 16:55:03 2015 +0100

Visual Studio Compatibility

unfortunately visual studio 2010 does not support C++11 standard.

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

commit 023a1f5062e61a5761f15a7c6ec93d05ec9e4bf3
Author: kulshres <kulshres@94ac48a7-3327-4b6a-8511-9a4036a20e83>
Date: Mon Feb 9 16:12:23 2015 +0000

correct ColPack? download website

git-svn-id: https://projects.coin-or.org/svn/ADOL-C/trunk@594 94ac48a7-3327-4b6a-8511-9a4036a20e83

commit 6a1c37c41b89b9c13b3702035d16ad78c5730166
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Feb 4 18:01:44 2015 +0100

scoping changes

forward declarations with friends and declspec(dllexport) for windows
are a bit tricky.

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

commit 199e0da8bbf28c4819cd47b5acfd5cd8a18d55a3
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Feb 4 17:42:37 2015 +0100

Add operations vec_dot and vec_axpy

This will reduce tape length and provide speed.
Dot-products and axpy operations done with
adoubles and for-loops require many temporary
adub variables and become slow.

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

commit d5f729d55ed250384fe62c64f6b5dcc5e8c09748
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Feb 3 15:30:04 2015 +0100

read unsigned values from .adolcrc

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

commit b7a9e1062c345624f27039b2a590f09bd8e70a70
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Jan 30 17:12:02 2015 +0100

specify initial size of live variable store in adolcrc

if one knows approximately how many live variables
there are going to be in the program one can
specify it in the .adolcrc file with INITLIVE
This will prevent the many initially required
new and delete calls while the store grows dynamically
when adouble objects are initialized

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

commit 9ce7f63b4c7a7099781a2d2f6c7a962e24932c65
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Jan 30 16:07:53 2015 +0100

provide a conversion to adouble* from advector

the memory will still be managed inside advector

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

commit 26ac5de41e0ef0e0faae26e32ea3b377570b7ef0
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Jan 30 16:06:53 2015 +0100

streamline advector class

since we now use c++11 we can use the default-insertion
instead of having to copy. This saves operations.
so we don't need the dflt field anymore.
We can also use the adolc_vec_copy() function to
implement the copy constructor.

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

commit 2b2f878a05082d777ebbe5e3d445751ca68759cb
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Jan 30 15:56:05 2015 +0100

add a faster vector copy operation

this should in principle be faster than calling
n assignment operators of adouble and it also
shortens the trace somewhat.

Can only be used if the arrays were allocated
with contiguous locations.

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

commit ef9babd35faea9e766c6c861d99b001510d7e5d4
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Jan 28 14:01:06 2015 +0100

try disabling multithreading support in boost

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

commit 766ac8360bb952b68ce345ea29ee96be65044c29
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Jan 27 14:28:23 2015 +0100

add DLL_EXPORT to function

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

commit fe580956f2664a743f1a981464fd398aabd9acbc
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Jan 27 12:41:51 2015 +0100

allow edf structures to be initialised to zero from outside the library

This is required to properly deallocate the memory, which is user
allocated and set as pointers in this structure, to ensure that
the structure does not call for this memory after the user deallocates
it.

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

commit 4c793005996f0af6b4a95788283e3baab233d3b8
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Jan 26 13:56:35 2015 +0100

more streamlining of next_loc()/free_loc()

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

commit 6686a248a2598a306f4502acd3158c4945d45705
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Jan 26 13:20:14 2015 +0100

a couple of warning fixes

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

commit 7a87f9f5ed97d0af7db7674229483aa782abd970
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Jan 26 11:17:10 2015 +0100

streamline StoreManagerLocintBlock::free_loc() slightly

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

commit 1e4b7a739849098fc33174138b237e5d44462822
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Jan 26 11:08:41 2015 +0100

Also check for boost::system in code

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

commit 1f9eb738280610aad49b1dff623e8aaaca9903d6
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Jan 26 11:05:02 2015 +0100

use a pool allocator from the boost library if available

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

commit 0498360e12d8590f67f19f9a1bca7dff1edb00a2
Author: kulshres <kulshres@94ac48a7-3327-4b6a-8511-9a4036a20e83>
Date: Tue Jan 6 14:48:24 2015 +0000

copy paste typos

Thanks to Mu Wang <wangmu0701@…>

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

git-svn-id: https://projects.coin-or.org/svn/ADOL-C/trunk@593 94ac48a7-3327-4b6a-8511-9a4036a20e83

commit 80f4a743262d32daf1869cfbc4486c977de1e3a4
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Dec 24 14:45:32 2014 +0100

Scatterv/Allgatherv? and compile fixes

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

commit 6caec6d3e19f234da22241e97999cb2eebb40be2
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Dec 24 01:04:48 2014 +0100

Implement Gatherv and some compile fixes

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

commit 439ab813d8b08c0a17c6afb6180ebe914acc3e20
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Dec 23 19:56:45 2014 +0100

Don't use uninitialised pointer for status in MPI calls

From: Max Sagebaum <max.sagebaum@…>
Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit fb911b73d6f9e4729fdf5148671b3c23ed9252b8
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Dec 19 11:02:14 2014 +0100

Implement AMPI calls in forward mode

Send,Recv,Gather,Scatter,Allgather

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

commit 5eecda924840d63fa7309bfc3e4758b28f7e41ec
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Dec 16 15:55:32 2014 +0100

try out some c++11 features since we mandate it anyway

use forward_list instead of list since its unidirectional

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

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

  • Property svn:keywords set to Author Date Id Revision
File size: 11.2 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     externfcts.h
4 Revision: $Id: externfcts.h 595 2015-02-16 11:08:54Z kulshres $
5 Contents: public functions and data types for extern (differentiated)
6           functions.
7 
8 Copyright (c) Andreas Kowarz, Jean Utke
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_EXTERNFCTS_H)
17#define ADOLC_EXTERNFCTS_H 1
18
19#include <adolc/internal/common.h>
20#include <adolc/adouble.h>
21
22BEGIN_C_DECLS
23
24typedef int (ADOLC_ext_fct) (int n, double *x, int m, double *y);
25typedef int (ADOLC_ext_fct_fos_forward) (int n, double *dp_x, double *dp_X, int m, double *dp_y, double *dp_Y);
26typedef int (ADOLC_ext_fct_fov_forward) (int n, double *dp_x, int p, double **dpp_X, int m, double *dp_y, double **dpp_Y);
27typedef int (ADOLC_ext_fct_hos_forward) (int n, double *dp_x, int d, double **dpp_X, int m, double *dp_y, double **dpp_Y);
28typedef int (ADOLC_ext_fct_hov_forward) (int n, double *dp_x, int d, int p, double ***dppp_X, int m, double *dp_y, double ***dppp_Y);
29typedef int (ADOLC_ext_fct_fos_reverse) (int m, double *dp_U, int n, double *dp_Z, double *dp_x, double *dp_y);
30typedef int (ADOLC_ext_fct_fov_reverse) (int m, int p, double **dpp_U, int n, double **dpp_Z, double *dp_x, double *dp_y);
31typedef int (ADOLC_ext_fct_hos_reverse) (int m, double *dp_U, int n, int d, double **dpp_Z); 
32typedef int (ADOLC_ext_fct_hov_reverse) (int m, int p, double **dpp_U, int n, int d, double ***dppp_Z, short **spp_nz);
33
34/**
35 * we add a second set of function pointers with a signature expanded by a an integer array iArr
36 * and a parameter iArrLength motivated by externalizing sparse solvers where the sparsity format
37 * may be triples (i,j,A[i][j]) and a number of nonzero entries nz where all these integers are to
38 * be packed into iArr. Doing this will still allow the integers to be stored in the locint part
39 * of the tape.
40 * The alternative to doing this is the introduction of a separate stack to contain the extra data
41 * but this would break the self-containment of the tape.
42 */
43typedef int (ADOLC_ext_fct_iArr) (int iArrLength, int *iArr, int n, double *x, int m, double *y);
44typedef int (ADOLC_ext_fct_iArr_fos_forward) (int iArrLength, int *iArr, int n, double *dp_x, double *dp_X, int m, double *dp_y, double *dp_Y);
45typedef int (ADOLC_ext_fct_iArr_fov_forward) (int iArrLength, int *iArr, int n, double *dp_x, int p, double **dpp_X, int m, double *dp_y, double **dpp_Y);
46typedef int (ADOLC_ext_fct_iArr_hos_forward) (int iArrLength, int *iArr, int n, double *dp_x, int d, double **dpp_X, int m, double *dp_y, double **dpp_Y);
47typedef int (ADOLC_ext_fct_iArr_hov_forward) (int iArrLength, int *iArr, int n, double *dp_x, int d, int p, double ***dppp_X, int m, double *dp_y, double ***dppp_Y);
48typedef int (ADOLC_ext_fct_iArr_fos_reverse) (int iArrLength, int *iArr, int m, double *dp_U, int n, double *dp_Z, double *dp_x, double *dp_y);
49typedef int (ADOLC_ext_fct_iArr_fov_reverse) (int iArrLength, int *iArr, int m, int p, double **dpp_U, int n, double **dpp_Z, double *dp_x, double *dp_y);
50typedef int (ADOLC_ext_fct_iArr_hos_reverse) (int iArrLength, int *iArr, int m, double *dp_U, int n, int d, double **dpp_Z);
51typedef int (ADOLC_ext_fct_iArr_hov_reverse) (int iArrLength, int *iArr, int m, int p, double **dpp_U, int n, int d, double ***dppp_Z, short **spp_nz);
52
53
54/**
55 * A variable of this type has to be instantiated by reg_ext_fct (see below) and a pointer to it is
56 * returned. Within reg_ext_fct the memberse function and index are properly set.
57 * is likely to be wrong in this case. Use pointers instead.
58 */
59typedef struct {
60
61  /**
62   * DO NOT touch - the function pointer is set through reg_ext_fct
63   */
64  ADOLC_ext_fct *function; 
65  ADOLC_ext_fct_iArr *function_iArr;
66
67  /**
68   * DO NOT touch - the index is set through reg_ext_fct
69   */
70  locint index;           
71
72  /**
73   * below are function pointers used for call back from the corresponding ADOL-C trace interpreters;
74   * these function pointers are initialized to 0 by reg_ext_fct;
75   * the  user needs to set eplicitly the function pointers for the trace interpreters called in the
76   * application driver
77   */
78
79  /**
80   * this points to a  method implementing a forward execution of the externally differentiated function dp_y=f(dp_x);
81   * the pointer would typically be set to the same function pointer supplied in the call to reg_ext_fct,
82   * i.e. zos_forward would be equal to function (above)
83   * but there are cases when it makes sense for this to be different as illustrated
84   * in examples/additional_examples/ext_diff_func/ext_diff_func.cpp 
85   */
86  ADOLC_ext_fct *zos_forward;
87  ADOLC_ext_fct_iArr *zos_forward_iArr;
88
89  /**
90   * this points to a  method implementing a forward execution of the externally differentiated function dp_y=f(dp_x)
91   * and computing the projection dp_Y=Jacobian*dp_x
92   * see also the explanation of the dp_X/Y  members below.
93   */
94  ADOLC_ext_fct_fos_forward *fos_forward;
95  ADOLC_ext_fct_iArr_fos_forward *fos_forward_iArr;
96
97  /**
98   * this points to a  method implementing a forward execution of the externally differentiated function dp_y=f(dp_x)
99   * and computing the projection dpp_Y=Jacobian*dpp_x
100   * see also the explanation of the dpp_X/Y  members below.
101   */
102  ADOLC_ext_fct_fov_forward *fov_forward;
103  ADOLC_ext_fct_iArr_fov_forward *fov_forward_iArr;
104  /**
105   * higher order scalar forward for external functions  is currently not implemented in uni5_for.c
106   */
107  ADOLC_ext_fct_hos_forward *hos_forward; 
108  ADOLC_ext_fct_iArr_hos_forward *hos_forward_iArr;
109  /**
110   * higher order vector forward for external functions  is currently not implemented in uni5_for.c
111   */
112  ADOLC_ext_fct_hov_forward *hov_forward;
113  ADOLC_ext_fct_iArr_hov_forward *hov_forward_iArr;
114  /**
115   * this points to a  method computing the projection dp_Z=transpose(dp_U) * Jacobian
116   * see also the explanation of the dp_U/Z  members below.
117   */
118  ADOLC_ext_fct_fos_reverse *fos_reverse; 
119  ADOLC_ext_fct_iArr_fos_reverse *fos_reverse_iArr;
120  /**
121   * this points to a  method computing the projection dpp_Z=transpose(dpp_U) * Jacobian
122   * see also the explanation of the dpp_U/Z  members below.
123   */
124  ADOLC_ext_fct_fov_reverse *fov_reverse; 
125  ADOLC_ext_fct_iArr_fov_reverse *fov_reverse_iArr;
126  /**
127   * higher order scalar reverse for external functions  is currently not implemented in ho_rev.c
128   */
129  ADOLC_ext_fct_hos_reverse *hos_reverse; 
130  ADOLC_ext_fct_iArr_hos_reverse *hos_reverse_iArr;
131  /**
132   * higher order vector reverse for external functions  is currently not implemented in ho_rev.c
133   */
134  ADOLC_ext_fct_hov_reverse *hov_reverse; 
135  ADOLC_ext_fct_iArr_hov_reverse *hov_reverse_iArr;
136
137
138  /**
139   * The names of the variables below correspond to the formal parameters names in the call back
140   * functions above;
141   * The user has to preallocate the variables and set the pointers for any of the call back functions
142   * that will be called during trace interpretation.
143   * The dimensions given below correspond to the formal arguments in the call back funtions signatures above.
144   * If the dimensions n and m change between multiple calls to the same external function, then the variables
145   * have to be preallocation with the maximum of the respective dimension values.
146   * The dp_x and dp_y pointers have to be valid during both, the tracing phase and the trace interpretation;
147   * all the other pointers are required to be valid only for the trace interpretation.
148   */
149       
150  /**
151   * function and all _forward calls: function argument, dimension [n]
152   */ 
153  double *dp_x;     
154
155  /**
156   * fos_forward: tangent direction, dimension [n]
157   */ 
158  double *dp_X;   
159
160  /**
161   * fov_forward: seed matrix for p directions, dimensions [n][p]
162   * hos_forward: argument Taylor polynomial coefficients up to order d. dimensions [n][d]
163   */
164  double **dpp_X;
165 
166  /**
167   * hov_forward: argument Taylor polynomial coefficients up to order d in p directions. dimensions [n][p][d]
168   */
169  double ***dppp_X; 
170
171  /**
172   * function and all _forward calls: function result, dimension [m]
173   */
174  double *dp_y;   
175
176  /**
177   * fos_forward: Jacobian projection, dimension [m]
178   */
179  double *dp_Y; 
180
181  /**
182   * fov_forward: Jacobian projection in p directions, dimension [m][p]
183   * hos_forward: result Taylor polynomial coefficients up to order d. dimensions [m][d]
184   */
185  double **dpp_Y;     
186
187  /**
188   * hov_forward: result Taylor polynomial coefficients up to order d in p directions. dimensions [m][p][d]
189   */
190  double ***dppp_Y;
191
192  /**
193   * fos_reverse and hos_reverse:  weight vector, dimension [m]
194   */
195  double *dp_U;
196 
197  /**
198   * fov_reverse and hov_reverse: p weight vectors, dimensions [p][m]
199   */
200  double **dpp_U;       
201
202  /**
203   * fos_reverse: Jacobian projection, dimension [n]
204   */
205  double *dp_Z; 
206
207  /**
208   * fov_reverse: Jacobian projection for p weight vectors, dimensions [p][n]
209   * hos_reverse: adjoint Taylor polynomial coefficients up to order d, dimensions [n][d+1]
210   */
211  double **dpp_Z;   
212
213  /**
214   * hov_reverse:  adjoint Taylor polynomial coefficients up to order d for p weight vectors, dimension [p][n][d+1]
215   */
216  double ***dppp_Z; 
217
218  /**
219   * hov_reverse: non-zero pattern of dppp_Z, dimension [p][n], see also the hov_reverse ADOL-C driver
220   */
221  short **spp_nz;
222
223  /**
224   * track maximal value of n when function is invoked
225   */
226  locint max_n;
227
228  /**
229   * track maximal value of m when function is invoked
230   */
231  locint max_m;
232
233  /**
234   * make the call such that Adol-C may be used inside
235   * of the externally differentiated function;
236   * defaults to non-0;
237   * this implies certain storage duplication that can
238   * be avoided if no nested use of Adol-C takes place
239   */
240  char nestedAdolc;
241
242  /**
243   * if 0, then the 'function' does not change dp_x;
244   * defaults to non-0 which implies dp_x values are saved in taylors
245   */
246  char dp_x_changes;
247
248  /**
249   * if 0, then the value of dp_y prior to calling 'function'
250   * is not required for reverse;
251   * defaults to non-0 which implies  dp_y values are saved in taylors
252   */
253  char dp_y_priorRequired;
254
255}
256ext_diff_fct;
257
258END_C_DECLS
259
260#if defined(__cplusplus)
261/****************************************************************************/
262/*                                                          This is all C++ */
263
264ADOLC_DLL_EXPORT ext_diff_fct *reg_ext_fct(ADOLC_ext_fct ext_fct);
265ADOLC_DLL_EXPORT ext_diff_fct *reg_ext_fct(ADOLC_ext_fct_iArr ext_fct);
266
267ADOLC_DLL_EXPORT int call_ext_fct (ext_diff_fct *edfct,
268                                   int n, double *xp, adouble *xa,
269                                   int m, double *yp, adouble *ya);
270ADOLC_DLL_EXPORT int call_ext_fct (ext_diff_fct *edfct,
271                                   int iArrLength, int* iArr,
272                                   int n, double *xp, adouble *xa,
273                                   int m, double *yp, adouble *ya);
274
275/**
276 * zeros out the edf pointers and sets bools to defaults
277 */
278ADOLC_DLL_EXPORT void edf_zero(ext_diff_fct *edfct);
279
280#endif /* __CPLUSPLUS */
281
282/****************************************************************************/
283#endif /* ADOLC_EXTERNFCTS_H */
284
Note: See TracBrowser for help on using the repository browser.