From: Alex Schmidt Date: Mon, 17 Jun 2013 13:01:38 +0000 (+0200) Subject: ... X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/36bc55ceb7b62569c7604f28b3e53bc2e42cf0ce?ds=sidebyside ... --- diff --git a/configcache.cpp b/configcache.cpp index 02b6d94..168de5e 100644 --- a/configcache.cpp +++ b/configcache.cpp @@ -37,11 +37,11 @@ configcache::configcache(const string& cacheid, const int& nequi, const int& nsk refetchDataFiles = false; } -string configcache::getFileId(const bool& shortid) +string configcache::getFileId(int actnequi, const bool& shortid) { stringstream fileid; - if(!shortid) fileid << CACHEID << "_" << NEQUI << "_" << NSKIP; + if(!shortid) fileid << CACHEID << "_" << actnequi << "_" << NSKIP; for(int ipara=0; iparafilename = infile; filedesc->doVirtualEquilibration = false; + filedesc->readEquilibratedConfigs = 0; if( infile.size() < 4 ) return false; @@ -97,9 +98,7 @@ bool configcache::isValidInFile(const string& infile, infiledesc *filedesc) return false; break; case 2: - if (atoi(inParts) > NEQUI) - return false; - else if (atoi(inParts) < NEQUI) + if (atoi(inParts) < NEQUI) filedesc->doVirtualEquilibration = true; filedesc->nequi = atoi(inParts); break; @@ -115,7 +114,7 @@ bool configcache::isValidInFile(const string& infile, infiledesc *filedesc) delete[] inchar; - if( truncIn.find( getFileId(true) + "_" ) == string::npos ) return false; + if( truncIn.find( getFileId(NEQUI, true) + "_" ) == string::npos ) return false; return true; } @@ -179,12 +178,14 @@ void * configcache::getHeader(const string& headerid) { return NULL; } -/* returns number of equilibration-steps left */ -int configcache::readConfig(vector *excludeFileHashes) +/* returns number of equilibration-steps left with new read configuration + or zero if no new configuration was read */ +void configcache::readConfig(bool& readnewconfig, int& nequileft, vector *excludeFileHashes) { - int nequileft = NEQUI; + readnewconfig = false; + nequileft = NEQUI; - if(DATADIR == "" || MODE == CACHE_MODE_DISABLED) return nequileft; + if(DATADIR == "" || MODE == CACHE_MODE_DISABLED) return; if(refetchDataFiles){ refetchDataFiles = false; @@ -195,7 +196,7 @@ int configcache::readConfig(vector *excludeFileHashes) { vector::iterator inFileIt = getNextInfile(excludeFileHashes); - if( (!inFile.is_open()) && inFileIt == inFiles.end() ) return nequileft; + if( (!inFile.is_open()) && inFileIt == inFiles.end() ) return; while( (!inFile.is_open()) && inFiles.size() > 0 ) { openFileDesc = *inFileIt; @@ -223,6 +224,7 @@ int configcache::readConfig(vector *excludeFileHashes) else if ( (NEQUI-openFileDesc.nequi) - (iskip+1)*openFileDesc.nskip < nequileft ) { memcpy(configMem, tmpConfig, configSize); nequileft = (NEQUI-openFileDesc.nequi) - (iskip+1)*openFileDesc.nskip; + readnewconfig = true; } } } @@ -230,7 +232,10 @@ int configcache::readConfig(vector *excludeFileHashes) if( readFullBlock(tmpConfig, configSize) == configSize && inFile.is_open() ) { memcpy(configMem, tmpConfig, configSize); - return -1; + readnewconfig = true; + nequileft = NEQUI - openFileDesc.nequi - openFileDesc.readEquilibratedConfigs*openFileDesc.nskip; + openFileDesc.readEquilibratedConfigs++; + return; } else { if(log) *log << "CCACHE: Could not read configuration. Closing dat-file: " << openFileDesc.filename << endl << flush; @@ -240,12 +245,12 @@ int configcache::readConfig(vector *excludeFileHashes) } } -void configcache::openOutFile() +void configcache::openOutFile(int actnequi) { time_t secstamp = time(NULL); outFileName.str(""); - outFileName << DATADIR << "/" << secstamp << "_" << getFileId() << "_.edat.tmp"; + outFileName << DATADIR << "/" << secstamp << "_" << getFileId(actnequi) << "_.edat.tmp"; outFile.open( outFileName.str().c_str(), std::ios::binary ); @@ -254,13 +259,13 @@ void configcache::openOutFile() outBuffer->push(outFile); } -void configcache::writeHeader(const string& headerid, const char *header, long unsigned int size) { +void configcache::writeHeader(const string& headerid, const char *header, long unsigned int size, int actnequi) { unsigned long headeridhash; if( DATADIR == "" || MODE < 2 ) return; if(!outFile.is_open()) - openOutFile(); + openOutFile(actnequi); headeridhash = hash(headerid); @@ -269,14 +274,14 @@ void configcache::writeHeader(const string& headerid, const char *header, long u boost::iostreams::write(*outBuffer, header, size); } -void configcache::writeConfig() +void configcache::writeConfig(int actnequi) { long unsigned int zeroheader=0; if ( DATADIR == "" || MODE < 2 ) return; if ( ! outFile.is_open() ) - openOutFile(); + openOutFile(actnequi); boost::iostreams::write(*outBuffer, (char*)&zeroheader, sizeof(long unsigned int)); diff --git a/configcache.h b/configcache.h index 82fa3f6..0af533a 100644 --- a/configcache.h +++ b/configcache.h @@ -30,6 +30,7 @@ struct infiledesc { int nskip; bool doVirtualEquilibration; bool extended; + int readEquilibratedConfigs; }; class configcache{ @@ -37,11 +38,11 @@ class configcache{ ~configcache(); configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL, ostream *_log=NULL); - int readConfig(vector *excludeFileHashes=NULL); - void writeConfig(); + void readConfig(bool& readnewconfig, int& nequileft, vector *excludeFileHashes=NULL); + void writeConfig(int actnequi); void addPara(const string& parid, const double& val=0); void setPara(const string& parid, const double& value); - void writeHeader(const string& headerid, const char *header, long unsigned int size); + void writeHeader(const string& headerid, const char *header, long unsigned int size, int actnequi); void * getHeader(const string& headerid); string getOutFileName() { return outFileName.str(); } string getInFileName() { return DATADIR + "/" + openFileDesc.filename; } @@ -59,7 +60,7 @@ class configcache{ string DATADIR; string CACHEID; int MODE; - string getFileId(const bool& shortid=false); + string getFileId(int actnequi, const bool& shortid=false); ofstream outFile; ifstream inFile; @@ -89,7 +90,7 @@ class configcache{ int readDataToMem(char *tmpData, long unsigned int dataSize); - void openOutFile(); + void openOutFile(int actnequi); int readHeader(); diff --git a/hypercache.cpp b/hypercache.cpp index 03a20f8..7b3f470 100644 --- a/hypercache.cpp +++ b/hypercache.cpp @@ -60,50 +60,36 @@ string hypercache::fileOfPath(const string& dressedfile) { return dressedfile.substr(dressedfile.find_last_of("\\/")+1); } -int hypercache::readC() { - int readret; +void hypercache::readC(bool& readnewconfig, int& nequileft) { + C->readConfig(readnewconfig, nequileft, &parentConfigs); - readret = C->readConfig(&parentConfigs); - - if ( readret == -1 ) + if ( nequileft < 0 ) activeCFile = fileOfPath(C->getInFileName()); else activeCFile = ""; - - return readret; -} - -int hypercache::read1CForEqui() { - int readret = C->readConfig(NULL); - C->closeInFile(); - return readret; } -void hypercache::writeC() { - C->writeConfig(); +void hypercache::writeC(int actnequi) { + C->writeConfig(actnequi); activeCFile = fileOfPath( C->getOutFileName().substr( 0, C->getOutFileName().length()-4 ) ); } -void hypercache::writeO(int obsid) { +void hypercache::writeO(int obsid, int actnequi) { if ( activeCFile != "" ) { unsigned long afilehash = configcache::hash(activeCFile); - Os[obsid]->writeHeader("concurrent_cfile", (char*)(&afilehash), sizeof(unsigned long)); + Os[obsid]->writeHeader("concurrent_cfile", (char*)(&afilehash), sizeof(unsigned long), actnequi); } - Os[obsid]->writeConfig(); + Os[obsid]->writeConfig(actnequi); } -int hypercache::readO(int obsid) { - int readret; - - readret = Os[obsid]->readConfig(); +void hypercache::readO(int obsid, bool& readnewconfig, int& nequileft) { + Os[obsid]->readConfig(readnewconfig, nequileft); - if ( readret == -1 ) { + if ( nequileft < 0 ) { unsigned long *parentconfig = (unsigned long*)Os[obsid]->getHeader("concurrent_cfile"); if ( parentconfig != NULL ) addParentConfig(parentconfig); } - - return readret; } void hypercache::addParentConfig(const unsigned long *parentconfig) { diff --git a/hypercache.h b/hypercache.h index a30e28e..1daa675 100644 --- a/hypercache.h +++ b/hypercache.h @@ -23,18 +23,17 @@ class hypercache { static void addPara(const string& parid, const double& val=0); static void setPara(const string& parid, const double& value); - static int readO(int obsid); - static int readC(); - static void writeO(int obsid); - static void writeC(); - static void writeHeaderO(int obsid, const string& headerid, char *header, long unsigned int size) { Os[obsid]->writeHeader(headerid, header, size); } + static void readO(int obsid, bool& readnewconfig, int& nequileft); + static void readC(bool& readnewconfig, int& nequileft); + static void writeO(int obsid, int actnequi); + static void writeC(int actnequi); + 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) { C->writeHeader(headerid, header, size); } + static void writeHeaderC(const string& headerid, char *header, long unsigned int size, int actnequi) { C->writeHeader(headerid, header, size, actnequi); } static void *getHeaderC(const string& headerid) { C->getHeader(headerid); } static void finalize(); - static int read1CForEqui(); static int CFilesLeft() { return C->inFilesLeft(); } private: diff --git a/o815/o815.cpp b/o815/o815.cpp index ff0b1ae..878df0f 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -135,18 +135,23 @@ void o815::mainLoop() { *out->log << " " << (*obsit)->obsid; *out->log << endl << flush; - Sim->toEquilibrate = true; + Sim->nequileft = comargs.nequi; for( int imeas=0; imeas::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { - if( hypercache::readO( (*obsit)->ocid ) != -1 ) { + bool readnewObs; + int nequileftNewObs; + + hypercache::readO( (*obsit)->ocid, readnewObs, nequileftNewObs ); + + if( ! readnewObs ) { if (!nextAlready) { Sim->nextConfig(); nextAlready = true; } (*obsit)->meas(false); - hypercache::writeO( (*obsit)->ocid ); + hypercache::writeO( (*obsit)->ocid, comargs.nmeas ); } else (*obsit)->meas(true); diff --git a/o815/o815.h b/o815/o815.h index 69a8276..67ef320 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -43,9 +43,9 @@ class o815 { public: sim(o815 *_O815, const int& _confmemSize); void nextConfig(); - bool toEquilibrate; 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 4e885b5..b37549a 100644 --- a/o815/sim.cpp +++ b/o815/sim.cpp @@ -7,53 +7,78 @@ 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); - toEquilibrate = true; nequi = O815->comargs.nequi; nskip = O815->comargs.nskip; confmemSize = confmemSize; } void o815::sim::nextConfig() { - int nequileft = hypercache::readC(); + bool readnewconfig; + int nequileftReadConfig; + bool skippedInEqui = false; + bool readNoSingleConfig = true; + bool createdNoNewConfigs = true; - if ( nequileft != -1 ) { - /* try to use excluded config-file for equilibration */ - if (toEquilibrate && hypercache::CFilesLeft() > 0) { - int exnequileft; - char *tmpconfig = (char*) malloc(confmemSize); + 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); - exnequileft = hypercache::read1CForEqui(); + hypercache::readC(readnewconfig, nequileftReadConfig); - if (exnequileft < nequileft) { - *log << "SIM: Found suitable excluded config-file configuration for equilibration." << endl << flush; - nequileft = exnequileft; + if (! readnewconfig) { + *log << "SIM: No more excluded config-files for possible equilibration available." << endl << flush; + break; } - else { - *log << "SIM: Could not find suitable excluded config-file configuration for equilibration." << endl << flush; + + 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); } + free(tmpconfig); + } - if(toEquilibrate && nequileft > 0) { - _reset(); - *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 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