説明を見る。00001
00002
00003 #ifndef OSL_DFPNPARALLEL_H
00004 #define OSL_DFPNPARALLEL_H
00005
00006 #include "osl/checkmate/dfpn.h"
00007 #include "osl/misc/lightMutex.h"
00008
00009 namespace osl
00010 {
00011 namespace checkmate
00012 {
00013 class DfpnShared
00014 {
00015 public:
00016 struct ThreadData
00017 {
00018 HashKey restart_key;
00019 volatile int depth;
00020 volatile bool restart;
00021 LightMutex mutex;
00022 ThreadData() : depth(0), restart(false)
00023 {
00024 }
00025 void clear()
00026 {
00027 restart = false;
00028 restart_key = HashKey();
00029 }
00030 }
00031 #ifdef __GNUC__
00032 __attribute__ ((aligned (64)))
00033 #endif
00034 ;
00035 volatile bool stop_all;
00036 CArray<ThreadData, 32> data;
00037 DfpnShared() : stop_all(false)
00038 {
00039 }
00040 void restartThreads(const HashKey& key, int depth, unsigned int threads)
00041 {
00042 for (int i=0; i<32; ++i)
00043 if ((1u << i) & threads) {
00044 SCOPED_LOCK(lk, data[i].mutex);
00045 if (! data[i].restart || data[i].depth > depth) {
00046 data[i].restart_key = key;
00047 data[i].depth = depth;
00048 data[i].restart = true;
00049 }
00050 }
00051 }
00052 void clear()
00053 {
00054 stop_all = false;
00055 for (size_t i=0; i<data.size(); ++i)
00056 data[i].clear();
00057 }
00058 };
00059 #ifdef OSL_DFPN_SMP
00060 class DfpnParallel
00061 {
00062 DfpnParallel(const DfpnParallel&) = delete;
00063 DfpnParallel& operator=(const DfpnParallel&) = delete;
00064 private:
00065 DfpnTable *table;
00066 boost::scoped_array<Dfpn> workers;
00067 size_t num_threads;
00068
00069 const NumEffectState *state;
00070 HashKey key;
00071 PathEncoding path;
00072 Move last_move;
00073 size_t limit;
00074 struct WorkerData
00075 {
00076 Move best_move;
00077 PieceStand proof;
00078 ProofDisproof result;
00079 };
00080 boost::scoped_array<WorkerData> worker_data;
00081 DfpnShared shared;
00082 public:
00083 explicit DfpnParallel(size_t num_threads=0);
00084 ~DfpnParallel();
00085 void setTable(DfpnTable *new_table);
00086
00087 const ProofDisproof
00088 hasCheckmateMove(const NumEffectState& state, const HashKey& key,
00089 const PathEncoding& path, size_t limit, Move& best_move,
00090 Move last_move=Move::INVALID(), std::vector<Move> *pv=0);
00091 const ProofDisproof
00092 hasCheckmateMove(const NumEffectState& state, const HashKey& key,
00093 const PathEncoding& path, size_t limit, Move& best_move, PieceStand& proof,
00094 Move last_move=Move::INVALID(), std::vector<Move> *pv=0);
00095 const ProofDisproof
00096 hasEscapeMove(const NumEffectState& state,
00097 const HashKey& key, const PathEncoding& path,
00098 size_t limit, Move last_move);
00099
00100 size_t nodeCount() const;
00101 const DfpnTable& currentTable() const { return *table; }
00102 void analyze(const PathEncoding& path,
00103 const NumEffectState& state, const std::vector<Move>& moves) const;
00104
00105 void stopNow()
00106 {
00107 shared.stop_all = true;
00108 }
00109
00110 struct AttackWorker;
00111 struct DefenseWorker;
00112 friend struct AttackWorker;
00113 friend struct DefenseWorker;
00114 };
00115 #endif
00116 }
00117 }
00118
00119
00120 #endif
00121
00122
00123
00124