From aed66f1fe06f2cbb9f4dd275d9ea050c4abf8eea Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Sun, 14 Nov 2010 19:36:35 +0100 Subject: [PATCH] Distributed engine: wait for enough slave replies before early stop. --- distributed/distributed.c | 9 +++++++-- uct/search.c | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/distributed/distributed.c b/distributed/distributed.c index 51a73c1..c19d65b 100644 --- a/distributed/distributed.c +++ b/distributed/distributed.c @@ -118,6 +118,9 @@ static const struct time_info default_ti = { /* Maximum time (seconds) to wait for answers to genmoves. */ #define MAX_GENMOVES_WAIT 0.1 /* 100 ms */ +/* Minimum time (seconds) to wait before we stop early. This should + * ensure that most slaves have replied at least once. */ +#define MIN_EARLY_STOP_WAIT 0.3 /* 300 ms */ /* Display a path as leafdim == TD_WALLTIME) { if (now - ti->len.t.timer_start >= stop.worst.time) break; + if (!keep_looking && now - first >= MIN_EARLY_STOP_WAIT) break; } else { - if (played >= stop.worst.playouts) break; + if (!keep_looking || played >= stop.worst.playouts) break; } if (DEBUGVV(2)) { char *coord = coord2sstr(best, b); diff --git a/uct/search.c b/uct/search.c index 848b252..cbd6f8b 100644 --- a/uct/search.c +++ b/uct/search.c @@ -271,13 +271,20 @@ uct_search_stop_early(struct uct *u, struct tree *t, struct board *b, if (fullmem) return true; + /* Think at least 100ms to avoid a random move. This is particularly + * important in distributed mode, where this function is called frequently. */ + double elapsed = 0.0; + if (ti->dim == TD_WALLTIME) { + elapsed = time_now() - ti->len.t.timer_start; + if (elapsed < TREE_BUSYWAIT_INTERVAL) return false; + } + /* Break early if we estimate the second-best move cannot * catch up in assigned time anymore. We use all our time * if we are in byoyomi with single stone remaining in our * period, however - it's better to pre-ponder. */ bool time_indulgent = (!ti->len.t.main_time && ti->len.t.byoyomi_stones == 1); if (best2 && ti->dim == TD_WALLTIME && !time_indulgent) { - double elapsed = time_now() - ti->len.t.timer_start; double remaining = stop->worst.time - elapsed; double pps = ((double)played) / elapsed; double estplayouts = remaining * pps + PLAYOUT_DELTA_SAFEMARGIN; -- 2.11.4.GIT