#include #include #include #include "levelgraph.hpp" #include #include using namespace tbb; using namespace tbb::flow; struct TBB { TBB(LevelGraph& graph, unsigned num_threads) { tbb::global_control c( tbb::global_control::max_allowed_parallelism, num_threads ); tasks.resize(graph.level()); for(size_t i=0; i>(G, [&](const continue_msg&){ n.mark(); } ); } for(int l=graph.level()-2; l>=0 ; l--){ for(size_t i=0; i>(G, [&](const continue_msg&){ n.mark(); } ); for(size_t k=0; k>(G, [](const continue_msg&){} ); for(int l=0; l>=0 ; l--) { for(size_t i=0; itry_put(continue_msg()); G.wait_for_all(); } tbb::flow::graph G; std::vector>>> tasks; std::unique_ptr> source; }; void traverse_regular_graph_tbb(LevelGraph& graph, unsigned num_threads){ TBB tbb(graph, num_threads); tbb.run(); } std::chrono::microseconds measure_time_tbb(LevelGraph& graph, unsigned num_threads){ auto beg = std::chrono::high_resolution_clock::now(); traverse_regular_graph_tbb(graph, num_threads); auto end = std::chrono::high_resolution_clock::now(); return std::chrono::duration_cast(end - beg); } //int main(int argc, char* argv[]){ // // for(int i=1; i<=200; i++){ // LevelGraph graph(i, i); // auto tbb = measure_time_tbb(graph); // std::cout << "Level graph:\t" << i << "\tby\t" << i << std::endl; // std::cout << "Elasped time tbb:\t" << tbb << std::endl; // std::cout << "Graph is fully traversed:\t" << graph.validate_result() << std::endl; // graph.clear_graph(); // std::cout << std::endl; // } // //}