Set num_threads to 50 on 32-bit hppa in two libgomp loop tests
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-89.c
blob6b4e3acf7dbded041408b807566e44d268459bbb
1 /* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
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_default);
27 acc_set_device_num (devnum, acc_device_default);
29 #if ACC_DEVICE_TYPE_nvidia
30 if (acc_get_current_cuda_context () == NULL)
31 abort ();
32 #else
33 if (acc_get_current_cuda_context () != NULL)
34 abort ();
35 #endif
37 p = (unsigned char *) malloc (N);
39 for (i = 0; i < N; i++)
41 p[i] = tid;
44 x[tid] = p;
46 d_x[tid] = acc_copyin (p, N);
48 return 0;
51 int
52 main (int argc, char **argv)
54 int i;
55 pthread_attr_t attr;
56 pthread_t *tid;
58 acc_init (acc_device_default);
60 x = (unsigned char **) malloc (NTHREADS * N);
61 d_x = (void **) malloc (NTHREADS * N);
63 if (pthread_attr_init (&attr) != 0)
64 perror ("pthread_attr_init failed");
66 tid = (pthread_t *) malloc (NTHREADS * sizeof (pthread_t));
68 for (i = 0; i < NTHREADS; i++)
70 if (pthread_create (&tid[i], &attr, &test, (void *) (unsigned long) (i))
71 != 0)
72 perror ("pthread_create failed");
75 if (pthread_attr_destroy (&attr) != 0)
76 perror ("pthread_attr_destroy failed");
78 for (i = 0; i < NTHREADS; i++)
80 void *res;
82 if (pthread_join (tid[i], &res) != 0)
83 perror ("pthread join failed");
86 for (i = 0; i < NTHREADS; i++)
88 if (acc_is_present (x[i], N) != 1)
89 abort ();
92 for (i = 0; i < NTHREADS; i++)
94 memset (x[i], 0, N);
95 acc_copyout (x[i], N);
98 for (i = 0; i < NTHREADS; i++)
100 unsigned char *p;
101 int j;
103 p = x[i];
105 for (j = 0; j < N; j++)
107 if (p[j] != i)
108 abort ();
111 if (acc_is_present (x[i], N) != 0)
112 abort ();
115 return 0;
118 /* { dg-output "" } */