summaryrefslogtreecommitdiff
path: root/core/simulate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/simulate.cpp')
-rw-r--r--core/simulate.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/core/simulate.cpp b/core/simulate.cpp
new file mode 100644
index 0000000..7205308
--- /dev/null
+++ b/core/simulate.cpp
@@ -0,0 +1,77 @@
+#include <boost/mpl/list.hpp>
+#include <boost/mpl/pair.hpp>
+#include <iostream>
+
+#include "everything_else.hpp"
+#include "perftools.hpp"
+#include "signal_handler.hpp"
+#include "sim_loop.hpp"
+
+#include "mempool.hpp"
+
+#include "model.hpp"
+
+using namespace std;
+
+int main(int argc, char **argv) {
+ // init sim env
+ const uint64_t eventsPerChunk = 100000;
+ uint64_t totalEventsProcessed(0);
+ installSigIntHandler();
+ assertSimDir();
+
+ // parse command line args
+ assert(argc == 2);
+ Time until(atof(argv[1]));
+
+ {
+ SimLoop<Lists::all> sim;
+
+ Time startTime(sim.currentTime()), oldTime(startTime);
+ cout << "simulating from " << oldTime()
+ << " to " << until() << endl;
+
+ // run for requested time
+ Timer timerAll;
+ while (oldTime < until && !terminationRequested) {
+ uint64_t eventsProcessed = eventsPerChunk - sim.run(until, eventsPerChunk);
+ totalEventsProcessed += eventsProcessed;
+ Time newTime(sim.currentTime()),
+ dt(newTime - oldTime);
+ cout << "\r\033[K"
+ << newTime() << "\t"
+ << eventsProcessed / dt() << " Hz(v)\t"
+ << totalEventsProcessed / timerAll.diff() << " Hz(p)\t"
+ << totalEventsProcessed << " events\t";
+ if (newTime < until)
+ cout << "ETA " << ceil( (until() - newTime())
+ / (newTime() - startTime())
+ * timerAll.diff());
+ cout << flush;
+ oldTime = newTime;
+ }
+
+ if (terminationRequested) {
+ cout << " ... received SIGINT, terminating" << endl;
+ }else{
+ cout << "\r\033[K";
+ }
+
+ // print summary
+ cout << "simulated " << totalEventsProcessed << " events "
+ << "in " << timerAll.diff() << " s "
+ << "(" << totalEventsProcessed / timerAll.diff() << " Hz(p))"
+ << endl;
+
+ // sync to disk
+ cout << "syncing ... " << flush;
+ Timer timerSync;
+ sim.sync();
+ cout << "done (" << timerSync.diff() << "s)" << endl;
+
+ if (terminationRequested)
+ sigIntExit();
+ }
+
+ return 0;
+}
contact: Jan Huwald // Impressum