You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
<p>The class provides essential methods to construct a task dependency graph from which <ahref="classtf_1_1Taskflow.html" class="m-doc">tf::<wbr/>Taskflow</a> and <ahref="classtf_1_1Subflow.html" class="m-doc">tf::<wbr/>Subflow</a> are derived.</p>
P part = P()) -> <ahref="classtf_1_1Task.html" class="m-doc">Task</a></span>
</dt>
<dd>constructs a parallel-transform task</dd>
<dt>
<divclass="m-doc-template">template<typename B, typename E, typename T, typename O, typename P = <ahref="namespacetf.html#ace2c5adcd5039483eebb6dbdbb6f33e3" class="m-doc">DefaultPartitioner</a>></div>
E last) -> <ahref="classtf_1_1Task.html" class="m-doc">Task</a></span>
</dt>
<dd>constructs a dynamic task to perform STL-styled parallel sort using the <code>std::less<T></code> comparator, where <code>T</code> is the element type</dd>
<td>callable type constructible from <ahref="http://en.cppreference.com/w/cpp/utility/functional/function.html" class="m-doc-external">std::<wbr/>function<void()></a></td>
<p>The following example creates a static task.</p><preclass="m-code"><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Task</span><spanclass="w"></span><spanclass="n">static_task</span><spanclass="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="n">taskflow</span><spanclass="p">.</span><spanclass="n">emplace</span><spanclass="p">([](){});</span></pre><p>Please refer to <ahref="StaticTasking.html" class="m-doc">Static Tasking</a> for details.</p>
<td>callable type constructible from <ahref="http://en.cppreference.com/w/cpp/utility/functional/function.html" class="m-doc-external">std::<wbr/>function<void(tf::<wbr/>Runtime&)></a></td>
<p>The following example creates a runtime task.</p><preclass="m-code"><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Task</span><spanclass="w"></span><spanclass="n">static_task</span><spanclass="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="n">taskflow</span><spanclass="p">.</span><spanclass="n">emplace</span><spanclass="p">([](</span><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Runtime</span><spanclass="o">&</span><spanclass="p">){});</span></pre><p>Please refer to <ahref="RuntimeTasking.html" class="m-doc">Interact with the Runtime</a> for details.</p>
<td>callable type constructible from <ahref="http://en.cppreference.com/w/cpp/utility/functional/function.html" class="m-doc-external">std::<wbr/>function<void(tf::<wbr/>Subflow&)></a></td>
<p>The following example creates a dynamic task (<ahref="classtf_1_1Subflow.html" class="m-doc">tf::<wbr/>Subflow</a>) that spawns two static tasks.</p><preclass="m-code"><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Task</span><spanclass="w"></span><spanclass="n">dynamic_task</span><spanclass="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="n">taskflow</span><spanclass="p">.</span><spanclass="n">emplace</span><spanclass="p">([](</span><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Subflow</span><spanclass="o">&</span><spanclass="w"></span><spanclass="n">sf</span><spanclass="p">){</span>
<td>callable type constructible from <ahref="http://en.cppreference.com/w/cpp/utility/functional/function.html" class="m-doc-external">std::<wbr/>function<int()></a></td>
<p>The following example creates an if-else block using one condition task and three static tasks.</p><preclass="m-code"><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Taskflow</span><spanclass="w"></span><spanclass="n">taskflow</span><spanclass="p">;</span>
<spanclass="n">cond</span><spanclass="p">.</span><spanclass="n">succeed</span><spanclass="p">(</span><spanclass="n">init</span><spanclass="p">);</span></pre><p>Please refer to <ahref="ConditionalTasking.html" class="m-doc">Conditional Tasking</a> for details.</p>
<td>callable type constructible from <ahref="http://en.cppreference.com/w/cpp/utility/functional/function.html" class="m-doc-external">std::<wbr/>function</a><tf::SmallVector<int>()></td>
</tr>
</tbody>
<thead>
<tr><thcolspan="2">Parameters</th></tr>
</thead>
<tbody>
<tr>
<td>callable</td>
<td>callable to construct a multi-condition task</td>
<p>The following example creates a multi-condition task that selectively jumps to two successor tasks.</p><preclass="m-code"><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Taskflow</span><spanclass="w"></span><spanclass="n">taskflow</span><spanclass="p">;</span>
<spanclass="n">cond</span><spanclass="p">.</span><spanclass="n">succeed</span><spanclass="p">(</span><spanclass="n">init</span><spanclass="p">);</span></pre><p>Please refer to <ahref="ConditionalTasking.html" class="m-doc">Conditional Tasking</a> for details.</p>
<p>The method returns a tuple of tasks each corresponding to the given callable target. You can use structured binding to get the return tasks one by one. The following example creates four static tasks and assign them to <code>A</code>, <code>B</code>, <code>C</code>, and <code>D</code> using structured binding.</p><preclass="m-code"><spanclass="k">auto</span><spanclass="w"></span><spanclass="p">[</span><spanclass="n">A</span><spanclass="p">,</span><spanclass="w"></span><spanclass="n">B</span><spanclass="p">,</span><spanclass="w"></span><spanclass="n">C</span><spanclass="p">,</span><spanclass="w"></span><spanclass="n">D</span><spanclass="p">]</span><spanclass="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="n">taskflow</span><spanclass="p">.</span><spanclass="n">emplace</span><spanclass="p">(</span>
<p>Removes a task and its input and output dependencies from the graph associated with the flow builder. If the task does not belong to the graph, nothing will happen.</p><preclass="m-code"><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Task</span><spanclass="w"></span><spanclass="n">A</span><spanclass="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="n">taskflow</span><spanclass="p">.</span><spanclass="n">emplace</span><spanclass="p">([](){</span><spanclass="w"></span><spanclass="n">std</span><spanclass="o">::</span><spanclass="n">cout</span><spanclass="w"></span><spanclass="o"><<</span><spanclass="w"></span><spanclass="s">"A"</span><spanclass="p">;</span><spanclass="w"></span><spanclass="p">});</span>
<p>The example below demonstrates a taskflow composition using the <code>composed_of</code> method.</p><preclass="m-code"><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Taskflow</span><spanclass="w"></span><spanclass="n">t1</span><spanclass="p">,</span><spanclass="w"></span><spanclass="n">t2</span><spanclass="p">;</span>
<spanclass="n">init</span><spanclass="p">.</span><spanclass="n">precede</span><spanclass="p">(</span><spanclass="n">comp</span><spanclass="p">);</span></pre><p>The taskflow object <code>t2</code> is composed of another taskflow object <code>t1</code>, preceded by another static task <code>init</code>. When taskflow <code>t2</code> is submitted to an executor, <code>init</code> will run first and then <code>comp</code> which spawns its definition in taskflow <code>t1</code>.</p><p>The target <code>object</code> being composed must define the method <code>T::graph()</code> that returns a reference to a graph object of type <ahref="classtf_1_1Graph.html" class="m-doc">tf::<wbr/>Graph</a> such that it can interact with the executor. For example:</p><preclass="m-code"><spanclass="c1">// custom struct</span>
<spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Task</span><spanclass="w"></span><spanclass="n">comp</span><spanclass="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="n">taskflow</span><spanclass="p">.</span><spanclass="n">composed_of</span><spanclass="p">(</span><spanclass="n">obj</span><spanclass="p">);</span></pre><p>Please refer to <ahref="ComposableTasking.html" class="m-doc">Composable Tasking</a> for details.</p>
<p>A placeholder task maps to a node in the taskflow graph, but it does not have any callable work assigned yet. A placeholder task is different from an empty task handle that does not point to any node in a graph.</p><preclass="m-code"><spanclass="c1">// create a placeholder task with no callable target assigned</span>
<p>adds adjacent dependency links to a linear list of tasks</p>
<tableclass="m-table m-fullwidth m-flat">
<thead>
<tr><thcolspan="2">Parameters</th></tr>
</thead>
<tbody>
<tr>
<tdstyle="width: 1%">tasks</td>
<td>a vector of tasks</td>
</tr>
</tbody>
</table>
<p>This member function creates linear dependencies over a vector of tasks.</p><preclass="m-code"><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Task</span><spanclass="w"></span><spanclass="n">A</span><spanclass="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="n">taskflow</span><spanclass="p">.</span><spanclass="n">emplace</span><spanclass="p">([](){</span><spanclass="w"></span><spanclass="n">std</span><spanclass="o">::</span><spanclass="n">cout</span><spanclass="w"></span><spanclass="o"><<</span><spanclass="w"></span><spanclass="s">"A"</span><spanclass="p">;</span><spanclass="w"></span><spanclass="p">});</span>
<p>adds adjacent dependency links to a linear list of tasks</p>
<tableclass="m-table m-fullwidth m-flat">
<thead>
<tr><thcolspan="2">Parameters</th></tr>
</thead>
<tbody>
<tr>
<tdstyle="width: 1%">tasks</td>
<td>an initializer list of tasks</td>
</tr>
</tbody>
</table>
<p>This member function creates linear dependencies over a list of tasks.</p><preclass="m-code"><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">Task</span><spanclass="w"></span><spanclass="n">A</span><spanclass="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="n">taskflow</span><spanclass="p">.</span><spanclass="n">emplace</span><spanclass="p">([](){</span><spanclass="w"></span><spanclass="n">std</span><spanclass="o">::</span><spanclass="n">cout</span><spanclass="w"></span><spanclass="o"><<</span><spanclass="w"></span><spanclass="s">"A"</span><spanclass="p">;</span><spanclass="w"></span><spanclass="p">});</span>
<p>The task spawns asynchronous tasks that applies the callable object to each object obtained by dereferencing every iterator in the range <code>[first, last)</code>. This method is equivalent to the parallel execution of the following loop:</p><preclass="m-code"><spanclass="k">for</span><spanclass="p">(</span><spanclass="k">auto</span><spanclass="w"></span><spanclass="n">itr</span><spanclass="o">=</span><spanclass="n">first</span><spanclass="p">;</span><spanclass="w"></span><spanclass="n">itr</span><spanclass="o">!=</span><spanclass="n">last</span><spanclass="p">;</span><spanclass="w"></span><spanclass="n">itr</span><spanclass="o">++</span><spanclass="p">)</span><spanclass="w"></span><spanclass="p">{</span>
<spanclass="p">}</span></pre><p>Iterators can be made stateful by using <ahref="http://en.cppreference.com/w/cpp/utility/functional/reference_wrapper.html" class="m-doc-external">std::<wbr/>reference_wrapper</a> The callable needs to take a single argument of the dereferenced iterator type.</p><p>Please refer to <ahref="ParallelIterations.html" class="m-doc">Parallel Iterations</a> for details.</p>
<p>The task spawns asynchronous tasks that applies the callable object to each index in the range <code>[first, last)</code> with the step size. This method is equivalent to the parallel execution of the following loop:</p><preclass="m-code"><spanclass="c1">// case 1: step size is positive</span>
<spanclass="p">}</span></pre><p>Iterators can be made stateful by using <ahref="http://en.cppreference.com/w/cpp/utility/functional/reference_wrapper.html" class="m-doc-external">std::<wbr/>reference_wrapper</a> The callable needs to take a single argument of the integral index type.</p><p>Please refer to <ahref="ParallelIterations.html" class="m-doc">Parallel Iterations</a> for details.</p>
<p>The task spawns asynchronous tasks that applies the callable object to in the range <code>[first, last)</code> with the step size.</p><preclass="m-code"><spanclass="c1">// [0, 17) with a step size of 2 using tf::IndexRange</span>
<spanclass="n">executor</span><spanclass="p">.</span><spanclass="n">run</span><spanclass="p">(</span><spanclass="n">taskflow</span><spanclass="p">).</span><spanclass="n">wait</span><spanclass="p">();</span></pre><p>The callable needs to take a single argument of type <ahref="classtf_1_1IndexRange.html" class="m-doc">tf::<wbr/>IndexRange</a>.</p><p>Please refer to <ahref="ParallelIterations.html" class="m-doc">Parallel Iterations</a> for details.</p>