AVR: Assert minimal required bit width of section_common::flags.
[gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / gang-static-2.c
blobe273a797b8e3bb67b2e98cd0b5aa3899a5f2663a
1 #include <assert.h>
2 #include <openacc.h>
3 #include <gomp-constants.h>
5 #define N 100
7 #define GANG_ID(I) \
8 (acc_on_device (acc_device_not_host) \
9 ? __builtin_goacc_parlevel_id (GOMP_DIM_GANG) \
10 : (I))
12 void
13 test_static(int *a, int num_gangs, int sarg)
15 int i, j;
17 if (acc_on_device (acc_device_host))
18 return;
20 if (sarg == 0)
21 sarg = 1;
23 for (i = 0; i < N / sarg; i++)
24 for (j = 0; j < sarg; j++)
25 assert (a[i*sarg+j] == i % num_gangs);
28 void
29 test_nonstatic(int *a, int gangs)
31 int i, j;
33 if (acc_on_device (acc_device_host))
34 return;
36 for (i = 0; i < N; i+=gangs)
37 for (j = 0; j < gangs; j++)
38 assert (a[i+j] == i/gangs);
41 int
42 main ()
44 int a[N];
45 int i, x;
47 #pragma acc parallel loop gang (static:*) num_gangs (10)
48 for (i = 0; i < 100; i++)
49 a[i] = GANG_ID (i);
51 test_nonstatic (a, 10);
53 #pragma acc parallel loop gang (static:1) num_gangs (10)
54 for (i = 0; i < 100; i++)
55 a[i] = GANG_ID (i);
57 test_static (a, 10, 1);
59 #pragma acc parallel loop gang (static:2) num_gangs (10)
60 for (i = 0; i < 100; i++)
61 a[i] = GANG_ID (i);
63 test_static (a, 10, 2);
65 #pragma acc parallel loop gang (static:5) num_gangs (10)
66 for (i = 0; i < 100; i++)
67 a[i] = GANG_ID (i);
69 test_static (a, 10, 5);
71 #pragma acc parallel loop gang (static:20) num_gangs (10)
72 for (i = 0; i < 100; i++)
73 a[i] = GANG_ID (i);
75 test_static (a, 10, 20);
77 /* Non-static gang. */
78 #pragma acc parallel loop gang num_gangs (10)
79 for (i = 0; i < 100; i++)
80 a[i] = GANG_ID (i);
82 test_nonstatic (a, 10);
84 /* Static arguments with a variable expression. */
86 x = 20;
87 #pragma acc parallel loop gang (static:0+x) num_gangs (10)
88 for (i = 0; i < 100; i++)
89 a[i] = GANG_ID (i);
91 test_static (a, 10, 20);
93 x = 20;
94 #pragma acc parallel loop gang (static:x) num_gangs (10)
95 for (i = 0; i < 100; i++)
96 a[i] = GANG_ID (i);
98 test_static (a, 10, 20);
100 return 0;