Add run tests for recent sibcall patches
[official-gcc.git] / libgomp / icv.c
blobe58b961558e8681c5936cd37ed99549038026358
1 /* Copyright (C) 2005-2016 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU Offloading and Multi Processing Library
5 (libgomp).
7 Libgomp is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 /* This file defines the OpenMP internal control variables and associated
27 OpenMP API entry points. */
29 #include "libgomp.h"
30 #include "gomp-constants.h"
31 #include <limits.h>
33 struct gomp_task_icv gomp_global_icv = {
34 .nthreads_var = 1,
35 .thread_limit_var = UINT_MAX,
36 .run_sched_var = GFS_DYNAMIC,
37 .run_sched_chunk_size = 1,
38 .default_device_var = 0,
39 .dyn_var = false,
40 .nest_var = false,
41 .bind_var = omp_proc_bind_false,
42 .target_data = NULL
45 unsigned long gomp_max_active_levels_var = INT_MAX;
46 bool gomp_cancel_var = false;
47 int gomp_max_task_priority_var = 0;
48 #ifndef HAVE_SYNC_BUILTINS
49 gomp_mutex_t gomp_managed_threads_lock;
50 #endif
51 unsigned long gomp_available_cpus = 1, gomp_managed_threads = 1;
52 unsigned long long gomp_spin_count_var, gomp_throttled_spin_count_var;
53 unsigned long *gomp_nthreads_var_list, gomp_nthreads_var_list_len;
54 char *gomp_bind_var_list;
55 unsigned long gomp_bind_var_list_len;
56 void **gomp_places_list;
57 unsigned long gomp_places_list_len;
58 int gomp_debug_var;
59 unsigned int gomp_num_teams_var;
60 char *goacc_device_type;
61 int goacc_device_num;
63 void
64 omp_set_num_threads (int n)
66 struct gomp_task_icv *icv = gomp_icv (true);
67 icv->nthreads_var = (n > 0 ? n : 1);
70 void
71 omp_set_dynamic (int val)
73 struct gomp_task_icv *icv = gomp_icv (true);
74 icv->dyn_var = val;
77 int
78 omp_get_dynamic (void)
80 struct gomp_task_icv *icv = gomp_icv (false);
81 return icv->dyn_var;
84 void
85 omp_set_nested (int val)
87 struct gomp_task_icv *icv = gomp_icv (true);
88 icv->nest_var = val;
91 int
92 omp_get_nested (void)
94 struct gomp_task_icv *icv = gomp_icv (false);
95 return icv->nest_var;
98 void
99 omp_set_schedule (omp_sched_t kind, int chunk_size)
101 struct gomp_task_icv *icv = gomp_icv (true);
102 switch (kind)
104 case omp_sched_static:
105 if (chunk_size < 1)
106 chunk_size = 0;
107 icv->run_sched_chunk_size = chunk_size;
108 break;
109 case omp_sched_dynamic:
110 case omp_sched_guided:
111 if (chunk_size < 1)
112 chunk_size = 1;
113 icv->run_sched_chunk_size = chunk_size;
114 break;
115 case omp_sched_auto:
116 break;
117 default:
118 return;
120 icv->run_sched_var = kind;
123 void
124 omp_get_schedule (omp_sched_t *kind, int *chunk_size)
126 struct gomp_task_icv *icv = gomp_icv (false);
127 *kind = icv->run_sched_var;
128 *chunk_size = icv->run_sched_chunk_size;
132 omp_get_max_threads (void)
134 struct gomp_task_icv *icv = gomp_icv (false);
135 return icv->nthreads_var;
139 omp_get_thread_limit (void)
141 struct gomp_task_icv *icv = gomp_icv (false);
142 return icv->thread_limit_var > INT_MAX ? INT_MAX : icv->thread_limit_var;
145 void
146 omp_set_max_active_levels (int max_levels)
148 if (max_levels >= 0)
149 gomp_max_active_levels_var = max_levels;
153 omp_get_max_active_levels (void)
155 return gomp_max_active_levels_var;
159 omp_get_cancellation (void)
161 return gomp_cancel_var;
165 omp_get_max_task_priority (void)
167 return gomp_max_task_priority_var;
170 omp_proc_bind_t
171 omp_get_proc_bind (void)
173 struct gomp_task_icv *icv = gomp_icv (false);
174 return icv->bind_var;
178 omp_get_initial_device (void)
180 return GOMP_DEVICE_HOST_FALLBACK;
184 omp_get_num_places (void)
186 return gomp_places_list_len;
190 omp_get_place_num (void)
192 if (gomp_places_list == NULL)
193 return -1;
195 struct gomp_thread *thr = gomp_thread ();
196 if (thr->place == 0)
197 gomp_init_affinity ();
199 return (int) thr->place - 1;
203 omp_get_partition_num_places (void)
205 if (gomp_places_list == NULL)
206 return 0;
208 struct gomp_thread *thr = gomp_thread ();
209 if (thr->place == 0)
210 gomp_init_affinity ();
212 return thr->ts.place_partition_len;
215 void
216 omp_get_partition_place_nums (int *place_nums)
218 if (gomp_places_list == NULL)
219 return;
221 struct gomp_thread *thr = gomp_thread ();
222 if (thr->place == 0)
223 gomp_init_affinity ();
225 unsigned int i;
226 for (i = 0; i < thr->ts.place_partition_len; i++)
227 *place_nums++ = thr->ts.place_partition_off + i;
230 ialias (omp_set_dynamic)
231 ialias (omp_set_nested)
232 ialias (omp_set_num_threads)
233 ialias (omp_get_dynamic)
234 ialias (omp_get_nested)
235 ialias (omp_set_schedule)
236 ialias (omp_get_schedule)
237 ialias (omp_get_max_threads)
238 ialias (omp_get_thread_limit)
239 ialias (omp_set_max_active_levels)
240 ialias (omp_get_max_active_levels)
241 ialias (omp_get_cancellation)
242 ialias (omp_get_proc_bind)
243 ialias (omp_get_initial_device)
244 ialias (omp_get_max_task_priority)
245 ialias (omp_get_num_places)
246 ialias (omp_get_place_num)
247 ialias (omp_get_partition_num_places)
248 ialias (omp_get_partition_place_nums)