Skip to content

Commit 79b5d68

Browse files
authored
Stabilize test_parallel_phase (#1623)
Use task_arena::enqueue instead of parallel_for to reduce probability of missed wakeup Signed-off-by: Isaev, Ilya <[email protected]>
1 parent 409280b commit 79b5d68

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

test/tbb/test_parallel_phase.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "common/spin_barrier.h"
2828

2929
#include "tbb/task_arena.h"
30-
#include "tbb/parallel_for.h"
3130

3231
void active_wait_for(std::chrono::microseconds duration) {
3332
for (auto t1 = std::chrono::steady_clock::now(), t2 = t1;
@@ -52,7 +51,7 @@ std::size_t measure_median_start_time(tbb::task_arena* ta, const F1& start = F1{
5251

5352
std::vector<std::chrono::steady_clock::time_point> start_times(num_threads);
5453
utils::SpinBarrier barrier(num_threads);
55-
auto measure_start_time = [&] (std::size_t) {
54+
auto measure_start_time = [&] {
5655
start_times[tbb::this_task_arena::current_thread_index()] = std::chrono::steady_clock::now();
5756
barrier.wait();
5857
};
@@ -69,7 +68,11 @@ std::size_t measure_median_start_time(tbb::task_arena* ta, const F1& start = F1{
6968
auto work = [&] {
7069
auto start_time = std::chrono::steady_clock::now();
7170
start();
72-
tbb::parallel_for(std::size_t(0), num_threads, measure_start_time, tbb::static_partitioner{});
71+
for(std::size_t thr = 0; thr < num_threads-1; ++thr) {
72+
tbb::this_task_arena::enqueue(measure_start_time);
73+
}
74+
start_times[tbb::this_task_arena::current_thread_index()] = std::chrono::steady_clock::now();
75+
barrier.wait();
7376
end();
7477
longest_start_times.push_back(get_longest_start(start_time));
7578
};
@@ -158,7 +161,7 @@ class start_time_collection_sequenced_phases
158161
std::size_t measure_impl() {
159162
std::size_t median_start_time;
160163
utils::SpinBarrier barrier;
161-
auto body = [&] (std::size_t) {
164+
auto body = [&] {
162165
barrier.wait();
163166
};
164167
if (arena) {
@@ -168,7 +171,10 @@ class start_time_collection_sequenced_phases
168171
std::size_t num_threads = arena->max_concurrency();
169172
arena->start_parallel_phase();
170173
arena->execute([&] {
171-
tbb::parallel_for(std::size_t(0), num_threads, body, tbb::static_partitioner{});
174+
for(std::size_t thr = 0; thr < num_threads-1; ++thr) {
175+
tbb::this_task_arena::enqueue(body);
176+
}
177+
barrier.wait();
172178
});
173179
arena->end_parallel_phase(with_fast_leave);
174180
}
@@ -179,7 +185,10 @@ class start_time_collection_sequenced_phases
179185
[&] {
180186
std::size_t num_threads = tbb::this_task_arena::max_concurrency();
181187
tbb::this_task_arena::start_parallel_phase();
182-
tbb::parallel_for(std::size_t(0), num_threads, body, tbb::static_partitioner{});
188+
for(std::size_t thr = 0; thr < num_threads-1; ++thr) {
189+
tbb::this_task_arena::enqueue(body);
190+
}
191+
barrier.wait();
183192
tbb::this_task_arena::end_parallel_phase(with_fast_leave);
184193
}
185194
);
@@ -207,7 +216,7 @@ class start_time_collection_sequenced_scoped_phases
207216

208217
std::size_t measure_impl() {
209218
utils::SpinBarrier barrier{static_cast<std::size_t>(arena->max_concurrency())};
210-
auto body = [&] (std::size_t) {
219+
auto body = [&] {
211220
barrier.wait();
212221
};
213222
auto median_start_time = measure_median_start_time(arena,
@@ -216,7 +225,10 @@ class start_time_collection_sequenced_scoped_phases
216225
{
217226
tbb::task_arena::scoped_parallel_phase phase{*arena, with_fast_leave};
218227
arena->execute([&] {
219-
tbb::parallel_for(std::size_t(0), num_threads, body, tbb::static_partitioner{});
228+
for(std::size_t thr = 0; thr < num_threads-1; ++thr) {
229+
tbb::this_task_arena::enqueue(body);
230+
}
231+
barrier.wait();
220232
});
221233
}
222234
}

0 commit comments

Comments
 (0)