1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___PSTL_BACKENDS_STD_THREAD_H
10 #define _LIBCPP___PSTL_BACKENDS_STD_THREAD_H
12 #include <__cxx03/__config>
13 #include <__cxx03/__pstl/backend_fwd.h>
14 #include <__cxx03/__pstl/cpu_algos/any_of.h>
15 #include <__cxx03/__pstl/cpu_algos/cpu_traits.h>
16 #include <__cxx03/__pstl/cpu_algos/fill.h>
17 #include <__cxx03/__pstl/cpu_algos/find_if.h>
18 #include <__cxx03/__pstl/cpu_algos/for_each.h>
19 #include <__cxx03/__pstl/cpu_algos/merge.h>
20 #include <__cxx03/__pstl/cpu_algos/stable_sort.h>
21 #include <__cxx03/__pstl/cpu_algos/transform.h>
22 #include <__cxx03/__pstl/cpu_algos/transform_reduce.h>
23 #include <__cxx03/__utility/empty.h>
24 #include <__cxx03/__utility/move.h>
25 #include <__cxx03/cstddef>
26 #include <__cxx03/optional>
28 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29 # pragma GCC system_header
33 #include <__cxx03/__undef_macros>
35 _LIBCPP_BEGIN_NAMESPACE_STD
39 // This partial backend implementation is for testing purposes only and not meant for production use. This will be
40 // replaced by a proper implementation once the PSTL implementation is somewhat stable.
42 // This is intended to be used on top of the "default backend".
46 struct __cpu_traits
<__std_thread_backend_tag
> {
47 template <class _RandomAccessIterator
, class _Fp
>
48 _LIBCPP_HIDE_FROM_ABI
static optional
<__empty
>
49 __for_each(_RandomAccessIterator __first
, _RandomAccessIterator __last
, _Fp __f
) {
54 template <class _Index
, class _UnaryOp
, class _Tp
, class _BinaryOp
, class _Reduce
>
55 _LIBCPP_HIDE_FROM_ABI
static optional
<_Tp
>
56 __transform_reduce(_Index __first
, _Index __last
, _UnaryOp
, _Tp __init
, _BinaryOp
, _Reduce __reduce
) {
57 return __reduce(std::move(__first
), std::move(__last
), std::move(__init
));
60 template <class _RandomAccessIterator
, class _Compare
, class _LeafSort
>
61 _LIBCPP_HIDE_FROM_ABI
static optional
<__empty
>
62 __stable_sort(_RandomAccessIterator __first
, _RandomAccessIterator __last
, _Compare __comp
, _LeafSort __leaf_sort
) {
63 __leaf_sort(__first
, __last
, __comp
);
67 _LIBCPP_HIDE_FROM_ABI
static void __cancel_execution() {}
69 template <class _RandomAccessIterator1
,
70 class _RandomAccessIterator2
,
71 class _RandomAccessIterator3
,
74 _LIBCPP_HIDE_FROM_ABI
static optional
<__empty
>
75 __merge(_RandomAccessIterator1 __first1
,
76 _RandomAccessIterator1 __last1
,
77 _RandomAccessIterator2 __first2
,
78 _RandomAccessIterator2 __last2
,
79 _RandomAccessIterator3 __outit
,
81 _LeafMerge __leaf_merge
) {
82 __leaf_merge(__first1
, __last1
, __first2
, __last2
, __outit
, __comp
);
86 static constexpr size_t __lane_size
= 64;
89 // Mandatory implementations of the computational basis
90 template <class _ExecutionPolicy
>
91 struct __find_if
<__std_thread_backend_tag
, _ExecutionPolicy
>
92 : __cpu_parallel_find_if
<__std_thread_backend_tag
, _ExecutionPolicy
> {};
94 template <class _ExecutionPolicy
>
95 struct __for_each
<__std_thread_backend_tag
, _ExecutionPolicy
>
96 : __cpu_parallel_for_each
<__std_thread_backend_tag
, _ExecutionPolicy
> {};
98 template <class _ExecutionPolicy
>
99 struct __merge
<__std_thread_backend_tag
, _ExecutionPolicy
>
100 : __cpu_parallel_merge
<__std_thread_backend_tag
, _ExecutionPolicy
> {};
102 template <class _ExecutionPolicy
>
103 struct __stable_sort
<__std_thread_backend_tag
, _ExecutionPolicy
>
104 : __cpu_parallel_stable_sort
<__std_thread_backend_tag
, _ExecutionPolicy
> {};
106 template <class _ExecutionPolicy
>
107 struct __transform
<__std_thread_backend_tag
, _ExecutionPolicy
>
108 : __cpu_parallel_transform
<__std_thread_backend_tag
, _ExecutionPolicy
> {};
110 template <class _ExecutionPolicy
>
111 struct __transform_binary
<__std_thread_backend_tag
, _ExecutionPolicy
>
112 : __cpu_parallel_transform_binary
<__std_thread_backend_tag
, _ExecutionPolicy
> {};
114 template <class _ExecutionPolicy
>
115 struct __transform_reduce
<__std_thread_backend_tag
, _ExecutionPolicy
>
116 : __cpu_parallel_transform_reduce
<__std_thread_backend_tag
, _ExecutionPolicy
> {};
118 template <class _ExecutionPolicy
>
119 struct __transform_reduce_binary
<__std_thread_backend_tag
, _ExecutionPolicy
>
120 : __cpu_parallel_transform_reduce_binary
<__std_thread_backend_tag
, _ExecutionPolicy
> {};
122 // Not mandatory, but better optimized
123 template <class _ExecutionPolicy
>
124 struct __any_of
<__std_thread_backend_tag
, _ExecutionPolicy
>
125 : __cpu_parallel_any_of
<__std_thread_backend_tag
, _ExecutionPolicy
> {};
127 template <class _ExecutionPolicy
>
128 struct __fill
<__std_thread_backend_tag
, _ExecutionPolicy
>
129 : __cpu_parallel_fill
<__std_thread_backend_tag
, _ExecutionPolicy
> {};
131 } // namespace __pstl
132 _LIBCPP_END_NAMESPACE_STD
136 #endif // _LIBCPP___PSTL_BACKENDS_STD_THREAD_H