Stockfish hangs

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Stockfish hangs

Post by hgm »

Well, searching also takes a noticeable amount of time. We don't stop the clock for that either. When I was still playing Chess, and arrived at my club for the match at 8 p.m., I could also not say to the referee "Sorry, but I have prepared this great opening repertoire, but I don't know it by heart yet. I want to study my notes on it first, so please start my clock only 15 min from now!".
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Stockfish hangs

Post by Ras »

hgm wrote: Tue Jan 19, 2021 11:36 pmWhen I was still playing Chess, and arrived at my club for the match at 8 p.m., I could also not say to the referee "Sorry, but I have prepared this great opening repertoire, but I don't know it by heart yet. I want to study my notes on it first, so please start my clock only 15 min from now!".
Come on, that doesn't make sense. It's more like starting the clock for a multi game blitz match when the pieces aren't even set up in the starting position. It makes even less sense to use "reuse=0" here because UCI engines are meant to play several games. The only engines I've ever seen who can't even re-initialise themselves properly and thus need to be restarted are CECP engines.

All it achieves is making Winboard useless for matches in particular at fast time controls.
Rasmus Althoff
https://www.ct800.net
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Stockfish hangs

Post by hgm »

Playing multiple games with the same instance has no advantage at all when engines need large amounts of time to reinitialize after every ucinewgame.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Stockfish hangs

Post by Ras »

hgm wrote: Wed Jan 20, 2021 9:22 amPlaying multiple games with the same instance has no advantage at all when engines need large amounts of time to reinitialize after every ucinewgame.
I don't see why e.g. EGTBs would be reloaded for a new game - unless the GUI goes through the whole setoption yadda yadda process again, which would be a GUI misdesign.
Rasmus Althoff
https://www.ct800.net
Dann Corbit
Posts: 12538
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Stockfish hangs

Post by Dann Corbit »

hgm wrote: Tue Jan 19, 2021 2:17 pm Perhaps I should simply refrain from sending 'ucinewgame'? Since there was no earlier game, this seems to comply even with the newer specs.
I am not sure if they are compliant or not, but there are some engines that must have either the position setup or ucinewgame or they will not have the starting position initialized.
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.
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Stockfish hangs

Post by hgm »

Ras wrote: Wed Jan 20, 2021 11:10 amI don't see why e.g. EGTBs would be reloaded for a new game - unless the GUI goes through the whole setoption yadda yadda process again, which would be a GUI misdesign.
So why would they need significant time after ucinewgame, then? They can load the EGT before the readyok after the setoptions.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Stockfish hangs

Post by Ras »

hgm wrote: Wed Jan 20, 2021 9:36 pmSo why would they need significant time after ucinewgame, then?
I'm too lazy to look up SF's source. In my engine, I'm clearing history and hashtables. The latter can take a significant amount of time with large hashtables in relation to short time controls like one second per game without increment, which is the fastest my engine can do. That's why the subsequent "isready" will only be answered after that is done.

Though it's not yet even sure that the missing "isready" is actually the culprit. That would require a counter-test with "isready" and waiting for "readyok" to see whether the problem is gone.

It's also possible that the ponder toggle is a problem - maybe just leaving that out would make more sense to try first because it looks easier. Maybe toggling it that fast triggers some kind of race conditon in Stockfish.
Rasmus Althoff
https://www.ct800.net
Joerg Oster
Posts: 937
Joined: Fri Mar 10, 2006 4:29 pm
Location: Germany

Re: Stockfish hangs

Post by Joerg Oster »

Ras wrote: Wed Jan 20, 2021 10:11 pm
hgm wrote: Wed Jan 20, 2021 9:36 pmSo why would they need significant time after ucinewgame, then?
I'm too lazy to look up SF's source. In my engine, I'm clearing history and hashtables. The latter can take a significant amount of time with large hashtables in relation to short time controls like one second per game without increment, which is the fastest my engine can do. That's why the subsequent "isready" will only be answered after that is done.

Though it's not yet even sure that the missing "isready" is actually the culprit. That would require a counter-test with "isready" and waiting for "readyok" to see whether the problem is gone.

It's also possible that the ponder toggle is a problem - maybe just leaving that out would make more sense to try first because it looks easier. Maybe toggling it that fast triggers some kind of race conditon in Stockfish.
No, the missing isready is no problem, and also not the ponder toggle.

In Stockfish, after receiving a ucinewgame, not only the hash table gets cleared but also various thread-related stuff, mainly history tables.
Probably very similar to your engine.

Additionally, TBs get re-initialized to free up memory.

Code: Select all

  Tablebases::init(Options["SyzygyPath"]); // Free mapped files
I only vaguely remember reports by users having trouble because of low memory after many games.
You have to find and lookup the relevant issue/commit on GitHub.
Jörg Oster
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Stockfish hangs

Post by hgm »

Ras wrote: Wed Jan 20, 2021 10:11 pmIn my engine, I'm clearing history and hashtables. The latter can take a significant amount of time with large hashtables in relation to short time controls like one second per game without increment, which is the fastest my engine can do. That's why the subsequent "isready" will only be answered after that is done.
Clearing history should not take measurable time. Why clear the hash table? Usually there is a button Clear Hash for that. Doing unsollicited just wastes time, which will hurt in ultra-fast games. Would you also do it when you knew it came out of your own thinking time? If not, then this shows how counter-productive it is to not penalize such time wastage.

Btw, if don't want to reuse any of the hash entries from the previous game, you could just XOR your incremental key at the start of the game with some new pseudo-random. That would force a miss on everything that was there. You could of course still get collisions, but you can always get those, and they would not be more frequent that otherwise. And it takes virtually zero time.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Stockfish hangs

Post by Ras »

hgm wrote: Wed Jan 20, 2021 11:31 pmClearing history should not take measurable time.
Agree.
Why clear the hash table?
Because that makes sure that the engine is in the same state upon each new game. I like things to be reproducible because it makes troubleshooting easier or even possible.
Would you also do it when you knew it came out of your own thinking time?
I'm using the UCI protocol as specified for that purpose. Re-initialising the engine doesn't count against one's time - and even less so if you re-start it anyway. I don't care about broken GUIs do as long as they don't manage to crash my engine.
Btw, if don't want to reuse any of the hash entries from the previous game, you could just XOR your incremental key at the start of the game with some new pseudo-random.
I could, but why would I add more complexity to think about and test (i.e. whether it will really work), and sacrifice reproducibility for no reason?
Rasmus Althoff
https://www.ct800.net