FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
taskflow/examples/fibonacci.cpp at master · githubCode3a/taskflow · GitHub
githubCode3a
/
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
/
examples
/
fibonacci.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (33 loc) · 993 Bytes
Breadcrumbs
taskflow
/
examples
/
fibonacci.cpp
Copy path
File metadata and controls
57 lines (33 loc) · 993 Bytes
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
#
include
<
taskflow/taskflow.hpp
>
int
spawn
(
int
n, tf::Subflow& sbf) {
if
(n <
2
)
return
n;
int
res1, res2;
//
compute f(n-1)
sbf.
emplace
([&res1, n] (tf::Subflow& sbf) { res1 =
spawn
(n -
1
, sbf); } )
.
name
(
std::to_string
(n-
1
));
//
compute f(n-2)
sbf.
emplace
([&res2, n] (tf::Subflow& sbf) { res2 =
spawn
(n -
2
, sbf); } )
.
name
(
std::to_string
(n-
2
));
sbf.
join
();
return
res1 + res2;
}
int
main
(
int
argc,
char
* argv[]) {
if
(argc !=
2
) {
std::cerr <<
"
usage: ./fibonacci N
\n
"
;
std::exit
(
EXIT_FAILURE
);
}
int
N =
std::atoi
(argv[
1
]);
if
(N <
0
) {
throw
std::runtime_error
(
"
N must be non-negative
"
);
}
int
res;
//
result
tf::Executor executor;
tf::Taskflow
taskflow
(
"
fibonacci
"
);
taskflow.
emplace
([&res, N] (tf::Subflow& sbf) {
res =
spawn
(N, sbf);
}).
name
(
std::to_string
(N));
executor.
run
(taskflow).
wait
();
//
taskflow.dump(std::cout);
std::cout <<
"
Fib[
"
<< N <<
"
]:
"
<< res << std::endl;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL