1/* 2 * Copyright (c) 2014 ETH Zurich. 3 * All rights reserved. 4 * 5 * This file is distributed under the terms in the attached LICENSE file. 6 * If you do not find this file, copies can be found by writing to: 7 * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group. 8 */ 9 10#ifndef _LIBBOMP_ICV_H 11#define _LIBBOMP_ICV_H 12 13/* 14 * --------------------------------------------------------------------------- 15 * 2.3 Internal Control Variables 16 * --------------------------------------------------------------------------- 17 * 18 * An OpenMP implementation must act as if there are internal control variables 19 * (ICVs) that control the behavior of an OpenMP program. 20 * They are initialized by the implementation itself and may be given values 21 * through OpenMP environment variables and through calls to OpenMP API routines. 22 */ 23 24 25/** 26 * \brief 27 */ 28struct omp_icv_task 29{ 30 /** 31 * controls whether dynamic adjustment of the number of threads is enabled 32 * for encountered parallel regions. 33 * 34 * Scope: Data Environment 35 * Initialization: OMP_DYNAMIC 36 * Accessed: omp_set_dynamic(), omp_get_dyamic() 37 */ 38 uint8_t dynamic; 39 40 /** 41 * controls whether nested parallelism is enabled for encountered parallel 42 * regions 43 * 44 * Scope: Data Environment 45 * Initialization: OMP_NESTED, set to false 46 * Accessed: omp_set_nested(), omp_get_nested() 47 */ 48 uint8_t nested; 49 50 /** 51 * controls the number of threads requested for encountered parallel regions 52 * 53 * Scope: Data Environment 54 * Initialization: OMP_NUM_THREADS 55 * Accessed: omp_set_num_threads(), omp_get_num_threads() 56 */ 57 uint32_t nthreads; 58 59 /** 60 * controls the maximum number of threads participating in the contention group 61 * 62 * Scope: Data Environment 63 * Initialization: OMP_THREAD_LIMIT 64 * Accessed: thread_limit (clause), omp_get_thread_limit() 65 */ 66 uint32_t thread_limit; 67 68 /** 69 * controls the place partition available to the execution environment for 70 * encountered parallel regions. 71 * 72 * Scope: Data Environment 73 * Initialization: OMP_PLACES 74 */ 75 uint32_t place_partition; 76 77 /** 78 * the number of nested, active parallel regions enclosing the current ask 79 * such that all of the parallel regions are enclosed by the outermost initial 80 * task region on the current device. 81 * 82 * Scope: Data Environment 83 * Initialization: set to zero 84 * Accessed: omp_get_active_levels() 85 */ 86 uint8_t active_levels; 87 88 /** 89 * the number of nested parallel regions enclosing the current task such that 90 * all of the parallel regions are enclosed by the outermost initial task region 91 * on the current device. 92 * 93 * Scope: Data Environment 94 * Initialization: set to zero 95 * Accessed: omp_get_level() 96 */ 97 uint8_t levels; 98 99#if OMP_VERSION >= OMP_VERSION_40 100 /** 101 * Controls the binding of OpenMP threads to places. When binding is requested, 102 * the variable indicates that the execution environment is advised not to 103 * move threads between places. The variable can also provide default thread 104 * affinity policies. 105 * 106 * Scope: Data Environment 107 * Initialization: OMP_PROC_BIND 108 * Accessed: omp_get_proc_bind() 109 */ 110 uint8_t bind; 111 112 /** 113 * controls the default target device. 114 * 115 * Scope: Data Environment 116 * Initialization: OMP_DEFAULT_DEVICE 117 * Accessed: omp_set_default_device(), omp_get_default_device() 118 */ 119 uint8_t default_device; 120#endif 121 122 /** 123 * controls the schedule that the runtime schedule clause uses for loop regions 124 * 125 * Scope: Data Environment 126 * Initialization: OMP_SCHEDULE 127 * Accessed: omp_set_schedule(), omp_get_schedule() 128 */ 129 omp_sched_t run_sched; 130 int run_sched_modifier; 131}; 132 133/** 134 * 135 */ 136struct omp_icv_device 137{ 138 /** 139 * controls the implementation defined default scheduling of loop loop regions 140 * 141 * Scope: Device 142 * Initialization: (none) 143 */ 144 uint8_t dev_sched; 145 146 /** 147 * controls the stack size for threads that the OpenMP implementation creates 148 * 149 * Scope: Device 150 * Initialization: OMP_STACKSIZE 151 */ 152 uint32_t stack_size; 153 154 /** 155 * controls the desired behavior of waiting threads. 156 * 157 * Scope: Device 158 * Initialization: OMP_WAIT_POLICY 159 */ 160 uint8_t wait_policy; 161 162#if OMP_VERSION >= OMP_VERSION_40 163 /** 164 * controls the desired behavior of the cancel construct and cancellation points 165 * 166 * Scope: Device 167 * Initialization: OMP_CANCELLATION 168 * Accessed: omp_get_cancellation() 169 */ 170 uint8_t cancel; 171#endif 172 173 /** 174 * The number of nested, active parallel regions enclosing the current ask 175 * such that all of the parallel regions are enclosed by the outermost initial 176 * task region on the current device. 177 * 178 * Scope: Device 179 * Initialization: OMP_MAX_ACTIVE_LEVELS 180 * Accessed: omp_set_max_active_levels(), omp_get_max_active_levels() 181 */ 182 uint8_t max_active_levels; 183}; 184 185/** 186 * 187 */ 188struct omp_icv_global { 189 190 /** 191 * the global thread limit of the OpenMP program 192 * 193 * This variable is purely BOMP related 194 */ 195 coreid_t thread_limit; 196 197 /** 198 * the start time of the program 199 */ 200 cycles_t time_start; 201}; 202 203 204/** 205 * \brief represents the OpenMP environment for each thread 206 */ 207struct omp_icv { 208 struct omp_icv_global *global; ///< global control variables 209 struct omp_icv_device *device; ///< device specific control variables 210 struct omp_icv_task *task; ///< task specific control variables 211}; 212 213/* global variables for default ICV values */ 214extern struct omp_icv_device g_omp_icv_device_default; 215extern struct omp_icv_global g_omp_icv_global_default; 216extern struct omp_icv_task g_omp_icv_task_default; 217 218/* initialization of the default ICV */ 219void bomp_icv_init_default(coreid_t nthreads); 220struct omp_icv_task *bomp_icv_task_new(void); 221 222 223 224/* macros for accessing the control variables */ 225 226#define OMP_SET_ICV_GLOBAL(_var, _val) \ 227 ((bomp_icv_get()->global)->_var=(_val) 228#define OMP_GET_ICV_GLOBAL(_var) \ 229 ((bomp_icv_get()->global)->_var) 230 231#define OMP_SET_ICV_DEV(_var, _val) \ 232 (bomp_icv_get()->device)->_var=(_val) 233#define OMP_GET_ICV_DEV(_var) \ 234 ((bomp_icv_get()->device)->_var) 235 236#define OMP_SET_ICV_TASK(_var, _val) \ 237 (bomp_icv_get()->task)->_var=(_val) 238#define OMP_GET_ICV_TASK(_var) \ 239 ((bomp_icv_get()->task)->_var) 240 241 242#endif /* _LIBBOMP_ENVIRONEMNT_H */ 243