Author: Robert Hyatt
Date: 10:20:50 09/10/03
Go up one level in this thread
On September 10, 2003 at 12:38:17, Steven Edwards wrote:
>Some programs like Crafty currently use a node count check to determine if a
>time check or interface check is needed. The code in Crafty looks like:
>
> tree->nodes_searched++;
> if (--next_time_check <= 0) {
> next_time_check=nodes_between_time_checks;
> if (tree->thread_id==0 && CheckInput()) Interrupt(ply);
> if (TimeCheck(tree,0)) {
> time_abort++;
> abort_search=1;
> return(0);
> }
>
>Now, the above works, but its behavior is dependent on the node search rate, and
>this is going to be different from machine to machine. The code may do time
>checks more often than needed (a loss of efficiency) or it may do too few (a
>loss of responsiveness).
You should look at the code more carefully...
Crafty dynamically computes "nodes_between_time_checks" so that it is a
bigger number on faster machines, smaller on slower machines. I set it so
that I check every "reasonable" unit of time. For normal time controls, say
40 moves in 2 hours, I check no more than once per second. For bullet (game
in 1 minute) I check much more frequently.
:)
That's a known issue...
>
>A better approach is to use a separate thread to wait efficiently for a constant
>time interval.
>
>At the start of the search, the program starts a separate thread and passes it a
>pointer to a timeout variable and a pointer to an exit flag. The timeout
>variable is just an integer which has a zero value (meaning that the timer
>interval has not expired) or a nonzero value (the interval has expired). The
>exit flag pointer is used to tell the thread when to exit. The thread code for
>a 1/10th second interval looks like:
>
>void Time100ms(int *theTimeOutPtr, int *theExitFlagPtr)
>{
> *theTimeOutPtr = 0; *theExitFlagPtr = 0;
> while (!*theExitFlagPtr)
> {
> usleep(100 * 1000);
> *theTimeOutPtr = 1;
> };
>}
>
>At each search node, the code looks like
>
>if (*theTimeOutPtr)
>{
> *theTimeOutPtr = 0;
>
> /* do various time check related processing */
>};
>
>At the conclusion of the search, the code does
>
> *theExitFlagPtr = 1;
>
>followed by thread clean up with pthread_join() or whatever.
That works ok. The overhead for scheduling a thread every N units of time is
a bit of a pain. I totally avoid that in Crafty without testing too frequently
or too infrequently.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.