source: stable/2.4/ADOL-C/src/checkpointing.cpp @ 397

Last change on this file since 397 was 370, checked in by kulshres, 7 years ago

Merge branch '2.3.x_ISSM' into svn

This introduces the new externally differentiated functions API

From: Jean Utke <utke@…>

Please see comments in ADOL-C/include/adolc/externfcts.h for details

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

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