| 1 |
/* Copyright (C) 2005-2025 Free Software Foundation, Inc. |
| 2 |
Contributed by Richard Henderson <[email protected]>. |
| 3 |
|
| 4 |
This file is part of the GNU Offloading and Multi Processing Library |
| 5 |
(libgomp). |
| 6 |
|
| 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. |
| 11 |
|
| 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. |
| 16 |
|
| 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. |
| 20 |
|
| 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/>. */ |
| 25 |
|
| 26 |
/* This file defines the OpenMP API entry points that operate on internal |
| 27 |
control variables. */ |
| 28 |
|
| 29 |
#include "libgomp.h" |
| 30 |
#include "gomp-constants.h" |
| 31 |
#include <limits.h> |
| 32 |
|
| 33 |
ialias_redirect (omp_get_active_level) |
| 34 |
|
| 35 |
void |
| 36 |
omp_set_num_threads (int n) |
| 37 |
{ |
| 38 |
struct gomp_task_icv *icv = gomp_icv (true); |
| 39 |
icv->nthreads_var = (n > 0 ? n : 1); |
| 40 |
} |
| 41 |
|
| 42 |
void |
| 43 |
omp_set_dynamic (int val) |
| 44 |
{ |
| 45 |
struct gomp_task_icv *icv = gomp_icv (true); |
| 46 |
icv->dyn_var = val; |
| 47 |
} |
| 48 |
|
| 49 |
int |
| 50 |
omp_get_dynamic (void) |
| 51 |
{ |
| 52 |
struct gomp_task_icv *icv = gomp_icv (false); |
| 53 |
return icv->dyn_var; |
| 54 |
} |
| 55 |
|
| 56 |
#pragma GCC diagnostic push |
| 57 |
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 58 |
void |
| 59 |
omp_set_nested (int val) |
| 60 |
{ |
| 61 |
struct gomp_task_icv *icv = gomp_icv (true); |
| 62 |
if (val) |
| 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; |
| 66 |
} |
| 67 |
|
| 68 |
int |
| 69 |
omp_get_nested (void) |
| 70 |
{ |
| 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 ()); |
| 74 |
} |
| 75 |
#pragma GCC diagnostic pop |
| 76 |
|
| 77 |
void |
| 78 |
omp_set_schedule (omp_sched_t kind, int chunk_size) |
| 79 |
{ |
| 80 |
struct gomp_task_icv *icv = gomp_icv (true); |
| 81 |
switch (kind & ~omp_sched_monotonic) |
| 82 |
{ |
| 83 |
case omp_sched_static: |
| 84 |
if (chunk_size < 1) |
| 85 |
chunk_size = 0; |
| 86 |
icv->run_sched_chunk_size = chunk_size; |
| 87 |
break; |
| 88 |
case omp_sched_dynamic: |
| 89 |
case omp_sched_guided: |
| 90 |
if (chunk_size < 1) |
| 91 |
chunk_size = 1; |
| 92 |
icv->run_sched_chunk_size = chunk_size; |
| 93 |
break; |
| 94 |
case omp_sched_auto: |
| 95 |
break; |
| 96 |
default: |
| 97 |
return; |
| 98 |
} |
| 99 |
icv->run_sched_var = kind; |
| 100 |
} |
| 101 |
|
| 102 |
void |
| 103 |
omp_get_schedule (omp_sched_t *kind, int *chunk_size) |
| 104 |
{ |
| 105 |
struct gomp_task_icv *icv = gomp_icv (false); |
| 106 |
*kind = icv->run_sched_var; |
| 107 |
*chunk_size = icv->run_sched_chunk_size; |
| 108 |
} |
| 109 |
|
| 110 |
int |
| 111 |
omp_get_max_threads (void) |
| 112 |
{ |
| 113 |
struct gomp_task_icv *icv = gomp_icv (false); |
| 114 |
return icv->nthreads_var; |
| 115 |
} |
| 116 |
|
| 117 |
int |
| 118 |
omp_get_thread_limit (void) |
| 119 |
{ |
| 120 |
struct gomp_task_icv *icv = gomp_icv (false); |
| 121 |
return icv->thread_limit_var > INT_MAX ? INT_MAX : icv->thread_limit_var; |
| 122 |
} |
| 123 |
|
| 124 |
void |
| 125 |
omp_set_max_active_levels (int max_levels) |
| 126 |
{ |
| 127 |
if (max_levels >= 0) |
| 128 |
{ |
| 129 |
struct gomp_task_icv *icv = gomp_icv (true); |
| 130 |
|
| 131 |
if (max_levels <= gomp_supported_active_levels) |
| 132 |
icv->max_active_levels_var = max_levels; |
| 133 |
else |
| 134 |
icv->max_active_levels_var = gomp_supported_active_levels; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
int |
| 139 |
omp_get_max_active_levels (void) |
| 140 |
{ |
| 141 |
struct gomp_task_icv *icv = gomp_icv (false); |
| 142 |
return icv->max_active_levels_var; |
| 143 |
} |
| 144 |
|
| 145 |
int |
| 146 |
omp_get_supported_active_levels (void) |
| 147 |
{ |
| 148 |
return gomp_supported_active_levels; |
| 149 |
} |
| 150 |
|
| 151 |
int |
| 152 |
omp_get_cancellation (void) |
| 153 |
{ |
| 154 |
return gomp_cancel_var; |
| 155 |
} |
| 156 |
|
| 157 |
int |
| 158 |
omp_get_max_task_priority (void) |
| 159 |
{ |
| 160 |
return gomp_max_task_priority_var; |
| 161 |
} |
| 162 |
|
| 163 |
omp_proc_bind_t |
| 164 |
omp_get_proc_bind (void) |
| 165 |
{ |
| 166 |
struct gomp_task_icv *icv = gomp_icv (false); |
| 167 |
return icv->bind_var; |
| 168 |
} |
| 169 |
|
| 170 |
int |
| 171 |
omp_get_num_places (void) |
| 172 |
{ |
| 173 |
return gomp_places_list_len; |
| 174 |
} |
| 175 |
|
| 176 |
int |
| 177 |
omp_get_place_num (void) |
| 178 |
{ |
| 179 |
if (gomp_places_list == NULL) |
| 180 |
return -1; |
| 181 |
|
| 182 |
struct gomp_thread *thr = gomp_thread (); |
| 183 |
if (thr->place == 0) |
| 184 |
gomp_init_affinity (); |
| 185 |
|
| 186 |
return (int) thr->place - 1; |
| 187 |
} |
| 188 |
|
| 189 |
int |
| 190 |
omp_get_partition_num_places (void) |
| 191 |
{ |
| 192 |
if (gomp_places_list == NULL) |
| 193 |
return 0; |
| 194 |
|
| 195 |
struct gomp_thread *thr = gomp_thread (); |
| 196 |
if (thr->place == 0) |
| 197 |
gomp_init_affinity (); |
| 198 |
|
| 199 |
return thr->ts.place_partition_len; |
| 200 |
} |
| 201 |
|
| 202 |
void |
| 203 |
omp_get_partition_place_nums (int *place_nums) |
| 204 |
{ |
| 205 |
if (gomp_places_list == NULL) |
| 206 |
return; |
| 207 |
|
| 208 |
struct gomp_thread *thr = gomp_thread (); |
| 209 |
if (thr->place == 0) |
| 210 |
gomp_init_affinity (); |
| 211 |
|
| 212 |
unsigned int i; |
| 213 |
for (i = 0; i < thr->ts.place_partition_len; i++) |
| 214 |
*place_nums++ = thr->ts.place_partition_off + i; |
| 215 |
} |
| 216 |
|
| 217 |
void |
| 218 |
omp_set_default_allocator (omp_allocator_handle_t allocator) |
| 219 |
{ |
| 220 |
struct gomp_thread *thr = gomp_thread (); |
| 221 |
if (allocator == omp_null_allocator) |
| 222 |
allocator = omp_default_mem_alloc; |
| 223 |
thr->ts.def_allocator = (uintptr_t) allocator; |
| 224 |
} |
| 225 |
|
| 226 |
omp_allocator_handle_t |
| 227 |
omp_get_default_allocator (void) |
| 228 |
{ |
| 229 |
struct gomp_thread *thr = gomp_thread (); |
| 230 |
if (thr->ts.def_allocator == omp_null_allocator) |
| 231 |
return (omp_allocator_handle_t) gomp_def_allocator; |
| 232 |
else |
| 233 |
return (omp_allocator_handle_t) thr->ts.def_allocator; |
| 234 |
} |
| 235 |
|
| 236 |
ialias (omp_set_dynamic) |
| 237 |
ialias (omp_get_dynamic) |
| 238 |
#pragma GCC diagnostic push |
| 239 |
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 240 |
ialias (omp_set_nested) |
| 241 |
ialias (omp_get_nested) |
| 242 |
#pragma GCC diagnostic pop |
| 243 |
ialias (omp_set_num_threads) |
| 244 |
ialias (omp_set_schedule) |
| 245 |
ialias (omp_get_schedule) |
| 246 |
ialias (omp_get_max_threads) |
| 247 |
ialias (omp_get_thread_limit) |
| 248 |
ialias (omp_set_max_active_levels) |
| 249 |
ialias (omp_get_max_active_levels) |
| 250 |
ialias (omp_get_supported_active_levels) |
| 251 |
ialias (omp_get_cancellation) |
| 252 |
ialias (omp_get_proc_bind) |
| 253 |
ialias (omp_get_max_task_priority) |
| 254 |
ialias (omp_get_num_places) |
| 255 |
ialias (omp_get_place_num) |
| 256 |
ialias (omp_get_partition_num_places) |
| 257 |
ialias (omp_get_partition_place_nums) |
| 258 |
ialias (omp_set_default_allocator) |
| 259 |
ialias (omp_get_default_allocator) |