Site Tools


reduction-openmp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

reduction-openmp [June 11, 2026 at 09:19] – created - external edit 127.0.0.1reduction-openmp [June 11, 2026 at 11:06] (current) Ivan Janevski
Line 8: Line 8:
 ``` ```
  
-Adding `#pragma omp parallel for` to this loop creates a race condition: multiple threads read `sum`, add to it, and write back simultaneously, so some updates are lost. The `reduction` clause fixes this. **Reduction** in OpenMP gives each thread a private copy of the accumulation variable, lets it accumulate locally without contention, then merges all copies at the end of the loop using the specified operator.+Adding `#pragma omp parallel for` to this loop creates a race condition: multiple threads read `sum`, add to it, and write back simultaneously, so some updates are lost. The `reduction` clause fixes this. 
 + 
 +**Reduction** in OpenMP gives each thread a private copy of the accumulation variable, lets it accumulate locally without contention, then merges all copies at the end of the loop using the specified operator.
  
 ```c ```c
reduction-openmp.1781169550.txt.gz · Last modified: by 127.0.0.1