11 #include "latlib/progress.h"
17 o815::o815(int argc, char **argv, const string& _programid, comoption specOps[], void (*helpHeader)()) {
18 programid = _programid;
25 comargs.obscache = make_pair("",0);
26 comargs.confcache = make_pair("",0);
28 comargs.idonly = false;
29 comargs.showjobnum = false;
32 MPI_Init(&argc, &argv);
33 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
34 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
40 addComOption("lsize", required_argument, NULL, 'L', "define lattice size", "xsize:tsize");
41 addComOption("nmeas", required_argument, NULL, 'N', "set number of measurements", "nmeas");
42 addComOption("skip", required_argument, NULL, 'S', "set number of skips between configs", "nskip");
43 addComOption("nequi", required_argument, NULL, 'E', "set number of equilibrations", "nequi");
44 addComOption("oro", required_argument, NULL, 'o', "read-only observable-store directory", "dir");
45 addComOption("orw", required_argument, NULL, 'O', "read-write observable-store directory", "dir");
46 addComOption("cro", required_argument, NULL, 'c', "read-only config-store directory", "dir");
47 addComOption("crw", required_argument, NULL, 'C', "read-write config-store directory", "dir");
48 addComOption("write", required_argument, NULL, 'w', "data writeout directory", "dir");
49 addComOption("idonly", no_argument, &comargs.idonly, 'i', "show output-id only", "");
50 addComOption("jobnum", no_argument, &comargs.showjobnum, 'j', "show jobnumber only", "");
53 for (int ispecop = 0; specOps[ispecop].name != ""; ispecop++)
54 comOptions.push_back(specOps[ispecop]);
57 parseArgs(argc, argv, specOps);
59 int longestCombinedLong=0;
61 if (helpHeader != NULL)
64 cout << "Options:" << endl;
66 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) {
67 stringstream combinedLong;
69 combinedLong << opit->name;
70 if (opit->has_arg == required_argument)
71 combinedLong << "=" << opit->argdesc;
72 else if (opit->has_arg == optional_argument)
73 combinedLong << "[=" << opit->argdesc << "]";
75 if (longestCombinedLong < combinedLong.str().size())
76 longestCombinedLong = combinedLong.str().size();
79 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) {
80 stringstream combinedLong;
82 cout << " -" << char(opit->val) << ", --";
84 combinedLong << opit->name;
85 if (opit->has_arg == required_argument)
86 combinedLong << "=" << opit->argdesc;
87 else if (opit->has_arg == optional_argument)
88 combinedLong << "[=" << opit->argdesc << "]";
90 cout << setw(longestCombinedLong) << setiosflags(ios::left) << combinedLong.str();
92 cout << "\t" << opit->optdesc;
99 paraQ = new paraq(numprocs, rank);
101 hypercache::addPara("lx", comargs.lsize[0]);
102 hypercache::addPara("lt", comargs.lsize[1]);
105 void o815::postParaInit() {
109 cout << programid << headMaster() << endl << flush;
113 if( comargs.showjobnum ) {
114 for( int i=1; i<=paraQ->getTotalJobs(); i++ ) {
115 if( paraQ->getTotalJobs()%i == 0 ) cout << paraQ->getTotalJobs()/i << "@" << i << " ";
122 timestamp = time(NULL);
124 for(int idest=1; idest<numprocs; idest++)
125 MPI_Send(×tamp, 1, MPI_LONG, idest, 123, MPI_COMM_WORLD);
130 MPI_Recv(×tamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
133 out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp);
136 void o815::mainLoop() {
137 *out->log << "OBS: Starting main loop." << endl;
139 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
142 while( nextParas() ) {
143 *out->log << endl << "O815: < ";
144 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
145 *out->log << *parait << "=" << (*paraQ)[*parait] << " ";
146 *out->log << ">" << endl << flush;
150 progress measProg(comargs.nmeas);
152 *out->log << "OBS: Starting measurement of observables:";
153 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
154 *out->log << " " << (*obsit)->obsid;
155 *out->log << endl << flush;
157 for( int imeas=0; imeas<comargs.nmeas; imeas++ ) {
158 bool nextAlready = false;
159 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) {
163 hypercache::readO( (*obsit)->ocid, &readnewObs, &nequileftNewObs );
165 if ( readnewObs && nequileftNewObs < 0 ) {
166 (*obsit)->meas(true, imeas);
173 (*obsit)->meas(false, imeas);
174 hypercache::writeO( (*obsit)->ocid );
178 while( measProg.madeStep(imeas) )
179 *out->log << "O815: " << measProg.done()*100 << "% of measurements done." << endl << flush;
181 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
186 void o815::addComOption(const char* name, int has_arg, int *flag, int val, const char* optdesc, const char* argdesc) {
187 comoption newop = { name, has_arg, flag, val, optdesc, argdesc };
188 comOptions.push_back(newop);
191 void o815::parseArgs(int argc, char **argv, comoption specOps[]) {
194 stringstream optargstr;
195 option allOptions[comOptions.size()+1];
197 for (int iop=0; iop < comOptions.size(); iop++) {
198 allOptions[iop].name = comOptions[iop].name.c_str();
199 allOptions[iop].has_arg = comOptions[iop].has_arg;
200 //allOptions[iop].flag = NULL;
201 allOptions[iop].flag = comOptions[iop].flag;
202 allOptions[iop].val = comOptions[iop].val;
204 optargstr << char(allOptions[iop].val);
205 if (allOptions[iop].has_arg == required_argument)
207 else if (allOptions[iop].has_arg == optional_argument)
211 allOptions[comOptions.size()].name = 0;
212 allOptions[comOptions.size()].has_arg = 0;
213 allOptions[comOptions.size()].flag = 0;
214 allOptions[comOptions.size()].val = 0;
216 while((opt = getopt_long( argc, argv, optargstr.str().c_str(), allOptions, &indexptr )) != -1)
219 listArg(comargs.lsize, 2, optarg);
222 comargs.nmeas = atoi(optarg);
225 comargs.nskip = atoi(optarg);
228 comargs.nequi = atoi(optarg);
231 comargs.obscache.first = optarg;
232 comargs.obscache.second = 1;
235 comargs.obscache.first = optarg;
236 comargs.obscache.second = 2;
239 comargs.confcache.first = optarg;
240 comargs.confcache.second = 1;
243 comargs.confcache.first = optarg;
244 comargs.confcache.second = 2;
247 comargs.outdir = optarg;
251 comoption* thisop = getOptionByVal(opt);
252 if (thisop->flag != 0)
253 *thisop->flag = thisop->val;
255 parsedSpecOps.push_back( pair<int,char*>(thisop->val, optarg) );
260 for (int ilon=0; optind+ilon < argc; ilon++)
261 lonelyArgs.push_back(argv[optind+ilon]);
264 o815::comoption* o815::getOptionByVal(int val) {
265 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit)
266 if ( opit->val == val )
271 void o815::listArg(int *target, int tlen, char *listarg) {
274 for( int pos=0; pos<strlen(listarg); pos++ )
275 if( listarg[pos] == ':' ) nargs++;
278 for(int i=0; i<tlen; i++) target[i] = atoi(listarg);
281 target[0] = atoi(strtok(listarg, ":"));
282 for(int i=0; i<nargs; i++)
283 target[i+1] = atoi(strtok(NULL, ":"));
287 string o815::headMaster()
291 hm << "-L" << comargs.lsize[0] << "_" << comargs.lsize[1] << "-E" << comargs.nequi << "-S" << comargs.nskip << "-N" << comargs.nmeas
292 << paraQ->rangeString();
298 if(comargs.outdir=="") {
300 MPI_Barrier(MPI_COMM_WORLD);
303 cout << "#end" << endl << flush;
305 hypercache::finalize();
312 int o815::nextParas()
314 if( paraQ->nextParas() ) {
315 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
316 hypercache::setPara(*parait, (*paraQ)[*parait]);
323 void o815::addPara(const string& paraid, const double& paraDefault) {
324 hypercache::addPara(paraid);
325 paraQ->setDefault(paraid, paraDefault);