source: trunk/ADOL-C/src/checkpointing.h @ 40

Last change on this file since 40 was 40, checked in by awalther, 10 years ago

adapted directoy structure

File size: 4.1 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     checkpointing.h
4 Revision: $Id: checkpointing.h 37 2009-05-28 12:56:44Z awalther $
5 Contents: Provides all checkointing interfaces.
6 
7 Copyright (c) Andreas Kowarz
8 
9 This file is part of ADOL-C. This software is provided as open source.
10 Any use, reproduction, or distribution of the software constitutes
11 recipient's acceptance of the terms of the accompanying license file.
12 
13----------------------------------------------------------------------------*/
14
15#if !defined(ADOLC_CHECKPOINTING_H)
16#define ADOLC_CHECKPOINTING_H 1
17
18#include <common.h>
19#include <adouble.h>
20
21#if defined(__cplusplus)
22/****************************************************************************/
23/*                                                          This is all C++ */
24
25typedef int (*ADOLC_TimeStepFuncion) (int n, adouble *x);
26typedef int (*ADOLC_TimeStepFuncion_double) (int n, double *x);
27typedef void *(*ADOLC_saveFct) ();
28typedef void (*ADOLC_restoreFct) (void *);
29
30typedef struct CpInfos {
31    ADOLC_TimeStepFuncion function;
32    ADOLC_TimeStepFuncion_double function_double;
33    ADOLC_saveFct saveNonAdoubles;
34    ADOLC_restoreFct restoreNonAdoubles;
35    int steps;
36    int checkpoints;
37    int tapeNumber;      /* tape number to be used for checkpointing */
38    int retaping;  /* != 0 forces retaping before every reverse step */
39
40    int n;          /* number of variables in input and output (n=m) */
41    adouble *adp_x;                       /* input of the first step */
42    adouble *adp_y; /* output of the last step; will be set by ADOLC */
43
44    /* these are internal checkpointing variables => do not use */
45    int check;
46    int capo;
47    int fine;
48    int info;
49    int currentCP;
50    double *dp_internal_for;
51    double *dp_internal_rev;
52    double **dpp_internal_rev;
53    locint index;                            /* please do not change */
54    char modeForward;
55    char modeReverse;
56}
57CpInfos;
58
59ADOLC_DLL_EXPORT
60CpInfos *reg_timestep_fct(ADOLC_TimeStepFuncion timeStepFunction);
61
62ADOLC_DLL_EXPORT int checkpointing (CpInfos *cpInfos);
63
64/* if tape with one program and use the tapes with another programm call this
65 * function within the latter                                               */
66ADOLC_DLL_EXPORT void reinit_checkpointing();
67
68class CP_Context {
69public:
70    inline CP_Context(ADOLC_TimeStepFuncion tsf);
71    inline ~CP_Context() {}
72
73    inline void setDoubleFct(ADOLC_TimeStepFuncion_double tsf);
74    inline void setSaveFct(ADOLC_saveFct sf);
75    inline void setRestoreFct(ADOLC_restoreFct rf);
76    inline void setNumberOfSteps(int number);
77    inline void setNumberOfCheckpoints(int number);
78    inline void setTapeNumber(int tapeNumber);
79    inline void setDimensionXY(int n);
80    inline void setInput(adouble *x);
81    inline void setOutput(adouble *y);
82    inline void setAlwaysRetaping(bool state);
83
84    inline int checkpointing();
85
86private:
87    inline CP_Context() {}
88
89    CpInfos *cpInfos;
90};
91
92CP_Context::CP_Context(ADOLC_TimeStepFuncion tsf) {
93    cpInfos = reg_timestep_fct(tsf);
94}
95
96void CP_Context::setDoubleFct(ADOLC_TimeStepFuncion_double tsf) {
97    cpInfos->function_double = tsf;
98}
99
100void CP_Context::setSaveFct(ADOLC_saveFct sf) {
101    cpInfos->saveNonAdoubles = sf;
102}
103
104void CP_Context::setRestoreFct(ADOLC_restoreFct rf) {
105    cpInfos->restoreNonAdoubles = rf;
106}
107
108void CP_Context::setNumberOfSteps(int number) {
109    cpInfos->steps = number;
110}
111
112void CP_Context::setNumberOfCheckpoints(int number) {
113    cpInfos->checkpoints = number;
114}
115
116void CP_Context::setTapeNumber(int tapeNumber) {
117    cpInfos->tapeNumber = tapeNumber;
118}
119
120void CP_Context::setDimensionXY(int n) {
121    cpInfos->n = n;
122}
123
124void CP_Context::setInput(adouble *x) {
125    cpInfos->adp_x = x;
126}
127
128void CP_Context::setOutput(adouble *y) {
129    cpInfos->adp_y = y;
130}
131
132void CP_Context::setAlwaysRetaping(bool state) {
133    if (state) cpInfos->retaping = 1;
134    else cpInfos->retaping = 0;
135}
136
137int CP_Context::checkpointing() {
138    return ::checkpointing(cpInfos);
139}
140
141#endif /* CPLUSPLUS */
142
143/****************************************************************************/
144#endif /* ADOLC_CHECKPOINTING_H */
145
Note: See TracBrowser for help on using the repository browser.