From: Wolfgang Bangerth Date: Wed, 15 Jan 2025 01:01:56 +0000 (-0700) Subject: Merge pull request #17516 from tjhei/taskflow-parallel-for X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6beaff027c5bda47e9b5cf0315d3d60eef9824d0;p=dealii.git Merge pull request #17516 from tjhei/taskflow-parallel-for parallel_for() for transform with taskflow --- 6beaff027c5bda47e9b5cf0315d3d60eef9824d0 diff --cc include/deal.II/base/parallel.h index b5c0f4e109,d66abdd01a..d9facdb167 --- a/include/deal.II/base/parallel.h +++ b/include/deal.II/base/parallel.h @@@ -162,20 -200,27 +200,27 @@@ namespace paralle decltype(*std::declval()), std::invoke_result_t())>>)) - void transform(const InputIterator &begin_in, - const InputIterator &end_in, - OutputIterator out, - const Function &function, - const unsigned int grainsize) + DEAL_II_DEPRECATED_EARLY void transform(const InputIterator &begin_in, + const InputIterator &end_in, + OutputIterator out, + const Function &function, + const unsigned int grainsize) { - #ifndef DEAL_II_WITH_TBB - // make sure we don't get compiler - // warnings about unused arguments - (void)grainsize; + #ifdef DEAL_II_WITH_TASKFLOW + using Iterators = std::tuple; + using SyncIterators = SynchronousIterators; + Iterators x_begin(begin_in, out); + Iterators x_end(end_in, OutputIterator()); - for (InputIterator in = begin_in; in != end_in;) - *out++ = function(*in++); - #else + internal::taskflow_parallel_for( + SyncIterators(x_begin), + SyncIterators(x_end), + [function](const auto &it) { + *std::get<1>(it) = function(*std::get<0>(it)); + }, + grainsize); + + #elif defined(DEAL_II_WITH_TBB) using Iterators = std::tuple; using SyncIterators = SynchronousIterators; Iterators x_begin(begin_in, out); @@@ -237,21 -289,29 +289,29 @@@ std::invoke_result_t()), decltype(*std::declval())>>)) - void transform(const InputIterator1 &begin_in1, - const InputIterator1 &end_in1, - InputIterator2 in2, - OutputIterator out, - const Function &function, - const unsigned int grainsize) + DEAL_II_DEPRECATED_EARLY void transform(const InputIterator1 &begin_in1, + const InputIterator1 &end_in1, + InputIterator2 in2, + OutputIterator out, + const Function &function, + const unsigned int grainsize) { - #ifndef DEAL_II_WITH_TBB - // make sure we don't get compiler - // warnings about unused arguments - (void)grainsize; + #ifdef DEAL_II_WITH_TASKFLOW + using Iterators = + std::tuple; + using SyncIterators = SynchronousIterators; + Iterators x_begin(begin_in1, in2, out); + Iterators x_end(end_in1, InputIterator2(), OutputIterator()); - for (InputIterator1 in1 = begin_in1; in1 != end_in1;) - *out++ = function(*in1++, *in2++); - #else + internal::taskflow_parallel_for( + SyncIterators(x_begin), + SyncIterators(x_end), + [function](const auto &it) { + *std::get<2>(it) = function(*std::get<0>(it), *std::get<1>(it)); + }, + grainsize); + + #elif defined(DEAL_II_WITH_TBB) using Iterators = std::tuple; using SyncIterators = SynchronousIterators; @@@ -319,22 -387,34 +387,34 @@@ decltype(*std::declval()), decltype(*std::declval()), decltype(*std::declval())>>)) - void transform(const InputIterator1 &begin_in1, - const InputIterator1 &end_in1, - InputIterator2 in2, - InputIterator3 in3, - OutputIterator out, - const Function &function, - const unsigned int grainsize) + DEAL_II_DEPRECATED_EARLY void transform(const InputIterator1 &begin_in1, + const InputIterator1 &end_in1, + InputIterator2 in2, + InputIterator3 in3, + OutputIterator out, + const Function &function, + const unsigned int grainsize) { - #ifndef DEAL_II_WITH_TBB - // make sure we don't get compiler - // warnings about unused arguments - (void)grainsize; + #ifdef DEAL_II_WITH_TASKFLOW + using Iterators = std:: + tuple; + using SyncIterators = SynchronousIterators; + Iterators x_begin(begin_in1, in2, in3, out); + Iterators x_end(end_in1, + InputIterator2(), + InputIterator3(), + OutputIterator()); - for (InputIterator1 in1 = begin_in1; in1 != end_in1;) - *out++ = function(*in1++, *in2++, *in3++); - #else + internal::taskflow_parallel_for( + SyncIterators(x_begin), + SyncIterators(x_end), + [function](const auto &it) { + *std::get<3>(it) = + function(*std::get<0>(it), *std::get<1>(it), *std::get<2>(it)); + }, + grainsize); + + #elif defined(DEAL_II_WITH_TBB) using Iterators = std:: tuple; using SyncIterators = SynchronousIterators;