FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
taskflow/examples/for_loop.cpp at master · taskflow/taskflow · GitHub
taskflow
taskflow
Repository navigation
Code
Issues
21
(21)
Pull requests
20
(20)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
taskflow
/
examples
/
for_loop.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (40 loc) · 1.49 KB
Breadcrumbs
taskflow
/
examples
/
for_loop.cpp
Copy path
File metadata and controls
51 lines (40 loc) · 1.49 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
#
include
<
taskflow/taskflow.hpp
>
void
loop_body
() { }
int
main
(
int
argc,
const
char
* argv[]) {
if
(argc !=
2
) {
std::cerr <<
"
usage: ./for_loop num_iterations
"
<< std::endl;
std::exit
(
EXIT_FAILURE
);
}
const
size_t
N =
std::atoi
(argv[
1
]);
//
expressing loop using Taskflow's control taskflow graph programming model
tf::Executor executor;
tf::Taskflow taskflow;
auto
X = taskflow.
emplace
([](){});
auto
Y = taskflow.
emplace
([&, i=
size_t
(
0
)]()
mutable
{
loop_body
();
return
(i++ < N) ?
0
:
1
;
});
auto
Z = taskflow.
emplace
([](){});
X.
precede
(Y);
Y.
precede
(Y, Z);
auto
tbeg =
std::chrono::steady_clock::now
();
executor.
run
(taskflow).
wait
();
auto
tend =
std::chrono::steady_clock::now
();
std::cout <<
"
in-graph control flow time :
"
<< std::chrono::duration_cast<std::chrono::microseconds>(tend-tbeg).
count
()
<<
"
us
\n
"
;
//
expressing the loop without using cointrol taskflow graph
tf::Taskflow taskflow_x, taskflow_y, taskflow_z;
taskflow_x.
emplace
([](){});
taskflow_y.
emplace
(loop_body);
taskflow_z.
emplace
([](){});
tbeg =
std::chrono::steady_clock::now
();
executor.
run
(taskflow_x).
wait
();
for
(
size_t
i=
0
; i<N; ++i) {
executor.
run
(taskflow_y).
wait
();
}
executor.
run
(taskflow_z).
wait
();
tend =
std::chrono::steady_clock::now
();
std::cout <<
"
out-of-graph control flow time:
"
<< std::chrono::duration_cast<std::chrono::microseconds>(tend-tbeg).
count
()
<<
"
us
\n
"
;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL