1 | // RUN: %libomp-compile-and-run |
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | #include "omp_testsuite.h" |
5 | |
6 | static int sum1 = 789; |
7 | #pragma omp threadprivate(sum1) |
8 | |
9 | int test_omp_parallel_copyin() |
10 | { |
11 | int sum, num_threads; |
12 | int known_sum; |
13 | |
14 | sum = 0; |
15 | sum1 = 7; |
16 | num_threads = 0; |
17 | |
18 | #pragma omp parallel copyin(sum1) |
19 | { |
20 | /*printf("sum1=%d\n",sum1);*/ |
21 | int i; |
22 | #pragma omp for |
23 | for (i = 1; i < 1000; i++) { |
24 | sum1 = sum1 + i; |
25 | } /*end of for*/ |
26 | #pragma omp critical |
27 | { |
28 | sum = sum + sum1; |
29 | num_threads++; |
30 | } /*end of critical*/ |
31 | } /* end of parallel*/ |
32 | known_sum = (999 * 1000) / 2 + 7 * num_threads; |
33 | return (known_sum == sum); |
34 | } |
35 | |
36 | int main() |
37 | { |
38 | int i; |
39 | int num_failed=0; |
40 | |
41 | for(i = 0; i < REPETITIONS; i++) { |
42 | if(!test_omp_parallel_copyin()) { |
43 | num_failed++; |
44 | } |
45 | } |
46 | return num_failed; |
47 | } |
48 | |