Skip to content

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

@engcang

Description

@engcang

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions