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

Go to the documentation of this file.
00001 /* { dg-do run } */
00002 
00003 int x, *p = &x;
00004 extern void abort (void);
00005 void
00006 f1 (int *q)
00007 {
00008   *q = 1;
00009 #pragma omp flush
00010   /* x, p, and *q are flushed */
00011   /* because they are shared and accessible */
00012   /* q is not flushed because it is not shared. */
00013 }
00014 
00015 void
00016 f2 (int *q)
00017 {
00018 #pragma omp barrier
00019   *q = 2;
00020 #pragma omp barrier
00021   /*  a barrier implies a flush */
00022   /*  x, p, and *q are flushed */
00023   /*  because they are shared and accessible */
00024   /*  q is not flushed because it is not shared. */
00025 }
00026 
00027 int
00028 g (int n)
00029 {
00030   int i = 1, j, sum = 0;
00031   *p = 1;
00032 #pragma omp parallel reduction(+: sum) num_threads(2)
00033   {
00034     f1 (&j);
00035     /* i, n and sum were not flushed */
00036     /* because they were not accessible in f1 */
00037     /* j was flushed because it was accessible */
00038     sum += j;
00039     f2 (&j);
00040     /* i, n, and sum were not flushed */
00041     /* because they were not accessible in f2 */
00042     /* j was flushed because it was accessible */
00043     sum += i + j + *p + n;
00044   }
00045   return sum;
00046 }
00047 
00048 int
00049 main ()
00050 {
00051   int result = g (10);
00052   if (result != 30)
00053     abort ();
00054   return 0;
00055 }

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