5 #include "latlib/progress.h"
7 o815::o815(int argc, char **argv, const string& _programid) {
10 programid = _programid;
17 comargs.obscache = make_pair("",0);
18 comargs.confcache = make_pair("",0);
20 comargs.idonly = false;
21 comargs.showjobnum = false;
23 MPI_Init(&argc, &argv);
24 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
25 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
27 paraQ = new paraq(numprocs, rank);
29 parseArgs(argc, argv);
32 cout << programid << headMaster() << endl << flush;
36 if( comargs.showjobnum ) {
37 for( int i=1; i<=paraQ->getTotalJobs(); i++ ) {
38 if( paraQ->getTotalJobs()%i == 0 ) cout << paraQ->getTotalJobs()/i << "@" << i << " ";
45 timestamp = time(NULL);
46 for(int idest=1; idest<numprocs; idest++)
47 MPI_Send(×tamp, 1, MPI_LONG, idest, 123, MPI_COMM_WORLD);
50 MPI_Recv(×tamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, &mpiStatus);
52 out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp);
55 void o815::mainLoop() {
56 *out->log << "OBS: Starting main loop." << endl;
58 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
61 while( nextParas() ) {
62 *out->log << endl << "O815: < ";
63 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
64 *out->log << *parait << "=" << (*paraQ)[*parait] << " ";
65 *out->log << ">" << endl << flush;
67 progress measProg(comargs.nmeas);
69 *out->log << "OBS: Starting measurements." << endl << flush;
71 for( int imeas=0; imeas<comargs.nmeas; imeas++ ) {
72 bool nextAlready = false;
73 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) {
74 if( hypercache::readO( (*obsit)->ocid ) != -1 ) {
79 (*obsit)->meas(false);
80 hypercache::writeO( (*obsit)->ocid );
85 while( measProg.madeStep(imeas) )
86 *out->log << "O815: " << measProg.done()*100 << "% of measurements done." << endl << flush;
88 for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
93 void o815::parseArgs(int argc, char **argv) {
96 while( (opt = getopt(argc, argv, "L:N:S:E:o:O:c:C:w:i:j:")) != -1 )
99 listArg(comargs.lsize, 2, optarg);
102 comargs.nmeas = atoi(optarg);
105 comargs.nskip = atoi(optarg);
108 comargs.nequi = atoi(optarg);
111 comargs.obscache.first = optarg;
112 comargs.obscache.second = 1;
115 comargs.obscache.first = optarg;
116 comargs.obscache.second = 2;
119 comargs.confcache.first = optarg;
120 comargs.confcache.second = 1;
123 comargs.confcache.first = optarg;
124 comargs.confcache.second = 2;
127 comargs.outdir = optarg;
130 comargs.idonly = atoi(optarg);
133 comargs.showjobnum = atoi(optarg);
138 void o815::listArg(int *target, int tlen, char *listarg) {
141 for( int pos=0; pos<strlen(listarg); pos++ )
142 if( listarg[pos] == ':' ) nargs++;
145 for(int i=0; i<tlen; i++) target[i] = atoi(listarg);
148 target[0] = atoi(strtok(listarg, ":"));
149 for(int i=0; i<nargs; i++)
150 target[i+1] = atoi(strtok(NULL, ":"));
154 string o815::headMaster()
158 hm << "-L" << comargs.lsize[0] << "_" << comargs.lsize[1] << "-E" << comargs.nequi << "-S" << comargs.nskip << "-N" << comargs.nmeas
159 << paraQ->rangeString();
165 if(comargs.outdir=="") {
166 MPI_Barrier(MPI_COMM_WORLD);
168 cout << "#end" << endl << flush;
170 hypercache::finalize();
175 int o815::nextParas()
177 if( paraQ->nextParas() ) {
178 for (vector<string>::iterator parait = paraQ->allParaIds.begin(); parait != paraQ->allParaIds.end(); ++parait)
179 hypercache::setPara(*parait, (*paraQ)[*parait]);
186 void o815::addPara(const string& paraid, const double& paraDefault) {
187 hypercache::addPara(paraid);
188 paraQ->setDefault(paraid, paraDefault);