X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/3db2602cfe30c61445e89cc334541ebb4ff76ed8..f6dad6a4230bed002b51de0ec8ff34410bac27ec:/writeout.cpp?ds=inline diff --git a/writeout.cpp b/writeout.cpp index 7834d6b..e10a9d4 100644 --- a/writeout.cpp +++ b/writeout.cpp @@ -11,6 +11,8 @@ #include #include +#include + using namespace std; string writeout::tstamp(const long& timestamp) @@ -22,7 +24,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() ); @@ -53,7 +55,14 @@ writeout::writeout(const string& wdir, const string& _signature, sprintf(cRank, "%d", rank); fulldir = wdir + "/" + tstamp(timestamp) + "_" + signature + ".tmp"; - mkdir(fulldir.c_str(), 0775); + if (rank==0) + mkdir(fulldir.c_str(), 0775); + else { + while ( ! ( boost::filesystem::exists(fulldir) && boost::filesystem::is_directory(fulldir) ) ) { + cerr << "WRITOUT: Waiting for rank 0 to create out directory." << endl << flush; + sleep(1); + } + } logf.open( (fulldir + "/rank" + cRank + ".log").c_str() ); @@ -85,7 +94,7 @@ writeout::~writeout() { if(fulldir != "") { for (map::iterator ofit = of.begin(); ofit != of.end(); ++ofit) { - if( cRank[0] == '0' ) { + if( cRank[0] == '0' ) { int jobsdone=0; while(jobsdonesecond << "#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(); @@ -129,16 +139,21 @@ string writeout::getdatfile(string subname) if((dp = opendir(fulldir.c_str())) == NULL) { logf << "Error(" << errno << ") opening " << fulldir << endl; + closedir(dp); return ""; } 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" && + subname == myfile.substr( myfile.find("-")+1, myfile.rfind(".")-myfile.find("-")-1 ) ) { + closedir(dp); return myfile; } } + closedir(dp); return ""; }