2 /* { dg-options "-O2 -fopenmp" } */
3 /* { dg-require-effective-target tls_runtime } */
10 #pragma omp threadprivate (cnt)
13 nqueens (char *a, int n, int pos)
15 /* b[i] = j means the queen in i-th row is in column j. */
19 for (i = 0; i < n; i++)
21 for (j = 0; j < pos; j++)
22 if (b[j] == i || b[j] == i + pos - j || i == b[j] + pos - j)
27 /* Found a solution. Could output it here. */
33 nqueens (b, n, pos + 1);
39 main (int argc, char **argv)
43 n = strtoul (argv[1], NULL, 0);
46 fprintf (stderr, "invalid count %d\n", n);
50 double stime = omp_get_wtime ();
52 printf ("serial N %d solutions # %d time %f\n", n, cnt, omp_get_wtime () - stime);
55 stime = omp_get_wtime ();
57 #pragma omp parallel reduction (+:tempcnt)
64 printf ("parallel N %d solutions # %d time %f\n", n, cnt, omp_get_wtime () - stime);