]> git.treefish.org Git - phys/latlib.git/commitdiff
...
authorAlex Schmidt <alex@treefish.org>
Mon, 15 Oct 2012 16:39:18 +0000 (18:39 +0200)
committerAlex Schmidt <alex@treefish.org>
Mon, 15 Oct 2012 16:39:18 +0000 (18:39 +0200)
CMakeLists.txt
progress.cpp [new file with mode: 0644]
progress.h [new file with mode: 0644]
writeout.cpp
writeout.h

index a251c138df5e180ccd44140fd4d7b633f773f7e7..017d8d8718590c317b6b794ae6fa9b7f67d744d4 100644 (file)
@@ -9,5 +9,7 @@ add_library(lat_writeout writeout.cpp)
 
 add_library(lat_paraq paraq.cpp)
 
+add_library(lat_progress progress.cpp)
+
 add_executable(neigh_test neigh_test.cpp)
 target_link_libraries(neigh_test lat_neigh)
\ No newline at end of file
diff --git a/progress.cpp b/progress.cpp
new file mode 100644 (file)
index 0000000..31d4859
--- /dev/null
@@ -0,0 +1,18 @@
+#include "progress.h"
+
+progress::progress(int a_realsteps, int a_progsteps)
+{
+  laststep = 0;
+  realsteps = a_realsteps;
+  progsteps = a_progsteps;
+}
+
+bool progress::madeStep(int realStep)
+{
+  if( (double)(realStep+1)*progsteps/realsteps >= laststep+1 ) {
+    laststep++;
+    return true;
+  }
+  else
+    return false;
+}
diff --git a/progress.h b/progress.h
new file mode 100644 (file)
index 0000000..44b6f94
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef PROGRESS_H
+#define PROGRESS_H
+
+class progress
+{
+ public:
+  progress(int a_realsteps, int a_progsteps=100);
+  bool madeStep( int realStep );
+  
+ private:
+  int realsteps;
+  int progsteps;
+  int laststep;
+};
+
+#endif
index 2290a941cb343b72a0c4afe224903b33a51dbf55..9a5409de4e16e0fdda1e654f2179f6364ef8034d 100644 (file)
@@ -33,12 +33,28 @@ writeout::writeout(const string& wdir, const string& signature,
     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() );
+
+    logf << "[ " << timestring() << " ] Log starts here." << endl;
+    
     buf = of.rdbuf();
+    logbuf = logf.rdbuf();
   }
   else{
     buf = cout.rdbuf();
+    logbuf = cerr.rdbuf();
   }
   out = new ostream(buf);
+  log = new ostream(logbuf);
+}
+
+string writeout::timestring()
+{
+  time_t rawtime;
+  string timestring;
+  time( &rawtime );
+  timestring = asctime( localtime( &rawtime ) );
+  return timestring.substr(0, timestring.size()-1);;
 }
 
 writeout::~writeout()
@@ -79,6 +95,8 @@ writeout::~writeout()
                 (fulldir + "/rank" + cRank + ".part").c_str());
        }
     }
+  logf << "[ " << timestring() << " ] Log ends here." << endl;
+  logf.close();
 }
 
 string writeout::getdatfile()
index 4df290d78f5c119c4ee0b4092d23656b61eec1d5..e7c3ea1e8db977e1fd29bbcac9075ff9b24c0688 100644 (file)
@@ -5,23 +5,27 @@
 #include <fstream>
 
 using namespace std;
-
 class writeout
 {
  public:
   writeout(const string& wdir, const string& signature, 
           const int& rank, const int& procs, const long& timestamp=0);
   ostream *out;
+  ostream *log;
   ~writeout();
 
  private:
   ofstream of;
+  ofstream logf;
   streambuf *buf;
+  streambuf *logbuf;
   string fulldir;
   char cRank[20];
   string tstamp(const long& timestamp);
   int numprocs;
   string getdatfile();
+  string timestring();
 };
 
 #endif