From cd2265a46b2572536a24ee06079594e4b08aae14 Mon Sep 17 00:00:00 2001 From: rektdie Date: Tue, 6 Oct 2026 18:03:08 +0200 Subject: [PATCH] smp persist history | bench 1632393 --- source/search.h | 8 ++++++++ source/uci.cpp | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/source/search.h b/source/search.h index 1639cb2..3b1180b 100644 --- a/source/search.h +++ b/source/search.h @@ -272,6 +272,14 @@ public: ss = {}; positionHistory.resize(1000); } + + void CopyLearningFrom(const SearchContext& other) { + history = other.history; + conthist = other.conthist; + corrhist = other.corrhist; + capthist = other.capthist; + killerMoves = other.killerMoves; + } }; bool SEE(Board& board, Move& move, int threshold); diff --git a/source/uci.cpp b/source/uci.cpp index 9bbff0f..924463d 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -193,9 +193,12 @@ static double ReadParam(const std::string& param, const std::string &command) { #ifdef _WIN32 // Windows implementation using std::thread template -static void ThreadFunc(Board board, SearchParams params, SEARCH::SearchContext* ctx) { +static void ThreadFunc(Board board, SearchParams params, SEARCH::SearchContext* ctx, SEARCH::SearchContext* master) { SearchResults results = SEARCH::SearchPosition(board, params, ctx); int id = ctx->threadId; + if (id == 0) { + master->CopyLearningFrom(*ctx); + } delete ctx; if (id == 0) { searchStopped.store(true, std::memory_order_relaxed); @@ -212,9 +215,9 @@ static void StartSearchThread(Board& board, SearchParams params, SEARCH::SearchC ctxCopy->doPrint = true; if (params.nodes) { - searchThreads.emplace_back(ThreadFunc, board, params, ctxCopy); + searchThreads.emplace_back(ThreadFunc, board, params, ctxCopy, ctx); } else { - searchThreads.emplace_back(ThreadFunc, board, params, ctxCopy); + searchThreads.emplace_back(ThreadFunc, board, params, ctxCopy, ctx); } } @@ -222,10 +225,14 @@ static void StartSearchThread(Board& board, SearchParams params, SEARCH::SearchC // Unix/Linux implementation using pthread template static void* ThreadFunc(void* arg) { - auto* tup = static_cast*>(arg); + auto* tup = static_cast*>(arg); SEARCH::SearchContext* ctx = std::get<2>(*tup); + SEARCH::SearchContext* master = std::get<3>(*tup); SearchResults results = SEARCH::SearchPosition(std::get<0>(*tup), std::get<1>(*tup), ctx); int id = ctx->threadId; + if (id == 0) { + master->CopyLearningFrom(*ctx); + } delete ctx; delete tup; if (id == 0) { @@ -251,7 +258,7 @@ static void StartSearchThread(Board& board, SearchParams params, SEARCH::SearchC int rc = 0; if (params.nodes) { - auto* arg = new std::tuple(board, params, ctxCopy); + auto* arg = new std::tuple(board, params, ctxCopy, ctx); rc = pthread_create(&thread, &attr, ThreadFunc, arg); if (rc != 0) { delete std::get<2>(*arg); @@ -259,7 +266,7 @@ static void StartSearchThread(Board& board, SearchParams params, SEARCH::SearchC ctxCopy = nullptr; } } else { - auto* arg = new std::tuple(board, params, ctxCopy); + auto* arg = new std::tuple(board, params, ctxCopy, ctx); rc = pthread_create(&thread, &attr, ThreadFunc, arg); if (rc != 0) { delete std::get<2>(*arg); -- 2.47.3