From f2373be314dc298d602b1939cde3d5ae990dd07f Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Tue, 16 Apr 2013 16:39:57 +0200 Subject: [PATCH] ... --- o815/o815.cpp | 30 ++++++++++++++++++++++++++++++ o815/o815.h | 12 +++++++++--- o815/obs.cpp | 23 ++++++++++++++--------- writeout.cpp | 24 ++++++++++++++++++------ 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/o815/o815.cpp b/o815/o815.cpp index 956eb09..a2b35e8 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -50,6 +50,24 @@ o815::o815(int argc, char **argv, const string& _programid) { out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp); } +void o815::mainLoop() { + for (vector::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { + (*obsit)->start(); + } + + for (int i=0; i<100; i++) { + for (vector::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { + (*obsit)->meas(); + } + } + + for (vector::iterator obsit = observables.begin(); obsit != observables.end(); ++obsit) { + (*obsit)->finish(); + } + + //MPI_Finalize(); +} + void o815::parseArgs(int argc, char **argv) { int opt = 0; @@ -121,3 +139,15 @@ string o815::headMaster() return hm.str(); } +o815::~o815() { + if(comargs.outdir=="") { + MPI_Barrier(MPI_COMM_WORLD); + if(rank==0) + cout << "#end" << endl << flush; + } + + cout << "bu:" << rank << endl; + + delete out; + MPI_Finalize(); +} diff --git a/o815/o815.h b/o815/o815.h index 31d36da..932af0f 100644 --- a/o815/o815.h +++ b/o815/o815.h @@ -15,20 +15,24 @@ class obs; class o815 { public: + class obs { public: - obs(const string& obsid, o815 *_O815); + obs(const string& _obsid, const string& _datadesc, o815 *_O815); void finish(); void meas(); + void start(); + string getDataDesc() { return datadesc; }; private: virtual void _meas(bool loadedobs)=0; virtual void _finish()=0; + virtual void _start()=0; protected: o815 *O815; char *obsMem; ostream *oout; ostream *olog; - string obsid; + string obsid, datadesc; }; struct { @@ -44,9 +48,12 @@ class o815 { } comargs; o815(int argc, char **argv, const string& programid); + ~o815(); paraq *paraQ; writeout *out; vector observables; + void mainLoop(); + string headMaster(); private: MPI_Status mpiStatus; @@ -54,7 +61,6 @@ private: 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 index cd86bf6..7cbae77 100644 --- a/o815/obs.cpp +++ b/o815/obs.cpp @@ -1,24 +1,29 @@ #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::start() { + if(O815->rank==0) { + *oout << "#" << obsid << O815->headMaster() << endl << flush; + *oout << "#" << obsid << O815->headMaster() << "-" << datadesc << endl << flush; + } + + if (O815->comargs.outdir=="") + MPI_Barrier(MPI_COMM_WORLD); + + _start(); +} + void o815::obs::meas() { _meas(true); } -o815::obs::obs(const string& _obsid, o815 *_O815) { +o815::obs::obs(const string& _obsid, const string& _datadesc, o815 *_O815) { obsid = _obsid; O815 = _O815; + datadesc = _datadesc; O815->out->newsub(obsid); oout = O815->out->out[obsid]; diff --git a/writeout.cpp b/writeout.cpp index 7834d6b..966559d 100644 --- a/writeout.cpp +++ b/writeout.cpp @@ -22,7 +22,7 @@ string writeout::tstamp(const long& timestamp) } void writeout::newsub(string subname) { - of[subname] = new ofstream; + of[subname] = new ofstream; if ( fulldir != "" ) { if(rank>0) of[subname]->open( (fulldir + "/rank" + cRank + "-" + subname + ".tmp").c_str() ); @@ -85,9 +85,12 @@ writeout::~writeout() { if(fulldir != "") { for (map::iterator ofit = of.begin(); ofit != of.end(); ++ofit) { - if( cRank[0] == '0' ) { + cout << ofit->first << endl; + if( cRank[0] == '0' ) { int jobsdone=0; while(jobsdonefirst << endl; + cout << "here" << endl; string nextfile; if( (nextfile = getdatfile(ofit->first)) == "" ) sleep(1); @@ -108,14 +111,15 @@ writeout::~writeout() } *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()); + rename((fulldir + "/rank" + cRank + "-" + ofit->first + ".tmp").c_str(), + (fulldir + "/rank" + cRank + "-" + ofit->first + ".part").c_str()); } } + if( cRank[0] == '0' ) + rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() ); } logf << "[ " << timestring() << " ] Log ends here." << endl; logf.close(); @@ -127,15 +131,23 @@ string writeout::getdatfile(string subname) DIR *dp; struct dirent *dirp; + cout << "getting:" << subname << endl; + if((dp = opendir(fulldir.c_str())) == NULL) { logf << "Error(" << errno << ") opening " << fulldir << endl; + cout << "blub" << endl; return ""; } while ((dirp = readdir(dp)) != NULL) { myfile = string(dirp->d_name); - if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part") { + + cout << myfile << endl; + + if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part" && + subname == myfile.substr( myfile.find("-")+1, myfile.rfind(".")-myfile.find("-")-1 ) ) { + cout << myfile << endl; return myfile; } } -- 2.39.5