| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1 | /*! \file */ |
| 2 | /* |
| 3 | * kmp.h -- KPTS runtime header file. |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // The LLVM Compiler Infrastructure |
| 10 | // |
| 11 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 12 | // Source Licenses. See LICENSE.txt for details. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | |
| 17 | #ifndef KMP_H |
| 18 | #define KMP_H |
| 19 | |
| Jonathan Peyton | c0225ca | 2015-08-28 18:42:10 +0000 | [diff] [blame] | 20 | #include "kmp_config.h" |
| 21 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 22 | /* #define BUILD_PARALLEL_ORDERED 1 */ |
| 23 | |
| 24 | /* This fix replaces gettimeofday with clock_gettime for better scalability on |
| 25 | the Altix. Requires user code to be linked with -lrt. |
| 26 | */ |
| 27 | //#define FIX_SGI_CLOCK |
| 28 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 29 | /* Defines for OpenMP 3.0 tasking and auto scheduling */ |
| 30 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 31 | # ifndef KMP_STATIC_STEAL_ENABLED |
| 32 | # define KMP_STATIC_STEAL_ENABLED 1 |
| 33 | # endif |
| 34 | |
| 35 | #define TASK_CURRENT_NOT_QUEUED 0 |
| 36 | #define TASK_CURRENT_QUEUED 1 |
| 37 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 38 | #ifdef BUILD_TIED_TASK_STACK |
| 39 | #define TASK_STACK_EMPTY 0 // entries when the stack is empty |
| 40 | |
| 41 | #define TASK_STACK_BLOCK_BITS 5 // Used to define TASK_STACK_SIZE and TASK_STACK_MASK |
| 42 | #define TASK_STACK_BLOCK_SIZE ( 1 << TASK_STACK_BLOCK_BITS ) // Number of entries in each task stack array |
| 43 | #define TASK_STACK_INDEX_MASK ( TASK_STACK_BLOCK_SIZE - 1 ) // Mask for determining index into stack block |
| 44 | #endif // BUILD_TIED_TASK_STACK |
| 45 | |
| 46 | #define TASK_NOT_PUSHED 1 |
| 47 | #define TASK_SUCCESSFULLY_PUSHED 0 |
| 48 | #define TASK_TIED 1 |
| 49 | #define TASK_UNTIED 0 |
| 50 | #define TASK_EXPLICIT 1 |
| 51 | #define TASK_IMPLICIT 0 |
| Andrey Churbanov | 535b6fa | 2015-05-07 17:41:51 +0000 | [diff] [blame] | 52 | #define TASK_PROXY 1 |
| 53 | #define TASK_FULL 0 |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 54 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 55 | #define KMP_CANCEL_THREADS |
| 56 | #define KMP_THREAD_ATTR |
| 57 | |
| 58 | #include <stdio.h> |
| 59 | #include <stdlib.h> |
| 60 | #include <stddef.h> |
| 61 | #include <stdarg.h> |
| 62 | #include <string.h> |
| 63 | #include <signal.h> |
| 64 | /* include <ctype.h> don't use; problems with /MD on Windows* OS NT due to bad Microsoft library */ |
| 65 | /* some macros provided below to replace some of these functions */ |
| 66 | #ifndef __ABSOFT_WIN |
| 67 | #include <sys/types.h> |
| 68 | #endif |
| 69 | #include <limits.h> |
| 70 | #include <time.h> |
| 71 | |
| 72 | #include <errno.h> |
| 73 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 74 | #include "kmp_os.h" |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 75 | |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 76 | #include "kmp_safe_c_api.h" |
| 77 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 78 | #if KMP_STATS_ENABLED |
| 79 | class kmp_stats_list; |
| 80 | #endif |
| 81 | |
| Jonathan Peyton | 0f3c2b9 | 2016-06-16 20:23:11 +0000 | [diff] [blame] | 82 | #if KMP_USE_HWLOC && KMP_AFFINITY_SUPPORTED |
| 83 | # include "hwloc.h" |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 84 | #endif |
| 85 | |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 86 | #if KMP_ARCH_X86 || KMP_ARCH_X86_64 |
| 87 | #include <xmmintrin.h> |
| 88 | #endif |
| 89 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 90 | #include "kmp_version.h" |
| 91 | #include "kmp_debug.h" |
| 92 | #include "kmp_lock.h" |
| Jonathan Peyton | 8fbb49a | 2015-07-09 18:16:58 +0000 | [diff] [blame] | 93 | #if USE_DEBUGGER |
| 94 | #include "kmp_debugger.h" |
| 95 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 96 | #include "kmp_i18n.h" |
| 97 | |
| Joerg Sonnenberger | 64be2d2 | 2015-09-21 19:38:56 +0000 | [diff] [blame] | 98 | #define KMP_HANDLE_SIGNALS (KMP_OS_UNIX || KMP_OS_WINDOWS) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 99 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 100 | #include "kmp_wrapper_malloc.h" |
| 101 | #if KMP_OS_UNIX |
| 102 | # include <unistd.h> |
| 103 | # if !defined NSIG && defined _NSIG |
| 104 | # define NSIG _NSIG |
| 105 | # endif |
| 106 | #endif |
| 107 | |
| 108 | #if KMP_OS_LINUX |
| 109 | # pragma weak clock_gettime |
| 110 | #endif |
| 111 | |
| Andrey Churbanov | e5f4492 | 2015-04-29 16:22:07 +0000 | [diff] [blame] | 112 | #if OMPT_SUPPORT |
| 113 | #include "ompt-internal.h" |
| 114 | #endif |
| 115 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 116 | /*Select data placement in NUMA memory */ |
| 117 | #define NO_FIRST_TOUCH 0 |
| 118 | #define FIRST_TOUCH 1 /* Exploit SGI's first touch page placement algo */ |
| 119 | |
| 120 | /* If not specified on compile command line, assume no first touch */ |
| 121 | #ifndef BUILD_MEMORY |
| 122 | #define BUILD_MEMORY NO_FIRST_TOUCH |
| 123 | #endif |
| 124 | |
| 125 | // 0 - no fast memory allocation, alignment: 8-byte on x86, 16-byte on x64. |
| 126 | // 3 - fast allocation using sync, non-sync free lists of any size, non-self free lists of limited size. |
| 127 | #ifndef USE_FAST_MEMORY |
| 128 | #define USE_FAST_MEMORY 3 |
| 129 | #endif |
| 130 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 131 | #ifndef KMP_NESTED_HOT_TEAMS |
| 132 | # define KMP_NESTED_HOT_TEAMS 0 |
| 133 | # define USE_NESTED_HOT_ARG(x) |
| 134 | #else |
| 135 | # if KMP_NESTED_HOT_TEAMS |
| 136 | # if OMP_40_ENABLED |
| 137 | # define USE_NESTED_HOT_ARG(x) ,x |
| 138 | # else |
| 139 | // Nested hot teams feature depends on omp 4.0, disable it for earlier versions |
| 140 | # undef KMP_NESTED_HOT_TEAMS |
| 141 | # define KMP_NESTED_HOT_TEAMS 0 |
| 142 | # define USE_NESTED_HOT_ARG(x) |
| 143 | # endif |
| 144 | # else |
| 145 | # define USE_NESTED_HOT_ARG(x) |
| 146 | # endif |
| 147 | #endif |
| 148 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 149 | // Assume using BGET compare_exchange instruction instead of lock by default. |
| 150 | #ifndef USE_CMP_XCHG_FOR_BGET |
| 151 | #define USE_CMP_XCHG_FOR_BGET 1 |
| 152 | #endif |
| 153 | |
| 154 | // Test to see if queuing lock is better than bootstrap lock for bget |
| 155 | // #ifndef USE_QUEUING_LOCK_FOR_BGET |
| 156 | // #define USE_QUEUING_LOCK_FOR_BGET |
| 157 | // #endif |
| 158 | |
| Jonathan Peyton | 1e7a1dd | 2015-06-04 17:29:13 +0000 | [diff] [blame] | 159 | #define KMP_NSEC_PER_SEC 1000000000L |
| 160 | #define KMP_USEC_PER_SEC 1000000L |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 161 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 162 | /*! |
| 163 | @ingroup BASIC_TYPES |
| 164 | @{ |
| 165 | */ |
| 166 | |
| 167 | // FIXME DOXYGEN... need to group these flags somehow (Making them an anonymous enum would do it...) |
| 168 | /*! |
| 169 | Values for bit flags used in the ident_t to describe the fields. |
| 170 | */ |
| 171 | /*! Use trampoline for internal microtasks */ |
| 172 | #define KMP_IDENT_IMB 0x01 |
| 173 | /*! Use c-style ident structure */ |
| 174 | #define KMP_IDENT_KMPC 0x02 |
| 175 | /* 0x04 is no longer used */ |
| 176 | /*! Entry point generated by auto-parallelization */ |
| 177 | #define KMP_IDENT_AUTOPAR 0x08 |
| 178 | /*! Compiler generates atomic reduction option for kmpc_reduce* */ |
| 179 | #define KMP_IDENT_ATOMIC_REDUCE 0x10 |
| 180 | /*! To mark a 'barrier' directive in user code */ |
| 181 | #define KMP_IDENT_BARRIER_EXPL 0x20 |
| 182 | /*! To Mark implicit barriers. */ |
| 183 | #define KMP_IDENT_BARRIER_IMPL 0x0040 |
| 184 | #define KMP_IDENT_BARRIER_IMPL_MASK 0x01C0 |
| 185 | #define KMP_IDENT_BARRIER_IMPL_FOR 0x0040 |
| 186 | #define KMP_IDENT_BARRIER_IMPL_SECTIONS 0x00C0 |
| 187 | |
| 188 | #define KMP_IDENT_BARRIER_IMPL_SINGLE 0x0140 |
| 189 | #define KMP_IDENT_BARRIER_IMPL_WORKSHARE 0x01C0 |
| 190 | |
| 191 | /*! |
| 192 | * The ident structure that describes a source location. |
| 193 | */ |
| 194 | typedef struct ident { |
| 195 | kmp_int32 reserved_1; /**< might be used in Fortran; see above */ |
| 196 | kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags; KMP_IDENT_KMPC identifies this union member */ |
| 197 | kmp_int32 reserved_2; /**< not really used in Fortran any more; see above */ |
| 198 | #if USE_ITT_BUILD |
| 199 | /* but currently used for storing region-specific ITT */ |
| 200 | /* contextual information. */ |
| 201 | #endif /* USE_ITT_BUILD */ |
| 202 | kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for C++ */ |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 203 | char const *psource; /**< String describing the source location. |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 204 | The string is composed of semi-colon separated fields which describe the source file, |
| 205 | the function and a pair of line numbers that delimit the construct. |
| 206 | */ |
| 207 | } ident_t; |
| 208 | /*! |
| 209 | @} |
| 210 | */ |
| 211 | |
| 212 | // Some forward declarations. |
| 213 | |
| 214 | typedef union kmp_team kmp_team_t; |
| 215 | typedef struct kmp_taskdata kmp_taskdata_t; |
| 216 | typedef union kmp_task_team kmp_task_team_t; |
| 217 | typedef union kmp_team kmp_team_p; |
| 218 | typedef union kmp_info kmp_info_p; |
| 219 | typedef union kmp_root kmp_root_p; |
| 220 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 221 | #ifdef __cplusplus |
| 222 | extern "C" { |
| 223 | #endif |
| 224 | |
| 225 | /* ------------------------------------------------------------------------ */ |
| 226 | /* ------------------------------------------------------------------------ */ |
| 227 | |
| 228 | /* Pack two 32-bit signed integers into a 64-bit signed integer */ |
| 229 | /* ToDo: Fix word ordering for big-endian machines. */ |
| 230 | #define KMP_PACK_64(HIGH_32,LOW_32) \ |
| 231 | ( (kmp_int64) ((((kmp_uint64)(HIGH_32))<<32) | (kmp_uint64)(LOW_32)) ) |
| 232 | |
| 233 | |
| 234 | /* |
| 235 | * Generic string manipulation macros. |
| 236 | * Assume that _x is of type char * |
| 237 | */ |
| 238 | #define SKIP_WS(_x) { while (*(_x) == ' ' || *(_x) == '\t') (_x)++; } |
| 239 | #define SKIP_DIGITS(_x) { while (*(_x) >= '0' && *(_x) <= '9') (_x)++; } |
| 240 | #define SKIP_TO(_x,_c) { while (*(_x) != '\0' && *(_x) != (_c)) (_x)++; } |
| 241 | |
| 242 | /* ------------------------------------------------------------------------ */ |
| 243 | /* ------------------------------------------------------------------------ */ |
| 244 | |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 245 | #define KMP_MAX( x, y ) ( (x) > (y) ? (x) : (y) ) |
| 246 | #define KMP_MIN( x, y ) ( (x) < (y) ? (x) : (y) ) |
| 247 | |
| 248 | /* ------------------------------------------------------------------------ */ |
| 249 | /* ------------------------------------------------------------------------ */ |
| 250 | |
| 251 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 252 | /* Enumeration types */ |
| 253 | |
| 254 | enum kmp_state_timer { |
| 255 | ts_stop, |
| 256 | ts_start, |
| 257 | ts_pause, |
| 258 | |
| 259 | ts_last_state |
| 260 | }; |
| 261 | |
| 262 | enum dynamic_mode { |
| 263 | dynamic_default, |
| 264 | #ifdef USE_LOAD_BALANCE |
| 265 | dynamic_load_balance, |
| 266 | #endif /* USE_LOAD_BALANCE */ |
| 267 | dynamic_random, |
| 268 | dynamic_thread_limit, |
| 269 | dynamic_max |
| 270 | }; |
| 271 | |
| 272 | /* external schedule constants, duplicate enum omp_sched in omp.h in order to not include it here */ |
| 273 | #ifndef KMP_SCHED_TYPE_DEFINED |
| 274 | #define KMP_SCHED_TYPE_DEFINED |
| 275 | typedef enum kmp_sched { |
| 276 | kmp_sched_lower = 0, // lower and upper bounds are for routine parameter check |
| 277 | // Note: need to adjust __kmp_sch_map global array in case this enum is changed |
| 278 | kmp_sched_static = 1, // mapped to kmp_sch_static_chunked (33) |
| 279 | kmp_sched_dynamic = 2, // mapped to kmp_sch_dynamic_chunked (35) |
| 280 | kmp_sched_guided = 3, // mapped to kmp_sch_guided_chunked (36) |
| 281 | kmp_sched_auto = 4, // mapped to kmp_sch_auto (38) |
| 282 | kmp_sched_upper_std = 5, // upper bound for standard schedules |
| 283 | kmp_sched_lower_ext = 100, // lower bound of Intel extension schedules |
| 284 | kmp_sched_trapezoidal = 101, // mapped to kmp_sch_trapezoidal (39) |
| 285 | // kmp_sched_static_steal = 102, // mapped to kmp_sch_static_steal (44) |
| 286 | kmp_sched_upper = 102, |
| 287 | kmp_sched_default = kmp_sched_static // default scheduling |
| 288 | } kmp_sched_t; |
| 289 | #endif |
| 290 | |
| 291 | /*! |
| 292 | @ingroup WORK_SHARING |
| 293 | * Describes the loop schedule to be used for a parallel for loop. |
| 294 | */ |
| 295 | enum sched_type { |
| 296 | kmp_sch_lower = 32, /**< lower bound for unordered values */ |
| 297 | kmp_sch_static_chunked = 33, |
| 298 | kmp_sch_static = 34, /**< static unspecialized */ |
| 299 | kmp_sch_dynamic_chunked = 35, |
| 300 | kmp_sch_guided_chunked = 36, /**< guided unspecialized */ |
| 301 | kmp_sch_runtime = 37, |
| 302 | kmp_sch_auto = 38, /**< auto */ |
| 303 | kmp_sch_trapezoidal = 39, |
| 304 | |
| 305 | /* accessible only through KMP_SCHEDULE environment variable */ |
| 306 | kmp_sch_static_greedy = 40, |
| 307 | kmp_sch_static_balanced = 41, |
| 308 | /* accessible only through KMP_SCHEDULE environment variable */ |
| 309 | kmp_sch_guided_iterative_chunked = 42, |
| 310 | kmp_sch_guided_analytical_chunked = 43, |
| 311 | |
| 312 | kmp_sch_static_steal = 44, /**< accessible only through KMP_SCHEDULE environment variable */ |
| 313 | |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 314 | #if OMP_45_ENABLED |
| Jonathan Peyton | ef73479 | 2016-05-31 19:12:18 +0000 | [diff] [blame] | 315 | kmp_sch_static_balanced_chunked = 45, /**< static with chunk adjustment (e.g., simd) */ |
| 316 | #endif |
| 317 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 318 | /* accessible only through KMP_SCHEDULE environment variable */ |
| Jonathan Peyton | ef73479 | 2016-05-31 19:12:18 +0000 | [diff] [blame] | 319 | kmp_sch_upper = 46, /**< upper bound for unordered values */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 320 | |
| 321 | kmp_ord_lower = 64, /**< lower bound for ordered values, must be power of 2 */ |
| 322 | kmp_ord_static_chunked = 65, |
| 323 | kmp_ord_static = 66, /**< ordered static unspecialized */ |
| 324 | kmp_ord_dynamic_chunked = 67, |
| 325 | kmp_ord_guided_chunked = 68, |
| 326 | kmp_ord_runtime = 69, |
| 327 | kmp_ord_auto = 70, /**< ordered auto */ |
| 328 | kmp_ord_trapezoidal = 71, |
| 329 | kmp_ord_upper = 72, /**< upper bound for ordered values */ |
| 330 | |
| 331 | #if OMP_40_ENABLED |
| 332 | /* Schedules for Distribute construct */ |
| 333 | kmp_distribute_static_chunked = 91, /**< distribute static chunked */ |
| 334 | kmp_distribute_static = 92, /**< distribute static unspecialized */ |
| 335 | #endif |
| 336 | |
| 337 | /* |
| 338 | * For the "nomerge" versions, kmp_dispatch_next*() will always return |
| 339 | * a single iteration/chunk, even if the loop is serialized. For the |
| 340 | * schedule types listed above, the entire iteration vector is returned |
| 341 | * if the loop is serialized. This doesn't work for gcc/gcomp sections. |
| 342 | */ |
| 343 | kmp_nm_lower = 160, /**< lower bound for nomerge values */ |
| 344 | |
| 345 | kmp_nm_static_chunked = (kmp_sch_static_chunked - kmp_sch_lower + kmp_nm_lower), |
| 346 | kmp_nm_static = 162, /**< static unspecialized */ |
| 347 | kmp_nm_dynamic_chunked = 163, |
| 348 | kmp_nm_guided_chunked = 164, /**< guided unspecialized */ |
| 349 | kmp_nm_runtime = 165, |
| 350 | kmp_nm_auto = 166, /**< auto */ |
| 351 | kmp_nm_trapezoidal = 167, |
| 352 | |
| 353 | /* accessible only through KMP_SCHEDULE environment variable */ |
| 354 | kmp_nm_static_greedy = 168, |
| 355 | kmp_nm_static_balanced = 169, |
| 356 | /* accessible only through KMP_SCHEDULE environment variable */ |
| 357 | kmp_nm_guided_iterative_chunked = 170, |
| 358 | kmp_nm_guided_analytical_chunked = 171, |
| 359 | kmp_nm_static_steal = 172, /* accessible only through OMP_SCHEDULE environment variable */ |
| 360 | |
| 361 | kmp_nm_ord_static_chunked = 193, |
| 362 | kmp_nm_ord_static = 194, /**< ordered static unspecialized */ |
| 363 | kmp_nm_ord_dynamic_chunked = 195, |
| 364 | kmp_nm_ord_guided_chunked = 196, |
| 365 | kmp_nm_ord_runtime = 197, |
| 366 | kmp_nm_ord_auto = 198, /**< auto */ |
| 367 | kmp_nm_ord_trapezoidal = 199, |
| 368 | kmp_nm_upper = 200, /**< upper bound for nomerge values */ |
| 369 | |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 370 | #if OMP_45_ENABLED |
| Jonathan Peyton | ea0fe1d | 2016-02-25 17:55:50 +0000 | [diff] [blame] | 371 | /* Support for OpenMP 4.5 monotonic and nonmonotonic schedule modifiers. |
| 372 | * Since we need to distinguish the three possible cases (no modifier, monotonic modifier, |
| 373 | * nonmonotonic modifier), we need separate bits for each modifier. |
| 374 | * The absence of monotonic does not imply nonmonotonic, especially since 4.5 says |
| 375 | * that the behaviour of the "no modifier" case is implementation defined in 4.5, |
| 376 | * but will become "nonmonotonic" in 5.0. |
| 377 | * |
| 378 | * Since we're passing a full 32 bit value, we can use a couple of high bits for these |
| 379 | * flags; out of paranoia we avoid the sign bit. |
| 380 | * |
| 381 | * These modifiers can be or-ed into non-static schedules by the compiler to pass |
| 382 | * the additional information. |
| 383 | * They will be stripped early in the processing in __kmp_dispatch_init when setting up schedules, so |
| 384 | * most of the code won't ever see schedules with these bits set. |
| 385 | */ |
| 386 | kmp_sch_modifier_monotonic = (1<<29), /**< Set if the monotonic schedule modifier was present */ |
| 387 | kmp_sch_modifier_nonmonotonic = (1<<30), /**< Set if the nonmonotonic schedule modifier was present */ |
| 388 | |
| 389 | # define SCHEDULE_WITHOUT_MODIFIERS(s) (enum sched_type)((s) & ~ (kmp_sch_modifier_nonmonotonic | kmp_sch_modifier_monotonic)) |
| 390 | # define SCHEDULE_HAS_MONOTONIC(s) (((s) & kmp_sch_modifier_monotonic) != 0) |
| 391 | # define SCHEDULE_HAS_NONMONOTONIC(s) (((s) & kmp_sch_modifier_nonmonotonic) != 0) |
| 392 | # define SCHEDULE_HAS_NO_MODIFIERS(s) (((s) & (kmp_sch_modifier_nonmonotonic | kmp_sch_modifier_monotonic)) == 0) |
| 393 | #else |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 394 | /* By doing this we hope to avoid multiple tests on OMP_45_ENABLED. Compilers can now eliminate tests on compile time |
| Jonathan Peyton | ea0fe1d | 2016-02-25 17:55:50 +0000 | [diff] [blame] | 395 | * constants and dead code that results from them, so we can leave code guarded by such an if in place. |
| 396 | */ |
| 397 | # define SCHEDULE_WITHOUT_MODIFIERS(s) (s) |
| 398 | # define SCHEDULE_HAS_MONOTONIC(s) false |
| 399 | # define SCHEDULE_HAS_NONMONOTONIC(s) false |
| 400 | # define SCHEDULE_HAS_NO_MODIFIERS(s) true |
| 401 | #endif |
| 402 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 403 | kmp_sch_default = kmp_sch_static /**< default scheduling algorithm */ |
| 404 | }; |
| 405 | |
| 406 | /* Type to keep runtime schedule set via OMP_SCHEDULE or omp_set_schedule() */ |
| 407 | typedef struct kmp_r_sched { |
| 408 | enum sched_type r_sched_type; |
| 409 | int chunk; |
| 410 | } kmp_r_sched_t; |
| 411 | |
| 412 | extern enum sched_type __kmp_sch_map[]; // map OMP 3.0 schedule types with our internal schedule types |
| 413 | |
| 414 | enum library_type { |
| 415 | library_none, |
| 416 | library_serial, |
| 417 | library_turnaround, |
| 418 | library_throughput |
| 419 | }; |
| 420 | |
| 421 | #if KMP_OS_LINUX |
| 422 | enum clock_function_type { |
| 423 | clock_function_gettimeofday, |
| 424 | clock_function_clock_gettime |
| 425 | }; |
| 426 | #endif /* KMP_OS_LINUX */ |
| 427 | |
| Andrey Churbanov | 613edeb | 2015-02-20 18:14:43 +0000 | [diff] [blame] | 428 | #if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS) |
| 429 | enum mic_type { |
| 430 | non_mic, |
| 431 | mic1, |
| 432 | mic2, |
| 433 | mic3, |
| 434 | dummy |
| 435 | }; |
| 436 | #endif |
| 437 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 438 | /* ------------------------------------------------------------------------ */ |
| 439 | /* -- fast reduction stuff ------------------------------------------------ */ |
| 440 | |
| 441 | #undef KMP_FAST_REDUCTION_BARRIER |
| 442 | #define KMP_FAST_REDUCTION_BARRIER 1 |
| 443 | |
| 444 | #undef KMP_FAST_REDUCTION_CORE_DUO |
| 445 | #if KMP_ARCH_X86 || KMP_ARCH_X86_64 |
| 446 | #define KMP_FAST_REDUCTION_CORE_DUO 1 |
| 447 | #endif |
| 448 | |
| 449 | enum _reduction_method { |
| 450 | reduction_method_not_defined = 0, |
| 451 | critical_reduce_block = ( 1 << 8 ), |
| 452 | atomic_reduce_block = ( 2 << 8 ), |
| 453 | tree_reduce_block = ( 3 << 8 ), |
| 454 | empty_reduce_block = ( 4 << 8 ) |
| 455 | }; |
| 456 | |
| 457 | // description of the packed_reduction_method variable |
| 458 | // the packed_reduction_method variable consists of two enum types variables that are packed together into 0-th byte and 1-st byte: |
| 459 | // 0: ( packed_reduction_method & 0x000000FF ) is a 'enum barrier_type' value of barrier that will be used in fast reduction: bs_plain_barrier or bs_reduction_barrier |
| 460 | // 1: ( packed_reduction_method & 0x0000FF00 ) is a reduction method that will be used in fast reduction; |
| 461 | // reduction method is of 'enum _reduction_method' type and it's defined the way so that the bits of 0-th byte are empty, |
| 462 | // so no need to execute a shift instruction while packing/unpacking |
| 463 | |
| 464 | #if KMP_FAST_REDUCTION_BARRIER |
| 465 | #define PACK_REDUCTION_METHOD_AND_BARRIER(reduction_method,barrier_type) \ |
| 466 | ( ( reduction_method ) | ( barrier_type ) ) |
| 467 | |
| 468 | #define UNPACK_REDUCTION_METHOD(packed_reduction_method) \ |
| 469 | ( ( enum _reduction_method )( ( packed_reduction_method ) & ( 0x0000FF00 ) ) ) |
| 470 | |
| 471 | #define UNPACK_REDUCTION_BARRIER(packed_reduction_method) \ |
| 472 | ( ( enum barrier_type )( ( packed_reduction_method ) & ( 0x000000FF ) ) ) |
| 473 | #else |
| 474 | #define PACK_REDUCTION_METHOD_AND_BARRIER(reduction_method,barrier_type) \ |
| 475 | ( reduction_method ) |
| 476 | |
| 477 | #define UNPACK_REDUCTION_METHOD(packed_reduction_method) \ |
| 478 | ( packed_reduction_method ) |
| 479 | |
| 480 | #define UNPACK_REDUCTION_BARRIER(packed_reduction_method) \ |
| 481 | ( bs_plain_barrier ) |
| 482 | #endif |
| 483 | |
| 484 | #define TEST_REDUCTION_METHOD(packed_reduction_method,which_reduction_block) \ |
| 485 | ( ( UNPACK_REDUCTION_METHOD( packed_reduction_method ) ) == ( which_reduction_block ) ) |
| 486 | |
| 487 | #if KMP_FAST_REDUCTION_BARRIER |
| 488 | #define TREE_REDUCE_BLOCK_WITH_REDUCTION_BARRIER \ |
| 489 | ( PACK_REDUCTION_METHOD_AND_BARRIER( tree_reduce_block, bs_reduction_barrier ) ) |
| 490 | |
| 491 | #define TREE_REDUCE_BLOCK_WITH_PLAIN_BARRIER \ |
| 492 | ( PACK_REDUCTION_METHOD_AND_BARRIER( tree_reduce_block, bs_plain_barrier ) ) |
| 493 | #endif |
| 494 | |
| 495 | typedef int PACKED_REDUCTION_METHOD_T; |
| 496 | |
| 497 | /* -- end of fast reduction stuff ----------------------------------------- */ |
| 498 | |
| 499 | /* ------------------------------------------------------------------------ */ |
| 500 | /* ------------------------------------------------------------------------ */ |
| 501 | |
| 502 | #if KMP_OS_WINDOWS |
| 503 | # define USE_CBLKDATA |
| 504 | # pragma warning( push ) |
| 505 | # pragma warning( disable: 271 310 ) |
| 506 | # include <windows.h> |
| 507 | # pragma warning( pop ) |
| 508 | #endif |
| 509 | |
| 510 | #if KMP_OS_UNIX |
| 511 | # include <pthread.h> |
| 512 | # include <dlfcn.h> |
| 513 | #endif |
| 514 | |
| 515 | /* ------------------------------------------------------------------------ */ |
| 516 | /* ------------------------------------------------------------------------ */ |
| 517 | |
| 518 | /* |
| 519 | * Only Linux* OS and Windows* OS support thread affinity. |
| 520 | */ |
| Alp Toker | 763b939 | 2014-02-28 09:42:41 +0000 | [diff] [blame] | 521 | #if KMP_AFFINITY_SUPPORTED |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 522 | |
| Jonathan Peyton | 0f3c2b9 | 2016-06-16 20:23:11 +0000 | [diff] [blame] | 523 | # if KMP_GROUP_AFFINITY |
| 524 | // GROUP_AFFINITY is already defined for _MSC_VER>=1600 (VS2010 and later). |
| 525 | # if _MSC_VER < 1600 |
| 526 | typedef struct GROUP_AFFINITY { |
| 527 | KAFFINITY Mask; |
| 528 | WORD Group; |
| 529 | WORD Reserved[3]; |
| 530 | } GROUP_AFFINITY; |
| 531 | # endif /* _MSC_VER < 1600 */ |
| 532 | extern int __kmp_num_proc_groups; |
| 533 | typedef DWORD (*kmp_GetActiveProcessorCount_t)(WORD); |
| 534 | extern kmp_GetActiveProcessorCount_t __kmp_GetActiveProcessorCount; |
| 535 | |
| 536 | typedef WORD (*kmp_GetActiveProcessorGroupCount_t)(void); |
| 537 | extern kmp_GetActiveProcessorGroupCount_t __kmp_GetActiveProcessorGroupCount; |
| 538 | |
| 539 | typedef BOOL (*kmp_GetThreadGroupAffinity_t)(HANDLE, GROUP_AFFINITY *); |
| 540 | extern kmp_GetThreadGroupAffinity_t __kmp_GetThreadGroupAffinity; |
| 541 | |
| 542 | typedef BOOL (*kmp_SetThreadGroupAffinity_t)(HANDLE, const GROUP_AFFINITY *, GROUP_AFFINITY *); |
| 543 | extern kmp_SetThreadGroupAffinity_t __kmp_SetThreadGroupAffinity; |
| 544 | # endif /* KMP_GROUP_AFFINITY */ |
| 545 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 546 | extern size_t __kmp_affin_mask_size; |
| 547 | # define KMP_AFFINITY_CAPABLE() (__kmp_affin_mask_size > 0) |
| Andrey Churbanov | 1f037e4 | 2015-03-10 09:15:26 +0000 | [diff] [blame] | 548 | # define KMP_AFFINITY_DISABLE() (__kmp_affin_mask_size = 0) |
| 549 | # define KMP_AFFINITY_ENABLE(mask_size) (__kmp_affin_mask_size = mask_size) |
| Jonathan Peyton | 0f3c2b9 | 2016-06-16 20:23:11 +0000 | [diff] [blame] | 550 | # if !KMP_USE_HWLOC |
| 551 | # define KMP_CPU_SETSIZE (__kmp_affin_mask_size * CHAR_BIT) |
| 552 | # define KMP_CPU_SET_ITERATE(i,mask) \ |
| 553 | for(i = 0; (size_t)i < KMP_CPU_SETSIZE; ++i) |
| 554 | # endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 555 | |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 556 | #if KMP_USE_HWLOC |
| 557 | |
| Jonathan Peyton | 0f3c2b9 | 2016-06-16 20:23:11 +0000 | [diff] [blame] | 558 | extern hwloc_topology_t __kmp_hwloc_topology; |
| 559 | extern int __kmp_hwloc_error; |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 560 | typedef hwloc_cpuset_t kmp_affin_mask_t; |
| 561 | # define KMP_CPU_SET(i,mask) hwloc_bitmap_set((hwloc_cpuset_t)mask, (unsigned)i) |
| 562 | # define KMP_CPU_ISSET(i,mask) hwloc_bitmap_isset((hwloc_cpuset_t)mask, (unsigned)i) |
| 563 | # define KMP_CPU_CLR(i,mask) hwloc_bitmap_clr((hwloc_cpuset_t)mask, (unsigned)i) |
| 564 | # define KMP_CPU_ZERO(mask) hwloc_bitmap_zero((hwloc_cpuset_t)mask) |
| 565 | # define KMP_CPU_COPY(dest, src) hwloc_bitmap_copy((hwloc_cpuset_t)dest, (hwloc_cpuset_t)src) |
| Jonathan Peyton | 34c72c4 | 2016-06-13 17:01:26 +0000 | [diff] [blame] | 566 | # define KMP_CPU_AND(dest, src) hwloc_bitmap_and((hwloc_cpuset_t)dest, (hwloc_cpuset_t)dest, (hwloc_cpuset_t)src) |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 567 | # define KMP_CPU_COMPLEMENT(max_bit_number, mask) \ |
| 568 | { \ |
| 569 | unsigned i; \ |
| 570 | for(i=0;i<(unsigned)max_bit_number+1;i++) { \ |
| 571 | if(hwloc_bitmap_isset((hwloc_cpuset_t)mask, i)) { \ |
| 572 | hwloc_bitmap_clr((hwloc_cpuset_t)mask, i); \ |
| 573 | } else { \ |
| 574 | hwloc_bitmap_set((hwloc_cpuset_t)mask, i); \ |
| 575 | } \ |
| 576 | } \ |
| Jonathan Peyton | 34c72c4 | 2016-06-13 17:01:26 +0000 | [diff] [blame] | 577 | hwloc_bitmap_and((hwloc_cpuset_t)mask, (hwloc_cpuset_t)mask, \ |
| Jonathan Peyton | c5304aa | 2016-06-13 21:28:03 +0000 | [diff] [blame] | 578 | (hwloc_cpuset_t)__kmp_affin_fullMask); \ |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 579 | } \ |
| 580 | |
| 581 | # define KMP_CPU_UNION(dest, src) hwloc_bitmap_or((hwloc_cpuset_t)dest, (hwloc_cpuset_t)dest, (hwloc_cpuset_t)src) |
| 582 | # define KMP_CPU_SET_ITERATE(i,mask) \ |
| 583 | for(i = hwloc_bitmap_first((hwloc_cpuset_t)mask); (int)i != -1; i = hwloc_bitmap_next((hwloc_cpuset_t)mask, i)) |
| 584 | |
| 585 | # define KMP_CPU_ALLOC(ptr) ptr = (kmp_affin_mask_t*)hwloc_bitmap_alloc() |
| 586 | # define KMP_CPU_FREE(ptr) hwloc_bitmap_free((hwloc_bitmap_t)ptr); |
| 587 | # define KMP_CPU_ALLOC_ON_STACK(ptr) KMP_CPU_ALLOC(ptr) |
| 588 | # define KMP_CPU_FREE_FROM_STACK(ptr) KMP_CPU_FREE(ptr) |
| 589 | # define KMP_CPU_INTERNAL_ALLOC(ptr) KMP_CPU_ALLOC(ptr) |
| 590 | # define KMP_CPU_INTERNAL_FREE(ptr) KMP_CPU_FREE(ptr) |
| 591 | |
| 592 | // |
| 593 | // The following macro should be used to index an array of masks. |
| 594 | // The array should be declared as "kmp_affinity_t *" and allocated with |
| 595 | // size "__kmp_affinity_mask_size * len". The macro takes care of the fact |
| 596 | // that on Windows* OS, sizeof(kmp_affin_t) is really the size of the mask, but |
| 597 | // on Linux* OS, sizeof(kmp_affin_t) is 1. |
| 598 | // |
| 599 | # define KMP_CPU_INDEX(array,i) ((kmp_affin_mask_t*)(array[i])) |
| 600 | # define KMP_CPU_ALLOC_ARRAY(arr, n) { \ |
| 601 | arr = (kmp_affin_mask_t *)__kmp_allocate(n*sizeof(kmp_affin_mask_t)); \ |
| 602 | unsigned i; \ |
| 603 | for(i=0;i<(unsigned)n;i++) { \ |
| 604 | arr[i] = hwloc_bitmap_alloc(); \ |
| 605 | } \ |
| 606 | } |
| 607 | # define KMP_CPU_FREE_ARRAY(arr, n) { \ |
| 608 | unsigned i; \ |
| 609 | for(i=0;i<(unsigned)n;i++) { \ |
| 610 | hwloc_bitmap_free(arr[i]); \ |
| 611 | } \ |
| 612 | __kmp_free(arr); \ |
| 613 | } |
| 614 | # define KMP_CPU_INTERNAL_ALLOC_ARRAY(arr, n) { \ |
| 615 | arr = (kmp_affin_mask_t *)KMP_INTERNAL_MALLOC(n*sizeof(kmp_affin_mask_t)); \ |
| 616 | unsigned i; \ |
| 617 | for(i=0;i<(unsigned)n;i++) { \ |
| 618 | arr[i] = hwloc_bitmap_alloc(); \ |
| 619 | } \ |
| 620 | } |
| 621 | # define KMP_CPU_INTERNAL_FREE_ARRAY(arr, n) { \ |
| 622 | unsigned i; \ |
| 623 | for(i=0;i<(unsigned)n;i++) { \ |
| 624 | hwloc_bitmap_free(arr[i]); \ |
| 625 | } \ |
| 626 | KMP_INTERNAL_FREE(arr); \ |
| 627 | } |
| 628 | |
| 629 | #else /* KMP_USE_HWLOC */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 630 | # if KMP_OS_LINUX |
| 631 | // |
| Jim Cownie | 3051f97 | 2014-08-07 10:12:54 +0000 | [diff] [blame] | 632 | // On Linux* OS, the mask is actually a vector of length __kmp_affin_mask_size |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 633 | // (in bytes). It should be allocated on a word boundary. |
| 634 | // |
| 635 | // WARNING!!! We have made the base type of the affinity mask unsigned char, |
| 636 | // in order to eliminate a lot of checks that the true system mask size is |
| 637 | // really a multiple of 4 bytes (on Linux* OS). |
| 638 | // |
| 639 | // THESE MACROS WON'T WORK PROPERLY ON BIG ENDIAN MACHINES!!! |
| 640 | // |
| 641 | |
| 642 | typedef unsigned char kmp_affin_mask_t; |
| 643 | |
| 644 | # define _KMP_CPU_SET(i,mask) (mask[i/CHAR_BIT] |= (((kmp_affin_mask_t)1) << (i % CHAR_BIT))) |
| 645 | # define KMP_CPU_SET(i,mask) _KMP_CPU_SET((i), ((kmp_affin_mask_t *)(mask))) |
| 646 | # define _KMP_CPU_ISSET(i,mask) (!!(mask[i/CHAR_BIT] & (((kmp_affin_mask_t)1) << (i % CHAR_BIT)))) |
| 647 | # define KMP_CPU_ISSET(i,mask) _KMP_CPU_ISSET((i), ((kmp_affin_mask_t *)(mask))) |
| 648 | # define _KMP_CPU_CLR(i,mask) (mask[i/CHAR_BIT] &= ~(((kmp_affin_mask_t)1) << (i % CHAR_BIT))) |
| 649 | # define KMP_CPU_CLR(i,mask) _KMP_CPU_CLR((i), ((kmp_affin_mask_t *)(mask))) |
| 650 | |
| 651 | # define KMP_CPU_ZERO(mask) \ |
| 652 | { \ |
| 653 | size_t __i; \ |
| 654 | for (__i = 0; __i < __kmp_affin_mask_size; __i++) { \ |
| 655 | ((kmp_affin_mask_t *)(mask))[__i] = 0; \ |
| 656 | } \ |
| 657 | } |
| 658 | |
| 659 | # define KMP_CPU_COPY(dest, src) \ |
| 660 | { \ |
| 661 | size_t __i; \ |
| 662 | for (__i = 0; __i < __kmp_affin_mask_size; __i++) { \ |
| 663 | ((kmp_affin_mask_t *)(dest))[__i] \ |
| 664 | = ((kmp_affin_mask_t *)(src))[__i]; \ |
| 665 | } \ |
| 666 | } |
| 667 | |
| Jonathan Peyton | 34c72c4 | 2016-06-13 17:01:26 +0000 | [diff] [blame] | 668 | # define KMP_CPU_AND(dest, src) \ |
| 669 | { \ |
| 670 | size_t __i; \ |
| 671 | for (__i = 0; __i < __kmp_affin_mask_size; __i++) { \ |
| 672 | ((kmp_affin_mask_t *)(dest))[__i] \ |
| 673 | &= ((kmp_affin_mask_t *)(src))[__i]; \ |
| 674 | } \ |
| 675 | } |
| 676 | |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 677 | # define KMP_CPU_COMPLEMENT(max_bit_number, mask) \ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 678 | { \ |
| 679 | size_t __i; \ |
| 680 | for (__i = 0; __i < __kmp_affin_mask_size; __i++) { \ |
| 681 | ((kmp_affin_mask_t *)(mask))[__i] \ |
| 682 | = ~((kmp_affin_mask_t *)(mask))[__i]; \ |
| 683 | } \ |
| Jonathan Peyton | c5304aa | 2016-06-13 21:28:03 +0000 | [diff] [blame] | 684 | KMP_CPU_AND(mask, __kmp_affin_fullMask); \ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | # define KMP_CPU_UNION(dest, src) \ |
| 688 | { \ |
| 689 | size_t __i; \ |
| 690 | for (__i = 0; __i < __kmp_affin_mask_size; __i++) { \ |
| 691 | ((kmp_affin_mask_t *)(dest))[__i] \ |
| 692 | |= ((kmp_affin_mask_t *)(src))[__i]; \ |
| 693 | } \ |
| 694 | } |
| 695 | |
| 696 | # endif /* KMP_OS_LINUX */ |
| 697 | |
| 698 | # if KMP_OS_WINDOWS |
| 699 | // |
| 700 | // On Windows* OS, the mask size is 4 bytes for IA-32 architecture, and on |
| 701 | // Intel(R) 64 it is 8 bytes times the number of processor groups. |
| 702 | // |
| 703 | |
| Andrey Churbanov | 7daf980 | 2015-01-27 16:52:57 +0000 | [diff] [blame] | 704 | # if KMP_GROUP_AFFINITY |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 705 | typedef DWORD_PTR kmp_affin_mask_t; |
| 706 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 707 | # define _KMP_CPU_SET(i,mask) \ |
| 708 | (mask[i/(CHAR_BIT * sizeof(kmp_affin_mask_t))] |= \ |
| 709 | (((kmp_affin_mask_t)1) << (i % (CHAR_BIT * sizeof(kmp_affin_mask_t))))) |
| 710 | |
| 711 | # define KMP_CPU_SET(i,mask) \ |
| 712 | _KMP_CPU_SET((i), ((kmp_affin_mask_t *)(mask))) |
| 713 | |
| 714 | # define _KMP_CPU_ISSET(i,mask) \ |
| 715 | (!!(mask[i/(CHAR_BIT * sizeof(kmp_affin_mask_t))] & \ |
| 716 | (((kmp_affin_mask_t)1) << (i % (CHAR_BIT * sizeof(kmp_affin_mask_t)))))) |
| 717 | |
| 718 | # define KMP_CPU_ISSET(i,mask) \ |
| 719 | _KMP_CPU_ISSET((i), ((kmp_affin_mask_t *)(mask))) |
| 720 | |
| 721 | # define _KMP_CPU_CLR(i,mask) \ |
| 722 | (mask[i/(CHAR_BIT * sizeof(kmp_affin_mask_t))] &= \ |
| 723 | ~(((kmp_affin_mask_t)1) << (i % (CHAR_BIT * sizeof(kmp_affin_mask_t))))) |
| 724 | |
| 725 | # define KMP_CPU_CLR(i,mask) \ |
| 726 | _KMP_CPU_CLR((i), ((kmp_affin_mask_t *)(mask))) |
| 727 | |
| 728 | # define KMP_CPU_ZERO(mask) \ |
| 729 | { \ |
| 730 | int __i; \ |
| 731 | for (__i = 0; __i < __kmp_num_proc_groups; __i++) { \ |
| 732 | ((kmp_affin_mask_t *)(mask))[__i] = 0; \ |
| 733 | } \ |
| 734 | } |
| 735 | |
| 736 | # define KMP_CPU_COPY(dest, src) \ |
| 737 | { \ |
| 738 | int __i; \ |
| 739 | for (__i = 0; __i < __kmp_num_proc_groups; __i++) { \ |
| 740 | ((kmp_affin_mask_t *)(dest))[__i] \ |
| 741 | = ((kmp_affin_mask_t *)(src))[__i]; \ |
| 742 | } \ |
| 743 | } |
| 744 | |
| Jonathan Peyton | 34c72c4 | 2016-06-13 17:01:26 +0000 | [diff] [blame] | 745 | # define KMP_CPU_AND(dest, src) \ |
| 746 | { \ |
| 747 | int __i; \ |
| 748 | for (__i = 0; __i < __kmp_num_proc_groups; __i++) { \ |
| 749 | ((kmp_affin_mask_t *)(dest))[__i] \ |
| 750 | &= ((kmp_affin_mask_t *)(src))[__i]; \ |
| 751 | } \ |
| 752 | } |
| 753 | |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 754 | # define KMP_CPU_COMPLEMENT(max_bit_number, mask) \ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 755 | { \ |
| 756 | int __i; \ |
| 757 | for (__i = 0; __i < __kmp_num_proc_groups; __i++) { \ |
| 758 | ((kmp_affin_mask_t *)(mask))[__i] \ |
| 759 | = ~((kmp_affin_mask_t *)(mask))[__i]; \ |
| 760 | } \ |
| Jonathan Peyton | c5304aa | 2016-06-13 21:28:03 +0000 | [diff] [blame] | 761 | KMP_CPU_AND(mask, __kmp_affin_fullMask); \ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | # define KMP_CPU_UNION(dest, src) \ |
| 765 | { \ |
| 766 | int __i; \ |
| 767 | for (__i = 0; __i < __kmp_num_proc_groups; __i++) { \ |
| 768 | ((kmp_affin_mask_t *)(dest))[__i] \ |
| 769 | |= ((kmp_affin_mask_t *)(src))[__i]; \ |
| 770 | } \ |
| 771 | } |
| 772 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 773 | |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 774 | # else /* KMP_GROUP_AFFINITY */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 775 | |
| 776 | typedef DWORD kmp_affin_mask_t; /* for compatibility with older winbase.h */ |
| 777 | |
| 778 | # define KMP_CPU_SET(i,mask) (*(mask) |= (((kmp_affin_mask_t)1) << (i))) |
| 779 | # define KMP_CPU_ISSET(i,mask) (!!(*(mask) & (((kmp_affin_mask_t)1) << (i)))) |
| 780 | # define KMP_CPU_CLR(i,mask) (*(mask) &= ~(((kmp_affin_mask_t)1) << (i))) |
| 781 | # define KMP_CPU_ZERO(mask) (*(mask) = 0) |
| 782 | # define KMP_CPU_COPY(dest, src) (*(dest) = *(src)) |
| Jonathan Peyton | 34c72c4 | 2016-06-13 17:01:26 +0000 | [diff] [blame] | 783 | # define KMP_CPU_AND(dest, src) (*(dest) &= *(src)) |
| Jonathan Peyton | c5304aa | 2016-06-13 21:28:03 +0000 | [diff] [blame] | 784 | # define KMP_CPU_COMPLEMENT(max_bit_number, mask) (*(mask) = ~*(mask)); KMP_CPU_AND(mask, __kmp_affin_fullMask) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 785 | # define KMP_CPU_UNION(dest, src) (*(dest) |= *(src)) |
| 786 | |
| Andrey Churbanov | 7daf980 | 2015-01-27 16:52:57 +0000 | [diff] [blame] | 787 | # endif /* KMP_GROUP_AFFINITY */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 788 | |
| 789 | # endif /* KMP_OS_WINDOWS */ |
| 790 | |
| 791 | // |
| 792 | // __kmp_allocate() will return memory allocated on a 4-bytes boundary. |
| 793 | // after zeroing it - it takes care of those assumptions stated above. |
| 794 | // |
| 795 | # define KMP_CPU_ALLOC(ptr) \ |
| 796 | (ptr = ((kmp_affin_mask_t *)__kmp_allocate(__kmp_affin_mask_size))) |
| 797 | # define KMP_CPU_FREE(ptr) __kmp_free(ptr) |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 798 | # define KMP_CPU_ALLOC_ON_STACK(ptr) (ptr = ((kmp_affin_mask_t *)KMP_ALLOCA(__kmp_affin_mask_size))) |
| 799 | # define KMP_CPU_FREE_FROM_STACK(ptr) /* Nothing */ |
| 800 | # define KMP_CPU_INTERNAL_ALLOC(ptr) (ptr = ((kmp_affin_mask_t *)KMP_INTERNAL_MALLOC(__kmp_affin_mask_size))) |
| 801 | # define KMP_CPU_INTERNAL_FREE(ptr) KMP_INTERNAL_FREE(ptr) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 802 | |
| 803 | // |
| 804 | // The following macro should be used to index an array of masks. |
| 805 | // The array should be declared as "kmp_affinity_t *" and allocated with |
| 806 | // size "__kmp_affinity_mask_size * len". The macro takes care of the fact |
| 807 | // that on Windows* OS, sizeof(kmp_affin_t) is really the size of the mask, but |
| 808 | // on Linux* OS, sizeof(kmp_affin_t) is 1. |
| 809 | // |
| 810 | # define KMP_CPU_INDEX(array,i) \ |
| 811 | ((kmp_affin_mask_t *)(((char *)(array)) + (i) * __kmp_affin_mask_size)) |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 812 | # define KMP_CPU_ALLOC_ARRAY(arr, n) arr = (kmp_affin_mask_t *)__kmp_allocate(n * __kmp_affin_mask_size) |
| 813 | # define KMP_CPU_FREE_ARRAY(arr, n) __kmp_free(arr); |
| 814 | # define KMP_CPU_INTERNAL_ALLOC_ARRAY(arr, n) arr = (kmp_affin_mask_t *)KMP_INTERNAL_MALLOC(n * __kmp_affin_mask_size) |
| 815 | # define KMP_CPU_INTERNAL_FREE_ARRAY(arr, n) KMP_INTERNAL_FREE(arr); |
| 816 | |
| 817 | #endif /* KMP_USE_HWLOC */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 818 | |
| Jonathan Peyton | 0f3c2b9 | 2016-06-16 20:23:11 +0000 | [diff] [blame] | 819 | // prototype after typedef of kmp_affin_mask_t |
| 820 | #if KMP_GROUP_AFFINITY |
| 821 | extern int __kmp_get_proc_group(kmp_affin_mask_t const *mask); |
| 822 | #endif |
| 823 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 824 | // |
| 825 | // Declare local char buffers with this size for printing debug and info |
| 826 | // messages, using __kmp_affinity_print_mask(). |
| 827 | // |
| 828 | #define KMP_AFFIN_MASK_PRINT_LEN 1024 |
| 829 | |
| 830 | enum affinity_type { |
| 831 | affinity_none = 0, |
| 832 | affinity_physical, |
| 833 | affinity_logical, |
| 834 | affinity_compact, |
| 835 | affinity_scatter, |
| 836 | affinity_explicit, |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 837 | affinity_balanced, |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 838 | affinity_disabled, // not used outsize the env var parser |
| 839 | affinity_default |
| 840 | }; |
| 841 | |
| 842 | enum affinity_gran { |
| 843 | affinity_gran_fine = 0, |
| 844 | affinity_gran_thread, |
| 845 | affinity_gran_core, |
| 846 | affinity_gran_package, |
| 847 | affinity_gran_node, |
| Andrey Churbanov | 7daf980 | 2015-01-27 16:52:57 +0000 | [diff] [blame] | 848 | #if KMP_GROUP_AFFINITY |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 849 | // |
| 850 | // The "group" granularity isn't necesssarily coarser than all of the |
| 851 | // other levels, but we put it last in the enum. |
| 852 | // |
| 853 | affinity_gran_group, |
| Andrey Churbanov | 7daf980 | 2015-01-27 16:52:57 +0000 | [diff] [blame] | 854 | #endif /* KMP_GROUP_AFFINITY */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 855 | affinity_gran_default |
| 856 | }; |
| 857 | |
| 858 | enum affinity_top_method { |
| 859 | affinity_top_method_all = 0, // try all (supported) methods, in order |
| 860 | #if KMP_ARCH_X86 || KMP_ARCH_X86_64 |
| 861 | affinity_top_method_apicid, |
| 862 | affinity_top_method_x2apicid, |
| 863 | #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */ |
| 864 | affinity_top_method_cpuinfo, // KMP_CPUINFO_FILE is usable on Windows* OS, too |
| Andrey Churbanov | 7daf980 | 2015-01-27 16:52:57 +0000 | [diff] [blame] | 865 | #if KMP_GROUP_AFFINITY |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 866 | affinity_top_method_group, |
| Andrey Churbanov | 7daf980 | 2015-01-27 16:52:57 +0000 | [diff] [blame] | 867 | #endif /* KMP_GROUP_AFFINITY */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 868 | affinity_top_method_flat, |
| Jonathan Peyton | 01dcf36 | 2015-11-30 20:02:59 +0000 | [diff] [blame] | 869 | #if KMP_USE_HWLOC |
| 870 | affinity_top_method_hwloc, |
| 871 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 872 | affinity_top_method_default |
| 873 | }; |
| 874 | |
| 875 | #define affinity_respect_mask_default (-1) |
| 876 | |
| 877 | extern enum affinity_type __kmp_affinity_type; /* Affinity type */ |
| 878 | extern enum affinity_gran __kmp_affinity_gran; /* Affinity granularity */ |
| 879 | extern int __kmp_affinity_gran_levels; /* corresponding int value */ |
| 880 | extern int __kmp_affinity_dups; /* Affinity duplicate masks */ |
| 881 | extern enum affinity_top_method __kmp_affinity_top_method; |
| 882 | extern int __kmp_affinity_compact; /* Affinity 'compact' value */ |
| 883 | extern int __kmp_affinity_offset; /* Affinity offset value */ |
| 884 | extern int __kmp_affinity_verbose; /* Was verbose specified for KMP_AFFINITY? */ |
| 885 | extern int __kmp_affinity_warnings; /* KMP_AFFINITY warnings enabled ? */ |
| 886 | extern int __kmp_affinity_respect_mask; /* Respect process' initial affinity mask? */ |
| 887 | extern char * __kmp_affinity_proclist; /* proc ID list */ |
| 888 | extern kmp_affin_mask_t *__kmp_affinity_masks; |
| 889 | extern unsigned __kmp_affinity_num_masks; |
| 890 | extern int __kmp_get_system_affinity(kmp_affin_mask_t *mask, int abort_on_error); |
| 891 | extern int __kmp_set_system_affinity(kmp_affin_mask_t const *mask, int abort_on_error); |
| 892 | extern void __kmp_affinity_bind_thread(int which); |
| 893 | |
| Jonathan Peyton | c5304aa | 2016-06-13 21:28:03 +0000 | [diff] [blame] | 894 | extern kmp_affin_mask_t *__kmp_affin_fullMask; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 895 | extern char const * __kmp_cpuinfo_file; |
| 896 | |
| Alp Toker | 763b939 | 2014-02-28 09:42:41 +0000 | [diff] [blame] | 897 | #endif /* KMP_AFFINITY_SUPPORTED */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 898 | |
| 899 | #if OMP_40_ENABLED |
| 900 | |
| 901 | // |
| 902 | // This needs to be kept in sync with the values in omp.h !!! |
| 903 | // |
| 904 | typedef enum kmp_proc_bind_t { |
| 905 | proc_bind_false = 0, |
| 906 | proc_bind_true, |
| 907 | proc_bind_master, |
| 908 | proc_bind_close, |
| 909 | proc_bind_spread, |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 910 | proc_bind_intel, // use KMP_AFFINITY interface |
| 911 | proc_bind_default |
| 912 | } kmp_proc_bind_t; |
| 913 | |
| 914 | typedef struct kmp_nested_proc_bind_t { |
| 915 | kmp_proc_bind_t *bind_types; |
| 916 | int size; |
| 917 | int used; |
| 918 | } kmp_nested_proc_bind_t; |
| 919 | |
| 920 | extern kmp_nested_proc_bind_t __kmp_nested_proc_bind; |
| 921 | |
| Andrey Churbanov | cbda868 | 2015-01-13 14:43:35 +0000 | [diff] [blame] | 922 | #endif /* OMP_40_ENABLED */ |
| 923 | |
| Alp Toker | 98758b0 | 2014-03-02 04:12:06 +0000 | [diff] [blame] | 924 | # if KMP_AFFINITY_SUPPORTED |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 925 | # define KMP_PLACE_ALL (-1) |
| 926 | # define KMP_PLACE_UNDEFINED (-2) |
| Alp Toker | 98758b0 | 2014-03-02 04:12:06 +0000 | [diff] [blame] | 927 | # endif /* KMP_AFFINITY_SUPPORTED */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 928 | |
| 929 | extern int __kmp_affinity_num_places; |
| 930 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 931 | |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 932 | #if OMP_40_ENABLED |
| 933 | typedef enum kmp_cancel_kind_t { |
| 934 | cancel_noreq = 0, |
| 935 | cancel_parallel = 1, |
| 936 | cancel_loop = 2, |
| 937 | cancel_sections = 3, |
| 938 | cancel_taskgroup = 4 |
| 939 | } kmp_cancel_kind_t; |
| 940 | #endif // OMP_40_ENABLED |
| 941 | |
| Jonathan Peyton | dd4aa9b | 2015-10-08 17:55:54 +0000 | [diff] [blame] | 942 | extern int __kmp_place_num_sockets; |
| 943 | extern int __kmp_place_socket_offset; |
| Andrey Churbanov | 1287557 | 2015-03-10 09:00:36 +0000 | [diff] [blame] | 944 | extern int __kmp_place_num_cores; |
| Andrey Churbanov | 1287557 | 2015-03-10 09:00:36 +0000 | [diff] [blame] | 945 | extern int __kmp_place_core_offset; |
| Jonathan Peyton | dd4aa9b | 2015-10-08 17:55:54 +0000 | [diff] [blame] | 946 | extern int __kmp_place_num_threads_per_core; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 947 | |
| 948 | /* ------------------------------------------------------------------------ */ |
| 949 | /* ------------------------------------------------------------------------ */ |
| 950 | |
| 951 | #define KMP_PAD(type, sz) (sizeof(type) + (sz - ((sizeof(type) - 1) % (sz)) - 1)) |
| 952 | |
| 953 | // |
| 954 | // We need to avoid using -1 as a GTID as +1 is added to the gtid |
| 955 | // when storing it in a lock, and the value 0 is reserved. |
| 956 | // |
| 957 | #define KMP_GTID_DNE (-2) /* Does not exist */ |
| 958 | #define KMP_GTID_SHUTDOWN (-3) /* Library is shutting down */ |
| 959 | #define KMP_GTID_MONITOR (-4) /* Monitor thread ID */ |
| 960 | #define KMP_GTID_UNKNOWN (-5) /* Is not known */ |
| 961 | #define KMP_GTID_MIN (-6) /* Minimal gtid for low bound check in DEBUG */ |
| 962 | |
| 963 | #define __kmp_get_gtid() __kmp_get_global_thread_id() |
| 964 | #define __kmp_entry_gtid() __kmp_get_global_thread_id_reg() |
| 965 | |
| 966 | #define __kmp_tid_from_gtid(gtid) ( KMP_DEBUG_ASSERT( (gtid) >= 0 ), \ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 967 | __kmp_threads[ (gtid) ]->th.th_info.ds.ds_tid ) |
| 968 | |
| 969 | #define __kmp_get_tid() ( __kmp_tid_from_gtid( __kmp_get_gtid() ) ) |
| 970 | #define __kmp_gtid_from_tid(tid,team) ( KMP_DEBUG_ASSERT( (tid) >= 0 && (team) != NULL ), \ |
| 971 | team -> t.t_threads[ (tid) ] -> th.th_info .ds.ds_gtid ) |
| 972 | |
| 973 | #define __kmp_get_team() ( __kmp_threads[ (__kmp_get_gtid()) ]-> th.th_team ) |
| 974 | #define __kmp_team_from_gtid(gtid) ( KMP_DEBUG_ASSERT( (gtid) >= 0 ), \ |
| 975 | __kmp_threads[ (gtid) ]-> th.th_team ) |
| 976 | |
| 977 | #define __kmp_thread_from_gtid(gtid) ( KMP_DEBUG_ASSERT( (gtid) >= 0 ), __kmp_threads[ (gtid) ] ) |
| 978 | #define __kmp_get_thread() ( __kmp_thread_from_gtid( __kmp_get_gtid() ) ) |
| 979 | |
| 980 | // Returns current thread (pointer to kmp_info_t). In contrast to __kmp_get_thread(), it works |
| 981 | // with registered and not-yet-registered threads. |
| 982 | #define __kmp_gtid_from_thread(thr) ( KMP_DEBUG_ASSERT( (thr) != NULL ), \ |
| 983 | (thr)->th.th_info.ds.ds_gtid ) |
| 984 | |
| 985 | // AT: Which way is correct? |
| 986 | // AT: 1. nproc = __kmp_threads[ ( gtid ) ] -> th.th_team -> t.t_nproc; |
| 987 | // AT: 2. nproc = __kmp_threads[ ( gtid ) ] -> th.th_team_nproc; |
| 988 | #define __kmp_get_team_num_threads(gtid) ( __kmp_threads[ ( gtid ) ] -> th.th_team -> t.t_nproc ) |
| 989 | |
| 990 | |
| 991 | /* ------------------------------------------------------------------------ */ |
| 992 | /* ------------------------------------------------------------------------ */ |
| 993 | |
| 994 | #define KMP_UINT64_MAX (~((kmp_uint64)1<<((sizeof(kmp_uint64)*(1<<3))-1))) |
| 995 | |
| 996 | #define KMP_MIN_NTH 1 |
| 997 | |
| 998 | #ifndef KMP_MAX_NTH |
| Dimitry Andric | 9b8c353 | 2015-10-19 17:32:04 +0000 | [diff] [blame] | 999 | # if defined(PTHREAD_THREADS_MAX) && PTHREAD_THREADS_MAX < INT_MAX |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1000 | # define KMP_MAX_NTH PTHREAD_THREADS_MAX |
| 1001 | # else |
| Dimitry Andric | 9b8c353 | 2015-10-19 17:32:04 +0000 | [diff] [blame] | 1002 | # define KMP_MAX_NTH INT_MAX |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1003 | # endif |
| 1004 | #endif /* KMP_MAX_NTH */ |
| 1005 | |
| 1006 | #ifdef PTHREAD_STACK_MIN |
| 1007 | # define KMP_MIN_STKSIZE PTHREAD_STACK_MIN |
| 1008 | #else |
| 1009 | # define KMP_MIN_STKSIZE ((size_t)(32 * 1024)) |
| 1010 | #endif |
| 1011 | |
| 1012 | #define KMP_MAX_STKSIZE (~((size_t)1<<((sizeof(size_t)*(1<<3))-1))) |
| 1013 | |
| 1014 | #if KMP_ARCH_X86 |
| 1015 | # define KMP_DEFAULT_STKSIZE ((size_t)(2 * 1024 * 1024)) |
| 1016 | #elif KMP_ARCH_X86_64 |
| 1017 | # define KMP_DEFAULT_STKSIZE ((size_t)(4 * 1024 * 1024)) |
| 1018 | # define KMP_BACKUP_STKSIZE ((size_t)(2 * 1024 * 1024)) |
| 1019 | #else |
| 1020 | # define KMP_DEFAULT_STKSIZE ((size_t)(1024 * 1024)) |
| 1021 | #endif |
| 1022 | |
| 1023 | #define KMP_DEFAULT_MONITOR_STKSIZE ((size_t)(64 * 1024)) |
| 1024 | |
| 1025 | #define KMP_DEFAULT_MALLOC_POOL_INCR ((size_t) (1024 * 1024)) |
| 1026 | #define KMP_MIN_MALLOC_POOL_INCR ((size_t) (4 * 1024)) |
| 1027 | #define KMP_MAX_MALLOC_POOL_INCR (~((size_t)1<<((sizeof(size_t)*(1<<3))-1))) |
| 1028 | |
| 1029 | #define KMP_MIN_STKOFFSET (0) |
| 1030 | #define KMP_MAX_STKOFFSET KMP_MAX_STKSIZE |
| Andrey Churbanov | a5547bc | 2015-02-20 17:57:58 +0000 | [diff] [blame] | 1031 | #if KMP_OS_DARWIN |
| 1032 | # define KMP_DEFAULT_STKOFFSET KMP_MIN_STKOFFSET |
| 1033 | #else |
| 1034 | # define KMP_DEFAULT_STKOFFSET CACHE_LINE |
| 1035 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1036 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1037 | #define KMP_MIN_STKPADDING (0) |
| 1038 | #define KMP_MAX_STKPADDING (2 * 1024 * 1024) |
| 1039 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1040 | #define KMP_MIN_MONITOR_WAKEUPS (1) /* min number of times monitor wakes up per second */ |
| 1041 | #define KMP_MAX_MONITOR_WAKEUPS (1000) /* maximum number of times monitor can wake up per second */ |
| 1042 | #define KMP_BLOCKTIME_MULTIPLIER (1000) /* number of blocktime units per second */ |
| 1043 | #define KMP_MIN_BLOCKTIME (0) |
| 1044 | #define KMP_MAX_BLOCKTIME (INT_MAX) /* Must be this for "infinite" setting the work */ |
| 1045 | #define KMP_DEFAULT_BLOCKTIME (200) /* __kmp_blocktime is in milliseconds */ |
| 1046 | /* Calculate new number of monitor wakeups for a specific block time based on previous monitor_wakeups */ |
| 1047 | /* Only allow increasing number of wakeups */ |
| 1048 | #define KMP_WAKEUPS_FROM_BLOCKTIME(blocktime, monitor_wakeups) \ |
| 1049 | ( ((blocktime) == KMP_MAX_BLOCKTIME) ? (monitor_wakeups) : \ |
| 1050 | ((blocktime) == KMP_MIN_BLOCKTIME) ? KMP_MAX_MONITOR_WAKEUPS : \ |
| 1051 | ((monitor_wakeups) > (KMP_BLOCKTIME_MULTIPLIER / (blocktime))) ? (monitor_wakeups) : \ |
| 1052 | (KMP_BLOCKTIME_MULTIPLIER) / (blocktime) ) |
| 1053 | |
| 1054 | /* Calculate number of intervals for a specific block time based on monitor_wakeups */ |
| 1055 | #define KMP_INTERVALS_FROM_BLOCKTIME(blocktime, monitor_wakeups) \ |
| 1056 | ( ( (blocktime) + (KMP_BLOCKTIME_MULTIPLIER / (monitor_wakeups)) - 1 ) / \ |
| 1057 | (KMP_BLOCKTIME_MULTIPLIER / (monitor_wakeups)) ) |
| 1058 | |
| 1059 | #define KMP_MIN_STATSCOLS 40 |
| 1060 | #define KMP_MAX_STATSCOLS 4096 |
| 1061 | #define KMP_DEFAULT_STATSCOLS 80 |
| 1062 | |
| 1063 | #define KMP_MIN_INTERVAL 0 |
| 1064 | #define KMP_MAX_INTERVAL (INT_MAX-1) |
| 1065 | #define KMP_DEFAULT_INTERVAL 0 |
| 1066 | |
| 1067 | #define KMP_MIN_CHUNK 1 |
| 1068 | #define KMP_MAX_CHUNK (INT_MAX-1) |
| 1069 | #define KMP_DEFAULT_CHUNK 1 |
| 1070 | |
| 1071 | #define KMP_MIN_INIT_WAIT 1 |
| 1072 | #define KMP_MAX_INIT_WAIT (INT_MAX/2) |
| 1073 | #define KMP_DEFAULT_INIT_WAIT 2048U |
| 1074 | |
| 1075 | #define KMP_MIN_NEXT_WAIT 1 |
| 1076 | #define KMP_MAX_NEXT_WAIT (INT_MAX/2) |
| 1077 | #define KMP_DEFAULT_NEXT_WAIT 1024U |
| 1078 | |
| Jonathan Peyton | 067325f | 2016-05-31 19:01:15 +0000 | [diff] [blame] | 1079 | #define KMP_DFLT_DISP_NUM_BUFF 7 |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1080 | #define KMP_MAX_ORDERED 8 |
| 1081 | |
| 1082 | #define KMP_MAX_FIELDS 32 |
| 1083 | |
| 1084 | #define KMP_MAX_BRANCH_BITS 31 |
| 1085 | |
| 1086 | #define KMP_MAX_ACTIVE_LEVELS_LIMIT INT_MAX |
| 1087 | |
| Jonathan Peyton | 2851072 | 2016-02-25 18:04:09 +0000 | [diff] [blame] | 1088 | #define KMP_MAX_TASK_PRIORITY_LIMIT INT_MAX |
| 1089 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1090 | /* Minimum number of threads before switch to TLS gtid (experimentally determined) */ |
| 1091 | /* josh TODO: what about OS X* tuning? */ |
| 1092 | #if KMP_ARCH_X86 || KMP_ARCH_X86_64 |
| 1093 | # define KMP_TLS_GTID_MIN 5 |
| 1094 | #else |
| 1095 | # define KMP_TLS_GTID_MIN INT_MAX |
| 1096 | #endif |
| 1097 | |
| 1098 | #define KMP_MASTER_TID(tid) ( (tid) == 0 ) |
| 1099 | #define KMP_WORKER_TID(tid) ( (tid) != 0 ) |
| 1100 | |
| 1101 | #define KMP_MASTER_GTID(gtid) ( __kmp_tid_from_gtid((gtid)) == 0 ) |
| 1102 | #define KMP_WORKER_GTID(gtid) ( __kmp_tid_from_gtid((gtid)) != 0 ) |
| 1103 | #define KMP_UBER_GTID(gtid) \ |
| 1104 | ( \ |
| 1105 | KMP_DEBUG_ASSERT( (gtid) >= KMP_GTID_MIN ), \ |
| 1106 | KMP_DEBUG_ASSERT( (gtid) < __kmp_threads_capacity ), \ |
| 1107 | (gtid) >= 0 && __kmp_root[(gtid)] && __kmp_threads[(gtid)] && \ |
| 1108 | (__kmp_threads[(gtid)] == __kmp_root[(gtid)]->r.r_uber_thread)\ |
| 1109 | ) |
| 1110 | #define KMP_INITIAL_GTID(gtid) ( (gtid) == 0 ) |
| 1111 | |
| 1112 | #ifndef TRUE |
| 1113 | #define FALSE 0 |
| 1114 | #define TRUE (! FALSE) |
| 1115 | #endif |
| 1116 | |
| 1117 | /* NOTE: all of the following constants must be even */ |
| 1118 | |
| 1119 | #if KMP_OS_WINDOWS |
| 1120 | # define KMP_INIT_WAIT 64U /* initial number of spin-tests */ |
| 1121 | # define KMP_NEXT_WAIT 32U /* susequent number of spin-tests */ |
| Jim Cownie | 3051f97 | 2014-08-07 10:12:54 +0000 | [diff] [blame] | 1122 | #elif KMP_OS_CNK |
| 1123 | # define KMP_INIT_WAIT 16U /* initial number of spin-tests */ |
| 1124 | # define KMP_NEXT_WAIT 8U /* susequent number of spin-tests */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1125 | #elif KMP_OS_LINUX |
| 1126 | # define KMP_INIT_WAIT 1024U /* initial number of spin-tests */ |
| 1127 | # define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */ |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1128 | #elif KMP_OS_DARWIN |
| 1129 | /* TODO: tune for KMP_OS_DARWIN */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1130 | # define KMP_INIT_WAIT 1024U /* initial number of spin-tests */ |
| 1131 | # define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */ |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1132 | #elif KMP_OS_FREEBSD |
| 1133 | /* TODO: tune for KMP_OS_FREEBSD */ |
| 1134 | # define KMP_INIT_WAIT 1024U /* initial number of spin-tests */ |
| 1135 | # define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */ |
| Joerg Sonnenberger | 1564f3c | 2015-09-21 20:02:45 +0000 | [diff] [blame] | 1136 | #elif KMP_OS_NETBSD |
| 1137 | /* TODO: tune for KMP_OS_NETBSD */ |
| 1138 | # define KMP_INIT_WAIT 1024U /* initial number of spin-tests */ |
| 1139 | # define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1140 | #endif |
| 1141 | |
| 1142 | #if KMP_ARCH_X86 || KMP_ARCH_X86_64 |
| Andrey Churbanov | 613edeb | 2015-02-20 18:14:43 +0000 | [diff] [blame] | 1143 | typedef struct kmp_cpuid { |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1144 | kmp_uint32 eax; |
| 1145 | kmp_uint32 ebx; |
| 1146 | kmp_uint32 ecx; |
| 1147 | kmp_uint32 edx; |
| Andrey Churbanov | 613edeb | 2015-02-20 18:14:43 +0000 | [diff] [blame] | 1148 | } kmp_cpuid_t; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1149 | extern void __kmp_x86_cpuid( int mode, int mode2, struct kmp_cpuid *p ); |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1150 | # if KMP_ARCH_X86 |
| 1151 | extern void __kmp_x86_pause( void ); |
| 1152 | # elif KMP_MIC |
| Jonathan Peyton | 95c95c3 | 2016-02-18 19:38:25 +0000 | [diff] [blame] | 1153 | static void __kmp_x86_pause( void ) { _mm_delay_32( 100 ); } |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1154 | # else |
| Jonathan Peyton | 95c95c3 | 2016-02-18 19:38:25 +0000 | [diff] [blame] | 1155 | static void __kmp_x86_pause( void ) { _mm_pause(); } |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1156 | # endif |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1157 | # define KMP_CPU_PAUSE() __kmp_x86_pause() |
| Jim Cownie | 3051f97 | 2014-08-07 10:12:54 +0000 | [diff] [blame] | 1158 | #elif KMP_ARCH_PPC64 |
| 1159 | # define KMP_PPC64_PRI_LOW() __asm__ volatile ("or 1, 1, 1") |
| 1160 | # define KMP_PPC64_PRI_MED() __asm__ volatile ("or 2, 2, 2") |
| 1161 | # define KMP_PPC64_PRI_LOC_MB() __asm__ volatile ("" : : : "memory") |
| 1162 | # define KMP_CPU_PAUSE() do { KMP_PPC64_PRI_LOW(); KMP_PPC64_PRI_MED(); KMP_PPC64_PRI_LOC_MB(); } while (0) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1163 | #else |
| 1164 | # define KMP_CPU_PAUSE() /* nothing to do */ |
| 1165 | #endif |
| 1166 | |
| 1167 | #define KMP_INIT_YIELD(count) { (count) = __kmp_yield_init; } |
| 1168 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1169 | #define KMP_YIELD(cond) { KMP_CPU_PAUSE(); __kmp_yield( (cond) ); } |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1170 | |
| 1171 | // Note the decrement of 2 in the following Macros. With KMP_LIBRARY=turnaround, |
| 1172 | // there should be no yielding since the starting value from KMP_INIT_YIELD() is odd. |
| 1173 | |
| 1174 | #define KMP_YIELD_WHEN(cond,count) { KMP_CPU_PAUSE(); (count) -= 2; \ |
| 1175 | if (!(count)) { KMP_YIELD(cond); (count) = __kmp_yield_next; } } |
| 1176 | #define KMP_YIELD_SPIN(count) { KMP_CPU_PAUSE(); (count) -=2; \ |
| 1177 | if (!(count)) { KMP_YIELD(1); (count) = __kmp_yield_next; } } |
| 1178 | |
| 1179 | /* ------------------------------------------------------------------------ */ |
| 1180 | /* Support datatypes for the orphaned construct nesting checks. */ |
| 1181 | /* ------------------------------------------------------------------------ */ |
| 1182 | |
| 1183 | enum cons_type { |
| 1184 | ct_none, |
| 1185 | ct_parallel, |
| 1186 | ct_pdo, |
| 1187 | ct_pdo_ordered, |
| 1188 | ct_psections, |
| 1189 | ct_psingle, |
| 1190 | |
| 1191 | /* the following must be left in order and not split up */ |
| 1192 | ct_taskq, |
| 1193 | ct_task, /* really task inside non-ordered taskq, considered a worksharing type */ |
| 1194 | ct_task_ordered, /* really task inside ordered taskq, considered a worksharing type */ |
| 1195 | /* the preceding must be left in order and not split up */ |
| 1196 | |
| 1197 | ct_critical, |
| 1198 | ct_ordered_in_parallel, |
| 1199 | ct_ordered_in_pdo, |
| 1200 | ct_ordered_in_taskq, |
| 1201 | ct_master, |
| 1202 | ct_reduce, |
| 1203 | ct_barrier |
| 1204 | }; |
| 1205 | |
| 1206 | /* test to see if we are in a taskq construct */ |
| 1207 | # define IS_CONS_TYPE_TASKQ( ct ) ( ((int)(ct)) >= ((int)ct_taskq) && ((int)(ct)) <= ((int)ct_task_ordered) ) |
| 1208 | # define IS_CONS_TYPE_ORDERED( ct ) ((ct) == ct_pdo_ordered || (ct) == ct_task_ordered) |
| 1209 | |
| 1210 | struct cons_data { |
| 1211 | ident_t const *ident; |
| 1212 | enum cons_type type; |
| 1213 | int prev; |
| 1214 | kmp_user_lock_p name; /* address exclusively for critical section name comparison */ |
| 1215 | }; |
| 1216 | |
| 1217 | struct cons_header { |
| 1218 | int p_top, w_top, s_top; |
| 1219 | int stack_size, stack_top; |
| 1220 | struct cons_data *stack_data; |
| 1221 | }; |
| 1222 | |
| 1223 | struct kmp_region_info { |
| 1224 | char *text; |
| 1225 | int offset[KMP_MAX_FIELDS]; |
| 1226 | int length[KMP_MAX_FIELDS]; |
| 1227 | }; |
| 1228 | |
| 1229 | |
| 1230 | /* ---------------------------------------------------------------------- */ |
| 1231 | /* ---------------------------------------------------------------------- */ |
| 1232 | |
| 1233 | #if KMP_OS_WINDOWS |
| 1234 | typedef HANDLE kmp_thread_t; |
| 1235 | typedef DWORD kmp_key_t; |
| 1236 | #endif /* KMP_OS_WINDOWS */ |
| 1237 | |
| 1238 | #if KMP_OS_UNIX |
| 1239 | typedef pthread_t kmp_thread_t; |
| 1240 | typedef pthread_key_t kmp_key_t; |
| 1241 | #endif |
| 1242 | |
| 1243 | extern kmp_key_t __kmp_gtid_threadprivate_key; |
| 1244 | |
| 1245 | typedef struct kmp_sys_info { |
| 1246 | long maxrss; /* the maximum resident set size utilized (in kilobytes) */ |
| 1247 | long minflt; /* the number of page faults serviced without any I/O */ |
| 1248 | long majflt; /* the number of page faults serviced that required I/O */ |
| 1249 | long nswap; /* the number of times a process was "swapped" out of memory */ |
| 1250 | long inblock; /* the number of times the file system had to perform input */ |
| 1251 | long oublock; /* the number of times the file system had to perform output */ |
| 1252 | long nvcsw; /* the number of times a context switch was voluntarily */ |
| 1253 | long nivcsw; /* the number of times a context switch was forced */ |
| 1254 | } kmp_sys_info_t; |
| 1255 | |
| Hal Finkel | 01bb240 | 2016-03-27 13:24:09 +0000 | [diff] [blame] | 1256 | #if KMP_ARCH_X86 || KMP_ARCH_X86_64 |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1257 | typedef struct kmp_cpuinfo { |
| 1258 | int initialized; // If 0, other fields are not initialized. |
| 1259 | int signature; // CPUID(1).EAX |
| 1260 | int family; // CPUID(1).EAX[27:20] + CPUID(1).EAX[11:8] ( Extended Family + Family ) |
| 1261 | int model; // ( CPUID(1).EAX[19:16] << 4 ) + CPUID(1).EAX[7:4] ( ( Extended Model << 4 ) + Model) |
| 1262 | int stepping; // CPUID(1).EAX[3:0] ( Stepping ) |
| 1263 | int sse2; // 0 if SSE2 instructions are not supported, 1 otherwise. |
| 1264 | int rtm; // 0 if RTM instructions are not supported, 1 otherwise. |
| 1265 | int cpu_stackoffset; |
| 1266 | int apic_id; |
| 1267 | int physical_id; |
| 1268 | int logical_id; |
| 1269 | kmp_uint64 frequency; // Nominal CPU frequency in Hz. |
| Jonathan Peyton | 6e98d798 | 2016-03-15 20:28:47 +0000 | [diff] [blame] | 1270 | char name [3*sizeof (kmp_cpuid_t)]; // CPUID(0x80000002,0x80000003,0x80000004) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1271 | } kmp_cpuinfo_t; |
| Hal Finkel | 01bb240 | 2016-03-27 13:24:09 +0000 | [diff] [blame] | 1272 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1273 | |
| 1274 | #ifdef BUILD_TV |
| 1275 | |
| 1276 | struct tv_threadprivate { |
| 1277 | /* Record type #1 */ |
| 1278 | void *global_addr; |
| 1279 | void *thread_addr; |
| 1280 | }; |
| 1281 | |
| 1282 | struct tv_data { |
| 1283 | struct tv_data *next; |
| 1284 | void *type; |
| 1285 | union tv_union { |
| 1286 | struct tv_threadprivate tp; |
| 1287 | } u; |
| 1288 | }; |
| 1289 | |
| 1290 | extern kmp_key_t __kmp_tv_key; |
| 1291 | |
| 1292 | #endif /* BUILD_TV */ |
| 1293 | |
| 1294 | /* ------------------------------------------------------------------------ */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1295 | |
| 1296 | #if USE_ITT_BUILD |
| 1297 | // We cannot include "kmp_itt.h" due to circular dependency. Declare the only required type here. |
| 1298 | // Later we will check the type meets requirements. |
| 1299 | typedef int kmp_itt_mark_t; |
| 1300 | #define KMP_ITT_DEBUG 0 |
| 1301 | #endif /* USE_ITT_BUILD */ |
| 1302 | |
| 1303 | /* ------------------------------------------------------------------------ */ |
| 1304 | |
| 1305 | /* |
| 1306 | * Taskq data structures |
| 1307 | */ |
| 1308 | |
| 1309 | #define HIGH_WATER_MARK(nslots) (((nslots) * 3) / 4) |
| 1310 | #define __KMP_TASKQ_THUNKS_PER_TH 1 /* num thunks that each thread can simultaneously execute from a task queue */ |
| 1311 | |
| 1312 | /* flags for taskq_global_flags, kmp_task_queue_t tq_flags, kmpc_thunk_t th_flags */ |
| 1313 | |
| 1314 | #define TQF_IS_ORDERED 0x0001 /* __kmpc_taskq interface, taskq ordered */ |
| 1315 | #define TQF_IS_LASTPRIVATE 0x0002 /* __kmpc_taskq interface, taskq with lastprivate list */ |
| 1316 | #define TQF_IS_NOWAIT 0x0004 /* __kmpc_taskq interface, end taskq nowait */ |
| 1317 | #define TQF_HEURISTICS 0x0008 /* __kmpc_taskq interface, use heuristics to decide task queue size */ |
| 1318 | #define TQF_INTERFACE_RESERVED1 0x0010 /* __kmpc_taskq interface, reserved for future use */ |
| 1319 | #define TQF_INTERFACE_RESERVED2 0x0020 /* __kmpc_taskq interface, reserved for future use */ |
| 1320 | #define TQF_INTERFACE_RESERVED3 0x0040 /* __kmpc_taskq interface, reserved for future use */ |
| 1321 | #define TQF_INTERFACE_RESERVED4 0x0080 /* __kmpc_taskq interface, reserved for future use */ |
| 1322 | |
| 1323 | #define TQF_INTERFACE_FLAGS 0x00ff /* all the __kmpc_taskq interface flags */ |
| 1324 | |
| 1325 | #define TQF_IS_LAST_TASK 0x0100 /* internal/read by instrumentation; only used with TQF_IS_LASTPRIVATE */ |
| 1326 | #define TQF_TASKQ_TASK 0x0200 /* internal use only; this thunk->th_task is the taskq_task */ |
| 1327 | #define TQF_RELEASE_WORKERS 0x0400 /* internal use only; must release worker threads once ANY queued task exists (global) */ |
| 1328 | #define TQF_ALL_TASKS_QUEUED 0x0800 /* internal use only; notify workers that master has finished enqueuing tasks */ |
| 1329 | #define TQF_PARALLEL_CONTEXT 0x1000 /* internal use only: this queue encountered in a parallel context: not serialized */ |
| 1330 | #define TQF_DEALLOCATED 0x2000 /* internal use only; this queue is on the freelist and not in use */ |
| 1331 | |
| 1332 | #define TQF_INTERNAL_FLAGS 0x3f00 /* all the internal use only flags */ |
| 1333 | |
| 1334 | typedef struct KMP_ALIGN_CACHE kmpc_aligned_int32_t { |
| 1335 | kmp_int32 ai_data; |
| 1336 | } kmpc_aligned_int32_t; |
| 1337 | |
| 1338 | typedef struct KMP_ALIGN_CACHE kmpc_aligned_queue_slot_t { |
| 1339 | struct kmpc_thunk_t *qs_thunk; |
| 1340 | } kmpc_aligned_queue_slot_t; |
| 1341 | |
| 1342 | typedef struct kmpc_task_queue_t { |
| 1343 | /* task queue linkage fields for n-ary tree of queues (locked with global taskq_tree_lck) */ |
| 1344 | kmp_lock_t tq_link_lck; /* lock for child link, child next/prev links and child ref counts */ |
| 1345 | union { |
| 1346 | struct kmpc_task_queue_t *tq_parent; /* pointer to parent taskq, not locked */ |
| 1347 | struct kmpc_task_queue_t *tq_next_free; /* for taskq internal freelists, locked with global taskq_freelist_lck */ |
| 1348 | } tq; |
| 1349 | volatile struct kmpc_task_queue_t *tq_first_child; /* pointer to linked-list of children, locked by tq's tq_link_lck */ |
| 1350 | struct kmpc_task_queue_t *tq_next_child; /* next child in linked-list, locked by parent tq's tq_link_lck */ |
| 1351 | struct kmpc_task_queue_t *tq_prev_child; /* previous child in linked-list, locked by parent tq's tq_link_lck */ |
| 1352 | volatile kmp_int32 tq_ref_count; /* reference count of threads with access to this task queue */ |
| 1353 | /* (other than the thread executing the kmpc_end_taskq call) */ |
| 1354 | /* locked by parent tq's tq_link_lck */ |
| 1355 | |
| 1356 | /* shared data for task queue */ |
| 1357 | struct kmpc_aligned_shared_vars_t *tq_shareds; /* per-thread array of pointers to shared variable structures */ |
| 1358 | /* only one array element exists for all but outermost taskq */ |
| 1359 | |
| 1360 | /* bookkeeping for ordered task queue */ |
| 1361 | kmp_uint32 tq_tasknum_queuing; /* ordered task number assigned while queuing tasks */ |
| 1362 | volatile kmp_uint32 tq_tasknum_serving; /* ordered number of next task to be served (executed) */ |
| 1363 | |
| 1364 | /* thunk storage management for task queue */ |
| 1365 | kmp_lock_t tq_free_thunks_lck; /* lock for thunk freelist manipulation */ |
| 1366 | struct kmpc_thunk_t *tq_free_thunks; /* thunk freelist, chained via th.th_next_free */ |
| 1367 | struct kmpc_thunk_t *tq_thunk_space; /* space allocated for thunks for this task queue */ |
| 1368 | |
| 1369 | /* data fields for queue itself */ |
| 1370 | kmp_lock_t tq_queue_lck; /* lock for [de]enqueue operations: tq_queue, tq_head, tq_tail, tq_nfull */ |
| 1371 | kmpc_aligned_queue_slot_t *tq_queue; /* array of queue slots to hold thunks for tasks */ |
| 1372 | volatile struct kmpc_thunk_t *tq_taskq_slot; /* special slot for taskq task thunk, occupied if not NULL */ |
| 1373 | kmp_int32 tq_nslots; /* # of tq_thunk_space thunks alloc'd (not incl. tq_taskq_slot space) */ |
| 1374 | kmp_int32 tq_head; /* enqueue puts next item in here (index into tq_queue array) */ |
| 1375 | kmp_int32 tq_tail; /* dequeue takes next item out of here (index into tq_queue array) */ |
| 1376 | volatile kmp_int32 tq_nfull; /* # of occupied entries in task queue right now */ |
| 1377 | kmp_int32 tq_hiwat; /* high-water mark for tq_nfull and queue scheduling */ |
| 1378 | volatile kmp_int32 tq_flags; /* TQF_xxx */ |
| 1379 | |
| Alp Toker | 8f2d3f0 | 2014-02-24 10:40:15 +0000 | [diff] [blame] | 1380 | /* bookkeeping for outstanding thunks */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1381 | struct kmpc_aligned_int32_t *tq_th_thunks; /* per-thread array for # of regular thunks currently being executed */ |
| 1382 | kmp_int32 tq_nproc; /* number of thunks in the th_thunks array */ |
| 1383 | |
| 1384 | /* statistics library bookkeeping */ |
| 1385 | ident_t *tq_loc; /* source location information for taskq directive */ |
| 1386 | } kmpc_task_queue_t; |
| 1387 | |
| 1388 | typedef void (*kmpc_task_t) (kmp_int32 global_tid, struct kmpc_thunk_t *thunk); |
| 1389 | |
| 1390 | /* sizeof_shareds passed as arg to __kmpc_taskq call */ |
| 1391 | typedef struct kmpc_shared_vars_t { /* aligned during dynamic allocation */ |
| 1392 | kmpc_task_queue_t *sv_queue; |
| 1393 | /* (pointers to) shared vars */ |
| 1394 | } kmpc_shared_vars_t; |
| 1395 | |
| 1396 | typedef struct KMP_ALIGN_CACHE kmpc_aligned_shared_vars_t { |
| 1397 | volatile struct kmpc_shared_vars_t *ai_data; |
| 1398 | } kmpc_aligned_shared_vars_t; |
| 1399 | |
| 1400 | /* sizeof_thunk passed as arg to kmpc_taskq call */ |
| 1401 | typedef struct kmpc_thunk_t { /* aligned during dynamic allocation */ |
| 1402 | union { /* field used for internal freelists too */ |
| 1403 | kmpc_shared_vars_t *th_shareds; |
| 1404 | struct kmpc_thunk_t *th_next_free; /* freelist of individual thunks within queue, head at tq_free_thunks */ |
| 1405 | } th; |
| 1406 | kmpc_task_t th_task; /* taskq_task if flags & TQF_TASKQ_TASK */ |
| 1407 | struct kmpc_thunk_t *th_encl_thunk; /* pointer to dynamically enclosing thunk on this thread's call stack */ |
| 1408 | kmp_int32 th_flags; /* TQF_xxx (tq_flags interface plus possible internal flags) */ |
| 1409 | kmp_int32 th_status; |
| 1410 | kmp_uint32 th_tasknum; /* task number assigned in order of queuing, used for ordered sections */ |
| 1411 | /* private vars */ |
| 1412 | } kmpc_thunk_t; |
| 1413 | |
| 1414 | typedef struct KMP_ALIGN_CACHE kmp_taskq { |
| 1415 | int tq_curr_thunk_capacity; |
| 1416 | |
| 1417 | kmpc_task_queue_t *tq_root; |
| 1418 | kmp_int32 tq_global_flags; |
| 1419 | |
| 1420 | kmp_lock_t tq_freelist_lck; |
| 1421 | kmpc_task_queue_t *tq_freelist; |
| 1422 | |
| 1423 | kmpc_thunk_t **tq_curr_thunk; |
| 1424 | } kmp_taskq_t; |
| 1425 | |
| 1426 | /* END Taskq data structures */ |
| 1427 | /* --------------------------------------------------------------------------- */ |
| 1428 | |
| 1429 | typedef kmp_int32 kmp_critical_name[8]; |
| 1430 | |
| 1431 | /*! |
| 1432 | @ingroup PARALLEL |
| 1433 | The type for a microtask which gets passed to @ref __kmpc_fork_call(). |
| 1434 | The arguments to the outlined function are |
| 1435 | @param global_tid the global thread identity of the thread executing the function. |
| 1436 | @param bound_tid the local identitiy of the thread executing the function |
| 1437 | @param ... pointers to shared variables accessed by the function. |
| 1438 | */ |
| 1439 | typedef void (*kmpc_micro) ( kmp_int32 * global_tid, kmp_int32 * bound_tid, ... ); |
| 1440 | typedef void (*kmpc_micro_bound) ( kmp_int32 * bound_tid, kmp_int32 * bound_nth, ... ); |
| 1441 | |
| 1442 | /*! |
| 1443 | @ingroup THREADPRIVATE |
| 1444 | @{ |
| 1445 | */ |
| 1446 | /* --------------------------------------------------------------------------- */ |
| 1447 | /* Threadprivate initialization/finalization function declarations */ |
| 1448 | |
| 1449 | /* for non-array objects: __kmpc_threadprivate_register() */ |
| 1450 | |
| 1451 | /*! |
| 1452 | Pointer to the constructor function. |
| 1453 | The first argument is the <tt>this</tt> pointer |
| 1454 | */ |
| 1455 | typedef void *(*kmpc_ctor) (void *); |
| 1456 | |
| 1457 | /*! |
| 1458 | Pointer to the destructor function. |
| 1459 | The first argument is the <tt>this</tt> pointer |
| 1460 | */ |
| 1461 | typedef void (*kmpc_dtor) (void * /*, size_t */); /* 2nd arg: magic number for KCC unused by Intel compiler */ |
| 1462 | /*! |
| 1463 | Pointer to an alternate constructor. |
| 1464 | The first argument is the <tt>this</tt> pointer. |
| 1465 | */ |
| 1466 | typedef void *(*kmpc_cctor) (void *, void *); |
| 1467 | |
| 1468 | /* for array objects: __kmpc_threadprivate_register_vec() */ |
| 1469 | /* First arg: "this" pointer */ |
| 1470 | /* Last arg: number of array elements */ |
| 1471 | /*! |
| 1472 | Array constructor. |
| 1473 | First argument is the <tt>this</tt> pointer |
| 1474 | Second argument the number of array elements. |
| 1475 | */ |
| 1476 | typedef void *(*kmpc_ctor_vec) (void *, size_t); |
| 1477 | /*! |
| 1478 | Pointer to the array destructor function. |
| 1479 | The first argument is the <tt>this</tt> pointer |
| 1480 | Second argument the number of array elements. |
| 1481 | */ |
| 1482 | typedef void (*kmpc_dtor_vec) (void *, size_t); |
| 1483 | /*! |
| 1484 | Array constructor. |
| 1485 | First argument is the <tt>this</tt> pointer |
| 1486 | Third argument the number of array elements. |
| 1487 | */ |
| 1488 | typedef void *(*kmpc_cctor_vec) (void *, void *, size_t); /* function unused by compiler */ |
| 1489 | |
| 1490 | /*! |
| 1491 | @} |
| 1492 | */ |
| 1493 | |
| 1494 | |
| 1495 | /* ------------------------------------------------------------------------ */ |
| 1496 | |
| 1497 | /* keeps tracked of threadprivate cache allocations for cleanup later */ |
| 1498 | typedef struct kmp_cached_addr { |
| 1499 | void **addr; /* address of allocated cache */ |
| 1500 | struct kmp_cached_addr *next; /* pointer to next cached address */ |
| 1501 | } kmp_cached_addr_t; |
| 1502 | |
| 1503 | struct private_data { |
| 1504 | struct private_data *next; /* The next descriptor in the list */ |
| 1505 | void *data; /* The data buffer for this descriptor */ |
| 1506 | int more; /* The repeat count for this descriptor */ |
| 1507 | size_t size; /* The data size for this descriptor */ |
| 1508 | }; |
| 1509 | |
| 1510 | struct private_common { |
| 1511 | struct private_common *next; |
| 1512 | struct private_common *link; |
| 1513 | void *gbl_addr; |
| 1514 | void *par_addr; /* par_addr == gbl_addr for MASTER thread */ |
| 1515 | size_t cmn_size; |
| 1516 | }; |
| 1517 | |
| 1518 | struct shared_common |
| 1519 | { |
| 1520 | struct shared_common *next; |
| 1521 | struct private_data *pod_init; |
| 1522 | void *obj_init; |
| 1523 | void *gbl_addr; |
| 1524 | union { |
| 1525 | kmpc_ctor ctor; |
| 1526 | kmpc_ctor_vec ctorv; |
| 1527 | } ct; |
| 1528 | union { |
| 1529 | kmpc_cctor cctor; |
| 1530 | kmpc_cctor_vec cctorv; |
| 1531 | } cct; |
| 1532 | union { |
| 1533 | kmpc_dtor dtor; |
| 1534 | kmpc_dtor_vec dtorv; |
| 1535 | } dt; |
| 1536 | size_t vec_len; |
| 1537 | int is_vec; |
| 1538 | size_t cmn_size; |
| 1539 | }; |
| 1540 | |
| 1541 | #define KMP_HASH_TABLE_LOG2 9 /* log2 of the hash table size */ |
| 1542 | #define KMP_HASH_TABLE_SIZE (1 << KMP_HASH_TABLE_LOG2) /* size of the hash table */ |
| 1543 | #define KMP_HASH_SHIFT 3 /* throw away this many low bits from the address */ |
| 1544 | #define KMP_HASH(x) ((((kmp_uintptr_t) x) >> KMP_HASH_SHIFT) & (KMP_HASH_TABLE_SIZE-1)) |
| 1545 | |
| 1546 | struct common_table { |
| 1547 | struct private_common *data[ KMP_HASH_TABLE_SIZE ]; |
| 1548 | }; |
| 1549 | |
| 1550 | struct shared_table { |
| 1551 | struct shared_common *data[ KMP_HASH_TABLE_SIZE ]; |
| 1552 | }; |
| 1553 | /* ------------------------------------------------------------------------ */ |
| 1554 | /* ------------------------------------------------------------------------ */ |
| 1555 | |
| 1556 | #ifdef KMP_STATIC_STEAL_ENABLED |
| 1557 | typedef struct KMP_ALIGN_CACHE dispatch_private_info32 { |
| 1558 | kmp_int32 count; |
| 1559 | kmp_int32 ub; |
| 1560 | /* Adding KMP_ALIGN_CACHE here doesn't help / can hurt performance */ |
| 1561 | kmp_int32 lb; |
| 1562 | kmp_int32 st; |
| 1563 | kmp_int32 tc; |
| 1564 | kmp_int32 static_steal_counter; /* for static_steal only; maybe better to put after ub */ |
| 1565 | |
| 1566 | // KMP_ALIGN( 16 ) ensures ( if the KMP_ALIGN macro is turned on ) |
| 1567 | // a) parm3 is properly aligned and |
| 1568 | // b) all parm1-4 are in the same cache line. |
| 1569 | // Because of parm1-4 are used together, performance seems to be better |
| 1570 | // if they are in the same line (not measured though). |
| 1571 | |
| 1572 | struct KMP_ALIGN( 32 ) { // AC: changed 16 to 32 in order to simplify template |
| 1573 | kmp_int32 parm1; // structures in kmp_dispatch.cpp. This should |
| 1574 | kmp_int32 parm2; // make no real change at least while padding is off. |
| 1575 | kmp_int32 parm3; |
| 1576 | kmp_int32 parm4; |
| 1577 | }; |
| 1578 | |
| 1579 | kmp_uint32 ordered_lower; |
| 1580 | kmp_uint32 ordered_upper; |
| 1581 | #if KMP_OS_WINDOWS |
| 1582 | // This var can be placed in the hole between 'tc' and 'parm1', instead of 'static_steal_counter'. |
| 1583 | // It would be nice to measure execution times. |
| 1584 | // Conditional if/endif can be removed at all. |
| 1585 | kmp_int32 last_upper; |
| 1586 | #endif /* KMP_OS_WINDOWS */ |
| 1587 | } dispatch_private_info32_t; |
| 1588 | |
| 1589 | typedef struct KMP_ALIGN_CACHE dispatch_private_info64 { |
| 1590 | kmp_int64 count; /* current chunk number for static and static-steal scheduling*/ |
| 1591 | kmp_int64 ub; /* upper-bound */ |
| 1592 | /* Adding KMP_ALIGN_CACHE here doesn't help / can hurt performance */ |
| 1593 | kmp_int64 lb; /* lower-bound */ |
| 1594 | kmp_int64 st; /* stride */ |
| 1595 | kmp_int64 tc; /* trip count (number of iterations) */ |
| 1596 | kmp_int64 static_steal_counter; /* for static_steal only; maybe better to put after ub */ |
| 1597 | |
| 1598 | /* parm[1-4] are used in different ways by different scheduling algorithms */ |
| 1599 | |
| 1600 | // KMP_ALIGN( 32 ) ensures ( if the KMP_ALIGN macro is turned on ) |
| 1601 | // a) parm3 is properly aligned and |
| 1602 | // b) all parm1-4 are in the same cache line. |
| 1603 | // Because of parm1-4 are used together, performance seems to be better |
| 1604 | // if they are in the same line (not measured though). |
| 1605 | |
| 1606 | struct KMP_ALIGN( 32 ) { |
| 1607 | kmp_int64 parm1; |
| 1608 | kmp_int64 parm2; |
| 1609 | kmp_int64 parm3; |
| 1610 | kmp_int64 parm4; |
| 1611 | }; |
| 1612 | |
| 1613 | kmp_uint64 ordered_lower; |
| 1614 | kmp_uint64 ordered_upper; |
| 1615 | #if KMP_OS_WINDOWS |
| 1616 | // This var can be placed in the hole between 'tc' and 'parm1', instead of 'static_steal_counter'. |
| 1617 | // It would be nice to measure execution times. |
| 1618 | // Conditional if/endif can be removed at all. |
| 1619 | kmp_int64 last_upper; |
| 1620 | #endif /* KMP_OS_WINDOWS */ |
| 1621 | } dispatch_private_info64_t; |
| 1622 | #else /* KMP_STATIC_STEAL_ENABLED */ |
| 1623 | typedef struct KMP_ALIGN_CACHE dispatch_private_info32 { |
| 1624 | kmp_int32 lb; |
| 1625 | kmp_int32 ub; |
| 1626 | kmp_int32 st; |
| 1627 | kmp_int32 tc; |
| 1628 | |
| 1629 | kmp_int32 parm1; |
| 1630 | kmp_int32 parm2; |
| 1631 | kmp_int32 parm3; |
| 1632 | kmp_int32 parm4; |
| 1633 | |
| 1634 | kmp_int32 count; |
| 1635 | |
| 1636 | kmp_uint32 ordered_lower; |
| 1637 | kmp_uint32 ordered_upper; |
| 1638 | #if KMP_OS_WINDOWS |
| 1639 | kmp_int32 last_upper; |
| 1640 | #endif /* KMP_OS_WINDOWS */ |
| 1641 | } dispatch_private_info32_t; |
| 1642 | |
| 1643 | typedef struct KMP_ALIGN_CACHE dispatch_private_info64 { |
| 1644 | kmp_int64 lb; /* lower-bound */ |
| 1645 | kmp_int64 ub; /* upper-bound */ |
| 1646 | kmp_int64 st; /* stride */ |
| 1647 | kmp_int64 tc; /* trip count (number of iterations) */ |
| 1648 | |
| 1649 | /* parm[1-4] are used in different ways by different scheduling algorithms */ |
| 1650 | kmp_int64 parm1; |
| 1651 | kmp_int64 parm2; |
| 1652 | kmp_int64 parm3; |
| 1653 | kmp_int64 parm4; |
| 1654 | |
| 1655 | kmp_int64 count; /* current chunk number for static scheduling */ |
| 1656 | |
| 1657 | kmp_uint64 ordered_lower; |
| 1658 | kmp_uint64 ordered_upper; |
| 1659 | #if KMP_OS_WINDOWS |
| 1660 | kmp_int64 last_upper; |
| 1661 | #endif /* KMP_OS_WINDOWS */ |
| 1662 | } dispatch_private_info64_t; |
| 1663 | #endif /* KMP_STATIC_STEAL_ENABLED */ |
| 1664 | |
| 1665 | typedef struct KMP_ALIGN_CACHE dispatch_private_info { |
| 1666 | union private_info { |
| 1667 | dispatch_private_info32_t p32; |
| 1668 | dispatch_private_info64_t p64; |
| 1669 | } u; |
| 1670 | enum sched_type schedule; /* scheduling algorithm */ |
| 1671 | kmp_int32 ordered; /* ordered clause specified */ |
| 1672 | kmp_int32 ordered_bumped; |
| 1673 | kmp_int32 ordered_dummy[KMP_MAX_ORDERED-3]; // to retain the structure size after making ordered_iteration scalar |
| 1674 | struct dispatch_private_info * next; /* stack of buffers for nest of serial regions */ |
| 1675 | kmp_int32 nomerge; /* don't merge iters if serialized */ |
| 1676 | kmp_int32 type_size; /* the size of types in private_info */ |
| 1677 | enum cons_type pushed_ws; |
| 1678 | } dispatch_private_info_t; |
| 1679 | |
| 1680 | typedef struct dispatch_shared_info32 { |
| 1681 | /* chunk index under dynamic, number of idle threads under static-steal; |
| 1682 | iteration index otherwise */ |
| 1683 | volatile kmp_uint32 iteration; |
| 1684 | volatile kmp_uint32 num_done; |
| 1685 | volatile kmp_uint32 ordered_iteration; |
| 1686 | kmp_int32 ordered_dummy[KMP_MAX_ORDERED-1]; // to retain the structure size after making ordered_iteration scalar |
| 1687 | } dispatch_shared_info32_t; |
| 1688 | |
| 1689 | typedef struct dispatch_shared_info64 { |
| 1690 | /* chunk index under dynamic, number of idle threads under static-steal; |
| 1691 | iteration index otherwise */ |
| 1692 | volatile kmp_uint64 iteration; |
| 1693 | volatile kmp_uint64 num_done; |
| 1694 | volatile kmp_uint64 ordered_iteration; |
| Jonathan Peyton | 71909c5 | 2016-03-02 22:42:06 +0000 | [diff] [blame] | 1695 | kmp_int64 ordered_dummy[KMP_MAX_ORDERED-3]; // to retain the structure size after making ordered_iteration scalar |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1696 | } dispatch_shared_info64_t; |
| 1697 | |
| 1698 | typedef struct dispatch_shared_info { |
| 1699 | union shared_info { |
| 1700 | dispatch_shared_info32_t s32; |
| 1701 | dispatch_shared_info64_t s64; |
| 1702 | } u; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1703 | volatile kmp_uint32 buffer_index; |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 1704 | #if OMP_45_ENABLED |
| Jonathan Peyton | 71909c5 | 2016-03-02 22:42:06 +0000 | [diff] [blame] | 1705 | volatile kmp_int32 doacross_buf_idx; // teamwise index |
| 1706 | volatile kmp_uint32 *doacross_flags; // shared array of iteration flags (0/1) |
| 1707 | kmp_int32 doacross_num_done; // count finished threads |
| 1708 | #endif |
| Jonathan Peyton | 4d3c213 | 2016-07-08 17:43:21 +0000 | [diff] [blame^] | 1709 | #if KMP_USE_HWLOC |
| 1710 | // When linking with libhwloc, the ORDERED EPCC test slows down on big |
| 1711 | // machines (> 48 cores). Performance analysis showed that a cache thrash |
| 1712 | // was occurring and this padding helps alleviate the problem. |
| 1713 | char padding[64]; |
| 1714 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1715 | } dispatch_shared_info_t; |
| 1716 | |
| 1717 | typedef struct kmp_disp { |
| 1718 | /* Vector for ORDERED SECTION */ |
| 1719 | void (*th_deo_fcn)( int * gtid, int * cid, ident_t *); |
| 1720 | /* Vector for END ORDERED SECTION */ |
| 1721 | void (*th_dxo_fcn)( int * gtid, int * cid, ident_t *); |
| 1722 | |
| 1723 | dispatch_shared_info_t *th_dispatch_sh_current; |
| 1724 | dispatch_private_info_t *th_dispatch_pr_current; |
| 1725 | |
| 1726 | dispatch_private_info_t *th_disp_buffer; |
| 1727 | kmp_int32 th_disp_index; |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 1728 | #if OMP_45_ENABLED |
| Jonathan Peyton | 71909c5 | 2016-03-02 22:42:06 +0000 | [diff] [blame] | 1729 | kmp_int32 th_doacross_buf_idx; // thread's doacross buffer index |
| 1730 | volatile kmp_uint32 *th_doacross_flags; // pointer to shared array of flags |
| 1731 | kmp_int64 *th_doacross_info; // info on loop bounds |
| 1732 | #else |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1733 | void* dummy_padding[2]; // make it 64 bytes on Intel(R) 64 |
| Jonathan Peyton | 71909c5 | 2016-03-02 22:42:06 +0000 | [diff] [blame] | 1734 | #endif |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1735 | #if KMP_USE_INTERNODE_ALIGNMENT |
| 1736 | char more_padding[INTERNODE_CACHE_LINE]; |
| 1737 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1738 | } kmp_disp_t; |
| 1739 | |
| 1740 | /* ------------------------------------------------------------------------ */ |
| 1741 | /* ------------------------------------------------------------------------ */ |
| 1742 | |
| 1743 | /* Barrier stuff */ |
| 1744 | |
| 1745 | /* constants for barrier state update */ |
| 1746 | #define KMP_INIT_BARRIER_STATE 0 /* should probably start from zero */ |
| 1747 | #define KMP_BARRIER_SLEEP_BIT 0 /* bit used for suspend/sleep part of state */ |
| 1748 | #define KMP_BARRIER_UNUSED_BIT 1 /* bit that must never be set for valid state */ |
| 1749 | #define KMP_BARRIER_BUMP_BIT 2 /* lsb used for bump of go/arrived state */ |
| 1750 | |
| Jonathan Peyton | 703d404 | 2016-01-04 20:51:48 +0000 | [diff] [blame] | 1751 | #define KMP_BARRIER_SLEEP_STATE (1 << KMP_BARRIER_SLEEP_BIT) |
| 1752 | #define KMP_BARRIER_UNUSED_STATE (1 << KMP_BARRIER_UNUSED_BIT) |
| 1753 | #define KMP_BARRIER_STATE_BUMP (1 << KMP_BARRIER_BUMP_BIT) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1754 | |
| 1755 | #if (KMP_BARRIER_SLEEP_BIT >= KMP_BARRIER_BUMP_BIT) |
| 1756 | # error "Barrier sleep bit must be smaller than barrier bump bit" |
| 1757 | #endif |
| 1758 | #if (KMP_BARRIER_UNUSED_BIT >= KMP_BARRIER_BUMP_BIT) |
| 1759 | # error "Barrier unused bit must be smaller than barrier bump bit" |
| 1760 | #endif |
| 1761 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1762 | // Constants for release barrier wait state: currently, hierarchical only |
| 1763 | #define KMP_BARRIER_NOT_WAITING 0 // Normal state; worker not in wait_sleep |
| 1764 | #define KMP_BARRIER_OWN_FLAG 1 // Normal state; worker waiting on own b_go flag in release |
| 1765 | #define KMP_BARRIER_PARENT_FLAG 2 // Special state; worker waiting on parent's b_go flag in release |
| 1766 | #define KMP_BARRIER_SWITCH_TO_OWN_FLAG 3 // Special state; tells worker to shift from parent to own b_go |
| 1767 | #define KMP_BARRIER_SWITCHING 4 // Special state; worker resets appropriate flag on wake-up |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1768 | |
| 1769 | enum barrier_type { |
| 1770 | bs_plain_barrier = 0, /* 0, All non-fork/join barriers (except reduction barriers if enabled) */ |
| 1771 | bs_forkjoin_barrier, /* 1, All fork/join (parallel region) barriers */ |
| 1772 | #if KMP_FAST_REDUCTION_BARRIER |
| 1773 | bs_reduction_barrier, /* 2, All barriers that are used in reduction */ |
| 1774 | #endif // KMP_FAST_REDUCTION_BARRIER |
| 1775 | bs_last_barrier /* Just a placeholder to mark the end */ |
| 1776 | }; |
| 1777 | |
| 1778 | // to work with reduction barriers just like with plain barriers |
| 1779 | #if !KMP_FAST_REDUCTION_BARRIER |
| 1780 | #define bs_reduction_barrier bs_plain_barrier |
| 1781 | #endif // KMP_FAST_REDUCTION_BARRIER |
| 1782 | |
| 1783 | typedef enum kmp_bar_pat { /* Barrier communication patterns */ |
| 1784 | bp_linear_bar = 0, /* Single level (degenerate) tree */ |
| 1785 | bp_tree_bar = 1, /* Balanced tree with branching factor 2^n */ |
| 1786 | bp_hyper_bar = 2, /* Hypercube-embedded tree with min branching factor 2^n */ |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1787 | bp_hierarchical_bar = 3, /* Machine hierarchy tree */ |
| 1788 | bp_last_bar = 4 /* Placeholder to mark the end */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1789 | } kmp_bar_pat_e; |
| 1790 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1791 | # define KMP_BARRIER_ICV_PUSH 1 |
| 1792 | |
| 1793 | /* Record for holding the values of the internal controls stack records */ |
| 1794 | typedef struct kmp_internal_control { |
| 1795 | int serial_nesting_level; /* corresponds to the value of the th_team_serialized field */ |
| 1796 | kmp_int8 nested; /* internal control for nested parallelism (per thread) */ |
| 1797 | kmp_int8 dynamic; /* internal control for dynamic adjustment of threads (per thread) */ |
| 1798 | kmp_int8 bt_set; /* internal control for whether blocktime is explicitly set */ |
| 1799 | int blocktime; /* internal control for blocktime */ |
| 1800 | int bt_intervals; /* internal control for blocktime intervals */ |
| 1801 | int nproc; /* internal control for #threads for next parallel region (per thread) */ |
| 1802 | int max_active_levels; /* internal control for max_active_levels */ |
| 1803 | kmp_r_sched_t sched; /* internal control for runtime schedule {sched,chunk} pair */ |
| 1804 | #if OMP_40_ENABLED |
| 1805 | kmp_proc_bind_t proc_bind; /* internal control for affinity */ |
| 1806 | #endif // OMP_40_ENABLED |
| 1807 | struct kmp_internal_control *next; |
| 1808 | } kmp_internal_control_t; |
| 1809 | |
| 1810 | static inline void |
| 1811 | copy_icvs( kmp_internal_control_t *dst, kmp_internal_control_t *src ) { |
| 1812 | *dst = *src; |
| 1813 | } |
| 1814 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1815 | /* Thread barrier needs volatile barrier fields */ |
| 1816 | typedef struct KMP_ALIGN_CACHE kmp_bstate { |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1817 | // th_fixed_icvs is aligned by virtue of kmp_bstate being aligned (and all uses of it). |
| 1818 | // It is not explicitly aligned below, because we *don't* want it to be padded -- instead, |
| 1819 | // we fit b_go into the same cache line with th_fixed_icvs, enabling NGO cache lines |
| 1820 | // stores in the hierarchical barrier. |
| 1821 | kmp_internal_control_t th_fixed_icvs; // Initial ICVs for the thread |
| 1822 | // Tuck b_go into end of th_fixed_icvs cache line, so it can be stored with same NGO store |
| 1823 | volatile kmp_uint64 b_go; // STATE => task should proceed (hierarchical) |
| 1824 | KMP_ALIGN_CACHE volatile kmp_uint64 b_arrived; // STATE => task reached synch point. |
| 1825 | kmp_uint32 *skip_per_level; |
| 1826 | kmp_uint32 my_level; |
| 1827 | kmp_int32 parent_tid; |
| Jonathan Peyton | 1e7a1dd | 2015-06-04 17:29:13 +0000 | [diff] [blame] | 1828 | kmp_int32 old_tid; |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1829 | kmp_uint32 depth; |
| 1830 | struct kmp_bstate *parent_bar; |
| 1831 | kmp_team_t *team; |
| 1832 | kmp_uint64 leaf_state; |
| 1833 | kmp_uint32 nproc; |
| 1834 | kmp_uint8 base_leaf_kids; |
| 1835 | kmp_uint8 leaf_kids; |
| 1836 | kmp_uint8 offset; |
| 1837 | kmp_uint8 wait_flag; |
| 1838 | kmp_uint8 use_oncore_barrier; |
| Jonathan Peyton | 8fbb49a | 2015-07-09 18:16:58 +0000 | [diff] [blame] | 1839 | #if USE_DEBUGGER |
| 1840 | // The following field is intended for the debugger solely. Only the worker thread itself accesses this |
| 1841 | // field: the worker increases it by 1 when it arrives to a barrier. |
| 1842 | KMP_ALIGN_CACHE kmp_uint b_worker_arrived; |
| 1843 | #endif /* USE_DEBUGGER */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1844 | } kmp_bstate_t; |
| 1845 | |
| 1846 | union KMP_ALIGN_CACHE kmp_barrier_union { |
| 1847 | double b_align; /* use worst case alignment */ |
| 1848 | char b_pad[ KMP_PAD(kmp_bstate_t, CACHE_LINE) ]; |
| 1849 | kmp_bstate_t bb; |
| 1850 | }; |
| 1851 | |
| 1852 | typedef union kmp_barrier_union kmp_balign_t; |
| 1853 | |
| 1854 | /* Team barrier needs only non-volatile arrived counter */ |
| 1855 | union KMP_ALIGN_CACHE kmp_barrier_team_union { |
| 1856 | double b_align; /* use worst case alignment */ |
| 1857 | char b_pad[ CACHE_LINE ]; |
| 1858 | struct { |
| Jonathan Peyton | d26e213 | 2015-09-10 18:44:30 +0000 | [diff] [blame] | 1859 | kmp_uint64 b_arrived; /* STATE => task reached synch point. */ |
| Jonathan Peyton | 8fbb49a | 2015-07-09 18:16:58 +0000 | [diff] [blame] | 1860 | #if USE_DEBUGGER |
| 1861 | // The following two fields are indended for the debugger solely. Only master of the team accesses |
| 1862 | // these fields: the first one is increased by 1 when master arrives to a barrier, the |
| 1863 | // second one is increased by one when all the threads arrived. |
| 1864 | kmp_uint b_master_arrived; |
| 1865 | kmp_uint b_team_arrived; |
| 1866 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1867 | }; |
| 1868 | }; |
| 1869 | |
| 1870 | typedef union kmp_barrier_team_union kmp_balign_team_t; |
| 1871 | |
| 1872 | /* |
| 1873 | * Padding for Linux* OS pthreads condition variables and mutexes used to signal |
| 1874 | * threads when a condition changes. This is to workaround an NPTL bug |
| 1875 | * where padding was added to pthread_cond_t which caused the initialization |
| 1876 | * routine to write outside of the structure if compiled on pre-NPTL threads. |
| 1877 | */ |
| 1878 | |
| 1879 | #if KMP_OS_WINDOWS |
| 1880 | typedef struct kmp_win32_mutex |
| 1881 | { |
| 1882 | /* The Lock */ |
| 1883 | CRITICAL_SECTION cs; |
| 1884 | } kmp_win32_mutex_t; |
| 1885 | |
| 1886 | typedef struct kmp_win32_cond |
| 1887 | { |
| 1888 | /* Count of the number of waiters. */ |
| 1889 | int waiters_count_; |
| 1890 | |
| 1891 | /* Serialize access to <waiters_count_> */ |
| 1892 | kmp_win32_mutex_t waiters_count_lock_; |
| 1893 | |
| 1894 | /* Number of threads to release via a <cond_broadcast> or a */ |
| 1895 | /* <cond_signal> */ |
| 1896 | int release_count_; |
| 1897 | |
| 1898 | /* Keeps track of the current "generation" so that we don't allow */ |
| 1899 | /* one thread to steal all the "releases" from the broadcast. */ |
| 1900 | int wait_generation_count_; |
| 1901 | |
| 1902 | /* A manual-reset event that's used to block and release waiting */ |
| 1903 | /* threads. */ |
| 1904 | HANDLE event_; |
| 1905 | } kmp_win32_cond_t; |
| 1906 | #endif |
| 1907 | |
| 1908 | #if KMP_OS_UNIX |
| 1909 | |
| 1910 | union KMP_ALIGN_CACHE kmp_cond_union { |
| 1911 | double c_align; |
| 1912 | char c_pad[ CACHE_LINE ]; |
| 1913 | pthread_cond_t c_cond; |
| 1914 | }; |
| 1915 | |
| 1916 | typedef union kmp_cond_union kmp_cond_align_t; |
| 1917 | |
| 1918 | union KMP_ALIGN_CACHE kmp_mutex_union { |
| 1919 | double m_align; |
| 1920 | char m_pad[ CACHE_LINE ]; |
| 1921 | pthread_mutex_t m_mutex; |
| 1922 | }; |
| 1923 | |
| 1924 | typedef union kmp_mutex_union kmp_mutex_align_t; |
| 1925 | |
| 1926 | #endif /* KMP_OS_UNIX */ |
| 1927 | |
| 1928 | typedef struct kmp_desc_base { |
| 1929 | void *ds_stackbase; |
| 1930 | size_t ds_stacksize; |
| 1931 | int ds_stackgrow; |
| 1932 | kmp_thread_t ds_thread; |
| 1933 | volatile int ds_tid; |
| 1934 | int ds_gtid; |
| 1935 | #if KMP_OS_WINDOWS |
| 1936 | volatile int ds_alive; |
| 1937 | DWORD ds_thread_id; |
| 1938 | /* |
| 1939 | ds_thread keeps thread handle on Windows* OS. It is enough for RTL purposes. However, |
| 1940 | debugger support (libomp_db) cannot work with handles, because they uncomparable. For |
| 1941 | example, debugger requests info about thread with handle h. h is valid within debugger |
| 1942 | process, and meaningless within debugee process. Even if h is duped by call to |
| 1943 | DuplicateHandle(), so the result h' is valid within debugee process, but it is a *new* |
| 1944 | handle which does *not* equal to any other handle in debugee... The only way to |
| 1945 | compare handles is convert them to system-wide ids. GetThreadId() function is |
| 1946 | available only in Longhorn and Server 2003. :-( In contrast, GetCurrentThreadId() is |
| 1947 | available on all Windows* OS flavours (including Windows* 95). Thus, we have to get thread id by |
| 1948 | call to GetCurrentThreadId() from within the thread and save it to let libomp_db |
| 1949 | identify threads. |
| 1950 | */ |
| 1951 | #endif /* KMP_OS_WINDOWS */ |
| 1952 | } kmp_desc_base_t; |
| 1953 | |
| 1954 | typedef union KMP_ALIGN_CACHE kmp_desc { |
| 1955 | double ds_align; /* use worst case alignment */ |
| 1956 | char ds_pad[ KMP_PAD(kmp_desc_base_t, CACHE_LINE) ]; |
| 1957 | kmp_desc_base_t ds; |
| 1958 | } kmp_desc_t; |
| 1959 | |
| 1960 | |
| 1961 | typedef struct kmp_local { |
| 1962 | volatile int this_construct; /* count of single's encountered by thread */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1963 | void *reduce_data; |
| 1964 | #if KMP_USE_BGET |
| 1965 | void *bget_data; |
| 1966 | void *bget_list; |
| 1967 | #if ! USE_CMP_XCHG_FOR_BGET |
| 1968 | #ifdef USE_QUEUING_LOCK_FOR_BGET |
| 1969 | kmp_lock_t bget_lock; /* Lock for accessing bget free list */ |
| 1970 | #else |
| 1971 | kmp_bootstrap_lock_t bget_lock; /* Lock for accessing bget free list */ |
| 1972 | /* Must be bootstrap lock so we can use it at library shutdown */ |
| 1973 | #endif /* USE_LOCK_FOR_BGET */ |
| 1974 | #endif /* ! USE_CMP_XCHG_FOR_BGET */ |
| 1975 | #endif /* KMP_USE_BGET */ |
| 1976 | |
| 1977 | #ifdef BUILD_TV |
| 1978 | struct tv_data *tv_data; |
| 1979 | #endif |
| 1980 | |
| 1981 | PACKED_REDUCTION_METHOD_T packed_reduction_method; /* stored by __kmpc_reduce*(), used by __kmpc_end_reduce*() */ |
| 1982 | |
| 1983 | } kmp_local_t; |
| 1984 | |
| Jonathan Peyton | b044e4f | 2016-05-23 18:01:19 +0000 | [diff] [blame] | 1985 | #define KMP_CHECK_UPDATE(a, b) if ((a) != (b)) (a) = (b) |
| 1986 | #define KMP_CHECK_UPDATE_SYNC(a, b) if ((a) != (b)) TCW_SYNC_PTR((a), (b)) |
| 1987 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1988 | #define get__blocktime( xteam, xtid ) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.blocktime) |
| 1989 | #define get__bt_set( xteam, xtid ) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_set) |
| 1990 | #define get__bt_intervals( xteam, xtid ) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_intervals) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1991 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1992 | #define get__nested_2(xteam,xtid) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.nested) |
| 1993 | #define get__dynamic_2(xteam,xtid) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.dynamic) |
| 1994 | #define get__nproc_2(xteam,xtid) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.nproc) |
| 1995 | #define get__sched_2(xteam,xtid) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.sched) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1996 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1997 | #define set__blocktime_team( xteam, xtid, xval ) \ |
| 1998 | ( ( (xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.blocktime ) = (xval) ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1999 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2000 | #define set__bt_intervals_team( xteam, xtid, xval ) \ |
| 2001 | ( ( (xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_intervals ) = (xval) ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2002 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2003 | #define set__bt_set_team( xteam, xtid, xval ) \ |
| 2004 | ( ( (xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_set ) = (xval) ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2005 | |
| 2006 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2007 | #define set__nested( xthread, xval ) \ |
| 2008 | ( ( (xthread)->th.th_current_task->td_icvs.nested ) = (xval) ) |
| 2009 | #define get__nested( xthread ) \ |
| 2010 | ( ( (xthread)->th.th_current_task->td_icvs.nested ) ? (FTN_TRUE) : (FTN_FALSE) ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2011 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2012 | #define set__dynamic( xthread, xval ) \ |
| 2013 | ( ( (xthread)->th.th_current_task->td_icvs.dynamic ) = (xval) ) |
| 2014 | #define get__dynamic( xthread ) \ |
| 2015 | ( ( (xthread)->th.th_current_task->td_icvs.dynamic ) ? (FTN_TRUE) : (FTN_FALSE) ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2016 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2017 | #define set__nproc( xthread, xval ) \ |
| 2018 | ( ( (xthread)->th.th_current_task->td_icvs.nproc ) = (xval) ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2019 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2020 | #define set__max_active_levels( xthread, xval ) \ |
| 2021 | ( ( (xthread)->th.th_current_task->td_icvs.max_active_levels ) = (xval) ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2022 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2023 | #define set__sched( xthread, xval ) \ |
| 2024 | ( ( (xthread)->th.th_current_task->td_icvs.sched ) = (xval) ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2025 | |
| 2026 | #if OMP_40_ENABLED |
| 2027 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2028 | #define set__proc_bind( xthread, xval ) \ |
| 2029 | ( ( (xthread)->th.th_current_task->td_icvs.proc_bind ) = (xval) ) |
| 2030 | #define get__proc_bind( xthread ) \ |
| 2031 | ( (xthread)->th.th_current_task->td_icvs.proc_bind ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2032 | |
| 2033 | #endif /* OMP_40_ENABLED */ |
| 2034 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2035 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2036 | /* ------------------------------------------------------------------------ */ |
| 2037 | // OpenMP tasking data structures |
| 2038 | // |
| 2039 | |
| 2040 | typedef enum kmp_tasking_mode { |
| 2041 | tskm_immediate_exec = 0, |
| 2042 | tskm_extra_barrier = 1, |
| 2043 | tskm_task_teams = 2, |
| 2044 | tskm_max = 2 |
| 2045 | } kmp_tasking_mode_t; |
| 2046 | |
| 2047 | extern kmp_tasking_mode_t __kmp_tasking_mode; /* determines how/when to execute tasks */ |
| 2048 | extern kmp_int32 __kmp_task_stealing_constraint; |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 2049 | #if OMP_45_ENABLED |
| Jonathan Peyton | 2851072 | 2016-02-25 18:04:09 +0000 | [diff] [blame] | 2050 | extern kmp_int32 __kmp_max_task_priority; // Set via OMP_MAX_TASK_PRIORITY if specified, defaults to 0 otherwise |
| 2051 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2052 | |
| 2053 | /* NOTE: kmp_taskdata_t and kmp_task_t structures allocated in single block with taskdata first */ |
| 2054 | #define KMP_TASK_TO_TASKDATA(task) (((kmp_taskdata_t *) task) - 1) |
| 2055 | #define KMP_TASKDATA_TO_TASK(taskdata) (kmp_task_t *) (taskdata + 1) |
| 2056 | |
| 2057 | // The tt_found_tasks flag is a signal to all threads in the team that tasks were spawned and |
| 2058 | // queued since the previous barrier release. |
| Andrey Churbanov | 6d224db | 2015-02-10 18:37:43 +0000 | [diff] [blame] | 2059 | #define KMP_TASKING_ENABLED(task_team) \ |
| 2060 | (TCR_SYNC_4((task_team)->tt.tt_found_tasks) == TRUE) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2061 | /*! |
| 2062 | @ingroup BASIC_TYPES |
| 2063 | @{ |
| 2064 | */ |
| 2065 | |
| 2066 | /*! |
| 2067 | */ |
| 2068 | typedef kmp_int32 (* kmp_routine_entry_t)( kmp_int32, void * ); |
| 2069 | |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 2070 | #if OMP_40_ENABLED || OMP_45_ENABLED |
| Jonathan Peyton | 2851072 | 2016-02-25 18:04:09 +0000 | [diff] [blame] | 2071 | typedef union kmp_cmplrdata { |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 2072 | #if OMP_45_ENABLED |
| Jonathan Peyton | 2851072 | 2016-02-25 18:04:09 +0000 | [diff] [blame] | 2073 | kmp_int32 priority; /**< priority specified by user for the task */ |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 2074 | #endif // OMP_45_ENABLED |
| Jonathan Peyton | 2851072 | 2016-02-25 18:04:09 +0000 | [diff] [blame] | 2075 | #if OMP_40_ENABLED |
| 2076 | kmp_routine_entry_t destructors; /* pointer to function to invoke deconstructors of firstprivate C++ objects */ |
| 2077 | #endif // OMP_40_ENABLED |
| 2078 | /* future data */ |
| 2079 | } kmp_cmplrdata_t; |
| 2080 | #endif |
| 2081 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2082 | /* sizeof_kmp_task_t passed as arg to kmpc_omp_task call */ |
| 2083 | /*! |
| 2084 | */ |
| 2085 | typedef struct kmp_task { /* GEH: Shouldn't this be aligned somehow? */ |
| 2086 | void * shareds; /**< pointer to block of pointers to shared vars */ |
| 2087 | kmp_routine_entry_t routine; /**< pointer to routine to call for executing task */ |
| 2088 | kmp_int32 part_id; /**< part id for the task */ |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 2089 | #if OMP_40_ENABLED || OMP_45_ENABLED |
| Jonathan Peyton | 2851072 | 2016-02-25 18:04:09 +0000 | [diff] [blame] | 2090 | kmp_cmplrdata_t data1; /* Two known optional additions: destructors and priority */ |
| 2091 | kmp_cmplrdata_t data2; /* Process destructors first, priority second */ |
| 2092 | /* future data */ |
| 2093 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2094 | /* private vars */ |
| 2095 | } kmp_task_t; |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2096 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2097 | /*! |
| 2098 | @} |
| 2099 | */ |
| 2100 | |
| 2101 | #if OMP_40_ENABLED |
| 2102 | typedef struct kmp_taskgroup { |
| 2103 | kmp_uint32 count; // number of allocated and not yet complete tasks |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2104 | kmp_int32 cancel_request; // request for cancellation of this taskgroup |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2105 | struct kmp_taskgroup *parent; // parent taskgroup |
| 2106 | } kmp_taskgroup_t; |
| 2107 | |
| 2108 | |
| 2109 | // forward declarations |
| 2110 | typedef union kmp_depnode kmp_depnode_t; |
| 2111 | typedef struct kmp_depnode_list kmp_depnode_list_t; |
| 2112 | typedef struct kmp_dephash_entry kmp_dephash_entry_t; |
| 2113 | |
| 2114 | typedef struct kmp_depend_info { |
| 2115 | kmp_intptr_t base_addr; |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2116 | size_t len; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2117 | struct { |
| 2118 | bool in:1; |
| 2119 | bool out:1; |
| 2120 | } flags; |
| 2121 | } kmp_depend_info_t; |
| 2122 | |
| 2123 | struct kmp_depnode_list { |
| 2124 | kmp_depnode_t * node; |
| 2125 | kmp_depnode_list_t * next; |
| 2126 | }; |
| 2127 | |
| 2128 | typedef struct kmp_base_depnode { |
| 2129 | kmp_depnode_list_t * successors; |
| 2130 | kmp_task_t * task; |
| 2131 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2132 | kmp_lock_t lock; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2133 | |
| 2134 | #if KMP_SUPPORT_GRAPH_OUTPUT |
| 2135 | kmp_uint32 id; |
| 2136 | #endif |
| 2137 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2138 | volatile kmp_int32 npredecessors; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2139 | volatile kmp_int32 nrefs; |
| 2140 | } kmp_base_depnode_t; |
| 2141 | |
| 2142 | union KMP_ALIGN_CACHE kmp_depnode { |
| 2143 | double dn_align; /* use worst case alignment */ |
| 2144 | char dn_pad[ KMP_PAD(kmp_base_depnode_t, CACHE_LINE) ]; |
| 2145 | kmp_base_depnode_t dn; |
| 2146 | }; |
| 2147 | |
| 2148 | struct kmp_dephash_entry { |
| 2149 | kmp_intptr_t addr; |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2150 | kmp_depnode_t * last_out; |
| 2151 | kmp_depnode_list_t * last_ins; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2152 | kmp_dephash_entry_t * next_in_bucket; |
| 2153 | }; |
| 2154 | |
| 2155 | typedef struct kmp_dephash { |
| 2156 | kmp_dephash_entry_t ** buckets; |
| Jonathan Peyton | 7d45451 | 2016-01-28 23:10:44 +0000 | [diff] [blame] | 2157 | size_t size; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2158 | #ifdef KMP_DEBUG |
| 2159 | kmp_uint32 nelements; |
| 2160 | kmp_uint32 nconflicts; |
| 2161 | #endif |
| 2162 | } kmp_dephash_t; |
| 2163 | |
| 2164 | #endif |
| 2165 | |
| 2166 | #ifdef BUILD_TIED_TASK_STACK |
| 2167 | |
| 2168 | /* Tied Task stack definitions */ |
| 2169 | typedef struct kmp_stack_block { |
| 2170 | kmp_taskdata_t * sb_block[ TASK_STACK_BLOCK_SIZE ]; |
| 2171 | struct kmp_stack_block * sb_next; |
| 2172 | struct kmp_stack_block * sb_prev; |
| 2173 | } kmp_stack_block_t; |
| 2174 | |
| 2175 | typedef struct kmp_task_stack { |
| 2176 | kmp_stack_block_t ts_first_block; // first block of stack entries |
| 2177 | kmp_taskdata_t ** ts_top; // pointer to the top of stack |
| 2178 | kmp_int32 ts_entries; // number of entries on the stack |
| 2179 | } kmp_task_stack_t; |
| 2180 | |
| 2181 | #endif // BUILD_TIED_TASK_STACK |
| 2182 | |
| 2183 | typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */ |
| 2184 | /* Compiler flags */ /* Total compiler flags must be 16 bits */ |
| 2185 | unsigned tiedness : 1; /* task is either tied (1) or untied (0) */ |
| 2186 | unsigned final : 1; /* task is final(1) so execute immediately */ |
| 2187 | unsigned merged_if0 : 1; /* no __kmpc_task_{begin/complete}_if0 calls in if0 code path */ |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2188 | #if OMP_40_ENABLED |
| 2189 | unsigned destructors_thunk : 1; /* set if the compiler creates a thunk to invoke destructors from the runtime */ |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 2190 | #if OMP_45_ENABLED |
| Andrey Churbanov | 535b6fa | 2015-05-07 17:41:51 +0000 | [diff] [blame] | 2191 | unsigned proxy : 1; /* task is a proxy task (it will be executed outside the context of the RTL) */ |
| Jonathan Peyton | 2851072 | 2016-02-25 18:04:09 +0000 | [diff] [blame] | 2192 | unsigned priority_specified :1; /* set if the compiler provides priority setting for the task */ |
| 2193 | unsigned reserved : 10; /* reserved for compiler use */ |
| Andrey Churbanov | 535b6fa | 2015-05-07 17:41:51 +0000 | [diff] [blame] | 2194 | #else |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2195 | unsigned reserved : 12; /* reserved for compiler use */ |
| Andrey Churbanov | 535b6fa | 2015-05-07 17:41:51 +0000 | [diff] [blame] | 2196 | #endif |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2197 | #else // OMP_40_ENABLED |
| 2198 | unsigned reserved : 13; /* reserved for compiler use */ |
| 2199 | #endif // OMP_40_ENABLED |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2200 | |
| 2201 | /* Library flags */ /* Total library flags must be 16 bits */ |
| 2202 | unsigned tasktype : 1; /* task is either explicit(1) or implicit (0) */ |
| 2203 | unsigned task_serial : 1; /* this task is executed immediately (1) or deferred (0) */ |
| 2204 | unsigned tasking_ser : 1; /* all tasks in team are either executed immediately (1) or may be deferred (0) */ |
| 2205 | unsigned team_serial : 1; /* entire team is serial (1) [1 thread] or parallel (0) [>= 2 threads] */ |
| 2206 | /* If either team_serial or tasking_ser is set, task team may be NULL */ |
| 2207 | /* Task State Flags: */ |
| 2208 | unsigned started : 1; /* 1==started, 0==not started */ |
| 2209 | unsigned executing : 1; /* 1==executing, 0==not executing */ |
| 2210 | unsigned complete : 1; /* 1==complete, 0==not complete */ |
| 2211 | unsigned freed : 1; /* 1==freed, 0==allocateed */ |
| 2212 | unsigned native : 1; /* 1==gcc-compiled task, 0==intel */ |
| 2213 | unsigned reserved31 : 7; /* reserved for library use */ |
| 2214 | |
| 2215 | } kmp_tasking_flags_t; |
| 2216 | |
| 2217 | |
| 2218 | struct kmp_taskdata { /* aligned during dynamic allocation */ |
| 2219 | kmp_int32 td_task_id; /* id, assigned by debugger */ |
| 2220 | kmp_tasking_flags_t td_flags; /* task flags */ |
| 2221 | kmp_team_t * td_team; /* team for this task */ |
| 2222 | kmp_info_p * td_alloc_thread; /* thread that allocated data structures */ |
| 2223 | /* Currently not used except for perhaps IDB */ |
| 2224 | kmp_taskdata_t * td_parent; /* parent task */ |
| 2225 | kmp_int32 td_level; /* task nesting level */ |
| Jonathan Peyton | e6643da | 2016-04-18 21:35:14 +0000 | [diff] [blame] | 2226 | kmp_int32 td_untied_count; /* untied task active parts counter */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2227 | ident_t * td_ident; /* task identifier */ |
| 2228 | // Taskwait data. |
| 2229 | ident_t * td_taskwait_ident; |
| 2230 | kmp_uint32 td_taskwait_counter; |
| 2231 | kmp_int32 td_taskwait_thread; /* gtid + 1 of thread encountered taskwait */ |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2232 | KMP_ALIGN_CACHE kmp_internal_control_t td_icvs; /* Internal control variables for the task */ |
| Jonathan Peyton | b044e4f | 2016-05-23 18:01:19 +0000 | [diff] [blame] | 2233 | KMP_ALIGN_CACHE volatile kmp_uint32 td_allocated_child_tasks; /* Child tasks (+ current task) not yet deallocated */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2234 | volatile kmp_uint32 td_incomplete_child_tasks; /* Child tasks not yet complete */ |
| 2235 | #if OMP_40_ENABLED |
| 2236 | kmp_taskgroup_t * td_taskgroup; // Each task keeps pointer to its current taskgroup |
| 2237 | kmp_dephash_t * td_dephash; // Dependencies for children tasks are tracked from here |
| 2238 | kmp_depnode_t * td_depnode; // Pointer to graph node if this task has dependencies |
| 2239 | #endif |
| Andrey Churbanov | e5f4492 | 2015-04-29 16:22:07 +0000 | [diff] [blame] | 2240 | #if OMPT_SUPPORT |
| 2241 | ompt_task_info_t ompt_task_info; |
| 2242 | #endif |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 2243 | #if OMP_45_ENABLED |
| Jonathan Peyton | 134f90d | 2016-02-11 23:07:30 +0000 | [diff] [blame] | 2244 | kmp_task_team_t * td_task_team; |
| Jonathan Peyton | 283a215 | 2016-03-02 22:47:51 +0000 | [diff] [blame] | 2245 | kmp_int32 td_size_alloc; // The size of task structure, including shareds etc. |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2246 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2247 | }; // struct kmp_taskdata |
| 2248 | |
| 2249 | // Make sure padding above worked |
| 2250 | KMP_BUILD_ASSERT( sizeof(kmp_taskdata_t) % sizeof(void *) == 0 ); |
| 2251 | |
| 2252 | // Data for task team but per thread |
| 2253 | typedef struct kmp_base_thread_data { |
| 2254 | kmp_info_p * td_thr; // Pointer back to thread info |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2255 | // Used only in __kmp_execute_tasks_template, maybe not avail until task is queued? |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2256 | kmp_bootstrap_lock_t td_deque_lock; // Lock for accessing deque |
| 2257 | kmp_taskdata_t ** td_deque; // Deque of tasks encountered by td_thr, dynamically allocated |
| Jonathan Peyton | f4f9695 | 2016-05-31 19:07:00 +0000 | [diff] [blame] | 2258 | kmp_int32 td_deque_size; // Size of deck |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2259 | kmp_uint32 td_deque_head; // Head of deque (will wrap) |
| 2260 | kmp_uint32 td_deque_tail; // Tail of deque (will wrap) |
| 2261 | kmp_int32 td_deque_ntasks; // Number of tasks in deque |
| 2262 | // GEH: shouldn't this be volatile since used in while-spin? |
| 2263 | kmp_int32 td_deque_last_stolen; // Thread number of last successful steal |
| 2264 | #ifdef BUILD_TIED_TASK_STACK |
| 2265 | kmp_task_stack_t td_susp_tied_tasks; // Stack of suspended tied tasks for task scheduling constraint |
| 2266 | #endif // BUILD_TIED_TASK_STACK |
| 2267 | } kmp_base_thread_data_t; |
| 2268 | |
| Jonathan Peyton | f4f9695 | 2016-05-31 19:07:00 +0000 | [diff] [blame] | 2269 | #define TASK_DEQUE_BITS 8 // Used solely to define INITIAL_TASK_DEQUE_SIZE |
| 2270 | #define INITIAL_TASK_DEQUE_SIZE ( 1 << TASK_DEQUE_BITS ) |
| 2271 | |
| 2272 | #define TASK_DEQUE_SIZE(td) ((td).td_deque_size) |
| 2273 | #define TASK_DEQUE_MASK(td) ((td).td_deque_size - 1) |
| 2274 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2275 | typedef union KMP_ALIGN_CACHE kmp_thread_data { |
| 2276 | kmp_base_thread_data_t td; |
| 2277 | double td_align; /* use worst case alignment */ |
| 2278 | char td_pad[ KMP_PAD(kmp_base_thread_data_t, CACHE_LINE) ]; |
| 2279 | } kmp_thread_data_t; |
| 2280 | |
| 2281 | |
| 2282 | // Data for task teams which are used when tasking is enabled for the team |
| 2283 | typedef struct kmp_base_task_team { |
| 2284 | kmp_bootstrap_lock_t tt_threads_lock; /* Lock used to allocate per-thread part of task team */ |
| 2285 | /* must be bootstrap lock since used at library shutdown*/ |
| 2286 | kmp_task_team_t * tt_next; /* For linking the task team free list */ |
| 2287 | kmp_thread_data_t * tt_threads_data; /* Array of per-thread structures for task team */ |
| 2288 | /* Data survives task team deallocation */ |
| 2289 | kmp_int32 tt_found_tasks; /* Have we found tasks and queued them while executing this team? */ |
| 2290 | /* TRUE means tt_threads_data is set up and initialized */ |
| 2291 | kmp_int32 tt_nproc; /* #threads in team */ |
| 2292 | kmp_int32 tt_max_threads; /* number of entries allocated for threads_data array */ |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 2293 | #if OMP_45_ENABLED |
| Andrey Churbanov | 535b6fa | 2015-05-07 17:41:51 +0000 | [diff] [blame] | 2294 | kmp_int32 tt_found_proxy_tasks; /* Have we found proxy tasks since last barrier */ |
| 2295 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2296 | |
| 2297 | KMP_ALIGN_CACHE |
| 2298 | volatile kmp_uint32 tt_unfinished_threads; /* #threads still active */ |
| 2299 | |
| 2300 | KMP_ALIGN_CACHE |
| 2301 | volatile kmp_uint32 tt_active; /* is the team still actively executing tasks */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2302 | } kmp_base_task_team_t; |
| 2303 | |
| 2304 | union KMP_ALIGN_CACHE kmp_task_team { |
| 2305 | kmp_base_task_team_t tt; |
| 2306 | double tt_align; /* use worst case alignment */ |
| 2307 | char tt_pad[ KMP_PAD(kmp_base_task_team_t, CACHE_LINE) ]; |
| 2308 | }; |
| 2309 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2310 | #if ( USE_FAST_MEMORY == 3 ) || ( USE_FAST_MEMORY == 5 ) |
| 2311 | // Free lists keep same-size free memory slots for fast memory allocation routines |
| 2312 | typedef struct kmp_free_list { |
| 2313 | void *th_free_list_self; // Self-allocated tasks free list |
| 2314 | void *th_free_list_sync; // Self-allocated tasks stolen/returned by other threads |
| 2315 | void *th_free_list_other; // Non-self free list (to be returned to owner's sync list) |
| 2316 | } kmp_free_list_t; |
| 2317 | #endif |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2318 | #if KMP_NESTED_HOT_TEAMS |
| 2319 | // Hot teams array keeps hot teams and their sizes for given thread. |
| 2320 | // Hot teams are not put in teams pool, and they don't put threads in threads pool. |
| 2321 | typedef struct kmp_hot_team_ptr { |
| 2322 | kmp_team_p *hot_team; // pointer to hot_team of given nesting level |
| 2323 | kmp_int32 hot_team_nth; // number of threads allocated for the hot_team |
| 2324 | } kmp_hot_team_ptr_t; |
| 2325 | #endif |
| 2326 | #if OMP_40_ENABLED |
| 2327 | typedef struct kmp_teams_size { |
| 2328 | kmp_int32 nteams; // number of teams in a league |
| 2329 | kmp_int32 nth; // number of threads in each team of the league |
| 2330 | } kmp_teams_size_t; |
| 2331 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2332 | |
| 2333 | /* ------------------------------------------------------------------------ */ |
| 2334 | // OpenMP thread data structures |
| 2335 | // |
| 2336 | |
| 2337 | typedef struct KMP_ALIGN_CACHE kmp_base_info { |
| 2338 | /* |
| 2339 | * Start with the readonly data which is cache aligned and padded. |
| 2340 | * this is written before the thread starts working by the master. |
| 2341 | * (uber masters may update themselves later) |
| 2342 | * (usage does not consider serialized regions) |
| 2343 | */ |
| 2344 | kmp_desc_t th_info; |
| 2345 | kmp_team_p *th_team; /* team we belong to */ |
| 2346 | kmp_root_p *th_root; /* pointer to root of task hierarchy */ |
| 2347 | kmp_info_p *th_next_pool; /* next available thread in the pool */ |
| 2348 | kmp_disp_t *th_dispatch; /* thread's dispatch data */ |
| 2349 | int th_in_pool; /* in thread pool (32 bits for TCR/TCW) */ |
| 2350 | |
| 2351 | /* The following are cached from the team info structure */ |
| 2352 | /* TODO use these in more places as determined to be needed via profiling */ |
| 2353 | int th_team_nproc; /* number of threads in a team */ |
| 2354 | kmp_info_p *th_team_master; /* the team's master thread */ |
| 2355 | int th_team_serialized; /* team is serialized */ |
| 2356 | #if OMP_40_ENABLED |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2357 | microtask_t th_teams_microtask; /* save entry address for teams construct */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2358 | int th_teams_level; /* save initial level of teams construct */ |
| 2359 | /* it is 0 on device but may be any on host */ |
| 2360 | #endif |
| 2361 | |
| 2362 | /* The blocktime info is copied from the team struct to the thread sruct */ |
| 2363 | /* at the start of a barrier, and the values stored in the team are used */ |
| 2364 | /* at points in the code where the team struct is no longer guaranteed */ |
| 2365 | /* to exist (from the POV of worker threads). */ |
| 2366 | int th_team_bt_intervals; |
| 2367 | int th_team_bt_set; |
| 2368 | |
| 2369 | |
| Alp Toker | 98758b0 | 2014-03-02 04:12:06 +0000 | [diff] [blame] | 2370 | #if KMP_AFFINITY_SUPPORTED |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2371 | kmp_affin_mask_t *th_affin_mask; /* thread's current affinity mask */ |
| 2372 | #endif |
| 2373 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2374 | /* |
| 2375 | * The data set by the master at reinit, then R/W by the worker |
| 2376 | */ |
| 2377 | KMP_ALIGN_CACHE int th_set_nproc; /* if > 0, then only use this request for the next fork */ |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2378 | #if KMP_NESTED_HOT_TEAMS |
| 2379 | kmp_hot_team_ptr_t *th_hot_teams; /* array of hot teams */ |
| 2380 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2381 | #if OMP_40_ENABLED |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2382 | kmp_proc_bind_t th_set_proc_bind; /* if != proc_bind_default, use request for next fork */ |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2383 | kmp_teams_size_t th_teams_size; /* number of teams/threads in teams construct */ |
| Alp Toker | 98758b0 | 2014-03-02 04:12:06 +0000 | [diff] [blame] | 2384 | # if KMP_AFFINITY_SUPPORTED |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2385 | int th_current_place; /* place currently bound to */ |
| 2386 | int th_new_place; /* place to bind to in par reg */ |
| 2387 | int th_first_place; /* first place in partition */ |
| 2388 | int th_last_place; /* last place in partition */ |
| 2389 | # endif |
| 2390 | #endif |
| 2391 | #if USE_ITT_BUILD |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2392 | kmp_uint64 th_bar_arrive_time; /* arrival to barrier timestamp */ |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2393 | kmp_uint64 th_bar_min_time; /* minimum arrival time at the barrier */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2394 | kmp_uint64 th_frame_time; /* frame timestamp */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2395 | #endif /* USE_ITT_BUILD */ |
| 2396 | kmp_local_t th_local; |
| 2397 | struct private_common *th_pri_head; |
| 2398 | |
| 2399 | /* |
| 2400 | * Now the data only used by the worker (after initial allocation) |
| 2401 | */ |
| 2402 | /* TODO the first serial team should actually be stored in the info_t |
| 2403 | * structure. this will help reduce initial allocation overhead */ |
| 2404 | KMP_ALIGN_CACHE kmp_team_p *th_serial_team; /*serialized team held in reserve*/ |
| Andrey Churbanov | e5f4492 | 2015-04-29 16:22:07 +0000 | [diff] [blame] | 2405 | |
| 2406 | #if OMPT_SUPPORT |
| 2407 | ompt_thread_info_t ompt_thread_info; |
| 2408 | #endif |
| 2409 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2410 | /* The following are also read by the master during reinit */ |
| 2411 | struct common_table *th_pri_common; |
| 2412 | |
| 2413 | volatile kmp_uint32 th_spin_here; /* thread-local location for spinning */ |
| 2414 | /* while awaiting queuing lock acquire */ |
| 2415 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2416 | volatile void *th_sleep_loc; // this points at a kmp_flag<T> |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2417 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2418 | ident_t *th_ident; |
| 2419 | unsigned th_x; // Random number generator data |
| 2420 | unsigned th_a; // Random number generator data |
| 2421 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2422 | /* |
| 2423 | * Tasking-related data for the thread |
| 2424 | */ |
| 2425 | kmp_task_team_t * th_task_team; // Task team struct |
| 2426 | kmp_taskdata_t * th_current_task; // Innermost Task being executed |
| 2427 | kmp_uint8 th_task_state; // alternating 0/1 for task team identification |
| Andrey Churbanov | 6d224db | 2015-02-10 18:37:43 +0000 | [diff] [blame] | 2428 | kmp_uint8 * th_task_state_memo_stack; // Stack holding memos of th_task_state at nested levels |
| 2429 | kmp_uint32 th_task_state_top; // Top element of th_task_state_memo_stack |
| 2430 | kmp_uint32 th_task_state_stack_sz; // Size of th_task_state_memo_stack |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2431 | |
| 2432 | /* |
| 2433 | * More stuff for keeping track of active/sleeping threads |
| 2434 | * (this part is written by the worker thread) |
| 2435 | */ |
| 2436 | kmp_uint8 th_active_in_pool; // included in count of |
| 2437 | // #active threads in pool |
| 2438 | int th_active; // ! sleeping |
| 2439 | // 32 bits for TCR/TCW |
| 2440 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2441 | struct cons_header * th_cons; // used for consistency check |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2442 | |
| 2443 | /* |
| 2444 | * Add the syncronizing data which is cache aligned and padded. |
| 2445 | */ |
| 2446 | KMP_ALIGN_CACHE kmp_balign_t th_bar[ bs_last_barrier ]; |
| 2447 | |
| 2448 | KMP_ALIGN_CACHE volatile kmp_int32 th_next_waiting; /* gtid+1 of next thread on lock wait queue, 0 if none */ |
| 2449 | |
| 2450 | #if ( USE_FAST_MEMORY == 3 ) || ( USE_FAST_MEMORY == 5 ) |
| 2451 | #define NUM_LISTS 4 |
| 2452 | kmp_free_list_t th_free_lists[NUM_LISTS]; // Free lists for fast memory allocation routines |
| 2453 | #endif |
| 2454 | |
| 2455 | #if KMP_OS_WINDOWS |
| 2456 | kmp_win32_cond_t th_suspend_cv; |
| 2457 | kmp_win32_mutex_t th_suspend_mx; |
| 2458 | int th_suspend_init; |
| 2459 | #endif |
| 2460 | #if KMP_OS_UNIX |
| 2461 | kmp_cond_align_t th_suspend_cv; |
| 2462 | kmp_mutex_align_t th_suspend_mx; |
| 2463 | int th_suspend_init_count; |
| 2464 | #endif |
| 2465 | |
| 2466 | #if USE_ITT_BUILD |
| 2467 | kmp_itt_mark_t th_itt_mark_single; |
| 2468 | // alignment ??? |
| 2469 | #endif /* USE_ITT_BUILD */ |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2470 | #if KMP_STATS_ENABLED |
| 2471 | kmp_stats_list* th_stats; |
| 2472 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2473 | } kmp_base_info_t; |
| 2474 | |
| 2475 | typedef union KMP_ALIGN_CACHE kmp_info { |
| 2476 | double th_align; /* use worst case alignment */ |
| 2477 | char th_pad[ KMP_PAD(kmp_base_info_t, CACHE_LINE) ]; |
| 2478 | kmp_base_info_t th; |
| 2479 | } kmp_info_t; |
| 2480 | |
| 2481 | /* ------------------------------------------------------------------------ */ |
| 2482 | // OpenMP thread team data structures |
| 2483 | // |
| 2484 | typedef struct kmp_base_data { |
| 2485 | volatile kmp_uint32 t_value; |
| 2486 | } kmp_base_data_t; |
| 2487 | |
| 2488 | typedef union KMP_ALIGN_CACHE kmp_sleep_team { |
| 2489 | double dt_align; /* use worst case alignment */ |
| 2490 | char dt_pad[ KMP_PAD(kmp_base_data_t, CACHE_LINE) ]; |
| 2491 | kmp_base_data_t dt; |
| 2492 | } kmp_sleep_team_t; |
| 2493 | |
| 2494 | typedef union KMP_ALIGN_CACHE kmp_ordered_team { |
| 2495 | double dt_align; /* use worst case alignment */ |
| 2496 | char dt_pad[ KMP_PAD(kmp_base_data_t, CACHE_LINE) ]; |
| 2497 | kmp_base_data_t dt; |
| 2498 | } kmp_ordered_team_t; |
| 2499 | |
| 2500 | typedef int (*launch_t)( int gtid ); |
| 2501 | |
| 2502 | /* Minimum number of ARGV entries to malloc if necessary */ |
| 2503 | #define KMP_MIN_MALLOC_ARGV_ENTRIES 100 |
| 2504 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2505 | // Set up how many argv pointers will fit in cache lines containing t_inline_argv. Historically, we |
| 2506 | // have supported at least 96 bytes. Using a larger value for more space between the master write/worker |
| 2507 | // read section and read/write by all section seems to buy more performance on EPCC PARALLEL. |
| 2508 | #if KMP_ARCH_X86 || KMP_ARCH_X86_64 |
| 2509 | # define KMP_INLINE_ARGV_BYTES ( 4 * CACHE_LINE - ( ( 3 * KMP_PTR_SKIP + 2 * sizeof(int) + 2 * sizeof(kmp_int8) + sizeof(kmp_int16) + sizeof(kmp_uint32) ) % CACHE_LINE ) ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2510 | #else |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2511 | # define KMP_INLINE_ARGV_BYTES ( 2 * CACHE_LINE - ( ( 3 * KMP_PTR_SKIP + 2 * sizeof(int) ) % CACHE_LINE ) ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2512 | #endif |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2513 | #define KMP_INLINE_ARGV_ENTRIES (int)( KMP_INLINE_ARGV_BYTES / KMP_PTR_SKIP ) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2514 | |
| 2515 | typedef struct KMP_ALIGN_CACHE kmp_base_team { |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2516 | // Synchronization Data --------------------------------------------------------------------------------- |
| 2517 | KMP_ALIGN_CACHE kmp_ordered_team_t t_ordered; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2518 | kmp_balign_team_t t_bar[ bs_last_barrier ]; |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2519 | volatile int t_construct; // count of single directive encountered by team |
| 2520 | kmp_lock_t t_single_lock; // team specific lock |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2521 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2522 | // Master only ----------------------------------------------------------------------------------------- |
| 2523 | KMP_ALIGN_CACHE int t_master_tid; // tid of master in parent team |
| 2524 | int t_master_this_cons; // "this_construct" single counter of master in parent team |
| 2525 | ident_t *t_ident; // if volatile, have to change too much other crud to volatile too |
| 2526 | kmp_team_p *t_parent; // parent team |
| 2527 | kmp_team_p *t_next_pool; // next free team in the team pool |
| 2528 | kmp_disp_t *t_dispatch; // thread's dispatch data |
| Andrey Churbanov | 6d224db | 2015-02-10 18:37:43 +0000 | [diff] [blame] | 2529 | kmp_task_team_t *t_task_team[2]; // Task team struct; switch between 2 |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2530 | #if OMP_40_ENABLED |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2531 | kmp_proc_bind_t t_proc_bind; // bind type for par region |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2532 | #endif // OMP_40_ENABLED |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2533 | #if USE_ITT_BUILD |
| 2534 | kmp_uint64 t_region_time; // region begin timestamp |
| 2535 | #endif /* USE_ITT_BUILD */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2536 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2537 | // Master write, workers read -------------------------------------------------------------------------- |
| 2538 | KMP_ALIGN_CACHE void **t_argv; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2539 | int t_argc; |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2540 | int t_nproc; // number of threads in team |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2541 | microtask_t t_pkfn; |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2542 | launch_t t_invoke; // procedure to launch the microtask |
| Andrey Churbanov | e5f4492 | 2015-04-29 16:22:07 +0000 | [diff] [blame] | 2543 | |
| 2544 | #if OMPT_SUPPORT |
| 2545 | ompt_team_info_t ompt_team_info; |
| 2546 | ompt_lw_taskteam_t *ompt_serialized_team_info; |
| 2547 | #endif |
| 2548 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2549 | #if KMP_ARCH_X86 || KMP_ARCH_X86_64 |
| 2550 | kmp_int8 t_fp_control_saved; |
| 2551 | kmp_int8 t_pad2b; |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2552 | kmp_int16 t_x87_fpu_control_word; // FP control regs |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2553 | kmp_uint32 t_mxcsr; |
| 2554 | #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */ |
| 2555 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2556 | void *t_inline_argv[ KMP_INLINE_ARGV_ENTRIES ]; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2557 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2558 | KMP_ALIGN_CACHE kmp_info_t **t_threads; |
| Jonathan Peyton | b044e4f | 2016-05-23 18:01:19 +0000 | [diff] [blame] | 2559 | kmp_taskdata_t *t_implicit_task_taskdata; // Taskdata for the thread's implicit task |
| 2560 | int t_level; // nested parallel level |
| 2561 | |
| 2562 | KMP_ALIGN_CACHE int t_max_argc; |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2563 | int t_max_nproc; // maximum threads this team can handle (dynamicly expandable) |
| 2564 | int t_serialized; // levels deep of serialized teams |
| 2565 | dispatch_shared_info_t *t_disp_buffer; // buffers for dispatch system |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2566 | int t_id; // team's id, assigned by debugger. |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2567 | int t_active_level; // nested active parallel level |
| 2568 | kmp_r_sched_t t_sched; // run-time schedule for the team |
| Alp Toker | 98758b0 | 2014-03-02 04:12:06 +0000 | [diff] [blame] | 2569 | #if OMP_40_ENABLED && KMP_AFFINITY_SUPPORTED |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2570 | int t_first_place; // first & last place in parent thread's partition. |
| 2571 | int t_last_place; // Restore these values to master after par region. |
| Alp Toker | 98758b0 | 2014-03-02 04:12:06 +0000 | [diff] [blame] | 2572 | #endif // OMP_40_ENABLED && KMP_AFFINITY_SUPPORTED |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2573 | int t_size_changed; // team size was changed?: 0: no, 1: yes, -1: changed via omp_set_num_threads() call |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2574 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2575 | // Read/write by workers as well ----------------------------------------------------------------------- |
| Jonathan Peyton | 4d3c213 | 2016-07-08 17:43:21 +0000 | [diff] [blame^] | 2576 | #if (KMP_ARCH_X86 || KMP_ARCH_X86_64) && !KMP_USE_HWLOC |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2577 | // Using CACHE_LINE=64 reduces memory footprint, but causes a big perf regression of epcc 'parallel' |
| 2578 | // and 'barrier' on fxe256lin01. This extra padding serves to fix the performance of epcc 'parallel' |
| 2579 | // and 'barrier' when CACHE_LINE=64. TODO: investigate more and get rid if this padding. |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2580 | char dummy_padding[1024]; |
| 2581 | #endif |
| Jonathan Peyton | b044e4f | 2016-05-23 18:01:19 +0000 | [diff] [blame] | 2582 | KMP_ALIGN_CACHE kmp_internal_control_t *t_control_stack_top; // internal control stack for additional nested teams. |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2583 | // for SERIALIZED teams nested 2 or more levels deep |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2584 | #if OMP_40_ENABLED |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2585 | kmp_int32 t_cancel_request; // typed flag to store request state of cancellation |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2586 | #endif |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2587 | int t_master_active; // save on fork, restore on join |
| 2588 | kmp_taskq_t t_taskq; // this team's task queue |
| 2589 | void *t_copypriv_data; // team specific pointer to copyprivate data array |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2590 | kmp_uint32 t_copyin_counter; |
| 2591 | #if USE_ITT_BUILD |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2592 | void *t_stack_id; // team specific stack stitching id (for ittnotify) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2593 | #endif /* USE_ITT_BUILD */ |
| 2594 | } kmp_base_team_t; |
| 2595 | |
| 2596 | union KMP_ALIGN_CACHE kmp_team { |
| 2597 | kmp_base_team_t t; |
| 2598 | double t_align; /* use worst case alignment */ |
| 2599 | char t_pad[ KMP_PAD(kmp_base_team_t, CACHE_LINE) ]; |
| 2600 | }; |
| 2601 | |
| 2602 | |
| 2603 | typedef union KMP_ALIGN_CACHE kmp_time_global { |
| 2604 | double dt_align; /* use worst case alignment */ |
| 2605 | char dt_pad[ KMP_PAD(kmp_base_data_t, CACHE_LINE) ]; |
| 2606 | kmp_base_data_t dt; |
| 2607 | } kmp_time_global_t; |
| 2608 | |
| 2609 | typedef struct kmp_base_global { |
| 2610 | /* cache-aligned */ |
| 2611 | kmp_time_global_t g_time; |
| 2612 | |
| 2613 | /* non cache-aligned */ |
| 2614 | volatile int g_abort; |
| 2615 | volatile int g_done; |
| 2616 | |
| 2617 | int g_dynamic; |
| 2618 | enum dynamic_mode g_dynamic_mode; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2619 | } kmp_base_global_t; |
| 2620 | |
| 2621 | typedef union KMP_ALIGN_CACHE kmp_global { |
| 2622 | kmp_base_global_t g; |
| 2623 | double g_align; /* use worst case alignment */ |
| 2624 | char g_pad[ KMP_PAD(kmp_base_global_t, CACHE_LINE) ]; |
| 2625 | } kmp_global_t; |
| 2626 | |
| 2627 | |
| 2628 | typedef struct kmp_base_root { |
| 2629 | // TODO: GEH - combine r_active with r_in_parallel then r_active == (r_in_parallel>= 0) |
| 2630 | // TODO: GEH - then replace r_active with t_active_levels if we can to reduce the synch |
| 2631 | // overhead or keeping r_active |
| 2632 | |
| 2633 | volatile int r_active; /* TRUE if some region in a nest has > 1 thread */ |
| 2634 | // GEH: This is misnamed, should be r_in_parallel |
| 2635 | volatile int r_nested; // TODO: GEH - This is unused, just remove it entirely. |
| 2636 | int r_in_parallel; /* keeps a count of active parallel regions per root */ |
| 2637 | // GEH: This is misnamed, should be r_active_levels |
| 2638 | kmp_team_t *r_root_team; |
| 2639 | kmp_team_t *r_hot_team; |
| 2640 | kmp_info_t *r_uber_thread; |
| 2641 | kmp_lock_t r_begin_lock; |
| 2642 | volatile int r_begin; |
| 2643 | int r_blocktime; /* blocktime for this root and descendants */ |
| 2644 | } kmp_base_root_t; |
| 2645 | |
| 2646 | typedef union KMP_ALIGN_CACHE kmp_root { |
| 2647 | kmp_base_root_t r; |
| 2648 | double r_align; /* use worst case alignment */ |
| 2649 | char r_pad[ KMP_PAD(kmp_base_root_t, CACHE_LINE) ]; |
| 2650 | } kmp_root_t; |
| 2651 | |
| 2652 | struct fortran_inx_info { |
| 2653 | kmp_int32 data; |
| 2654 | }; |
| 2655 | |
| 2656 | /* ------------------------------------------------------------------------ */ |
| 2657 | |
| 2658 | /* ------------------------------------------------------------------------ */ |
| 2659 | /* ------------------------------------------------------------------------ */ |
| 2660 | |
| 2661 | extern int __kmp_settings; |
| 2662 | extern int __kmp_duplicate_library_ok; |
| 2663 | #if USE_ITT_BUILD |
| 2664 | extern int __kmp_forkjoin_frames; |
| 2665 | extern int __kmp_forkjoin_frames_mode; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2666 | #endif |
| 2667 | extern PACKED_REDUCTION_METHOD_T __kmp_force_reduction_method; |
| 2668 | extern int __kmp_determ_red; |
| 2669 | |
| 2670 | #ifdef KMP_DEBUG |
| 2671 | extern int kmp_a_debug; |
| 2672 | extern int kmp_b_debug; |
| 2673 | extern int kmp_c_debug; |
| 2674 | extern int kmp_d_debug; |
| 2675 | extern int kmp_e_debug; |
| 2676 | extern int kmp_f_debug; |
| 2677 | #endif /* KMP_DEBUG */ |
| 2678 | |
| 2679 | /* For debug information logging using rotating buffer */ |
| 2680 | #define KMP_DEBUG_BUF_LINES_INIT 512 |
| 2681 | #define KMP_DEBUG_BUF_LINES_MIN 1 |
| 2682 | |
| 2683 | #define KMP_DEBUG_BUF_CHARS_INIT 128 |
| 2684 | #define KMP_DEBUG_BUF_CHARS_MIN 2 |
| 2685 | |
| 2686 | extern int __kmp_debug_buf; /* TRUE means use buffer, FALSE means print to stderr */ |
| 2687 | extern int __kmp_debug_buf_lines; /* How many lines of debug stored in buffer */ |
| 2688 | extern int __kmp_debug_buf_chars; /* How many characters allowed per line in buffer */ |
| 2689 | extern int __kmp_debug_buf_atomic; /* TRUE means use atomic update of buffer entry pointer */ |
| 2690 | |
| 2691 | extern char *__kmp_debug_buffer; /* Debug buffer itself */ |
| 2692 | extern int __kmp_debug_count; /* Counter for number of lines printed in buffer so far */ |
| 2693 | extern int __kmp_debug_buf_warn_chars; /* Keep track of char increase recommended in warnings */ |
| 2694 | /* end rotating debug buffer */ |
| 2695 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2696 | #ifdef KMP_DEBUG |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2697 | extern int __kmp_par_range; /* +1 => only go par for constructs in range */ |
| 2698 | |
| 2699 | #define KMP_PAR_RANGE_ROUTINE_LEN 1024 |
| 2700 | extern char __kmp_par_range_routine[KMP_PAR_RANGE_ROUTINE_LEN]; |
| 2701 | #define KMP_PAR_RANGE_FILENAME_LEN 1024 |
| 2702 | extern char __kmp_par_range_filename[KMP_PAR_RANGE_FILENAME_LEN]; |
| 2703 | extern int __kmp_par_range_lb; |
| 2704 | extern int __kmp_par_range_ub; |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2705 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2706 | |
| 2707 | /* For printing out dynamic storage map for threads and teams */ |
| 2708 | extern int __kmp_storage_map; /* True means print storage map for threads and teams */ |
| 2709 | extern int __kmp_storage_map_verbose; /* True means storage map includes placement info */ |
| 2710 | extern int __kmp_storage_map_verbose_specified; |
| 2711 | |
| Hal Finkel | 01bb240 | 2016-03-27 13:24:09 +0000 | [diff] [blame] | 2712 | #if KMP_ARCH_X86 || KMP_ARCH_X86_64 |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2713 | extern kmp_cpuinfo_t __kmp_cpuinfo; |
| Hal Finkel | 01bb240 | 2016-03-27 13:24:09 +0000 | [diff] [blame] | 2714 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2715 | |
| 2716 | extern volatile int __kmp_init_serial; |
| 2717 | extern volatile int __kmp_init_gtid; |
| 2718 | extern volatile int __kmp_init_common; |
| 2719 | extern volatile int __kmp_init_middle; |
| 2720 | extern volatile int __kmp_init_parallel; |
| 2721 | extern volatile int __kmp_init_monitor; |
| 2722 | extern volatile int __kmp_init_user_locks; |
| 2723 | extern int __kmp_init_counter; |
| 2724 | extern int __kmp_root_counter; |
| 2725 | extern int __kmp_version; |
| 2726 | |
| 2727 | /* list of address of allocated caches for commons */ |
| 2728 | extern kmp_cached_addr_t *__kmp_threadpriv_cache_list; |
| 2729 | |
| 2730 | /* Barrier algorithm types and options */ |
| 2731 | extern kmp_uint32 __kmp_barrier_gather_bb_dflt; |
| 2732 | extern kmp_uint32 __kmp_barrier_release_bb_dflt; |
| 2733 | extern kmp_bar_pat_e __kmp_barrier_gather_pat_dflt; |
| 2734 | extern kmp_bar_pat_e __kmp_barrier_release_pat_dflt; |
| 2735 | extern kmp_uint32 __kmp_barrier_gather_branch_bits [ bs_last_barrier ]; |
| 2736 | extern kmp_uint32 __kmp_barrier_release_branch_bits [ bs_last_barrier ]; |
| 2737 | extern kmp_bar_pat_e __kmp_barrier_gather_pattern [ bs_last_barrier ]; |
| 2738 | extern kmp_bar_pat_e __kmp_barrier_release_pattern [ bs_last_barrier ]; |
| 2739 | extern char const *__kmp_barrier_branch_bit_env_name [ bs_last_barrier ]; |
| 2740 | extern char const *__kmp_barrier_pattern_env_name [ bs_last_barrier ]; |
| 2741 | extern char const *__kmp_barrier_type_name [ bs_last_barrier ]; |
| 2742 | extern char const *__kmp_barrier_pattern_name [ bp_last_bar ]; |
| 2743 | |
| 2744 | /* Global Locks */ |
| 2745 | extern kmp_bootstrap_lock_t __kmp_initz_lock; /* control initialization */ |
| Jonathan Peyton | 021cad0 | 2015-06-02 22:21:37 +0000 | [diff] [blame] | 2746 | extern kmp_bootstrap_lock_t __kmp_forkjoin_lock; /* control fork/join access */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2747 | extern kmp_bootstrap_lock_t __kmp_exit_lock; /* exit() is not always thread-safe */ |
| 2748 | extern kmp_bootstrap_lock_t __kmp_monitor_lock; /* control monitor thread creation */ |
| 2749 | extern kmp_bootstrap_lock_t __kmp_tp_cached_lock; /* used for the hack to allow threadprivate cache and __kmp_threads expansion to co-exist */ |
| 2750 | |
| 2751 | extern kmp_lock_t __kmp_global_lock; /* control OS/global access */ |
| 2752 | extern kmp_queuing_lock_t __kmp_dispatch_lock; /* control dispatch access */ |
| 2753 | extern kmp_lock_t __kmp_debug_lock; /* control I/O access for KMP_DEBUG */ |
| 2754 | |
| 2755 | /* used for yielding spin-waits */ |
| 2756 | extern unsigned int __kmp_init_wait; /* initial number of spin-tests */ |
| 2757 | extern unsigned int __kmp_next_wait; /* susequent number of spin-tests */ |
| 2758 | |
| 2759 | extern enum library_type __kmp_library; |
| 2760 | |
| 2761 | extern enum sched_type __kmp_sched; /* default runtime scheduling */ |
| 2762 | extern enum sched_type __kmp_static; /* default static scheduling method */ |
| 2763 | extern enum sched_type __kmp_guided; /* default guided scheduling method */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2764 | extern enum sched_type __kmp_auto; /* default auto scheduling method */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2765 | extern int __kmp_chunk; /* default runtime chunk size */ |
| 2766 | |
| 2767 | extern size_t __kmp_stksize; /* stack size per thread */ |
| 2768 | extern size_t __kmp_monitor_stksize;/* stack size for monitor thread */ |
| 2769 | extern size_t __kmp_stkoffset; /* stack offset per thread */ |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2770 | extern int __kmp_stkpadding; /* Should we pad root thread(s) stack */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2771 | |
| 2772 | extern size_t __kmp_malloc_pool_incr; /* incremental size of pool for kmp_malloc() */ |
| 2773 | extern int __kmp_env_chunk; /* was KMP_CHUNK specified? */ |
| 2774 | extern int __kmp_env_stksize; /* was KMP_STACKSIZE specified? */ |
| 2775 | extern int __kmp_env_omp_stksize;/* was OMP_STACKSIZE specified? */ |
| 2776 | extern int __kmp_env_all_threads; /* was KMP_ALL_THREADS or KMP_MAX_THREADS specified? */ |
| 2777 | extern int __kmp_env_omp_all_threads;/* was OMP_THREAD_LIMIT specified? */ |
| 2778 | extern int __kmp_env_blocktime; /* was KMP_BLOCKTIME specified? */ |
| 2779 | extern int __kmp_env_checks; /* was KMP_CHECKS specified? */ |
| 2780 | extern int __kmp_env_consistency_check; /* was KMP_CONSISTENCY_CHECK specified? */ |
| 2781 | extern int __kmp_generate_warnings; /* should we issue warnings? */ |
| 2782 | extern int __kmp_reserve_warn; /* have we issued reserve_threads warning? */ |
| 2783 | |
| 2784 | #ifdef DEBUG_SUSPEND |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2785 | extern int __kmp_suspend_count; /* count inside __kmp_suspend_template() */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2786 | #endif |
| 2787 | |
| 2788 | extern kmp_uint32 __kmp_yield_init; |
| 2789 | extern kmp_uint32 __kmp_yield_next; |
| 2790 | extern kmp_uint32 __kmp_yielding_on; |
| 2791 | extern kmp_uint32 __kmp_yield_cycle; |
| 2792 | extern kmp_int32 __kmp_yield_on_count; |
| 2793 | extern kmp_int32 __kmp_yield_off_count; |
| 2794 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2795 | /* ------------------------------------------------------------------------- */ |
| 2796 | extern int __kmp_allThreadsSpecified; |
| 2797 | |
| 2798 | extern size_t __kmp_align_alloc; |
| 2799 | /* following data protected by initialization routines */ |
| 2800 | extern int __kmp_xproc; /* number of processors in the system */ |
| 2801 | extern int __kmp_avail_proc; /* number of processors available to the process */ |
| 2802 | extern size_t __kmp_sys_min_stksize; /* system-defined minimum stack size */ |
| 2803 | extern int __kmp_sys_max_nth; /* system-imposed maximum number of threads */ |
| 2804 | extern int __kmp_max_nth; /* maximum total number of concurrently-existing threads */ |
| 2805 | extern int __kmp_threads_capacity; /* capacity of the arrays __kmp_threads and __kmp_root */ |
| 2806 | extern int __kmp_dflt_team_nth; /* default number of threads in a parallel region a la OMP_NUM_THREADS */ |
| 2807 | extern int __kmp_dflt_team_nth_ub; /* upper bound on "" determined at serial initialization */ |
| 2808 | extern int __kmp_tp_capacity; /* capacity of __kmp_threads if threadprivate is used (fixed) */ |
| 2809 | extern int __kmp_tp_cached; /* whether threadprivate cache has been created (__kmpc_threadprivate_cached()) */ |
| 2810 | extern int __kmp_dflt_nested; /* nested parallelism enabled by default a la OMP_NESTED */ |
| 2811 | extern int __kmp_dflt_blocktime; /* number of milliseconds to wait before blocking (env setting) */ |
| 2812 | extern int __kmp_monitor_wakeups;/* number of times monitor wakes up per second */ |
| 2813 | extern int __kmp_bt_intervals; /* number of monitor timestamp intervals before blocking */ |
| 2814 | #ifdef KMP_ADJUST_BLOCKTIME |
| 2815 | extern int __kmp_zero_bt; /* whether blocktime has been forced to zero */ |
| 2816 | #endif /* KMP_ADJUST_BLOCKTIME */ |
| Andrey Churbanov | f696c82 | 2015-01-27 16:55:43 +0000 | [diff] [blame] | 2817 | #ifdef KMP_DFLT_NTH_CORES |
| Andrey Churbanov | 5cd50e3 | 2015-01-29 17:14:58 +0000 | [diff] [blame] | 2818 | extern int __kmp_ncores; /* Total number of cores for threads placement */ |
| Andrey Churbanov | f696c82 | 2015-01-27 16:55:43 +0000 | [diff] [blame] | 2819 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2820 | extern int __kmp_abort_delay; /* Number of millisecs to delay on abort for VTune */ |
| 2821 | |
| 2822 | extern int __kmp_need_register_atfork_specified; |
| 2823 | extern int __kmp_need_register_atfork;/* At initialization, call pthread_atfork to install fork handler */ |
| 2824 | extern int __kmp_gtid_mode; /* Method of getting gtid, values: |
| 2825 | 0 - not set, will be set at runtime |
| 2826 | 1 - using stack search |
| 2827 | 2 - dynamic TLS (pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)) |
| 2828 | 3 - static TLS (__declspec(thread) __kmp_gtid), Linux* OS .so only. |
| 2829 | */ |
| 2830 | extern int __kmp_adjust_gtid_mode; /* If true, adjust method based on #threads */ |
| 2831 | #ifdef KMP_TDATA_GTID |
| 2832 | #if KMP_OS_WINDOWS |
| 2833 | extern __declspec(thread) int __kmp_gtid; /* This thread's gtid, if __kmp_gtid_mode == 3 */ |
| 2834 | #else |
| 2835 | extern __thread int __kmp_gtid; |
| 2836 | #endif /* KMP_OS_WINDOWS - workaround because Intel(R) Many Integrated Core compiler 20110316 doesn't accept __declspec */ |
| 2837 | #endif |
| 2838 | extern int __kmp_tls_gtid_min; /* #threads below which use sp search for gtid */ |
| 2839 | extern int __kmp_foreign_tp; /* If true, separate TP var for each foreign thread */ |
| 2840 | #if KMP_ARCH_X86 || KMP_ARCH_X86_64 |
| 2841 | extern int __kmp_inherit_fp_control; /* copy fp creg(s) parent->workers at fork */ |
| 2842 | extern kmp_int16 __kmp_init_x87_fpu_control_word; /* init thread's FP control reg */ |
| 2843 | extern kmp_uint32 __kmp_init_mxcsr; /* init thread's mxscr */ |
| 2844 | #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */ |
| 2845 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2846 | extern int __kmp_dflt_max_active_levels; /* max_active_levels for nested parallelism enabled by default a la OMP_MAX_ACTIVE_LEVELS */ |
| Jonathan Peyton | 067325f | 2016-05-31 19:01:15 +0000 | [diff] [blame] | 2847 | extern int __kmp_dispatch_num_buffers; /* max possible dynamic loops in concurrent execution per team */ |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 2848 | #if KMP_NESTED_HOT_TEAMS |
| 2849 | extern int __kmp_hot_teams_mode; |
| 2850 | extern int __kmp_hot_teams_max_level; |
| 2851 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2852 | |
| 2853 | # if KMP_OS_LINUX |
| 2854 | extern enum clock_function_type __kmp_clock_function; |
| 2855 | extern int __kmp_clock_function_param; |
| 2856 | # endif /* KMP_OS_LINUX */ |
| 2857 | |
| Andrey Churbanov | 613edeb | 2015-02-20 18:14:43 +0000 | [diff] [blame] | 2858 | #if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS) |
| 2859 | extern enum mic_type __kmp_mic_type; |
| 2860 | #endif |
| 2861 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2862 | # ifdef USE_LOAD_BALANCE |
| 2863 | extern double __kmp_load_balance_interval; /* Interval for the load balance algorithm */ |
| 2864 | # endif /* USE_LOAD_BALANCE */ |
| 2865 | |
| 2866 | // OpenMP 3.1 - Nested num threads array |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2867 | typedef struct kmp_nested_nthreads_t { |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2868 | int * nth; |
| 2869 | int size; |
| 2870 | int used; |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2871 | } kmp_nested_nthreads_t; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2872 | |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2873 | extern kmp_nested_nthreads_t __kmp_nested_nth; |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2874 | |
| 2875 | #if KMP_USE_ADAPTIVE_LOCKS |
| 2876 | |
| 2877 | // Parameters for the speculative lock backoff system. |
| 2878 | struct kmp_adaptive_backoff_params_t { |
| 2879 | // Number of soft retries before it counts as a hard retry. |
| 2880 | kmp_uint32 max_soft_retries; |
| 2881 | // Badness is a bit mask : 0,1,3,7,15,... on each hard failure we move one to the right |
| 2882 | kmp_uint32 max_badness; |
| 2883 | }; |
| 2884 | |
| 2885 | extern kmp_adaptive_backoff_params_t __kmp_adaptive_backoff_params; |
| 2886 | |
| 2887 | #if KMP_DEBUG_ADAPTIVE_LOCKS |
| 2888 | extern char * __kmp_speculative_statsfile; |
| 2889 | #endif |
| 2890 | |
| 2891 | #endif // KMP_USE_ADAPTIVE_LOCKS |
| 2892 | |
| 2893 | #if OMP_40_ENABLED |
| 2894 | extern int __kmp_display_env; /* TRUE or FALSE */ |
| 2895 | extern int __kmp_display_env_verbose; /* TRUE if OMP_DISPLAY_ENV=VERBOSE */ |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2896 | extern int __kmp_omp_cancellation; /* TRUE or FALSE */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2897 | #endif |
| 2898 | |
| 2899 | /* ------------------------------------------------------------------------- */ |
| 2900 | |
| 2901 | /* --------------------------------------------------------------------------- */ |
| 2902 | /* the following are protected by the fork/join lock */ |
| 2903 | /* write: lock read: anytime */ |
| 2904 | extern kmp_info_t **__kmp_threads; /* Descriptors for the threads */ |
| 2905 | /* read/write: lock */ |
| 2906 | extern volatile kmp_team_t * __kmp_team_pool; |
| 2907 | extern volatile kmp_info_t * __kmp_thread_pool; |
| 2908 | |
| 2909 | /* total number of threads reachable from some root thread including all root threads*/ |
| 2910 | extern volatile int __kmp_nth; |
| 2911 | /* total number of threads reachable from some root thread including all root threads, |
| 2912 | and those in the thread pool */ |
| 2913 | extern volatile int __kmp_all_nth; |
| 2914 | extern int __kmp_thread_pool_nth; |
| 2915 | extern volatile int __kmp_thread_pool_active_nth; |
| 2916 | |
| 2917 | extern kmp_root_t **__kmp_root; /* root of thread hierarchy */ |
| 2918 | /* end data protected by fork/join lock */ |
| 2919 | /* --------------------------------------------------------------------------- */ |
| 2920 | |
| 2921 | extern kmp_global_t __kmp_global; /* global status */ |
| 2922 | |
| 2923 | extern kmp_info_t __kmp_monitor; |
| 2924 | extern volatile kmp_uint32 __kmp_team_counter; // Used by Debugging Support Library. |
| 2925 | extern volatile kmp_uint32 __kmp_task_counter; // Used by Debugging Support Library. |
| 2926 | |
| Jonathan Peyton | 8fbb49a | 2015-07-09 18:16:58 +0000 | [diff] [blame] | 2927 | #if USE_DEBUGGER |
| 2928 | |
| 2929 | #define _KMP_GEN_ID( counter ) \ |
| 2930 | ( \ |
| 2931 | __kmp_debugging \ |
| 2932 | ? \ |
| 2933 | KMP_TEST_THEN_INC32( (volatile kmp_int32 *) & counter ) + 1 \ |
| 2934 | : \ |
| 2935 | ~ 0 \ |
| 2936 | ) |
| 2937 | #else |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2938 | #define _KMP_GEN_ID( counter ) \ |
| 2939 | ( \ |
| 2940 | ~ 0 \ |
| 2941 | ) |
| Jonathan Peyton | 8fbb49a | 2015-07-09 18:16:58 +0000 | [diff] [blame] | 2942 | #endif /* USE_DEBUGGER */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2943 | |
| 2944 | #define KMP_GEN_TASK_ID() _KMP_GEN_ID( __kmp_task_counter ) |
| 2945 | #define KMP_GEN_TEAM_ID() _KMP_GEN_ID( __kmp_team_counter ) |
| 2946 | |
| 2947 | /* ------------------------------------------------------------------------ */ |
| 2948 | /* ------------------------------------------------------------------------ */ |
| 2949 | |
| 2950 | extern void __kmp_print_storage_map_gtid( int gtid, void *p1, void* p2, size_t size, char const *format, ... ); |
| 2951 | |
| 2952 | extern void __kmp_serial_initialize( void ); |
| 2953 | extern void __kmp_middle_initialize( void ); |
| 2954 | extern void __kmp_parallel_initialize( void ); |
| 2955 | |
| 2956 | extern void __kmp_internal_begin( void ); |
| 2957 | extern void __kmp_internal_end_library( int gtid ); |
| 2958 | extern void __kmp_internal_end_thread( int gtid ); |
| 2959 | extern void __kmp_internal_end_atexit( void ); |
| 2960 | extern void __kmp_internal_end_fini( void ); |
| 2961 | extern void __kmp_internal_end_dtor( void ); |
| 2962 | extern void __kmp_internal_end_dest( void* ); |
| 2963 | |
| 2964 | extern int __kmp_register_root( int initial_thread ); |
| 2965 | extern void __kmp_unregister_root( int gtid ); |
| 2966 | |
| 2967 | extern int __kmp_ignore_mppbeg( void ); |
| 2968 | extern int __kmp_ignore_mppend( void ); |
| 2969 | |
| 2970 | extern int __kmp_enter_single( int gtid, ident_t *id_ref, int push_ws ); |
| 2971 | extern void __kmp_exit_single( int gtid ); |
| 2972 | |
| 2973 | extern void __kmp_parallel_deo( int *gtid_ref, int *cid_ref, ident_t *loc_ref ); |
| 2974 | extern void __kmp_parallel_dxo( int *gtid_ref, int *cid_ref, ident_t *loc_ref ); |
| 2975 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2976 | #ifdef USE_LOAD_BALANCE |
| 2977 | extern int __kmp_get_load_balance( int ); |
| 2978 | #endif |
| 2979 | |
| 2980 | #ifdef BUILD_TV |
| 2981 | extern void __kmp_tv_threadprivate_store( kmp_info_t *th, void *global_addr, void *thread_addr ); |
| 2982 | #endif |
| 2983 | |
| 2984 | extern int __kmp_get_global_thread_id( void ); |
| 2985 | extern int __kmp_get_global_thread_id_reg( void ); |
| 2986 | extern void __kmp_exit_thread( int exit_status ); |
| 2987 | extern void __kmp_abort( char const * format, ... ); |
| 2988 | extern void __kmp_abort_thread( void ); |
| 2989 | extern void __kmp_abort_process( void ); |
| 2990 | extern void __kmp_warn( char const * format, ... ); |
| 2991 | |
| 2992 | extern void __kmp_set_num_threads( int new_nth, int gtid ); |
| 2993 | |
| 2994 | // Returns current thread (pointer to kmp_info_t). Current thread *must* be registered. |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 2995 | static inline kmp_info_t * __kmp_entry_thread() |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 2996 | { |
| 2997 | int gtid = __kmp_entry_gtid(); |
| 2998 | |
| 2999 | return __kmp_threads[gtid]; |
| 3000 | } |
| 3001 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3002 | extern void __kmp_set_max_active_levels( int gtid, int new_max_active_levels ); |
| 3003 | extern int __kmp_get_max_active_levels( int gtid ); |
| 3004 | extern int __kmp_get_ancestor_thread_num( int gtid, int level ); |
| 3005 | extern int __kmp_get_team_size( int gtid, int level ); |
| 3006 | extern void __kmp_set_schedule( int gtid, kmp_sched_t new_sched, int chunk ); |
| 3007 | extern void __kmp_get_schedule( int gtid, kmp_sched_t * sched, int * chunk ); |
| 3008 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3009 | extern unsigned short __kmp_get_random( kmp_info_t * thread ); |
| 3010 | extern void __kmp_init_random( kmp_info_t * thread ); |
| 3011 | |
| 3012 | extern kmp_r_sched_t __kmp_get_schedule_global( void ); |
| 3013 | extern void __kmp_adjust_num_threads( int new_nproc ); |
| 3014 | |
| 3015 | extern void * ___kmp_allocate( size_t size KMP_SRC_LOC_DECL ); |
| 3016 | extern void * ___kmp_page_allocate( size_t size KMP_SRC_LOC_DECL ); |
| 3017 | extern void ___kmp_free( void * ptr KMP_SRC_LOC_DECL ); |
| 3018 | #define __kmp_allocate( size ) ___kmp_allocate( (size) KMP_SRC_LOC_CURR ) |
| 3019 | #define __kmp_page_allocate( size ) ___kmp_page_allocate( (size) KMP_SRC_LOC_CURR ) |
| 3020 | #define __kmp_free( ptr ) ___kmp_free( (ptr) KMP_SRC_LOC_CURR ) |
| 3021 | |
| 3022 | #if USE_FAST_MEMORY |
| 3023 | extern void * ___kmp_fast_allocate( kmp_info_t *this_thr, size_t size KMP_SRC_LOC_DECL ); |
| 3024 | extern void ___kmp_fast_free( kmp_info_t *this_thr, void *ptr KMP_SRC_LOC_DECL ); |
| 3025 | extern void __kmp_free_fast_memory( kmp_info_t *this_thr ); |
| 3026 | extern void __kmp_initialize_fast_memory( kmp_info_t *this_thr ); |
| 3027 | #define __kmp_fast_allocate( this_thr, size ) ___kmp_fast_allocate( (this_thr), (size) KMP_SRC_LOC_CURR ) |
| 3028 | #define __kmp_fast_free( this_thr, ptr ) ___kmp_fast_free( (this_thr), (ptr) KMP_SRC_LOC_CURR ) |
| 3029 | #endif |
| 3030 | |
| 3031 | extern void * ___kmp_thread_malloc( kmp_info_t *th, size_t size KMP_SRC_LOC_DECL ); |
| 3032 | extern void * ___kmp_thread_calloc( kmp_info_t *th, size_t nelem, size_t elsize KMP_SRC_LOC_DECL ); |
| 3033 | extern void * ___kmp_thread_realloc( kmp_info_t *th, void *ptr, size_t size KMP_SRC_LOC_DECL ); |
| 3034 | extern void ___kmp_thread_free( kmp_info_t *th, void *ptr KMP_SRC_LOC_DECL ); |
| 3035 | #define __kmp_thread_malloc( th, size ) ___kmp_thread_malloc( (th), (size) KMP_SRC_LOC_CURR ) |
| 3036 | #define __kmp_thread_calloc( th, nelem, elsize ) ___kmp_thread_calloc( (th), (nelem), (elsize) KMP_SRC_LOC_CURR ) |
| 3037 | #define __kmp_thread_realloc( th, ptr, size ) ___kmp_thread_realloc( (th), (ptr), (size) KMP_SRC_LOC_CURR ) |
| 3038 | #define __kmp_thread_free( th, ptr ) ___kmp_thread_free( (th), (ptr) KMP_SRC_LOC_CURR ) |
| 3039 | |
| 3040 | #define KMP_INTERNAL_MALLOC(sz) malloc(sz) |
| 3041 | #define KMP_INTERNAL_FREE(p) free(p) |
| 3042 | #define KMP_INTERNAL_REALLOC(p,sz) realloc((p),(sz)) |
| 3043 | #define KMP_INTERNAL_CALLOC(n,sz) calloc((n),(sz)) |
| 3044 | |
| 3045 | extern void __kmp_push_num_threads( ident_t *loc, int gtid, int num_threads ); |
| 3046 | |
| 3047 | #if OMP_40_ENABLED |
| 3048 | extern void __kmp_push_proc_bind( ident_t *loc, int gtid, kmp_proc_bind_t proc_bind ); |
| 3049 | extern void __kmp_push_num_teams( ident_t *loc, int gtid, int num_teams, int num_threads ); |
| 3050 | #endif |
| 3051 | |
| 3052 | extern void __kmp_yield( int cond ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3053 | |
| 3054 | extern void __kmpc_dispatch_init_4( ident_t *loc, kmp_int32 gtid, |
| 3055 | enum sched_type schedule, kmp_int32 lb, kmp_int32 ub, kmp_int32 st, |
| 3056 | kmp_int32 chunk ); |
| 3057 | extern void __kmpc_dispatch_init_4u( ident_t *loc, kmp_int32 gtid, |
| 3058 | enum sched_type schedule, kmp_uint32 lb, kmp_uint32 ub, kmp_int32 st, |
| 3059 | kmp_int32 chunk ); |
| 3060 | extern void __kmpc_dispatch_init_8( ident_t *loc, kmp_int32 gtid, |
| 3061 | enum sched_type schedule, kmp_int64 lb, kmp_int64 ub, kmp_int64 st, |
| 3062 | kmp_int64 chunk ); |
| 3063 | extern void __kmpc_dispatch_init_8u( ident_t *loc, kmp_int32 gtid, |
| 3064 | enum sched_type schedule, kmp_uint64 lb, kmp_uint64 ub, kmp_int64 st, |
| 3065 | kmp_int64 chunk ); |
| 3066 | |
| 3067 | extern int __kmpc_dispatch_next_4( ident_t *loc, kmp_int32 gtid, |
| 3068 | kmp_int32 *p_last, kmp_int32 *p_lb, kmp_int32 *p_ub, kmp_int32 *p_st ); |
| 3069 | extern int __kmpc_dispatch_next_4u( ident_t *loc, kmp_int32 gtid, |
| 3070 | kmp_int32 *p_last, kmp_uint32 *p_lb, kmp_uint32 *p_ub, kmp_int32 *p_st ); |
| 3071 | extern int __kmpc_dispatch_next_8( ident_t *loc, kmp_int32 gtid, |
| 3072 | kmp_int32 *p_last, kmp_int64 *p_lb, kmp_int64 *p_ub, kmp_int64 *p_st ); |
| 3073 | extern int __kmpc_dispatch_next_8u( ident_t *loc, kmp_int32 gtid, |
| 3074 | kmp_int32 *p_last, kmp_uint64 *p_lb, kmp_uint64 *p_ub, kmp_int64 *p_st ); |
| 3075 | |
| 3076 | extern void __kmpc_dispatch_fini_4( ident_t *loc, kmp_int32 gtid ); |
| 3077 | extern void __kmpc_dispatch_fini_8( ident_t *loc, kmp_int32 gtid ); |
| 3078 | extern void __kmpc_dispatch_fini_4u( ident_t *loc, kmp_int32 gtid ); |
| 3079 | extern void __kmpc_dispatch_fini_8u( ident_t *loc, kmp_int32 gtid ); |
| 3080 | |
| 3081 | |
| 3082 | #ifdef KMP_GOMP_COMPAT |
| 3083 | |
| 3084 | extern void __kmp_aux_dispatch_init_4( ident_t *loc, kmp_int32 gtid, |
| 3085 | enum sched_type schedule, kmp_int32 lb, kmp_int32 ub, kmp_int32 st, |
| 3086 | kmp_int32 chunk, int push_ws ); |
| 3087 | extern void __kmp_aux_dispatch_init_4u( ident_t *loc, kmp_int32 gtid, |
| 3088 | enum sched_type schedule, kmp_uint32 lb, kmp_uint32 ub, kmp_int32 st, |
| 3089 | kmp_int32 chunk, int push_ws ); |
| 3090 | extern void __kmp_aux_dispatch_init_8( ident_t *loc, kmp_int32 gtid, |
| 3091 | enum sched_type schedule, kmp_int64 lb, kmp_int64 ub, kmp_int64 st, |
| 3092 | kmp_int64 chunk, int push_ws ); |
| 3093 | extern void __kmp_aux_dispatch_init_8u( ident_t *loc, kmp_int32 gtid, |
| 3094 | enum sched_type schedule, kmp_uint64 lb, kmp_uint64 ub, kmp_int64 st, |
| 3095 | kmp_int64 chunk, int push_ws ); |
| 3096 | extern void __kmp_aux_dispatch_fini_chunk_4( ident_t *loc, kmp_int32 gtid ); |
| 3097 | extern void __kmp_aux_dispatch_fini_chunk_8( ident_t *loc, kmp_int32 gtid ); |
| 3098 | extern void __kmp_aux_dispatch_fini_chunk_4u( ident_t *loc, kmp_int32 gtid ); |
| 3099 | extern void __kmp_aux_dispatch_fini_chunk_8u( ident_t *loc, kmp_int32 gtid ); |
| 3100 | |
| 3101 | #endif /* KMP_GOMP_COMPAT */ |
| 3102 | |
| 3103 | |
| 3104 | extern kmp_uint32 __kmp_eq_4( kmp_uint32 value, kmp_uint32 checker ); |
| 3105 | extern kmp_uint32 __kmp_neq_4( kmp_uint32 value, kmp_uint32 checker ); |
| 3106 | extern kmp_uint32 __kmp_lt_4( kmp_uint32 value, kmp_uint32 checker ); |
| 3107 | extern kmp_uint32 __kmp_ge_4( kmp_uint32 value, kmp_uint32 checker ); |
| 3108 | extern kmp_uint32 __kmp_le_4( kmp_uint32 value, kmp_uint32 checker ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3109 | extern kmp_uint32 __kmp_wait_yield_4( kmp_uint32 volatile * spinner, kmp_uint32 checker, kmp_uint32 (*pred) (kmp_uint32, kmp_uint32), void * obj ); |
| Paul Osmialowski | f7cc6af | 2016-05-31 20:20:32 +0000 | [diff] [blame] | 3110 | extern void __kmp_wait_yield_4_ptr( void * spinner, kmp_uint32 checker, kmp_uint32 (* pred)( void *, kmp_uint32 ), void * obj ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3111 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3112 | class kmp_flag_32; |
| 3113 | class kmp_flag_64; |
| 3114 | class kmp_flag_oncore; |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3115 | extern void __kmp_wait_64(kmp_info_t *this_thr, kmp_flag_64 *flag, int final_spin |
| 3116 | #if USE_ITT_BUILD |
| 3117 | , void * itt_sync_obj |
| 3118 | #endif |
| 3119 | ); |
| 3120 | extern void __kmp_release_64(kmp_flag_64 *flag); |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3121 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3122 | extern void __kmp_infinite_loop( void ); |
| 3123 | |
| 3124 | extern void __kmp_cleanup( void ); |
| 3125 | |
| 3126 | #if KMP_HANDLE_SIGNALS |
| 3127 | extern int __kmp_handle_signals; |
| 3128 | extern void __kmp_install_signals( int parallel_init ); |
| 3129 | extern void __kmp_remove_signals( void ); |
| 3130 | #endif |
| 3131 | |
| 3132 | extern void __kmp_clear_system_time( void ); |
| 3133 | extern void __kmp_read_system_time( double *delta ); |
| 3134 | |
| 3135 | extern void __kmp_check_stack_overlap( kmp_info_t *thr ); |
| 3136 | |
| 3137 | extern void __kmp_expand_host_name( char *buffer, size_t size ); |
| 3138 | extern void __kmp_expand_file_name( char *result, size_t rlen, char *pattern ); |
| 3139 | |
| 3140 | #if KMP_OS_WINDOWS |
| 3141 | extern void __kmp_initialize_system_tick( void ); /* Initialize timer tick value */ |
| 3142 | #endif |
| 3143 | |
| 3144 | extern void __kmp_runtime_initialize( void ); /* machine specific initialization */ |
| 3145 | extern void __kmp_runtime_destroy( void ); |
| 3146 | |
| Alp Toker | 763b939 | 2014-02-28 09:42:41 +0000 | [diff] [blame] | 3147 | #if KMP_AFFINITY_SUPPORTED |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3148 | extern char *__kmp_affinity_print_mask(char *buf, int buf_len, kmp_affin_mask_t *mask); |
| 3149 | extern void __kmp_affinity_initialize(void); |
| 3150 | extern void __kmp_affinity_uninitialize(void); |
| 3151 | extern void __kmp_affinity_set_init_mask(int gtid, int isa_root); /* set affinity according to KMP_AFFINITY */ |
| 3152 | #if OMP_40_ENABLED |
| 3153 | extern void __kmp_affinity_set_place(int gtid); |
| 3154 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3155 | extern void __kmp_affinity_determine_capable( const char *env_var ); |
| 3156 | extern int __kmp_aux_set_affinity(void **mask); |
| 3157 | extern int __kmp_aux_get_affinity(void **mask); |
| 3158 | extern int __kmp_aux_set_affinity_mask_proc(int proc, void **mask); |
| 3159 | extern int __kmp_aux_unset_affinity_mask_proc(int proc, void **mask); |
| 3160 | extern int __kmp_aux_get_affinity_mask_proc(int proc, void **mask); |
| 3161 | extern void __kmp_balanced_affinity( int tid, int team_size ); |
| Alp Toker | 763b939 | 2014-02-28 09:42:41 +0000 | [diff] [blame] | 3162 | #endif /* KMP_AFFINITY_SUPPORTED */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3163 | |
| Jonathan Peyton | 1707836 | 2015-09-10 19:22:07 +0000 | [diff] [blame] | 3164 | extern void __kmp_cleanup_hierarchy(); |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3165 | extern void __kmp_get_hierarchy(kmp_uint32 nproc, kmp_bstate_t *thr_bar); |
| 3166 | |
| Paul Osmialowski | fb043fd | 2016-05-16 09:44:11 +0000 | [diff] [blame] | 3167 | #if KMP_USE_FUTEX |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3168 | |
| 3169 | extern int __kmp_futex_determine_capable( void ); |
| 3170 | |
| Paul Osmialowski | fb043fd | 2016-05-16 09:44:11 +0000 | [diff] [blame] | 3171 | #endif // KMP_USE_FUTEX |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3172 | |
| 3173 | extern void __kmp_gtid_set_specific( int gtid ); |
| 3174 | extern int __kmp_gtid_get_specific( void ); |
| 3175 | |
| 3176 | extern double __kmp_read_cpu_time( void ); |
| 3177 | |
| 3178 | extern int __kmp_read_system_info( struct kmp_sys_info *info ); |
| 3179 | |
| 3180 | extern void __kmp_create_monitor( kmp_info_t *th ); |
| 3181 | |
| 3182 | extern void *__kmp_launch_thread( kmp_info_t *thr ); |
| 3183 | |
| 3184 | extern void __kmp_create_worker( int gtid, kmp_info_t *th, size_t stack_size ); |
| 3185 | |
| 3186 | #if KMP_OS_WINDOWS |
| 3187 | extern int __kmp_still_running(kmp_info_t *th); |
| 3188 | extern int __kmp_is_thread_alive( kmp_info_t * th, DWORD *exit_val ); |
| 3189 | extern void __kmp_free_handle( kmp_thread_t tHandle ); |
| 3190 | #endif |
| 3191 | |
| 3192 | extern void __kmp_reap_monitor( kmp_info_t *th ); |
| 3193 | extern void __kmp_reap_worker( kmp_info_t *th ); |
| 3194 | extern void __kmp_terminate_thread( int gtid ); |
| 3195 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3196 | extern void __kmp_suspend_32( int th_gtid, kmp_flag_32 *flag ); |
| 3197 | extern void __kmp_suspend_64( int th_gtid, kmp_flag_64 *flag ); |
| 3198 | extern void __kmp_suspend_oncore( int th_gtid, kmp_flag_oncore *flag ); |
| 3199 | extern void __kmp_resume_32( int target_gtid, kmp_flag_32 *flag ); |
| 3200 | extern void __kmp_resume_64( int target_gtid, kmp_flag_64 *flag ); |
| 3201 | extern void __kmp_resume_oncore( int target_gtid, kmp_flag_oncore *flag ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3202 | |
| 3203 | extern void __kmp_elapsed( double * ); |
| 3204 | extern void __kmp_elapsed_tick( double * ); |
| 3205 | |
| 3206 | extern void __kmp_enable( int old_state ); |
| 3207 | extern void __kmp_disable( int *old_state ); |
| 3208 | |
| 3209 | extern void __kmp_thread_sleep( int millis ); |
| 3210 | |
| 3211 | extern void __kmp_common_initialize( void ); |
| 3212 | extern void __kmp_common_destroy( void ); |
| 3213 | extern void __kmp_common_destroy_gtid( int gtid ); |
| 3214 | |
| 3215 | #if KMP_OS_UNIX |
| 3216 | extern void __kmp_register_atfork( void ); |
| 3217 | #endif |
| 3218 | extern void __kmp_suspend_initialize( void ); |
| 3219 | extern void __kmp_suspend_uninitialize_thread( kmp_info_t *th ); |
| 3220 | |
| 3221 | extern kmp_info_t * __kmp_allocate_thread( kmp_root_t *root, |
| 3222 | kmp_team_t *team, int tid); |
| 3223 | #if OMP_40_ENABLED |
| 3224 | extern kmp_team_t * __kmp_allocate_team( kmp_root_t *root, int new_nproc, int max_nproc, |
| Andrey Churbanov | d7d088f | 2015-04-29 16:42:24 +0000 | [diff] [blame] | 3225 | #if OMPT_SUPPORT |
| 3226 | ompt_parallel_id_t ompt_parallel_id, |
| 3227 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3228 | kmp_proc_bind_t proc_bind, |
| 3229 | kmp_internal_control_t *new_icvs, |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3230 | int argc USE_NESTED_HOT_ARG(kmp_info_t *thr) ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3231 | #else |
| 3232 | extern kmp_team_t * __kmp_allocate_team( kmp_root_t *root, int new_nproc, int max_nproc, |
| Andrey Churbanov | d7d088f | 2015-04-29 16:42:24 +0000 | [diff] [blame] | 3233 | #if OMPT_SUPPORT |
| 3234 | ompt_parallel_id_t ompt_parallel_id, |
| 3235 | #endif |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3236 | kmp_internal_control_t *new_icvs, |
| 3237 | int argc USE_NESTED_HOT_ARG(kmp_info_t *thr) ); |
| 3238 | #endif // OMP_40_ENABLED |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3239 | extern void __kmp_free_thread( kmp_info_t * ); |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3240 | extern void __kmp_free_team( kmp_root_t *, kmp_team_t * USE_NESTED_HOT_ARG(kmp_info_t *) ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3241 | extern kmp_team_t * __kmp_reap_team( kmp_team_t * ); |
| 3242 | |
| 3243 | /* ------------------------------------------------------------------------ */ |
| 3244 | |
| 3245 | extern void __kmp_initialize_bget( kmp_info_t *th ); |
| 3246 | extern void __kmp_finalize_bget( kmp_info_t *th ); |
| 3247 | |
| 3248 | KMP_EXPORT void *kmpc_malloc( size_t size ); |
| Jonathan Peyton | f83ae31 | 2016-05-12 22:00:37 +0000 | [diff] [blame] | 3249 | KMP_EXPORT void *kmpc_aligned_malloc( size_t size, size_t alignment ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3250 | KMP_EXPORT void *kmpc_calloc( size_t nelem, size_t elsize ); |
| 3251 | KMP_EXPORT void *kmpc_realloc( void *ptr, size_t size ); |
| 3252 | KMP_EXPORT void kmpc_free( void *ptr ); |
| 3253 | |
| 3254 | /* ------------------------------------------------------------------------ */ |
| 3255 | /* declarations for internal use */ |
| 3256 | |
| 3257 | extern int __kmp_barrier( enum barrier_type bt, int gtid, int is_split, |
| 3258 | size_t reduce_size, void *reduce_data, void (*reduce)(void *, void *) ); |
| 3259 | extern void __kmp_end_split_barrier ( enum barrier_type bt, int gtid ); |
| 3260 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3261 | /*! |
| 3262 | * Tell the fork call which compiler generated the fork call, and therefore how to deal with the call. |
| 3263 | */ |
| 3264 | enum fork_context_e |
| 3265 | { |
| 3266 | fork_context_gnu, /**< Called from GNU generated code, so must not invoke the microtask internally. */ |
| 3267 | fork_context_intel, /**< Called from Intel generated code. */ |
| 3268 | fork_context_last |
| 3269 | }; |
| 3270 | extern int __kmp_fork_call( ident_t *loc, int gtid, enum fork_context_e fork_context, |
| Andrey Churbanov | d7d088f | 2015-04-29 16:42:24 +0000 | [diff] [blame] | 3271 | kmp_int32 argc, |
| 3272 | #if OMPT_SUPPORT |
| 3273 | void *unwrapped_task, |
| 3274 | #endif |
| 3275 | microtask_t microtask, launch_t invoker, |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3276 | /* TODO: revert workaround for Intel(R) 64 tracker #96 */ |
| Andrey Churbanov | cbda868 | 2015-01-13 14:43:35 +0000 | [diff] [blame] | 3277 | #if (KMP_ARCH_ARM || KMP_ARCH_X86_64 || KMP_ARCH_AARCH64) && KMP_OS_LINUX |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3278 | va_list *ap |
| 3279 | #else |
| 3280 | va_list ap |
| 3281 | #endif |
| 3282 | ); |
| 3283 | |
| Jonathan Peyton | f89fbbb | 2015-08-31 18:15:00 +0000 | [diff] [blame] | 3284 | extern void __kmp_join_call( ident_t *loc, int gtid |
| 3285 | #if OMPT_SUPPORT |
| 3286 | , enum fork_context_e fork_context |
| 3287 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3288 | #if OMP_40_ENABLED |
| 3289 | , int exit_teams = 0 |
| 3290 | #endif |
| 3291 | ); |
| 3292 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3293 | extern void __kmp_serialized_parallel(ident_t *id, kmp_int32 gtid); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3294 | extern void __kmp_internal_fork( ident_t *id, int gtid, kmp_team_t *team ); |
| 3295 | extern void __kmp_internal_join( ident_t *id, int gtid, kmp_team_t *team ); |
| 3296 | extern int __kmp_invoke_task_func( int gtid ); |
| 3297 | extern void __kmp_run_before_invoked_task( int gtid, int tid, kmp_info_t *this_thr, kmp_team_t *team ); |
| 3298 | extern void __kmp_run_after_invoked_task( int gtid, int tid, kmp_info_t *this_thr, kmp_team_t *team ); |
| 3299 | |
| 3300 | // should never have been exported |
| 3301 | KMP_EXPORT int __kmpc_invoke_task_func( int gtid ); |
| 3302 | #if OMP_40_ENABLED |
| 3303 | extern int __kmp_invoke_teams_master( int gtid ); |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3304 | extern void __kmp_teams_master( int gtid ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3305 | #endif |
| 3306 | extern void __kmp_save_internal_controls( kmp_info_t * thread ); |
| 3307 | extern void __kmp_user_set_library (enum library_type arg); |
| 3308 | extern void __kmp_aux_set_library (enum library_type arg); |
| 3309 | extern void __kmp_aux_set_stacksize( size_t arg); |
| 3310 | extern void __kmp_aux_set_blocktime (int arg, kmp_info_t *thread, int tid); |
| 3311 | extern void __kmp_aux_set_defaults( char const * str, int len ); |
| 3312 | |
| 3313 | /* Functions below put here to call them from __kmp_aux_env_initialize() in kmp_settings.c */ |
| 3314 | void kmpc_set_blocktime (int arg); |
| 3315 | void ompc_set_nested( int flag ); |
| 3316 | void ompc_set_dynamic( int flag ); |
| 3317 | void ompc_set_num_threads( int arg ); |
| 3318 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3319 | extern void __kmp_push_current_task_to_thread( kmp_info_t *this_thr, |
| 3320 | kmp_team_t *team, int tid ); |
| 3321 | extern void __kmp_pop_current_task_from_thread( kmp_info_t *this_thr ); |
| 3322 | extern kmp_task_t* __kmp_task_alloc( ident_t *loc_ref, kmp_int32 gtid, |
| 3323 | kmp_tasking_flags_t *flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 3324 | kmp_routine_entry_t task_entry ); |
| 3325 | extern void __kmp_init_implicit_task( ident_t *loc_ref, kmp_info_t *this_thr, |
| 3326 | kmp_team_t *team, int tid, int set_curr_task ); |
| 3327 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3328 | int __kmp_execute_tasks_32(kmp_info_t *thread, kmp_int32 gtid, kmp_flag_32 *flag, int final_spin, |
| 3329 | int *thread_finished, |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3330 | #if USE_ITT_BUILD |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3331 | void * itt_sync_obj, |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3332 | #endif /* USE_ITT_BUILD */ |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3333 | kmp_int32 is_constrained); |
| 3334 | int __kmp_execute_tasks_64(kmp_info_t *thread, kmp_int32 gtid, kmp_flag_64 *flag, int final_spin, |
| 3335 | int *thread_finished, |
| 3336 | #if USE_ITT_BUILD |
| 3337 | void * itt_sync_obj, |
| 3338 | #endif /* USE_ITT_BUILD */ |
| 3339 | kmp_int32 is_constrained); |
| 3340 | int __kmp_execute_tasks_oncore(kmp_info_t *thread, kmp_int32 gtid, kmp_flag_oncore *flag, int final_spin, |
| 3341 | int *thread_finished, |
| 3342 | #if USE_ITT_BUILD |
| 3343 | void * itt_sync_obj, |
| 3344 | #endif /* USE_ITT_BUILD */ |
| 3345 | kmp_int32 is_constrained); |
| 3346 | |
| Jonathan Peyton | 5412798 | 2015-11-04 21:37:48 +0000 | [diff] [blame] | 3347 | extern void __kmp_free_task_team( kmp_info_t *thread, kmp_task_team_t *task_team ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3348 | extern void __kmp_reap_task_teams( void ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3349 | extern void __kmp_wait_to_unref_task_teams( void ); |
| Jonathan Peyton | 5412798 | 2015-11-04 21:37:48 +0000 | [diff] [blame] | 3350 | extern void __kmp_task_team_setup ( kmp_info_t *this_thr, kmp_team_t *team, int always ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3351 | extern void __kmp_task_team_sync ( kmp_info_t *this_thr, kmp_team_t *team ); |
| 3352 | extern void __kmp_task_team_wait ( kmp_info_t *this_thr, kmp_team_t *team |
| 3353 | #if USE_ITT_BUILD |
| 3354 | , void * itt_sync_obj |
| 3355 | #endif /* USE_ITT_BUILD */ |
| Jonathan Peyton | 5412798 | 2015-11-04 21:37:48 +0000 | [diff] [blame] | 3356 | , int wait=1 |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3357 | ); |
| 3358 | extern void __kmp_tasking_barrier( kmp_team_t *team, kmp_info_t *thread, int gtid ); |
| 3359 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3360 | extern int __kmp_is_address_mapped( void *addr ); |
| 3361 | extern kmp_uint64 __kmp_hardware_timestamp(void); |
| 3362 | |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 3363 | #if KMP_OS_UNIX |
| 3364 | extern int __kmp_read_from_file( char const *path, char const *format, ... ); |
| 3365 | #endif |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3366 | |
| 3367 | /* ------------------------------------------------------------------------ */ |
| 3368 | // |
| 3369 | // Assembly routines that have no compiler intrinsic replacement |
| 3370 | // |
| 3371 | |
| 3372 | #if KMP_ARCH_X86 || KMP_ARCH_X86_64 |
| 3373 | |
| 3374 | extern void __kmp_query_cpuid( kmp_cpuinfo_t *p ); |
| 3375 | |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 3376 | #define __kmp_load_mxcsr(p) _mm_setcsr(*(p)) |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3377 | static inline void __kmp_store_mxcsr( kmp_uint32 *p ) { *p = _mm_getcsr(); } |
| 3378 | |
| 3379 | extern void __kmp_load_x87_fpu_control_word( kmp_int16 *p ); |
| 3380 | extern void __kmp_store_x87_fpu_control_word( kmp_int16 *p ); |
| 3381 | extern void __kmp_clear_x87_fpu_status_word(); |
| 3382 | # define KMP_X86_MXCSR_MASK 0xffffffc0 /* ignore status flags (6 lsb) */ |
| 3383 | |
| 3384 | #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */ |
| 3385 | |
| Andrey Churbanov | d7d088f | 2015-04-29 16:42:24 +0000 | [diff] [blame] | 3386 | extern int __kmp_invoke_microtask( microtask_t pkfn, int gtid, int npr, int argc, void *argv[] |
| 3387 | #if OMPT_SUPPORT |
| 3388 | , void **exit_frame_ptr |
| 3389 | #endif |
| 3390 | ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3391 | |
| 3392 | |
| 3393 | /* ------------------------------------------------------------------------ */ |
| 3394 | |
| 3395 | KMP_EXPORT void __kmpc_begin ( ident_t *, kmp_int32 flags ); |
| 3396 | KMP_EXPORT void __kmpc_end ( ident_t * ); |
| 3397 | |
| 3398 | KMP_EXPORT void __kmpc_threadprivate_register_vec ( ident_t *, void * data, kmpc_ctor_vec ctor, |
| 3399 | kmpc_cctor_vec cctor, kmpc_dtor_vec dtor, size_t vector_length ); |
| 3400 | KMP_EXPORT void __kmpc_threadprivate_register ( ident_t *, void * data, kmpc_ctor ctor, kmpc_cctor cctor, kmpc_dtor dtor ); |
| 3401 | KMP_EXPORT void * __kmpc_threadprivate ( ident_t *, kmp_int32 global_tid, void * data, size_t size ); |
| 3402 | |
| 3403 | KMP_EXPORT kmp_int32 __kmpc_global_thread_num ( ident_t * ); |
| 3404 | KMP_EXPORT kmp_int32 __kmpc_global_num_threads ( ident_t * ); |
| 3405 | KMP_EXPORT kmp_int32 __kmpc_bound_thread_num ( ident_t * ); |
| 3406 | KMP_EXPORT kmp_int32 __kmpc_bound_num_threads ( ident_t * ); |
| 3407 | |
| 3408 | KMP_EXPORT kmp_int32 __kmpc_ok_to_fork ( ident_t * ); |
| 3409 | KMP_EXPORT void __kmpc_fork_call ( ident_t *, kmp_int32 nargs, kmpc_micro microtask, ... ); |
| 3410 | |
| 3411 | KMP_EXPORT void __kmpc_serialized_parallel ( ident_t *, kmp_int32 global_tid ); |
| 3412 | KMP_EXPORT void __kmpc_end_serialized_parallel ( ident_t *, kmp_int32 global_tid ); |
| 3413 | |
| Andrey Churbanov | 723a6b6 | 2015-02-20 18:09:27 +0000 | [diff] [blame] | 3414 | KMP_EXPORT void __kmpc_flush ( ident_t *); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3415 | KMP_EXPORT void __kmpc_barrier ( ident_t *, kmp_int32 global_tid ); |
| 3416 | KMP_EXPORT kmp_int32 __kmpc_master ( ident_t *, kmp_int32 global_tid ); |
| 3417 | KMP_EXPORT void __kmpc_end_master ( ident_t *, kmp_int32 global_tid ); |
| 3418 | KMP_EXPORT void __kmpc_ordered ( ident_t *, kmp_int32 global_tid ); |
| 3419 | KMP_EXPORT void __kmpc_end_ordered ( ident_t *, kmp_int32 global_tid ); |
| 3420 | KMP_EXPORT void __kmpc_critical ( ident_t *, kmp_int32 global_tid, kmp_critical_name * ); |
| 3421 | KMP_EXPORT void __kmpc_end_critical ( ident_t *, kmp_int32 global_tid, kmp_critical_name * ); |
| 3422 | |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 3423 | #if OMP_45_ENABLED |
| Jonathan Peyton | b87b581 | 2015-12-11 22:04:05 +0000 | [diff] [blame] | 3424 | KMP_EXPORT void __kmpc_critical_with_hint ( ident_t *, kmp_int32 global_tid, kmp_critical_name *, uintptr_t hint ); |
| 3425 | #endif |
| 3426 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3427 | KMP_EXPORT kmp_int32 __kmpc_barrier_master ( ident_t *, kmp_int32 global_tid ); |
| 3428 | KMP_EXPORT void __kmpc_end_barrier_master ( ident_t *, kmp_int32 global_tid ); |
| 3429 | |
| 3430 | KMP_EXPORT kmp_int32 __kmpc_barrier_master_nowait ( ident_t *, kmp_int32 global_tid ); |
| 3431 | |
| 3432 | KMP_EXPORT kmp_int32 __kmpc_single ( ident_t *, kmp_int32 global_tid ); |
| 3433 | KMP_EXPORT void __kmpc_end_single ( ident_t *, kmp_int32 global_tid ); |
| 3434 | |
| 3435 | KMP_EXPORT void KMPC_FOR_STATIC_INIT ( ident_t *loc, kmp_int32 global_tid, kmp_int32 schedtype, kmp_int32 *plastiter, |
| 3436 | kmp_int *plower, kmp_int *pupper, kmp_int *pstride, kmp_int incr, kmp_int chunk ); |
| 3437 | |
| 3438 | KMP_EXPORT void __kmpc_for_static_fini ( ident_t *loc, kmp_int32 global_tid ); |
| 3439 | |
| 3440 | KMP_EXPORT void __kmpc_copyprivate( ident_t *loc, kmp_int32 global_tid, size_t cpy_size, void *cpy_data, void(*cpy_func)(void*,void*), kmp_int32 didit ); |
| 3441 | |
| 3442 | extern void KMPC_SET_NUM_THREADS ( int arg ); |
| 3443 | extern void KMPC_SET_DYNAMIC ( int flag ); |
| 3444 | extern void KMPC_SET_NESTED ( int flag ); |
| 3445 | |
| 3446 | /* --------------------------------------------------------------------------- */ |
| 3447 | |
| 3448 | /* |
| 3449 | * Taskq interface routines |
| 3450 | */ |
| 3451 | |
| 3452 | KMP_EXPORT kmpc_thunk_t * __kmpc_taskq (ident_t *loc, kmp_int32 global_tid, kmpc_task_t taskq_task, size_t sizeof_thunk, |
| 3453 | size_t sizeof_shareds, kmp_int32 flags, kmpc_shared_vars_t **shareds); |
| 3454 | KMP_EXPORT void __kmpc_end_taskq (ident_t *loc, kmp_int32 global_tid, kmpc_thunk_t *thunk); |
| 3455 | KMP_EXPORT kmp_int32 __kmpc_task (ident_t *loc, kmp_int32 global_tid, kmpc_thunk_t *thunk); |
| 3456 | KMP_EXPORT void __kmpc_taskq_task (ident_t *loc, kmp_int32 global_tid, kmpc_thunk_t *thunk, kmp_int32 status); |
| 3457 | KMP_EXPORT void __kmpc_end_taskq_task (ident_t *loc, kmp_int32 global_tid, kmpc_thunk_t *thunk); |
| 3458 | KMP_EXPORT kmpc_thunk_t * __kmpc_task_buffer (ident_t *loc, kmp_int32 global_tid, kmpc_thunk_t *taskq_thunk, kmpc_task_t task); |
| 3459 | |
| 3460 | /* ------------------------------------------------------------------------ */ |
| 3461 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3462 | /* |
| 3463 | * OMP 3.0 tasking interface routines |
| 3464 | */ |
| 3465 | |
| 3466 | KMP_EXPORT kmp_int32 |
| 3467 | __kmpc_omp_task( ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * new_task ); |
| 3468 | KMP_EXPORT kmp_task_t* |
| 3469 | __kmpc_omp_task_alloc( ident_t *loc_ref, kmp_int32 gtid, kmp_int32 flags, |
| 3470 | size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 3471 | kmp_routine_entry_t task_entry ); |
| 3472 | KMP_EXPORT void |
| 3473 | __kmpc_omp_task_begin_if0( ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * task ); |
| 3474 | KMP_EXPORT void |
| 3475 | __kmpc_omp_task_complete_if0( ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *task ); |
| 3476 | KMP_EXPORT kmp_int32 |
| 3477 | __kmpc_omp_task_parts( ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * new_task ); |
| 3478 | KMP_EXPORT kmp_int32 |
| 3479 | __kmpc_omp_taskwait( ident_t *loc_ref, kmp_int32 gtid ); |
| 3480 | |
| 3481 | KMP_EXPORT kmp_int32 |
| 3482 | __kmpc_omp_taskyield( ident_t *loc_ref, kmp_int32 gtid, int end_part ); |
| 3483 | |
| 3484 | #if TASK_UNUSED |
| 3485 | void __kmpc_omp_task_begin( ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * task ); |
| 3486 | void __kmpc_omp_task_complete( ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *task ); |
| 3487 | #endif // TASK_UNUSED |
| 3488 | |
| 3489 | /* ------------------------------------------------------------------------ */ |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3490 | |
| 3491 | #if OMP_40_ENABLED |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3492 | |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 3493 | KMP_EXPORT void __kmpc_taskgroup( ident_t * loc, int gtid ); |
| 3494 | KMP_EXPORT void __kmpc_end_taskgroup( ident_t * loc, int gtid ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3495 | |
| 3496 | KMP_EXPORT kmp_int32 __kmpc_omp_task_with_deps ( ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * new_task, |
| 3497 | kmp_int32 ndeps, kmp_depend_info_t *dep_list, |
| 3498 | kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list ); |
| 3499 | KMP_EXPORT void __kmpc_omp_wait_deps ( ident_t *loc_ref, kmp_int32 gtid, kmp_int32 ndeps, kmp_depend_info_t *dep_list, |
| 3500 | kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list ); |
| 3501 | extern void __kmp_release_deps ( kmp_int32 gtid, kmp_taskdata_t *task ); |
| 3502 | |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3503 | extern kmp_int32 __kmp_omp_task( kmp_int32 gtid, kmp_task_t * new_task, bool serialize_immediate ); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3504 | |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 3505 | KMP_EXPORT kmp_int32 __kmpc_cancel(ident_t* loc_ref, kmp_int32 gtid, kmp_int32 cncl_kind); |
| 3506 | KMP_EXPORT kmp_int32 __kmpc_cancellationpoint(ident_t* loc_ref, kmp_int32 gtid, kmp_int32 cncl_kind); |
| 3507 | KMP_EXPORT kmp_int32 __kmpc_cancel_barrier(ident_t* loc_ref, kmp_int32 gtid); |
| 3508 | KMP_EXPORT int __kmp_get_cancellation_status(int cancel_kind); |
| Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 3509 | |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 3510 | #if OMP_45_ENABLED |
| Andrey Churbanov | 535b6fa | 2015-05-07 17:41:51 +0000 | [diff] [blame] | 3511 | |
| 3512 | KMP_EXPORT void __kmpc_proxy_task_completed( kmp_int32 gtid, kmp_task_t *ptask ); |
| 3513 | KMP_EXPORT void __kmpc_proxy_task_completed_ooo ( kmp_task_t *ptask ); |
| Jonathan Peyton | 283a215 | 2016-03-02 22:47:51 +0000 | [diff] [blame] | 3514 | KMP_EXPORT void __kmpc_taskloop(ident_t *loc, kmp_int32 gtid, kmp_task_t *task, kmp_int32 if_val, |
| 3515 | kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, |
| 3516 | kmp_int32 nogroup, kmp_int32 sched, kmp_uint64 grainsize, void * task_dup ); |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 3517 | #endif |
| 3518 | |
| Andrey Churbanov | 535b6fa | 2015-05-07 17:41:51 +0000 | [diff] [blame] | 3519 | #endif |
| 3520 | |
| 3521 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3522 | /* |
| 3523 | * Lock interface routines (fast versions with gtid passed in) |
| 3524 | */ |
| 3525 | KMP_EXPORT void __kmpc_init_lock( ident_t *loc, kmp_int32 gtid, void **user_lock ); |
| 3526 | KMP_EXPORT void __kmpc_init_nest_lock( ident_t *loc, kmp_int32 gtid, void **user_lock ); |
| 3527 | KMP_EXPORT void __kmpc_destroy_lock( ident_t *loc, kmp_int32 gtid, void **user_lock ); |
| 3528 | KMP_EXPORT void __kmpc_destroy_nest_lock( ident_t *loc, kmp_int32 gtid, void **user_lock ); |
| 3529 | KMP_EXPORT void __kmpc_set_lock( ident_t *loc, kmp_int32 gtid, void **user_lock ); |
| 3530 | KMP_EXPORT void __kmpc_set_nest_lock( ident_t *loc, kmp_int32 gtid, void **user_lock ); |
| 3531 | KMP_EXPORT void __kmpc_unset_lock( ident_t *loc, kmp_int32 gtid, void **user_lock ); |
| 3532 | KMP_EXPORT void __kmpc_unset_nest_lock( ident_t *loc, kmp_int32 gtid, void **user_lock ); |
| 3533 | KMP_EXPORT int __kmpc_test_lock( ident_t *loc, kmp_int32 gtid, void **user_lock ); |
| 3534 | KMP_EXPORT int __kmpc_test_nest_lock( ident_t *loc, kmp_int32 gtid, void **user_lock ); |
| 3535 | |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 3536 | #if OMP_45_ENABLED |
| Jonathan Peyton | b87b581 | 2015-12-11 22:04:05 +0000 | [diff] [blame] | 3537 | KMP_EXPORT void __kmpc_init_lock_with_hint( ident_t *loc, kmp_int32 gtid, void **user_lock, uintptr_t hint ); |
| 3538 | KMP_EXPORT void __kmpc_init_nest_lock_with_hint( ident_t *loc, kmp_int32 gtid, void **user_lock, uintptr_t hint ); |
| 3539 | #endif |
| 3540 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3541 | /* ------------------------------------------------------------------------ */ |
| 3542 | |
| 3543 | /* |
| 3544 | * Interface to fast scalable reduce methods routines |
| 3545 | */ |
| 3546 | |
| 3547 | KMP_EXPORT kmp_int32 __kmpc_reduce_nowait( ident_t *loc, kmp_int32 global_tid, |
| 3548 | kmp_int32 num_vars, size_t reduce_size, |
| 3549 | void *reduce_data, void (*reduce_func)(void *lhs_data, void *rhs_data), |
| 3550 | kmp_critical_name *lck ); |
| 3551 | KMP_EXPORT void __kmpc_end_reduce_nowait( ident_t *loc, kmp_int32 global_tid, kmp_critical_name *lck ); |
| 3552 | KMP_EXPORT kmp_int32 __kmpc_reduce( ident_t *loc, kmp_int32 global_tid, |
| 3553 | kmp_int32 num_vars, size_t reduce_size, |
| 3554 | void *reduce_data, void (*reduce_func)(void *lhs_data, void *rhs_data), |
| 3555 | kmp_critical_name *lck ); |
| 3556 | KMP_EXPORT void __kmpc_end_reduce( ident_t *loc, kmp_int32 global_tid, kmp_critical_name *lck ); |
| 3557 | |
| 3558 | /* |
| 3559 | * internal fast reduction routines |
| 3560 | */ |
| 3561 | |
| 3562 | extern PACKED_REDUCTION_METHOD_T |
| 3563 | __kmp_determine_reduction_method( ident_t *loc, kmp_int32 global_tid, |
| 3564 | kmp_int32 num_vars, size_t reduce_size, |
| 3565 | void *reduce_data, void (*reduce_func)(void *lhs_data, void *rhs_data), |
| 3566 | kmp_critical_name *lck ); |
| 3567 | |
| 3568 | // this function is for testing set/get/determine reduce method |
| 3569 | KMP_EXPORT kmp_int32 __kmp_get_reduce_method( void ); |
| 3570 | |
| 3571 | KMP_EXPORT kmp_uint64 __kmpc_get_taskid(); |
| 3572 | KMP_EXPORT kmp_uint64 __kmpc_get_parent_taskid(); |
| 3573 | |
| Jonathan Peyton | dd4aa9b | 2015-10-08 17:55:54 +0000 | [diff] [blame] | 3574 | // this function exported for testing of KMP_PLACE_THREADS functionality |
| 3575 | KMP_EXPORT void __kmpc_place_threads(int,int,int,int,int); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3576 | |
| 3577 | /* ------------------------------------------------------------------------ */ |
| 3578 | /* ------------------------------------------------------------------------ */ |
| 3579 | |
| 3580 | // C++ port |
| 3581 | // missing 'extern "C"' declarations |
| 3582 | |
| 3583 | KMP_EXPORT kmp_int32 __kmpc_in_parallel( ident_t *loc ); |
| 3584 | KMP_EXPORT void __kmpc_pop_num_threads( ident_t *loc, kmp_int32 global_tid ); |
| 3585 | KMP_EXPORT void __kmpc_push_num_threads( ident_t *loc, kmp_int32 global_tid, kmp_int32 num_threads ); |
| 3586 | |
| 3587 | #if OMP_40_ENABLED |
| 3588 | KMP_EXPORT void __kmpc_push_proc_bind( ident_t *loc, kmp_int32 global_tid, int proc_bind ); |
| 3589 | KMP_EXPORT void __kmpc_push_num_teams( ident_t *loc, kmp_int32 global_tid, kmp_int32 num_teams, kmp_int32 num_threads ); |
| 3590 | KMP_EXPORT void __kmpc_fork_teams(ident_t *loc, kmp_int32 argc, kmpc_micro microtask, ...); |
| Jonathan Peyton | 71909c5 | 2016-03-02 22:42:06 +0000 | [diff] [blame] | 3591 | #endif |
| Jonathan Peyton | df6818b | 2016-06-14 17:57:47 +0000 | [diff] [blame] | 3592 | #if OMP_45_ENABLED |
| Jonathan Peyton | 71909c5 | 2016-03-02 22:42:06 +0000 | [diff] [blame] | 3593 | struct kmp_dim { // loop bounds info casted to kmp_int64 |
| 3594 | kmp_int64 lo; // lower |
| 3595 | kmp_int64 up; // upper |
| 3596 | kmp_int64 st; // stride |
| 3597 | }; |
| 3598 | KMP_EXPORT void __kmpc_doacross_init(ident_t *loc, kmp_int32 gtid, kmp_int32 num_dims, struct kmp_dim * dims); |
| 3599 | KMP_EXPORT void __kmpc_doacross_wait(ident_t *loc, kmp_int32 gtid, kmp_int64 *vec); |
| 3600 | KMP_EXPORT void __kmpc_doacross_post(ident_t *loc, kmp_int32 gtid, kmp_int64 *vec); |
| 3601 | KMP_EXPORT void __kmpc_doacross_fini(ident_t *loc, kmp_int32 gtid); |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3602 | #endif |
| 3603 | |
| 3604 | KMP_EXPORT void* |
| 3605 | __kmpc_threadprivate_cached( ident_t * loc, kmp_int32 global_tid, |
| 3606 | void * data, size_t size, void *** cache ); |
| 3607 | |
| 3608 | // Symbols for MS mutual detection. |
| 3609 | extern int _You_must_link_with_exactly_one_OpenMP_library; |
| 3610 | extern int _You_must_link_with_Intel_OpenMP_library; |
| 3611 | #if KMP_OS_WINDOWS && ( KMP_VERSION_MAJOR > 4 ) |
| 3612 | extern int _You_must_link_with_Microsoft_OpenMP_library; |
| 3613 | #endif |
| 3614 | |
| 3615 | |
| 3616 | // The routines below are not exported. |
| 3617 | // Consider making them 'static' in corresponding source files. |
| 3618 | void |
| 3619 | kmp_threadprivate_insert_private_data( int gtid, void *pc_addr, void *data_addr, size_t pc_size ); |
| 3620 | struct private_common * |
| 3621 | kmp_threadprivate_insert( int gtid, void *pc_addr, void *data_addr, size_t pc_size ); |
| 3622 | |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 3623 | // |
| 3624 | // ompc_, kmpc_ entries moved from omp.h. |
| 3625 | // |
| 3626 | #if KMP_OS_WINDOWS |
| 3627 | # define KMPC_CONVENTION __cdecl |
| 3628 | #else |
| 3629 | # define KMPC_CONVENTION |
| 3630 | #endif |
| 3631 | |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 3632 | #ifndef __OMP_H |
| 3633 | typedef enum omp_sched_t { |
| 3634 | omp_sched_static = 1, |
| 3635 | omp_sched_dynamic = 2, |
| 3636 | omp_sched_guided = 3, |
| 3637 | omp_sched_auto = 4 |
| 3638 | } omp_sched_t; |
| 3639 | typedef void * kmp_affinity_mask_t; |
| 3640 | #endif |
| 3641 | |
| 3642 | KMP_EXPORT void KMPC_CONVENTION ompc_set_max_active_levels(int); |
| 3643 | KMP_EXPORT void KMPC_CONVENTION ompc_set_schedule(omp_sched_t, int); |
| 3644 | KMP_EXPORT int KMPC_CONVENTION ompc_get_ancestor_thread_num(int); |
| 3645 | KMP_EXPORT int KMPC_CONVENTION ompc_get_team_size(int); |
| 3646 | KMP_EXPORT int KMPC_CONVENTION kmpc_set_affinity_mask_proc(int, kmp_affinity_mask_t *); |
| 3647 | KMP_EXPORT int KMPC_CONVENTION kmpc_unset_affinity_mask_proc(int, kmp_affinity_mask_t *); |
| 3648 | KMP_EXPORT int KMPC_CONVENTION kmpc_get_affinity_mask_proc(int, kmp_affinity_mask_t *); |
| 3649 | |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 3650 | KMP_EXPORT void KMPC_CONVENTION kmpc_set_stacksize(int); |
| 3651 | KMP_EXPORT void KMPC_CONVENTION kmpc_set_stacksize_s(size_t); |
| 3652 | KMP_EXPORT void KMPC_CONVENTION kmpc_set_library(int); |
| 3653 | KMP_EXPORT void KMPC_CONVENTION kmpc_set_defaults(char const *); |
| Jonathan Peyton | 067325f | 2016-05-31 19:01:15 +0000 | [diff] [blame] | 3654 | KMP_EXPORT void KMPC_CONVENTION kmpc_set_disp_num_buffers(int); |
| Jim Cownie | 181b4bb | 2013-12-23 17:28:57 +0000 | [diff] [blame] | 3655 | |
| Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3656 | #ifdef __cplusplus |
| 3657 | } |
| 3658 | #endif |
| 3659 | |
| 3660 | #endif /* KMP_H */ |
| 3661 | |