]> git.sesse.net Git - stockfish/commitdiff
Don't wake up threads at the beginning of the search
authorMarco Costalba <mcostalba@gmail.com>
Sun, 12 Feb 2012 13:07:21 +0000 (14:07 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 12 Feb 2012 13:17:12 +0000 (14:17 +0100)
But only when needed, after a split point. This behaviour
does not apply when useSleepingThreads is false, becuase
in this case threads are not woken up at split points so
must be already running.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/search.cpp
src/thread.cpp

index 8adbfd92ca240b418c09598f67847c2097a745d8..5706b959f2d9ffeb1e0a121a001a7a44c31b5c3b 100644 (file)
@@ -307,11 +307,7 @@ void Search::think() {
           << endl;
   }
 
           << endl;
   }
 
-  for (int i = 0; i < Threads.size(); i++)
-  {
-      Threads[i].maxPly = 0;
-      Threads[i].wake_up();
-  }
+  Threads.set_size(Options["Threads"]);
 
   // Set best timer interval to avoid lagging under time pressure. Timer is
   // used to check for remaining available thinking time.
 
   // Set best timer interval to avoid lagging under time pressure. Timer is
   // used to check for remaining available thinking time.
index 457a92780ced8cb17348516c2d8fc69e6b5b6334..3b87a72415ddd0fd3fc57ba345a55c3af78fbc97 100644 (file)
@@ -171,16 +171,14 @@ bool Thread::is_available_to(int master) const {
 }
 
 
 }
 
 
-// read_uci_options() updates number of active threads and other parameters
-// according to the UCI options values. It is called before to start a new search.
+// read_uci_options() updates internal threads parameters from the corresponding
+// UCI options. It is called before to start a new search.
 
 void ThreadsManager::read_uci_options() {
 
   maxThreadsPerSplitPoint = Options["Max Threads per Split Point"];
   minimumSplitDepth       = Options["Min Split Depth"] * ONE_PLY;
   useSleepingThreads      = Options["Use Sleeping Threads"];
 
 void ThreadsManager::read_uci_options() {
 
   maxThreadsPerSplitPoint = Options["Max Threads per Split Point"];
   minimumSplitDepth       = Options["Min Split Depth"] * ONE_PLY;
   useSleepingThreads      = Options["Use Sleeping Threads"];
-
-  set_size(Options["Threads"]);
 }
 
 
 }
 
 
@@ -189,11 +187,11 @@ void ThreadsManager::read_uci_options() {
 
 void ThreadsManager::set_size(int cnt) {
 
 
 void ThreadsManager::set_size(int cnt) {
 
-  assert(cnt > 0 && cnt <= MAX_THREADS);
+  assert(cnt > 0 && cnt < MAX_THREADS);
 
   activeThreads = cnt;
 
 
   activeThreads = cnt;
 
-  for (int i = 1; i < MAX_THREADS; i++) // Ignore main thread
+  for (int i = 0; i < MAX_THREADS; i++)
       if (i < activeThreads)
       {
           // Dynamically allocate pawn and material hash tables according to the
       if (i < activeThreads)
       {
           // Dynamically allocate pawn and material hash tables according to the
@@ -201,8 +199,12 @@ void ThreadsManager::set_size(int cnt) {
           // possible threads if only few are used.
           threads[i].pawnTable.init();
           threads[i].materialTable.init();
           // possible threads if only few are used.
           threads[i].pawnTable.init();
           threads[i].materialTable.init();
+          threads[i].maxPly = 0;
 
           threads[i].do_sleep = false;
 
           threads[i].do_sleep = false;
+
+          if (!useSleepingThreads)
+              threads[i].wake_up();
       }
       else
           threads[i].do_sleep = true;
       }
       else
           threads[i].do_sleep = true;