Skip to content

Commit

Permalink
Reduce scope of variables
Browse files Browse the repository at this point in the history
Small cleanup TranspositionTable:clear().

Closes #1659

No functional change.
  • Loading branch information
vondele authored and snicolet committed Jul 3, 2018
1 parent a781535 commit 8c4f0ff
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/tt.cpp
Expand Up @@ -53,24 +53,27 @@ void TranspositionTable::resize(size_t mbSize) {
}


/// TranspositionTable::clear() overwrites the entire transposition table
/// with zeros. It is called whenever the table is resized, or when the
/// user asks the program to clear the table (from the UCI interface).
/// It starts as many threads as allowed by the Threads option.
/// TranspositionTable::clear() initializes the entire transposition table to zero,
// in a multi-threaded way.

void TranspositionTable::clear() {

const size_t stride = clusterCount / Options["Threads"];
std::vector<std::thread> threads;

for (size_t idx = 0; idx < Options["Threads"]; idx++)
{
const size_t start = stride * idx,
len = idx != Options["Threads"] - 1 ?
stride :
clusterCount - start;
threads.push_back(std::thread([this, idx, start, len]() {
threads.push_back(std::thread([this, idx]() {

// Thread binding gives faster search on systems with a first-touch policy
if (Options["Threads"] >= 8)
WinProcGroup::bindThisThread(idx);

// Each thread will zero its part of the hash table
const size_t stride = clusterCount / Options["Threads"],
start = stride * idx,
len = idx != Options["Threads"] - 1 ?
stride : clusterCount - start;

std::memset(&table[start], 0, len * sizeof(Cluster));
}));
}
Expand Down

0 comments on commit 8c4f0ff

Please sign in to comment.