X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/40171a80594f79b137900fae122a2e33a3a88f95..f6dad6a4230bed002b51de0ec8ff34410bac27ec:/writeout.cpp?ds=inline diff --git a/writeout.cpp b/writeout.cpp index 03423c5..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() ); @@ -130,6 +139,7 @@ string writeout::getdatfile(string subname) if((dp = opendir(fulldir.c_str())) == NULL) { logf << "Error(" << errno << ") opening " << fulldir << endl; + closedir(dp); return ""; } @@ -139,9 +149,11 @@ string writeout::getdatfile(string subname) 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 ""; }