1 | // RUN: %libomp-compile-and-run |
2 | #include <stdio.h> |
3 | #include <math.h> |
4 | #include "omp_testsuite.h" |
5 | |
6 | int sum0; |
7 | #pragma omp threadprivate(sum0) |
8 | |
9 | int test_omp_for_lastprivate() |
10 | { |
11 | int sum = 0; |
12 | int known_sum; |
13 | int i0; |
14 | |
15 | i0 = -1; |
16 | |
17 | #pragma omp parallel |
18 | { |
19 | sum0 = 0; |
20 | { /* Begin of orphaned block */ |
21 | int i; |
22 | #pragma omp for schedule(static,7) lastprivate(i0) |
23 | for (i = 1; i <= LOOPCOUNT; i++) { |
24 | sum0 = sum0 + i; |
25 | i0 = i; |
26 | } /* end of for */ |
27 | } /* end of orphaned block */ |
28 | |
29 | #pragma omp critical |
30 | { |
31 | sum = sum + sum0; |
32 | } /* end of critical */ |
33 | } /* end of parallel */ |
34 | |
35 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; |
36 | fprintf(stderr, format: "known_sum = %d , sum = %d\n" ,known_sum,sum); |
37 | fprintf(stderr, "LOOPCOUNT = %d , i0 = %d\n" ,LOOPCOUNT,i0); |
38 | return ((known_sum == sum) && (i0 == LOOPCOUNT)); |
39 | } |
40 | |
41 | int main() |
42 | { |
43 | int i; |
44 | int num_failed=0; |
45 | |
46 | for (i = 0; i < REPETITIONS; i++) { |
47 | if(!test_omp_for_lastprivate()) { |
48 | num_failed++; |
49 | } |
50 | } |
51 | return num_failed; |
52 | } |
53 | |