Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

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

[cpp]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;[/cpp]

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

[cpp]class ColumnInit {
    RowMap *const pMyEdgeMap;
    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;
                      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:

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

Any suggestions or feedback would be great.


0 Kudos
1 Reply
Valued Contributor III

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

0 Kudos