简体   繁体   English

TBB Concurrent Hash地图

[英]TBB Concurrent Hash map

I am implementing tbb's concurrent hash map to compare the performance of it against a suite of other concurrent hash tables. 我正在实现tbb的并发哈希映射,以将其性能与一组其他并发哈希表进行比较。

However the performance I get out of it is horrendous, I just can't believe it is that slow compared to other concurrent hash tables 然而,我从中获得的性能是可怕的,我无法相信它与其他并发哈希表相比是那么慢

Here is my implementation of it: 这是我的实现:

class TBB: public TestDs{
    typedef tbb::concurrent_hash_map<int,int, HashCompare<int> > hash_t;
private:
        hash_t _ds;
public:
        TBB(const Configuration& config) : _ds(config.initial_count) {
        }

    bool containsKey(int key) {
        hash_t::accessor a;

        if(_ds.find(a,key)){
            return true;
        }
        else 
            return false;
    }

    int get(int key) {
        hash_t::accessor a;

        if(_ds.find(a,key)){
             return (int)(a->second);
        }
        else 
            return 0;
    }

    int put(int key, int value) {
        return _ds.insert( std::make_pair(key, value) );
    }

    int remove(int key) {
        return _ds.erase(key);
    }

    int size() {
        return _ds.size();
    }
    const char* name() {
        return "TBB";
    }
    void print() {}
    void shutdown() {}

};

Does anyone see any issue with my implementation or know of any reason why it may perform slow? 有没有人看到我的实施有任何问题或知道为什么它可能执行缓慢的任何原因? It takes over 30 mins for it to insert 200,000 elements in a single thread environment. 它需要超过30分钟才能在单个线程环境中插入200,000个元素。 To put that in perspective, nearly all the other tables perform this test in less than 5 mins. 为了正确看待这一点,几乎所有其他表都在不到5分钟的时间内完成了这项测试。

Here is my build code: 这是我的构建代码:

-w  -DNDEBUG -g -msse2 -m32  -DINTEL -D_REENTRANT -lrt -pthread -fno-strict-aliasing -l cds -l tbb -lllalloc 

UPDATE: I have adjusted my testing code to prefill the hash tables to 1000, instead of 100,000. 更新:我已经调整了我的测试代码,将哈希表预填充到1000而不是100,000。 When running it again, tbb performs 92 op/sec while, another implementation performs 89431 op/sec. 再次运行时,tbb执行92 op / sec,而另一个实现执行89431 op / sec。 (64 thread environment)...Just saying something doesn't seem right.... (64线程环境)......只是说一些东西似乎不对......

Additional Info: Computer is a HP Z600 Workstation with 6gb of ram and 6 cores. 附加信息:计算机是HP Z600工作站,具有6GB的RAM和6个内核。

Notice Cross positing at : http://software.intel.com/en-us/forums/showthread.php?t=86119 注意交叉定位: http ://software.intel.com/en-us/forums/showthread.php?t = 86119

You HashCompare::hash() returns sizeof(int) , which, I guess, means every entry maps into the same bucket. HashCompare::hash()返回sizeof(int) ,我猜,这意味着每个条目都映射到同一个桶中。 It seems like you are not using it as a hash table, more of a linked list. 看起来你没有将它用作哈希表,更多的是链表。

You could try using Boost's hash: 您可以尝试使用Boost的哈希:

#include <boost/functional/hash.hpp>

template<typename K> 
struct HashCompare { 
    static size_t hash( const K& key )                  { return boost::hash_value(key); } 
    static bool   equal( const K& key1, const K& key2 ) { return ( key1 == key2 ); } 
}; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM