X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/4d1416455c49f0ba19954ca80a72b72f9dfcd33e..66dd4bd348bacf6b43b59c2b349a913b722c6504:/o815/o815.cpp?ds=inline diff --git a/o815/o815.cpp b/o815/o815.cpp index cf461ba..956ad2e 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -1,10 +1,15 @@ #include "o815.h" #include +#include -o815::o815(int argc, char **argv, const string& _programid) { - long timestamp; +#include "latlib/progress.h" + +using namespace std; + +extern int opterr; +o815::o815(int argc, char **argv, const string& _programid, comoption specOps[], void (*helpHeader)()) { programid = _programid; comargs.nmeas = 100; @@ -22,9 +27,73 @@ o815::o815(int argc, char **argv, const string& _programid) { MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); + 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); + } + paraQ = new paraq(numprocs, rank); - parseArgs(argc, argv); + hypercache::addPara("lx", comargs.lsize[0]); + hypercache::addPara("lt", comargs.lsize[1]); +} + +void o815::postParaInit() { + long timestamp; if(comargs.idonly) { cout << programid << headMaster() << endl << flush; @@ -38,7 +107,7 @@ o815::o815(int argc, char **argv, const string& _programid) { cout << endl; exit(0); } - + if(rank==0) { timestamp = time(NULL); for(int idest=1; idestlog << "OBS: Starting main loop." << endl; - for (vector::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { + 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(); - } - } - */ + while( nextParas() ) { + *out->log << endl << "O815: < "; + 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); + + *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 (vector::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { - (*obsit)->finish(); + for( int imeas=0; imeas::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { + bool readnewObs; + int nequileftNewObs; + + hypercache::readO( (*obsit)->ocid, &readnewObs, &nequileftNewObs ); + + if ( readnewObs && nequileftNewObs < 0 ) { + (*obsit)->meas(true); + } + else { + if (!nextAlready) { + Sim->nextConfig(); + nextAlready = true; + } + (*obsit)->meas(false); + hypercache::writeO( (*obsit)->ocid ); + } + + } + while( measProg.madeStep(imeas) ) + *out->log << "O815: " << measProg.done()*100 << "% of measurements done." << endl << flush; + } + for (vector::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) + (*obsit)->finish(); } } -void o815::parseArgs(int argc, char **argv) { - int opt = 0; - - while( (opt = getopt(argc, argv, "L:N:S:E:o:O:c:C:w:i:j:")) != -1 ) +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 << "::"; + } + + 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); @@ -109,13 +232,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); + exit(1); } void o815::listArg(int *target, int tlen, char *listarg) { @@ -150,6 +286,7 @@ o815::~o815() { if(rank==0) cout << "#end" << endl << flush; } + hypercache::finalize(); delete out; MPI_Finalize(); } @@ -157,16 +294,15 @@ o815::~o815() { int o815::nextParas() { if( paraQ->nextParas() ) { - /* - setB( (*paraQ)["beta"] ); - setK( (*paraQ)["kappa"] ); - setL( (*paraQ)["lambda"] ); - setM1( (*paraQ)["mu1"] ); - setM2( (*paraQ)["mu2"] ); - */ - + for (vector::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait) + hypercache::setPara(*parait, (*paraQ)[*parait]); return 1; } else return 0; } + +void o815::addPara(const string& paraid, const double& paraDefault) { + hypercache::addPara(paraid); + paraQ->setDefault(paraid, paraDefault); +}