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

Improve multi-threaded mate finding

If any thread found a 'mate in x' stop the search. Previously only
mainThread would do so. Requires the bestThread selection to be
adjusted to always prefer mate scores, even if the search depth is less.

I've tried to collect some data for this patch. On 30 cores, mate finding
seems 5-30% faster on average. It is not so easy to get numbers for this,
as the time to find a mate fluctuates significantly with multi-threaded runs,
so it is an average over 100 searches for the same position. Furthermore,
hash size and position make a difference as well.

Bench: 5965302
This commit is contained in:
Joost VandeVondele 2017-08-18 19:38:18 +02:00 committed by Marco Costalba
parent 92c39522b1
commit d5f883ab29

View file

@ -308,7 +308,9 @@ void MainThread::search() {
Depth depthDiff = th->completedDepth - bestThread->completedDepth; Depth depthDiff = th->completedDepth - bestThread->completedDepth;
Value scoreDiff = th->rootMoves[0].score - bestThread->rootMoves[0].score; Value scoreDiff = th->rootMoves[0].score - bestThread->rootMoves[0].score;
if (scoreDiff > 0 && depthDiff >= 0) // Select the thread with the best score, always if it is a mate
if ( scoreDiff > 0
&& (depthDiff >= 0 || th->rootMoves[0].score >= VALUE_MATE_IN_MAX_PLY))
bestThread = th; bestThread = th;
} }
} }
@ -455,16 +457,20 @@ void Thread::search() {
// Sort the PV lines searched so far and update the GUI // Sort the PV lines searched so far and update the GUI
std::stable_sort(rootMoves.begin(), rootMoves.begin() + PVIdx + 1); std::stable_sort(rootMoves.begin(), rootMoves.begin() + PVIdx + 1);
if (!mainThread) if ( mainThread
continue; && (Threads.stop || PVIdx + 1 == multiPV || Time.elapsed() > 3000))
if (Threads.stop || PVIdx + 1 == multiPV || Time.elapsed() > 3000)
sync_cout << UCI::pv(rootPos, rootDepth, alpha, beta) << sync_endl; sync_cout << UCI::pv(rootPos, rootDepth, alpha, beta) << sync_endl;
} }
if (!Threads.stop) if (!Threads.stop)
completedDepth = rootDepth; completedDepth = rootDepth;
// Have we found a "mate in x"?
if ( Limits.mate
&& bestValue >= VALUE_MATE_IN_MAX_PLY
&& VALUE_MATE - bestValue <= 2 * Limits.mate)
Threads.stop = true;
if (!mainThread) if (!mainThread)
continue; continue;
@ -472,12 +478,6 @@ void Thread::search() {
if (skill.enabled() && skill.time_to_pick(rootDepth)) if (skill.enabled() && skill.time_to_pick(rootDepth))
skill.pick_best(multiPV); skill.pick_best(multiPV);
// Have we found a "mate in x"?
if ( Limits.mate
&& bestValue >= VALUE_MATE_IN_MAX_PLY
&& VALUE_MATE - bestValue <= 2 * Limits.mate)
Threads.stop = true;
// Do we have time for the next iteration? Can we stop searching now? // Do we have time for the next iteration? Can we stop searching now?
if (Limits.use_time_management()) if (Limits.use_time_management())
{ {