21 |
|
static final long NPS = (1000L * 1000 * 1000); |
22 |
|
|
23 |
|
static int tasksPerPhaser = Math.max(NCPUS / 8, 4); |
24 |
< |
|
24 |
> |
|
25 |
|
static void build(Runnable[] actions, int sz, int lo, int hi, Phaser b) { |
26 |
|
int step = (hi - lo) / tasksPerPhaser; |
27 |
|
if (step > 1) { |
33 |
|
} |
34 |
|
} |
35 |
|
else { |
36 |
< |
for (int i = lo; i < hi; ++i) |
36 |
> |
for (int i = lo; i < hi; ++i) |
37 |
|
actions[i] = new PhaserAction(i, b, sz); |
38 |
|
} |
39 |
|
} |
53 |
|
public void run() { |
54 |
|
int n = size; |
55 |
|
Phaser b = phaser; |
56 |
< |
for(int i = 0; i < n; ++i) |
56 |
> |
for (int i = 0; i < n; ++i) |
57 |
|
b.arriveAndAwaitAdvance(); |
58 |
|
} |
59 |
|
} |
64 |
|
nthreads = Integer.parseInt(args[0]); |
65 |
|
if (args.length > 1) |
66 |
|
tasksPerPhaser = Integer.parseInt(args[1]); |
67 |
< |
|
67 |
> |
|
68 |
|
System.out.printf("Max %d Threads, %d tasks per phaser\n", nthreads, tasksPerPhaser); |
69 |
|
|
70 |
|
for (int k = 2; k <= nthreads; k *= 2) { |
71 |
|
for (int size = FIRST_SIZE; size <= LAST_SIZE; size *= 10) { |
72 |
|
long startTime = System.nanoTime(); |
73 |
< |
|
73 |
> |
|
74 |
|
Runnable[] actions = new Runnable [k]; |
75 |
|
build(actions, size, 0, k, new Phaser()); |
76 |
|
Future[] futures = new Future[k]; |
88 |
|
} |
89 |
|
pool.shutdown(); |
90 |
|
} |
91 |
– |
|
92 |
– |
} |
93 |
– |
|
91 |
|
|
92 |
+ |
} |