Skip to content

Commit 2abd788

Browse files
Update README and add images
1 parent e3f2021 commit 2abd788

4 files changed

Lines changed: 42 additions & 16 deletions

File tree

README.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,39 @@ tf.wait_for_all();
114114
# Debug a Taskflow Graph
115115
Concurrent programs are notoriously difficult to debug.
116116
We suggest (1) naming tasks and dumping the graph, and (2) starting with single thread before going multiple.
117+
Currently, Cpp-Taskflow supports [GraphViz](https://www.graphviz.org/) format.
117118

118119
```cpp
119120
// debug.cpp
120121
tf::Taskflow tf(0); // force the master thread to execute all tasks
121-
auto A = tf.silent_emplace([] () { std::cout << "Task A\n"; }).name("A");
122-
auto B = tf.silent_emplace([] () { std::cout << "Task B\n"; }).name("B");
123-
A.precede(B);
124-
std::cout << tf;
122+
auto A = tf.silent_emplace([] () { /* ... */ }).name("A");
123+
auto B = tf.silent_emplace([] () { /* ... */ }).name("B");
124+
auto C = tf.silent_emplace([] () { /* ... */ }).name("C");
125+
auto D = tf.silent_emplace([] () { /* ... */ }).name("D");
126+
auto E = tf.silent_emplace([] () { /* ... */ }).name("E");
127+
128+
A.broadcast(B, C, E);
129+
C.precede(D);
130+
B.broadcast(D, E);
131+
132+
std::cout << tf.dump_graphviz();
125133
```
126134
Run the program and inspect whether dependencies are expressed in the right way.
127135
```bash
128136
~$ ./debug
129-
# dumped graph
130-
Task 0x540000 [dependents:0|successors:1] "A"
131-
|--> task "B"
132-
Task 0x540064 [dependents:1|successors:0] "B"
133-
# runtime message
134-
TaskA
135-
TaskB
137+
digraph Taskflow {
138+
"A" -> "B"
139+
"A" -> "C"
140+
"A" -> "E"
141+
"B" -> "D"
142+
"B" -> "E"
143+
"C" -> "D"
144+
}
136145
```
146+
There are a number of free online GraphViz tools you could find online
147+
to visualize your Taskflow graph.
148+
149+
<img src="image/graphviz.png" width="25%"> Taskflow with five tasks and six dependencies, generated by [Viz.js](http://viz-js.com/).
137150

138151
# Caveats
139152
While Cpp-Taskflow enables the expression of very complex task dependency graph that might contain

example/simple.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77

88
int main(){
99

10+
tf::Taskflow tf(0); // force the master thread to execute all tasks
11+
auto A = tf.silent_emplace([] () { }).name("A");
12+
auto B = tf.silent_emplace([] () { }).name("B");
13+
auto C = tf.silent_emplace([] () { }).name("C");
14+
auto D = tf.silent_emplace([] () { }).name("D");
15+
auto E = tf.silent_emplace([] () { }).name("E");
16+
17+
A.broadcast(B, C, E);
18+
C.precede(D);
19+
B.broadcast(D, E);
20+
21+
std::cout << tf.dump_graphviz();
22+
23+
return 0;
24+
/*
1025
tf::Taskflow tf(std::thread::hardware_concurrency());
1126
1227
auto [A, B, C, D] = tf.silent_emplace(
@@ -21,10 +36,8 @@ int main(){
2136
B.precede(D); // D runs after B
2237
C.precede(D); // C runs after D
2338
24-
std::cout << tf.dump_graphviz();
25-
2639
tf.wait_for_all(); // block until all task finish
27-
40+
*/
2841
return 0;
2942
}
3043

image/graphviz.png

16.8 KB
Loading

taskflow.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ std::string BasicTaskflow<F>::dump_graphviz() const {
856856
return os.str();
857857
}
858858

859-
// Operator <<
859+
/*// Operator <<
860860
template <typename F>
861861
std::ostream& operator << (std::ostream& os, const BasicTaskflow<F>& tf) {
862862
@@ -874,7 +874,7 @@ std::ostream& operator << (std::ostream& os, const BasicTaskflow<F>& tf) {
874874
}
875875
}
876876
return os;
877-
}
877+
} */
878878

879879
//-------------------------------------------------------------------------------------------------
880880

0 commit comments

Comments
 (0)