source:
CIVL/mods/dev.civl.com/examples/omp/atomics/atomic_default.c@
cb4d4f4
| Last change on this file since cb4d4f4 was aad342c, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 435 bytes | |
| Line | |
|---|---|
| 1 | #include<assert.h> |
| 2 | |
| 3 | int main() { |
| 4 | int x = 0; |
| 5 | int y = 0; |
| 6 | #pragma omp parallel sections |
| 7 | { |
| 8 | #pragma omp section |
| 9 | { |
| 10 | #pragma omp atomic |
| 11 | x++; |
| 12 | } |
| 13 | #pragma omp section |
| 14 | { |
| 15 | #pragma omp atomic |
| 16 | x = x + y; |
| 17 | } |
| 18 | #pragma omp section |
| 19 | { |
| 20 | #pragma omp atomic |
| 21 | x += y; |
| 22 | } |
| 23 | #pragma omp section |
| 24 | { |
| 25 | #pragma omp atomic |
| 26 | x = y + x; |
| 27 | } |
| 28 | } |
| 29 | assert (x == 0 || x == 1); |
| 30 | } |
Note:
See TracBrowser
for help on using the repository browser.
