testsuite: Correct vec-rlmi-rlnm.c testsuite expected result
[official-gcc.git] / libgomp / icv.c
blob4da6527c9b82f43319047c65d9d79a12bb2455bc
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 void
55 omp_set_nested (int val)
57 struct gomp_task_icv *icv = gomp_icv (true);
58 icv->nest_var = val;
61 int
62 omp_get_nested (void)
64 struct gomp_task_icv *icv = gomp_icv (false);
65 return icv->nest_var;
68 void
69 omp_set_schedule (omp_sched_t kind, int chunk_size)
71 struct gomp_task_icv *icv = gomp_icv (true);
72 switch (kind & ~omp_sched_monotonic)
74 case omp_sched_static:
75 if (chunk_size < 1)
76 chunk_size = 0;
77 icv->run_sched_chunk_size = chunk_size;
78 break;
79 case omp_sched_dynamic:
80 case omp_sched_guided:
81 if (chunk_size < 1)
82 chunk_size = 1;
83 icv->run_sched_chunk_size = chunk_size;
84 break;
85 case omp_sched_auto:
86 break;
87 default:
88 return;
90 icv->run_sched_var = kind;
93 void
94 omp_get_schedule (omp_sched_t *kind, int *chunk_size)
96 struct gomp_task_icv *icv = gomp_icv (false);
97 *kind = icv->run_sched_var;
98 *chunk_size = icv->run_sched_chunk_size;
102 omp_get_max_threads (void)
104 struct gomp_task_icv *icv = gomp_icv (false);
105 return icv->nthreads_var;
109 omp_get_thread_limit (void)
111 struct gomp_task_icv *icv = gomp_icv (false);
112 return icv->thread_limit_var > INT_MAX ? INT_MAX : icv->thread_limit_var;
115 void
116 omp_set_max_active_levels (int max_levels)
118 if (max_levels >= 0)
120 if (max_levels <= gomp_supported_active_levels)
121 gomp_max_active_levels_var = max_levels;
122 else
123 gomp_max_active_levels_var = gomp_supported_active_levels;
128 omp_get_max_active_levels (void)
130 return gomp_max_active_levels_var;
134 omp_get_supported_active_levels (void)
136 return gomp_supported_active_levels;
140 omp_get_cancellation (void)
142 return gomp_cancel_var;
146 omp_get_max_task_priority (void)
148 return gomp_max_task_priority_var;
151 omp_proc_bind_t
152 omp_get_proc_bind (void)
154 struct gomp_task_icv *icv = gomp_icv (false);
155 return icv->bind_var;
159 omp_get_num_places (void)
161 return gomp_places_list_len;
165 omp_get_place_num (void)
167 if (gomp_places_list == NULL)
168 return -1;
170 struct gomp_thread *thr = gomp_thread ();
171 if (thr->place == 0)
172 gomp_init_affinity ();
174 return (int) thr->place - 1;
178 omp_get_partition_num_places (void)
180 if (gomp_places_list == NULL)
181 return 0;
183 struct gomp_thread *thr = gomp_thread ();
184 if (thr->place == 0)
185 gomp_init_affinity ();
187 return thr->ts.place_partition_len;
190 void
191 omp_get_partition_place_nums (int *place_nums)
193 if (gomp_places_list == NULL)
194 return;
196 struct gomp_thread *thr = gomp_thread ();
197 if (thr->place == 0)
198 gomp_init_affinity ();
200 unsigned int i;
201 for (i = 0; i < thr->ts.place_partition_len; i++)
202 *place_nums++ = thr->ts.place_partition_off + i;
205 void
206 omp_set_default_allocator (omp_allocator_handle_t allocator)
208 struct gomp_thread *thr = gomp_thread ();
209 if (allocator == omp_null_allocator)
210 allocator = omp_default_mem_alloc;
211 thr->ts.def_allocator = (uintptr_t) allocator;
214 omp_allocator_handle_t
215 omp_get_default_allocator (void)
217 struct gomp_thread *thr = gomp_thread ();
218 if (thr->ts.def_allocator == omp_null_allocator)
219 return (omp_allocator_handle_t) gomp_def_allocator;
220 else
221 return (omp_allocator_handle_t) thr->ts.def_allocator;
224 ialias (omp_set_dynamic)
225 ialias (omp_set_nested)
226 ialias (omp_set_num_threads)
227 ialias (omp_get_dynamic)
228 ialias (omp_get_nested)
229 ialias (omp_set_schedule)
230 ialias (omp_get_schedule)
231 ialias (omp_get_max_threads)
232 ialias (omp_get_thread_limit)
233 ialias (omp_set_max_active_levels)
234 ialias (omp_get_max_active_levels)
235 ialias (omp_get_supported_active_levels)
236 ialias (omp_get_cancellation)
237 ialias (omp_get_proc_bind)
238 ialias (omp_get_max_task_priority)
239 ialias (omp_get_num_places)
240 ialias (omp_get_place_num)
241 ialias (omp_get_partition_num_places)
242 ialias (omp_get_partition_place_nums)
243 ialias (omp_set_default_allocator)
244 ialias (omp_get_default_allocator)