dfpnParallel.h
Go to the documentation of this file.
/* dfpnParallel.h
*/
#ifndef OSL_DFPNPARALLEL_H
#define OSL_DFPNPARALLEL_H
#include "osl/checkmate/dfpn.h"
#include "osl/misc/lightMutex.h"
namespace osl
{
namespace checkmate
{
class DfpnShared
{
public:
struct ThreadData
{
HashKey restart_key;
volatile int depth;
volatile bool restart;
LightMutex mutex;
ThreadData() : depth(0), restart(false)
{
}
void clear()
{
restart = false;
restart_key = HashKey();
}
}
#ifdef __GNUC__
__attribute__ ((aligned (64)))
#endif
;
volatile bool stop_all;
CArray<ThreadData, 32> data;
DfpnShared() : stop_all(false)
{
}
void restartThreads(const HashKey& key, int depth, unsigned int threads)
{
for (int i=0; i<32; ++i)
if ((1u << i) & threads) {
SCOPED_LOCK(lk, data[i].mutex);
if (! data[i].restart || data[i].depth > depth) {
data[i].restart_key = key;
data[i].depth = depth;
data[i].restart = true;
}
}
}
void clear()
{
stop_all = false;
for (size_t i=0; i<data.size(); ++i)
data[i].clear();
}
};
#ifdef OSL_DFPN_SMP
class DfpnParallel
{
DfpnParallel(const DfpnParallel&) = delete;
DfpnParallel& operator=(const DfpnParallel&) = delete;
private:
DfpnTable *table;
boost::scoped_array<Dfpn> workers;
size_t num_threads;
// working data
const NumEffectState *state;
HashKey key;
PathEncoding path;
Move last_move;
size_t limit;
struct WorkerData
{
Move best_move;
PieceStand proof;
ProofDisproof result;
};
boost::scoped_array<WorkerData> worker_data;
DfpnShared shared;
public:
explicit DfpnParallel(size_t num_threads=0);
~DfpnParallel();
void setTable(DfpnTable *new_table);
const ProofDisproof
hasCheckmateMove(const NumEffectState& state, const HashKey& key,
const PathEncoding& path, size_t limit, Move& best_move,
Move last_move=Move::INVALID(), std::vector<Move> *pv=0);
const ProofDisproof
hasCheckmateMove(const NumEffectState& state, const HashKey& key,
const PathEncoding& path, size_t limit, Move& best_move, PieceStand& proof,
Move last_move=Move::INVALID(), std::vector<Move> *pv=0);
const ProofDisproof
hasEscapeMove(const NumEffectState& state,
const HashKey& key, const PathEncoding& path,
size_t limit, Move last_move);
size_t nodeCount() const;
const DfpnTable& currentTable() const { return *table; }
void analyze(const PathEncoding& path,
const NumEffectState& state, const std::vector<Move>& moves) const;
void stopNow()
{
shared.stop_all = true;
}
struct AttackWorker;
struct DefenseWorker;
friend struct AttackWorker;
friend struct DefenseWorker;
};
#endif
}
}
#endif /* OSL_DFPNPARALLEL_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::CArray
Definition container.h:20
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::PieceStand
片方の手番の持駒の枚数を記録するクラス.
Definition bits/pieceStand.h:38
osl::checkmate::DfpnShared::stop_all
volatile bool stop_all
Definition dfpnParallel.h:35
osl::checkmate::DfpnShared::data
CArray< ThreadData, 32 > data
Definition dfpnParallel.h:36
osl::checkmate::DfpnShared::clear
void clear()
Definition dfpnParallel.h:52
osl::checkmate::DfpnShared::DfpnShared
DfpnShared()
Definition dfpnParallel.h:37
osl::checkmate::DfpnShared::restartThreads
void restartThreads(const HashKey &key, int depth, unsigned int threads)
Definition dfpnParallel.h:40
osl::checkmate::DfpnTable
詰探索局面表 – 並列でも共有する部分
Definition dfpn.h:30
osl::checkmate::ProofDisproof
証明数(proof number)と反証数(disproof number).
Definition proofDisproof.h:17
osl::hash::HashKey
Definition hashKey.h:153
osl::misc::LightMutex
Definition lightMutex.h:51
dfpn.h
lightMutex.h
SCOPED_LOCK
#define SCOPED_LOCK(lock, m)
Definition lightMutex.h:176
PathEncoding
Definition pathEncoding.cc:12
osl::checkmate
Definition king8Info.h:12
osl
Definition additionalEffect.h:6
osl::__attribute__
const PtypeO PTYPEO_EDGE __attribute__((unused))
osl::checkmate::DfpnShared::ThreadData::restart_key
HashKey restart_key
Definition dfpnParallel.h:18
osl::checkmate::DfpnShared::ThreadData::depth
volatile int depth
Definition dfpnParallel.h:19
osl::checkmate::DfpnShared::ThreadData::clear
void clear()
Definition dfpnParallel.h:25
osl::checkmate::DfpnShared::ThreadData::ThreadData
ThreadData()
Definition dfpnParallel.h:22
osl::checkmate::DfpnShared::ThreadData::restart
volatile bool restart
Definition dfpnParallel.h:20
osl::checkmate::DfpnShared::ThreadData::mutex
LightMutex mutex
Definition dfpnParallel.h:21