user20311: I am developing a program that analyzes games sequentially, i.e. one game after another.
Below are the parameters.

Engine: Stockfish 10
Threads: 2
Hash Table: 4000
Depth: 30

My question is about when to use the command: "setoption name Clear Hash."
Should it be used after each position is analysed? This means that each position would have a "fresh" hash at the beginning of the analysis.
Or should it be used after each game is analysed? What are the differences?

user12873: A hash table is used to store evaluations/information for a position, so that evaluating it later is either instantaneous or much more efficient. If you let your engine think on a certain position for a while, the positions it thinks of when searching ahead are stored in its table. This is useful when you make a move on the current position and reach a new position for Stockfish to analyse (since its already "seen" it in its analysis).
So when analyzing a certain game, do not reset the hash table. You could reset it when moving on to a new game though, especially if the new game starts off with different opening moves than the previous game. This is because most/all of the positions analysed in the previous game will be irrelevant, and will just take up space in the hash table.

user-1: If you want to analyze a single game, IMHO the cleanest and best solution is to do that, as if stockfish would play a game against some other opponent, apart from the time control. Since this resembles the way, stockfish is tested and will always work.
Note that it is important to command
position startpos moves  .... 

and not
 position <fen>  

since the latter form messes up repetitions and the 50 move rule (UCI is stateless).
If you are unsure, simple let Arena or cutechess-cli play a single game for you with stockfish having logging enabled and then inspect the head of that logfile.

user15415: If your goal is to get the highest quality of analysis, then the short answer is "never".
The reason is that if you analyze similar positions within a game, then the existing hash table entries can still be valuable for move ordering and evaluation, because the same positions might be encountered somewhere in the search tree again.
If you switch to a new game, then the hash should be cleared, but in that case Stockfish already does it implicitly when it receives the ucinewgame command. In fact, in Stockfish ucinewgame does exactly the same as setoption name Clear Hash.

20311: <p>I am developing a program that analyzes games sequentially, i.e. one game after another.</p>

<p>Below are the parameters.</p>

<hr>

<p>Engine: Stockfish 10</p>

<p>Threads: 2</p>

<p>Hash Table: 4000</p>

<p>Depth: 30</p>

<hr>

<p>My question is about when to use the command: "setoption name Clear Hash."</p>

<p>Should it be used after each position is analysed? This means that each position would have a "fresh" hash at the beginning of the analysis.</p>

<p>Or should it be used after each game is analysed? What are the differences?</p>
 12873: <p>A hash table is used to store evaluations/information for a position, so that evaluating it later is either instantaneous or much more efficient. If you let your engine think on a certain position for a while, the positions it thinks of when searching ahead are stored in its table. This is useful when you make a move on the current position and reach a new position for Stockfish to analyse (since its already "seen" it in its analysis).</p>

<p>So when analyzing a certain game, do not reset the hash table. You could reset it when moving on to a new game though, especially if the new game starts off with different opening moves than the previous game. This is because most/all of the positions analysed in the previous game will be irrelevant, and will just take up space in the hash table.</p>
 -1: <p>If you want to analyze a single game, IMHO the cleanest and best solution is to do that, as if stockfish would play a game against some other opponent, apart from the time control. Since this resembles the way, stockfish is tested and will always work.
Note that it is important to command</p>
<pre><code>position startpos moves  .... 
</code></pre>
<p>and not</p>
<pre><code> position &lt;fen&gt;  
</code></pre>
<p>since the latter form messes up repetitions and the 50 move rule (UCI is stateless).
If you are unsure, simple let <a href="http://www.playwitharena.de/" rel="nofollow noreferrer">Arena</a> or <a href="https://github.com/cutechess/cutechess" rel="nofollow noreferrer">cutechess-cli</a> play a single game for you with stockfish having logging enabled and then inspect the head of that logfile.</p>
 15415: <p>If your goal is to get the highest quality of analysis, then the short answer is "never".</p>

<p>The reason is that if you analyze similar positions within a game, then the existing hash table entries can still be valuable for move ordering and evaluation, because the same positions might be encountered somewhere in the search tree again.</p>

<p>If you switch to a new game, then the hash should be cleared, but in that case Stockfish already does it implicitly when it receives the <code>ucinewgame</code> command. In fact, in Stockfish <a href="https://github.com/official-stockfish/Stockfish/blob/80d59eea392fc073f6d0ba29cb9a97e3d705ee58/src/uci.cpp#L229" rel="nofollow noreferrer"><code>ucinewgame</code></a> does exactly the same as <a href="https://github.com/official-stockfish/Stockfish/blob/80d59eea392fc073f6d0ba29cb9a97e3d705ee58/src/ucioption.cpp#L40" rel="nofollow noreferrer"><code>setoption name Clear Hash</code></a>.</p>
