Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reallocate TT on threadpool resize.
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 #1601
where additional data and discussion is available.

Closes #1620

No functional change.
  • Loading branch information
vondele authored and snicolet committed Jun 2, 2018
1 parent 31b8243 commit 6cc5614
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/main.cpp
Expand Up @@ -44,7 +44,6 @@ int main(int argc, char* argv[]) {
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

Expand Down
4 changes: 4 additions & 0 deletions src/thread.cpp
Expand Up @@ -26,6 +26,7 @@
#include "thread.h"
#include "uci.h"
#include "syzygy/tbprobe.h"
#include "tt.h"

ThreadPool Threads; // Global object

Expand Down Expand Up @@ -136,6 +137,9 @@ void ThreadPool::set(size_t requested) {
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.
Expand Down
7 changes: 1 addition & 6 deletions src/tt.cpp
Expand Up @@ -36,12 +36,7 @@ TranspositionTable TT; // Our global transposition table

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);
Expand Down

0 comments on commit 6cc5614

Please sign in to comment.