* tree-ssa-loop-ivopts.c (relate_compare_use_with_all_cands): Handle
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-88.c
blob10f4ad8664aa087626ddf302c4903a9a7888f1a9
1 /* { dg-do run } */
3 #include <stdio.h>
4 #include <pthread.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <ctype.h>
8 #include <openacc.h>
10 unsigned char *x;
11 void *d_x;
12 const int N = 256;
14 static void *
15 test (void *arg)
17 int i;
19 if (acc_get_current_cuda_context () != NULL)
20 abort ();
22 if (acc_is_present (x, N) != 1)
23 abort ();
25 memset (x, 0, N);
27 acc_copyout (x, N);
29 for (i = 0; i < N; i++)
31 if (x[i] != i)
32 abort ();
34 x[i] = N - i - 1;
37 d_x = acc_copyin (x, N);
39 return 0;
42 int
43 main (int argc, char **argv)
45 const int nthreads = 1;
46 int i;
47 pthread_attr_t attr;
48 pthread_t *tid;
50 if (acc_get_num_devices (acc_device_nvidia) == 0)
51 return 0;
53 acc_init (acc_device_nvidia);
55 x = (unsigned char *) malloc (N);
57 for (i = 0; i < N; i++)
59 x[i] = i;
62 d_x = acc_copyin (x, N);
64 if (acc_is_present (x, N) != 1)
65 abort ();
67 if (pthread_attr_init (&attr) != 0)
68 perror ("pthread_attr_init failed");
70 tid = (pthread_t *) malloc (nthreads * sizeof (pthread_t));
72 for (i = 0; i < nthreads; i++)
74 if (pthread_create (&tid[i], &attr, &test, (void *) (unsigned long) (i))
75 != 0)
76 perror ("pthread_create failed");
79 if (pthread_attr_destroy (&attr) != 0)
80 perror ("pthread_attr_destroy failed");
82 for (i = 0; i < nthreads; i++)
84 void *res;
86 if (pthread_join (tid[i], &res) != 0)
87 perror ("pthread join failed");
90 if (acc_is_present (x, N) != 1)
91 abort ();
93 memset (x, 0, N);
95 acc_copyout (x, N);
97 for (i = 0; i < N; i++)
99 if (x[i] != N - i - 1)
100 abort ();
103 if (acc_is_present (x, N) != 0)
104 abort ();
106 acc_shutdown (acc_device_nvidia);
108 return 0;
111 /* { dg-output "" } */