Debian Codegraph @

libgomp/testsuite/libgomp.c/pr81778.c

raw
1 /* Minimized from for-5.c. */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 /* Size of array we want to write. */
7 #define N 32
8
9 /* Size of extra space before and after. */
10 #define CANARY_SIZE (N * 32)
11
12 /* Start of array we want to write. */
13 #define BASE (CANARY_SIZE)
14
15 // Total size to be allocated.
16 #define ALLOC_SIZE (CANARY_SIZE + N + CANARY_SIZE)
17
18 #pragma omp declare target
19 int a[ALLOC_SIZE];
20 #pragma omp end declare target
21
22 int
23 main (void)
24 {
25 /* Use variable step in for loop. */
26 int s = 1;
27
28 #pragma omp target update to(a)
29
30 /* Write a[BASE] .. a[BASE + N - 1]. */
31 #pragma omp target simd
32 for (int i = N - 1; i > -1; i -= s)
33 a[BASE + i] = 1;
34
35 #pragma omp target update from(a)
36
37 for (int i = 0; i < ALLOC_SIZE; i++)
38 {
39 int expected = (BASE <= i && i < BASE + N) ? 1 : 0;
40 if (a[i] == expected)
41 continue;
42
43 printf ("Expected %d, got %d at base[%d]\n", expected, a[i], i - BASE);
44 abort ();
45 }
46
47 return 0;
48 }