]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgomp/testsuite/libgomp.oacc-c-c++-common/lib-88.c
Merge current set of OpenACC changes from gomp-4_0-branch.
[thirdparty/gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-88.c
1 /* { dg-do run } */
2
3 #include <stdio.h>
4 #include <pthread.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <ctype.h>
8 #include <openacc.h>
9
10 unsigned char *x;
11 void *d_x;
12 const int N = 256;
13
14 static void *
15 test (void *arg)
16 {
17 int i;
18
19 if (acc_get_current_cuda_context () != NULL)
20 abort ();
21
22 if (acc_is_present (x, N) != 1)
23 abort ();
24
25 memset (x, 0, N);
26
27 acc_copyout (x, N);
28
29 for (i = 0; i < N; i++)
30 {
31 if (x[i] != i)
32 abort ();
33
34 x[i] = N - i - 1;
35 }
36
37 d_x = acc_copyin (x, N);
38
39 return 0;
40 }
41
42 int
43 main (int argc, char **argv)
44 {
45 const int nthreads = 1;
46 int i;
47 pthread_attr_t attr;
48 pthread_t *tid;
49
50 if (acc_get_num_devices (acc_device_nvidia) == 0)
51 return 0;
52
53 acc_init (acc_device_nvidia);
54
55 x = (unsigned char *) malloc (N);
56
57 for (i = 0; i < N; i++)
58 {
59 x[i] = i;
60 }
61
62 d_x = acc_copyin (x, N);
63
64 if (acc_is_present (x, N) != 1)
65 abort ();
66
67 if (pthread_attr_init (&attr) != 0)
68 perror ("pthread_attr_init failed");
69
70 tid = (pthread_t *) malloc (nthreads * sizeof (pthread_t));
71
72 for (i = 0; i < nthreads; i++)
73 {
74 if (pthread_create (&tid[i], &attr, &test, (void *) (unsigned long) (i))
75 != 0)
76 perror ("pthread_create failed");
77 }
78
79 if (pthread_attr_destroy (&attr) != 0)
80 perror ("pthread_attr_destroy failed");
81
82 for (i = 0; i < nthreads; i++)
83 {
84 void *res;
85
86 if (pthread_join (tid[i], &res) != 0)
87 perror ("pthread join failed");
88 }
89
90 if (acc_is_present (x, N) != 1)
91 abort ();
92
93 memset (x, 0, N);
94
95 acc_copyout (x, N);
96
97 for (i = 0; i < N; i++)
98 {
99 if (x[i] != N - i - 1)
100 abort ();
101 }
102
103 if (acc_is_present (x, N) != 0)
104 abort ();
105
106 acc_shutdown (acc_device_nvidia);
107
108 return 0;
109 }
110
111 /* { dg-output "" } */