Changeset 352


Ignore:
Timestamp:
Sep 24, 2012 8:40:20 AM (7 years ago)
Author:
kulshres
Message:

Rewrite of the StoreManagerLocintBlock? class

From: Jean Utke <utke@…>

and change in variable names as suggested to do away with mixing
english and german names.

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

This also combines the following commits on Jean's branch:

commit 79f770c3d2ab865a38301d1f86fa7c5b1b5d8dcf
Author: Jean Utke <utke@…>
Date: Sat Sep 22 01:15:58 2012 -0500

the previous fix was still insufficient because it inadvertently left
0 size blocks in the front of the list and the comment that the
newly allocated blocks should be pushed to the end apparently applied
only to the grow routine but not to next_loc so I went and did a more
wholesale change of what I think might work and what incidentally also
seems a little more straitghtforward. This is still a limited change
and I am still dubious about the constructor when non-zero values for
anxahl and groesse are passed
And ALSO these variable names OUGHT to be changed to something reasonable. :-)

commit f463cfcef971df5354709f430083a651ee543713
Author: Jean Utke <utke@…>
Date: Fri Sep 21 18:25:21 2012 -0500

fixing up earlier change in 3e9a21e76d1cb2ee10c220fa7a2f4d0dc8ae8e09
this earlier change was wrong too because while it expanded to
indexFeld with maximal location it still was wrong because
locations with bigger values could already be handed out.
So we restore part of the older code BUT then track if
we actually updated any existing IndexFeld? instance and if not
make a new one.

commit c7892ac99dea373e3eb7d5b7812230b18cf76ce3
Author: Jean Utke <utke@…>
Date: Fri Sep 21 17:32:37 2012 -0500

it is more efficient to use empty instead of size in these conditions

commit 3e9a21e76d1cb2ee10c220fa7a2f4d0dc8ae8e09
Author: Jean Utke <utke@…>
Date: Fri Sep 21 17:23:34 2012 -0500

fixed the behavior where the condition essentially makes the assumption
that the INDEXFELD must include the tail of the handed out locints as
if the locints were allocated in freed in LIFO fashion similar to the old
allocation scheme that this trying to avoid... details are below quoted from an e-mail
also changed some debug messages
================= Details =============

Below you see how the remaining open locations are tracked in just one remaining "IndexFeld?"
instance in the list where size counts down as locations are handed out in next_loc.

INDEXFELD ( 41772 , 3)
next_loc() , anzahl= 65534, groesse= 65536
next_loc: 41772 fill: 65534 max: 65536
INDEXFELD ( 41773 , 2)
next_loc() , anzahl= 65535, groesse= 65536
next_loc: 41773 fill: 65535 max: 65536
INDEXFELD ( 41774 , 1)
next_loc() , anzahl= 65536, groesse= 65536
next_loc: 41774 fill: 65536 max: 65536
INDEXFELD ( 41775 , 0)

Here we are now at the point where - after handing out location 41775
we have to grow so grow() is called:

StoreManagerIntegerBlock::grow(): increase size from 65536 to 131072 entries (currently 65536 entries used)
StoreManagerInteger::grow(): allocate 1048576 B doubles and 2097152 B LinkBlocks?
StoreManagerInteger::grow(): copy values
StoreManagerInteger::grow(): free 524288 + 1048576 B

Unfortunately the logic that should now modify the one remaining INDEXFELD mistakenly
assumes that there has to be an INDEXFELD satisfying something very much like
having locints (de)allocated in LIFO fashion as in the old ADOLC:

"iter->next + iter->size == alteGroesse"

but as you can see the one remaining one doesn't so
then this iter->size is *NOT updated*:
but we continue anyway:
Growing:
INDEXFELD ( 41775 , 0)

and now the next time we call next_loc we happily find the one IndexFeld? instance whose size is 0 and do:

indexFeld.front().size--;

and we get *... DRUMROLL ...* the wraparound for size:

INDEXFELD ( 41776 , 18446744073709551615)

and from there on things go downhill....

Location:
trunk/ADOL-C/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ADOL-C/src/storemanager.h

    r337 r352  
    6969class StoreManager {
    7070protected:
    71   static size_t const initialeGroesse = 4;
     71  static size_t const initialSize = 4;
    7272public:
    7373  virtual ~StoreManager() {}
     
    8989protected:
    9090  double * &storePtr;
    91   locint * indexFeld;
     91  locint * indexFree;
    9292  locint head;
    93   size_t &groesse;
    94   size_t &anzahl;
     93  size_t &maxsize;
     94  size_t &currentfill;
    9595private:
    9696  void grow();
     
    101101
    102102  virtual ~StoreManagerLocint();
    103   virtual inline size_t size() const { return anzahl; }
    104 
    105   virtual inline size_t maxSize() const { return groesse; }
     103  virtual inline size_t size() const { return currentfill; }
     104
     105  virtual inline size_t maxSize() const { return maxsize; }
    106106
    107107  virtual inline bool realloc_on_next_loc() const {
     
    117117protected:
    118118    double * &storePtr;
    119     struct FeldBlock {
     119    struct FreeBlock {
    120120        locint next; // next location
    121121        size_t size; // number of following free locations
    122         FeldBlock(): next(0), size(0) {}
    123         FeldBlock(const struct FeldBlock &block) :
     122        FreeBlock(): next(0), size(0) {}
     123        FreeBlock(const struct FreeBlock &block) :
    124124            next(block.next),size(block.size) {}
    125125    };
    126126
    127     list<struct FeldBlock> indexFeld;
    128     size_t &groesse;
    129     size_t &anzahl;
     127    list<struct FreeBlock> indexFree;
     128    size_t &maxsize;
     129    size_t &currentfill;
    130130private:
    131     void grow( );
     131    /**
     132     * when minGrow is specified we asssume that we have already
     133     * search the blocks and found no block with minGrow locations in it
     134     */
     135    void grow(size_t minGrow=0 );
    132136public:
    133137    StoreManagerLocintBlock(double * &storePtr, size_t &size, size_t &numlives);
     
    135139
    136140    virtual ~StoreManagerLocintBlock();
    137     virtual inline size_t size() const { return anzahl; }
    138 
    139     virtual inline size_t maxSize() const { return groesse; }
     141    virtual inline size_t size() const { return currentfill; }
     142
     143    virtual inline size_t maxSize() const { return maxsize; }
    140144
    141145    virtual locint next_loc();
  • trunk/ADOL-C/src/tape_handling.cpp

    r350 r352  
    4141
    4242GlobalTapeVarsCL::GlobalTapeVarsCL() {
    43   store = 0;
    44   // we do not use location 0 so start with 1 always
     43  store = NULL;
    4544  storeSize = 0;
    4645  numLives = 0;
     
    5150  if (storeManagerPtr) {
    5251    delete storeManagerPtr;
    53     storeManagerPtr = 0;
     52    storeManagerPtr = NULL;
    5453  }
    5554}
     
    7978StoreManagerLocint::StoreManagerLocint(double * &storePtr, size_t &size, size_t &numlives) :
    8079    storePtr(storePtr),
    81     indexFeld(0),
     80    indexFree(0),
    8281    head(0),
    83     groesse(size), anzahl(numlives)
     82    maxsize(size), currentfill(numlives)
    8483{
    8584#ifdef ADOLC_DEBUG
     
    9796        storePtr = 0;
    9897    }
    99     if (indexFeld) {
    100         delete[] indexFeld;
    101         indexFeld = 0;
    102     }
    103     groesse = 0;
    104     anzahl = 0;
     98    if (indexFree) {
     99        delete[] indexFree;
     100        indexFree = 0;
     101    }
     102    maxsize = 0;
     103    currentfill = 0;
    105104    head = 0;
    106105}
     
    109108                                       double * &storePtr, size_t &size, size_t &numlives) :
    110109    storePtr(storePtr),
    111     groesse(size), anzahl(numlives)
     110    maxsize(size), currentfill(numlives)
    112111{
    113112#ifdef ADOLC_DEBUG
     
    115114#endif
    116115    head = stm->head;
    117     indexFeld = new locint[groesse];
    118     for (int i = 0; i < groesse; i++)
    119         indexFeld[i] = stm->indexFeld[i];
     116    indexFree = new locint[maxsize];
     117    for (int i = 0; i < maxsize; i++)
     118        indexFree[i] = stm->indexFree[i];
    120119}
    121120
     
    126125    assert(head);
    127126    locint const result = head;
    128     head = indexFeld[head];
    129     ++anzahl;
     127    head = indexFree[head];
     128    ++currentfill;
    130129#ifdef ADOLC_DEBUG
    131130    std::cerr << "next_loc: " << result << " fill: " << size() << "max: " << maxSize() << endl;
     
    135134
    136135void StoreManagerLocint::free_loc(locint loc) {
    137     assert(0 < loc && loc < groesse);
    138     indexFeld[loc] = head;
     136    assert(0 < loc && loc < maxsize);
     137    indexFree[loc] = head;
    139138    head = loc;
    140     --anzahl;
     139    --currentfill;
    141140#ifdef ADOLC_DEBUG
    142141    std::cerr << "free_loc: " << loc << " fill: " << size() << "max: " << maxSize() << endl;
     
    145144
    146145void StoreManagerLocint::grow() {
    147     if (groesse == 0) groesse += initialeGroesse;
    148     size_t const alteGroesse = groesse;
    149     groesse *= 2;
    150 
    151     if (groesse > std::numeric_limits<locint>::max()) {
     146    if (maxsize == 0) maxsize += initialSize;
     147    size_t const oldMaxsize = maxsize;
     148    maxsize *= 2;
     149
     150    if (maxsize > std::numeric_limits<locint>::max()) {
    152151      // encapsulate this error message
    153152      fprintf(DIAG_OUT,"\nADOL-C error:\n");
     
    158157
    159158#ifdef ADOLC_DEBUG
    160     std::cerr << "StoreManagerInteger::grow(): increase size from " << alteGroesse
    161          << " to " << groesse << " entries (currently " << size() << " entries used)\n";
    162     assert(alteGroesse == initialeGroesse or size() == alteGroesse);
     159    std::cerr << "StoreManagerInteger::grow(): increase size from " << oldMaxsize
     160         << " to " << maxsize << " entries (currently " << size() << " entries used)\n";
     161    assert(oldMaxsize == initialSize or size() == oldMaxsize);
    163162#endif
    164163
    165164    double *const oldStore = storePtr;
    166     locint *const oldIndex = indexFeld;
     165    locint *const oldIndex = indexFree;
    167166
    168167#if defined(ADOLC_DEBUG)
    169     std::cerr << "StoreManagerInteger::grow(): allocate " << groesse * sizeof(double) << " B doubles "
    170          << "and " << groesse * sizeof(locint) << " B locints\n";
    171 #endif
    172     storePtr = new double[groesse];
    173     indexFeld = new locint[groesse];
     168    std::cerr << "StoreManagerInteger::grow(): allocate " << maxsize * sizeof(double) << " B doubles "
     169         << "and " << maxsize * sizeof(locint) << " B locints\n";
     170#endif
     171    storePtr = new double[maxsize];
     172    indexFree = new locint[maxsize];
    174173    // we use index 0 as end-of-list marker
    175174    size_t i = 1;
    176175    storePtr[0] =  std::numeric_limits<double>::quiet_NaN();
    177176
    178     if (alteGroesse != initialeGroesse) { // not the first time
     177    if (oldMaxsize != initialSize) { // not the first time
    179178#if defined(ADOLC_DEBUG)
    180179      std::cerr << "StoreManagerInteger::grow(): copy values\n";
    181180#endif
    182       for (size_t j = i; j < alteGroesse; ++j) {
    183         indexFeld[j] = oldIndex[j];
     181      for (size_t j = i; j < oldMaxsize; ++j) {
     182        indexFree[j] = oldIndex[j];
    184183      }
    185       for (size_t j = i; j < alteGroesse; ++j) {
     184      for (size_t j = i; j < oldMaxsize; ++j) {
    186185        storePtr[j] = oldStore[j];
    187186      }
    188187
    189188      // reset i to start of new slots (upper half)
    190       i = alteGroesse;
     189      i = oldMaxsize;
    191190
    192191#if defined(ADOLC_DEBUG)
    193       std::cerr << "StoreManagerInteger::grow(): free " << alteGroesse * sizeof(double)
    194                 << " + " << alteGroesse * sizeof(locint) << " B\n";
     192      std::cerr << "StoreManagerInteger::grow(): free " << oldMaxsize * sizeof(double)
     193                << " + " << oldMaxsize * sizeof(locint) << " B\n";
    195194#endif
    196195      delete [] oldStore;
     
    200199    head = i;
    201200    // create initial linked list for new slots
    202     for ( ; i < groesse-1; ++i) {
    203       indexFeld[i] = i + 1;
    204     }
    205     indexFeld[i] = 0; // end marker
    206     assert(i == groesse-1);
     201    for ( ; i < maxsize-1; ++i) {
     202      indexFree[i] = i + 1;
     203    }
     204    indexFree[i] = 0; // end marker
     205    assert(i == maxsize-1);
    207206}
    208207
     
    11831182StoreManagerLocintBlock::StoreManagerLocintBlock(double * &storePtr, size_t &size, size_t &numlives) :
    11841183    storePtr(storePtr),
    1185     groesse(size), anzahl(numlives)
     1184    maxsize(size), currentfill(numlives)
    11861185{
    1187     indexFeld.clear();
     1186    indexFree.clear();
    11881187#ifdef ADOLC_DEBUG
    11891188    std::cerr << "StoreManagerIntegerBlock::StoreManagerIntegerBlock()\n";
     
    12001199     storePtr = 0;
    12011200    }
    1202     if (indexFeld.size() ) {
    1203         indexFeld.clear();
    1204     }
    1205     groesse = 0;
    1206     anzahl = 0;
     1201    if (!indexFree.empty() ) {
     1202        indexFree.clear();
     1203    }
     1204    maxsize = 0;
     1205    currentfill = 0;
    12071206}
    12081207
     
    12111210    double * &storePtr, size_t &size, size_t &numlives) :
    12121211    storePtr(storePtr),
    1213     groesse(size), anzahl(numlives)
     1212    maxsize(size), currentfill(numlives)
    12141213{
    12151214#ifdef ADOLC_DEBUG
    12161215    std::cerr << "StoreManagerInteger::StoreManagerInteger()\n";
    12171216#endif
    1218     indexFeld.clear();
    1219     list<struct FeldBlock>::const_iterator iter = stm->indexFeld.begin();
    1220     for (; iter != stm->indexFeld.end(); iter++)
    1221         indexFeld.push_back( *iter );
     1217    indexFree.clear();
     1218    list<struct FreeBlock>::const_iterator iter = stm->indexFree.begin();
     1219    for (; iter != stm->indexFree.end(); iter++)
     1220        indexFree.push_back( *iter );
    12221221}
    12231222
    12241223
    12251224locint StoreManagerLocintBlock::next_loc() {
    1226     if ( indexFeld.size()==0 )
     1225    if ( indexFree.empty() )
    12271226        grow();
    12281227
    1229     locint const result = indexFeld.front().next;
    1230     indexFeld.front().next++;
    1231     indexFeld.front().size--;
    1232 
    1233     ++anzahl;
    1234 
    1235 #ifdef ADOLC_DEBUG
    1236      std::cerr  << "next_loc() , anzahl= " <<anzahl << ", groesse= "<< groesse << endl;
    1237     list<struct FeldBlock>::iterator iter = indexFeld.begin();
    1238     for( ; iter != indexFeld.end(); iter++ )
     1228    locint const result = indexFree.front().next;
     1229    indexFree.front().next++;
     1230    indexFree.front().size--;
     1231
     1232    ++currentfill;
     1233
     1234#ifdef ADOLC_DEBUG
     1235    std::cerr << "StoreManagerLocintBlock::next_loc: result: " << result << " fill: " << size() << "max: " << maxSize() << endl;
     1236    list<struct FreeBlock>::iterator iter = indexFree.begin();
     1237    for( ; iter != indexFree.end(); iter++ )
    12391238       std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" << endl;
    1240     std::cerr << "next_loc: " << result << " fill: " << size() << "max: " << maxSize() << endl;
    1241 #endif
    1242 
    1243     if (indexFeld.front().size == 0) {
    1244         if (indexFeld.size() <= 1)
     1239#endif
     1240
     1241    if (indexFree.front().size == 0) {
     1242        if (indexFree.size() <= 1)
    12451243            grow();
    12461244        else
    1247           indexFeld.pop_front();
     1245          indexFree.pop_front();
    12481246    }
    12491247
     
    12521250
    12531251void StoreManagerLocintBlock::ensure_block(size_t n) {
    1254     bool grown = false;
    1255 
    1256     if ( indexFeld.size()==0 ) {
    1257 #ifdef ADOLC_DEBUG
    1258         std::cerr << "no free blocks...growing " << endl;
    1259 #endif
    1260         grow();
    1261         grown = true;
    1262     }
    1263 
    1264     while (indexFeld.front().size < n) {
    1265         if (grown && indexFeld.back().size >= n) {
    1266 #ifdef ADOLC_DEBUG
    1267             std::cerr << "bringing back to front " << endl;
    1268 #endif
    1269             struct FeldBlock tmp(indexFeld.back());
    1270             indexFeld.pop_back();
    1271             indexFeld.push_front(tmp);
     1252    bool found = false;
     1253
     1254#ifdef ADOLC_DEBUG
     1255    std::cerr << "StoreManagerLocintBlock::ensure_Block: required " << n << " ... ";
     1256    std::cerr << "searching for big enough block " << endl;
     1257#endif
     1258    list<struct FreeBlock>::iterator iter = indexFree.begin();
     1259    for (; iter != indexFree.end() ; iter++ ) {
     1260        if ( iter->size >= n) {
     1261            if (iter != indexFree.begin() ) {
     1262                struct FreeBlock tmp(*iter);
     1263                iter = indexFree.erase(iter);
     1264                indexFree.push_front(tmp);
     1265            }
     1266            found = true;
     1267            break;
    12721268        }
    1273         else if (grown && indexFeld.back().size < n) {
    1274 #ifdef ADOLC_DEBUG
    1275             std::cerr << "still not enough...growing " << endl;
    1276 #endif
    1277             grow();
     1269    }
     1270    if (!found) {
     1271#ifdef ADOLC_DEBUG
     1272        std::cerr << "no big enough block...growing " << endl;
     1273#endif
     1274        grow(n);
     1275    }
     1276
     1277#ifdef ADOLC_DEBUG
     1278    std::cerr << "StoreManagerLocintBlock::ensure_Block: " << " fill: " << size() << "max: " << maxSize() <<  " ensure_Block (" << n << ")" << endl;
     1279    iter = indexFree.begin();
     1280    for( ; iter != indexFree.end(); iter++ )
     1281        std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" << endl;
     1282#endif
     1283}
     1284
     1285void StoreManagerLocintBlock::grow(size_t minGrow) {
     1286    // first figure out what eventual size we want
     1287    size_t const oldMaxsize = maxsize;
     1288
     1289    if (maxsize == 0){
     1290        maxsize = initialSize;
     1291    } else {
     1292        maxsize *= 2;
     1293    }
     1294
     1295    if (minGrow > 0) {
     1296        while (maxsize - oldMaxsize < minGrow) {
     1297            maxsize *= 2;
    12781298        }
    1279         else {
    1280 #ifdef ADOLC_DEBUG
    1281             std::cerr << "searching for big enough block " << endl;
    1282 #endif
    1283             bool found = false;
    1284             list<struct FeldBlock>::iterator iter = indexFeld.begin();
    1285             for (; iter != indexFeld.end() ; iter++ ) {
    1286                 if ( iter->size >= n) {
    1287                     if (iter != indexFeld.begin() ) {
    1288                         struct FeldBlock tmp(*iter);
    1289                         iter = indexFeld.erase(iter);
    1290                         indexFeld.push_front(tmp);
    1291                     }
    1292                     found = true;
    1293                     break;
    1294                 }
    1295             }
    1296             if (!found) {
    1297 #ifdef ADOLC_DEBUG
    1298                 std::cerr << "no big enough block...growing " << endl;
    1299 #endif
    1300                 grow();
    1301                 grown = true;
    1302             }
    1303         }
    1304     }
    1305 
    1306 #ifdef ADOLC_DEBUG
    1307     std::cerr << "ensure_Block: " << " fill: " << size() << "max: " << maxSize() << endl;
    1308     std::cerr << "ensure_Block (" << n << ")" << endl;
    1309     list<struct FeldBlock>::iterator iter = indexFeld.begin();
    1310     for( ; iter != indexFeld.end(); iter++ )
    1311        std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" << endl;
    1312 #endif
    1313 }
    1314 
    1315 void StoreManagerLocintBlock::grow() {
    1316     if (groesse == 0){
    1317         groesse = initialeGroesse;
    1318         struct FeldBlock tmp;
    1319         // do not use location 0
    1320         tmp.next = 0;
    1321         tmp.size = groesse;
    1322         indexFeld.push_back(tmp);
    1323     }
    1324 
    1325     size_t const alteGroesse = groesse;
    1326     groesse *= 2;
    1327 
    1328     if (groesse > std::numeric_limits<locint>::max()) {
     1299    }
     1300
     1301    if (maxsize > std::numeric_limits<locint>::max()) {
    13291302      // encapsulate this error message
    13301303      fprintf(DIAG_OUT,"\nADOL-C error:\n");
    1331       fprintf(DIAG_OUT,"maximal number (%d) of live active variables exceeded\n\n",
     1304      fprintf(DIAG_OUT,"maximal number (%u) of live active variables exceeded\n\n",
    13321305           std::numeric_limits<locint>::max());
    13331306      exit(-3);
     
    13361309#ifdef ADOLC_DEBUG
    13371310    // index 0 is not used, means one slot less
    1338     std::cerr << "StoreManagerIntegerBlock::grow(): increase size from " << alteGroesse
    1339       << " to " << groesse << " entries (currently " << size() << " entries used)\n";
     1311    std::cerr << "StoreManagerIntegerBlock::grow(): increase size from " << oldMaxsize
     1312      << " to " << maxsize << " entries (currently " << size() << " entries used)\n";
    13401313#endif
    13411314
     
    13431316
    13441317#if defined(ADOLC_DEBUG)
    1345     std::cerr << "StoreManagerInteger::grow(): allocate " << groesse * sizeof(double) << " B doubles "
    1346       << "and " << groesse * sizeof(struct FeldBlock) << " B LinkBlocks\n";
    1347 #endif
    1348     storePtr = new double[groesse];
    1349     memset(storePtr, 0, groesse*sizeof(double));
    1350     size_t i = 0;
    1351 
    1352     if (alteGroesse != initialeGroesse) { // not the first time
     1318    std::cerr << "StoreManagerInteger::grow(): allocate " << maxsize * sizeof(double) << " B doubles\n";
     1319#endif
     1320    storePtr = new double[maxsize];
     1321    assert(storePtr);
     1322    memset(storePtr, 0, maxsize*sizeof(double));
     1323
     1324    if (oldStore != NULL) { // not the first time
    13531325#if defined(ADOLC_DEBUG)
    13541326      std::cerr << "StoreManagerInteger::grow(): copy values\n";
    13551327#endif
    1356       for (size_t j = i; j < alteGroesse; ++j) {
    1357           storePtr[j] = oldStore[j];
    1358       }
     1328
     1329      memcpy(storePtr, oldStore, oldMaxsize*sizeof(double));
    13591330
    13601331#if defined(ADOLC_DEBUG)
    1361       std::cerr << "StoreManagerInteger::grow(): free " << alteGroesse * sizeof(double)
    1362           << " + " << alteGroesse * sizeof(struct FeldBlock) << " B\n";
     1332      std::cerr << "StoreManagerInteger::grow(): free " << oldMaxsize * sizeof(double) << "\n";
    13631333#endif
    13641334      delete [] oldStore;
    13651335    }
    1366     list<struct FeldBlock>::iterator iter = indexFeld.begin();
    1367     for (; iter != indexFeld.end() ; iter++ ) {
    1368          if (iter->next + iter->size == alteGroesse ) {
    1369              iter->size += (groesse - alteGroesse);
    1370               // move the block to the end of the list because that is where
    1371               // other functions expect the newly grown block to be
    1372               struct FeldBlock tmp(*iter);
    1373               iter = indexFeld.erase(iter);
    1374               indexFeld.push_back(tmp);
    1375               break;
     1336    bool foundTail = false;
     1337    list<struct FreeBlock>::iterator iter = indexFree.begin();
     1338    for (; iter != indexFree.end() ; iter++ ) {
     1339         if (iter->next + iter->size == oldMaxsize ) {
     1340             iter->size += (maxsize - oldMaxsize);
     1341              struct FreeBlock tmp(*iter);
     1342              iter = indexFree.erase(iter);
     1343              indexFree.push_front(tmp);
     1344              foundTail = true;
    13761345         }
     1346         if (!(iter->size)) iter=indexFree.erase(iter); // don't leave 0 blocks around
     1347    }
     1348    if (! foundTail) {
     1349        struct FreeBlock tmp;
     1350        tmp.next = oldMaxsize;
     1351        tmp.size = (maxsize - oldMaxsize);
     1352        indexFree.push_front(tmp);
    13771353    }
    13781354#ifdef ADOLC_DEBUG
    13791355    std::cerr << "Growing:" << endl;
    1380     iter = indexFeld.begin();
    1381     for( ; iter != indexFeld.end(); iter++ )
     1356    iter = indexFree.begin();
     1357    for( ; iter != indexFree.end(); iter++ )
    13821358       std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" << endl;
    13831359#endif
     
    13851361
    13861362void StoreManagerLocintBlock::free_loc(locint loc) {
    1387     assert( loc < groesse);
    1388 
    1389     list<struct FeldBlock>::iterator iter = indexFeld.begin();
    1390     for (; iter != indexFeld.end() ; iter++ ) {
     1363    assert( loc < maxsize);
     1364
     1365    list<struct FreeBlock>::iterator iter = indexFree.begin();
     1366    for (; iter != indexFree.end() ; iter++ ) {
    13911367         if (loc+1 == iter->next || iter->next + iter->size == loc) {
    13921368              iter->size++;
     
    13961372    // in case several contiguous adouble are deallcated right after
    13971373    // one another, e.g. advector
    1398               struct FeldBlock tmp(*iter);
    1399               iter = indexFeld.erase(iter);
    1400               indexFeld.push_front(tmp);
    1401               iter = indexFeld.begin();
     1374              struct FreeBlock tmp(*iter);
     1375              iter = indexFree.erase(iter);
     1376              indexFree.push_front(tmp);
     1377              iter = indexFree.begin();
    14021378              break;
    14031379         }
    14041380    }
    1405     if (iter == indexFeld.end()) {
    1406          struct FeldBlock tmp;
     1381    if (iter == indexFree.end()) {
     1382         struct FreeBlock tmp;
    14071383         tmp.next = loc;
    14081384         tmp.size = 1;
    1409          indexFeld.push_front(tmp);
    1410     }
    1411 
    1412     --anzahl;
     1385         indexFree.push_front(tmp);
     1386    }
     1387
     1388    --currentfill;
    14131389#ifdef ADOLC_DEBUG
    14141390    std::cerr << "free_loc: " << loc << " fill: " << size() << "max: " << maxSize() << endl;
    14151391
    1416     iter = indexFeld.begin();
    1417     for( ; iter != indexFeld.end(); iter++ )
     1392    iter = indexFree.begin();
     1393    for( ; iter != indexFree.end(); iter++ )
    14181394       std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" << endl;
    14191395#endif
Note: See TracChangeset for help on using the changeset viewer.