filedesc->filename = infile;
filedesc->doVirtualEquilibration = false;
- filedesc->readEquilibratedConfigs = 0;
+ filedesc->firstConfig = true;
if( infile.size() < 4 ) return false;
void configcache::readConfig(bool& readnewconfig, int& nequileft, vector<unsigned long> *excludeFileHashes)
{
readnewconfig = false;
- nequileft = NEQUI;
if(DATADIR == "" || MODE == CACHE_MODE_DISABLED) return;
{
vector<infiledesc>::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;
for (int iskip=0; iskip < (NEQUI-openFileDesc.nequi)/openFileDesc.nskip; iskip++) {
if( readFullBlock(tmpConfig, configSize) != configSize || ! inFile.is_open() )
break;
- else if ( (NEQUI-openFileDesc.nequi) - (iskip+1)*openFileDesc.nskip < nequileft ) {
+ else if ( (NEQUI-openFileDesc.nequi) - (iskip+1)*openFileDesc.nskip < nequileft_internal ) {
memcpy(configMem, tmpConfig, configSize);
- nequileft = (NEQUI-openFileDesc.nequi) - (iskip+1)*openFileDesc.nskip;
+ nequileft_internal = NEQUI - openFileDesc.nequi - (iskip+1)*openFileDesc.nskip;
+ cout << "blabla:" << nequileft_internal << endl;
readnewconfig = true;
}
}
+ openFileDesc.firstConfig = false;
}
if( readFullBlock(tmpConfig, configSize) == configSize && inFile.is_open() )
{
memcpy(configMem, tmpConfig, configSize);
readnewconfig = true;
- nequileft = NEQUI - openFileDesc.nequi - openFileDesc.readEquilibratedConfigs*openFileDesc.nskip;
- openFileDesc.readEquilibratedConfigs++;
+ if (openFileDesc.firstConfig) {
+ openFileDesc.firstConfig = false;
+ nequileft_internal = NEQUI - openFileDesc.nequi;
+ }
+ nequileft_internal -= openFileDesc.nskip;
+ cout << "sadasd:" << nequileft_internal << endl;
+ nequileft = nequileft_internal;
return;
}
else {
int nskip;
bool doVirtualEquilibration;
bool extended;
- int readEquilibratedConfigs;
+ bool firstConfig;
};
class configcache{
static unsigned long hash(const string& str);
void closeInFile() { inFile.close(); }
int inFilesLeft() { return inFiles.size(); }
+ char* getConfigMem() { return configMem; }
+ int getConfigSize() { return configSize; }
private:
ostream* log;
bool readAllHeaders();
vector<infiledesc>::iterator getNextInfile(vector<unsigned long> *excludeFileHashes);
+
+ int nequileft_internal;
};
#endif
vector<unsigned long> hypercache::parentConfigs;
ostream* hypercache::log;
vector<configcache*> 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,
for (vector<para>::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) {
for (vector<configcache*>::iterator osit = Os.begin(); osit != Os.end(); ++osit)
(*osit)->setPara(parid, val);
+
+ nequileft = NEQUI;
}
void hypercache::finalize() {
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 ) );
}
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); }
static vector<unsigned long> parentConfigs;
static void addParentConfig(const unsigned long *parentconfig);
static ostream* log;
+
+ static int NEQUI;
+ static int NSKIP;
+ static int nequileft;
};
#endif
*out->log << " " << (*obsit)->obsid;
*out->log << endl << flush;
- 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) {
void nextConfig();
char *confMem;
virtual void _newParas() {};
- int nequileft;
private:
virtual void _reset()=0;
virtual void _makeSweep()=0;
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<nequileft; iequi++ ) {
+ if (hypercache::getNEquiLeft() != nequi)
+ *log << "SIM: " << hypercache::getNEquiLeft() << " of " << nequi << " equilibration steps left after virtual equilibration." << endl << flush;
+ progress equiProg(hypercache::getNEquiLeft());
+ for ( int iequi = 0; iequi < hypercache::getNEquiLeft(); iequi++ ) {
_makeSweep();
while( equiProg.madeStep(iequi) ) *log << "SIM: " << equiProg.done()*100 << "% of equilibration done." << endl << flush;
}
- nequileft = 0;
skippedInEqui = true;
createdNoNewConfigs = false;
}
/* make skip if no config could be read */
- if ( ! skippedInEqui && readNoSingleConfig ) {
- cout << "here" << endl;
+ if ( (! readAtLeastOneConfig) ) {
+ cout << "SKIPPING" << endl;
for (int iskip=0; iskip<nskip; iskip++) {
_makeSweep();
- nequileft--;
}
createdNoNewConfigs = false;
}
- if (! createdNoNewConfigs)
- hypercache::writeC(nequi-nequileft);
+ if (! createdNoNewConfigs) {
+ cout << "::" << hypercache::getNEquiLeft() << endl;
+ hypercache::writeC();
+ }
- cout << nequileft << endl;
+ cout << hypercache::getNEquiLeft() << endl;
}