1 /* Verify back to back 'async' operations, two data mappings.
2
3 Make sure that despite two data mappings, this isn't using the libgomp
4 'cbuf' buffering.
5 */
6
7
8 #include <stdlib.h>
9
10
11 #define N 128
12
13
14 static void
15 t1 (void)
16 {
17 unsigned int *a, *b;
18 int i;
19 int nbytes;
20
21 nbytes = N * sizeof (unsigned int);
22
23 a = (unsigned int *) malloc (nbytes);
24 b = (unsigned int *) malloc (nbytes);
25
26 for (i = 0; i < N; i++)
27 b[i] = a[i] = 3;
28
29 #pragma acc parallel async copy (a[0:N], b[0:N])
30 for (int ii = 0; ii < N; ii++)
31 b[ii] += (a[ii] += 1);
32
33 #pragma acc parallel async copy (a[0:N], b[0:N])
34 for (int ii = 0; ii < N; ii++)
35 b[ii] += (a[ii] += 1);
36
37 #pragma acc wait
38
39 for (i = 0; i < N; i++)
40 {
41 if (a[i] != 5)
42 abort ();
43 if (b[i] != 12)
44 abort ();
45 }
46 }
47
48
49 static void
50 t2 (void)
51 {
52 unsigned int *a, *b;
53 int i;
54 int nbytes;
55
56 nbytes = N * sizeof (unsigned int);
57
58 a = (unsigned int *) malloc (nbytes);
59 b = (unsigned int *) malloc (nbytes);
60
61 #pragma acc data copyin (a[0:N], b[0:N])
62 {
63 for (i = 0; i < N; i++)
64 b[i] = a[i] = 3;
65
66 #pragma acc update async device (a[0:N], b[0:N])
67 #pragma acc parallel async present (a[0:N], b[0:N])
68 for (int ii = 0; ii < N; ii++)
69 b[ii] += (a[ii] += 1);
70 #pragma acc update async host (a[0:N], b[0:N])
71
72 #pragma acc update async device (a[0:N], b[0:N])
73 #pragma acc parallel async present (a[0:N], b[0:N])
74 for (int ii = 0; ii < N; ii++)
75 b[ii] += (a[ii] += 1);
76 #pragma acc update async host (a[0:N], b[0:N])
77
78 #pragma acc wait
79 }
80
81 for (i = 0; i < N; i++)
82 {
83 if (a[i] != 5)
84 abort ();
85 if (b[i] != 12)
86 abort ();
87 }
88 }
89
90
91 int
92 main (void)
93 {
94 t1 ();
95
96 t2 ();
97
98 return 0;
99 }