1 /* Copyright (C) 2005-2021 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 API entry points that operate on internal
30 #include "gomp-constants.h"
33 ialias_redirect (omp_get_active_level
)
36 omp_set_num_threads (int n
)
38 struct gomp_task_icv
*icv
= gomp_icv (true);
39 icv
->nthreads_var
= (n
> 0 ? n
: 1);
43 omp_set_dynamic (int val
)
45 struct gomp_task_icv
*icv
= gomp_icv (true);
50 omp_get_dynamic (void)
52 struct gomp_task_icv
*icv
= gomp_icv (false);
56 #pragma GCC diagnostic push
57 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
59 omp_set_nested (int val
)
61 struct gomp_task_icv
*icv
= gomp_icv (true);
63 icv
->max_active_levels_var
= gomp_supported_active_levels
;
64 else if (icv
->max_active_levels_var
> 1)
65 icv
->max_active_levels_var
= 1;
71 struct gomp_task_icv
*icv
= gomp_icv (false);
72 return (icv
->max_active_levels_var
> 1
73 && icv
->max_active_levels_var
> omp_get_active_level ());
75 #pragma GCC diagnostic pop
78 omp_set_schedule (omp_sched_t kind
, int chunk_size
)
80 struct gomp_task_icv
*icv
= gomp_icv (true);
81 switch (kind
& ~omp_sched_monotonic
)
83 case omp_sched_static
:
86 icv
->run_sched_chunk_size
= chunk_size
;
88 case omp_sched_dynamic
:
89 case omp_sched_guided
:
92 icv
->run_sched_chunk_size
= chunk_size
;
99 icv
->run_sched_var
= kind
;
103 omp_get_schedule (omp_sched_t
*kind
, int *chunk_size
)
105 struct gomp_task_icv
*icv
= gomp_icv (false);
106 *kind
= icv
->run_sched_var
;
107 *chunk_size
= icv
->run_sched_chunk_size
;
111 omp_get_max_threads (void)
113 struct gomp_task_icv
*icv
= gomp_icv (false);
114 return icv
->nthreads_var
;
118 omp_get_thread_limit (void)
120 struct gomp_task_icv
*icv
= gomp_icv (false);
121 return icv
->thread_limit_var
> INT_MAX
? INT_MAX
: icv
->thread_limit_var
;
125 omp_set_max_active_levels (int max_levels
)
129 struct gomp_task_icv
*icv
= gomp_icv (true);
131 if (max_levels
<= gomp_supported_active_levels
)
132 icv
->max_active_levels_var
= max_levels
;
134 icv
->max_active_levels_var
= gomp_supported_active_levels
;
139 omp_get_max_active_levels (void)
141 struct gomp_task_icv
*icv
= gomp_icv (false);
142 return icv
->max_active_levels_var
;
146 omp_get_supported_active_levels (void)
148 return gomp_supported_active_levels
;
152 omp_set_num_teams (int num_teams
)
155 gomp_nteams_var
= num_teams
;
159 omp_get_max_teams (void)
161 return gomp_nteams_var
;
165 omp_set_teams_thread_limit (int thread_limit
)
167 if (thread_limit
>= 0)
168 gomp_teams_thread_limit_var
= thread_limit
;
172 omp_get_teams_thread_limit (void)
174 return gomp_teams_thread_limit_var
;
178 omp_get_cancellation (void)
180 return gomp_cancel_var
;
184 omp_get_max_task_priority (void)
186 return gomp_max_task_priority_var
;
190 omp_get_proc_bind (void)
192 struct gomp_task_icv
*icv
= gomp_icv (false);
193 return icv
->bind_var
;
197 omp_get_num_places (void)
199 return gomp_places_list_len
;
203 omp_get_place_num (void)
205 if (gomp_places_list
== NULL
)
208 struct gomp_thread
*thr
= gomp_thread ();
210 gomp_init_affinity ();
212 return (int) thr
->place
- 1;
216 omp_get_partition_num_places (void)
218 if (gomp_places_list
== NULL
)
221 struct gomp_thread
*thr
= gomp_thread ();
223 gomp_init_affinity ();
225 return thr
->ts
.place_partition_len
;
229 omp_get_partition_place_nums (int *place_nums
)
231 if (gomp_places_list
== NULL
)
234 struct gomp_thread
*thr
= gomp_thread ();
236 gomp_init_affinity ();
239 for (i
= 0; i
< thr
->ts
.place_partition_len
; i
++)
240 *place_nums
++ = thr
->ts
.place_partition_off
+ i
;
244 omp_set_default_allocator (omp_allocator_handle_t allocator
)
246 struct gomp_thread
*thr
= gomp_thread ();
247 if (allocator
== omp_null_allocator
)
248 allocator
= omp_default_mem_alloc
;
249 thr
->ts
.def_allocator
= (uintptr_t) allocator
;
252 omp_allocator_handle_t
253 omp_get_default_allocator (void)
255 struct gomp_thread
*thr
= gomp_thread ();
256 if (thr
->ts
.def_allocator
== omp_null_allocator
)
257 return (omp_allocator_handle_t
) gomp_def_allocator
;
259 return (omp_allocator_handle_t
) thr
->ts
.def_allocator
;
262 ialias (omp_set_dynamic
)
263 ialias (omp_get_dynamic
)
264 #pragma GCC diagnostic push
265 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
266 ialias (omp_set_nested
)
267 ialias (omp_get_nested
)
268 #pragma GCC diagnostic pop
269 ialias (omp_set_num_threads
)
270 ialias (omp_set_schedule
)
271 ialias (omp_get_schedule
)
272 ialias (omp_get_max_threads
)
273 ialias (omp_get_thread_limit
)
274 ialias (omp_set_max_active_levels
)
275 ialias (omp_get_max_active_levels
)
276 ialias (omp_get_supported_active_levels
)
277 ialias (omp_set_num_teams
)
278 ialias (omp_get_max_teams
)
279 ialias (omp_set_teams_thread_limit
)
280 ialias (omp_get_teams_thread_limit
)
281 ialias (omp_get_cancellation
)
282 ialias (omp_get_proc_bind
)
283 ialias (omp_get_max_task_priority
)
284 ialias (omp_get_num_places
)
285 ialias (omp_get_place_num
)
286 ialias (omp_get_partition_num_places
)
287 ialias (omp_get_partition_place_nums
)
288 ialias (omp_set_default_allocator
)
289 ialias (omp_get_default_allocator
)