Assume we want to count something in an OpenMP loop. Compare the reductionwith the atomic incrementThe atomic access provides the result immediately, while a reduction only assumes its correct value at the end of the loop. For instance, reductions do not allow this:
I have a std::deque<std::pair<CustomObj, int>> that doesn't change in size when starting the concurrent block.
I was using rand() function to generate pseudo-random numbers between 0,1 for a simulation purpose, but when I decided to make my C++ code run in parallel (via OpenMP) I noticed rand() isn't thread-safe and also is not very uniform.