From: Alexander Schmidt Date: Thu, 13 Feb 2014 19:12:41 +0000 (+0100) Subject: Implemented rw-cache. Made general options uppercase. Formatted options. X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/594f56b186b5d2f5e25293d6952c9325576aa080?ds=sidebyside Implemented rw-cache. Made general options uppercase. Formatted options. --- diff --git a/configcache.cpp b/configcache.cpp index c6f9082..34789ee 100644 --- a/configcache.cpp +++ b/configcache.cpp @@ -191,7 +191,7 @@ void configcache::readConfig(bool *readnewconfig, int *nequileft, vector #include -#define CACHE_MODE_DISABLED 0 -#define CACHE_MODE_READ 1 -#define CACHE_MODE_FULL 2 +#define CACHE_MODE_OO 0 +#define CACHE_MODE_RO 1 +#define CACHE_MODE_WO 2 +#define CACHE_MODE_RW 3 using namespace std; @@ -29,7 +30,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, ostream *_log=NULL); + const int& cachemode=CACHE_MODE_RW, ostream *_log=NULL); void readConfig(bool *readnewconfig, int *nequileft, vector *excludeFileHashes=NULL); void writeConfig(int actnequi); void addPara(const string& parid, const double& val=0); diff --git a/hypercache.h b/hypercache.h index 1a64373..199b7e7 100644 --- a/hypercache.h +++ b/hypercache.h @@ -16,7 +16,7 @@ class hypercache { }; 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, ostream *_log=NULL) { + char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_RW, ostream *_log=NULL) { observable newobs; newobs.c = NULL; @@ -27,7 +27,7 @@ class hypercache { 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, ostream *_log=NULL) { + char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_RW, ostream *_log=NULL) { initCache(&C, cacheid, nequi, nskip, datadir, configmem, configMemSize, cachemode, _log); mostEquilibratedConfig.second = new char[configMemSize]; } @@ -57,10 +57,10 @@ 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, ostream* _log=NULL); + char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_RW, ostream* _log=NULL); static void initCache( configcache **cache, - const string& cacheid, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL); + const string& cacheid, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_RW); static configcache *C; static vector Os; diff --git a/o815/o815.cpp b/o815/o815.cpp index 630d680..17581ec 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -37,17 +37,17 @@ o815::o815(int argc, char **argv, const string& _programid, comoption specOps[], rank = 0; #endif - 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", ""); + 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("ocache", required_argument, NULL, 'O', "set observable cache (mode=oo|ro|wo|rw)", "dir:mode"); + addComOption("ccache", required_argument, NULL, 'C', "set config cache (mode=oo|ro|wo|rw)", "dir:mode"); + 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", ""); + + vector::iterator lastO815Opt = comOptions.end()-1; if (specOps != NULL) for (int ispecop = 0; specOps[ispecop].name != ""; ispecop++) @@ -61,7 +61,7 @@ o815::o815(int argc, char **argv, const string& _programid, comoption specOps[], if (helpHeader != NULL) helpHeader(); - cout << "Options:" << endl; + cout << "General options:" << endl; for (vector::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) { stringstream combinedLong; @@ -92,6 +92,11 @@ o815::o815(int argc, char **argv, const string& _programid, comoption specOps[], cout << "\t" << opit->optdesc; cout << endl; + + if ( opit == lastO815Opt && (opit+1) != comOptions.end() ) { + cout << endl; + cout << "Simulation specific options:" << endl; + } } exit(0); } @@ -215,21 +220,11 @@ void o815::parseArgs(int argc, char **argv, comoption specOps[]) { case 'E': comargs.nequi = atoi(optarg); break; - case 'o': - comargs.obscache.first = optarg; - comargs.obscache.second = 1; - break; case 'O': - comargs.obscache.first = optarg; - comargs.obscache.second = 2; - break; - case 'c': - comargs.confcache.first = optarg; - comargs.confcache.second = 1; + readCacheArgs(optarg, comargs.obscache.first, comargs.obscache.second); break; case 'C': - comargs.confcache.first = optarg; - comargs.confcache.second = 2; + readCacheArgs(optarg, comargs.confcache.first, comargs.confcache.second); break; case 'w': comargs.outdir = optarg; @@ -312,3 +307,27 @@ void o815::addPara(const string& paraid, const double& paraDefault) { hypercache::addPara(paraid); paraQ->setDefault(paraid, paraDefault); } + +void o815::readCacheArgs(const string& arg, string& cachedir, int& cachemode) +{ + if ( arg.rfind(":") == string::npos ) { + cerr << "O815: Invalid cache argument!" << endl; + exit(1); + } + + string arg_mode = arg.substr( arg.rfind(":")+1 ); + if ( arg_mode == "oo" ) + cachemode = CACHE_MODE_OO; + else if ( arg_mode == "ro" ) + cachemode = CACHE_MODE_RO; + else if ( arg_mode == "wo" ) + cachemode = CACHE_MODE_WO; + else if ( arg_mode == "rw" ) + cachemode = CACHE_MODE_RW; + else { + cerr << "O815: Unknown cache mode " << arg_mode << "!" << endl; + exit(1); + } + + cachedir = arg.substr( 0, arg.rfind(":") ); +} diff --git a/o815/o815.h b/o815/o815.h index 4f741a1..79d427d 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -97,6 +97,7 @@ private: string programid; int nextParas(); comoption* getOptionByVal(int val); + static void readCacheArgs(const string& arg, string& cachedir, int& cachemode); }; #endif