]> git.treefish.org Git - phys/latlib.git/blobdiff - o815/o815.cpp
Added MPI_DISABLED cmake switch.
[phys/latlib.git] / o815 / o815.cpp
index 878df0f6297556bb66e3986d2858da20ca9327e1..b68a38b061df92d0741b4a3bdb6ab0f3ce1093e1 100644 (file)
@@ -2,6 +2,11 @@
 
 #include <sstream>
 #include <iomanip>
 
 #include <sstream>
 #include <iomanip>
+#include <cstring>
+
+#ifndef MPI_DISABLED
+#include <mpi.h>
+#endif
 
 #include "latlib/progress.h"
 
 
 #include "latlib/progress.h"
 
@@ -10,8 +15,6 @@ using namespace std;
 extern int opterr;
 
 o815::o815(int argc, char **argv, const string& _programid, comoption specOps[], void (*helpHeader)()) {
 extern int opterr;
 
 o815::o815(int argc, char **argv, const string& _programid, comoption specOps[], void (*helpHeader)()) {
-  long timestamp;
-
   programid = _programid;
 
   comargs.nmeas = 100;
   programid = _programid;
 
   comargs.nmeas = 100;
@@ -25,11 +28,14 @@ o815::o815(int argc, char **argv, const string& _programid, comoption specOps[],
   comargs.idonly = false;
   comargs.showjobnum = false;
 
   comargs.idonly = false;
   comargs.showjobnum = false;
 
+#ifndef MPI_DISABLED
   MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
-
-  paraQ = new paraq(numprocs, rank);
+#else
+  numprocs = 1;
+  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("lsize",  required_argument, NULL,                'L', "define lattice size",                   "xsize:tsize");
   addComOption("nmeas",  required_argument, NULL,                'N', "set number of measurements",            "nmeas");
@@ -90,31 +96,44 @@ o815::o815(int argc, char **argv, const string& _programid, comoption specOps[],
     exit(0);
   }
 
     exit(0);
   }
 
+  paraQ = new paraq(numprocs, rank);
+
+  hypercache::addPara("lx", comargs.lsize[0]);
+  hypercache::addPara("lt", comargs.lsize[1]);
+}
+
+void o815::postParaInit() {
+  long timestamp;
+
   if(comargs.idonly) {
     cout << programid << headMaster() << endl << flush;
     exit(0);
   }
 
   if(comargs.idonly) {
     cout << programid << headMaster() << endl << flush;
     exit(0);
   }
 
+  if( comargs.showjobnum ) {
+    for( int i=1; i<=paraQ->getTotalJobs(); i++ ) {
+      if( paraQ->getTotalJobs()%i == 0 ) cout << paraQ->getTotalJobs()/i << "@" << i << " ";
+    }
+    cout << endl;
+    exit(0);
+  }
+  
   if(rank==0) {
     timestamp = time(NULL);
   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);
     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)
   else if(rank>0)
-    MPI_Recv(&timestamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, &mpiStatus);
-  
+    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);
 }
 
 void o815::mainLoop() {
   out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp);
 }
 
 void o815::mainLoop() {
-  if( comargs.showjobnum ) {
-    for( int i=1; i<=paraQ->getTotalJobs(); i++ ) {
-      if( paraQ->getTotalJobs()%i == 0 ) cout << paraQ->getTotalJobs()/i << "@" << i << " ";
-    }
-    cout << endl;
-    exit(0);
-  }
-
   *out->log << "OBS: Starting main loop." << endl;
 
   for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
   *out->log << "OBS: Starting main loop." << endl;
 
   for (vector<obs*>::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit)
@@ -135,26 +154,26 @@ void o815::mainLoop() {
       *out->log << " " << (*obsit)->obsid;
     *out->log << endl << flush;
 
       *out->log << " " << (*obsit)->obsid;
     *out->log << endl << flush;
 
-    Sim->nequileft = comargs.nequi;
-
     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;
        
     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;
        
-       hypercache::readO( (*obsit)->ocid, readnewObs, nequileftNewObs );
+       hypercache::readO( (*obsit)->ocid, &readnewObs, &nequileftNewObs );
 
 
-       if( ! readnewObs ) {
+       if ( readnewObs && nequileftNewObs < 0 ) {
+         (*obsit)->meas(true, imeas);
+       }
+       else {
          if (!nextAlready) {
            Sim->nextConfig();
            nextAlready = true;
          }
          if (!nextAlready) {
            Sim->nextConfig();
            nextAlready = true;
          }
-         (*obsit)->meas(false);
-         hypercache::writeO( (*obsit)->ocid, comargs.nmeas );
+         (*obsit)->meas(false, imeas);
+         hypercache::writeO( (*obsit)->ocid );
        }
        }
-       else
-         (*obsit)->meas(true);
+         
       }
       while( measProg.madeStep(imeas) ) 
        *out->log << "O815: " << measProg.done()*100 << "% of measurements done." << endl << flush;
       }
       while( measProg.madeStep(imeas) ) 
        *out->log << "O815: " << measProg.done()*100 << "% of measurements done." << endl << flush;
@@ -277,13 +296,17 @@ string o815::headMaster()
 
 o815::~o815() {
   if(comargs.outdir=="") {
 
 o815::~o815() {
   if(comargs.outdir=="") {
+#ifndef MPI_DISABLED
     MPI_Barrier(MPI_COMM_WORLD);
     MPI_Barrier(MPI_COMM_WORLD);
+#endif
     if(rank==0)
       cout << "#end" << endl << flush;
   }
   hypercache::finalize();
   delete out;
     if(rank==0)
       cout << "#end" << endl << flush;
   }
   hypercache::finalize();
   delete out;
+#ifndef MPI_DISABLED
   MPI_Finalize();
   MPI_Finalize();
+#endif
 }
 
 int o815::nextParas()
 }
 
 int o815::nextParas()