]> git.treefish.org Git - phys/latlib.git/blobdiff - o815/o815.cpp
Fixed writeout option.
[phys/latlib.git] / o815 / o815.cpp
index b68a38b061df92d0741b4a3bdb6ab0f3ce1093e1..f078db3a0dcb16dd9d017d5409c49551af100a23 100644 (file)
@@ -37,17 +37,17 @@ o815::o815(int argc, char **argv, const string& _programid, comoption specOps[],
   rank = 0;
 #endif
 
-  addComOption("lsize",  required_argument, NULL,                'L', "define lattice size",                   "xsize:tsize");
-  addComOption("nmeas",  required_argument, NULL,                'N', "set number of measurements",            "nmeas");
-  addComOption("skip",   required_argument, NULL,                'S', "set number of skips between configs",   "nskip");
-  addComOption("nequi",  required_argument, NULL,                'E', "set number of equilibrations",          "nequi");
-  addComOption("oro",    required_argument, NULL,                'o', "read-only observable-store directory",  "dir");
-  addComOption("orw",    required_argument, NULL,                'O', "read-write observable-store directory", "dir");
-  addComOption("cro",    required_argument, NULL,                'c', "read-only config-store directory",      "dir");
-  addComOption("crw",    required_argument, NULL,                'C', "read-write config-store directory",     "dir");
-  addComOption("write",  required_argument, NULL,                'w', "data writeout directory",               "dir");
-  addComOption("idonly", no_argument,       &comargs.idonly,     'i', "show output-id only",                   "");
-  addComOption("jobnum", no_argument,       &comargs.showjobnum, 'j', "show jobnumber only",                   "");
+  addComOption("lsize",  required_argument, NULL,                'L', "define lattice size",                     "xsize:tsize");
+  addComOption("nmeas",  required_argument, NULL,                'N', "set number of measurements",              "nmeas");
+  addComOption("skip",   required_argument, NULL,                'S', "set number of skips between configs",     "nskip");
+  addComOption("nequi",  required_argument, NULL,                'E', "set number of equilibrations",            "nequi");
+  addComOption("ocache", required_argument, NULL,                'O', "set observable cache (mode=oo|ro|wo|rw)", "dir:mode");
+  addComOption("ccache", required_argument, NULL,                'C', "set config cache (mode=oo|ro|wo|rw)",     "dir:mode");
+  addComOption("write",  required_argument, NULL,                'W', "data writeout directory",                 "dir");
+  addComOption("idonly", no_argument,       &comargs.idonly,     'I', "show output-id only",                     "");
+  addComOption("jobnum", no_argument,       &comargs.showjobnum, 'J', "show jobnumber only",                     "");
+
+  vector<comoption>::iterator lastO815Opt = comOptions.end()-1;
 
   if (specOps != NULL)
     for (int ispecop = 0; specOps[ispecop].name != ""; ispecop++)
@@ -61,7 +61,7 @@ o815::o815(int argc, char **argv, const string& _programid, comoption specOps[],
     if (helpHeader != NULL)
       helpHeader();
 
-    cout << "Options:" << endl;
+    cout << "General options:" << endl;
 
     for (vector<comoption>::iterator opit = comOptions.begin(); opit != comOptions.end(); ++opit) {
       stringstream combinedLong;
@@ -92,6 +92,11 @@ o815::o815(int argc, char **argv, const string& _programid, comoption specOps[],
       cout << "\t" << opit->optdesc;
       
       cout << endl;
+
+      if ( opit == lastO815Opt && (opit+1) != comOptions.end() ) {
+       cout << endl;
+       cout << "Simulation specific options:" << endl;
+      }
     }
     exit(0);
   }
@@ -118,24 +123,15 @@ void o815::postParaInit() {
     exit(0);
   }
   
-  if(rank==0) {
-    timestamp = time(NULL);
-#ifndef MPI_DISABLED
-    for(int idest=1; idest<numprocs; idest++)
-      MPI_Send(&timestamp, 1, MPI_LONG, idest, 123, MPI_COMM_WORLD);
-#endif
-  }
-#ifndef MPI_DISABLED
-  else if(rank>0)
-    MPI_Recv(&timestamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
-#endif  
-
-  out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp);
+  out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs);
 }
 
 void o815::mainLoop() {
   *out->log << "OBS: Starting main loop." << endl;
 
+  if ( observables.size() == 0 )
+    *out->log << "O815: Running in 0-observable-mode." << endl;
+
   for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
     (*obsit)->start();
 
@@ -156,6 +152,7 @@ void o815::mainLoop() {
 
     for( int imeas=0; imeas<comargs.nmeas; imeas++ ) {
       bool nextAlready = false;
+
       for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) {
        bool readnewObs;
        int nequileftNewObs;
@@ -172,9 +169,12 @@ void o815::mainLoop() {
          }
          (*obsit)->meas(false, imeas);
          hypercache::writeO( (*obsit)->ocid );
-       }
-         
+       }         
       }
+
+      if ( observables.size() == 0 )
+       Sim->nextConfig();
+
       while( measProg.madeStep(imeas) ) 
        *out->log << "O815: " << measProg.done()*100 << "% of measurements done." << endl << flush;
     }
@@ -227,23 +227,13 @@ void o815::parseArgs(int argc, char **argv, comoption specOps[]) {
     case 'E':
       comargs.nequi = atoi(optarg);
       break;
-    case 'o':
-      comargs.obscache.first = optarg;
-      comargs.obscache.second = 1;
-      break;
     case 'O':
-      comargs.obscache.first = optarg;
-      comargs.obscache.second = 2;
-      break;
-    case 'c':
-      comargs.confcache.first = optarg;
-      comargs.confcache.second = 1;
+      readCacheArgs(optarg, comargs.obscache.first, comargs.obscache.second);
       break;
     case 'C':
-      comargs.confcache.first = optarg;
-      comargs.confcache.second = 2;
+      readCacheArgs(optarg, comargs.confcache.first, comargs.confcache.second);
       break;
-    case 'w':
+    case 'W':
       comargs.outdir = optarg;
       break;
     default:
@@ -324,3 +314,27 @@ void o815::addPara(const string& paraid, const double& paraDefault) {
   hypercache::addPara(paraid);
   paraQ->setDefault(paraid, paraDefault);
 }
+
+void o815::readCacheArgs(const string& arg, string& cachedir, int& cachemode)
+{
+  if ( arg.rfind(":") == string::npos ) {
+    cerr << "O815: Invalid cache argument!" << endl;
+    exit(1);
+  }
+
+  string arg_mode = arg.substr( arg.rfind(":")+1 );
+  if ( arg_mode == "oo" )
+    cachemode = CACHE_MODE_OO;
+  else if ( arg_mode == "ro" )
+    cachemode = CACHE_MODE_RO;
+  else if ( arg_mode == "wo" )
+    cachemode = CACHE_MODE_WO;
+  else if ( arg_mode == "rw" )
+    cachemode = CACHE_MODE_RW;
+  else {
+    cerr << "O815: Unknown cache mode " << arg_mode << "!" << endl;
+    exit(1);
+  }
+
+  cachedir = arg.substr( 0, arg.rfind(":") );
+}