mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 11:39:15 +00:00
Use one History table per thread
This reduces contention and reduce history trashing effect especially at high search depths. No functional change for single CPU case. After 999 games at 1+0 on Dual Core Intel we have Mod vs Orig +233 =526 -240 -2 ELO We need to test at longer time controls and possibly with a QUAD where we could foreseen an improvment. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
c1b60269a2
commit
b4a04d8038
2 changed files with 16 additions and 15 deletions
|
@ -207,9 +207,6 @@ namespace {
|
||||||
// Search depth at iteration 1
|
// Search depth at iteration 1
|
||||||
const Depth InitialDepth = OnePly /*+ OnePly/2*/;
|
const Depth InitialDepth = OnePly /*+ OnePly/2*/;
|
||||||
|
|
||||||
// History tables
|
|
||||||
History H;
|
|
||||||
|
|
||||||
// Node counters
|
// Node counters
|
||||||
int NodesSincePoll;
|
int NodesSincePoll;
|
||||||
int NodesBetweenPolls = 30000;
|
int NodesBetweenPolls = 30000;
|
||||||
|
@ -284,10 +281,10 @@ namespace {
|
||||||
bool move_is_killer(Move m, const SearchStack& ss);
|
bool move_is_killer(Move m, const SearchStack& ss);
|
||||||
Depth extension(const Position &pos, Move m, bool pvNode, bool capture, bool check, bool singleReply, bool mateThreat, bool* dangerous);
|
Depth extension(const Position &pos, Move m, bool pvNode, bool capture, bool check, bool singleReply, bool mateThreat, bool* dangerous);
|
||||||
bool ok_to_do_nullmove(const Position &pos);
|
bool ok_to_do_nullmove(const Position &pos);
|
||||||
bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d);
|
bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d, const History& H);
|
||||||
bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply);
|
bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply);
|
||||||
bool ok_to_history(const Position &pos, Move m);
|
bool ok_to_history(const Position &pos, Move m);
|
||||||
void update_history(const Position& pos, Move m, Depth depth, Move movesSearched[], int moveCount);
|
void update_history(const Position& pos, Move m, Depth depth, History& H, Move movesSearched[], int moveCount);
|
||||||
void update_killers(Move m, SearchStack& ss);
|
void update_killers(Move m, SearchStack& ss);
|
||||||
|
|
||||||
bool fail_high_ply_1();
|
bool fail_high_ply_1();
|
||||||
|
@ -645,7 +642,9 @@ namespace {
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
TT.new_search();
|
TT.new_search();
|
||||||
H.clear();
|
for (int i = 0; i < THREAD_MAX; i++)
|
||||||
|
Threads[i].H.clear();
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
ss[i].init(i);
|
ss[i].init(i);
|
||||||
|
@ -1057,7 +1056,7 @@ namespace {
|
||||||
|
|
||||||
// Initialize a MovePicker object for the current position, and prepare
|
// Initialize a MovePicker object for the current position, and prepare
|
||||||
// to search all moves
|
// to search all moves
|
||||||
MovePicker mp = MovePicker(pos, true, ttMove, depth, H, &ss[ply]);
|
MovePicker mp = MovePicker(pos, true, ttMove, depth, Threads[threadID].H, &ss[ply]);
|
||||||
|
|
||||||
Move move, movesSearched[256];
|
Move move, movesSearched[256];
|
||||||
int moveCount = 0;
|
int moveCount = 0;
|
||||||
|
@ -1186,7 +1185,7 @@ namespace {
|
||||||
Move m = ss[ply].pv[ply];
|
Move m = ss[ply].pv[ply];
|
||||||
if (ok_to_history(pos, m)) // Only non capture moves are considered
|
if (ok_to_history(pos, m)) // Only non capture moves are considered
|
||||||
{
|
{
|
||||||
update_history(pos, m, depth, movesSearched, moveCount);
|
update_history(pos, m, depth, Threads[threadID].H, movesSearched, moveCount);
|
||||||
update_killers(m, ss[ply]);
|
update_killers(m, ss[ply]);
|
||||||
}
|
}
|
||||||
TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m);
|
TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m);
|
||||||
|
@ -1318,7 +1317,7 @@ namespace {
|
||||||
|
|
||||||
// Initialize a MovePicker object for the current position, and prepare
|
// Initialize a MovePicker object for the current position, and prepare
|
||||||
// to search all moves:
|
// to search all moves:
|
||||||
MovePicker mp = MovePicker(pos, false, ttMove, depth, H, &ss[ply]);
|
MovePicker mp = MovePicker(pos, false, ttMove, depth, Threads[threadID].H, &ss[ply]);
|
||||||
|
|
||||||
Move move, movesSearched[256];
|
Move move, movesSearched[256];
|
||||||
int moveCount = 0;
|
int moveCount = 0;
|
||||||
|
@ -1356,7 +1355,7 @@ namespace {
|
||||||
{
|
{
|
||||||
// History pruning. See ok_to_prune() definition
|
// History pruning. See ok_to_prune() definition
|
||||||
if ( moveCount >= 2 + int(depth)
|
if ( moveCount >= 2 + int(depth)
|
||||||
&& ok_to_prune(pos, move, ss[ply].threatMove, depth))
|
&& ok_to_prune(pos, move, ss[ply].threatMove, depth, Threads[threadID].H))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Value based pruning
|
// Value based pruning
|
||||||
|
@ -1446,7 +1445,7 @@ namespace {
|
||||||
Move m = ss[ply].pv[ply];
|
Move m = ss[ply].pv[ply];
|
||||||
if (ok_to_history(pos, m)) // Only non capture moves are considered
|
if (ok_to_history(pos, m)) // Only non capture moves are considered
|
||||||
{
|
{
|
||||||
update_history(pos, m, depth, movesSearched, moveCount);
|
update_history(pos, m, depth, Threads[threadID].H, movesSearched, moveCount);
|
||||||
update_killers(m, ss[ply]);
|
update_killers(m, ss[ply]);
|
||||||
}
|
}
|
||||||
TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m);
|
TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m);
|
||||||
|
@ -1539,7 +1538,7 @@ namespace {
|
||||||
// Initialize a MovePicker object for the current position, and prepare
|
// Initialize a MovePicker object for the current position, and prepare
|
||||||
// to search the moves. Because the depth is <= 0 here, only captures,
|
// to search the moves. Because the depth is <= 0 here, only captures,
|
||||||
// queen promotions and checks (only if depth == 0) will be generated.
|
// queen promotions and checks (only if depth == 0) will be generated.
|
||||||
MovePicker mp = MovePicker(pos, pvNode, ttMove, depth, H);
|
MovePicker mp = MovePicker(pos, pvNode, ttMove, depth, Threads[threadID].H);
|
||||||
Move move;
|
Move move;
|
||||||
int moveCount = 0;
|
int moveCount = 0;
|
||||||
Bitboard dcCandidates = mp.discovered_check_candidates();
|
Bitboard dcCandidates = mp.discovered_check_candidates();
|
||||||
|
@ -1682,7 +1681,7 @@ namespace {
|
||||||
&& !moveIsCapture
|
&& !moveIsCapture
|
||||||
&& !move_promotion(move)
|
&& !move_promotion(move)
|
||||||
&& moveCount >= 2 + int(sp->depth)
|
&& moveCount >= 2 + int(sp->depth)
|
||||||
&& ok_to_prune(pos, move, ss[sp->ply].threatMove, sp->depth))
|
&& ok_to_prune(pos, move, ss[sp->ply].threatMove, sp->depth, Threads[threadID].H))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Make and search the move.
|
// Make and search the move.
|
||||||
|
@ -2290,7 +2289,7 @@ namespace {
|
||||||
// non-tactical moves late in the move list close to the leaves are
|
// non-tactical moves late in the move list close to the leaves are
|
||||||
// candidates for pruning.
|
// candidates for pruning.
|
||||||
|
|
||||||
bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d) {
|
bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d, const History& H) {
|
||||||
Square mfrom, mto, tfrom, tto;
|
Square mfrom, mto, tfrom, tto;
|
||||||
|
|
||||||
assert(move_is_ok(m));
|
assert(move_is_ok(m));
|
||||||
|
@ -2369,7 +2368,7 @@ namespace {
|
||||||
// update_history() registers a good move that produced a beta-cutoff
|
// update_history() registers a good move that produced a beta-cutoff
|
||||||
// in history and marks as failures all the other moves of that ply.
|
// in history and marks as failures all the other moves of that ply.
|
||||||
|
|
||||||
void update_history(const Position& pos, Move m, Depth depth,
|
void update_history(const Position& pos, Move m, Depth depth, History& H,
|
||||||
Move movesSearched[], int moveCount) {
|
Move movesSearched[], int moveCount) {
|
||||||
|
|
||||||
H.success(pos.piece_on(move_from(m)), move_to(m), depth);
|
H.success(pos.piece_on(move_from(m)), move_to(m), depth);
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include "history.h"
|
||||||
#include "lock.h"
|
#include "lock.h"
|
||||||
#include "movepick.h"
|
#include "movepick.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
@ -73,6 +74,7 @@ struct Thread {
|
||||||
volatile bool idle;
|
volatile bool idle;
|
||||||
volatile bool workIsWaiting;
|
volatile bool workIsWaiting;
|
||||||
volatile bool printCurrentLine;
|
volatile bool printCurrentLine;
|
||||||
|
History H;
|
||||||
unsigned char pad[64]; // set some distance among local data for each thread
|
unsigned char pad[64]; // set some distance among local data for each thread
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue