Update 'Q' constraint documentation.
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / data-firstprivate-1.c
blob8900a4e070da1d7ccc5b31427485e92e02e844d8
1 /* Test behavior of 'firstprivate' lexically vs. dynamically nested inside a
2 'data' region. */
4 #include <stdlib.h>
7 #define VERIFY(x) \
8 do { \
9 if (!(x)) \
10 abort (); \
11 } while (0);
14 /* This is basically and extended version of 't2' from 'firstprivate-1.c'. */
16 int lexically_nested_val = 2;
18 static void
19 lexically_nested ()
21 #pragma acc data \
22 copy (lexically_nested_val)
24 VERIFY (lexically_nested_val == 2);
26 #pragma acc parallel \
27 present (lexically_nested_val)
29 VERIFY (lexically_nested_val == 2);
31 /* This updates the device copy, or shared variable. */
32 lexically_nested_val = 7;
35 #if ACC_MEM_SHARED
36 VERIFY (lexically_nested_val == 7);
37 #else
38 VERIFY (lexically_nested_val == 2);
39 #endif
41 /* This only updates the local/shared variable, but not the device
42 copy. */
43 lexically_nested_val = 5;
45 #pragma acc parallel \
46 firstprivate (lexically_nested_val)
48 #if 1 /* Current behavior. */
49 /* The 'firstprivate' copy is initialized from the device copy, or
50 shared variable. */
51 # if ACC_MEM_SHARED
52 VERIFY (lexically_nested_val == 5);
53 # else
54 VERIFY (lexically_nested_val == 7);
55 # endif
56 #else /* Expected behavior per PR92036. */
57 /* The 'firstprivate' copy is initialized from the local thread. */
58 VERIFY (lexically_nested_val == 5);
59 #endif
61 /* This updates the 'firstprivate' copy only, but not the shared
62 variable. */
63 lexically_nested_val = 9;
66 VERIFY (lexically_nested_val == 5);
68 /* If not shared, the device copy has now been copied back. */
70 #if ACC_MEM_SHARED
71 VERIFY (lexically_nested_val == 5);
72 #else
73 VERIFY (lexically_nested_val == 7);
74 #endif
78 int dynamically_nested_val = 2;
80 /* Same as above, but compute construct 1 broken out, so no longer lexically
81 nested inside 'data' region. */
83 static void
84 dynamically_nested_compute_1 ()
86 #pragma acc parallel \
87 present (dynamically_nested_val)
89 VERIFY (dynamically_nested_val == 2);
91 /* This updates the device copy, or shared variable. */
92 dynamically_nested_val = 7;
96 /* Same as above, but compute construct 2 broken out, so no longer lexically
97 nested inside 'data' region. */
99 static void
100 dynamically_nested_compute_2 ()
102 #pragma acc parallel \
103 firstprivate (dynamically_nested_val)
105 #if 1 /* Current behavior. */
106 /* The 'firstprivate' copy is initialized from the device copy, or shared
107 variable. */
108 # if ACC_MEM_SHARED
109 VERIFY (dynamically_nested_val == 5);
110 # else
111 VERIFY (dynamically_nested_val == 7);
112 # endif
113 #else /* Expected behavior per PR92036. */
114 /* The 'firstprivate' copy is initialized from the local thread. */
115 VERIFY (dynamically_nested_val == 5);
116 #endif
118 /* This updates the 'firstprivate' copy only, but not the shared
119 variable. */
120 dynamically_nested_val = 9;
124 static void
125 dynamically_nested ()
127 #pragma acc data \
128 copy (dynamically_nested_val)
130 VERIFY (dynamically_nested_val == 2);
132 dynamically_nested_compute_1 ();
134 #if ACC_MEM_SHARED
135 VERIFY (dynamically_nested_val == 7);
136 #else
137 VERIFY (dynamically_nested_val == 2);
138 #endif
140 /* This only updates the local/shared variable, but not the device
141 copy. */
142 dynamically_nested_val = 5;
144 dynamically_nested_compute_2 ();
146 VERIFY (dynamically_nested_val == 5);
148 /* If not shared, the device copy has now been copied back. */
150 #if ACC_MEM_SHARED
151 VERIFY (dynamically_nested_val == 5);
152 #else
153 VERIFY (dynamically_nested_val == 7);
154 #endif
159 main()
161 lexically_nested ();
162 dynamically_nested ();
164 return 0;