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/ParallelIterations.html
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ <h3>Contents</h3>
60
60
<li><ahref="#ParallelIterationsConfigureAPartitioner">Configure a Partitioner</a></li>
61
61
</ul>
62
62
</nav>
63
-
<p>Taskflow provides template functions for constructing tasks to perform parallel iterations over ranges of items.</p><sectionid="ParallelIterationsIncludeTheHeader"><h2><ahref="#ParallelIterationsIncludeTheHeader">Include the Header</a></h2><p>You need to include the header file, <code>taskflow/algorithm/for_each.hpp</code>, for using parallel-iteration algorithms.</p><preclass="m-code"><spanclass="cp">#include</span><spanclass="w"></span><spanclass="cpf"><taskflow/algorithm/for_each.hpp></span><spanclass="cp"></span></pre></section><sectionid="A1IndexBasedParallelFor"><h2><ahref="#A1IndexBasedParallelFor">Create an Index-based Parallel-Iteration Task</a></h2><p>Index-based parallel-for performs parallel iterations over a range <code>[first, last)</code> with the given <code>step</code> size. The task created by <ahref="classtf_1_1FlowBuilder.html#a47ea2b35d0ec18afb35b45316939dc67" class="m-doc">tf::<wbr/>Taskflow::<wbr/>for_each_index(B first, E last, S step, C callable, P&& part)</a> represents parallel execution of the following loop:</p><preclass="m-code"><spanclass="c1">// positive step</span>
63
+
<p>Taskflow provides template functions for constructing tasks to perform parallel iterations over ranges of items.</p><sectionid="ParallelIterationsIncludeTheHeader"><h2><ahref="#ParallelIterationsIncludeTheHeader">Include the Header</a></h2><p>You need to include the header file, <code>taskflow/algorithm/for_each.hpp</code>, for using parallel-iteration algorithms.</p><preclass="m-code"><spanclass="cp">#include</span><spanclass="w"></span><spanclass="cpf"><taskflow/algorithm/for_each.hpp></span><spanclass="cp"></span></pre></section><sectionid="A1IndexBasedParallelFor"><h2><ahref="#A1IndexBasedParallelFor">Create an Index-based Parallel-Iteration Task</a></h2><p>Index-based parallel-for performs parallel iterations over a range <code>[first, last)</code> with the given <code>step</code> size. The task created by tf::Taskflow::for_each_index(B first, E last, S step, C callable, P&& part) represents parallel execution of the following loop:</p><preclass="m-code"><spanclass="c1">// positive step</span>
<spanclass="c1">// std::cout << "parallel iteration on index " << vec[i] << '\n';</span>
220
220
<spanclass="c1">// });</span>
221
221
222
-
<spanclass="n">init</span><spanclass="p">.</span><spanclass="n">precede</span><spanclass="p">(</span><spanclass="n">pf</span><spanclass="p">);</span><spanclass="w"></span></pre><p>When <code>init</code> finishes, the parallel-for task <code>pf</code> will see <code>first</code> as 0 and <code>last</code> as 1000 and performs parallel iterations over the 1000 items.</p></section><sectionid="A1IteratorBasedParallelFor"><h2><ahref="#A1IteratorBasedParallelFor">Create an Iterator-based Parallel-Iteration Task</a></h2><p>Iterator-based parallel-for performs parallel iterations over a range specified by two <ahref="https://en.cppreference.com/w/cpp/iterator/iterator">STL-styled iterators</a>, <code>first</code> and <code>last</code>. The task created by <ahref="classtf_1_1FlowBuilder.html#a025717373e424a6ccf9a61163bdaa585" class="m-doc">tf::<wbr/>Taskflow::<wbr/>for_each(B first, E last, C callable, P&& part)</a> represents a 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">i</span><spanclass="o">=</span><spanclass="n">first</span><spanclass="p">;</span><spanclass="w"></span><spanclass="n">i</span><spanclass="o"><</span><spanclass="n">last</span><spanclass="p">;</span><spanclass="w"></span><spanclass="n">i</span><spanclass="o">++</span><spanclass="p">)</span><spanclass="w"></span><spanclass="p">{</span><spanclass="w"></span>
222
+
<spanclass="n">init</span><spanclass="p">.</span><spanclass="n">precede</span><spanclass="p">(</span><spanclass="n">pf</span><spanclass="p">);</span><spanclass="w"></span></pre><p>When <code>init</code> finishes, the parallel-for task <code>pf</code> will see <code>first</code> as 0 and <code>last</code> as 1000 and performs parallel iterations over the 1000 items.</p></section><sectionid="A1IteratorBasedParallelFor"><h2><ahref="#A1IteratorBasedParallelFor">Create an Iterator-based Parallel-Iteration Task</a></h2><p>Iterator-based parallel-for performs parallel iterations over a range specified by two <ahref="https://en.cppreference.com/w/cpp/iterator/iterator">STL-styled iterators</a>, <code>first</code> and <code>last</code>. The task created by tf::Taskflow::for_each(B first, E last, C callable, P&& part) represents a 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">i</span><spanclass="o">=</span><spanclass="n">first</span><spanclass="p">;</span><spanclass="w"></span><spanclass="n">i</span><spanclass="o"><</span><spanclass="n">last</span><spanclass="p">;</span><spanclass="w"></span><spanclass="n">i</span><spanclass="o">++</span><spanclass="p">)</span><spanclass="w"></span><spanclass="p">{</span><spanclass="w"></span>
<spanclass="p">}</span><spanclass="w"></span></pre><p><ahref="classtf_1_1FlowBuilder.html#a025717373e424a6ccf9a61163bdaa585" class="m-doc">tf::<wbr/>Taskflow::<wbr/>for_each(B first, E last, C callable, P&& part)</a> simultaneously applies the callable to the object obtained by dereferencing every iterator in the range <code>[first, last)</code>. It is user's responsibility for ensuring the range is valid within the execution of the parallel-for task. Iterators must have the post-increment operator ++ defined.</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="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="p">{</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="w"></span><spanclass="mi">2</span><spanclass="p">,</span><spanclass="w"></span><spanclass="mi">3</span><spanclass="p">,</span><spanclass="w"></span><spanclass="mi">4</span><spanclass="p">,</span><spanclass="w"></span><spanclass="mi">5</span><spanclass="p">};</span><spanclass="w"></span>
224
+
<spanclass="p">}</span><spanclass="w"></span></pre><p>tf::Taskflow::for_each(B first, E last, C callable, P&& part) simultaneously applies the callable to the object obtained by dereferencing every iterator in the range <code>[first, last)</code>. It is user's responsibility for ensuring the range is valid within the execution of the parallel-for task. Iterators must have the post-increment operator ++ defined.</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="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="p">{</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="w"></span><spanclass="mi">2</span><spanclass="p">,</span><spanclass="w"></span><spanclass="mi">3</span><spanclass="p">,</span><spanclass="w"></span><spanclass="mi">4</span><spanclass="p">,</span><spanclass="w"></span><spanclass="mi">5</span><spanclass="p">};</span><spanclass="w"></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">"parallel for on item "</span><spanclass="w"></span><spanclass="o"><<</span><spanclass="w"></span><spanclass="n">i</span><spanclass="w"></span><spanclass="o"><<</span><spanclass="w"></span><spanclass="sc">'\n'</span><spanclass="p">;</span><spanclass="w"></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">"parallel for on item "</span><spanclass="w"></span><spanclass="o"><<</span><spanclass="w"></span><spanclass="n">str</span><spanclass="w"></span><spanclass="o"><<</span><spanclass="w"></span><spanclass="sc">'\n'</span><spanclass="p">;</span><spanclass="w"></span>
232
-
<spanclass="p">});</span><spanclass="w"></span></pre></section><sectionid="ParallelForEachCaptureIteratorsByReference"><h2><ahref="#ParallelForEachCaptureIteratorsByReference">Capture Iterators by Reference</a></h2><p>Similar to <ahref="classtf_1_1FlowBuilder.html#a47ea2b35d0ec18afb35b45316939dc67" class="m-doc">tf::<wbr/>Taskflow::<wbr/>for_each_index</a>, iterators of <ahref="classtf_1_1FlowBuilder.html#a025717373e424a6ccf9a61163bdaa585" class="m-doc">tf::<wbr/>Taskflow::<wbr/>for_each</a> are templated to allow capturing range parameters by reference, such that one task can set up the range before another task performs the parallel-for algorithm. For example:</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="w"></span>
232
+
<spanclass="p">});</span><spanclass="w"></span></pre></section><sectionid="ParallelForEachCaptureIteratorsByReference"><h2><ahref="#ParallelForEachCaptureIteratorsByReference">Capture Iterators by Reference</a></h2><p>Similar to <ahref="classtf_1_1FlowBuilder.html#a3b132bd902331a11b04b4ad66cf8bf77" class="m-doc">tf::<wbr/>Taskflow::<wbr/>for_each_index</a>, iterators of <ahref="classtf_1_1FlowBuilder.html#aae3edfa278baa75b08414e083c14c836" class="m-doc">tf::<wbr/>Taskflow::<wbr/>for_each</a> are templated to allow capturing range parameters by reference, such that one task can set up the range before another task performs the parallel-for algorithm. For example:</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="w"></span>
0 commit comments