Re: Refactor copying decl section names
[official-gcc.git] / libgomp / icv.c
blob8df15e385e705a799f4b82027d306a47df6e64cd
1 /* Copyright (C) 2005-2020 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 API entry points that operate on internal
27 control variables. */
29 #include "libgomp.h"
30 #include "gomp-constants.h"
31 #include <limits.h>
33 void
34 omp_set_num_threads (int n)
36 struct gomp_task_icv *icv = gomp_icv (true);
37 icv->nthreads_var = (n > 0 ? n : 1);
40 void
41 omp_set_dynamic (int val)
43 struct gomp_task_icv *icv = gomp_icv (true);
44 icv->dyn_var = val;
47 int
48 omp_get_dynamic (void)
50 struct gomp_task_icv *icv = gomp_icv (false);
51 return icv->dyn_var;
54 #pragma GCC diagnostic push
55 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
56 void
57 omp_set_nested (int val)
59 struct gomp_task_icv *icv = gomp_icv (true);
60 icv->nest_var = val;
63 int
64 omp_get_nested (void)
66 struct gomp_task_icv *icv = gomp_icv (false);
67 return icv->nest_var;
69 #pragma GCC diagnostic pop
71 void
72 omp_set_schedule (omp_sched_t kind, int chunk_size)
74 struct gomp_task_icv *icv = gomp_icv (true);
75 switch (kind & ~omp_sched_monotonic)
77 case omp_sched_static:
78 if (chunk_size < 1)
79 chunk_size = 0;
80 icv->run_sched_chunk_size = chunk_size;
81 break;
82 case omp_sched_dynamic:
83 case omp_sched_guided:
84 if (chunk_size < 1)
85 chunk_size = 1;
86 icv->run_sched_chunk_size = chunk_size;
87 break;
88 case omp_sched_auto:
89 break;
90 default:
91 return;
93 icv->run_sched_var = kind;
96 void
97 omp_get_schedule (omp_sched_t *kind, int *chunk_size)
99 struct gomp_task_icv *icv = gomp_icv (false);
100 *kind = icv->run_sched_var;
101 *chunk_size = icv->run_sched_chunk_size;
105 omp_get_max_threads (void)
107 struct gomp_task_icv *icv = gomp_icv (false);
108 return icv->nthreads_var;
112 omp_get_thread_limit (void)
114 struct gomp_task_icv *icv = gomp_icv (false);
115 return icv->thread_limit_var > INT_MAX ? INT_MAX : icv->thread_limit_var;
118 void
119 omp_set_max_active_levels (int max_levels)
121 if (max_levels >= 0)
123 if (max_levels <= gomp_supported_active_levels)
124 gomp_max_active_levels_var = max_levels;
125 else
126 gomp_max_active_levels_var = gomp_supported_active_levels;
131 omp_get_max_active_levels (void)
133 return gomp_max_active_levels_var;
137 omp_get_supported_active_levels (void)
139 return gomp_supported_active_levels;
143 omp_get_cancellation (void)
145 return gomp_cancel_var;
149 omp_get_max_task_priority (void)
151 return gomp_max_task_priority_var;
154 omp_proc_bind_t
155 omp_get_proc_bind (void)
157 struct gomp_task_icv *icv = gomp_icv (false);
158 return icv->bind_var;
162 omp_get_num_places (void)
164 return gomp_places_list_len;
168 omp_get_place_num (void)
170 if (gomp_places_list == NULL)
171 return -1;
173 struct gomp_thread *thr = gomp_thread ();
174 if (thr->place == 0)
175 gomp_init_affinity ();
177 return (int) thr->place - 1;
181 omp_get_partition_num_places (void)
183 if (gomp_places_list == NULL)
184 return 0;
186 struct gomp_thread *thr = gomp_thread ();
187 if (thr->place == 0)
188 gomp_init_affinity ();
190 return thr->ts.place_partition_len;
193 void
194 omp_get_partition_place_nums (int *place_nums)
196 if (gomp_places_list == NULL)
197 return;
199 struct gomp_thread *thr = gomp_thread ();
200 if (thr->place == 0)
201 gomp_init_affinity ();
203 unsigned int i;
204 for (i = 0; i < thr->ts.place_partition_len; i++)
205 *place_nums++ = thr->ts.place_partition_off + i;
208 void
209 omp_set_default_allocator (omp_allocator_handle_t allocator)
211 struct gomp_thread *thr = gomp_thread ();
212 if (allocator == omp_null_allocator)
213 allocator = omp_default_mem_alloc;
214 thr->ts.def_allocator = (uintptr_t) allocator;
217 omp_allocator_handle_t
218 omp_get_default_allocator (void)
220 struct gomp_thread *thr = gomp_thread ();
221 if (thr->ts.def_allocator == omp_null_allocator)
222 return (omp_allocator_handle_t) gomp_def_allocator;
223 else
224 return (omp_allocator_handle_t) thr->ts.def_allocator;
227 ialias (omp_set_dynamic)
228 ialias (omp_get_dynamic)
229 #pragma GCC diagnostic push
230 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
231 ialias (omp_set_nested)
232 ialias (omp_get_nested)
233 #pragma GCC diagnostic pop
234 ialias (omp_set_num_threads)
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_supported_active_levels)
242 ialias (omp_get_cancellation)
243 ialias (omp_get_proc_bind)
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)
249 ialias (omp_set_default_allocator)
250 ialias (omp_get_default_allocator)