1139825Simp/* Copyright (C) 2005-2020 Free Software Foundation, Inc. 21541Srgrimes Contributed by Richard Henderson <rth@redhat.com>. 31541Srgrimes 41541Srgrimes This file is part of the GNU Offloading and Multi Processing Library 51541Srgrimes (libgomp). 61541Srgrimes 71541Srgrimes Libgomp is free software; you can redistribute it and/or modify it 81541Srgrimes under the terms of the GNU General Public License as published by 91541Srgrimes the Free Software Foundation; either version 3, or (at your option) 101541Srgrimes any later version. 111541Srgrimes 121541Srgrimes Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY 131541Srgrimes WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 141541Srgrimes FOR A PARTICULAR PURPOSE. See the GNU General Public License for 151541Srgrimes more details. 161541Srgrimes 171541Srgrimes Under Section 7 of GPL version 3, you are granted additional 181541Srgrimes permissions described in the GCC Runtime Library Exception, version 191541Srgrimes 3.1, as published by the Free Software Foundation. 201541Srgrimes 211541Srgrimes You should have received a copy of the GNU General Public License and 221541Srgrimes a copy of the GCC Runtime Library Exception along with this program; 231541Srgrimes see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 241541Srgrimes <http://www.gnu.org/licenses/>. */ 251541Srgrimes 261541Srgrimes/* This file defines the OpenMP API entry points that operate on internal 271541Srgrimes control variables. */ 281541Srgrimes 291541Srgrimes#include "libgomp.h" 3050477Speter#include "gomp-constants.h" 311541Srgrimes#include <limits.h> 321541Srgrimes 331541Srgrimesvoid 341541Srgrimesomp_set_num_threads (int n) 351541Srgrimes{ 36143063Sjoerg struct gomp_task_icv *icv = gomp_icv (true); 37143063Sjoerg icv->nthreads_var = (n > 0 ? n : 1); 38143063Sjoerg} 3924778Sbde 4024778Sbdevoid 4124778Sbdeomp_set_dynamic (int val) 4224778Sbde{ 431541Srgrimes struct gomp_task_icv *icv = gomp_icv (true); 441541Srgrimes icv->dyn_var = val; 451541Srgrimes} 461541Srgrimes 471541Srgrimesint 4824778Sbdeomp_get_dynamic (void) 4924778Sbde{ 501541Srgrimes struct gomp_task_icv *icv = gomp_icv (false); 511541Srgrimes return icv->dyn_var; 52} 53 54void 55omp_set_nested (int val) 56{ 57 struct gomp_task_icv *icv = gomp_icv (true); 58 icv->nest_var = val; 59} 60 61int 62omp_get_nested (void) 63{ 64 struct gomp_task_icv *icv = gomp_icv (false); 65 return icv->nest_var; 66} 67 68void 69omp_set_schedule (omp_sched_t kind, int chunk_size) 70{ 71 struct gomp_task_icv *icv = gomp_icv (true); 72 switch (kind & ~omp_sched_monotonic) 73 { 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; 89 } 90 icv->run_sched_var = kind; 91} 92 93void 94omp_get_schedule (omp_sched_t *kind, int *chunk_size) 95{ 96 struct gomp_task_icv *icv = gomp_icv (false); 97 *kind = icv->run_sched_var; 98 *chunk_size = icv->run_sched_chunk_size; 99} 100 101int 102omp_get_max_threads (void) 103{ 104 struct gomp_task_icv *icv = gomp_icv (false); 105 return icv->nthreads_var; 106} 107 108int 109omp_get_thread_limit (void) 110{ 111 struct gomp_task_icv *icv = gomp_icv (false); 112 return icv->thread_limit_var > INT_MAX ? INT_MAX : icv->thread_limit_var; 113} 114 115void 116omp_set_max_active_levels (int max_levels) 117{ 118 if (max_levels >= 0) 119 gomp_max_active_levels_var = max_levels; 120} 121 122int 123omp_get_max_active_levels (void) 124{ 125 return gomp_max_active_levels_var; 126} 127 128int 129omp_get_cancellation (void) 130{ 131 return gomp_cancel_var; 132} 133 134int 135omp_get_max_task_priority (void) 136{ 137 return gomp_max_task_priority_var; 138} 139 140omp_proc_bind_t 141omp_get_proc_bind (void) 142{ 143 struct gomp_task_icv *icv = gomp_icv (false); 144 return icv->bind_var; 145} 146 147int 148omp_get_initial_device (void) 149{ 150 return GOMP_DEVICE_HOST_FALLBACK; 151} 152 153int 154omp_get_num_places (void) 155{ 156 return gomp_places_list_len; 157} 158 159int 160omp_get_place_num (void) 161{ 162 if (gomp_places_list == NULL) 163 return -1; 164 165 struct gomp_thread *thr = gomp_thread (); 166 if (thr->place == 0) 167 gomp_init_affinity (); 168 169 return (int) thr->place - 1; 170} 171 172int 173omp_get_partition_num_places (void) 174{ 175 if (gomp_places_list == NULL) 176 return 0; 177 178 struct gomp_thread *thr = gomp_thread (); 179 if (thr->place == 0) 180 gomp_init_affinity (); 181 182 return thr->ts.place_partition_len; 183} 184 185void 186omp_get_partition_place_nums (int *place_nums) 187{ 188 if (gomp_places_list == NULL) 189 return; 190 191 struct gomp_thread *thr = gomp_thread (); 192 if (thr->place == 0) 193 gomp_init_affinity (); 194 195 unsigned int i; 196 for (i = 0; i < thr->ts.place_partition_len; i++) 197 *place_nums++ = thr->ts.place_partition_off + i; 198} 199 200ialias (omp_set_dynamic) 201ialias (omp_set_nested) 202ialias (omp_set_num_threads) 203ialias (omp_get_dynamic) 204ialias (omp_get_nested) 205ialias (omp_set_schedule) 206ialias (omp_get_schedule) 207ialias (omp_get_max_threads) 208ialias (omp_get_thread_limit) 209ialias (omp_set_max_active_levels) 210ialias (omp_get_max_active_levels) 211ialias (omp_get_cancellation) 212ialias (omp_get_proc_bind) 213ialias (omp_get_initial_device) 214ialias (omp_get_max_task_priority) 215ialias (omp_get_num_places) 216ialias (omp_get_place_num) 217ialias (omp_get_partition_num_places) 218ialias (omp_get_partition_place_nums) 219