1 /* { dg-do run } */
2
3 #include <stdio.h>
4
5 float
work1(int i)6 work1 (int i)
7 {
8 return 1.0 * i;
9 }
10
11 float
work2(int i)12 work2 (int i)
13 {
14 return 2.0 * i;
15 }
16
17 void
a16(float * x,float * y,int * index,int n)18 a16 (float *x, float *y, int *index, int n)
19 {
20 int i;
21 #pragma omp parallel for shared(x, y, index, n)
22 for (i = 0; i < n; i++)
23 {
24 #pragma omp atomic
25 x[index[i]] += work1 (i);
26 y[i] += work2 (i);
27 }
28 }
29 int
main()30 main ()
31 {
32 float x[1000];
33 float y[10000];
34 int index[10000];
35 int i;
36 for (i = 0; i < 10000; i++)
37 {
38 index[i] = i % 1000;
39 y[i] = 0.0;
40 }
41 for (i = 0; i < 1000; i++)
42 x[i] = 0.0;
43 a16 (x, y, index, 10000);
44 for (i = 0; i < 10; i++)
45 printf ("x[%d] = %f, y[%d] = %f\n", i, x[i], i, y[i]);
46 return 0;
47 }
48