chiark / gitweb /
break out set_best
[matchsticks-search.git] / main.c
diff --git a/main.c b/main.c
index 8aaebad359679275a74ebd524460c6f67d0356f6..fd0569be80e712602988a5f79207b77bcb45ff5b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -107,6 +107,10 @@ static void progress_eol(void) {
   fflush(stderr);
 }
 
+static void set_best(double new_best) {
+  best = new_best;
+}
+
 /*----- multicore support -----*/
 
 /*
@@ -202,6 +206,8 @@ static void mc_awaitpid(int wnum, pid_t pid) {
 }
 
 static void multicore_outer_iteration(int i, AdjWord min) {
+  static unsigned check_counter;
+
   assert(i == multicore_iteration_boundary);
   mc_iter_min = min;
   mc_rwvsetup_outer();
@@ -209,6 +215,9 @@ static void multicore_outer_iteration(int i, AdjWord min) {
   assert(r == mc_iovlen);
   /* effectively, this writev arranges to transfers control
    * to some worker's instance of iterate_recurse via mc_iterate_worker */
+
+  if (!(check_counter++ & 0xff))
+    multicore_check_for_new_best();
 }
 
 static void mc_iterate_worker(void) {
@@ -217,6 +226,13 @@ static void mc_iterate_worker(void) {
     ssize_t r = readv(mc_work[0], mc_iov, mc_niovs);
     if (r == 0) break;
     assert(r == mc_iovlen);
+    
+    bool ok = maxhamweight_ok();
+    if (!ok) continue;
+
+    ok = preconsider_ok(multicore_iteration_boundary, 1);
+    progress_eol();
+    if (!ok) continue;
 
     /* stop iterate_recurse from trying to run multicore_outer_iteration */
     int mc_org_it_bound = multicore_iteration_boundary;
@@ -297,7 +313,7 @@ static void multicore_check_for_new_best(void) {
     if (!got) break;
     assert(got == sizeof(msg));
     if (msg > best)
-      best = msg;
+      set_best(msg);
     mc_bus_read += sizeof(msg);
   }
 }
@@ -543,7 +559,7 @@ static void optimise(bool doprint) {
 
   HAVE_PRINTED;
 
-  best = got;
+  set_best(got);
   multicore_found_new_best();
 
   if (best_prob) glp_delete_prob(best_prob);