Also rename idle_thread_exists() in available_thread_exists()
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
}
csStr >> threads;
csVal >> val;
}
csStr >> threads;
csVal >> val;
- if (val < 1 || val > THREAD_MAX)
+ if (val < 1 || val > MAX_THREADS)
- cerr << "The number of threads must be between 1 and " << THREAD_MAX << endl;
+ cerr << "The number of threads must be between 1 and " << MAX_THREADS << endl;
Application::exit_with_failure();
}
set_option_value("Hash", ttSize);
Application::exit_with_failure();
}
set_option_value("Hash", ttSize);
// Pawn and material hash tables, indexed by the current thread id.
// Note that they will be initialized at 0 being global variables.
// Pawn and material hash tables, indexed by the current thread id.
// Note that they will be initialized at 0 being global variables.
- MaterialInfoTable* MaterialTable[THREAD_MAX];
- PawnInfoTable* PawnTable[THREAD_MAX];
+ MaterialInfoTable* MaterialTable[MAX_THREADS];
+ PawnInfoTable* PawnTable[MAX_THREADS];
// Sizes of pawn and material hash tables
const int PawnTableSize = 16384;
// Sizes of pawn and material hash tables
const int PawnTableSize = 16384;
Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
assert(pos.is_ok());
Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
assert(pos.is_ok());
- assert(threadID >= 0 && threadID < THREAD_MAX);
+ assert(threadID >= 0 && threadID < MAX_THREADS);
assert(!pos.is_check());
memset(&ei, 0, sizeof(EvalInfo));
assert(!pos.is_check());
memset(&ei, 0, sizeof(EvalInfo));
void init_eval(int threads) {
void init_eval(int threads) {
- assert(threads <= THREAD_MAX);
+ assert(threads <= MAX_THREADS);
- for (int i = 0; i < THREAD_MAX; i++)
+ for (int i = 0; i < MAX_THREADS; i++)
- for (int i = 0; i < THREAD_MAX; i++)
+ for (int i = 0; i < MAX_THREADS; i++)
{
delete PawnTable[i];
delete MaterialTable[i];
{
delete PawnTable[i];
delete MaterialTable[i];
void resetBetaCounters();
int64_t nodes_searched() const;
void get_beta_counters(Color us, int64_t& our, int64_t& their) const;
void resetBetaCounters();
int64_t nodes_searched() const;
void get_beta_counters(Color us, int64_t& our, int64_t& their) const;
- bool idle_thread_exists(int master) const;
+ bool available_thread_exists(int master) const;
bool thread_is_available(int slave, int master) const;
bool thread_should_stop(int threadID) const;
void wake_sleeping_threads();
bool thread_is_available(int slave, int master) const;
bool thread_should_stop(int threadID) const;
void wake_sleeping_threads();
int ActiveThreads;
bool AllThreadsShouldExit, AllThreadsShouldSleep;
int ActiveThreads;
bool AllThreadsShouldExit, AllThreadsShouldSleep;
- Thread threads[THREAD_MAX];
- SplitPoint SplitPointStack[THREAD_MAX][ACTIVE_SPLIT_POINTS_MAX];
+ Thread threads[MAX_THREADS];
+ SplitPoint SplitPointStack[MAX_THREADS][ACTIVE_SPLIT_POINTS_MAX];
pthread_cond_t WaitCond;
pthread_mutex_t WaitLock;
#else
pthread_cond_t WaitCond;
pthread_mutex_t WaitLock;
#else
- HANDLE SitIdleEvent[THREAD_MAX];
+ HANDLE SitIdleEvent[MAX_THREADS];
&& bestValue < beta
&& depth >= MinimumSplitDepth
&& Iteration <= 99
&& bestValue < beta
&& depth >= MinimumSplitDepth
&& Iteration <= 99
- && TM.idle_thread_exists(threadID)
+ && TM.available_thread_exists(threadID)
&& !AbortSearch
&& !TM.thread_should_stop(threadID)
&& TM.split(pos, ss, ply, &alpha, &beta, &bestValue, VALUE_NONE,
&& !AbortSearch
&& !TM.thread_should_stop(threadID)
&& TM.split(pos, ss, ply, &alpha, &beta, &bestValue, VALUE_NONE,
&& bestValue < beta
&& depth >= MinimumSplitDepth
&& Iteration <= 99
&& bestValue < beta
&& depth >= MinimumSplitDepth
&& Iteration <= 99
- && TM.idle_thread_exists(threadID)
+ && TM.available_thread_exists(threadID)
&& !AbortSearch
&& !TM.thread_should_stop(threadID)
&& TM.split(pos, ss, ply, &beta, &beta, &bestValue, futilityValue, //FIXME: SMP & futilityValue
&& !AbortSearch
&& !TM.thread_should_stop(threadID)
&& TM.split(pos, ss, ply, &beta, &beta, &bestValue, futilityValue, //FIXME: SMP & futilityValue
void ThreadsManager::resetNodeCounters() {
void ThreadsManager::resetNodeCounters() {
- for (int i = 0; i < THREAD_MAX; i++)
+ for (int i = 0; i < MAX_THREADS; i++)
threads[i].nodes = 0ULL;
}
void ThreadsManager::resetBetaCounters() {
threads[i].nodes = 0ULL;
}
void ThreadsManager::resetBetaCounters() {
- for (int i = 0; i < THREAD_MAX; i++)
+ for (int i = 0; i < MAX_THREADS; i++)
threads[i].betaCutOffs[WHITE] = threads[i].betaCutOffs[BLACK] = 0ULL;
}
threads[i].betaCutOffs[WHITE] = threads[i].betaCutOffs[BLACK] = 0ULL;
}
void ThreadsManager::get_beta_counters(Color us, int64_t& our, int64_t& their) const {
our = their = 0UL;
void ThreadsManager::get_beta_counters(Color us, int64_t& our, int64_t& their) const {
our = their = 0UL;
- for (int i = 0; i < THREAD_MAX; i++)
+ for (int i = 0; i < MAX_THREADS; i++)
{
our += threads[i].betaCutOffs[us];
their += threads[i].betaCutOffs[opposite_color(us)];
{
our += threads[i].betaCutOffs[us];
their += threads[i].betaCutOffs[opposite_color(us)];
void ThreadsManager::idle_loop(int threadID, SplitPoint* waitSp) {
void ThreadsManager::idle_loop(int threadID, SplitPoint* waitSp) {
- assert(threadID >= 0 && threadID < THREAD_MAX);
+ assert(threadID >= 0 && threadID < MAX_THREADS);
threads[threadID].running = true;
threads[threadID].running = true;
lock_init(&IOLock, NULL);
// Initialize SplitPointStack locks
lock_init(&IOLock, NULL);
// Initialize SplitPointStack locks
- for (int i = 0; i < THREAD_MAX; i++)
+ for (int i = 0; i < MAX_THREADS; i++)
for (int j = 0; j < ACTIVE_SPLIT_POINTS_MAX; j++)
{
SplitPointStack[i][j].parent = NULL;
for (int j = 0; j < ACTIVE_SPLIT_POINTS_MAX; j++)
{
SplitPointStack[i][j].parent = NULL;
pthread_mutex_init(&WaitLock, NULL);
pthread_cond_init(&WaitCond, NULL);
#else
pthread_mutex_init(&WaitLock, NULL);
pthread_cond_init(&WaitCond, NULL);
#else
- for (i = 0; i < THREAD_MAX; i++)
+ for (i = 0; i < MAX_THREADS; i++)
SitIdleEvent[i] = CreateEvent(0, FALSE, FALSE, 0);
#endif
SitIdleEvent[i] = CreateEvent(0, FALSE, FALSE, 0);
#endif
// All threads except the main thread should be initialized to idle state
ActiveThreads = 1;
// All threads except the main thread should be initialized to idle state
ActiveThreads = 1;
- for (i = 1; i < THREAD_MAX; i++)
+ for (i = 1; i < MAX_THREADS; i++)
threads[i].idle = true;
// Launch the helper threads
threads[i].idle = true;
// Launch the helper threads
- for (i = 1; i < THREAD_MAX; i++)
+ for (i = 1; i < MAX_THREADS; i++)
void ThreadsManager::exit_threads() {
void ThreadsManager::exit_threads() {
- ActiveThreads = THREAD_MAX; // HACK
+ ActiveThreads = MAX_THREADS; // HACK
AllThreadsShouldSleep = true; // HACK
wake_sleeping_threads();
AllThreadsShouldExit = true;
AllThreadsShouldSleep = true; // HACK
wake_sleeping_threads();
AllThreadsShouldExit = true;
- for (int i = 1; i < THREAD_MAX; i++)
+ for (int i = 1; i < MAX_THREADS; i++)
{
threads[i].stopRequest = true;
while (threads[i].running);
}
// Now we can safely destroy the locks
{
threads[i].stopRequest = true;
while (threads[i].running);
}
// Now we can safely destroy the locks
- for (int i = 0; i < THREAD_MAX; i++)
+ for (int i = 0; i < MAX_THREADS; i++)
for (int j = 0; j < ACTIVE_SPLIT_POINTS_MAX; j++)
lock_destroy(&(SplitPointStack[i][j].lock));
}
for (int j = 0; j < ACTIVE_SPLIT_POINTS_MAX; j++)
lock_destroy(&(SplitPointStack[i][j].lock));
}
- // idle_thread_exists() tries to find an idle thread which is available as
+ // available_thread_exists() tries to find an idle thread which is available as
// a slave for the thread with threadID "master".
// a slave for the thread with threadID "master".
- bool ThreadsManager::idle_thread_exists(int master) const {
+ bool ThreadsManager::available_thread_exists(int master) const {
assert(master >= 0 && master < ActiveThreads);
assert(ActiveThreads > 1);
assert(master >= 0 && master < ActiveThreads);
assert(ActiveThreads > 1);
// If no other thread is available to help us, or if we have too many
// active split points, don't split.
// If no other thread is available to help us, or if we have too many
// active split points, don't split.
- if ( !idle_thread_exists(master)
+ if ( !available_thread_exists(master)
|| threads[master].activeSplitPoints >= ACTIVE_SPLIT_POINTS_MAX)
{
lock_release(&MPLock);
|| threads[master].activeSplitPoints >= ACTIVE_SPLIT_POINTS_MAX)
{
lock_release(&MPLock);
pthread_cond_broadcast(&WaitCond);
pthread_mutex_unlock(&WaitLock);
#else
pthread_cond_broadcast(&WaitCond);
pthread_mutex_unlock(&WaitLock);
#else
- for (int i = 1; i < THREAD_MAX; i++)
+ for (int i = 1; i < MAX_THREADS; i++)
SetEvent(SitIdleEvent[i]);
#endif
SetEvent(SitIdleEvent[i]);
#endif
//// Constants and variables
////
//// Constants and variables
////
-const int THREAD_MAX = 8;
+const int MAX_THREADS = 8;
const int ACTIVE_SPLIT_POINTS_MAX = 8;
const int ACTIVE_SPLIT_POINTS_MAX = 8;
struct SplitPoint {
SplitPoint *parent;
const Position* pos;
struct SplitPoint {
SplitPoint *parent;
const Position* pos;
- SearchStack sstack[THREAD_MAX][PLY_MAX_PLUS_2];
+ SearchStack sstack[MAX_THREADS][PLY_MAX_PLUS_2];
SearchStack *parentSstack;
int ply;
Depth depth;
volatile Value alpha, beta, bestValue;
Value futilityValue;
bool pvNode;
SearchStack *parentSstack;
int ply;
Depth depth;
volatile Value alpha, beta, bestValue;
Value futilityValue;
bool pvNode;
- int master, slaves[THREAD_MAX];
+ int master, slaves[MAX_THREADS];
Lock lock;
MovePicker *mp;
volatile int moves;
Lock lock;
MovePicker *mp;
volatile int moves;
o["Randomness"] = Option(0, 0, 10);
o["Minimum Split Depth"] = Option(4, 4, 7);
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
o["Randomness"] = Option(0, 0, 10);
o["Minimum Split Depth"] = Option(4, 4, 7);
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
- o["Threads"] = Option(1, 1, THREAD_MAX);
+ o["Threads"] = Option(1, 1, MAX_THREADS);
o["Hash"] = Option(32, 4, 8192);
o["Clear Hash"] = Option(false, BUTTON);
o["New Game"] = Option(false, BUTTON);
o["Hash"] = Option(32, 4, 8192);
o["Clear Hash"] = Option(false, BUTTON);
o["New Game"] = Option(false, BUTTON);