Skip to content

Commit de76e84

Browse files
committed
before pull
1 parent 16fb321 commit de76e84

32 files changed

Lines changed: 277 additions & 109 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ both academic and industrial research projects in parallel
406406
and heterogeneous computing.
407407
If you are using Taskflow, please cite the following paper we publised at 2021 IEEE TPDS:
408408

409-
+ Tsung-Wei Huang, Dian-Lun Lin, Chun-Xun Lin, and Yibo Lin, &quot;[Taskflow: A Lightweight Parallel and Heterogeneous Task Graph Computing System](https://tsung-wei-huang.github.io/papers/tpds21-taskflow.pdf),&quot; <i>IEEE Transactions on Parallel and Distributed Systems (TPDS)</i>, accepted, 2021
409+
+ Tsung-Wei Huang, Dian-Lun Lin, Chun-Xun Lin, and Yibo Lin, &quot;[Taskflow: A Lightweight Parallel and Heterogeneous Task Graph Computing System](https://tsung-wei-huang.github.io/papers/tpds21-taskflow.pdf),&quot; <i>IEEE Transactions on Parallel and Distributed Systems (TPDS)</i>, vol. 33, no. 6, pp. 1303-1320, June 2022
410410

411411
More importantly, we appreciate all Taskflow [contributors][contributors] and
412412
the following organizations for sponsoring the Taskflow project!

benchmarks/reduce_sum/taskflow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "reduce_sum.hpp"
22
#include <taskflow/taskflow.hpp>
3+
#include <taskflow/algorithm/reduce.hpp>
34

45
void reduce_sum_taskflow(unsigned num_threads) {
56

docs/ComposableTasking.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ <h3>Contents</h3>
5454
<ul>
5555
<li><a href="#ComposeATaskflow">Compose a Taskflow</a></li>
5656
<li><a href="#CreateAModuleTask">Create a Module Task</a></li>
57+
<li><a href="#CreateACustomComposableGraph">Create a Custom Composable Graph</a></li>
5758
</ul>
5859
</div>
5960
<p>Composition is a key to improve the programmability of a complex workflow. This chapter describes how to create a large parallel graph through composition of modular and reusable blocks that are easier to optimize.</p><section id="ComposeATaskflow"><h2><a href="#ComposeATaskflow">Compose a Taskflow</a></h2><p>A powerful feature of <a href="classtf_1_1Taskflow.html" class="m-doc">tf::<wbr />Taskflow</a> is its <em>composable</em> interface. You can break down a large parallel workload into smaller pieces each designed to run a specific task dependency graph. This largely facilitates the <em>modularity</em> of writing a parallel task program.</p><pre class="m-code"> <span class="mi">1</span><span class="o">:</span> <span class="c1">// f1 has three independent tasks</span>
@@ -386,7 +387,20 @@ <h3>Contents</h3>
386387
</g>
387388
</g>
388389
</svg>
389-
</div></section>
390+
</div></section><section id="CreateACustomComposableGraph"><h2><a href="#CreateACustomComposableGraph">Create a Custom Composable Graph</a></h2><p>Taskflow allows you to create a custom graph object that can participate in the scheduling using composition. To become a module task, your class <code>T</code> must define a method <code>T::graph()</code> that returns a reference to a <a href="classtf_1_1Graph.html" class="m-doc">tf::<wbr />Graph</a> object. The following example defines a custom graph object that can be assembled in a taskflow throw composition:</p><pre class="m-code"> <span class="mi">1</span><span class="o">:</span> <span class="k">struct</span> <span class="nc">CustomGraph</span> <span class="p">{</span>
391+
<span class="mi">2</span><span class="o">:</span> <span class="n">tf</span><span class="o">::</span><span class="n">Graph</span> <span class="n">graph</span><span class="p">;</span>
392+
<span class="mi">3</span><span class="o">:</span> <span class="n">CustomGraph</span><span class="p">()</span> <span class="p">{</span>
393+
<span class="mi">4</span><span class="o">:</span> <span class="n">tf</span><span class="o">::</span><span class="n">FlowBuilder</span> <span class="n">builder</span><span class="p">(</span><span class="n">graph</span><span class="p">);</span>
394+
<span class="mi">5</span><span class="o">:</span> <span class="n">tf</span><span class="o">::</span><span class="n">Task</span> <span class="n">task</span> <span class="o">=</span> <span class="n">builder</span><span class="p">.</span><span class="n">emplace</span><span class="p">([](){</span>
395+
<span class="mi">6</span><span class="o">:</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;a task</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span> <span class="c1">// static task</span>
396+
<span class="mi">7</span><span class="o">:</span> <span class="p">});</span>
397+
<span class="mi">8</span><span class="o">:</span> <span class="p">}</span>
398+
<span class="mi">9</span><span class="o">:</span> <span class="c1">// returns a reference to the graph for taskflow composition</span>
399+
<span class="mi">10</span><span class="o">:</span> <span class="n">Graph</span><span class="o">&amp;</span> <span class="n">graph</span><span class="p">()</span> <span class="p">{</span> <span class="k">return</span> <span class="n">graph</span><span class="p">;</span> <span class="p">}</span>
400+
<span class="mi">11</span><span class="o">:</span> <span class="p">};</span>
401+
<span class="mi">12</span><span class="o">:</span>
402+
<span class="mi">13</span><span class="o">:</span> <span class="n">CustomGraph</span> <span class="n">obj</span><span class="p">;</span>
403+
<span class="mi">14</span><span class="o">:</span> <span class="n">tf</span><span class="o">::</span><span class="n">Task</span> <span class="n">comp</span> <span class="o">=</span> <span class="n">taskflow</span><span class="p">.</span><span class="n">composed_of</span><span class="p">(</span><span class="n">obj</span><span class="p">);</span></pre><p>Debrief:</p><ul><li>Lines 1-11 define a custom graph interface to participate in taskflow composition</li><li>Line 2 defines the graph object using <a href="classtf_1_1Graph.html" class="m-doc">tf::<wbr />Graph</a></li><li>Lines 3-8 defines the constructor that constructs the task graph using <a href="classtf_1_1FlowBuilder.html" class="m-doc">tf::<wbr />FlowBuilder</a></li><li>Line 10 defines the required method for taskflow composition</li><li>Lines 13-14 creates a module task for the declared graph object in the taskflow</li></ul><p>The composition method <a href="classtf_1_1FlowBuilder.html#ac6f22228d4c2ea2e643c4b0d42c0e92a" class="m-doc">tf::<wbr />Taskflow::<wbr />composed_of</a> requires the target to define the <code>graph()</code> method that returns a reference to a <a href="classtf_1_1Graph.html" class="m-doc">tf::<wbr />Graph</a> object defined by the target. At runtime, the executor will run dependent tasks in that graph using the same work-stealing scheduling algorithm as other taskflows. Taskflow leverages this powerful feature to design high-level algorithms, such as <a href="classtf_1_1Pipeline.html" class="m-doc">tf::<wbr />Pipeline</a>.</p><aside class="m-note m-info"><h4>Note</h4><p>While Taskflow gives you the flexibility to create a composable graph object, you should consider using <a href="classtf_1_1Graph.html" class="m-doc">tf::<wbr />Graph</a> as an opaque data structure just to interact with the library. Additionally, as other module tasks, Taskflow does not own the lifetime of a custom composable graph object but keeps a soft mapping to it. You should keep the graph object alive during its execution.</p></aside></section>
390404
</div>
391405
</div>
392406
</div>

docs/DynamicTasking.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h3>Contents</h3>
5555
<li><a href="#CreateASubflow">Create a Subflow</a></li>
5656
<li><a href="#JoinASubflow">Join a Subflow</a></li>
5757
<li><a href="#DetachASubflow">Detach a Subflow</a></li>
58-
<li><a href="#MakeANestedSubflow">Make a Nested Subflow</a></li>
58+
<li><a href="#CreateANestedSubflow">Create a Nested Subflow</a></li>
5959
</ul>
6060
</div>
6161
<p>It is very common for a parallel program to spawn task dependency graphs at runtime. In Taskflow, we call this <em>dynamic tasking</em>.</p><section id="CreateASubflow"><h2><a href="#CreateASubflow">Create a Subflow</a></h2><p>Dynamic tasks are those created during the execution of a graph. These tasks are spawned from a parent task and are grouped together to a <em>subflow</em> dependency graph. Taskflow has an unified interface for static and dynamic tasking. To create a subflow, emplace a callable that takes an argument of type <a href="classtf_1_1Subflow.html" class="m-doc">tf::<wbr />Subflow</a>. A <a href="classtf_1_1Subflow.html" class="m-doc">tf::<wbr />Subflow</a> object will be created and forwarded to the execution context of the task. All methods you find in <a href="classtf_1_1Taskflow.html" class="m-doc">tf::<wbr />Taskflow</a> are applicable for <a href="classtf_1_1Subflow.html" class="m-doc">tf::<wbr />Subflow</a>.</p><pre class="m-code"> <span class="mi">1</span><span class="o">:</span> <span class="n">tf</span><span class="o">::</span><span class="n">Taskflow</span> <span class="n">taskflow</span><span class="p">;</span>
@@ -641,7 +641,7 @@ <h3>Contents</h3>
641641
</g>
642642
</g>
643643
</svg>
644-
</div></section><section id="MakeANestedSubflow"><h2><a href="#MakeANestedSubflow">Make a Nested Subflow</a></h2><p>A subflow can be nested or recursive. You can create another subflow from the execution of a subflow and so on.</p><pre class="m-code"> <span class="mi">1</span><span class="o">:</span> <span class="n">tf</span><span class="o">::</span><span class="n">Taskflow</span> <span class="n">taskflow</span><span class="p">;</span>
644+
</div></section><section id="CreateANestedSubflow"><h2><a href="#CreateANestedSubflow">Create a Nested Subflow</a></h2><p>A subflow can be nested or recursive. You can create another subflow from the execution of a subflow and so on.</p><pre class="m-code"> <span class="mi">1</span><span class="o">:</span> <span class="n">tf</span><span class="o">::</span><span class="n">Taskflow</span> <span class="n">taskflow</span><span class="p">;</span>
645645
<span class="mi">2</span><span class="o">:</span>
646646
<span class="mi">3</span><span class="o">:</span> <span class="n">tf</span><span class="o">::</span><span class="n">Task</span> <span class="n">A</span> <span class="o">=</span> <span class="n">taskflow</span><span class="p">.</span><span class="n">emplace</span><span class="p">([]</span> <span class="p">(</span><span class="n">tf</span><span class="o">::</span><span class="n">Subflow</span><span class="o">&amp;</span> <span class="n">sbf</span><span class="p">){</span>
647647
<span class="mi">4</span><span class="o">:</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;A spawns A1 &amp; subflow A2</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span>

docs/ParallelReduction.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ <h1>
5252
<div class="m-block m-default">
5353
<h3>Contents</h3>
5454
<ul>
55+
<li><a href="#ParallelReductionInclude">Include the Header</a></li>
5556
<li><a href="#A2ParallelReduction">Create a Parallel-Reduction Task</a></li>
5657
<li><a href="#A2ParallelTransformationReduction">Create a Parallel Transform-Reduction Task</a></li>
5758
</ul>
5859
</div>
59-
<p>Taskflow provides template function that constructs a task to perform parallel reduction over a range of items.</p><section id="A2ParallelReduction"><h2><a href="#A2ParallelReduction">Create a Parallel-Reduction Task</a></h2><p>The reduction task created by <a href="classtf_1_1FlowBuilder.html#aa9494fe7b862fc832884ce318e8a37f5" class="m-doc">tf::<wbr />Taskflow::<wbr />reduce(B first, E last, T&amp; result, O bop)</a> performs parallel reduction over a range of elements specified by <code>[first, last)</code> using the binary operator <code>bop</code> and stores the reduced result in <code>result</code>. It represents the parallel execution of the following reduction loop:</p><pre class="m-code"><span class="k">for</span><span class="p">(</span><span class="k">auto</span> <span class="n">itr</span><span class="o">=</span><span class="n">first</span><span class="p">;</span> <span class="n">itr</span><span class="o">&lt;</span><span class="n">last</span><span class="p">;</span> <span class="n">itr</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
60+
<p>Taskflow provides template function that constructs a task to perform parallel reduction over a range of items.</p><section id="ParallelReductionInclude"><h2><a href="#ParallelReductionInclude">Include the Header</a></h2><p>You need to include the header file, <code>taskflow/algorithm/reduce.hpp</code>, for creating a parallel-reduction task.</p><pre class="m-code"><span class="cp">#include</span> <span class="cpf">&lt;taskflow/algorithm/reduce.hpp&gt;</span><span class="cp"></span></pre></section><section id="A2ParallelReduction"><h2><a href="#A2ParallelReduction">Create a Parallel-Reduction Task</a></h2><p>The reduction task created by <a href="classtf_1_1FlowBuilder.html#aa9494fe7b862fc832884ce318e8a37f5" class="m-doc">tf::<wbr />Taskflow::<wbr />reduce(B first, E last, T&amp; result, O bop)</a> performs parallel reduction over a range of elements specified by <code>[first, last)</code> using the binary operator <code>bop</code> and stores the reduced result in <code>result</code>. It represents the parallel execution of the following reduction loop:</p><pre class="m-code"><span class="k">for</span><span class="p">(</span><span class="k">auto</span> <span class="n">itr</span><span class="o">=</span><span class="n">first</span><span class="p">;</span> <span class="n">itr</span><span class="o">&lt;</span><span class="n">last</span><span class="p">;</span> <span class="n">itr</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
6061
<span class="n">result</span> <span class="o">=</span> <span class="n">bop</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="o">*</span><span class="n">itr</span><span class="p">);</span>
6162
<span class="p">}</span></pre><p>At runtime, the reduction task spawns a subflow to perform parallel reduction. The reduced result is stored in <code>result</code> that will be captured by reference in the reduction task. It is your responsibility to ensure <code>result</code> remains alive during the parallel execution.</p><pre class="m-code"><span class="kt">int</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">100</span><span class="p">;</span>
6263
<span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span> <span class="n">vec</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">10</span><span class="p">};</span>

0 commit comments

Comments
 (0)