source: trunk/ADOL-C/src/checkpointing.cpp @ 71

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

set svn keywords property

  • Property svn:keywords set to Author Date Id Revision
File size: 21.3 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     checkpointing.cpp
4 Revision: $Id: checkpointing.cpp 42 2009-07-15 18:37:17Z awalther $
5 Contents: checkpointing algorithms
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#include <oplate.h>
16#include <adalloc.h>
17#include <taping_p.h>
18#include <externfcts.h>
19#include <interfaces.h>
20#include <checkpointing.h>
21#include <checkpointing_p.h>
22#include <revolve.h>
23
24#include <cstring>
25
26#include <stack>
27using namespace std;
28
29ADOLC_BUFFER_TYPE ADOLC_EXT_DIFF_FCTS_BUFFER_DECL;
30
31/* field of pointers to the value fields of a checkpoint */
32stack<StackElement> ADOLC_CHECKPOINTS_STACK_DECL;
33
34/* forward function declarations */
35void init_edf(ext_diff_fct *edf);
36int cp_zos_forward (int n, double *dp_x, int m, double *dp_y);
37int cp_fos_forward (int n, double *dp_x, double *dp_X,
38                    int m, double *dp_y, double *dp_Y);
39int cp_fov_forward (int n, double *dp_x, double **dpp_X,
40                    int m, double *dp_y, double **dpp_Y);
41int cp_hos_forward (int n, double *dp_x, double **dpp_X,
42                    int m, double *dp_y, double **dpp_Y);
43int cp_hov_forward (int n, double *dp_x, double ***dppp_X,
44                    int m, double *dp_y, double ***dppp_Y);
45int cp_fos_reverse (int m, double *dp_U, int n, double *dp_Z);
46int cp_fov_reverse (int m, double **dpp_U, int n, double **dpp_Z);
47int cp_hos_reverse (int m, double *dp_U, int n, double **dpp_Z);
48int cp_hov_reverse (int m, double **dpp_U, int n, double ***dppp_Z,
49                    short **spp_nz);
50void cp_takeshot(CpInfos *cpInfos);
51void cp_restore(CpInfos *cpInfos);
52void cp_release(CpInfos *cpInfos);
53void cp_taping(CpInfos *cpInfos);
54void revolve_for(CpInfos *cpInfos);
55void revolveError(CpInfos *cpInfos);
56
57/* we do not really have an ext. diff. function that we want to be called */
58int dummy(int n, double *x, int m, double *y) {
59    return 0;
60}
61
62/* register one time step function (uses buffer template) */
63CpInfos *reg_timestep_fct(ADOLC_TimeStepFuncion timeStepFunction) {
64    ADOLC_OPENMP_THREAD_NUMBER;
65    ADOLC_OPENMP_GET_THREAD_NUMBER;
66
67    return ADOLC_EXT_DIFF_FCTS_BUFFER.append(timeStepFunction);
68}
69
70/* This is the main checkpointing function the user calls within the taping
71 * process. It performs n time steps with or without taping and registers an
72 * external dummy function which calls the actual checkpointing workhorses
73 * from within the used drivers. */
74int checkpointing (CpInfos *cpInfos) {
75    int i;
76    ext_diff_fct *edf;
77    int oldTraceFlag;
78    locint firstVal, numVals;
79    double *vals;
80    ADOLC_OPENMP_THREAD_NUMBER;
81    ADOLC_OPENMP_GET_THREAD_NUMBER;
82
83    // knockout
84    if (cpInfos==NULL)
85        fail(ADOLC_CHECKPOINTING_CPINFOS_NULLPOINTER);
86    if (cpInfos->function==NULL)
87        fail(ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION);
88    if (cpInfos->function_double==NULL)
89        fail(ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION_DOUBLE);
90    if (cpInfos->adp_x==NULL)
91        fail(ADOLC_CHECKPOINTING_NULLPOINTER_ARGUMENT);
92
93    // register extern function
94    edf=reg_ext_fct(dummy);
95    init_edf(edf);
96
97    // but we do not call it
98    // we use direct taping to avoid unnecessary argument copying
99    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
100        put_op(ext_diff);
101        ADOLC_PUT_LOCINT(edf->index);
102        ADOLC_PUT_LOCINT(0);
103        ADOLC_PUT_LOCINT(0);
104        ADOLC_PUT_LOCINT(cpInfos->adp_x[0].loc());
105        ADOLC_PUT_LOCINT(cpInfos->adp_y[0].loc());
106        // this CpInfos id has to be read by the actual checkpointing
107        // functions
108        ADOLC_PUT_LOCINT(cpInfos->index);
109
110        oldTraceFlag=ADOLC_CURRENT_TAPE_INFOS.traceFlag;
111        ADOLC_CURRENT_TAPE_INFOS.traceFlag=0;
112    } else oldTraceFlag=0;
113
114#if defined(ADOLC_SAFE_EXTERN)
115    firstVal = 0;
116#else
117    updateLocs();
118    firstVal = ADOLC_GLOBAL_TAPE_VARS.locMinUnused;
119#endif
120    numVals = ADOLC_GLOBAL_TAPE_VARS.numMaxAlive - firstVal;
121    vals = new double[numVals];
122    memcpy(vals, ADOLC_GLOBAL_TAPE_VARS.store + firstVal,
123            numVals * sizeof(double));
124
125    cpInfos->dp_internal_for = new double[cpInfos->n];
126    // initialize internal arguments
127    for (i=0; i<cpInfos->n; ++i)
128        cpInfos->dp_internal_for[i]=cpInfos->adp_x[i].getValue();
129    if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors != 0)
130        // perform all time steps, tape the last, take checkpoints
131        revolve_for(cpInfos);
132    else
133        // perform all time steps without taping
134        for (i=0; i<cpInfos->steps; ++i)
135            cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for);
136
137    memcpy(ADOLC_GLOBAL_TAPE_VARS.store + firstVal, vals,
138            numVals * sizeof(double));
139    delete[] vals;
140
141    // update taylor stack; same structure as in adouble.cpp +
142    // correction in taping.c
143    if (oldTraceFlag != 0) {
144        ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += cpInfos->n;
145        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors != 0)
146            for (i = 0; i < cpInfos->n; ++i)
147                ADOLC_WRITE_SCAYLOR(cpInfos->adp_y[i].getValue());
148    }
149    // save results
150    for (i=0; i<cpInfos->n; ++i) {
151        cpInfos->adp_y[i].setValue(cpInfos->dp_internal_for[i]);
152    }
153    delete[] cpInfos->dp_internal_for;
154    cpInfos->dp_internal_for = NULL;
155
156    // normal taping again
157    ADOLC_CURRENT_TAPE_INFOS.traceFlag=oldTraceFlag;
158
159    return 0;
160}
161
162/* - reinit external function buffer and checkpointing buffer
163 * - necessary when using tape within a different program */
164void reinit_checkpointing() {}
165
166CpInfos *get_cp_fct(int index) {
167    ADOLC_OPENMP_THREAD_NUMBER;
168    ADOLC_OPENMP_GET_THREAD_NUMBER;
169
170    return ADOLC_EXT_DIFF_FCTS_BUFFER.getElement(index);
171}
172
173/* initialize the CpInfos variable (function and index are set within
174 * the template code */
175void init_CpInfos(CpInfos *cpInfos) {
176    char *ptr;
177
178    ptr = (char *)cpInfos;
179    for (unsigned int i = 0; i < sizeof(CpInfos); ++i) ptr[i] = 0;
180    cpInfos->tapeNumber = -1;
181}
182
183/* initialize the information for the external function in a way that our
184 * checkpointing functions are called */
185void init_edf(ext_diff_fct *edf) {
186    edf->function=dummy;
187    edf->zos_forward=cp_zos_forward;
188    edf->fos_forward=cp_fos_forward;
189    edf->fov_forward=cp_fov_forward;
190    edf->hos_forward=cp_hos_forward;
191    edf->hov_forward=cp_hov_forward;
192    edf->fos_reverse=cp_fos_reverse;
193    edf->fov_reverse=cp_fov_reverse;
194    edf->hos_reverse=cp_hos_reverse;
195    edf->hov_reverse=cp_hov_reverse;
196}
197
198/****************************************************************************/
199/* the following are the main checkpointing functions called by the         */
200/* external differentiated function alogrithms                              */
201/****************************************************************************/
202
203/* special case: use double version where possible, no taping */
204int cp_zos_forward (int n, double *dp_x, int m, double *dp_y) {
205    CpInfos *cpInfos;
206    double *T0;
207    int i, oldTraceFlag;
208    locint arg;
209    ADOLC_OPENMP_THREAD_NUMBER;
210    ADOLC_OPENMP_GET_THREAD_NUMBER;
211
212    // taping off
213    oldTraceFlag=ADOLC_CURRENT_TAPE_INFOS.traceFlag;
214    ADOLC_CURRENT_TAPE_INFOS.traceFlag=0;
215
216    // get checkpointing information
217    cpInfos=get_cp_fct(ADOLC_CURRENT_TAPE_INFOS.cpIndex);
218    T0 = ADOLC_CURRENT_TAPE_INFOS.dp_T0;
219
220    // note the mode
221    cpInfos->modeForward = ADOLC_ZOS_FORWARD;
222    cpInfos->modeReverse = ADOLC_NO_MODE;
223
224    // prepare arguments
225    cpInfos->dp_internal_for=new double[cpInfos->n];
226    arg=ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for;
227    for (i=0; i<cpInfos->n; ++i) {
228        cpInfos->dp_internal_for[i]=T0[arg];
229        ++arg;
230    }
231
232    revolve_for(cpInfos);
233
234    // write back
235    arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for; // keep input
236    for (i=0; i<cpInfos->n; ++i) {
237        ADOLC_WRITE_SCAYLOR(T0[arg]);
238        T0[arg]=cpInfos->dp_internal_for[i];
239        ++arg;
240    }
241    delete[] cpInfos->dp_internal_for;
242    cpInfos->dp_internal_for = NULL;
243
244    // taping "on"
245    ADOLC_CURRENT_TAPE_INFOS.traceFlag=oldTraceFlag;
246
247    return 0;
248}
249
250void revolve_for(CpInfos *cpInfos) {
251    /* init revolve */
252    cpInfos->check=-1;
253    cpInfos->capo=0;
254    cpInfos->info = 0;
255    cpInfos->fine=cpInfos->steps;
256
257    /* execute all time steps */
258    enum revolve_action whattodo;
259    do {
260        whattodo=revolve(&cpInfos->check, &cpInfos->capo, &cpInfos->fine,
261                         cpInfos->checkpoints, &cpInfos->info);
262        switch (whattodo) {
263            case revolve_takeshot:
264                cp_takeshot(cpInfos);
265                cpInfos->currentCP=cpInfos->capo;
266                break;
267            case revolve_advance:
268                for (int i=0; i<cpInfos->capo-cpInfos->currentCP; ++i) {
269                    cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for);
270                }
271                break;
272            case revolve_firsturn:
273                cp_taping(cpInfos);
274                break;
275            case revolve_error:
276                revolveError(cpInfos);
277                break;
278            default:
279                fail(ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION);
280        }
281    } while (whattodo==revolve_takeshot || whattodo==revolve_advance);
282}
283
284int cp_fos_forward (int n, double *dp_x, double *dp_X,
285                    int m, double *dp_y, double *dp_Y) {
286    printf("WARNING: Checkpointing algorithm not "
287           "implemented for the fos_forward mode!\n");
288    return 0;
289}
290
291int cp_fov_forward (int n, double *dp_x, double **dpp_X,
292                    int m, double *dp_y, double **dpp_Y) {
293    printf("WARNING: Checkpointing algorithm not "
294           "implemented for the fov_forward mode!\n");
295    return 0;
296}
297
298int cp_hos_forward (int n, double *dp_x, double **dpp_X,
299                    int m, double *dp_y, double **dpp_Y) {
300    printf("WARNING: Checkpointing algorithm not "
301           "implemented for the hos_forward mode!\n");
302    return 0;
303}
304
305int cp_hov_forward (int n, double *dp_x, double ***dppp_X,
306                    int m, double *dp_y, double ***dppp_Y) {
307    printf("WARNING: Checkpointing algorithm not "
308           "implemented for the hov_forward mode!\n");
309    return 0;
310}
311
312int cp_fos_reverse (int m, double *dp_U, int n, double *dp_Z) {
313    ADOLC_OPENMP_THREAD_NUMBER;
314    ADOLC_OPENMP_GET_THREAD_NUMBER;
315    double *A = ADOLC_CURRENT_TAPE_INFOS.dp_A;
316    int oldTraceFlag;
317    locint arg;
318    CpInfos *cpInfos=get_cp_fct(ADOLC_CURRENT_TAPE_INFOS.cpIndex);
319    char old_bsw;
320
321    // note the mode
322    cpInfos->modeReverse = ADOLC_FOS_REVERSE;
323
324    cpInfos->dp_internal_for=new double[cpInfos->n];
325    cpInfos->dp_internal_rev=new double[cpInfos->n];
326
327    // taping "off"
328    oldTraceFlag=ADOLC_CURRENT_TAPE_INFOS.traceFlag;
329    ADOLC_CURRENT_TAPE_INFOS.traceFlag=0;
330
331    arg=ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev;
332    for (int i=0; i<cpInfos->n; ++i) {
333        cpInfos->dp_internal_rev[i]=A[arg];
334        ++arg;
335    }       
336    // update taylor buffer
337    for (int i = 0; i < cpInfos->n; ++i) {
338        --arg;
339        ADOLC_GET_TAYLOR(arg);
340    }
341    // execute second part of revolve_firstturn left from forward sweep
342    fos_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n,
343                cpInfos->dp_internal_rev, cpInfos->dp_internal_rev);
344
345    old_bsw = ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning;
346    ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = 0;
347    // checkpointing
348    enum revolve_action whattodo;
349    do {
350        whattodo=revolve(&cpInfos->check, &cpInfos->capo, &cpInfos->fine,
351                         cpInfos->checkpoints, &cpInfos->info);
352        switch (whattodo) {
353            case revolve_terminate:
354                break;
355            case revolve_takeshot:
356                cp_takeshot(cpInfos);
357                cpInfos->currentCP=cpInfos->capo;
358                break;
359            case revolve_advance:
360                for (int i=0; i<cpInfos->capo-cpInfos->currentCP; ++i)
361                    cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for);
362                break;
363            case revolve_youturn:
364                if (cpInfos->retaping != 0) cp_taping(cpInfos); // retaping forced
365                else {
366                    // one forward step with keep and retaping if necessary
367                    if (zos_forward(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, 1,
368                                    cpInfos->dp_internal_for, cpInfos->dp_internal_for) < 0)
369                        cp_taping(cpInfos);
370                }
371                // one reverse step
372                fos_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n,
373                            cpInfos->dp_internal_rev, cpInfos->dp_internal_rev);
374                break;
375            case revolve_restore:
376                if (cpInfos->capo!=cpInfos->currentCP) cp_release(cpInfos);
377                cpInfos->currentCP=cpInfos->capo;
378                cp_restore(cpInfos);
379                break;
380            case revolve_error:
381                revolveError(cpInfos);
382                break;
383            default:
384                fail(ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION);
385                break;
386        }
387    } while (whattodo!=revolve_terminate && whattodo!=revolve_error);
388    cp_release(cpInfos); // release first checkpoint if written
389    ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = old_bsw;
390
391    // save results
392    arg=ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev;
393    for (int i=0; i<cpInfos->n; ++i) {
394        A[arg]=cpInfos->dp_internal_rev[i];
395        ++arg;
396    }
397
398    // clean up
399    delete[] cpInfos->dp_internal_for;
400    cpInfos->dp_internal_for = NULL;
401    delete[] cpInfos->dp_internal_rev;
402    cpInfos->dp_internal_rev = NULL;
403
404    // taping "on"
405    ADOLC_CURRENT_TAPE_INFOS.traceFlag=oldTraceFlag;
406
407    return 0;
408}
409
410int cp_fov_reverse (int m, double **dpp_U, int n, double **dpp_Z) {
411    ADOLC_OPENMP_THREAD_NUMBER;
412    ADOLC_OPENMP_GET_THREAD_NUMBER;
413    double **A = ADOLC_CURRENT_TAPE_INFOS.dpp_A;
414    int oldTraceFlag, numDirs;
415    locint arg;
416    CpInfos *cpInfos = get_cp_fct(ADOLC_CURRENT_TAPE_INFOS.cpIndex);
417    char old_bsw;
418
419    // note the mode
420    cpInfos->modeReverse = ADOLC_FOV_REVERSE;
421
422    numDirs = ADOLC_CURRENT_TAPE_INFOS.numDirs_rev;
423    cpInfos->dp_internal_for = new double[cpInfos->n];
424    cpInfos->dpp_internal_rev = myalloc2(numDirs, cpInfos->n);
425
426    // taping "off"
427    oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag;
428    ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0;
429
430    arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev;
431    for (int i = 0; i < cpInfos->n; ++i) {
432        for (int j = 0; j < numDirs; ++j) {
433            cpInfos->dpp_internal_rev[j][i] = A[arg][j];
434        }
435        ++arg;
436    }
437    // update taylor buffer
438    for (int i = 0; i < cpInfos->n; ++i) {
439        --arg;
440        ADOLC_GET_TAYLOR(arg);
441    }
442    // execute second part of revolve_firstturn left from forward sweep
443    fov_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, numDirs,
444                cpInfos->dpp_internal_rev, cpInfos->dpp_internal_rev);
445
446    old_bsw = ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning;
447    ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = 0;
448    // checkpointing
449    enum revolve_action whattodo;
450    do {
451        whattodo=revolve(&cpInfos->check, &cpInfos->capo, &cpInfos->fine,
452                         cpInfos->checkpoints, &cpInfos->info);
453        switch (whattodo) {
454            case revolve_terminate:
455                break;
456            case revolve_takeshot:
457                cp_takeshot(cpInfos);
458                cpInfos->currentCP = cpInfos->capo;
459                break;
460            case revolve_advance:
461                for (int i = 0; i < cpInfos->capo - cpInfos->currentCP; ++i)
462                    cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for);
463                break;
464            case revolve_youturn:
465                if (cpInfos->retaping != 0) cp_taping(cpInfos); // retaping forced
466                else {
467                    // one forward step with keep and retaping if necessary
468                    if (zos_forward(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, 1,
469                                    cpInfos->dp_internal_for, cpInfos->dp_internal_for) < 0)
470                        cp_taping(cpInfos);
471                }
472                // one reverse step
473                fov_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, numDirs,
474                            cpInfos->dpp_internal_rev, cpInfos->dpp_internal_rev);
475                break;
476            case revolve_restore:
477                if (cpInfos->capo != cpInfos->currentCP) cp_release(cpInfos);
478                cpInfos->currentCP = cpInfos->capo;
479                cp_restore(cpInfos);
480                break;
481            case revolve_error:
482                revolveError(cpInfos);
483                break;
484            default:
485                fail(ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION);
486                break;
487        }
488    } while (whattodo != revolve_terminate && whattodo != revolve_error);
489    cp_release(cpInfos); // release first checkpoint if written
490    ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = old_bsw;
491
492    // save results
493    arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev;
494    for (int i = 0; i < cpInfos->n; ++i) {
495        for (int j = 0; j < numDirs; ++j) {
496            A[arg][j] = cpInfos->dpp_internal_rev[j][i];
497        }
498        ++arg;
499    }
500
501    // clean up
502    delete[] cpInfos->dp_internal_for;
503    cpInfos->dp_internal_for = NULL;
504    myfree2(cpInfos->dpp_internal_rev);
505    cpInfos->dpp_internal_rev = NULL;
506
507    // taping "on"
508    ADOLC_CURRENT_TAPE_INFOS.traceFlag=oldTraceFlag;
509
510    return 0;
511}
512
513int cp_hos_reverse (int m, double *dp_U, int n, double **dpp_Z) {
514    printf("WARNING: Checkpointing algorithm not "
515           "implemented for the hos_reverse mode!\n");
516    return 0;
517}
518
519int cp_hov_reverse (int m, double **dpp_U, int n, double ***dppp_Z,
520                    short **spp_nz) {
521    printf("WARNING: Checkpointing algorithm not "
522           "implemented for the hov_reverse mode!\n");
523    return 0;
524}
525
526/****************************************************************************/
527/*                              functions for handling the checkpoint stack */
528/****************************************************************************/
529
530void cp_clearStack() {
531    StackElement se;
532    ADOLC_OPENMP_THREAD_NUMBER;
533    ADOLC_OPENMP_GET_THREAD_NUMBER;
534
535    while (!ADOLC_CHECKPOINTS_STACK.empty()) {
536        se = ADOLC_CHECKPOINTS_STACK.top();
537        ADOLC_CHECKPOINTS_STACK.pop();
538        delete[] se[0];
539        delete[] se;
540    }
541}
542
543void cp_takeshot (CpInfos *cpInfos) {
544    ADOLC_OPENMP_THREAD_NUMBER;
545    ADOLC_OPENMP_GET_THREAD_NUMBER;
546
547    StackElement se = new double *[2];
548    ADOLC_CHECKPOINTS_STACK.push(se);
549    se[0] = new double[cpInfos->n];
550    for (int i = 0; i < cpInfos->n; ++i)
551        se[0][i] = cpInfos->dp_internal_for[i];
552    if (cpInfos->saveNonAdoubles != NULL)
553        se[1] = static_cast<double *>(cpInfos->saveNonAdoubles());
554    else
555        se[1] = NULL;
556}
557
558void cp_restore (CpInfos *cpInfos) {
559    ADOLC_OPENMP_THREAD_NUMBER;
560    ADOLC_OPENMP_GET_THREAD_NUMBER;
561
562    StackElement se = ADOLC_CHECKPOINTS_STACK.top();
563    for (int i = 0; i < cpInfos->n; ++i)
564        cpInfos->dp_internal_for[i] = se[0][i];
565    if (se[1] != NULL)
566        cpInfos->restoreNonAdoubles(static_cast<void *>(se[1]));
567}
568
569void cp_release (CpInfos *cpInfos) {
570    ADOLC_OPENMP_THREAD_NUMBER;
571    ADOLC_OPENMP_GET_THREAD_NUMBER;
572
573    if (!ADOLC_CHECKPOINTS_STACK.empty()) {
574        StackElement se = ADOLC_CHECKPOINTS_STACK.top();
575        ADOLC_CHECKPOINTS_STACK.pop();
576        delete[] se[0];
577        if (se[1] != NULL)
578            delete[] se[1];
579        delete[] se;
580    }
581}
582
583void cp_taping(CpInfos *cpInfos) {
584    adouble *tapingAdoubles = new adouble[cpInfos->n];
585
586    trace_on(cpInfos->tapeNumber, 1);
587
588    for (int i = 0; i < cpInfos->n; ++i)
589        tapingAdoubles[i] <<= cpInfos->dp_internal_for[i];
590
591    cpInfos->function(cpInfos->n, tapingAdoubles);
592
593    for (int i = 0; i < cpInfos->n; ++i)
594        tapingAdoubles[i] >>= cpInfos->dp_internal_for[i];
595
596    trace_off();
597
598    delete[] tapingAdoubles;
599}
600
601/****************************************************************************/
602/*                                                   revolve error function */
603/****************************************************************************/
604void revolveError (CpInfos *cpInfos) {
605    switch(cpInfos->info) {
606        case 10:
607            printf("   Number of checkpoints stored exceeds "
608                   "checkup!\n   Increase constant 'checkup' "
609                   "and recompile!\n");
610            break;
611        case 11:
612            printf("   Number of checkpoints stored = %d exceeds "
613                   "snaps = %d!\n   Ensure 'snaps' > 0 and increase "
614                   "initial 'fine'!\n", cpInfos->check+1,
615                   cpInfos->checkpoints);
616            break;
617        case 12:
618            printf("   Error occured in numforw!\n");
619            break;
620        case 13:
621            printf("   Enhancement of 'fine', 'snaps' checkpoints "
622                   "stored!\n   Increase 'snaps'!\n");
623            break;
624        case 14:
625            printf("   Number of snaps exceeds checkup!\n   Increase "
626                   "constant 'checkup' and recompile!\n");
627            break;
628        case 15:
629            printf("   Number of reps exceeds repsup!\n   Increase "
630                   "constant 'repsup' and recompile!\n");
631            break;
632    }
633    fail(ADOLC_CHECKPOINTING_REVOLVE_IRREGULAR_TERMINATED);
634}
635
Note: See TracBrowser for help on using the repository browser.