14 lines
800 B
Markdown
14 lines
800 B
Markdown
|
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](http://www.openmp.org/wp-content/uploads/OpenMP3.1-CCard.pdf).
|
||
|
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.
|