On Fri, Nov 27, 2026 at 10:50 PM Jonathan Wakely <[email protected]> wrote:
> Define some internal macros based on known properties of libstdc++,
> instead of via internal oneDPL headers that are not present in
> libstdc++.
>
> Rename the user-facing macros ONEDPL_USE_TBB_BACKEND and
> ONEDPL_USE_OPENMP_BACKEND to be in the _GLIBCXX namespace. The
> non-user-facing macros such as _ONEDPL_TBB_AVAILABLE are not changed,
> which mean they would conflict with the macros in the oneDPL project if
> a program included both sets of headers. The include guards on the
> headers already have that problem. Maybe we should rename all of those
> macros to be in our own namespace.
>
> Disable the config for the SYCL backend which has not been tested at
> all.
>
> Currently this is consistent with the upstream oneDPL code which prefers
> to use the TBB backend if the OpenMP one is not explicitly selected.
> That is consistent with past GCC releases, which only supported the TBB
> backend. We should consider making OpenMP the default, so that it works
> out of the box with libgomp and doesn't require the third-party TBB
> library. If we did that, programs which use the TBB backend today would
> need to define the _GLIBCXX_USE_TBB_PAR_BACKEND macro to continue using
> that backend.
>
> Due to how a backend is selected in <pstl/onedpl_config.h> (based on the
> availability of TBB and OpenMP and which user-facing macros are defined)
> we no longer need to set _GLIBCXX_USE_TBB_PAR_BACKEND automatically in
> <bits/c++config.h>. But if -fopenmp (and suitable include paths) aren't
> given, we do need to #undef any _GLIBCXX_USE_OPENMP_PAR_BACKEND, so that
> defining that when running the testsuite won't cause every test that
> doesn't use { dg-add-options pstl } to FAIL.
>
> The <pstl/pstl_config.h> header is no longer used anywhere, but is left
> in the tree because it's present in the upstream oneDPL release too.
>
> We need to ensure that the new onedpl_config.h header is included
> consistently, before any of the other PSTL headers. We could include it
> in bits/c++config.h but that would mean it's included by all libstdc++
> headers. It's only needed by the headers that define parallel algos or
> execution policies, so include it in those headers.
>
> We also need to ensure that pstl/glue_execution_defs.h defines the
> execution policies (std::execution::par etc.) unconditionally, instead
> of suppressing them if _ONEDPL_CPP17_EXECUTION_POLICIES_PRESENT is
> defined. That macro should be non-zero if the std::lib headers provide
> the policies, but that means it shouldn't be checked in the std::lib
> headers themselves, so that the policies do get defined.
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/c++config: Remove PSTL configuration. Undefine
> _GLIBCXX_USE_OPENMP_PAR_BACKEND if it would cause an error
> in onedpl_config.h.
> * include/pstl/glue_execution_defs.h (std::execution): Define
> namespace and contents unconditionally.
> * include/pstl/onedpl_config.h (_ONEDPL_CPP20_CONCEPTS_PRESENT)
> (_ONEDPL_CPP20_RANGES_PRESENT): Define in terms of
> __cpp_concepts.
> (_ONEDPL_STD_FEATURE_MACROS_PRESENT): Define to 1.
> (_ONEDPL___cplusplus): Define to __cplusplus.
> (ONEDPL_USE_TBB_BACKEND): Rename to _GLIBCXX_USE_TBB_PAR_BACKEND.
> (ONEDPL_USE_OPENMP_BACKEND): Rename to
> _GLIBCXX_USE_OPENMP_PAR_BACKEND.
> * include/pstl/parallel_backend.h: Adjust for new macro names.
> * include/std/algorithm: Include pstl/onedpl_config.h.
> * include/std/execution: Likewise.
> * include/std/memory: Likewise.
> * include/std/numeric: Likewise.
> * src/c++23/std.cc.in: Adjust TBB suppression.
> * testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc: Use
> new macro.
> ---
>
> Tested x86_64-linux.
>
LGTM
>
> libstdc++-v3/include/bits/c++config | 33 ++++---------------
> .../include/pstl/glue_execution_defs.h | 2 +-
> libstdc++-v3/include/pstl/onedpl_config.h | 19 ++++++++---
> libstdc++-v3/include/pstl/parallel_backend.h | 4 +--
> libstdc++-v3/include/std/algorithm | 1 +
> libstdc++-v3/include/std/execution | 1 +
> libstdc++-v3/include/std/memory | 1 +
> libstdc++-v3/include/std/numeric | 1 +
> libstdc++-v3/src/c++23/std.cc.in | 6 ++--
> .../pstl/alg_sorting/partial_sort.cc | 2 +-
> 10 files changed, 32 insertions(+), 38 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/c++config
> b/libstdc++-v3/include/bits/c++config
> index 04912633afc4..d813374aee6f 100644
> --- a/libstdc++-v3/include/bits/c++config
> +++ b/libstdc++-v3/include/bits/c++config
> @@ -951,36 +951,17 @@ namespace __gnu_cxx
> // Mark code that should be ignored by the compiler, but seen by Doxygen.
> #define _GLIBCXX_DOXYGEN_ONLY(X)
>
> -// PSTL configuration
> -
> -#if __cplusplus >= 201703L
> -// This header is not installed for freestanding:
> -#if __has_include(<pstl/pstl_config.h>)
> -// Preserved here so we have some idea which version of upstream we've
> pulled in
> -// #define PSTL_VERSION 9000
> -
> -// For now this defaults to being based on the presence of Thread
> Building Blocks
> -# ifndef _GLIBCXX_USE_TBB_PAR_BACKEND
> -# define _GLIBCXX_USE_TBB_PAR_BACKEND __has_include(<tbb/tbb.h>)
> -# endif
> -// This section will need some rework when a new (default) backend type
> is added
> -# if _GLIBCXX_USE_TBB_PAR_BACKEND
> -# define _PSTL_PAR_BACKEND_TBB
> -# else
> -# define _PSTL_PAR_BACKEND_SERIAL
> -# endif
> -
> -# define _PSTL_ASSERT(_Condition) __glibcxx_assert(_Condition)
> -# define _PSTL_ASSERT_MSG(_Condition, _Message)
> __glibcxx_assert(_Condition)
> -
> -#include <pstl/pstl_config.h>
> -#endif // __has_include
> -#endif // C++17
> -
> #if __cplusplus >= 201103L &&
> !defined(_GLIBCXX_USE_NEW_PIECEWISE_DISTRIBUTIONS)
> # define _GLIBCXX_USE_NEW_PIECEWISE_DISTRIBUTIONS 1
> #endif
>
> +#if _GLIBCXX_USE_OPENMP_PAR_BACKEND
> +// Ignore this macro unless -fopenmp was also provided.
> +# if !(defined(_OPENMP) && __has_include(<omp.h>))
> +# undef _GLIBCXX_USE_OPENMP_PAR_BACKEND
> +# endif
> +#endif
> +
> #pragma GCC diagnostic pop
>
> // End of prewritten config; the settings discovered at configure time
> follow.
> diff --git a/libstdc++-v3/include/pstl/glue_execution_defs.h
> b/libstdc++-v3/include/pstl/glue_execution_defs.h
> index d5a73ba00993..494ec7f195a8 100644
> --- a/libstdc++-v3/include/pstl/glue_execution_defs.h
> +++ b/libstdc++-v3/include/pstl/glue_execution_defs.h
> @@ -20,7 +20,7 @@
>
> #include "execution_defs.h"
>
> -#if !_ONEDPL_CPP17_EXECUTION_POLICIES_PRESENT
> +#if __glibcxx_parallel_algorithm //
> !_ONEDPL_CPP17_EXECUTION_POLICIES_PRESENT
> namespace std
> {
> // Type trait
> diff --git a/libstdc++-v3/include/pstl/onedpl_config.h
> b/libstdc++-v3/include/pstl/onedpl_config.h
> index 6e6e63d4ea4f..48f32e2c3fb3 100644
> --- a/libstdc++-v3/include/pstl/onedpl_config.h
> +++ b/libstdc++-v3/include/pstl/onedpl_config.h
> @@ -16,15 +16,22 @@
> #ifndef _ONEDPL_CONFIG_H
> #define _ONEDPL_CONFIG_H
>
> -// The version header also defines a few configuration macros used in
> this file
> -#include "../internal/version_impl.h"
> +// In oneDPL these are defined by ../internal/version_impl.h but we can
> +// hardcode the values based on properties we know to be true.
> +#define _ONEDPL_CPP20_CONCEPTS_PRESENT (__cpp_concepts >= 201907L)
> +#define _ONEDPL_CPP20_RANGES_PRESENT _ONEDPL_CPP20_CONCEPTS_PRESENT
> +#define _ONEDPL_STD_FEATURE_MACROS_PRESENT 1
> +// Similarly for this one from ../internal/common_config.h
> +#define _ONEDPL___cplusplus __cplusplus
>
> // -- Check availability of parallel backends --
>
> +// TODO rename all _ONEDPL_xxx macros to be in our own namespace?
> +
> #if __has_include(<tbb/tbb.h>)
> # define _ONEDPL_TBB_AVAILABLE 1
> #endif
> -#if ONEDPL_USE_TBB_BACKEND && !_ONEDPL_TBB_AVAILABLE
> +#if _GLIBCXX_USE_TBB_PAR_BACKEND && !_ONEDPL_TBB_AVAILABLE
> # error "Parallel execution policies with oneTBB or Intel(R) TBB
> support are enabled, but the library is not found"
> #endif
>
> @@ -33,11 +40,13 @@
> #endif
> // During compilation for a device _OPENMP may not be set, so avoid
> throwing an error if
> // __SYCL_DEVICE_ONLY__ found
> -#if ONEDPL_USE_OPENMP_BACKEND && !_ONEDPL_OPENMP_AVAILABLE &&
> !defined(__SYCL_DEVICE_ONLY__)
> +#if _GLIBCXX_USE_OPENMP_PAR_BACKEND && !_ONEDPL_OPENMP_AVAILABLE &&
> !defined(__SYCL_DEVICE_ONLY__)
> # error "Parallel execution policies with OpenMP* support are enabled,
> \
> but OpenMP headers are not found or the compiler does not support
> OpenMP"
> #endif
>
> +#if 0 // disabled for libstdc++
> +
> // -- Check availability of heterogeneous backends --
>
> // Due to the use in feature test macros, _ONEDPL_BACKEND_SYCL is defined
> in version_impl.h
> @@ -49,6 +58,8 @@
> # define _ONEDPL_HETERO_BACKEND 1
> #endif
>
> +#endif
> +
> // -- Configure host backends and common parts --
>
> // Check the user-defined macro for warnings
> diff --git a/libstdc++-v3/include/pstl/parallel_backend.h
> b/libstdc++-v3/include/pstl/parallel_backend.h
> index 13433f23fb86..ddf4a6ef7585 100644
> --- a/libstdc++-v3/include/pstl/parallel_backend.h
> +++ b/libstdc++-v3/include/pstl/parallel_backend.h
> @@ -17,10 +17,10 @@
> #include "onedpl_config.h"
>
> // Select a parallel backend
> -#if ONEDPL_USE_TBB_BACKEND || (!defined(ONEDPL_USE_TBB_BACKEND) &&
> !ONEDPL_USE_OPENMP_BACKEND && _ONEDPL_TBB_AVAILABLE)
> +#if _GLIBCXX_USE_TBB_PAR_BACKEND ||
> (!defined(_GLIBCXX_USE_TBB_PAR_BACKEND) && !_GLIBCXX_USE_OPENMP_PAR_BACKEND
> && _ONEDPL_TBB_AVAILABLE)
> # define _ONEDPL_PAR_BACKEND_TBB 1
> # include "parallel_backend_tbb.h"
> -#elif ONEDPL_USE_OPENMP_BACKEND || (!defined(ONEDPL_USE_OPENMP_BACKEND)
> && _ONEDPL_OPENMP_AVAILABLE)
> +#elif _GLIBCXX_USE_OPENMP_PAR_BACKEND ||
> (!defined(_GLIBCXX_USE_OPENMP_PAR_BACKEND) && _ONEDPL_OPENMP_AVAILABLE)
> # define _ONEDPL_PAR_BACKEND_OPENMP 1
> # include "parallel_backend_omp.h"
> #else
> diff --git a/libstdc++-v3/include/std/algorithm
> b/libstdc++-v3/include/std/algorithm
> index 5a0577308c87..a877dbc32174 100644
> --- a/libstdc++-v3/include/std/algorithm
> +++ b/libstdc++-v3/include/std/algorithm
> @@ -83,6 +83,7 @@
>
> #if __cpp_lib_parallel_algorithm // C++ >= 17 && HOSTED
> // Parallel STL algorithms
> +# include <pstl/onedpl_config.h>
> # if _PSTL_EXECUTION_POLICIES_DEFINED
> // If <execution> has already been included, pull in implementations
> # include <pstl/glue_algorithm_impl.h>
> diff --git a/libstdc++-v3/include/std/execution
> b/libstdc++-v3/include/std/execution
> index 5993347edbdc..81662e85ea2c 100644
> --- a/libstdc++-v3/include/std/execution
> +++ b/libstdc++-v3/include/std/execution
> @@ -38,6 +38,7 @@
> // C++ >= 17 && HOSTED
> #if defined(__cpp_lib_parallel_algorithm) || defined(__cpp_lib_execution)
> # include <bits/c++config.h>
> +# include <pstl/onedpl_config.h>
> # include <pstl/glue_execution_defs.h>
>
> # define _PSTL_EXECUTION_POLICIES_DEFINED 1
> diff --git a/libstdc++-v3/include/std/memory
> b/libstdc++-v3/include/std/memory
> index 8009a2c9b40f..cd8507dc23d3 100644
> --- a/libstdc++-v3/include/std/memory
> +++ b/libstdc++-v3/include/std/memory
> @@ -179,6 +179,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
>
> #ifdef __cpp_lib_parallel_algorithm // C++ >= 17 && HOSTED
> // Parallel STL algorithms
> +# include <pstl/onedpl_config.h>
> # if _PSTL_EXECUTION_POLICIES_DEFINED
> // If <execution> has already been included, pull in implementations
> # include <pstl/glue_memory_impl.h>
> diff --git a/libstdc++-v3/include/std/numeric
> b/libstdc++-v3/include/std/numeric
> index ec1064013825..545131a05432 100644
> --- a/libstdc++-v3/include/std/numeric
> +++ b/libstdc++-v3/include/std/numeric
> @@ -852,6 +852,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
>
> #if __cpp_lib_parallel_algorithm // C++ >= 17 && HOSTED
> // Parallel STL algorithms
> +# include <pstl/onedpl_config.h>
> # if _PSTL_EXECUTION_POLICIES_DEFINED
> // If <execution> has already been included, pull in implementations
> # include <pstl/glue_numeric_impl.h>
> diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/
> std.cc.in
> index 15349adf1be0..cf99c7665939 100644
> --- a/libstdc++-v3/src/c++23/std.cc.in
> +++ b/libstdc++-v3/src/c++23/std.cc.in
> @@ -27,10 +27,8 @@ module;
>
> // stdc++.h doesn't include <execution> because of TBB issues;
> // FIXME for now let's avoid the problem by suppressing TBB.
> -#ifdef _PSTL_PAR_BACKEND_TBB
> -#undef _PSTL_PAR_BACKEND_TBB
> -#define _PSTL_PAR_BACKEND_SERIAL
> -#endif
> +#undef _GLIBCXX_USE_TBB_PAR_BACKEND
> +#define _GLIBCXX_USE_TBB_PAR_BACKEND 0
> #include <execution>
>
> // Module std does include deprecated library interfaces.
> diff --git
> a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc
> b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc
> index 797d0ee9340c..53f8a861c47a 100644
> --- a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc
> +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc
> @@ -92,7 +92,7 @@ struct test_brick_partial_sort
> if (m1 - first > 1)
> {
> #ifdef _DEBUG
> -# if defined(_PSTL_PAR_BACKEND_TBB)
> +# if defined(_ONEDPL_PAR_BACKEND_TBB)
> auto p = tbb::this_task_arena::max_concurrency();
> # else
> auto p = 1;
> --
> 2.56.1
>
>