5#include <boost/ptr_container/ptr_vector.hpp>
10DfpnParallel::DfpnParallel(
size_t threads)
11 : table(0), num_threads(threads), state(0)
14 num_threads = OslConfig::concurrency();
15 workers.reset(
new Dfpn[num_threads]);
16 for (
size_t i=0; i<num_threads; ++i)
17 workers[i].setParallel(i, &shared);
21DfpnParallel::~DfpnParallel()
29DfpnParallel::setTable(DfpnTable *new_table)
32 for (
size_t i=0; i<num_threads; ++i)
33 workers[i].setTable(table);
38DfpnParallel::hasCheckmateMove(
const NumEffectState& state,
const HashKey& key,
40 Move last_move, std::vector<Move> *pv)
43 return hasCheckmateMove(state, key, path, limit, best_move, proof, last_move, pv);
46struct osl::checkmate::DfpnParallel::AttackWorker
51 AttackWorker(DfpnParallel *p,
int id)
52 : parent(p), thread_id(id)
55 void operator()()
const
57 assert(! parent->shared.data[thread_id].restart);
58 WorkerData& work = parent->worker_data[thread_id];
59 work.result = parent->workers[thread_id].hasCheckmateMove
60 (*(parent->state), parent->key, parent->path,
61 parent->limit, work.best_move, work.proof, parent->last_move);
62 parent->workers[thread_id].clear();
68DfpnParallel::hasCheckmateMove(
const NumEffectState& state,
const HashKey& key,
69 const PathEncoding& path,
size_t limit, Move& best_move, PieceStand& proof,
70 Move last_move, std::vector<Move> *pv)
75 this->last_move = last_move;
78 worker_data.reset(
new WorkerData[num_threads]);
79 boost::ptr_vector<std::thread> threads;
80 for (
size_t i=0; i<num_threads; ++i)
81 threads.push_back(
new std::thread(AttackWorker(
this, i)));
83 unsigned int min_proof = ProofDisproof::PROOF_MAX;
84 for (
size_t i=0; i<num_threads; ++i) {
87 || (worker_data[i].result.proof() >= min_proof
88 && ! worker_data[i].result.isFinal()))
90 ret = worker_data[i].result;
91 min_proof = ret.
proof();
92 best_move = worker_data[i].best_move;
93 proof = worker_data[i].proof;
95 if (pv && ret.isCheckmateSuccess()) {
96 ProofTreeDepthDfpn analyzer(*table);
97 analyzer.retrievePV(state,
true, *pv);
102struct osl::checkmate::DfpnParallel::DefenseWorker
104 DfpnParallel *parent;
107 DefenseWorker(DfpnParallel *p,
int id)
108 : parent(p), thread_id(id)
111 void operator()()
const
113 WorkerData& work = parent->worker_data[thread_id];
114 work.result = parent->workers[thread_id].hasEscapeMove
115 (*(parent->state), parent->key, parent->path,
116 parent->limit, parent->last_move);
122DfpnParallel::hasEscapeMove(
const NumEffectState& state,
124 size_t limit, Move last_move)
126 this->state = &state;
129 this->last_move = last_move;
132 worker_data.reset(
new WorkerData[num_threads]);
133 boost::ptr_vector<std::thread> threads;
134 for (
size_t i=0; i<num_threads; ++i)
135 threads.push_back(
new std::thread(DefenseWorker(
this, i)));
137 unsigned int min_disproof = ProofDisproof::DISPROOF_MAX;
138 for (
size_t i=0; i<num_threads; ++i) {
140 if (worker_data[i].result.disproof() >= min_disproof)
142 ret = worker_data[i].result;
148size_t osl::checkmate::
149DfpnParallel::nodeCount()
const
152 for (
size_t i=0; i<num_threads; ++i)
153 sum += workers[i].nodeCount();
160 const NumEffectState& src,
const std::vector<Move>& moves)
const
163 workers[0].analyze(path, src, moves);
証明数(proof number)と反証数(disproof number).
unsigned int disproof() const
unsigned int proof() const