source:
CIVL/examples/omp/region1.c
| Last change on this file was ea777aa, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 466 bytes | |
| Rev | Line | |
|---|---|---|
| [fd42b02] | 1 | #include <omp.h> |
| [c592254] | 2 | #include <assert.h> |
| [fd42b02] | 3 | #define N 10 |
| 4 | ||
| 5 | int main (int argc, char * argv[]){ | |
| 6 | int i; | |
| 7 | int a[N]; | |
| [c592254] | 8 | int sum = 0; |
| [fd42b02] | 9 | |
| 10 | #pragma omp parallel | |
| 11 | { | |
| 12 | int max = N; | |
| 13 | ||
| 14 | #pragma omp for | |
| 15 | for(i=0; i<max; i++) | |
| 16 | a[i] = 0; | |
| 17 | ||
| 18 | max = 0; | |
| 19 | } | |
| [c592254] | 20 | |
| 21 | #pragma omp parallel | |
| 22 | if (i>0) { | |
| 23 | sum = N; | |
| 24 | } else { | |
| 25 | #pragma omp for reduction(+:sum) | |
| 26 | for(i=0; i<N; i++) | |
| 27 | sum = sum + a[i]; | |
| 28 | } | |
| 29 | ||
| 30 | { | |
| 31 | int counter = 0; | |
| 32 | #pragma omp parallel | |
| 33 | if (counter == 0) counter++; | |
| 34 | ||
| 35 | assert(counter == 1); | |
| 36 | } | |
| 37 | ||
| [fd42b02] | 38 | } |
Note:
See TracBrowser
for help on using the repository browser.
