Skip to content

Commit 9abc14d

Browse files
author
Tsung-Wei Huang
committed
updated index range-based parallel-for algorithm
1 parent 2a99016 commit 9abc14d

65 files changed

Lines changed: 3541 additions & 1621 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/Cookbook.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<h1>
4949
Cookbook
5050
</h1>
51-
<p>This cookbook provides a step-by-step tutorial for writing Taskflow programs.</p><ul><li><a href="ProjectMotivation.html" class="m-doc">Project Motivation</a></li><li><a href="StaticTasking.html" class="m-doc">Static Tasking</a></li><li><a href="ExecuteTaskflow.html" class="m-doc">Executor</a></li><li><a href="SubflowTasking.html" class="m-doc">Subflow Tasking</a></li><li><a href="ConditionalTasking.html" class="m-doc">Conditional Tasking</a></li><li><a href="ComposableTasking.html" class="m-doc">Composable Tasking</a></li><li><a href="AsyncTasking.html" class="m-doc">Asynchronous Tasking</a></li><li><a href="DependentAsyncTasking.html" class="m-doc">Asynchronous Tasking with Dependencies</a></li><li><a href="RuntimeTasking.html" class="m-doc">Interact with the Runtime</a></li><li><a href="ExceptionHandling.html" class="m-doc">Exception Handling</a></li><li><a href="GPUTaskingcudaFlow.html" class="m-doc">GPU Tasking (cudaFlow)</a></li><li><a href="GPUTaskingcudaFlowCapturer.html" class="m-doc">GPU Tasking (cudaFlowCapturer)</a></li><li><a href="LimitTheMaximumConcurrency.html" class="m-doc">Limit the Maximum Concurrency</a></li><li><a href="RequestCancellation.html" class="m-doc">Request Cancellation</a></li><li><a href="Profiler.html" class="m-doc">Profile Taskflow Programs</a></li></ul>
51+
<p>This cookbook provides a step-by-step tutorial for writing Taskflow programs.</p><ul><li><a href="ProjectMotivation.html" class="m-doc">Project Motivation</a></li><li><a href="StaticTasking.html" class="m-doc">Static Tasking</a></li><li><a href="ExecuteTaskflow.html" class="m-doc">Executor</a></li><li><a href="SubflowTasking.html" class="m-doc">Subflow Tasking</a></li><li><a href="ConditionalTasking.html" class="m-doc">Conditional Tasking</a></li><li><a href="ComposableTasking.html" class="m-doc">Composable Tasking</a></li><li><a href="AsyncTasking.html" class="m-doc">Asynchronous Tasking</a></li><li><a href="DependentAsyncTasking.html" class="m-doc">Asynchronous Tasking with Dependencies</a></li><li><a href="RuntimeTasking.html" class="m-doc">Interact with the Runtime</a></li><li><a href="ExceptionHandling.html" class="m-doc">Exception Handling</a></li><li><a href="LimitTheMaximumConcurrency.html" class="m-doc">Limit the Maximum Concurrency</a></li><li><a href="RequestCancellation.html" class="m-doc">Request Cancellation</a></li><li><a href="GPUTaskingcudaFlow.html" class="m-doc">GPU Tasking (cudaFlow)</a></li><li><a href="GPUTaskingcudaFlowCapturer.html" class="m-doc">GPU Tasking (cudaFlowCapturer)</a></li><li><a href="Profiler.html" class="m-doc">Profile Taskflow Programs</a></li></ul>
5252
</div>
5353
</div>
5454
</div>

docs/ParallelFind.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h3>Contents</h3>
6161
<li><a href="#ParallelFindConfigureAPartitioner">Configure a Partitioner</a></li>
6262
</ul>
6363
</nav>
64-
<p>Taskflow provides template functions for constructing tasks to perform parallel iterations over ranges of items.</p><section id="ParallelFindIncludeTheHeader"><h2><a href="#ParallelFindIncludeTheHeader">Include the Header</a></h2><p>You need to include the header file, <code>taskflow/algorithm/find.hpp</code>, for using parallel-find algorithms.</p><pre class="m-code"><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;taskflow/algorithm/find.hpp&gt;</span></pre></section><section id="WhatIsAFindAlgorithm"><h2><a href="#WhatIsAFindAlgorithm">What is a Find Algorithm?</a></h2><p>A find algorithm allows you to find an element in a range <code>[first, last)</code> that satisfies a specific criteria. The algorithm returns an iterator to the first found element in the range or returns <code>last</code> if there is no such iterator. Taskflow provides the following parallel-find algorithms:</p><ul><li>tf::Taskflow::find_if(B first, E last, T&amp; result, UOP predicate, P&amp;&amp; part)</li><li>tf::Taskflow::find_if_not(B first, E last, T&amp; result, UOP predicate, P&amp;&amp; part)</li><li>tf::Taskflow::min_element(B first, E last, T&amp; result, C comp, P&amp;&amp; part)</li><li>tf::Taskflow::max_element(B first, E last, T&amp; result, C comp, P&amp;&amp; part)</li></ul></section><section id="CreateAParallelFindIfTask"><h2><a href="#CreateAParallelFindIfTask">Create a Parallel Find-If Task</a></h2><p><a href="classtf_1_1FlowBuilder.html#a46a96f5889e6ac87b1ff8d6313b5f471" class="m-doc">tf::<wbr />Taskflow::<wbr />find_if</a> performs parallel iterations to find the first element in the range <code>[first, last)</code> that makes the given predicate return <code>true</code>. It resembles a parallel implementation of the following loop:</p><pre class="m-code"><span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span><span class="w"> </span><span class="nc">InputIt</span><span class="p">,</span><span class="w"> </span><span class="k">typename</span><span class="w"> </span><span class="nc">UnaryPredicate</span><span class="o">&gt;</span>
64+
<p>Taskflow provides template functions for constructing tasks to perform parallel iterations over ranges of items.</p><section id="ParallelFindIncludeTheHeader"><h2><a href="#ParallelFindIncludeTheHeader">Include the Header</a></h2><p>You need to include the header file, <code>taskflow/algorithm/find.hpp</code>, for using parallel-find algorithms.</p><pre class="m-code"><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;taskflow/algorithm/find.hpp&gt;</span></pre></section><section id="WhatIsAFindAlgorithm"><h2><a href="#WhatIsAFindAlgorithm">What is a Find Algorithm?</a></h2><p>A find algorithm allows you to find an element in a range <code>[first, last)</code> that satisfies a specific criteria. The algorithm returns an iterator to the first found element in the range or returns <code>last</code> if there is no such iterator. Taskflow provides the following parallel-find algorithms:</p><ul><li><a href="classtf_1_1FlowBuilder.html#a46a96f5889e6ac87b1ff8d6313b5f471" class="m-doc">tf::<wbr />Taskflow::<wbr />find_if(B first, E last, T&amp; result, UOP predicate, P part)</a></li><li><a href="classtf_1_1FlowBuilder.html#a95fa2719fa7bbe7d171cf474ddb06726" class="m-doc">tf::<wbr />Taskflow::<wbr />find_if_not(B first, E last, T&amp; result, UOP predicate, P part)</a></li><li><a href="classtf_1_1FlowBuilder.html#a6bf43eeaa81900084a472be1d36d46a6" class="m-doc">tf::<wbr />Taskflow::<wbr />min_element(B first, E last, T&amp; result, C comp, P part)</a></li><li><a href="classtf_1_1FlowBuilder.html#a6be5d7f053a868647c3b9e0d9cdf6b68" class="m-doc">tf::<wbr />Taskflow::<wbr />max_element(B first, E last, T&amp; result, C comp, P part)</a></li></ul></section><section id="CreateAParallelFindIfTask"><h2><a href="#CreateAParallelFindIfTask">Create a Parallel Find-If Task</a></h2><p><a href="classtf_1_1FlowBuilder.html#a46a96f5889e6ac87b1ff8d6313b5f471" class="m-doc">tf::<wbr />Taskflow::<wbr />find_if</a> performs parallel iterations to find the first element in the range <code>[first, last)</code> that makes the given predicate return <code>true</code>. It resembles a parallel implementation of the following loop:</p><pre class="m-code"><span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span><span class="w"> </span><span class="nc">InputIt</span><span class="p">,</span><span class="w"> </span><span class="k">typename</span><span class="w"> </span><span class="nc">UnaryPredicate</span><span class="o">&gt;</span>
6565
<span class="n">InputIt</span><span class="w"> </span><span class="n">find_if</span><span class="p">(</span><span class="n">InputIt</span><span class="w"> </span><span class="n">first</span><span class="p">,</span><span class="w"> </span><span class="n">InputIt</span><span class="w"> </span><span class="n">last</span><span class="p">,</span><span class="w"> </span><span class="n">UnaryPredicate</span><span class="w"> </span><span class="n">predicate</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
6666
<span class="w"> </span><span class="k">for</span><span class="p">(;</span><span class="w"> </span><span class="n">first</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">last</span><span class="p">;</span><span class="w"> </span><span class="o">++</span><span class="n">first</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
6767
<span class="w"> </span><span class="k">if</span><span class="p">(</span><span class="n">predicate</span><span class="p">(</span><span class="o">*</span><span class="n">first</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
@@ -122,8 +122,9 @@ <h3>Contents</h3>
122122
<span class="n">assert</span><span class="p">(</span><span class="o">*</span><span class="n">result</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">2</span><span class="p">);</span></pre><aside class="m-note m-warning"><h4>Attention</h4><p>When using <a href="classtf_1_1FlowBuilder.html#a6be5d7f053a868647c3b9e0d9cdf6b68" class="m-doc">tf::<wbr />Taskflow::<wbr />max_element</a> to find the large element, we will still need to use <a href="http://en.cppreference.com/w/cpp/utility/functional/less.html" class="m-doc-external">std::<wbr />less</a> as our comparison function. Details can be referred to <a href="https://en.cppreference.com/w/cpp/algorithm/max_element">std::<wbr />max_element</a>.</p></aside></section><section id="ParallelFindConfigureAPartitioner"><h2><a href="#ParallelFindConfigureAPartitioner">Configure a Partitioner</a></h2><p>You can configure a partitioner for parallel-find tasks (<a href="classtf_1_1FlowBuilder.html#a46a96f5889e6ac87b1ff8d6313b5f471" class="m-doc">tf::<wbr />Taskflow::<wbr />find_if</a>, <a href="classtf_1_1FlowBuilder.html#a95fa2719fa7bbe7d171cf474ddb06726" class="m-doc">tf::<wbr />Taskflow::<wbr />find_if_not</a>, <a href="classtf_1_1FlowBuilder.html#a6bf43eeaa81900084a472be1d36d46a6" class="m-doc">tf::<wbr />Taskflow::<wbr />min_element</a>, <a href="classtf_1_1FlowBuilder.html#a6be5d7f053a868647c3b9e0d9cdf6b68" class="m-doc">tf::<wbr />Taskflow::<wbr />max_element</a>) to run with different scheduling methods, such as guided partitioning, dynamic partitioning, and static partitioning. The following example creates two parallel-find tasks using two different partitioners, one with the static partitioning algorithm and another one with the guided partitioning algorithm:</p><pre class="m-code"><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="w"> </span><span class="n">vec</span><span class="p">(</span><span class="mi">1024</span><span class="p">,</span><span class="w"> </span><span class="mi">-1</span><span class="p">);</span>
123123
<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">iterator</span><span class="w"> </span><span class="n">result</span><span class="p">;</span>
124124

125-
<span class="n">tf</span><span class="o">::</span><span class="n">ExecutionPolicy</span><span class="o">&lt;</span><span class="n">tf</span><span class="o">::</span><span class="n">StaticPartitioner</span><span class="o">&gt;</span><span class="w"> </span><span class="n">static_partitioner</span><span class="p">;</span>
126-
<span class="n">tf</span><span class="o">::</span><span class="n">ExecutionPolicy</span><span class="o">&lt;</span><span class="n">tf</span><span class="o">::</span><span class="n">GuidedPartitioner</span><span class="o">&gt;</span><span class="w"> </span><span class="n">guided_partitioner</span><span class="p">;</span>
125+
<span class="c1">// create two partitioners with a chunk size of 10</span>
126+
<span class="n">tf</span><span class="o">::</span><span class="n">StaticPartitioner</span><span class="w"> </span><span class="nf">static_partitioner</span><span class="p">(</span><span class="mi">10</span><span class="p">);</span>
127+
<span class="n">tf</span><span class="o">::</span><span class="n">GuidedPartitioner</span><span class="w"> </span><span class="nf">guided_partitioner</span><span class="p">(</span><span class="mi">10</span><span class="p">);</span>
127128

128129
<span class="c1">// create a parallel-find task with a static partitioner</span>
129130
<span class="n">taskflow</span><span class="p">.</span><span class="n">find_if</span><span class="p">(</span>

0 commit comments

Comments
 (0)