|
1 | 1 | #include "levelgraph.hpp" |
| 2 | +#include <CLI11.hpp> |
2 | 3 |
|
3 | 4 | int main(int argc, char* argv[]) { |
4 | 5 |
|
5 | | - unsigned num_threads = std::thread::hardware_concurrency(); |
| 6 | + CLI::App app{"Wavefront"}; |
| 7 | + |
| 8 | + unsigned num_threads {1}; |
| 9 | + app.add_option("-t,--num_threads", num_threads, "number of threads (default=1)"); |
| 10 | + |
| 11 | + unsigned num_rounds {1}; |
| 12 | + app.add_option("-r,--num_rounds", num_rounds, "number of rounds (default=1)"); |
| 13 | + |
| 14 | + std::string model = "tf"; |
| 15 | + app.add_option("-m,--model", model, "model name tbb|omp|tf (default=tf)") |
| 16 | + ->check([] (const std::string& m) { |
| 17 | + if(m != "tbb" && m != "omp" && m != "tf") { |
| 18 | + return "model name should be \"tbb\", \"omp\", or \"tf\""; |
| 19 | + } |
| 20 | + return ""; |
| 21 | + }); |
| 22 | + |
| 23 | + CLI11_PARSE(app, argc, argv); |
| 24 | + |
| 25 | + std::cout << "model=" << model << ' ' |
| 26 | + << "num_threads=" << num_threads << ' ' |
| 27 | + << "num_rounds=" << num_rounds << ' ' |
| 28 | + << std::endl; |
6 | 29 |
|
7 | | - if(argc > 1) { |
8 | | - num_threads = std::atoi(argv[1]); |
9 | | - } |
10 | 30 |
|
11 | 31 | const int width {12}; |
12 | | - const int rounds {5}; |
13 | 32 | const int repeat [] = {1, 5, 10, 100}; |
14 | 33 |
|
15 | 34 | std::cout << std::setw(width) << "|V|+|E|" |
16 | | - << std::setw(width) << "Repeat" |
17 | | - << std::setw(width) << "OMP" |
18 | | - << std::setw(width) << "TBB" |
19 | | - << std::setw(width) << "TF" |
20 | | - << std::setw(width) << "speedup1" |
21 | | - << std::setw(width) << "speedup2" |
| 35 | + << std::setw(width) << repeat[0] |
| 36 | + << std::setw(width) << repeat[1] |
| 37 | + << std::setw(width) << repeat[2] |
| 38 | + << std::setw(width) << repeat[3] |
22 | 39 | << '\n'; |
23 | | - std::cout << std::string(100, '=') << std::endl; |
24 | 40 |
|
25 | 41 | std::cout.precision(3); |
26 | 42 |
|
27 | | - const std::string line (100, '-'); |
28 | | - |
29 | 43 | for(int i=1; i<=451; i += 15) { |
30 | | - |
31 | 44 | for(int k=0; k<4; k++) { |
32 | | - double omp_time {0.0}; |
33 | | - double tbb_time {0.0}; |
34 | | - double tf_time {0.0}; |
| 45 | + double runtime {0.0}; |
35 | 46 |
|
36 | 47 | LevelGraph graph(i, i); |
37 | 48 |
|
38 | 49 | if(k == 0) { |
39 | 50 | std::cout << std::setw(width) << graph.graph_size(); |
40 | 51 | } |
41 | | - else { |
42 | | - std::cout << std::setw(width) << " "; |
43 | | - } |
44 | 52 |
|
45 | | - for(int j=0; j<rounds; ++j) { |
46 | | - omp_time += measure_time_omp(graph, num_threads, repeat[k]).count(); |
47 | | - |
48 | | - tbb_time += measure_time_tbb(graph, num_threads, repeat[k]).count(); |
49 | | - |
50 | | - tf_time += measure_time_taskflow(graph, num_threads, repeat[k]).count(); |
| 53 | + for(unsigned j=0; j<num_rounds; ++j) { |
| 54 | + if(model == "tf") { |
| 55 | + runtime += measure_time_taskflow(graph, num_threads, repeat[k]).count(); |
| 56 | + } |
| 57 | + else if(model == "tbb") { |
| 58 | + runtime += measure_time_tbb(graph, num_threads, repeat[k]).count(); |
| 59 | + } |
| 60 | + else if(model == "omp") { |
| 61 | + runtime += measure_time_omp(graph, num_threads, repeat[k]).count(); |
| 62 | + } |
| 63 | + else assert(false); |
51 | 64 | } |
52 | 65 |
|
53 | | - std::cout << std::setw(width) << repeat[k] << std::fixed |
54 | | - << std::setw(width) << omp_time / rounds / 1e3 << std::fixed |
55 | | - << std::setw(width) << tbb_time / rounds / 1e3 << std::fixed |
56 | | - << std::setw(width) << tf_time / rounds / 1e3 << std::fixed |
57 | | - << std::setw(width) << omp_time / tf_time << std::fixed |
58 | | - << std::setw(width) << tbb_time / tf_time << std::fixed |
59 | | - << std::endl; |
| 66 | + std::cout << std::setw(width) << runtime / num_rounds / 1e3 << std::fixed; |
60 | 67 | } |
61 | | - std::cout << line << std::endl; |
| 68 | + std::cout << std::endl; |
62 | 69 | } |
| 70 | + |
63 | 71 | } |
64 | 72 |
|
65 | 73 |
|
0 commit comments