Skip to content

Commit 65a422c

Browse files
committedApr 24, 2019
[pstl] Make the default backend be the serial backend and always provide parallel policies
Summary: Before this change, the default backend was TBB but one could disable anything related to TBB by removing the parallel policies. This change uses the serial backend by default and removes the ability to disable parallel policies, which is not useful anymore. Reviewers: rodgert, MikeDvorskiy Subscribers: mgorny, jkorous, dexonsmith, jdoerfert, libcxx-commits Differential Revision: https://reviews.llvm.org/D59792 llvm-svn: 359134
1 parent 0ddd12e commit 65a422c

11 files changed

+20
-287
lines changed
 

‎pstl/CMakeLists.txt

+10-15
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ math(EXPR VERSION_PATCH "(${PARALLELSTL_VERSION_SOURCE} % 10)")
1616

1717
project(ParallelSTL VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} LANGUAGES CXX)
1818

19-
option(PARALLELSTL_USE_PARALLEL_POLICIES "Enable parallel policies" OFF)
20-
set(PARALLELSTL_BACKEND "tbb" CACHE STRING "Threading backend; defaults to TBB")
19+
set(PARALLELSTL_BACKEND "serial" CACHE STRING "Threading backend to use. Valid choices are 'serial' and 'tbb'. The default is 'serial'.")
2120

2221
if (NOT TBB_DIR)
2322
get_filename_component(PSTL_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
@@ -34,20 +33,16 @@ add_library(ParallelSTL INTERFACE)
3433
add_library(pstl::ParallelSTL ALIAS ParallelSTL)
3534
target_compile_features(ParallelSTL INTERFACE cxx_std_17)
3635

37-
if (PARALLELSTL_USE_PARALLEL_POLICIES)
38-
if (PARALLELSTL_BACKEND STREQUAL "serial")
39-
message(STATUS "Parallel STL uses the serial backend")
40-
target_compile_definitions(ParallelSTL INTERFACE -D_PSTL_PAR_BACKEND_SERIAL)
41-
elseif (PARALLELSTL_BACKEND STREQUAL "tbb")
42-
find_package(TBB 2018 REQUIRED tbb OPTIONAL_COMPONENTS tbbmalloc)
43-
message(STATUS "Parallel STL uses TBB ${TBB_VERSION} (interface version: ${TBB_INTERFACE_VERSION})")
44-
target_link_libraries(ParallelSTL INTERFACE TBB::tbb)
45-
target_compile_definitions(ParallelSTL INTERFACE -D_PSTL_PAR_BACKEND_TBB)
46-
else()
47-
message(FATAL_ERROR "Requested unknown Parallel STL backend '${PARALLELSTL_BACKEND}'.")
48-
endif()
36+
if (PARALLELSTL_BACKEND STREQUAL "serial")
37+
message(STATUS "Parallel STL uses the serial backend")
38+
target_compile_definitions(ParallelSTL INTERFACE -D_PSTL_PAR_BACKEND_SERIAL)
39+
elseif (PARALLELSTL_BACKEND STREQUAL "tbb")
40+
find_package(TBB 2018 REQUIRED tbb OPTIONAL_COMPONENTS tbbmalloc)
41+
message(STATUS "Parallel STL uses TBB ${TBB_VERSION} (interface version: ${TBB_INTERFACE_VERSION})")
42+
target_link_libraries(ParallelSTL INTERFACE TBB::tbb)
43+
target_compile_definitions(ParallelSTL INTERFACE -D_PSTL_PAR_BACKEND_TBB)
4944
else()
50-
target_compile_definitions(ParallelSTL INTERFACE PSTL_USE_PARALLEL_POLICIES=0)
45+
message(FATAL_ERROR "Requested unknown Parallel STL backend '${PARALLELSTL_BACKEND}'.")
5146
endif()
5247

5348
target_include_directories(ParallelSTL

‎pstl/include/pstl/internal/algorithm_fwd.h

-104
Large diffs are not rendered by default.

‎pstl/include/pstl/internal/algorithm_impl.h

+2-110
Large diffs are not rendered by default.

‎pstl/include/pstl/internal/execution_defs.h

-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class sequenced_policy
4141
}
4242
};
4343

44-
#if _PSTL_USE_PAR_POLICIES
4544
// 2.5, Parallel execution policy
4645
class parallel_policy
4746
{
@@ -85,7 +84,6 @@ class parallel_unsequenced_policy
8584
return std::true_type{};
8685
}
8786
};
88-
#endif
8987

9088
class unsequenced_policy
9189
{
@@ -110,10 +108,8 @@ class unsequenced_policy
110108

111109
// 2.8, Execution policy objects
112110
constexpr sequenced_policy seq{};
113-
#if _PSTL_USE_PAR_POLICIES
114111
constexpr parallel_policy par{};
115112
constexpr parallel_unsequenced_policy par_unseq{};
116-
#endif
117113
constexpr unsequenced_policy unseq{};
118114

119115
// 2.3, Execution policy type trait
@@ -126,7 +122,6 @@ template <>
126122
struct is_execution_policy<__pstl::execution::sequenced_policy> : std::true_type
127123
{
128124
};
129-
#if _PSTL_USE_PAR_POLICIES
130125
template <>
131126
struct is_execution_policy<__pstl::execution::parallel_policy> : std::true_type
132127
{
@@ -135,7 +130,6 @@ template <>
135130
struct is_execution_policy<__pstl::execution::parallel_unsequenced_policy> : std::true_type
136131
{
137132
};
138-
#endif
139133
template <>
140134
struct is_execution_policy<__pstl::execution::unsequenced_policy> : std::true_type
141135
{

‎pstl/include/pstl/internal/execution_impl.h

-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ struct __policy_traits<unsequenced_policy>
8787
typedef std::true_type allow_vector;
8888
};
8989

90-
#if _PSTL_USE_PAR_POLICIES
9190
template <>
9291
struct __policy_traits<parallel_policy>
9392
{
@@ -103,7 +102,6 @@ struct __policy_traits<parallel_unsequenced_policy>
103102
typedef std::true_type allow_unsequenced;
104103
typedef std::true_type allow_vector;
105104
};
106-
#endif
107105

108106
template <typename _ExecutionPolicy>
109107
using __collector_t =

‎pstl/include/pstl/internal/glue_execution_defs.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@ using __pstl::execution::is_execution_policy_v;
3030
namespace execution
3131
{
3232
// Standard C++ policy classes
33-
using __pstl::execution::sequenced_policy;
34-
#if _PSTL_USE_PAR_POLICIES
3533
using __pstl::execution::parallel_policy;
3634
using __pstl::execution::parallel_unsequenced_policy;
37-
#endif
35+
using __pstl::execution::sequenced_policy;
36+
3837
// Standard predefined policy instances
39-
using __pstl::execution::seq;
40-
#if _PSTL_USE_PAR_POLICIES
4138
using __pstl::execution::par;
4239
using __pstl::execution::par_unseq;
43-
#endif
40+
using __pstl::execution::seq;
41+
4442
// Implementation-defined names
4543
// Unsequenced policy is not yet standard, but for consistency
4644
// we include it into namespace std::execution as well

‎pstl/include/pstl/internal/numeric_fwd.h

-10
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ __pattern_transform_reduce(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterat
3939
_BinaryOperation1, _BinaryOperation2, _IsVector,
4040
/*is_parallel=*/std::false_type) noexcept;
4141

42-
#if _PSTL_USE_PAR_POLICIES
4342
template <class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2, class _Tp,
4443
class _BinaryOperation1, class _BinaryOperation2, class _IsVector>
4544
_Tp
4645
__pattern_transform_reduce(_ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
4746
_Tp, _BinaryOperation1, _BinaryOperation2, _IsVector __is_vector,
4847
/*is_parallel=*/std::true_type);
49-
#endif
5048

5149
//------------------------------------------------------------------------
5250
// transform_reduce (version with unary and binary functions)
@@ -67,14 +65,12 @@ __pattern_transform_reduce(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterato
6765
_UnaryOperation, _IsVector,
6866
/*is_parallel=*/std::false_type) noexcept;
6967

70-
#if _PSTL_USE_PAR_POLICIES
7168
template <class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation,
7269
class _IsVector>
7370
_Tp
7471
__pattern_transform_reduce(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Tp, _BinaryOperation,
7572
_UnaryOperation, _IsVector,
7673
/*is_parallel=*/std::true_type);
77-
#endif
7874

7975
//------------------------------------------------------------------------
8076
// transform_exclusive_scan
@@ -99,21 +95,17 @@ __pattern_transform_scan(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator,
9995
_BinaryOperation, _Inclusive, _IsVector,
10096
/*is_parallel=*/std::false_type) noexcept;
10197

102-
#if _PSTL_USE_PAR_POLICIES
10398
template <class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator, class _UnaryOperation, class _Tp,
10499
class _BinaryOperation, class _Inclusive, class _IsVector>
105100
typename std::enable_if<!std::is_floating_point<_Tp>::value, _OutputIterator>::type
106101
__pattern_transform_scan(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _OutputIterator,
107102
_UnaryOperation, _Tp, _BinaryOperation, _Inclusive, _IsVector, /*is_parallel=*/std::true_type);
108-
#endif
109103

110-
#if _PSTL_USE_PAR_POLICIES
111104
template <class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator, class _UnaryOperation, class _Tp,
112105
class _BinaryOperation, class _Inclusive, class _IsVector>
113106
typename std::enable_if<std::is_floating_point<_Tp>::value, _OutputIterator>::type
114107
__pattern_transform_scan(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _OutputIterator,
115108
_UnaryOperation, _Tp, _BinaryOperation, _Inclusive, _IsVector, /*is_parallel=*/std::true_type);
116-
#endif
117109

118110
//------------------------------------------------------------------------
119111
// adjacent_difference
@@ -133,13 +125,11 @@ _OutputIterator
133125
__pattern_adjacent_difference(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _OutputIterator, _BinaryOperation,
134126
_IsVector, /*is_parallel*/ std::false_type) noexcept;
135127

136-
#if _PSTL_USE_PAR_POLICIES
137128
template <class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _BinaryOperation,
138129
class _IsVector>
139130
_OutputIterator
140131
__pattern_adjacent_difference(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _OutputIterator, _BinaryOperation,
141132
_IsVector, /*is_parallel*/ std::true_type);
142-
#endif
143133

144134
} // namespace __internal
145135
} // namespace __pstl

‎pstl/include/pstl/internal/numeric_impl.h

+2-14
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
#include <type_traits>
1515
#include <numeric>
1616

17+
#include "parallel_backend.h"
18+
#include "pstl_config.h"
1719
#include "execution_impl.h"
1820
#include "unseq_backend_simd.h"
1921
#include "algorithm_fwd.h"
2022

21-
#if _PSTL_USE_PAR_POLICIES
22-
# include "parallel_backend.h"
23-
#endif
24-
2523
namespace __pstl
2624
{
2725
namespace __internal
@@ -63,7 +61,6 @@ __pattern_transform_reduce(_ExecutionPolicy&&, _ForwardIterator1 __first1, _Forw
6361
return __brick_transform_reduce(__first1, __last1, __first2, __init, __binary_op1, __binary_op2, __is_vector);
6462
}
6563

66-
#if _PSTL_USE_PAR_POLICIES
6764
template <class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2, class _Tp,
6865
class _BinaryOperation1, class _BinaryOperation2, class _IsVector>
6966
_Tp
@@ -86,7 +83,6 @@ __pattern_transform_reduce(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __f
8683
});
8784
});
8885
}
89-
#endif
9086

9187
//------------------------------------------------------------------------
9288
// transform_reduce (version with unary and binary functions)
@@ -125,7 +121,6 @@ __pattern_transform_reduce(_ExecutionPolicy&&, _ForwardIterator __first, _Forwar
125121
return __internal::__brick_transform_reduce(__first, __last, __init, __binary_op, __unary_op, __is_vector);
126122
}
127123

128-
#if _PSTL_USE_PAR_POLICIES
129124
template <class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation,
130125
class _IsVector>
131126
_Tp
@@ -142,7 +137,6 @@ __pattern_transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first,
142137
});
143138
});
144139
}
145-
#endif
146140

147141
//------------------------------------------------------------------------
148142
// transform_exclusive_scan
@@ -229,7 +223,6 @@ __pattern_transform_scan(_ExecutionPolicy&&, _ForwardIterator __first, _ForwardI
229223
.first;
230224
}
231225

232-
#if _PSTL_USE_PAR_POLICIES
233226
template <class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator, class _UnaryOperation, class _Tp,
234227
class _BinaryOperation, class _Inclusive, class _IsVector>
235228
typename std::enable_if<!std::is_floating_point<_Tp>::value, _OutputIterator>::type
@@ -259,9 +252,7 @@ __pattern_transform_scan(_ExecutionPolicy&& __exec, _RandomAccessIterator __firs
259252
return __result + (__last - __first);
260253
});
261254
}
262-
#endif
263255

264-
#if _PSTL_USE_PAR_POLICIES
265256
template <class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator, class _UnaryOperation, class _Tp,
266257
class _BinaryOperation, class _Inclusive, class _IsVector>
267258
typename std::enable_if<std::is_floating_point<_Tp>::value, _OutputIterator>::type
@@ -297,7 +288,6 @@ __pattern_transform_scan(_ExecutionPolicy&& __exec, _RandomAccessIterator __firs
297288
return __result + (__last - __first);
298289
});
299290
}
300-
#endif
301291

302292
//------------------------------------------------------------------------
303293
// adjacent_difference
@@ -338,7 +328,6 @@ __pattern_adjacent_difference(_ExecutionPolicy&&, _ForwardIterator __first, _For
338328
return __internal::__brick_adjacent_difference(__first, __last, __d_first, __op, __is_vector);
339329
}
340330

341-
#if _PSTL_USE_PAR_POLICIES
342331
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation,
343332
class _IsVector>
344333
_ForwardIterator2
@@ -362,7 +351,6 @@ __pattern_adjacent_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __fir
362351
});
363352
return __d_first + (__last - __first);
364353
}
365-
#endif
366354

367355
} // namespace __internal
368356
} // namespace __pstl

‎pstl/include/pstl/internal/pstl_config.h

+1-10
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,8 @@
1616
#define _PSTL_VERSION_MINOR ((_PSTL_VERSION % 1000) / 10)
1717
#define _PSTL_VERSION_PATCH (_PSTL_VERSION % 10)
1818

19-
// Check the user-defined macro for parallel policies
20-
#if defined(PSTL_USE_PARALLEL_POLICIES)
21-
# undef _PSTL_USE_PAR_POLICIES
22-
# define _PSTL_USE_PAR_POLICIES PSTL_USE_PARALLEL_POLICIES
23-
// Check the internal macro for parallel policies
24-
#elif !defined(_PSTL_USE_PAR_POLICIES)
25-
# define _PSTL_USE_PAR_POLICIES 1
26-
#endif
27-
2819
#if !defined(_PSTL_PAR_BACKEND_SERIAL) && !defined(_PSTL_PAR_BACKEND_TBB)
29-
# error "The parallel backend is neither serial nor TBB"
20+
# error "The parallel backend is neither serial nor TBB"
3021
#endif
3122

3223
// Check the user-defined macro for warnings

‎pstl/test/support/pstl_test_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define _PSTL_ICC_16_VC14_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN \
3131
(_M_IX86 && _DEBUG && __INTEL_COMPILER >= 1600 && __INTEL_COMPILER < 1700 && _MSC_VER == 1900)
3232
#define _PSTL_ICC_16_VC14_TEST_PAR_TBB_RT_RELEASE_64_BROKEN \
33-
(_PSTL_USE_PAR_POLICIES && ((_M_X64 && _MSC_VER == 1900) || __x86_64) && !_DEBUG && __INTEL_COMPILER < 1700)
33+
(((_M_X64 && _MSC_VER == 1900) || __x86_64) && !_DEBUG && __INTEL_COMPILER < 1700)
3434
#define _PSTL_ICC_16_17_TEST_64_TIMEOUT (__x86_64 && __INTEL_COMPILER && __INTEL_COMPILER < 1800 && !__APPLE__)
3535
#define _PSTL_ICC_18_TEST_EARLY_EXIT_MONOTONIC_RELEASE_BROKEN (!_DEBUG && __INTEL_COMPILER && __INTEL_COMPILER == 1800)
3636
#define _PSTL_CLANG_TEST_BIG_OBJ_DEBUG_32_BROKEN \

‎pstl/test/support/utils.h

-9
Original file line numberDiff line numberDiff line change
@@ -606,13 +606,6 @@ multiply_matrix(const Matrix2x2<T>& left, const Matrix2x2<T>& right)
606606
return result;
607607
}
608608

609-
// Check that Intel(R) Threading Building Blocks header files are not used when parallel policies are off
610-
#if !_PSTL_USE_PAR_POLICIES
611-
#if defined(TBB_INTERFACE_VERSION)
612-
#error The parallel backend is used while it should not (_PSTL_USE_PAR_POLICIES==0)
613-
#endif
614-
#endif
615-
616609
//============================================================================
617610
// Adapters for creating different types of iterators.
618611
//
@@ -1051,10 +1044,8 @@ invoke_on_all_policies(Op op, T&&... rest)
10511044
// Try static execution policies
10521045
invoke_on_all_iterator_types()(seq, op, std::forward<T>(rest)...);
10531046
invoke_on_all_iterator_types()(unseq, op, std::forward<T>(rest)...);
1054-
#if _PSTL_USE_PAR_POLICIES
10551047
invoke_on_all_iterator_types()(par, op, std::forward<T>(rest)...);
10561048
invoke_on_all_iterator_types()(par_unseq, op, std::forward<T>(rest)...);
1057-
#endif
10581049
}
10591050

10601051
template <typename F>

0 commit comments

Comments
 (0)
Please sign in to comment.