-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathExamplesPERT.html
More file actions
307 lines (305 loc) · 26.7 KB
/
Copy pathExamplesPERT.html
File metadata and controls
307 lines (305 loc) · 26.7 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<!-- HTML header for doxygen 1.13.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.13.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Taskflow: A General-purpose Task-parallel Programming System: Critical Path Scheduling</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="custom.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectlogo"><img alt="Logo" src="taskflow_logo.png"/></td>
<td id="projectalign">
<div id="projectname"><a href="https://github.com/taskflow/taskflow" style="color:inherit; text-decoration:none;">Taskflow: A General-purpose Task-parallel Programming System</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.13.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search',true);
$(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function(){initNavTree('ExamplesPERT.html',''); initResizable(true); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div><div class="header">
<div class="headertitle"><div class="title">Critical Path Scheduling</div></div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul>
<li class="level1">
<a href="#PERTIntroduction">What is a PERT Chart?</a>
</li>
<li class="level1">
<a href="#PERTProblem">A Concrete Project</a>
</li>
<li class="level1">
<a href="#PERTCriticalPath">Finding the Critical Path</a>
</li>
<li class="level1">
<a href="#PERTImplementation">Implementation</a>
</li>
<li class="level1">
<a href="#PERTDesignPoints">Design Points</a>
</li>
</ul>
</div>
<div class="textblock"><p>We study how to express a <em>PERT</em> (Program Evaluation and Review Technique) <em>chart</em> as a static <a class="el" href="classtf_1_1Taskflow.html" title="class to create a taskflow object">tf::Taskflow</a> and use the task graph to automatically parallelize a project schedule while respecting all precedence constraints. This example shows how project-management scheduling theory maps directly onto Taskflow's task dependency model, and why a static task graph is the right tool when the dependency structure is fully known before execution begins.</p>
<h1><a class="anchor" id="PERTIntroduction"></a>
What is a PERT Chart?</h1>
<p>PERT (Program Evaluation and Review Technique) is a project-management method that represents a project as a directed acyclic graph. Each node is a task with an estimated duration. Each directed edge means this task cannot begin until its predecessor is complete. The goal is to finish the entire project as fast as possible by running independent tasks in parallel, while respecting every dependency.</p>
<p>The key quantity in PERT analysis is the <em>critical</em> <em>path:</em> the longest chain of dependent tasks from project start to project finish. No matter how many workers are available, the project cannot complete faster than the sum of durations along the critical path. Every task on the critical path has zero slack—any delay to it delays the whole project. Tasks off the critical path have positive slack and can be deferred or slowed without affecting the project deadline.</p>
<p>PERT analysis is classically done on paper or in a spreadsheet. The observation at the heart of this example is that a PERT chart <em>is</em> a task dependency graph, and Taskflow can execute it directly: tasks that are independent in the project schedule run in parallel on separate CPU cores, exactly as a project manager would assign them to separate teams.</p>
<h1><a class="anchor" id="PERTProblem"></a>
A Concrete Project</h1>
<p>Consider a nine-task software release project. Each task has an estimated duration in days and a set of prerequisites:</p>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadLeft">Task </th><th class="markdownTableHeadLeft">Description </th><th class="markdownTableHeadCenter">Duration </th><th class="markdownTableHeadLeft">Prerequisites </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft">A </td><td class="markdownTableBodyLeft">Requirements gathering </td><td class="markdownTableBodyCenter">3 d </td><td class="markdownTableBodyLeft">— </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft">B </td><td class="markdownTableBodyLeft">System architecture </td><td class="markdownTableBodyCenter">2 d </td><td class="markdownTableBodyLeft">A </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft">C </td><td class="markdownTableBodyLeft">UI mockups </td><td class="markdownTableBodyCenter">2 d </td><td class="markdownTableBodyLeft">A </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft">D </td><td class="markdownTableBodyLeft">Backend API </td><td class="markdownTableBodyCenter">3 d </td><td class="markdownTableBodyLeft">B </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft">E </td><td class="markdownTableBodyLeft">Frontend implementation </td><td class="markdownTableBodyCenter">4 d </td><td class="markdownTableBodyLeft">C </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft">F </td><td class="markdownTableBodyLeft">Database schema </td><td class="markdownTableBodyCenter">2 d </td><td class="markdownTableBodyLeft">B </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft">G </td><td class="markdownTableBodyLeft">Integration </td><td class="markdownTableBodyCenter">2 d </td><td class="markdownTableBodyLeft">D, E, F </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft">H </td><td class="markdownTableBodyLeft">QA testing </td><td class="markdownTableBodyCenter">3 d </td><td class="markdownTableBodyLeft">G </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft">I </td><td class="markdownTableBodyLeft">Deployment </td><td class="markdownTableBodyCenter">1 d </td><td class="markdownTableBodyLeft">H </td></tr>
</table>
<p>The dependency graph is shown below. Tasks are coloured by phase: blue for discovery, green for design, yellow for implementation, orange for integration and test, and red for delivery.</p>
<div class="dotgraph">
<iframe scrolling="no" frameborder="0" src="dot_pert_dag.svg" width="936" height="215"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<p>The graph has a single source (A) and a single sink (I). After A completes, B and C are both unblocked and can run on separate cores simultaneously. After B completes, D and F are both unblocked. G cannot start until D, E, and F have all finished.</p>
<h1><a class="anchor" id="PERTCriticalPath"></a>
Finding the Critical Path</h1>
<p>The critical path is found by a forward pass through the graph: for each task, the <em>earliest</em> <em>start</em> (ES) is the maximum earliest finish (EF) among all its predecessors, and the earliest finish is ES plus the task duration.</p>
<div class="fragment"><div class="line">Forward pass (ES = max EF of predecessors, EF = ES + duration):</div>
<div class="line"> A: ES = 0, EF = 0 + 3 = 3</div>
<div class="line"> B: ES = 3, EF = 3 + 2 = 5 (predecessor: A)</div>
<div class="line"> C: ES = 3, EF = 3 + 2 = 5 (predecessor: A)</div>
<div class="line"> D: ES = 5, EF = 5 + 3 = 8 (predecessor: B)</div>
<div class="line"> E: ES = 5, EF = 5 + 4 = 9 (predecessor: C)</div>
<div class="line"> F: ES = 5, EF = 5 + 2 = 7 (predecessor: B)</div>
<div class="line"> G: ES = 9, EF = 9 + 2 = 11 (predecessors: D, E, F — max EF is E's 9)</div>
<div class="line"> H: ES = 11, EF = 11 + 3 = 14 (predecessor: G)</div>
<div class="line"> I: ES = 14, EF = 14 + 1 = 15 (predecessor: H)</div>
</div><!-- fragment --><p>The project takes <b>15</b> <b>days</b> in the best case. A backward pass then computes the latest start (LS) and latest finish (LF) for each task, and slack = LS − ES:</p>
<div class="fragment"><div class="line">Backward pass and slack:</div>
<div class="line"> I: LF = 15, LS = 14, slack = 0 <- critical</div>
<div class="line"> H: LF = 14, LS = 11, slack = 0 <- critical</div>
<div class="line"> G: LF = 11, LS = 9, slack = 0 <- critical</div>
<div class="line"> E: LF = 9, LS = 5, slack = 0 <- critical</div>
<div class="line"> C: LF = 5, LS = 3, slack = 0 <- critical</div>
<div class="line"> A: LF = 3, LS = 0, slack = 0 <- critical</div>
<div class="line"> D: LF = 9, LS = 6, slack = 1</div>
<div class="line"> B: LF = 6, LS = 4, slack = 1</div>
<div class="line"> F: LF = 9, LS = 7, slack = 2</div>
</div><!-- fragment --><p>The critical path is <b>A -> C -> E -> G -> H -> I</b>. Tasks B, D, and F each have positive slack: B and D can each slip by one day without affecting the deadline, and F can slip by two days. The figure below highlights the critical path in red and annotates each task with its earliest start, earliest finish, and slack.</p>
<div class="dotgraph">
<iframe scrolling="no" frameborder="0" src="dot_pert_critical_path.svg" width="1067" height="240"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<h1><a class="anchor" id="PERTImplementation"></a>
Implementation</h1>
<p>The mapping from a PERT chart to a <a class="el" href="classtf_1_1Taskflow.html" title="class to create a taskflow object">tf::Taskflow</a> is direct: one task per project activity, one <code>precede</code> call per dependency edge. We represent each project activity as a <code><a class="el" href="classtf_1_1Task.html" title="class to create a task handle over a taskflow node">Task</a></code> struct carrying its name, duration, and the earliest-start time recorded at runtime for verification:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include <taskflow/taskflow.hpp></span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// A project activity: name, duration (simulated by sleeping), and</span></div>
<div class="line"><span class="comment">// the wall-clock earliest-start time recorded when the task fires.</span></div>
<div class="line"><span class="keyword">struct </span>Activity {</div>
<div class="line"> std::string name;</div>
<div class="line"> <span class="keywordtype">int</span> duration; <span class="comment">// simulated duration in time units</span></div>
<div class="line"> <span class="keywordtype">int</span> earliest_start{-1}; <span class="comment">// filled in at runtime</span></div>
<div class="line">};</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line"> </div>
<div class="line"> <a class="code hl_class" href="classtf_1_1Executor.html">tf::Executor</a> executor;</div>
<div class="line"> <a class="code hl_class" href="classtf_1_1Taskflow.html">tf::Taskflow</a> taskflow(<span class="stringliteral">"software-release"</span>);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Project start time used to compute relative earliest-start values.</span></div>
<div class="line"> std::atomic<bool> started{<span class="keyword">false</span>};</div>
<div class="line"> std::chrono::steady_clock::time_point t0;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// ── define activities ───────────────────────────────────────────</span></div>
<div class="line"> <span class="comment">// Each activity sleeps for 'duration' units to simulate real work.</span></div>
<div class="line"> <span class="comment">// In a real project scheduler the lambda body would dispatch the</span></div>
<div class="line"> <span class="comment">// actual workload for that activity.</span></div>
<div class="line"> </div>
<div class="line"> Activity acts[] = {</div>
<div class="line"> {<span class="stringliteral">"A"</span>, 3}, {<span class="stringliteral">"B"</span>, 2}, {<span class="stringliteral">"C"</span>, 2}, {<span class="stringliteral">"D"</span>, 3},</div>
<div class="line"> {<span class="stringliteral">"E"</span>, 4}, {<span class="stringliteral">"F"</span>, 2}, {<span class="stringliteral">"G"</span>, 2}, {<span class="stringliteral">"H"</span>, 3}, {<span class="stringliteral">"I"</span>, 1}</div>
<div class="line"> };</div>
<div class="line"> </div>
<div class="line"> <span class="keyword">auto</span> make_task = [&](Activity& act) {</div>
<div class="line"> <span class="keywordflow">return</span> taskflow.emplace([&]() {</div>
<div class="line"> <span class="comment">// record the relative start time on first observation</span></div>
<div class="line"> act.earliest_start = <span class="keyword">static_cast<</span><span class="keywordtype">int</span><span class="keyword">></span>(</div>
<div class="line"> std::chrono::duration_cast<std::chrono::seconds>(</div>
<div class="line"> std::chrono::steady_clock::now() - t0).count());</div>
<div class="line"> std::this_thread::sleep_for(</div>
<div class="line"> std::chrono::seconds(act.duration)); <span class="comment">// simulate work</span></div>
<div class="line"> }).name(act.name);</div>
<div class="line"> };</div>
<div class="line"> </div>
<div class="line"> tf::Task A = make_task(acts[0]);</div>
<div class="line"> tf::Task B = make_task(acts[1]);</div>
<div class="line"> tf::Task C = make_task(acts[2]);</div>
<div class="line"> tf::Task D = make_task(acts[3]);</div>
<div class="line"> tf::Task E = make_task(acts[4]);</div>
<div class="line"> tf::Task F = make_task(acts[5]);</div>
<div class="line"> tf::Task G = make_task(acts[6]);</div>
<div class="line"> tf::Task H = make_task(acts[7]);</div>
<div class="line"> tf::Task I = make_task(acts[8]);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// ── wire precedence constraints ─────────────────────────────────</span></div>
<div class="line"> A.<a class="code hl_function" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(B, C); <span class="comment">// B and C both wait for A</span></div>
<div class="line"> B.<a class="code hl_function" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(D, F); <span class="comment">// D and F both wait for B</span></div>
<div class="line"> C.<a class="code hl_function" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(E); <span class="comment">// E waits for C</span></div>
<div class="line"> G.<a class="code hl_function" href="classtf_1_1Task.html#a331b1b726555072e7c7d10941257f664">succeed</a>(D, E, F); <span class="comment">// G waits for all three</span></div>
<div class="line"> H.<a class="code hl_function" href="classtf_1_1Task.html#a331b1b726555072e7c7d10941257f664">succeed</a>(G);</div>
<div class="line"> I.<a class="code hl_function" href="classtf_1_1Task.html#a331b1b726555072e7c7d10941257f664">succeed</a>(H);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// ── run ─────────────────────────────────────────────────────────</span></div>
<div class="line"> t0 = std::chrono::steady_clock::now();</div>
<div class="line"> executor.<a class="code hl_function" href="classtf_1_1Executor.html#a519777f5783981d534e9e53b99712069">run</a>(taskflow).wait();</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// ── report ──────────────────────────────────────────────────────</span></div>
<div class="line"> printf(<span class="stringliteral">"%-12s %8s %8s\n"</span>, <span class="stringliteral">"Activity"</span>, <span class="stringliteral">"ES(obs)"</span>, <span class="stringliteral">"ES(theory)"</span>);</div>
<div class="line"> <span class="keywordtype">int</span> theory[] = {0, 3, 3, 5, 5, 5, 9, 11, 14};</div>
<div class="line"> <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i < 9; i++) {</div>
<div class="line"> printf(<span class="stringliteral">"%-12s %8d %10d\n"</span>,</div>
<div class="line"> acts[i].name.c_str(), acts[i].earliest_start, theory[i]);</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="ttc" id="aclasstf_1_1Executor_html"><div class="ttname"><a href="classtf_1_1Executor.html">tf::Executor</a></div><div class="ttdoc">class to create an executor</div><div class="ttdef"><b>Definition</b> executor.hpp:62</div></div>
<div class="ttc" id="aclasstf_1_1Executor_html_a519777f5783981d534e9e53b99712069"><div class="ttname"><a href="classtf_1_1Executor.html#a519777f5783981d534e9e53b99712069">tf::Executor::run</a></div><div class="ttdeci">tf::Future< void > run(Taskflow &taskflow)</div><div class="ttdoc">runs a taskflow once</div></div>
<div class="ttc" id="aclasstf_1_1Task_html_a331b1b726555072e7c7d10941257f664"><div class="ttname"><a href="classtf_1_1Task.html#a331b1b726555072e7c7d10941257f664">tf::Task::succeed</a></div><div class="ttdeci">Task & succeed(Ts &&... tasks)</div><div class="ttdoc">adds precedence links from other tasks to this</div><div class="ttdef"><b>Definition</b> task.hpp:1266</div></div>
<div class="ttc" id="aclasstf_1_1Task_html_a8c78c453295a553c1c016e4062da8588"><div class="ttname"><a href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">tf::Task::precede</a></div><div class="ttdeci">Task & precede(Ts &&... tasks)</div><div class="ttdoc">adds precedence links from this to other tasks</div><div class="ttdef"><b>Definition</b> task.hpp:1258</div></div>
<div class="ttc" id="aclasstf_1_1Taskflow_html"><div class="ttname"><a href="classtf_1_1Taskflow.html">tf::Taskflow</a></div><div class="ttdoc">class to create a taskflow object</div><div class="ttdef"><b>Definition</b> taskflow.hpp:64</div></div>
</div><!-- fragment --><p>The expected output (with a 4-worker executor) is:</p>
<div class="fragment"><div class="line">Activity ES(obs) ES(theory)</div>
<div class="line">A 0 0</div>
<div class="line">B 3 3</div>
<div class="line">C 3 3</div>
<div class="line">D 5 5</div>
<div class="line">E 5 5</div>
<div class="line">F 5 5</div>
<div class="line">G 9 9</div>
<div class="line">H 11 11</div>
<div class="line">I 14 14</div>
</div><!-- fragment --><p>Observed earliest-start times match the theoretical values computed by the forward pass. B and C both start at t=3 on separate workers; D, E, and F all start at t=5 on separate workers; G is held until t=9 when the slowest of its three predecessors (E, finishing at t=9) completes.</p>
<p>The task graph that Taskflow constructs and executes is:</p>
<div class="dotgraph">
<iframe scrolling="no" frameborder="0" src="dot_pert_taskflow.svg" width="756" height="187"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<h1><a class="anchor" id="PERTDesignPoints"></a>
Design Points</h1>
<p>Several aspects of this example apply broadly to any static-dependency workflow, not just project scheduling:</p>
<ul>
<li>The PERT graph and the <a class="el" href="classtf_1_1Taskflow.html" title="class to create a taskflow object">tf::Taskflow</a> are the same object: There is no translation step between the project plan and the parallel program. The dependency edges written as <code>A.precede(B,C)</code>, <code>B.precede(D,F)</code>, and so on are simultaneously the project schedule and the task graph the executor runs. Adding, removing, or reordering a dependency changes both the logical plan and the runtime behaviour in a single edit.</li>
<li>Static construction gives the scheduler full visibility: All tasks and all edges are established before <code>executor.run</code> is called. The scheduler sees the complete graph from the start and can make globally informed decisions—for example, prioritising tasks on the critical path (A, C, E, G, H, I) over tasks with positive slack (B, D, F). A dynamic approach that spawned successors only as each task completed would deny the scheduler this global view, potentially leaving workers idle during the early steps when B, C, D, E, and F are all available.</li>
<li><code>succeed</code> is the mirror of <code>precede</code>, not a different concept: The line <code>G.succeed(D,E,F)</code> is exactly equivalent to writing <code>D.precede(G)</code>, <code>E.precede(G)</code>, <code>F.precede(G)</code> in three separate calls. Use whichever reads more naturally for the task at hand: <code>precede</code> is convenient when writing from a predecessor's perspective ("after me,
run these"), and <code>succeed</code> is convenient when writing from a successor's perspective ("before me, require these"). In a PERT chart, the join task G is the natural place to state its own prerequisites, so <code>succeed</code> reads more clearly there.</li>
<li>Task naming is load-bearing for diagnostics: Every task is given a human-readable name via <code></code>.name(). This name appears verbatim in <code>taskflow.dump()</code> (which emits a Graphviz-compatible description of the graph), in the Taskflow profiler timeline, and in any error or assertion messages. In a project-scheduling context, naming each task after its activity makes the profiler output directly interpretable as a Gantt chart, showing exactly which activities ran in parallel and where the critical path was actually observed.</li>
<li>Slack directly measures scheduling flexibility: Tasks B (slack=1), D (slack=1), and F (slack=2) can start later than their earliest start without delaying the project. In a real system, this slack translates directly to scheduling latitude: the executor can delay these tasks—for example, to co-locate them with other work on the same NUMA node—without violating the project deadline. Taskflow's work-stealing scheduler exploits this implicitly: it will pick up B, D, or F whenever a worker becomes free, without the programmer having to annotate priorities or affinities manually.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This example uses <code>std::this_thread::sleep_for</code> to simulate task durations, which is appropriate for illustrating scheduling behaviour but not for production use. In a real project executor, each task lambda would dispatch the actual computational work for that activity—compiling a source file, running a test suite, transferring a dataset—and the sleep would be replaced by that work. The dependency wiring and scheduling logic remain identical regardless of what the task bodies actually do. </dd></dl>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.13.1-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="Examples.html">Learning from Examples</a></li>
<li class="footer">
Maintained by <a href="https://tsung-wei-huang.github.io/">Dr. Tsung-Wei Huang</a>
—
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.13.1
</li>
</ul>
</div>