FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/examples/dependent_async_algorithm.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
/
dependent_async_algorithm.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (36 loc) · 1.06 KB
Breadcrumbs
cpp-taskflow
/
examples
/
dependent_async_algorithm.cpp
Copy path
File metadata and controls
51 lines (36 loc) · 1.06 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
/*
*
This program demonstrates how to use dependent async tasks to create
algorithm tasks.
*/
#
include
<
taskflow/taskflow.hpp
>
#
include
<
taskflow/algorithm/for_each.hpp
>
#
include
<
taskflow/algorithm/transform.hpp
>
#
include
<
taskflow/algorithm/reduce.hpp
>
int
main
(){
const
size_t
N =
65536
;
tf::Executor executor;
int
sum{
1
};
std::vector<
int
>
data
(N);
//
for-each
tf::AsyncTask A = executor.
silent_dependent_async
(
tf::make_for_each_task
(
data.
begin
(), data.
end
(), [](
int
& i){ i =
1
; }
));
//
transform
tf::AsyncTask B = executor.
silent_dependent_async
(
tf::make_transform_task
(
data.
begin
(), data.
end
(), data.
begin
(), [](
int
& i) {
return
i*
2
; }
), A);
//
reduce
tf::AsyncTask C = executor.
silent_dependent_async
(
tf::make_reduce_task
(
data.
begin
(), data.
end
(), sum, std::plus<
int
>{}
), B);
//
wait for all async task to complete
executor.
wait_for_all
();
//
verify the result
if
(sum != N*
2
+
1
) {
throw
std::runtime_error
(
"
INCORRECT RESULT
"
);
}
else
{
std::cout <<
"
CORRECT RESULT
\n
"
;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL