gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnugo-devel] Re: your mail


From: Daniel Bump
Subject: [gnugo-devel] Re: your mail
Date: Mon, 8 Oct 2001 20:24:20 -0700

> > There is another way this could be done without having
> > to insert these commands into the file but it would
> > require modifying gtp.c. There would be a ``timer mode''
> > in which the time for each command would be written to
> > stderr.
> 
> Sounds rather impractical and quite ugly to me.

Here's an implementation of this. I don't think it's ugly or
impractical. In fact, this seems to be the simplest way.

The objection that can be raised to this patch is that we
don't really want this in gtp.c.

With this patch if you run gnugo --mode gtp --showtime you get
timing data in stderr. I generalized time_report slightly
since in 3.1.9 it is silent for times less than 1 second. 
For timing the gtp we don't want that.

Dan



Index: engine/dragon.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/dragon.c,v
retrieving revision 1.16
diff -u -r1.16 dragon.c
--- engine/dragon.c     2001/10/04 18:38:53     1.16
+++ engine/dragon.c     2001/10/09 03:03:10
@@ -93,15 +93,15 @@
              m, n, worm[POS(m, n)].size);
     }
 
-  time_report(2, "  time to initialize dragons", -1, -1);
+  time_report(2, "  time to initialize dragons", -1, -1, 1.0);
   make_domains(black_eye, white_eye, 0);
-  time_report(2, "  time to make domains", -1, -1);
+  time_report(2, "  time to make domains", -1, -1, 1.0);
 
   /* Find explicit connections patterns in database and amalgamate
    * involved dragons.
    */
   find_connections();
-  time_report(2, "  time to find connections", -1, -1);
+  time_report(2, "  time to find connections", -1, -1, 1.0);
   
   /* Amalgamate dragons sharing an eyespace (not ko). At the same time
    * we decide to which dragon an eyespace belongs. Ko eyespaces
@@ -145,14 +145,14 @@
        }
       }
     }
-  time_report(2, "  time to amalgamate dragons", -1, -1);
+  time_report(2, "  time to amalgamate dragons", -1, -1, 1.0);
 
   /* At this time, all dragons have been finalized and we can
    * initialize the dragon2[] array. After that we can no longer allow
    * amalgamation of dragons.
    */
   initialize_supplementary_dragon_data();
-  time_report(2, "  time to initialize dragon2", -1, -1);
+  time_report(2, "  time to initialize dragon2", -1, -1, 1.0);
   
   /* Find adjacent worms which can be easily captured: */
   for (m = 0; m < board_size; m++)
@@ -195,7 +195,7 @@
       }
     }
 
-  time_report(2, "  time to find lunches", -1, -1);
+  time_report(2, "  time to find lunches", -1, -1, 1.0);
 
   /* In case origins of dragons got moved, put the dragons of eyes aright. */
   for (i = 0; i < board_size; i++)
@@ -210,7 +210,7 @@
          white_eye[POS(i, j)].dragon = dr;
       }
     }
-  time_report(2, "  time to fix origins", -1, -1);
+  time_report(2, "  time to fix origins", -1, -1, 1.0);
 
   /* Find topological half eyes and false eyes by analyzing the
    * diagonal intersections, as described in the Texinfo
@@ -300,7 +300,7 @@
        propagate_eye(POS(i, j), white_eye);
       }
     }
-  time_report(2, "  time to find eyes", -1, -1);
+  time_report(2, "  time to find eyes", -1, -1, 1.0);
 
   /* Now we compute the genus. */
   for (i = 0; i < board_size; i++)
@@ -338,7 +338,7 @@
       }
     }
 
-  time_report(2, "  time to compute genus", -1, -1);
+  time_report(2, "  time to compute genus", -1, -1, 1.0);
 
   /* Compute the escape route measure. */
   for (m = 0; m < board_size; m++)
@@ -348,7 +348,7 @@
        DRAGON2(m, n).escape_route = compute_escape(m, n, 0);
       }
 
-  time_report(2, "  time to compute escape", -1, -1);
+  time_report(2, "  time to compute escape", -1, -1, 1.0);
 
   /* Update the segmentation of the initial influence before we
    * compute the surrounding moyo sizes. The reason for this is that
@@ -356,7 +356,7 @@
    * into account.
    */
   resegment_initial_influence();
-  time_report(2, "  resegment_initial_influence", -1, -1);
+  time_report(2, "  resegment_initial_influence", -1, -1, 1.0);
 
   /* Compute the surrounding moyo sizes. */
   for (d = 0; d < number_of_dragons; d++) {
@@ -364,7 +364,7 @@
                                              J(dragon2[d].origin),
                                              DRAGON(d).color, 1);
   }
-  time_report(2, "  influence_get_moyo_size", -1, -1);
+  time_report(2, "  influence_get_moyo_size", -1, -1, 1.0);
 
   /* Determine status: ALIVE, DEAD, CRITICAL or UNKNOWN */
   for (m = 0; m < board_size; m++)
@@ -374,7 +374,7 @@
        sgffile_dragon_status(m, n, dragon[POS(m, n)].status);
       }
     }
-  time_report(2, "  compute_dragon_status", -1, -1);
+  time_report(2, "  compute_dragon_status", -1, -1, 1.0);
 
   /* We must update the dragon status at every intersection before we
    * call the owl code. This updates all fields.
@@ -386,7 +386,7 @@
     }
   
   find_neighbor_dragons();
-  time_report(2, "  find_neighbor_dragons", -1, -1);
+  time_report(2, "  find_neighbor_dragons", -1, -1, 1.0);
 
   if (stop_before_owl)
     return;
@@ -490,11 +490,11 @@
              dragon[POS(m, n)].owl_threat_status = ALIVE;
          }
        }
-       time_report(3, "    owl reading for dragon at ", m, n);
+       time_report(3, "    owl reading for dragon at ", m, n, 1.0);
       }
     }
 
-  time_report(2, "  owl reading", -1, -1);
+  time_report(2, "  owl reading", -1, -1, 1.0);
 
   /* The dragon data is now correct at the origin of each dragon but
    * we need to copy it to every vertex.  
@@ -527,7 +527,7 @@
          dragon[POS(m, n)].matcher_status = dragon[POS(m, n)].status;
       }
 
-  time_report(2, "  compute matcher status", -1, -1);
+  time_report(2, "  compute matcher status", -1, -1, 1.0);
 
   /* Compute the safety value. */
   for (d = 0; d < number_of_dragons; d++) {
@@ -573,11 +573,11 @@
       dragon2[d].safety = ALIVE;
   }
 
-  time_report(2, "  compute dragon safety", -1, -1);
+  time_report(2, "  compute dragon safety", -1, -1, 1.0);
 
   /* Resolve semeais. This may revise the safety and status fields. */
   semeai(color);
-  time_report(2, "  semeai module", -1, -1);
+  time_report(2, "  semeai module", -1, -1, 1.0);
 
   /* The matcher_status is now correct at the origin of each dragon
    * but we need to copy it to every vertex.
@@ -616,7 +616,7 @@
        }
       }
   
-  time_report(2, "  revise inessentiality", -1, -1);
+  time_report(2, "  revise inessentiality", -1, -1, 1.0);
 
   /* Count the non-dead dragons. */
   lively_white_dragons = 0;
Index: engine/genmove.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/genmove.c,v
retrieving revision 1.8
diff -u -r1.8 genmove.c
--- engine/genmove.c    2001/09/26 00:35:03     1.8
+++ engine/genmove.c    2001/10/09 03:03:17
@@ -104,7 +104,7 @@
   if (NEEDS_UPDATE(worms_examined)) {
     start_timer(0);
     make_worms();
-    time_report(0, "  make worms", -1, -1);
+    time_report(0, "  make worms", -1, -1, 1.0);
   }
   if (how_much == EXAMINE_WORMS) {
     verbose = save_verbose;
@@ -278,7 +278,7 @@
   /* Find out information about the worms and dragons. */
   start_timer(1);
   examine_position(color, EXAMINE_ALL);
-  time_report(1, "examine position", -1, -1);
+  time_report(1, "examine position", -1, -1, 1.0);
   if (level >= 8) {
     estimate_score(&lower_bound, &upper_bound);
     if (verbose || showscore) {
@@ -290,7 +290,7 @@
                lower_bound > 0 ? "W " : "B ", gg_abs(lower_bound),
                upper_bound > 0 ? "W " : "B ", gg_abs(upper_bound));
     }
-    time_report(1, "estimate score", -1, -1);
+    time_report(1, "estimate score", -1, -1, 1.0);
 
     /* The score will be used to determine when we are safely
      * ahead. So we want the most conservative score.
@@ -334,7 +334,7 @@
   /* Pattern matcher. */
   start_timer(1);
   shapes(color);
-  time_report(1, "shapes", -1, -1);
+  time_report(1, "shapes", -1, -1, 1.0);
   gg_assert(stackp == 0);
 
   /* Look for combination attacks. */
@@ -357,14 +357,14 @@
       add_your_atari_atari_move(I(apos), J(apos), aa_val);
     verbose = save_verbose;
   }
-  time_report(1, "atari atari", -1, -1);
+  time_report(1, "atari atari", -1, -1, 1.0);
 
   /* Review the move reasons and estimate move values. */
   if (review_move_reasons(i, j, &val, color, 
                          pure_threat_value, lower_bound))
     TRACE("Move generation likes %m with value %f\n", *i, *j, val);
   gg_assert(stackp == 0);
-  time_report(1, "review move reasons", -1, -1);
+  time_report(1, "review move reasons", -1, -1, 1.0);
 
   /* If the move value is 6 or lower, we look for endgame patterns too. */
   if (val <= 6.0 && !disable_endgame_patterns) {
@@ -373,7 +373,7 @@
     if (review_move_reasons(i, j, &val, color, pure_threat_value, score))
       TRACE("Move generation likes %m with value %f\n", *i, *j, val);
     gg_assert(stackp == 0);
-    time_report(1, "endgame", -1, -1);
+    time_report(1, "endgame", -1, -1, 1.0);
   }
   
   /* If no move found yet, revisit any semeai and change the
@@ -389,7 +389,7 @@
              *i, *j, val); 
       }
     }
-    time_report(1, "move reasons with revised semeai status", -1, -1);
+    time_report(1, "move reasons with revised semeai status", -1, -1, 1.0);
   }
 
   /* If still no move, fill a remaining liberty. This should pick up
@@ -400,7 +400,7 @@
     val = 1.0;
     TRACE("Filling a liberty at %m\n", *i, *j);
     move_considered(*i, *j, val);
-    time_report(1, "fill liberty", -1, -1);
+    time_report(1, "fill liberty", -1, -1, 1.0);
   }
 
   /* If we're instructed to play out the aftermath or capture all dead
@@ -413,7 +413,7 @@
     val = 1.0;
     TRACE("Aftermath move at %m\n", *i, *j);
     move_considered(*i, *j, val);
-    time_report(1, "aftermath_genmove", -1, -1);
+    time_report(1, "aftermath_genmove", -1, -1, 1.0);
   }
 
   /* If we're instructed to capture all dead opponent stones, generate
@@ -426,7 +426,7 @@
     val = 1.0;
     TRACE("Aftermath move at %m\n", *i, *j);
     move_considered(*i, *j, val);
-    time_report(1, "aftermath_genmove", -1, -1);
+    time_report(1, "aftermath_genmove", -1, -1, 1.0);
   }
 
   /* If no move is found then pass. */
@@ -447,9 +447,9 @@
     printf("Read result hits:     %d\n", stats.read_result_hits);
     printf("Hash collisions:      %d\n", stats.hash_collisions);
   }
-
-  if (showtime) {
-    double spent = time_report(0, "TIME to generate move at ", *i, *j);
+ 
+ if (showtime) {
+    double spent = time_report(0, "TIME to generate move at ", *i, *j, 1.0);
     total_time += spent;
     if (spent > slowest_time) {
       slowest_time = spent;
Index: engine/liberty.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.27
diff -u -r1.27 liberty.h
--- engine/liberty.h    2001/10/06 20:00:51     1.27
+++ engine/liberty.h    2001/10/09 03:03:28
@@ -144,7 +144,8 @@
 int find_common_libs(int str1, int str2, int maxlib, int *libs);
 
 void start_timer(int n);
-double time_report(int n, const char *occupation, int i, int j);
+double time_report(int n, const char *occupation, int i, int j, 
+                  double mintime);
 
 /* Play at (m, n) and then count the liberties. */
 int accurate_approxlib(int pos, int color, int maxlib, int *libs);
Index: engine/move_reasons.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/move_reasons.c,v
retrieving revision 1.23
diff -u -r1.23 move_reasons.c
--- engine/move_reasons.c       2001/10/06 21:01:04     1.23
+++ engine/move_reasons.c       2001/10/09 03:04:00
@@ -1800,7 +1800,7 @@
       else
        move[pos].move_safety = 0;
 
-      time_report(3, "    examine_move_safety: ", i, j);
+      time_report(3, "    examine_move_safety: ", i, j, 1.0);
     }
 }
 
@@ -3564,31 +3564,31 @@
   start_timer(2);
   if (!urgent || allpats) {
     find_more_attack_and_defense_moves(color);
-    time_report(2, "  find_more_attack_and_defense_moves", -1, -1);
+    time_report(2, "  find_more_attack_and_defense_moves", -1, -1, 1.0);
   }
 
   remove_opponent_attack_and_defense_moves(color);
-  time_report(2, "  remove_opponent_attack_and_defense_moves", -1, -1);
+  time_report(2, "  remove_opponent_attack_and_defense_moves", -1, -1, 1.0);
 
   do_remove_false_attack_and_defense_moves();
-  time_report(2, "  do_remove_false_attack_and_defense_moves", -1, -1);
+  time_report(2, "  do_remove_false_attack_and_defense_moves", -1, -1, 1.0);
 
   save_verbose = verbose;
   if (verbose > 0)
     verbose--;
   if (level > 5) {
     find_more_owl_attack_and_defense_moves(color);
-    time_report(2, "  find_more_owl_attack_and_defense_moves", -1, -1);
+    time_report(2, "  find_more_owl_attack_and_defense_moves", -1, -1, 1.0);
   }
   verbose = save_verbose;
 
   induce_secondary_move_reasons(color);
-  time_report(2, "  induce_secondary_move_reasons", -1, -1);
+  time_report(2, "  induce_secondary_move_reasons", -1, -1, 1.0);
   
   if (verbose > 0)
     verbose--;
   examine_move_safety(color);
-  time_report(2, "  examine_move_safety", -1, -1);
+  time_report(2, "  examine_move_safety", -1, -1, 1.0);
   verbose = save_verbose;
 
   if (printworms || verbose)
@@ -3596,7 +3596,7 @@
 
   /* Evaluate all moves with move reasons. */
   value_moves(color, pure_threat_value, score);
-  time_report(2, "  value_moves", -1, -1);
+  time_report(2, "  value_moves", -1, -1, 1.0);
 
   /* Perform point redistribution */
   redistribute_points();
@@ -3654,7 +3654,7 @@
       TRACE("Move at %m would be an illegal ko capture.\n", best_i, best_j);
       reevaluate_ko_threats();
       redistribute_points();
-      time_report(2, "  reevaluate_ko_threats", -1, -1);
+      time_report(2, "  reevaluate_ko_threats", -1, -1, 1.0);
       ko_values_have_been_added = 1;
       move[POS(best_i, best_j)].value = 0.0;
       move[POS(best_i, best_j)].final_value = 0.0;
Index: engine/utils.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/utils.c,v
retrieving revision 1.16
diff -u -r1.16 utils.c
--- engine/utils.c      2001/10/04 18:38:53     1.16
+++ engine/utils.c      2001/10/09 03:04:16
@@ -1699,17 +1699,18 @@
 
 /* Report time spent and restart the timer. */
 double
-time_report(int n, const char *occupation, int i, int j)
+time_report(int n, const char *occupation, int i, int j, double mintime)
 {
   double t;
   double dt;
   gg_assert(n >= 0 && n < NUMBER_OF_TIMERS);
+
   if (!showtime)
     return 0.0;
 
   t = gg_gettimeofday();
   dt = t - timers[n];
-  if (dt > 1.0) {
+  if (dt > mintime) {
     gprintf("%s", occupation);
     if (!is_pass(POS(i, j)))
       gprintf("%m", i, j);
Index: interface/gtp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/gtp.c,v
retrieving revision 1.5
diff -u -r1.5 gtp.c
--- interface/gtp.c     2001/09/06 21:39:52     1.5
+++ interface/gtp.c     2001/10/09 03:04:20
@@ -97,7 +97,12 @@
      */
     for (i = 0; commands[i].name != NULL; i++) {
       if (strcmp(command, commands[i].name) == 0) {
+       int save_showtime = showtime;
+       start_timer(0);
+       showtime = 0;
        status = (*commands[i].function)(p, id);
+       showtime = save_showtime;
+       time_report(0, "[gtp time] ", -1, -1, 0.0);     
        break;
       }
     }
Index: interface/gtp.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/gtp.h,v
retrieving revision 1.5
diff -u -r1.5 gtp.h
--- interface/gtp.h     2001/09/06 21:39:52     1.5
+++ interface/gtp.h     2001/10/09 03:04:21
@@ -75,6 +75,12 @@
 void gtp_print_vertices(int n, int movei[], int movej[]);
 void gtp_print_vertex(int i, int j);
 
+int showtime;
+void start_timer(int n);
+double time_report(int n, const char *occupation, int i, int j,
+                  double mintime);
+
+
 /*
  * Local Variables:
  * tab-width: 8




reply via email to

[Prev in Thread] Current Thread [Next in Thread]