X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/f2373be314dc298d602b1939cde3d5ae990dd07f..f6dad6a4230bed002b51de0ec8ff34410bac27ec:/writeout.cpp?ds=inline diff --git a/writeout.cpp b/writeout.cpp index 966559d..e10a9d4 100644 --- a/writeout.cpp +++ b/writeout.cpp @@ -11,6 +11,8 @@ #include #include +#include + using namespace std; string writeout::tstamp(const long& timestamp) @@ -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,12 +94,9 @@ writeout::~writeout() { if(fulldir != "") { for (map::iterator ofit = of.begin(); ofit != of.end(); ++ofit) { - 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); @@ -131,11 +137,9 @@ 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; + closedir(dp); return ""; } @@ -143,14 +147,13 @@ string writeout::getdatfile(string subname) { myfile = string(dirp->d_name); - 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; + closedir(dp); return myfile; } } + closedir(dp); return ""; }