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 );
151 (*obsit)->meas(false);
152 hypercache::writeO( (*obsit)->ocid, comargs.nmeas );
155 (*obsit)->meas(true);
157 while( measProg.madeStep(imeas) )
158 *out->log << "O815: " << measProg.done()*100 << "% of measurements done." << endl << flush;
160 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
165 void o815::addComOption(const char* name, int has_arg, int *flag, int val, const char* optdesc, const char* argdesc) {
166 comoption newop = { name, has_arg, flag, val, optdesc, argdesc };
167 comOptions.push_back(newop);
170 void o815::parseArgs(int argc, char **argv, comoption specOps[]) {
173 stringstream optargstr;
174 option allOptions[comOptions.size()+1];
176 for (int iop=0; iop < comOptions.size(); iop++) {
177 allOptions[iop].name = comOptions[iop].name.c_str();
178 allOptions[iop].has_arg = comOptions[iop].has_arg;
179 //allOptions[iop].flag = NULL;
180 allOptions[iop].flag = comOptions[iop].flag;
181 allOptions[iop].val = comOptions[iop].val;
183 optargstr << char(allOptions[iop].val);
184 if (allOptions[iop].has_arg == required_argument)
186 else if (allOptions[iop].has_arg == optional_argument)
190 allOptions[comOptions.size()].name = 0;
191 allOptions[comOptions.size()].has_arg = 0;
192 allOptions[comOptions.size()].flag = 0;
193 allOptions[comOptions.size()].val = 0;
195 while((opt = getopt_long( argc, argv, optargstr.str().c_str(), allOptions, &indexptr )) != -1)
198 listArg(comargs.lsize, 2, optarg);
201 comargs.nmeas = atoi(optarg);
204 comargs.nskip = atoi(optarg);
207 comargs.nequi = atoi(optarg);
210 comargs.obscache.first = optarg;
211 comargs.obscache.second = 1;
214 comargs.obscache.first = optarg;
215 comargs.obscache.second = 2;
218 comargs.confcache.first = optarg;
219 comargs.confcache.second = 1;
222 comargs.confcache.first = optarg;
223 comargs.confcache.second = 2;
226 comargs.outdir = optarg;
230 comoption* thisop = getOptionByVal(opt);
231 if (thisop->flag != 0)
232 *thisop->flag = thisop->val;
234 parsedSpecOps.push_back( pair<int,char*>(thisop->val, optarg) );
239 for (int ilon=0; optind+ilon < argc; ilon++)
240 lonelyArgs.push_back(argv[optind+ilon]);
243 o815::comoption* o815::getOptionByVal(int val) {
244 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit)
245 if ( opit->val == val )
250 void o815::listArg(int *target, int tlen, char *listarg) {
253 for( int pos=0; pos<strlen(listarg); pos++ )
254 if( listarg[pos] == ':' ) nargs++;
257 for(int i=0; i<tlen; i++) target[i] = atoi(listarg);
260 target[0] = atoi(strtok(listarg, ":"));
261 for(int i=0; i<nargs; i++)
262 target[i+1] = atoi(strtok(NULL, ":"));
266 string o815::headMaster()
270 hm << "-L" << comargs.lsize[0] << "_" << comargs.lsize[1] << "-E" << comargs.nequi << "-S" << comargs.nskip << "-N" << comargs.nmeas
271 << paraQ->rangeString();
277 if(comargs.outdir=="") {
278 MPI_Barrier(MPI_COMM_WORLD);
280 cout << "#end" << endl << flush;
282 hypercache::finalize();
287 int o815::nextParas()
289 if( paraQ->nextParas() ) {
290 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
291 hypercache::setPara(*parait, (*paraQ)[*parait]);
298 void o815::addPara(const string& paraid, const double& paraDefault) {
299 hypercache::addPara(paraid);
300 paraQ->setDefault(paraid, paraDefault);