crafty/c++ question

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Cardoso
Posts: 362
Joined: Thu Mar 16, 2006 7:39 pm
Location: Portugal
Full name: Alvaro Cardoso

crafty/c++ question

Post by Cardoso »

Hi,
in trying to understand the parallel structure of crafty I notice the existence of a global structure called "shared".

in data.c we have
SHARED *shared;
in data.h we have
extern SHARED *shared;

but that is just a pointer and I'm sure sizeof(shared)=4 (or 8 in 64bit OS).

So where is the actual data? I couldn´t find the creation of that entity.
I saw InitializeSharedData() but that doesn't seem to be it.
Can someone help me?

best regards,
Alvaro
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: crafty/c++ question

Post by bob »

Cardoso wrote:Hi,
in trying to understand the parallel structure of crafty I notice the existence of a global structure called "shared".

in data.c we have
SHARED *shared;
in data.h we have
extern SHARED *shared;

but that is just a pointer and I'm sure sizeof(shared)=4 (or 8 in 64bit OS).

So where is the actual data? I couldn´t find the creation of that entity.
I saw InitializeSharedData() but that doesn't seem to be it.
Can someone help me?

best regards,
Alvaro
The actual data is created by a shmget() shared memory allocate. If you look at the structure definition for SHARED (in chess.h) you can see the values that are in this shared block of memory. In short, data in shared is data that can be modified as the game progresses, so it has to be shared so that all processes see the changes as they occur. In the case of Crafty, the original thread is the only one that will changed stuff in shared, but I want the other processes to see the changes.
Cardoso
Posts: 362
Joined: Thu Mar 16, 2006 7:39 pm
Location: Portugal
Full name: Alvaro Cardoso

One more thing

Post by Cardoso »

If instead of a pointer shared was declared as data of type SHARED:
SHARED shared;
woudn't that work in the context of a parallel search?

Alvaro
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: One more thing

Post by bob »

Cardoso wrote:If instead of a pointer shared was declared as data of type SHARED:
SHARED shared;
woudn't that work in the context of a parallel search?

Alvaro
No. There is no such thing as "implicit shared memory" when you use processes. Your only choice is to create a shared chunk of memory by one of several approaches. You can mmap() a file into memory, and create a shared block of memory the size of the file; you can use shmget()/shmat() (the system V shared memory approach that is included in all unix platforms just like mmap()).

But you have to create something that another process can somehow access, because fork() does not understand the concept of "this is private, that is shared" it just assumes everything is private. I chose shmget()/shmat() because it is simple, and some versions of linux had problems with mmap() a few years back. But there is no declaration that produces memory visible to other processes...