From 42a12b76bffc51ce16d8833d8b4cebb19c621de5 Mon Sep 17 00:00:00 2001 From: Jay Yang Date: Sun, 1 May 2022 19:10:02 +0100 Subject: [PATCH] Add support for TBB 2021. Forwarded: https://github.com/Macaulay2/M2/pull/2367 Gbp-Pq: Name tbb-2021.patch --- M2/Macaulay2/d/version.dd | 7 +++---- M2/Macaulay2/e/NCAlgebras/NCF4.cpp | 12 ++++++++++++ M2/Macaulay2/e/NCAlgebras/NCF4.hpp | 13 +++++++++++-- M2/configure.ac | 6 ++++-- M2/include/M2/config.h.cmake | 2 ++ 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/M2/Macaulay2/d/version.dd b/M2/Macaulay2/d/version.dd index aad8348..a437aef 100644 --- a/M2/Macaulay2/d/version.dd +++ b/M2/Macaulay2/d/version.dd @@ -61,13 +61,12 @@ header " #include Givaro::GivaroMain givaroMain; - /* TODO - fix conditionals once TBB 2021 support is added (#2105) */ - #if 1 /* TBB 2020 */ + #ifdef HAVE_TBB2021 + #include + #else /* TBB 2020 */ #include #define TBB_VERSION_STRING \\ (stringize(TBB_VERSION_MAJOR) \".\" stringize(TBB_VERSION_MINOR)) - #else /* TBB 2021 */ - #include #endif #include diff --git a/M2/Macaulay2/e/NCAlgebras/NCF4.cpp b/M2/Macaulay2/e/NCAlgebras/NCF4.cpp index 4d9bd35..bd16e68 100644 --- a/M2/Macaulay2/e/NCAlgebras/NCF4.cpp +++ b/M2/Macaulay2/e/NCAlgebras/NCF4.cpp @@ -529,6 +529,17 @@ void NCF4::parallelBuildF4Matrix(const std::deque& 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& overlapsToProcess) *data.memoryBlock, &feeder); }); +#endif /* HAVE_TBB2021 */ // combine the thread local rows into mRows for (const auto& data : threadData) diff --git a/M2/Macaulay2/e/NCAlgebras/NCF4.hpp b/M2/Macaulay2/e/NCAlgebras/NCF4.hpp index 3cf7fd3..9e7fa51 100644 --- a/M2/Macaulay2/e/NCAlgebras/NCF4.hpp +++ b/M2/Macaulay2/e/NCAlgebras/NCF4.hpp @@ -1,9 +1,15 @@ #ifndef __nc_f4_hpp__ #define __nc_f4_hpp__ +#include "M2/config.h" + #include // for queuing_mutex #include // for null_mutex -#include // for parallel_do_feeder +#ifdef HAVE_TBB2021 +#include // for feeder +#else /*TBB 2020*/ +#include // for parallel_do_feeder +#endif /*HAVE_TBB2021*/ #include // for concurrent_unordered_map //#include // 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>; //using RowsVector = tbb::concurrent_vector; - +#ifdef HAVE_TBB2021 + using PreRowFeeder = tbb::feeder; +#else /* TBB 2020 */ using PreRowFeeder = tbb::parallel_do_feeder; +#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 diff --git a/M2/configure.ac b/M2/configure.ac index 2c61ad1..df6b42b 100644 --- a/M2/configure.ac +++ b/M2/configure.ac @@ -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) diff --git a/M2/include/M2/config.h.cmake b/M2/include/M2/config.h.cmake index 4addb1b..7bd3cd8 100644 --- a/M2/include/M2/config.h.cmake +++ b/M2/include/M2/config.h.cmake @@ -350,4 +350,6 @@ /* Define to `unsigned int' if does not define. */ #cmakedefine size_t ${CMAKE_HOST_SYSTEM} +#cmakedefine HAVE_TBB2021 + #endif /* _M2_CONFIG_H */ -- 2.30.2