X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/f2373be314dc298d602b1939cde3d5ae990dd07f..e34773ccb43eefc86dc814b768af85da2873e5ef:/writeout.cpp diff --git a/writeout.cpp b/writeout.cpp index 966559d..41dcdf5 100644 --- a/writeout.cpp +++ b/writeout.cpp @@ -11,14 +11,17 @@ #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) { @@ -42,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; @@ -51,10 +57,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() ) { @@ -85,12 +119,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 +162,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 +172,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 ""; }