Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the proper way to use robin_map in lambda function for parallelizing? #69

Open
engcang opened this issue Aug 20, 2023 · 0 comments

Comments

@engcang
Copy link

engcang commented Aug 20, 2023

Thank you for the great work

As written in the title, I want to use the robin_map instead of std::unordered_map in lambda function.
Jumping into the code right away, the code below works well with std::unordered_map.

struct DataType
{
  bool to_be_del = false;
  DataType(){};
}

unordered_map<KeyType, DataType> candidates;
tbb::parallel_for_each(candidates.begin(), candidates.end(), [&](auto &cand_)
{
  if (some_condition)
  {
    cand_.second.to_be_del = true;
  }
});

But, as robin_map returns const iterator, the below code cannot be compiled.

tsl::robin_map<KeyType, DataType> candidates;
tbb::parallel_for_each(candidates.begin(), candidates.end(), [&](auto &cand_)
{
  if (some_condition)
  {
    cand_.second.to_be_del = true; // modifying const iterator
    cand_.value().to_be_del = true; // errors: cand_ has no member function named 'value()'
  }
});

As can be seen, I want to use tbb::parallel_for or tbb::parallel_for_each for faster computations.
So I would like to ask if there is a proper way to use robin_map and capture the iterator to modify the value within the lambda function!

Thank you in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant