]> git.sesse.net Git - stockfish/commitdiff
Do not copy master position in split()
authorMarco Costalba <mcostalba@gmail.com>
Mon, 25 Jan 2010 11:44:30 +0000 (12:44 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 25 Jan 2010 11:46:08 +0000 (12:46 +0100)
A pointer is enough because after a split point has been
setup master and slaves thread end up calling sp_search() or
sp_search_pv() and here a full copy of split point position is
done again, note that even master does another copy (of itself)
and this is done before any do_move() call so that master Position
is never updated between split() and sp_search().

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

index e7dc3a802fca35ae821517815650dfb692db7eef..c4dbfcf6bef163aac51ab3b6a40bce43decb261d 100644 (file)
@@ -147,8 +147,8 @@ public:
 
   // Constructors
   Position();
 
   // Constructors
   Position();
-  Position(const Position& pos);
-  Position(const std::string& fen);
+  explicit Position(const Position& pos);
+  explicit Position(const std::string& fen);
 
   // Text input/output
   void from_fen(const std::string& fen);
 
   // Text input/output
   void from_fen(const std::string& fen);
index 2244a2f7da805599ea07d260134c52e2ee3e6b16..1c2715615ed6cc0424a8e68e18b00390442a632e 100644 (file)
@@ -1813,8 +1813,7 @@ namespace {
     assert(threadID >= 0 && threadID < ActiveThreads);
     assert(ActiveThreads > 1);
 
     assert(threadID >= 0 && threadID < ActiveThreads);
     assert(ActiveThreads > 1);
 
-    Position pos;
-    pos.fast_copy(sp->pos);
+    Position pos(*sp->pos);
     CheckInfo ci(pos);
     SearchStack* ss = sp->sstack[threadID];
     Value value = -VALUE_INFINITE;
     CheckInfo ci(pos);
     SearchStack* ss = sp->sstack[threadID];
     Value value = -VALUE_INFINITE;
@@ -1956,8 +1955,7 @@ namespace {
     assert(threadID >= 0 && threadID < ActiveThreads);
     assert(ActiveThreads > 1);
 
     assert(threadID >= 0 && threadID < ActiveThreads);
     assert(ActiveThreads > 1);
 
-    Position pos;
-    pos.fast_copy(sp->pos);
+    Position pos(*sp->pos);
     CheckInfo ci(pos);
     SearchStack* ss = sp->sstack[threadID];
     Value value = -VALUE_INFINITE;
     CheckInfo ci(pos);
     SearchStack* ss = sp->sstack[threadID];
     Value value = -VALUE_INFINITE;
@@ -2969,7 +2967,7 @@ namespace {
     splitPoint = SplitPointStack[master] + Threads[master].activeSplitPoints;
     Threads[master].activeSplitPoints++;
 
     splitPoint = SplitPointStack[master] + Threads[master].activeSplitPoints;
     Threads[master].activeSplitPoints++;
 
-    // Initialize the split point object and copy current position
+    // Initialize the split point object
     splitPoint->parent = Threads[master].splitPoint;
     splitPoint->finished = false;
     splitPoint->ply = ply;
     splitPoint->parent = Threads[master].splitPoint;
     splitPoint->finished = false;
     splitPoint->ply = ply;
@@ -2983,14 +2981,11 @@ namespace {
     splitPoint->mp = mp;
     splitPoint->moves = *moves;
     splitPoint->cpus = 1;
     splitPoint->mp = mp;
     splitPoint->moves = *moves;
     splitPoint->cpus = 1;
-    splitPoint->pos.fast_copy(p);
+    splitPoint->pos = &p;
     splitPoint->parentSstack = sstck;
     for (i = 0; i < ActiveThreads; i++)
         splitPoint->slaves[i] = 0;
 
     splitPoint->parentSstack = sstck;
     for (i = 0; i < ActiveThreads; i++)
         splitPoint->slaves[i] = 0;
 
-    // Detach splitPoint Position from the master one
-    splitPoint->pos.detach();
-
     // Copy the tail of current search stack to the master thread
     memcpy(splitPoint->sstack[master] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack));
     Threads[master].splitPoint = splitPoint;
     // Copy the tail of current search stack to the master thread
     memcpy(splitPoint->sstack[master] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack));
     Threads[master].splitPoint = splitPoint;
index 2ac968131c0ad98fbb47db5b404562d90ad5a43e..d12ec845c01f4bc4a288bd6bfe076b8652ca9b5b 100644 (file)
@@ -46,7 +46,7 @@ const int ACTIVE_SPLIT_POINTS_MAX = 8;
 
 struct SplitPoint {
   SplitPoint *parent;
 
 struct SplitPoint {
   SplitPoint *parent;
-  Position pos;
+  const Position* pos;
   SearchStack sstack[THREAD_MAX][PLY_MAX_PLUS_2];
   SearchStack *parentSstack;
   int ply;
   SearchStack sstack[THREAD_MAX][PLY_MAX_PLUS_2];
   SearchStack *parentSstack;
   int ply;
index 21bbb88472d4ce55b1fb5e56eba372a333e074c7..3812a3792c17d068cdb0bccd575e2a3922088f34 100644 (file)
@@ -314,7 +314,7 @@ namespace {
 
     string token;
     int depth, tm, n;
 
     string token;
     int depth, tm, n;
-    Position pos = RootPosition;
+    Position pos(RootPosition);
 
     if (!(uip >> depth))
         return;
 
     if (!(uip >> depth))
         return;