#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;
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;
}
}
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();
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() )
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();
}
}
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();
}
#include <string>
#include <fstream>
#include <sstream>
+#include <ostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/copy.hpp>
-#include "writeout.h"
-
#define CACHE_MODE_DISABLED 0
#define CACHE_MODE_READ 1
#define CACHE_MODE_FULL 2
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<unsigned long> *excludeFileHashes=NULL);
void writeConfig();
void addPara(const string& parid, const double& val=0);
static unsigned long hash(const string& str);
private:
+ ostream* log;
infiledesc openFileDesc;
void finishOutFile();
int getParIndex(const string& parid);
ofstream outFile;
ifstream inFile;
- writeout *out;
-
stringstream outFileName;
int readnum;
vector<hypercache::para> hypercache::delayedParaSet;
string hypercache::activeCFile = "";
vector<unsigned long> hypercache::parentConfigs;
-writeout *hypercache::out = NULL;
+ostream* hypercache::log;
vector<configcache*> 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<para>::iterator parit=delayedParaAdd.begin(); parit != delayedParaAdd.end(); ++parit)
(*cache)->addPara(parit->parid, parit->val);
#define HYPERCACHE_H
#include <iostream>
+#include <ostream>
#include "configcache.h"
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);
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);
static vector<configcache*> Os;
static vector<para> delayedParaAdd;
static vector<para> delayedParaSet;
- static writeout *out;
static string fileOfPath(const string& dressedfile);
static string activeCFile;
static vector<unsigned long> parentConfigs;
static void addParentConfig(const unsigned long *parentconfig);
+ static ostream* log;
};
#endif
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)
}
void o815::mainLoop() {
+ *out->log << "OBS: Starting main loop." << endl;
+
for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) {
(*obsit)->start();
}
+
+ //while( nextParas() ) {
+ //}
+ /*
for (int i=0; i<100; i++) {
for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) {
(*obsit)->meas();
}
}
+ */
for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) {
(*obsit)->finish();
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;
+}
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();
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 {
paraq *paraQ;
writeout *out;
vector<obs*> observables;
+ sim* Sim;
void mainLoop();
string headMaster();
static void listArg(int *target, int tlen, char *listarg);
void parseArgs(int argc, char **argv);
string programid;
+ int nextParas();
};
#endif
#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=="")
_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);
}
--- /dev/null
+#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<nequileft; iequi++ ) {
+ _makeSweep(1);
+ while( equiProg.madeStep(iequi) ) *log << "SIM: " << equiProg.done()*100 << "% of equilibration done." << endl << flush;
+ }
+ }
+ _makeSweep(nskip);
+ hypercache::writeC();
+ }
+
+ toEquilibrate = false;
+}