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
crafty/c++ question
Moderators: hgm, Rebel, chrisw
-
- Posts: 362
- Joined: Thu Mar 16, 2006 7:39 pm
- Location: Portugal
- Full name: Alvaro Cardoso
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: crafty/c++ question
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 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
-
- Posts: 362
- Joined: Thu Mar 16, 2006 7:39 pm
- Location: Portugal
- Full name: Alvaro Cardoso
One more thing
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
SHARED shared;
woudn't that work in the context of a parallel search?
Alvaro
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: One more thing
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()).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
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...