Rev 169 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 169 | Rev 185 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad |
4 | Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad |
5 | Copyright (C) 2015- |
5 | Copyright (C) 2015-2019 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad |
6 | 6 | ||
7 | Stockfish is free software: you can redistribute it and/or modify |
7 | Stockfish is free software: you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation, either version 3 of the License, or |
9 | the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. |
10 | (at your option) any later version. |
Line 24... | Line 24... | ||
24 | #include "movegen.h" |
24 | #include "movegen.h" |
25 | #include "search.h" |
25 | #include "search.h" |
26 | #include "thread.h" |
26 | #include "thread.h" |
27 | #include "uci.h" |
27 | #include "uci.h" |
28 | #include "syzygy/tbprobe.h" |
28 | #include "syzygy/tbprobe.h" |
- | 29 | #include "tt.h" |
|
29 | 30 | ||
30 | ThreadPool Threads; // Global object |
31 | ThreadPool Threads; // Global object |
31 | 32 | ||
32 | 33 | ||
33 | /// Thread constructor launches the thread and waits until it goes to sleep |
34 | /// Thread constructor launches the thread and waits until it goes to sleep |
Line 58... | Line 59... | ||
58 | 59 | ||
59 | counterMoves.fill(MOVE_NONE); |
60 | counterMoves.fill(MOVE_NONE); |
60 | mainHistory.fill(0); |
61 | mainHistory.fill(0); |
61 | captureHistory.fill(0); |
62 | captureHistory.fill(0); |
62 | 63 | ||
63 | for (auto& to : |
64 | for (auto& to : continuationHistory) |
64 | for (auto& h : to) |
65 | for (auto& h : to) |
65 | h |
66 | h->fill(0); |
66 | 67 | ||
67 |
|
68 | continuationHistory[NO_PIECE][0]->fill(Search::CounterMovePruneThreshold - 1); |
68 | } |
69 | } |
69 | 70 | ||
70 | /// Thread::start_searching() wakes up the thread that will start the search |
71 | /// Thread::start_searching() wakes up the thread that will start the search |
71 | 72 | ||
72 | void Thread::start_searching() { |
73 | void Thread::start_searching() { |
Line 95... | Line 96... | ||
95 | // If OS already scheduled us on a different group than 0 then don't overwrite |
96 | // If OS already scheduled us on a different group than 0 then don't overwrite |
96 | // the choice, eventually we are one of many one-threaded processes running on |
97 | // the choice, eventually we are one of many one-threaded processes running on |
97 | // some Windows NUMA hardware, for instance in fishtest. To make it simple, |
98 | // some Windows NUMA hardware, for instance in fishtest. To make it simple, |
98 | // just check if running threads are below a threshold, in this case all this |
99 | // just check if running threads are below a threshold, in this case all this |
99 | // NUMA machinery is not needed. |
100 | // NUMA machinery is not needed. |
100 | if (Options["Threads"] > |
101 | if (Options["Threads"] > 8) |
101 | WinProcGroup::bindThisThread(idx); |
102 | WinProcGroup::bindThisThread(idx); |
102 | 103 | ||
103 | while (true) |
104 | while (true) |
104 | { |
105 | { |
105 | std::unique_lock<Mutex> lk(mutex); |
106 | std::unique_lock<Mutex> lk(mutex); |
Line 115... | Line 116... | ||
115 | search(); |
116 | search(); |
116 | } |
117 | } |
117 | } |
118 | } |
118 | 119 | ||
119 | /// ThreadPool::set() creates/destroys threads to match the requested number. |
120 | /// ThreadPool::set() creates/destroys threads to match the requested number. |
120 | /// Created and |
121 | /// Created and launched threads will go immediately to sleep in idle_loop. |
121 | /// Upon resizing, threads are recreated to allow for binding if necessary. |
122 | /// Upon resizing, threads are recreated to allow for binding if necessary. |
122 | 123 | ||
123 | void ThreadPool::set(size_t requested) { |
124 | void ThreadPool::set(size_t requested) { |
124 | 125 | ||
125 | if (size() > 0) { // destroy any existing thread(s) |
126 | if (size() > 0) { // destroy any existing thread(s) |
Line 134... | Line 135... | ||
134 | 135 | ||
135 | while (size() < requested) |
136 | while (size() < requested) |
136 | push_back(new Thread(size())); |
137 | push_back(new Thread(size())); |
137 | clear(); |
138 | clear(); |
138 | } |
139 | } |
- | 140 | ||
- | 141 | // Reallocate the hash with the new threadpool size |
|
- | 142 | TT.resize(Options["Hash"]); |
|
139 | } |
143 | } |
140 | 144 | ||
141 | /// ThreadPool::clear() sets threadPool data to initial values. |
145 | /// ThreadPool::clear() sets threadPool data to initial values. |
142 | 146 | ||
143 | void ThreadPool::clear() { |
147 | void ThreadPool::clear() { |
Line 145... | Line 149... | ||
145 | for (Thread* th : *this) |
149 | for (Thread* th : *this) |
146 | th->clear(); |
150 | th->clear(); |
147 | 151 | ||
148 | main()->callsCnt = 0; |
152 | main()->callsCnt = 0; |
149 | main()->previousScore = VALUE_INFINITE; |
153 | main()->previousScore = VALUE_INFINITE; |
150 | main()->previousTimeReduction = |
154 | main()->previousTimeReduction = 1.0; |
151 | } |
155 | } |
152 | 156 | ||
153 | /// ThreadPool::start_thinking() wakes up main thread waiting in idle_loop() and |
157 | /// ThreadPool::start_thinking() wakes up main thread waiting in idle_loop() and |
154 | /// returns immediately. Main thread will wake up other threads and start the search. |
158 | /// returns immediately. Main thread will wake up other threads and start the search. |
155 | 159 | ||
Line 167... | Line 171... | ||
167 | if ( limits.searchmoves.empty() |
171 | if ( limits.searchmoves.empty() |
168 | || std::count(limits.searchmoves.begin(), limits.searchmoves.end(), m)) |
172 | || std::count(limits.searchmoves.begin(), limits.searchmoves.end(), m)) |
169 | rootMoves.emplace_back(m); |
173 | rootMoves.emplace_back(m); |
170 | 174 | ||
171 | if (!rootMoves.empty()) |
175 | if (!rootMoves.empty()) |
172 | Tablebases:: |
176 | Tablebases::rank_root_moves(pos, rootMoves); |
173 | 177 | ||
174 | // After ownership transfer 'states' becomes empty, so if we stop the search |
178 | // After ownership transfer 'states' becomes empty, so if we stop the search |
175 | // and call 'go' again without setting a new position states.get() == NULL. |
179 | // and call 'go' again without setting a new position states.get() == NULL. |
176 | assert(states.get() || setupStates.get()); |
180 | assert(states.get() || setupStates.get()); |
177 | 181 | ||
Line 185... | Line 189... | ||
185 | // is shared by threads but is accessed in read-only mode. |
189 | // is shared by threads but is accessed in read-only mode. |
186 | StateInfo tmp = setupStates->back(); |
190 | StateInfo tmp = setupStates->back(); |
187 | 191 | ||
188 | for (Thread* th : *this) |
192 | for (Thread* th : *this) |
189 | { |
193 | { |
190 | th->nodes = th->tbHits = th-> |
194 | th->nodes = th->tbHits = th->nmpMinPly = 0; |
191 | th->rootDepth = th->completedDepth = DEPTH_ZERO; |
195 | th->rootDepth = th->completedDepth = DEPTH_ZERO; |
192 | th->rootMoves = rootMoves; |
196 | th->rootMoves = rootMoves; |
193 | th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th); |
197 | th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th); |
194 | } |
198 | } |
195 | 199 |