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