From: Marco Costalba Date: Fri, 25 Jan 2013 20:01:24 +0000 (+0100) Subject: Merge branch 'simplify_eval' of https://github.com/glinscott/Stockfish X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=496c7497cb81de4383f7df42b1836af53e432ce3;hp=e83b9075ffc2efb72a3008e9261e575c66eb3d06 Merge branch 'simplify_eval' of https://github.com/glinscott/Stockfish Test results are looking good after 12500 games. ELO: 6.55 +- 99%: 8.02 95%: 6.09 LOS: 99.99% Wins: 1968 Losses: 1732 Draws: 8813 Also, here are the noise.py results, which seem to have stabilized: Games: 12526 , result: [1969, 1734, 8823] Estimated ELO: 6.94963842777 Noise as function of number of games: ['81.89', '565.26', '110.87', '104.39', '38.22', '49.98', '18.56', '16.76', '11.02', '8.90', '17.36', '9.84', '10.81', '5.13', '6.22', '3.32', '5.83', '7.21', '15.27', '1.63', '4.04', '9.51', '0.54', '0.75', '1.06', '2.93', '4.59', '6.85', '13.62', '9.87', '14.74', '20.46', '22.18', '24.33', '31.02', '34.99', '35.22', '33.22', '32.46', '37.02', '29.10', '36.34', '42.11', '39.33', '26.16', '28.25', '35.42', '31.04', '29.26', '23.91', '22.52', '23.49', '20.00', '24.39', '17.22', '16.50', '10.69', '9.15', '9.57', '4.77', '6.67', '3.87', '2.57', '2.84', '2.60', '3.32', '2.08', '2.93', '4.47', '4.41', '4.83', '4.86', '6.40', '5.98', '6.10', '6.83', '5.83', '6.22', '5.71', '8.52', '9.25', '5.98', '7.52', '7.76', '8.76', '8.55', '8.64', '7.19', '5.83', '4.59', '4.77', '4.26', '4.98', '5.29', '5.41', '4.92', '5.59'] bench: 5229106 --- diff --git a/src/search.cpp b/src/search.cpp index a66fe40e..35d1eb5b 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1008,7 +1008,8 @@ split_point_start: // At split points actual search starts from here // Step 19. Check for splitting the search if ( !SpNode && depth >= Threads.minimumSplitDepth - && Threads.slave_available(thisThread)) + && Threads.slave_available(thisThread) + && thisThread->splitPointsSize < MAX_SPLITPOINTS_PER_THREAD) { assert(bestValue < beta); diff --git a/src/thread.cpp b/src/thread.cpp index 229c6beb..9aa0b55e 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -176,10 +176,10 @@ bool Thread::is_available_to(Thread* master) const { } -// init() is called at startup. Initializes lock and condition variable and -// launches requested threads sending them immediately to sleep. We cannot use +// init() is called at startup to create and launch requested threads, that will +// go immediately to sleep due to 'sleepWhileIdle' set to true. We cannot use // a c'tor becuase Threads is a static object and we need a fully initialized -// engine at this point due to allocation of endgames in Thread c'tor. +// engine at this point due to allocation of Endgames in Thread c'tor. void ThreadPool::init() { @@ -190,11 +190,11 @@ void ThreadPool::init() { } -// exit() cleanly terminates the threads before the program exits. +// exit() cleanly terminates the threads before the program exits void ThreadPool::exit() { - delete timer; // As first becuase check_time() accesses threads data + delete timer; // As first because check_time() accesses threads data for (size_t i = 0; i < threads.size(); i++) delete threads[i]; @@ -240,12 +240,12 @@ bool ThreadPool::slave_available(Thread* master) const { // split() does the actual work of distributing the work at a node between // several available threads. If it does not succeed in splitting the node -// (because no idle threads are available, or because we have no unused split -// point objects), the function immediately returns. If splitting is possible, a -// SplitPoint object is initialized with all the data that must be copied to the -// helper threads and then helper threads are told that they have been assigned -// work. This will cause them to instantly leave their idle loops and call -// search(). When all threads have returned from search() then split() returns. +// (because no idle threads are available), the function immediately returns. +// If splitting is possible, a SplitPoint object is initialized with all the +// data that must be copied to the helper threads and then helper threads are +// told that they have been assigned work. This will cause them to instantly +// leave their idle loops and call search(). When all threads have returned from +// search() then split() returns. template Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta, @@ -253,16 +253,14 @@ Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta, int moveCount, MovePicker& mp, int nodeType) { assert(pos.pos_is_ok()); + assert(bestValue <= alpha && alpha < beta && beta <= VALUE_INFINITE); assert(bestValue > -VALUE_INFINITE); - assert(bestValue <= alpha); - assert(alpha < beta); - assert(beta <= VALUE_INFINITE); - assert(depth > DEPTH_ZERO); + assert(depth >= Threads.minimumSplitDepth); Thread* master = pos.this_thread(); - if (master->splitPointsSize >= MAX_SPLITPOINTS_PER_THREAD) - return bestValue; + assert(master->searching); + assert(master->splitPointsSize < MAX_SPLITPOINTS_PER_THREAD); // Pick the next available split point from the split point stack SplitPoint& sp = master->splitPoints[master->splitPointsSize]; @@ -284,31 +282,26 @@ Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta, sp.cutoff = false; sp.ss = ss; - master->activeSplitPoint = &sp; - int slavesCnt = 0; - - assert(master->searching); - // Try to allocate available threads and ask them to start searching setting // 'searching' flag. This must be done under lock protection to avoid concurrent // allocation of the same slave by another master. mutex.lock(); sp.mutex.lock(); + master->splitPointsSize++; + master->activeSplitPoint = &sp; + + size_t slavesCnt = 1; // Master is always included + for (size_t i = 0; i < threads.size() && !Fake; ++i) - if (threads[i]->is_available_to(master)) + if (threads[i]->is_available_to(master) && ++slavesCnt <= maxThreadsPerSplitPoint) { sp.slavesMask |= 1ULL << i; threads[i]->activeSplitPoint = &sp; threads[i]->searching = true; // Slave leaves idle_loop() threads[i]->notify_one(); // Could be sleeping - - if (++slavesCnt + 1 >= maxThreadsPerSplitPoint) // Include master - break; } - master->splitPointsSize++; - sp.mutex.unlock(); mutex.unlock(); @@ -316,7 +309,7 @@ Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta, // it will instantly launch a search, because its 'searching' flag is set. // The thread will return from the idle loop when all slaves have finished // their work at this split point. - if (slavesCnt || Fake) + if (slavesCnt > 1 || Fake) { master->Thread::idle_loop(); // Force a call to base class idle_loop() diff --git a/src/thread.h b/src/thread.h index 5f8ad28e..7df9f241 100644 --- a/src/thread.h +++ b/src/thread.h @@ -167,7 +167,7 @@ public: private: std::vector threads; TimerThread* timer; - int maxThreadsPerSplitPoint; + size_t maxThreadsPerSplitPoint; }; extern ThreadPool Threads;