C++: simplify output from suggest_alternatives_for
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-92.c
blob18193e0e8f945dba2bd0c12510df044fb72ec6ab
1 /* { dg-do run } */
3 #include <pthread.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <errno.h>
7 #include <ctype.h>
8 #include <openacc.h>
10 unsigned char **x;
11 void **d_x;
12 const int N = 32;
13 const int NTHREADS = 32;
15 static void *
16 test (void *arg)
18 int i;
19 int tid;
20 unsigned char *p;
21 int devnum;
23 tid = (int) (long) arg;
25 devnum = acc_get_device_num (acc_device_nvidia);
26 acc_set_device_num (devnum, acc_device_nvidia);
28 if (acc_get_current_cuda_context () == NULL)
29 abort ();
31 acc_copyout (x[tid], N);
33 p = x[tid];
35 for (i = 0; i < N; i++)
37 if (p[i] != i)
38 abort ();
41 return 0;
44 int
45 main (int argc, char **argv)
47 int i;
48 pthread_attr_t attr;
49 pthread_t *tid;
50 unsigned char *p;
52 if (acc_get_num_devices (acc_device_nvidia) == 0)
53 return 0;
55 acc_init (acc_device_nvidia);
57 x = (unsigned char **) malloc (NTHREADS * N);
58 d_x = (void **) malloc (NTHREADS * N);
60 for (i = 0; i < N; i++)
62 int j;
64 p = (unsigned char *) malloc (N);
66 x[i] = p;
68 for (j = 0; j < N; j++)
70 p[j] = j;
73 d_x[i] = acc_copyin (p, N);
76 if (pthread_attr_init (&attr) != 0)
77 perror ("pthread_attr_init failed");
79 tid = (pthread_t *) malloc (NTHREADS * sizeof (pthread_t));
81 acc_get_cuda_stream (1);
83 for (i = 0; i < NTHREADS; i++)
85 if (pthread_create (&tid[i], &attr, &test, (void *) (unsigned long) (i))
86 != 0)
87 perror ("pthread_create failed");
90 if (pthread_attr_destroy (&attr) != 0)
91 perror ("pthread_attr_destroy failed");
93 for (i = 0; i < NTHREADS; i++)
95 void *res;
97 if (pthread_join (tid[i], &res) != 0)
98 perror ("pthread join failed");
101 for (i = 0; i < NTHREADS; i++)
103 if (acc_is_present (x[i], N) != 0)
104 abort ();
107 acc_shutdown (acc_device_nvidia);
109 return 0;
112 /* { dg-output "" } */