From ad54f29de351976a096b4991fe426ffc30332df2 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Wed, 15 May 2013 14:22:03 +0200 Subject: [PATCH] added support for using excluded config-files for equilibration. --- configcache.cpp | 44 ++++++++++++++++++++++++++------------------ configcache.h | 4 ++++ hypercache.cpp | 6 ++++++ hypercache.h | 3 +++ o815/o815.h | 2 +- o815/sim.cpp | 30 ++++++++++++++++++++++++++---- 6 files changed, 66 insertions(+), 23 deletions(-) diff --git a/configcache.cpp b/configcache.cpp index d45e4d6..6cd46a1 100644 --- a/configcache.cpp +++ b/configcache.cpp @@ -186,28 +186,17 @@ int configcache::readConfig(vector *excludeFileHashes) while(true) { - if( (!inFile.is_open()) && inFiles.size() == 0 ) return nequileft; + vector::iterator inFileIt = getNextInfile(excludeFileHashes); - while( (!inFile.is_open()) && inFiles.size() > 0 ) { - bool excludethisfile=false; + if( (!inFile.is_open()) && inFileIt == inFiles.end() ) return nequileft; - openFileDesc = inFiles.back(); + while( (!inFile.is_open()) && inFiles.size() > 0 ) { + openFileDesc = *inFileIt; - if (excludeFileHashes != NULL) - for (vector::iterator exit = excludeFileHashes->begin(); exit != excludeFileHashes->end(); ++exit) - if ( *exit == hash(inFiles.back().filename) ) { - excludethisfile = true; - break; - } - - if ( ! excludethisfile ) { - if(log) *log << "CCACHE: Opening dat-file: " << inFiles.back().filename << endl << flush; - inFile.open( (DATADIR + "/" + inFiles.back().filename).c_str(), std::ios::binary ); - } - else - if(log) *log << "CCACHE: Excluded dat-file: " << inFiles.back().filename << endl << flush; + if(log) *log << "CCACHE: Opening dat-file: " << inFileIt->filename << endl << flush; + inFile.open( (DATADIR + "/" + inFileIt->filename).c_str(), std::ios::binary ); - inFiles.pop_back(); + inFiles.erase(inFileIt); if( !inFile.is_open() ) continue; @@ -382,3 +371,22 @@ void configcache::deleteHeaderStore() headerStore.pop_back(); } } + +vector::iterator configcache::getNextInfile(vector *excludeFileHashes) { + for (vector::iterator init = inFiles.begin(); init != inFiles.end(); ++init) { + if (excludeFileHashes != NULL) { + bool excludethisfile = false; + + for (vector::iterator exit = excludeFileHashes->begin(); exit != excludeFileHashes->end(); ++exit) + if ( *exit == hash(init->filename) ) { + excludethisfile = true; + break; + } + + if (excludethisfile) + continue; + } + return init; + } + return inFiles.end(); +} diff --git a/configcache.h b/configcache.h index d79afa6..82fa3f6 100644 --- a/configcache.h +++ b/configcache.h @@ -46,6 +46,8 @@ class configcache{ string getOutFileName() { return outFileName.str(); } string getInFileName() { return DATADIR + "/" + openFileDesc.filename; } static unsigned long hash(const string& str); + void closeInFile() { inFile.close(); } + int inFilesLeft() { return inFiles.size(); } private: ostream* log; @@ -100,6 +102,8 @@ class configcache{ void deleteHeaderStore(); bool readAllHeaders(); + + vector::iterator getNextInfile(vector *excludeFileHashes); }; #endif diff --git a/hypercache.cpp b/hypercache.cpp index 734a640..03a20f8 100644 --- a/hypercache.cpp +++ b/hypercache.cpp @@ -73,6 +73,12 @@ int hypercache::readC() { return readret; } +int hypercache::read1CForEqui() { + int readret = C->readConfig(NULL); + C->closeInFile(); + return readret; +} + void hypercache::writeC() { C->writeConfig(); activeCFile = fileOfPath( C->getOutFileName().substr( 0, C->getOutFileName().length()-4 ) ); diff --git a/hypercache.h b/hypercache.h index dd2ce0b..a30e28e 100644 --- a/hypercache.h +++ b/hypercache.h @@ -33,6 +33,9 @@ class hypercache { static void *getHeaderC(const string& headerid) { C->getHeader(headerid); } static void finalize(); + + static int read1CForEqui(); + static int CFilesLeft() { return C->inFilesLeft(); } private: struct para{ diff --git a/o815/o815.h b/o815/o815.h index 242d1e8..510e799 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -51,7 +51,7 @@ class o815 { protected: o815 *O815; ostream *log; - int nequi, nskip; + int nequi, nskip, confmemSize; }; struct { diff --git a/o815/sim.cpp b/o815/sim.cpp index 2e68ae2..1b81dda 100644 --- a/o815/sim.cpp +++ b/o815/sim.cpp @@ -3,20 +3,41 @@ #include "latlib/hypercache.h" #include "latlib/progress.h" -o815::sim::sim(o815 *_O815, const int& confmemSize) { +o815::sim::sim(o815 *_O815, const int& _confmemSize) { O815 = _O815; log = O815->out->log; - hypercache::initC(O815->programid, O815->comargs.nequi, O815->comargs.nskip, O815->comargs.confcache.first, &confMem, confmemSize, O815->comargs.confcache.second, log); + hypercache::initC(O815->programid, O815->comargs.nequi, O815->comargs.nskip, O815->comargs.confcache.first, &confMem, _confmemSize, O815->comargs.confcache.second, log); toEquilibrate = true; nequi = O815->comargs.nequi; nskip = O815->comargs.nskip; + confmemSize = confmemSize; } void o815::sim::nextConfig() { int nequileft = hypercache::readC(); if ( nequileft != -1 ) { - if(toEquilibrate) { + /* try to use excluded config-file for equilibration */ + if (toEquilibrate && hypercache::CFilesLeft() > 0) { + int exnequileft; + char *tmpconfig = (char*) malloc(confmemSize); + + memcpy (tmpconfig, confMem, confmemSize); + exnequileft = hypercache::read1CForEqui(); + + if (exnequileft < nequileft) { + *log << "SIM: Found suitable excluded config-file configuration for equilibration." << endl << flush; + nequileft = exnequileft; + } + else { + *log << "SIM: Could not find suitable excluded config-file configuration for equilibration." << endl << flush; + memcpy (confMem, tmpconfig, confmemSize); + } + + free(tmpconfig); + } + + if(toEquilibrate && nequileft > 0) { _reset(); *log << "SIM: Starting equilibration." << endl << flush; if (nequileft != nequi) @@ -26,7 +47,8 @@ void o815::sim::nextConfig() { _makeSweep(1); while( equiProg.madeStep(iequi) ) *log << "SIM: " << equiProg.done()*100 << "% of equilibration done." << endl << flush; } - } + } + _makeSweep(nskip); hypercache::writeC(); } -- 2.39.5