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; ipara<Paras.size(); ipara++)
fileid << "_" << Paras[ipara].id << Paras[ipara].val;
filedesc->filename = infile;
filedesc->doVirtualEquilibration = false;
+ filedesc->readEquilibratedConfigs = 0;
if( infile.size() < 4 ) return false;
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;
delete[] inchar;
- if( truncIn.find( getFileId(true) + "_" ) == string::npos ) return false;
+ if( truncIn.find( getFileId(NEQUI, true) + "_" ) == string::npos ) return false;
return true;
}
return NULL;
}
-/* returns number of equilibration-steps left */
-int configcache::readConfig(vector<unsigned long> *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<unsigned long> *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;
{
vector<infiledesc>::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;
else if ( (NEQUI-openFileDesc.nequi) - (iskip+1)*openFileDesc.nskip < nequileft ) {
memcpy(configMem, tmpConfig, configSize);
nequileft = (NEQUI-openFileDesc.nequi) - (iskip+1)*openFileDesc.nskip;
+ readnewconfig = true;
}
}
}
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;
}
}
-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 );
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);
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));
int nskip;
bool doVirtualEquilibration;
bool extended;
+ int readEquilibratedConfigs;
};
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<unsigned long> *excludeFileHashes=NULL);
- void writeConfig();
+ void readConfig(bool& readnewconfig, int& nequileft, vector<unsigned long> *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; }
string DATADIR;
string CACHEID;
int MODE;
- string getFileId(const bool& shortid=false);
+ string getFileId(int actnequi, const bool& shortid=false);
ofstream outFile;
ifstream inFile;
int readDataToMem(char *tmpData, long unsigned int dataSize);
- void openOutFile();
+ void openOutFile(int actnequi);
int readHeader();
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) {
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:
*out->log << " " << (*obsit)->obsid;
*out->log << endl << flush;
- Sim->toEquilibrate = true;
+ Sim->nequileft = comargs.nequi;
for( int imeas=0; imeas<comargs.nmeas; imeas++ ) {
bool nextAlready = false;
for (vector<obs*>::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);
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;
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<nequileft; iequi++ ) {
- _makeSweep();
- while( equiProg.madeStep(iequi) ) *log << "SIM: " << equiProg.done()*100 << "% of equilibration done." << endl << flush;
- }
+ /* equilibrate if necessary */
+ if (nequileft > 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<nequileft; iequi++ ) {
+ _makeSweep();
+ while( equiProg.madeStep(iequi) ) *log << "SIM: " << equiProg.done()*100 << "% of equilibration done." << endl << flush;
}
-
- for (int iskip=0; iskip<nskip; iskip++)
+ nequileft = 0;
+ skippedInEqui = true;
+ createdNoNewConfigs = false;
+ }
+
+ /* make skip if no config could be read */
+ if ( ! skippedInEqui && readNoSingleConfig ) {
+ cout << "here" << endl;
+ for (int iskip=0; iskip<nskip; iskip++) {
_makeSweep();
-
- hypercache::writeC();
+ nequileft--;
+ }
+ createdNoNewConfigs = false;
}
-
- toEquilibrate = false;
+
+ if (! createdNoNewConfigs)
+ hypercache::writeC(nequi-nequileft);
+
+ cout << nequileft << endl;
}