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