From 0f9ae0d11cd034288a49ef3892c580dfed025091 Mon Sep 17 00:00:00 2001 From: Joost VandeVondele Date: Sat, 22 Feb 2025 10:50:41 +0100 Subject: [PATCH] Check maximum time every iteration This fixes a TCEC timeloss, where slow DTZ TB7 access, in combination with syzygy PV extension, led to a timeloss. While the extension code correctly aborted after spending moveOverhead/2 time, the mainThread did not search sufficient nodes (512 in > 1s) to trigger the stop in check_time. At the same time, totalTime exceeded tm.maximum() due to the factors multiplying tm.optimum(). This corner case is fixed by checking also against the tm.maximum() at each iteration. Even though this problem can't be triggered on fishtest, the patch was verified there. Passed STC: https://tests.stockfishchess.org/tests/view/67b99e1be99f8640b318810d LLR: 2.93 (-2.94,2.94) <-1.75,0.25> Total: 136832 W: 35625 L: 35518 D: 65689 Ptnml(0-2): 499, 14963, 37431, 14978, 545 closes https://github.com/official-stockfish/Stockfish/pull/5896 No functional change --- src/search.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 6a2f8f2d..edd8d9eb 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -520,8 +520,8 @@ void Search::Worker::iterative_deepening() { && !mainThread->ponder) threads.stop = true; - // Stop the search if we have exceeded the totalTime - if (elapsedTime > totalTime) + // Stop the search if we have exceeded the totalTime or maximum + if (elapsedTime > std::min(totalTime, double(mainThread->tm.maximum()))) { // If we are allowed to ponder do not stop the search now but // keep pondering until the GUI sends "ponderhit" or "stop".