-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathvnoc_main.cpp
121 lines (94 loc) · 3.66 KB
/
vnoc_main.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
////////////////////////////////////////////////////////////////////////////////
//
// VNOC: versatile network on chip simulator. Version 2.0
//
////////////////////////////////////////////////////////////////////////////////
#include "vnoc_topology.h"
#include "vnoc_event.h"
#include "vnoc_gui.h"
#include "vnoc.h"
#include <sys/param.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
using namespace std;
////////////////////////////////////////////////////////////////////////////////
//
// launching point;
//
////////////////////////////////////////////////////////////////////////////////
int main( int argc, char *argv[])
{
// welcome;
char welcome[] =
"\n--------------------------------------------------\n"
"VNOC: Versatile NOC Simulator, Version 2.0 \n"
"Cristinel Ababei, Compiled "__DATE__" \n"
"--------------------------------------------------\n";
printf("%s", welcome);
// (1) runtime;
// cpu time: method 1;
clock_t start_clock, end_clock;
clock_t diff_clock;
start_clock = clock();
assert(start_clock != (clock_t)(-1));
// cpu time: method 2;
//struct tms t1, t2;
//times(&t1);
// wall clock;
timeval start_wall, end_wall; // sec and microsec;
gettimeofday( &start_wall, 0);
// (2) create topology object; some minimal sanity checks;
TOPOLOGY topology( argc, argv);
// create queue object, which is the primary engine of running the
// event-driven simulation;
EVENT_QUEUE event_queue( 0.0, &topology); // start time = 0.0;
// create network's host; also open the main trace file where in
// addition an event type PE is added to the simulation-queue,
// which will kick of the simulation and insertion of additional
// events PE later on;
VNOC vnoc( &topology, &event_queue, topology.verbose());
event_queue.set_vnoc( &vnoc);
// insert an event type ROUTER into simulation-queue, which will
// help kick of the simulation and insertion of additional
// events ROUTER later on;
event_queue.insert_initial_events();
GUI_GRAPHICS gui( &topology, &vnoc);
vnoc.set_gui( &gui); // innitially gui is empty;
if ( topology.use_gui()) { // if user asked to use the gui;
// mark flag that we are gonna use the gui; set is_gui_usable
// and wait_for_user_input_automode; then build;
gui.set_graphics_state( true, 1);
gui.build();
gui.init_draw_coords( 100.0, 100.0);
} else { // gui is not usable;
gui.set_graphics_state( false, 1);
}
// (3) run VNOC simulator;
vnoc.run_simulation();
// entertain user;
printf("\n\nRESULTS SUMMARY:\n================\n");
vnoc.update_and_print_simulation_results();
vnoc.compute_and_print_prediction_stats();
// (4) runtime: cpu and wall times;
// cpu time: method 1;
end_clock = clock();
assert(end_clock != (clock_t)(-1));
diff_clock = end_clock - start_clock;
printf("\n\n vnoc total cputime = %.3f sec\n",
(double)diff_clock/CLOCKS_PER_SEC); // (processor time, clock())
// cpu time: method 2;
//times(&t2);
//printf("vnoc total cputime = %.3f sec\n",
// (double)(t2.tms_utime-t1.tms_utime)/HZ); // (processor time, tms)
// wall clock;
gettimeofday( &end_wall, 0);
double diff_sec_usec = end_wall.tv_sec - start_wall.tv_sec +
double(end_wall.tv_usec - start_wall.tv_usec) / 1000000.0;
printf (" vnoc total walltime = %.3f sec\n\n", diff_sec_usec); // (wall clock time)
// (5) clean-up;
if ( gui.is_gui_usable()) {
gui.close_graphics(); // close down X Display
}
}