From 7301d0a8be9b5eb83d80198d589ca708e395c4fd Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sun, 17 Jan 2010 01:03:15 +0100 Subject: [PATCH] uct_playouts_threaded(): Also check for won situation here inst. of uct_playouts() Now, uct_playouts() will never voluntarily terminate. --- uct/uct.c | 23 +++++++++++++++++------ uct/walk.c | 7 ------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/uct/uct.c b/uct/uct.c index ece322a..1c888a0 100644 --- a/uct/uct.c +++ b/uct/uct.c @@ -265,7 +265,16 @@ uct_done(struct engine *e) * ... * workerK * uct_playouts() loop, doing descend-playout until uct_halt - */ + * + * Another way to look at it is by functions (lines denote thread boundaries): + * + * | uct_genmove() + * | uct_playouts_threaded() + * | ----------------------- + * | spawn_thread_manager() + * | ----------------------- + * | spawn_worker() + * V uct_playouts() */ /* Set in thread manager in case the workers should stop. */ volatile sig_atomic_t uct_halt = 0; @@ -365,9 +374,6 @@ spawn_thread_manager(void *ctx_) free(ctx); if (UDEBUGL(2)) fprintf(stderr, "Joined worker %d\n", finish_thread); - /* Do not get stalled by slow threads. */ - if (joined >= u->threads / 2) - uct_halt = 1; pthread_mutex_unlock(&finish_serializer); } @@ -433,14 +439,19 @@ uct_playouts_threaded(struct uct *u, struct board *b, enum stone color, struct t * count. However, TM_ROOT just does not deserve any more extra code * right now. */ - /* We periodically poll the search tree and stop when we played enough - * games. */ + /* Now, just periodically poll the search tree. */ struct timespec busywait_interval = TREE_BUSYWAIT_INTERVAL; while (1) { nanosleep(&busywait_interval, NULL); + /* Did we play enough games? */ if (ctx->t->root->u.playouts - pgames > 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; } ctx = uct_search_stop(); diff --git a/uct/walk.c b/uct/walk.c index c7ec5c1..4b9bdf3 100644 --- a/uct/walk.c +++ b/uct/walk.c @@ -352,13 +352,6 @@ uct_playouts(struct uct *u, struct board *b, enum stone color, struct tree *t) if (unlikely(ok_to_talk && i > 0 && !(i % 10000))) { uct_progress_status(u, t, color, i); } - - if (i > 0 && !(i % 500)) { - struct tree_node *best = u->policy->choose(u->policy, t->root, b, color); - if (best && ((best->u.playouts >= 2000 && tree_node_get_value(t, 1, best->u.value) >= u->loss_threshold) - || (best->u.playouts >= 500 && tree_node_get_value(t, 1, best->u.value) >= 0.95))) - break; - } } if (ok_to_talk) { -- 2.11.4.GIT