]> git.sesse.net Git - stockfish/commitdiff
Reallocate TT on threadpool resize.
authorJoost VandeVondele <Joost.VandeVondele@gmail.com>
Sat, 2 Jun 2018 15:02:23 +0000 (17:02 +0200)
committerStéphane Nicolet <cassio@free.fr>
Sat, 2 Jun 2018 15:03:01 +0000 (17:03 +0200)
Makes sure the potential benefit of first touch does not depend on
the order of the UCI commands Threads and Hash, by reallocating the
hash if a Threads is issued. The cost is zeroing the TT once more
than needed. In case the prefered order (first Threads than Hash)
is employed, this amounts to zeroing the default sized TT (16Mb),
which is essentially instantaneous.

Follow up for https://github.com/official-stockfish/Stockfish/pull/1601
where additional data and discussion is available.

Closes https://github.com/official-stockfish/Stockfish/pull/1620

No functional change.

src/main.cpp
src/thread.cpp
src/tt.cpp

index b5067b9b2df725a8f5cd4bac3cf6628d8175f479..c5bf325538f3d66a30566aef023f02235a0920d5 100644 (file)
@@ -44,7 +44,6 @@ int main(int argc, char* argv[]) {
   Search::init();
   Pawns::init();
   Tablebases::init(Options["SyzygyPath"]); // After Bitboards are set
   Search::init();
   Pawns::init();
   Tablebases::init(Options["SyzygyPath"]); // After Bitboards are set
-  TT.resize(Options["Hash"]);
   Threads.set(Options["Threads"]);
   Search::clear(); // After threads are up
 
   Threads.set(Options["Threads"]);
   Search::clear(); // After threads are up
 
index cab2d382f1737da5da250e304fcd6e4627b10cd6..43a38e804d83e698d04345bb084162728f95a59e 100644 (file)
@@ -26,6 +26,7 @@
 #include "thread.h"
 #include "uci.h"
 #include "syzygy/tbprobe.h"
 #include "thread.h"
 #include "uci.h"
 #include "syzygy/tbprobe.h"
+#include "tt.h"
 
 ThreadPool Threads; // Global object
 
 
 ThreadPool Threads; // Global object
 
@@ -136,6 +137,9 @@ void ThreadPool::set(size_t requested) {
           push_back(new Thread(size()));
       clear();
   }
           push_back(new Thread(size()));
       clear();
   }
+
+  // Reallocate the hash with the new threadpool size
+  TT.resize(Options["Hash"]);
 }
 
 /// ThreadPool::clear() sets threadPool data to initial values.
 }
 
 /// ThreadPool::clear() sets threadPool data to initial values.
index 5fa1290b9f721400cdb70d785277bc9fd5a8b736..9f0bc4ba63091919a123fad9a2185f5f8e1e4fa6 100644 (file)
@@ -36,12 +36,7 @@ TranspositionTable TT; // Our global transposition table
 
 void TranspositionTable::resize(size_t mbSize) {
 
 
 void TranspositionTable::resize(size_t mbSize) {
 
-  size_t newClusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
-
-  if (newClusterCount == clusterCount)
-      return;
-
-  clusterCount = newClusterCount;
+  clusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
 
   free(mem);
   mem = malloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1);
 
   free(mem);
   mem = malloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1);