From e82cb4b1f88e18f5b9487e49f79b9a091942132f Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Mon, 9 Dec 2013 01:56:06 +0100 Subject: [PATCH] Added writeoutdir sequencing for equal timestamps. --- o815/o815.cpp | 14 +------------- writeout.cpp | 47 +++++++++++++++++++++++++++++++++++++++-------- writeout.h | 4 ++-- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/o815/o815.cpp b/o815/o815.cpp index b68a38b..630d680 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -118,19 +118,7 @@ void o815::postParaInit() { exit(0); } - if(rank==0) { - timestamp = time(NULL); -#ifndef MPI_DISABLED - for(int idest=1; idest0) - MPI_Recv(×tamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, MPI_STATUS_IGNORE); -#endif - - out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp); + out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs); } void o815::mainLoop() { diff --git a/writeout.cpp b/writeout.cpp index af67fb5..9fc40f5 100644 --- a/writeout.cpp +++ b/writeout.cpp @@ -10,15 +10,15 @@ #include #include #include +#include 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) { @@ -42,8 +42,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; @@ -51,10 +54,38 @@ writeout::writeout(const string& wdir, const string& _signature, if(wdir != ""){ numprocs = procs; sprintf(cRank, "%d", rank); - fulldir = wdir + "/" + tstamp(timestamp) + "_" + signature + ".tmp"; - mkdir(fulldir.c_str(), 0775); + 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() ) { diff --git a/writeout.h b/writeout.h index 67c07c8..fc48c16 100644 --- a/writeout.h +++ b/writeout.h @@ -11,7 +11,7 @@ class writeout { public: writeout(const string& wdir, const string& signature, - const int& rank, const int& procs, const long& timestamp=0); + const int& rank, const int& procs); void newsub(string subname); map out; ostream *log; @@ -25,11 +25,11 @@ class writeout string fulldir; char cRank[20]; int rank; - string tstamp(const long& timestamp); int numprocs; string getdatfile(string subname); string timestring(); string signature; + static string longToStr (long arg); }; #endif -- 2.39.5