]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Merge pull request #17516 from tjhei/taskflow-parallel-for master
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 15 Jan 2025 01:01:56 +0000 (18:01 -0700)
committerGitHub <noreply@github.com>
Wed, 15 Jan 2025 01:01:56 +0000 (18:01 -0700)
parallel_for() for transform with taskflow

1  2 
include/deal.II/base/parallel.h

index b5c0f4e1097b3aeaa686f66b432be7879dd32af8,d66abdd01a49ad7a1948e9014d9012a8c20178b4..d9facdb1673bf0831ed9cd67b0c1a4d236d5fa6d
@@@ -162,20 -200,27 +200,27 @@@ namespace paralle
         decltype(*std::declval<OutputIterator>()),
         std::invoke_result_t<Function,
                              decltype(*std::declval<InputIterator>())>>))
 -  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<InputIterator, OutputIterator>;
+     using SyncIterators = SynchronousIterators<Iterators>;
+     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<InputIterator, OutputIterator>;
      using SyncIterators = SynchronousIterators<Iterators>;
      Iterators x_begin(begin_in, out);
         std::invoke_result_t<Function,
                              decltype(*std::declval<InputIterator1>()),
                              decltype(*std::declval<InputIterator2>())>>))
 -  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<InputIterator1, InputIterator2, OutputIterator>;
+     using SyncIterators = SynchronousIterators<Iterators>;
+     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<InputIterator1, InputIterator2, OutputIterator>;
      using SyncIterators = SynchronousIterators<Iterators>;
                              decltype(*std::declval<InputIterator1>()),
                              decltype(*std::declval<InputIterator2>()),
                              decltype(*std::declval<InputIterator3>())>>))
 -  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<InputIterator1, InputIterator2, InputIterator3, OutputIterator>;
+     using SyncIterators = SynchronousIterators<Iterators>;
+     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<InputIterator1, InputIterator2, InputIterator3, OutputIterator>;
      using SyncIterators = SynchronousIterators<Iterators>;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.