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
Copy file name to clipboardExpand all lines: docs/ParallelFind.html
+4-3Lines changed: 4 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ <h3>Contents</h3>
61
61
<li><ahref="#ParallelFindConfigureAPartitioner">Configure a Partitioner</a></li>
62
62
</ul>
63
63
</nav>
64
-
<p>Taskflow provides template functions for constructing tasks to perform parallel iterations over ranges of items.</p><sectionid="ParallelFindIncludeTheHeader"><h2><ahref="#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><preclass="m-code"><spanclass="cp">#include</span><spanclass="w"></span><spanclass="cpf"><taskflow/algorithm/find.hpp></span></pre></section><sectionid="WhatIsAFindAlgorithm"><h2><ahref="#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& result, UOP predicate, P&& part)</li><li>tf::Taskflow::find_if_not(B first, E last, T& result, UOP predicate, P&& part)</li><li>tf::Taskflow::min_element(B first, E last, T& result, C comp, P&& part)</li><li>tf::Taskflow::max_element(B first, E last, T& result, C comp, P&& part)</li></ul></section><sectionid="CreateAParallelFindIfTask"><h2><ahref="#CreateAParallelFindIfTask">Create a Parallel Find-If Task</a></h2><p><ahref="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><preclass="m-code"><spanclass="k">template</span><spanclass="o"><</span><spanclass="k">typename</span><spanclass="w"></span><spanclass="nc">InputIt</span><spanclass="p">,</span><spanclass="w"></span><spanclass="k">typename</span><spanclass="w"></span><spanclass="nc">UnaryPredicate</span><spanclass="o">></span>
64
+
<p>Taskflow provides template functions for constructing tasks to perform parallel iterations over ranges of items.</p><sectionid="ParallelFindIncludeTheHeader"><h2><ahref="#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><preclass="m-code"><spanclass="cp">#include</span><spanclass="w"></span><spanclass="cpf"><taskflow/algorithm/find.hpp></span></pre></section><sectionid="WhatIsAFindAlgorithm"><h2><ahref="#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><ahref="classtf_1_1FlowBuilder.html#a46a96f5889e6ac87b1ff8d6313b5f471" class="m-doc">tf::<wbr/>Taskflow::<wbr/>find_if(B first, E last, T& result, UOP predicate, P part)</a></li><li><ahref="classtf_1_1FlowBuilder.html#a95fa2719fa7bbe7d171cf474ddb06726" class="m-doc">tf::<wbr/>Taskflow::<wbr/>find_if_not(B first, E last, T& result, UOP predicate, P part)</a></li><li><ahref="classtf_1_1FlowBuilder.html#a6bf43eeaa81900084a472be1d36d46a6" class="m-doc">tf::<wbr/>Taskflow::<wbr/>min_element(B first, E last, T& result, C comp, P part)</a></li><li><ahref="classtf_1_1FlowBuilder.html#a6be5d7f053a868647c3b9e0d9cdf6b68" class="m-doc">tf::<wbr/>Taskflow::<wbr/>max_element(B first, E last, T& result, C comp, P part)</a></li></ul></section><sectionid="CreateAParallelFindIfTask"><h2><ahref="#CreateAParallelFindIfTask">Create a Parallel Find-If Task</a></h2><p><ahref="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><preclass="m-code"><spanclass="k">template</span><spanclass="o"><</span><spanclass="k">typename</span><spanclass="w"></span><spanclass="nc">InputIt</span><spanclass="p">,</span><spanclass="w"></span><spanclass="k">typename</span><spanclass="w"></span><spanclass="nc">UnaryPredicate</span><spanclass="o">></span>
<spanclass="n">assert</span><spanclass="p">(</span><spanclass="o">*</span><spanclass="n">result</span><spanclass="w"></span><spanclass="o">==</span><spanclass="w"></span><spanclass="mi">2</span><spanclass="p">);</span></pre><asideclass="m-note m-warning"><h4>Attention</h4><p>When using <ahref="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 <ahref="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 <ahref="https://en.cppreference.com/w/cpp/algorithm/max_element">std::<wbr/>max_element</a>.</p></aside></section><sectionid="ParallelFindConfigureAPartitioner"><h2><ahref="#ParallelFindConfigureAPartitioner">Configure a Partitioner</a></h2><p>You can configure a partitioner for parallel-find tasks (<ahref="classtf_1_1FlowBuilder.html#a46a96f5889e6ac87b1ff8d6313b5f471" class="m-doc">tf::<wbr/>Taskflow::<wbr/>find_if</a>, <ahref="classtf_1_1FlowBuilder.html#a95fa2719fa7bbe7d171cf474ddb06726" class="m-doc">tf::<wbr/>Taskflow::<wbr/>find_if_not</a>, <ahref="classtf_1_1FlowBuilder.html#a6bf43eeaa81900084a472be1d36d46a6" class="m-doc">tf::<wbr/>Taskflow::<wbr/>min_element</a>, <ahref="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><preclass="m-code"><spanclass="n">std</span><spanclass="o">::</span><spanclass="n">vector</span><spanclass="o"><</span><spanclass="kt">int</span><spanclass="o">></span><spanclass="w"></span><spanclass="n">vec</span><spanclass="p">(</span><spanclass="mi">1024</span><spanclass="p">,</span><spanclass="w"></span><spanclass="mi">-1</span><spanclass="p">);</span>
0 commit comments