File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -203,9 +203,9 @@ class LevelGraph {
203203
204204};
205205
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 );
209209
210210
211211
Original file line number Diff line number Diff line change 11#include " levelgraph.hpp"
22
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+ }
410
511 double omp_time {0.0 };
612 double tbb_time {0.0 };
713 double tf_time {0.0 };
814 int rounds {5 };
9-
15+
1016 std::cout << std::setw (12 ) << " |V|+|E|"
1117 << std::setw (12 ) << " OpenMP"
1218 << std::setw (12 ) << " TBB"
1319 << std::setw (12 ) << " Taskflow"
1420 << std::endl;
1521
16- for (int i=1 ; i<=401 ; i += 4 ) {
22+ for (int i=1 ; i<=401 ; i += 10 ) {
1723
1824 LevelGraph graph (i, i);
1925
2026 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 ();
2228 graph.clear_graph ();
2329
24- tbb_time += measure_time_tbb (graph).count ();
30+ tbb_time += measure_time_tbb (graph, num_threads ).count ();
2531 graph.clear_graph ();
2632
27- tf_time += measure_time_taskflow (graph).count ();
33+ tf_time += measure_time_taskflow (graph, num_threads ).count ();
2834 graph.clear_graph ();
2935 }
3036
Original file line number Diff line number Diff line change 44
55#include " levelgraph.hpp"
66
7- void traverse_regular_graph_omp (LevelGraph& graph){
7+ void traverse_regular_graph_omp (LevelGraph& graph, unsigned num_threads ){
88
9- omp_set_num_threads (std::thread::hardware_concurrency () );
9+ omp_set_num_threads (num_threads );
1010
1111 #pragma omp parallel
1212 {
@@ -262,9 +262,9 @@ void traverse_regular_graph_omp(LevelGraph& graph){
262262 }
263263}
264264
265- std::chrono::microseconds measure_time_omp (LevelGraph& graph){
265+ std::chrono::microseconds measure_time_omp (LevelGraph& graph, unsigned num_threads ){
266266 auto beg = std::chrono::high_resolution_clock::now ();
267- traverse_regular_graph_omp (graph);
267+ traverse_regular_graph_omp (graph, num_threads );
268268 auto end = std::chrono::high_resolution_clock::now ();
269269 return std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
270270}
Original file line number Diff line number Diff line change 66
77struct TF {
88
9- TF (LevelGraph& graph) {
9+ TF (LevelGraph& graph, unsigned num_threads) : tf {num_threads} {
1010
1111 tasks.resize (graph.level ());
1212 for (size_t i=0 ; i<tasks.size (); ++i) {
@@ -38,14 +38,14 @@ struct TF {
3838
3939};
4040
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 );
4343 tf.run ();
4444}
4545
46- std::chrono::microseconds measure_time_taskflow (LevelGraph& graph){
46+ std::chrono::microseconds measure_time_taskflow (LevelGraph& graph, unsigned num_threads ){
4747 auto beg = std::chrono::high_resolution_clock::now ();
48- traverse_level_graph_taskflow (graph);
48+ traverse_level_graph_taskflow (graph, num_threads );
4949 auto end = std::chrono::high_resolution_clock::now ();
5050 return std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
5151}
Original file line number Diff line number Diff line change @@ -11,9 +11,9 @@ using namespace tbb::flow;
1111
1212struct TBB {
1313
14- TBB (LevelGraph& graph) {
14+ TBB (LevelGraph& graph, unsigned num_threads ) {
1515
16- tbb::task_scheduler_init init (std::thread::hardware_concurrency () );
16+ tbb::task_scheduler_init init (num_threads );
1717
1818 tasks.resize (graph.level ());
1919 for (size_t i=0 ; i<tasks.size (); ++i) {
@@ -60,14 +60,14 @@ struct TBB {
6060 std::unique_ptr<continue_node<continue_msg>> source;
6161};
6262
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 );
6565 tbb.run ();
6666}
6767
68- std::chrono::microseconds measure_time_tbb (LevelGraph& graph){
68+ std::chrono::microseconds measure_time_tbb (LevelGraph& graph, unsigned num_threads ){
6969 auto beg = std::chrono::high_resolution_clock::now ();
70- traverse_regular_graph_tbb (graph);
70+ traverse_regular_graph_tbb (graph, num_threads );
7171 auto end = std::chrono::high_resolution_clock::now ();
7272 return std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
7373}
Original file line number Diff line number Diff line change 11#include " matrix.hpp"
22
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+ }
410
511 double omp_time {0.0 };
612 double tbb_time {0.0 };
@@ -23,9 +29,9 @@ int main() {
2329 init_matrix ();
2430
2531 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 ();
2935 }
3036
3137 destroy_matrix ();
Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ inline double **matrix {nullptr};
1717
1818// nominal operations
1919inline 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);
2222}
2323
2424// initialize the matrix
@@ -56,8 +56,8 @@ inline void block_computation(int i, int j){
5656}
5757
5858
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 );
6262
6363
Original file line number Diff line number Diff line change 55int **D {nullptr };
66
77// wavefront computation
8- void wavefront_omp () {
8+ void wavefront_omp (unsigned num_threads ) {
99
1010 // set up the dependency matrix
1111 D = new int *[MB];
@@ -16,7 +16,7 @@ void wavefront_omp() {
1616 }
1717 }
1818
19- omp_set_num_threads (std::thread::hardware_concurrency () );
19+ omp_set_num_threads (num_threads );
2020
2121 #pragma omp parallel
2222 {
@@ -73,9 +73,9 @@ void wavefront_omp() {
7373 delete [] D;
7474}
7575
76- std::chrono::microseconds measure_time_omp () {
76+ std::chrono::microseconds measure_time_omp (unsigned num_threads ) {
7777 auto beg = std::chrono::high_resolution_clock::now ();
78- wavefront_omp ();
78+ wavefront_omp (num_threads );
7979 auto end = std::chrono::high_resolution_clock::now ();
8080 return std::chrono::duration_cast<std::chrono::milliseconds>(end - beg);
8181}
Original file line number Diff line number Diff line change 22#include < taskflow/taskflow.hpp>
33
44// wavefront computing
5- void wavefront_taskflow () {
5+ void wavefront_taskflow (unsigned num_threads ) {
66
7- tf::Taskflow tf;
7+ tf::Taskflow tf{num_threads} ;
88
99 std::vector<std::vector<tf::Task>> node (MB);
1010
@@ -22,17 +22,18 @@ void wavefront_taskflow() {
2222 block_computation (i, j);
2323 }
2424 );
25- if (j+ 1 < NB) node[i][j]. precede (node[i][j+ 1 ]);
25+
2626 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 ]);
2728 }
2829 }
2930
3031 tf.wait_for_all ();
3132}
3233
33- std::chrono::microseconds measure_time_taskflow () {
34+ std::chrono::microseconds measure_time_taskflow (unsigned num_threads ) {
3435 auto beg = std::chrono::high_resolution_clock::now ();
35- wavefront_taskflow ();
36+ wavefront_taskflow (num_threads );
3637 auto end = std::chrono::high_resolution_clock::now ();
3738 return std::chrono::duration_cast<std::chrono::milliseconds>(end - beg);
3839}
Original file line number Diff line number Diff line change 33#include < tbb/flow_graph.h>
44
55// the wavefront computation
6- void wavefront_tbb () {
6+ void wavefront_tbb (unsigned num_threads ) {
77
88 using namespace tbb ;
99 using namespace tbb ::flow;
1010
11- tbb::task_scheduler_init init (std::thread::hardware_concurrency () );
11+ tbb::task_scheduler_init init (num_threads );
1212
1313 continue_node<continue_msg> ***node = new continue_node<continue_msg> **[MB];
1414
@@ -42,9 +42,9 @@ void wavefront_tbb() {
4242 }
4343}
4444
45- std::chrono::microseconds measure_time_tbb () {
45+ std::chrono::microseconds measure_time_tbb (unsigned num_threads ) {
4646 auto beg = std::chrono::high_resolution_clock::now ();
47- wavefront_tbb ();
47+ wavefront_tbb (num_threads );
4848 auto end = std::chrono::high_resolution_clock::now ();
4949 return std::chrono::duration_cast<std::chrono::milliseconds>(end - beg);
5050}
You can’t perform that action at this time.
0 commit comments