1 | // RUN: %libomp-compile-and-run |
2 | #include <stdio.h> |
3 | #include <math.h> |
4 | #include "omp_testsuite.h" |
5 | |
6 | int test_omp_task_firstprivate() |
7 | { |
8 | int i; |
9 | int sum = 1234; |
10 | int known_sum; |
11 | int result = 0; /* counts the wrong sums from tasks */ |
12 | |
13 | known_sum = 1234 + (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; |
14 | |
15 | #pragma omp parallel |
16 | { |
17 | #pragma omp single |
18 | { |
19 | for (i = 0; i < NUM_TASKS; i++) { |
20 | #pragma omp task firstprivate(sum) |
21 | { |
22 | int j; |
23 | for (j = 0; j <= LOOPCOUNT; j++) { |
24 | #pragma omp flush |
25 | sum += j; |
26 | } |
27 | |
28 | /* check if calculated sum was right */ |
29 | if (sum != known_sum) { |
30 | #pragma omp critical |
31 | { result++; } |
32 | } |
33 | } /* omp task */ |
34 | } /* for loop */ |
35 | } /* omp single */ |
36 | } /* omp parallel */ |
37 | return (result == 0); |
38 | } |
39 | |
40 | int main() |
41 | { |
42 | int i; |
43 | int num_failed=0; |
44 | |
45 | for(i = 0; i < REPETITIONS; i++) { |
46 | if(!test_omp_task_firstprivate()) { |
47 | num_failed++; |
48 | } |
49 | } |
50 | return num_failed; |
51 | } |
52 | |