@@ -6,24 +6,26 @@ SPDX-License-Identifier: CC-BY-4.0
66
77---
88title: OpenMP data sharing
9- event: CSC Summer School in High-Performance Computing 2025
9+ event: CSC Summer School in High-Performance Computing 2026
1010lang: en
1111---
1212
13+ # Outline
1314
14- # Parallel regions and data sharing {.section}
15+ - Data sharing in OpenMP
16+
17+
18+ # Data sharing {.section}
1519
1620# How do OpenMP threads interact?
1721
18- - Because of the shared address space threads can interact using
19- _ shared variables_
20- - Threads often need some _ private work space_ in addition to the shared
21- variables
22- - for example the index variable of a loop
23- - If threads write to the same shared variable a ** race condition** appears
24- <br >⇒ undefined end result
22+ - Threads share the memory address space, so they can interact using _ shared variables_
23+ - Threads often need some _ private variables_ in addition to the shared variables
24+ - For example the index variable of a multithreaded loop
25+ - If multiple threads write to the same shared variable a ** race condition** appears
26+ - End results varies randomly depending on the order in which the threads executed
27+ - < https://deadlockempire.github.io/ >
2528- Visibility of different variables is defined using _ data-sharing clauses_
26- in the parallel region definition
2729
2830
2931# Race condition in Hello world
@@ -107,39 +109,7 @@ int main(int argc, char* argv[]) {
107109}
108110```
109111
110-
111- # Data sharing example
112-
113- <div class =column >
114- <small >main.c</small >
115- ``` c
116- int A[5 ]; // shared
117-
118- int main (void) {
119- int B[ 2] ; // shared
120- #pragma omp parallel
121- {
122- float c; // private
123- do_things(B);
124- ...
125- }
126- return 0;
127- }
128- ```
129- </div>
130- <div class=column>
131- <small>kernel.c</small>
132- ```c
133- extern int A[5]; // shared
134-
135- void do_things(int *var) {
136- double wrk[10]; // private
137- static int status; // shared
138- ...
139- }
140- ```
141- </div >
142-
112+ # Summary {.section}
143113
144114# Summary
145115
@@ -149,3 +119,4 @@ void do_things(int *var) {
149119 - ** shared** : all threads can write to and read from a shared variable
150120- Race conditions possible when writing to shared variables
151121 - avoiding race conditions is key to correctly functioning OpenMP programs
122+
0 commit comments