data-sharing-openmp
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| data-sharing-openmp [June 11, 2026 at 11:05] – Ivan Janevski | data-sharing-openmp [June 13, 2026 at 03:13] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| 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. | + | 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: |
| - | + | ||
| - | **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.1781175925.txt.gz · Last modified: by Ivan Janevski
