Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: what classes all the serious C++ chess programs have?

Author: Gerd Isenberg

Date: 23:13:57 08/10/04

Go up one level in this thread


<snip>
>>>A colleague of mine proposed a way of getting rid of the indirection and the
>>>extra argument, without forcing you to use a single board. It is a little
>>>twisted, but interesting. You just make your engine a template class that gets a
>>>pointer to Board in the template:
>>>
>>>class Board {
>>>  //...
>>>};
>>>
>>>template <Board *b>
>>>class Engine {
>>>  //...use the board *b for everything.
>>>};
>>>
>>>Board my_board;
>>>Engine<&my_board> my_engine;
>>>
>>>Board my_other_board;
>>>Engine<&my_other_board> my_other_engine;
>>>
>>>This gives you performance that is as good as using a single global board, but
>>>you can have more than one board. Of course this duplicates all the code
>>>internally and your binary ends up being very large, but you can't get
>>>everything.
>>
>>Really nice, pointer as actual template parameters.
>>
>>What about some "board-sharing" (in a multi-threading environment)?
>>
>>Board my_board;
>>Engine<&my_board> my_engine;
>>Engine<&my_board> my_other_engine;
>>;-)
>
>Then you'll need to make sure that you are guarding the board (semaphores,
>mutexes, etc.)
>If we presume that the two engine instances are running in separate threads then
>the Board object should provide some locking mechanism.


Probably it is indeed smarter to use two "global" boards ;-)

Otherwise if two asynchronious search threads share the same board, even using
mutual exclusion while accessing it during make and unmake, the two seperate
makes and unmakes will ensure some very invalid positions after some time.

Hashtable is another matter of course.

Gerd

>
>I have noticed that a good SMP design is not directly mappable or even
>comparable to single threaded execution. Sometimes you need to rip the whole
>thing apart to get the performance you need. For instance switching the design
>to use message passing instead of direct memory sharing.
>
>Cheers,
>Hristo
>
>
>>
>>Gerd



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.