Skip to content

Commit cc76524

Browse files
pb00068zamar
authored andcommitted
Further simplify skipping of plies with threads
No functional change Closes #1020
1 parent 3627348 commit cc76524

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/search.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,6 @@ namespace {
132132
Move pv[3];
133133
};
134134

135-
// skip half of the plies in blocks depending on the helper thread idx.
136-
bool skip_ply(int idx, int ply) {
137-
138-
idx = (idx - 1) % 20 + 1; // cycle after 20 threads.
139-
140-
// number of successive plies to skip, depending on idx.
141-
int ones = 1;
142-
while (ones * (ones + 1) < idx)
143-
ones++;
144-
145-
return ((ply + idx - 1) / ones - ones) % 2 == 0;
146-
}
147-
148135
EasyMoveManager EasyMove;
149136
Value DrawValue[COLOR_NB];
150137

@@ -321,6 +308,9 @@ void MainThread::search() {
321308
std::cout << sync_endl;
322309
}
323310

311+
// Sizes and phases of the skip-blocks, used for distributing search depths across the threads.
312+
static int skipsize[20] = {1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
313+
static int phase [20] = {0, 1, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 7};
324314

325315
// Thread::search() is the main iterative deepening loop. It calls search()
326316
// repeatedly with increasing depth until the allocated thinking time has been
@@ -358,13 +348,15 @@ void Thread::search() {
358348

359349
multiPV = std::min(multiPV, rootMoves.size());
360350

351+
int hIdx = (idx - 1) % 20; // helper index, cycle after 20 threads
352+
361353
// Iterative deepening loop until requested to stop or the target depth is reached
362354
while ( (rootDepth += ONE_PLY) < DEPTH_MAX
363355
&& !Signals.stop
364356
&& (!Limits.depth || Threads.main()->rootDepth / ONE_PLY <= Limits.depth))
365357
{
366-
// skip plies for helper threads
367-
if (idx && skip_ply(idx, rootDepth / ONE_PLY + rootPos.game_ply()))
358+
// skip half of the plies in blocks depending on game ply and helper index.
359+
if (idx && ((rootDepth / ONE_PLY + rootPos.game_ply() + phase[hIdx]) / skipsize[hIdx]) % 2)
368360
continue;
369361

370362
// Age out PV variability metric

0 commit comments

Comments
 (0)