1 | // RUN: %libomp-compile-and-run |
2 | #include <stdio.h> |
3 | #include "omp_testsuite.h" |
4 | |
5 | int test_omp_parallel_shared() |
6 | { |
7 | int i; |
8 | int sum; |
9 | int known_sum; |
10 | |
11 | sum = 0; |
12 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2 ; |
13 | |
14 | #pragma omp parallel private(i) shared(sum) |
15 | { |
16 | |
17 | int mysum = 0; |
18 | #pragma omp for |
19 | for (i = 1; i <= LOOPCOUNT; i++) { |
20 | mysum = mysum + i; |
21 | } |
22 | #pragma omp critical |
23 | { |
24 | sum = sum + mysum; |
25 | } |
26 | |
27 | |
28 | } |
29 | if (known_sum != sum) { |
30 | fprintf(stderr, format: "KNOWN_SUM = %d; SUM = %d\n" , known_sum, sum); |
31 | } |
32 | return (known_sum == sum); |
33 | } |
34 | |
35 | int main() |
36 | { |
37 | int i; |
38 | int num_failed=0; |
39 | |
40 | for(i = 0; i < REPETITIONS; i++) { |
41 | if(!test_omp_parallel_shared()) { |
42 | num_failed++; |
43 | } |
44 | } |
45 | return num_failed; |
46 | } |
47 | |