mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 09:13:08 +00:00
Reduce lock contention in sp_search_pv()
In less then 1% of cases value > sp->bestValue, so avoid an useless lock in the common case. This is the same change already applied to sp_search(). Also SplitPoint futilityValue is not volatile because never changes after has been assigned in split() No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
5ca4284027
commit
cf9bf4e58f
2 changed files with 30 additions and 26 deletions
|
@ -2046,37 +2046,40 @@ namespace {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// New best move?
|
// New best move?
|
||||||
lock_grab(&(sp->lock));
|
if (value > sp->bestValue) // Less then 2% of cases
|
||||||
if (value > sp->bestValue && !thread_should_stop(threadID))
|
|
||||||
{
|
{
|
||||||
sp->bestValue = value;
|
lock_grab(&(sp->lock));
|
||||||
if (value > sp->alpha)
|
if (value > sp->bestValue && !thread_should_stop(threadID))
|
||||||
{
|
{
|
||||||
// Ask threads to stop before to modify sp->alpha
|
sp->bestValue = value;
|
||||||
if (value >= sp->beta)
|
if (value > sp->alpha)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ActiveThreads; i++)
|
// Ask threads to stop before to modify sp->alpha
|
||||||
if (i != threadID && (i == sp->master || sp->slaves[i]))
|
if (value >= sp->beta)
|
||||||
Threads[i].stop = true;
|
{
|
||||||
|
for (int i = 0; i < ActiveThreads; i++)
|
||||||
|
if (i != threadID && (i == sp->master || sp->slaves[i]))
|
||||||
|
Threads[i].stop = true;
|
||||||
|
|
||||||
sp->finished = true;
|
sp->finished = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
sp->alpha = value;
|
||||||
|
|
||||||
|
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
||||||
|
if (value == value_mate_in(sp->ply + 1))
|
||||||
|
ss[sp->ply].mateKiller = move;
|
||||||
}
|
}
|
||||||
|
// If we are at ply 1, and we are searching the first root move at
|
||||||
sp->alpha = value;
|
// ply 0, set the 'Problem' variable if the score has dropped a lot
|
||||||
|
// (from the computer's point of view) since the previous iteration.
|
||||||
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
if ( sp->ply == 1
|
||||||
if (value == value_mate_in(sp->ply + 1))
|
&& Iteration >= 2
|
||||||
ss[sp->ply].mateKiller = move;
|
&& -value <= IterationInfo[Iteration-1].value - ProblemMargin)
|
||||||
}
|
Problem = true;
|
||||||
// If we are at ply 1, and we are searching the first root move at
|
}
|
||||||
// ply 0, set the 'Problem' variable if the score has dropped a lot
|
lock_release(&(sp->lock));
|
||||||
// (from the computer's point of view) since the previous iteration.
|
|
||||||
if ( sp->ply == 1
|
|
||||||
&& Iteration >= 2
|
|
||||||
&& -value <= IterationInfo[Iteration-1].value - ProblemMargin)
|
|
||||||
Problem = true;
|
|
||||||
}
|
}
|
||||||
lock_release(&(sp->lock));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lock_grab(&(sp->lock));
|
lock_grab(&(sp->lock));
|
||||||
|
|
|
@ -51,7 +51,8 @@ struct SplitPoint {
|
||||||
SearchStack *parentSstack;
|
SearchStack *parentSstack;
|
||||||
int ply;
|
int ply;
|
||||||
Depth depth;
|
Depth depth;
|
||||||
volatile Value alpha, beta, bestValue, futilityValue;
|
volatile Value alpha, beta, bestValue;
|
||||||
|
Value futilityValue;
|
||||||
bool pvNode;
|
bool pvNode;
|
||||||
int master, slaves[THREAD_MAX];
|
int master, slaves[THREAD_MAX];
|
||||||
Lock lock;
|
Lock lock;
|
||||||
|
|
Loading…
Add table
Reference in a new issue