1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Set the search start time much earlier

The start time is the time point we start our clock and in
an ideal case it should be set to the same clock running in
the tournament manager when it sends to the engine the 'go'
UCI command.

Currently it is set at the beginning of MainThread::think()
but this means we have not accounted for the time to wake
up the thread and the time it takes start_thinking to join()
the main thread, possibly waiting for the slave threads to finish.

In standard conditions we are talking of very few msecs, but
with high number of cores and high time pressure, it is
difficult to get a reliable estimate.

So move it much earlier, just before processing the 'go' command.

bench: 8397672
This commit is contained in:
Marco Costalba 2015-10-10 08:34:29 +02:00
parent e854b30c84
commit 47b5242930
6 changed files with 10 additions and 6 deletions

View file

@ -156,6 +156,7 @@ void benchmark(const Position& current, istream& is) {
else
{
Search::StateStackPtr st;
limits.startTime = now();
Threads.start_thinking(pos, limits, st);
Threads.main()->join();
nodes += Threads.nodes_searched();

View file

@ -226,7 +226,7 @@ template uint64_t Search::perft<true>(Position& pos, Depth depth);
void MainThread::think() {
Color us = pos.side_to_move();
Time.init(Limits, us, pos.game_ply(), now());
Time.init(Limits, us, pos.game_ply());
int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns
DrawValue[ us] = VALUE_DRAW - Value(contempt);

View file

@ -88,6 +88,7 @@ struct LimitsType {
std::vector<Move> searchmoves;
int time[COLOR_NB], inc[COLOR_NB], npmsec, movestogo, depth, movetime, mate, infinite, ponder;
int64_t nodes;
TimePoint startTime;
};
/// The SignalsType struct stores volatile flags updated during the search

View file

@ -80,7 +80,7 @@ namespace {
/// inc > 0 && movestogo == 0 means: x basetime + z increment
/// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply, TimePoint now)
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply)
{
int minThinkingTime = Options["Minimum Thinking Time"];
int moveOverhead = Options["Move Overhead"];
@ -102,7 +102,7 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply, TimePoi
limits.npmsec = npmsec;
}
start = now;
startTime = limits.startTime;
unstablePvFactor = 1;
optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);

View file

@ -29,16 +29,16 @@
class TimeManagement {
public:
void init(Search::LimitsType& limits, Color us, int ply, TimePoint now);
void init(Search::LimitsType& limits, Color us, int ply);
void pv_instability(double bestMoveChanges) { unstablePvFactor = 1 + bestMoveChanges; }
int available() const { return int(optimumTime * unstablePvFactor * 0.76); }
int maximum() const { return maximumTime; }
int elapsed() const { return int(Search::Limits.npmsec ? Threads.nodes_searched() : now() - start); }
int elapsed() const { return int(Search::Limits.npmsec ? Threads.nodes_searched() : now() - startTime); }
int64_t availableNodes; // When in 'nodes as time' mode
private:
TimePoint start;
TimePoint startTime;
int optimumTime;
int maximumTime;
double unstablePvFactor;

View file

@ -112,6 +112,8 @@ namespace {
Search::LimitsType limits;
string token;
limits.startTime = now(); // As early as possible!
while (is >> token)
if (token == "searchmoves")
while (is >> token)