]> git.treefish.org Git - phys/latlib.git/blobdiff - writeout.cpp
Let outdir be created from rank 0.
[phys/latlib.git] / writeout.cpp
index af67fb5fc913dfa9032aea8df877578e646007b4..e10a9d446da6e4db3e0109a0628239b4ceaa54bc 100644 (file)
@@ -11,6 +11,8 @@
 #include <errno.h>
 #include <unistd.h>
 
 #include <errno.h>
 #include <unistd.h>
 
+#include <boost/filesystem.hpp>
+
 using namespace std;
 
 string writeout::tstamp(const long& timestamp)
 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";
 
     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() );
 
 
     logf.open( (fulldir + "/rank" + cRank + ".log").c_str() );