1 /*---------------------------------------------------------------------------- 2 ADOL-C -- Automatic Differentiation by Overloading in C++ 3 File: taping_p.h 4 Revision: $Id: taping_p.h 760 2018-09-10 11:02:03Z kulshres $ 5 Contents: declarations for used by taping routines 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 #if !defined(ADOLC_TAPING_P_H) 15 #define ADOLC_TAPING_P_H 1 16 17 #ifdef __cplusplus 18 #include "storemanager.h" 19 #endif 20 #include <adolc/internal/common.h> 21 #include <adolc/taping.h> 22 #include <errno.h> 23 24 BEGIN_C_DECLS 25 26 enum WORKMODES { 27 ADOLC_NO_MODE, 28 29 ADOLC_FORWARD, 30 ADOLC_ZOS_FORWARD, 31 ADOLC_FOS_FORWARD, 32 ADOLC_FOV_FORWARD, 33 ADOLC_HOS_FORWARD, 34 ADOLC_HOV_FORWARD, 35 36 ADOLC_REVERSE, 37 ADOLC_FOS_REVERSE, 38 ADOLC_FOV_REVERSE, 39 ADOLC_HOS_REVERSE, 40 ADOLC_HOV_REVERSE, 41 42 ADOLC_TAPING 43 }; 44 45 /****************************************************************************/ 46 /* Tape identification (ADOLC & version check) */ 47 /****************************************************************************/ 48 typedef struct { 49 short adolc_ver; 50 short adolc_sub; 51 short adolc_lvl; 52 short locint_size; 53 short revreal_size; 54 short address_size; 55 } 56 ADOLC_ID; 57 58 extern ADOLC_ID adolc_id; 59 60 /****************************************************************************/ 61 /* tape types => used for file name generation */ 62 /****************************************************************************/ 63 enum TAPENAMES { 64 LOCATIONS_TAPE, 65 VALUES_TAPE, 66 OPERATIONS_TAPE, 67 TAYLORS_TAPE 68 }; 69 70 /****************************************************************************/ 71 /* Errors handled by fail(...) */ 72 /****************************************************************************/ 73 enum ADOLC_ERRORS { 74 ADOLC_MALLOC_FAILED, 75 ADOLC_INTEGER_TAPE_FOPEN_FAILED, 76 ADOLC_INTEGER_TAPE_FREAD_FAILED, 77 ADOLC_VALUE_TAPE_FOPEN_FAILED, 78 ADOLC_VALUE_TAPE_FREAD_FAILED, 79 ADOLC_TAPE_TO_OLD, 80 ADOLC_WRONG_LOCINT_SIZE, 81 ADOLC_MORE_STAT_SPACE_REQUIRED, 82 83 ADOLC_TAPING_BUFFER_ALLOCATION_FAILED, 84 ADOLC_TAPING_TBUFFER_ALLOCATION_FAILED, 85 ADOLC_TAPING_READ_ERROR_IN_TAYLOR_CLOSE, 86 ADOLC_TAPING_TO_MANY_TAYLOR_BUFFERS, 87 ADOLC_TAPING_TO_MANY_LOCINTS, 88 ADOLC_TAPING_STORE_REALLOC_FAILED, 89 ADOLC_TAPING_FATAL_IO_ERROR, 90 ADOLC_TAPING_TAPE_STILL_IN_USE, 91 ADOLC_TAPING_TAYLOR_OPEN_FAILED, 92 93 ADOLC_EVAL_SEEK_VALUE_STACK, 94 ADOLC_EVAL_OP_TAPE_READ_FAILED, 95 ADOLC_EVAL_VAL_TAPE_READ_FAILED, 96 ADOLC_EVAL_LOC_TAPE_READ_FAILED, 97 ADOLC_EVAL_TAY_TAPE_READ_FAILED, 98 99 ADOLC_REVERSE_NO_TAYLOR_STACK, 100 ADOLC_REVERSE_COUNTS_MISMATCH, 101 ADOLC_REVERSE_TAYLOR_COUNTS_MISMATCH, 102 103 ADOLC_BUFFER_NULLPOINTER_FUNCTION, 104 ADOLC_BUFFER_INDEX_TO_LARGE, 105 106 ADOLC_EXT_DIFF_NULLPOINTER_STRUCT, 107 ADOLC_EXT_DIFF_WRONG_TAPESTATS, 108 ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION, 109 ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC, 110 ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT, 111 ADOLC_EXT_DIFF_WRONG_FUNCTION_INDEX, 112 ADOLC_EXT_DIFF_LOCATIONGAP, 113 114 ADOLC_CHECKPOINTING_CPINFOS_NULLPOINTER, 115 ADOLC_CHECKPOINTING_NULLPOINTER_ARGUMENT, 116 ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION, 117 ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION_DOUBLE, 118 ADOLC_CHECKPOINTING_REVOLVE_IRREGULAR_TERMINATED, 119 ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION, 120 ADOLC_WRONG_PLATFORM_32, 121 ADOLC_WRONG_PLATFORM_64, 122 ADOLC_TAPING_NOT_ACTUALLY_TAPING, 123 ADOLC_VEC_LOCATIONGAP 124 }; 125 /* additional infos fail can work with */ 126 extern int failAdditionalInfo1; 127 extern int failAdditionalInfo2; 128 extern locint failAdditionalInfo3; 129 extern locint failAdditionalInfo4; 130 extern void *failAdditionalInfo5; 131 extern void *failAdditionalInfo6; 132 133 /****************************************************************************/ 134 /* tape information */ 135 /****************************************************************************/ 136 137 #ifdef SPARSE 138 typedef struct SparseJacInfos { 139 void *g; 140 void *jr1d; 141 142 double *y; 143 double **Seed; 144 double **B; 145 146 unsigned int **JP; 147 148 int depen, nnz_in, seed_clms, seed_rows; 149 } SparseJacInfos; 150 151 typedef struct SparseHessInfos { 152 void *g; 153 void *hr; 154 155 double **Hcomp; 156 double*** Xppp; 157 double*** Yppp; 158 double*** Zppp; 159 double** Upp; 160 161 unsigned int **HP; 162 163 int nnz_in, indep, p; 164 } SparseHessInfos; 165 #endif 166 167 typedef struct PersistantTapeInfos { /* survive tape re-usage */ 168 int forodec_nax, forodec_dax; 169 double *forodec_y, *forodec_z, **forodec_Z; 170 double **jacSolv_J; 171 double **jacSolv_I; 172 double *jacSolv_xold; 173 int *jacSolv_ri; 174 int *jacSolv_ci; 175 int jacSolv_nax, jacSolv_modeold, jacSolv_cgd; 176 177 #ifdef SPARSE 178 /* sparse Jacobian matrices */ 179 180 SparseJacInfos sJinfos; 181 182 /* sparse Hessian matrices */ 183 184 SparseHessInfos sHinfos; 185 #endif 186 187 /* file names */ 188 189 char *op_fileName; 190 char *loc_fileName; 191 char *val_fileName; 192 char *tay_fileName; 193 194 int keepTape; /* - remember if tapes shall be written out to disk 195 - this information can only be given at taping time and 196 must survive all other actions on the tape */ 197 198 /** 199 * defaults to 0, if 1 skips file removal (when file operations are costly) 200 */ 201 int skipFileCleanup; 202 203 revreal *paramstore; 204 #ifdef __cplusplus 205 PersistantTapeInfos(); 206 ~PersistantTapeInfos(); 207 void copy(const PersistantTapeInfos&); 208 #endif 209 } PersistantTapeInfos; 210 211 /** 212 * maximal number of locations writen per op code 213 */ 214 #if defined(__USE_ISOC99) 215 extern const int maxLocsPerOp; 216 #else 217 #define maxLocsPerOp 10 218 #endif 219 220 typedef struct TapeInfos { 221 short tapeID; 222 int inUse; 223 uint numInds; 224 uint numDeps; 225 int keepTaylors; /* == 1 - write taylor stack in taping mode */ 226 size_t stats[STAT_SIZE]; 227 int traceFlag; 228 char tapingComplete; 229 230 /* operations tape */ 231 FILE *op_file; /* file descriptor */ 232 unsigned char *opBuffer; /* pointer to the current tape buffer */ 233 unsigned char *currOp; /* pointer to the current opcode */ 234 unsigned char *lastOpP1; /* pointer to element following the buffer */ 235 size_t numOps_Tape; /* overall number of opcodes */ 236 size_t num_eq_prod; /* overall number of eq_*_prod for nlf */ 237 238 /* values (real) tape */ 239 FILE *val_file; 240 double *valBuffer; 241 double *currVal; 242 double *lastValP1; 243 size_t numVals_Tape; 244 245 /* locations tape */ 246 FILE *loc_file; 247 locint *locBuffer; 248 locint *currLoc; 249 locint *lastLocP1; 250 size_t numLocs_Tape; 251 252 /* taylor stack tape */ 253 FILE *tay_file; 254 revreal *tayBuffer; 255 revreal *currTay; 256 revreal *lastTayP1; 257 size_t numTays_Tape; 258 int nextBufferNumber; /* the next Buffer to read back */ 259 char lastTayBlockInCore; /* == 1 if last taylor buffer is still in 260 in core (first call of reverse) */ 261 double **T_for; /* derivative buffer - forward */ 262 uint deg_save; /* degree to save and saved respectively */ 263 uint tay_numInds; /* # of independents for the taylor stack */ 264 uint tay_numDeps; /* # of dependents for the taylor stack */ 265 266 /* checkpointing */ 267 locint lowestXLoc_for; /* location of the first ind. - forward mode */ 268 locint lowestYLoc_for; /* location of the first dep. - forward mode */ 269 locint lowestXLoc_rev; /* location of the first ind. - reverse mode */ 270 locint lowestYLoc_rev; /* location of the first dep. - reverse mode */ 271 locint cpIndex; /* index of the curr. cp function <- tape */ 272 int numDirs_rev; /* # of directions for **v_reverse (checkpointing) */ 273 274 locint *lowestXLoc_ext_v2; 275 locint *lowestYLoc_ext_v2; 276 277 /* evaluation forward */ 278 double *dp_T0; 279 int gDegree, numTay; 280 enum WORKMODES workMode; 281 /* 282 * Taylor coefficient array allocated like this: 283 * dpp_T[ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES][numTay*gDegree] 284 */ 285 double **dpp_T; 286 287 /* evaluation reverse */ 288 revreal *rp_T; 289 revreal **rpp_T; 290 revreal *rp_A; 291 revreal **rpp_A; 292 unsigned long int **upp_A; 293 294 /* extern diff. fcts */ 295 locint ext_diff_fct_index; /* set by forward and reverse (from tape) */ 296 char in_nested_ctx; 297 298 size_t numSwitches; 299 locint* switchlocs; 300 double* signature; 301 302 PersistantTapeInfos pTapeInfos; 303 304 #if defined(__cplusplus) 305 TapeInfos(); 306 TapeInfos(short tapeID); ~TapeInfosTapeInfos307 ~TapeInfos() {} 308 void copy(const TapeInfos&); 309 #endif 310 } 311 TapeInfos; 312 313 typedef struct GlobalTapeVarsCL { 314 double* store; /* double store for calc. while taping */ 315 #if defined(ADOLC_TRACK_ACTIVITY) 316 char* actStore; /* activity store for tracking while taping */ 317 #endif 318 size_t storeSize; 319 size_t numLives; 320 locint maxLoc; 321 322 locint operationBufferSize; /* Defaults to the value specified in */ 323 locint locationBufferSize; /* usrparms.h. May be overwritten by values */ 324 locint valueBufferSize; /* in a local config file .adolcrc. */ 325 locint taylorBufferSize; 326 int maxNumberTaylorBuffers; 327 328 char inParallelRegion; /* set to 1 if in an OpenMP parallel region */ 329 char newTape; /* signals: at least one tape created (0/1) */ 330 char branchSwitchWarning; 331 TapeInfos *currentTapeInfosPtr; 332 uint nominmaxFlag; 333 size_t numparam; 334 size_t maxparam; 335 double *pStore; 336 size_t initialStoreSize; 337 #ifdef __cplusplus 338 StoreManager *paramStoreMgrPtr; 339 StoreManager *storeManagerPtr; 340 GlobalTapeVarsCL(); 341 ~GlobalTapeVarsCL(); 342 const GlobalTapeVarsCL& operator=(const GlobalTapeVarsCL&); 343 void reallocStore(unsigned char type); 344 #else 345 void *paramStoreMgrPtr; 346 void *storeManagerPtr; 347 #endif 348 } 349 GlobalTapeVars; 350 351 #if defined(_OPENMP) 352 353 extern int isParallel(); 354 355 #define ADOLC_TAPE_INFOS_BUFFER_DECL *tapeInfosBuffer 356 #define ADOLC_TAPE_STACK_DECL *tapeStack 357 #define ADOLC_CURRENT_TAPE_INFOS_DECL *currentTapeInfos 358 #define ADOLC_CURRENT_TAPE_INFOS_FALLBACK_DECL *currentTapeInfos_fallBack 359 #define ADOLC_GLOBAL_TAPE_VARS_DECL *globalTapeVars 360 #define ADOLC_EXT_DIFF_FCTS_BUFFER_DECL *ADOLC_extDiffFctsBuffer 361 #define ADOLC_CHECKPOINTS_STACK_DECL *ADOLC_checkpointsStack 362 363 #define ADOLC_OPENMP_THREAD_NUMBER int ADOLC_threadNumber 364 #if defined(ADOLC_THREADSAVE_ERRNO) 365 #define ADOLC_OPENMP_GET_THREAD_NUMBER ADOLC_threadNumber = errno 366 #define ADOLC_OPENMP_RESTORE_THREAD_NUMBER errno = ADOLC_threadNumber 367 #else 368 #define ADOLC_OPENMP_GET_THREAD_NUMBER ADOLC_threadNumber = omp_get_thread_num() 369 #define ADOLC_OPENMP_RESTORE_THREAD_NUMBER 370 #endif 371 372 #define ADOLC_TAPE_INFOS_BUFFER tapeInfosBuffer[ADOLC_threadNumber] 373 #define ADOLC_TAPE_STACK tapeStack[ADOLC_threadNumber] 374 #define ADOLC_CURRENT_TAPE_INFOS currentTapeInfos[ADOLC_threadNumber] 375 #define ADOLC_CURRENT_TAPE_INFOS_FALLBACK currentTapeInfos_fallBack[ADOLC_threadNumber] 376 #define ADOLC_GLOBAL_TAPE_VARS globalTapeVars[ADOLC_threadNumber] 377 #define ADOLC_EXT_DIFF_FCTS_BUFFER ADOLC_extDiffFctsBuffer[ADOLC_threadNumber] 378 #define ADOLC_CHECKPOINTS_STACK ADOLC_checkpointsStack[ADOLC_threadNumber] 379 #define REVOLVE_NUMBERS revolve_numbers[ADOLC_threadNumber] 380 381 #else 382 383 #define ADOLC_TAPE_INFOS_BUFFER_DECL tapeInfosBuffer 384 #define ADOLC_TAPE_STACK_DECL tapeStack 385 #define ADOLC_CURRENT_TAPE_INFOS_DECL currentTapeInfos 386 #define ADOLC_CURRENT_TAPE_INFOS_FALLBACK_DECL currentTapeInfos_fallBack 387 #define ADOLC_GLOBAL_TAPE_VARS_DECL globalTapeVars 388 #define ADOLC_EXT_DIFF_FCTS_BUFFER_DECL ADOLC_extDiffFctsBuffer 389 #define ADOLC_CHECKPOINTS_STACK_DECL ADOLC_checkpointsStack 390 391 #define ADOLC_OPENMP_THREAD_NUMBER 392 #define ADOLC_OPENMP_GET_THREAD_NUMBER 393 #define ADOLC_OPENMP_RESTORE_THREAD_NUMBER 394 395 #define ADOLC_TAPE_INFOS_BUFFER tapeInfosBuffer 396 #define ADOLC_TAPE_STACK tapeStack 397 #define ADOLC_CURRENT_TAPE_INFOS currentTapeInfos 398 #define ADOLC_CURRENT_TAPE_INFOS_FALLBACK currentTapeInfos_fallBack 399 #define ADOLC_GLOBAL_TAPE_VARS globalTapeVars 400 #define ADOLC_EXT_DIFF_FCTS_BUFFER ADOLC_extDiffFctsBuffer 401 #define ADOLC_CHECKPOINTS_STACK ADOLC_checkpointsStack 402 #define REVOLVE_NUMBERS revolve_numbers 403 404 #endif /* _OPENMP */ 405 406 extern TapeInfos ADOLC_CURRENT_TAPE_INFOS_DECL; 407 extern TapeInfos ADOLC_CURRENT_TAPE_INFOS_FALLBACK_DECL; 408 extern GlobalTapeVars ADOLC_GLOBAL_TAPE_VARS_DECL; 409 410 /****************************************************************************/ 411 /* C Function interfaces */ 412 /****************************************************************************/ 413 414 int initNewTape(short tapeID); 415 /* initializes a new tape 416 * - returns 0 on success 417 * - returns 1 in case tapeID is already/still in use */ 418 419 void openTape(short tapeID, char mode); 420 /* opens an existing tape or creates a new one */ 421 422 void releaseTape(); 423 /* release the current tape and give control to the previous one 424 * if keepVS is not zero (keep value stack for reverse) => belonging TapeInfos 425 * are kept marked as being in use */ 426 427 TapeInfos *getTapeInfos(short tapeID); 428 /* updates the tape infos for the given ID - a tapeInfos struct is created 429 * and registered if non is found but its state will remain "not in use" */ 430 431 #ifdef SPARSE 432 void setTapeInfoJacSparse(short tapeID, SparseJacInfos sJinfos); 433 /* updates the tape infos on sparse Jac for the given ID */ 434 435 void setTapeInfoHessSparse(short tapeID, SparseHessInfos sHinfos); 436 /* updates the tape infos n sparse Hess for the given ID */ 437 #endif 438 439 void take_stock(); 440 /* record all existing adoubles on the tape 441 * - intended to be used in start_trace only */ 442 443 locint keep_stock(); 444 /* record all remaining live variables on the value stack tape 445 * - turns off trace_flag 446 * - intended to be used in stop_trace only */ 447 448 void updateLocs(); 449 450 locint next_loc(); 451 /* returns the next free location in "adouble" memory */ 452 453 void free_loc(locint loc); 454 /* frees the specified location in "adouble" memory */ 455 456 void taylor_begin(uint bufferSize, int degreeSave); 457 /* set up statics for writing taylor data */ 458 459 void taylor_close(uint buffer); 460 /* close taylor file if necessary and refill buffer if possible */ 461 462 void taylor_back(short tag, int* dep, int* ind, int* degree); 463 /* initializes a reverse sweep */ 464 465 void write_taylor(locint loc, int keep); 466 /* writes the block of size depth of taylor coefficients from point loc to 467 * the taylor buffer, if the buffer is filled, then it is written to the 468 * taylor tape */ 469 470 void write_taylors(locint loc, int keep, int degree, int numDir); 471 /* writes the block of size depth of taylor coefficients from point loc to 472 * the taylor buffer, if the buffer is filled, then it is written to the 473 * taylor tape */ 474 475 #define ADOLC_WRITE_SCAYLOR(X) \ 476 {\ 477 if (ADOLC_CURRENT_TAPE_INFOS.currTay == ADOLC_CURRENT_TAPE_INFOS.lastTayP1)\ 478 put_tay_block(ADOLC_CURRENT_TAPE_INFOS.lastTayP1);\ 479 *ADOLC_CURRENT_TAPE_INFOS.currTay = (X);\ 480 ++ADOLC_CURRENT_TAPE_INFOS.currTay;\ 481 } 482 /* writes a single element (x) to the taylor buffer and writes the buffer to 483 * disk if necessary */ 484 485 void write_scaylors(revreal *x, uint size); 486 /* write_scaylors writes # size elements from x to the taylor buffer */ 487 488 #define ADOLC_OVERWRITE_SCAYLOR(X,Y) \ 489 {\ 490 *Y = *(ADOLC_CURRENT_TAPE_INFOS.currTay - 1);\ 491 *(ADOLC_CURRENT_TAPE_INFOS.currTay - 1) = X;\ 492 } 493 /* overwrites the last (single) element (x) of the taylor buffer */ 494 495 #define ADOLC_DELETE_SCAYLOR(X) \ 496 {\ 497 --ADOLC_CURRENT_TAPE_INFOS.currTay;\ 498 *X = *ADOLC_CURRENT_TAPE_INFOS.currTay;\ 499 } 500 /* deletes the last (single) element (x) of the taylor buffer */ 501 502 void put_tay_block(revreal *lastValP1); 503 /* writes the taylor stack buffer onto hard disk */ 504 505 #define ADOLC_GET_TAYLOR(X) \ 506 {\ 507 if (ADOLC_CURRENT_TAPE_INFOS.currTay == ADOLC_CURRENT_TAPE_INFOS.tayBuffer)\ 508 get_tay_block_r();\ 509 --ADOLC_CURRENT_TAPE_INFOS.currTay;\ 510 ADOLC_CURRENT_TAPE_INFOS.rp_T[X] = *ADOLC_CURRENT_TAPE_INFOS.currTay;\ 511 } 512 /* puts a taylor value from the value stack buffer to the taylor buffer */ 513 514 void get_taylors(locint loc, int degree); 515 /* puts a block of taylor coefficients from the value stack buffer to the 516 * taylor buffer --- Higher Order Scalar */ 517 518 void get_taylors_p(locint loc, int degree, int numDir); 519 /* puts a block of taylor coefficients from the value stack buffer to the 520 * taylor buffer --- Higher Order Vector */ 521 522 void get_tay_block_r(); 523 /* gets the next (previous block) of the value stack */ 524 525 526 527 void initTapeBuffers(); 528 /* free/allocate memory for buffers, initialize pointers */ 529 530 void start_trace(); 531 /* initialization for the taping process -> buffer allocation, sets 532 * files names, and calls appropriate setup routines */ 533 534 void stop_trace(int flag); 535 /* stop Tracing, clean up, and turn off trace_flag */ 536 537 void close_tape(int flag); 538 /* close open tapes, update stats and clean up */ 539 540 void freeTapeResources(TapeInfos *tapeInfos); 541 /* free all resources used by a tape before overwriting the tape */ 542 543 void read_tape_stats(TapeInfos *tapeInfos); 544 /* does the actual reading from the hard disk into the stats buffer */ 545 546 void init_for_sweep(short tag); 547 /* initialize a forward sweep, get stats, open tapes, fill buffers, ... */ 548 549 void init_rev_sweep(short tag); 550 /* initialize a reverse sweep, get stats, open tapes, fill buffers, ... */ 551 552 void end_sweep(); 553 /* finish a forward or reverse sweep */ 554 555 556 557 void fail(int error); 558 /* outputs an appropriate error message using DIAG_OUT and exits the running 559 * program */ 560 561 /* print an error message describing the error number */ 562 void printError(); 563 564 char *createFileName(short tapeID, int tapeType); 565 /* create file name depending on tape type and number */ 566 567 568 569 /* puts an operation into the operation buffer, ensures that location buffer 570 * and constants buffer are prepared to take the belonging stuff */ 571 void put_op_reserve(unsigned char op, unsigned int reserveExtraLocations); 572 #define put_op(i) put_op_reserve((i),0) 573 574 void put_op_block(unsigned char *lastOpP1); 575 /* writes a block of operations onto hard disk and handles file creation, 576 * removal, ... */ 577 578 void get_op_block_f(); 579 /* reads the next operations block into the internal buffer */ 580 581 void get_op_block_r(); 582 /* reads the previous block of operations into the internal buffer */ 583 584 #define ADOLC_PUT_LOCINT(X) \ 585 {\ 586 *ADOLC_CURRENT_TAPE_INFOS.currLoc = X;\ 587 ++ADOLC_CURRENT_TAPE_INFOS.currLoc;\ 588 } 589 /* puts a single locations into the location buffer, no disk access */ 590 591 void put_loc_block(locint *lastLocP1); 592 /* writes a block of locations onto hard disk and handles file creation, 593 * removal, ... */ 594 595 void get_loc_block_f(); 596 /* reads the next block of locations into the internal buffer */ 597 598 void get_loc_block_r(); 599 /* reads the previous block of locations into the internal buffer */ 600 601 #define ADOLC_PUT_VAL(X) \ 602 {\ 603 *ADOLC_CURRENT_TAPE_INFOS.currVal = X;\ 604 ++ADOLC_CURRENT_TAPE_INFOS.currVal;\ 605 } 606 /* puts a single constant into the location buffer, no disk access */ 607 608 void put_vals_writeBlock(double *reals, locint numReals); 609 /* fill the constants buffer and write it to disk */ 610 611 void put_vals_notWriteBlock(double *reals, locint numReals); 612 /* write some constants to the buffer without disk access */ 613 614 void put_val_block(double *lastValP1); 615 /* writes a block of constants (real) onto hard disk and handles file 616 * creation, removal, ... */ 617 618 void get_val_block_f(); 619 /* reads the next block of constants into the internal buffer */ 620 621 void get_val_block_r(); 622 /* reads the previous block of constants into the internal buffer */ 623 624 locint get_val_space(void); 625 /* returns the number of free constants in the real tape, ensures that it 626 * is at least 5 */ 627 628 double *get_val_v_f(locint size); 629 /* return a pointer to the first element of a constants vector 630 * -- Forward Mode -- */ 631 632 double *get_val_v_r(locint size); 633 /* return a pointer to the first element of a constants vector 634 * -- Reverse Mode -- */ 635 636 637 638 /* suspicious function, maybe for vector class - kept for compatibility */ 639 void reset_val_r(); 640 641 /* updates */ 642 int upd_resloc(locint temp, locint lhs); 643 644 int upd_resloc_check(locint temp, locint lhs); 645 646 int upd_resloc_inc_prod(locint temp, locint newlhs, unsigned char newop); 647 648 /* special IEEE values */ 649 double make_nan(); 650 651 double make_inf(); 652 653 654 655 #if !defined(ADOLC_HARDDEBUG) 656 /*--------------------------------------------------------------------------*/ 657 /* MACRO or FUNCTION */ 658 #define get_op_f() *ADOLC_CURRENT_TAPE_INFOS.currOp++ 659 #define get_op_r() *--ADOLC_CURRENT_TAPE_INFOS.currOp 660 661 #define get_locint_f() *ADOLC_CURRENT_TAPE_INFOS.currLoc++ 662 #define get_locint_r() *--ADOLC_CURRENT_TAPE_INFOS.currLoc 663 664 #define get_val_f() *ADOLC_CURRENT_TAPE_INFOS.currVal++ 665 #define get_val_r() *--ADOLC_CURRENT_TAPE_INFOS.currVal 666 #else /* HARDDEBUG */ 667 unsigned char get_op_f(); 668 unsigned char get_op_r(); 669 670 locint get_locint_f(); 671 locint get_locint_r(); 672 673 double get_val_f(); 674 double get_val_r(); 675 #endif 676 677 /* tries to read a local config file containing, e.g., buffer sizes */ 678 void readConfigFile(); 679 680 void checkInitialStoreSize(GlobalTapeVars *gtv); 681 682 /* clear the tapeBaseNames that were alocated above in readConfigFile() */ 683 void clearTapeBaseNames(); 684 685 /****************************************************************************/ 686 /* This function sets the flag "newTape" if either a taylor buffer has been */ 687 /* created or a taping process has been performed. Calling the function is */ 688 /* also useful to "convince" the linker of including the cleaner part into */ 689 /* the binary when linking statically! */ 690 /****************************************************************************/ 691 void markNewTape(); 692 693 /****************************************************************************/ 694 /* Allows us to throw an exception instead of calling exit() in case of a */ 695 /* irrecoverable error */ 696 /****************************************************************************/ 697 void adolc_exit(int errorcode, const char *what, const char *function, const char* file, int line); 698 699 /****************************************************************************/ 700 /* Discards parameters from the end of value tape during reverse mode */ 701 /****************************************************************************/ 702 void discard_params_r(); 703 704 /****************************************************************************/ 705 /* Frees parameter indices after taping is complete */ 706 /****************************************************************************/ 707 void free_all_taping_params(); 708 709 END_C_DECLS 710 711 /****************************************************************************/ 712 /* That's all */ 713 /****************************************************************************/ 714 715 #endif /* ADOLC_TAPING_P_H */ 716 717 718