From e671a4c0a71f984a97c48a975baf012335e51650 Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Thu, 11 Mar 2010 17:08:49 +0100 Subject: [PATCH] Distributed master sends time info to slaves in genmoves command. --- distributed/distributed.c | 25 +++++++++++++++++++++---- gtp.c | 16 +++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/distributed/distributed.c b/distributed/distributed.c index 870dad5..6653170 100644 --- a/distributed/distributed.c +++ b/distributed/distributed.c @@ -514,20 +514,37 @@ distributed_genmove(struct engine *e, struct board *b, struct time_info *ti, enu long time_limit = 0; int min_playouts = 0; + char *cmd = pass_all_alive ? "pachi-genmoves_cleanup" : "pachi-genmoves"; + char args[128]; + if (ti->period == TT_NULL) *ti = default_ti; struct time_stop stop; time_stop_conditions(ti, b, FUSEKI_END, YOSE_START, &stop); + if (ti->dim == TD_WALLTIME) { time_limit = ti->len.t.timer_start + stop.worst.time; + + /* Send time info to the slaves to make sure they all + * reply in time, particularly if they were out of sync + * and there are no time_left commands. We cannot send + * the absolute time limit because slaves may have a + * different system time. + * Keep this code in sync with gtp_parse(). */ + snprintf(args, sizeof(args), "%s %.3f %.3f %d %d\n", + stone2str(color), ti->len.t.main_time, + ti->len.t.byoyomi_time, ti->len.t.byoyomi_periods, + ti->len.t.byoyomi_stones); } else { min_playouts = stop.desired.playouts; + + /* For absolute number of simulations, slaves still + * use their own -t =NUM parameter. (The master + * needs to know the total number of simulations over + * all slaves so it has a different -t parameter.) */ + snprintf(args, sizeof(args), "%s\n", stone2str(color)); } pthread_mutex_lock(&slave_lock); - - char *cmd = pass_all_alive ? "pachi-genmoves_cleanup" : "pachi-genmoves"; - char args[64]; - snprintf(args, sizeof(args), "%s\n", stone2str(color)); new_cmd(b, cmd, args); get_replies(time_limit, min_playouts, b); diff --git a/gtp.c b/gtp.c index 986de0b..643177c 100644 --- a/gtp.c +++ b/gtp.c @@ -252,8 +252,18 @@ gtp_parse(struct board *board, struct engine *engine, struct time_info *ti, char char *arg; next_tok(arg); enum stone color = str2stone(arg); + struct time_info *myti = &ti[color]; + /* Get correct time from master. Keep this code in sync + * with distributed_genmove(). */ + if (myti->dim == TD_WALLTIME && + sscanf(next, "%lf %lf %d %d", &myti->len.t.main_time, + &myti->len.t.byoyomi_time, &myti->len.t.byoyomi_periods, + &myti->len.t.byoyomi_stones) != 4) { + gtp_error(id, "incorrect time info", NULL); + return P_OK; + } - char *reply = engine->genmoves(engine, board, &ti[color], color, !strcasecmp(cmd, "pachi-genmoves_cleanup")); + char *reply = engine->genmoves(engine, board, myti, color, !strcasecmp(cmd, "pachi-genmoves_cleanup")); if (DEBUGL(2)) fprintf(stderr, "proposing moves %s\n", reply); if (DEBUGL(1)) { @@ -261,10 +271,6 @@ gtp_parse(struct board *board, struct engine *engine, struct time_info *ti, char } gtp_reply(id, reply, NULL); - /* See "genmove" above about time management. */ - if (ti[color].period != TT_NULL && ti[color].dim == TD_WALLTIME) - time_sub(&ti[color], time_now() - ti[color].len.t.timer_start); - } else if (!strcasecmp(cmd, "set_free_handicap")) { struct move m; m.color = S_BLACK; -- 2.11.4.GIT