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 Sim->toEquilibrate = true;
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) {
143 if( hypercache::readO( (*obsit)->ocid ) != -1 ) {
148 (*obsit)->meas(false);
149 hypercache::writeO( (*obsit)->ocid );
152 (*obsit)->meas(true);
154 while( measProg.madeStep(imeas) )
155 *out->log << "O815: " << measProg.done()*100 << "% of measurements done." << endl << flush;
157 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
162 void o815::addComOption(const char* name, int has_arg, int *flag, int val, const char* optdesc, const char* argdesc) {
163 comoption newop = { name, has_arg, flag, val, optdesc, argdesc };
164 comOptions.push_back(newop);
167 void o815::parseArgs(int argc, char **argv, comoption specOps[]) {
170 stringstream optargstr;
171 option allOptions[comOptions.size()+1];
173 for (int iop=0; iop < comOptions.size(); iop++) {
174 allOptions[iop].name = comOptions[iop].name.c_str();
175 allOptions[iop].has_arg = comOptions[iop].has_arg;
176 //allOptions[iop].flag = NULL;
177 allOptions[iop].flag = comOptions[iop].flag;
178 allOptions[iop].val = comOptions[iop].val;
180 optargstr << char(allOptions[iop].val);
181 if (allOptions[iop].has_arg == required_argument)
183 else if (allOptions[iop].has_arg == optional_argument)
187 allOptions[comOptions.size()].name = 0;
188 allOptions[comOptions.size()].has_arg = 0;
189 allOptions[comOptions.size()].flag = 0;
190 allOptions[comOptions.size()].val = 0;
192 while((opt = getopt_long( argc, argv, optargstr.str().c_str(), allOptions, &indexptr )) != -1)
195 listArg(comargs.lsize, 2, optarg);
198 comargs.nmeas = atoi(optarg);
201 comargs.nskip = atoi(optarg);
204 comargs.nequi = atoi(optarg);
207 comargs.obscache.first = optarg;
208 comargs.obscache.second = 1;
211 comargs.obscache.first = optarg;
212 comargs.obscache.second = 2;
215 comargs.confcache.first = optarg;
216 comargs.confcache.second = 1;
219 comargs.confcache.first = optarg;
220 comargs.confcache.second = 2;
223 comargs.outdir = optarg;
227 comoption* thisop = getOptionByVal(opt);
228 if (thisop->flag != 0)
229 *thisop->flag = thisop->val;
231 parsedSpecOps.push_back( pair<int,char*>(thisop->val, optarg) );
236 for (int ilon=0; optind+ilon < argc; ilon++)
237 lonelyArgs.push_back(argv[optind+ilon]);
240 o815::comoption* o815::getOptionByVal(int val) {
241 for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit)
242 if ( opit->val == val )
247 void o815::listArg(int *target, int tlen, char *listarg) {
250 for( int pos=0; pos<strlen(listarg); pos++ )
251 if( listarg[pos] == ':' ) nargs++;
254 for(int i=0; i<tlen; i++) target[i] = atoi(listarg);
257 target[0] = atoi(strtok(listarg, ":"));
258 for(int i=0; i<nargs; i++)
259 target[i+1] = atoi(strtok(NULL, ":"));
263 string o815::headMaster()
267 hm << "-L" << comargs.lsize[0] << "_" << comargs.lsize[1] << "-E" << comargs.nequi << "-S" << comargs.nskip << "-N" << comargs.nmeas
268 << paraQ->rangeString();
274 if(comargs.outdir=="") {
275 MPI_Barrier(MPI_COMM_WORLD);
277 cout << "#end" << endl << flush;
279 hypercache::finalize();
284 int o815::nextParas()
286 if( paraQ->nextParas() ) {
287 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
288 hypercache::setPara(*parait, (*paraQ)[*parait]);
295 void o815::addPara(const string& paraid, const double& paraDefault) {
296 hypercache::addPara(paraid);
297 paraQ->setDefault(paraid, paraDefault);