1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00

Space inflate bottom part of search.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2010-01-03 21:30:46 +01:00
parent 9e6d38d224
commit 0e15b0f1d3

View file

@ -2562,6 +2562,7 @@ namespace {
// since the beginning of the current search.
int current_search_time() {
return get_system_time() - SearchStartTime;
}
@ -2569,8 +2570,9 @@ namespace {
// nps() computes the current nodes/second count.
int nps() {
int t = current_search_time();
return (t > 0)? int((nodes_searched() * 1000) / t) : 0;
return (t > 0 ? int((nodes_searched() * 1000) / t) : 0);
}
@ -2588,6 +2590,7 @@ namespace {
{
// We are line oriented, don't read single chars
std::string command;
if (!std::getline(std::cin, command))
command = "quit";
@ -2606,6 +2609,7 @@ namespace {
else if (command == "ponderhit")
ponderhit();
}
// Print search information
if (t < 1000)
lastInfoTime = 0;
@ -2619,6 +2623,7 @@ namespace {
{
lastInfoTime = t;
lock_grab(&IOLock);
if (dbg_show_mean)
dbg_print_mean();
@ -2627,20 +2632,32 @@ namespace {
cout << "info nodes " << nodes_searched() << " nps " << nps()
<< " time " << t << " hashfull " << TT.full() << endl;
lock_release(&IOLock);
if (ShowCurrentLine)
Threads[0].printCurrentLine = true;
}
// Should we stop the search?
if (PonderSearch)
return;
bool overTime = t > AbsoluteMaxSearchTime
|| (RootMoveNumber == 1 && t > MaxSearchTime + ExtraSearchTime && !FailLow) //FIXME: We are not checking any problem flags, BUG?
|| ( !FailHigh && !FailLow && !fail_high_ply_1() && !Problem
&& t > 6*(MaxSearchTime + ExtraSearchTime));
bool stillAtFirstMove = RootMoveNumber == 1
&& !FailLow
&& t > MaxSearchTime + ExtraSearchTime;
if ( (Iteration >= 3 && (!InfiniteSearch && overTime))
bool noProblemFound = !FailHigh
&& !FailLow
&& !fail_high_ply_1()
&& !Problem
&& t > 6 * (MaxSearchTime + ExtraSearchTime);
bool noMoreTime = t > AbsoluteMaxSearchTime
|| stillAtFirstMove //FIXME: We are not checking any problem flags, BUG?
|| noProblemFound;
if ( (Iteration >= 3 && !InfiniteSearch && noMoreTime)
|| (ExactMaxTime && t >= ExactMaxTime)
|| (Iteration >= 3 && MaxNodes && nodes_searched() >= MaxNodes))
AbortSearch = true;
@ -2655,13 +2672,22 @@ namespace {
int t = current_search_time();
PonderSearch = false;
if (Iteration >= 3 &&
(!InfiniteSearch && (StopOnPonderhit ||
t > AbsoluteMaxSearchTime ||
(RootMoveNumber == 1 &&
t > MaxSearchTime + ExtraSearchTime && !FailLow) ||
(!FailHigh && !FailLow && !fail_high_ply_1() && !Problem &&
t > 6*(MaxSearchTime + ExtraSearchTime)))))
bool stillAtFirstMove = RootMoveNumber == 1
&& !FailLow
&& t > MaxSearchTime + ExtraSearchTime;
bool noProblemFound = !FailHigh
&& !FailLow
&& !fail_high_ply_1()
&& !Problem
&& t > 6 * (MaxSearchTime + ExtraSearchTime);
bool noMoreTime = t > AbsoluteMaxSearchTime
|| stillAtFirstMove
|| noProblemFound;
if (Iteration >= 3 && !InfiniteSearch && (noMoreTime || StopOnPonderhit))
AbortSearch = true;
}
@ -2734,21 +2760,26 @@ namespace {
// object for which the current thread is the master.
void idle_loop(int threadID, SplitPoint* waitSp) {
assert(threadID >= 0 && threadID < THREAD_MAX);
Threads[threadID].running = true;
while(true) {
while (true)
{
if (AllThreadsShouldExit && threadID != 0)
break;
// If we are not thinking, wait for a condition to be signaled instead
// of wasting CPU time polling for work:
while(threadID != 0 && (Idle || threadID >= ActiveThreads)) {
// of wasting CPU time polling for work.
while (threadID != 0 && (Idle || threadID >= ActiveThreads))
{
#if !defined(_MSC_VER)
pthread_mutex_lock(&WaitLock);
if (Idle || threadID >= ActiveThreads)
pthread_cond_wait(&WaitCond, &WaitLock);
pthread_mutex_unlock(&WaitLock);
#else
WaitForSingleObject(SitIdleEvent[threadID], INFINITE);
@ -2756,12 +2787,14 @@ namespace {
}
// If this thread has been assigned work, launch a search
if(Threads[threadID].workIsWaiting) {
if (Threads[threadID].workIsWaiting)
{
Threads[threadID].workIsWaiting = false;
if (Threads[threadID].splitPoint->pvNode)
sp_search_pv(Threads[threadID].splitPoint, threadID);
else
sp_search(Threads[threadID].splitPoint, threadID);
Threads[threadID].idle = true;
}
@ -2779,8 +2812,10 @@ namespace {
// initializes all split point objects.
void init_split_point_stack() {
for (int i = 0; i < THREAD_MAX; 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;
lock_init(&(SplitPointStack[i][j].lock), NULL);
}
@ -2791,6 +2826,7 @@ namespace {
// destroys all locks in the precomputed split point objects.
void destroy_split_point_stack() {
for (int i = 0; i < THREAD_MAX; i++)
for (int j = 0; j < ACTIVE_SPLIT_POINTS_MAX; j++)
lock_destroy(&(SplitPointStack[i][j].lock));
@ -2799,10 +2835,11 @@ namespace {
// thread_should_stop() checks whether the thread with a given threadID has
// been asked to stop, directly or indirectly. This can happen if a beta
// cutoff has occured in thre thread's currently active split point, or in
// cutoff has occured in the thread's currently active split point, or in
// some ancestor of the current split point.
bool thread_should_stop(int threadID) {
assert(threadID >= 0 && threadID < ActiveThreads);
SplitPoint* sp;
@ -2812,7 +2849,8 @@ namespace {
if (ActiveThreads <= 2)
return false;
for (sp = Threads[threadID].splitPoint; sp != NULL; sp = sp->parent)
if(sp->finished) {
if (sp->finished)
{
Threads[threadID].stop = true;
return true;
}
@ -2829,6 +2867,7 @@ namespace {
// split point stack (the "helpful master concept" in YBWC terminology).
bool thread_is_available(int slave, int master) {
assert(slave >= 0 && slave < ActiveThreads);
assert(master >= 0 && master < ActiveThreads);
assert(ActiveThreads > 1);
@ -2837,8 +2876,8 @@ namespace {
return false;
if (Threads[slave].activeSplitPoints == 0)
// No active split points means that the thread is available as a slave
// for any other thread.
// No active split points means that the thread is available as
// a slave for any other thread.
return true;
if (ActiveThreads == 2)
@ -2856,12 +2895,14 @@ namespace {
// a slave for the thread with threadID "master".
bool idle_thread_exists(int master) {
assert(master >= 0 && master < ActiveThreads);
assert(ActiveThreads > 1);
for (int i = 0; i < ActiveThreads; i++)
if (thread_is_available(i, master))
return true;
return false;
}
@ -2899,8 +2940,9 @@ namespace {
// 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) ||
Threads[master].activeSplitPoints >= ACTIVE_SPLIT_POINTS_MAX) {
if ( !idle_thread_exists(master)
|| Threads[master].activeSplitPoints >= ACTIVE_SPLIT_POINTS_MAX)
{
lock_release(&MPLock);
return false;
}
@ -2909,7 +2951,7 @@ namespace {
splitPoint = SplitPointStack[master] + Threads[master].activeSplitPoints;
Threads[master].activeSplitPoints++;
// Initialize the split point object
// Initialize the split point object and copy current position
splitPoint->parent = Threads[master].splitPoint;
splitPoint->finished = false;
splitPoint->ply = ply;
@ -2928,14 +2970,14 @@ namespace {
for (i = 0; i < ActiveThreads; i++)
splitPoint->slaves[i] = 0;
// Copy the current position and the search stack to the master thread
// Copy the current search stack to the master thread
memcpy(splitPoint->sstack[master], sstck, (ply+1) * sizeof(SearchStack));
Threads[master].splitPoint = splitPoint;
// Make copies of the current position and search stack for each thread
for(i = 0; i < ActiveThreads && splitPoint->cpus < MaxThreadsPerSplitPoint;
i++)
if(thread_is_available(i, master)) {
for (i = 0; i < ActiveThreads && splitPoint->cpus < MaxThreadsPerSplitPoint; i++)
if (thread_is_available(i, master))
{
memcpy(splitPoint->sstack[i], sstck, (ply+1) * sizeof(SearchStack));
Threads[i].splitPoint = splitPoint;
splitPoint->slaves[i] = 1;
@ -2945,7 +2987,8 @@ namespace {
// Tell the threads that they have work to do. This will make them leave
// their idle loop.
for (i = 0; i < ActiveThreads; i++)
if(i == master || splitPoint->slaves[i]) {
if (i == master || splitPoint->slaves[i])
{
Threads[i].workIsWaiting = true;
Threads[i].idle = false;
Threads[i].stop = false;
@ -2958,21 +3001,24 @@ namespace {
// slot is 'true'. We send the split point as a second parameter to the
// idle loop, which means that the main thread will return from the idle
// loop when all threads have finished their work at this split point
// (i.e. when // splitPoint->cpus == 0).
// (i.e. when splitPoint->cpus == 0).
idle_loop(master, splitPoint);
// We have returned from the idle loop, which means that all threads are
// finished. Update alpha, beta and bestvalue, and return.
// finished. Update alpha, beta and bestValue, and return.
lock_grab(&MPLock);
if(pvNode) *alpha = splitPoint->alpha;
if (pvNode)
*alpha = splitPoint->alpha;
*beta = splitPoint->beta;
*bestValue = splitPoint->bestValue;
Threads[master].stop = false;
Threads[master].idle = false;
Threads[master].activeSplitPoints--;
Threads[master].splitPoint = splitPoint->parent;
lock_release(&MPLock);
lock_release(&MPLock);
return true;
}
@ -2981,11 +3027,15 @@ namespace {
// to start a new search from the root.
void wake_sleeping_threads() {
if(ActiveThreads > 1) {
for(int i = 1; i < ActiveThreads; i++) {
if (ActiveThreads > 1)
{
for (int i = 1; i < ActiveThreads; i++)
{
Threads[i].idle = true;
Threads[i].workIsWaiting = false;
}
#if !defined(_MSC_VER)
pthread_mutex_lock(&WaitLock);
pthread_cond_broadcast(&WaitCond);
@ -3000,12 +3050,13 @@ namespace {
// init_thread() is the function which is called when a new thread is
// launched. It simply calls the idle_loop() function with the supplied
// threadID. There are two versions of this function; one for POSIX threads
// and one for Windows threads.
// threadID. There are two versions of this function; one for POSIX
// threads and one for Windows threads.
#if !defined(_MSC_VER)
void* init_thread(void *threadID) {
idle_loop(*(int*)threadID, NULL);
return NULL;
}
@ -3013,6 +3064,7 @@ namespace {
#else
DWORD WINAPI init_thread(LPVOID threadID) {
idle_loop(*(int*)threadID, NULL);
return NULL;
}