From: Alex Schmidt Date: Mon, 15 Oct 2012 16:39:18 +0000 (+0200) Subject: ... X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/931c993776aa8bc41f11d6d676a894324d73a1a3?hp=3eb3a1c16cd9d9f76a21d29194301cd69f77eca6 ... --- 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