From 3db2602cfe30c61445e89cc334541ebb4ff76ed8 Mon Sep 17 00:00:00 2001 From: Alex Schmidt Date: Tue, 16 Apr 2013 12:22:31 +0200 Subject: [PATCH] added o815 --- CMakeLists.txt | 4 +- o815/.gitignore | 4 ++ o815/CMakeLists.txt | 13 +++++ o815/o815.cpp | 123 ++++++++++++++++++++++++++++++++++++++++++++ o815/o815.h | 60 +++++++++++++++++++++ o815/obs.cpp | 26 ++++++++++ writeout.cpp | 109 ++++++++++++++++++++++----------------- writeout.h | 12 +++-- 8 files changed, 299 insertions(+), 52 deletions(-) create mode 100644 o815/.gitignore create mode 100644 o815/CMakeLists.txt create mode 100644 o815/o815.cpp create mode 100644 o815/o815.h create mode 100644 o815/obs.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c421ce..ba307ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,4 +32,6 @@ add_executable(culooks_test culooks_test.cpp) target_link_libraries(culooks_test lat_culooks) add_executable(hypercache_test hypercache_test.cpp) -target_link_libraries(hypercache_test lat_hypercache) \ No newline at end of file +target_link_libraries(hypercache_test lat_hypercache) + +add_subdirectory(o815) diff --git a/o815/.gitignore b/o815/.gitignore new file mode 100644 index 0000000..6bdb794 --- /dev/null +++ b/o815/.gitignore @@ -0,0 +1,4 @@ +CMakeFiles +cmake_install +libo815.a +Makefile diff --git a/o815/CMakeLists.txt b/o815/CMakeLists.txt new file mode 100644 index 0000000..8431e25 --- /dev/null +++ b/o815/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 2.8) + +project(o815) + +find_package(MPI REQUIRED) +set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) +set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS}) +include_directories(${MPI_INCLUDE_PATH} ../) + +SET(CMAKE_BUILD_TYPE Release) + +add_library(o815 o815.cpp obs.cpp) +target_link_libraries(o815 ${MPI_LIBRARIES} lat_paraq lat_writeout) diff --git a/o815/o815.cpp b/o815/o815.cpp new file mode 100644 index 0000000..956eb09 --- /dev/null +++ b/o815/o815.cpp @@ -0,0 +1,123 @@ +#include "o815.h" + +#include + +o815::o815(int argc, char **argv, const string& _programid) { + long timestamp; + + programid = _programid; + + comargs.nmeas = 100; + comargs.nskip = 10; + comargs.nequi = 100; + comargs.lsize[0] = 4; + comargs.lsize[1] = 4; + comargs.obscache = make_pair("",0); + comargs.confcache = make_pair("",0); + comargs.outdir=""; + comargs.idonly = false; + comargs.showjobnum = false; + + MPI_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &numprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + paraQ = new paraq(numprocs, rank); + + parseArgs(argc, argv); + + if(comargs.idonly) { + cout << programid << headMaster() << endl << flush; + exit(0); + } + + if( comargs.showjobnum ) { + for( int i=1; i<=paraQ->getTotalJobs(); i++ ) { + if( paraQ->getTotalJobs()%i == 0 ) cout << paraQ->getTotalJobs()/i << "@" << i << " "; + } + cout << endl; + exit(0); + } + + if(rank==0) { + timestamp = time(NULL); + for(int idest=1; idest0) + MPI_Recv(×tamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, &mpiStatus); + + out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp); +} + +void o815::parseArgs(int argc, char **argv) { + int opt = 0; + + while( (opt = getopt(argc, argv, "L:N:S:E:o:O:c:C:w:i:j:")) != -1 ) + switch(opt) { + case 'L': + listArg(comargs.lsize, 2, optarg); + break; + case 'N': + comargs.nmeas = atoi(optarg); + break; + case 'S': + comargs.nskip = atoi(optarg); + break; + case 'E': + comargs.nequi = atoi(optarg); + break; + case 'o': + comargs.obscache.first = optarg; + comargs.obscache.second = 1; + break; + case 'O': + comargs.obscache.first = optarg; + comargs.obscache.second = 2; + break; + case 'c': + comargs.confcache.first = optarg; + comargs.confcache.second = 1; + break; + case 'C': + comargs.confcache.first = optarg; + comargs.confcache.second = 2; + break; + case 'w': + comargs.outdir = optarg; + break; + case 'i': + comargs.idonly = atoi(optarg); + break; + case 'j': + comargs.showjobnum = atoi(optarg); + break; + } +} + +void o815::listArg(int *target, int tlen, char *listarg) { + int nargs=0; + + for( int pos=0; posrangeString(); + + return hm.str(); +} + diff --git a/o815/o815.h b/o815/o815.h new file mode 100644 index 0000000..31d36da --- /dev/null +++ b/o815/o815.h @@ -0,0 +1,60 @@ +#ifndef O815_H +#define O815_H + +#include +#include +#include +#include + +#include "latlib/paraq.h" +#include "latlib/writeout.h" + +using namespace std; + +class obs; + +class o815 { + public: + class obs { + public: + obs(const string& obsid, o815 *_O815); + void finish(); + void meas(); + private: + virtual void _meas(bool loadedobs)=0; + virtual void _finish()=0; + protected: + o815 *O815; + char *obsMem; + ostream *oout; + ostream *olog; + string obsid; + }; + + struct { + int nmeas; + int nskip; + int nequi; + int lsize[2]; + pair obscache; + pair confcache; + string outdir; + bool idonly; + bool showjobnum; + } comargs; + + o815(int argc, char **argv, const string& programid); + paraq *paraQ; + writeout *out; + vector observables; + +private: + MPI_Status mpiStatus; + int numprocs, rank; + static void listArg(int *target, int tlen, char *listarg); + void parseArgs(int argc, char **argv); + string programid; + string headMaster(); +}; + +#endif diff --git a/o815/obs.cpp b/o815/obs.cpp new file mode 100644 index 0000000..cd86bf6 --- /dev/null +++ b/o815/obs.cpp @@ -0,0 +1,26 @@ +#include "o815.h" + +void o815::obs::_meas(bool loadedobs) { + *olog << "OBS_" << obsid << ": meas not implemented!" << endl << flush; +}; + +void o815::obs::_finish() { + *olog << "OBS_" << obsid << ": finish not implemented!" << endl << flush; +}; + +void o815::obs::finish() { + _finish(); +} + +void o815::obs::meas() { + _meas(true); +} + +o815::obs::obs(const string& _obsid, o815 *_O815) { + obsid = _obsid; + O815 = _O815; + + O815->out->newsub(obsid); + oout = O815->out->out[obsid]; + olog = O815->out->log; +} diff --git a/writeout.cpp b/writeout.cpp index 3849ac9..7834d6b 100644 --- a/writeout.cpp +++ b/writeout.cpp @@ -21,9 +21,33 @@ string writeout::tstamp(const long& timestamp) return sstr.str(); } -writeout::writeout(const string& wdir, const string& signature, - const int& rank, const int& procs, const long& timestamp) +void writeout::newsub(string subname) { + of[subname] = new ofstream; + + if ( fulldir != "" ) { + if(rank>0) of[subname]->open( (fulldir + "/rank" + cRank + "-" + subname + ".tmp").c_str() ); + else of[subname]->open( (fulldir + "/" + signature + "-" + subname + ".dat").c_str() ); + + if ( !of[subname]->is_open() ) { + logf << "WRITEOUT: Could not open output-file!" << endl << flush; + exit(1); + } + + buf[subname] = of[subname]->rdbuf(); + } + else + buf[subname] = cout.rdbuf(); + + out[subname] = new ostream(buf[subname]); +} + +writeout::writeout(const string& wdir, const string& _signature, + const int& _rank, const int& procs, const long& timestamp) { + fulldir = ""; + signature = _signature; + rank = _rank; + if(wdir != ""){ numprocs = procs; sprintf(cRank, "%d", rank); @@ -31,28 +55,20 @@ writeout::writeout(const string& wdir, const string& signature, mkdir(fulldir.c_str(), 0775); - if(rank>0) of.open( (fulldir + "/rank" + cRank + ".tmp").c_str() ); - else of.open( (fulldir + "/" + signature + ".dat").c_str() ); - logf.open( (fulldir + "/rank" + cRank + ".log").c_str() ); - if ( (!of.is_open()) || (!logf.is_open()) ) { - cerr << "WRITEOUT: Could not open output- and/or log-file!" << endl << flush; + if ( !logf.is_open() ) { + cerr << "WRITEOUT: Could not open log-file!" << endl << flush; exit(1); } logf << "[ " << timestring() << " ] Log starts here." << endl; - buf = of.rdbuf(); logbuf = logf.rdbuf(); - - cout << buf << endl; } else{ - buf = cout.rdbuf(); logbuf = cerr.rdbuf(); } - out = new ostream(buf); log = new ostream(logbuf); } @@ -67,47 +83,45 @@ string writeout::timestring() writeout::~writeout() { - if(fulldir != "") - { - if( cRank[0] == '0' ) - { - int jobsdone=0; - while(jobsdone::iterator ofit = of.begin(); ofit != of.end(); ++ofit) { + if( cRank[0] == '0' ) { + int jobsdone=0; + while(jobsdonefirst)) == "" ) + sleep(1); + else { + logf << "collecting " << nextfile << endl; + + ifstream myfile( (fulldir + "/" + nextfile).c_str() ); + while(true) { + string line; + getline(myfile, line); + if( !myfile.good() ) break; + *ofit->second << line << endl << flush; } - of << "#end" << endl << flush; - of.close(); - rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() ); - } - else - { - of.close(); - rename((fulldir + "/rank" + cRank + ".tmp").c_str(), - (fulldir + "/rank" + cRank + ".part").c_str()); + myfile.close(); + remove( (fulldir + "/" + nextfile).c_str() ); + jobsdone++; + } } + *ofit->second << "#end" << endl << flush; + ofit->second->close(); + rename( fulldir.c_str(), fulldir.substr(0, fulldir.length()-4).c_str() ); + } + else { + ofit->second->close(); + rename((fulldir + "/rank" + cRank + ".tmp").c_str(), + (fulldir + "/rank" + cRank + ".part").c_str()); + } } + } logf << "[ " << timestring() << " ] Log ends here." << endl; logf.close(); } -string writeout::getdatfile() +string writeout::getdatfile(string subname) { string myfile; DIR *dp; @@ -121,8 +135,9 @@ string writeout::getdatfile() while ((dirp = readdir(dp)) != NULL) { myfile = string(dirp->d_name); - if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part") + if(myfile.length() > 3 && myfile.substr(myfile.length()-4) == "part") { return myfile; + } } return ""; diff --git a/writeout.h b/writeout.h index e7c3ea1..67c07c8 100644 --- a/writeout.h +++ b/writeout.h @@ -3,6 +3,7 @@ #include #include +#include using namespace std; @@ -11,21 +12,24 @@ class writeout public: writeout(const string& wdir, const string& signature, const int& rank, const int& procs, const long& timestamp=0); - ostream *out; + void newsub(string subname); + map out; ostream *log; ~writeout(); private: - ofstream of; + map of; + map buf; ofstream logf; - streambuf *buf; streambuf *logbuf; string fulldir; char cRank[20]; + int rank; string tstamp(const long& timestamp); int numprocs; - string getdatfile(); + string getdatfile(string subname); string timestring(); + string signature; }; #endif -- 2.39.5