Line data Source code
1 : #pragma once
2 :
3 : #include "definition.hpp"
4 : #include "position.hpp"
5 : #include "stats.hpp"
6 :
7 : struct Searcher; // forward decl
8 :
9 : struct SearchData {
10 481 : SearchData() {
11 : scores.fill(0);
12 : moves.fill(INVALIDMINIMOVE);
13 : nodes.fill(0ull);
14 : times.fill(0ull);
15 481 : }
16 : array1d<ScoreType, MAX_DEPTH> scores;
17 : array1d<MiniMove, MAX_DEPTH> moves;
18 : array1d<Counter, MAX_DEPTH> nodes;
19 : array1d<TimeType, MAX_DEPTH> times;
20 : };
21 :
22 : // an little input/output structure for each thread
23 481 : struct ThreadData {
24 : DepthType depth = MAX_DEPTH, seldepth = 0;
25 : ScoreType score = 0;
26 : Position p;
27 : Move best = INVALIDMOVE;
28 : PVList pv;
29 : SearchData datas;
30 : bool isPondering = false;
31 : bool isAnalysis = false;
32 : void reset(){
33 223 : score = 0;
34 223 : best = INVALIDMOVE;
35 223 : seldepth = 0;
36 223 : depth = 0;
37 : pv.clear();
38 : }
39 : };
40 :
41 : std::ostream& operator<<(std::ostream& of, const ThreadData& d);
42 :
43 : /*!
44 : * This is the singleton pool of threads
45 : * The search function here is the main entry point for an analysis
46 : * This is based on the former Stockfish design
47 : */
48 : class ThreadPool : public std::vector<std::unique_ptr<Searcher>> {
49 : public:
50 : static ThreadPool& instance();
51 : ~ThreadPool();
52 22 : ThreadPool() = default;
53 : // non copyable
54 : ThreadPool(const ThreadPool&) = delete;
55 : ThreadPool(const ThreadPool&&) = delete;
56 : ThreadPool& operator=(const ThreadPool&) = delete;
57 : ThreadPool& operator=(const ThreadPool&&) = delete;
58 :
59 : static void initPawnTables();
60 :
61 : [[nodiscard]] Searcher& main();
62 : void setup();
63 : void distributeData(const ThreadData& data) const;
64 : void startSearch(const ThreadData& d); // non-blocking
65 : void startOthers() const; // non-blocking
66 : void wait(bool otherOnly = false) const;
67 : void stop() const; // non-blocking
68 :
69 : // gathering counter information from all threads
70 : [[nodiscard]] Counter counter(Stats::StatId id, bool forceLocal = false) const;
71 :
72 : void displayStats() const;
73 : void clearGame() const;
74 : void clearSearch() const;
75 :
76 : TimeType currentMoveMs = 999;
77 : };
|