Page 1 of 5

use sleeping threads

Posted: Wed Jul 10, 2013 8:31 pm
by Don
What does the option "use sleeping threads" in Stockfish mean? If I set Stockfish to use 4 threads does it mean it will try to use more than 4 threads if they are not being used by other processes?

Don

Re: use sleeping threads

Posted: Wed Jul 10, 2013 9:05 pm
by Joerg Oster
No.
Afaik, it means, threads without work should sleep and not keep spinning. See http://talkchess.com/forum/viewtopic.ph ... 14&t=37574

Re: use sleeping threads

Posted: Wed Jul 10, 2013 9:38 pm
by Graham Banks
Joerg Oster wrote:No.
Afaik, it means, threads without work should sleep and not keep spinning. See http://talkchess.com/forum/viewtopic.ph ... 14&t=37574
Confusing use of language.
Should be changed to Non-use of sleeping threads or something that more correctly indicates what is meant.

Re: use sleeping threads

Posted: Wed Jul 10, 2013 10:03 pm
by bob
I think we had this discussion a while back. The question is, when a thread has no work, what does it do? If you do a spin-wait, the instant the pointer to the work is updated, the thread can get to work with no delay. If you somehow block (whether it be waiting on a semaphore, a condition variable, or even a mutex) when work becomes available it takes time to wake the thread, get its context restored (registers, memory management stuff, etc) and actually start executing the thing, introducing a little "lag" between when work is available and the thread gets busy on that work.

I do busy spins in Crafty, period, since I know that the length of time between when a thread goes idle and it starts to help another thread is very short.

The only exception I make is at the end of an iteration when pondering is disabled. In normal mode, Crafty keeps the threads spinning waiting for work. Not good if you want to do an 8 core vs 8 core game, without pondering. There's an "smpnice" variable that can be set to 1 which tells it to terminate threads while waiting on an opponent's move.

I believe the stockfish option is backward in terminology. That is, if you prefer threads to sleep when not busy, you want that off... and vice-versa...

Re: use sleeping threads

Posted: Wed Jul 10, 2013 10:39 pm
by michiguel
Graham Banks wrote:
Joerg Oster wrote:No.
Afaik, it means, threads without work should sleep and not keep spinning. See http://talkchess.com/forum/viewtopic.ph ... 14&t=37574
Confusing use of language.
Should be changed to Non-use of sleeping threads or something that more correctly indicates what is meant.
I do not think it is confusing, but to have a very straightforward dialog,
I would suggest a UCI variable "threads wait" = sleeping/spinning

Miguel

Re: use sleeping threads

Posted: Wed Jul 10, 2013 11:32 pm
by zullil
Don wrote:What does the option "use sleeping threads" in Stockfish mean? If I set Stockfish to use 4 threads does it mean it will try to use more than 4 threads if they are not being used by other processes?

Don
Whatever it means, apparently the default choice is Use Sleeping Threads = true.

Code: Select all

/// init() initializes the UCI options to their hard coded default values
/// and initializes the default value of "Threads" and "Min Split Depth"
/// parameters according to the number of CPU cores detected.

void init(OptionsMap& o) {

  int cpus = std::min(cpu_count(), MAX_THREADS);
  int msd = cpus < 8 ? 4 &#58; 7;

  o&#91;"Use Debug Log"&#93;               = Option&#40;false, on_logger&#41;;
  o&#91;"Use Search Log"&#93;              = Option&#40;false&#41;;
  o&#91;"Search Log Filename"&#93;         = Option&#40;"SearchLog.txt");
  o&#91;"Book File"&#93;                   = Option&#40;"book.bin");
  o&#91;"Best Book Move"&#93;              = Option&#40;false&#41;;
  o&#91;"Contempt Factor"&#93;             = Option&#40;0, -50,  50&#41;;
  o&#91;"Mobility &#40;Midgame&#41;"&#93;          = Option&#40;100, 0, 200, on_eval&#41;;
  o&#91;"Mobility &#40;Endgame&#41;"&#93;          = Option&#40;100, 0, 200, on_eval&#41;;
  o&#91;"Pawn Structure &#40;Midgame&#41;"&#93;    = Option&#40;100, 0, 200, on_eval&#41;;
  o&#91;"Pawn Structure &#40;Endgame&#41;"&#93;    = Option&#40;100, 0, 200, on_eval&#41;;
  o&#91;"Passed Pawns &#40;Midgame&#41;"&#93;      = Option&#40;100, 0, 200, on_eval&#41;;
  o&#91;"Passed Pawns &#40;Endgame&#41;"&#93;      = Option&#40;100, 0, 200, on_eval&#41;;
  o&#91;"Space"&#93;                       = Option&#40;100, 0, 200, on_eval&#41;;
  o&#91;"Aggressiveness"&#93;              = Option&#40;100, 0, 200, on_eval&#41;;
  o&#91;"Cowardice"&#93;                   = Option&#40;100, 0, 200, on_eval&#41;;
  o&#91;"Min Split Depth"&#93;             = Option&#40;msd, 4, 12, on_threads&#41;;
  o&#91;"Max Threads per Split Point"&#93; = Option&#40;5, 4, 8, on_threads&#41;;
  o&#91;"Threads"&#93;                     = Option&#40;cpus, 1, MAX_THREADS, on_threads&#41;;
  o&#91;"Use Sleeping Threads"&#93;        = Option&#40;true&#41;;
See https://github.com/mcostalba/Stockfish/ ... option.cpp

Re: use sleeping threads

Posted: Wed Jul 10, 2013 11:40 pm
by gladius
zullil wrote:
Don wrote:What does the option "use sleeping threads" in Stockfish mean? If I set Stockfish to use 4 threads does it mean it will try to use more than 4 threads if they are not being used by other processes?

Don
Whatever it means, apparently the default choice is Use Sleeping Threads = true.
This is only true for development versions of SF. For release versions, it is set to false by default. This commit did that for SF3 https://github.com/mcostalba/Stockfish/ ... de3dfe22be

Re: use sleeping threads?

Posted: Wed Jul 10, 2013 11:55 pm
by carldaman
gladius wrote:
zullil wrote:
Don wrote:What does the option "use sleeping threads" in Stockfish mean? If I set Stockfish to use 4 threads does it mean it will try to use more than 4 threads if they are not being used by other processes?

Don
Whatever it means, apparently the default choice is Use Sleeping Threads = true.
This is only true for development versions of SF. For release versions, it is set to false by default. This commit did that for SF3 https://github.com/mcostalba/Stockfish/ ... de3dfe22be
So then which setting should we use? Is there any guideline?
If testing a newer developmental version, should we leave the default setting alone (=true), even though Stockfish v3 has it the other way around (=false)?

Thanks,
CL

Re: use sleeping threads?

Posted: Thu Jul 11, 2013 12:53 am
by bob
carldaman wrote:
gladius wrote:
zullil wrote:
Don wrote:What does the option "use sleeping threads" in Stockfish mean? If I set Stockfish to use 4 threads does it mean it will try to use more than 4 threads if they are not being used by other processes?

Don
Whatever it means, apparently the default choice is Use Sleeping Threads = true.
This is only true for development versions of SF. For release versions, it is set to false by default. This commit did that for SF3 https://github.com/mcostalba/Stockfish/ ... de3dfe22be
So then which setting should we use? Is there any guideline?
If testing a newer developmental version, should we leave the default setting alone (=true), even though Stockfish v3 has it the other way around (=false)?

Thanks,
CL
Unless Marco says otherwise, I believe you want it "false". It sounds like a good idea (use sleeping threads) but I believe he stated that the term doesn't really mean what it says (he is not a native English speaker)...

Re: use sleeping threads?

Posted: Thu Jul 11, 2013 12:55 am
by Don
carldaman wrote:
gladius wrote:
zullil wrote:
Don wrote:What does the option "use sleeping threads" in Stockfish mean? If I set Stockfish to use 4 threads does it mean it will try to use more than 4 threads if they are not being used by other processes?

Don
Whatever it means, apparently the default choice is Use Sleeping Threads = true.
This is only true for development versions of SF. For release versions, it is set to false by default. This commit did that for SF3 https://github.com/mcostalba/Stockfish/ ... de3dfe22be
So then which setting should we use? Is there any guideline?
If testing a newer developmental version, should we leave the default setting alone (=true), even though Stockfish v3 has it the other way around (=false)?

Thanks,
CL

If you don't use all your threads it should be a minor benefit to the other programs using the same machine. So for competition testing on the same machine the fairest thing to do is to use all the resources that are rightfully yours, even if they are not of much benefit to you. Here is why:

Even though the ideal with modern processors is for them to act completely independent, the reality is that this is not the case. If you let some processors go idle it will benefit (at least slightly) other processes. I don't know if that is a big deal or not but the issue does exist.