同步操作将从 Gitee 极速下载/cpp-taskflow 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?xml version='1.0' encoding='UTF-8' standalone='no'?><doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.12.0" xml:lang="en-US"><compounddef id="ParallelIterations" kind="page"><compoundname>ParallelIterations</compoundname><title>Parallel Iterations</title><tableofcontents><tocsect><name>Include the Header</name><reference>ParallelIterations_1ParallelIterationsIncludeTheHeader</reference></tocsect><tocsect><name>Create an Index-based Parallel-Iteration Task</name><reference>ParallelIterations_1A1IndexBasedParallelFor</reference></tocsect><tocsect><name>Capture Indices by Reference</name><reference>ParallelIterations_1ParallelForEachCaptureIndicesByReference</reference></tocsect><tocsect><name>Create an Iterator-based Parallel-Iteration Task</name><reference>ParallelIterations_1A1IteratorBasedParallelFor</reference></tocsect><tocsect><name>Capture Iterators by Reference</name><reference>ParallelIterations_1ParallelForEachCaptureIteratorsByReference</reference></tocsect><tocsect><name>Configure a Partitioner</name><reference>ParallelIterations_1ParallelIterationsConfigureAPartitioner</reference></tocsect></tableofcontents><briefdescription></briefdescription><detaileddescription><para>Taskflow provides template functions for constructing tasks to perform parallel iterations over ranges of items.</para><sect1 id="ParallelIterations_1ParallelIterationsIncludeTheHeader"><title>Include the Header</title><para>You need to include the header file, <computeroutput>taskflow/algorithm/for_each.hpp</computeroutput>, for using parallel-iteration algorithms.</para><para><programlisting filename=".cpp"><codeline><highlight class="preprocessor">#include<sp/><taskflow/algorithm/for_each.hpp></highlight></codeline></programlisting></para></sect1><sect1 id="ParallelIterations_1A1IndexBasedParallelFor"><title>Create an Index-based Parallel-Iteration Task</title><para>Index-based parallel-for performs parallel iterations over a range <computeroutput>[first, last)</computeroutput> with the given <computeroutput>step</computeroutput> size. The task created by <ref refid="classtf_1_1FlowBuilder_1a3b132bd902331a11b04b4ad66cf8bf77" kindref="member">tf::Taskflow::for_each_index(B first, E last, S step, C callable, P part)</ref> represents parallel execution of the following loop:</para><para><programlisting filename=".cpp"><codeline><highlight class="comment">//<sp/>positive<sp/>step</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="keywordflow">for</highlight><highlight class="normal">(</highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>i=first;<sp/>i<last;<sp/>i+=step)<sp/>{</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>callable(i);</highlight></codeline><codeline><highlight class="normal">}</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>negative<sp/>step</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="keywordflow">for</highlight><highlight class="normal">(</highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>i=first;<sp/>i>last;<sp/>i+=step)<sp/>{</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>callable(i);</highlight></codeline><codeline><highlight class="normal">}</highlight></codeline></programlisting></para><para>We support only integer-based range. The range can go positive or negative direction.</para><para><programlisting filename=".cpp"><codeline><highlight class="normal">taskflow.for_each_index(0,<sp/>100,<sp/><sp/>2,<sp/>[](</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i)<sp/>{<sp/>});<sp/><sp/></highlight><highlight class="comment">//<sp/>50<sp/>loops<sp/>with<sp/>a<sp/>+<sp/>step</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal">taskflow.for_each_index(100,<sp/>0,<sp/>-2,<sp/>[](</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i)<sp/>{<sp/>});<sp/><sp/></highlight><highlight class="comment">//<sp/>50<sp/>loops<sp/>with<sp/>a<sp/>-<sp/>step</highlight></codeline></programlisting></para><para>Notice that either positive or negative direction is defined in terms of the range, <computeroutput>[first, last)</computeroutput>, where <computeroutput>end</computeroutput> is excluded. In the positive case, the 50 items are 0, 2, 4, 6, 8, ..., 96, 98. In the negative case, the 50 items are 100, 98, 96, 04, ... 4, 2. An example of the Taskflow graph for the positive case under 12 workers is depicted below:</para><para><dotfile name="parallel_for_1.dot"></dotfile></para><para>Instead of explicitly specifying the index range and the callable for each index invocation, the overload <ref refid="classtf_1_1FlowBuilder_1a2582a216d54dacca2b7022ea7e89452a" kindref="member">tf::Taskflow::for_each_by_index(R range, C callable, P part)</ref> provides you with a more flexible way to iterate over subranges of indices. This overload uses <ref refid="classtf_1_1IndexRange" kindref="compound">tf::IndexRange</ref> to partition the range into subranges, allowing finer control over how each subrange is processed. For instance, the code below does the same thing using two different approaches:</para><para><programlisting filename=".cpp"><codeline><highlight class="normal"><ref refid="cpp/container/vector" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::vector<int></ref><sp/>data1(100),<sp/>data2(100);</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>Approach<sp/>1:<sp/>initialize<sp/>data1<sp/>using<sp/>explicit<sp/>index<sp/>range</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal">taskflow.for_each_index(0,<sp/>100,<sp/>1,<sp/>[&](</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i){<sp/>data1[i]<sp/>=<sp/>10;<sp/>});</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>Approach<sp/>2:<sp/>initialize<sp/>data2<sp/>using<sp/>tf::IndexRange</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"><ref refid="classtf_1_1IndexRange" kindref="compound">tf::IndexRange<int></ref><sp/>range(0,<sp/>100,<sp/>1);</highlight></codeline><codeline><highlight class="normal">taskflow.for_each_by_index(range,<sp/>[&](<ref refid="classtf_1_1IndexRange" kindref="compound">tf::IndexRange<int></ref><sp/>subrange){</highlight></codeline><codeline><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal">(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i=subrange.<ref refid="classtf_1_1IndexRange_1a2b52381358ab392efa257e185a33d4af" kindref="member">begin</ref>();<sp/>i<subrange.<ref refid="classtf_1_1IndexRange_1a280096cb4056bc19b86da77d019434e4" kindref="member">end</ref>();<sp/>i+=subrange.<ref refid="classtf_1_1IndexRange_1aafd4f2d04614e550649cd9b7912e0bf1" kindref="member">step_size</ref>())<sp/>{</highlight></codeline><codeline><highlight class="normal"><sp/><sp/><sp/><sp/>data2[i]<sp/>=<sp/>10;</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>}</highlight></codeline><codeline><highlight class="normal">});</highlight></codeline></programlisting></para><para>Both approaches produce the same result, but the second approach offers more flexibility in terms of how each partitioned subrange is iterated. This is particularly useful for applications that benefit from SIMD optimizations or other range-based processing strategies.</para></sect1><sect1 id="ParallelIterations_1ParallelForEachCaptureIndicesByReference"><title>Capture Indices by Reference</title><para>You can pass indices by reference using <ulink url="https://en.cppreference.com/w/cpp/utility/functional/ref">std::ref</ulink> to marshal parameter update between dependent tasks. This is especially useful when the range indices are unknown at the time of creating a for-each-index task, but is initialized from another task.</para><para><programlisting filename=".cpp"><codeline><highlight class="keywordtype">int</highlight><highlight class="normal">*<sp/>vec;</highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>first,<sp/>last;</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>init<sp/>=<sp/>taskflow.emplace([&](){</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>first<sp/>=<sp/>0;</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>last<sp/><sp/>=<sp/>1000;</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>vec<sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal">[1000];<sp/><sp/></highlight></codeline><codeline><highlight class="normal">});</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>pf<sp/>=<sp/>taskflow.for_each_index(<ref refid="cpp/utility/functional/ref" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::ref</ref>(first),<sp/><ref refid="cpp/utility/functional/ref" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::ref</ref>(last),<sp/>1,<sp/></highlight></codeline><codeline><highlight class="normal"><sp/><sp/>[&]<sp/>(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i)<sp/>{</highlight></codeline><codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="cpp/io/basic_ostream" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::cout</ref><sp/><<<sp/></highlight><highlight class="stringliteral">"parallel<sp/>iteration<sp/>on<sp/>index<sp/>"</highlight><highlight class="normal"><sp/><<<sp/>vec[i]<sp/><<<sp/></highlight><highlight class="charliteral">'\n'</highlight><highlight class="normal">;</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>}</highlight></codeline><codeline><highlight class="normal">);</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>wrong!<sp/>must<sp/>use<sp/>std::ref,<sp/>or<sp/>first<sp/>and<sp/>last<sp/>are<sp/>captured<sp/>by<sp/>copy</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>auto<sp/>pf<sp/>=<sp/>taskflow.for_each_index(first,<sp/>last,<sp/>1,<sp/>[&](int<sp/>i)<sp/>{</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/>std::cout<sp/><<<sp/>"parallel<sp/>iteration<sp/>on<sp/>index<sp/>"<sp/><<<sp/>vec[i]<sp/><<<sp/>'\n';</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>});</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal">init.precede(pf);</highlight></codeline></programlisting></para><para>When <computeroutput>init</computeroutput> finishes, the parallel-for task <computeroutput>pf</computeroutput> will see <computeroutput>first</computeroutput> as 0 and <computeroutput>last</computeroutput> as 1000 and performs parallel iterations over the 1000 items.</para></sect1><sect1 id="ParallelIterations_1A1IteratorBasedParallelFor"><title>Create an Iterator-based Parallel-Iteration Task</title><para>Iterator-based parallel-for performs parallel iterations over a range specified by two <ulink url="https://en.cppreference.com/w/cpp/iterator/iterator">STL-styled iterators</ulink>, <computeroutput>first</computeroutput> and <computeroutput>last</computeroutput>. The task created by <ref refid="classtf_1_1FlowBuilder_1aae3edfa278baa75b08414e083c14c836" kindref="member">tf::Taskflow::for_each(B first, E last, C callable, P part)</ref> represents a parallel execution of the following loop:</para><para><programlisting filename=".cpp"><codeline><highlight class="keywordflow">for</highlight><highlight class="normal">(</highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>i=first;<sp/>i<last;<sp/>i++)<sp/>{</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>callable(*i);</highlight></codeline><codeline><highlight class="normal">}</highlight></codeline></programlisting></para><para>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 <computeroutput>[first, last)</computeroutput>. 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.</para><para><programlisting filename=".cpp"><codeline><highlight class="normal"><ref refid="cpp/container/vector" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::vector<int></ref><sp/>vec<sp/>=<sp/>{1,<sp/>2,<sp/>3,<sp/>4,<sp/>5};</highlight></codeline><codeline><highlight class="normal">taskflow.for_each(vec.begin(),<sp/>vec.end(),<sp/>[](</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i){<sp/></highlight></codeline><codeline><highlight class="normal"><sp/><sp/>std::cout<sp/><<<sp/></highlight><highlight class="stringliteral">"parallel<sp/>for<sp/>on<sp/>item<sp/>"</highlight><highlight class="normal"><sp/><<<sp/>i<sp/><<<sp/></highlight><highlight class="stringliteral">'\n'</highlight><highlight class="normal">;<sp/><sp/></highlight></codeline><codeline><highlight class="normal">});</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"><ref refid="cpp/container/list" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::list<std::string></ref><sp/>list<sp/>=<sp/>{</highlight><highlight class="stringliteral">"hi"</highlight><highlight class="normal">,<sp/></highlight><highlight class="stringliteral">"from"</highlight><highlight class="normal">,<sp/></highlight><highlight class="stringliteral">"t"</highlight><highlight class="normal">,<sp/></highlight><highlight class="stringliteral">"a"</highlight><highlight class="normal">,<sp/></highlight><highlight class="stringliteral">"s"</highlight><highlight class="normal">,<sp/></highlight><highlight class="stringliteral">"k"</highlight><highlight class="normal">,<sp/></highlight><highlight class="stringliteral">"f"</highlight><highlight class="normal">,<sp/></highlight><highlight class="stringliteral">"low"</highlight><highlight class="normal">};</highlight></codeline><codeline><highlight class="normal">taskflow.for_each(list.begin(),<sp/>list.end(),<sp/>[](</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/><ref refid="cpp/string/basic_string" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::string</ref>&<sp/>str){<sp/></highlight></codeline><codeline><highlight class="normal"><sp/><sp/>std::cout<sp/><<<sp/></highlight><highlight class="stringliteral">"parallel<sp/>for<sp/>on<sp/>item<sp/>"</highlight><highlight class="normal"><sp/><<<sp/>str<sp/><<<sp/></highlight><highlight class="stringliteral">'\n'</highlight><highlight class="normal">;<sp/><sp/></highlight></codeline><codeline><highlight class="normal">});</highlight></codeline></programlisting></para></sect1><sect1 id="ParallelIterations_1ParallelForEachCaptureIteratorsByReference"><title>Capture Iterators by Reference</title><para>Similar to <ref refid="classtf_1_1FlowBuilder_1a3b132bd902331a11b04b4ad66cf8bf77" kindref="member">tf::Taskflow::for_each_index</ref>, iterators of <ref refid="classtf_1_1FlowBuilder_1aae3edfa278baa75b08414e083c14c836" kindref="member">tf::Taskflow::for_each</ref> 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:</para><para><programlisting filename=".cpp"><codeline><highlight class="normal"><ref refid="cpp/container/vector" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::vector<int></ref><sp/>vec;</highlight></codeline><codeline><highlight class="normal"><ref refid="cpp/container/vector" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::vector<int>::iterator</ref><sp/>first,<sp/>last;;</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"><ref refid="classtf_1_1Task" kindref="compound">tf::Task</ref><sp/>init<sp/>=<sp/>taskflow.emplace([&](){</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>vec.resize(1000);</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>first<sp/>=<sp/>vec.begin();</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>last<sp/><sp/>=<sp/>vec.end();</highlight></codeline><codeline><highlight class="normal">});</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"><ref refid="classtf_1_1Task" kindref="compound">tf::Task</ref><sp/>pf<sp/>=<sp/>taskflow.for_each(<ref refid="cpp/utility/functional/ref" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::ref</ref>(first),<sp/><ref refid="cpp/utility/functional/ref" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::ref</ref>(last),<sp/>[&](</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i)<sp/>{</highlight></codeline><codeline><highlight class="normal"><sp/><sp/><ref refid="cpp/io/basic_ostream" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::cout</ref><sp/><<<sp/></highlight><highlight class="stringliteral">"parallel<sp/>iteration<sp/>on<sp/>item<sp/>"</highlight><highlight class="normal"><sp/><<<sp/>i<sp/><<<sp/></highlight><highlight class="charliteral">'\n'</highlight><highlight class="normal">;</highlight></codeline><codeline><highlight class="normal">});</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>wrong!<sp/>must<sp/>use<sp/>std::ref,<sp/>or<sp/>first<sp/>and<sp/>last<sp/>are<sp/>captured<sp/>by<sp/>copy</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>tf::Task<sp/>pf<sp/>=<sp/>taskflow.for_each(first,<sp/>last,<sp/>[&](int<sp/>i)<sp/>{</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/>std::cout<sp/><<<sp/>"parallel<sp/>iteration<sp/>on<sp/>item<sp/>"<sp/><<<sp/>i<sp/><<<sp/>'\n';</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>});</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal">init.<ref refid="classtf_1_1Task_1a8c78c453295a553c1c016e4062da8588" kindref="member">precede</ref>(pf);</highlight></codeline></programlisting></para><para>When <computeroutput>init</computeroutput> finishes, the parallel-for task <computeroutput>pf</computeroutput> will see <computeroutput>first</computeroutput> pointing to the beginning of <computeroutput>vec</computeroutput> and <computeroutput>last</computeroutput> pointing to the end of <computeroutput>vec</computeroutput> and performs parallel iterations over the 1000 items. The two tasks form an end-to-end task graph where the parameters of parallel-for are computed on the fly.</para></sect1><sect1 id="ParallelIterations_1ParallelIterationsConfigureAPartitioner"><title>Configure a Partitioner</title><para>You can configure a partitioner for parallel-iteration tasks to run with different scheduling methods, such as guided partitioning, dynamic partitioning, and static partitioning. The following example creates two parallel-iteration tasks using two different partitioners, one with the static partitioning algorithm and another one with the guided partitioning algorithm:</para><para><programlisting filename=".cpp"><codeline><highlight class="normal"><ref refid="cpp/container/vector" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::vector<int></ref><sp/>vec(1024,<sp/>0);</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>create<sp/>two<sp/>partitioners<sp/>with<sp/>a<sp/>chunk<sp/>size<sp/>of<sp/>10</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"><ref refid="classtf_1_1StaticPartitioner" kindref="compound">tf::StaticPartitioner</ref><sp/>static_partitioner(10);</highlight></codeline><codeline><highlight class="normal"><ref refid="classtf_1_1GuidedPartitioner" kindref="compound">tf::GuidedPartitioner</ref><sp/>guided_partitioner(10);</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>create<sp/>a<sp/>parallel-iteration<sp/>task<sp/>with<sp/>static<sp/>partitioner</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal">taskflow.for_each(</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>vec.begin(),<sp/>vec.end(),<sp/>[&](</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i)<sp/>{</highlight></codeline><codeline><highlight class="normal"><sp/><sp/><sp/><sp/>std::cout<sp/><<<sp/></highlight><highlight class="stringliteral">"parallel<sp/>iteration<sp/>on<sp/>item<sp/>"</highlight><highlight class="normal"><sp/><<<sp/>i<sp/><<<sp/></highlight><highlight class="stringliteral">'\n'</highlight><highlight class="normal">;</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>},</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>static_partitioner</highlight></codeline><codeline><highlight class="normal">);</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>create<sp/>a<sp/>parallel-iteration<sp/>task<sp/>with<sp/>guided<sp/>partitioner</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal">taskflow.for_each(</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>vec.begin(),<sp/>vec.end(),<sp/>[&](</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i)<sp/>{</highlight></codeline><codeline><highlight class="normal"><sp/><sp/><sp/><sp/>std::cout<sp/><<<sp/></highlight><highlight class="stringliteral">"parallel<sp/>iteration<sp/>on<sp/>item<sp/>"</highlight><highlight class="normal"><sp/><<<sp/>i<sp/><<<sp/></highlight><highlight class="stringliteral">'\n'</highlight><highlight class="normal">;</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>},</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>guided_partitioner</highlight></codeline><codeline><highlight class="normal">);</highlight></codeline></programlisting></para><para><simplesect kind="attention"><para>By default, parallel-iteration tasks use <ref refid="namespacetf_1ace2c5adcd5039483eebb6dbdbb6f33e3" kindref="member">tf::DefaultPartitioner</ref> if no partitioner is specified. </para></simplesect></para></sect1></detaileddescription><location file="doxygen/algorithms/for_each.dox"/></compounddef></doxygen>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。