From: Alexander Schmidt Date: Fri, 14 Mar 2014 15:38:50 +0000 (+0100) Subject: Implemented new writeout file naming scheme using hashed range string. X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/38ffdcb3843eec92d62b23d32a735107a49fb7d8?ds=sidebyside;hp=e34773ccb43eefc86dc814b768af85da2873e5ef Implemented new writeout file naming scheme using hashed range string. --- diff --git a/o815/o815.cpp b/o815/o815.cpp index f078db3..c559281 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -111,7 +111,7 @@ void o815::postParaInit() { long timestamp; if(comargs.idonly) { - cout << programid << headMaster() << endl << flush; + cout << programid << headMaster(true) << endl << flush; exit(0); } @@ -123,7 +123,7 @@ void o815::postParaInit() { exit(0); } - out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs); + out = new writeout(comargs.outdir, programid+headMaster(true), rank, numprocs); } void o815::mainLoop() { @@ -274,12 +274,16 @@ void o815::listArg(int *target, int tlen, char *listarg) { } } -string o815::headMaster() +string o815::headMaster(bool hashedrange) { stringstream hm; - hm << "-L" << comargs.lsize[0] << "_" << comargs.lsize[1] << "-E" << comargs.nequi << "-S" << comargs.nskip << "-N" << comargs.nmeas - << paraQ->rangeString(); + hm << "_L" << comargs.lsize[0] << "x" << comargs.lsize[1] << "_E" << comargs.nequi << "_S" << comargs.nskip << "_N" << comargs.nmeas; + + if( ! hashedrange ) + hm << paraQ->rangeString(); + else + hm << "_" << hash( paraQ->rangeString() ); return hm.str(); } @@ -338,3 +342,13 @@ void o815::readCacheArgs(const string& arg, string& cachedir, int& cachemode) cachedir = arg.substr( 0, arg.rfind(":") ); } + +unsigned long o815::hash(const string& str) +{ + unsigned long hash = 5381; + + for(string::const_iterator it=str.begin();it!=str.end();it++) + hash = ((hash << 5) + hash) + *it; /* hash * 33 + character */ + + return hash; +} diff --git a/o815/o815.h b/o815/o815.h index 79d427d..d3e5a21 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -83,7 +83,7 @@ class o815 { vector observables; sim* Sim; void mainLoop(); - string headMaster(); + string headMaster( bool hashedrange=false ); 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; @@ -98,6 +98,7 @@ private: int nextParas(); comoption* getOptionByVal(int val); static void readCacheArgs(const string& arg, string& cachedir, int& cachemode); + unsigned long hash(const string& str); }; #endif diff --git a/paraq.cpp b/paraq.cpp index d512c9c..0892962 100644 --- a/paraq.cpp +++ b/paraq.cpp @@ -41,10 +41,10 @@ string paraq::rangeString() for( map< string, vector >::iterator paraIt = rangeMap.begin(); paraIt != rangeMap.end(); ++paraIt ) if( paraIt->second.size() > 0 ) for( vector::iterator rangeIt = paraIt->second.begin(); rangeIt != paraIt->second.end(); ++rangeIt) - rangestring << "-" << paraIt->first << (*rangeIt)[0] << "_" << (*rangeIt)[1] << "_" << (*rangeIt)[2]; + rangestring << "_" << paraIt->first << (*rangeIt)[0] << "-" << (*rangeIt)[1] << "-" << (*rangeIt)[2]; for (vector::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) - rangestring << "-" << linkit->first << "--" << linkit->linktype << "--" << linkit->second; + rangestring << "_" << linkit->first << "--" << linkit->linktype << "--" << linkit->second; for( map::iterator defIt = defaultPara.begin(); defIt != defaultPara.end(); ++defIt ) if( rangeMap.find(defIt->first) == rangeMap.end() ) { @@ -57,7 +57,7 @@ string paraq::rangeString() } if (!linkedpara) - rangestring << "-" << defIt->first << defIt->second; + rangestring << "_" << defIt->first << defIt->second; } return rangestring.str(); diff --git a/writeout.cpp b/writeout.cpp index 41dcdf5..a756394 100644 --- a/writeout.cpp +++ b/writeout.cpp @@ -28,8 +28,8 @@ void writeout::newsub(string subname) { of[subname] = new ofstream; if ( fulldir != "" ) { - if(rank>0) of[subname]->open( (fulldir + "/rank" + cRank + "-" + subname + ".tmp").c_str() ); - else of[subname]->open( (fulldir + "/" + signature + "-" + subname + ".dat").c_str() ); + if(rank>0) of[subname]->open( (fulldir + "/rank" + cRank + "_" + subname + ".tmp").c_str() ); + else of[subname]->open( (fulldir + "/" + signature + "_" + subname + ".dat").c_str() ); if ( !of[subname]->is_open() ) { logf << "WRITEOUT: Could not open output-file!" << endl << flush; @@ -145,8 +145,8 @@ writeout::~writeout() } else { ofit->second->close(); - rename((fulldir + "/rank" + cRank + "-" + ofit->first + ".tmp").c_str(), - (fulldir + "/rank" + cRank + "-" + ofit->first + ".part").c_str()); + rename((fulldir + "/rank" + cRank + "_" + ofit->first + ".tmp").c_str(), + (fulldir + "/rank" + cRank + "_" + ofit->first + ".part").c_str()); } } if( cRank[0] == '0' ) @@ -173,7 +173,7 @@ string writeout::getdatfile(string subname) myfile = string(dirp->d_name); if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part" && - subname == myfile.substr( myfile.find("-")+1, myfile.rfind(".")-myfile.find("-")-1 ) ) { + subname == myfile.substr( myfile.find("_")+1, myfile.rfind(".")-myfile.find("_")-1 ) ) { closedir(dp); return myfile; }