<title>Include the Header</title><para>You need to include the header file, <computeroutput>taskflow/algorithm/transform.hpp</computeroutput>, for creating a parallel-transform task.</para>
<title>Create a Unary Parallel-Transform Task</title><para>Parallel-transform transforms a range of items, possibly with a different type for the transformed data, and stores the result in another range. The task created by <refrefid="classtf_1_1FlowBuilder_1a97be7ceef6fa4276e3b074c10c13b826"kindref="member">tf::Taskflow::transform(B first1, E last1, O d_first, C c, P part)</ref> is equivalent to a parallel execution of the following loop:</para>
<para><refrefid="classtf_1_1FlowBuilder_1a97be7ceef6fa4276e3b074c10c13b826"kindref="member">tf::Taskflow::transform</ref> simultaneously applies the callable <computeroutput>c</computeroutput> to the object obtained by dereferencing every iterator in the range <computeroutput>[first1, last1)</computeroutput> and stores the result in another range beginning at <computeroutput>d_first</computeroutput>. It is user's responsibility for ensuring the range is valid within the execution of the parallel-transform task.</para>
<title>Capture Iterators by Reference</title><para>You can pass iterators by reference using <ulinkurl="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 is unknown at the time of creating a parallel-transform task, but needs initialization from another task.</para>
<para>When <computeroutput>init</computeroutput> finishes, the parallel-transform task <computeroutput>transform</computeroutput> will see <computeroutput>first</computeroutput> pointing to the beginning of <computeroutput>src</computeroutput> and <computeroutput>last</computeroutput> pointing to the end of <computeroutput>src</computeroutput>. Then, it simultaneously transforms these 1000 items by adding one to each element and stores the result in another range starting at <computeroutput>d_first</computeroutput>.</para>
<title>Create a Binary Parallel-Transform Task</title><para>You can use the overload, <refrefid="classtf_1_1FlowBuilder_1a7ea96d3fa0aa9e3ff337a9f1e37682b0"kindref="member">tf::Taskflow::transform(B1 first1, E1 last1, B2 first2, O d_first, C c, P part)</ref>, to perform parallel transforms on two source ranges pointed by <computeroutput>first1</computeroutput> and <computeroutput>first2</computeroutput> using the binary operator <computeroutput>c</computeroutput> and store the result in another range pointed by <computeroutput>d_first</computeroutput>. This method is equivalent to the parallel execution of the following loop:</para>
<para>The following example creates a parallel-transform task that adds two ranges of elements one by one and stores the result in a target range:</para>
<title>Configure a Partitioner</title><para>You can configure a partitioner for parallel-transform tasks to run with different scheduling methods, such as guided partitioning, dynamic partitioning, and static partitioning. The following example creates two parallel-transform tasks using two different partitioners, one with the static partitioning algorithm and another one with the guided partitioning algorithm:</para>
<para><simplesectkind="attention"><para>By default, parallel-transform tasks use <refrefid="namespacetf_1ace2c5adcd5039483eebb6dbdbb6f33e3"kindref="member">tf::DefaultPartitioner</ref> if no partitioner is specified. </para>