SMP, game struct, thread struct and MakeMove
Moderators: hgm, Rebel, chrisw
-
- Posts: 3196
- Joined: Fri May 26, 2006 3:00 am
- Location: WY, USA
- Full name: Michael Sherwin
SMP, game struct, thread struct and MakeMove
In my single thread engine I chose to have a single struct for both the game history and the search history. That seems wasteful for a multithreaded engine. So in my new multithreaded engine I have a game history and multiple search histories. So, do I also have to have two make move functions?
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
-
- Posts: 12542
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: SMP, game struct, thread struct and MakeMove
If your functions are re-entrant, you should not need more than one.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
-
- Posts: 3196
- Joined: Fri May 26, 2006 3:00 am
- Location: WY, USA
- Full name: Michael Sherwin
Re: SMP, game struct, thread struct and MakeMove
Sorry Dann, I do not know what a re-entrant function means.Dann Corbit wrote: ↑Fri Apr 19, 2019 2:49 am If your functions are re-entrant, you should not need more than one.
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
-
- Posts: 12542
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: SMP, game struct, thread struct and MakeMove
There are functions that carry state from the caller and rely on that behavior or that keep an internal object and return a pointer to it or things of that nature. An example is strtok() for parsing strings. The strtok() function is not re-entrant, but strtok_r() is re-entrant.Michael Sherwin wrote: ↑Fri Apr 19, 2019 3:02 amSorry Dann, I do not know what a re-entrant function means.Dann Corbit wrote: ↑Fri Apr 19, 2019 2:49 am If your functions are re-entrant, you should not need more than one.
If all the variables in your function are auto variables (no static or global variables in use) and the function is stateless (does not need to memorize something from the previous call) then as many threads as you want can call it simultaneously without collision
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
-
- Posts: 3196
- Joined: Fri May 26, 2006 3:00 am
- Location: WY, USA
- Full name: Michael Sherwin
Re: SMP, game struct, thread struct and MakeMove
Thank you Dann, But that was not my question. Do I need a separate Make Move for the game history record? I understand about thread safety for the search histories. Or maybe I should only use search histories and start every search at game ply. It's okay I'll figure it out.Dann Corbit wrote: ↑Fri Apr 19, 2019 7:31 amThere are functions that carry state from the caller and rely on that behavior or that keep an internal object and return a pointer to it or things of that nature. An example is strtok() for parsing strings. The strtok() function is not re-entrant, but strtok_r() is re-entrant.Michael Sherwin wrote: ↑Fri Apr 19, 2019 3:02 amSorry Dann, I do not know what a re-entrant function means.Dann Corbit wrote: ↑Fri Apr 19, 2019 2:49 am If your functions are re-entrant, you should not need more than one.
If all the variables in your function are auto variables (no static or global variables in use) and the function is stateless (does not need to memorize something from the previous call) then as many threads as you want can call it simultaneously without collision
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: SMP, game struct, thread struct and MakeMove
In Jumbo the game history is simply part of the Board object (so "Board" is more like "Game with current position and history"). The small memory overhead is negligible but the gain of simplicity is significant in my view. Each search thread, as well as the game-playing part of the engine (ChessPlayer), has its own copy of the Board and therefore of the game history. And making a move during search is also a change of the game history - the reason is that I mainly use the game history for two purposes during search: 1) repetition check, 2) access to the last and possibly next-to-last move (e.g. for null move or counter move). So I do not need two different makeMove() functions. Whether you would need it might depend on your data structures.Michael Sherwin wrote: ↑Fri Apr 19, 2019 3:27 pm Do I need a separate Make Move for the game history record?
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
-
- Posts: 3196
- Joined: Fri May 26, 2006 3:00 am
- Location: WY, USA
- Full name: Michael Sherwin
Re: SMP, game struct, thread struct and MakeMove
Thanks Sven! You do what I do in RomiChess for just one thread. So if you say that the additional memory to include the game history in every thread is negligible then I'll do the same.Sven wrote: ↑Sat Apr 20, 2019 10:37 pmIn Jumbo the game history is simply part of the Board object (so "Board" is more like "Game with current position and history"). The small memory overhead is negligible but the gain of simplicity is significant in my view. Each search thread, as well as the game-playing part of the engine (ChessPlayer), has its own copy of the Board and therefore of the game history. And making a move during search is also a change of the game history - the reason is that I mainly use the game history for two purposes during search: 1) repetition check, 2) access to the last and possibly next-to-last move (e.g. for null move or counter move). So I do not need two different makeMove() functions. Whether you would need it might depend on your data structures.Michael Sherwin wrote: ↑Fri Apr 19, 2019 3:27 pm Do I need a separate Make Move for the game history record?
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
-
- Posts: 3196
- Joined: Fri May 26, 2006 3:00 am
- Location: WY, USA
- Full name: Michael Sherwin
Re: SMP, game struct, thread struct and MakeMove
Turns out that I accidently did it another way. From my move list array, just for debugging, I made the move directly from there and unmade the move from there. So in the search no moves are stored in history. I forgot I had done it that way so my entered moves from the command line would not work. I had to make a game history first. And it seems to be working just fine. Sometimes it pays to have a terrible memory, lol.
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through