Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
2421 Discussions

Can TBB use concurrent_hash_map for another concurrent_hash_map?

merlion_m_
Beginner
174 Views

Dear all,

I read the following example of concurrent_hash_map example(https://software.intel.com/zh-cn/node/506077) and this is fine:

    parallel_for( blocked_range<string*>( Data, Data+N, 1000 ),
                  Tally(table) );

Can the "Data" be a concurrent_hash_map type?

My requirement is that I have a concurrent_hash_map A, and a concurrent_hash_map B, how can I insert the entries in concurrent_hash_map A into the concurrent_hash_map B? I need to insert entries from concurrent_hash_maps into concurrent_hash_maps.

I write my code as follows:

 40 struct MyHashCompare {
 41   static size_t hash( const int& x ) {
 42     return x;
 43   }
 44   //! True if strings are equal
 45   static bool equal( const int& x, const int& y ) {
 46     return x==y;
 47   }
 48 };
 49 // A concurrent hash table that maps ints to ints.
 50 typedef concurrent_hash_map<int,int,MyHashCompare> mapTable;

 95 struct RULE{
 96   mapTable rule_index;
 97   mapTable word_index;
 98 };

105 struct RULE* rule_full;

295   rule_full=new struct RULE[rules];

112 struct count4Rule{
113   mapTable& table;
114   count4Rule( mapTable& table_ ) : table(table_) {}
115   void operator()( const blocked_range<int*> range ) const {
116 //
117   }
118 };

181       parallel_for(blocked_range< mapTable::iterator >(rule_full[rulenum].word_index.range(),64), count4Rule((rule_full[rulenum].word_index)));

However, when I compile the code, I get the following error:

icpc -g -O3 -std=c++11 main.cc -pthread -ltbb
main.cc(181): error: no instance of constructor "tbb::blocked_range<Value>::blocked_range [with Value=tbb::interface5::internal::hash_map_iterator<tbb::interface5::concurrent_hash_map<int, int, MyHashCompare, tbb::tbb_allocator<std::pair<int, int>>>, std::pair<const int, int>>]" matches the argument list
            argument types are: (tbb::interface5::internal::hash_map_range<tbb::interface5::internal::hash_map_iterator<tbb::interface5::concurrent_hash_map<int, int, MyHashCompare, tbb::tbb_allocator<std::pair<int, int>>>, std::pair<const int, int>>>)
        parallel_for(blocked_range< mapTable::iterator >(rule_full[rulenum].word_index.range()), count4Rule((rule_full[rulenum].word_index)));
                     ^

compilation aborted for main.cc (code 2)
make: *** [main] Error 2

What should I do? Any suggestions or example?

Thanks,

Feng

0 Kudos
0 Replies
Reply