<p><ahref="classtf_1_1syclFlow.html" class="m-doc">tf::<wbr/>syclFlow</a> provides two template methods, <ahref="classtf_1_1syclFlow.html#a30c3f7a279d1f88b6052f7ded1ee381a" class="m-doc">tf::<wbr/>syclFlow::<wbr/>for_each</a> and <ahref="classtf_1_1syclFlow.html#a25e8aa7d7efbd05ef11353317174574a" class="m-doc">tf::<wbr/>syclFlow::<wbr/>for_each_index</a>, for creating tasks to perform parallel iterations over a range of items.</p><sectionid="ForEachSYCLIndexBasedParallelFor"><h2><ahref="#ForEachSYCLIndexBasedParallelFor">Index-based Parallel Iterations</a></h2><p>Index-based parallel-for performs parallel iterations over a range <code>[first, last)</code> with the given <code>step</code> size. These indices must be <em>integral</em> type. The task created by <ahref="classtf_1_1syclFlow.html#a25e8aa7d7efbd05ef11353317174574a" class="m-doc">tf::<wbr/>syclFlow::<wbr/>for_each_index(I first, I last, I step, C&& callable)</a> represents a kernel of parallel execution for the following loop:</p><preclass="m-code"><spanclass="c1">// positive step: first, first+step, first+2*step, ...</span>
<spanclass="p">}</span><spanclass="w"></span></pre><p>Each iteration <code>i</code> is independent of each other and is assigned one kernel thread to run the callable. The following example creates a kernel that assigns each element of <code>gpu_data</code> to 1 over the range [0, 100) with step size 1.</p><preclass="m-code"><spanclass="n">taskflow</span><spanclass="p">.</span><spanclass="n">emplace_on</span><spanclass="p">([</span><spanclass="o">&</span><spanclass="p">](</span><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">syclFlow</span><spanclass="o">&</span><spanclass="w"></span><spanclass="n">sf</span><spanclass="p">){</span><spanclass="w"></span>
<spanclass="w"></span><spanclass="c1">// ... create other gpu tasks</span>
<spanclass="w"></span><spanclass="c1">// assigns each element in gpu_data to 1 over the range [0, 100) with step size 1</span>
<spanclass="p">},</span><spanclass="w"></span><spanclass="n">sycl_queue</span><spanclass="p">);</span><spanclass="w"></span></pre></section><sectionid="ForEachSYCLIteratorBasedParallelIterations"><h2><ahref="#ForEachSYCLIteratorBasedParallelIterations">Iterator-based Parallel Iterations</a></h2><p>Iterator-based parallel-for performs parallel iterations over a range specified by two STL-styled iterators, <code>first</code> and <code>last</code>. The task created by <ahref="classtf_1_1syclFlow.html#a30c3f7a279d1f88b6052f7ded1ee381a" class="m-doc">tf::<wbr/>syclFlow::<wbr/>for_each(I first, I last, C&& callable)</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>
<spanclass="p">}</span><spanclass="w"></span></pre><p>The two iterators, <code>first</code> and <code>last</code>, are typically two raw pointers to the first element and the next to the last element in the range in GPU memory space. The following example creates a <code>for_each</code> kernel that assigns each element in <code>gpu_data</code> to 1 over the range <code>[gpu_data, gpu_data + 1000)</code>.</p><preclass="m-code"><spanclass="n">taskflow</span><spanclass="p">.</span><spanclass="n">emplace_on</span><spanclass="p">([</span><spanclass="o">&</span><spanclass="p">](</span><spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">syclFlow</span><spanclass="o">&</span><spanclass="w"></span><spanclass="n">cf</span><spanclass="p">){</span><spanclass="w"></span>
<spanclass="p">},</span><spanclass="w"></span><spanclass="n">sycl_queue</span><spanclass="p">);</span><spanclass="w"></span></pre><p>Each iteration is independent of each other and is assigned one kernel thread to run the callable.</p></section>
</div>
</div>
</div>
</article></main>
<divclass="m-doc-search" id="search">
<ahref="#!" onclick="return hideSearch()"></a>
<divclass="m-container">
<divclass="m-row">
<divclass="m-col-m-8 m-push-m-2">
<divclass="m-doc-search-header m-text m-small">
<div><spanclass="m-label m-default">Tab</span> / <spanclass="m-label m-default">T</span> to search, <spanclass="m-label m-default">Esc</span> to close</div>