#pragma once #include "../taskflow.hpp" namespace tf { // Function: make_transform_task template auto make_transform_task(B first1, E last1, O d_first, C c, P part = P()) { using namespace std::string_literals; using B_t = std::decay_t>; using E_t = std::decay_t>; using O_t = std::decay_t>; return [=] (Runtime& rt) mutable { // fetch the stateful values B_t beg = first1; E_t end = last1; O_t d_beg = d_first; size_t W = rt.executor().num_workers(); size_t N = std::distance(beg, end); if(N == 0) { return; } // only myself - no need to spawn another graph if(W <= 1 || N <= part.chunk_size()) { part([=]() mutable { std::transform(beg, end, d_beg, c); })(); return; } if(N < W) { W = N; } // static partitioner if constexpr(part.type() == PartitionerType::STATIC) { for(size_t w=0, curr_b=0; w= N) ? task() : rt.silent_async(task); } } // dynamic partitioner else { auto next = std::make_shared>(0); for(size_t w=0; w requires (!PartitionerLike>) auto make_transform_task(B1 first1, E1 last1, B2 first2, O d_first, C c, P part = P()) { using namespace std::string_literals; using B1_t = std::decay_t>; using E1_t = std::decay_t>; using B2_t = std::decay_t>; using O_t = std::decay_t>; return [=] (Runtime& rt) mutable { // fetch the stateful values B1_t beg1 = first1; E1_t end1 = last1; B2_t beg2 = first2; O_t d_beg = d_first; size_t W = rt.executor().num_workers(); size_t N = std::distance(beg1, end1); if(N == 0) { return; } // only myself - no need to spawn another graph if(W <= 1 || N <= part.chunk_size()) { part([=]() mutable { std::transform(beg1, end1, beg2, d_beg, c); })(); return; } if(N < W) { W = N; } // static partitioner if constexpr(part.type() == PartitionerType::STATIC) { for(size_t w=0, curr_b=0; w= N) ? task() : rt.silent_async(task); } } // dynamic partitioner else { auto next = std::make_shared>(0); for(size_t w=0; w Task FlowBuilder::transform(B first1, E last1, O d_first, C c, P part) { return emplace( make_transform_task(first1, last1, d_first, c, part) ); } // ---------------------------------------------------------------------------- // transform2 // ---------------------------------------------------------------------------- // Function: transform template requires (!PartitionerLike>) Task FlowBuilder::transform( B1 first1, E1 last1, B2 first2, O d_first, C c, P part ) { return emplace(make_transform_task( first1, last1, first2, d_first, c, part )); } } // end of namespace tf -----------------------------------------------------