]> git.sesse.net Git - stockfish/commitdiff
Refactor ThreadsManager::set_size() functionality
authorMarco Costalba <mcostalba@gmail.com>
Sat, 24 Mar 2012 18:29:12 +0000 (19:29 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 25 Mar 2012 09:23:49 +0000 (10:23 +0100)
Split the data allocation, now done (mostly once)
in read_uci_options(), from the wake up and sleeping
of the slave threads upon entering/exiting the search.

No functional change.

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

index fb5d375e8e591a58a91fb0e9afe8a147846b426c..cc82af7dbf1a88959316b2c8dd3c025f6cf78227 100644 (file)
@@ -298,7 +298,7 @@ void Search::think() {
           << endl;
   }
 
-  Threads.set_size(Options["Threads"]);
+  Threads.wake_up();
 
   // Set best timer interval to avoid lagging under time pressure. Timer is
   // used to check for remaining available thinking time.
@@ -312,7 +312,7 @@ void Search::think() {
 
   // Stop timer and send all the slaves to sleep, if not already sleeping
   Threads.set_timer(0);
-  Threads.set_size(1);
+  Threads.sleep();
 
   if (Options["Use Search Log"])
   {
index 5c23aa50373618f80a5f2b0a004cac5211548b90..1913aee43ca62601a68000392cad4e844c779fb0 100644 (file)
@@ -173,35 +173,35 @@ 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() changes the number of active threads and raises do_sleep flag for
-// all the unused threads that will go immediately to sleep.
-
-void ThreadsManager::set_size(int cnt) {
-
-  assert(cnt > 0 && cnt < MAX_THREADS);
-
-  activeThreads = cnt;
+  activeThreads           = Options["Threads"];
 
+  // Dynamically allocate pawn and material hash tables according to the
+  // number of active threads. This avoids preallocating memory for all
+  // possible threads if only few are used.
   for (int i = 0; i < MAX_THREADS; i++)
       if (i < activeThreads)
       {
-          // Dynamically allocate pawn and material hash tables according to the
-          // number of active threads. This avoids preallocating memory for all
-          // possible threads if only few are used.
           threads[i].pawnTable.init();
           threads[i].materialTable.init();
           threads[i].maxPly = 0;
+      }
+}
 
-          threads[i].do_sleep = false;
 
-          if (!useSleepingThreads)
-              threads[i].wake_up();
-      }
-      else
-          threads[i].do_sleep = true;
+void ThreadsManager::wake_up() {
+
+  for (int i = 0; i < activeThreads; i++)
+  {
+      threads[i].do_sleep = false;
+      threads[i].wake_up();
+  }
+}
+
+
+void ThreadsManager::sleep() {
+
+  for (int i = 0; i < activeThreads; i++)
+      threads[i].do_sleep = true;
 }
 
 
index e71db835734d7bd2bc146b0cf71332e0d9b6ca61..6f231363e7e5de837afe89e67f73c947c58ce192 100644 (file)
@@ -108,7 +108,8 @@ public:
   int min_split_depth() const { return minimumSplitDepth; }
   int size() const { return activeThreads; }
 
-  void set_size(int cnt);
+  void wake_up();
+  void sleep();
   void read_uci_options();
   bool available_slave_exists(int master) const;
   void set_timer(int msec);
index df73670b23d090df0922b25604fd2b16c226100b..4be580fcbfaf0760974300e02871580549577686 100644 (file)
@@ -73,7 +73,7 @@ OptionsMap::OptionsMap() {
   o["Cowardice"]                   = UCIOption(100, 0, 200, on_eval);
   o["Min Split Depth"]             = UCIOption(msd, 4, 7, on_threads);
   o["Max Threads per Split Point"] = UCIOption(5, 4, 8, on_threads);
-  o["Threads"]                     = UCIOption(cpus, 1, MAX_THREADS);
+  o["Threads"]                     = UCIOption(cpus, 1, MAX_THREADS, on_threads);
   o["Use Sleeping Threads"]        = UCIOption(true, on_threads);
   o["Hash"]                        = UCIOption(32, 4, 8192, on_hash_size);
   o["Clear Hash"]                  = UCIOption(on_clear_hash);