-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathScalableTaskParallelPipeline.html
More file actions
288 lines (286 loc) · 27.7 KB
/
Copy pathScalableTaskParallelPipeline.html
File metadata and controls
288 lines (286 loc) · 27.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
<!-- 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: Scalable Task-parallel Pipeline</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('ScalableTaskParallelPipeline.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">Scalable Task-parallel Pipeline</div></div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul>
<li class="level1">
<a href="#IncludeTheScalablePipelineHeader">Include the Header</a>
</li>
<li class="level1">
<a href="#CreateAScalablePipelineModuleTask">Create a Scalable Pipeline Module Task</a>
</li>
<li class="level1">
<a href="#ResetAPlaceholderScalablePipeline">Reset a Placeholder Scalable Pipeline</a>
</li>
<li class="level1">
<a href="#ScalablePipelineUseOtherIteratorTypes">Use Other Iterator Types</a>
</li>
</ul>
</div>
<div class="textblock"><p>Unlike <a class="el" href="classtf_1_1Pipeline.html" title="class to create a pipeline scheduling framework">tf::Pipeline</a> (see <a class="el" href="TaskParallelPipeline.html">Task-parallel Pipeline</a>) that instantiates all pipes at the construction time, Taskflow provides a scalable alternative called <a class="el" href="classtf_1_1ScalablePipeline.html" title="class to create a scalable pipeline object">tf::ScalablePipeline</a> to allow variable assignments of pipes using range iterators. A scalable pipeline is thus more flexible for applications to create a pipeline scheduling framework whose pipeline structure depends on runtime variables.</p>
<h1><a class="anchor" id="IncludeTheScalablePipelineHeader"></a>
Include the Header</h1>
<p>You need to include the header file, <code>taskflow/algorithm/pipeline.hpp</code>, for creating a scalable pipeline scheduling framework.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include <taskflow/algorithm/pipeline.hpp></span></div>
</div><!-- fragment --><h1><a class="anchor" id="CreateAScalablePipelineModuleTask"></a>
Create a Scalable Pipeline Module Task</h1>
<p>Similar to <a class="el" href="classtf_1_1Pipeline.html" title="class to create a pipeline scheduling framework">tf::Pipeline</a>, <a class="el" href="classtf_1_1ScalablePipeline.html" title="class to create a scalable pipeline object">tf::ScalablePipeline</a> is a composable graph object to implement a <em>pipeline scheduling framework</em> in a taskflow. The key difference between <a class="el" href="classtf_1_1Pipeline.html" title="class to create a pipeline scheduling framework">tf::Pipeline</a> and <a class="el" href="classtf_1_1ScalablePipeline.html" title="class to create a scalable pipeline object">tf::ScalablePipeline</a> is that a scalable pipeline can accept <em>variable</em> assignments of pipes rather than instantiating all pipes at construction or programming time. Users define a linear range of pipes, each of the same callable type, and apply that range to construct a scalable pipeline. Between successive runs, users can reset the pipeline to a different range of pipes. The following code creates a scalable pipeline that uses four parallel lines to schedule tokens through three serial pipes in the given vector, then resetting that pipeline to a new range of five serial pipes:</p>
<div class="fragment"><div class="line"><a class="code hl_class" href="classtf_1_1Taskflow.html">tf::Taskflow</a> taskflow(<span class="stringliteral">"pipeline"</span>);</div>
<div class="line"><a class="code hl_class" href="classtf_1_1Executor.html">tf::Executor</a> executor;</div>
<div class="line"> </div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">size_t</span> num_lines = 4;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// create data storage</span></div>
<div class="line">std::array<int, num_lines> buffer;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// define the pipe callable</span></div>
<div class="line"><span class="keyword">auto</span> pipe_callable = [&buffer] (<a class="code hl_class" href="classtf_1_1Pipeflow.html">tf::Pipeflow</a>& pf) <span class="keyword">mutable</span> {</div>
<div class="line"> <span class="keywordflow">switch</span>(pf.pipe()) {</div>
<div class="line"> <span class="comment">// first stage generates only 5 scheduling tokens and saves the </span></div>
<div class="line"> <span class="comment">// token number into the buffer.</span></div>
<div class="line"> <span class="keywordflow">case</span> 0: {</div>
<div class="line"> <span class="keywordflow">if</span>(pf.token() == 5) {</div>
<div class="line"> pf.stop();</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">else</span> {</div>
<div class="line"> printf(<span class="stringliteral">"stage 1: input token = %zu\n"</span>, pf.token());</div>
<div class="line"> buffer[pf.line()] = pf.token();</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">return</span>;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// other stages propagate the previous result to this pipe and</span></div>
<div class="line"> <span class="comment">// increment it by one</span></div>
<div class="line"> <span class="keywordflow">default</span>: {</div>
<div class="line"> printf(</div>
<div class="line"> <span class="stringliteral">"stage %zu: input buffer[%zu] = %d\n"</span>, pf.pipe(), pf.line(), buffer[pf.line()]</div>
<div class="line"> );</div>
<div class="line"> buffer[pf.line()] = buffer[pf.line()] + 1;</div>
<div class="line"> } </div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> }</div>
<div class="line">};</div>
<div class="line"> </div>
<div class="line"><span class="comment">// create a vector of three pipes</span></div>
<div class="line">std::vector< tf::Pipe<std::function<void(tf::Pipeflow&)>> > pipes;</div>
<div class="line"> </div>
<div class="line"><span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i=0; i<3; i++) {</div>
<div class="line"> pipes.emplace_back(<a class="code hl_enumvalue" href="namespacetf.html#abb7a11e41fd457f69e7ff45d4c769564a7b804a28d6154ab8007287532037f1d0">tf::PipeType::SERIAL</a>, pipe_callable);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">// create a pipeline of four parallel lines based on the given vector of pipes</span></div>
<div class="line">tf::ScalablePipeline pl(num_lines, pipes.begin(), pipes.end());</div>
<div class="line"> </div>
<div class="line"><span class="comment">// build the pipeline graph using composition</span></div>
<div class="line">tf::Task init = taskflow.emplace([](){ std::cout << <span class="stringliteral">"ready\n"</span>; })</div>
<div class="line"> .name(<span class="stringliteral">"starting pipeline"</span>);</div>
<div class="line">tf::Task task = taskflow.composed_of(pl)</div>
<div class="line"> .name(<span class="stringliteral">"pipeline"</span>);</div>
<div class="line">tf::Task stop = taskflow.emplace([](){ std::cout << <span class="stringliteral">"stopped\n"</span>; })</div>
<div class="line"> .name(<span class="stringliteral">"pipeline stopped"</span>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// create task dependency</span></div>
<div class="line">init.<a class="code hl_function" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(task);</div>
<div class="line">task.<a class="code hl_function" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(stop);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// dump the pipeline graph structure (with composition)</span></div>
<div class="line">taskflow.<a class="code hl_function" href="classtf_1_1Task.html#a3318a49ff9d0a01cd1e8ee675251e3b7">dump</a>(std::cout);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// run the pipeline</span></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">// reset the pipeline to a new range of five pipes and starts from</span></div>
<div class="line"><span class="comment">// the initial state (i.e., token counts from zero)</span></div>
<div class="line"><span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i=0; i<2; i++) {</div>
<div class="line"> pipes.emplace_back(<a class="code hl_enumvalue" href="namespacetf.html#abb7a11e41fd457f69e7ff45d4c769564a7b804a28d6154ab8007287532037f1d0">tf::PipeType::SERIAL</a>, pipe_callable);</div>
<div class="line">}</div>
<div class="line">pl.reset(pipes.begin(), pipes.end());</div>
<div class="line"> </div>
<div class="line">executor.<a class="code hl_function" href="classtf_1_1Executor.html#a519777f5783981d534e9e53b99712069">run</a>(taskflow).wait();</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_1Pipeflow_html"><div class="ttname"><a href="classtf_1_1Pipeflow.html">tf::Pipeflow</a></div><div class="ttdoc">class to create a pipeflow object used by the pipe callable</div><div class="ttdef"><b>Definition</b> pipeline.hpp:43</div></div>
<div class="ttc" id="aclasstf_1_1Task_html_a3318a49ff9d0a01cd1e8ee675251e3b7"><div class="ttname"><a href="classtf_1_1Task.html#a3318a49ff9d0a01cd1e8ee675251e3b7">tf::Task::dump</a></div><div class="ttdeci">void dump(std::ostream &ostream) const</div><div class="ttdoc">dumps the task through an output stream</div><div class="ttdef"><b>Definition</b> task.hpp:1482</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 class="ttc" id="anamespacetf_html_abb7a11e41fd457f69e7ff45d4c769564a7b804a28d6154ab8007287532037f1d0"><div class="ttname"><a href="namespacetf.html#abb7a11e41fd457f69e7ff45d4c769564a7b804a28d6154ab8007287532037f1d0">tf::PipeType::SERIAL</a></div><div class="ttdeci">@ SERIAL</div><div class="ttdoc">serial type</div><div class="ttdef"><b>Definition</b> pipeline.hpp:117</div></div>
</div><!-- fragment --><p>The program defines a uniform pipe type of <code>tf::Pipe<std::function<void(tf::Pipeflow&)>></code> and keep all pipes in a vector that is amenable to change. Then, it constructs a scalable pipeline using two range iterators, <code>[first, last)</code>, that point to the beginning and the end of the pipe vector, resulting in a pipeline of three serial stages:</p>
<div class="dotgraph">
<iframe scrolling="no" frameborder="0" src="dot_scalable_pipeline_1.svg" width="376" height="390"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<p>Then, the program appends another two pipes into the vector and resets the pipeline to the new range of two additional pipes, resulting in a pipeline of five serial stages:</p>
<div class="dotgraph">
<iframe scrolling="no" frameborder="0" src="dot_scalable_pipeline_2.svg" width="608" height="390"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<p>When resetting a scalable pipeline to a new range, it will start from the initial state as if it has just been constructed, i.e., the token number counts from zero.</p>
<dl class="section note"><dt>Note</dt><dd>Unlike <a class="el" href="classtf_1_1Pipeline.html" title="class to create a pipeline scheduling framework">tf::Pipeline</a> that keeps the given pipes in a std::tuple object, <a class="el" href="classtf_1_1ScalablePipeline.html" title="class to create a scalable pipeline object">tf::ScalablePipeline</a> does not own the given pipe but maintains a vector of iterators to each pipe in the given range. It is your responsibility to keep those pipe objects alive during the execution of the pipeline task.</dd></dl>
<h1><a class="anchor" id="ResetAPlaceholderScalablePipeline"></a>
Reset a Placeholder Scalable Pipeline</h1>
<p>It is possible to create a scalable pipeline as a placeholder using the constructor <a class="el" href="classtf_1_1ScalablePipeline.html" title="class to create a scalable pipeline object">tf::ScalablePipeline(size_t num_lines)</a> and reset it to another range later in the application. The following code creates a task to emplace a range of pipes and reset the pipeline to that range, before running the pipeline task:</p>
<div class="fragment"><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;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">size_t</span> num_pipes = 10;</div>
<div class="line"><span class="keywordtype">size_t</span> num_lines = 10;</div>
<div class="line"> </div>
<div class="line">std::vector<<a class="code hl_class" href="classtf_1_1Pipe.html">tf::Pipe</a><std::function<void(<a class="code hl_class" href="classtf_1_1Pipeflow.html">tf::Pipeflow</a>&)>>> pipes;</div>
<div class="line"><a class="code hl_class" href="classtf_1_1ScalablePipeline.html">tf::ScalablePipeline</a><<span class="keyword">typename</span> <span class="keyword">decltype</span>(pipes)::iterator> spl(num_lines); </div>
<div class="line"> </div>
<div class="line"><a class="code hl_class" href="classtf_1_1Task.html">tf::Task</a> init = taskflow.<a class="code hl_function" href="classtf_1_1FlowBuilder.html#a4d52a7fe2814b264846a2085e931652c">emplace</a>([&](){</div>
<div class="line"> <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i=0; i<num_pipes; i++) {</div>
<div class="line"> pipes.emplace_back(<a class="code hl_enumvalue" href="namespacetf.html#abb7a11e41fd457f69e7ff45d4c769564a7b804a28d6154ab8007287532037f1d0">tf::PipeType::SERIAL</a>, [&](<a class="code hl_class" href="classtf_1_1Pipeflow.html">tf::Pipeflow</a>& pf) { </div>
<div class="line"> <span class="keywordflow">if</span>(pf.<a class="code hl_function" href="classtf_1_1Pipeflow.html#a4914c1f381a3016e98285b019cf60d6d">pipe</a>() == 0 && pf.<a class="code hl_function" href="classtf_1_1Pipeflow.html#a295e5d884665c076f4ef5d78139f7c51">token</a>() == 1024) {</div>
<div class="line"> pf.<a class="code hl_function" href="classtf_1_1Pipeflow.html#a830b7f204cb87fff17e8d424918d9453">stop</a>();</div>
<div class="line"> <span class="keywordflow">return</span>;</div>
<div class="line"> }</div>
<div class="line"> });</div>
<div class="line"> }</div>
<div class="line"> spl.reset(pipes.begin(), pipes.end());</div>
<div class="line">}).name(<span class="stringliteral">"init"</span>);</div>
<div class="line"> </div>
<div class="line">tf::Task pipeline = taskflow.<a class="code hl_function" href="classtf_1_1FlowBuilder.html#ac6f22228d4c2ea2e643c4b0d42c0e92a">composed_of</a>(spl).<a class="code hl_function" href="classtf_1_1Task.html#a08ada0425b490997b6ff7f310107e5e3">name</a>(<span class="stringliteral">"pipeline"</span>);</div>
<div class="line">pipeline.<a class="code hl_function" href="classtf_1_1Task.html#a331b1b726555072e7c7d10941257f664">succeed</a>(init);</div>
<div class="line">executor.<a class="code hl_function" href="classtf_1_1Executor.html#a519777f5783981d534e9e53b99712069">run</a>(taskflow).wait(); </div>
<div class="ttc" id="aclasstf_1_1FlowBuilder_html_a4d52a7fe2814b264846a2085e931652c"><div class="ttname"><a href="classtf_1_1FlowBuilder.html#a4d52a7fe2814b264846a2085e931652c">tf::FlowBuilder::emplace</a></div><div class="ttdeci">Task emplace(C &&callable)</div><div class="ttdoc">creates a static task</div><div class="ttdef"><b>Definition</b> flow_builder.hpp:1571</div></div>
<div class="ttc" id="aclasstf_1_1FlowBuilder_html_ac6f22228d4c2ea2e643c4b0d42c0e92a"><div class="ttname"><a href="classtf_1_1FlowBuilder.html#ac6f22228d4c2ea2e643c4b0d42c0e92a">tf::FlowBuilder::composed_of</a></div><div class="ttdeci">Task composed_of(T &object)</div><div class="ttdoc">creates a module task for the target object</div><div class="ttdef"><b>Definition</b> flow_builder.hpp:1621</div></div>
<div class="ttc" id="aclasstf_1_1Pipe_html"><div class="ttname"><a href="classtf_1_1Pipe.html">tf::Pipe</a></div><div class="ttdoc">class to create a pipe object for a pipeline stage</div><div class="ttdef"><b>Definition</b> pipeline.hpp:144</div></div>
<div class="ttc" id="aclasstf_1_1Pipeflow_html_a295e5d884665c076f4ef5d78139f7c51"><div class="ttname"><a href="classtf_1_1Pipeflow.html#a295e5d884665c076f4ef5d78139f7c51">tf::Pipeflow::token</a></div><div class="ttdeci">size_t token() const</div><div class="ttdoc">queries the token identifier</div><div class="ttdef"><b>Definition</b> pipeline.hpp:78</div></div>
<div class="ttc" id="aclasstf_1_1Pipeflow_html_a4914c1f381a3016e98285b019cf60d6d"><div class="ttname"><a href="classtf_1_1Pipeflow.html#a4914c1f381a3016e98285b019cf60d6d">tf::Pipeflow::pipe</a></div><div class="ttdeci">size_t pipe() const</div><div class="ttdoc">queries the pipe identifier of the present token</div><div class="ttdef"><b>Definition</b> pipeline.hpp:71</div></div>
<div class="ttc" id="aclasstf_1_1Pipeflow_html_a830b7f204cb87fff17e8d424918d9453"><div class="ttname"><a href="classtf_1_1Pipeflow.html#a830b7f204cb87fff17e8d424918d9453">tf::Pipeflow::stop</a></div><div class="ttdeci">void stop()</div><div class="ttdoc">stops the pipeline scheduling</div><div class="ttdef"><b>Definition</b> pipeline.hpp:88</div></div>
<div class="ttc" id="aclasstf_1_1ScalablePipeline_html"><div class="ttname"><a href="classtf_1_1ScalablePipeline.html">tf::ScalablePipeline</a></div><div class="ttdoc">class to create a scalable pipeline object</div><div class="ttdef"><b>Definition</b> pipeline.hpp:775</div></div>
<div class="ttc" id="aclasstf_1_1Task_html"><div class="ttname"><a href="classtf_1_1Task.html">tf::Task</a></div><div class="ttdoc">class to create a task handle over a taskflow node</div><div class="ttdef"><b>Definition</b> task.hpp:569</div></div>
<div class="ttc" id="aclasstf_1_1Task_html_a08ada0425b490997b6ff7f310107e5e3"><div class="ttname"><a href="classtf_1_1Task.html#a08ada0425b490997b6ff7f310107e5e3">tf::Task::name</a></div><div class="ttdeci">const std::string & name() const</div><div class="ttdoc">queries the name of the task</div><div class="ttdef"><b>Definition</b> task.hpp:1388</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><!-- fragment --><p>The task graph of this program is shown below:</p>
<div class="dotgraph">
<iframe scrolling="no" frameborder="0" src="dot_scalable_pipeline_3.svg" width="1142" height="252"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<dl class="section note"><dt>Note</dt><dd>It is your responsibility to ensure a scalable pipeline has a valid structure before running it. A valid pipeline must have at least one parallel line and one pipe, where the first pipe is a serial type.</dd></dl>
<p>Similarly, you can create an empty scalable pipeline using the default constructor <a class="el" href="classtf_1_1ScalablePipeline.html" title="class to create a scalable pipeline object">tf::ScalablePipeline()</a> and reset it later in your program.</p>
<div class="fragment"><div class="line">std::vector<<a class="code hl_class" href="classtf_1_1Pipe.html">tf::Pipe</a><std::function<void(<a class="code hl_class" href="classtf_1_1Pipeflow.html">tf::Pipeflow</a>&)>>> pipes;</div>
<div class="line"><a class="code hl_class" href="classtf_1_1ScalablePipeline.html">tf::ScalablePipeline</a><<span class="keyword">typename</span> <span class="keyword">decltype</span>(pipes)::iterator> spl; </div>
<div class="line"><span class="comment">// create pipes ...</span></div>
<div class="line">spl.<a class="code hl_function" href="classtf_1_1ScalablePipeline.html#a940a8de7b53ac5cbd59c55091d88c88f">reset</a>(num_lines, pipes.begin(), pipes.end());</div>
<div class="ttc" id="aclasstf_1_1ScalablePipeline_html_a940a8de7b53ac5cbd59c55091d88c88f"><div class="ttname"><a href="classtf_1_1ScalablePipeline.html#a940a8de7b53ac5cbd59c55091d88c88f">tf::ScalablePipeline::reset</a></div><div class="ttdeci">void reset()</div><div class="ttdoc">resets the pipeline</div><div class="ttdef"><b>Definition</b> pipeline.hpp:1084</div></div>
</div><!-- fragment --><h1><a class="anchor" id="ScalablePipelineUseOtherIteratorTypes"></a>
Use Other Iterator Types</h1>
<p>When assigning a range to a scalable pipeline, the pipeline fetches all pipe iterators in that range to an internal vector. This organization allows invoking a pipe callable to be a random accessible operation, regardless of the pipe container type. Taskflow does not have much restriction on the iterator type, as long as these pipes can be iterated in a sequential order using the postfix increment operator, <code>++</code>.</p>
<div class="fragment"><div class="line"><span class="comment">// use vector to store pipes</span></div>
<div class="line">std::vector<<a class="code hl_class" href="classtf_1_1Pipe.html">tf::Pipe</a><std::function<void(<a class="code hl_class" href="classtf_1_1Pipeflow.html">tf::Pipeflow</a>&)>>> vector;</div>
<div class="line"><a class="code hl_class" href="classtf_1_1ScalablePipeline.html">tf::ScalablePipeline</a> spl1(num_lines, vector.begin(), vector.end());</div>
<div class="line"> </div>
<div class="line"><span class="comment">// use list to store pipes</span></div>
<div class="line">std::list<<a class="code hl_class" href="classtf_1_1Pipe.html">tf::Pipe</a><std::function<void(<a class="code hl_class" href="classtf_1_1Pipeflow.html">tf::Pipeflow</a>&)>>> list;</div>
<div class="line"><a class="code hl_class" href="classtf_1_1ScalablePipeline.html">tf::ScalablePipeline</a> spl2(num_lines, list.begin(), list.end());</div>
</div><!-- fragment --> </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="Algorithms.html">Taskflow Algorithms</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>