FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/benchmark/binary_tree/omp.cpp at master · cg4115/cpp-taskflow · GitHub
cg4115
/
cpp-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
cpp-taskflow
/
benchmark
/
binary_tree
/
omp.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (44 loc) · 1.25 KB
Breadcrumbs
cpp-taskflow
/
benchmark
/
binary_tree
/
omp.cpp
Copy path
File metadata and controls
55 lines (44 loc) · 1.25 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
#
include
"
binary_tree.hpp
"
#
include
<
omp.h
>
//
binary_tree_omp
void
binary_tree_omp
(
size_t
num_layers,
unsigned
num_threads) {
std::atomic<
size_t
> counter =
0
;
size_t
N =
1
<< num_layers;
size_t
*D =
new
size_t
[N];
#
pragma
omp parallel num_threads(num_threads)
{
#
pragma
omp single
{
for
(
size_t
i =
1
; i<N; ++i) {
size_t
p = i /
2
;
size_t
l = i *
2
;
size_t
r = l +
1
;
if
(l < N && r < N) {
#
pragma
omp task firstprivate(i) depend(out:D[l], D[r]) depend(in:D[p])
{
//
printf("%d\n", i);
counter.
fetch_add
(
1
, std::memory_order_relaxed);
}
}
else
{
#
pragma
omp task firstprivate(i) depend(in:D[p])
{
//
printf("%d\n", i);
counter.
fetch_add
(
1
, std::memory_order_relaxed);
}
}
}
}
}
assert
((counter +
1
) == N);
delete []
D;
}
std::chrono::microseconds
measure_time_omp
(
size_t
num_layers,
unsigned
num_threads
) {
auto
beg =
std::chrono::high_resolution_clock::now
();
binary_tree_omp
(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