From 57120da66874b239e28824c9790a62c3556a489e Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Thu, 18 Apr 2013 20:58:21 +0200 Subject: [PATCH 01/16] ... --- o815/o815.cpp | 21 ++++++++++++--------- o815/o815.h | 5 ++++- o815/obs.cpp | 6 ++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/o815/o815.cpp b/o815/o815.cpp index 29f5fd3..4d6f047 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -33,14 +33,6 @@ o815::o815(int argc, char **argv, const string& _programid) { exit(0); } - if( comargs.showjobnum ) { - for( int i=1; i<=paraQ->getTotalJobs(); i++ ) { - if( paraQ->getTotalJobs()%i == 0 ) cout << paraQ->getTotalJobs()/i << "@" << i << " "; - } - cout << endl; - exit(0); - } - if(rank==0) { timestamp = time(NULL); for(int idest=1; idestgetTotalJobs(); i++ ) { + if( paraQ->getTotalJobs()%i == 0 ) cout << paraQ->getTotalJobs()/i << "@" << i << " "; + } + cout << endl; + exit(0); + } + *out->log << "OBS: Starting main loop." << endl; for (vector::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) @@ -66,7 +66,10 @@ void o815::mainLoop() { progress measProg(comargs.nmeas); - *out->log << "OBS: Starting measurements." << endl << flush; + *out->log << "OBS: Starting measurement of observables:"; + for (vector::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) + *out->log << " " << (*obsit)->obsid; + *out->log << endl << flush; for( int imeas=0; imeasout->out[obsid]; log = O815->out->log; + paraQ = O815->paraQ; ocid = hypercache::initO(O815->programid + "-" + obsid, O815->comargs.nequi, O815->comargs.nskip, O815->comargs.obscache.first, &obsMem, obsmemSize, O815->comargs.obscache.second, log); } + +void o815::obs::printParas() { + for (vector::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait) + *O815->out->out[obsid] << (*paraQ)[*parait] << "\t"; +} -- 2.39.5 From 81106ca76faf22180d0cd4bc1402847378e4ff68 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Fri, 19 Apr 2013 01:08:01 +0200 Subject: [PATCH 02/16] ... --- o815/o815.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/o815/o815.cpp b/o815/o815.cpp index 4d6f047..f92d37f 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -71,6 +71,8 @@ void o815::mainLoop() { *out->log << " " << (*obsit)->obsid; *out->log << endl << flush; + Sim->toEquilibrate = true; + for( int imeas=0; imeas::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { -- 2.39.5 From c1fa6a1beca0ee805fd717b65ab4e959c5864950 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Fri, 19 Apr 2013 01:21:46 +0200 Subject: [PATCH 03/16] ... --- culooks.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/culooks.cpp b/culooks.cpp index 6e7fded..94b9aa9 100644 --- a/culooks.cpp +++ b/culooks.cpp @@ -18,6 +18,8 @@ culooks::culooks (const char* name, const int& xcubes, const int& ycubes, const window *Win = new window; int winsize[2]; + XInitThreads(); + Win->layout[0] = xcubes; Win->layout[1] = ycubes; Win->aspect = (double)xcubes/ycubes; -- 2.39.5 From ad54f29de351976a096b4991fe426ffc30332df2 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Wed, 15 May 2013 14:22:03 +0200 Subject: [PATCH 04/16] added support for using excluded config-files for equilibration. --- configcache.cpp | 44 ++++++++++++++++++++++++++------------------ configcache.h | 4 ++++ hypercache.cpp | 6 ++++++ hypercache.h | 3 +++ o815/o815.h | 2 +- o815/sim.cpp | 30 ++++++++++++++++++++++++++---- 6 files changed, 66 insertions(+), 23 deletions(-) diff --git a/configcache.cpp b/configcache.cpp index d45e4d6..6cd46a1 100644 --- a/configcache.cpp +++ b/configcache.cpp @@ -186,28 +186,17 @@ int configcache::readConfig(vector *excludeFileHashes) while(true) { - if( (!inFile.is_open()) && inFiles.size() == 0 ) return nequileft; + vector::iterator inFileIt = getNextInfile(excludeFileHashes); - while( (!inFile.is_open()) && inFiles.size() > 0 ) { - bool excludethisfile=false; + if( (!inFile.is_open()) && inFileIt == inFiles.end() ) return nequileft; - openFileDesc = inFiles.back(); + while( (!inFile.is_open()) && inFiles.size() > 0 ) { + openFileDesc = *inFileIt; - if (excludeFileHashes != NULL) - for (vector::iterator exit = excludeFileHashes->begin(); exit != excludeFileHashes->end(); ++exit) - if ( *exit == hash(inFiles.back().filename) ) { - excludethisfile = true; - break; - } - - if ( ! excludethisfile ) { - if(log) *log << "CCACHE: Opening dat-file: " << inFiles.back().filename << endl << flush; - inFile.open( (DATADIR + "/" + inFiles.back().filename).c_str(), std::ios::binary ); - } - else - if(log) *log << "CCACHE: Excluded dat-file: " << inFiles.back().filename << endl << flush; + if(log) *log << "CCACHE: Opening dat-file: " << inFileIt->filename << endl << flush; + inFile.open( (DATADIR + "/" + inFileIt->filename).c_str(), std::ios::binary ); - inFiles.pop_back(); + inFiles.erase(inFileIt); if( !inFile.is_open() ) continue; @@ -382,3 +371,22 @@ void configcache::deleteHeaderStore() headerStore.pop_back(); } } + +vector::iterator configcache::getNextInfile(vector *excludeFileHashes) { + for (vector::iterator init = inFiles.begin(); init != inFiles.end(); ++init) { + if (excludeFileHashes != NULL) { + bool excludethisfile = false; + + for (vector::iterator exit = excludeFileHashes->begin(); exit != excludeFileHashes->end(); ++exit) + if ( *exit == hash(init->filename) ) { + excludethisfile = true; + break; + } + + if (excludethisfile) + continue; + } + return init; + } + return inFiles.end(); +} diff --git a/configcache.h b/configcache.h index d79afa6..82fa3f6 100644 --- a/configcache.h +++ b/configcache.h @@ -46,6 +46,8 @@ class configcache{ string getOutFileName() { return outFileName.str(); } string getInFileName() { return DATADIR + "/" + openFileDesc.filename; } static unsigned long hash(const string& str); + void closeInFile() { inFile.close(); } + int inFilesLeft() { return inFiles.size(); } private: ostream* log; @@ -100,6 +102,8 @@ class configcache{ void deleteHeaderStore(); bool readAllHeaders(); + + vector::iterator getNextInfile(vector *excludeFileHashes); }; #endif diff --git a/hypercache.cpp b/hypercache.cpp index 734a640..03a20f8 100644 --- a/hypercache.cpp +++ b/hypercache.cpp @@ -73,6 +73,12 @@ int hypercache::readC() { return readret; } +int hypercache::read1CForEqui() { + int readret = C->readConfig(NULL); + C->closeInFile(); + return readret; +} + void hypercache::writeC() { C->writeConfig(); activeCFile = fileOfPath( C->getOutFileName().substr( 0, C->getOutFileName().length()-4 ) ); diff --git a/hypercache.h b/hypercache.h index dd2ce0b..a30e28e 100644 --- a/hypercache.h +++ b/hypercache.h @@ -33,6 +33,9 @@ class hypercache { static void *getHeaderC(const string& headerid) { C->getHeader(headerid); } static void finalize(); + + static int read1CForEqui(); + static int CFilesLeft() { return C->inFilesLeft(); } private: struct para{ diff --git a/o815/o815.h b/o815/o815.h index 242d1e8..510e799 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -51,7 +51,7 @@ class o815 { protected: o815 *O815; ostream *log; - int nequi, nskip; + int nequi, nskip, confmemSize; }; struct { diff --git a/o815/sim.cpp b/o815/sim.cpp index 2e68ae2..1b81dda 100644 --- a/o815/sim.cpp +++ b/o815/sim.cpp @@ -3,20 +3,41 @@ #include "latlib/hypercache.h" #include "latlib/progress.h" -o815::sim::sim(o815 *_O815, const int& confmemSize) { +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); + 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(); if ( nequileft != -1 ) { - if(toEquilibrate) { + /* try to use excluded config-file for equilibration */ + if (toEquilibrate && hypercache::CFilesLeft() > 0) { + int exnequileft; + char *tmpconfig = (char*) malloc(confmemSize); + + memcpy (tmpconfig, confMem, confmemSize); + exnequileft = hypercache::read1CForEqui(); + + if (exnequileft < nequileft) { + *log << "SIM: Found suitable excluded config-file configuration for equilibration." << endl << flush; + nequileft = exnequileft; + } + else { + *log << "SIM: Could not find suitable excluded config-file configuration for equilibration." << endl << flush; + memcpy (confMem, tmpconfig, confmemSize); + } + + free(tmpconfig); + } + + if(toEquilibrate && nequileft > 0) { _reset(); *log << "SIM: Starting equilibration." << endl << flush; if (nequileft != nequi) @@ -26,7 +47,8 @@ void o815::sim::nextConfig() { _makeSweep(1); while( equiProg.madeStep(iequi) ) *log << "SIM: " << equiProg.done()*100 << "% of equilibration done." << endl << flush; } - } + } + _makeSweep(nskip); hypercache::writeC(); } -- 2.39.5 From 7ba7584af501689c899b1b311286140d88e23b25 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Tue, 21 May 2013 15:20:10 +0200 Subject: [PATCH 05/16] disabled warnings for unknown command line options. --- o815/o815.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/o815/o815.cpp b/o815/o815.cpp index f92d37f..9b0fff8 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -4,6 +4,8 @@ #include "latlib/progress.h" +extern int opterr; + o815::o815(int argc, char **argv, const string& _programid) { long timestamp; @@ -98,6 +100,8 @@ void o815::mainLoop() { void o815::parseArgs(int argc, char **argv) { int opt = 0; + opterr = 0; + while( (opt = getopt(argc, argv, "L:N:S:E:o:O:c:C:w:i:j:")) != -1 ) switch(opt) { case 'L': -- 2.39.5 From 7a385d92335a4707d5b0aae66e4850d137c1fe7d Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Thu, 23 May 2013 13:51:05 +0200 Subject: [PATCH 06/16] improved argument handling. --- o815/o815.cpp | 122 +++++++++++++++++++++++++++++++++++++++++++++----- o815/o815.h | 23 ++++++++-- 2 files changed, 129 insertions(+), 16 deletions(-) diff --git a/o815/o815.cpp b/o815/o815.cpp index 9b0fff8..4c2b28d 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -1,12 +1,15 @@ #include "o815.h" #include +#include #include "latlib/progress.h" +using namespace std; + extern int opterr; -o815::o815(int argc, char **argv, const string& _programid) { +o815::o815(int argc, char **argv, const string& _programid, comoption specOps[], void (*helpHeader)()) { long timestamp; programid = _programid; @@ -28,7 +31,64 @@ o815::o815(int argc, char **argv, const string& _programid) { paraQ = new paraq(numprocs, rank); - parseArgs(argc, argv); + addComOption("lsize", required_argument, NULL, 'L', "define lattice size", "xsize:tsize"); + addComOption("nmeas", required_argument, NULL, 'N', "set number of measurements", "nmeas"); + addComOption("skip", required_argument, NULL, 'S', "set number of skips between configs", "nskip"); + addComOption("nequi", required_argument, NULL, 'E', "set number of equilibrations", "nequi"); + addComOption("oro", required_argument, NULL, 'o', "read-only observable-store directory", "dir"); + addComOption("orw", required_argument, NULL, 'O', "read-write observable-store directory", "dir"); + addComOption("cro", required_argument, NULL, 'c', "read-only config-store directory", "dir"); + addComOption("crw", required_argument, NULL, 'C', "read-write config-store directory", "dir"); + addComOption("write", required_argument, NULL, 'w', "data writeout directory", "dir"); + addComOption("idonly", no_argument, &comargs.idonly, 'i', "show output-id only", ""); + addComOption("jobnum", no_argument, &comargs.showjobnum, 'j', "show jobnumber only", ""); + + if (specOps != NULL) + for (int ispecop = 0; specOps[ispecop].name != ""; ispecop++) + comOptions.push_back(specOps[ispecop]); + + if (argc > 1) + parseArgs(argc, argv, specOps); + else { + int longestCombinedLong=0; + + if (helpHeader != NULL) + helpHeader(); + + cout << "Options:" << endl; + + for (vector::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) { + stringstream combinedLong; + + combinedLong << opit->name; + if (opit->has_arg == required_argument) + combinedLong << "=" << opit->argdesc; + else if (opit->has_arg == optional_argument) + combinedLong << "[=" << opit->argdesc << "]"; + + if (longestCombinedLong < combinedLong.str().size()) + longestCombinedLong = combinedLong.str().size(); + } + + for (vector::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) { + stringstream combinedLong; + + cout << " -" << char(opit->val) << ", --"; + + combinedLong << opit->name; + if (opit->has_arg == required_argument) + combinedLong << "=" << opit->argdesc; + else if (opit->has_arg == optional_argument) + combinedLong << "[=" << opit->argdesc << "]"; + + cout << setw(longestCombinedLong) << setiosflags(ios::left) << combinedLong.str(); + + cout << "\t" << opit->optdesc; + + cout << endl; + } + exit(0); + } if(comargs.idonly) { cout << programid << headMaster() << endl << flush; @@ -97,12 +157,37 @@ void o815::mainLoop() { } } -void o815::parseArgs(int argc, char **argv) { - int opt = 0; - - opterr = 0; +void o815::addComOption(const char* name, int has_arg, int *flag, int val, const char* optdesc, const char* argdesc) { + comoption newop = { name, has_arg, flag, val, optdesc, argdesc }; + comOptions.push_back(newop); +} + +void o815::parseArgs(int argc, char **argv, comoption specOps[]) { + int opt; + int indexptr=0; + stringstream optargstr; + option allOptions[comOptions.size()+1]; + + for (int iop=0; iop < comOptions.size(); iop++) { + allOptions[iop].name = comOptions[iop].name.c_str(); + allOptions[iop].has_arg = comOptions[iop].has_arg; + //allOptions[iop].flag = NULL; + allOptions[iop].flag = comOptions[iop].flag; + allOptions[iop].val = comOptions[iop].val; + + optargstr << char(allOptions[iop].val); + if (allOptions[iop].has_arg == required_argument) + optargstr << ":"; + else if (allOptions[iop].has_arg == optional_argument) + optargstr << "::"; + } - while( (opt = getopt(argc, argv, "L:N:S:E:o:O:c:C:w:i:j:")) != -1 ) + allOptions[comOptions.size()].name = 0; + allOptions[comOptions.size()].has_arg = 0; + allOptions[comOptions.size()].flag = 0; + allOptions[comOptions.size()].val = 0; + + while((opt = getopt_long( argc, argv, optargstr.str().c_str(), allOptions, &indexptr )) != -1) switch(opt) { case 'L': listArg(comargs.lsize, 2, optarg); @@ -135,13 +220,26 @@ void o815::parseArgs(int argc, char **argv) { case 'w': comargs.outdir = optarg; break; - case 'i': - comargs.idonly = atoi(optarg); - break; - case 'j': - comargs.showjobnum = atoi(optarg); + default: + if ( opt != 0) { + comoption* thisop = getOptionByVal(opt); + if (thisop->flag != 0) + *thisop->flag = thisop->val; + else + parsedSpecOps.push_back( pair(thisop->val, optarg) ); + } break; } + + for (int ilon=0; optind+ilon < argc; ilon++) + lonelyArgs.push_back(argv[optind+ilon]); +} + +o815::comoption* o815::getOptionByVal(int val) { + for (vector::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) + if ( opit->val == val ) + return &(*opit); + return NULL; } void o815::listArg(int *target, int tlen, char *listarg) { diff --git a/o815/o815.h b/o815/o815.h index 510e799..8b00437 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "latlib/paraq.h" #include "latlib/writeout.h" @@ -62,11 +63,20 @@ class o815 { pair obscache; pair confcache; string outdir; - bool idonly; - bool showjobnum; + int idonly; + int showjobnum; } comargs; - o815(int argc, char **argv, const string& programid); + struct comoption { + string name; + int has_arg; + int *flag; + int val; + string optdesc; + string argdesc; + }; + + o815(int argc, char **argv, const string& _programid, comoption specOps[]=NULL, void (*helpHeader)()=NULL); ~o815(); paraq *paraQ; writeout *out; @@ -75,14 +85,19 @@ class o815 { void mainLoop(); string headMaster(); void addPara(const string& paraid, const double& paraDefault); + void addComOption(const char* name, int has_arg, int *flag, int val, const char* optdesc, const char* argdesc); + vector< pair > parsedSpecOps; + vector lonelyArgs; private: + vector comOptions; MPI_Status mpiStatus; int numprocs, rank; static void listArg(int *target, int tlen, char *listarg); - void parseArgs(int argc, char **argv); + void parseArgs(int argc, char **argv, comoption specOps[]); string programid; int nextParas(); + comoption* getOptionByVal(int val); }; #endif -- 2.39.5 From 2c7e8d0d8fdb233087376cc62752fdc45646c8c8 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Thu, 23 May 2013 13:56:01 +0200 Subject: [PATCH 07/16] ... --- o815/o815.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/o815/o815.cpp b/o815/o815.cpp index 4c2b28d..8700f67 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -239,7 +239,7 @@ o815::comoption* o815::getOptionByVal(int val) { for (vector::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) if ( opit->val == val ) return &(*opit); - return NULL; + exit(1); } void o815::listArg(int *target, int tlen, char *listarg) { -- 2.39.5 From a5f05e337d18c193ac57b4da0013d1cdc69f8faa Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Thu, 23 May 2013 15:18:01 +0200 Subject: [PATCH 08/16] ... --- o815/o815.h | 1 - o815/obs.cpp | 5 ----- obs.hpp => obstat.hpp | 18 +++++++++--------- paraq.cpp | 21 +++++++++++++++++++++ paraq.h | 2 ++ 5 files changed, 32 insertions(+), 15 deletions(-) rename obs.hpp => obstat.hpp (87%) diff --git a/o815/o815.h b/o815/o815.h index 8b00437..91fc747 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -36,7 +36,6 @@ class o815 { char *obsMem; string simid, datadesc; ostream *out, *log; - void printParas(); paraq* paraQ; }; diff --git a/o815/obs.cpp b/o815/obs.cpp index c10a5f4..807d4ee 100644 --- a/o815/obs.cpp +++ b/o815/obs.cpp @@ -35,8 +35,3 @@ o815::obs::obs(const string& _obsid, const string& _datadesc, o815 *_O815, const ocid = hypercache::initO(O815->programid + "-" + obsid, O815->comargs.nequi, O815->comargs.nskip, O815->comargs.obscache.first, &obsMem, obsmemSize, O815->comargs.obscache.second, log); } - -void o815::obs::printParas() { - for (vector::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait) - *O815->out->out[obsid] << (*paraQ)[*parait] << "\t"; -} diff --git a/obs.hpp b/obstat.hpp similarity index 87% rename from obs.hpp rename to obstat.hpp index 4d20bd6..d66467b 100644 --- a/obs.hpp +++ b/obstat.hpp @@ -1,5 +1,5 @@ -#ifndef OBS_HPP -#define OBS_HPP +#ifndef OBSTAT_HPP +#define OBSTAT_HPP #include #include @@ -9,7 +9,7 @@ using namespace std; template -class obs +class obstat { public: void addMeas(const obstype& val); @@ -40,20 +40,20 @@ private: template -void obs::reset() +void obstat::reset() { computations.clear(); measurements.clear(); } template -void obs::addMeas(const obstype& val) +void obstat::addMeas(const obstype& val) { measurements.push_back( vector(1,val) ); } template -void obs::addMeas(obstype val[], int valsize) +void obstat::addMeas(obstype val[], int valsize) { vector tmpvec; for(int i=0; i::addMeas(obstype val[], int valsize) } template -void obs::mean(const string& compid, vector< vector > *meas, const int& ival) +void obstat::mean(const string& compid, vector< vector > *meas, const int& ival) { computations[compid].val = 0; computations[compid].err = 0; @@ -78,7 +78,7 @@ void obs::mean(const string& compid, vector< vector > *meas, co } template -void obs::mean(const string& compid, vector< vector > *meas, const int& ival) +void obstat::mean(const string& compid, vector< vector > *meas, const int& ival) { computations[compid].val = 0; computations[compid].err = 0; @@ -95,7 +95,7 @@ void obs::mean(const string& compid, vector< vector > *meas, const } template -void obs::computeJack(const string& compid, double (*func)(vector< vector > *vals, void *para), void *para) +void obstat::computeJack(const string& compid, double (*func)(vector< vector > *vals, void *para), void *para) { int nmeas=measurements.size(); double manymeans[nmeas]; diff --git a/paraq.cpp b/paraq.cpp index 381941f..ac8fc14 100644 --- a/paraq.cpp +++ b/paraq.cpp @@ -129,3 +129,24 @@ void paraq::uniqueAllParaIdsAdd(const string& paraid) { allParaIds.push_back(paraid); } + +string paraq::getParaNames() { + stringstream paranames; + + for (vector::iterator parait = allParaIds.begin(); parait != allParaIds.end(); ++parait) + paranames << *parait << ":"; + + return paranames.str(); +} + +string paraq::getParaVals() { + stringstream paravals; + + for (vector::iterator parait = allParaIds.begin(); parait != allParaIds.end(); ++parait) { + if ( parait != allParaIds.begin() ) + paravals << "\t"; + paravals << (*this)[*parait]; + } + + return paravals.str(); +} diff --git a/paraq.h b/paraq.h index 6aba45b..6dc582d 100644 --- a/paraq.h +++ b/paraq.h @@ -19,6 +19,8 @@ class paraq { int getTotalJobs(); string rangeString(); vector allParaIds; + string getParaNames(); + string getParaVals(); private: int nprocs, rank; -- 2.39.5 From e46233799c25067188549528947ae980579a5e8c Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Fri, 24 May 2013 15:42:19 +0200 Subject: [PATCH 09/16] ... --- o815/o815.cpp | 2 ++ o815/o815.h | 1 + paraq.cpp | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/o815/o815.cpp b/o815/o815.cpp index 8700f67..ff0b1ae 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -125,6 +125,8 @@ void o815::mainLoop() { for (vector::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait) *out->log << *parait << "=" << (*paraQ)[*parait] << " "; *out->log << ">" << endl << flush; + + Sim->_newParas(); progress measProg(comargs.nmeas); diff --git a/o815/o815.h b/o815/o815.h index 91fc747..1b94170 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -45,6 +45,7 @@ class o815 { void nextConfig(); bool toEquilibrate; char *confMem; + virtual void _newParas() {}; private: virtual void _reset()=0; virtual void _makeSweep(int nsweep)=0; diff --git a/paraq.cpp b/paraq.cpp index ac8fc14..87ec773 100644 --- a/paraq.cpp +++ b/paraq.cpp @@ -114,7 +114,8 @@ double& paraq::operator[] (string paraid) { return defaultPara[paraid]; } - return masterdefault; + cerr << "PARAQ: Parameter " << paraid << " does not exist!" << endl << flush; + exit(1); } int paraq::getTotalJobs() { -- 2.39.5 From db68c55d4535522352b71a8d69d3a38ba97c67a5 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Tue, 4 Jun 2013 14:00:16 +0200 Subject: [PATCH 10/16] added underscore in cacheid check --- configcache.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/configcache.cpp b/configcache.cpp index 6cd46a1..bcfe92f 100644 --- a/configcache.cpp +++ b/configcache.cpp @@ -18,6 +18,11 @@ configcache::configcache(const string& cacheid, const int& nequi, const int& nsk DATADIR = datadir; CACHEID = cacheid; + if ( cacheid.find("_") != -1 ) { + if(log) *log << "CCACHE: Invalid cacheid \"" << cacheid << "\" given. Cacheids must not contain underscores!" << endl << flush; + exit(1); + } + configMem = (char*)malloc(configMemSize); tmpConfig = (char*)malloc(configMemSize); @@ -80,7 +85,7 @@ bool configcache::isValidInFile(const string& infile, infiledesc *filedesc) inchar = new char [infile.size()+1]; strcpy (inchar, infile.c_str()); - + inParts = strtok( inchar, "_" ); for(int iPart=0; inParts!=NULL; iPart++) { @@ -88,7 +93,10 @@ bool configcache::isValidInFile(const string& infile, infiledesc *filedesc) switch(iPart) { - case 1: if(inParts != CACHEID) return false; break; + case 1: if(inParts != CACHEID) { + return false; + break; + } case 2: if (atoi(inParts) > NEQUI) return false; -- 2.39.5 From 238fccf7dd50a69b5825f4544b3e247bfbf4e417 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Tue, 4 Jun 2013 14:23:10 +0200 Subject: [PATCH 11/16] bugbug --- configcache.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/configcache.cpp b/configcache.cpp index bcfe92f..02b6d94 100644 --- a/configcache.cpp +++ b/configcache.cpp @@ -93,11 +93,10 @@ bool configcache::isValidInFile(const string& infile, infiledesc *filedesc) switch(iPart) { - case 1: if(inParts != CACHEID) { - return false; - break; - } - case 2: + case 1: if(inParts != CACHEID) + return false; + break; + case 2: if (atoi(inParts) > NEQUI) return false; else if (atoi(inParts) < NEQUI) -- 2.39.5 From 1b842b9fcf404b5973c01ce883eafc53553b83c9 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Wed, 5 Jun 2013 12:59:21 +0200 Subject: [PATCH 12/16] implemented parameter linking. --- paraq.cpp | 23 +++++++++++++++++++++-- paraq.h | 3 +++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/paraq.cpp b/paraq.cpp index 87ec773..93496fc 100644 --- a/paraq.cpp +++ b/paraq.cpp @@ -43,9 +43,22 @@ string paraq::rangeString() for( vector::iterator rangeIt = paraIt->second.begin(); rangeIt != paraIt->second.end(); ++rangeIt) rangestring << "-" << paraIt->first << (*rangeIt)[0] << "_" << (*rangeIt)[1] << "_" << (*rangeIt)[2]; + for (vector< pair >::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) + rangestring << "-" << linkit->first << "->" << linkit->second; + for( map::iterator defIt = defaultPara.begin(); defIt != defaultPara.end(); ++defIt ) - if( rangeMap.find(defIt->first) == rangeMap.end() ) - rangestring << "-" << defIt->first << defIt->second; + if( rangeMap.find(defIt->first) == rangeMap.end() ) { + bool linkedpara = false; + + for (vector< pair >::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) + if (linkit->first == defIt->first) { + linkedpara = true; + break; + } + + if (!linkedpara) + rangestring << "-" << defIt->first << defIt->second; + } return rangestring.str(); } @@ -81,7 +94,13 @@ void paraq::initJobList() while( jobList.begin()->find(paraIt->first) == jobList.begin()->end() ) { for( vector::iterator valIt = paraIt->second.begin(); valIt != paraIt->second.end(); ++valIt ) { jobList.push_back( *jobList.begin() ); + jobList.back()[paraIt->first] = *valIt; + + /* also set linked parameters */ + for (vector< pair >::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) + if (linkit->second == paraIt->first) + jobList.back()[linkit->first] = *valIt; } jobList.erase( jobList.begin() ); } diff --git a/paraq.h b/paraq.h index 6dc582d..0167bcb 100644 --- a/paraq.h +++ b/paraq.h @@ -16,6 +16,8 @@ class paraq { void addRange(const string& paraid, double range[3]) { addRange(paraid, range[0], range[1], range[2]); } void addRange(const string& paraid, char *range); void setDefault(const string& paraid, double value) { defaultPara[paraid] = value; uniqueAllParaIdsAdd(paraid); } + + void linkParas(const string& paraid1, const string ¶id2) { linkedParas.push_back( make_pair(paraid1,paraid2) ); } int getTotalJobs(); string rangeString(); vector allParaIds; @@ -28,6 +30,7 @@ class paraq { map defaultPara; map< string, vector > paraMap; map< string, vector > rangeMap; + vector< pair > linkedParas; vector< map > jobList; void initJobList(); bool inParas(vector& paraVec, double& tofind); -- 2.39.5 From f46daea04f594f9f386ac6514733ec1eff860462 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Mon, 10 Jun 2013 09:33:13 +0200 Subject: [PATCH 13/16] doing sweeploop in o815. --- o815/o815.h | 2 +- o815/sim.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/o815/o815.h b/o815/o815.h index 1b94170..69a8276 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -48,7 +48,7 @@ class o815 { virtual void _newParas() {}; private: virtual void _reset()=0; - virtual void _makeSweep(int nsweep)=0; + virtual void _makeSweep()=0; protected: o815 *O815; ostream *log; diff --git a/o815/sim.cpp b/o815/sim.cpp index 1b81dda..4e885b5 100644 --- a/o815/sim.cpp +++ b/o815/sim.cpp @@ -44,12 +44,14 @@ void o815::sim::nextConfig() { *log << "SIM: " << nequileft << " of " << nequi << " equilibration steps left after virtual equilibration." << endl << flush; progress equiProg(nequileft); for( int iequi=0; iequi Date: Mon, 17 Jun 2013 15:01:38 +0200 Subject: [PATCH 14/16] ... --- configcache.cpp | 41 +++++++++++++---------- configcache.h | 11 ++++--- hypercache.cpp | 36 +++++++------------- hypercache.h | 13 ++++---- o815/o815.cpp | 11 +++++-- o815/o815.h | 2 +- o815/sim.cpp | 87 +++++++++++++++++++++++++++++++------------------ 7 files changed, 111 insertions(+), 90 deletions(-) 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 Date: Tue, 18 Jun 2013 15:46:56 +0200 Subject: [PATCH 15/16] ... --- configcache.cpp | 24 +++++++++++++------ configcache.h | 6 ++++- hypercache.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++---- hypercache.h | 10 ++++++-- o815/o815.cpp | 2 -- o815/o815.h | 1 - o815/sim.cpp | 58 +++++++++++--------------------------------- 7 files changed, 104 insertions(+), 61 deletions(-) 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 Date: Tue, 18 Jun 2013 21:19:13 +0200 Subject: [PATCH 16/16] ... --- configcache.cpp | 20 ++++++++++++-------- configcache.h | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/configcache.cpp b/configcache.cpp index 35e8548..f642e9f 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->firstConfig = true; + filedesc->firstUsedConfig = true; if( infile.size() < 4 ) return false; @@ -194,6 +194,7 @@ void configcache::readConfig(bool& readnewconfig, int& nequileft, vector::iterator inFileIt = getNextInfile(excludeFileHashes); + int iDidVirtualSkips; if( (!inFile.is_open()) && inFileIt == inFiles.end() ) { cout << "RETURNING..." << endl; @@ -221,26 +222,29 @@ void configcache::readConfig(bool& readnewconfig, int& nequileft, vector