From 2405b3816507975ff93e780d4a650bc367222383 Mon Sep 17 00:00:00 2001 From: noobpwnftw Date: Fri, 13 Jul 2018 16:51:26 +0800 Subject: [PATCH] Fix search result aggregation This reverts my earlier change that only the root node gets to output best move after fixing problem with MPI_Allreduce by our custom operator(BestMoveOp). This function is not commutable and we must ensure that its output is consistent among all nodes. --- src/cluster.cpp | 6 +++--- src/search.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cluster.cpp b/src/cluster.cpp index a09f2da6..342c1831 100644 --- a/src/cluster.cpp +++ b/src/cluster.cpp @@ -58,8 +58,8 @@ static void BestMove(void* in, void* inout, int* len, MPI_Datatype* datatype) { MoveInfo* r = static_cast(inout); for (int i=0; i < *len; ++i) { - if ( l[i].depth > r[i].depth - && (l[i].score >= r[i].score || l[i].score >= VALUE_MATE_IN_MAX_PLY)) + if ( (l[i].depth > r[i].depth || (l[i].depth == r[i].depth && l[i].rank < r[i].rank)) + && (l[i].score >= r[i].score)) r[i] = l[i]; } } @@ -102,7 +102,7 @@ void init() { MPI_Type_create_hindexed_block(3, 1, MIdisps.data(), MPI_INT, &MIDatatype); MPI_Type_commit(&MIDatatype); - MPI_Op_create(BestMove, true, &BestMoveOp); + MPI_Op_create(BestMove, false, &BestMoveOp); MPI_Comm_dup(MPI_COMM_WORLD, &InputComm); MPI_Comm_dup(MPI_COMM_WORLD, &TTComm); diff --git a/src/search.cpp b/src/search.cpp index 9e6e5f54..8cf78713 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -295,7 +295,7 @@ void MainThread::search() { previousScore = static_cast(mi.score); - if (Cluster::is_root()) { + if (mi.rank == Cluster::rank()) { // Send again PV info if we have a new best thread if (bestThread != this) sync_cout << UCI::pv(bestThread->rootPos, bestThread->completedDepth, -VALUE_INFINITE, VALUE_INFINITE) << sync_endl; @@ -373,7 +373,7 @@ void Thread::search() { // Distribute search depths across the helper threads if (idx + Cluster::rank() > 0) { - int i = (idx + Cluster::rank() - 1) % 20; + int i = (idx + Cluster::rank() * (int)Options["Threads"] - 1) % 20; if (((rootDepth / ONE_PLY + SkipPhase[i]) / SkipSize[i]) % 2) continue; // Retry with an incremented rootDepth }