summaryrefslogtreecommitdiff
path: root/core/simulate.cpp
blob: 720530836b850437f4f89ea6f1837bac4b4ca240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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