Question Details

No question body available.

Tags

c++ c++11 optimization parallel-processing openmp

Answers (2)

January 30, 2026 Score: 0 Rep: 36,941 Quality: Low Completeness: 40%

Added the c++ tag because the base language tag should always be present.

(this should have been a comment, but the new open-ended questions format does not support it at the moment).

January 30, 2026 Score: 0 Rep: 6,032 Quality: Low Completeness: 50%

You're trying to implement a manager-worker paradigm. That may be possible, but instead try treating all threads equally.

What you want, based on your description, is a reduction from one container into another. And reductions in openmp are very parallel. Since your "reduced" object is a container, you need to define a reduction operator, and let's just use "+", that merges that type of container.

OpenMP supports this: if you have operator+ defined on a class, you can do reduction(+:thatclass). Now each thread generates a private sublist, and the omp reduction merges these.

The only problem I see in your code is that you iterate over a set which does not support the random-access iterator that OpenMP requires. There are various ways around this, such as using a vector of reference_wrapper.

Can you take it from here? I'll try to find time to code this out for you.