1 | // RUN: %libomp-compile-and-run |
2 | #include <stdio.h> |
3 | #include "omp_testsuite.h" |
4 | |
5 | int test_omp_parallel_sections_private() |
6 | { |
7 | int sum; |
8 | int sum0; |
9 | int i; |
10 | int known_sum; |
11 | |
12 | sum = 7; |
13 | sum0=0; |
14 | |
15 | #pragma omp parallel sections private(sum0, i) |
16 | { |
17 | #pragma omp section |
18 | { |
19 | sum0=0; |
20 | for (i=1;i<400;i++) |
21 | sum0=sum0+i; |
22 | #pragma omp critical |
23 | { |
24 | sum= sum+sum0; |
25 | } |
26 | } |
27 | #pragma omp section |
28 | { |
29 | sum0=0; |
30 | for(i=400;i<700;i++) |
31 | sum0=sum0+i; |
32 | #pragma omp critical |
33 | { |
34 | sum= sum+sum0; |
35 | } |
36 | } |
37 | #pragma omp section |
38 | { |
39 | sum0=0; |
40 | for(i=700;i<1000;i++) |
41 | sum0=sum0+i; |
42 | #pragma omp critical |
43 | { |
44 | sum= sum+sum0; |
45 | } |
46 | } |
47 | } |
48 | |
49 | known_sum=(999*1000)/2+7; |
50 | return (known_sum==sum); |
51 | } /* end of check_section_private*/ |
52 | |
53 | int main() |
54 | { |
55 | int i; |
56 | int num_failed=0; |
57 | |
58 | for(i = 0; i < REPETITIONS; i++) { |
59 | if(!test_omp_parallel_sections_private()) { |
60 | num_failed++; |
61 | } |
62 | } |
63 | return num_failed; |
64 | } |
65 | |