testsuite/libgomp.c/appendix-a/a.16.1.c

Go to the documentation of this file.
00001 /* { dg-do run } */
00002 
00003 #include <stdio.h>
00004 
00005 float
00006 work1 (int i)
00007 {
00008   return 1.0 * i;
00009 }
00010 
00011 float
00012 work2 (int i)
00013 {
00014   return 2.0 * i;
00015 }
00016 
00017 void
00018 a16 (float *x, float *y, int *index, int n)
00019 {
00020   int i;
00021 #pragma omp parallel for shared(x, y, index, n)
00022   for (i = 0; i < n; i++)
00023     {
00024 #pragma omp atomic
00025       x[index[i]] += work1 (i);
00026       y[i] += work2 (i);
00027     }
00028 }
00029 int
00030 main ()
00031 {
00032   float x[1000];
00033   float y[10000];
00034   int index[10000];
00035   int i;
00036   for (i = 0; i < 10000; i++)
00037     {
00038       index[i] = i % 1000;
00039       y[i] = 0.0;
00040     }
00041   for (i = 0; i < 1000; i++)
00042     x[i] = 0.0;
00043   a16 (x, y, index, 10000);
00044   for (i = 0; i < 10; i++)
00045     printf ("x[%d] = %f, y[%d] = %f\n", i, x[i], i, y[i]);
00046   return 0;
00047 }

Generated on Fri Apr 5 05:38:10 2013 for Libgomp by  doxygen 1.4.7