From a477390b3aa6eea3a7d822a0499816eb0e2bf499 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Wed, 19 Jun 2013 11:12:59 +0200 Subject: [PATCH 1/1] ... --- configcache.cpp | 5 ----- hypercache.cpp | 19 ++++++++++++++++++- hypercache.h | 3 +++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/configcache.cpp b/configcache.cpp index b6edc17..4c7963d 100644 --- a/configcache.cpp +++ b/configcache.cpp @@ -193,7 +193,6 @@ void configcache::readConfig(bool& readnewconfig, int& nequileft, vector hypercache::Os; int hypercache::NEQUI; int hypercache::NSKIP; int hypercache::nequileft; +pair hypercache::mostEquilibratedConfig; void hypercache::initCache(configcache **cache, const string& cacheid, const int& nequi, const int& nskip, const string& datadir, @@ -55,6 +56,7 @@ void hypercache::setPara(const string& parid, const double& val) { (*osit)->setPara(parid, val); nequileft = NEQUI; + mostEquilibratedConfig.first = NEQUI; } void hypercache::finalize() { @@ -76,7 +78,6 @@ bool hypercache::readC() { C->readConfig(readnewconfig_nonex, nequileftReadConfig_nonex, &parentConfigs); if (readnewconfig_nonex) { - cout << ":" << nequileftReadConfig_nonex << endl; nequileft = nequileftReadConfig_nonex; readAtLeastOneConfig = true; } @@ -117,6 +118,22 @@ bool hypercache::readC() { free(tmpconfig); } + /* storing most equilibrated config */ + if ( nequileft < mostEquilibratedConfig.first && readAtLeastOneConfig ) { + *log << "HYPERCACHE: Storing a copy of so far most equilibrated config with nequileft = " << nequileft << endl << flush; + mostEquilibratedConfig.first = nequileft; + memcpy(mostEquilibratedConfig.second, C->getConfigMem(), C->getConfigSize()); + } + + + /* injecting back most equilibrated config if nothing could be used anymore */ + if ( nequileft > 0 && mostEquilibratedConfig.first < nequileft ) { + *log << "HYPERCACHE: Injecting back most equilibrated stored config with nequileft = " << mostEquilibratedConfig.first << endl << flush; + nequileft = mostEquilibratedConfig.first; + memcpy(C->getConfigMem(), mostEquilibratedConfig.second, C->getConfigSize()); + readAtLeastOneConfig = false; + } + return readAtLeastOneConfig; } diff --git a/hypercache.h b/hypercache.h index 79fe825..20ce840 100644 --- a/hypercache.h +++ b/hypercache.h @@ -19,6 +19,7 @@ class hypercache { static void initC(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) { initCache(&C, cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, _log); + mostEquilibratedConfig.second = new char[configMemSize]; } static int getNEquiLeft() { return nequileft; } @@ -65,6 +66,8 @@ class hypercache { static int NEQUI; static int NSKIP; static int nequileft; + + static pair mostEquilibratedConfig; }; #endif -- 2.39.5