mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-20 00:56:39 +08:00
StateInfo is usually allocated on the stack by search()
And passed in do_move(), this ensures maximum efficiency and speed and at the same time unlimited move numbers. The draw back is that to handle Position init we need to reserve a StateInfo inside Position itself and use at init time and when copying from another Position. After lazy SMP we don't need anymore this gimmick and we can get rid of this special case and always pass an external StateInfo to Position object. Also rewritten and simplified Position constructors. Verified it does not regress with a 3 threads SMP test: ELO: -0.00 +-12.7 (95%) LOS: 50.0% Total: 1000 W: 173 L: 173 D: 654 No functional change.
This commit is contained in:
@@ -26,8 +26,6 @@
|
||||
#include "thread.h"
|
||||
#include "uci.h"
|
||||
|
||||
using namespace Search;
|
||||
|
||||
ThreadPool Threads; // Global object
|
||||
|
||||
/// Thread constructor launches the thread and then waits until it goes to sleep
|
||||
@@ -171,26 +169,34 @@ int64_t ThreadPool::nodes_searched() {
|
||||
/// ThreadPool::start_thinking() wakes up the main thread sleeping in idle_loop()
|
||||
/// and starts a new search, then returns immediately.
|
||||
|
||||
void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
|
||||
StateStackPtr& states) {
|
||||
void ThreadPool::start_thinking(const Position& pos, StateListPtr& states,
|
||||
const Search::LimitsType& limits) {
|
||||
|
||||
main()->wait_for_search_finished();
|
||||
|
||||
Signals.stopOnPonderhit = Signals.stop = false;
|
||||
|
||||
main()->rootMoves.clear();
|
||||
main()->rootPos = pos;
|
||||
Limits = limits;
|
||||
if (states.get()) // If we don't set a new position, preserve current state
|
||||
{
|
||||
SetupStates = std::move(states); // Ownership transfer here
|
||||
assert(!states.get());
|
||||
}
|
||||
Search::Signals.stopOnPonderhit = Search::Signals.stop = false;
|
||||
Search::Limits = limits;
|
||||
Search::RootMoves rootMoves;
|
||||
|
||||
for (const auto& m : MoveList<LEGAL>(pos))
|
||||
if ( limits.searchmoves.empty()
|
||||
|| std::count(limits.searchmoves.begin(), limits.searchmoves.end(), m))
|
||||
main()->rootMoves.push_back(RootMove(m));
|
||||
rootMoves.push_back(Search::RootMove(m));
|
||||
|
||||
// After ownership transfer 'states' becomes empty, so if we stop the search
|
||||
// and call 'go' again without setting a new position states.get() == NULL.
|
||||
assert(states.get() || setupStates.get());
|
||||
|
||||
if (states.get())
|
||||
setupStates = std::move(states); // Ownership transfer, states is now empty
|
||||
|
||||
for (Thread* th : Threads)
|
||||
{
|
||||
th->maxPly = 0;
|
||||
th->rootDepth = DEPTH_ZERO;
|
||||
th->rootMoves = rootMoves;
|
||||
th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th);
|
||||
}
|
||||
|
||||
main()->start_searching();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user