I want to traverse my std::map in parallel with parallel_for.
As the tutorial says, we cannot randomly access it, so I chose parallel_for_each.
std::map<std::string, std::string> map_; // student name, student age
tbb::parallel_for_each(map_.begin(), map_.end(), [&](const auto& item) {
processOne worker;
worker(item.first, map_.size());
});
But it seems that parallel_for_each will not chunk the map into subtasks, so it is quite slow.
Is it possible to do something like this?
tbb::parallel_for(tbb::blocked_range<int>(0, map_.size(), 10000), [&](tbb::blocked_range<int> r) {
...
});
paleonix
3,3435 gold badges20 silver badges42 bronze badges
asked Jan 17, 2024 at 8:40
Weimin Chan
3671 gold badge3 silver badges19 bronze badges
lang-cpp
std::vector<std::pair<Key,Value>>instead of the mapparellel_for_each, weird.