testsuite/libgomp.c/pr26943-4.c

Go to the documentation of this file.
00001 /* PR c++/26943 */
00002 /* { dg-do run } */
00003 
00004 extern int omp_set_dynamic (int);
00005 extern int omp_get_thread_num (void);
00006 extern void abort (void);
00007 
00008 int a = 8, b = 12, c = 16, d = 20, j = 0, l = 0;
00009 char e[10] = "a", f[10] = "b", g[10] = "c", h[10] = "d";
00010 volatile int k;
00011 
00012 int
00013 main (void)
00014 {
00015   int i;
00016   omp_set_dynamic (0);
00017   omp_set_nested (1);
00018 #pragma omp parallel num_threads (2) reduction (+:l) \
00019              firstprivate (a, b, c, d, e, f, g, h, j)
00020   if (k == omp_get_thread_num ())
00021     {
00022 #pragma omp parallel for shared (a, e) firstprivate (b, f) \
00023              lastprivate (c, g) private (d, h) \
00024              schedule (static, 1) num_threads (4) \
00025              reduction (+:j)
00026       for (i = 0; i < 4; i++)
00027     {
00028       if (a != 8 || b != 12 || e[0] != 'a' || f[0] != 'b')
00029         j++;
00030 #pragma omp barrier /* { dg-warning "may not be closely nested" } */
00031 #pragma omp atomic
00032       a += i;
00033       b += i;
00034       c = i;
00035       d = i;
00036 #pragma omp atomic
00037       e[0] += i;
00038       f[0] += i;
00039       g[0] = 'g' + i;
00040       h[0] = 'h' + i;
00041 #pragma omp barrier /* { dg-warning "may not be closely nested" } */
00042       if (a != 8 + 6 || b != 12 + i || c != i || d != i)
00043         j += 8;
00044       if (e[0] != 'a' + 6 || f[0] != 'b' + i || g[0] != 'g' + i)
00045         j += 64;
00046       if (h[0] != 'h' + i)
00047         j += 512;
00048     }
00049       if (j || a != 8 + 6 || b != 12 || c != 3 || d != 20)
00050     ++l;
00051       if (e[0] != 'a' + 6 || f[0] != 'b' || g[0] != 'g' + 3 || h[0] != 'd')
00052     l += 8;
00053     }
00054   if (l)
00055     abort ();
00056   if (a != 8 || b != 12 || c != 16 || d != 20)
00057     abort ();
00058   if (e[0] != 'a' || f[0] != 'b' || g[0] != 'c' || h[0] != 'd')
00059     abort ();
00060   return 0;
00061 }

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