mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-21 17:46:26 +08:00
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:
https://github.com/official-stockfish/Stockfish/pull/2482
Bench: 4586187
This commit is contained in:
committed by
Stéphane Nicolet
parent
9f800a2577
commit
69204f0720
11
AUTHORS
11
AUTHORS
@@ -91,6 +91,7 @@ Luca Brivio (lucabrivio)
|
|||||||
Lucas Braesch (lucasart)
|
Lucas Braesch (lucasart)
|
||||||
Lyudmil Antonov (lantonov)
|
Lyudmil Antonov (lantonov)
|
||||||
Maciej Żenczykowski (zenczykowski)
|
Maciej Żenczykowski (zenczykowski)
|
||||||
|
Malcolm Campbell (xoto10)
|
||||||
Mark Tenzer (31m059)
|
Mark Tenzer (31m059)
|
||||||
marotear
|
marotear
|
||||||
Matthew Lai (matthewlai)
|
Matthew Lai (matthewlai)
|
||||||
@@ -151,6 +152,12 @@ Tracey Emery (basepr1me)
|
|||||||
Uri Blass (uriblass)
|
Uri Blass (uriblass)
|
||||||
Vince Negri (cuddlestmonkey)
|
Vince Negri (cuddlestmonkey)
|
||||||
|
|
||||||
# Additionally, we acknowledge the authors of fishtest,
|
|
||||||
# an essential framework for the development of Stockfish:
|
# Additionally, we acknowledge the authors and maintainer of fishtest,
|
||||||
|
# an amazing and essential framework for the development of Stockfish!
|
||||||
|
#
|
||||||
# https://github.com/glinscott/fishtest/blob/master/AUTHORS
|
# https://github.com/glinscott/fishtest/blob/master/AUTHORS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -393,6 +393,8 @@ void Thread::search() {
|
|||||||
contempt = (us == WHITE ? make_score(ct, ct / 2)
|
contempt = (us == WHITE ? make_score(ct, ct / 2)
|
||||||
: -make_score(ct, ct / 2));
|
: -make_score(ct, ct / 2));
|
||||||
|
|
||||||
|
int searchAgainCounter = 0;
|
||||||
|
|
||||||
// Iterative deepening loop until requested to stop or the target depth is reached
|
// Iterative deepening loop until requested to stop or the target depth is reached
|
||||||
while ( ++rootDepth < MAX_PLY
|
while ( ++rootDepth < MAX_PLY
|
||||||
&& !Threads.stop
|
&& !Threads.stop
|
||||||
@@ -410,6 +412,9 @@ void Thread::search() {
|
|||||||
size_t pvFirst = 0;
|
size_t pvFirst = 0;
|
||||||
pvLast = 0;
|
pvLast = 0;
|
||||||
|
|
||||||
|
if (!Threads.increaseDepth)
|
||||||
|
searchAgainCounter++;
|
||||||
|
|
||||||
// MultiPV loop. We perform a full root search for each PV line
|
// MultiPV loop. We perform a full root search for each PV line
|
||||||
for (pvIdx = 0; pvIdx < multiPV && !Threads.stop; ++pvIdx)
|
for (pvIdx = 0; pvIdx < multiPV && !Threads.stop; ++pvIdx)
|
||||||
{
|
{
|
||||||
@@ -445,7 +450,7 @@ void Thread::search() {
|
|||||||
int failedHighCnt = 0;
|
int failedHighCnt = 0;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Depth adjustedDepth = std::max(1, rootDepth - failedHighCnt);
|
Depth adjustedDepth = std::max(1, rootDepth - failedHighCnt - searchAgainCounter);
|
||||||
bestValue = ::search<PV>(rootPos, ss, alpha, beta, adjustedDepth, false);
|
bestValue = ::search<PV>(rootPos, ss, alpha, beta, adjustedDepth, false);
|
||||||
|
|
||||||
// Bring the best move to the front. It is critical that sorting
|
// Bring the best move to the front. It is critical that sorting
|
||||||
@@ -558,6 +563,11 @@ void Thread::search() {
|
|||||||
else
|
else
|
||||||
Threads.stop = true;
|
Threads.stop = true;
|
||||||
}
|
}
|
||||||
|
else if ( Threads.increaseDepth
|
||||||
|
&& Time.elapsed() > Time.optimum() * fallingEval * reduction * bestMoveInstability * 0.6)
|
||||||
|
Threads.increaseDepth = false;
|
||||||
|
else
|
||||||
|
Threads.increaseDepth = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mainThread->iterValue[iterIdx] = bestValue;
|
mainThread->iterValue[iterIdx] = bestValue;
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ void ThreadPool::start_thinking(Position& pos, StateListPtr& states,
|
|||||||
main()->wait_for_search_finished();
|
main()->wait_for_search_finished();
|
||||||
|
|
||||||
main()->stopOnPonderhit = stop = false;
|
main()->stopOnPonderhit = stop = false;
|
||||||
|
increaseDepth = true;
|
||||||
main()->ponder = ponderMode;
|
main()->ponder = ponderMode;
|
||||||
Search::Limits = limits;
|
Search::Limits = limits;
|
||||||
Search::RootMoves rootMoves;
|
Search::RootMoves rootMoves;
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ struct ThreadPool : public std::vector<Thread*> {
|
|||||||
uint64_t nodes_searched() const { return accumulate(&Thread::nodes); }
|
uint64_t nodes_searched() const { return accumulate(&Thread::nodes); }
|
||||||
uint64_t tb_hits() const { return accumulate(&Thread::tbHits); }
|
uint64_t tb_hits() const { return accumulate(&Thread::tbHits); }
|
||||||
|
|
||||||
std::atomic_bool stop;
|
std::atomic_bool stop, increaseDepth;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StateListPtr setupStates;
|
StateListPtr setupStates;
|
||||||
|
|||||||
Reference in New Issue
Block a user