Changeset 197


Ignore:
Timestamp:
Feb 9, 2011 11:26:49 AM (9 years ago)
Author:
kulshres
Message:

New memory management using a pool-allocator

See comments at the top of storemanager.hh

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

Location:
trunk/ADOL-C/src
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/ADOL-C/src/adouble.cpp

    r168 r197  
    156156/*                                                              DESTRUCTORS */
    157157
    158 #define ADOLC_FREE_LOC(X) \
    159     {\
    160         ADOLC_OPENMP_THREAD_NUMBER;\
    161         ADOLC_OPENMP_GET_THREAD_NUMBER;\
    162         ++ADOLC_GLOBAL_TAPE_VARS.numToFree;\
    163         if (X < ADOLC_GLOBAL_TAPE_VARS.minLocToFree)\
    164             ADOLC_GLOBAL_TAPE_VARS.minLocToFree = X;\
    165     }
    166 
    167158/*--------------------------------------------------------------------------*/
    168159adouble::~adouble() {
    169160#ifdef overwrite
    170     ADOLC_FREE_LOC(location);
     161    new_free_loc(location);
    171162#endif
    172163}
     
    175166adub::~adub() {
    176167#ifdef overwrite
    177     ADOLC_FREE_LOC(location);
     168    new_free_loc(location);
    178169#endif
    179170}
     
    341332        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
    342333            ADOLC_OVERWRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location],&ADOLC_GLOBAL_TAPE_VARS.store[a_loc]);
    343         if (a_loc == ADOLC_GLOBAL_TAPE_VARS.locMinUnused-1) {
    344             ADOLC_GLOBAL_TAPE_VARS.locMinUnused--;     // The temporary will die in a minute and
    345             ADOLC_GLOBAL_TAPE_VARS.numToFree--;         // by reducing dealloc and current_top
    346         }                    // we neutralize that effect
    347334        ADOLC_GLOBAL_TAPE_VARS.store[location] = tempVal;
    348335    } else {
     
    589576        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
    590577            ADOLC_DELETE_SCAYLOR(&ADOLC_GLOBAL_TAPE_VARS.store[a_loc]);
    591         if (a_loc == ADOLC_GLOBAL_TAPE_VARS.locMinUnused-1) {
    592             ADOLC_GLOBAL_TAPE_VARS.locMinUnused--;     // The temporary will die in a minute and
    593             ADOLC_GLOBAL_TAPE_VARS.numToFree--;         // by reducing dealloc and current_top
    594         }                    // we neutralize that effect
    595578        --ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
    596579    } else {
     
    643626        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
    644627            ADOLC_DELETE_SCAYLOR(&ADOLC_GLOBAL_TAPE_VARS.store[a_loc]);
    645         if (a_loc == ADOLC_GLOBAL_TAPE_VARS.locMinUnused-1) {
    646             ADOLC_GLOBAL_TAPE_VARS.locMinUnused--;     // The temporary will die in a minute and
    647             ADOLC_GLOBAL_TAPE_VARS.numToFree--;         // by reducing dealloc and current_top
    648         }                    // we neutralize that effect
    649628        --ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
    650629    } else {
  • trunk/ADOL-C/src/adouble.h

    r179 r197  
    256256class ADOLC_DLL_EXPORT adub:public badouble {
    257257    friend ADOLC_DLL_EXPORT class adouble;
     258    adub( adub const &) {}
    258259protected:
    259260    adub( locint lo ):badouble(lo) {};
  • trunk/ADOL-C/src/checkpointing.cpp

    r106 r197  
    7676    ext_diff_fct *edf;
    7777    int oldTraceFlag;
    78     locint firstVal, numVals;
     78    locint numVals;
    7979    double *vals;
    8080    ADOLC_OPENMP_THREAD_NUMBER;
     
    112112    } else oldTraceFlag=0;
    113113
    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;
     114    numVals = ADOLC_GLOBAL_TAPE_VARS.storeSize;
    121115    vals = new double[numVals];
    122     memcpy(vals, ADOLC_GLOBAL_TAPE_VARS.store + firstVal,
     116    memcpy(vals, ADOLC_GLOBAL_TAPE_VARS.store,
    123117            numVals * sizeof(double));
    124118
     
    135129            cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for);
    136130
    137     memcpy(ADOLC_GLOBAL_TAPE_VARS.store + firstVal, vals,
     131    memcpy(ADOLC_GLOBAL_TAPE_VARS.store, vals,
    138132            numVals * sizeof(double));
    139133    delete[] vals;
  • trunk/ADOL-C/src/externfcts.cpp

    r106 r197  
    3939{
    4040    int i = 0, ret;
    41     locint firstVal, numVals;
     41    locint numVals;
    4242    double *vals;
    4343    ADOLC_OPENMP_THREAD_NUMBER;
     
    5959    } else oldTraceFlag=0;
    6060
    61 #if defined(ADOLC_SAFE_EXTERN)
    62     firstVal = 0;
    63 #else
    64     updateLocs();
    65     firstVal = ADOLC_GLOBAL_TAPE_VARS.locMinUnused;
    66 #endif
    67     numVals = ADOLC_GLOBAL_TAPE_VARS.numMaxAlive - firstVal;
     61    numVals = ADOLC_GLOBAL_TAPE_VARS.storeSize;
    6862    vals = new double[numVals];
    69     memcpy(vals, ADOLC_GLOBAL_TAPE_VARS.store + firstVal,
     63    memcpy(vals, ADOLC_GLOBAL_TAPE_VARS.store,
    7064            numVals * sizeof(double));
    7165
     
    7569    ret=edfct->function(n, xp, m, yp);
    7670
    77     memcpy(ADOLC_GLOBAL_TAPE_VARS.store + firstVal, vals,
     71    memcpy(ADOLC_GLOBAL_TAPE_VARS.store, vals,
    7872            numVals * sizeof(double));
    7973    delete[] vals;
  • trunk/ADOL-C/src/tape_handling.cpp

    r177 r197  
    3636END_C_DECLS
    3737#endif
     38
     39GlobalTapeVarsCL::GlobalTapeVarsCL() {
     40  store = 0;
     41  storeSize = 0;
     42  storeManagerPtr = new StoreManagerInteger(store, storeSize);
     43}
     44
     45GlobalTapeVarsCL::~GlobalTapeVarsCL() {
     46  if (storeManagerPtr) {
     47    delete storeManagerPtr;
     48    storeManagerPtr = 0;
     49  }
     50}
     51
     52locint new_next_loc() {
     53  ADOLC_OPENMP_THREAD_NUMBER;
     54  ADOLC_OPENMP_GET_THREAD_NUMBER;
     55  return ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr->next_loc();
     56}
     57
     58void new_free_loc(locint loc) {
     59  ADOLC_OPENMP_THREAD_NUMBER;
     60  ADOLC_OPENMP_GET_THREAD_NUMBER;
     61  ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr->free_loc(loc);
     62}
     63
    3864/* vector of tape infos for all tapes in use */
    3965vector<TapeInfos *> ADOLC_TAPE_INFOS_BUFFER_DECL;
     
    449475    ADOLC_CURRENT_TAPE_INFOS.keepTaylors = 0;
    450476
    451     ADOLC_GLOBAL_TAPE_VARS.store=NULL;
    452477    ADOLC_GLOBAL_TAPE_VARS.maxLoc=1;
    453478    for (uint i=0; i<sizeof(locint)*8-1; ++i) {
     
    455480        ++ADOLC_GLOBAL_TAPE_VARS.maxLoc;
    456481    }
    457     ADOLC_GLOBAL_TAPE_VARS.locMinUnused = 0;
    458     ADOLC_GLOBAL_TAPE_VARS.numMaxAlive = 0;
    459     ADOLC_GLOBAL_TAPE_VARS.storeSize = 0;
    460     ADOLC_GLOBAL_TAPE_VARS.numToFree = 0;
    461     ADOLC_GLOBAL_TAPE_VARS.minLocToFree = 0;
    462482    ADOLC_GLOBAL_TAPE_VARS.inParallelRegion = 0;
    463483    ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = NULL;
  • trunk/ADOL-C/src/taping.c

    r177 r197  
    561561    ADOLC_OPENMP_GET_THREAD_NUMBER;
    562562    space_left  = get_val_space(); /* remaining space in const. tape buffer */
    563     vals_left = ADOLC_GLOBAL_TAPE_VARS.locMinUnused;
     563    vals_left = ADOLC_GLOBAL_TAPE_VARS.storeSize;
    564564    vals      = ADOLC_GLOBAL_TAPE_VARS.store;
    565565
     
    596596    ADOLC_OPENMP_GET_THREAD_NUMBER;
    597597    /* if we have adoubles in use */
    598     if (ADOLC_GLOBAL_TAPE_VARS.numMaxAlive > 0) {
    599         locint loc2 = ADOLC_GLOBAL_TAPE_VARS.numMaxAlive - 1;
     598    if (ADOLC_GLOBAL_TAPE_VARS.storeSize > 0) {
     599        locint loc2 = ADOLC_GLOBAL_TAPE_VARS.storeSize - 1;
    600600
    601601        /* special signal -> all alive adoubles recorded on the end of the
     
    605605        ADOLC_PUT_LOCINT(loc2); /* highest loc */
    606606
    607         ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += ADOLC_GLOBAL_TAPE_VARS.numMaxAlive;
     607        ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += ADOLC_GLOBAL_TAPE_VARS.storeSize;
    608608        /* now really do it if keepTaylors ist set */
    609609        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) {
     
    614614    }
    615615    ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0;
    616     return ADOLC_GLOBAL_TAPE_VARS.numMaxAlive;
    617 }
    618 
    619 
    620 void updateLocs() {
    621     ADOLC_OPENMP_THREAD_NUMBER;
    622     ADOLC_OPENMP_GET_THREAD_NUMBER;
    623 
    624     /* deallocate dead adoubles if they form a contiguous tail */
    625     #ifdef overwrite
    626     if (ADOLC_GLOBAL_TAPE_VARS.numToFree &&
    627             ADOLC_GLOBAL_TAPE_VARS.minLocToFree + ADOLC_GLOBAL_TAPE_VARS.numToFree ==
    628             ADOLC_GLOBAL_TAPE_VARS.locMinUnused) {
    629         ADOLC_GLOBAL_TAPE_VARS.locMinUnused = ADOLC_GLOBAL_TAPE_VARS.minLocToFree ;
    630         ADOLC_GLOBAL_TAPE_VARS.numToFree = 0;
    631         ADOLC_GLOBAL_TAPE_VARS.minLocToFree = ADOLC_GLOBAL_TAPE_VARS.maxLoc;
    632     }
    633     #endif
    634 }
     616    return ADOLC_GLOBAL_TAPE_VARS.storeSize;
     617}
     618
     619
     620/* void updateLocs() { */
     621/* (JW) This function is not needed any more */
     622/* } */
    635623
    636624/****************************************************************************/
     
    638626/****************************************************************************/
    639627locint next_loc() {
    640     locint newStoreSize;
    641     ADOLC_OPENMP_THREAD_NUMBER;
    642     ADOLC_OPENMP_GET_THREAD_NUMBER;
    643 
    644     updateLocs();
    645     if (ADOLC_GLOBAL_TAPE_VARS.locMinUnused == ADOLC_GLOBAL_TAPE_VARS.numMaxAlive)
    646         ++ADOLC_GLOBAL_TAPE_VARS.numMaxAlive;
    647     if (ADOLC_GLOBAL_TAPE_VARS.numMaxAlive > ADOLC_GLOBAL_TAPE_VARS.storeSize) {
    648         /* try to double (plus 2) the available space */
    649         ++ADOLC_GLOBAL_TAPE_VARS.storeSize;
    650         if (ADOLC_GLOBAL_TAPE_VARS.storeSize == ADOLC_GLOBAL_TAPE_VARS.maxLoc) {
    651             failAdditionalInfo1 = ADOLC_GLOBAL_TAPE_VARS.maxLoc;
    652             fail(ADOLC_TAPING_TO_MANY_LOCINTS);
    653         }
    654         failAdditionalInfo3 = ADOLC_GLOBAL_TAPE_VARS.storeSize;
    655         newStoreSize = ADOLC_GLOBAL_TAPE_VARS.storeSize * 2;
    656         ADOLC_GLOBAL_TAPE_VARS.storeSize = newStoreSize;
    657         failAdditionalInfo4 = newStoreSize;
    658         failAdditionalInfo5 = ADOLC_GLOBAL_TAPE_VARS.store;
    659         if (ADOLC_GLOBAL_TAPE_VARS.store == NULL) {
    660             ADOLC_GLOBAL_TAPE_VARS.store =
    661                 (double *)malloc(ADOLC_GLOBAL_TAPE_VARS.storeSize * sizeof(double));
    662             ADOLC_GLOBAL_TAPE_VARS.minLocToFree = ADOLC_GLOBAL_TAPE_VARS.maxLoc;
    663         } else
    664             ADOLC_GLOBAL_TAPE_VARS.store =
    665                 (double *)realloc((char *)ADOLC_GLOBAL_TAPE_VARS.store,
    666                         ADOLC_GLOBAL_TAPE_VARS.storeSize * sizeof(double));
    667         if (ADOLC_GLOBAL_TAPE_VARS.store == NULL)
    668             fail(ADOLC_TAPING_STORE_REALLOC_FAILED);
    669     }
    670     return ADOLC_GLOBAL_TAPE_VARS.locMinUnused++;
     628    return new_next_loc();
    671629}
    672630
     
    674632/* Returns the next #size free locations in "adouble" memory.               */
    675633/****************************************************************************/
    676 locint next_loc_v(int size) {
    677     locint newStoreSize, retVal;
    678     ADOLC_OPENMP_THREAD_NUMBER;
    679     ADOLC_OPENMP_GET_THREAD_NUMBER;
    680 
    681     updateLocs();
    682     if (ADOLC_GLOBAL_TAPE_VARS.locMinUnused + size > ADOLC_GLOBAL_TAPE_VARS.numMaxAlive)
    683         ADOLC_GLOBAL_TAPE_VARS.numMaxAlive = ADOLC_GLOBAL_TAPE_VARS.locMinUnused + size;
    684     while (ADOLC_GLOBAL_TAPE_VARS.numMaxAlive > ADOLC_GLOBAL_TAPE_VARS.storeSize) {
    685         /* try to double (plus 2) the available space */
    686         ++ADOLC_GLOBAL_TAPE_VARS.storeSize;
    687         if (ADOLC_GLOBAL_TAPE_VARS.storeSize*2 > ADOLC_GLOBAL_TAPE_VARS.maxLoc)
    688             newStoreSize = ADOLC_GLOBAL_TAPE_VARS.maxLoc;
    689         else newStoreSize = ADOLC_GLOBAL_TAPE_VARS.storeSize * 2;
    690         if (newStoreSize == ADOLC_GLOBAL_TAPE_VARS.maxLoc) {
    691             failAdditionalInfo3 = ADOLC_GLOBAL_TAPE_VARS.maxLoc;
    692             fail(ADOLC_TAPING_TO_MANY_LOCINTS);
    693         } else {
    694             ADOLC_GLOBAL_TAPE_VARS.storeSize = newStoreSize;
    695             if (ADOLC_GLOBAL_TAPE_VARS.storeSize == 2) {
    696                 ADOLC_GLOBAL_TAPE_VARS.store =
    697                     (double *)malloc(ADOLC_GLOBAL_TAPE_VARS.storeSize * sizeof(double));
    698                 ADOLC_GLOBAL_TAPE_VARS.minLocToFree = ADOLC_GLOBAL_TAPE_VARS.maxLoc;
    699             } else
    700                 ADOLC_GLOBAL_TAPE_VARS.store =
    701                     (double *)realloc((char *)ADOLC_GLOBAL_TAPE_VARS.store,
    702                             ADOLC_GLOBAL_TAPE_VARS.storeSize * sizeof(double));
    703             if (ADOLC_GLOBAL_TAPE_VARS.store == NULL)
    704                 fail(ADOLC_TAPING_STORE_REALLOC_FAILED);
    705         }
    706     }
    707     #if defined(ADOLC_DEBUG)
    708     fprintf (DIAG_OUT, "ADOL-C debug: Top is: %d !\n",
    709             ADOLC_GLOBAL_TAPE_VARS.locMinUnused + size);
    710     #endif
    711     retVal = ADOLC_GLOBAL_TAPE_VARS.locMinUnused;
    712     ADOLC_GLOBAL_TAPE_VARS.locMinUnused += size;
    713     return retVal;
    714 }
     634/* locint next_loc_v(int size) { */
     635/* (JW) This function cannot be supported by the storemanager */
     636/* } */
    715637
    716638/****************************************************************************/
     
    11341056    for (i = 0; i < statSpace; ++i) ADOLC_PUT_LOCINT(0);
    11351057
    1136     /* free locations if possible => take_stock may benefit */
    1137     if (ADOLC_GLOBAL_TAPE_VARS.minLocToFree +
    1138             ADOLC_GLOBAL_TAPE_VARS.numToFree ==
    1139             ADOLC_GLOBAL_TAPE_VARS.locMinUnused) {
    1140         ADOLC_GLOBAL_TAPE_VARS.locMinUnused =
    1141             ADOLC_GLOBAL_TAPE_VARS.minLocToFree ;
    1142         ADOLC_GLOBAL_TAPE_VARS.numToFree = 0;
    1143         ADOLC_GLOBAL_TAPE_VARS.minLocToFree = ADOLC_GLOBAL_TAPE_VARS.maxLoc;
    1144     }
    1145 
    11461058    /* initialize value stack if necessary */
    11471059    if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
     
    11651077        ADOLC_CURRENT_TAPE_INFOS.numDeps;
    11661078    ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] =
    1167         ADOLC_GLOBAL_TAPE_VARS.numMaxAlive;
     1079        ADOLC_GLOBAL_TAPE_VARS.storeSize;
    11681080
    11691081    taylor_close(ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]);
  • trunk/ADOL-C/src/taping_p.h

    r177 r197  
    1818#include <adolc/taping.h>
    1919#include <errno.h>
     20#ifdef __cplusplus
     21#include "storemanager.hh"
     22#endif
    2023
    2124BEGIN_C_DECLS
     
    265268TapeInfos;
    266269
    267 typedef struct {
     270typedef struct GlobalTapeVarsCL {
    268271    double* store;              /* double store for calc. while taping */
     272    size_t storeSize;
    269273    locint maxLoc;
    270     locint locMinUnused;        /* largest live location + 1 */
    271     locint numMaxAlive;         /* maximal # of lives so far */
    272     locint storeSize;           /* current size of store */
    273     locint numToFree;           /* # of locations to be freed */
    274     locint minLocToFree;        /* lowest loc to be freed */
     274/*     locint locMinUnused;        /\* largest live location + 1 *\/ */
     275/*     locint numMaxAlive;         /\* maximal # of lives so far *\/ */
     276/*     locint storeSize;           /\* current size of store *\/ */
     277/*     locint numToFree;           /\* # of locations to be freed *\/ */
     278/*     locint minLocToFree;        /\* lowest loc to be freed *\/ */
    275279
    276280    locint operationBufferSize; /* Defaults to the value specified in */
     
    284288    char branchSwitchWarning;
    285289    TapeInfos *currentTapeInfosPtr;
     290#ifdef __cplusplus
     291    GlobalTapeVarsCL();
     292    ~GlobalTapeVarsCL();
     293    StoreManagerInteger *storeManagerPtr;
     294#else
     295    void *storeManagerPtr;
     296#endif
    286297}
    287298GlobalTapeVars;
    288299
    289300#if defined(_OPENMP)
    290 
     301#error nicht hier
    291302extern int isParallel();
    292303
     
    389400/* returns the next free location in "adouble" memory */
    390401
    391 locint next_loc_v(int size);
     402locint new_next_loc();
     403void new_free_loc(locint);
     404
     405/* locint next_loc_v(int size); */
    392406/* returns the next #size free locations in "adouble" memory */
    393407
Note: See TracChangeset for help on using the changeset viewer.