12 sum_nodes (struct node
*head
)
16 #pragma acc parallel reduction(+:sum) present(head[:1])
18 for (; head
!= NULL
; head
= head
->next
)
26 insert (struct node
*head
, int val
)
28 struct node
*n
= (struct node
*) malloc (sizeof (struct node
));
31 acc_detach ((void **) &head
->next
);
37 acc_copyin (n
, sizeof (struct node
));
38 acc_attach((void **) &head
->next
);
41 acc_attach ((void **) &n
->next
);
45 destroy (struct node
*head
)
47 while (head
->next
!= NULL
)
49 acc_detach ((void **) &head
->next
);
50 struct node
* n
= head
->next
;
53 acc_detach ((void **) &n
->next
);
55 acc_delete (n
, sizeof (struct node
));
57 acc_attach((void **) &head
->next
);
66 struct node list
= { .next
= NULL
, .val
= 0 };
69 acc_copyin (&list
, sizeof (struct node
));
71 for (i
= 0; i
< 10; i
++)
74 assert (sum_nodes (&list
) == 10 * 2);
78 acc_delete (&list
, sizeof (struct node
));