Check CXXFLAGS, instead of CFLAGS, for NO_PIE_CFLAGS
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-89.c
blob061c4099c2dad5eb81f9b60ffb300717e52a03bf
1 /* { dg-do run } */
3 #include <stdio.h>
4 #include <pthread.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <errno.h>
8 #include <ctype.h>
9 #include <openacc.h>
11 unsigned char **x;
12 void **d_x;
13 const int N = 16;
14 const int NTHREADS = 32;
16 static void *
17 test (void *arg)
19 int i;
20 int tid;
21 unsigned char *p;
22 int devnum;
24 tid = (int) (long) arg;
26 devnum = acc_get_device_num (acc_device_nvidia);
27 acc_set_device_num (devnum, acc_device_nvidia);
29 if (acc_get_current_cuda_context () == NULL)
30 abort ();
32 p = (unsigned char *) malloc (N);
34 for (i = 0; i < N; i++)
36 p[i] = tid;
39 x[tid] = p;
41 d_x[tid] = acc_copyin (p, N);
43 return 0;
46 int
47 main (int argc, char **argv)
49 int i;
50 pthread_attr_t attr;
51 pthread_t *tid;
53 if (acc_get_num_devices (acc_device_nvidia) == 0)
54 return 0;
56 acc_init (acc_device_nvidia);
58 x = (unsigned char **) malloc (NTHREADS * N);
59 d_x = (void **) malloc (NTHREADS * N);
61 if (pthread_attr_init (&attr) != 0)
62 perror ("pthread_attr_init failed");
64 tid = (pthread_t *) malloc (NTHREADS * sizeof (pthread_t));
66 for (i = 0; i < NTHREADS; i++)
68 if (pthread_create (&tid[i], &attr, &test, (void *) (unsigned long) (i))
69 != 0)
70 perror ("pthread_create failed");
73 if (pthread_attr_destroy (&attr) != 0)
74 perror ("pthread_attr_destroy failed");
76 for (i = 0; i < NTHREADS; i++)
78 void *res;
80 if (pthread_join (tid[i], &res) != 0)
81 perror ("pthread join failed");
84 for (i = 0; i < NTHREADS; i++)
86 if (acc_is_present (x[i], N) != 1)
87 abort ();
90 for (i = 0; i < NTHREADS; i++)
92 memset (x[i], 0, N);
93 acc_copyout (x[i], N);
96 for (i = 0; i < NTHREADS; i++)
98 unsigned char *p;
99 int j;
101 p = x[i];
103 for (j = 0; j < N; j++)
105 if (p[j] != i)
106 abort ();
109 if (acc_is_present (x[i], N) != 0)
110 abort ();
113 acc_shutdown (acc_device_nvidia);
115 return 0;
118 /* { dg-output "" } */