6 #include "latlib/progress.h"
12 o815::o815(int argc, char **argv, const string& _programid, comoption specOps[], void (*helpHeader)()) {
13 programid = _programid;
20 comargs.obscache = make_pair("",0);
21 comargs.confcache = make_pair("",0);
23 comargs.idonly = false;
24 comargs.showjobnum = false;
26 MPI_Init(&argc, &argv);
27 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
28 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30 addComOption("lsize", required_argument, NULL, 'L', "define lattice size", "xsize:tsize");
31 addComOption("nmeas", required_argument, NULL, 'N', "set number of measurements", "nmeas");
32 addComOption("skip", required_argument, NULL, 'S', "set number of skips between configs", "nskip");
33 addComOption("nequi", required_argument, NULL, 'E', "set number of equilibrations", "nequi");
34 addComOption("oro", required_argument, NULL, 'o', "read-only observable-store directory", "dir");
35 addComOption("orw", required_argument, NULL, 'O', "read-write observable-store directory", "dir");
36 addComOption("cro", required_argument, NULL, 'c', "read-only config-store directory", "dir");
37 addComOption("crw", required_argument, NULL, 'C', "read-write config-store directory", "dir");
38 addComOption("write", required_argument, NULL, 'w', "data writeout directory", "dir");
39 addComOption("idonly", no_argument, &comargs.idonly, 'i', "show output-id only", "");
40 addComOption("jobnum", no_argument, &comargs.showjobnum, 'j', "show jobnumber only", "");
43 for (int ispecop = 0; specOps[ispecop].name != ""; ispecop++)
44 comOptions.push_back(specOps[ispecop]);
47 parseArgs(argc, argv, specOps);
49 int longestCombinedLong=0;
51 if (helpHeader != NULL)
54 cout << "Options:" << endl;
56 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) {
57 stringstream combinedLong;
59 combinedLong << opit->name;
60 if (opit->has_arg == required_argument)
61 combinedLong << "=" << opit->argdesc;
62 else if (opit->has_arg == optional_argument)
63 combinedLong << "[=" << opit->argdesc << "]";
65 if (longestCombinedLong < combinedLong.str().size())
66 longestCombinedLong = combinedLong.str().size();
69 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) {
70 stringstream combinedLong;
72 cout << " -" << char(opit->val) << ", --";
74 combinedLong << opit->name;
75 if (opit->has_arg == required_argument)
76 combinedLong << "=" << opit->argdesc;
77 else if (opit->has_arg == optional_argument)
78 combinedLong << "[=" << opit->argdesc << "]";
80 cout << setw(longestCombinedLong) << setiosflags(ios::left) << combinedLong.str();
82 cout << "\t" << opit->optdesc;
89 paraQ = new paraq(numprocs, rank);
92 void o815::postParaInit() {
96 cout << programid << headMaster() << endl << flush;
101 timestamp = time(NULL);
102 for(int idest=1; idest<numprocs; idest++)
103 MPI_Send(×tamp, 1, MPI_LONG, idest, 123, MPI_COMM_WORLD);
106 MPI_Recv(×tamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, &mpiStatus);
108 out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp);
111 void o815::mainLoop() {
112 if( comargs.showjobnum ) {
113 for( int i=1; i<=paraQ->getTotalJobs(); i++ ) {
114 if( paraQ->getTotalJobs()%i == 0 ) cout << paraQ->getTotalJobs()/i << "@" << i << " ";
120 *out->log << "OBS: Starting main loop." << endl;
122 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
125 while( nextParas() ) {
126 *out->log << endl << "O815: < ";
127 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
128 *out->log << *parait << "=" << (*paraQ)[*parait] << " ";
129 *out->log << ">" << endl << flush;
133 progress measProg(comargs.nmeas);
135 *out->log << "OBS: Starting measurement of observables:";
136 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
137 *out->log << " " << (*obsit)->obsid;
138 *out->log << endl << flush;
140 for( int imeas=0; imeas<comargs.nmeas; imeas++ ) {
141 bool nextAlready = false;
142 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) {
146 hypercache::readO( (*obsit)->ocid, &readnewObs, &nequileftNewObs );
148 if ( readnewObs && nequileftNewObs < 0 ) {
149 (*obsit)->meas(true);
156 (*obsit)->meas(false);
157 hypercache::writeO( (*obsit)->ocid );
161 while( measProg.madeStep(imeas) )
162 *out->log << "O815: " << measProg.done()*100 << "% of measurements done." << endl << flush;
164 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
169 void o815::addComOption(const char* name, int has_arg, int *flag, int val, const char* optdesc, const char* argdesc) {
170 comoption newop = { name, has_arg, flag, val, optdesc, argdesc };
171 comOptions.push_back(newop);
174 void o815::parseArgs(int argc, char **argv, comoption specOps[]) {
177 stringstream optargstr;
178 option allOptions[comOptions.size()+1];
180 for (int iop=0; iop < comOptions.size(); iop++) {
181 allOptions[iop].name = comOptions[iop].name.c_str();
182 allOptions[iop].has_arg = comOptions[iop].has_arg;
183 //allOptions[iop].flag = NULL;
184 allOptions[iop].flag = comOptions[iop].flag;
185 allOptions[iop].val = comOptions[iop].val;
187 optargstr << char(allOptions[iop].val);
188 if (allOptions[iop].has_arg == required_argument)
190 else if (allOptions[iop].has_arg == optional_argument)
194 allOptions[comOptions.size()].name = 0;
195 allOptions[comOptions.size()].has_arg = 0;
196 allOptions[comOptions.size()].flag = 0;
197 allOptions[comOptions.size()].val = 0;
199 while((opt = getopt_long( argc, argv, optargstr.str().c_str(), allOptions, &indexptr )) != -1)
202 listArg(comargs.lsize, 2, optarg);
205 comargs.nmeas = atoi(optarg);
208 comargs.nskip = atoi(optarg);
211 comargs.nequi = atoi(optarg);
214 comargs.obscache.first = optarg;
215 comargs.obscache.second = 1;
218 comargs.obscache.first = optarg;
219 comargs.obscache.second = 2;
222 comargs.confcache.first = optarg;
223 comargs.confcache.second = 1;
226 comargs.confcache.first = optarg;
227 comargs.confcache.second = 2;
230 comargs.outdir = optarg;
234 comoption* thisop = getOptionByVal(opt);
235 if (thisop->flag != 0)
236 *thisop->flag = thisop->val;
238 parsedSpecOps.push_back( pair<int,char*>(thisop->val, optarg) );
243 for (int ilon=0; optind+ilon < argc; ilon++)
244 lonelyArgs.push_back(argv[optind+ilon]);
247 o815::comoption* o815::getOptionByVal(int val) {
248 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit)
249 if ( opit->val == val )
254 void o815::listArg(int *target, int tlen, char *listarg) {
257 for( int pos=0; pos<strlen(listarg); pos++ )
258 if( listarg[pos] == ':' ) nargs++;
261 for(int i=0; i<tlen; i++) target[i] = atoi(listarg);
264 target[0] = atoi(strtok(listarg, ":"));
265 for(int i=0; i<nargs; i++)
266 target[i+1] = atoi(strtok(NULL, ":"));
270 string o815::headMaster()
274 hm << "-L" << comargs.lsize[0] << "_" << comargs.lsize[1] << "-E" << comargs.nequi << "-S" << comargs.nskip << "-N" << comargs.nmeas
275 << paraQ->rangeString();
281 if(comargs.outdir=="") {
282 MPI_Barrier(MPI_COMM_WORLD);
284 cout << "#end" << endl << flush;
286 hypercache::finalize();
291 int o815::nextParas()
293 if( paraQ->nextParas() ) {
294 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
295 hypercache::setPara(*parait, (*paraQ)[*parait]);
302 void o815::addPara(const string& paraid, const double& paraDefault) {
303 hypercache::addPara(paraid);
304 paraQ->setDefault(paraid, paraDefault);