From 931c993776aa8bc41f11d6d676a894324d73a1a3 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Mon, 15 Oct 2012 18:39:18 +0200 Subject: [PATCH] ... --- CMakeLists.txt | 2 ++ progress.cpp | 18 ++++++++++++++++++ progress.h | 16 ++++++++++++++++ writeout.cpp | 18 ++++++++++++++++++ writeout.h | 6 +++++- 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 progress.cpp create mode 100644 progress.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a251c13..017d8d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 0000000..31d4859 --- /dev/null +++ b/progress.cpp @@ -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 index 0000000..44b6f94 --- /dev/null +++ b/progress.h @@ -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 diff --git a/writeout.cpp b/writeout.cpp index 2290a94..9a5409d 100644 --- a/writeout.cpp +++ b/writeout.cpp @@ -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() diff --git a/writeout.h b/writeout.h index 4df290d..e7c3ea1 100644 --- a/writeout.h +++ b/writeout.h @@ -5,23 +5,27 @@ #include 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 -- 2.39.5