]> git.treefish.org Git - phys/latlib.git/commitdiff
added o815
authorAlex Schmidt <alex@treefish.org>
Tue, 16 Apr 2013 10:22:31 +0000 (12:22 +0200)
committerAlex Schmidt <alex@treefish.org>
Tue, 16 Apr 2013 10:22:31 +0000 (12:22 +0200)
CMakeLists.txt
o815/.gitignore [new file with mode: 0644]
o815/CMakeLists.txt [new file with mode: 0644]
o815/o815.cpp [new file with mode: 0644]
o815/o815.h [new file with mode: 0644]
o815/obs.cpp [new file with mode: 0644]
writeout.cpp
writeout.h

index 9c421cef912da45a47cb6a8c6cdf23250c394757..ba307ba0f601b371f2689265a5514449ec5b1fbb 100644 (file)
@@ -32,4 +32,6 @@ add_executable(culooks_test culooks_test.cpp)
 target_link_libraries(culooks_test lat_culooks)
 
 add_executable(hypercache_test hypercache_test.cpp)
-target_link_libraries(hypercache_test lat_hypercache)
\ No newline at end of file
+target_link_libraries(hypercache_test lat_hypercache)
+
+add_subdirectory(o815)
diff --git a/o815/.gitignore b/o815/.gitignore
new file mode 100644 (file)
index 0000000..6bdb794
--- /dev/null
@@ -0,0 +1,4 @@
+CMakeFiles
+cmake_install
+libo815.a
+Makefile
diff --git a/o815/CMakeLists.txt b/o815/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8431e25
--- /dev/null
@@ -0,0 +1,13 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(o815)
+
+find_package(MPI REQUIRED)
+set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS})
+set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS})
+include_directories(${MPI_INCLUDE_PATH} ../)
+
+SET(CMAKE_BUILD_TYPE Release)
+
+add_library(o815 o815.cpp obs.cpp)
+target_link_libraries(o815 ${MPI_LIBRARIES} lat_paraq lat_writeout)
diff --git a/o815/o815.cpp b/o815/o815.cpp
new file mode 100644 (file)
index 0000000..956eb09
--- /dev/null
@@ -0,0 +1,123 @@
+#include "o815.h"
+
+#include <sstream>
+
+o815::o815(int argc, char **argv, const string& _programid) {
+  long timestamp;
+
+  programid = _programid;
+
+  comargs.nmeas = 100;
+  comargs.nskip = 10;
+  comargs.nequi = 100;
+  comargs.lsize[0] = 4;
+  comargs.lsize[1] = 4;
+  comargs.obscache = make_pair("",0);
+  comargs.confcache = make_pair("",0);
+  comargs.outdir="";
+  comargs.idonly = false;
+  comargs.showjobnum = false;
+
+  MPI_Init(&argc, &argv);
+  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
+  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+
+  paraQ = new paraq(numprocs, rank);
+
+  parseArgs(argc, argv);
+
+  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);
+    for(int idest=1; idest<numprocs; idest++)
+      MPI_Send(&timestamp, 1, MPI_LONG, idest, 123, MPI_COMM_WORLD);
+  }
+  else if(rank>0)
+    MPI_Recv(&timestamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, &mpiStatus);
+  
+  out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp);
+}
+
+void o815::parseArgs(int argc, char **argv) {
+  int opt = 0;
+  
+  while( (opt = getopt(argc, argv, "L:N:S:E:o:O:c:C:w:i:j:")) != -1 )
+    switch(opt) {
+    case 'L':
+      listArg(comargs.lsize, 2, optarg);
+      break;
+    case 'N':
+      comargs.nmeas = atoi(optarg);
+      break;
+    case 'S':
+      comargs.nskip = atoi(optarg);
+      break;
+    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;
+      break;
+    case 'C':
+      comargs.confcache.first = optarg;
+      comargs.confcache.second = 2;
+      break;
+    case 'w':
+      comargs.outdir = optarg;
+      break;
+    case 'i':
+      comargs.idonly = atoi(optarg);
+      break;
+    case 'j':
+      comargs.showjobnum = atoi(optarg);
+      break;
+    }
+}
+
+void o815::listArg(int *target, int tlen, char *listarg) {
+  int nargs=0;
+  
+  for( int pos=0; pos<strlen(listarg); pos++ ) 
+    if( listarg[pos] == ':' ) nargs++;
+  
+  if(nargs==0) 
+    for(int i=0; i<tlen; i++) target[i] = atoi(listarg);
+  else
+    {
+      target[0] = atoi(strtok(listarg, ":"));
+      for(int i=0; i<nargs; i++)
+       target[i+1] = atoi(strtok(NULL, ":"));
+    }
+}
+
+string o815::headMaster()
+{
+  stringstream hm;
+  
+  hm << "-L" << comargs.lsize[0] << "_" << comargs.lsize[1] << "-E" << comargs.nequi << "-S" << comargs.nskip << "-N" << comargs.nmeas 
+     << paraQ->rangeString();
+  
+  return hm.str();
+}
+
diff --git a/o815/o815.h b/o815/o815.h
new file mode 100644 (file)
index 0000000..31d36da
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef O815_H
+#define O815_H
+
+#include <string>
+#include <vector>
+#include <mpi.h>
+#include <stdlib.h>
+
+#include "latlib/paraq.h"
+#include "latlib/writeout.h"
+
+using namespace std;
+
+class obs;
+
+class o815 {
+ public:
+  class obs {
+  public:
+    obs(const string& obsid, o815 *_O815);
+    void finish();
+    void meas();
+  private:
+    virtual void _meas(bool loadedobs)=0;
+    virtual void _finish()=0;
+  protected:
+    o815 *O815;
+    char *obsMem;
+    ostream *oout;
+    ostream *olog;
+    string obsid;
+  };
+
+  struct {
+    int nmeas;
+    int nskip;
+    int nequi;
+    int lsize[2];
+    pair<string,int> obscache;
+    pair<string,int> confcache;
+    string outdir;
+    bool idonly;
+    bool showjobnum;
+  } comargs;
+
+  o815(int argc, char **argv, const string& programid);
+  paraq *paraQ;
+  writeout *out;
+  vector<obs*> observables;
+
+private:
+  MPI_Status mpiStatus;
+  int numprocs, rank;
+  static void listArg(int *target, int tlen, char *listarg);
+  void parseArgs(int argc, char **argv);
+  string programid;
+  string headMaster();
+};
+
+#endif
diff --git a/o815/obs.cpp b/o815/obs.cpp
new file mode 100644 (file)
index 0000000..cd86bf6
--- /dev/null
@@ -0,0 +1,26 @@
+#include "o815.h"
+
+void o815::obs::_meas(bool loadedobs) {
+  *olog << "OBS_" << obsid << ": meas not implemented!" << endl << flush;
+};
+
+void o815::obs::_finish() {
+  *olog << "OBS_" << obsid << ": finish not implemented!" << endl << flush;
+};
+
+void o815::obs::finish() {
+  _finish();
+}
+
+void o815::obs::meas() {
+  _meas(true);
+}
+
+o815::obs::obs(const string& _obsid, o815 *_O815) {
+  obsid = _obsid;
+  O815 = _O815;
+  
+  O815->out->newsub(obsid);
+  oout = O815->out->out[obsid];
+  olog = O815->out->log;
+}
index 3849ac9bab479c02fc944dd32be082ca848f25e0..7834d6b743173b70e239dd4849a1c69171dc7847 100644 (file)
@@ -21,9 +21,33 @@ string writeout::tstamp(const long& timestamp)
   return sstr.str();
 }
 
-writeout::writeout(const string& wdir, const string& signature, 
-                  const int& rank, const int& procs, const long& timestamp)
+void writeout::newsub(string subname) {
+   of[subname] = new ofstream;
+
+  if ( fulldir != "" ) {
+    if(rank>0) of[subname]->open( (fulldir + "/rank" + cRank + "-" + subname + ".tmp").c_str() );
+    else of[subname]->open( (fulldir + "/" + signature + "-" + subname + ".dat").c_str() );
+
+    if ( !of[subname]->is_open() ) {
+      logf << "WRITEOUT: Could not open output-file!" << endl << flush;
+      exit(1);
+    }
+
+    buf[subname] = of[subname]->rdbuf();
+  }
+  else
+    buf[subname] = cout.rdbuf();
+
+  out[subname] = new ostream(buf[subname]);
+}
+
+writeout::writeout(const string& wdir, const string& _signature, 
+                  const int& _rank, const int& procs, const long& timestamp)
 {
+  fulldir = "";
+  signature = _signature;
+  rank = _rank;
+
   if(wdir != ""){
     numprocs = procs;
     sprintf(cRank, "%d", rank);
@@ -31,28 +55,20 @@ writeout::writeout(const string& wdir, const string& signature,
 
     mkdir(fulldir.c_str(), 0775);
 
-    if(rank>0) of.open( (fulldir + "/rank" + cRank + ".tmp").c_str() );
-    else of.open( (fulldir + "/" + signature + ".dat").c_str() );
-
     logf.open( (fulldir + "/rank" + cRank + ".log").c_str() );
 
-    if ( (!of.is_open()) || (!logf.is_open()) ) {
-      cerr << "WRITEOUT: Could not open output- and/or log-file!" << endl << flush;
+    if ( !logf.is_open() ) {
+      cerr << "WRITEOUT: Could not open log-file!" << endl << flush;
       exit(1);
     }
 
     logf << "[ " << timestring() << " ] Log starts here." << endl;
     
-    buf = of.rdbuf();
     logbuf = logf.rdbuf();
-
-    cout << buf << endl;
   }
   else{
-    buf = cout.rdbuf();
     logbuf = cerr.rdbuf();
   }
-  out = new ostream(buf);
   log = new ostream(logbuf);
 }
 
@@ -67,47 +83,45 @@ string writeout::timestring()
 
 writeout::~writeout()
 {
-  if(fulldir != "")
-    {
-      if( cRank[0] == '0' )
-       {
-         int jobsdone=0;
-         while(jobsdone<numprocs-1)
-           {
-             string nextfile;
-             if( (nextfile=getdatfile()) == "" ) sleep(1);
-             else
-               {
-                 logf << "collecting " << nextfile << endl;
-
-                 ifstream myfile( (fulldir + "/" + nextfile).c_str() );
-                 while(true){
-                   string line;
-                   getline(myfile, line);
-                   if( !myfile.good() ) break;
-                   of << line << endl << flush;
-                 }
-                 myfile.close();
-                 remove( (fulldir + "/" + nextfile).c_str() );
-                 jobsdone++;
-               }
+  if(fulldir != "") {
+    for (map<string,ofstream*>::iterator ofit = of.begin(); ofit != of.end(); ++ofit) {
+      if( cRank[0] == '0' ) {    
+       int jobsdone=0;
+       while(jobsdone<numprocs-1) {
+         string nextfile;
+         if( (nextfile = getdatfile(ofit->first)) == "" ) 
+           sleep(1);
+         else {
+           logf << "collecting " << nextfile << endl;
+                   
+           ifstream myfile( (fulldir + "/" + nextfile).c_str() );
+           while(true) {
+             string line;
+             getline(myfile, line);
+             if( !myfile.good() ) break;
+             *ofit->second << line << endl << flush;
            }
-         of << "#end" << endl << flush;
-         of.close();
-         rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
-       }
-      else
-       {
-         of.close();
-         rename((fulldir + "/rank" + cRank + ".tmp").c_str(),
-                (fulldir + "/rank" + cRank + ".part").c_str());
+           myfile.close();
+           remove( (fulldir + "/" + nextfile).c_str() );
+           jobsdone++;
+         }
        }
+       *ofit->second << "#end" << endl << flush;
+       ofit->second->close();
+       rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() );
+      }
+      else {
+       ofit->second->close();
+       rename((fulldir + "/rank" + cRank + ".tmp").c_str(),
+              (fulldir + "/rank" + cRank + ".part").c_str());
+      }
     }
+  }
   logf << "[ " << timestring() << " ] Log ends here." << endl;
   logf.close();
 }
 
-string writeout::getdatfile()
+string writeout::getdatfile(string subname)
 {
   string myfile;
   DIR *dp;
@@ -121,8 +135,9 @@ string writeout::getdatfile()
   while ((dirp = readdir(dp)) != NULL)
     {
       myfile = string(dirp->d_name);
-      if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part")
+      if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part") {
        return myfile;
+      }
     }
 
   return "";
index e7c3ea1e8db977e1fd29bbcac9075ff9b24c0688..67c07c8d35a6e1c1fe48d832b7e395bc29ac2c73 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <ostream>
 #include <fstream>
+#include <map>
 
 using namespace std;
  
@@ -11,21 +12,24 @@ class writeout
  public:
   writeout(const string& wdir, const string& signature, 
           const int& rank, const int& procs, const long& timestamp=0);
-  ostream *out;
+  void newsub(string subname);
+  map<string,ostream*> out;
   ostream *log;
   ~writeout();
 
  private:
-  ofstream of;
+  map<string,ofstream*> of;
+  map<string,streambuf*> buf;
   ofstream logf;
-  streambuf *buf;
   streambuf *logbuf;
   string fulldir;
   char cRank[20];
+  int rank;
   string tstamp(const long& timestamp);
   int numprocs;
-  string getdatfile();
+  string getdatfile(string subname);
   string timestring();
+  string signature;
 };
 
 #endif