forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtbb.cpp
More file actions
50 lines (39 loc) · 1.07 KB
/
Copy pathtbb.cpp
File metadata and controls
50 lines (39 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "linear_chain.hpp"
#include <tbb/global_control.h>
#include <tbb/flow_graph.h>
// linear_chain_tbb
void linear_chain_tbb(size_t length, unsigned num_threads) {
using namespace tbb;
using namespace tbb::flow;
size_t counter = 0;
tbb::global_control c(
tbb::global_control::max_allowed_parallelism, num_threads
);
graph g;
std::vector<continue_node<continue_msg>*> tasks(length);
for(size_t i=0; i<tasks.size(); i++) {
tasks[i] = new continue_node<continue_msg>(g,
[&]( const continue_msg& ) {
counter++;
}
);
if(i) {
make_edge(*tasks[i-1], *tasks[i]);
}
}
tasks[0]->try_put(continue_msg());
g.wait_for_all();
for(auto& task : tasks) {
delete task;
}
assert(counter == tasks.size());
}
std::chrono::microseconds measure_time_tbb(
size_t length,
unsigned num_threads
) {
auto beg = std::chrono::high_resolution_clock::now();
linear_chain_tbb(length, num_threads);
auto end = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
}