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

Last change on this file since 708 was 704, checked in by kulshres, 3 years ago

spelling

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