[PATCH] Integrate non-TBB serial backend support

Thomas Rodgers trodgers@redhat.com
Tue Jun 4 22:47:00 GMT 2019


	* include/bits/c++config: Adjust TBB detection logic to select serial
	PSTL backend if no TBB present.
	* testsuite/utils/pstl/test_utils.h: Remove check for
	__PSTL_USE_PAR_POLICIES
---
 libstdc++-v3/include/bits/c++config           |  8 ++--
 libstdc++-v3/testsuite/util/pstl/test_utils.h | 40 +++++++------------
 2 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 4b8574bf433..746e35efbfc 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -656,9 +656,7 @@ namespace std
 
 #if __cplusplus >= 201703L
 // Preserved here so we have some idea which version of upstream we've pulled in
-// #define PSTL_VERSION 104
-// #define PSTL_VERSION_MAJOR (PSTL_VERSION/100)
-// #define PSTL_VERSION_MINOR (PSTL_VERSION - PSTL_VERSION_MAJOR * 100)
+// #define PSTL_VERSION 9000
 
 // For now this defaults to being based on the presence of Thread Building Blocks
 # ifndef _GLIBCXX_USE_TBB_PAR_BACKEND
@@ -666,7 +664,9 @@ namespace std
 # endif
 // This section will need some rework when a new (default) backend type is added
 # if _GLIBCXX_USE_TBB_PAR_BACKEND
-#  define _PSTL_USE_PAR_POLICIES 1
+#  define _PSTL_PAR_BACKEND_TBB
+# else
+#  define _PSTL_PAR_BACKEND_SERIAL
 # endif
 
 # define _PSTL_ASSERT(_Condition) __glibcxx_assert(_Condition)
diff --git a/libstdc++-v3/testsuite/util/pstl/test_utils.h b/libstdc++-v3/testsuite/util/pstl/test_utils.h
index 9d16fa566e2..6547d931c29 100644
--- a/libstdc++-v3/testsuite/util/pstl/test_utils.h
+++ b/libstdc++-v3/testsuite/util/pstl/test_utils.h
@@ -10,14 +10,15 @@
 // File contains common utilities that tests rely on
 
 // Do not #include <algorithm>, because if we do we will not detect accidental dependencies.
-#include <sstream>
-#include <iostream>
+#include <atomic>
+#include <cstdint>
+#include <cstdlib>
 #include <cstring>
+#include <iostream>
 #include <iterator>
-#include <vector>
-#include <atomic>
 #include <memory>
-#include <cstdint>
+#include <sstream>
+#include <vector>
 
 #include "pstl_test_config.h"
 
@@ -38,32 +39,30 @@ template <typename T>
 class Sequence;
 
 // Handy macros for error reporting
-#define EXPECT_TRUE(condition, message) TestUtils::expect<true>(condition, __FILE__, __LINE__, message)
-#define EXPECT_FALSE(condition, message) TestUtils::expect<false>(condition, __FILE__, __LINE__, message)
+#define EXPECT_TRUE(condition, message) ::TestUtils::expect(true, condition, __FILE__, __LINE__, message)
+#define EXPECT_FALSE(condition, message) ::TestUtils::expect(false, condition, __FILE__, __LINE__, message)
 
 // Check that expected and actual are equal and have the same type.
-#define EXPECT_EQ(expected, actual, message) TestUtils::expect_equal(expected, actual, __FILE__, __LINE__, message)
+#define EXPECT_EQ(expected, actual, message) ::TestUtils::expect_equal(expected, actual, __FILE__, __LINE__, message)
 
 // Check that sequences started with expected and actual and have had size n are equal and have the same type.
 #define EXPECT_EQ_N(expected, actual, n, message)                                                                      \
-    TestUtils::expect_equal(expected, actual, n, __FILE__, __LINE__, message)
+    ::TestUtils::expect_equal(expected, actual, n, __FILE__, __LINE__, message)
 
 // Issue error message from outstr, adding a newline.
 // Real purpose of this routine is to have a place to hang a breakpoint.
-static void
+inline void
 issue_error_message(std::stringstream& outstr)
 {
     outstr << std::endl;
     std::cerr << outstr.str();
+    std::exit(EXIT_FAILURE);
 }
 
-template <bool B>
-void
-expect(bool condition, const char* file, int32_t line, const char* message)
+inline void
+expect(bool expected, bool condition, const char* file, int32_t line, const char* message)
 {
-    // Templating this function is somewhat silly, but avoids the need to declare it static
-    // or have a separate translation unit.
-    if (condition != B)
+    if (condition != expected)
     {
         std::stringstream outstr;
         outstr << "error at " << file << ":" << line << " - " << message;
@@ -607,13 +606,6 @@ multiply_matrix(const Matrix2x2<T>& left, const Matrix2x2<T>& right)
     return result;
 }
 
-// Check that Intel(R) Threading Building Blocks header files are not used when parallel policies are off
-#if !_PSTL_USE_PAR_POLICIES
-#if defined(TBB_INTERFACE_VERSION)
-#error The parallel backend is used while it should not (_PSTL_USE_PAR_POLICIES==0)
-#endif
-#endif
-
 //============================================================================
 // Adapters for creating different types of iterators.
 //
@@ -1052,10 +1044,8 @@ invoke_on_all_policies(Op op, T&&... rest)
     // Try static execution policies
     invoke_on_all_iterator_types()(seq, op, std::forward<T>(rest)...);
     invoke_on_all_iterator_types()(unseq, op, std::forward<T>(rest)...);
-#if _PSTL_USE_PAR_POLICIES
     invoke_on_all_iterator_types()(par, op, std::forward<T>(rest)...);
     invoke_on_all_iterator_types()(par_unseq, op, std::forward<T>(rest)...);
-#endif
 }
 
 template <typename F>
-- 
2.20.1



More information about the Gcc-patches mailing list