* es.po: Update.
[official-gcc.git] / libgomp / testsuite / libgomp.c / cancel-for-2.c
blob30cfbb1c502bff11c0aa65e2ec9e90bf7c04b29a
1 /* { dg-do run } */
2 /* { dg-set-target-env-var OMP_CANCELLATION "true" } */
4 #include <stdlib.h>
5 #include <omp.h>
7 __attribute__((noinline, noclone)) int
8 foo (int *x)
10 int v = 0, w = 0;
11 #pragma omp parallel num_threads (32) shared (v, w)
13 int i;
14 #pragma omp for
15 for (i = 0; i < 1000; ++i)
17 #pragma omp cancel for if (x[0])
18 abort ();
20 #pragma omp for
21 for (i = 0; i < 1000; ++i)
23 #pragma omp cancel for if (x[1])
24 #pragma omp atomic
25 v++;
27 #pragma omp for
28 for (i = 0; i < 1000; ++i)
30 #pragma omp cancel for if (x[2])
31 #pragma omp atomic
32 w += 8;
34 #pragma omp for
35 for (i = 0; i < 1000; ++i)
37 #pragma omp cancel for if (x[3])
38 #pragma omp atomic
39 v += 2;
42 if (v != 3000 || w != 0)
43 abort ();
44 #pragma omp parallel num_threads (32) shared (v, w)
46 int i;
47 /* None of these cancel directives should actually cancel anything,
48 but the compiler shouldn't know that and thus should use cancellable
49 barriers at the end of all the workshares. */
50 #pragma omp cancel parallel if (omp_get_thread_num () == 1 && x[4])
51 #pragma omp for
52 for (i = 0; i < 1000; ++i)
54 #pragma omp cancel for if (x[0])
55 abort ();
57 #pragma omp cancel parallel if (omp_get_thread_num () == 2 && x[4])
58 #pragma omp for
59 for (i = 0; i < 1000; ++i)
61 #pragma omp cancel for if (x[1])
62 #pragma omp atomic
63 v++;
65 #pragma omp cancel parallel if (omp_get_thread_num () == 3 && x[4])
66 #pragma omp for
67 for (i = 0; i < 1000; ++i)
69 #pragma omp cancel for if (x[2])
70 #pragma omp atomic
71 w += 8;
73 #pragma omp cancel parallel if (omp_get_thread_num () == 4 && x[4])
74 #pragma omp for
75 for (i = 0; i < 1000; ++i)
77 #pragma omp cancel for if (x[3])
78 #pragma omp atomic
79 v += 2;
81 #pragma omp cancel parallel if (omp_get_thread_num () == 5 && x[4])
83 if (v != 6000 || w != 0)
84 abort ();
85 return 0;
88 int
89 main ()
91 int x[] = { 1, 0, 1, 0, 0 };
92 if (omp_get_cancellation ())
93 foo (x);
94 return 0;