145
|
1 /* { dg-do compile } */
|
|
2 /* { dg-options "-O3 -std=gnu++14" } */
|
|
3
|
|
4 template <typename Function>
|
|
5 bool run(const int item_count,
|
|
6 Function && process_range,
|
|
7 const int max_parallelism,
|
|
8 int* progress = nullptr)
|
|
9 {
|
|
10 if (max_parallelism <= 1)
|
|
11 {
|
|
12 if (progress == nullptr)
|
|
13 {
|
|
14 return process_range(0);
|
|
15 }
|
|
16 else
|
|
17 {
|
|
18 auto result = true;
|
|
19 for (int i = 0; i != item_count && result; ++i)
|
|
20 {
|
|
21 (*progress)++;
|
|
22 result = process_range(i);
|
|
23 }
|
|
24 return result;
|
|
25 }
|
|
26 }
|
|
27
|
|
28 if (max_parallelism > 10)
|
|
29 {
|
|
30 if (progress == nullptr)
|
|
31 {
|
|
32 return process_range(0);
|
|
33 }
|
|
34 else
|
|
35 {
|
|
36 auto result = true;
|
|
37 for (int i = 0; i != item_count && result; ++i)
|
|
38 {
|
|
39 (*progress)++;
|
|
40 result = process_range(i);
|
|
41 }
|
|
42 return result;
|
|
43 }
|
|
44 }
|
|
45 return false;
|
|
46 }
|
|
47
|
|
48 namespace
|
|
49 {
|
|
50 __attribute__((optimize(0))) bool worker_fun(const int)
|
|
51 {
|
|
52 return true;
|
|
53 }
|
|
54 }
|
|
55
|
|
56 void demo(int n)
|
|
57 {
|
|
58 for (int i = 0; i < n; ++i)
|
|
59 {
|
|
60 run(n, &worker_fun, n);
|
|
61 }
|
|
62 }
|