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)
--- /dev/null
+CMakeFiles
+cmake_install
+libo815.a
+Makefile
--- /dev/null
+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)
--- /dev/null
+#include "o815.h"
+
+#include <sstream>
+
+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; idest<numprocs; idest++)
+ MPI_Send(×tamp, 1, MPI_LONG, idest, 123, MPI_COMM_WORLD);
+ }
+ else if(rank>0)
+ 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; pos<strlen(listarg); pos++ )
+ if( listarg[pos] == ':' ) nargs++;
+
+ if(nargs==0)
+ for(int i=0; i<tlen; i++) target[i] = atoi(listarg);
+ else
+ {
+ target[0] = atoi(strtok(listarg, ":"));
+ for(int i=0; i<nargs; i++)
+ target[i+1] = atoi(strtok(NULL, ":"));
+ }
+}
+
+string o815::headMaster()
+{
+ stringstream hm;
+
+ hm << "-L" << comargs.lsize[0] << "_" << comargs.lsize[1] << "-E" << comargs.nequi << "-S" << comargs.nskip << "-N" << comargs.nmeas
+ << paraQ->rangeString();
+
+ return hm.str();
+}
+
--- /dev/null
+#ifndef O815_H
+#define O815_H
+
+#include <string>
+#include <vector>
+#include <mpi.h>
+#include <stdlib.h>
+
+#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<string,int> obscache;
+ pair<string,int> confcache;
+ string outdir;
+ bool idonly;
+ bool showjobnum;
+ } comargs;
+
+ o815(int argc, char **argv, const string& programid);
+ paraq *paraQ;
+ writeout *out;
+ vector<obs*> 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
--- /dev/null
+#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;
+}
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);
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);
}
writeout::~writeout()
{
- if(fulldir != "")
- {
- if( cRank[0] == '0' )
- {
- int jobsdone=0;
- while(jobsdone<numprocs-1)
- {
- string nextfile;
- if( (nextfile=getdatfile()) == "" ) sleep(1);
- else
- {
- logf << "collecting " << nextfile << endl;
-
- ifstream myfile( (fulldir + "/" + nextfile).c_str() );
- while(true){
- string line;
- getline(myfile, line);
- if( !myfile.good() ) break;
- of << line << endl << flush;
- }
- myfile.close();
- remove( (fulldir + "/" + nextfile).c_str() );
- jobsdone++;
- }
+ if(fulldir != "") {
+ for (map<string,ofstream*>::iterator ofit = of.begin(); ofit != of.end(); ++ofit) {
+ if( cRank[0] == '0' ) {
+ int jobsdone=0;
+ while(jobsdone<numprocs-1) {
+ string nextfile;
+ if( (nextfile = getdatfile(ofit->first)) == "" )
+ 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;
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 "";
#include <ostream>
#include <fstream>
+#include <map>
using namespace std;
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<string,ostream*> out;
ostream *log;
~writeout();
private:
- ofstream of;
+ map<string,ofstream*> of;
+ map<string,streambuf*> 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