6 #include "latlib/progress.h"
12 o815::o815(int argc, char **argv, const string& _programid, comoption specOps[], void (*helpHeader)()) {
15 programid = _programid;
22 comargs.obscache = make_pair("",0);
23 comargs.confcache = make_pair("",0);
25 comargs.idonly = false;
26 comargs.showjobnum = false;
28 MPI_Init(&argc, &argv);
29 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
30 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
32 paraQ = new paraq(numprocs, rank);
34 addComOption("lsize", required_argument, NULL, 'L', "define lattice size", "xsize:tsize");
35 addComOption("nmeas", required_argument, NULL, 'N', "set number of measurements", "nmeas");
36 addComOption("skip", required_argument, NULL, 'S', "set number of skips between configs", "nskip");
37 addComOption("nequi", required_argument, NULL, 'E', "set number of equilibrations", "nequi");
38 addComOption("oro", required_argument, NULL, 'o', "read-only observable-store directory", "dir");
39 addComOption("orw", required_argument, NULL, 'O', "read-write observable-store directory", "dir");
40 addComOption("cro", required_argument, NULL, 'c', "read-only config-store directory", "dir");
41 addComOption("crw", required_argument, NULL, 'C', "read-write config-store directory", "dir");
42 addComOption("write", required_argument, NULL, 'w', "data writeout directory", "dir");
43 addComOption("idonly", no_argument, &comargs.idonly, 'i', "show output-id only", "");
44 addComOption("jobnum", no_argument, &comargs.showjobnum, 'j', "show jobnumber only", "");
47 for (int ispecop = 0; specOps[ispecop].name != ""; ispecop++)
48 comOptions.push_back(specOps[ispecop]);
51 parseArgs(argc, argv, specOps);
53 int longestCombinedLong=0;
55 if (helpHeader != NULL)
58 cout << "Options:" << endl;
60 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) {
61 stringstream combinedLong;
63 combinedLong << opit->name;
64 if (opit->has_arg == required_argument)
65 combinedLong << "=" << opit->argdesc;
66 else if (opit->has_arg == optional_argument)
67 combinedLong << "[=" << opit->argdesc << "]";
69 if (longestCombinedLong < combinedLong.str().size())
70 longestCombinedLong = combinedLong.str().size();
73 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) {
74 stringstream combinedLong;
76 cout << " -" << char(opit->val) << ", --";
78 combinedLong << opit->name;
79 if (opit->has_arg == required_argument)
80 combinedLong << "=" << opit->argdesc;
81 else if (opit->has_arg == optional_argument)
82 combinedLong << "[=" << opit->argdesc << "]";
84 cout << setw(longestCombinedLong) << setiosflags(ios::left) << combinedLong.str();
86 cout << "\t" << opit->optdesc;
94 cout << programid << headMaster() << endl << flush;
99 timestamp = time(NULL);
100 for(int idest=1; idest<numprocs; idest++)
101 MPI_Send(×tamp, 1, MPI_LONG, idest, 123, MPI_COMM_WORLD);
104 MPI_Recv(×tamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, &mpiStatus);
106 out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp);
109 void o815::mainLoop() {
110 if( comargs.showjobnum ) {
111 for( int i=1; i<=paraQ->getTotalJobs(); i++ ) {
112 if( paraQ->getTotalJobs()%i == 0 ) cout << paraQ->getTotalJobs()/i << "@" << i << " ";
118 *out->log << "OBS: Starting main loop." << endl;
120 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
123 while( nextParas() ) {
124 *out->log << endl << "O815: < ";
125 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
126 *out->log << *parait << "=" << (*paraQ)[*parait] << " ";
127 *out->log << ">" << endl << flush;
131 progress measProg(comargs.nmeas);
133 *out->log << "OBS: Starting measurement of observables:";
134 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
135 *out->log << " " << (*obsit)->obsid;
136 *out->log << endl << flush;
138 for( int imeas=0; imeas<comargs.nmeas; imeas++ ) {
139 bool nextAlready = false;
140 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) {
144 hypercache::readO( (*obsit)->ocid, &readnewObs, &nequileftNewObs );
146 if ( readnewObs && nequileftNewObs < 0 ) {
147 (*obsit)->meas(true);
154 (*obsit)->meas(false);
155 hypercache::writeO( (*obsit)->ocid );
159 while( measProg.madeStep(imeas) )
160 *out->log << "O815: " << measProg.done()*100 << "% of measurements done." << endl << flush;
162 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
167 void o815::addComOption(const char* name, int has_arg, int *flag, int val, const char* optdesc, const char* argdesc) {
168 comoption newop = { name, has_arg, flag, val, optdesc, argdesc };
169 comOptions.push_back(newop);
172 void o815::parseArgs(int argc, char **argv, comoption specOps[]) {
175 stringstream optargstr;
176 option allOptions[comOptions.size()+1];
178 for (int iop=0; iop < comOptions.size(); iop++) {
179 allOptions[iop].name = comOptions[iop].name.c_str();
180 allOptions[iop].has_arg = comOptions[iop].has_arg;
181 //allOptions[iop].flag = NULL;
182 allOptions[iop].flag = comOptions[iop].flag;
183 allOptions[iop].val = comOptions[iop].val;
185 optargstr << char(allOptions[iop].val);
186 if (allOptions[iop].has_arg == required_argument)
188 else if (allOptions[iop].has_arg == optional_argument)
192 allOptions[comOptions.size()].name = 0;
193 allOptions[comOptions.size()].has_arg = 0;
194 allOptions[comOptions.size()].flag = 0;
195 allOptions[comOptions.size()].val = 0;
197 while((opt = getopt_long( argc, argv, optargstr.str().c_str(), allOptions, &indexptr )) != -1)
200 listArg(comargs.lsize, 2, optarg);
203 comargs.nmeas = atoi(optarg);
206 comargs.nskip = atoi(optarg);
209 comargs.nequi = atoi(optarg);
212 comargs.obscache.first = optarg;
213 comargs.obscache.second = 1;
216 comargs.obscache.first = optarg;
217 comargs.obscache.second = 2;
220 comargs.confcache.first = optarg;
221 comargs.confcache.second = 1;
224 comargs.confcache.first = optarg;
225 comargs.confcache.second = 2;
228 comargs.outdir = optarg;
232 comoption* thisop = getOptionByVal(opt);
233 if (thisop->flag != 0)
234 *thisop->flag = thisop->val;
236 parsedSpecOps.push_back( pair<int,char*>(thisop->val, optarg) );
241 for (int ilon=0; optind+ilon < argc; ilon++)
242 lonelyArgs.push_back(argv[optind+ilon]);
245 o815::comoption* o815::getOptionByVal(int val) {
246 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit)
247 if ( opit->val == val )
252 void o815::listArg(int *target, int tlen, char *listarg) {
255 for( int pos=0; pos<strlen(listarg); pos++ )
256 if( listarg[pos] == ':' ) nargs++;
259 for(int i=0; i<tlen; i++) target[i] = atoi(listarg);
262 target[0] = atoi(strtok(listarg, ":"));
263 for(int i=0; i<nargs; i++)
264 target[i+1] = atoi(strtok(NULL, ":"));
268 string o815::headMaster()
272 hm << "-L" << comargs.lsize[0] << "_" << comargs.lsize[1] << "-E" << comargs.nequi << "-S" << comargs.nskip << "-N" << comargs.nmeas
273 << paraQ->rangeString();
279 if(comargs.outdir=="") {
280 MPI_Barrier(MPI_COMM_WORLD);
282 cout << "#end" << endl << flush;
284 hypercache::finalize();
289 int o815::nextParas()
291 if( paraQ->nextParas() ) {
292 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
293 hypercache::setPara(*parait, (*paraQ)[*parait]);
300 void o815::addPara(const string& paraid, const double& paraDefault) {
301 hypercache::addPara(paraid);
302 paraQ->setDefault(paraid, paraDefault);