1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

Make reduction search code SMP-friendly

In sp_search_pv() we do a LMR search using sp->alpha, at the end
we detect a fail high with condition (value > sp->alpha), but if
another thread has increased sp->alpha during our LMR search we
could miss to detect a fail high event becasue value will be equal
to old alpha and so smaller then new one.

This patch fixes this SMP-bug and changes also the non SMP versions
of the search to keep code style in sync.

Bug spotted by Bruno Causse.

No functional change (for single CPU case)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Joona Kiiski 2010-01-17 19:14:23 +02:00 committed by Marco Costalba
parent 72e1e9b986
commit 419c5b69ca

View file

@ -955,6 +955,8 @@ namespace {
{
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
bool doFullDepthSearch = true;
if ( depth >= 3*OnePly // FIXME was newDepth
&& !dangerous
&& !captureOrPromotion
@ -965,13 +967,11 @@ namespace {
{
ss[0].reduction = Depth(int(floor(red * int(OnePly))));
value = -search(pos, ss, -alpha, newDepth-ss[0].reduction, 1, true, 0);
doFullDepthSearch = (value > alpha);
}
}
else
value = alpha + 1; // Just to trigger next condition
} else
value = alpha + 1; // Just to trigger next condition
if (value > alpha)
if (doFullDepthSearch)
{
value = -search(pos, ss, -alpha, newDepth, 1, true, 0);
@ -1207,6 +1207,8 @@ namespace {
{
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
bool doFullDepthSearch = true;
if ( depth >= 3*OnePly
&& !dangerous
&& !captureOrPromotion
@ -1218,14 +1220,11 @@ namespace {
{
ss[ply].reduction = Depth(int(floor(red * int(OnePly))));
value = -search(pos, ss, -alpha, newDepth-ss[ply].reduction, ply+1, true, threadID);
doFullDepthSearch = (value > alpha);
}
else
value = alpha + 1; // Just to trigger next condition
}
else
value = alpha + 1; // Just to trigger next condition
if (value > alpha) // Go with full depth non-pv search
if (doFullDepthSearch) // Go with full depth non-pv search
{
ss[ply].reduction = Depth(0);
value = -search(pos, ss, -alpha, newDepth, ply+1, true, threadID);
@ -1541,6 +1540,8 @@ namespace {
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
bool doFullDepthSearch = true;
if ( depth >= 3*OnePly
&& !dangerous
&& !captureOrPromotion
@ -1553,14 +1554,11 @@ namespace {
{
ss[ply].reduction = Depth(int(floor(red * int(OnePly))));
value = -search(pos, ss, -(beta-1), newDepth-ss[ply].reduction, ply+1, true, threadID);
doFullDepthSearch = (value >= beta);
}
else
value = beta; // Just to trigger next condition
}
else
value = beta; // Just to trigger next condition
if (value >= beta) // Go with full depth non-pv search
if (doFullDepthSearch) // Go with full depth non-pv search
{
ss[ply].reduction = Depth(0);
value = -search(pos, ss, -(beta-1), newDepth, ply+1, true, threadID);
@ -1871,6 +1869,8 @@ namespace {
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
bool doFullDepthSearch = true;
if ( !dangerous
&& !captureOrPromotion
&& !move_is_castle(move)
@ -1881,14 +1881,11 @@ namespace {
{
ss[sp->ply].reduction = Depth(int(floor(red * int(OnePly))));
value = -search(pos, ss, -(sp->beta-1), newDepth-ss[sp->ply].reduction, sp->ply+1, true, threadID);
doFullDepthSearch = (value >= sp->beta);
}
else
value = sp->beta; // Just to trigger next condition
}
else
value = sp->beta; // Just to trigger next condition
if (value >= sp->beta) // Go with full depth non-pv search
if (doFullDepthSearch) // Go with full depth non-pv search
{
ss[sp->ply].reduction = Depth(0);
value = -search(pos, ss, -(sp->beta - 1), newDepth, sp->ply+1, true, threadID);
@ -1982,6 +1979,8 @@ namespace {
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
bool doFullDepthSearch = true;
if ( !dangerous
&& !captureOrPromotion
&& !move_is_castle(move)
@ -1990,21 +1989,20 @@ namespace {
double red = 0.5 + ln(moveCount) * ln(sp->depth / 2) / 6.0;
if (red >= 1.0)
{
Value localAlpha = sp->alpha;
ss[sp->ply].reduction = Depth(int(floor(red * int(OnePly))));
value = -search(pos, ss, -sp->alpha, newDepth-ss[sp->ply].reduction, sp->ply+1, true, threadID);
value = -search(pos, ss, -localAlpha, newDepth-ss[sp->ply].reduction, sp->ply+1, true, threadID);
doFullDepthSearch = (value > localAlpha);
}
else
value = sp->alpha + 1; // Just to trigger next condition
}
else
value = sp->alpha + 1; // Just to trigger next condition
if (value > sp->alpha) // Go with full depth non-pv search
if (doFullDepthSearch) // Go with full depth non-pv search
{
Value localAlpha = sp->alpha;
ss[sp->ply].reduction = Depth(0);
value = -search(pos, ss, -sp->alpha, newDepth, sp->ply+1, true, threadID);
value = -search(pos, ss, -localAlpha, newDepth, sp->ply+1, true, threadID);
if (value > sp->alpha && value < sp->beta)
if (value > localAlpha && value < sp->beta)
{
// When the search fails high at ply 1 while searching the first
// move at the root, set the flag failHighPly1. This is used for