c++ - Tbb concurrent hash map iterator -
i'm traversing entire tbb concurrent hash map using iterator , inspecting each (key,value) pair.
for (map::pair = myhashtable.begin(); myhashtable.end(); pair++)
how can parallelize iterator?
use range()
method described in reference manual:
hashtable_t myhashtable; // assuming hashtable_t concurrent_hash_map specialization tbb::parallel_for( myhashtable.range(), [](const hashtable_t::range_type &r) { for( hashtable_t::iterator = r.begin(); != r.end(); i++); } );
(i use c++11 concision show types explicitly sake of c++03)
and please pay attention caution note there:
do not call concurrent operations, including count , find while iterating table. use concurrent_unordered_map if concurrent traversal , insertion required.
Comments
Post a Comment