X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fsearch.cpp;h=11299121ba2435a4d1631df85616e22e779f7521;hb=79b57dd4ca54bcb80a50c8fadadc7e64269fb756;hp=38e2ac14084a26442fdafa19581f5843ec1dc897;hpb=512a4e4ff044aeddebc0df42b7fbabb365f9a22d;p=stockfish diff --git a/src/search.cpp b/src/search.cpp index 38e2ac14..11299121 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -84,7 +84,7 @@ namespace { void wake_sleeping_threads(); void put_threads_to_sleep(); void idle_loop(int threadID, SplitPoint* waitSp); - bool split(const Position& pos, SearchStack* ss, int ply, Value* alpha, Value* beta, Value* bestValue, + bool split(const Position& pos, SearchStack* ss, int ply, Value* alpha, const Value beta, Value* bestValue, const Value futilityValue, Depth depth, int* moves, MovePicker* mp, int master, bool pvNode); private: @@ -1210,7 +1210,7 @@ namespace { && TM.available_thread_exists(threadID) && !AbortSearch && !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, depth, &moveCount, &mp, threadID, true)) break; } @@ -1524,7 +1524,7 @@ namespace { && TM.available_thread_exists(threadID) && !AbortSearch && !TM.thread_should_stop(threadID) - && TM.split(pos, ss, ply, &beta, &beta, &bestValue, futilityValue, //FIXME: SMP & futilityValue + && TM.split(pos, ss, ply, NULL, beta, &bestValue, futilityValue, //FIXME: SMP & futilityValue depth, &moveCount, &mp, threadID, false)) break; } @@ -1851,25 +1851,10 @@ namespace { assert(value > -VALUE_INFINITE && value < VALUE_INFINITE); - if (TM.thread_should_stop(threadID)) - { - lock_grab(&(sp->lock)); - break; - } - // New best move? if (value > sp->bestValue) // Less then 2% of cases { - // Recursive locking, lock current split point and its ancestors to - // guarantee thread_should_stop() and sp_update_pv() are race free. - SplitPoint* spChain[MAX_THREADS * ACTIVE_SPLIT_POINTS_MAX]; - int cnt = 0; - for (spChain[cnt] = sp; spChain[cnt]; ) - { - lock_grab(&(spChain[cnt++]->lock)); - spChain[cnt] = spChain[cnt - 1]->parent; - } - + lock_grab(&(sp->lock)); if (value > sp->bestValue && !TM.thread_should_stop(threadID)) { sp->bestValue = value; @@ -1879,10 +1864,7 @@ namespace { sp_update_pv(sp->parentSstack, ss, sp->ply); } } - - // Release locks in reverse order - while (cnt > 0) - lock_release(&(spChain[--cnt]->lock)); + lock_release(&(sp->lock)); } } @@ -1978,25 +1960,10 @@ namespace { assert(value > -VALUE_INFINITE && value < VALUE_INFINITE); - if (TM.thread_should_stop(threadID)) - { - lock_grab(&(sp->lock)); - break; - } - // New best move? if (value > sp->bestValue) // Less then 2% of cases { - // Recursive locking, lock current split point and its ancestors to - // guarantee thread_should_stop() and sp_update_pv() are race free. - SplitPoint* spChain[MAX_THREADS * ACTIVE_SPLIT_POINTS_MAX]; - int cnt = 0; - for (spChain[cnt] = sp; spChain[cnt]; ) - { - lock_grab(&(spChain[cnt++]->lock)); - spChain[cnt] = spChain[cnt - 1]->parent; - } - + lock_grab(&(sp->lock)); if (value > sp->bestValue && !TM.thread_should_stop(threadID)) { sp->bestValue = value; @@ -2013,10 +1980,7 @@ namespace { ss[sp->ply].mateKiller = move; } } - - // Release locks in reverse order - while (cnt > 0) - lock_release(&(spChain[--cnt]->lock)); + lock_release(&(sp->lock)); } } @@ -2650,6 +2614,8 @@ namespace { // If this thread has been assigned work, launch a search if (threads[threadID].state == THREAD_WORKISWAITING) { + assert(!AllThreadsShouldExit); + threads[threadID].state = THREAD_SEARCHING; if (threads[threadID].splitPoint->pvNode) @@ -2659,13 +2625,7 @@ namespace { assert(threads[threadID].state == THREAD_SEARCHING); - // If this is a slave thread reset to available, instead - // if it is a master thread and all slaves have finished - // then leave as is to avoid booking by another master, - // we will leave idle loop shortly anyhow. - if ( !AllThreadsShouldExit - && (!waitSp || waitSp->cpus > 0)) - threads[threadID].state = THREAD_AVAILABLE; + threads[threadID].state = THREAD_AVAILABLE; } // If this thread is the master of a split point and all threads have @@ -2700,7 +2660,7 @@ namespace { lock_init(&IOLock, NULL); // Initialize SplitPointStack locks - for (int i = 0; i < MAX_THREADS; i++) + for (i = 0; i < MAX_THREADS; i++) for (int j = 0; j < ACTIVE_SPLIT_POINTS_MAX; j++) { SplitPointStack[i][j].parent = NULL; @@ -2855,7 +2815,7 @@ namespace { // splitPoint->cpus becomes 0), split() returns true. bool ThreadsManager::split(const Position& p, SearchStack* sstck, int ply, - Value* alpha, Value* beta, Value* bestValue, const Value futilityValue, + Value* alpha, const Value beta, Value* bestValue, const Value futilityValue, Depth depth, int* moves, MovePicker* mp, int master, bool pvNode) { assert(p.is_ok()); @@ -2882,16 +2842,15 @@ namespace { } // Pick the next available split point object from the split point stack - splitPoint = SplitPointStack[master] + threads[master].activeSplitPoints; - threads[master].activeSplitPoints++; + splitPoint = &SplitPointStack[master][threads[master].activeSplitPoints]; // Initialize the split point object splitPoint->parent = threads[master].splitPoint; splitPoint->stopRequest = false; splitPoint->ply = ply; splitPoint->depth = depth; - splitPoint->alpha = pvNode ? *alpha : (*beta - 1); - splitPoint->beta = *beta; + splitPoint->alpha = pvNode ? *alpha : beta - 1; + splitPoint->beta = beta; splitPoint->pvNode = pvNode; splitPoint->bestValue = *bestValue; splitPoint->futilityValue = futilityValue; @@ -2905,6 +2864,7 @@ namespace { splitPoint->slaves[i] = 0; threads[master].splitPoint = splitPoint; + threads[master].activeSplitPoints++; // If we are here it means we are not available assert(threads[master].state != THREAD_AVAILABLE); @@ -2951,7 +2911,6 @@ namespace { if (pvNode) *alpha = splitPoint->alpha; - *beta = splitPoint->beta; *bestValue = splitPoint->bestValue; threads[master].activeSplitPoints--; threads[master].splitPoint = splitPoint->parent;