Debian Codegraph @

libgomp/testsuite/libgomp.oacc-c-c++-common/firstprivate-1.c

raw
1 /* { dg-additional-options "-fopt-info-note-omp" }
2 { dg-additional-options "--param=openacc-privatization=noisy" }
3 { dg-additional-options "-foffload=-fopt-info-note-omp" }
4 { dg-additional-options "-foffload=--param=openacc-privatization=noisy" }
5 for testing/documenting aspects of that functionality. */
6
7 /* { dg-additional-options "-Wopenacc-parallelism" } for testing/documenting
8 aspects of that functionality. */
9
10 #include <openacc.h>
11
12
13 void t1 ()
14 {
15 int ok = 1;
16 int val = 2;
17 int ary[32];
18 int ondev = 0;
19
20 for (int i = 0; i < 32; i++)
21 ary[i] = ~0;
22
23 #pragma acc parallel num_gangs (32) copy (ok) firstprivate (val) copy(ary, ondev)
24 /* { dg-note {variable 'i' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-1 } */
25 {
26 ondev = acc_on_device (acc_device_not_host);
27 #pragma acc loop gang(static:1)
28 /* { dg-note {variable 'i' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-1 } */
29 for (unsigned i = 0; i < 32; i++)
30 {
31 if (val != 2)
32 ok = 0;
33 val += i;
34 ary[i] = val;
35 }
36 }
37
38 if (ondev)
39 {
40 if (!ok)
41 __builtin_abort ();
42 if (val != 2)
43 __builtin_abort ();
44
45 for (int i = 0; i < 32; i++)
46 if (ary[i] != 2 + i)
47 __builtin_abort ();
48 }
49 }
50
51
52 void t2 ()
53 {
54 int ok = 1;
55 int val = 2;
56
57 #pragma acc data copy(val)
58 {
59 #pragma acc parallel present (val)
60 {
61 val = 7;
62 }
63
64 #pragma acc parallel firstprivate (val) copy(ok)
65 {
66 ok = val == 7;
67 val = 9;
68 }
69 }
70
71 if (!ok)
72 __builtin_abort ();
73 if (val != 7)
74 __builtin_abort ();
75 }
76
77
78 #define N 100
79 void t3 ()
80 {
81 int a, b[N], c, d, i;
82 int n = acc_get_device_type () != acc_device_host ? N : 1;
83
84 a = 5;
85 for (i = 0; i < n; i++)
86 b[i] = -1;
87
88 #pragma acc parallel num_gangs (n) firstprivate (a)
89 #pragma acc loop gang
90 /* { dg-note {variable 'i' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-1 } */
91 for (i = 0; i < n; i++)
92 {
93 a = a + i;
94 b[i] = a;
95 }
96
97 for (i = 0; i < n; i++)
98 if (a + i != b[i])
99 __builtin_abort ();
100
101 #pragma acc data copy (a)
102 {
103 #pragma acc parallel firstprivate (a) copyout (c)
104 {
105 a = 10;
106 c = a;
107 }
108
109 /* This version of 'a' should still be 5. */
110 #pragma acc parallel copyout (d) present (a)
111 {
112 d = a;
113 }
114 }
115
116 if (c != 10)
117 __builtin_abort ();
118 if (d != 5)
119 __builtin_abort ();
120 }
121 #undef N
122
123
124 void t4 ()
125 {
126 int x = 5, i, arr[32];
127
128 for (i = 0; i < 32; i++)
129 arr[i] = 3;
130
131 #pragma acc parallel firstprivate(x) copy(arr) num_gangs(32) num_workers(8) vector_length(32)
132 /* { dg-warning "region is worker partitioned but does not contain worker partitioned code" "" { target *-*-* } .-1 } */
133 /* { dg-warning "region is vector partitioned but does not contain vector partitioned code" "" { target *-*-* } .-2 } */
134 {
135 #pragma acc loop gang
136 /* { dg-note {variable 'i' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-1 } */
137 for (i = 0; i < 32; i++)
138 arr[i] += x;
139 }
140
141 for (i = 0; i < 32; i++)
142 if (arr[i] != 8)
143 __builtin_abort ();
144 }
145
146
147 int
148 main()
149 {
150 t1 ();
151 t2 ();
152 t3 ();
153 t4 ();
154
155 return 0;
156 }