2013-04-08 67 views
0

我想初始化一个2D concurrent_hash_map,一个在Intel TBB库中可用的容器。编译通过并且在运行时没有错误。但是,并非容器中的所有初始化值都可用,导致错误行为。TBB:初始化concurrent_hash_map

的散列映射被定义为

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; 

功能对象被定义如下。不正确行为的原因是否源于此处?

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) 
    { 
    } 
}; 

函数对象是调用调用parallel_for时如下:

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

任何建议或反馈将是巨大的。

谢谢。

回答

1

如果您打算创建64x64表,请将blocked_range(1,,16)作为parallel_for的第一个参数。原因是一个blocked_range表示一个半开区间,它包含下界但排除了上界。