Changeset 198


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

move around some of Johannes Willkomm's code

Bring the code in tape_handling.cpp leaving only the declaration
in header. Make the StoreManager? the default. Remove old next_loc
and add free_loc without the new_ prefix. Add the header file to
Makefile.am in order for it to be distributed.

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

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

Legend:

Unmodified
Added
Removed
  • trunk/ADOL-C/src/Makefile.am

    r171 r198  
    3232
    3333EXTRA_DIST           = uni5_for.c fo_rev.c ho_rev.c \
    34                        taping_p.h malloc.h \
     34                       taping_p.h malloc.h storemanager.h \
    3535                       externfcts_p.h checkpointing_p.h buffer_temp.h
    3636
  • trunk/ADOL-C/src/adouble.cpp

    r197 r198  
    159159adouble::~adouble() {
    160160#ifdef overwrite
    161     new_free_loc(location);
     161    free_loc(location);
    162162#endif
    163163}
     
    166166adub::~adub() {
    167167#ifdef overwrite
    168     new_free_loc(location);
     168    free_loc(location);
    169169#endif
    170170}
  • trunk/ADOL-C/src/tape_handling.cpp

    r197 r198  
    1616#include <adolc/revolve.h>
    1717
     18#include <cassert>
     19#include <limits>
    1820#include <iostream>
    1921#include <string.h>
     
    4042  store = 0;
    4143  storeSize = 0;
    42   storeManagerPtr = new StoreManagerInteger(store, storeSize);
     44  storeManagerPtr = new StoreManagerLocint(store, storeSize);
    4345}
    4446
     
    5052}
    5153
    52 locint new_next_loc() {
     54StoreManagerLocint::StoreManagerLocint(double * &storePtr, size_t &size) :
     55    storePtr(storePtr),
     56    indexFeld(0),
     57    head(0),
     58    groesse(size), anzahl(0)
     59{
     60#ifdef ADOLC_DEBUG
     61    std::cerr << "StoreManagerInteger::StoreManagerInteger()\n";
     62#endif
     63    groesse = initialeGroesse;
     64}
     65
     66StoreManagerLocint::~StoreManagerLocint()
     67{
     68#ifdef ADOLC_DEBUG
     69    std::cerr << "StoreManagerInteger::~StoreManagerInteger()\n";
     70#endif
     71    if (storePtr) {
     72        delete[] storePtr;
     73        storePtr = 0;
     74    }
     75    if (indexFeld) {
     76        delete[] indexFeld;
     77        indexFeld = 0;
     78    }
     79    groesse = 0;
     80    anzahl = 0;
     81    head = 0;
     82}
     83
     84locint StoreManagerLocint::next_loc() {
     85    if (head == 0) {
     86      grow();
     87    }
     88    assert(head);
     89    locint const result = head;
     90    head = indexFeld[head];
     91    ++anzahl;
     92#ifdef ADOLC_DEBUG
     93    std::cerr << "next_loc: " << result << " fill: " << size() << "max: " << maxSize() << endl;
     94#endif
     95    return result;
     96}
     97
     98void StoreManagerLocint::free_loc(locint loc) {
     99    assert(loc < groesse);
     100    indexFeld[loc] = head;
     101    head = loc;
     102    --anzahl;
     103#ifdef ADOLC_DEBUG
     104    std::cerr << "free_loc: " << loc << " fill: " << size() << "max: " << maxSize() << endl;
     105#endif
     106}
     107
     108void StoreManagerLocint::grow() {
     109    size_t const alteGroesse = groesse;
     110    groesse *= 2;
     111
     112    if (groesse > std::numeric_limits<locint>::max()) {
     113      // encapsulate this error message
     114      fprintf(DIAG_OUT,"\nADOL-C error:\n");
     115      fprintf(DIAG_OUT,"maximal number (%d) of live active variables exceeded\n\n",
     116              std::numeric_limits<locint>::max());
     117      exit(-3);
     118    }
     119
     120#ifdef ADOLC_DEBUG
     121    // index 0 is not used, means one slot less
     122    std::cerr << "StoreManagerInteger::grow(): increase size from " << alteGroesse
     123         << " to " << groesse << " entries (currently " << size() << " entries used)\n";
     124    assert(alteGroesse == initialeGroesse or size() == (alteGroesse-1));
     125#endif
     126
     127    double *const oldStore = storePtr;
     128    locint *const oldIndex = indexFeld;
     129
     130#if defined(ADOLC_DEBUG)
     131    std::cerr << "StoreManagerInteger::grow(): allocate " << groesse * sizeof(double) << " B doubles "
     132         << "and " << groesse * sizeof(locint) << " B locints\n";
     133#endif
     134    storePtr = new double[groesse];
     135    indexFeld = new locint[groesse];
     136
     137    // we use index 0 as end-of-list marker
     138    size_t i = 1;
     139    //     storePtr[0] = nan(""); not available on solaris
     140    storePtr[0] = (non_num/non_den);
     141
     142    if (alteGroesse != initialeGroesse) { // not the first time
     143#if defined(ADOLC_DEBUG)
     144      std::cerr << "StoreManagerInteger::grow(): copy values\n";
     145#endif
     146      for (size_t j = i; j < alteGroesse; ++j) {
     147        indexFeld[j] = oldIndex[j];
     148      }
     149      for (size_t j = i; j < alteGroesse; ++j) {
     150        storePtr[j] = oldStore[j];
     151      }
     152
     153      // reset i to start of new slots (upper half)
     154      i = alteGroesse;
     155
     156#if defined(ADOLC_DEBUG)
     157      std::cerr << "StoreManagerInteger::grow(): free " << alteGroesse * sizeof(double)
     158                << " + " << alteGroesse * sizeof(locint) << " B\n";
     159#endif
     160      delete [] oldStore;
     161      delete [] oldIndex;
     162    }
     163
     164    head = i;
     165    // create initial linked list for new slots
     166    for ( ; i < groesse-1; ++i) {
     167      indexFeld[i] = i + 1;
     168    }
     169    indexFeld[i] = 0; // end marker
     170    assert(i == groesse-1);
     171}
     172
     173
     174/****************************************************************************/
     175/* Returns the next free location in "adouble" memory.                      */
     176/****************************************************************************/
     177locint next_loc() {
    53178  ADOLC_OPENMP_THREAD_NUMBER;
    54179  ADOLC_OPENMP_GET_THREAD_NUMBER;
     
    56181}
    57182
    58 void new_free_loc(locint loc) {
     183/****************************************************************************/
     184/* frees the specified location in "adouble" memory                         */
     185/****************************************************************************/
     186void free_loc(locint loc) {
    59187  ADOLC_OPENMP_THREAD_NUMBER;
    60188  ADOLC_OPENMP_GET_THREAD_NUMBER;
  • trunk/ADOL-C/src/taping.c

    r197 r198  
    618618
    619619
    620 /* void updateLocs() { */
    621 /* (JW) This function is not needed any more */
    622 /* } */
    623 
    624 /****************************************************************************/
    625 /* Returns the next free location in "adouble" memory.                      */
    626 /****************************************************************************/
    627 locint next_loc() {
    628     return new_next_loc();
    629 }
    630 
    631 /****************************************************************************/
    632 /* Returns the next #size free locations in "adouble" memory.               */
    633 /****************************************************************************/
    634 /* locint next_loc_v(int size) { */
    635 /* (JW) This function cannot be supported by the storemanager */
    636 /* } */
    637 
    638620/****************************************************************************/
    639621/* Set up statics for writing taylor data                                   */
  • trunk/ADOL-C/src/taping_p.h

    r197 r198  
    1919#include <errno.h>
    2020#ifdef __cplusplus
    21 #include "storemanager.hh"
     21#include "storemanager.h"
    2222#endif
    2323
     
    272272    size_t storeSize;
    273273    locint maxLoc;
    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 *\/ */
    279274
    280275    locint operationBufferSize; /* Defaults to the value specified in */
     
    291286    GlobalTapeVarsCL();
    292287    ~GlobalTapeVarsCL();
    293     StoreManagerInteger *storeManagerPtr;
     288    StoreManager *storeManagerPtr;
    294289#else
    295290    void *storeManagerPtr;
     
    400395/* returns the next free location in "adouble" memory */
    401396
    402 locint new_next_loc();
    403 void new_free_loc(locint);
    404 
    405 /* locint next_loc_v(int size); */
    406 /* returns the next #size free locations in "adouble" memory */
     397void free_loc(locint loc);
     398/* frees the specified location in "adouble" memory */
    407399
    408400void taylor_begin(uint bufferSize, double **Tg, int degreeSave);
Note: See TracChangeset for help on using the changeset viewer.