From: Marco Costalba Date: Tue, 26 Jan 2010 11:05:38 +0000 (+0100) Subject: Reduce lock contention in sp_search_pv() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=cf9bf4e58fba6f478f3263412d224a4499f3fad6 Reduce lock contention in sp_search_pv() In less then 1% of cases value > sp->bestValue, so avoid an useless lock in the common case. This is the same change already applied to sp_search(). Also SplitPoint futilityValue is not volatile because never changes after has been assigned in split() No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/search.cpp b/src/search.cpp index 7c341f87..8c5319b2 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -2046,37 +2046,40 @@ namespace { break; // New best move? - lock_grab(&(sp->lock)); - if (value > sp->bestValue && !thread_should_stop(threadID)) + if (value > sp->bestValue) // Less then 2% of cases { - sp->bestValue = value; - if (value > sp->alpha) + lock_grab(&(sp->lock)); + if (value > sp->bestValue && !thread_should_stop(threadID)) { - // Ask threads to stop before to modify sp->alpha - if (value >= sp->beta) + sp->bestValue = value; + if (value > sp->alpha) { - for (int i = 0; i < ActiveThreads; i++) - if (i != threadID && (i == sp->master || sp->slaves[i])) - Threads[i].stop = true; + // Ask threads to stop before to modify sp->alpha + if (value >= sp->beta) + { + for (int i = 0; i < ActiveThreads; i++) + if (i != threadID && (i == sp->master || sp->slaves[i])) + Threads[i].stop = true; - sp->finished = true; - } + sp->finished = true; + } - sp->alpha = value; + sp->alpha = value; - sp_update_pv(sp->parentSstack, ss, sp->ply); - if (value == value_mate_in(sp->ply + 1)) - ss[sp->ply].mateKiller = move; - } - // If we are at ply 1, and we are searching the first root move at - // ply 0, set the 'Problem' variable if the score has dropped a lot - // (from the computer's point of view) since the previous iteration. - if ( sp->ply == 1 - && Iteration >= 2 - && -value <= IterationInfo[Iteration-1].value - ProblemMargin) - Problem = true; + sp_update_pv(sp->parentSstack, ss, sp->ply); + if (value == value_mate_in(sp->ply + 1)) + ss[sp->ply].mateKiller = move; + } + // If we are at ply 1, and we are searching the first root move at + // ply 0, set the 'Problem' variable if the score has dropped a lot + // (from the computer's point of view) since the previous iteration. + if ( sp->ply == 1 + && Iteration >= 2 + && -value <= IterationInfo[Iteration-1].value - ProblemMargin) + Problem = true; + } + lock_release(&(sp->lock)); } - lock_release(&(sp->lock)); } lock_grab(&(sp->lock)); diff --git a/src/thread.h b/src/thread.h index d0c1d8e9..899ccfe9 100644 --- a/src/thread.h +++ b/src/thread.h @@ -51,7 +51,8 @@ struct SplitPoint { SearchStack *parentSstack; int ply; Depth depth; - volatile Value alpha, beta, bestValue, futilityValue; + volatile Value alpha, beta, bestValue; + Value futilityValue; bool pvNode; int master, slaves[THREAD_MAX]; Lock lock;