|
| 1 | +#include "data_pipeline.hpp" |
| 2 | +#include <CLI11.hpp> |
| 3 | + |
| 4 | +int main(int argc, char* argv[]) { |
| 5 | + |
| 6 | + CLI::App app{"Parallel DataPipeline"}; |
| 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|tf (default=tf)") |
| 16 | + ->check([] (const std::string& m) { |
| 17 | + if(m != "tbb" && m != "tf") { |
| 18 | + return "model name should be \"tbb\" or \"tf\""; |
| 19 | + } |
| 20 | + return ""; |
| 21 | + }); |
| 22 | + |
| 23 | + unsigned num_lines {8}; |
| 24 | + app.add_option("-l,--num_lines", num_lines, "num of lines (default=8)"); |
| 25 | + |
| 26 | + std::string pipes = "ssssssss"; |
| 27 | + app.add_option("-p,--pipes", pipes, "the chain of pipes (default=ssssssss)") |
| 28 | + ->check([pipes] (const std::string& p) { |
| 29 | + if (p[0] == 'p') { |
| 30 | + return "the first pipe should be \"s\" (serial)"; |
| 31 | + } |
| 32 | + else if (p.size() > 16) { |
| 33 | + return "no more than 16 pipes"; |
| 34 | + } |
| 35 | + else if (p.size() == 0) { |
| 36 | + return "at least one pipe is required"; |
| 37 | + } |
| 38 | + return ""; |
| 39 | + }); |
| 40 | + |
| 41 | + CLI11_PARSE(app, argc, argv); |
| 42 | + |
| 43 | + std::cout << "model=" << model << ' ' |
| 44 | + << "num_threads=" << num_threads << ' ' |
| 45 | + << "num_rounds=" << num_rounds << ' ' |
| 46 | + << "num_lines=" << num_lines << ' ' |
| 47 | + << "pipes=" << pipes << ' ' |
| 48 | + << std::endl; |
| 49 | + |
| 50 | + std::cout << std::setw(12) << "size" |
| 51 | + << std::setw(12) << "Runtime" |
| 52 | + << '\n'; |
| 53 | + |
| 54 | + size_t log_length = 23; |
| 55 | + |
| 56 | + for(size_t i = 1; i <= log_length; ++i) { |
| 57 | + |
| 58 | + size_t L = 1 << i; |
| 59 | + |
| 60 | + double runtime {0.0}; |
| 61 | + |
| 62 | + for(unsigned j = 0; j < num_rounds; ++j) { |
| 63 | + if(model == "tf") { |
| 64 | + runtime += measure_time_taskflow(pipes, num_lines, num_threads, L).count(); |
| 65 | + } |
| 66 | + else if(model == "tbb") { |
| 67 | + runtime += measure_time_tbb(pipes, num_lines, num_threads, L).count(); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + std::cout << std::setw(12) << L |
| 72 | + << std::setw(12) << runtime / num_rounds / 1e3 |
| 73 | + << std::endl; |
| 74 | + |
| 75 | + /*if (model == "tf") { |
| 76 | + std::ofstream outputfile; |
| 77 | + outputfile.open("./tf_time.csv", std::ofstream::app); |
| 78 | + outputfile << num_threads << ',' |
| 79 | + << num_lines << ',' |
| 80 | + << pipes << ',' |
| 81 | + << L << ',' |
| 82 | + << runtime / num_rounds / 1e3 << '\n'; |
| 83 | +
|
| 84 | + outputfile.close(); |
| 85 | + } |
| 86 | + else if (model == "tbb") { |
| 87 | + std::ofstream outputfile; |
| 88 | + outputfile.open("./tbb_time.csv", std::ofstream::app); |
| 89 | + outputfile << num_threads << ',' |
| 90 | + << num_lines << ',' |
| 91 | + << pipes << ',' |
| 92 | + << L << ',' |
| 93 | + << runtime / num_rounds / 1e3 << '\n'; |
| 94 | +
|
| 95 | + outputfile.close(); |
| 96 | + }*/ |
| 97 | + } |
| 98 | +} |
0 commit comments