Set num_threads to 50 on 32-bit hppa in two libgomp loop tests
[official-gcc.git] / libgomp / testsuite / libgomp.c-c++-common / teams-nteams-icv-1.c
blobc3c21091e9703967edb4c31aad511226ddd29196
1 /* Check that the nteams ICV is honored. */
2 /* PR libgomp/109875 */
4 /* This base version of testcases is supposed to be run with all
5 OMP_NUM_TEAMS* env vars being unset.
7 The variants teams-nteams-icv-{2,3,4}.c test it by setting the
8 various OMP_NUM_TEAMS* env vars and #define MY_... for checking.
10 Currently, only <num> 0,1,2 is supported for the envar via #define
11 and with remote execution, dg-set-target-env-var does not work with
12 DejaGNU, hence, gcc/testsuite/lib/gcc-dg.exp marks those tests as
13 UNSUPPORTED. */
15 #define MY_MAX_DEVICES 3
17 /* OpenMP currently has:
18 - nteams-var ICV is initialized to 0; one ICV per device
19 - OMP_NUM_TEAMS(_DEV(_<dev-num>)) overrides it
20 OMP_NUM_TEAMS_ALL overrides it
21 - Number of teams is:
22 -> the value specific by num_teams([lower:]upper)
23 with lower := upper if unspecified
24 -> Otherwise, if nteams-var ICV > 0, #teams <= nteams-var ICV
25 -> Otherwise, if nteams-var ICV <= 0, #teams > 1
26 GCC uses 3 as default on the host and 1 for host fallback.
27 For offloading, it is device specific >> 1. */
29 #include <omp.h>
31 int
32 main ()
34 int num_teams_env = -1, num_teams_env_dev = -1;
35 int num_teams_env_devs[MY_MAX_DEVICES];
37 #ifdef MY_OMP_NUM_TEAMS_ALL
38 num_teams_env = num_teams_env_dev = MY_OMP_NUM_TEAMS_ALL;
39 #endif
41 #ifdef MY_OMP_NUM_TEAMS
42 num_teams_env = MY_OMP_NUM_TEAMS;
43 #endif
45 #ifdef MY_OMP_NUM_TEAMS_DEV
46 num_teams_env_dev = MY_OMP_NUM_TEAMS_DEV;
47 #endif
49 #if MY_MAX_DEVICES != 3
50 #error "Currently strictly assuming MY_MAX_DEVICES = 3"
51 #endif
53 #if defined(MY_OMP_NUM_TEAMS_DEV_4) || defined(MY_OMP_NUM_TEAMS_DEV_5)
54 #error "Currently strictly assuming MY_MAX_DEVICES = 3"
55 #endif
57 #ifdef MY_OMP_NUM_TEAMS_DEV_0
58 num_teams_env_devs[0] = MY_OMP_NUM_TEAMS_DEV_0;
59 #else
60 num_teams_env_devs[0] = num_teams_env_dev;
61 #endif
63 #ifdef MY_OMP_NUM_TEAMS_DEV_1
64 num_teams_env_devs[1] = MY_OMP_NUM_TEAMS_DEV_1;
65 #else
66 num_teams_env_devs[1] = num_teams_env_dev;
67 #endif
69 #ifdef MY_OMP_NUM_TEAMS_DEV_2
70 num_teams_env_devs[2] = MY_OMP_NUM_TEAMS_DEV_2;
71 #else
72 num_teams_env_devs[2] = num_teams_env_dev;
73 #endif
75 /* Check that the number of teams (initial device and in target) is
76 >= 1 and, if omp_get_max_teams() > 0, it does not
77 exceed omp_get_max_teams (). */
79 int nteams, num_teams;
81 /* Assume that omp_get_max_teams (); returns the ICV, i.e. 0 as default init
82 and not the number of teams that would be run; hence: '>='. */
83 nteams = omp_get_max_teams ();
84 if (nteams < 0 || (num_teams_env >= 0 && nteams != num_teams_env))
85 __builtin_abort ();
86 num_teams = -1;
88 #pragma omp teams
89 if (omp_get_team_num () == 0)
90 num_teams = omp_get_num_teams ();
91 if (num_teams < 1 || (nteams > 0 && num_teams > nteams))
92 __builtin_abort ();
94 /* GCC hard codes 3 teams - check for it. */
95 if (nteams <= 0 && num_teams != 3)
96 __builtin_abort ();
98 /* For each device, including host fallback. */
99 for (int dev = 0; dev <= omp_get_num_devices (); dev++)
101 int num_teams_icv = num_teams_env_dev;
102 if (dev == omp_get_num_devices ())
103 num_teams_icv = num_teams_env;
104 else if (dev < MY_MAX_DEVICES)
105 num_teams_icv = num_teams_env_devs[dev];
107 nteams = -1;
108 #pragma omp target device(dev) map(from: nteams)
109 nteams = omp_get_max_teams ();
110 if (nteams < 0 || (num_teams_icv >= 0 && nteams != num_teams_icv))
111 __builtin_abort ();
113 num_teams = -1;
114 #pragma omp target teams device(dev) map(from: num_teams)
115 if (omp_get_team_num () == 0)
116 num_teams = omp_get_num_teams ();
118 if (num_teams < 1 || (nteams > 0 && num_teams > nteams))
119 __builtin_abort ();
121 /* GCC hard codes 1 team for host fallback - check for it. */
122 if (dev == omp_get_num_devices () && num_teams != 1)
123 __builtin_abort ();
126 /* Now set the nteams-var ICV and check that omp_get_max_teams()
127 returns the set value and that the following holds:
128 num_teams >= 1 and num_teams <= nteams-var ICV.
130 Additionally, implementation defined, assume:
131 - num_teams == (not '<=') nteams-var ICV, except:
132 - num_teams == 1 for host fallback. */
134 omp_set_num_teams (5);
136 nteams = omp_get_max_teams ();
137 if (nteams != 5)
138 __builtin_abort ();
139 num_teams = -1;
141 #pragma omp teams
142 if (omp_get_team_num () == 0)
143 num_teams = omp_get_num_teams ();
144 if (num_teams != 5)
145 __builtin_abort ();
147 /* For each device, including host fallback. */
148 for (int dev = 0; dev <= omp_get_num_devices (); dev++)
150 #pragma omp target device(dev) firstprivate(dev)
151 omp_set_num_teams (7 + dev);
153 #pragma omp target device(dev) map(from: nteams)
154 nteams = omp_get_max_teams ();
155 if (nteams != 7 + dev)
156 __builtin_abort ();
158 num_teams = -1;
159 #pragma omp target teams device(dev) map(from: num_teams)
160 if (omp_get_team_num () == 0)
161 num_teams = omp_get_num_teams ();
163 if (dev == omp_get_num_devices ())
165 if (num_teams != 1)
166 __builtin_abort ();
168 else
170 if (num_teams != 7 + dev)
171 __builtin_abort ();
175 /* Now use the num_teams clause explicitly. */
177 num_teams = -1;
178 #pragma omp teams num_teams(6)
179 if (omp_get_team_num () == 0)
180 num_teams = omp_get_num_teams ();
181 if (num_teams != 6)
182 __builtin_abort ();
184 /* For each device, including host fallback. */
185 for (int dev = 0; dev <= omp_get_num_devices (); dev++)
187 num_teams = -1;
188 #pragma omp target teams device(dev) map(from: num_teams) num_teams(dev+3)
189 if (omp_get_team_num () == 0)
190 num_teams = omp_get_num_teams ();
192 /* This must match the set value, also with host fallback. */
193 if (num_teams != 3 + dev)
194 __builtin_abort ();
197 return 0;