annotate include/llvm/Support/Parallel.h @ 121:803732b1fca8

LLVM 5.0
author kono
date Fri, 27 Oct 2017 17:07:41 +0900
parents
children c2174574ed3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===- llvm/Support/Parallel.h - Parallel algorithms ----------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 #ifndef LLVM_SUPPORT_PARALLEL_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 #define LLVM_SUPPORT_PARALLEL_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 #include "llvm/ADT/STLExtras.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "llvm/Config/llvm-config.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #include "llvm/Support/MathExtras.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include <algorithm>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 #include <condition_variable>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 #include <functional>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 #include <mutex>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 #if defined(_MSC_VER) && LLVM_ENABLE_THREADS
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 #pragma warning(push)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 #pragma warning(disable : 4530)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 #include <concrt.h>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 #include <ppl.h>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 #pragma warning(pop)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 #endif
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 namespace llvm {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 namespace parallel {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 struct sequential_execution_policy {};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 struct parallel_execution_policy {};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 template <typename T>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 struct is_execution_policy
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 : public std::integral_constant<
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 bool, llvm::is_one_of<T, sequential_execution_policy,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 parallel_execution_policy>::value> {};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 constexpr sequential_execution_policy seq{};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 constexpr parallel_execution_policy par{};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 namespace detail {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 #if LLVM_ENABLE_THREADS
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 class Latch {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 uint32_t Count;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 mutable std::mutex Mutex;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 mutable std::condition_variable Cond;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 explicit Latch(uint32_t Count = 0) : Count(Count) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 ~Latch() { sync(); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 void inc() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 std::unique_lock<std::mutex> lock(Mutex);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 ++Count;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 void dec() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 std::unique_lock<std::mutex> lock(Mutex);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 if (--Count == 0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 Cond.notify_all();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 void sync() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 std::unique_lock<std::mutex> lock(Mutex);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 Cond.wait(lock, [&] { return Count == 0; });
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 class TaskGroup {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76 Latch L;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79 void spawn(std::function<void()> f);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 void sync() const { L.sync(); }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 #if defined(_MSC_VER)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 template <class RandomAccessIterator, class Comparator>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86 void parallel_sort(RandomAccessIterator Start, RandomAccessIterator End,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 const Comparator &Comp) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88 concurrency::parallel_sort(Start, End, Comp);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 template <class IterTy, class FuncTy>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91 void parallel_for_each(IterTy Begin, IterTy End, FuncTy Fn) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92 concurrency::parallel_for_each(Begin, End, Fn);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95 template <class IndexTy, class FuncTy>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96 void parallel_for_each_n(IndexTy Begin, IndexTy End, FuncTy Fn) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97 concurrency::parallel_for(Begin, End, Fn);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
98 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
99
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
100 #else
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
101 const ptrdiff_t MinParallelSize = 1024;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
102
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
103 /// \brief Inclusive median.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
104 template <class RandomAccessIterator, class Comparator>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
105 RandomAccessIterator medianOf3(RandomAccessIterator Start,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
106 RandomAccessIterator End,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
107 const Comparator &Comp) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
108 RandomAccessIterator Mid = Start + (std::distance(Start, End) / 2);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
109 return Comp(*Start, *(End - 1))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
110 ? (Comp(*Mid, *(End - 1)) ? (Comp(*Start, *Mid) ? Mid : Start)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
111 : End - 1)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
112 : (Comp(*Mid, *Start) ? (Comp(*(End - 1), *Mid) ? Mid : End - 1)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
113 : Start);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
114 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
115
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
116 template <class RandomAccessIterator, class Comparator>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
117 void parallel_quick_sort(RandomAccessIterator Start, RandomAccessIterator End,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
118 const Comparator &Comp, TaskGroup &TG, size_t Depth) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
119 // Do a sequential sort for small inputs.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
120 if (std::distance(Start, End) < detail::MinParallelSize || Depth == 0) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
121 std::sort(Start, End, Comp);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
122 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
123 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
124
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
125 // Partition.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
126 auto Pivot = medianOf3(Start, End, Comp);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
127 // Move Pivot to End.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
128 std::swap(*(End - 1), *Pivot);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
129 Pivot = std::partition(Start, End - 1, [&Comp, End](decltype(*Start) V) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
130 return Comp(V, *(End - 1));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
131 });
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
132 // Move Pivot to middle of partition.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
133 std::swap(*Pivot, *(End - 1));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
134
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
135 // Recurse.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
136 TG.spawn([=, &Comp, &TG] {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
137 parallel_quick_sort(Start, Pivot, Comp, TG, Depth - 1);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
138 });
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
139 parallel_quick_sort(Pivot + 1, End, Comp, TG, Depth - 1);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
140 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
141
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
142 template <class RandomAccessIterator, class Comparator>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
143 void parallel_sort(RandomAccessIterator Start, RandomAccessIterator End,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
144 const Comparator &Comp) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
145 TaskGroup TG;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
146 parallel_quick_sort(Start, End, Comp, TG,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
147 llvm::Log2_64(std::distance(Start, End)) + 1);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
148 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
149
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
150 template <class IterTy, class FuncTy>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
151 void parallel_for_each(IterTy Begin, IterTy End, FuncTy Fn) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
152 // TaskGroup has a relatively high overhead, so we want to reduce
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
153 // the number of spawn() calls. We'll create up to 1024 tasks here.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
154 // (Note that 1024 is an arbitrary number. This code probably needs
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
155 // improving to take the number of available cores into account.)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
156 ptrdiff_t TaskSize = std::distance(Begin, End) / 1024;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
157 if (TaskSize == 0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
158 TaskSize = 1;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
159
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
160 TaskGroup TG;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
161 while (TaskSize < std::distance(Begin, End)) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
162 TG.spawn([=, &Fn] { std::for_each(Begin, Begin + TaskSize, Fn); });
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
163 Begin += TaskSize;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
164 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
165 std::for_each(Begin, End, Fn);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
166 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
167
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
168 template <class IndexTy, class FuncTy>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
169 void parallel_for_each_n(IndexTy Begin, IndexTy End, FuncTy Fn) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
170 ptrdiff_t TaskSize = (End - Begin) / 1024;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
171 if (TaskSize == 0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
172 TaskSize = 1;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
173
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
174 TaskGroup TG;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
175 IndexTy I = Begin;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
176 for (; I + TaskSize < End; I += TaskSize) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
177 TG.spawn([=, &Fn] {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
178 for (IndexTy J = I, E = I + TaskSize; J != E; ++J)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
179 Fn(J);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
180 });
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
181 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
182 for (IndexTy J = I; J < End; ++J)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
183 Fn(J);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
184 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
185
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
186 #endif
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
187
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
188 #endif
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
189
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
190 template <typename Iter>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
191 using DefComparator =
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
192 std::less<typename std::iterator_traits<Iter>::value_type>;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
193
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
194 } // namespace detail
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
195
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
196 // sequential algorithm implementations.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
197 template <class Policy, class RandomAccessIterator,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
198 class Comparator = detail::DefComparator<RandomAccessIterator>>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
199 void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
200 const Comparator &Comp = Comparator()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
201 static_assert(is_execution_policy<Policy>::value,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
202 "Invalid execution policy!");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
203 std::sort(Start, End, Comp);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
204 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
205
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
206 template <class Policy, class IterTy, class FuncTy>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
207 void for_each(Policy policy, IterTy Begin, IterTy End, FuncTy Fn) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
208 static_assert(is_execution_policy<Policy>::value,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
209 "Invalid execution policy!");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
210 std::for_each(Begin, End, Fn);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
211 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
212
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
213 template <class Policy, class IndexTy, class FuncTy>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
214 void for_each_n(Policy policy, IndexTy Begin, IndexTy End, FuncTy Fn) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
215 static_assert(is_execution_policy<Policy>::value,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
216 "Invalid execution policy!");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
217 for (IndexTy I = Begin; I != End; ++I)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
218 Fn(I);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
219 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
220
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
221 // Parallel algorithm implementations, only available when LLVM_ENABLE_THREADS
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
222 // is true.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
223 #if LLVM_ENABLE_THREADS
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
224 template <class RandomAccessIterator,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
225 class Comparator = detail::DefComparator<RandomAccessIterator>>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
226 void sort(parallel_execution_policy policy, RandomAccessIterator Start,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
227 RandomAccessIterator End, const Comparator &Comp = Comparator()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
228 detail::parallel_sort(Start, End, Comp);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
229 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
230
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
231 template <class IterTy, class FuncTy>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
232 void for_each(parallel_execution_policy policy, IterTy Begin, IterTy End,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
233 FuncTy Fn) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
234 detail::parallel_for_each(Begin, End, Fn);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
235 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
236
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
237 template <class IndexTy, class FuncTy>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
238 void for_each_n(parallel_execution_policy policy, IndexTy Begin, IndexTy End,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
239 FuncTy Fn) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
240 detail::parallel_for_each_n(Begin, End, Fn);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
241 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
242 #endif
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
243
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
244 } // namespace parallel
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
245 } // namespace llvm
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
246
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
247 #endif // LLVM_SUPPORT_PARALLEL_H