mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Rename THREAD_MAX in MAX_THREADS
Also rename idle_thread_exists() in available_thread_exists() No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
7c61b8ad2a
commit
189a005a0b
5 changed files with 33 additions and 33 deletions
|
@ -84,9 +84,9 @@ void benchmark(const string& commandLine) {
|
||||||
}
|
}
|
||||||
csStr >> threads;
|
csStr >> threads;
|
||||||
csVal >> val;
|
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();
|
Application::exit_with_failure();
|
||||||
}
|
}
|
||||||
set_option_value("Hash", ttSize);
|
set_option_value("Hash", ttSize);
|
||||||
|
|
|
@ -253,8 +253,8 @@ namespace {
|
||||||
|
|
||||||
// Pawn and material hash tables, indexed by the current thread id.
|
// Pawn and material hash tables, indexed by the current thread id.
|
||||||
// Note that they will be initialized at 0 being global variables.
|
// Note that they will be initialized at 0 being global variables.
|
||||||
MaterialInfoTable* MaterialTable[THREAD_MAX];
|
MaterialInfoTable* MaterialTable[MAX_THREADS];
|
||||||
PawnInfoTable* PawnTable[THREAD_MAX];
|
PawnInfoTable* PawnTable[MAX_THREADS];
|
||||||
|
|
||||||
// Sizes of pawn and material hash tables
|
// Sizes of pawn and material hash tables
|
||||||
const int PawnTableSize = 16384;
|
const int PawnTableSize = 16384;
|
||||||
|
@ -305,7 +305,7 @@ template<bool HasPopCnt>
|
||||||
Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||||
|
|
||||||
assert(pos.is_ok());
|
assert(pos.is_ok());
|
||||||
assert(threadID >= 0 && threadID < THREAD_MAX);
|
assert(threadID >= 0 && threadID < MAX_THREADS);
|
||||||
assert(!pos.is_check());
|
assert(!pos.is_check());
|
||||||
|
|
||||||
memset(&ei, 0, sizeof(EvalInfo));
|
memset(&ei, 0, sizeof(EvalInfo));
|
||||||
|
@ -440,9 +440,9 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
|
||||||
|
|
||||||
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++)
|
||||||
{
|
{
|
||||||
if (i >= threads)
|
if (i >= threads)
|
||||||
{
|
{
|
||||||
|
@ -464,7 +464,7 @@ void init_eval(int threads) {
|
||||||
|
|
||||||
void quit_eval() {
|
void quit_eval() {
|
||||||
|
|
||||||
for (int i = 0; i < THREAD_MAX; i++)
|
for (int i = 0; i < MAX_THREADS; i++)
|
||||||
{
|
{
|
||||||
delete PawnTable[i];
|
delete PawnTable[i];
|
||||||
delete MaterialTable[i];
|
delete MaterialTable[i];
|
||||||
|
|
|
@ -79,7 +79,7 @@ namespace {
|
||||||
void resetBetaCounters();
|
void resetBetaCounters();
|
||||||
int64_t nodes_searched() const;
|
int64_t nodes_searched() const;
|
||||||
void get_beta_counters(Color us, int64_t& our, int64_t& their) 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_is_available(int slave, int master) const;
|
||||||
bool thread_should_stop(int threadID) const;
|
bool thread_should_stop(int threadID) const;
|
||||||
void wake_sleeping_threads();
|
void wake_sleeping_threads();
|
||||||
|
@ -93,8 +93,8 @@ namespace {
|
||||||
|
|
||||||
int ActiveThreads;
|
int ActiveThreads;
|
||||||
bool AllThreadsShouldExit, AllThreadsShouldSleep;
|
bool AllThreadsShouldExit, AllThreadsShouldSleep;
|
||||||
Thread threads[THREAD_MAX];
|
Thread threads[MAX_THREADS];
|
||||||
SplitPoint SplitPointStack[THREAD_MAX][ACTIVE_SPLIT_POINTS_MAX];
|
SplitPoint SplitPointStack[MAX_THREADS][ACTIVE_SPLIT_POINTS_MAX];
|
||||||
|
|
||||||
Lock MPLock, IOLock;
|
Lock MPLock, IOLock;
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ namespace {
|
||||||
pthread_cond_t WaitCond;
|
pthread_cond_t WaitCond;
|
||||||
pthread_mutex_t WaitLock;
|
pthread_mutex_t WaitLock;
|
||||||
#else
|
#else
|
||||||
HANDLE SitIdleEvent[THREAD_MAX];
|
HANDLE SitIdleEvent[MAX_THREADS];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1208,7 +1208,7 @@ namespace {
|
||||||
&& bestValue < beta
|
&& bestValue < beta
|
||||||
&& depth >= MinimumSplitDepth
|
&& depth >= MinimumSplitDepth
|
||||||
&& Iteration <= 99
|
&& Iteration <= 99
|
||||||
&& TM.idle_thread_exists(threadID)
|
&& TM.available_thread_exists(threadID)
|
||||||
&& !AbortSearch
|
&& !AbortSearch
|
||||||
&& !TM.thread_should_stop(threadID)
|
&& !TM.thread_should_stop(threadID)
|
||||||
&& TM.split(pos, ss, ply, &alpha, &beta, &bestValue, VALUE_NONE,
|
&& TM.split(pos, ss, ply, &alpha, &beta, &bestValue, VALUE_NONE,
|
||||||
|
@ -1522,7 +1522,7 @@ namespace {
|
||||||
&& bestValue < beta
|
&& bestValue < beta
|
||||||
&& depth >= MinimumSplitDepth
|
&& depth >= MinimumSplitDepth
|
||||||
&& Iteration <= 99
|
&& Iteration <= 99
|
||||||
&& TM.idle_thread_exists(threadID)
|
&& TM.available_thread_exists(threadID)
|
||||||
&& !AbortSearch
|
&& !AbortSearch
|
||||||
&& !TM.thread_should_stop(threadID)
|
&& !TM.thread_should_stop(threadID)
|
||||||
&& TM.split(pos, ss, ply, &beta, &beta, &bestValue, futilityValue, //FIXME: SMP & futilityValue
|
&& TM.split(pos, ss, ply, &beta, &beta, &bestValue, futilityValue, //FIXME: SMP & futilityValue
|
||||||
|
@ -2585,13 +2585,13 @@ namespace {
|
||||||
|
|
||||||
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;
|
threads[i].nodes = 0ULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadsManager::resetBetaCounters() {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2607,7 +2607,7 @@ namespace {
|
||||||
void ThreadsManager::get_beta_counters(Color us, int64_t& our, int64_t& their) const {
|
void ThreadsManager::get_beta_counters(Color us, int64_t& our, int64_t& their) const {
|
||||||
|
|
||||||
our = their = 0UL;
|
our = their = 0UL;
|
||||||
for (int i = 0; i < THREAD_MAX; i++)
|
for (int i = 0; i < MAX_THREADS; i++)
|
||||||
{
|
{
|
||||||
our += threads[i].betaCutOffs[us];
|
our += threads[i].betaCutOffs[us];
|
||||||
their += threads[i].betaCutOffs[opposite_color(us)];
|
their += threads[i].betaCutOffs[opposite_color(us)];
|
||||||
|
@ -2621,7 +2621,7 @@ namespace {
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
@ -2693,7 +2693,7 @@ namespace {
|
||||||
lock_init(&IOLock, NULL);
|
lock_init(&IOLock, NULL);
|
||||||
|
|
||||||
// Initialize SplitPointStack locks
|
// 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++)
|
for (int j = 0; j < ACTIVE_SPLIT_POINTS_MAX; j++)
|
||||||
{
|
{
|
||||||
SplitPointStack[i][j].parent = NULL;
|
SplitPointStack[i][j].parent = NULL;
|
||||||
|
@ -2704,7 +2704,7 @@ namespace {
|
||||||
pthread_mutex_init(&WaitLock, NULL);
|
pthread_mutex_init(&WaitLock, NULL);
|
||||||
pthread_cond_init(&WaitCond, NULL);
|
pthread_cond_init(&WaitCond, NULL);
|
||||||
#else
|
#else
|
||||||
for (i = 0; i < THREAD_MAX; i++)
|
for (i = 0; i < MAX_THREADS; i++)
|
||||||
SitIdleEvent[i] = CreateEvent(0, FALSE, FALSE, 0);
|
SitIdleEvent[i] = CreateEvent(0, FALSE, FALSE, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2716,11 +2716,11 @@ namespace {
|
||||||
|
|
||||||
// All threads except the main thread should be initialized to idle state
|
// All threads except the main thread should be initialized to idle state
|
||||||
ActiveThreads = 1;
|
ActiveThreads = 1;
|
||||||
for (i = 1; i < THREAD_MAX; i++)
|
for (i = 1; i < MAX_THREADS; i++)
|
||||||
threads[i].idle = true;
|
threads[i].idle = true;
|
||||||
|
|
||||||
// Launch the helper threads
|
// Launch the helper threads
|
||||||
for (i = 1; i < THREAD_MAX; i++)
|
for (i = 1; i < MAX_THREADS; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER)
|
||||||
|
@ -2747,18 +2747,18 @@ namespace {
|
||||||
|
|
||||||
void ThreadsManager::exit_threads() {
|
void ThreadsManager::exit_threads() {
|
||||||
|
|
||||||
ActiveThreads = THREAD_MAX; // HACK
|
ActiveThreads = MAX_THREADS; // HACK
|
||||||
AllThreadsShouldSleep = true; // HACK
|
AllThreadsShouldSleep = true; // HACK
|
||||||
wake_sleeping_threads();
|
wake_sleeping_threads();
|
||||||
AllThreadsShouldExit = true;
|
AllThreadsShouldExit = true;
|
||||||
for (int i = 1; i < THREAD_MAX; i++)
|
for (int i = 1; i < MAX_THREADS; i++)
|
||||||
{
|
{
|
||||||
threads[i].stopRequest = true;
|
threads[i].stopRequest = true;
|
||||||
while (threads[i].running);
|
while (threads[i].running);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we can safely destroy the locks
|
// 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++)
|
for (int j = 0; j < ACTIVE_SPLIT_POINTS_MAX; j++)
|
||||||
lock_destroy(&(SplitPointStack[i][j].lock));
|
lock_destroy(&(SplitPointStack[i][j].lock));
|
||||||
}
|
}
|
||||||
|
@ -2827,10 +2827,10 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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(master >= 0 && master < ActiveThreads);
|
||||||
assert(ActiveThreads > 1);
|
assert(ActiveThreads > 1);
|
||||||
|
@ -2875,7 +2875,7 @@ namespace {
|
||||||
|
|
||||||
// If no other thread is available to help us, or if we have too many
|
// If no other thread is available to help us, or if we have too many
|
||||||
// active split points, don't split.
|
// active split points, don't split.
|
||||||
if ( !idle_thread_exists(master)
|
if ( !available_thread_exists(master)
|
||||||
|| threads[master].activeSplitPoints >= ACTIVE_SPLIT_POINTS_MAX)
|
|| threads[master].activeSplitPoints >= ACTIVE_SPLIT_POINTS_MAX)
|
||||||
{
|
{
|
||||||
lock_release(&MPLock);
|
lock_release(&MPLock);
|
||||||
|
@ -2993,7 +2993,7 @@ namespace {
|
||||||
pthread_cond_broadcast(&WaitCond);
|
pthread_cond_broadcast(&WaitCond);
|
||||||
pthread_mutex_unlock(&WaitLock);
|
pthread_mutex_unlock(&WaitLock);
|
||||||
#else
|
#else
|
||||||
for (int i = 1; i < THREAD_MAX; i++)
|
for (int i = 1; i < MAX_THREADS; i++)
|
||||||
SetEvent(SitIdleEvent[i]);
|
SetEvent(SitIdleEvent[i]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
//// 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;
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,14 +49,14 @@ const int ACTIVE_SPLIT_POINTS_MAX = 8;
|
||||||
struct SplitPoint {
|
struct SplitPoint {
|
||||||
SplitPoint *parent;
|
SplitPoint *parent;
|
||||||
const Position* pos;
|
const Position* pos;
|
||||||
SearchStack sstack[THREAD_MAX][PLY_MAX_PLUS_2];
|
SearchStack sstack[MAX_THREADS][PLY_MAX_PLUS_2];
|
||||||
SearchStack *parentSstack;
|
SearchStack *parentSstack;
|
||||||
int ply;
|
int ply;
|
||||||
Depth depth;
|
Depth depth;
|
||||||
volatile Value alpha, beta, bestValue;
|
volatile Value alpha, beta, bestValue;
|
||||||
Value futilityValue;
|
Value futilityValue;
|
||||||
bool pvNode;
|
bool pvNode;
|
||||||
int master, slaves[THREAD_MAX];
|
int master, slaves[MAX_THREADS];
|
||||||
Lock lock;
|
Lock lock;
|
||||||
MovePicker *mp;
|
MovePicker *mp;
|
||||||
volatile int moves;
|
volatile int moves;
|
||||||
|
|
|
@ -120,7 +120,7 @@ namespace {
|
||||||
o["Randomness"] = Option(0, 0, 10);
|
o["Randomness"] = Option(0, 0, 10);
|
||||||
o["Minimum Split Depth"] = Option(4, 4, 7);
|
o["Minimum Split Depth"] = Option(4, 4, 7);
|
||||||
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
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["Hash"] = Option(32, 4, 8192);
|
||||||
o["Clear Hash"] = Option(false, BUTTON);
|
o["Clear Hash"] = Option(false, BUTTON);
|
||||||
o["New Game"] = Option(false, BUTTON);
|
o["New Game"] = Option(false, BUTTON);
|
||||||
|
|
Loading…
Add table
Reference in a new issue