Skip to content

Commit 69204f0

Browse files
xoto10snicolet
authored andcommitted
Smarter time management near stop limit
This patch makes Stockfish search same depth again if > 60% of optimum time is already used, instead of trying the next iteration. The idea is that the next iteration will generally take about the same amount of time as has already been used in total. When we are likely to begin the last iteration, as judged by total time taken so far > 0.6 * optimum time, searching the last depth again instead of increasing the depth still helps the other threads in lazy SMP and prepares better move ordering for the next moves. STC : LLR: 2.95 (-2.94,2.94) {-1.00,3.00} Total: 13436 W: 2695 L: 2558 D: 8183 Ptnml(0-2): 222, 1538, 3087, 1611, 253 https://tests.stockfishchess.org/tests/view/5e1618a761fe5f83a67dd964 LTC : LLR: 2.94 (-2.94,2.94) {0.00,2.00} Total: 32160 W: 4261 L: 4047 D: 23852 Ptnml(0-2): 211, 2988, 9448, 3135, 247 https://tests.stockfishchess.org/tests/view/5e162ca061fe5f83a67dd96d The code was revised as suggested by @vondele for multithreading: STC (8 threads): LLR: 2.95 (-2.94,2.94) {0.00,2.00} Total: 16640 W: 2049 L: 1885 D: 12706 Ptnml(0-2): 119, 1369, 5158, 1557, 108 https://tests.stockfishchess.org/tests/view/5e19826a2cc590e03c3c2f52 LTC (8 threads): LLR: 2.95 (-2.94,2.94) {-1.00,3.00} Total: 16536 W: 2758 L: 2629 D: 11149 Ptnml(0-2): 182, 1758, 4296, 1802, 224 https://tests.stockfishchess.org/tests/view/5e18b91a27dab692fcf9a140 Thanks to those discussing Stockfish lazy SMP on fishcooking which made me try this, and to @vondele for suggestions and doing related tests. See full discussion in the pull request thread: #2482 Bench: 4586187
1 parent 9f800a2 commit 69204f0

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

AUTHORS

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Luca Brivio (lucabrivio)
9191
Lucas Braesch (lucasart)
9292
Lyudmil Antonov (lantonov)
9393
Maciej Żenczykowski (zenczykowski)
94+
Malcolm Campbell (xoto10)
9495
Mark Tenzer (31m059)
9596
marotear
9697
Matthew Lai (matthewlai)
@@ -151,6 +152,12 @@ Tracey Emery (basepr1me)
151152
Uri Blass (uriblass)
152153
Vince Negri (cuddlestmonkey)
153154

154-
# Additionally, we acknowledge the authors of fishtest,
155-
# an essential framework for the development of Stockfish:
155+
156+
# Additionally, we acknowledge the authors and maintainer of fishtest,
157+
# an amazing and essential framework for the development of Stockfish!
158+
#
156159
# https://github.com/glinscott/fishtest/blob/master/AUTHORS
160+
161+
162+
163+

src/search.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ void Thread::search() {
393393
contempt = (us == WHITE ? make_score(ct, ct / 2)
394394
: -make_score(ct, ct / 2));
395395

396+
int searchAgainCounter = 0;
397+
396398
// Iterative deepening loop until requested to stop or the target depth is reached
397399
while ( ++rootDepth < MAX_PLY
398400
&& !Threads.stop
@@ -410,6 +412,9 @@ void Thread::search() {
410412
size_t pvFirst = 0;
411413
pvLast = 0;
412414

415+
if (!Threads.increaseDepth)
416+
searchAgainCounter++;
417+
413418
// MultiPV loop. We perform a full root search for each PV line
414419
for (pvIdx = 0; pvIdx < multiPV && !Threads.stop; ++pvIdx)
415420
{
@@ -445,7 +450,7 @@ void Thread::search() {
445450
int failedHighCnt = 0;
446451
while (true)
447452
{
448-
Depth adjustedDepth = std::max(1, rootDepth - failedHighCnt);
453+
Depth adjustedDepth = std::max(1, rootDepth - failedHighCnt - searchAgainCounter);
449454
bestValue = ::search<PV>(rootPos, ss, alpha, beta, adjustedDepth, false);
450455

451456
// Bring the best move to the front. It is critical that sorting
@@ -558,6 +563,11 @@ void Thread::search() {
558563
else
559564
Threads.stop = true;
560565
}
566+
else if ( Threads.increaseDepth
567+
&& Time.elapsed() > Time.optimum() * fallingEval * reduction * bestMoveInstability * 0.6)
568+
Threads.increaseDepth = false;
569+
else
570+
Threads.increaseDepth = true;
561571
}
562572

563573
mainThread->iterValue[iterIdx] = bestValue;

src/thread.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ void ThreadPool::start_thinking(Position& pos, StateListPtr& states,
179179
main()->wait_for_search_finished();
180180

181181
main()->stopOnPonderhit = stop = false;
182+
increaseDepth = true;
182183
main()->ponder = ponderMode;
183184
Search::Limits = limits;
184185
Search::RootMoves rootMoves;

src/thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct ThreadPool : public std::vector<Thread*> {
109109
uint64_t nodes_searched() const { return accumulate(&Thread::nodes); }
110110
uint64_t tb_hits() const { return accumulate(&Thread::tbHits); }
111111

112-
std::atomic_bool stop;
112+
std::atomic_bool stop, increaseDepth;
113113

114114
private:
115115
StateListPtr setupStates;

0 commit comments

Comments
 (0)