Add support for TBB 2021.
authorJay Yang <yangj306@mcmaster.ca>
Mon, 2 May 2022 00:14:15 +0000 (01:14 +0100)
committerDoug Torrance <dtorrance@debian.org>
Mon, 2 May 2022 00:14:15 +0000 (01:14 +0100)
Forwarded: https://github.com/Macaulay2/M2/pull/2367

Gbp-Pq: Name tbb-2021.patch

M2/Macaulay2/d/version.dd
M2/Macaulay2/e/NCAlgebras/NCF4.cpp
M2/Macaulay2/e/NCAlgebras/NCF4.hpp
M2/configure.ac
M2/include/M2/config.h.cmake

index aad834861315b8794cb93a64307be17ed8b60d8a..a437aef7742fd02fdfce47bdc0d13dfaa062204b 100644 (file)
@@ -61,13 +61,12 @@ header "
    #include <givaro/givconfig.h>
    Givaro::GivaroMain givaroMain;
 
-   /* TODO - fix conditionals once TBB 2021 support is added (#2105) */
-   #if 1 /* TBB 2020 */
+   #ifdef HAVE_TBB2021
+     #include <tbb/version.h>
+   #else /* TBB 2020 */
      #include <tbb/tbb_stddef.h>
      #define TBB_VERSION_STRING \\
        (stringize(TBB_VERSION_MAJOR) \".\" stringize(TBB_VERSION_MINOR))
-   #else /* TBB 2021 */
-     #include <tbb/version.h>
    #endif
 
    #include <Eigen/Core>
index 4d9bd3503a9ac13cdd9829f82edb89ee557dfe0a..bd16e68b65765eac8cc81f74c1333be677141fbf 100644 (file)
@@ -529,6 +529,17 @@ void NCF4::parallelBuildF4Matrix(const std::deque<Overlap>& overlapsToProcess)
   // can't do this loop as a range-based for loop since we are adding to it
   // during the for loop
   // process each element in mReducersTodo
+#ifdef HAVE_TBB2021
+  tbb::parallel_for_each(mReducersTodo.begin(), mReducersTodo.end(),
+      [&](const PreRow& prerow, PreRowFeeder& feeder)
+      {
+        auto& data = threadData.local();
+        processPreRow(prerow,
+                      data.rowsVector,
+                      *data.memoryBlock,
+                      &feeder);
+      });
+#else /*TBB 2020*/
   tbb::parallel_do(mReducersTodo.begin(), mReducersTodo.end(),
       [&](const PreRow& prerow, PreRowFeeder& feeder)
       {
@@ -538,6 +549,7 @@ void NCF4::parallelBuildF4Matrix(const std::deque<Overlap>& overlapsToProcess)
                       *data.memoryBlock,
                       &feeder);
       });
+#endif /* HAVE_TBB2021 */
 
   // combine the thread local rows into mRows
   for (const auto& data : threadData)
index 3cf7fd3ca1aedd0acea7514aa283929814e8857c..9e7fa51ad294087d0c670b58d332e2dc41ce21f1 100644 (file)
@@ -1,9 +1,15 @@
 #ifndef __nc_f4_hpp__
 #define __nc_f4_hpp__
 
+#include "M2/config.h"
+
 #include <tbb/queuing_mutex.h>                // for queuing_mutex
 #include <tbb/null_mutex.h>                   // for null_mutex
-#include <tbb/parallel_do.h>                  // for parallel_do_feeder
+#ifdef HAVE_TBB2021
+#include <tbb/parallel_for_each.h>                 // for feeder
+#else /*TBB 2020*/
+#include <tbb/parallel_do.h>                 // for parallel_do_feeder
+#endif /*HAVE_TBB2021*/
 #include <tbb/concurrent_unordered_map.h>     // for concurrent_unordered_map
 //#include <tbb/concurrent_vector.h>          // for concurrent_vector (no longer needed)
 
@@ -86,8 +92,11 @@ private:
   // unfortunately we must use the GC allocator here for now
   using RowsVector = std::vector<Row,gc_allocator<Row>>;
   //using RowsVector = tbb::concurrent_vector<Row>;
-
+#ifdef HAVE_TBB2021
+  using PreRowFeeder = tbb::feeder<PreRow>;
+#else /* TBB 2020 */
   using PreRowFeeder = tbb::parallel_do_feeder<PreRow>;
+#endif /* HAVE_TBB2021 */
   // The pair in this unordered_map is (i,j) where:
   //    i is the column number
   //    j is the row that reduces it
index 2c61ad1124b6a88c1420d3a6cfb89340927e8ea6..df6b42b855fb649bc9834843a118aa6b496c53ef 100644 (file)
@@ -362,8 +362,10 @@ AC_SUBST(LIBTBB)
    AC_LANG(C++)
    AC_CHECK_HEADER(tbb/tbb.h,
       [AC_SEARCH_LIBS(TBB_runtime_interface_version,"tbb",
-        LIBTBB=$ac_cv_search_TBB_runtime_interface_version
-        HAVE_LIBTBB=yes,
+        [LIBTBB=$ac_cv_search_TBB_runtime_interface_version
+          HAVE_LIBTBB=yes
+          AC_CHECK_HEADER(tbb/version.h,[AC_DEFINE(HAVE_TBB2021,[],[TBB version at least 2021])])
+         ],
         [AC_MSG_ERROR([tbb library not found])])],
        [AC_MSG_ERROR([tbb include file (tbb.h) not found])])
    AC_LANG(C)
index 4addb1be228453f7daaa87b7dc9f3e037f10f19d..7bd3cd80dc8478b970d1c5a3c6b5b7bae6e65952 100644 (file)
 /* Define to `unsigned int' if <sys/types.h> does not define. */
 #cmakedefine size_t ${CMAKE_HOST_SYSTEM}
 
+#cmakedefine HAVE_TBB2021
+
 #endif /* _M2_CONFIG_H */