From f61d3e458796848c6ef18269e8ea3b4c93f81df1 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sun, 17 Jan 2010 01:12:14 +0100 Subject: [PATCH] uct_search(): Print progress status here inst. of uct_playouts() --- uct/uct.c | 14 +++++++++++++- uct/walk.c | 24 ++---------------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/uct/uct.c b/uct/uct.c index c9af048..dfd65d7 100644 --- a/uct/uct.c +++ b/uct/uct.c @@ -42,6 +42,8 @@ static void uct_pondering_stop(struct uct *u); /* How often to inspect the tree from the main thread to check for playout * stop, progress reports, etc. A (struct timespec) initializer. */ #define TREE_BUSYWAIT_INTERVAL { .tv_sec = 0, .tv_nsec = 100*1000000 /* 100ms */ } +/* Once per how many simulations to show a progress report line. */ +#define TREE_SIMPROGRESS_INTERVAL 10000 static void @@ -427,6 +429,8 @@ uct_search(struct uct *u, struct board *b, enum stone color, struct tree *t, int int ngames = games * (u->thread_model == TM_ROOT ? 1 : u->threads); /* Number of already played games. */ int pgames = t->root->u.playouts; + /* Number of last game with progress print. */ + int last_print = 0; struct spawn_ctx *ctx = uct_search_start(u, b, color, t); @@ -445,16 +449,24 @@ uct_search(struct uct *u, struct board *b, enum stone color, struct tree *t, int nanosleep(&busywait_interval, NULL); /* Did we play enough games? */ - if (ctx->t->root->u.playouts - pgames > ngames) + int i = ctx->t->root->u.playouts - pgames; + if (i > ngames) break; /* Won situation? */ struct tree_node *best = u->policy->choose(u->policy, ctx->t->root, b, color); if (best && ((best->u.playouts >= 2000 && tree_node_get_value(ctx->t, 1, best->u.value) >= u->loss_threshold) || (best->u.playouts >= 500 && tree_node_get_value(ctx->t, 1, best->u.value) >= 0.95))) break; + + /* Print progress? */ + if (i - last_print > TREE_SIMPROGRESS_INTERVAL) { + last_print += TREE_SIMPROGRESS_INTERVAL; // keep the numbers tidy + uct_progress_status(u, ctx->t, color, last_print); + } } ctx = uct_search_stop(); + uct_progress_status(u, t, color, ctx->games); return ctx->games; } diff --git a/uct/walk.c b/uct/walk.c index 4b9bdf3..4972ea9 100644 --- a/uct/walk.c +++ b/uct/walk.c @@ -336,28 +336,8 @@ end: int uct_playouts(struct uct *u, struct board *b, enum stone color, struct tree *t) { - /* Should we print progress info? In case all threads work on the same - * tree, only the first thread does. */ - /* XXX: The thread manager should do things like this. */ - #define ok_to_talk (!u->parallel_tree || !thread_id) - int i; - for (i = 0; !uct_halt; i++) { - int result = uct_playout(u, b, color, t); - if (result == 0) { - /* Tree descent has hit invalid move. */ - continue; - } - - if (unlikely(ok_to_talk && i > 0 && !(i % 10000))) { - uct_progress_status(u, t, color, i); - } - } - - if (ok_to_talk) { - uct_progress_status(u, t, color, i); - if (UDEBUGL(3)) - tree_dump(t, u->dumpthres); - } + for (i = 0; !uct_halt; i++) + uct_playout(u, b, color, t); return i; } -- 2.11.4.GIT