Thread management / organization in parallel processing?

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
User avatar
phhnguyen
Posts: 802
Joined: Wed Apr 21, 2010 2:58 am
Location: Australia
Full name: Nguyen Hong Pham
Contact:

Thread management / organization in parallel processing?

Post by phhnguyen » Mon Dec 06, 2010 12:36 pm

Hi all,

I have been redesigning my program and now working on thread management. Just some basic questions which need your suggestions:

Suppose my computer has n processors (cores) and I always need to create one thread for common tasks such as listening keyboard and starting / controlling other threads:

1) How many threads should I create for move computing? n or (n-1) or smaller?

2) How to communicate between computing threads and common task thread?

From common task thread, I can start / stop / give tasks computing threads (by setting up task then wake them up) - I am not worry much about those code.

However, after completing computing, my computing threads have to do the move by calling functions to modify directly the main data structure (store as global data or in common task thread) - that point I want to improve.

Is there any ways less "dirty" to do that? (say, the main data structure should be maintained by one thread only)?

3) How to implement self play function which helps program to play both sides until the end (without using any other program)? (I don't want recursive calling - too many)

(I know that I can solve 2 above problems by implementing something similar to event system but still worry about performance (it may require other "hard working thread" to maintain event only) and wonder if there is any other solution).

Thanks a lot for any idea / suggestion

bob
Posts: 20916
Joined: Mon Feb 27, 2006 6:30 pm
Location: Birmingham, AL

Re: Thread management / organization in parallel processing?

Post by bob » Mon Dec 06, 2010 4:19 pm

phhnguyen wrote:Hi all,

I have been redesigning my program and now working on thread management. Just some basic questions which need your suggestions:

Suppose my computer has n processors (cores) and I always need to create one thread for common tasks such as listening keyboard and starting / controlling other threads:

1) How many threads should I create for move computing? n or (n-1) or smaller?
The "general" correct answer is N. The extra thread does nothing almost 100% of the time. But, as always, the answer will depend on your implementation.

2) How to communicate between computing threads and common task thread?

From common task thread, I can start / stop / give tasks computing threads (by setting up task then wake them up) - I am not worry much about those code.

However, after completing computing, my computing threads have to do the move by calling functions to modify directly the main data structure (store as global data or in common task thread) - that point I want to improve.

Is there any ways less "dirty" to do that? (say, the main data structure should be maintained by one thread only)?
The most generic way is to use a global variable for each thread. If you want a thread to exit, or stop searching, or whatever, set this variable to the correct value. The thread can check this once per node with zero penalty since it will be cached.
3) How to implement self play function which helps program to play both sides until the end (without using any other program)? (I don't want recursive calling - too many)

(I know that I can solve 2 above problems by implementing something similar to event system but still worry about performance (it may require other "hard working thread" to maintain event only) and wonder if there is any other solution).

Thanks a lot for any idea / suggestion
I don't do that, even in Crafty. Should I want to do this, I would use xboard and just play two instances of Crafty against each other. That lets me continue to ponder and such.

Post Reply