FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
taskflow/benchmarks/binary_tree/tbb.cpp at master · ModuleWorks/taskflow · GitHub
ModuleWorks
/
taskflow
Public
forked from
taskflow/taskflow
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
taskflow
/
benchmarks
/
binary_tree
/
tbb.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (44 loc) · 1.31 KB
Breadcrumbs
taskflow
/
benchmarks
/
binary_tree
/
tbb.cpp
Copy path
File metadata and controls
56 lines (44 loc) · 1.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
51
52
53
54
55
56
#
include
"
binary_tree.hpp
"
#
include
<
tbb/global_control.h
>
#
include
<
tbb/flow_graph.h
>
//
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<
size_t
> counter {
0
};
graph g;
std::vector<continue_node<continue_msg>*>
tasks
(
1
<< num_layers);
for
(
unsigned
i=
1
; i<tasks.
size
(); i++) {
tasks[i] =
new
continue_node<continue_msg>(g,
[&](
const
continue_msg& ) {
counter.
fetch_add
(
1
, std::memory_order_relaxed);
}
);
}
for
(
unsigned
i=
1
; i<tasks.
size
(); i++) {
unsigned
l = i <<
1
;
unsigned
r = l +
1
;
if
(l < tasks.
size
() && r < tasks.
size
()) {
make_edge
(*tasks[i], *tasks[l]);
make_edge
(*tasks[i], *tasks[r]);
}
}
tasks[
1
]->
try_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<std::chrono::microseconds>(end - beg);
}
Back
|
FazBrowse Home
|
New Git URL