testsuite/libgomp.c/vla-1.c

Go to the documentation of this file.
00001 /* { dg-do run } */
00002 
00003 #include <omp.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 
00007 int
00008 main (int argc, char **argv[])
00009 {
00010   int n = argc < 5 ? 12 : 31, i, m, l;
00011   char a[n + 3];
00012   unsigned short b[n / 2 - 1];
00013   int c[n * 2 + 1];
00014 
00015   for (i = 0; i < n + 3; i++)
00016     a[i] = i;
00017   for (i = 0; i < n / 2 - 1; i++)
00018     b[i] = (i << 8) | i;
00019   for (i = 0; i < n * 2 + 1; i++)
00020     c[i] = (i << 24) | i;
00021   l = 0;
00022   m = n;
00023 #pragma omp parallel default (shared) num_threads (4) \
00024   firstprivate (a, m) private (b, i) reduction (+:l)
00025   {
00026     for (i = 0; i < m + 3; i++)
00027       if (a[i] != i)
00028     l++;
00029     for (i = 0; i < m * 2 + 1; i++)
00030       if (c[i] != ((i << 24) | i))
00031     l++;
00032 #pragma omp barrier
00033     memset (a, omp_get_thread_num (), m + 3);
00034     for (i = 0; i < m / 2 - 1; i++)
00035       b[i] = a[0] + 7;
00036 #pragma omp master
00037     {
00038       for (i = 0; i < m * 2 + 1; i++)
00039     c[i] = a[0] + 16;
00040     }
00041 #pragma omp barrier
00042     if (a[0] != omp_get_thread_num ())
00043       l++;
00044     for (i = 1; i < m + 3; i++)
00045       if (a[i] != a[0])
00046     l++;
00047     for (i = 0; i < m / 2 - 1; i++)
00048       if (b[i] != a[0] + 7)
00049     l++;
00050     for (i = 0; i < m * 2 + 1; i++)
00051       if (c[i] != 16)
00052     l++;
00053   }
00054   if (l)
00055     abort ();
00056   for (i = 0; i < n * 2 + 1; i++)
00057     if (c[i] != 16)
00058       l++;
00059   return 0;
00060 }

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