1// RUN: %libomp-compile-and-run
2#include "omp_testsuite.h"
3
4#define N 100
5
6int x1, x2, x3, x4, x5;
7#pragma omp threadprivate(x1, x2, x3, x4, x5)
8
9int test_omp_parallel_copyin() {
10 int a[N];
11 x1 = 1;
12
13#pragma omp parallel copyin(x1)
14#pragma omp for
15 for (int i = 0; i < N; i++)
16 a[i] = i + x1;
17
18 int sum = 0;
19
20 for (int i = 0; i < N; i++)
21 sum += a[i];
22
23 return (sum == ((99 + 2 * x1) * 100) / 2);
24}
25
26int test_omp_parallel_for_copyin() {
27 int a[N];
28 x2 = 2;
29
30#pragma omp parallel for copyin(x2)
31 for (int i = 0; i < N; i++)
32 a[i] = i + x2;
33
34 int sum = 0;
35
36 for (int i = 0; i < N; i++)
37 sum += a[i];
38
39 return (sum == ((99 + 2 * x2) * 100) / 2);
40}
41
42int test_omp_parallel_for_simd_copyin() {
43 int a[N];
44 x3 = 3;
45
46#pragma omp parallel for simd copyin(x3)
47 for (int i = 0; i < N; i++)
48 a[i] = i + x3;
49
50 int sum = 0;
51
52 for (int i = 0; i < N; i++)
53 sum += a[i];
54
55 return (sum == ((99 + 2 * x3) * 100) / 2);
56}
57
58int test_omp_parallel_sections_copyin() {
59 int a = 0;
60 int b = 0;
61 x4 = 4;
62
63#pragma omp parallel sections copyin(x4)
64 {
65#pragma omp section
66 { a = x4; }
67
68#pragma omp section
69 { b = x4; }
70 }
71
72 return (a + b == x4 * 2);
73}
74
75int test_omp_parallel_master_copyin() {
76 int a[N];
77 x5 = 5;
78
79#pragma omp parallel master copyin(x5)
80 for (int i = 0; i < N; i++)
81 a[i] = i + x5;
82
83 int sum = 0;
84
85 for (int i = 0; i < N; i++)
86 sum += a[i];
87
88 return (sum == ((99 + 2 * x5) * 100) / 2);
89}
90
91int main() {
92 int num_failed = 0;
93
94 if (!test_omp_parallel_copyin())
95 num_failed++;
96
97 if (!test_omp_parallel_for_copyin())
98 num_failed++;
99
100 if (!test_omp_parallel_for_simd_copyin())
101 num_failed++;
102
103 if (!test_omp_parallel_sections_copyin())
104 num_failed++;
105
106 if (!test_omp_parallel_master_copyin())
107 num_failed++;
108
109 return num_failed;
110}
111

source code of openmp/runtime/test/parallel/omp_parallel_copyin_combined.c