X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/f6dad6a4230bed002b51de0ec8ff34410bac27ec..e34773ccb43eefc86dc814b768af85da2873e5ef:/writeout.cpp diff --git a/writeout.cpp b/writeout.cpp index e10a9d4..41dcdf5 100644 --- a/writeout.cpp +++ b/writeout.cpp @@ -11,16 +11,17 @@ #include #include -#include +#ifndef MPI_DISABLED +#include +#endif using namespace std; -string writeout::tstamp(const long& timestamp) +string writeout::longToStr (long arg) { - stringstream sstr; - if(!timestamp) sstr << time (NULL); - else sstr << timestamp; - return sstr.str(); + stringstream ss; + ss << arg; + return ss.str(); } void writeout::newsub(string subname) { @@ -44,8 +45,11 @@ void writeout::newsub(string subname) { } writeout::writeout(const string& wdir, const string& _signature, - const int& _rank, const int& procs, const long& timestamp) + const int& _rank, const int& procs) { + long timestamp; + int iseq=0; + fulldir = ""; signature = _signature; rank = _rank; @@ -53,17 +57,38 @@ writeout::writeout(const string& wdir, const string& _signature, if(wdir != ""){ numprocs = procs; sprintf(cRank, "%d", rank); - fulldir = wdir + "/" + tstamp(timestamp) + "_" + signature + ".tmp"; - - 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); + + if (rank == 0) { + timestamp = time(NULL); + + while (true) { + fulldir = wdir + "/" + longToStr(timestamp) + "." + longToStr(iseq) + "_" + signature + ".tmp"; + if ( mkdir(fulldir.c_str(), 0775) == 0 ) + break; + else if ( errno != EEXIST ) { + cerr << "WRITEOUT: Could not create outdir!" << endl << flush; + break; + } + iseq++; } + +#ifndef MPI_DISABLED + for(int idest=1; idest0) { + MPI_Recv(×tamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Recv(&iseq, 1, MPI_LONG, 0, 124, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + fulldir = wdir + "/" + longToStr(timestamp) + "." + longToStr(iseq) + "_" + signature + ".tmp"; + } +#endif + logf.open( (fulldir + "/rank" + cRank + ".log").c_str() ); if ( !logf.is_open() ) {