From 4d1416455c49f0ba19954ca80a72b72f9dfcd33e Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Wed, 17 Apr 2013 11:41:32 +0200 Subject: [PATCH] ... --- configcache.cpp | 24 ++++++++++++------------ configcache.h | 8 +++----- hypercache.cpp | 10 +++++----- hypercache.h | 13 +++++++------ o815/CMakeLists.txt | 4 ++-- o815/o815.cpp | 24 ++++++++++++++++++++++++ o815/o815.h | 25 +++++++++++++++++++++---- o815/obs.cpp | 17 +++++++++++------ o815/sim.cpp | 35 +++++++++++++++++++++++++++++++++++ 9 files changed, 120 insertions(+), 40 deletions(-) create mode 100644 o815/sim.cpp diff --git a/configcache.cpp b/configcache.cpp index a3490ad..d45e4d6 100644 --- a/configcache.cpp +++ b/configcache.cpp @@ -10,8 +10,8 @@ #define HEADER_READLAST 2 configcache::configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, const int& cachemode, - writeout *out_a){ - out = out_a; + ostream *_log){ + log = _log; NEQUI = nequi; NSKIP = nskip; @@ -131,19 +131,19 @@ int configcache::readHeader() return HEADER_READOK; } else { - if(out) *out->log << "CCACHE: Could not read heade-data! Closing dat-file: " << openFileDesc.filename << endl << flush; + if(log) *log << "CCACHE: Could not read heade-data! Closing dat-file: " << openFileDesc.filename << endl << flush; inFile.close(); return HEADER_READERR; } } else { - if(out) *out->log << "CCACHE: Could not read headerid-hash! Closing dat-file: " << openFileDesc.filename << endl << flush; + if(log) *log << "CCACHE: Could not read headerid-hash! Closing dat-file: " << openFileDesc.filename << endl << flush; inFile.close(); return HEADER_READERR; } } else { - if(out) *out->log << "CCACHE: Could not read header size. Closing dat-file: " << openFileDesc.filename << endl << flush; + if(log) *log << "CCACHE: Could not read header size. Closing dat-file: " << openFileDesc.filename << endl << flush; inFile.close(); return HEADER_READERR; } @@ -201,11 +201,11 @@ int configcache::readConfig(vector *excludeFileHashes) } if ( ! excludethisfile ) { - if(out) *out->log << "CCACHE: Opening dat-file: " << inFiles.back().filename << endl << flush; + 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(out) *out->log << "CCACHE: Excluded dat-file: " << inFiles.back().filename << endl << flush; + if(log) *log << "CCACHE: Excluded dat-file: " << inFiles.back().filename << endl << flush; inFiles.pop_back(); @@ -219,7 +219,7 @@ int configcache::readConfig(vector *excludeFileHashes) if( inFile.is_open() ) { if (openFileDesc.doVirtualEquilibration) { - if(out) *out->log << "CCACHE: Trying virtual equilibration." << endl << flush; + if(log) *log << "CCACHE: Trying virtual equilibration." << endl << flush; openFileDesc.doVirtualEquilibration = false; for (int iskip=0; iskip < (NEQUI-openFileDesc.nequi)/openFileDesc.nskip; iskip++) { if( readFullBlock(tmpConfig, configSize) != configSize || ! inFile.is_open() ) @@ -237,7 +237,7 @@ int configcache::readConfig(vector *excludeFileHashes) return -1; } else { - if(out) *out->log << "CCACHE: Could not read configuration. Closing dat-file: " << openFileDesc.filename << endl << flush; + if(log) *log << "CCACHE: Could not read configuration. Closing dat-file: " << openFileDesc.filename << endl << flush; inFile.close(); } } @@ -350,15 +350,15 @@ int configcache::readDataToMem(char *tmpData, long unsigned int dataSize) try { readturn = boost::iostreams::read(*inBuffer, tmpData, dataSize); } catch(boost::iostreams::bzip2_error& error) { - if(out) *out->log << "CCACHE: Caught bzip2 exception with error code: " << error.error() << endl << flush; + if(log) *log << "CCACHE: Caught bzip2 exception with error code: " << error.error() << endl << flush; inFile.close(); } catch (std::exception const& ex) { - if(out) *out->log << "CCACHE: Caught exception: " << ex.what() << endl << flush; + if(log) *log << "CCACHE: Caught exception: " << ex.what() << endl << flush; inFile.close(); } catch( ... ) { - if(out) *out->log << "CCACHE: Caught unknown exception while reading." << endl << flush; + if(log) *log << "CCACHE: Caught unknown exception while reading." << endl << flush; inFile.close(); } diff --git a/configcache.h b/configcache.h index f07ccf5..d79afa6 100644 --- a/configcache.h +++ b/configcache.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -12,8 +13,6 @@ #include #include -#include "writeout.h" - #define CACHE_MODE_DISABLED 0 #define CACHE_MODE_READ 1 #define CACHE_MODE_FULL 2 @@ -37,7 +36,7 @@ class configcache{ public: ~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, writeout *out_a=NULL); + const int& cachemode=CACHE_MODE_FULL, ostream *_log=NULL); int readConfig(vector *excludeFileHashes=NULL); void writeConfig(); void addPara(const string& parid, const double& val=0); @@ -49,6 +48,7 @@ class configcache{ static unsigned long hash(const string& str); private: + ostream* log; infiledesc openFileDesc; void finishOutFile(); int getParIndex(const string& parid); @@ -62,8 +62,6 @@ class configcache{ ofstream outFile; ifstream inFile; - writeout *out; - stringstream outFileName; int readnum; diff --git a/hypercache.cpp b/hypercache.cpp index 6c8e190..734a640 100644 --- a/hypercache.cpp +++ b/hypercache.cpp @@ -5,16 +5,16 @@ vector hypercache::delayedParaAdd; vector hypercache::delayedParaSet; string hypercache::activeCFile = ""; vector hypercache::parentConfigs; -writeout *hypercache::out = NULL; +ostream* hypercache::log; vector hypercache::Os; void hypercache::initCache(configcache **cache, const string& cacheid, const int& nequi, const int& nskip, const string& datadir, - char **configmem, const int& configMemSize, const int& cachemode, writeout *out_a) { - if ( out_a != NULL ) - out = out_a; + char **configmem, const int& configMemSize, const int& cachemode, ostream* _log) { + if ( _log != NULL ) + log = _log; - *cache = new configcache(cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, out_a); + *cache = new configcache(cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, log); for (vector::iterator parit=delayedParaAdd.begin(); parit != delayedParaAdd.end(); ++parit) (*cache)->addPara(parit->parid, parit->val); diff --git a/hypercache.h b/hypercache.h index 523cc56..dd2ce0b 100644 --- a/hypercache.h +++ b/hypercache.h @@ -2,6 +2,7 @@ #define HYPERCACHE_H #include +#include #include "configcache.h" @@ -10,14 +11,14 @@ using namespace std; class hypercache { public: static int initO(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, - char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL, writeout *out_a=NULL) { + char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL, ostream *_log=NULL) { Os.push_back(NULL); - initCache(&Os.back(), cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, out_a); + initCache(&Os.back(), cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, _log); return Os.size()-1; } 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, writeout *out_a=NULL) { - initCache(&C, cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, out_a); + 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 void addPara(const string& parid, const double& val=0); @@ -41,7 +42,7 @@ class hypercache { static void initCache(configcache **cache, const string& cacheid, const int& nequi, const int& nskip, const string& datadir, - char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL, writeout *out_a=NULL); + char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL, ostream* _log=NULL); static void initCache( configcache **cache, const string& cacheid, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL); @@ -50,12 +51,12 @@ class hypercache { static vector Os; static vector delayedParaAdd; static vector delayedParaSet; - static writeout *out; static string fileOfPath(const string& dressedfile); static string activeCFile; static vector parentConfigs; static void addParentConfig(const unsigned long *parentconfig); + static ostream* log; }; #endif diff --git a/o815/CMakeLists.txt b/o815/CMakeLists.txt index 8431e25..49fa081 100644 --- a/o815/CMakeLists.txt +++ b/o815/CMakeLists.txt @@ -9,5 +9,5 @@ include_directories(${MPI_INCLUDE_PATH} ../) SET(CMAKE_BUILD_TYPE Release) -add_library(o815 o815.cpp obs.cpp) -target_link_libraries(o815 ${MPI_LIBRARIES} lat_paraq lat_writeout) +add_library(o815 o815.cpp obs.cpp sim.cpp) +target_link_libraries(o815 ${MPI_LIBRARIES} lat_paraq lat_writeout lat_hypercache lat_progress) diff --git a/o815/o815.cpp b/o815/o815.cpp index 9fcae16..cf461ba 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -51,15 +51,22 @@ o815::o815(int argc, char **argv, const string& _programid) { } void o815::mainLoop() { + *out->log << "OBS: Starting main loop." << endl; + for (vector::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { (*obsit)->start(); } + + //while( nextParas() ) { + //} + /* for (int i=0; i<100; i++) { for (vector::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { (*obsit)->meas(); } } + */ for (vector::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { (*obsit)->finish(); @@ -146,3 +153,20 @@ o815::~o815() { delete out; MPI_Finalize(); } + +int o815::nextParas() +{ + if( paraQ->nextParas() ) { + /* + setB( (*paraQ)["beta"] ); + setK( (*paraQ)["kappa"] ); + setL( (*paraQ)["lambda"] ); + setM1( (*paraQ)["mu1"] ); + setM2( (*paraQ)["mu2"] ); + */ + + return 1; + } + else + return 0; +} diff --git a/o815/o815.h b/o815/o815.h index 5776917..2f12fc5 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -18,7 +18,7 @@ class o815 { class obs { public: - obs(const string& _obsid, const string& _datadesc, o815 *_O815, char *_obsmem, const int& _obsmemSize); + obs(const string& _obsid, const string& _datadesc, o815 *_O815, const int& _obsmemSize); void finish(); void meas(); void start(); @@ -30,9 +30,24 @@ class o815 { protected: o815 *O815; char *obsMem; - ostream *oout; - ostream *olog; - string obsid, datadesc; + string obsid, simid, datadesc; + ostream *out, *log; + int ocid; + }; + + class sim { + public: + sim(o815 *_O815, const int& _confmemSize); + void nextConfig(); + bool toEquilibrate; + char *confMem; + private: + virtual void _reset()=0; + virtual void _makeSweep(int nsweep)=0; + protected: + o815 *O815; + ostream *log; + int nequi, nskip; }; struct { @@ -52,6 +67,7 @@ class o815 { paraq *paraQ; writeout *out; vector observables; + sim* Sim; void mainLoop(); string headMaster(); @@ -61,6 +77,7 @@ private: static void listArg(int *target, int tlen, char *listarg); void parseArgs(int argc, char **argv); string programid; + int nextParas(); }; #endif diff --git a/o815/obs.cpp b/o815/obs.cpp index c927935..70aa8b6 100644 --- a/o815/obs.cpp +++ b/o815/obs.cpp @@ -1,13 +1,15 @@ #include "o815.h" +#include "latlib/hypercache.h" + void o815::obs::finish() { _finish(); } void o815::obs::start() { if(O815->rank==0) { - *oout << "#" << obsid << O815->headMaster() << endl << flush; - *oout << "#" << obsid << O815->headMaster() << "-" << datadesc << endl << flush; + *out << "#" << O815->programid << "-" << obsid << O815->headMaster() << endl << flush; + *out << "#" << O815->programid << "-" << obsid << O815->headMaster() << "-" << datadesc << endl << flush; } if (O815->comargs.outdir=="") @@ -20,12 +22,15 @@ void o815::obs::meas() { _meas(true); } -o815::obs::obs(const string& _obsid, const string& _datadesc, o815 *_O815, char *_obsmem, const int& _obsmemSize) { +o815::obs::obs(const string& _obsid, const string& _datadesc, o815 *_O815, const int& obsmemSize) { obsid = _obsid; O815 = _O815; datadesc = _datadesc; - O815->out->newsub(obsid); - oout = O815->out->out[obsid]; - olog = O815->out->log; + + out = O815->out->out[obsid]; + log = O815->out->log; + + ocid = hypercache::initO(O815->programid + "-" + obsid, O815->comargs.nequi, O815->comargs.nskip, + O815->comargs.obscache.first, &obsMem, obsmemSize, O815->comargs.obscache.second, log); } diff --git a/o815/sim.cpp b/o815/sim.cpp new file mode 100644 index 0000000..2e68ae2 --- /dev/null +++ b/o815/sim.cpp @@ -0,0 +1,35 @@ +#include "o815.h" + +#include "latlib/hypercache.h" +#include "latlib/progress.h" + +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; +} + +void o815::sim::nextConfig() { + int nequileft = hypercache::readC(); + + if ( nequileft != -1 ) { + if(toEquilibrate) { + _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