我有简单的 parallel_for 循环和我插入到 concurrent_unordered_map 的每次迭代的结果。我看到插入使我的代码变慢了。那么将对从parallel_for返回到unordered_map的最佳方法是什么?我正在尝试使用 Critical_section,但速度要慢得多。我试图使用combinable,但我不知道如何使用map。
伪代码:
concurrent_unordered_map<type, type> my_map;
parallel_for(0, max, [](int i){
//is a lot of work happening
my_map.insert(std::pair<type, type>(a, b); //here is bottleneck!!
}, static::partitioner());