data-sharing-openmp
Differences
This shows you the differences between two versions of the page.
| data-sharing-openmp [June 11, 2026 at 09:19] – created - external edit 127.0.0.1 | data-sharing-openmp [June 11, 2026 at 11:05] (current) – Ivan Janevski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| # Data sharing (OpenMP) | # Data sharing (OpenMP) | ||
| - | A local variable in a C function lives on the stack and is private to that call. When multiple threads run the same code, each gets its own stack, so locals are naturally separate. Variables declared *outside* a parallel region are different: all threads share the same memory location. **Data sharing** in OpenMP makes this explicit. Every variable accessed inside a parallel region is either **shared** (all threads read and write the same location) or **private** (each thread gets its own copy). The default for variables declared outside the region is `shared`, which silently causes a race condition if threads write to them: | + | A local variable in a C function lives on the stack and is private to that call. When multiple threads run the same code, each gets its own stack, so locals are naturally separate. Variables declared *outside* a parallel region are different: all threads share the same memory location. |
| + | |||
| + | **Data sharing** in OpenMP makes this explicit. Every variable accessed inside a parallel region is either **shared** (all threads read and write the same location) or **private** (each thread gets its own copy). The default for variables declared outside the region is `shared`, which silently causes a race condition if threads write to them: | ||
| ```c | ```c | ||
data-sharing-openmp.txt · Last modified: by Ivan Janevski
