AVR: Assert minimal required bit width of section_common::flags.
[gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / structured-dynamic-lifetimes-1.c
blob0d6b4159ad0909c4ce878d8e4feaef062561165d
1 /* Test transitioning of data lifetimes between structured and dynamic. */
3 /* { dg-skip-if "" { *-*-* } { "-DACC_MEM_SHARED=1" } } */
5 #include <openacc.h>
6 #include <assert.h>
7 #include <stdlib.h>
9 #define SIZE 1024
11 void
12 f1 (void)
14 char *block1 = (char *) malloc (SIZE);
16 #ifdef OPENACC_API
17 acc_copyin (block1, SIZE);
18 acc_copyin (block1, SIZE);
19 #else
20 #pragma acc enter data copyin(block1[0:SIZE])
21 #pragma acc enter data copyin(block1[0:SIZE])
22 #endif
24 #pragma acc data copy(block1[0:SIZE])
26 #ifdef OPENACC_API
27 acc_copyin (block1, SIZE);
28 #else
29 #pragma acc enter data copyin(block1[0:SIZE])
30 #endif
33 assert (acc_is_present (block1, SIZE));
35 #ifdef OPENACC_API
36 acc_copyout (block1, SIZE);
37 assert (acc_is_present (block1, SIZE));
38 acc_copyout (block1, SIZE);
39 assert (acc_is_present (block1, SIZE));
40 acc_copyout (block1, SIZE);
41 assert (!acc_is_present (block1, SIZE));
42 #else
43 #pragma acc exit data copyout(block1[0:SIZE])
44 assert (acc_is_present (block1, SIZE));
45 #pragma acc exit data copyout(block1[0:SIZE])
46 assert (acc_is_present (block1, SIZE));
47 #pragma acc exit data copyout(block1[0:SIZE])
48 assert (!acc_is_present (block1, SIZE));
49 #endif
51 free (block1);
54 void
55 f2 (void)
57 char *block1 = (char *) malloc (SIZE);
59 #ifdef OPENACC_API
60 acc_copyin (block1, SIZE);
61 #else
62 #pragma acc enter data copyin(block1[0:SIZE])
63 #endif
65 #pragma acc data copy(block1[0:SIZE])
67 #ifdef OPENACC_API
68 acc_copyout (block1, SIZE);
69 #else
70 #pragma acc exit data copyout(block1[0:SIZE])
71 #endif
72 /* This should stay present until the end of the structured data
73 lifetime. */
74 assert (acc_is_present (block1, SIZE));
77 assert (!acc_is_present (block1, SIZE));
79 free (block1);
82 void
83 f3 (void)
85 char *block1 = (char *) malloc (SIZE);
87 #ifdef OPENACC_API
88 acc_copyin (block1, SIZE);
89 #else
90 #pragma acc enter data copyin(block1[0:SIZE])
91 #endif
93 #pragma acc data copy(block1[0:SIZE])
95 #ifdef OPENACC_API
96 acc_copyout (block1, SIZE);
97 acc_copyin (block1, SIZE);
98 #else
99 #pragma acc exit data copyout(block1[0:SIZE])
100 #pragma acc enter data copyin(block1[0:SIZE])
101 #endif
102 assert (acc_is_present (block1, SIZE));
105 assert (acc_is_present (block1, SIZE));
106 #ifdef OPENACC_API
107 acc_copyout (block1, SIZE);
108 #else
109 #pragma acc exit data copyout(block1[0:SIZE])
110 #endif
111 assert (!acc_is_present (block1, SIZE));
113 free (block1);
116 void
117 f4 (void)
119 char *block1 = (char *) malloc (SIZE);
120 char *block2 = (char *) malloc (SIZE);
121 char *block3 = (char *) malloc (SIZE);
123 #pragma acc data copy(block1[0:SIZE], block2[0:SIZE], block3[0:SIZE])
125 /* The first copyin of block2 is the enclosing data region. This
126 "enter data" should make it live beyond the end of this region.
127 This works, though the on-target copies of block1, block2 and block3
128 will stay allocated until block2 is unmapped because they are bound
129 together in a single target_mem_desc. */
130 #ifdef OPENACC_API
131 acc_copyin (block2, SIZE);
132 #else
133 #pragma acc enter data copyin(block2[0:SIZE])
134 #endif
137 assert (!acc_is_present (block1, SIZE));
138 assert (acc_is_present (block2, SIZE));
139 assert (!acc_is_present (block3, SIZE));
141 #ifdef OPENACC_API
142 acc_copyout (block2, SIZE);
143 #else
144 #pragma acc exit data copyout(block2[0:SIZE])
145 #endif
146 assert (!acc_is_present (block2, SIZE));
148 free (block1);
149 free (block2);
150 free (block3);
154 main (int argc, char *argv[])
156 f1 ();
157 f2 ();
158 f3 ();
159 f4 ();
160 return 0;