gcc/
[official-gcc.git] / libgomp / testsuite / libgomp.c / cancel-parallel-2.c
blobcae0aa45c0f8152565c8d90fec46914f178e4b61
1 /* { dg-do run } */
2 /* { dg-set-target-env-var OMP_CANCELLATION "true" } */
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <omp.h>
8 static void
9 foo (int *x)
11 #pragma omp parallel firstprivate(x) num_threads (32)
13 int thr = omp_get_thread_num ();
14 switch (x[thr])
16 case 4:
17 #pragma omp cancel parallel
18 break;
19 case 3:
20 #pragma omp task
21 usleep (1000);
22 #pragma omp task
23 usleep (2000);
24 #pragma omp task
25 usleep (4000);
26 break;
27 case 2:
28 usleep (1000);
29 /* FALLTHRU */
30 case 1:
31 #pragma omp cancellation point parallel
32 break;
34 #pragma omp barrier
35 if (omp_get_cancellation ())
36 abort ();
40 int
41 main ()
43 int i, j, x[32] = { 0, 1, 2, 4, 2, 2, 1, 0 };
44 foo (x);
45 for (i = 0; i < 32; i++)
47 for (j = 0; j < 32; j++)
48 x[j] = rand () & 3;
49 x[rand () & 31] = 4;
50 foo (x);
52 return 0;