#include "binary_tree.hpp" #include #include // binary_tree_tbb void binary_tree_tbb(size_t num_layers, unsigned num_threads) { using namespace tbb; using namespace tbb::flow; tbb::global_control c( tbb::global_control::max_allowed_parallelism, num_threads ); std::atomic counter {0}; graph g; std::vector*> tasks(1 << num_layers); for(unsigned i=1; i(g, [&]( const continue_msg& ) { counter.fetch_add(1, std::memory_order_relaxed); } ); } for(unsigned i=1; itry_put(continue_msg()); g.wait_for_all(); for(auto& task : tasks) { delete task; } assert(counter + 1 == tasks.size()); } std::chrono::microseconds measure_time_tbb( size_t num_layers, unsigned num_threads ) { auto beg = std::chrono::high_resolution_clock::now(); binary_tree_tbb(num_layers, num_threads); auto end = std::chrono::high_resolution_clock::now(); return std::chrono::duration_cast(end - beg); }