/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* Written by Doug Lea with assistance from members of JCP JSR-166
* Expert Group and released to the public domain, as explained at
*/
/*
* @test
* @bug 6865571
* @run main NQueensCS maxBoardSize=11 reps=1
* @run main NQueensCS maxBoardSize=11 reps=1 procs=8
*/
static long lastStealCount;
static int boardSize;
static final int[] expectedSolutions = new int[] {
0, 1, 0, 0, 2, 10, 4, 40, 92, 352, 724, 2680, 14200,
73712, 365596, 2279184, 14772512, 95815104, 666090624
}; // see http://www.durangobill.com/N_Queens.html
return null;
}
}
/** for time conversion */
/**
* Usage: NQueensCS [minBoardSize=N] [maxBoardSize=N] [procs=N] [reps=N]
*/
// Board sizes too small: hard to measure well.
// Board sizes too large: take too long to run.
new ForkJoinPool() :
new ForkJoinPool(procs);
lastStealCount = g.getStealCount();
for (int i = minBoardSize; i <= maxBoardSize; i++)
test(g, i);
g.shutdown();
}
}
boardSize = i;
int ps = g.getParallelism();
if (solutions != expectedSolutions[i])
throw new Error();
long sc = g.getStealCount();
lastStealCount = sc;
}
// Boards are represented as arrays where each cell
// holds the column number of the queen in that row
final int[] sofar;
int solutions;
NQueensCS(int[] a) {
this.sofar = a;
}
public final void compute() {
solutions = 1;
}
for (int q = 0; q < bs; ++q) {
for (int i = 0; i < row; i++) {
int p = array[i];
continue outer; // attacked
}
s = subtask;
}
return s;
}
// Always run first the task held instead of forked
s.compute();
s = s.nextSubtask;
// Then the unstolen ones
s.compute();
s = s.nextSubtask;
}
// Then wait for the stolen ones
while (s != null) {
s.join();
s = s.nextSubtask;
}
return ns;
}
}