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
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)
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
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. */
30 #include "gomp-constants.h"
33 struct gomp_task_icv gomp_global_icv
= {
35 .thread_limit_var
= UINT_MAX
,
36 .run_sched_var
= GFS_DYNAMIC
,
37 .run_sched_chunk_size
= 1,
38 .default_device_var
= 0,
41 .bind_var
= omp_proc_bind_false
,
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
;
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
;
59 unsigned int gomp_num_teams_var
;
60 char *goacc_device_type
;
64 omp_set_num_threads (int n
)
66 struct gomp_task_icv
*icv
= gomp_icv (true);
67 icv
->nthreads_var
= (n
> 0 ? n
: 1);
71 omp_set_dynamic (int val
)
73 struct gomp_task_icv
*icv
= gomp_icv (true);
78 omp_get_dynamic (void)
80 struct gomp_task_icv
*icv
= gomp_icv (false);
85 omp_set_nested (int val
)
87 struct gomp_task_icv
*icv
= gomp_icv (true);
94 struct gomp_task_icv
*icv
= gomp_icv (false);
99 omp_set_schedule (omp_sched_t kind
, int chunk_size
)
101 struct gomp_task_icv
*icv
= gomp_icv (true);
104 case omp_sched_static
:
107 icv
->run_sched_chunk_size
= chunk_size
;
109 case omp_sched_dynamic
:
110 case omp_sched_guided
:
113 icv
->run_sched_chunk_size
= chunk_size
;
120 icv
->run_sched_var
= kind
;
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
;
146 omp_set_max_active_levels (int max_levels
)
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
;
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
)
195 struct gomp_thread
*thr
= gomp_thread ();
197 gomp_init_affinity ();
199 return (int) thr
->place
- 1;
203 omp_get_partition_num_places (void)
205 if (gomp_places_list
== NULL
)
208 struct gomp_thread
*thr
= gomp_thread ();
210 gomp_init_affinity ();
212 return thr
->ts
.place_partition_len
;
216 omp_get_partition_place_nums (int *place_nums
)
218 if (gomp_places_list
== NULL
)
221 struct gomp_thread
*thr
= gomp_thread ();
223 gomp_init_affinity ();
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
)