23 |
|
|
24 |
|
/** for time conversion */ |
25 |
|
static final long NPS = (1000L * 1000 * 1000); |
26 |
< |
|
26 |
> |
|
27 |
|
public static void main(String[] args) throws Exception { |
28 |
|
int procs = 0; |
29 |
|
try { |
35 |
|
return; |
36 |
|
} |
37 |
|
for (int reps = 0; reps < 2; ++reps) { |
38 |
< |
ForkJoinPool g = procs == 0? new ForkJoinPool() : |
38 |
> |
ForkJoinPool g = (procs == 0) ? |
39 |
> |
new ForkJoinPool() : |
40 |
|
new ForkJoinPool(procs); |
41 |
|
lastStealCount = g.getStealCount(); |
42 |
|
for (int i = FIRST_SIZE; i <= LAST_SIZE; i++) |
43 |
|
test(g, i); |
44 |
|
System.out.println(g); |
45 |
< |
g.shutdown(); |
45 |
> |
g.shutdown(); |
46 |
|
} |
47 |
|
} |
48 |
|
|
54 |
|
g.invoke(task); |
55 |
|
int solutions = task.solutions; |
56 |
|
long time = System.nanoTime() - start; |
57 |
< |
double secs = ((double)time) / NPS; |
57 |
> |
double secs = (double) time / NPS; |
58 |
|
if (solutions != expectedSolutions[i]) |
59 |
|
throw new Error(); |
60 |
|
System.out.printf("NQueensCS %3d", i); |
64 |
|
lastStealCount = sc; |
65 |
|
System.out.printf(" Steals/t: %5d", ns/ps); |
66 |
|
System.out.println(); |
67 |
< |
} |
67 |
> |
} |
68 |
|
|
69 |
< |
// Boards are represented as arrays where each cell |
69 |
> |
// Boards are represented as arrays where each cell |
70 |
|
// holds the column number of the queen in that row |
71 |
|
|
72 |
|
final int[] sofar; |
73 |
|
NQueensCS nextSubtask; // to link subtasks |
74 |
|
int solutions; |
75 |
< |
NQueensCS(int[] a) { |
76 |
< |
this.sofar = a; |
75 |
> |
NQueensCS(int[] a) { |
76 |
> |
this.sofar = a; |
77 |
|
} |
78 |
|
|
79 |
|
public final void compute() { |
109 |
|
|
110 |
|
private static int processSubtasks(NQueensCS s) { |
111 |
|
// Always run first the task held instead of forked |
112 |
< |
s.compute(); |
112 |
> |
s.compute(); |
113 |
|
int ns = s.solutions; |
114 |
|
s = s.nextSubtask; |
115 |
|
// Then the unstolen ones |