Skip to content

Commit 4ac3518

Browse files
updated README
1 parent 165f063 commit 4ac3518

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ A fast C++ header-only library to help you quickly build parallel programs with
1212
# Why Cpp-Taskflow?
1313

1414
Cpp-Taskflow lets you quickly build parallel dependency graphs using modern C++17.
15-
It is by far faster, more expressive, and easier for drop-in integration than existing libraries such as [OpenMP Tasking][OpenMP Tasking] and
16-
[TBB FlowGraph][TBB FlowGraph].
15+
It is by far faster, more expressive, and easier for drop-in integration than existing libraries.
1716

1817
| Without Cpp-Taskflow | With Cpp-Taskflow |
1918
| -------------------- | ----------------- |
@@ -476,12 +475,12 @@ The folder `example/` contains several examples and is a great place to learn to
476475
| [matrix.cpp](./example/matrix.cpp) | create two set of matrices and multiply each individually in parallel |
477476
| [parallel_for.cpp](./example/parallel_for.cpp)| parallelize a for loop with unbalanced workload |
478477
| [reduce.cpp](./example/reduce.cpp)| perform reduce operations over linear containers |
478+
| [subflow.cpp](./example/subflow.cpp)| create a taskflow graph that spawns dynamic tasks |
479479

480480

481481
# Get Involved
482482
+ Report bugs/issues by submitting a [Github issue][Github issues].
483483
+ Submit contributions using [pull requests][Github pull requests].
484-
+ Live chat and ask questions on [Gitter][Gitter].
485484

486485
# Contributors
487486
Cpp-Taskflow is being actively developed and contributed by the following people:

example/subflow.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,40 @@
99
// Do so is difference from "wait_for_all" which will clean up the
1010
// finished graphs. After the graph finished, we dump the topology
1111
// for inspection.
12+
//
13+
// Usage: ./subflow detach|join
14+
//
1215

1316
#include <taskflow.hpp>
1417

15-
int main() {
18+
const auto usage = "usage: ./subflow detach|join";
19+
20+
int main(int argc, char* argv[]) {
21+
22+
if(argc != 2) {
23+
std::cerr << usage << std::endl;
24+
std::exit(EXIT_FAILURE);
25+
}
1626

27+
std::string_view opt(argv[1]);
28+
29+
if(opt != "detach" && opt != "join") {
30+
std::cerr << usage << std::endl;
31+
std::exit(EXIT_FAILURE);
32+
}
33+
34+
auto detached = (opt == "detach") ? true : false;
35+
36+
// Create a taskflow graph with three regular tasks and one subflow task.
1737
tf::Taskflow tf(std::thread::hardware_concurrency());
1838

1939
auto [A, B, C, D] = tf.silent_emplace(
2040
// Task A
2141
[] () { std::cout << "TaskA\n"; },
2242
// Task B
23-
[cap=std::vector<int>{1,2,3,4,5,6,7,8}] (auto& subflow) {
43+
[cap=std::vector<int>{1,2,3,4,5,6,7,8}, detached] (auto& subflow) {
2444

25-
std::cout << "TaskB\n";
45+
std::cout << "TaskB is spawning B1, B2, and B3 ...\n";
2646

2747
auto B1 = subflow.silent_emplace([&]() {
2848
printf(" Subtask B1: reduce sum = %d\n",
@@ -41,6 +61,9 @@ int main() {
4161

4262
B1.precede(B3);
4363
B2.precede(B3);
64+
65+
// detach or join the subflow (by default the subflow join at B)
66+
if(detached) subflow.detach();
4467
},
4568
// Task C
4669
[] () { std::cout << "TaskC\n"; },
@@ -60,8 +83,8 @@ int main() {
6083

6184
tf.dispatch().get(); // block until finished
6285

63-
// Now we can dump the topology
64-
std::cout << tf.dump_topologies();
86+
// examine the graph
87+
std::cout << '\n' << tf.dump_topologies();
6588

6689
return 0;
6790
}

0 commit comments

Comments
 (0)