Update concepts branch to revision 131834
[official-gcc.git] / libgomp / testsuite / libgomp.c / nested-3.c
blob618600633ac2e89a674654dc5ac30a809d4c42d5
1 #include <omp.h>
2 #include <stdlib.h>
3 #include <string.h>
5 int
6 main (void)
8 int e[3];
10 memset (e, '\0', sizeof (e));
11 omp_set_nested (1);
12 omp_set_dynamic (0);
13 if (omp_in_parallel ()
14 || omp_get_level () != 0
15 || omp_get_ancestor_thread_num (0) != 0
16 || omp_get_ancestor_thread_num (-1) != -1
17 || omp_get_ancestor_thread_num (1) != -1
18 || omp_get_team_size (0) != 1
19 || omp_get_team_size (-1) != -1
20 || omp_get_team_size (1) != -1
21 || omp_get_active_level () != 0)
22 abort ();
23 #pragma omp parallel num_threads (4)
25 int tn1 = omp_get_thread_num ();
26 if (omp_in_parallel () != 1
27 || omp_get_num_threads () != 4
28 || tn1 >= 4 || tn1 < 0
29 || omp_get_level () != 1
30 || omp_get_ancestor_thread_num (0) != 0
31 || omp_get_ancestor_thread_num (1) != tn1
32 || omp_get_ancestor_thread_num (-1) != -1
33 || omp_get_ancestor_thread_num (2) != -1
34 || omp_get_team_size (0) != 1
35 || omp_get_team_size (1) != omp_get_num_threads ()
36 || omp_get_team_size (-1) != -1
37 || omp_get_team_size (2) != -1
38 || omp_get_active_level () != 1)
39 #pragma omp atomic
40 e[0] += 1;
41 #pragma omp parallel if (0) num_threads(5) firstprivate(tn1)
43 int tn2 = omp_get_thread_num ();
44 if (omp_in_parallel () != 1
45 || omp_get_num_threads () != 1
46 || tn2 != 0
47 || omp_get_level () != 2
48 || omp_get_ancestor_thread_num (0) != 0
49 || omp_get_ancestor_thread_num (1) != tn1
50 || omp_get_ancestor_thread_num (2) != tn2
51 || omp_get_ancestor_thread_num (-1) != -1
52 || omp_get_ancestor_thread_num (3) != -1
53 || omp_get_team_size (0) != 1
54 || omp_get_team_size (1) != 4
55 || omp_get_team_size (2) != 1
56 || omp_get_team_size (-1) != -1
57 || omp_get_team_size (3) != -1
58 || omp_get_active_level () != 1)
59 #pragma omp atomic
60 e[1] += 1;
61 #pragma omp parallel num_threads(2) firstprivate(tn1, tn2)
63 int tn3 = omp_get_thread_num ();
64 if (omp_in_parallel () != 1
65 || omp_get_num_threads () != 2
66 || tn3 > 1 || tn3 < 0
67 || omp_get_level () != 3
68 || omp_get_ancestor_thread_num (0) != 0
69 || omp_get_ancestor_thread_num (1) != tn1
70 || omp_get_ancestor_thread_num (2) != tn2
71 || omp_get_ancestor_thread_num (3) != tn3
72 || omp_get_ancestor_thread_num (-1) != -1
73 || omp_get_ancestor_thread_num (4) != -1
74 || omp_get_team_size (0) != 1
75 || omp_get_team_size (1) != 4
76 || omp_get_team_size (2) != 1
77 || omp_get_team_size (3) != 2
78 || omp_get_team_size (-1) != -1
79 || omp_get_team_size (4) != -1
80 || omp_get_active_level () != 2)
81 #pragma omp atomic
82 e[2] += 1;
86 if (e[0] || e[1] || e[2])
87 abort ();
88 return 0;