1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00

Simplify skipping of plies with helper threads

Replaces the HalfDensity array with an equivalent, compact implementation.
Includes suggestions by mcostalba & snicolet.

No functional change

Closes #1004
This commit is contained in:
Joost VandeVondele 2017-02-26 16:41:58 -08:00 committed by Joona Kiiski
parent 8f7e032b8c
commit 1810c4d758

View file

@ -132,34 +132,18 @@ namespace {
Move pv[3]; Move pv[3];
}; };
// Set of rows with half bits set to 1 and half to 0. It is used to allocate // skip half of the plies in blocks depending on the helper thread idx.
// the search depths across the threads. bool skip_ply(int idx, int ply) {
typedef std::vector<int> Row;
const Row HalfDensity[] = { idx = (idx - 1) % 20 + 1; // cycle after 20 threads.
{0, 1},
{1, 0},
{0, 0, 1, 1},
{0, 1, 1, 0},
{1, 1, 0, 0},
{1, 0, 0, 1},
{0, 0, 0, 1, 1, 1},
{0, 0, 1, 1, 1, 0},
{0, 1, 1, 1, 0, 0},
{1, 1, 1, 0, 0, 0},
{1, 1, 0, 0, 0, 1},
{1, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 1},
{0, 0, 0, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 0 ,0},
{0, 1, 1, 1, 1, 0, 0 ,0},
{1, 1, 1, 1, 0, 0, 0 ,0},
{1, 1, 1, 0, 0, 0, 0 ,1},
{1, 1, 0, 0, 0, 0, 1 ,1},
{1, 0, 0, 0, 0, 1, 1 ,1},
};
const size_t HalfDensitySize = std::extent<decltype(HalfDensity)>::value; // number of successive plies to skip, depending on idx.
int ones = 1;
while (ones * (ones + 1) < idx)
ones++;
return ((ply + idx - 1) / ones - ones) % 2 == 0;
}
EasyMoveManager EasyMove; EasyMoveManager EasyMove;
Value DrawValue[COLOR_NB]; Value DrawValue[COLOR_NB];
@ -379,14 +363,9 @@ void Thread::search() {
&& !Signals.stop && !Signals.stop
&& (!Limits.depth || Threads.main()->rootDepth / ONE_PLY <= Limits.depth)) && (!Limits.depth || Threads.main()->rootDepth / ONE_PLY <= Limits.depth))
{ {
// Set up the new depths for the helper threads skipping on average every // skip plies for helper threads
// 2nd ply (using a half-density matrix). if (idx && skip_ply(idx, rootDepth / ONE_PLY + rootPos.game_ply()))
if (!mainThread) continue;
{
const Row& row = HalfDensity[(idx - 1) % HalfDensitySize];
if (row[(rootDepth / ONE_PLY + rootPos.game_ply()) % row.size()])
continue;
}
// Age out PV variability metric // Age out PV variability metric
if (mainThread) if (mainThread)