dfpnParallel.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
dfpnParallel.h
Go to the documentation of this file.
1 /* dfpnParallel.h
2 */
3 #ifndef OSL_DFPNPARALLEL_H
4 #define OSL_DFPNPARALLEL_H
5
6 #include "osl/checkmate/dfpn.h"
7 #include "osl/misc/lightMutex.h"
8
9 namespace osl
10 {
11 namespace checkmate
12 {
13 class DfpnShared
14 {
15 public:
16 struct ThreadData
17 {
18 HashKey restart_key;
19 volatile int depth;
20 volatile bool restart;
21 LightMutex mutex;
22 ThreadData() : depth(0), restart(false)
23 {
24 }
25 void clear()
26 {
27 restart = false;
28 restart_key = HashKey();
29 }
30 }
31 #ifdef __GNUC__
32 __attribute__ ((aligned (64)))
33 #endif
34 ;
35 volatile bool stop_all;
36 CArray<ThreadData, 32> data;
37 DfpnShared() : stop_all(false)
38 {
39 }
40 void restartThreads(const HashKey& key, int depth, unsigned int threads)
41 {
42 for (int i=0; i<32; ++i)
43 if ((1u << i) & threads) {
44 SCOPED_LOCK(lk, data[i].mutex);
45 if (! data[i].restart || data[i].depth > depth) {
46 data[i].restart_key = key;
47 data[i].depth = depth;
48 data[i].restart = true;
49 }
50 }
51 }
52 void clear()
53 {
54 stop_all = false;
55 for (size_t i=0; i<data.size(); ++i)
56 data[i].clear();
57 }
58 };
59 #ifdef OSL_DFPN_SMP
60 class DfpnParallel : boost::noncopyable
61 {
62 private:
63 DfpnTable *table;
64 boost::scoped_array<Dfpn> workers;
65 size_t num_threads;
66 // working data
67 const NumEffectState *state;
68 HashKey key;
69 PathEncoding path;
70 Move last_move;
71 size_t limit;
72 struct WorkerData
73 {
74 Move best_move;
75 PieceStand proof;
76 ProofDisproof result;
77 };
78 boost::scoped_array<WorkerData> worker_data;
79 DfpnShared shared;
80 public:
81 explicit DfpnParallel(size_t num_threads=0);
82 ~DfpnParallel();
83 void setTable(DfpnTable *new_table);
84
85 const ProofDisproof
86 hasCheckmateMove(const NumEffectState& state, const HashKey& key,
87 const PathEncoding& path, size_t limit, Move& best_move,
88 Move last_move=Move::INVALID(), vector<Move> *pv=0);
89 const ProofDisproof
90 hasCheckmateMove(const NumEffectState& state, const HashKey& key,
91 const PathEncoding& path, size_t limit, Move& best_move, PieceStand& proof,
92 Move last_move=Move::INVALID(), vector<Move> *pv=0);
93 const ProofDisproof
94 hasEscapeMove(const NumEffectState& state,
95 const HashKey& key, const PathEncoding& path,
96 size_t limit, Move last_move);
97
98 size_t nodeCount() const;
99 const DfpnTable& currentTable() const { return *table; }
100 void analyze(const PathEncoding& path,
101 const NumEffectState& state, const vector<Move>& moves) const;
102
103 void stopNow()
104 {
105 shared.stop_all = true;
106 }
107
108 struct AttackWorker;
109 struct DefenseWorker;
110 friend struct AttackWorker;
111 friend struct DefenseWorker;
112 };
113 #endif
114 }
115 }
116
117
118 #endif /* OSL_DFPNPARALLEL_H */
119 // ;;; Local Variables:
120 // ;;; mode:c++
121 // ;;; c-basic-offset:2
122 // ;;; End: