From: Alex Schmidt Date: Tue, 18 Jun 2013 13:46:56 +0000 (+0200) Subject: ... X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/46e492935d31a36641b8e8a5cd27bd86e7df96c4 ... --- diff --git a/configcache.cpp b/configcache.cpp index 168de5e..35e8548 100644 --- a/configcache.cpp +++ b/configcache.cpp @@ -73,7 +73,7 @@ bool configcache::isValidInFile(const string& infile, infiledesc *filedesc) filedesc->filename = infile; filedesc->doVirtualEquilibration = false; - filedesc->readEquilibratedConfigs = 0; + filedesc->firstConfig = true; if( infile.size() < 4 ) return false; @@ -183,7 +183,6 @@ void * configcache::getHeader(const string& headerid) { void configcache::readConfig(bool& readnewconfig, int& nequileft, vector *excludeFileHashes) { readnewconfig = false; - nequileft = NEQUI; if(DATADIR == "" || MODE == CACHE_MODE_DISABLED) return; @@ -196,7 +195,11 @@ void configcache::readConfig(bool& readnewconfig, int& nequileft, vector::iterator inFileIt = getNextInfile(excludeFileHashes); - if( (!inFile.is_open()) && inFileIt == inFiles.end() ) return; + if( (!inFile.is_open()) && inFileIt == inFiles.end() ) { + cout << "RETURNING..." << endl; + nequileft = nequileft_internal; + return; + } while( (!inFile.is_open()) && inFiles.size() > 0 ) { openFileDesc = *inFileIt; @@ -221,20 +224,27 @@ void configcache::readConfig(bool& readnewconfig, int& nequileft, vector::iterator getNextInfile(vector *excludeFileHashes); + + int nequileft_internal; }; #endif diff --git a/hypercache.cpp b/hypercache.cpp index 7b3f470..0f8d856 100644 --- a/hypercache.cpp +++ b/hypercache.cpp @@ -7,6 +7,9 @@ string hypercache::activeCFile = ""; vector hypercache::parentConfigs; ostream* hypercache::log; vector hypercache::Os; +int hypercache::NEQUI; +int hypercache::NSKIP; +int hypercache::nequileft; void hypercache::initCache(configcache **cache, const string& cacheid, const int& nequi, const int& nskip, const string& datadir, @@ -21,6 +24,9 @@ void hypercache::initCache(configcache **cache, for (vector::iterator parit=delayedParaSet.begin(); parit != delayedParaSet.end(); ++parit) (*cache)->setPara(parit->parid, parit->val); + + NEQUI = nequi; + NSKIP = nskip; } void hypercache::addPara(const string& parid, const double& val) { @@ -47,6 +53,8 @@ void hypercache::setPara(const string& parid, const double& val) { for (vector::iterator osit = Os.begin(); osit != Os.end(); ++osit) (*osit)->setPara(parid, val); + + nequileft = NEQUI; } void hypercache::finalize() { @@ -60,17 +68,65 @@ string hypercache::fileOfPath(const string& dressedfile) { return dressedfile.substr(dressedfile.find_last_of("\\/")+1); } -void hypercache::readC(bool& readnewconfig, int& nequileft) { - C->readConfig(readnewconfig, nequileft, &parentConfigs); +bool hypercache::readC() { + bool readnewconfig_nonex; + int nequileftReadConfig_nonex; + bool readAtLeastOneConfig = false; + + C->readConfig(readnewconfig_nonex, nequileftReadConfig_nonex, &parentConfigs); + + if (readnewconfig_nonex) { + cout << ":" << nequileftReadConfig_nonex << endl; + nequileft = nequileftReadConfig_nonex; + readAtLeastOneConfig = true; + } if ( nequileft < 0 ) activeCFile = fileOfPath(C->getInFileName()); else activeCFile = ""; + + /* try to find more equilibrated config-file configuration for equilibration in excluded files */ + if ( nequileft > 0 && C->inFilesLeft() > 0 ) { + *log << "HYPERCACHE: Trying to find more equilibrated config in excluded files." << endl << flush; + + char *tmpconfig = (char*) malloc(C->getConfigSize()); + + while (true) { + bool readnewconfig_ex; + int nequileftReadConfig_ex; + + memcpy (tmpconfig, C->getConfigMem(), C->getConfigSize()); + C->readConfig(readnewconfig_ex, nequileftReadConfig_ex, NULL); + + if (! readnewconfig_ex) { + *log << "HYPERCACHE: No more excluded config-files for possible equilibration available." << endl << flush; + break; + } + + if (nequileftReadConfig_ex <= nequileft) { + *log << "HYPERCACHE: Found more equilibrated or same equilibrated excluded config-file configuration for equilibration." << endl << flush; + nequileft = nequileftReadConfig_ex; + readAtLeastOneConfig = true; + } + else if (nequileftReadConfig_ex > nequileft) { + *log << "HYPERCACHE: Excluded config-file configuration for equilibration is less equilibrated than actual config." << endl << flush; + memcpy (C->getConfigMem(), tmpconfig, C->getConfigSize()); + } + } + free(tmpconfig); + } + + return readAtLeastOneConfig; } -void hypercache::writeC(int actnequi) { - C->writeConfig(actnequi); +void hypercache::writeC() { + if (nequileft > 0) + nequileft = 0; + + nequileft -= NSKIP; + + C->writeConfig(NEQUI-nequileft-NSKIP); activeCFile = fileOfPath( C->getOutFileName().substr( 0, C->getOutFileName().length()-4 ) ); } diff --git a/hypercache.h b/hypercache.h index 1daa675..79fe825 100644 --- a/hypercache.h +++ b/hypercache.h @@ -20,13 +20,15 @@ class hypercache { char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL, ostream *_log=NULL) { initCache(&C, cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, _log); } + + static int getNEquiLeft() { return nequileft; } static void addPara(const string& parid, const double& val=0); static void setPara(const string& parid, const double& value); static void readO(int obsid, bool& readnewconfig, int& nequileft); - static void readC(bool& readnewconfig, int& nequileft); + static bool readC(); static void writeO(int obsid, int actnequi); - static void writeC(int actnequi); + static void writeC(); static void writeHeaderO(int obsid, const string& headerid, char *header, long unsigned int size, int actnequi) { Os[obsid]->writeHeader(headerid, header, size, actnequi); } static void *getHeaderO(int obsid, const string& headerid) { Os[obsid]->getHeader(headerid); } static void writeHeaderC(const string& headerid, char *header, long unsigned int size, int actnequi) { C->writeHeader(headerid, header, size, actnequi); } @@ -59,6 +61,10 @@ class hypercache { static vector parentConfigs; static void addParentConfig(const unsigned long *parentconfig); static ostream* log; + + static int NEQUI; + static int NSKIP; + static int nequileft; }; #endif diff --git a/o815/o815.cpp b/o815/o815.cpp index 878df0f..9afaa0c 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -135,8 +135,6 @@ void o815::mainLoop() { *out->log << " " << (*obsit)->obsid; *out->log << endl << flush; - Sim->nequileft = comargs.nequi; - for( int imeas=0; imeas::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { diff --git a/o815/o815.h b/o815/o815.h index 67ef320..ac192cf 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -45,7 +45,6 @@ class o815 { void nextConfig(); char *confMem; virtual void _newParas() {}; - int nequileft; private: virtual void _reset()=0; virtual void _makeSweep()=0; diff --git a/o815/sim.cpp b/o815/sim.cpp index b37549a..6abf7c6 100644 --- a/o815/sim.cpp +++ b/o815/sim.cpp @@ -18,67 +18,37 @@ void o815::sim::nextConfig() { bool skippedInEqui = false; bool readNoSingleConfig = true; bool createdNoNewConfigs = true; + bool readAtLeastOneConfig; - hypercache::readC(readnewconfig, nequileftReadConfig); - - if (readnewconfig) { - nequileft = nequileftReadConfig; - readNoSingleConfig = false; - } - - /* try to find more equilibrated config-file for equilibration including excluded files */ - if ( nequileft > 0 && hypercache::CFilesLeft() > 0 ) { - char *tmpconfig = (char*) malloc(confmemSize); - - while (true) { - memcpy (tmpconfig, confMem, confmemSize); - hypercache::readC(readnewconfig, nequileftReadConfig); - - if (! readnewconfig) { - *log << "SIM: No more excluded config-files for possible equilibration available." << endl << flush; - break; - } - - if (nequileftReadConfig <= nequileft) { - *log << "SIM: Found more equilibrated or same equilibrated excluded config-file configuration for equilibration." << endl << flush; - nequileft = nequileftReadConfig; - readNoSingleConfig = false; - } - else if (nequileftReadConfig > nequileft) { - *log << "SIM: Excluded config-file configuration for equilibration is less equilibrated than actual config." << endl << flush; - memcpy (confMem, tmpconfig, confmemSize); - } - } - free(tmpconfig); - } + readAtLeastOneConfig = hypercache::readC(); /* equilibrate if necessary */ - if (nequileft > 0) { + if (hypercache::getNEquiLeft() > 0) { *log << "SIM: Starting equilibration." << endl << flush; - if (nequileft != nequi) - *log << "SIM: " << nequileft << " of " << nequi << " equilibration steps left after virtual equilibration." << endl << flush; - progress equiProg(nequileft); - for ( int iequi=0; iequi