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

Better integration of faked split

We don't need to comment/uncomment code, just
set FakeSplit bool to true to enable faked split.

Also reintroduced some asserts and cleaned up a bit.

Tested that with FakeSplit = true we have reproducible
finger printing even in SMP.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2010-05-09 23:31:43 +01:00
parent 7abe5f12ef
commit c053f0b838

View file

@ -54,6 +54,10 @@ namespace {
/// Types /// Types
enum NodeType { NonPV, PV }; enum NodeType { NonPV, PV };
// Set to true to force running with one thread.
// Used for debugging SMP code.
const bool FakeSplit = false;
// ThreadsManager class is used to handle all the threads related stuff in search, // ThreadsManager class is used to handle all the threads related stuff in search,
// init, starting, parking and, the most important, launching a slave thread at a // init, starting, parking and, the most important, launching a slave thread at a
// split point are what this class does. All the access to shared thread data is // split point are what this class does. All the access to shared thread data is
@ -1362,21 +1366,9 @@ namespace {
&& TM.available_thread_exists(threadID) && TM.available_thread_exists(threadID)
&& !AbortSearch && !AbortSearch
&& !TM.thread_should_stop(threadID) && !TM.thread_should_stop(threadID)
&& TM.split<false>(pos, ss, ply, &alpha, beta, &bestValue, && TM.split<FakeSplit>(pos, ss, ply, &alpha, beta, &bestValue, depth,
depth, mateThreat, &moveCount, &mp, threadID, PvNode)) mateThreat, &moveCount, &mp, threadID, PvNode))
break; break;
// Uncomment to debug sp_search() in single thread mode
/*
if ( bestValue < beta
&& depth >= 4
&& Iteration <= 99
&& !AbortSearch
&& !TM.thread_should_stop(threadID)
&& TM.split<true>(pos, ss, ply, &alpha, beta, &bestValue,
depth, mateThreat, &moveCount, &mp, threadID, PvNode))
break;
*/
} }
// Step 19. Check for mate and stalemate // Step 19. Check for mate and stalemate
@ -1618,6 +1610,7 @@ namespace {
void sp_search(SplitPoint* sp, int threadID) { void sp_search(SplitPoint* sp, int threadID) {
assert(threadID >= 0 && threadID < TM.active_threads()); assert(threadID >= 0 && threadID < TM.active_threads());
assert(TM.active_threads() > 1);
StateInfo st; StateInfo st;
Move move; Move move;
@ -1779,8 +1772,6 @@ namespace {
} }
ss[ply].init(ply); ss[ply].init(ply);
ss[ply + 2].initKillers(); ss[ply + 2].initKillers();
} }
// update_pv() is called whenever a search returns a value > alpha. // update_pv() is called whenever a search returns a value > alpha.
@ -2610,10 +2601,9 @@ namespace {
// splitPoint->cpus becomes 0), split() returns true. // splitPoint->cpus becomes 0), split() returns true.
template <bool Fake> template <bool Fake>
bool ThreadsManager::split(const Position& p, SearchStack* sstck, int ply, bool ThreadsManager::split(const Position& p, SearchStack* sstck, int ply, Value* alpha,
Value* alpha, const Value beta, Value* bestValue, const Value beta, Value* bestValue, Depth depth, bool mateThreat,
Depth depth, bool mateThreat, int* moves, MovePicker* mp, int master, bool pvNode) { int* moves, MovePicker* mp, int master, bool pvNode) {
assert(p.is_ok()); assert(p.is_ok());
assert(sstck != NULL); assert(sstck != NULL);
assert(ply >= 0 && ply < PLY_MAX); assert(ply >= 0 && ply < PLY_MAX);
@ -2623,7 +2613,7 @@ namespace {
assert(beta <= VALUE_INFINITE); assert(beta <= VALUE_INFINITE);
assert(depth > Depth(0)); assert(depth > Depth(0));
assert(master >= 0 && master < ActiveThreads); assert(master >= 0 && master < ActiveThreads);
assert(Fake || ActiveThreads > 1); assert(ActiveThreads > 1);
SplitPoint* splitPoint; SplitPoint* splitPoint;
@ -2631,7 +2621,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 ( (!Fake && !available_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);
@ -2667,8 +2657,8 @@ namespace {
assert(threads[master].state != THREAD_AVAILABLE); assert(threads[master].state != THREAD_AVAILABLE);
// Allocate available threads setting state to THREAD_BOOKED // Allocate available threads setting state to THREAD_BOOKED
for (int i = 0; i < ActiveThreads && splitPoint->cpus < MaxThreadsPerSplitPoint; i++) for (int i = 0; !Fake && i < ActiveThreads && splitPoint->cpus < MaxThreadsPerSplitPoint; i++)
if (!Fake && thread_is_available(i, master)) if (thread_is_available(i, master))
{ {
threads[i].state = THREAD_BOOKED; threads[i].state = THREAD_BOOKED;
threads[i].splitPoint = splitPoint; threads[i].splitPoint = splitPoint;