My Project
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  {
19  volatile int depth;
20  volatile bool restart;
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;
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
61  {
62  DfpnParallel(const DfpnParallel&) = delete;
63  DfpnParallel& operator=(const DfpnParallel&) = delete;
64  private:
65  DfpnTable *table;
66  boost::scoped_array<Dfpn> workers;
67  size_t num_threads;
68  // working data
69  const NumEffectState *state;
70  HashKey key;
71  PathEncoding path;
72  Move last_move;
73  size_t limit;
74  struct WorkerData
75  {
76  Move best_move;
77  PieceStand proof;
78  ProofDisproof result;
79  };
80  boost::scoped_array<WorkerData> worker_data;
81  DfpnShared shared;
82  public:
83  explicit DfpnParallel(size_t num_threads=0);
84  ~DfpnParallel();
85  void setTable(DfpnTable *new_table);
86 
87  const ProofDisproof
88  hasCheckmateMove(const NumEffectState& state, const HashKey& key,
89  const PathEncoding& path, size_t limit, Move& best_move,
90  Move last_move=Move::INVALID(), std::vector<Move> *pv=0);
91  const ProofDisproof
92  hasCheckmateMove(const NumEffectState& state, const HashKey& key,
93  const PathEncoding& path, size_t limit, Move& best_move, PieceStand& proof,
94  Move last_move=Move::INVALID(), std::vector<Move> *pv=0);
95  const ProofDisproof
96  hasEscapeMove(const NumEffectState& state,
97  const HashKey& key, const PathEncoding& path,
98  size_t limit, Move last_move);
99 
100  size_t nodeCount() const;
101  const DfpnTable& currentTable() const { return *table; }
102  void analyze(const PathEncoding& path,
103  const NumEffectState& state, const std::vector<Move>& moves) const;
104 
105  void stopNow()
106  {
107  shared.stop_all = true;
108  }
109 
110  struct AttackWorker;
111  struct DefenseWorker;
112  friend struct AttackWorker;
113  friend struct DefenseWorker;
114  };
115 #endif
116  }
117 }
118 
119 
120 #endif /* OSL_DFPNPARALLEL_H */
121 // ;;; Local Variables:
122 // ;;; mode:c++
123 // ;;; c-basic-offset:2
124 // ;;; End:
圧縮していない moveの表現 .
Definition: basic_type.h:1052
static const Move INVALID()
Definition: basic_type.h:1095
利きを持つ局面
片方の手番の持駒の枚数を記録するクラス.
CArray< ThreadData, 32 > data
Definition: dfpnParallel.h:36
void restartThreads(const HashKey &key, int depth, unsigned int threads)
Definition: dfpnParallel.h:40
詰探索局面表 – 並列でも共有する部分
Definition: dfpn.h:30
証明数(proof number)と反証数(disproof number).
Definition: proofDisproof.h:17
#define SCOPED_LOCK(lock, m)
Definition: lightMutex.h:176
const PtypeO PTYPEO_EDGE __attribute__((unused))