]> git.sesse.net Git - stockfish/commitdiff
Move beta counter variables to the per-thread data
authorMarco Costalba <mcostalba@gmail.com>
Sat, 16 May 2009 11:22:40 +0000 (12:22 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 16 May 2009 11:25:35 +0000 (12:25 +0100)
This should reduce concurrent accessing in SMP case.

Suggestion by Tord Romstad.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/search.cpp
src/thread.h

index 4e04d0745ed6caf86c1d8a87eb5baee10a8fbdd1..ba5ad365af2f1caffb95fa56caa9004ec1520dc5 100644 (file)
@@ -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)];
     }
   }
 
index 157df03608411f74e8e78abed527900fa7c88ec4..dc839d441518d51f2f7204b7b6a5adbdbbcda8f7 100644 (file)
@@ -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
 };