TBB: initialize concurrent_hash_map

TBB: initialize concurrent_hash_map

I am trying to initialize a 2D concurrent_hash_map, a container available in the Intel TBB library. Compilation passes and there is no error at runtime. However, not all initialized values are available in the container leading to incorrect behavior.

The hash map is defined as

template<typename K>
struct MyHashCompare {
    static size_t hash(const K& key) { return boost::hash_value(key); }
    static bool equal(const K& key1, const K& key2) { return (key1 == key2); }
};
typedef concurrent_hash_map<int, int, MyHashCompare<int> > ColMap;
typedef concurrent_hash_map<int, ColMap, MyHashCompare<int> > RowMap;

The function object is defined as follows. Could the reason for the incorrect behavior originate here?

class ColumnInit {
    RowMap *const pMyEdgeMap;
    public:
    void operator()(const blocked_range<size_t>& r) const {
        RowMap* pEdgeMap = pMyEdgeMap;
        RowMap::accessor accessX;
        ColMap::accessor accessY;
        for(size_t n1 = r.begin(); n1 != r.end(); n1++)
        {
            pEdgeMap->insert(accessX, n1);
            for(int n2 = 1; n2 <= 64; n2++)
            {
                int diff = abs((int)n1 - n2);
                if ((diff == 8) || (diff == 1))
                {
                       assert((accessX->second).insert(accessY, n2));
                       accessY->second = -1;
                }
                else
                {
                       assert((accessX->second).insert(accessY, n2));
                       accessY->second = 0;
                }
            }
        }
    }
    ColumnInit(RowMap* pEdgeMap): pMyEdgeMap(pEdgeMap)
    {
    }
};

The function object is invoked from a call to parallel_for as follows:

parallel_for(blocked_range<size_t>(1,64,16), ColumnInit((RowMap*)&mEdges), simple_partitioner());

Any suggestions or feedback would be great.

Thanks.

2 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

That range goes from 1 to 63 (the second boundary is exclusive).

发表评论

登录添加评论。还不是成员?立即加入