FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/examples/exclusive_scan.cpp at master · feiyunwill/cpp-taskflow · GitHub
feiyunwill
/
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
/
examples
/
exclusive_scan.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (52 loc) · 1.71 KB
Breadcrumbs
cpp-taskflow
/
examples
/
exclusive_scan.cpp
Copy path
File metadata and controls
63 lines (52 loc) · 1.71 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
57
58
59
60
61
62
63
//
This program demonstrates how to perform parallel exclusive scan.
#
include
<
taskflow/taskflow.hpp
>
#
include
<
taskflow/algorithm/scan.hpp
>
int
main
(
int
argc,
char
* argv[]) {
if
(argc !=
3
) {
std::cerr <<
"
usage: ./exclusive_scan num_workers num_elements
\n
"
;
std::exit
(
EXIT_FAILURE
);
}
size_t
W =
std::atoi
(argv[
1
]);
size_t
N =
std::atoi
(argv[
2
]);
tf::Executor
executor
(W);
tf::Taskflow taskflow;
std::vector<
int
>
elements
(N),
scan_seq
(N),
scan_par
(N);
for
(
size_t
i=
0
; i<N; i++) {
elements[i] =
static_cast
<
int
>(i);
}
//
sequential exclusive scan
{
std::cout <<
"
sequential exclusive scan ...
"
;
auto
beg =
std::chrono::steady_clock::now
();
std::exclusive_scan
(
elements.
begin
(), elements.
end
(), scan_seq.
begin
(), -
1
, std::plus<
int
>{}
);
auto
end =
std::chrono::steady_clock::now
();
std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(end-beg).
count
()
<<
"
ns
\n
"
;
}
//
create a parallel exclusive scan task
{
std::cout <<
"
parallel exclusive scan ...
"
;
auto
beg =
std::chrono::steady_clock::now
();
taskflow.
exclusive_scan
(
elements.
begin
(), elements.
end
(), scan_par.
begin
(), -
1
, std::plus<
int
>{}
);
executor.
run
(taskflow).
wait
();
auto
end =
std::chrono::steady_clock::now
();
std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(end-beg).
count
()
<<
"
ns
\n
"
;
}
//
verify the result
for
(
size_t
i=
0
; i<N; i++) {
if
(scan_seq[i] != scan_par[i]) {
printf
(
"
scan_seq[%zu]=%d..., scan_par[%zu]=%d...
\n
"
,
i, scan_seq[i], i, scan_par[i]
);
throw
std::runtime_error
(
"
incorrect result
"
);
}
}
printf
(
"
correct result
\n
"
);
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL