From: Marco Costalba Date: Sat, 16 May 2009 11:22:40 +0000 (+0100) Subject: Move beta counter variables to the per-thread data X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=a75aa6035b1ac27a6a2a44f523ec2ffd011485d8;ds=sidebyside Move beta counter variables to the per-thread data This should reduce concurrent accessing in SMP case. Suggestion by Tord Romstad. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/search.cpp b/src/search.cpp index 4e04d074..ba5ad365 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -72,7 +72,8 @@ namespace { // Apart for the first one that has its score, following moves // normally have score -VALUE_INFINITE, so are ordered according // to the number of beta cutoffs occurred under their subtree during - // the last iteration. + // the last iteration. The counters are per thread variables to avoid + // concurrent accessing under SMP case. struct BetaCounterType { @@ -80,8 +81,6 @@ namespace { void clear(); void add(Color us, Depth d, int threadID); void read(Color us, int64_t& our, int64_t& their); - - int64_t hits[THREAD_MAX][2]; }; @@ -1894,13 +1893,13 @@ namespace { void BetaCounterType::clear() { for (int i = 0; i < THREAD_MAX; i++) - hits[i][WHITE] = hits[i][BLACK] = 0ULL; + Threads[i].betaCutOffs[WHITE] = Threads[i].betaCutOffs[BLACK] = 0ULL; } void BetaCounterType::add(Color us, Depth d, int threadID) { // Weighted count based on depth - hits[threadID][us] += int(d); + Threads[threadID].betaCutOffs[us] += unsigned(d); } void BetaCounterType::read(Color us, int64_t& our, int64_t& their) { @@ -1908,8 +1907,8 @@ namespace { our = their = 0UL; for (int i = 0; i < THREAD_MAX; i++) { - our += hits[i][us]; - their += hits[i][opposite_color(us)]; + our += Threads[i].betaCutOffs[us]; + their += Threads[i].betaCutOffs[opposite_color(us)]; } } diff --git a/src/thread.h b/src/thread.h index 157df036..dc839d44 100644 --- a/src/thread.h +++ b/src/thread.h @@ -66,13 +66,14 @@ struct Thread { SplitPoint *splitPoint; int activeSplitPoints; uint64_t nodes; + uint64_t betaCutOffs[2]; bool failHighPly1; volatile bool stop; volatile bool running; volatile bool idle; volatile bool workIsWaiting; volatile bool printCurrentLine; - unsigned char pad[64]; + unsigned char pad[64]; // set some distance among local data for each thread };