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);
91 hypercache::addPara("lx", comargs.lsize[0]);
92 hypercache::addPara("lt", comargs.lsize[1]);
95 void o815::postParaInit() {
99 cout << programid << headMaster() << endl << flush;
103 if( comargs.showjobnum ) {
104 for( int i=1; i<=paraQ->getTotalJobs(); i++ ) {
105 if( paraQ->getTotalJobs()%i == 0 ) cout << paraQ->getTotalJobs()/i << "@" << i << " ";
112 timestamp = time(NULL);
113 for(int idest=1; idest<numprocs; idest++)
114 MPI_Send(×tamp, 1, MPI_LONG, idest, 123, MPI_COMM_WORLD);
117 MPI_Recv(×tamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, &mpiStatus);
119 out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp);
122 void o815::mainLoop() {
123 *out->log << "OBS: Starting main loop." << endl;
125 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
128 while( nextParas() ) {
129 *out->log << endl << "O815: < ";
130 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
131 *out->log << *parait << "=" << (*paraQ)[*parait] << " ";
132 *out->log << ">" << endl << flush;
136 progress measProg(comargs.nmeas);
138 *out->log << "OBS: Starting measurement of observables:";
139 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
140 *out->log << " " << (*obsit)->obsid;
141 *out->log << endl << flush;
143 for( int imeas=0; imeas<comargs.nmeas; imeas++ ) {
144 bool nextAlready = false;
145 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) {
149 hypercache::readO( (*obsit)->ocid, &readnewObs, &nequileftNewObs );
151 if ( readnewObs && nequileftNewObs < 0 ) {
152 (*obsit)->meas(true);
159 (*obsit)->meas(false);
160 hypercache::writeO( (*obsit)->ocid );
164 while( measProg.madeStep(imeas) )
165 *out->log << "O815: " << measProg.done()*100 << "% of measurements done." << endl << flush;
167 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
172 void o815::addComOption(const char* name, int has_arg, int *flag, int val, const char* optdesc, const char* argdesc) {
173 comoption newop = { name, has_arg, flag, val, optdesc, argdesc };
174 comOptions.push_back(newop);
177 void o815::parseArgs(int argc, char **argv, comoption specOps[]) {
180 stringstream optargstr;
181 option allOptions[comOptions.size()+1];
183 for (int iop=0; iop < comOptions.size(); iop++) {
184 allOptions[iop].name = comOptions[iop].name.c_str();
185 allOptions[iop].has_arg = comOptions[iop].has_arg;
186 //allOptions[iop].flag = NULL;
187 allOptions[iop].flag = comOptions[iop].flag;
188 allOptions[iop].val = comOptions[iop].val;
190 optargstr << char(allOptions[iop].val);
191 if (allOptions[iop].has_arg == required_argument)
193 else if (allOptions[iop].has_arg == optional_argument)
197 allOptions[comOptions.size()].name = 0;
198 allOptions[comOptions.size()].has_arg = 0;
199 allOptions[comOptions.size()].flag = 0;
200 allOptions[comOptions.size()].val = 0;
202 while((opt = getopt_long( argc, argv, optargstr.str().c_str(), allOptions, &indexptr )) != -1)
205 listArg(comargs.lsize, 2, optarg);
208 comargs.nmeas = atoi(optarg);
211 comargs.nskip = atoi(optarg);
214 comargs.nequi = atoi(optarg);
217 comargs.obscache.first = optarg;
218 comargs.obscache.second = 1;
221 comargs.obscache.first = optarg;
222 comargs.obscache.second = 2;
225 comargs.confcache.first = optarg;
226 comargs.confcache.second = 1;
229 comargs.confcache.first = optarg;
230 comargs.confcache.second = 2;
233 comargs.outdir = optarg;
237 comoption* thisop = getOptionByVal(opt);
238 if (thisop->flag != 0)
239 *thisop->flag = thisop->val;
241 parsedSpecOps.push_back( pair<int,char*>(thisop->val, optarg) );
246 for (int ilon=0; optind+ilon < argc; ilon++)
247 lonelyArgs.push_back(argv[optind+ilon]);
250 o815::comoption* o815::getOptionByVal(int val) {
251 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit)
252 if ( opit->val == val )
257 void o815::listArg(int *target, int tlen, char *listarg) {
260 for( int pos=0; pos<strlen(listarg); pos++ )
261 if( listarg[pos] == ':' ) nargs++;
264 for(int i=0; i<tlen; i++) target[i] = atoi(listarg);
267 target[0] = atoi(strtok(listarg, ":"));
268 for(int i=0; i<nargs; i++)
269 target[i+1] = atoi(strtok(NULL, ":"));
273 string o815::headMaster()
277 hm << "-L" << comargs.lsize[0] << "_" << comargs.lsize[1] << "-E" << comargs.nequi << "-S" << comargs.nskip << "-N" << comargs.nmeas
278 << paraQ->rangeString();
284 if(comargs.outdir=="") {
285 MPI_Barrier(MPI_COMM_WORLD);
287 cout << "#end" << endl << flush;
289 hypercache::finalize();
294 int o815::nextParas()
296 if( paraQ->nextParas() ) {
297 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
298 hypercache::setPara(*parait, (*paraQ)[*parait]);
305 void o815::addPara(const string& paraid, const double& paraDefault) {
306 hypercache::addPara(paraid);
307 paraQ->setDefault(paraid, paraDefault);