| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 28e90f5 commit 61c650d
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -203,9 +203,9 @@ class LevelGraph { | |||
| 203 | 203 | ||
| 204 | 204 | }; | |
| 205 | 205 | ||
| 206 | - std::chrono::microseconds measure_time_taskflow(LevelGraph&); | ||
| 207 | - std::chrono::microseconds measure_time_omp(LevelGraph&); | ||
| 208 | - std::chrono::microseconds measure_time_tbb(LevelGraph&); | ||
| 206 | + std::chrono::microseconds measure_time_taskflow(LevelGraph&, unsigned); | ||
| 207 | + std::chrono::microseconds measure_time_omp(LevelGraph&, unsigned); | ||
| 208 | + std::chrono::microseconds measure_time_tbb(LevelGraph&, unsigned); | ||
| 209 | 209 | ||
| 210 | 210 | ||
| 211 | 211 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,30 +1,36 @@ | |||
| 1 | 1 | #include "levelgraph.hpp" | |
| 2 | 2 | ||
| 3 | - int main() { | ||
| 3 | + int main(int argc, char* argv[]) { | ||
| 4 | + | ||
| 5 | + unsigned num_threads = std::thread::hardware_concurrency(); | ||
| 6 | + | ||
| 7 | + if(argc > 1) { | ||
| 8 | + num_threads = std::atoi(argv[1]); | ||
| 9 | + } | ||
| 4 | 10 | ||
| 5 | 11 | double omp_time {0.0}; | |
| 6 | 12 | double tbb_time {0.0}; | |
| 7 | 13 | double tf_time {0.0}; | |
| 8 | 14 | int rounds {5}; | |
| 9 | - | ||
| 15 | + | ||
| 10 | 16 | std::cout << std::setw(12) << "|V|+|E|" | |
| 11 | 17 | << std::setw(12) << "OpenMP" | |
| 12 | 18 | << std::setw(12) << "TBB" | |
| 13 | 19 | << std::setw(12) << "Taskflow" | |
| 14 | 20 | << std::endl; | |
| 15 | 21 | ||
| 16 | - for(int i=1; i<=401; i += 4) { | ||
| 22 | + for(int i=1; i<=401; i += 10) { | ||
| 17 | 23 | ||
| 18 | 24 | LevelGraph graph(i, i); | |
| 19 | 25 | ||
| 20 | 26 | for(int j=0; j<rounds; ++j) { | |
| 21 | - omp_time += measure_time_omp(graph).count(); | ||
| 27 | + omp_time += measure_time_omp(graph, num_threads).count(); | ||
| 22 | 28 | graph.clear_graph(); | |
| 23 | 29 | ||
| 24 | - tbb_time += measure_time_tbb(graph).count(); | ||
| 30 | + tbb_time += measure_time_tbb(graph, num_threads).count(); | ||
| 25 | 31 | graph.clear_graph(); | |
| 26 | 32 | ||
| 27 | - tf_time += measure_time_taskflow(graph).count(); | ||
| 33 | + tf_time += measure_time_taskflow(graph, num_threads).count(); | ||
| 28 | 34 | graph.clear_graph(); | |
| 29 | 35 | } | |
| 30 | 36 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,9 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | 5 | #include "levelgraph.hpp" | |
| 6 | 6 | ||
| 7 | - void traverse_regular_graph_omp(LevelGraph& graph){ | ||
| 7 | + void traverse_regular_graph_omp(LevelGraph& graph, unsigned num_threads){ | ||
| 8 | 8 | ||
| 9 | - omp_set_num_threads(std::thread::hardware_concurrency()); | ||
| 9 | + omp_set_num_threads(num_threads); | ||
| 10 | 10 | ||
| 11 | 11 | #pragma omp parallel | |
| 12 | 12 | { | |
@@ -262,9 +262,9 @@ void traverse_regular_graph_omp(LevelGraph& graph){ | |||
| 262 | 262 | } | |
| 263 | 263 | } | |
| 264 | 264 | ||
| 265 | - std::chrono::microseconds measure_time_omp(LevelGraph& graph){ | ||
| 265 | + std::chrono::microseconds measure_time_omp(LevelGraph& graph, unsigned num_threads){ | ||
| 266 | 266 | auto beg = std::chrono::high_resolution_clock::now(); | |
| 267 | - traverse_regular_graph_omp(graph); | ||
| 267 | + traverse_regular_graph_omp(graph, num_threads); | ||
| 268 | 268 | auto end = std::chrono::high_resolution_clock::now(); | |
| 269 | 269 | return std::chrono::duration_cast<std::chrono::microseconds>(end - beg); | |
| 270 | 270 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | 7 | struct TF { | |
| 8 | 8 | ||
| 9 | - TF(LevelGraph& graph) { | ||
| 9 | + TF(LevelGraph& graph, unsigned num_threads) : tf {num_threads} { | ||
| 10 | 10 | ||
| 11 | 11 | tasks.resize(graph.level()); | |
| 12 | 12 | for(size_t i=0; i<tasks.size(); ++i) { | |
@@ -38,14 +38,14 @@ struct TF { | |||
| 38 | 38 | ||
| 39 | 39 | }; | |
| 40 | 40 | ||
| 41 | - void traverse_level_graph_taskflow(LevelGraph& graph){ | ||
| 42 | - TF tf(graph); | ||
| 41 | + void traverse_level_graph_taskflow(LevelGraph& graph, unsigned num_threads){ | ||
| 42 | + TF tf(graph, num_threads); | ||
| 43 | 43 | tf.run(); | |
| 44 | 44 | } | |
| 45 | 45 | ||
| 46 | - std::chrono::microseconds measure_time_taskflow(LevelGraph& graph){ | ||
| 46 | + std::chrono::microseconds measure_time_taskflow(LevelGraph& graph, unsigned num_threads){ | ||
| 47 | 47 | auto beg = std::chrono::high_resolution_clock::now(); | |
| 48 | - traverse_level_graph_taskflow(graph); | ||
| 48 | + traverse_level_graph_taskflow(graph, num_threads); | ||
| 49 | 49 | auto end = std::chrono::high_resolution_clock::now(); | |
| 50 | 50 | return std::chrono::duration_cast<std::chrono::microseconds>(end - beg); | |
| 51 | 51 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,9 +11,9 @@ using namespace tbb::flow; | |||
| 11 | 11 | ||
| 12 | 12 | struct TBB { | |
| 13 | 13 | ||
| 14 | - TBB(LevelGraph& graph) { | ||
| 14 | + TBB(LevelGraph& graph, unsigned num_threads) { | ||
| 15 | 15 | ||
| 16 | - tbb::task_scheduler_init init(std::thread::hardware_concurrency()); | ||
| 16 | + tbb::task_scheduler_init init(num_threads); | ||
| 17 | 17 | ||
| 18 | 18 | tasks.resize(graph.level()); | |
| 19 | 19 | for(size_t i=0; i<tasks.size(); ++i) { | |
@@ -60,14 +60,14 @@ struct TBB { | |||
| 60 | 60 | std::unique_ptr<continue_node<continue_msg>> source; | |
| 61 | 61 | }; | |
| 62 | 62 | ||
| 63 | - void traverse_regular_graph_tbb(LevelGraph& graph){ | ||
| 64 | - TBB tbb(graph); | ||
| 63 | + void traverse_regular_graph_tbb(LevelGraph& graph, unsigned num_threads){ | ||
| 64 | + TBB tbb(graph, num_threads); | ||
| 65 | 65 | tbb.run(); | |
| 66 | 66 | } | |
| 67 | 67 | ||
| 68 | - std::chrono::microseconds measure_time_tbb(LevelGraph& graph){ | ||
| 68 | + std::chrono::microseconds measure_time_tbb(LevelGraph& graph, unsigned num_threads){ | ||
| 69 | 69 | auto beg = std::chrono::high_resolution_clock::now(); | |
| 70 | - traverse_regular_graph_tbb(graph); | ||
| 70 | + traverse_regular_graph_tbb(graph, num_threads); | ||
| 71 | 71 | auto end = std::chrono::high_resolution_clock::now(); | |
| 72 | 72 | return std::chrono::duration_cast<std::chrono::microseconds>(end - beg); | |
| 73 | 73 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,12 @@ | |||
| 1 | 1 | #include "matrix.hpp" | |
| 2 | 2 | ||
| 3 | - int main() { | ||
| 3 | + int main(int argc, char* argv[]) { | ||
| 4 | + | ||
| 5 | + unsigned num_threads = std::thread::hardware_concurrency(); | ||
| 6 | + | ||
| 7 | + if(argc > 1) { | ||
| 8 | + num_threads = std::atoi(argv[1]); | ||
| 9 | + } | ||
| 4 | 10 | ||
| 5 | 11 | double omp_time {0.0}; | |
| 6 | 12 | double tbb_time {0.0}; | |
@@ -23,9 +29,9 @@ int main() { | |||
| 23 | 29 | init_matrix(); | |
| 24 | 30 | ||
| 25 | 31 | for(int j=0; j<rounds; ++j) { | |
| 26 | - omp_time += measure_time_omp().count(); | ||
| 27 | - tbb_time += measure_time_tbb().count(); | ||
| 28 | - tf_time += measure_time_taskflow().count(); | ||
| 32 | + omp_time += measure_time_omp(num_threads).count(); | ||
| 33 | + tbb_time += measure_time_tbb(num_threads).count(); | ||
| 34 | + tf_time += measure_time_taskflow(num_threads).count(); | ||
| 29 | 35 | } | |
| 30 | 36 | ||
| 31 | 37 | destroy_matrix(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,8 +17,8 @@ inline double **matrix {nullptr}; | |||
| 17 | 17 | ||
| 18 | 18 | // nominal operations | |
| 19 | 19 | inline double calc(double v0, double v1) { | |
| 20 | - return (v0 == v1) ? std::pow(v0/v1, 4.0f) : std::max(v0,v1); | ||
| 21 | - //return std::max(v0, v1); | ||
| 20 | + //return (v0 == v1) ? std::pow(v0/v1, 4.0f) : std::max(v0,v1); | ||
| 21 | + return std::max(v0, v1); | ||
| 22 | 22 | } | |
| 23 | 23 | ||
| 24 | 24 | // initialize the matrix | |
@@ -56,8 +56,8 @@ inline void block_computation(int i, int j){ | |||
| 56 | 56 | } | |
| 57 | 57 | ||
| 58 | 58 | ||
| 59 | - std::chrono::microseconds measure_time_taskflow(); | ||
| 60 | - std::chrono::microseconds measure_time_omp(); | ||
| 61 | - std::chrono::microseconds measure_time_tbb(); | ||
| 59 | + std::chrono::microseconds measure_time_taskflow(unsigned); | ||
| 60 | + std::chrono::microseconds measure_time_omp(unsigned); | ||
| 61 | + std::chrono::microseconds measure_time_tbb(unsigned); | ||
| 62 | 62 | ||
| 63 | 63 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | int **D {nullptr}; | |
| 6 | 6 | ||
| 7 | 7 | // wavefront computation | |
| 8 | - void wavefront_omp() { | ||
| 8 | + void wavefront_omp(unsigned num_threads) { | ||
| 9 | 9 | ||
| 10 | 10 | // set up the dependency matrix | |
| 11 | 11 | D = new int *[MB]; | |
@@ -16,7 +16,7 @@ void wavefront_omp() { | |||
| 16 | 16 | } | |
| 17 | 17 | } | |
| 18 | 18 | ||
| 19 | - omp_set_num_threads(std::thread::hardware_concurrency()); | ||
| 19 | + omp_set_num_threads(num_threads); | ||
| 20 | 20 | ||
| 21 | 21 | #pragma omp parallel | |
| 22 | 22 | { | |
@@ -73,9 +73,9 @@ void wavefront_omp() { | |||
| 73 | 73 | delete [] D; | |
| 74 | 74 | } | |
| 75 | 75 | ||
| 76 | - std::chrono::microseconds measure_time_omp() { | ||
| 76 | + std::chrono::microseconds measure_time_omp(unsigned num_threads) { | ||
| 77 | 77 | auto beg = std::chrono::high_resolution_clock::now(); | |
| 78 | - wavefront_omp(); | ||
| 78 | + wavefront_omp(num_threads); | ||
| 79 | 79 | auto end = std::chrono::high_resolution_clock::now(); | |
| 80 | 80 | return std::chrono::duration_cast<std::chrono::milliseconds>(end - beg); | |
| 81 | 81 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,9 +2,9 @@ | |||
| 2 | 2 | #include <taskflow/taskflow.hpp> | |
| 3 | 3 | ||
| 4 | 4 | // wavefront computing | |
| 5 | - void wavefront_taskflow() { | ||
| 5 | + void wavefront_taskflow(unsigned num_threads) { | ||
| 6 | 6 | ||
| 7 | - tf::Taskflow tf; | ||
| 7 | + tf::Taskflow tf{num_threads}; | ||
| 8 | 8 | ||
| 9 | 9 | std::vector<std::vector<tf::Task>> node(MB); | |
| 10 | 10 | ||
@@ -22,17 +22,18 @@ void wavefront_taskflow() { | |||
| 22 | 22 | block_computation(i, j); | |
| 23 | 23 | } | |
| 24 | 24 | ); | |
| 25 | - if(j+1 < NB) node[i][j].precede(node[i][j+1]); | ||
| 25 | + | ||
| 26 | 26 | if(i+1 < MB) node[i][j].precede(node[i+1][j]); | |
| 27 | + if(j+1 < NB) node[i][j].precede(node[i][j+1]); | ||
| 27 | 28 | } | |
| 28 | 29 | } | |
| 29 | 30 | ||
| 30 | 31 | tf.wait_for_all(); | |
| 31 | 32 | } | |
| 32 | 33 | ||
| 33 | - std::chrono::microseconds measure_time_taskflow() { | ||
| 34 | + std::chrono::microseconds measure_time_taskflow(unsigned num_threads) { | ||
| 34 | 35 | auto beg = std::chrono::high_resolution_clock::now(); | |
| 35 | - wavefront_taskflow(); | ||
| 36 | + wavefront_taskflow(num_threads); | ||
| 36 | 37 | auto end = std::chrono::high_resolution_clock::now(); | |
| 37 | 38 | return std::chrono::duration_cast<std::chrono::milliseconds>(end - beg); | |
| 38 | 39 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,12 +3,12 @@ | |||
| 3 | 3 | #include <tbb/flow_graph.h> | |
| 4 | 4 | ||
| 5 | 5 | // the wavefront computation | |
| 6 | - void wavefront_tbb() { | ||
| 6 | + void wavefront_tbb(unsigned num_threads) { | ||
| 7 | 7 | ||
| 8 | 8 | using namespace tbb; | |
| 9 | 9 | using namespace tbb::flow; | |
| 10 | 10 | ||
| 11 | - tbb::task_scheduler_init init(std::thread::hardware_concurrency()); | ||
| 11 | + tbb::task_scheduler_init init(num_threads); | ||
| 12 | 12 | ||
| 13 | 13 | continue_node<continue_msg> ***node = new continue_node<continue_msg> **[MB]; | |
| 14 | 14 | ||
@@ -42,9 +42,9 @@ void wavefront_tbb() { | |||
| 42 | 42 | } | |
| 43 | 43 | } | |
| 44 | 44 | ||
| 45 | - std::chrono::microseconds measure_time_tbb() { | ||
| 45 | + std::chrono::microseconds measure_time_tbb(unsigned num_threads) { | ||
| 46 | 46 | auto beg = std::chrono::high_resolution_clock::now(); | |
| 47 | - wavefront_tbb(); | ||
| 47 | + wavefront_tbb(num_threads); | ||
| 48 | 48 | auto end = std::chrono::high_resolution_clock::now(); | |
| 49 | 49 | return std::chrono::duration_cast<std::chrono::milliseconds>(end - beg); | |
| 50 | 50 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments