Improve atomic store implementation on hppa-linux.
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / deep-copy-5.c
blob89cafbb62abbf2d4467ca03dbfb1684d9858d54e
1 #include <assert.h>
2 #include <stdlib.h>
3 #include <openacc.h>
5 struct node
7 struct node *next;
8 int val;
9 };
11 int
12 sum_nodes (struct node *head)
14 int i = 0, sum = 0;
16 #pragma acc parallel reduction(+:sum) present(head[:1])
18 for (; head != NULL; head = head->next)
19 sum += head->val;
22 return sum;
25 void
26 insert (struct node *head, int val)
28 struct node *n = (struct node *) malloc (sizeof (struct node));
30 if (head->next)
31 acc_detach ((void **) &head->next);
33 n->val = val;
34 n->next = head->next;
35 head->next = n;
37 acc_copyin (n, sizeof (struct node));
38 acc_attach((void **) &head->next);
40 if (n->next)
41 acc_attach ((void **) &n->next);
44 void
45 destroy (struct node *head)
47 while (head->next != NULL)
49 acc_detach ((void **) &head->next);
50 struct node * n = head->next;
51 head->next = n->next;
52 if (n->next)
53 acc_detach ((void **) &n->next);
55 acc_delete (n, sizeof (struct node));
56 if (head->next)
57 acc_attach((void **) &head->next);
59 free (n);
63 int
64 main ()
66 struct node list = { .next = NULL, .val = 0 };
67 int i;
69 acc_copyin (&list, sizeof (struct node));
71 for (i = 0; i < 10; i++)
72 insert (&list, 2);
74 assert (sum_nodes (&list) == 10 * 2);
76 destroy (&list);
78 acc_delete (&list, sizeof (struct node));
80 return 0;