哈希表的结构如下:
class ttEntry
{
private:
signed int key:32; /*! 32 bit for the upper part of the key*/
signed int packedMove:16; /*! 16 bit for the move*/
signed int depth:16; /*! 16 bit for depth*/
signed int value:23; /*! 23 bit for the value*/
signed int generation:8; /*! 8 bit for the generation id*/
signed int staticValue:23; /*! 23 bit for the static evalutation (eval())*/
signed int type:3; /*! 2 bit for the type of the entry*/
/* 144 bits total = 16 bytes*/
public:
explicit ttEntry(unsigned int _Key, Score _Value, unsigned char _Type, signed short int _Depth, unsigned short _Move, Score _StaticValue, unsigned char _gen): key(_Key), packedMove(_Move), depth(_Depth), value(_Value), generation(_gen), staticValue(_StaticValue), type(_Type){}
explicit ttEntry(){}
...
...
};
using ttCluster = std::array<ttEntry, 4>;
class transpositionTable
{
private:
std::vector<ttCluster> _table;
....
....
}
我用于分配空间的代码如下:
uint64_t transpositionTable::setSize(unsigned long int mbSize)
{
uint64_t size = (uint64_t)((((uint64_t)mbSize) << 20) / sizeof(ttCluster));
_elements = size;
_table.clear();
_table.shrink_to_fit();
try
{
_table.reserve(_elements);
_table.resize(_elements); // big bottleneck
}
catch(...)
{
std::cerr << "Failed to allocate " << mbSize<< "MB for transposition table." << std::endl;
exit(EXIT_FAILURE);
}
return _elements * 4;
}
要以128GB的内存初始化表108秒。我对用已知值初始化内存不感兴趣,而只是分配空间并具有足够长的std :: vector。
我知道我可以用良好的旧C代码和malloc重写代码,但我想使用现代的std :: vector。
关于如何加速代码以及我在哪里做错的任何想法?
在我的国际象棋引擎代码库中,我使用了一个非常大的哈希表,哈希表的大小最多可以达到128 GB。 hast表是大小为4的存储桶的大型数组。使用...