icp/oer/courses/c-openmp/sections/02-advanced/03-reduce/content.md

800 B

Some race conditions can be resolved by every thread calculating the result in a private variable and combining all the results in the end. This is often faster, because it involves less waiting.

Knowledge

To use the reduction, you have to add the reduction clause reduction(operator : var) to your compiler directive. You can use reductions for a handful of operations. Most of the arithmetic operators and some of the logic and bitwise ones plus min and max. For a complete list check the quick reference. Reduction only need to synchronize as often as there are threads instead of how many operations are actually done.

Task

Instead of using a critical section as before, try your hand at a reduction variable instead.