LLVM OpenMP* Runtime Library
kmp.h
1 
2 /*
3  * kmp.h -- KPTS runtime header file.
4  */
5 
6 //===----------------------------------------------------------------------===//
7 //
8 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9 // See https://llvm.org/LICENSE.txt for license information.
10 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef KMP_H
15 #define KMP_H
16 
17 #include "kmp_config.h"
18 
19 /* #define BUILD_PARALLEL_ORDERED 1 */
20 
21 /* This fix replaces gettimeofday with clock_gettime for better scalability on
22  the Altix. Requires user code to be linked with -lrt. */
23 //#define FIX_SGI_CLOCK
24 
25 /* Defines for OpenMP 3.0 tasking and auto scheduling */
26 
27 #ifndef KMP_STATIC_STEAL_ENABLED
28 #define KMP_STATIC_STEAL_ENABLED 1
29 #endif
30 
31 #define TASK_CURRENT_NOT_QUEUED 0
32 #define TASK_CURRENT_QUEUED 1
33 
34 #ifdef BUILD_TIED_TASK_STACK
35 #define TASK_STACK_EMPTY 0 // entries when the stack is empty
36 #define TASK_STACK_BLOCK_BITS 5 // Used in TASK_STACK_SIZE and TASK_STACK_MASK
37 // Number of entries in each task stack array
38 #define TASK_STACK_BLOCK_SIZE (1 << TASK_STACK_BLOCK_BITS)
39 // Mask for determining index into stack block
40 #define TASK_STACK_INDEX_MASK (TASK_STACK_BLOCK_SIZE - 1)
41 #endif // BUILD_TIED_TASK_STACK
42 
43 #define TASK_NOT_PUSHED 1
44 #define TASK_SUCCESSFULLY_PUSHED 0
45 #define TASK_TIED 1
46 #define TASK_UNTIED 0
47 #define TASK_EXPLICIT 1
48 #define TASK_IMPLICIT 0
49 #define TASK_PROXY 1
50 #define TASK_FULL 0
51 #define TASK_DETACHABLE 1
52 #define TASK_UNDETACHABLE 0
53 
54 #define KMP_CANCEL_THREADS
55 #define KMP_THREAD_ATTR
56 
57 // Android does not have pthread_cancel. Undefine KMP_CANCEL_THREADS if being
58 // built on Android
59 #if defined(__ANDROID__)
60 #undef KMP_CANCEL_THREADS
61 #endif
62 
63 #include <signal.h>
64 #include <stdarg.h>
65 #include <stddef.h>
66 #include <stdio.h>
67 #include <stdlib.h>
68 #include <string.h>
69 #include <limits>
70 #include <type_traits>
71 /* include <ctype.h> don't use; problems with /MD on Windows* OS NT due to bad
72  Microsoft library. Some macros provided below to replace these functions */
73 #ifndef __ABSOFT_WIN
74 #include <sys/types.h>
75 #endif
76 #include <limits.h>
77 #include <time.h>
78 
79 #include <errno.h>
80 
81 #include "kmp_os.h"
82 
83 #include "kmp_safe_c_api.h"
84 
85 #if KMP_STATS_ENABLED
86 class kmp_stats_list;
87 #endif
88 
89 #if KMP_USE_HIER_SCHED
90 // Only include hierarchical scheduling if affinity is supported
91 #undef KMP_USE_HIER_SCHED
92 #define KMP_USE_HIER_SCHED KMP_AFFINITY_SUPPORTED
93 #endif
94 
95 #if KMP_USE_HWLOC && KMP_AFFINITY_SUPPORTED
96 #include "hwloc.h"
97 #ifndef HWLOC_OBJ_NUMANODE
98 #define HWLOC_OBJ_NUMANODE HWLOC_OBJ_NODE
99 #endif
100 #ifndef HWLOC_OBJ_PACKAGE
101 #define HWLOC_OBJ_PACKAGE HWLOC_OBJ_SOCKET
102 #endif
103 #endif
104 
105 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
106 #include <xmmintrin.h>
107 #endif
108 
109 #include "kmp_debug.h"
110 #include "kmp_lock.h"
111 #include "kmp_version.h"
112 #include "kmp_barrier.h"
113 #if USE_DEBUGGER
114 #include "kmp_debugger.h"
115 #endif
116 #include "kmp_i18n.h"
117 
118 #define KMP_HANDLE_SIGNALS (KMP_OS_UNIX || KMP_OS_WINDOWS)
119 
120 #include "kmp_wrapper_malloc.h"
121 #if KMP_OS_UNIX
122 #include <unistd.h>
123 #if !defined NSIG && defined _NSIG
124 #define NSIG _NSIG
125 #endif
126 #endif
127 
128 #if KMP_OS_LINUX
129 #pragma weak clock_gettime
130 #endif
131 
132 #if OMPT_SUPPORT
133 #include "ompt-internal.h"
134 #endif
135 
136 #if OMPD_SUPPORT
137 #include "ompd-specific.h"
138 #endif
139 
140 #ifndef UNLIKELY
141 #define UNLIKELY(x) (x)
142 #endif
143 
144 // Affinity format function
145 #include "kmp_str.h"
146 
147 // 0 - no fast memory allocation, alignment: 8-byte on x86, 16-byte on x64.
148 // 3 - fast allocation using sync, non-sync free lists of any size, non-self
149 // free lists of limited size.
150 #ifndef USE_FAST_MEMORY
151 #define USE_FAST_MEMORY 3
152 #endif
153 
154 #ifndef KMP_NESTED_HOT_TEAMS
155 #define KMP_NESTED_HOT_TEAMS 0
156 #define USE_NESTED_HOT_ARG(x)
157 #else
158 #if KMP_NESTED_HOT_TEAMS
159 #define USE_NESTED_HOT_ARG(x) , x
160 #else
161 #define USE_NESTED_HOT_ARG(x)
162 #endif
163 #endif
164 
165 // Assume using BGET compare_exchange instruction instead of lock by default.
166 #ifndef USE_CMP_XCHG_FOR_BGET
167 #define USE_CMP_XCHG_FOR_BGET 1
168 #endif
169 
170 // Test to see if queuing lock is better than bootstrap lock for bget
171 // #ifndef USE_QUEUING_LOCK_FOR_BGET
172 // #define USE_QUEUING_LOCK_FOR_BGET
173 // #endif
174 
175 #define KMP_NSEC_PER_SEC 1000000000L
176 #define KMP_USEC_PER_SEC 1000000L
177 
186 enum {
191  /* 0x04 is no longer used */
200  KMP_IDENT_BARRIER_IMPL_MASK = 0x01C0,
201  KMP_IDENT_BARRIER_IMPL_FOR = 0x0040,
202  KMP_IDENT_BARRIER_IMPL_SECTIONS = 0x00C0,
203 
204  KMP_IDENT_BARRIER_IMPL_SINGLE = 0x0140,
205  KMP_IDENT_BARRIER_IMPL_WORKSHARE = 0x01C0,
206 
218  KMP_IDENT_ATOMIC_HINT_UNCONTENDED = 0x010000,
219  KMP_IDENT_ATOMIC_HINT_CONTENDED = 0x020000,
220  KMP_IDENT_ATOMIC_HINT_NONSPECULATIVE = 0x040000,
221  KMP_IDENT_ATOMIC_HINT_SPECULATIVE = 0x080000,
222  KMP_IDENT_OPENMP_SPEC_VERSION_MASK = 0xFF000000
223 };
224 
228 typedef struct ident {
229  kmp_int32 reserved_1;
230  kmp_int32 flags;
232  kmp_int32 reserved_2;
233 #if USE_ITT_BUILD
234 /* but currently used for storing region-specific ITT */
235 /* contextual information. */
236 #endif /* USE_ITT_BUILD */
237  kmp_int32 reserved_3;
238  char const *psource;
242  // Returns the OpenMP version in form major*10+minor (e.g., 50 for 5.0)
243  kmp_int32 get_openmp_version() {
244  return (((flags & KMP_IDENT_OPENMP_SPEC_VERSION_MASK) >> 24) & 0xFF);
245  }
251 // Some forward declarations.
252 typedef union kmp_team kmp_team_t;
253 typedef struct kmp_taskdata kmp_taskdata_t;
254 typedef union kmp_task_team kmp_task_team_t;
255 typedef union kmp_team kmp_team_p;
256 typedef union kmp_info kmp_info_p;
257 typedef union kmp_root kmp_root_p;
258 
259 template <bool C = false, bool S = true> class kmp_flag_32;
260 template <bool C = false, bool S = true> class kmp_flag_64;
261 template <bool C = false, bool S = true> class kmp_atomic_flag_64;
262 class kmp_flag_oncore;
263 
264 #ifdef __cplusplus
265 extern "C" {
266 #endif
267 
268 /* ------------------------------------------------------------------------ */
269 
270 /* Pack two 32-bit signed integers into a 64-bit signed integer */
271 /* ToDo: Fix word ordering for big-endian machines. */
272 #define KMP_PACK_64(HIGH_32, LOW_32) \
273  ((kmp_int64)((((kmp_uint64)(HIGH_32)) << 32) | (kmp_uint64)(LOW_32)))
274 
275 // Generic string manipulation macros. Assume that _x is of type char *
276 #define SKIP_WS(_x) \
277  { \
278  while (*(_x) == ' ' || *(_x) == '\t') \
279  (_x)++; \
280  }
281 #define SKIP_DIGITS(_x) \
282  { \
283  while (*(_x) >= '0' && *(_x) <= '9') \
284  (_x)++; \
285  }
286 #define SKIP_TOKEN(_x) \
287  { \
288  while ((*(_x) >= '0' && *(_x) <= '9') || (*(_x) >= 'a' && *(_x) <= 'z') || \
289  (*(_x) >= 'A' && *(_x) <= 'Z') || *(_x) == '_') \
290  (_x)++; \
291  }
292 #define SKIP_TO(_x, _c) \
293  { \
294  while (*(_x) != '\0' && *(_x) != (_c)) \
295  (_x)++; \
296  }
297 
298 /* ------------------------------------------------------------------------ */
299 
300 #define KMP_MAX(x, y) ((x) > (y) ? (x) : (y))
301 #define KMP_MIN(x, y) ((x) < (y) ? (x) : (y))
302 
303 /* ------------------------------------------------------------------------ */
304 /* Enumeration types */
305 
306 enum kmp_state_timer {
307  ts_stop,
308  ts_start,
309  ts_pause,
310 
311  ts_last_state
312 };
313 
314 enum dynamic_mode {
315  dynamic_default,
316 #ifdef USE_LOAD_BALANCE
317  dynamic_load_balance,
318 #endif /* USE_LOAD_BALANCE */
319  dynamic_random,
320  dynamic_thread_limit,
321  dynamic_max
322 };
323 
324 /* external schedule constants, duplicate enum omp_sched in omp.h in order to
325  * not include it here */
326 #ifndef KMP_SCHED_TYPE_DEFINED
327 #define KMP_SCHED_TYPE_DEFINED
328 typedef enum kmp_sched {
329  kmp_sched_lower = 0, // lower and upper bounds are for routine parameter check
330  // Note: need to adjust __kmp_sch_map global array in case enum is changed
331  kmp_sched_static = 1, // mapped to kmp_sch_static_chunked (33)
332  kmp_sched_dynamic = 2, // mapped to kmp_sch_dynamic_chunked (35)
333  kmp_sched_guided = 3, // mapped to kmp_sch_guided_chunked (36)
334  kmp_sched_auto = 4, // mapped to kmp_sch_auto (38)
335  kmp_sched_upper_std = 5, // upper bound for standard schedules
336  kmp_sched_lower_ext = 100, // lower bound of Intel extension schedules
337  kmp_sched_trapezoidal = 101, // mapped to kmp_sch_trapezoidal (39)
338 #if KMP_STATIC_STEAL_ENABLED
339  kmp_sched_static_steal = 102, // mapped to kmp_sch_static_steal (44)
340 #endif
341  kmp_sched_upper,
342  kmp_sched_default = kmp_sched_static, // default scheduling
343  kmp_sched_monotonic = 0x80000000
344 } kmp_sched_t;
345 #endif
346 
351 enum sched_type : kmp_int32 {
353  kmp_sch_static_chunked = 33,
355  kmp_sch_dynamic_chunked = 35,
357  kmp_sch_runtime = 37,
359  kmp_sch_trapezoidal = 39,
360 
361  /* accessible only through KMP_SCHEDULE environment variable */
362  kmp_sch_static_greedy = 40,
363  kmp_sch_static_balanced = 41,
364  /* accessible only through KMP_SCHEDULE environment variable */
365  kmp_sch_guided_iterative_chunked = 42,
366  kmp_sch_guided_analytical_chunked = 43,
367  /* accessible only through KMP_SCHEDULE environment variable */
368  kmp_sch_static_steal = 44,
369 
370  /* static with chunk adjustment (e.g., simd) */
371  kmp_sch_static_balanced_chunked = 45,
375  /* accessible only through KMP_SCHEDULE environment variable */
379  kmp_ord_static_chunked = 65,
381  kmp_ord_dynamic_chunked = 67,
382  kmp_ord_guided_chunked = 68,
383  kmp_ord_runtime = 69,
385  kmp_ord_trapezoidal = 71,
388  /* Schedules for Distribute construct */
392  /* For the "nomerge" versions, kmp_dispatch_next*() will always return a
393  single iteration/chunk, even if the loop is serialized. For the schedule
394  types listed above, the entire iteration vector is returned if the loop is
395  serialized. This doesn't work for gcc/gcomp sections. */
396  kmp_nm_lower = 160,
398  kmp_nm_static_chunked =
399  (kmp_sch_static_chunked - kmp_sch_lower + kmp_nm_lower),
401  kmp_nm_dynamic_chunked = 163,
403  kmp_nm_runtime = 165,
404  kmp_nm_auto = 166,
405  kmp_nm_trapezoidal = 167,
406 
407  /* accessible only through KMP_SCHEDULE environment variable */
408  kmp_nm_static_greedy = 168,
409  kmp_nm_static_balanced = 169,
410  /* accessible only through KMP_SCHEDULE environment variable */
411  kmp_nm_guided_iterative_chunked = 170,
412  kmp_nm_guided_analytical_chunked = 171,
413  kmp_nm_static_steal =
414  172, /* accessible only through OMP_SCHEDULE environment variable */
415 
416  kmp_nm_ord_static_chunked = 193,
418  kmp_nm_ord_dynamic_chunked = 195,
419  kmp_nm_ord_guided_chunked = 196,
420  kmp_nm_ord_runtime = 197,
422  kmp_nm_ord_trapezoidal = 199,
425  /* Support for OpenMP 4.5 monotonic and nonmonotonic schedule modifiers. Since
426  we need to distinguish the three possible cases (no modifier, monotonic
427  modifier, nonmonotonic modifier), we need separate bits for each modifier.
428  The absence of monotonic does not imply nonmonotonic, especially since 4.5
429  says that the behaviour of the "no modifier" case is implementation defined
430  in 4.5, but will become "nonmonotonic" in 5.0.
431 
432  Since we're passing a full 32 bit value, we can use a couple of high bits
433  for these flags; out of paranoia we avoid the sign bit.
434 
435  These modifiers can be or-ed into non-static schedules by the compiler to
436  pass the additional information. They will be stripped early in the
437  processing in __kmp_dispatch_init when setting up schedules, so most of the
438  code won't ever see schedules with these bits set. */
440  (1 << 29),
442  (1 << 30),
444 #define SCHEDULE_WITHOUT_MODIFIERS(s) \
445  (enum sched_type)( \
447 #define SCHEDULE_HAS_MONOTONIC(s) (((s)&kmp_sch_modifier_monotonic) != 0)
448 #define SCHEDULE_HAS_NONMONOTONIC(s) (((s)&kmp_sch_modifier_nonmonotonic) != 0)
449 #define SCHEDULE_HAS_NO_MODIFIERS(s) \
450  (((s) & (kmp_sch_modifier_nonmonotonic | kmp_sch_modifier_monotonic)) == 0)
451 #define SCHEDULE_GET_MODIFIERS(s) \
452  ((enum sched_type)( \
453  (s) & (kmp_sch_modifier_nonmonotonic | kmp_sch_modifier_monotonic)))
454 #define SCHEDULE_SET_MODIFIERS(s, m) \
455  (s = (enum sched_type)((kmp_int32)s | (kmp_int32)m))
456 #define SCHEDULE_NONMONOTONIC 0
457 #define SCHEDULE_MONOTONIC 1
458 
460 };
461 
462 // Apply modifiers on internal kind to standard kind
463 static inline void
464 __kmp_sched_apply_mods_stdkind(kmp_sched_t *kind,
465  enum sched_type internal_kind) {
466  if (SCHEDULE_HAS_MONOTONIC(internal_kind)) {
467  *kind = (kmp_sched_t)((int)*kind | (int)kmp_sched_monotonic);
468  }
469 }
470 
471 // Apply modifiers on standard kind to internal kind
472 static inline void
473 __kmp_sched_apply_mods_intkind(kmp_sched_t kind,
474  enum sched_type *internal_kind) {
475  if ((int)kind & (int)kmp_sched_monotonic) {
476  *internal_kind = (enum sched_type)((int)*internal_kind |
478  }
479 }
480 
481 // Get standard schedule without modifiers
482 static inline kmp_sched_t __kmp_sched_without_mods(kmp_sched_t kind) {
483  return (kmp_sched_t)((int)kind & ~((int)kmp_sched_monotonic));
484 }
485 
486 /* Type to keep runtime schedule set via OMP_SCHEDULE or omp_set_schedule() */
487 typedef union kmp_r_sched {
488  struct {
489  enum sched_type r_sched_type;
490  int chunk;
491  };
492  kmp_int64 sched;
493 } kmp_r_sched_t;
494 
495 extern enum sched_type __kmp_sch_map[]; // map OMP 3.0 schedule types with our
496 // internal schedule types
497 
498 enum library_type {
499  library_none,
500  library_serial,
501  library_turnaround,
502  library_throughput
503 };
504 
505 #if KMP_OS_LINUX
506 enum clock_function_type {
507  clock_function_gettimeofday,
508  clock_function_clock_gettime
509 };
510 #endif /* KMP_OS_LINUX */
511 
512 #if KMP_MIC_SUPPORTED
513 enum mic_type { non_mic, mic1, mic2, mic3, dummy };
514 #endif
515 
516 /* -- fast reduction stuff ------------------------------------------------ */
517 
518 #undef KMP_FAST_REDUCTION_BARRIER
519 #define KMP_FAST_REDUCTION_BARRIER 1
520 
521 #undef KMP_FAST_REDUCTION_CORE_DUO
522 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
523 #define KMP_FAST_REDUCTION_CORE_DUO 1
524 #endif
525 
526 enum _reduction_method {
527  reduction_method_not_defined = 0,
528  critical_reduce_block = (1 << 8),
529  atomic_reduce_block = (2 << 8),
530  tree_reduce_block = (3 << 8),
531  empty_reduce_block = (4 << 8)
532 };
533 
534 // Description of the packed_reduction_method variable:
535 // The packed_reduction_method variable consists of two enum types variables
536 // that are packed together into 0-th byte and 1-st byte:
537 // 0: (packed_reduction_method & 0x000000FF) is a 'enum barrier_type' value of
538 // barrier that will be used in fast reduction: bs_plain_barrier or
539 // bs_reduction_barrier
540 // 1: (packed_reduction_method & 0x0000FF00) is a reduction method that will
541 // be used in fast reduction;
542 // Reduction method is of 'enum _reduction_method' type and it's defined the way
543 // so that the bits of 0-th byte are empty, so no need to execute a shift
544 // instruction while packing/unpacking
545 
546 #if KMP_FAST_REDUCTION_BARRIER
547 #define PACK_REDUCTION_METHOD_AND_BARRIER(reduction_method, barrier_type) \
548  ((reduction_method) | (barrier_type))
549 
550 #define UNPACK_REDUCTION_METHOD(packed_reduction_method) \
551  ((enum _reduction_method)((packed_reduction_method) & (0x0000FF00)))
552 
553 #define UNPACK_REDUCTION_BARRIER(packed_reduction_method) \
554  ((enum barrier_type)((packed_reduction_method) & (0x000000FF)))
555 #else
556 #define PACK_REDUCTION_METHOD_AND_BARRIER(reduction_method, barrier_type) \
557  (reduction_method)
558 
559 #define UNPACK_REDUCTION_METHOD(packed_reduction_method) \
560  (packed_reduction_method)
561 
562 #define UNPACK_REDUCTION_BARRIER(packed_reduction_method) (bs_plain_barrier)
563 #endif
564 
565 #define TEST_REDUCTION_METHOD(packed_reduction_method, which_reduction_block) \
566  ((UNPACK_REDUCTION_METHOD(packed_reduction_method)) == \
567  (which_reduction_block))
568 
569 #if KMP_FAST_REDUCTION_BARRIER
570 #define TREE_REDUCE_BLOCK_WITH_REDUCTION_BARRIER \
571  (PACK_REDUCTION_METHOD_AND_BARRIER(tree_reduce_block, bs_reduction_barrier))
572 
573 #define TREE_REDUCE_BLOCK_WITH_PLAIN_BARRIER \
574  (PACK_REDUCTION_METHOD_AND_BARRIER(tree_reduce_block, bs_plain_barrier))
575 #endif
576 
577 typedef int PACKED_REDUCTION_METHOD_T;
578 
579 /* -- end of fast reduction stuff ----------------------------------------- */
580 
581 #if KMP_OS_WINDOWS
582 #define USE_CBLKDATA
583 #if KMP_MSVC_COMPAT
584 #pragma warning(push)
585 #pragma warning(disable : 271 310)
586 #endif
587 #include <windows.h>
588 #if KMP_MSVC_COMPAT
589 #pragma warning(pop)
590 #endif
591 #endif
592 
593 #if KMP_OS_UNIX
594 #include <dlfcn.h>
595 #include <pthread.h>
596 #endif
597 
598 enum kmp_hw_t : int {
599  KMP_HW_UNKNOWN = -1,
600  KMP_HW_SOCKET = 0,
601  KMP_HW_PROC_GROUP,
602  KMP_HW_NUMA,
603  KMP_HW_DIE,
604  KMP_HW_LLC,
605  KMP_HW_L3,
606  KMP_HW_TILE,
607  KMP_HW_MODULE,
608  KMP_HW_L2,
609  KMP_HW_L1,
610  KMP_HW_CORE,
611  KMP_HW_THREAD,
612  KMP_HW_LAST
613 };
614 
615 typedef enum kmp_hw_core_type_t {
616  KMP_HW_CORE_TYPE_UNKNOWN = 0x0,
617 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
618  KMP_HW_CORE_TYPE_ATOM = 0x20,
619  KMP_HW_CORE_TYPE_CORE = 0x40,
620  KMP_HW_MAX_NUM_CORE_TYPES = 3,
621 #else
622  KMP_HW_MAX_NUM_CORE_TYPES = 1,
623 #endif
624 } kmp_hw_core_type_t;
625 
626 #define KMP_HW_MAX_NUM_CORE_EFFS 8
627 
628 #define KMP_DEBUG_ASSERT_VALID_HW_TYPE(type) \
629  KMP_DEBUG_ASSERT(type >= (kmp_hw_t)0 && type < KMP_HW_LAST)
630 #define KMP_ASSERT_VALID_HW_TYPE(type) \
631  KMP_ASSERT(type >= (kmp_hw_t)0 && type < KMP_HW_LAST)
632 
633 #define KMP_FOREACH_HW_TYPE(type) \
634  for (kmp_hw_t type = (kmp_hw_t)0; type < KMP_HW_LAST; \
635  type = (kmp_hw_t)((int)type + 1))
636 
637 const char *__kmp_hw_get_keyword(kmp_hw_t type, bool plural = false);
638 const char *__kmp_hw_get_catalog_string(kmp_hw_t type, bool plural = false);
639 const char *__kmp_hw_get_core_type_string(kmp_hw_core_type_t type);
640 
641 /* Only Linux* OS and Windows* OS support thread affinity. */
642 #if KMP_AFFINITY_SUPPORTED
643 
644 // GROUP_AFFINITY is already defined for _MSC_VER>=1600 (VS2010 and later).
645 #if KMP_OS_WINDOWS
646 #if _MSC_VER < 1600 && KMP_MSVC_COMPAT
647 typedef struct GROUP_AFFINITY {
648  KAFFINITY Mask;
649  WORD Group;
650  WORD Reserved[3];
651 } GROUP_AFFINITY;
652 #endif /* _MSC_VER < 1600 */
653 #if KMP_GROUP_AFFINITY
654 extern int __kmp_num_proc_groups;
655 #else
656 static const int __kmp_num_proc_groups = 1;
657 #endif /* KMP_GROUP_AFFINITY */
658 typedef DWORD (*kmp_GetActiveProcessorCount_t)(WORD);
659 extern kmp_GetActiveProcessorCount_t __kmp_GetActiveProcessorCount;
660 
661 typedef WORD (*kmp_GetActiveProcessorGroupCount_t)(void);
662 extern kmp_GetActiveProcessorGroupCount_t __kmp_GetActiveProcessorGroupCount;
663 
664 typedef BOOL (*kmp_GetThreadGroupAffinity_t)(HANDLE, GROUP_AFFINITY *);
665 extern kmp_GetThreadGroupAffinity_t __kmp_GetThreadGroupAffinity;
666 
667 typedef BOOL (*kmp_SetThreadGroupAffinity_t)(HANDLE, const GROUP_AFFINITY *,
668  GROUP_AFFINITY *);
669 extern kmp_SetThreadGroupAffinity_t __kmp_SetThreadGroupAffinity;
670 #endif /* KMP_OS_WINDOWS */
671 
672 #if KMP_USE_HWLOC
673 extern hwloc_topology_t __kmp_hwloc_topology;
674 extern int __kmp_hwloc_error;
675 #endif
676 
677 extern size_t __kmp_affin_mask_size;
678 #define KMP_AFFINITY_CAPABLE() (__kmp_affin_mask_size > 0)
679 #define KMP_AFFINITY_DISABLE() (__kmp_affin_mask_size = 0)
680 #define KMP_AFFINITY_ENABLE(mask_size) (__kmp_affin_mask_size = mask_size)
681 #define KMP_CPU_SET_ITERATE(i, mask) \
682  for (i = (mask)->begin(); (int)i != (mask)->end(); i = (mask)->next(i))
683 #define KMP_CPU_SET(i, mask) (mask)->set(i)
684 #define KMP_CPU_ISSET(i, mask) (mask)->is_set(i)
685 #define KMP_CPU_CLR(i, mask) (mask)->clear(i)
686 #define KMP_CPU_ZERO(mask) (mask)->zero()
687 #define KMP_CPU_COPY(dest, src) (dest)->copy(src)
688 #define KMP_CPU_AND(dest, src) (dest)->bitwise_and(src)
689 #define KMP_CPU_COMPLEMENT(max_bit_number, mask) (mask)->bitwise_not()
690 #define KMP_CPU_UNION(dest, src) (dest)->bitwise_or(src)
691 #define KMP_CPU_ALLOC(ptr) (ptr = __kmp_affinity_dispatch->allocate_mask())
692 #define KMP_CPU_FREE(ptr) __kmp_affinity_dispatch->deallocate_mask(ptr)
693 #define KMP_CPU_ALLOC_ON_STACK(ptr) KMP_CPU_ALLOC(ptr)
694 #define KMP_CPU_FREE_FROM_STACK(ptr) KMP_CPU_FREE(ptr)
695 #define KMP_CPU_INTERNAL_ALLOC(ptr) KMP_CPU_ALLOC(ptr)
696 #define KMP_CPU_INTERNAL_FREE(ptr) KMP_CPU_FREE(ptr)
697 #define KMP_CPU_INDEX(arr, i) __kmp_affinity_dispatch->index_mask_array(arr, i)
698 #define KMP_CPU_ALLOC_ARRAY(arr, n) \
699  (arr = __kmp_affinity_dispatch->allocate_mask_array(n))
700 #define KMP_CPU_FREE_ARRAY(arr, n) \
701  __kmp_affinity_dispatch->deallocate_mask_array(arr)
702 #define KMP_CPU_INTERNAL_ALLOC_ARRAY(arr, n) KMP_CPU_ALLOC_ARRAY(arr, n)
703 #define KMP_CPU_INTERNAL_FREE_ARRAY(arr, n) KMP_CPU_FREE_ARRAY(arr, n)
704 #define __kmp_get_system_affinity(mask, abort_bool) \
705  (mask)->get_system_affinity(abort_bool)
706 #define __kmp_set_system_affinity(mask, abort_bool) \
707  (mask)->set_system_affinity(abort_bool)
708 #define __kmp_get_proc_group(mask) (mask)->get_proc_group()
709 
710 class KMPAffinity {
711 public:
712  class Mask {
713  public:
714  void *operator new(size_t n);
715  void operator delete(void *p);
716  void *operator new[](size_t n);
717  void operator delete[](void *p);
718  virtual ~Mask() {}
719  // Set bit i to 1
720  virtual void set(int i) {}
721  // Return bit i
722  virtual bool is_set(int i) const { return false; }
723  // Set bit i to 0
724  virtual void clear(int i) {}
725  // Zero out entire mask
726  virtual void zero() {}
727  // Copy src into this mask
728  virtual void copy(const Mask *src) {}
729  // this &= rhs
730  virtual void bitwise_and(const Mask *rhs) {}
731  // this |= rhs
732  virtual void bitwise_or(const Mask *rhs) {}
733  // this = ~this
734  virtual void bitwise_not() {}
735  // API for iterating over an affinity mask
736  // for (int i = mask->begin(); i != mask->end(); i = mask->next(i))
737  virtual int begin() const { return 0; }
738  virtual int end() const { return 0; }
739  virtual int next(int previous) const { return 0; }
740 #if KMP_OS_WINDOWS
741  virtual int set_process_affinity(bool abort_on_error) const { return -1; }
742 #endif
743  // Set the system's affinity to this affinity mask's value
744  virtual int set_system_affinity(bool abort_on_error) const { return -1; }
745  // Set this affinity mask to the current system affinity
746  virtual int get_system_affinity(bool abort_on_error) { return -1; }
747  // Only 1 DWORD in the mask should have any procs set.
748  // Return the appropriate index, or -1 for an invalid mask.
749  virtual int get_proc_group() const { return -1; }
750  };
751  void *operator new(size_t n);
752  void operator delete(void *p);
753  // Need virtual destructor
754  virtual ~KMPAffinity() = default;
755  // Determine if affinity is capable
756  virtual void determine_capable(const char *env_var) {}
757  // Bind the current thread to os proc
758  virtual void bind_thread(int proc) {}
759  // Factory functions to allocate/deallocate a mask
760  virtual Mask *allocate_mask() { return nullptr; }
761  virtual void deallocate_mask(Mask *m) {}
762  virtual Mask *allocate_mask_array(int num) { return nullptr; }
763  virtual void deallocate_mask_array(Mask *m) {}
764  virtual Mask *index_mask_array(Mask *m, int index) { return nullptr; }
765  static void pick_api();
766  static void destroy_api();
767  enum api_type {
768  NATIVE_OS
769 #if KMP_USE_HWLOC
770  ,
771  HWLOC
772 #endif
773  };
774  virtual api_type get_api_type() const {
775  KMP_ASSERT(0);
776  return NATIVE_OS;
777  }
778 
779 private:
780  static bool picked_api;
781 };
782 
783 typedef KMPAffinity::Mask kmp_affin_mask_t;
784 extern KMPAffinity *__kmp_affinity_dispatch;
785 
786 // Declare local char buffers with this size for printing debug and info
787 // messages, using __kmp_affinity_print_mask().
788 #define KMP_AFFIN_MASK_PRINT_LEN 1024
789 
790 enum affinity_type {
791  affinity_none = 0,
792  affinity_physical,
793  affinity_logical,
794  affinity_compact,
795  affinity_scatter,
796  affinity_explicit,
797  affinity_balanced,
798  affinity_disabled, // not used outsize the env var parser
799  affinity_default
800 };
801 
802 enum affinity_top_method {
803  affinity_top_method_all = 0, // try all (supported) methods, in order
804 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
805  affinity_top_method_apicid,
806  affinity_top_method_x2apicid,
807  affinity_top_method_x2apicid_1f,
808 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
809  affinity_top_method_cpuinfo, // KMP_CPUINFO_FILE is usable on Windows* OS, too
810 #if KMP_GROUP_AFFINITY
811  affinity_top_method_group,
812 #endif /* KMP_GROUP_AFFINITY */
813  affinity_top_method_flat,
814 #if KMP_USE_HWLOC
815  affinity_top_method_hwloc,
816 #endif
817  affinity_top_method_default
818 };
819 
820 #define affinity_respect_mask_default (-1)
821 
822 extern enum affinity_type __kmp_affinity_type; /* Affinity type */
823 extern kmp_hw_t __kmp_affinity_gran; /* Affinity granularity */
824 extern int __kmp_affinity_gran_levels; /* corresponding int value */
825 extern int __kmp_affinity_dups; /* Affinity duplicate masks */
826 extern enum affinity_top_method __kmp_affinity_top_method;
827 extern int __kmp_affinity_compact; /* Affinity 'compact' value */
828 extern int __kmp_affinity_offset; /* Affinity offset value */
829 extern int __kmp_affinity_verbose; /* Was verbose specified for KMP_AFFINITY? */
830 extern int __kmp_affinity_warnings; /* KMP_AFFINITY warnings enabled ? */
831 extern int __kmp_affinity_respect_mask; // Respect process' init affinity mask?
832 extern char *__kmp_affinity_proclist; /* proc ID list */
833 extern kmp_affin_mask_t *__kmp_affinity_masks;
834 extern unsigned __kmp_affinity_num_masks;
835 extern void __kmp_affinity_bind_thread(int which);
836 
837 extern kmp_affin_mask_t *__kmp_affin_fullMask;
838 extern char *__kmp_cpuinfo_file;
839 
840 #endif /* KMP_AFFINITY_SUPPORTED */
841 
842 // This needs to be kept in sync with the values in omp.h !!!
843 typedef enum kmp_proc_bind_t {
844  proc_bind_false = 0,
845  proc_bind_true,
846  proc_bind_primary,
847  proc_bind_close,
848  proc_bind_spread,
849  proc_bind_intel, // use KMP_AFFINITY interface
850  proc_bind_default
851 } kmp_proc_bind_t;
852 
853 typedef struct kmp_nested_proc_bind_t {
854  kmp_proc_bind_t *bind_types;
855  int size;
856  int used;
857 } kmp_nested_proc_bind_t;
858 
859 extern kmp_nested_proc_bind_t __kmp_nested_proc_bind;
860 extern kmp_proc_bind_t __kmp_teams_proc_bind;
861 
862 extern int __kmp_display_affinity;
863 extern char *__kmp_affinity_format;
864 static const size_t KMP_AFFINITY_FORMAT_SIZE = 512;
865 #if OMPT_SUPPORT
866 extern int __kmp_tool;
867 extern char *__kmp_tool_libraries;
868 #endif // OMPT_SUPPORT
869 
870 #if KMP_AFFINITY_SUPPORTED
871 #define KMP_PLACE_ALL (-1)
872 #define KMP_PLACE_UNDEFINED (-2)
873 // Is KMP_AFFINITY is being used instead of OMP_PROC_BIND/OMP_PLACES?
874 #define KMP_AFFINITY_NON_PROC_BIND \
875  ((__kmp_nested_proc_bind.bind_types[0] == proc_bind_false || \
876  __kmp_nested_proc_bind.bind_types[0] == proc_bind_intel) && \
877  (__kmp_affinity_num_masks > 0 || __kmp_affinity_type == affinity_balanced))
878 #endif /* KMP_AFFINITY_SUPPORTED */
879 
880 extern int __kmp_affinity_num_places;
881 
882 typedef enum kmp_cancel_kind_t {
883  cancel_noreq = 0,
884  cancel_parallel = 1,
885  cancel_loop = 2,
886  cancel_sections = 3,
887  cancel_taskgroup = 4
888 } kmp_cancel_kind_t;
889 
890 // KMP_HW_SUBSET support:
891 typedef struct kmp_hws_item {
892  int num;
893  int offset;
894 } kmp_hws_item_t;
895 
896 extern kmp_hws_item_t __kmp_hws_socket;
897 extern kmp_hws_item_t __kmp_hws_die;
898 extern kmp_hws_item_t __kmp_hws_node;
899 extern kmp_hws_item_t __kmp_hws_tile;
900 extern kmp_hws_item_t __kmp_hws_core;
901 extern kmp_hws_item_t __kmp_hws_proc;
902 extern int __kmp_hws_requested;
903 extern int __kmp_hws_abs_flag; // absolute or per-item number requested
904 
905 /* ------------------------------------------------------------------------ */
906 
907 #define KMP_PAD(type, sz) \
908  (sizeof(type) + (sz - ((sizeof(type) - 1) % (sz)) - 1))
909 
910 // We need to avoid using -1 as a GTID as +1 is added to the gtid
911 // when storing it in a lock, and the value 0 is reserved.
912 #define KMP_GTID_DNE (-2) /* Does not exist */
913 #define KMP_GTID_SHUTDOWN (-3) /* Library is shutting down */
914 #define KMP_GTID_MONITOR (-4) /* Monitor thread ID */
915 #define KMP_GTID_UNKNOWN (-5) /* Is not known */
916 #define KMP_GTID_MIN (-6) /* Minimal gtid for low bound check in DEBUG */
917 
918 /* OpenMP 5.0 Memory Management support */
919 
920 #ifndef __OMP_H
921 // Duplicate type definitions from omp.h
922 typedef uintptr_t omp_uintptr_t;
923 
924 typedef enum {
925  omp_atk_sync_hint = 1,
926  omp_atk_alignment = 2,
927  omp_atk_access = 3,
928  omp_atk_pool_size = 4,
929  omp_atk_fallback = 5,
930  omp_atk_fb_data = 6,
931  omp_atk_pinned = 7,
932  omp_atk_partition = 8
933 } omp_alloctrait_key_t;
934 
935 typedef enum {
936  omp_atv_false = 0,
937  omp_atv_true = 1,
938  omp_atv_contended = 3,
939  omp_atv_uncontended = 4,
940  omp_atv_serialized = 5,
941  omp_atv_sequential = omp_atv_serialized, // (deprecated)
942  omp_atv_private = 6,
943  omp_atv_all = 7,
944  omp_atv_thread = 8,
945  omp_atv_pteam = 9,
946  omp_atv_cgroup = 10,
947  omp_atv_default_mem_fb = 11,
948  omp_atv_null_fb = 12,
949  omp_atv_abort_fb = 13,
950  omp_atv_allocator_fb = 14,
951  omp_atv_environment = 15,
952  omp_atv_nearest = 16,
953  omp_atv_blocked = 17,
954  omp_atv_interleaved = 18
955 } omp_alloctrait_value_t;
956 #define omp_atv_default ((omp_uintptr_t)-1)
957 
958 typedef void *omp_memspace_handle_t;
959 extern omp_memspace_handle_t const omp_default_mem_space;
960 extern omp_memspace_handle_t const omp_large_cap_mem_space;
961 extern omp_memspace_handle_t const omp_const_mem_space;
962 extern omp_memspace_handle_t const omp_high_bw_mem_space;
963 extern omp_memspace_handle_t const omp_low_lat_mem_space;
964 extern omp_memspace_handle_t const llvm_omp_target_host_mem_space;
965 extern omp_memspace_handle_t const llvm_omp_target_shared_mem_space;
966 extern omp_memspace_handle_t const llvm_omp_target_device_mem_space;
967 
968 typedef struct {
969  omp_alloctrait_key_t key;
970  omp_uintptr_t value;
971 } omp_alloctrait_t;
972 
973 typedef void *omp_allocator_handle_t;
974 extern omp_allocator_handle_t const omp_null_allocator;
975 extern omp_allocator_handle_t const omp_default_mem_alloc;
976 extern omp_allocator_handle_t const omp_large_cap_mem_alloc;
977 extern omp_allocator_handle_t const omp_const_mem_alloc;
978 extern omp_allocator_handle_t const omp_high_bw_mem_alloc;
979 extern omp_allocator_handle_t const omp_low_lat_mem_alloc;
980 extern omp_allocator_handle_t const omp_cgroup_mem_alloc;
981 extern omp_allocator_handle_t const omp_pteam_mem_alloc;
982 extern omp_allocator_handle_t const omp_thread_mem_alloc;
983 extern omp_allocator_handle_t const llvm_omp_target_host_mem_alloc;
984 extern omp_allocator_handle_t const llvm_omp_target_shared_mem_alloc;
985 extern omp_allocator_handle_t const llvm_omp_target_device_mem_alloc;
986 extern omp_allocator_handle_t const kmp_max_mem_alloc;
987 extern omp_allocator_handle_t __kmp_def_allocator;
988 
989 // end of duplicate type definitions from omp.h
990 #endif
991 
992 extern int __kmp_memkind_available;
993 
994 typedef omp_memspace_handle_t kmp_memspace_t; // placeholder
995 
996 typedef struct kmp_allocator_t {
997  omp_memspace_handle_t memspace;
998  void **memkind; // pointer to memkind
999  size_t alignment;
1000  omp_alloctrait_value_t fb;
1001  kmp_allocator_t *fb_data;
1002  kmp_uint64 pool_size;
1003  kmp_uint64 pool_used;
1004 } kmp_allocator_t;
1005 
1006 extern omp_allocator_handle_t __kmpc_init_allocator(int gtid,
1007  omp_memspace_handle_t,
1008  int ntraits,
1009  omp_alloctrait_t traits[]);
1010 extern void __kmpc_destroy_allocator(int gtid, omp_allocator_handle_t al);
1011 extern void __kmpc_set_default_allocator(int gtid, omp_allocator_handle_t al);
1012 extern omp_allocator_handle_t __kmpc_get_default_allocator(int gtid);
1013 // external interfaces, may be used by compiler
1014 extern void *__kmpc_alloc(int gtid, size_t sz, omp_allocator_handle_t al);
1015 extern void *__kmpc_aligned_alloc(int gtid, size_t align, size_t sz,
1016  omp_allocator_handle_t al);
1017 extern void *__kmpc_calloc(int gtid, size_t nmemb, size_t sz,
1018  omp_allocator_handle_t al);
1019 extern void *__kmpc_realloc(int gtid, void *ptr, size_t sz,
1020  omp_allocator_handle_t al,
1021  omp_allocator_handle_t free_al);
1022 extern void __kmpc_free(int gtid, void *ptr, omp_allocator_handle_t al);
1023 // internal interfaces, contain real implementation
1024 extern void *__kmp_alloc(int gtid, size_t align, size_t sz,
1025  omp_allocator_handle_t al);
1026 extern void *__kmp_calloc(int gtid, size_t align, size_t nmemb, size_t sz,
1027  omp_allocator_handle_t al);
1028 extern void *__kmp_realloc(int gtid, void *ptr, size_t sz,
1029  omp_allocator_handle_t al,
1030  omp_allocator_handle_t free_al);
1031 extern void ___kmpc_free(int gtid, void *ptr, omp_allocator_handle_t al);
1032 
1033 extern void __kmp_init_memkind();
1034 extern void __kmp_fini_memkind();
1035 extern void __kmp_init_target_mem();
1036 
1037 /* ------------------------------------------------------------------------ */
1038 
1039 #define KMP_UINT64_MAX \
1040  (~((kmp_uint64)1 << ((sizeof(kmp_uint64) * (1 << 3)) - 1)))
1041 
1042 #define KMP_MIN_NTH 1
1043 
1044 #ifndef KMP_MAX_NTH
1045 #if defined(PTHREAD_THREADS_MAX) && PTHREAD_THREADS_MAX < INT_MAX
1046 #define KMP_MAX_NTH PTHREAD_THREADS_MAX
1047 #else
1048 #define KMP_MAX_NTH INT_MAX
1049 #endif
1050 #endif /* KMP_MAX_NTH */
1051 
1052 #ifdef PTHREAD_STACK_MIN
1053 #define KMP_MIN_STKSIZE PTHREAD_STACK_MIN
1054 #else
1055 #define KMP_MIN_STKSIZE ((size_t)(32 * 1024))
1056 #endif
1057 
1058 #define KMP_MAX_STKSIZE (~((size_t)1 << ((sizeof(size_t) * (1 << 3)) - 1)))
1059 
1060 #if KMP_ARCH_X86
1061 #define KMP_DEFAULT_STKSIZE ((size_t)(2 * 1024 * 1024))
1062 #elif KMP_ARCH_X86_64
1063 #define KMP_DEFAULT_STKSIZE ((size_t)(4 * 1024 * 1024))
1064 #define KMP_BACKUP_STKSIZE ((size_t)(2 * 1024 * 1024))
1065 #else
1066 #define KMP_DEFAULT_STKSIZE ((size_t)(1024 * 1024))
1067 #endif
1068 
1069 #define KMP_DEFAULT_MALLOC_POOL_INCR ((size_t)(1024 * 1024))
1070 #define KMP_MIN_MALLOC_POOL_INCR ((size_t)(4 * 1024))
1071 #define KMP_MAX_MALLOC_POOL_INCR \
1072  (~((size_t)1 << ((sizeof(size_t) * (1 << 3)) - 1)))
1073 
1074 #define KMP_MIN_STKOFFSET (0)
1075 #define KMP_MAX_STKOFFSET KMP_MAX_STKSIZE
1076 #if KMP_OS_DARWIN
1077 #define KMP_DEFAULT_STKOFFSET KMP_MIN_STKOFFSET
1078 #else
1079 #define KMP_DEFAULT_STKOFFSET CACHE_LINE
1080 #endif
1081 
1082 #define KMP_MIN_STKPADDING (0)
1083 #define KMP_MAX_STKPADDING (2 * 1024 * 1024)
1084 
1085 #define KMP_BLOCKTIME_MULTIPLIER \
1086  (1000) /* number of blocktime units per second */
1087 #define KMP_MIN_BLOCKTIME (0)
1088 #define KMP_MAX_BLOCKTIME \
1089  (INT_MAX) /* Must be this for "infinite" setting the work */
1090 
1091 /* __kmp_blocktime is in milliseconds */
1092 #define KMP_DEFAULT_BLOCKTIME (__kmp_is_hybrid_cpu() ? (0) : (200))
1093 
1094 #if KMP_USE_MONITOR
1095 #define KMP_DEFAULT_MONITOR_STKSIZE ((size_t)(64 * 1024))
1096 #define KMP_MIN_MONITOR_WAKEUPS (1) // min times monitor wakes up per second
1097 #define KMP_MAX_MONITOR_WAKEUPS (1000) // max times monitor can wake up per sec
1098 
1099 /* Calculate new number of monitor wakeups for a specific block time based on
1100  previous monitor_wakeups. Only allow increasing number of wakeups */
1101 #define KMP_WAKEUPS_FROM_BLOCKTIME(blocktime, monitor_wakeups) \
1102  (((blocktime) == KMP_MAX_BLOCKTIME) ? (monitor_wakeups) \
1103  : ((blocktime) == KMP_MIN_BLOCKTIME) ? KMP_MAX_MONITOR_WAKEUPS \
1104  : ((monitor_wakeups) > (KMP_BLOCKTIME_MULTIPLIER / (blocktime))) \
1105  ? (monitor_wakeups) \
1106  : (KMP_BLOCKTIME_MULTIPLIER) / (blocktime))
1107 
1108 /* Calculate number of intervals for a specific block time based on
1109  monitor_wakeups */
1110 #define KMP_INTERVALS_FROM_BLOCKTIME(blocktime, monitor_wakeups) \
1111  (((blocktime) + (KMP_BLOCKTIME_MULTIPLIER / (monitor_wakeups)) - 1) / \
1112  (KMP_BLOCKTIME_MULTIPLIER / (monitor_wakeups)))
1113 #else
1114 #define KMP_BLOCKTIME(team, tid) \
1115  (get__bt_set(team, tid) ? get__blocktime(team, tid) : __kmp_dflt_blocktime)
1116 #if KMP_OS_UNIX && (KMP_ARCH_X86 || KMP_ARCH_X86_64)
1117 // HW TSC is used to reduce overhead (clock tick instead of nanosecond).
1118 extern kmp_uint64 __kmp_ticks_per_msec;
1119 #if KMP_COMPILER_ICC || KMP_COMPILER_ICX
1120 #define KMP_NOW() ((kmp_uint64)_rdtsc())
1121 #else
1122 #define KMP_NOW() __kmp_hardware_timestamp()
1123 #endif
1124 #define KMP_NOW_MSEC() (KMP_NOW() / __kmp_ticks_per_msec)
1125 #define KMP_BLOCKTIME_INTERVAL(team, tid) \
1126  (KMP_BLOCKTIME(team, tid) * __kmp_ticks_per_msec)
1127 #define KMP_BLOCKING(goal, count) ((goal) > KMP_NOW())
1128 #else
1129 // System time is retrieved sporadically while blocking.
1130 extern kmp_uint64 __kmp_now_nsec();
1131 #define KMP_NOW() __kmp_now_nsec()
1132 #define KMP_NOW_MSEC() (KMP_NOW() / KMP_USEC_PER_SEC)
1133 #define KMP_BLOCKTIME_INTERVAL(team, tid) \
1134  (KMP_BLOCKTIME(team, tid) * KMP_USEC_PER_SEC)
1135 #define KMP_BLOCKING(goal, count) ((count) % 1000 != 0 || (goal) > KMP_NOW())
1136 #endif
1137 #endif // KMP_USE_MONITOR
1138 
1139 #define KMP_MIN_STATSCOLS 40
1140 #define KMP_MAX_STATSCOLS 4096
1141 #define KMP_DEFAULT_STATSCOLS 80
1142 
1143 #define KMP_MIN_INTERVAL 0
1144 #define KMP_MAX_INTERVAL (INT_MAX - 1)
1145 #define KMP_DEFAULT_INTERVAL 0
1146 
1147 #define KMP_MIN_CHUNK 1
1148 #define KMP_MAX_CHUNK (INT_MAX - 1)
1149 #define KMP_DEFAULT_CHUNK 1
1150 
1151 #define KMP_MIN_DISP_NUM_BUFF 1
1152 #define KMP_DFLT_DISP_NUM_BUFF 7
1153 #define KMP_MAX_DISP_NUM_BUFF 4096
1154 
1155 #define KMP_MAX_ORDERED 8
1156 
1157 #define KMP_MAX_FIELDS 32
1158 
1159 #define KMP_MAX_BRANCH_BITS 31
1160 
1161 #define KMP_MAX_ACTIVE_LEVELS_LIMIT INT_MAX
1162 
1163 #define KMP_MAX_DEFAULT_DEVICE_LIMIT INT_MAX
1164 
1165 #define KMP_MAX_TASK_PRIORITY_LIMIT INT_MAX
1166 
1167 /* Minimum number of threads before switch to TLS gtid (experimentally
1168  determined) */
1169 /* josh TODO: what about OS X* tuning? */
1170 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
1171 #define KMP_TLS_GTID_MIN 5
1172 #else
1173 #define KMP_TLS_GTID_MIN INT_MAX
1174 #endif
1175 
1176 #define KMP_MASTER_TID(tid) (0 == (tid))
1177 #define KMP_WORKER_TID(tid) (0 != (tid))
1178 
1179 #define KMP_MASTER_GTID(gtid) (0 == __kmp_tid_from_gtid((gtid)))
1180 #define KMP_WORKER_GTID(gtid) (0 != __kmp_tid_from_gtid((gtid)))
1181 #define KMP_INITIAL_GTID(gtid) (0 == (gtid))
1182 
1183 #ifndef TRUE
1184 #define FALSE 0
1185 #define TRUE (!FALSE)
1186 #endif
1187 
1188 /* NOTE: all of the following constants must be even */
1189 
1190 #if KMP_OS_WINDOWS
1191 #define KMP_INIT_WAIT 64U /* initial number of spin-tests */
1192 #define KMP_NEXT_WAIT 32U /* susequent number of spin-tests */
1193 #elif KMP_OS_LINUX
1194 #define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
1195 #define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
1196 #elif KMP_OS_DARWIN
1197 /* TODO: tune for KMP_OS_DARWIN */
1198 #define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
1199 #define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
1200 #elif KMP_OS_DRAGONFLY
1201 /* TODO: tune for KMP_OS_DRAGONFLY */
1202 #define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
1203 #define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
1204 #elif KMP_OS_FREEBSD
1205 /* TODO: tune for KMP_OS_FREEBSD */
1206 #define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
1207 #define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
1208 #elif KMP_OS_NETBSD
1209 /* TODO: tune for KMP_OS_NETBSD */
1210 #define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
1211 #define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
1212 #elif KMP_OS_HURD
1213 /* TODO: tune for KMP_OS_HURD */
1214 #define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
1215 #define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
1216 #elif KMP_OS_OPENBSD
1217 /* TODO: tune for KMP_OS_OPENBSD */
1218 #define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
1219 #define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
1220 #endif
1221 
1222 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
1223 typedef struct kmp_cpuid {
1224  kmp_uint32 eax;
1225  kmp_uint32 ebx;
1226  kmp_uint32 ecx;
1227  kmp_uint32 edx;
1228 } kmp_cpuid_t;
1229 
1230 typedef struct kmp_cpuinfo_flags_t {
1231  unsigned sse2 : 1; // 0 if SSE2 instructions are not supported, 1 otherwise.
1232  unsigned rtm : 1; // 0 if RTM instructions are not supported, 1 otherwise.
1233  unsigned hybrid : 1;
1234  unsigned reserved : 29; // Ensure size of 32 bits
1235 } kmp_cpuinfo_flags_t;
1236 
1237 typedef struct kmp_cpuinfo {
1238  int initialized; // If 0, other fields are not initialized.
1239  int signature; // CPUID(1).EAX
1240  int family; // CPUID(1).EAX[27:20]+CPUID(1).EAX[11:8] (Extended Family+Family)
1241  int model; // ( CPUID(1).EAX[19:16] << 4 ) + CPUID(1).EAX[7:4] ( ( Extended
1242  // Model << 4 ) + Model)
1243  int stepping; // CPUID(1).EAX[3:0] ( Stepping )
1244  kmp_cpuinfo_flags_t flags;
1245  int apic_id;
1246  int physical_id;
1247  int logical_id;
1248  kmp_uint64 frequency; // Nominal CPU frequency in Hz.
1249  char name[3 * sizeof(kmp_cpuid_t)]; // CPUID(0x80000002,0x80000003,0x80000004)
1250 } kmp_cpuinfo_t;
1251 
1252 extern void __kmp_query_cpuid(kmp_cpuinfo_t *p);
1253 
1254 #if KMP_OS_UNIX
1255 // subleaf is only needed for cache and topology discovery and can be set to
1256 // zero in most cases
1257 static inline void __kmp_x86_cpuid(int leaf, int subleaf, struct kmp_cpuid *p) {
1258  __asm__ __volatile__("cpuid"
1259  : "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
1260  : "a"(leaf), "c"(subleaf));
1261 }
1262 // Load p into FPU control word
1263 static inline void __kmp_load_x87_fpu_control_word(const kmp_int16 *p) {
1264  __asm__ __volatile__("fldcw %0" : : "m"(*p));
1265 }
1266 // Store FPU control word into p
1267 static inline void __kmp_store_x87_fpu_control_word(kmp_int16 *p) {
1268  __asm__ __volatile__("fstcw %0" : "=m"(*p));
1269 }
1270 static inline void __kmp_clear_x87_fpu_status_word() {
1271 #if KMP_MIC
1272  // 32-bit protected mode x87 FPU state
1273  struct x87_fpu_state {
1274  unsigned cw;
1275  unsigned sw;
1276  unsigned tw;
1277  unsigned fip;
1278  unsigned fips;
1279  unsigned fdp;
1280  unsigned fds;
1281  };
1282  struct x87_fpu_state fpu_state = {0, 0, 0, 0, 0, 0, 0};
1283  __asm__ __volatile__("fstenv %0\n\t" // store FP env
1284  "andw $0x7f00, %1\n\t" // clear 0-7,15 bits of FP SW
1285  "fldenv %0\n\t" // load FP env back
1286  : "+m"(fpu_state), "+m"(fpu_state.sw));
1287 #else
1288  __asm__ __volatile__("fnclex");
1289 #endif // KMP_MIC
1290 }
1291 #if __SSE__
1292 static inline void __kmp_load_mxcsr(const kmp_uint32 *p) { _mm_setcsr(*p); }
1293 static inline void __kmp_store_mxcsr(kmp_uint32 *p) { *p = _mm_getcsr(); }
1294 #else
1295 static inline void __kmp_load_mxcsr(const kmp_uint32 *p) {}
1296 static inline void __kmp_store_mxcsr(kmp_uint32 *p) { *p = 0; }
1297 #endif
1298 #else
1299 // Windows still has these as external functions in assembly file
1300 extern void __kmp_x86_cpuid(int mode, int mode2, struct kmp_cpuid *p);
1301 extern void __kmp_load_x87_fpu_control_word(const kmp_int16 *p);
1302 extern void __kmp_store_x87_fpu_control_word(kmp_int16 *p);
1303 extern void __kmp_clear_x87_fpu_status_word();
1304 static inline void __kmp_load_mxcsr(const kmp_uint32 *p) { _mm_setcsr(*p); }
1305 static inline void __kmp_store_mxcsr(kmp_uint32 *p) { *p = _mm_getcsr(); }
1306 #endif // KMP_OS_UNIX
1307 
1308 #define KMP_X86_MXCSR_MASK 0xffffffc0 /* ignore status flags (6 lsb) */
1309 
1310 // User-level Monitor/Mwait
1311 #if KMP_HAVE_UMWAIT
1312 // We always try for UMWAIT first
1313 #if KMP_HAVE_WAITPKG_INTRINSICS
1314 #if KMP_HAVE_IMMINTRIN_H
1315 #include <immintrin.h>
1316 #elif KMP_HAVE_INTRIN_H
1317 #include <intrin.h>
1318 #endif
1319 #endif // KMP_HAVE_WAITPKG_INTRINSICS
1320 
1321 KMP_ATTRIBUTE_TARGET_WAITPKG
1322 static inline int __kmp_tpause(uint32_t hint, uint64_t counter) {
1323 #if !KMP_HAVE_WAITPKG_INTRINSICS
1324  uint32_t timeHi = uint32_t(counter >> 32);
1325  uint32_t timeLo = uint32_t(counter & 0xffffffff);
1326  char flag;
1327  __asm__ volatile("#tpause\n.byte 0x66, 0x0F, 0xAE, 0xF1\n"
1328  "setb %0"
1329  // The "=q" restraint means any register accessible as rl
1330  // in 32-bit mode: a, b, c, and d;
1331  // in 64-bit mode: any integer register
1332  : "=q"(flag)
1333  : "a"(timeLo), "d"(timeHi), "c"(hint)
1334  :);
1335  return flag;
1336 #else
1337  return _tpause(hint, counter);
1338 #endif
1339 }
1340 KMP_ATTRIBUTE_TARGET_WAITPKG
1341 static inline void __kmp_umonitor(void *cacheline) {
1342 #if !KMP_HAVE_WAITPKG_INTRINSICS
1343  __asm__ volatile("# umonitor\n.byte 0xF3, 0x0F, 0xAE, 0x01 "
1344  :
1345  : "a"(cacheline)
1346  :);
1347 #else
1348  _umonitor(cacheline);
1349 #endif
1350 }
1351 KMP_ATTRIBUTE_TARGET_WAITPKG
1352 static inline int __kmp_umwait(uint32_t hint, uint64_t counter) {
1353 #if !KMP_HAVE_WAITPKG_INTRINSICS
1354  uint32_t timeHi = uint32_t(counter >> 32);
1355  uint32_t timeLo = uint32_t(counter & 0xffffffff);
1356  char flag;
1357  __asm__ volatile("#umwait\n.byte 0xF2, 0x0F, 0xAE, 0xF1\n"
1358  "setb %0"
1359  // The "=q" restraint means any register accessible as rl
1360  // in 32-bit mode: a, b, c, and d;
1361  // in 64-bit mode: any integer register
1362  : "=q"(flag)
1363  : "a"(timeLo), "d"(timeHi), "c"(hint)
1364  :);
1365  return flag;
1366 #else
1367  return _umwait(hint, counter);
1368 #endif
1369 }
1370 #elif KMP_HAVE_MWAIT
1371 #if KMP_OS_UNIX
1372 #include <pmmintrin.h>
1373 #else
1374 #include <intrin.h>
1375 #endif
1376 #if KMP_OS_UNIX
1377 __attribute__((target("sse3")))
1378 #endif
1379 static inline void
1380 __kmp_mm_monitor(void *cacheline, unsigned extensions, unsigned hints) {
1381  _mm_monitor(cacheline, extensions, hints);
1382 }
1383 #if KMP_OS_UNIX
1384 __attribute__((target("sse3")))
1385 #endif
1386 static inline void
1387 __kmp_mm_mwait(unsigned extensions, unsigned hints) {
1388  _mm_mwait(extensions, hints);
1389 }
1390 #endif // KMP_HAVE_UMWAIT
1391 
1392 #if KMP_ARCH_X86
1393 extern void __kmp_x86_pause(void);
1394 #elif KMP_MIC
1395 // Performance testing on KNC (C0QS-7120 P/A/X/D, 61-core, 16 GB Memory) showed
1396 // regression after removal of extra PAUSE from spin loops. Changing
1397 // the delay from 100 to 300 showed even better performance than double PAUSE
1398 // on Spec OMP2001 and LCPC tasking tests, no regressions on EPCC.
1399 static inline void __kmp_x86_pause(void) { _mm_delay_32(300); }
1400 #else
1401 static inline void __kmp_x86_pause(void) { _mm_pause(); }
1402 #endif
1403 #define KMP_CPU_PAUSE() __kmp_x86_pause()
1404 #elif KMP_ARCH_PPC64
1405 #define KMP_PPC64_PRI_LOW() __asm__ volatile("or 1, 1, 1")
1406 #define KMP_PPC64_PRI_MED() __asm__ volatile("or 2, 2, 2")
1407 #define KMP_PPC64_PRI_LOC_MB() __asm__ volatile("" : : : "memory")
1408 #define KMP_CPU_PAUSE() \
1409  do { \
1410  KMP_PPC64_PRI_LOW(); \
1411  KMP_PPC64_PRI_MED(); \
1412  KMP_PPC64_PRI_LOC_MB(); \
1413  } while (0)
1414 #else
1415 #define KMP_CPU_PAUSE() /* nothing to do */
1416 #endif
1417 
1418 #define KMP_INIT_YIELD(count) \
1419  { (count) = __kmp_yield_init; }
1420 
1421 #define KMP_INIT_BACKOFF(time) \
1422  { (time) = __kmp_pause_init; }
1423 
1424 #define KMP_OVERSUBSCRIBED \
1425  (TCR_4(__kmp_nth) > (__kmp_avail_proc ? __kmp_avail_proc : __kmp_xproc))
1426 
1427 #define KMP_TRY_YIELD \
1428  ((__kmp_use_yield == 1) || (__kmp_use_yield == 2 && (KMP_OVERSUBSCRIBED)))
1429 
1430 #define KMP_TRY_YIELD_OVERSUB \
1431  ((__kmp_use_yield == 1 || __kmp_use_yield == 2) && (KMP_OVERSUBSCRIBED))
1432 
1433 #define KMP_YIELD(cond) \
1434  { \
1435  KMP_CPU_PAUSE(); \
1436  if ((cond) && (KMP_TRY_YIELD)) \
1437  __kmp_yield(); \
1438  }
1439 
1440 #define KMP_YIELD_OVERSUB() \
1441  { \
1442  KMP_CPU_PAUSE(); \
1443  if ((KMP_TRY_YIELD_OVERSUB)) \
1444  __kmp_yield(); \
1445  }
1446 
1447 // Note the decrement of 2 in the following Macros. With KMP_LIBRARY=turnaround,
1448 // there should be no yielding since initial value from KMP_INIT_YIELD() is odd.
1449 #define KMP_YIELD_SPIN(count) \
1450  { \
1451  KMP_CPU_PAUSE(); \
1452  if (KMP_TRY_YIELD) { \
1453  (count) -= 2; \
1454  if (!(count)) { \
1455  __kmp_yield(); \
1456  (count) = __kmp_yield_next; \
1457  } \
1458  } \
1459  }
1460 
1461 // If TPAUSE is available & enabled, use it. If oversubscribed, use the slower
1462 // (C0.2) state, which improves performance of other SMT threads on the same
1463 // core, otherwise, use the fast (C0.1) default state, or whatever the user has
1464 // requested. Uses a timed TPAUSE, and exponential backoff. If TPAUSE isn't
1465 // available, fall back to the regular CPU pause and yield combination.
1466 #if KMP_HAVE_UMWAIT
1467 #define KMP_YIELD_OVERSUB_ELSE_SPIN(count, time) \
1468  { \
1469  if (__kmp_tpause_enabled) { \
1470  if (KMP_OVERSUBSCRIBED) { \
1471  __kmp_tpause(0, (time)); \
1472  } else { \
1473  __kmp_tpause(__kmp_tpause_hint, (time)); \
1474  } \
1475  (time) *= 2; \
1476  } else { \
1477  KMP_CPU_PAUSE(); \
1478  if ((KMP_TRY_YIELD_OVERSUB)) { \
1479  __kmp_yield(); \
1480  } else if (__kmp_use_yield == 1) { \
1481  (count) -= 2; \
1482  if (!(count)) { \
1483  __kmp_yield(); \
1484  (count) = __kmp_yield_next; \
1485  } \
1486  } \
1487  } \
1488  }
1489 #else
1490 #define KMP_YIELD_OVERSUB_ELSE_SPIN(count, time) \
1491  { \
1492  KMP_CPU_PAUSE(); \
1493  if ((KMP_TRY_YIELD_OVERSUB)) \
1494  __kmp_yield(); \
1495  else if (__kmp_use_yield == 1) { \
1496  (count) -= 2; \
1497  if (!(count)) { \
1498  __kmp_yield(); \
1499  (count) = __kmp_yield_next; \
1500  } \
1501  } \
1502  }
1503 #endif // KMP_HAVE_UMWAIT
1504 
1505 /* ------------------------------------------------------------------------ */
1506 /* Support datatypes for the orphaned construct nesting checks. */
1507 /* ------------------------------------------------------------------------ */
1508 
1509 /* When adding to this enum, add its corresponding string in cons_text_c[]
1510  * array in kmp_error.cpp */
1511 enum cons_type {
1512  ct_none,
1513  ct_parallel,
1514  ct_pdo,
1515  ct_pdo_ordered,
1516  ct_psections,
1517  ct_psingle,
1518  ct_critical,
1519  ct_ordered_in_parallel,
1520  ct_ordered_in_pdo,
1521  ct_master,
1522  ct_reduce,
1523  ct_barrier,
1524  ct_masked
1525 };
1526 
1527 #define IS_CONS_TYPE_ORDERED(ct) ((ct) == ct_pdo_ordered)
1528 
1529 struct cons_data {
1530  ident_t const *ident;
1531  enum cons_type type;
1532  int prev;
1533  kmp_user_lock_p
1534  name; /* address exclusively for critical section name comparison */
1535 };
1536 
1537 struct cons_header {
1538  int p_top, w_top, s_top;
1539  int stack_size, stack_top;
1540  struct cons_data *stack_data;
1541 };
1542 
1543 struct kmp_region_info {
1544  char *text;
1545  int offset[KMP_MAX_FIELDS];
1546  int length[KMP_MAX_FIELDS];
1547 };
1548 
1549 /* ---------------------------------------------------------------------- */
1550 /* ---------------------------------------------------------------------- */
1551 
1552 #if KMP_OS_WINDOWS
1553 typedef HANDLE kmp_thread_t;
1554 typedef DWORD kmp_key_t;
1555 #endif /* KMP_OS_WINDOWS */
1556 
1557 #if KMP_OS_UNIX
1558 typedef pthread_t kmp_thread_t;
1559 typedef pthread_key_t kmp_key_t;
1560 #endif
1561 
1562 extern kmp_key_t __kmp_gtid_threadprivate_key;
1563 
1564 typedef struct kmp_sys_info {
1565  long maxrss; /* the maximum resident set size utilized (in kilobytes) */
1566  long minflt; /* the number of page faults serviced without any I/O */
1567  long majflt; /* the number of page faults serviced that required I/O */
1568  long nswap; /* the number of times a process was "swapped" out of memory */
1569  long inblock; /* the number of times the file system had to perform input */
1570  long oublock; /* the number of times the file system had to perform output */
1571  long nvcsw; /* the number of times a context switch was voluntarily */
1572  long nivcsw; /* the number of times a context switch was forced */
1573 } kmp_sys_info_t;
1574 
1575 #if USE_ITT_BUILD
1576 // We cannot include "kmp_itt.h" due to circular dependency. Declare the only
1577 // required type here. Later we will check the type meets requirements.
1578 typedef int kmp_itt_mark_t;
1579 #define KMP_ITT_DEBUG 0
1580 #endif /* USE_ITT_BUILD */
1581 
1582 typedef kmp_int32 kmp_critical_name[8];
1583 
1593 typedef void (*kmpc_micro)(kmp_int32 *global_tid, kmp_int32 *bound_tid, ...);
1594 typedef void (*kmpc_micro_bound)(kmp_int32 *bound_tid, kmp_int32 *bound_nth,
1595  ...);
1596 
1601 /* ---------------------------------------------------------------------------
1602  */
1603 /* Threadprivate initialization/finalization function declarations */
1604 
1605 /* for non-array objects: __kmpc_threadprivate_register() */
1606 
1611 typedef void *(*kmpc_ctor)(void *);
1612 
1617 typedef void (*kmpc_dtor)(
1618  void * /*, size_t */); /* 2nd arg: magic number for KCC unused by Intel
1619  compiler */
1624 typedef void *(*kmpc_cctor)(void *, void *);
1625 
1626 /* for array objects: __kmpc_threadprivate_register_vec() */
1627 /* First arg: "this" pointer */
1628 /* Last arg: number of array elements */
1634 typedef void *(*kmpc_ctor_vec)(void *, size_t);
1640 typedef void (*kmpc_dtor_vec)(void *, size_t);
1646 typedef void *(*kmpc_cctor_vec)(void *, void *,
1647  size_t); /* function unused by compiler */
1648 
1653 /* keeps tracked of threadprivate cache allocations for cleanup later */
1654 typedef struct kmp_cached_addr {
1655  void **addr; /* address of allocated cache */
1656  void ***compiler_cache; /* pointer to compiler's cache */
1657  void *data; /* pointer to global data */
1658  struct kmp_cached_addr *next; /* pointer to next cached address */
1659 } kmp_cached_addr_t;
1660 
1661 struct private_data {
1662  struct private_data *next; /* The next descriptor in the list */
1663  void *data; /* The data buffer for this descriptor */
1664  int more; /* The repeat count for this descriptor */
1665  size_t size; /* The data size for this descriptor */
1666 };
1667 
1668 struct private_common {
1669  struct private_common *next;
1670  struct private_common *link;
1671  void *gbl_addr;
1672  void *par_addr; /* par_addr == gbl_addr for PRIMARY thread */
1673  size_t cmn_size;
1674 };
1675 
1676 struct shared_common {
1677  struct shared_common *next;
1678  struct private_data *pod_init;
1679  void *obj_init;
1680  void *gbl_addr;
1681  union {
1682  kmpc_ctor ctor;
1683  kmpc_ctor_vec ctorv;
1684  } ct;
1685  union {
1686  kmpc_cctor cctor;
1687  kmpc_cctor_vec cctorv;
1688  } cct;
1689  union {
1690  kmpc_dtor dtor;
1691  kmpc_dtor_vec dtorv;
1692  } dt;
1693  size_t vec_len;
1694  int is_vec;
1695  size_t cmn_size;
1696 };
1697 
1698 #define KMP_HASH_TABLE_LOG2 9 /* log2 of the hash table size */
1699 #define KMP_HASH_TABLE_SIZE \
1700  (1 << KMP_HASH_TABLE_LOG2) /* size of the hash table */
1701 #define KMP_HASH_SHIFT 3 /* throw away this many low bits from the address */
1702 #define KMP_HASH(x) \
1703  ((((kmp_uintptr_t)x) >> KMP_HASH_SHIFT) & (KMP_HASH_TABLE_SIZE - 1))
1704 
1705 struct common_table {
1706  struct private_common *data[KMP_HASH_TABLE_SIZE];
1707 };
1708 
1709 struct shared_table {
1710  struct shared_common *data[KMP_HASH_TABLE_SIZE];
1711 };
1712 
1713 /* ------------------------------------------------------------------------ */
1714 
1715 #if KMP_USE_HIER_SCHED
1716 // Shared barrier data that exists inside a single unit of the scheduling
1717 // hierarchy
1718 typedef struct kmp_hier_private_bdata_t {
1719  kmp_int32 num_active;
1720  kmp_uint64 index;
1721  kmp_uint64 wait_val[2];
1722 } kmp_hier_private_bdata_t;
1723 #endif
1724 
1725 typedef struct kmp_sched_flags {
1726  unsigned ordered : 1;
1727  unsigned nomerge : 1;
1728  unsigned contains_last : 1;
1729 #if KMP_USE_HIER_SCHED
1730  unsigned use_hier : 1;
1731  unsigned unused : 28;
1732 #else
1733  unsigned unused : 29;
1734 #endif
1735 } kmp_sched_flags_t;
1736 
1737 KMP_BUILD_ASSERT(sizeof(kmp_sched_flags_t) == 4);
1738 
1739 #if KMP_STATIC_STEAL_ENABLED
1740 typedef struct KMP_ALIGN_CACHE dispatch_private_info32 {
1741  kmp_int32 count;
1742  kmp_int32 ub;
1743  /* Adding KMP_ALIGN_CACHE here doesn't help / can hurt performance */
1744  kmp_int32 lb;
1745  kmp_int32 st;
1746  kmp_int32 tc;
1747  kmp_lock_t *steal_lock; // lock used for chunk stealing
1748  // KMP_ALIGN(32) ensures (if the KMP_ALIGN macro is turned on)
1749  // a) parm3 is properly aligned and
1750  // b) all parm1-4 are on the same cache line.
1751  // Because of parm1-4 are used together, performance seems to be better
1752  // if they are on the same cache line (not measured though).
1753 
1754  struct KMP_ALIGN(32) { // AC: changed 16 to 32 in order to simplify template
1755  kmp_int32 parm1; // structures in kmp_dispatch.cpp. This should
1756  kmp_int32 parm2; // make no real change at least while padding is off.
1757  kmp_int32 parm3;
1758  kmp_int32 parm4;
1759  };
1760 
1761  kmp_uint32 ordered_lower;
1762  kmp_uint32 ordered_upper;
1763 #if KMP_OS_WINDOWS
1764  kmp_int32 last_upper;
1765 #endif /* KMP_OS_WINDOWS */
1766 } dispatch_private_info32_t;
1767 
1768 typedef struct KMP_ALIGN_CACHE dispatch_private_info64 {
1769  kmp_int64 count; // current chunk number for static & static-steal scheduling
1770  kmp_int64 ub; /* upper-bound */
1771  /* Adding KMP_ALIGN_CACHE here doesn't help / can hurt performance */
1772  kmp_int64 lb; /* lower-bound */
1773  kmp_int64 st; /* stride */
1774  kmp_int64 tc; /* trip count (number of iterations) */
1775  kmp_lock_t *steal_lock; // lock used for chunk stealing
1776  /* parm[1-4] are used in different ways by different scheduling algorithms */
1777 
1778  // KMP_ALIGN( 32 ) ensures ( if the KMP_ALIGN macro is turned on )
1779  // a) parm3 is properly aligned and
1780  // b) all parm1-4 are in the same cache line.
1781  // Because of parm1-4 are used together, performance seems to be better
1782  // if they are in the same line (not measured though).
1783 
1784  struct KMP_ALIGN(32) {
1785  kmp_int64 parm1;
1786  kmp_int64 parm2;
1787  kmp_int64 parm3;
1788  kmp_int64 parm4;
1789  };
1790 
1791  kmp_uint64 ordered_lower;
1792  kmp_uint64 ordered_upper;
1793 #if KMP_OS_WINDOWS
1794  kmp_int64 last_upper;
1795 #endif /* KMP_OS_WINDOWS */
1796 } dispatch_private_info64_t;
1797 #else /* KMP_STATIC_STEAL_ENABLED */
1798 typedef struct KMP_ALIGN_CACHE dispatch_private_info32 {
1799  kmp_int32 lb;
1800  kmp_int32 ub;
1801  kmp_int32 st;
1802  kmp_int32 tc;
1803 
1804  kmp_int32 parm1;
1805  kmp_int32 parm2;
1806  kmp_int32 parm3;
1807  kmp_int32 parm4;
1808 
1809  kmp_int32 count;
1810 
1811  kmp_uint32 ordered_lower;
1812  kmp_uint32 ordered_upper;
1813 #if KMP_OS_WINDOWS
1814  kmp_int32 last_upper;
1815 #endif /* KMP_OS_WINDOWS */
1816 } dispatch_private_info32_t;
1817 
1818 typedef struct KMP_ALIGN_CACHE dispatch_private_info64 {
1819  kmp_int64 lb; /* lower-bound */
1820  kmp_int64 ub; /* upper-bound */
1821  kmp_int64 st; /* stride */
1822  kmp_int64 tc; /* trip count (number of iterations) */
1823 
1824  /* parm[1-4] are used in different ways by different scheduling algorithms */
1825  kmp_int64 parm1;
1826  kmp_int64 parm2;
1827  kmp_int64 parm3;
1828  kmp_int64 parm4;
1829 
1830  kmp_int64 count; /* current chunk number for static scheduling */
1831 
1832  kmp_uint64 ordered_lower;
1833  kmp_uint64 ordered_upper;
1834 #if KMP_OS_WINDOWS
1835  kmp_int64 last_upper;
1836 #endif /* KMP_OS_WINDOWS */
1837 } dispatch_private_info64_t;
1838 #endif /* KMP_STATIC_STEAL_ENABLED */
1839 
1840 typedef struct KMP_ALIGN_CACHE dispatch_private_info {
1841  union private_info {
1842  dispatch_private_info32_t p32;
1843  dispatch_private_info64_t p64;
1844  } u;
1845  enum sched_type schedule; /* scheduling algorithm */
1846  kmp_sched_flags_t flags; /* flags (e.g., ordered, nomerge, etc.) */
1847  std::atomic<kmp_uint32> steal_flag; // static_steal only, state of a buffer
1848  kmp_int32 ordered_bumped;
1849  // Stack of buffers for nest of serial regions
1850  struct dispatch_private_info *next;
1851  kmp_int32 type_size; /* the size of types in private_info */
1852 #if KMP_USE_HIER_SCHED
1853  kmp_int32 hier_id;
1854  void *parent; /* hierarchical scheduling parent pointer */
1855 #endif
1856  enum cons_type pushed_ws;
1857 } dispatch_private_info_t;
1858 
1859 typedef struct dispatch_shared_info32 {
1860  /* chunk index under dynamic, number of idle threads under static-steal;
1861  iteration index otherwise */
1862  volatile kmp_uint32 iteration;
1863  volatile kmp_int32 num_done;
1864  volatile kmp_uint32 ordered_iteration;
1865  // Dummy to retain the structure size after making ordered_iteration scalar
1866  kmp_int32 ordered_dummy[KMP_MAX_ORDERED - 1];
1867 } dispatch_shared_info32_t;
1868 
1869 typedef struct dispatch_shared_info64 {
1870  /* chunk index under dynamic, number of idle threads under static-steal;
1871  iteration index otherwise */
1872  volatile kmp_uint64 iteration;
1873  volatile kmp_int64 num_done;
1874  volatile kmp_uint64 ordered_iteration;
1875  // Dummy to retain the structure size after making ordered_iteration scalar
1876  kmp_int64 ordered_dummy[KMP_MAX_ORDERED - 3];
1877 } dispatch_shared_info64_t;
1878 
1879 typedef struct dispatch_shared_info {
1880  union shared_info {
1881  dispatch_shared_info32_t s32;
1882  dispatch_shared_info64_t s64;
1883  } u;
1884  volatile kmp_uint32 buffer_index;
1885  volatile kmp_int32 doacross_buf_idx; // teamwise index
1886  volatile kmp_uint32 *doacross_flags; // shared array of iteration flags (0/1)
1887  kmp_int32 doacross_num_done; // count finished threads
1888 #if KMP_USE_HIER_SCHED
1889  void *hier;
1890 #endif
1891 #if KMP_USE_HWLOC
1892  // When linking with libhwloc, the ORDERED EPCC test slows down on big
1893  // machines (> 48 cores). Performance analysis showed that a cache thrash
1894  // was occurring and this padding helps alleviate the problem.
1895  char padding[64];
1896 #endif
1897 } dispatch_shared_info_t;
1898 
1899 typedef struct kmp_disp {
1900  /* Vector for ORDERED SECTION */
1901  void (*th_deo_fcn)(int *gtid, int *cid, ident_t *);
1902  /* Vector for END ORDERED SECTION */
1903  void (*th_dxo_fcn)(int *gtid, int *cid, ident_t *);
1904 
1905  dispatch_shared_info_t *th_dispatch_sh_current;
1906  dispatch_private_info_t *th_dispatch_pr_current;
1907 
1908  dispatch_private_info_t *th_disp_buffer;
1909  kmp_uint32 th_disp_index;
1910  kmp_int32 th_doacross_buf_idx; // thread's doacross buffer index
1911  volatile kmp_uint32 *th_doacross_flags; // pointer to shared array of flags
1912  kmp_int64 *th_doacross_info; // info on loop bounds
1913 #if KMP_USE_INTERNODE_ALIGNMENT
1914  char more_padding[INTERNODE_CACHE_LINE];
1915 #endif
1916 } kmp_disp_t;
1917 
1918 /* ------------------------------------------------------------------------ */
1919 /* Barrier stuff */
1920 
1921 /* constants for barrier state update */
1922 #define KMP_INIT_BARRIER_STATE 0 /* should probably start from zero */
1923 #define KMP_BARRIER_SLEEP_BIT 0 /* bit used for suspend/sleep part of state */
1924 #define KMP_BARRIER_UNUSED_BIT 1 // bit that must never be set for valid state
1925 #define KMP_BARRIER_BUMP_BIT 2 /* lsb used for bump of go/arrived state */
1926 
1927 #define KMP_BARRIER_SLEEP_STATE (1 << KMP_BARRIER_SLEEP_BIT)
1928 #define KMP_BARRIER_UNUSED_STATE (1 << KMP_BARRIER_UNUSED_BIT)
1929 #define KMP_BARRIER_STATE_BUMP (1 << KMP_BARRIER_BUMP_BIT)
1930 
1931 #if (KMP_BARRIER_SLEEP_BIT >= KMP_BARRIER_BUMP_BIT)
1932 #error "Barrier sleep bit must be smaller than barrier bump bit"
1933 #endif
1934 #if (KMP_BARRIER_UNUSED_BIT >= KMP_BARRIER_BUMP_BIT)
1935 #error "Barrier unused bit must be smaller than barrier bump bit"
1936 #endif
1937 
1938 // Constants for release barrier wait state: currently, hierarchical only
1939 #define KMP_BARRIER_NOT_WAITING 0 // Normal state; worker not in wait_sleep
1940 #define KMP_BARRIER_OWN_FLAG \
1941  1 // Normal state; worker waiting on own b_go flag in release
1942 #define KMP_BARRIER_PARENT_FLAG \
1943  2 // Special state; worker waiting on parent's b_go flag in release
1944 #define KMP_BARRIER_SWITCH_TO_OWN_FLAG \
1945  3 // Special state; tells worker to shift from parent to own b_go
1946 #define KMP_BARRIER_SWITCHING \
1947  4 // Special state; worker resets appropriate flag on wake-up
1948 
1949 #define KMP_NOT_SAFE_TO_REAP \
1950  0 // Thread th_reap_state: not safe to reap (tasking)
1951 #define KMP_SAFE_TO_REAP 1 // Thread th_reap_state: safe to reap (not tasking)
1952 
1953 // The flag_type describes the storage used for the flag.
1954 enum flag_type {
1955  flag32,
1956  flag64,
1957  atomic_flag64,
1958  flag_oncore,
1959  flag_unset
1960 };
1961 
1962 enum barrier_type {
1963  bs_plain_barrier = 0, /* 0, All non-fork/join barriers (except reduction
1964  barriers if enabled) */
1965  bs_forkjoin_barrier, /* 1, All fork/join (parallel region) barriers */
1966 #if KMP_FAST_REDUCTION_BARRIER
1967  bs_reduction_barrier, /* 2, All barriers that are used in reduction */
1968 #endif // KMP_FAST_REDUCTION_BARRIER
1969  bs_last_barrier /* Just a placeholder to mark the end */
1970 };
1971 
1972 // to work with reduction barriers just like with plain barriers
1973 #if !KMP_FAST_REDUCTION_BARRIER
1974 #define bs_reduction_barrier bs_plain_barrier
1975 #endif // KMP_FAST_REDUCTION_BARRIER
1976 
1977 typedef enum kmp_bar_pat { /* Barrier communication patterns */
1978  bp_linear_bar =
1979  0, /* Single level (degenerate) tree */
1980  bp_tree_bar =
1981  1, /* Balanced tree with branching factor 2^n */
1982  bp_hyper_bar = 2, /* Hypercube-embedded tree with min
1983  branching factor 2^n */
1984  bp_hierarchical_bar = 3, /* Machine hierarchy tree */
1985  bp_dist_bar = 4, /* Distributed barrier */
1986  bp_last_bar /* Placeholder to mark the end */
1987 } kmp_bar_pat_e;
1988 
1989 #define KMP_BARRIER_ICV_PUSH 1
1990 
1991 /* Record for holding the values of the internal controls stack records */
1992 typedef struct kmp_internal_control {
1993  int serial_nesting_level; /* corresponds to the value of the
1994  th_team_serialized field */
1995  kmp_int8 dynamic; /* internal control for dynamic adjustment of threads (per
1996  thread) */
1997  kmp_int8
1998  bt_set; /* internal control for whether blocktime is explicitly set */
1999  int blocktime; /* internal control for blocktime */
2000 #if KMP_USE_MONITOR
2001  int bt_intervals; /* internal control for blocktime intervals */
2002 #endif
2003  int nproc; /* internal control for #threads for next parallel region (per
2004  thread) */
2005  int thread_limit; /* internal control for thread-limit-var */
2006  int max_active_levels; /* internal control for max_active_levels */
2007  kmp_r_sched_t
2008  sched; /* internal control for runtime schedule {sched,chunk} pair */
2009  kmp_proc_bind_t proc_bind; /* internal control for affinity */
2010  kmp_int32 default_device; /* internal control for default device */
2011  struct kmp_internal_control *next;
2012 } kmp_internal_control_t;
2013 
2014 static inline void copy_icvs(kmp_internal_control_t *dst,
2015  kmp_internal_control_t *src) {
2016  *dst = *src;
2017 }
2018 
2019 /* Thread barrier needs volatile barrier fields */
2020 typedef struct KMP_ALIGN_CACHE kmp_bstate {
2021  // th_fixed_icvs is aligned by virtue of kmp_bstate being aligned (and all
2022  // uses of it). It is not explicitly aligned below, because we *don't* want
2023  // it to be padded -- instead, we fit b_go into the same cache line with
2024  // th_fixed_icvs, enabling NGO cache lines stores in the hierarchical barrier.
2025  kmp_internal_control_t th_fixed_icvs; // Initial ICVs for the thread
2026  // Tuck b_go into end of th_fixed_icvs cache line, so it can be stored with
2027  // same NGO store
2028  volatile kmp_uint64 b_go; // STATE => task should proceed (hierarchical)
2029  KMP_ALIGN_CACHE volatile kmp_uint64
2030  b_arrived; // STATE => task reached synch point.
2031  kmp_uint32 *skip_per_level;
2032  kmp_uint32 my_level;
2033  kmp_int32 parent_tid;
2034  kmp_int32 old_tid;
2035  kmp_uint32 depth;
2036  struct kmp_bstate *parent_bar;
2037  kmp_team_t *team;
2038  kmp_uint64 leaf_state;
2039  kmp_uint32 nproc;
2040  kmp_uint8 base_leaf_kids;
2041  kmp_uint8 leaf_kids;
2042  kmp_uint8 offset;
2043  kmp_uint8 wait_flag;
2044  kmp_uint8 use_oncore_barrier;
2045 #if USE_DEBUGGER
2046  // The following field is intended for the debugger solely. Only the worker
2047  // thread itself accesses this field: the worker increases it by 1 when it
2048  // arrives to a barrier.
2049  KMP_ALIGN_CACHE kmp_uint b_worker_arrived;
2050 #endif /* USE_DEBUGGER */
2051 } kmp_bstate_t;
2052 
2053 union KMP_ALIGN_CACHE kmp_barrier_union {
2054  double b_align; /* use worst case alignment */
2055  char b_pad[KMP_PAD(kmp_bstate_t, CACHE_LINE)];
2056  kmp_bstate_t bb;
2057 };
2058 
2059 typedef union kmp_barrier_union kmp_balign_t;
2060 
2061 /* Team barrier needs only non-volatile arrived counter */
2062 union KMP_ALIGN_CACHE kmp_barrier_team_union {
2063  double b_align; /* use worst case alignment */
2064  char b_pad[CACHE_LINE];
2065  struct {
2066  kmp_uint64 b_arrived; /* STATE => task reached synch point. */
2067 #if USE_DEBUGGER
2068  // The following two fields are indended for the debugger solely. Only
2069  // primary thread of the team accesses these fields: the first one is
2070  // increased by 1 when the primary thread arrives to a barrier, the second
2071  // one is increased by one when all the threads arrived.
2072  kmp_uint b_master_arrived;
2073  kmp_uint b_team_arrived;
2074 #endif
2075  };
2076 };
2077 
2078 typedef union kmp_barrier_team_union kmp_balign_team_t;
2079 
2080 /* Padding for Linux* OS pthreads condition variables and mutexes used to signal
2081  threads when a condition changes. This is to workaround an NPTL bug where
2082  padding was added to pthread_cond_t which caused the initialization routine
2083  to write outside of the structure if compiled on pre-NPTL threads. */
2084 #if KMP_OS_WINDOWS
2085 typedef struct kmp_win32_mutex {
2086  /* The Lock */
2087  CRITICAL_SECTION cs;
2088 } kmp_win32_mutex_t;
2089 
2090 typedef struct kmp_win32_cond {
2091  /* Count of the number of waiters. */
2092  int waiters_count_;
2093 
2094  /* Serialize access to <waiters_count_> */
2095  kmp_win32_mutex_t waiters_count_lock_;
2096 
2097  /* Number of threads to release via a <cond_broadcast> or a <cond_signal> */
2098  int release_count_;
2099 
2100  /* Keeps track of the current "generation" so that we don't allow */
2101  /* one thread to steal all the "releases" from the broadcast. */
2102  int wait_generation_count_;
2103 
2104  /* A manual-reset event that's used to block and release waiting threads. */
2105  HANDLE event_;
2106 } kmp_win32_cond_t;
2107 #endif
2108 
2109 #if KMP_OS_UNIX
2110 
2111 union KMP_ALIGN_CACHE kmp_cond_union {
2112  double c_align;
2113  char c_pad[CACHE_LINE];
2114  pthread_cond_t c_cond;
2115 };
2116 
2117 typedef union kmp_cond_union kmp_cond_align_t;
2118 
2119 union KMP_ALIGN_CACHE kmp_mutex_union {
2120  double m_align;
2121  char m_pad[CACHE_LINE];
2122  pthread_mutex_t m_mutex;
2123 };
2124 
2125 typedef union kmp_mutex_union kmp_mutex_align_t;
2126 
2127 #endif /* KMP_OS_UNIX */
2128 
2129 typedef struct kmp_desc_base {
2130  void *ds_stackbase;
2131  size_t ds_stacksize;
2132  int ds_stackgrow;
2133  kmp_thread_t ds_thread;
2134  volatile int ds_tid;
2135  int ds_gtid;
2136 #if KMP_OS_WINDOWS
2137  volatile int ds_alive;
2138  DWORD ds_thread_id;
2139 /* ds_thread keeps thread handle on Windows* OS. It is enough for RTL purposes.
2140  However, debugger support (libomp_db) cannot work with handles, because they
2141  uncomparable. For example, debugger requests info about thread with handle h.
2142  h is valid within debugger process, and meaningless within debugee process.
2143  Even if h is duped by call to DuplicateHandle(), so the result h' is valid
2144  within debugee process, but it is a *new* handle which does *not* equal to
2145  any other handle in debugee... The only way to compare handles is convert
2146  them to system-wide ids. GetThreadId() function is available only in
2147  Longhorn and Server 2003. :-( In contrast, GetCurrentThreadId() is available
2148  on all Windows* OS flavours (including Windows* 95). Thus, we have to get
2149  thread id by call to GetCurrentThreadId() from within the thread and save it
2150  to let libomp_db identify threads. */
2151 #endif /* KMP_OS_WINDOWS */
2152 } kmp_desc_base_t;
2153 
2154 typedef union KMP_ALIGN_CACHE kmp_desc {
2155  double ds_align; /* use worst case alignment */
2156  char ds_pad[KMP_PAD(kmp_desc_base_t, CACHE_LINE)];
2157  kmp_desc_base_t ds;
2158 } kmp_desc_t;
2159 
2160 typedef struct kmp_local {
2161  volatile int this_construct; /* count of single's encountered by thread */
2162  void *reduce_data;
2163 #if KMP_USE_BGET
2164  void *bget_data;
2165  void *bget_list;
2166 #if !USE_CMP_XCHG_FOR_BGET
2167 #ifdef USE_QUEUING_LOCK_FOR_BGET
2168  kmp_lock_t bget_lock; /* Lock for accessing bget free list */
2169 #else
2170  kmp_bootstrap_lock_t bget_lock; // Lock for accessing bget free list. Must be
2171 // bootstrap lock so we can use it at library
2172 // shutdown.
2173 #endif /* USE_LOCK_FOR_BGET */
2174 #endif /* ! USE_CMP_XCHG_FOR_BGET */
2175 #endif /* KMP_USE_BGET */
2176 
2177  PACKED_REDUCTION_METHOD_T
2178  packed_reduction_method; /* stored by __kmpc_reduce*(), used by
2179  __kmpc_end_reduce*() */
2180 
2181 } kmp_local_t;
2182 
2183 #define KMP_CHECK_UPDATE(a, b) \
2184  if ((a) != (b)) \
2185  (a) = (b)
2186 #define KMP_CHECK_UPDATE_SYNC(a, b) \
2187  if ((a) != (b)) \
2188  TCW_SYNC_PTR((a), (b))
2189 
2190 #define get__blocktime(xteam, xtid) \
2191  ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.blocktime)
2192 #define get__bt_set(xteam, xtid) \
2193  ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_set)
2194 #if KMP_USE_MONITOR
2195 #define get__bt_intervals(xteam, xtid) \
2196  ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_intervals)
2197 #endif
2198 
2199 #define get__dynamic_2(xteam, xtid) \
2200  ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.dynamic)
2201 #define get__nproc_2(xteam, xtid) \
2202  ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.nproc)
2203 #define get__sched_2(xteam, xtid) \
2204  ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.sched)
2205 
2206 #define set__blocktime_team(xteam, xtid, xval) \
2207  (((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.blocktime) = \
2208  (xval))
2209 
2210 #if KMP_USE_MONITOR
2211 #define set__bt_intervals_team(xteam, xtid, xval) \
2212  (((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_intervals) = \
2213  (xval))
2214 #endif
2215 
2216 #define set__bt_set_team(xteam, xtid, xval) \
2217  (((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_set) = (xval))
2218 
2219 #define set__dynamic(xthread, xval) \
2220  (((xthread)->th.th_current_task->td_icvs.dynamic) = (xval))
2221 #define get__dynamic(xthread) \
2222  (((xthread)->th.th_current_task->td_icvs.dynamic) ? (FTN_TRUE) : (FTN_FALSE))
2223 
2224 #define set__nproc(xthread, xval) \
2225  (((xthread)->th.th_current_task->td_icvs.nproc) = (xval))
2226 
2227 #define set__thread_limit(xthread, xval) \
2228  (((xthread)->th.th_current_task->td_icvs.thread_limit) = (xval))
2229 
2230 #define set__max_active_levels(xthread, xval) \
2231  (((xthread)->th.th_current_task->td_icvs.max_active_levels) = (xval))
2232 
2233 #define get__max_active_levels(xthread) \
2234  ((xthread)->th.th_current_task->td_icvs.max_active_levels)
2235 
2236 #define set__sched(xthread, xval) \
2237  (((xthread)->th.th_current_task->td_icvs.sched) = (xval))
2238 
2239 #define set__proc_bind(xthread, xval) \
2240  (((xthread)->th.th_current_task->td_icvs.proc_bind) = (xval))
2241 #define get__proc_bind(xthread) \
2242  ((xthread)->th.th_current_task->td_icvs.proc_bind)
2243 
2244 // OpenMP tasking data structures
2245 
2246 typedef enum kmp_tasking_mode {
2247  tskm_immediate_exec = 0,
2248  tskm_extra_barrier = 1,
2249  tskm_task_teams = 2,
2250  tskm_max = 2
2251 } kmp_tasking_mode_t;
2252 
2253 extern kmp_tasking_mode_t
2254  __kmp_tasking_mode; /* determines how/when to execute tasks */
2255 extern int __kmp_task_stealing_constraint;
2256 extern int __kmp_enable_task_throttling;
2257 extern kmp_int32 __kmp_default_device; // Set via OMP_DEFAULT_DEVICE if
2258 // specified, defaults to 0 otherwise
2259 // Set via OMP_MAX_TASK_PRIORITY if specified, defaults to 0 otherwise
2260 extern kmp_int32 __kmp_max_task_priority;
2261 // Set via KMP_TASKLOOP_MIN_TASKS if specified, defaults to 0 otherwise
2262 extern kmp_uint64 __kmp_taskloop_min_tasks;
2263 
2264 /* NOTE: kmp_taskdata_t and kmp_task_t structures allocated in single block with
2265  taskdata first */
2266 #define KMP_TASK_TO_TASKDATA(task) (((kmp_taskdata_t *)task) - 1)
2267 #define KMP_TASKDATA_TO_TASK(taskdata) (kmp_task_t *)(taskdata + 1)
2268 
2269 // The tt_found_tasks flag is a signal to all threads in the team that tasks
2270 // were spawned and queued since the previous barrier release.
2271 #define KMP_TASKING_ENABLED(task_team) \
2272  (TRUE == TCR_SYNC_4((task_team)->tt.tt_found_tasks))
2280 typedef kmp_int32 (*kmp_routine_entry_t)(kmp_int32, void *);
2281 
2282 typedef union kmp_cmplrdata {
2283  kmp_int32 priority;
2284  kmp_routine_entry_t
2285  destructors; /* pointer to function to invoke deconstructors of
2286  firstprivate C++ objects */
2287  /* future data */
2288 } kmp_cmplrdata_t;
2289 
2290 /* sizeof_kmp_task_t passed as arg to kmpc_omp_task call */
2293 typedef struct kmp_task { /* GEH: Shouldn't this be aligned somehow? */
2294  void *shareds;
2295  kmp_routine_entry_t
2296  routine;
2297  kmp_int32 part_id;
2298  kmp_cmplrdata_t
2299  data1; /* Two known optional additions: destructors and priority */
2300  kmp_cmplrdata_t data2; /* Process destructors first, priority second */
2301  /* future data */
2302  /* private vars */
2303 } kmp_task_t;
2304 
2309 typedef struct kmp_taskgroup {
2310  std::atomic<kmp_int32> count; // number of allocated and incomplete tasks
2311  std::atomic<kmp_int32>
2312  cancel_request; // request for cancellation of this taskgroup
2313  struct kmp_taskgroup *parent; // parent taskgroup
2314  // Block of data to perform task reduction
2315  void *reduce_data; // reduction related info
2316  kmp_int32 reduce_num_data; // number of data items to reduce
2317  uintptr_t *gomp_data; // gomp reduction data
2318 } kmp_taskgroup_t;
2319 
2320 // forward declarations
2321 typedef union kmp_depnode kmp_depnode_t;
2322 typedef struct kmp_depnode_list kmp_depnode_list_t;
2323 typedef struct kmp_dephash_entry kmp_dephash_entry_t;
2324 
2325 // macros for checking dep flag as an integer
2326 #define KMP_DEP_IN 0x1
2327 #define KMP_DEP_OUT 0x2
2328 #define KMP_DEP_INOUT 0x3
2329 #define KMP_DEP_MTX 0x4
2330 #define KMP_DEP_SET 0x8
2331 #define KMP_DEP_ALL 0x80
2332 // Compiler sends us this info:
2333 typedef struct kmp_depend_info {
2334  kmp_intptr_t base_addr;
2335  size_t len;
2336  union {
2337  kmp_uint8 flag; // flag as an unsigned char
2338  struct { // flag as a set of 8 bits
2339  unsigned in : 1;
2340  unsigned out : 1;
2341  unsigned mtx : 1;
2342  unsigned set : 1;
2343  unsigned unused : 3;
2344  unsigned all : 1;
2345  } flags;
2346  };
2347 } kmp_depend_info_t;
2348 
2349 // Internal structures to work with task dependencies:
2350 struct kmp_depnode_list {
2351  kmp_depnode_t *node;
2352  kmp_depnode_list_t *next;
2353 };
2354 
2355 // Max number of mutexinoutset dependencies per node
2356 #define MAX_MTX_DEPS 4
2357 
2358 typedef struct kmp_base_depnode {
2359  kmp_depnode_list_t *successors; /* used under lock */
2360  kmp_task_t *task; /* non-NULL if depnode is active, used under lock */
2361  kmp_lock_t *mtx_locks[MAX_MTX_DEPS]; /* lock mutexinoutset dependent tasks */
2362  kmp_int32 mtx_num_locks; /* number of locks in mtx_locks array */
2363  kmp_lock_t lock; /* guards shared fields: task, successors */
2364 #if KMP_SUPPORT_GRAPH_OUTPUT
2365  kmp_uint32 id;
2366 #endif
2367  std::atomic<kmp_int32> npredecessors;
2368  std::atomic<kmp_int32> nrefs;
2369 } kmp_base_depnode_t;
2370 
2371 union KMP_ALIGN_CACHE kmp_depnode {
2372  double dn_align; /* use worst case alignment */
2373  char dn_pad[KMP_PAD(kmp_base_depnode_t, CACHE_LINE)];
2374  kmp_base_depnode_t dn;
2375 };
2376 
2377 struct kmp_dephash_entry {
2378  kmp_intptr_t addr;
2379  kmp_depnode_t *last_out;
2380  kmp_depnode_list_t *last_set;
2381  kmp_depnode_list_t *prev_set;
2382  kmp_uint8 last_flag;
2383  kmp_lock_t *mtx_lock; /* is referenced by depnodes w/mutexinoutset dep */
2384  kmp_dephash_entry_t *next_in_bucket;
2385 };
2386 
2387 typedef struct kmp_dephash {
2388  kmp_dephash_entry_t **buckets;
2389  size_t size;
2390  kmp_depnode_t *last_all;
2391  size_t generation;
2392  kmp_uint32 nelements;
2393  kmp_uint32 nconflicts;
2394 } kmp_dephash_t;
2395 
2396 typedef struct kmp_task_affinity_info {
2397  kmp_intptr_t base_addr;
2398  size_t len;
2399  struct {
2400  bool flag1 : 1;
2401  bool flag2 : 1;
2402  kmp_int32 reserved : 30;
2403  } flags;
2404 } kmp_task_affinity_info_t;
2405 
2406 typedef enum kmp_event_type_t {
2407  KMP_EVENT_UNINITIALIZED = 0,
2408  KMP_EVENT_ALLOW_COMPLETION = 1
2409 } kmp_event_type_t;
2410 
2411 typedef struct {
2412  kmp_event_type_t type;
2413  kmp_tas_lock_t lock;
2414  union {
2415  kmp_task_t *task;
2416  } ed;
2417 } kmp_event_t;
2418 
2419 #ifdef BUILD_TIED_TASK_STACK
2420 
2421 /* Tied Task stack definitions */
2422 typedef struct kmp_stack_block {
2423  kmp_taskdata_t *sb_block[TASK_STACK_BLOCK_SIZE];
2424  struct kmp_stack_block *sb_next;
2425  struct kmp_stack_block *sb_prev;
2426 } kmp_stack_block_t;
2427 
2428 typedef struct kmp_task_stack {
2429  kmp_stack_block_t ts_first_block; // first block of stack entries
2430  kmp_taskdata_t **ts_top; // pointer to the top of stack
2431  kmp_int32 ts_entries; // number of entries on the stack
2432 } kmp_task_stack_t;
2433 
2434 #endif // BUILD_TIED_TASK_STACK
2435 
2436 typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */
2437  /* Compiler flags */ /* Total compiler flags must be 16 bits */
2438  unsigned tiedness : 1; /* task is either tied (1) or untied (0) */
2439  unsigned final : 1; /* task is final(1) so execute immediately */
2440  unsigned merged_if0 : 1; /* no __kmpc_task_{begin/complete}_if0 calls in if0
2441  code path */
2442  unsigned destructors_thunk : 1; /* set if the compiler creates a thunk to
2443  invoke destructors from the runtime */
2444  unsigned proxy : 1; /* task is a proxy task (it will be executed outside the
2445  context of the RTL) */
2446  unsigned priority_specified : 1; /* set if the compiler provides priority
2447  setting for the task */
2448  unsigned detachable : 1; /* 1 == can detach */
2449  unsigned hidden_helper : 1; /* 1 == hidden helper task */
2450  unsigned reserved : 8; /* reserved for compiler use */
2451 
2452  /* Library flags */ /* Total library flags must be 16 bits */
2453  unsigned tasktype : 1; /* task is either explicit(1) or implicit (0) */
2454  unsigned task_serial : 1; // task is executed immediately (1) or deferred (0)
2455  unsigned tasking_ser : 1; // all tasks in team are either executed immediately
2456  // (1) or may be deferred (0)
2457  unsigned team_serial : 1; // entire team is serial (1) [1 thread] or parallel
2458  // (0) [>= 2 threads]
2459  /* If either team_serial or tasking_ser is set, task team may be NULL */
2460  /* Task State Flags: */
2461  unsigned started : 1; /* 1==started, 0==not started */
2462  unsigned executing : 1; /* 1==executing, 0==not executing */
2463  unsigned complete : 1; /* 1==complete, 0==not complete */
2464  unsigned freed : 1; /* 1==freed, 0==allocated */
2465  unsigned native : 1; /* 1==gcc-compiled task, 0==intel */
2466  unsigned reserved31 : 7; /* reserved for library use */
2467 
2468 } kmp_tasking_flags_t;
2469 
2470 struct kmp_taskdata { /* aligned during dynamic allocation */
2471  kmp_int32 td_task_id; /* id, assigned by debugger */
2472  kmp_tasking_flags_t td_flags; /* task flags */
2473  kmp_team_t *td_team; /* team for this task */
2474  kmp_info_p *td_alloc_thread; /* thread that allocated data structures */
2475  /* Currently not used except for perhaps IDB */
2476  kmp_taskdata_t *td_parent; /* parent task */
2477  kmp_int32 td_level; /* task nesting level */
2478  std::atomic<kmp_int32> td_untied_count; // untied task active parts counter
2479  ident_t *td_ident; /* task identifier */
2480  // Taskwait data.
2481  ident_t *td_taskwait_ident;
2482  kmp_uint32 td_taskwait_counter;
2483  kmp_int32 td_taskwait_thread; /* gtid + 1 of thread encountered taskwait */
2484  KMP_ALIGN_CACHE kmp_internal_control_t
2485  td_icvs; /* Internal control variables for the task */
2486  KMP_ALIGN_CACHE std::atomic<kmp_int32>
2487  td_allocated_child_tasks; /* Child tasks (+ current task) not yet
2488  deallocated */
2489  std::atomic<kmp_int32>
2490  td_incomplete_child_tasks; /* Child tasks not yet complete */
2491  kmp_taskgroup_t
2492  *td_taskgroup; // Each task keeps pointer to its current taskgroup
2493  kmp_dephash_t
2494  *td_dephash; // Dependencies for children tasks are tracked from here
2495  kmp_depnode_t
2496  *td_depnode; // Pointer to graph node if this task has dependencies
2497  kmp_task_team_t *td_task_team;
2498  size_t td_size_alloc; // Size of task structure, including shareds etc.
2499 #if defined(KMP_GOMP_COMPAT)
2500  // 4 or 8 byte integers for the loop bounds in GOMP_taskloop
2501  kmp_int32 td_size_loop_bounds;
2502 #endif
2503  kmp_taskdata_t *td_last_tied; // keep tied task for task scheduling constraint
2504 #if defined(KMP_GOMP_COMPAT)
2505  // GOMP sends in a copy function for copy constructors
2506  void (*td_copy_func)(void *, void *);
2507 #endif
2508  kmp_event_t td_allow_completion_event;
2509 #if OMPT_SUPPORT
2510  ompt_task_info_t ompt_task_info;
2511 #endif
2512 }; // struct kmp_taskdata
2513 
2514 // Make sure padding above worked
2515 KMP_BUILD_ASSERT(sizeof(kmp_taskdata_t) % sizeof(void *) == 0);
2516 
2517 // Data for task team but per thread
2518 typedef struct kmp_base_thread_data {
2519  kmp_info_p *td_thr; // Pointer back to thread info
2520  // Used only in __kmp_execute_tasks_template, maybe not avail until task is
2521  // queued?
2522  kmp_bootstrap_lock_t td_deque_lock; // Lock for accessing deque
2523  kmp_taskdata_t *
2524  *td_deque; // Deque of tasks encountered by td_thr, dynamically allocated
2525  kmp_int32 td_deque_size; // Size of deck
2526  kmp_uint32 td_deque_head; // Head of deque (will wrap)
2527  kmp_uint32 td_deque_tail; // Tail of deque (will wrap)
2528  kmp_int32 td_deque_ntasks; // Number of tasks in deque
2529  // GEH: shouldn't this be volatile since used in while-spin?
2530  kmp_int32 td_deque_last_stolen; // Thread number of last successful steal
2531 #ifdef BUILD_TIED_TASK_STACK
2532  kmp_task_stack_t td_susp_tied_tasks; // Stack of suspended tied tasks for task
2533 // scheduling constraint
2534 #endif // BUILD_TIED_TASK_STACK
2535 } kmp_base_thread_data_t;
2536 
2537 #define TASK_DEQUE_BITS 8 // Used solely to define INITIAL_TASK_DEQUE_SIZE
2538 #define INITIAL_TASK_DEQUE_SIZE (1 << TASK_DEQUE_BITS)
2539 
2540 #define TASK_DEQUE_SIZE(td) ((td).td_deque_size)
2541 #define TASK_DEQUE_MASK(td) ((td).td_deque_size - 1)
2542 
2543 typedef union KMP_ALIGN_CACHE kmp_thread_data {
2544  kmp_base_thread_data_t td;
2545  double td_align; /* use worst case alignment */
2546  char td_pad[KMP_PAD(kmp_base_thread_data_t, CACHE_LINE)];
2547 } kmp_thread_data_t;
2548 
2549 typedef struct kmp_task_pri {
2550  kmp_thread_data_t td;
2551  kmp_int32 priority;
2552  kmp_task_pri *next;
2553 } kmp_task_pri_t;
2554 
2555 // Data for task teams which are used when tasking is enabled for the team
2556 typedef struct kmp_base_task_team {
2557  kmp_bootstrap_lock_t
2558  tt_threads_lock; /* Lock used to allocate per-thread part of task team */
2559  /* must be bootstrap lock since used at library shutdown*/
2560 
2561  // TODO: check performance vs kmp_tas_lock_t
2562  kmp_bootstrap_lock_t tt_task_pri_lock; /* Lock to access priority tasks */
2563  kmp_task_pri_t *tt_task_pri_list;
2564 
2565  kmp_task_team_t *tt_next; /* For linking the task team free list */
2566  kmp_thread_data_t
2567  *tt_threads_data; /* Array of per-thread structures for task team */
2568  /* Data survives task team deallocation */
2569  kmp_int32 tt_found_tasks; /* Have we found tasks and queued them while
2570  executing this team? */
2571  /* TRUE means tt_threads_data is set up and initialized */
2572  kmp_int32 tt_nproc; /* #threads in team */
2573  kmp_int32 tt_max_threads; // # entries allocated for threads_data array
2574  kmp_int32 tt_found_proxy_tasks; // found proxy tasks since last barrier
2575  kmp_int32 tt_untied_task_encountered;
2576  std::atomic<kmp_int32> tt_num_task_pri; // number of priority tasks enqueued
2577  // There is hidden helper thread encountered in this task team so that we must
2578  // wait when waiting on task team
2579  kmp_int32 tt_hidden_helper_task_encountered;
2580 
2581  KMP_ALIGN_CACHE
2582  std::atomic<kmp_int32> tt_unfinished_threads; /* #threads still active */
2583 
2584  KMP_ALIGN_CACHE
2585  volatile kmp_uint32
2586  tt_active; /* is the team still actively executing tasks */
2587 } kmp_base_task_team_t;
2588 
2589 union KMP_ALIGN_CACHE kmp_task_team {
2590  kmp_base_task_team_t tt;
2591  double tt_align; /* use worst case alignment */
2592  char tt_pad[KMP_PAD(kmp_base_task_team_t, CACHE_LINE)];
2593 };
2594 
2595 #if (USE_FAST_MEMORY == 3) || (USE_FAST_MEMORY == 5)
2596 // Free lists keep same-size free memory slots for fast memory allocation
2597 // routines
2598 typedef struct kmp_free_list {
2599  void *th_free_list_self; // Self-allocated tasks free list
2600  void *th_free_list_sync; // Self-allocated tasks stolen/returned by other
2601  // threads
2602  void *th_free_list_other; // Non-self free list (to be returned to owner's
2603  // sync list)
2604 } kmp_free_list_t;
2605 #endif
2606 #if KMP_NESTED_HOT_TEAMS
2607 // Hot teams array keeps hot teams and their sizes for given thread. Hot teams
2608 // are not put in teams pool, and they don't put threads in threads pool.
2609 typedef struct kmp_hot_team_ptr {
2610  kmp_team_p *hot_team; // pointer to hot_team of given nesting level
2611  kmp_int32 hot_team_nth; // number of threads allocated for the hot_team
2612 } kmp_hot_team_ptr_t;
2613 #endif
2614 typedef struct kmp_teams_size {
2615  kmp_int32 nteams; // number of teams in a league
2616  kmp_int32 nth; // number of threads in each team of the league
2617 } kmp_teams_size_t;
2618 
2619 // This struct stores a thread that acts as a "root" for a contention
2620 // group. Contention groups are rooted at kmp_root threads, but also at
2621 // each primary thread of each team created in the teams construct.
2622 // This struct therefore also stores a thread_limit associated with
2623 // that contention group, and a counter to track the number of threads
2624 // active in that contention group. Each thread has a list of these: CG
2625 // root threads have an entry in their list in which cg_root refers to
2626 // the thread itself, whereas other workers in the CG will have a
2627 // single entry where cg_root is same as the entry containing their CG
2628 // root. When a thread encounters a teams construct, it will add a new
2629 // entry to the front of its list, because it now roots a new CG.
2630 typedef struct kmp_cg_root {
2631  kmp_info_p *cg_root; // "root" thread for a contention group
2632  // The CG root's limit comes from OMP_THREAD_LIMIT for root threads, or
2633  // thread_limit clause for teams primary threads
2634  kmp_int32 cg_thread_limit;
2635  kmp_int32 cg_nthreads; // Count of active threads in CG rooted at cg_root
2636  struct kmp_cg_root *up; // pointer to higher level CG root in list
2637 } kmp_cg_root_t;
2638 
2639 // OpenMP thread data structures
2640 
2641 typedef struct KMP_ALIGN_CACHE kmp_base_info {
2642  /* Start with the readonly data which is cache aligned and padded. This is
2643  written before the thread starts working by the primary thread. Uber
2644  masters may update themselves later. Usage does not consider serialized
2645  regions. */
2646  kmp_desc_t th_info;
2647  kmp_team_p *th_team; /* team we belong to */
2648  kmp_root_p *th_root; /* pointer to root of task hierarchy */
2649  kmp_info_p *th_next_pool; /* next available thread in the pool */
2650  kmp_disp_t *th_dispatch; /* thread's dispatch data */
2651  int th_in_pool; /* in thread pool (32 bits for TCR/TCW) */
2652 
2653  /* The following are cached from the team info structure */
2654  /* TODO use these in more places as determined to be needed via profiling */
2655  int th_team_nproc; /* number of threads in a team */
2656  kmp_info_p *th_team_master; /* the team's primary thread */
2657  int th_team_serialized; /* team is serialized */
2658  microtask_t th_teams_microtask; /* save entry address for teams construct */
2659  int th_teams_level; /* save initial level of teams construct */
2660 /* it is 0 on device but may be any on host */
2661 
2662 /* The blocktime info is copied from the team struct to the thread struct */
2663 /* at the start of a barrier, and the values stored in the team are used */
2664 /* at points in the code where the team struct is no longer guaranteed */
2665 /* to exist (from the POV of worker threads). */
2666 #if KMP_USE_MONITOR
2667  int th_team_bt_intervals;
2668  int th_team_bt_set;
2669 #else
2670  kmp_uint64 th_team_bt_intervals;
2671 #endif
2672 
2673 #if KMP_AFFINITY_SUPPORTED
2674  kmp_affin_mask_t *th_affin_mask; /* thread's current affinity mask */
2675 #endif
2676  omp_allocator_handle_t th_def_allocator; /* default allocator */
2677  /* The data set by the primary thread at reinit, then R/W by the worker */
2678  KMP_ALIGN_CACHE int
2679  th_set_nproc; /* if > 0, then only use this request for the next fork */
2680 #if KMP_NESTED_HOT_TEAMS
2681  kmp_hot_team_ptr_t *th_hot_teams; /* array of hot teams */
2682 #endif
2683  kmp_proc_bind_t
2684  th_set_proc_bind; /* if != proc_bind_default, use request for next fork */
2685  kmp_teams_size_t
2686  th_teams_size; /* number of teams/threads in teams construct */
2687 #if KMP_AFFINITY_SUPPORTED
2688  int th_current_place; /* place currently bound to */
2689  int th_new_place; /* place to bind to in par reg */
2690  int th_first_place; /* first place in partition */
2691  int th_last_place; /* last place in partition */
2692 #endif
2693  int th_prev_level; /* previous level for affinity format */
2694  int th_prev_num_threads; /* previous num_threads for affinity format */
2695 #if USE_ITT_BUILD
2696  kmp_uint64 th_bar_arrive_time; /* arrival to barrier timestamp */
2697  kmp_uint64 th_bar_min_time; /* minimum arrival time at the barrier */
2698  kmp_uint64 th_frame_time; /* frame timestamp */
2699 #endif /* USE_ITT_BUILD */
2700  kmp_local_t th_local;
2701  struct private_common *th_pri_head;
2702 
2703  /* Now the data only used by the worker (after initial allocation) */
2704  /* TODO the first serial team should actually be stored in the info_t
2705  structure. this will help reduce initial allocation overhead */
2706  KMP_ALIGN_CACHE kmp_team_p
2707  *th_serial_team; /*serialized team held in reserve*/
2708 
2709 #if OMPT_SUPPORT
2710  ompt_thread_info_t ompt_thread_info;
2711 #endif
2712 
2713  /* The following are also read by the primary thread during reinit */
2714  struct common_table *th_pri_common;
2715 
2716  volatile kmp_uint32 th_spin_here; /* thread-local location for spinning */
2717  /* while awaiting queuing lock acquire */
2718 
2719  volatile void *th_sleep_loc; // this points at a kmp_flag<T>
2720  flag_type th_sleep_loc_type; // enum type of flag stored in th_sleep_loc
2721 
2722  ident_t *th_ident;
2723  unsigned th_x; // Random number generator data
2724  unsigned th_a; // Random number generator data
2725 
2726  /* Tasking-related data for the thread */
2727  kmp_task_team_t *th_task_team; // Task team struct
2728  kmp_taskdata_t *th_current_task; // Innermost Task being executed
2729  kmp_uint8 th_task_state; // alternating 0/1 for task team identification
2730  kmp_uint8 *th_task_state_memo_stack; // Stack holding memos of th_task_state
2731  // at nested levels
2732  kmp_uint32 th_task_state_top; // Top element of th_task_state_memo_stack
2733  kmp_uint32 th_task_state_stack_sz; // Size of th_task_state_memo_stack
2734  kmp_uint32 th_reap_state; // Non-zero indicates thread is not
2735  // tasking, thus safe to reap
2736 
2737  /* More stuff for keeping track of active/sleeping threads (this part is
2738  written by the worker thread) */
2739  kmp_uint8 th_active_in_pool; // included in count of #active threads in pool
2740  int th_active; // ! sleeping; 32 bits for TCR/TCW
2741  std::atomic<kmp_uint32> th_used_in_team; // Flag indicating use in team
2742  // 0 = not used in team; 1 = used in team;
2743  // 2 = transitioning to not used in team; 3 = transitioning to used in team
2744  struct cons_header *th_cons; // used for consistency check
2745 #if KMP_USE_HIER_SCHED
2746  // used for hierarchical scheduling
2747  kmp_hier_private_bdata_t *th_hier_bar_data;
2748 #endif
2749 
2750  /* Add the syncronizing data which is cache aligned and padded. */
2751  KMP_ALIGN_CACHE kmp_balign_t th_bar[bs_last_barrier];
2752 
2753  KMP_ALIGN_CACHE volatile kmp_int32
2754  th_next_waiting; /* gtid+1 of next thread on lock wait queue, 0 if none */
2755 
2756 #if (USE_FAST_MEMORY == 3) || (USE_FAST_MEMORY == 5)
2757 #define NUM_LISTS 4
2758  kmp_free_list_t th_free_lists[NUM_LISTS]; // Free lists for fast memory
2759 // allocation routines
2760 #endif
2761 
2762 #if KMP_OS_WINDOWS
2763  kmp_win32_cond_t th_suspend_cv;
2764  kmp_win32_mutex_t th_suspend_mx;
2765  std::atomic<int> th_suspend_init;
2766 #endif
2767 #if KMP_OS_UNIX
2768  kmp_cond_align_t th_suspend_cv;
2769  kmp_mutex_align_t th_suspend_mx;
2770  std::atomic<int> th_suspend_init_count;
2771 #endif
2772 
2773 #if USE_ITT_BUILD
2774  kmp_itt_mark_t th_itt_mark_single;
2775 // alignment ???
2776 #endif /* USE_ITT_BUILD */
2777 #if KMP_STATS_ENABLED
2778  kmp_stats_list *th_stats;
2779 #endif
2780 #if KMP_OS_UNIX
2781  std::atomic<bool> th_blocking;
2782 #endif
2783  kmp_cg_root_t *th_cg_roots; // list of cg_roots associated with this thread
2784 } kmp_base_info_t;
2785 
2786 typedef union KMP_ALIGN_CACHE kmp_info {
2787  double th_align; /* use worst case alignment */
2788  char th_pad[KMP_PAD(kmp_base_info_t, CACHE_LINE)];
2789  kmp_base_info_t th;
2790 } kmp_info_t;
2791 
2792 // OpenMP thread team data structures
2793 
2794 typedef struct kmp_base_data {
2795  volatile kmp_uint32 t_value;
2796 } kmp_base_data_t;
2797 
2798 typedef union KMP_ALIGN_CACHE kmp_sleep_team {
2799  double dt_align; /* use worst case alignment */
2800  char dt_pad[KMP_PAD(kmp_base_data_t, CACHE_LINE)];
2801  kmp_base_data_t dt;
2802 } kmp_sleep_team_t;
2803 
2804 typedef union KMP_ALIGN_CACHE kmp_ordered_team {
2805  double dt_align; /* use worst case alignment */
2806  char dt_pad[KMP_PAD(kmp_base_data_t, CACHE_LINE)];
2807  kmp_base_data_t dt;
2808 } kmp_ordered_team_t;
2809 
2810 typedef int (*launch_t)(int gtid);
2811 
2812 /* Minimum number of ARGV entries to malloc if necessary */
2813 #define KMP_MIN_MALLOC_ARGV_ENTRIES 100
2814 
2815 // Set up how many argv pointers will fit in cache lines containing
2816 // t_inline_argv. Historically, we have supported at least 96 bytes. Using a
2817 // larger value for more space between the primary write/worker read section and
2818 // read/write by all section seems to buy more performance on EPCC PARALLEL.
2819 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
2820 #define KMP_INLINE_ARGV_BYTES \
2821  (4 * CACHE_LINE - \
2822  ((3 * KMP_PTR_SKIP + 2 * sizeof(int) + 2 * sizeof(kmp_int8) + \
2823  sizeof(kmp_int16) + sizeof(kmp_uint32)) % \
2824  CACHE_LINE))
2825 #else
2826 #define KMP_INLINE_ARGV_BYTES \
2827  (2 * CACHE_LINE - ((3 * KMP_PTR_SKIP + 2 * sizeof(int)) % CACHE_LINE))
2828 #endif
2829 #define KMP_INLINE_ARGV_ENTRIES (int)(KMP_INLINE_ARGV_BYTES / KMP_PTR_SKIP)
2830 
2831 typedef struct KMP_ALIGN_CACHE kmp_base_team {
2832  // Synchronization Data
2833  // ---------------------------------------------------------------------------
2834  KMP_ALIGN_CACHE kmp_ordered_team_t t_ordered;
2835  kmp_balign_team_t t_bar[bs_last_barrier];
2836  std::atomic<int> t_construct; // count of single directive encountered by team
2837  char pad[sizeof(kmp_lock_t)]; // padding to maintain performance on big iron
2838 
2839  // [0] - parallel / [1] - worksharing task reduction data shared by taskgroups
2840  std::atomic<void *> t_tg_reduce_data[2]; // to support task modifier
2841  std::atomic<int> t_tg_fini_counter[2]; // sync end of task reductions
2842 
2843  // Primary thread only
2844  // ---------------------------------------------------------------------------
2845  KMP_ALIGN_CACHE int t_master_tid; // tid of primary thread in parent team
2846  int t_master_this_cons; // "this_construct" single counter of primary thread
2847  // in parent team
2848  ident_t *t_ident; // if volatile, have to change too much other crud to
2849  // volatile too
2850  kmp_team_p *t_parent; // parent team
2851  kmp_team_p *t_next_pool; // next free team in the team pool
2852  kmp_disp_t *t_dispatch; // thread's dispatch data
2853  kmp_task_team_t *t_task_team[2]; // Task team struct; switch between 2
2854  kmp_proc_bind_t t_proc_bind; // bind type for par region
2855 #if USE_ITT_BUILD
2856  kmp_uint64 t_region_time; // region begin timestamp
2857 #endif /* USE_ITT_BUILD */
2858 
2859  // Primary thread write, workers read
2860  // --------------------------------------------------------------------------
2861  KMP_ALIGN_CACHE void **t_argv;
2862  int t_argc;
2863  int t_nproc; // number of threads in team
2864  microtask_t t_pkfn;
2865  launch_t t_invoke; // procedure to launch the microtask
2866 
2867 #if OMPT_SUPPORT
2868  ompt_team_info_t ompt_team_info;
2869  ompt_lw_taskteam_t *ompt_serialized_team_info;
2870 #endif
2871 
2872 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
2873  kmp_int8 t_fp_control_saved;
2874  kmp_int8 t_pad2b;
2875  kmp_int16 t_x87_fpu_control_word; // FP control regs
2876  kmp_uint32 t_mxcsr;
2877 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2878 
2879  void *t_inline_argv[KMP_INLINE_ARGV_ENTRIES];
2880 
2881  KMP_ALIGN_CACHE kmp_info_t **t_threads;
2882  kmp_taskdata_t
2883  *t_implicit_task_taskdata; // Taskdata for the thread's implicit task
2884  int t_level; // nested parallel level
2885 
2886  KMP_ALIGN_CACHE int t_max_argc;
2887  int t_max_nproc; // max threads this team can handle (dynamically expandable)
2888  int t_serialized; // levels deep of serialized teams
2889  dispatch_shared_info_t *t_disp_buffer; // buffers for dispatch system
2890  int t_id; // team's id, assigned by debugger.
2891  int t_active_level; // nested active parallel level
2892  kmp_r_sched_t t_sched; // run-time schedule for the team
2893 #if KMP_AFFINITY_SUPPORTED
2894  int t_first_place; // first & last place in parent thread's partition.
2895  int t_last_place; // Restore these values to primary thread after par region.
2896 #endif // KMP_AFFINITY_SUPPORTED
2897  int t_display_affinity;
2898  int t_size_changed; // team size was changed?: 0: no, 1: yes, -1: changed via
2899  // omp_set_num_threads() call
2900  omp_allocator_handle_t t_def_allocator; /* default allocator */
2901 
2902 // Read/write by workers as well
2903 #if (KMP_ARCH_X86 || KMP_ARCH_X86_64)
2904  // Using CACHE_LINE=64 reduces memory footprint, but causes a big perf
2905  // regression of epcc 'parallel' and 'barrier' on fxe256lin01. This extra
2906  // padding serves to fix the performance of epcc 'parallel' and 'barrier' when
2907  // CACHE_LINE=64. TODO: investigate more and get rid if this padding.
2908  char dummy_padding[1024];
2909 #endif
2910  // Internal control stack for additional nested teams.
2911  KMP_ALIGN_CACHE kmp_internal_control_t *t_control_stack_top;
2912  // for SERIALIZED teams nested 2 or more levels deep
2913  // typed flag to store request state of cancellation
2914  std::atomic<kmp_int32> t_cancel_request;
2915  int t_master_active; // save on fork, restore on join
2916  void *t_copypriv_data; // team specific pointer to copyprivate data array
2917 #if KMP_OS_WINDOWS
2918  std::atomic<kmp_uint32> t_copyin_counter;
2919 #endif
2920 #if USE_ITT_BUILD
2921  void *t_stack_id; // team specific stack stitching id (for ittnotify)
2922 #endif /* USE_ITT_BUILD */
2923  distributedBarrier *b; // Distributed barrier data associated with team
2924 } kmp_base_team_t;
2925 
2926 union KMP_ALIGN_CACHE kmp_team {
2927  kmp_base_team_t t;
2928  double t_align; /* use worst case alignment */
2929  char t_pad[KMP_PAD(kmp_base_team_t, CACHE_LINE)];
2930 };
2931 
2932 typedef union KMP_ALIGN_CACHE kmp_time_global {
2933  double dt_align; /* use worst case alignment */
2934  char dt_pad[KMP_PAD(kmp_base_data_t, CACHE_LINE)];
2935  kmp_base_data_t dt;
2936 } kmp_time_global_t;
2937 
2938 typedef struct kmp_base_global {
2939  /* cache-aligned */
2940  kmp_time_global_t g_time;
2941 
2942  /* non cache-aligned */
2943  volatile int g_abort;
2944  volatile int g_done;
2945 
2946  int g_dynamic;
2947  enum dynamic_mode g_dynamic_mode;
2948 } kmp_base_global_t;
2949 
2950 typedef union KMP_ALIGN_CACHE kmp_global {
2951  kmp_base_global_t g;
2952  double g_align; /* use worst case alignment */
2953  char g_pad[KMP_PAD(kmp_base_global_t, CACHE_LINE)];
2954 } kmp_global_t;
2955 
2956 typedef struct kmp_base_root {
2957  // TODO: GEH - combine r_active with r_in_parallel then r_active ==
2958  // (r_in_parallel>= 0)
2959  // TODO: GEH - then replace r_active with t_active_levels if we can to reduce
2960  // the synch overhead or keeping r_active
2961  volatile int r_active; /* TRUE if some region in a nest has > 1 thread */
2962  // keeps a count of active parallel regions per root
2963  std::atomic<int> r_in_parallel;
2964  // GEH: This is misnamed, should be r_active_levels
2965  kmp_team_t *r_root_team;
2966  kmp_team_t *r_hot_team;
2967  kmp_info_t *r_uber_thread;
2968  kmp_lock_t r_begin_lock;
2969  volatile int r_begin;
2970  int r_blocktime; /* blocktime for this root and descendants */
2971 #if KMP_AFFINITY_SUPPORTED
2972  int r_affinity_assigned;
2973 #endif // KMP_AFFINITY_SUPPORTED
2974 } kmp_base_root_t;
2975 
2976 typedef union KMP_ALIGN_CACHE kmp_root {
2977  kmp_base_root_t r;
2978  double r_align; /* use worst case alignment */
2979  char r_pad[KMP_PAD(kmp_base_root_t, CACHE_LINE)];
2980 } kmp_root_t;
2981 
2982 struct fortran_inx_info {
2983  kmp_int32 data;
2984 };
2985 
2986 /* ------------------------------------------------------------------------ */
2987 
2988 extern int __kmp_settings;
2989 extern int __kmp_duplicate_library_ok;
2990 #if USE_ITT_BUILD
2991 extern int __kmp_forkjoin_frames;
2992 extern int __kmp_forkjoin_frames_mode;
2993 #endif
2994 extern PACKED_REDUCTION_METHOD_T __kmp_force_reduction_method;
2995 extern int __kmp_determ_red;
2996 
2997 #ifdef KMP_DEBUG
2998 extern int kmp_a_debug;
2999 extern int kmp_b_debug;
3000 extern int kmp_c_debug;
3001 extern int kmp_d_debug;
3002 extern int kmp_e_debug;
3003 extern int kmp_f_debug;
3004 #endif /* KMP_DEBUG */
3005 
3006 /* For debug information logging using rotating buffer */
3007 #define KMP_DEBUG_BUF_LINES_INIT 512
3008 #define KMP_DEBUG_BUF_LINES_MIN 1
3009 
3010 #define KMP_DEBUG_BUF_CHARS_INIT 128
3011 #define KMP_DEBUG_BUF_CHARS_MIN 2
3012 
3013 extern int
3014  __kmp_debug_buf; /* TRUE means use buffer, FALSE means print to stderr */
3015 extern int __kmp_debug_buf_lines; /* How many lines of debug stored in buffer */
3016 extern int
3017  __kmp_debug_buf_chars; /* How many characters allowed per line in buffer */
3018 extern int __kmp_debug_buf_atomic; /* TRUE means use atomic update of buffer
3019  entry pointer */
3020 
3021 extern char *__kmp_debug_buffer; /* Debug buffer itself */
3022 extern std::atomic<int> __kmp_debug_count; /* Counter for number of lines
3023  printed in buffer so far */
3024 extern int __kmp_debug_buf_warn_chars; /* Keep track of char increase
3025  recommended in warnings */
3026 /* end rotating debug buffer */
3027 
3028 #ifdef KMP_DEBUG
3029 extern int __kmp_par_range; /* +1 => only go par for constructs in range */
3030 
3031 #define KMP_PAR_RANGE_ROUTINE_LEN 1024
3032 extern char __kmp_par_range_routine[KMP_PAR_RANGE_ROUTINE_LEN];
3033 #define KMP_PAR_RANGE_FILENAME_LEN 1024
3034 extern char __kmp_par_range_filename[KMP_PAR_RANGE_FILENAME_LEN];
3035 extern int __kmp_par_range_lb;
3036 extern int __kmp_par_range_ub;
3037 #endif
3038 
3039 /* For printing out dynamic storage map for threads and teams */
3040 extern int
3041  __kmp_storage_map; /* True means print storage map for threads and teams */
3042 extern int __kmp_storage_map_verbose; /* True means storage map includes
3043  placement info */
3044 extern int __kmp_storage_map_verbose_specified;
3045 
3046 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3047 extern kmp_cpuinfo_t __kmp_cpuinfo;
3048 static inline bool __kmp_is_hybrid_cpu() { return __kmp_cpuinfo.flags.hybrid; }
3049 #else
3050 static inline bool __kmp_is_hybrid_cpu() { return false; }
3051 #endif
3052 
3053 extern volatile int __kmp_init_serial;
3054 extern volatile int __kmp_init_gtid;
3055 extern volatile int __kmp_init_common;
3056 extern volatile int __kmp_init_middle;
3057 extern volatile int __kmp_init_parallel;
3058 #if KMP_USE_MONITOR
3059 extern volatile int __kmp_init_monitor;
3060 #endif
3061 extern volatile int __kmp_init_user_locks;
3062 extern volatile int __kmp_init_hidden_helper_threads;
3063 extern int __kmp_init_counter;
3064 extern int __kmp_root_counter;
3065 extern int __kmp_version;
3066 
3067 /* list of address of allocated caches for commons */
3068 extern kmp_cached_addr_t *__kmp_threadpriv_cache_list;
3069 
3070 /* Barrier algorithm types and options */
3071 extern kmp_uint32 __kmp_barrier_gather_bb_dflt;
3072 extern kmp_uint32 __kmp_barrier_release_bb_dflt;
3073 extern kmp_bar_pat_e __kmp_barrier_gather_pat_dflt;
3074 extern kmp_bar_pat_e __kmp_barrier_release_pat_dflt;
3075 extern kmp_uint32 __kmp_barrier_gather_branch_bits[bs_last_barrier];
3076 extern kmp_uint32 __kmp_barrier_release_branch_bits[bs_last_barrier];
3077 extern kmp_bar_pat_e __kmp_barrier_gather_pattern[bs_last_barrier];
3078 extern kmp_bar_pat_e __kmp_barrier_release_pattern[bs_last_barrier];
3079 extern char const *__kmp_barrier_branch_bit_env_name[bs_last_barrier];
3080 extern char const *__kmp_barrier_pattern_env_name[bs_last_barrier];
3081 extern char const *__kmp_barrier_type_name[bs_last_barrier];
3082 extern char const *__kmp_barrier_pattern_name[bp_last_bar];
3083 
3084 /* Global Locks */
3085 extern kmp_bootstrap_lock_t __kmp_initz_lock; /* control initialization */
3086 extern kmp_bootstrap_lock_t __kmp_forkjoin_lock; /* control fork/join access */
3087 extern kmp_bootstrap_lock_t __kmp_task_team_lock;
3088 extern kmp_bootstrap_lock_t
3089  __kmp_exit_lock; /* exit() is not always thread-safe */
3090 #if KMP_USE_MONITOR
3091 extern kmp_bootstrap_lock_t
3092  __kmp_monitor_lock; /* control monitor thread creation */
3093 #endif
3094 extern kmp_bootstrap_lock_t
3095  __kmp_tp_cached_lock; /* used for the hack to allow threadprivate cache and
3096  __kmp_threads expansion to co-exist */
3097 
3098 extern kmp_lock_t __kmp_global_lock; /* control OS/global access */
3099 extern kmp_queuing_lock_t __kmp_dispatch_lock; /* control dispatch access */
3100 extern kmp_lock_t __kmp_debug_lock; /* control I/O access for KMP_DEBUG */
3101 
3102 extern enum library_type __kmp_library;
3103 
3104 extern enum sched_type __kmp_sched; /* default runtime scheduling */
3105 extern enum sched_type __kmp_static; /* default static scheduling method */
3106 extern enum sched_type __kmp_guided; /* default guided scheduling method */
3107 extern enum sched_type __kmp_auto; /* default auto scheduling method */
3108 extern int __kmp_chunk; /* default runtime chunk size */
3109 extern int __kmp_force_monotonic; /* whether monotonic scheduling forced */
3110 
3111 extern size_t __kmp_stksize; /* stack size per thread */
3112 #if KMP_USE_MONITOR
3113 extern size_t __kmp_monitor_stksize; /* stack size for monitor thread */
3114 #endif
3115 extern size_t __kmp_stkoffset; /* stack offset per thread */
3116 extern int __kmp_stkpadding; /* Should we pad root thread(s) stack */
3117 
3118 extern size_t
3119  __kmp_malloc_pool_incr; /* incremental size of pool for kmp_malloc() */
3120 extern int __kmp_env_stksize; /* was KMP_STACKSIZE specified? */
3121 extern int __kmp_env_blocktime; /* was KMP_BLOCKTIME specified? */
3122 extern int __kmp_env_checks; /* was KMP_CHECKS specified? */
3123 extern int __kmp_env_consistency_check; // was KMP_CONSISTENCY_CHECK specified?
3124 extern int __kmp_generate_warnings; /* should we issue warnings? */
3125 extern int __kmp_reserve_warn; /* have we issued reserve_threads warning? */
3126 
3127 #ifdef DEBUG_SUSPEND
3128 extern int __kmp_suspend_count; /* count inside __kmp_suspend_template() */
3129 #endif
3130 
3131 extern kmp_int32 __kmp_use_yield;
3132 extern kmp_int32 __kmp_use_yield_exp_set;
3133 extern kmp_uint32 __kmp_yield_init;
3134 extern kmp_uint32 __kmp_yield_next;
3135 extern kmp_uint64 __kmp_pause_init;
3136 
3137 /* ------------------------------------------------------------------------- */
3138 extern int __kmp_allThreadsSpecified;
3139 
3140 extern size_t __kmp_align_alloc;
3141 /* following data protected by initialization routines */
3142 extern int __kmp_xproc; /* number of processors in the system */
3143 extern int __kmp_avail_proc; /* number of processors available to the process */
3144 extern size_t __kmp_sys_min_stksize; /* system-defined minimum stack size */
3145 extern int __kmp_sys_max_nth; /* system-imposed maximum number of threads */
3146 // maximum total number of concurrently-existing threads on device
3147 extern int __kmp_max_nth;
3148 // maximum total number of concurrently-existing threads in a contention group
3149 extern int __kmp_cg_max_nth;
3150 extern int __kmp_teams_max_nth; // max threads used in a teams construct
3151 extern int __kmp_threads_capacity; /* capacity of the arrays __kmp_threads and
3152  __kmp_root */
3153 extern int __kmp_dflt_team_nth; /* default number of threads in a parallel
3154  region a la OMP_NUM_THREADS */
3155 extern int __kmp_dflt_team_nth_ub; /* upper bound on "" determined at serial
3156  initialization */
3157 extern int __kmp_tp_capacity; /* capacity of __kmp_threads if threadprivate is
3158  used (fixed) */
3159 extern int __kmp_tp_cached; /* whether threadprivate cache has been created
3160  (__kmpc_threadprivate_cached()) */
3161 extern int __kmp_dflt_blocktime; /* number of milliseconds to wait before
3162  blocking (env setting) */
3163 #if KMP_USE_MONITOR
3164 extern int
3165  __kmp_monitor_wakeups; /* number of times monitor wakes up per second */
3166 extern int __kmp_bt_intervals; /* number of monitor timestamp intervals before
3167  blocking */
3168 #endif
3169 #ifdef KMP_ADJUST_BLOCKTIME
3170 extern int __kmp_zero_bt; /* whether blocktime has been forced to zero */
3171 #endif /* KMP_ADJUST_BLOCKTIME */
3172 #ifdef KMP_DFLT_NTH_CORES
3173 extern int __kmp_ncores; /* Total number of cores for threads placement */
3174 #endif
3175 /* Number of millisecs to delay on abort for Intel(R) VTune(TM) tools */
3176 extern int __kmp_abort_delay;
3177 
3178 extern int __kmp_need_register_atfork_specified;
3179 extern int __kmp_need_register_atfork; /* At initialization, call pthread_atfork
3180  to install fork handler */
3181 extern int __kmp_gtid_mode; /* Method of getting gtid, values:
3182  0 - not set, will be set at runtime
3183  1 - using stack search
3184  2 - dynamic TLS (pthread_getspecific(Linux* OS/OS
3185  X*) or TlsGetValue(Windows* OS))
3186  3 - static TLS (__declspec(thread) __kmp_gtid),
3187  Linux* OS .so only. */
3188 extern int
3189  __kmp_adjust_gtid_mode; /* If true, adjust method based on #threads */
3190 #ifdef KMP_TDATA_GTID
3191 extern KMP_THREAD_LOCAL int __kmp_gtid;
3192 #endif
3193 extern int __kmp_tls_gtid_min; /* #threads below which use sp search for gtid */
3194 extern int __kmp_foreign_tp; // If true, separate TP var for each foreign thread
3195 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3196 extern int __kmp_inherit_fp_control; // copy fp creg(s) parent->workers at fork
3197 extern kmp_int16 __kmp_init_x87_fpu_control_word; // init thread's FP ctrl reg
3198 extern kmp_uint32 __kmp_init_mxcsr; /* init thread's mxscr */
3199 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
3200 
3201 // max_active_levels for nested parallelism enabled by default via
3202 // OMP_MAX_ACTIVE_LEVELS, OMP_NESTED, OMP_NUM_THREADS, and OMP_PROC_BIND
3203 extern int __kmp_dflt_max_active_levels;
3204 // Indicates whether value of __kmp_dflt_max_active_levels was already
3205 // explicitly set by OMP_MAX_ACTIVE_LEVELS or OMP_NESTED=false
3206 extern bool __kmp_dflt_max_active_levels_set;
3207 extern int __kmp_dispatch_num_buffers; /* max possible dynamic loops in
3208  concurrent execution per team */
3209 #if KMP_NESTED_HOT_TEAMS
3210 extern int __kmp_hot_teams_mode;
3211 extern int __kmp_hot_teams_max_level;
3212 #endif
3213 
3214 #if KMP_OS_LINUX
3215 extern enum clock_function_type __kmp_clock_function;
3216 extern int __kmp_clock_function_param;
3217 #endif /* KMP_OS_LINUX */
3218 
3219 #if KMP_MIC_SUPPORTED
3220 extern enum mic_type __kmp_mic_type;
3221 #endif
3222 
3223 #ifdef USE_LOAD_BALANCE
3224 extern double __kmp_load_balance_interval; // load balance algorithm interval
3225 #endif /* USE_LOAD_BALANCE */
3226 
3227 // OpenMP 3.1 - Nested num threads array
3228 typedef struct kmp_nested_nthreads_t {
3229  int *nth;
3230  int size;
3231  int used;
3232 } kmp_nested_nthreads_t;
3233 
3234 extern kmp_nested_nthreads_t __kmp_nested_nth;
3235 
3236 #if KMP_USE_ADAPTIVE_LOCKS
3237 
3238 // Parameters for the speculative lock backoff system.
3239 struct kmp_adaptive_backoff_params_t {
3240  // Number of soft retries before it counts as a hard retry.
3241  kmp_uint32 max_soft_retries;
3242  // Badness is a bit mask : 0,1,3,7,15,... on each hard failure we move one to
3243  // the right
3244  kmp_uint32 max_badness;
3245 };
3246 
3247 extern kmp_adaptive_backoff_params_t __kmp_adaptive_backoff_params;
3248 
3249 #if KMP_DEBUG_ADAPTIVE_LOCKS
3250 extern const char *__kmp_speculative_statsfile;
3251 #endif
3252 
3253 #endif // KMP_USE_ADAPTIVE_LOCKS
3254 
3255 extern int __kmp_display_env; /* TRUE or FALSE */
3256 extern int __kmp_display_env_verbose; /* TRUE if OMP_DISPLAY_ENV=VERBOSE */
3257 extern int __kmp_omp_cancellation; /* TRUE or FALSE */
3258 extern int __kmp_nteams;
3259 extern int __kmp_teams_thread_limit;
3260 
3261 /* ------------------------------------------------------------------------- */
3262 
3263 /* the following are protected by the fork/join lock */
3264 /* write: lock read: anytime */
3265 extern kmp_info_t **__kmp_threads; /* Descriptors for the threads */
3266 /* read/write: lock */
3267 extern volatile kmp_team_t *__kmp_team_pool;
3268 extern volatile kmp_info_t *__kmp_thread_pool;
3269 extern kmp_info_t *__kmp_thread_pool_insert_pt;
3270 
3271 // total num threads reachable from some root thread including all root threads
3272 extern volatile int __kmp_nth;
3273 /* total number of threads reachable from some root thread including all root
3274  threads, and those in the thread pool */
3275 extern volatile int __kmp_all_nth;
3276 extern std::atomic<int> __kmp_thread_pool_active_nth;
3277 
3278 extern kmp_root_t **__kmp_root; /* root of thread hierarchy */
3279 /* end data protected by fork/join lock */
3280 /* ------------------------------------------------------------------------- */
3281 
3282 #define __kmp_get_gtid() __kmp_get_global_thread_id()
3283 #define __kmp_entry_gtid() __kmp_get_global_thread_id_reg()
3284 #define __kmp_get_tid() (__kmp_tid_from_gtid(__kmp_get_gtid()))
3285 #define __kmp_get_team() (__kmp_threads[(__kmp_get_gtid())]->th.th_team)
3286 #define __kmp_get_thread() (__kmp_thread_from_gtid(__kmp_get_gtid()))
3287 
3288 // AT: Which way is correct?
3289 // AT: 1. nproc = __kmp_threads[ ( gtid ) ] -> th.th_team -> t.t_nproc;
3290 // AT: 2. nproc = __kmp_threads[ ( gtid ) ] -> th.th_team_nproc;
3291 #define __kmp_get_team_num_threads(gtid) \
3292  (__kmp_threads[(gtid)]->th.th_team->t.t_nproc)
3293 
3294 static inline bool KMP_UBER_GTID(int gtid) {
3295  KMP_DEBUG_ASSERT(gtid >= KMP_GTID_MIN);
3296  KMP_DEBUG_ASSERT(gtid < __kmp_threads_capacity);
3297  return (gtid >= 0 && __kmp_root[gtid] && __kmp_threads[gtid] &&
3298  __kmp_threads[gtid] == __kmp_root[gtid]->r.r_uber_thread);
3299 }
3300 
3301 static inline int __kmp_tid_from_gtid(int gtid) {
3302  KMP_DEBUG_ASSERT(gtid >= 0);
3303  return __kmp_threads[gtid]->th.th_info.ds.ds_tid;
3304 }
3305 
3306 static inline int __kmp_gtid_from_tid(int tid, const kmp_team_t *team) {
3307  KMP_DEBUG_ASSERT(tid >= 0 && team);
3308  return team->t.t_threads[tid]->th.th_info.ds.ds_gtid;
3309 }
3310 
3311 static inline int __kmp_gtid_from_thread(const kmp_info_t *thr) {
3312  KMP_DEBUG_ASSERT(thr);
3313  return thr->th.th_info.ds.ds_gtid;
3314 }
3315 
3316 static inline kmp_info_t *__kmp_thread_from_gtid(int gtid) {
3317  KMP_DEBUG_ASSERT(gtid >= 0);
3318  return __kmp_threads[gtid];
3319 }
3320 
3321 static inline kmp_team_t *__kmp_team_from_gtid(int gtid) {
3322  KMP_DEBUG_ASSERT(gtid >= 0);
3323  return __kmp_threads[gtid]->th.th_team;
3324 }
3325 
3326 static inline void __kmp_assert_valid_gtid(kmp_int32 gtid) {
3327  if (UNLIKELY(gtid < 0 || gtid >= __kmp_threads_capacity))
3328  KMP_FATAL(ThreadIdentInvalid);
3329 }
3330 
3331 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
3332 extern int __kmp_user_level_mwait; // TRUE or FALSE; from KMP_USER_LEVEL_MWAIT
3333 extern int __kmp_umwait_enabled; // Runtime check if user-level mwait enabled
3334 extern int __kmp_mwait_enabled; // Runtime check if ring3 mwait is enabled
3335 extern int __kmp_mwait_hints; // Hints to pass in to mwait
3336 #endif
3337 
3338 #if KMP_HAVE_UMWAIT
3339 extern int __kmp_waitpkg_enabled; // Runtime check if waitpkg exists
3340 extern int __kmp_tpause_state; // 0 (default), 1=C0.1, 2=C0.2; from KMP_TPAUSE
3341 extern int __kmp_tpause_hint; // 1=C0.1 (default), 0=C0.2; from KMP_TPAUSE
3342 extern int __kmp_tpause_enabled; // 0 (default), 1 (KMP_TPAUSE is non-zero)
3343 #endif
3344 
3345 /* ------------------------------------------------------------------------- */
3346 
3347 extern kmp_global_t __kmp_global; /* global status */
3348 
3349 extern kmp_info_t __kmp_monitor;
3350 // For Debugging Support Library
3351 extern std::atomic<kmp_int32> __kmp_team_counter;
3352 // For Debugging Support Library
3353 extern std::atomic<kmp_int32> __kmp_task_counter;
3354 
3355 #if USE_DEBUGGER
3356 #define _KMP_GEN_ID(counter) \
3357  (__kmp_debugging ? KMP_ATOMIC_INC(&counter) + 1 : ~0)
3358 #else
3359 #define _KMP_GEN_ID(counter) (~0)
3360 #endif /* USE_DEBUGGER */
3361 
3362 #define KMP_GEN_TASK_ID() _KMP_GEN_ID(__kmp_task_counter)
3363 #define KMP_GEN_TEAM_ID() _KMP_GEN_ID(__kmp_team_counter)
3364 
3365 /* ------------------------------------------------------------------------ */
3366 
3367 extern void __kmp_print_storage_map_gtid(int gtid, void *p1, void *p2,
3368  size_t size, char const *format, ...);
3369 
3370 extern void __kmp_serial_initialize(void);
3371 extern void __kmp_middle_initialize(void);
3372 extern void __kmp_parallel_initialize(void);
3373 
3374 extern void __kmp_internal_begin(void);
3375 extern void __kmp_internal_end_library(int gtid);
3376 extern void __kmp_internal_end_thread(int gtid);
3377 extern void __kmp_internal_end_atexit(void);
3378 extern void __kmp_internal_end_dtor(void);
3379 extern void __kmp_internal_end_dest(void *);
3380 
3381 extern int __kmp_register_root(int initial_thread);
3382 extern void __kmp_unregister_root(int gtid);
3383 extern void __kmp_unregister_library(void); // called by __kmp_internal_end()
3384 
3385 extern int __kmp_ignore_mppbeg(void);
3386 extern int __kmp_ignore_mppend(void);
3387 
3388 extern int __kmp_enter_single(int gtid, ident_t *id_ref, int push_ws);
3389 extern void __kmp_exit_single(int gtid);
3390 
3391 extern void __kmp_parallel_deo(int *gtid_ref, int *cid_ref, ident_t *loc_ref);
3392 extern void __kmp_parallel_dxo(int *gtid_ref, int *cid_ref, ident_t *loc_ref);
3393 
3394 #ifdef USE_LOAD_BALANCE
3395 extern int __kmp_get_load_balance(int);
3396 #endif
3397 
3398 extern int __kmp_get_global_thread_id(void);
3399 extern int __kmp_get_global_thread_id_reg(void);
3400 extern void __kmp_exit_thread(int exit_status);
3401 extern void __kmp_abort(char const *format, ...);
3402 extern void __kmp_abort_thread(void);
3403 KMP_NORETURN extern void __kmp_abort_process(void);
3404 extern void __kmp_warn(char const *format, ...);
3405 
3406 extern void __kmp_set_num_threads(int new_nth, int gtid);
3407 
3408 // Returns current thread (pointer to kmp_info_t). Current thread *must* be
3409 // registered.
3410 static inline kmp_info_t *__kmp_entry_thread() {
3411  int gtid = __kmp_entry_gtid();
3412 
3413  return __kmp_threads[gtid];
3414 }
3415 
3416 extern void __kmp_set_max_active_levels(int gtid, int new_max_active_levels);
3417 extern int __kmp_get_max_active_levels(int gtid);
3418 extern int __kmp_get_ancestor_thread_num(int gtid, int level);
3419 extern int __kmp_get_team_size(int gtid, int level);
3420 extern void __kmp_set_schedule(int gtid, kmp_sched_t new_sched, int chunk);
3421 extern void __kmp_get_schedule(int gtid, kmp_sched_t *sched, int *chunk);
3422 
3423 extern unsigned short __kmp_get_random(kmp_info_t *thread);
3424 extern void __kmp_init_random(kmp_info_t *thread);
3425 
3426 extern kmp_r_sched_t __kmp_get_schedule_global(void);
3427 extern void __kmp_adjust_num_threads(int new_nproc);
3428 extern void __kmp_check_stksize(size_t *val);
3429 
3430 extern void *___kmp_allocate(size_t size KMP_SRC_LOC_DECL);
3431 extern void *___kmp_page_allocate(size_t size KMP_SRC_LOC_DECL);
3432 extern void ___kmp_free(void *ptr KMP_SRC_LOC_DECL);
3433 #define __kmp_allocate(size) ___kmp_allocate((size)KMP_SRC_LOC_CURR)
3434 #define __kmp_page_allocate(size) ___kmp_page_allocate((size)KMP_SRC_LOC_CURR)
3435 #define __kmp_free(ptr) ___kmp_free((ptr)KMP_SRC_LOC_CURR)
3436 
3437 #if USE_FAST_MEMORY
3438 extern void *___kmp_fast_allocate(kmp_info_t *this_thr,
3439  size_t size KMP_SRC_LOC_DECL);
3440 extern void ___kmp_fast_free(kmp_info_t *this_thr, void *ptr KMP_SRC_LOC_DECL);
3441 extern void __kmp_free_fast_memory(kmp_info_t *this_thr);
3442 extern void __kmp_initialize_fast_memory(kmp_info_t *this_thr);
3443 #define __kmp_fast_allocate(this_thr, size) \
3444  ___kmp_fast_allocate((this_thr), (size)KMP_SRC_LOC_CURR)
3445 #define __kmp_fast_free(this_thr, ptr) \
3446  ___kmp_fast_free((this_thr), (ptr)KMP_SRC_LOC_CURR)
3447 #endif
3448 
3449 extern void *___kmp_thread_malloc(kmp_info_t *th, size_t size KMP_SRC_LOC_DECL);
3450 extern void *___kmp_thread_calloc(kmp_info_t *th, size_t nelem,
3451  size_t elsize KMP_SRC_LOC_DECL);
3452 extern void *___kmp_thread_realloc(kmp_info_t *th, void *ptr,
3453  size_t size KMP_SRC_LOC_DECL);
3454 extern void ___kmp_thread_free(kmp_info_t *th, void *ptr KMP_SRC_LOC_DECL);
3455 #define __kmp_thread_malloc(th, size) \
3456  ___kmp_thread_malloc((th), (size)KMP_SRC_LOC_CURR)
3457 #define __kmp_thread_calloc(th, nelem, elsize) \
3458  ___kmp_thread_calloc((th), (nelem), (elsize)KMP_SRC_LOC_CURR)
3459 #define __kmp_thread_realloc(th, ptr, size) \
3460  ___kmp_thread_realloc((th), (ptr), (size)KMP_SRC_LOC_CURR)
3461 #define __kmp_thread_free(th, ptr) \
3462  ___kmp_thread_free((th), (ptr)KMP_SRC_LOC_CURR)
3463 
3464 #define KMP_INTERNAL_MALLOC(sz) malloc(sz)
3465 #define KMP_INTERNAL_FREE(p) free(p)
3466 #define KMP_INTERNAL_REALLOC(p, sz) realloc((p), (sz))
3467 #define KMP_INTERNAL_CALLOC(n, sz) calloc((n), (sz))
3468 
3469 extern void __kmp_push_num_threads(ident_t *loc, int gtid, int num_threads);
3470 
3471 extern void __kmp_push_proc_bind(ident_t *loc, int gtid,
3472  kmp_proc_bind_t proc_bind);
3473 extern void __kmp_push_num_teams(ident_t *loc, int gtid, int num_teams,
3474  int num_threads);
3475 extern void __kmp_push_num_teams_51(ident_t *loc, int gtid, int num_teams_lb,
3476  int num_teams_ub, int num_threads);
3477 
3478 extern void __kmp_yield();
3479 
3480 extern void __kmpc_dispatch_init_4(ident_t *loc, kmp_int32 gtid,
3481  enum sched_type schedule, kmp_int32 lb,
3482  kmp_int32 ub, kmp_int32 st, kmp_int32 chunk);
3483 extern void __kmpc_dispatch_init_4u(ident_t *loc, kmp_int32 gtid,
3484  enum sched_type schedule, kmp_uint32 lb,
3485  kmp_uint32 ub, kmp_int32 st,
3486  kmp_int32 chunk);
3487 extern void __kmpc_dispatch_init_8(ident_t *loc, kmp_int32 gtid,
3488  enum sched_type schedule, kmp_int64 lb,
3489  kmp_int64 ub, kmp_int64 st, kmp_int64 chunk);
3490 extern void __kmpc_dispatch_init_8u(ident_t *loc, kmp_int32 gtid,
3491  enum sched_type schedule, kmp_uint64 lb,
3492  kmp_uint64 ub, kmp_int64 st,
3493  kmp_int64 chunk);
3494 
3495 extern int __kmpc_dispatch_next_4(ident_t *loc, kmp_int32 gtid,
3496  kmp_int32 *p_last, kmp_int32 *p_lb,
3497  kmp_int32 *p_ub, kmp_int32 *p_st);
3498 extern int __kmpc_dispatch_next_4u(ident_t *loc, kmp_int32 gtid,
3499  kmp_int32 *p_last, kmp_uint32 *p_lb,
3500  kmp_uint32 *p_ub, kmp_int32 *p_st);
3501 extern int __kmpc_dispatch_next_8(ident_t *loc, kmp_int32 gtid,
3502  kmp_int32 *p_last, kmp_int64 *p_lb,
3503  kmp_int64 *p_ub, kmp_int64 *p_st);
3504 extern int __kmpc_dispatch_next_8u(ident_t *loc, kmp_int32 gtid,
3505  kmp_int32 *p_last, kmp_uint64 *p_lb,
3506  kmp_uint64 *p_ub, kmp_int64 *p_st);
3507 
3508 extern void __kmpc_dispatch_fini_4(ident_t *loc, kmp_int32 gtid);
3509 extern void __kmpc_dispatch_fini_8(ident_t *loc, kmp_int32 gtid);
3510 extern void __kmpc_dispatch_fini_4u(ident_t *loc, kmp_int32 gtid);
3511 extern void __kmpc_dispatch_fini_8u(ident_t *loc, kmp_int32 gtid);
3512 
3513 #ifdef KMP_GOMP_COMPAT
3514 
3515 extern void __kmp_aux_dispatch_init_4(ident_t *loc, kmp_int32 gtid,
3516  enum sched_type schedule, kmp_int32 lb,
3517  kmp_int32 ub, kmp_int32 st,
3518  kmp_int32 chunk, int push_ws);
3519 extern void __kmp_aux_dispatch_init_4u(ident_t *loc, kmp_int32 gtid,
3520  enum sched_type schedule, kmp_uint32 lb,
3521  kmp_uint32 ub, kmp_int32 st,
3522  kmp_int32 chunk, int push_ws);
3523 extern void __kmp_aux_dispatch_init_8(ident_t *loc, kmp_int32 gtid,
3524  enum sched_type schedule, kmp_int64 lb,
3525  kmp_int64 ub, kmp_int64 st,
3526  kmp_int64 chunk, int push_ws);
3527 extern void __kmp_aux_dispatch_init_8u(ident_t *loc, kmp_int32 gtid,
3528  enum sched_type schedule, kmp_uint64 lb,
3529  kmp_uint64 ub, kmp_int64 st,
3530  kmp_int64 chunk, int push_ws);
3531 extern void __kmp_aux_dispatch_fini_chunk_4(ident_t *loc, kmp_int32 gtid);
3532 extern void __kmp_aux_dispatch_fini_chunk_8(ident_t *loc, kmp_int32 gtid);
3533 extern void __kmp_aux_dispatch_fini_chunk_4u(ident_t *loc, kmp_int32 gtid);
3534 extern void __kmp_aux_dispatch_fini_chunk_8u(ident_t *loc, kmp_int32 gtid);
3535 
3536 #endif /* KMP_GOMP_COMPAT */
3537 
3538 extern kmp_uint32 __kmp_eq_4(kmp_uint32 value, kmp_uint32 checker);
3539 extern kmp_uint32 __kmp_neq_4(kmp_uint32 value, kmp_uint32 checker);
3540 extern kmp_uint32 __kmp_lt_4(kmp_uint32 value, kmp_uint32 checker);
3541 extern kmp_uint32 __kmp_ge_4(kmp_uint32 value, kmp_uint32 checker);
3542 extern kmp_uint32 __kmp_le_4(kmp_uint32 value, kmp_uint32 checker);
3543 extern kmp_uint32 __kmp_wait_4(kmp_uint32 volatile *spinner, kmp_uint32 checker,
3544  kmp_uint32 (*pred)(kmp_uint32, kmp_uint32),
3545  void *obj);
3546 extern void __kmp_wait_4_ptr(void *spinner, kmp_uint32 checker,
3547  kmp_uint32 (*pred)(void *, kmp_uint32), void *obj);
3548 
3549 extern void __kmp_wait_64(kmp_info_t *this_thr, kmp_flag_64<> *flag,
3550  int final_spin
3551 #if USE_ITT_BUILD
3552  ,
3553  void *itt_sync_obj
3554 #endif
3555 );
3556 extern void __kmp_release_64(kmp_flag_64<> *flag);
3557 
3558 extern void __kmp_infinite_loop(void);
3559 
3560 extern void __kmp_cleanup(void);
3561 
3562 #if KMP_HANDLE_SIGNALS
3563 extern int __kmp_handle_signals;
3564 extern void __kmp_install_signals(int parallel_init);
3565 extern void __kmp_remove_signals(void);
3566 #endif
3567 
3568 extern void __kmp_clear_system_time(void);
3569 extern void __kmp_read_system_time(double *delta);
3570 
3571 extern void __kmp_check_stack_overlap(kmp_info_t *thr);
3572 
3573 extern void __kmp_expand_host_name(char *buffer, size_t size);
3574 extern void __kmp_expand_file_name(char *result, size_t rlen, char *pattern);
3575 
3576 #if KMP_ARCH_X86 || KMP_ARCH_X86_64 || (KMP_OS_WINDOWS && KMP_ARCH_AARCH64)
3577 extern void
3578 __kmp_initialize_system_tick(void); /* Initialize timer tick value */
3579 #endif
3580 
3581 extern void
3582 __kmp_runtime_initialize(void); /* machine specific initialization */
3583 extern void __kmp_runtime_destroy(void);
3584 
3585 #if KMP_AFFINITY_SUPPORTED
3586 extern char *__kmp_affinity_print_mask(char *buf, int buf_len,
3587  kmp_affin_mask_t *mask);
3588 extern kmp_str_buf_t *__kmp_affinity_str_buf_mask(kmp_str_buf_t *buf,
3589  kmp_affin_mask_t *mask);
3590 extern void __kmp_affinity_initialize(void);
3591 extern void __kmp_affinity_uninitialize(void);
3592 extern void __kmp_affinity_set_init_mask(
3593  int gtid, int isa_root); /* set affinity according to KMP_AFFINITY */
3594 extern void __kmp_affinity_set_place(int gtid);
3595 extern void __kmp_affinity_determine_capable(const char *env_var);
3596 extern int __kmp_aux_set_affinity(void **mask);
3597 extern int __kmp_aux_get_affinity(void **mask);
3598 extern int __kmp_aux_get_affinity_max_proc();
3599 extern int __kmp_aux_set_affinity_mask_proc(int proc, void **mask);
3600 extern int __kmp_aux_unset_affinity_mask_proc(int proc, void **mask);
3601 extern int __kmp_aux_get_affinity_mask_proc(int proc, void **mask);
3602 extern void __kmp_balanced_affinity(kmp_info_t *th, int team_size);
3603 #if KMP_OS_LINUX || KMP_OS_FREEBSD
3604 extern int kmp_set_thread_affinity_mask_initial(void);
3605 #endif
3606 static inline void __kmp_assign_root_init_mask() {
3607  int gtid = __kmp_entry_gtid();
3608  kmp_root_t *r = __kmp_threads[gtid]->th.th_root;
3609  if (r->r.r_uber_thread == __kmp_threads[gtid] && !r->r.r_affinity_assigned) {
3610  __kmp_affinity_set_init_mask(gtid, TRUE);
3611  r->r.r_affinity_assigned = TRUE;
3612  }
3613 }
3614 #else /* KMP_AFFINITY_SUPPORTED */
3615 #define __kmp_assign_root_init_mask() /* Nothing */
3616 #endif /* KMP_AFFINITY_SUPPORTED */
3617 // No need for KMP_AFFINITY_SUPPORTED guard as only one field in the
3618 // format string is for affinity, so platforms that do not support
3619 // affinity can still use the other fields, e.g., %n for num_threads
3620 extern size_t __kmp_aux_capture_affinity(int gtid, const char *format,
3621  kmp_str_buf_t *buffer);
3622 extern void __kmp_aux_display_affinity(int gtid, const char *format);
3623 
3624 extern void __kmp_cleanup_hierarchy();
3625 extern void __kmp_get_hierarchy(kmp_uint32 nproc, kmp_bstate_t *thr_bar);
3626 
3627 #if KMP_USE_FUTEX
3628 
3629 extern int __kmp_futex_determine_capable(void);
3630 
3631 #endif // KMP_USE_FUTEX
3632 
3633 extern void __kmp_gtid_set_specific(int gtid);
3634 extern int __kmp_gtid_get_specific(void);
3635 
3636 extern double __kmp_read_cpu_time(void);
3637 
3638 extern int __kmp_read_system_info(struct kmp_sys_info *info);
3639 
3640 #if KMP_USE_MONITOR
3641 extern void __kmp_create_monitor(kmp_info_t *th);
3642 #endif
3643 
3644 extern void *__kmp_launch_thread(kmp_info_t *thr);
3645 
3646 extern void __kmp_create_worker(int gtid, kmp_info_t *th, size_t stack_size);
3647 
3648 #if KMP_OS_WINDOWS
3649 extern int __kmp_still_running(kmp_info_t *th);
3650 extern int __kmp_is_thread_alive(kmp_info_t *th, DWORD *exit_val);
3651 extern void __kmp_free_handle(kmp_thread_t tHandle);
3652 #endif
3653 
3654 #if KMP_USE_MONITOR
3655 extern void __kmp_reap_monitor(kmp_info_t *th);
3656 #endif
3657 extern void __kmp_reap_worker(kmp_info_t *th);
3658 extern void __kmp_terminate_thread(int gtid);
3659 
3660 extern int __kmp_try_suspend_mx(kmp_info_t *th);
3661 extern void __kmp_lock_suspend_mx(kmp_info_t *th);
3662 extern void __kmp_unlock_suspend_mx(kmp_info_t *th);
3663 
3664 extern void __kmp_elapsed(double *);
3665 extern void __kmp_elapsed_tick(double *);
3666 
3667 extern void __kmp_enable(int old_state);
3668 extern void __kmp_disable(int *old_state);
3669 
3670 extern void __kmp_thread_sleep(int millis);
3671 
3672 extern void __kmp_common_initialize(void);
3673 extern void __kmp_common_destroy(void);
3674 extern void __kmp_common_destroy_gtid(int gtid);
3675 
3676 #if KMP_OS_UNIX
3677 extern void __kmp_register_atfork(void);
3678 #endif
3679 extern void __kmp_suspend_initialize(void);
3680 extern void __kmp_suspend_initialize_thread(kmp_info_t *th);
3681 extern void __kmp_suspend_uninitialize_thread(kmp_info_t *th);
3682 
3683 extern kmp_info_t *__kmp_allocate_thread(kmp_root_t *root, kmp_team_t *team,
3684  int tid);
3685 extern kmp_team_t *
3686 __kmp_allocate_team(kmp_root_t *root, int new_nproc, int max_nproc,
3687 #if OMPT_SUPPORT
3688  ompt_data_t ompt_parallel_data,
3689 #endif
3690  kmp_proc_bind_t proc_bind, kmp_internal_control_t *new_icvs,
3691  int argc USE_NESTED_HOT_ARG(kmp_info_t *thr));
3692 extern void __kmp_free_thread(kmp_info_t *);
3693 extern void __kmp_free_team(kmp_root_t *,
3694  kmp_team_t *USE_NESTED_HOT_ARG(kmp_info_t *));
3695 extern kmp_team_t *__kmp_reap_team(kmp_team_t *);
3696 
3697 /* ------------------------------------------------------------------------ */
3698 
3699 extern void __kmp_initialize_bget(kmp_info_t *th);
3700 extern void __kmp_finalize_bget(kmp_info_t *th);
3701 
3702 KMP_EXPORT void *kmpc_malloc(size_t size);
3703 KMP_EXPORT void *kmpc_aligned_malloc(size_t size, size_t alignment);
3704 KMP_EXPORT void *kmpc_calloc(size_t nelem, size_t elsize);
3705 KMP_EXPORT void *kmpc_realloc(void *ptr, size_t size);
3706 KMP_EXPORT void kmpc_free(void *ptr);
3707 
3708 /* declarations for internal use */
3709 
3710 extern int __kmp_barrier(enum barrier_type bt, int gtid, int is_split,
3711  size_t reduce_size, void *reduce_data,
3712  void (*reduce)(void *, void *));
3713 extern void __kmp_end_split_barrier(enum barrier_type bt, int gtid);
3714 extern int __kmp_barrier_gomp_cancel(int gtid);
3715 
3720 enum fork_context_e {
3721  fork_context_gnu,
3723  fork_context_intel,
3724  fork_context_last
3725 };
3726 extern int __kmp_fork_call(ident_t *loc, int gtid,
3727  enum fork_context_e fork_context, kmp_int32 argc,
3728  microtask_t microtask, launch_t invoker,
3729  kmp_va_list ap);
3730 
3731 extern void __kmp_join_call(ident_t *loc, int gtid
3732 #if OMPT_SUPPORT
3733  ,
3734  enum fork_context_e fork_context
3735 #endif
3736  ,
3737  int exit_teams = 0);
3738 
3739 extern void __kmp_serialized_parallel(ident_t *id, kmp_int32 gtid);
3740 extern void __kmp_internal_fork(ident_t *id, int gtid, kmp_team_t *team);
3741 extern void __kmp_internal_join(ident_t *id, int gtid, kmp_team_t *team);
3742 extern int __kmp_invoke_task_func(int gtid);
3743 extern void __kmp_run_before_invoked_task(int gtid, int tid,
3744  kmp_info_t *this_thr,
3745  kmp_team_t *team);
3746 extern void __kmp_run_after_invoked_task(int gtid, int tid,
3747  kmp_info_t *this_thr,
3748  kmp_team_t *team);
3749 
3750 // should never have been exported
3751 KMP_EXPORT int __kmpc_invoke_task_func(int gtid);
3752 extern int __kmp_invoke_teams_master(int gtid);
3753 extern void __kmp_teams_master(int gtid);
3754 extern int __kmp_aux_get_team_num();
3755 extern int __kmp_aux_get_num_teams();
3756 extern void __kmp_save_internal_controls(kmp_info_t *thread);
3757 extern void __kmp_user_set_library(enum library_type arg);
3758 extern void __kmp_aux_set_library(enum library_type arg);
3759 extern void __kmp_aux_set_stacksize(size_t arg);
3760 extern void __kmp_aux_set_blocktime(int arg, kmp_info_t *thread, int tid);
3761 extern void __kmp_aux_set_defaults(char const *str, size_t len);
3762 
3763 /* Functions called from __kmp_aux_env_initialize() in kmp_settings.cpp */
3764 void kmpc_set_blocktime(int arg);
3765 void ompc_set_nested(int flag);
3766 void ompc_set_dynamic(int flag);
3767 void ompc_set_num_threads(int arg);
3768 
3769 extern void __kmp_push_current_task_to_thread(kmp_info_t *this_thr,
3770  kmp_team_t *team, int tid);
3771 extern void __kmp_pop_current_task_from_thread(kmp_info_t *this_thr);
3772 extern kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
3773  kmp_tasking_flags_t *flags,
3774  size_t sizeof_kmp_task_t,
3775  size_t sizeof_shareds,
3776  kmp_routine_entry_t task_entry);
3777 extern void __kmp_init_implicit_task(ident_t *loc_ref, kmp_info_t *this_thr,
3778  kmp_team_t *team, int tid,
3779  int set_curr_task);
3780 extern void __kmp_finish_implicit_task(kmp_info_t *this_thr);
3781 extern void __kmp_free_implicit_task(kmp_info_t *this_thr);
3782 
3783 extern kmp_event_t *__kmpc_task_allow_completion_event(ident_t *loc_ref,
3784  int gtid,
3785  kmp_task_t *task);
3786 extern void __kmp_fulfill_event(kmp_event_t *event);
3787 
3788 extern void __kmp_free_task_team(kmp_info_t *thread,
3789  kmp_task_team_t *task_team);
3790 extern void __kmp_reap_task_teams(void);
3791 extern void __kmp_wait_to_unref_task_teams(void);
3792 extern void __kmp_task_team_setup(kmp_info_t *this_thr, kmp_team_t *team,
3793  int always);
3794 extern void __kmp_task_team_sync(kmp_info_t *this_thr, kmp_team_t *team);
3795 extern void __kmp_task_team_wait(kmp_info_t *this_thr, kmp_team_t *team
3796 #if USE_ITT_BUILD
3797  ,
3798  void *itt_sync_obj
3799 #endif /* USE_ITT_BUILD */
3800  ,
3801  int wait = 1);
3802 extern void __kmp_tasking_barrier(kmp_team_t *team, kmp_info_t *thread,
3803  int gtid);
3804 
3805 extern int __kmp_is_address_mapped(void *addr);
3806 extern kmp_uint64 __kmp_hardware_timestamp(void);
3807 
3808 #if KMP_OS_UNIX
3809 extern int __kmp_read_from_file(char const *path, char const *format, ...);
3810 #endif
3811 
3812 /* ------------------------------------------------------------------------ */
3813 //
3814 // Assembly routines that have no compiler intrinsic replacement
3815 //
3816 
3817 extern int __kmp_invoke_microtask(microtask_t pkfn, int gtid, int npr, int argc,
3818  void *argv[]
3819 #if OMPT_SUPPORT
3820  ,
3821  void **exit_frame_ptr
3822 #endif
3823 );
3824 
3825 /* ------------------------------------------------------------------------ */
3826 
3827 KMP_EXPORT void __kmpc_begin(ident_t *, kmp_int32 flags);
3828 KMP_EXPORT void __kmpc_end(ident_t *);
3829 
3830 KMP_EXPORT void __kmpc_threadprivate_register_vec(ident_t *, void *data,
3831  kmpc_ctor_vec ctor,
3832  kmpc_cctor_vec cctor,
3833  kmpc_dtor_vec dtor,
3834  size_t vector_length);
3835 KMP_EXPORT void __kmpc_threadprivate_register(ident_t *, void *data,
3836  kmpc_ctor ctor, kmpc_cctor cctor,
3837  kmpc_dtor dtor);
3838 KMP_EXPORT void *__kmpc_threadprivate(ident_t *, kmp_int32 global_tid,
3839  void *data, size_t size);
3840 
3841 KMP_EXPORT kmp_int32 __kmpc_global_thread_num(ident_t *);
3842 KMP_EXPORT kmp_int32 __kmpc_global_num_threads(ident_t *);
3843 KMP_EXPORT kmp_int32 __kmpc_bound_thread_num(ident_t *);
3844 KMP_EXPORT kmp_int32 __kmpc_bound_num_threads(ident_t *);
3845 
3846 KMP_EXPORT kmp_int32 __kmpc_ok_to_fork(ident_t *);
3847 KMP_EXPORT void __kmpc_fork_call(ident_t *, kmp_int32 nargs,
3848  kmpc_micro microtask, ...);
3849 
3850 KMP_EXPORT void __kmpc_serialized_parallel(ident_t *, kmp_int32 global_tid);
3851 KMP_EXPORT void __kmpc_end_serialized_parallel(ident_t *, kmp_int32 global_tid);
3852 
3853 KMP_EXPORT void __kmpc_flush(ident_t *);
3854 KMP_EXPORT void __kmpc_barrier(ident_t *, kmp_int32 global_tid);
3855 KMP_EXPORT kmp_int32 __kmpc_master(ident_t *, kmp_int32 global_tid);
3856 KMP_EXPORT void __kmpc_end_master(ident_t *, kmp_int32 global_tid);
3857 KMP_EXPORT kmp_int32 __kmpc_masked(ident_t *, kmp_int32 global_tid,
3858  kmp_int32 filter);
3859 KMP_EXPORT void __kmpc_end_masked(ident_t *, kmp_int32 global_tid);
3860 KMP_EXPORT void __kmpc_ordered(ident_t *, kmp_int32 global_tid);
3861 KMP_EXPORT void __kmpc_end_ordered(ident_t *, kmp_int32 global_tid);
3862 KMP_EXPORT void __kmpc_critical(ident_t *, kmp_int32 global_tid,
3863  kmp_critical_name *);
3864 KMP_EXPORT void __kmpc_end_critical(ident_t *, kmp_int32 global_tid,
3865  kmp_critical_name *);
3866 KMP_EXPORT void __kmpc_critical_with_hint(ident_t *, kmp_int32 global_tid,
3867  kmp_critical_name *, uint32_t hint);
3868 
3869 KMP_EXPORT kmp_int32 __kmpc_barrier_master(ident_t *, kmp_int32 global_tid);
3870 KMP_EXPORT void __kmpc_end_barrier_master(ident_t *, kmp_int32 global_tid);
3871 
3872 KMP_EXPORT kmp_int32 __kmpc_barrier_master_nowait(ident_t *,
3873  kmp_int32 global_tid);
3874 
3875 KMP_EXPORT kmp_int32 __kmpc_single(ident_t *, kmp_int32 global_tid);
3876 KMP_EXPORT void __kmpc_end_single(ident_t *, kmp_int32 global_tid);
3877 
3878 KMP_EXPORT void KMPC_FOR_STATIC_INIT(ident_t *loc, kmp_int32 global_tid,
3879  kmp_int32 schedtype, kmp_int32 *plastiter,
3880  kmp_int *plower, kmp_int *pupper,
3881  kmp_int *pstride, kmp_int incr,
3882  kmp_int chunk);
3883 
3884 KMP_EXPORT void __kmpc_for_static_fini(ident_t *loc, kmp_int32 global_tid);
3885 
3886 KMP_EXPORT void __kmpc_copyprivate(ident_t *loc, kmp_int32 global_tid,
3887  size_t cpy_size, void *cpy_data,
3888  void (*cpy_func)(void *, void *),
3889  kmp_int32 didit);
3890 
3891 extern void KMPC_SET_NUM_THREADS(int arg);
3892 extern void KMPC_SET_DYNAMIC(int flag);
3893 extern void KMPC_SET_NESTED(int flag);
3894 
3895 /* OMP 3.0 tasking interface routines */
3896 KMP_EXPORT kmp_int32 __kmpc_omp_task(ident_t *loc_ref, kmp_int32 gtid,
3897  kmp_task_t *new_task);
3898 KMP_EXPORT kmp_task_t *__kmpc_omp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
3899  kmp_int32 flags,
3900  size_t sizeof_kmp_task_t,
3901  size_t sizeof_shareds,
3902  kmp_routine_entry_t task_entry);
3903 KMP_EXPORT kmp_task_t *__kmpc_omp_target_task_alloc(
3904  ident_t *loc_ref, kmp_int32 gtid, kmp_int32 flags, size_t sizeof_kmp_task_t,
3905  size_t sizeof_shareds, kmp_routine_entry_t task_entry, kmp_int64 device_id);
3906 KMP_EXPORT void __kmpc_omp_task_begin_if0(ident_t *loc_ref, kmp_int32 gtid,
3907  kmp_task_t *task);
3908 KMP_EXPORT void __kmpc_omp_task_complete_if0(ident_t *loc_ref, kmp_int32 gtid,
3909  kmp_task_t *task);
3910 KMP_EXPORT kmp_int32 __kmpc_omp_task_parts(ident_t *loc_ref, kmp_int32 gtid,
3911  kmp_task_t *new_task);
3912 KMP_EXPORT kmp_int32 __kmpc_omp_taskwait(ident_t *loc_ref, kmp_int32 gtid);
3913 
3914 KMP_EXPORT kmp_int32 __kmpc_omp_taskyield(ident_t *loc_ref, kmp_int32 gtid,
3915  int end_part);
3916 
3917 #if TASK_UNUSED
3918 void __kmpc_omp_task_begin(ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *task);
3919 void __kmpc_omp_task_complete(ident_t *loc_ref, kmp_int32 gtid,
3920  kmp_task_t *task);
3921 #endif // TASK_UNUSED
3922 
3923 /* ------------------------------------------------------------------------ */
3924 
3925 KMP_EXPORT void __kmpc_taskgroup(ident_t *loc, int gtid);
3926 KMP_EXPORT void __kmpc_end_taskgroup(ident_t *loc, int gtid);
3927 
3928 KMP_EXPORT kmp_int32 __kmpc_omp_task_with_deps(
3929  ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *new_task, kmp_int32 ndeps,
3930  kmp_depend_info_t *dep_list, kmp_int32 ndeps_noalias,
3931  kmp_depend_info_t *noalias_dep_list);
3932 KMP_EXPORT void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32 gtid,
3933  kmp_int32 ndeps,
3934  kmp_depend_info_t *dep_list,
3935  kmp_int32 ndeps_noalias,
3936  kmp_depend_info_t *noalias_dep_list);
3937 extern kmp_int32 __kmp_omp_task(kmp_int32 gtid, kmp_task_t *new_task,
3938  bool serialize_immediate);
3939 
3940 KMP_EXPORT kmp_int32 __kmpc_cancel(ident_t *loc_ref, kmp_int32 gtid,
3941  kmp_int32 cncl_kind);
3942 KMP_EXPORT kmp_int32 __kmpc_cancellationpoint(ident_t *loc_ref, kmp_int32 gtid,
3943  kmp_int32 cncl_kind);
3944 KMP_EXPORT kmp_int32 __kmpc_cancel_barrier(ident_t *loc_ref, kmp_int32 gtid);
3945 KMP_EXPORT int __kmp_get_cancellation_status(int cancel_kind);
3946 
3947 KMP_EXPORT void __kmpc_proxy_task_completed(kmp_int32 gtid, kmp_task_t *ptask);
3948 KMP_EXPORT void __kmpc_proxy_task_completed_ooo(kmp_task_t *ptask);
3949 KMP_EXPORT void __kmpc_taskloop(ident_t *loc, kmp_int32 gtid, kmp_task_t *task,
3950  kmp_int32 if_val, kmp_uint64 *lb,
3951  kmp_uint64 *ub, kmp_int64 st, kmp_int32 nogroup,
3952  kmp_int32 sched, kmp_uint64 grainsize,
3953  void *task_dup);
3954 KMP_EXPORT void __kmpc_taskloop_5(ident_t *loc, kmp_int32 gtid,
3955  kmp_task_t *task, kmp_int32 if_val,
3956  kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st,
3957  kmp_int32 nogroup, kmp_int32 sched,
3958  kmp_uint64 grainsize, kmp_int32 modifier,
3959  void *task_dup);
3960 KMP_EXPORT void *__kmpc_task_reduction_init(int gtid, int num_data, void *data);
3961 KMP_EXPORT void *__kmpc_taskred_init(int gtid, int num_data, void *data);
3962 KMP_EXPORT void *__kmpc_task_reduction_get_th_data(int gtid, void *tg, void *d);
3963 KMP_EXPORT void *__kmpc_task_reduction_modifier_init(ident_t *loc, int gtid,
3964  int is_ws, int num,
3965  void *data);
3966 KMP_EXPORT void *__kmpc_taskred_modifier_init(ident_t *loc, int gtid, int is_ws,
3967  int num, void *data);
3968 KMP_EXPORT void __kmpc_task_reduction_modifier_fini(ident_t *loc, int gtid,
3969  int is_ws);
3970 KMP_EXPORT kmp_int32 __kmpc_omp_reg_task_with_affinity(
3971  ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *new_task, kmp_int32 naffins,
3972  kmp_task_affinity_info_t *affin_list);
3973 KMP_EXPORT void __kmp_set_num_teams(int num_teams);
3974 KMP_EXPORT int __kmp_get_max_teams(void);
3975 KMP_EXPORT void __kmp_set_teams_thread_limit(int limit);
3976 KMP_EXPORT int __kmp_get_teams_thread_limit(void);
3977 
3978 /* Lock interface routines (fast versions with gtid passed in) */
3979 KMP_EXPORT void __kmpc_init_lock(ident_t *loc, kmp_int32 gtid,
3980  void **user_lock);
3981 KMP_EXPORT void __kmpc_init_nest_lock(ident_t *loc, kmp_int32 gtid,
3982  void **user_lock);
3983 KMP_EXPORT void __kmpc_destroy_lock(ident_t *loc, kmp_int32 gtid,
3984  void **user_lock);
3985 KMP_EXPORT void __kmpc_destroy_nest_lock(ident_t *loc, kmp_int32 gtid,
3986  void **user_lock);
3987 KMP_EXPORT void __kmpc_set_lock(ident_t *loc, kmp_int32 gtid, void **user_lock);
3988 KMP_EXPORT void __kmpc_set_nest_lock(ident_t *loc, kmp_int32 gtid,
3989  void **user_lock);
3990 KMP_EXPORT void __kmpc_unset_lock(ident_t *loc, kmp_int32 gtid,
3991  void **user_lock);
3992 KMP_EXPORT void __kmpc_unset_nest_lock(ident_t *loc, kmp_int32 gtid,
3993  void **user_lock);
3994 KMP_EXPORT int __kmpc_test_lock(ident_t *loc, kmp_int32 gtid, void **user_lock);
3995 KMP_EXPORT int __kmpc_test_nest_lock(ident_t *loc, kmp_int32 gtid,
3996  void **user_lock);
3997 
3998 KMP_EXPORT void __kmpc_init_lock_with_hint(ident_t *loc, kmp_int32 gtid,
3999  void **user_lock, uintptr_t hint);
4000 KMP_EXPORT void __kmpc_init_nest_lock_with_hint(ident_t *loc, kmp_int32 gtid,
4001  void **user_lock,
4002  uintptr_t hint);
4003 
4004 /* Interface to fast scalable reduce methods routines */
4005 
4006 KMP_EXPORT kmp_int32 __kmpc_reduce_nowait(
4007  ident_t *loc, kmp_int32 global_tid, kmp_int32 num_vars, size_t reduce_size,
4008  void *reduce_data, void (*reduce_func)(void *lhs_data, void *rhs_data),
4009  kmp_critical_name *lck);
4010 KMP_EXPORT void __kmpc_end_reduce_nowait(ident_t *loc, kmp_int32 global_tid,
4011  kmp_critical_name *lck);
4012 KMP_EXPORT kmp_int32 __kmpc_reduce(
4013  ident_t *loc, kmp_int32 global_tid, kmp_int32 num_vars, size_t reduce_size,
4014  void *reduce_data, void (*reduce_func)(void *lhs_data, void *rhs_data),
4015  kmp_critical_name *lck);
4016 KMP_EXPORT void __kmpc_end_reduce(ident_t *loc, kmp_int32 global_tid,
4017  kmp_critical_name *lck);
4018 
4019 /* Internal fast reduction routines */
4020 
4021 extern PACKED_REDUCTION_METHOD_T __kmp_determine_reduction_method(
4022  ident_t *loc, kmp_int32 global_tid, kmp_int32 num_vars, size_t reduce_size,
4023  void *reduce_data, void (*reduce_func)(void *lhs_data, void *rhs_data),
4024  kmp_critical_name *lck);
4025 
4026 // this function is for testing set/get/determine reduce method
4027 KMP_EXPORT kmp_int32 __kmp_get_reduce_method(void);
4028 
4029 KMP_EXPORT kmp_uint64 __kmpc_get_taskid();
4030 KMP_EXPORT kmp_uint64 __kmpc_get_parent_taskid();
4031 
4032 // C++ port
4033 // missing 'extern "C"' declarations
4034 
4035 KMP_EXPORT kmp_int32 __kmpc_in_parallel(ident_t *loc);
4036 KMP_EXPORT void __kmpc_pop_num_threads(ident_t *loc, kmp_int32 global_tid);
4037 KMP_EXPORT void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid,
4038  kmp_int32 num_threads);
4039 
4040 KMP_EXPORT void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 global_tid,
4041  int proc_bind);
4042 KMP_EXPORT void __kmpc_push_num_teams(ident_t *loc, kmp_int32 global_tid,
4043  kmp_int32 num_teams,
4044  kmp_int32 num_threads);
4045 /* Function for OpenMP 5.1 num_teams clause */
4046 KMP_EXPORT void __kmpc_push_num_teams_51(ident_t *loc, kmp_int32 global_tid,
4047  kmp_int32 num_teams_lb,
4048  kmp_int32 num_teams_ub,
4049  kmp_int32 num_threads);
4050 KMP_EXPORT void __kmpc_fork_teams(ident_t *loc, kmp_int32 argc,
4051  kmpc_micro microtask, ...);
4052 struct kmp_dim { // loop bounds info casted to kmp_int64
4053  kmp_int64 lo; // lower
4054  kmp_int64 up; // upper
4055  kmp_int64 st; // stride
4056 };
4057 KMP_EXPORT void __kmpc_doacross_init(ident_t *loc, kmp_int32 gtid,
4058  kmp_int32 num_dims,
4059  const struct kmp_dim *dims);
4060 KMP_EXPORT void __kmpc_doacross_wait(ident_t *loc, kmp_int32 gtid,
4061  const kmp_int64 *vec);
4062 KMP_EXPORT void __kmpc_doacross_post(ident_t *loc, kmp_int32 gtid,
4063  const kmp_int64 *vec);
4064 KMP_EXPORT void __kmpc_doacross_fini(ident_t *loc, kmp_int32 gtid);
4065 
4066 KMP_EXPORT void *__kmpc_threadprivate_cached(ident_t *loc, kmp_int32 global_tid,
4067  void *data, size_t size,
4068  void ***cache);
4069 
4070 // Symbols for MS mutual detection.
4071 extern int _You_must_link_with_exactly_one_OpenMP_library;
4072 extern int _You_must_link_with_Intel_OpenMP_library;
4073 #if KMP_OS_WINDOWS && (KMP_VERSION_MAJOR > 4)
4074 extern int _You_must_link_with_Microsoft_OpenMP_library;
4075 #endif
4076 
4077 // The routines below are not exported.
4078 // Consider making them 'static' in corresponding source files.
4079 void kmp_threadprivate_insert_private_data(int gtid, void *pc_addr,
4080  void *data_addr, size_t pc_size);
4081 struct private_common *kmp_threadprivate_insert(int gtid, void *pc_addr,
4082  void *data_addr,
4083  size_t pc_size);
4084 void __kmp_threadprivate_resize_cache(int newCapacity);
4085 void __kmp_cleanup_threadprivate_caches();
4086 
4087 // ompc_, kmpc_ entries moved from omp.h.
4088 #if KMP_OS_WINDOWS
4089 #define KMPC_CONVENTION __cdecl
4090 #else
4091 #define KMPC_CONVENTION
4092 #endif
4093 
4094 #ifndef __OMP_H
4095 typedef enum omp_sched_t {
4096  omp_sched_static = 1,
4097  omp_sched_dynamic = 2,
4098  omp_sched_guided = 3,
4099  omp_sched_auto = 4
4100 } omp_sched_t;
4101 typedef void *kmp_affinity_mask_t;
4102 #endif
4103 
4104 KMP_EXPORT void KMPC_CONVENTION ompc_set_max_active_levels(int);
4105 KMP_EXPORT void KMPC_CONVENTION ompc_set_schedule(omp_sched_t, int);
4106 KMP_EXPORT int KMPC_CONVENTION ompc_get_ancestor_thread_num(int);
4107 KMP_EXPORT int KMPC_CONVENTION ompc_get_team_size(int);
4108 KMP_EXPORT int KMPC_CONVENTION
4109 kmpc_set_affinity_mask_proc(int, kmp_affinity_mask_t *);
4110 KMP_EXPORT int KMPC_CONVENTION
4111 kmpc_unset_affinity_mask_proc(int, kmp_affinity_mask_t *);
4112 KMP_EXPORT int KMPC_CONVENTION
4113 kmpc_get_affinity_mask_proc(int, kmp_affinity_mask_t *);
4114 
4115 KMP_EXPORT void KMPC_CONVENTION kmpc_set_stacksize(int);
4116 KMP_EXPORT void KMPC_CONVENTION kmpc_set_stacksize_s(size_t);
4117 KMP_EXPORT void KMPC_CONVENTION kmpc_set_library(int);
4118 KMP_EXPORT void KMPC_CONVENTION kmpc_set_defaults(char const *);
4119 KMP_EXPORT void KMPC_CONVENTION kmpc_set_disp_num_buffers(int);
4120 void KMP_EXPAND_NAME(ompc_set_affinity_format)(char const *format);
4121 size_t KMP_EXPAND_NAME(ompc_get_affinity_format)(char *buffer, size_t size);
4122 void KMP_EXPAND_NAME(ompc_display_affinity)(char const *format);
4123 size_t KMP_EXPAND_NAME(ompc_capture_affinity)(char *buffer, size_t buf_size,
4124  char const *format);
4125 
4126 enum kmp_target_offload_kind {
4127  tgt_disabled = 0,
4128  tgt_default = 1,
4129  tgt_mandatory = 2
4130 };
4131 typedef enum kmp_target_offload_kind kmp_target_offload_kind_t;
4132 // Set via OMP_TARGET_OFFLOAD if specified, defaults to tgt_default otherwise
4133 extern kmp_target_offload_kind_t __kmp_target_offload;
4134 extern int __kmpc_get_target_offload();
4135 
4136 // Constants used in libomptarget
4137 #define KMP_DEVICE_DEFAULT -1 // This is libomptarget's default device.
4138 #define KMP_DEVICE_ALL -11 // This is libomptarget's "all devices".
4139 
4140 // OMP Pause Resource
4141 
4142 // The following enum is used both to set the status in __kmp_pause_status, and
4143 // as the internal equivalent of the externally-visible omp_pause_resource_t.
4144 typedef enum kmp_pause_status_t {
4145  kmp_not_paused = 0, // status is not paused, or, requesting resume
4146  kmp_soft_paused = 1, // status is soft-paused, or, requesting soft pause
4147  kmp_hard_paused = 2 // status is hard-paused, or, requesting hard pause
4148 } kmp_pause_status_t;
4149 
4150 // This stores the pause state of the runtime
4151 extern kmp_pause_status_t __kmp_pause_status;
4152 extern int __kmpc_pause_resource(kmp_pause_status_t level);
4153 extern int __kmp_pause_resource(kmp_pause_status_t level);
4154 // Soft resume sets __kmp_pause_status, and wakes up all threads.
4155 extern void __kmp_resume_if_soft_paused();
4156 // Hard resume simply resets the status to not paused. Library will appear to
4157 // be uninitialized after hard pause. Let OMP constructs trigger required
4158 // initializations.
4159 static inline void __kmp_resume_if_hard_paused() {
4160  if (__kmp_pause_status == kmp_hard_paused) {
4161  __kmp_pause_status = kmp_not_paused;
4162  }
4163 }
4164 
4165 extern void __kmp_omp_display_env(int verbose);
4166 
4167 // 1: it is initializing hidden helper team
4168 extern volatile int __kmp_init_hidden_helper;
4169 // 1: the hidden helper team is done
4170 extern volatile int __kmp_hidden_helper_team_done;
4171 // 1: enable hidden helper task
4172 extern kmp_int32 __kmp_enable_hidden_helper;
4173 // Main thread of hidden helper team
4174 extern kmp_info_t *__kmp_hidden_helper_main_thread;
4175 // Descriptors for the hidden helper threads
4176 extern kmp_info_t **__kmp_hidden_helper_threads;
4177 // Number of hidden helper threads
4178 extern kmp_int32 __kmp_hidden_helper_threads_num;
4179 // Number of hidden helper tasks that have not been executed yet
4180 extern std::atomic<kmp_int32> __kmp_unexecuted_hidden_helper_tasks;
4181 
4182 extern void __kmp_hidden_helper_initialize();
4183 extern void __kmp_hidden_helper_threads_initz_routine();
4184 extern void __kmp_do_initialize_hidden_helper_threads();
4185 extern void __kmp_hidden_helper_threads_initz_wait();
4186 extern void __kmp_hidden_helper_initz_release();
4187 extern void __kmp_hidden_helper_threads_deinitz_wait();
4188 extern void __kmp_hidden_helper_threads_deinitz_release();
4189 extern void __kmp_hidden_helper_main_thread_wait();
4190 extern void __kmp_hidden_helper_worker_thread_wait();
4191 extern void __kmp_hidden_helper_worker_thread_signal();
4192 extern void __kmp_hidden_helper_main_thread_release();
4193 
4194 // Check whether a given thread is a hidden helper thread
4195 #define KMP_HIDDEN_HELPER_THREAD(gtid) \
4196  ((gtid) >= 1 && (gtid) <= __kmp_hidden_helper_threads_num)
4197 
4198 #define KMP_HIDDEN_HELPER_WORKER_THREAD(gtid) \
4199  ((gtid) > 1 && (gtid) <= __kmp_hidden_helper_threads_num)
4200 
4201 #define KMP_HIDDEN_HELPER_TEAM(team) \
4202  (team->t.t_threads[0] == __kmp_hidden_helper_main_thread)
4203 
4204 // Map a gtid to a hidden helper thread. The first hidden helper thread, a.k.a
4205 // main thread, is skipped.
4206 #define KMP_GTID_TO_SHADOW_GTID(gtid) \
4207  ((gtid) % (__kmp_hidden_helper_threads_num - 1) + 2)
4208 
4209 // Return the adjusted gtid value by subtracting from gtid the number
4210 // of hidden helper threads. This adjusted value is the gtid the thread would
4211 // have received if there were no hidden helper threads.
4212 static inline int __kmp_adjust_gtid_for_hidden_helpers(int gtid) {
4213  int adjusted_gtid = gtid;
4214  if (__kmp_hidden_helper_threads_num > 0 && gtid > 0 &&
4215  gtid - __kmp_hidden_helper_threads_num >= 0) {
4216  adjusted_gtid -= __kmp_hidden_helper_threads_num;
4217  }
4218  return adjusted_gtid;
4219 }
4220 
4221 // Support for error directive
4222 typedef enum kmp_severity_t {
4223  severity_warning = 1,
4224  severity_fatal = 2
4225 } kmp_severity_t;
4226 extern void __kmpc_error(ident_t *loc, int severity, const char *message);
4227 
4228 // Support for scope directive
4229 KMP_EXPORT void __kmpc_scope(ident_t *loc, kmp_int32 gtid, void *reserved);
4230 KMP_EXPORT void __kmpc_end_scope(ident_t *loc, kmp_int32 gtid, void *reserved);
4231 
4232 #ifdef __cplusplus
4233 }
4234 #endif
4235 
4236 template <bool C, bool S>
4237 extern void __kmp_suspend_32(int th_gtid, kmp_flag_32<C, S> *flag);
4238 template <bool C, bool S>
4239 extern void __kmp_suspend_64(int th_gtid, kmp_flag_64<C, S> *flag);
4240 template <bool C, bool S>
4241 extern void __kmp_atomic_suspend_64(int th_gtid,
4242  kmp_atomic_flag_64<C, S> *flag);
4243 extern void __kmp_suspend_oncore(int th_gtid, kmp_flag_oncore *flag);
4244 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
4245 template <bool C, bool S>
4246 extern void __kmp_mwait_32(int th_gtid, kmp_flag_32<C, S> *flag);
4247 template <bool C, bool S>
4248 extern void __kmp_mwait_64(int th_gtid, kmp_flag_64<C, S> *flag);
4249 template <bool C, bool S>
4250 extern void __kmp_atomic_mwait_64(int th_gtid, kmp_atomic_flag_64<C, S> *flag);
4251 extern void __kmp_mwait_oncore(int th_gtid, kmp_flag_oncore *flag);
4252 #endif
4253 template <bool C, bool S>
4254 extern void __kmp_resume_32(int target_gtid, kmp_flag_32<C, S> *flag);
4255 template <bool C, bool S>
4256 extern void __kmp_resume_64(int target_gtid, kmp_flag_64<C, S> *flag);
4257 template <bool C, bool S>
4258 extern void __kmp_atomic_resume_64(int target_gtid,
4259  kmp_atomic_flag_64<C, S> *flag);
4260 extern void __kmp_resume_oncore(int target_gtid, kmp_flag_oncore *flag);
4261 
4262 template <bool C, bool S>
4263 int __kmp_execute_tasks_32(kmp_info_t *thread, kmp_int32 gtid,
4264  kmp_flag_32<C, S> *flag, int final_spin,
4265  int *thread_finished,
4266 #if USE_ITT_BUILD
4267  void *itt_sync_obj,
4268 #endif /* USE_ITT_BUILD */
4269  kmp_int32 is_constrained);
4270 template <bool C, bool S>
4271 int __kmp_execute_tasks_64(kmp_info_t *thread, kmp_int32 gtid,
4272  kmp_flag_64<C, S> *flag, int final_spin,
4273  int *thread_finished,
4274 #if USE_ITT_BUILD
4275  void *itt_sync_obj,
4276 #endif /* USE_ITT_BUILD */
4277  kmp_int32 is_constrained);
4278 template <bool C, bool S>
4279 int __kmp_atomic_execute_tasks_64(kmp_info_t *thread, kmp_int32 gtid,
4280  kmp_atomic_flag_64<C, S> *flag,
4281  int final_spin, int *thread_finished,
4282 #if USE_ITT_BUILD
4283  void *itt_sync_obj,
4284 #endif /* USE_ITT_BUILD */
4285  kmp_int32 is_constrained);
4286 int __kmp_execute_tasks_oncore(kmp_info_t *thread, kmp_int32 gtid,
4287  kmp_flag_oncore *flag, int final_spin,
4288  int *thread_finished,
4289 #if USE_ITT_BUILD
4290  void *itt_sync_obj,
4291 #endif /* USE_ITT_BUILD */
4292  kmp_int32 is_constrained);
4293 
4294 extern int __kmp_nesting_mode;
4295 extern int __kmp_nesting_mode_nlevels;
4296 extern int *__kmp_nesting_nth_level;
4297 extern void __kmp_init_nesting_mode();
4298 extern void __kmp_set_nesting_mode_threads();
4299 
4307  FILE *f;
4308 
4309  void close() {
4310  if (f && f != stdout && f != stderr) {
4311  fclose(f);
4312  f = nullptr;
4313  }
4314  }
4315 
4316 public:
4317  kmp_safe_raii_file_t() : f(nullptr) {}
4318  kmp_safe_raii_file_t(const char *filename, const char *mode,
4319  const char *env_var = nullptr)
4320  : f(nullptr) {
4321  open(filename, mode, env_var);
4322  }
4323  ~kmp_safe_raii_file_t() { close(); }
4324 
4328  void open(const char *filename, const char *mode,
4329  const char *env_var = nullptr) {
4330  KMP_ASSERT(!f);
4331  f = fopen(filename, mode);
4332  if (!f) {
4333  int code = errno;
4334  if (env_var) {
4335  __kmp_fatal(KMP_MSG(CantOpenFileForReading, filename), KMP_ERR(code),
4336  KMP_HNT(CheckEnvVar, env_var, filename), __kmp_msg_null);
4337  } else {
4338  __kmp_fatal(KMP_MSG(CantOpenFileForReading, filename), KMP_ERR(code),
4339  __kmp_msg_null);
4340  }
4341  }
4342  }
4345  int try_open(const char *filename, const char *mode) {
4346  KMP_ASSERT(!f);
4347  f = fopen(filename, mode);
4348  if (!f)
4349  return errno;
4350  return 0;
4351  }
4354  void set_stdout() {
4355  KMP_ASSERT(!f);
4356  f = stdout;
4357  }
4360  void set_stderr() {
4361  KMP_ASSERT(!f);
4362  f = stderr;
4363  }
4364  operator bool() { return bool(f); }
4365  operator FILE *() { return f; }
4366 };
4367 
4368 template <typename SourceType, typename TargetType,
4369  bool isSourceSmaller = (sizeof(SourceType) < sizeof(TargetType)),
4370  bool isSourceEqual = (sizeof(SourceType) == sizeof(TargetType)),
4371  bool isSourceSigned = std::is_signed<SourceType>::value,
4372  bool isTargetSigned = std::is_signed<TargetType>::value>
4373 struct kmp_convert {};
4374 
4375 // Both types are signed; Source smaller
4376 template <typename SourceType, typename TargetType>
4377 struct kmp_convert<SourceType, TargetType, true, false, true, true> {
4378  static TargetType to(SourceType src) { return (TargetType)src; }
4379 };
4380 // Source equal
4381 template <typename SourceType, typename TargetType>
4382 struct kmp_convert<SourceType, TargetType, false, true, true, true> {
4383  static TargetType to(SourceType src) { return src; }
4384 };
4385 // Source bigger
4386 template <typename SourceType, typename TargetType>
4387 struct kmp_convert<SourceType, TargetType, false, false, true, true> {
4388  static TargetType to(SourceType src) {
4389  KMP_ASSERT(src <= static_cast<SourceType>(
4390  (std::numeric_limits<TargetType>::max)()));
4391  KMP_ASSERT(src >= static_cast<SourceType>(
4392  (std::numeric_limits<TargetType>::min)()));
4393  return (TargetType)src;
4394  }
4395 };
4396 
4397 // Source signed, Target unsigned
4398 // Source smaller
4399 template <typename SourceType, typename TargetType>
4400 struct kmp_convert<SourceType, TargetType, true, false, true, false> {
4401  static TargetType to(SourceType src) {
4402  KMP_ASSERT(src >= 0);
4403  return (TargetType)src;
4404  }
4405 };
4406 // Source equal
4407 template <typename SourceType, typename TargetType>
4408 struct kmp_convert<SourceType, TargetType, false, true, true, false> {
4409  static TargetType to(SourceType src) {
4410  KMP_ASSERT(src >= 0);
4411  return (TargetType)src;
4412  }
4413 };
4414 // Source bigger
4415 template <typename SourceType, typename TargetType>
4416 struct kmp_convert<SourceType, TargetType, false, false, true, false> {
4417  static TargetType to(SourceType src) {
4418  KMP_ASSERT(src >= 0);
4419  KMP_ASSERT(src <= static_cast<SourceType>(
4420  (std::numeric_limits<TargetType>::max)()));
4421  return (TargetType)src;
4422  }
4423 };
4424 
4425 // Source unsigned, Target signed
4426 // Source smaller
4427 template <typename SourceType, typename TargetType>
4428 struct kmp_convert<SourceType, TargetType, true, false, false, true> {
4429  static TargetType to(SourceType src) { return (TargetType)src; }
4430 };
4431 // Source equal
4432 template <typename SourceType, typename TargetType>
4433 struct kmp_convert<SourceType, TargetType, false, true, false, true> {
4434  static TargetType to(SourceType src) {
4435  KMP_ASSERT(src <= static_cast<SourceType>(
4436  (std::numeric_limits<TargetType>::max)()));
4437  return (TargetType)src;
4438  }
4439 };
4440 // Source bigger
4441 template <typename SourceType, typename TargetType>
4442 struct kmp_convert<SourceType, TargetType, false, false, false, true> {
4443  static TargetType to(SourceType src) {
4444  KMP_ASSERT(src <= static_cast<SourceType>(
4445  (std::numeric_limits<TargetType>::max)()));
4446  return (TargetType)src;
4447  }
4448 };
4449 
4450 // Source unsigned, Target unsigned
4451 // Source smaller
4452 template <typename SourceType, typename TargetType>
4453 struct kmp_convert<SourceType, TargetType, true, false, false, false> {
4454  static TargetType to(SourceType src) { return (TargetType)src; }
4455 };
4456 // Source equal
4457 template <typename SourceType, typename TargetType>
4458 struct kmp_convert<SourceType, TargetType, false, true, false, false> {
4459  static TargetType to(SourceType src) { return src; }
4460 };
4461 // Source bigger
4462 template <typename SourceType, typename TargetType>
4463 struct kmp_convert<SourceType, TargetType, false, false, false, false> {
4464  static TargetType to(SourceType src) {
4465  KMP_ASSERT(src <= static_cast<SourceType>(
4466  (std::numeric_limits<TargetType>::max)()));
4467  return (TargetType)src;
4468  }
4469 };
4470 
4471 template <typename T1, typename T2>
4472 static inline void __kmp_type_convert(T1 src, T2 *dest) {
4473  *dest = kmp_convert<T1, T2>::to(src);
4474 }
4475 
4476 #endif /* KMP_H */
void set_stdout()
Definition: kmp.h:4354
void set_stderr()
Definition: kmp.h:4360
int try_open(const char *filename, const char *mode)
Definition: kmp.h:4345
void open(const char *filename, const char *mode, const char *env_var=nullptr)
Definition: kmp.h:4328
struct ident ident_t
@ KMP_IDENT_KMPC
Definition: kmp.h:190
@ KMP_IDENT_IMB
Definition: kmp.h:188
@ KMP_IDENT_WORK_LOOP
Definition: kmp.h:208
@ KMP_IDENT_BARRIER_IMPL
Definition: kmp.h:199
@ KMP_IDENT_WORK_SECTIONS
Definition: kmp.h:210
@ KMP_IDENT_AUTOPAR
Definition: kmp.h:193
@ KMP_IDENT_ATOMIC_HINT_MASK
Definition: kmp.h:217
@ KMP_IDENT_WORK_DISTRIBUTE
Definition: kmp.h:212
@ KMP_IDENT_BARRIER_EXPL
Definition: kmp.h:197
@ KMP_IDENT_ATOMIC_REDUCE
Definition: kmp.h:195
KMP_EXPORT kmp_int32 __kmpc_ok_to_fork(ident_t *)
KMP_EXPORT void __kmpc_fork_teams(ident_t *loc, kmp_int32 argc, kmpc_micro microtask,...)
KMP_EXPORT void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_threads)
KMP_EXPORT void __kmpc_serialized_parallel(ident_t *, kmp_int32 global_tid)
KMP_EXPORT void __kmpc_push_num_teams(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_teams, kmp_int32 num_threads)
KMP_EXPORT void __kmpc_fork_call(ident_t *, kmp_int32 nargs, kmpc_micro microtask,...)
KMP_EXPORT void __kmpc_end_serialized_parallel(ident_t *, kmp_int32 global_tid)
void(* kmpc_micro)(kmp_int32 *global_tid, kmp_int32 *bound_tid,...)
Definition: kmp.h:1593
KMP_EXPORT void __kmpc_push_num_teams_51(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_teams_lb, kmp_int32 num_teams_ub, kmp_int32 num_threads)
KMP_EXPORT void __kmpc_begin(ident_t *, kmp_int32 flags)
KMP_EXPORT void __kmpc_end(ident_t *)
KMP_EXPORT void __kmpc_end_reduce(ident_t *loc, kmp_int32 global_tid, kmp_critical_name *lck)
KMP_EXPORT void __kmpc_end_barrier_master(ident_t *, kmp_int32 global_tid)
KMP_EXPORT kmp_int32 __kmpc_barrier_master_nowait(ident_t *, kmp_int32 global_tid)
KMP_EXPORT void __kmpc_end_reduce_nowait(ident_t *loc, kmp_int32 global_tid, kmp_critical_name *lck)
KMP_EXPORT kmp_int32 __kmpc_reduce(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_vars, size_t reduce_size, void *reduce_data, void(*reduce_func)(void *lhs_data, void *rhs_data), kmp_critical_name *lck)
KMP_EXPORT void __kmpc_barrier(ident_t *, kmp_int32 global_tid)
KMP_EXPORT void __kmpc_flush(ident_t *)
KMP_EXPORT kmp_int32 __kmpc_barrier_master(ident_t *, kmp_int32 global_tid)
KMP_EXPORT kmp_int32 __kmpc_reduce_nowait(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_vars, size_t reduce_size, void *reduce_data, void(*reduce_func)(void *lhs_data, void *rhs_data), kmp_critical_name *lck)
void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int nogroup, int sched, kmp_uint64 grainsize, void *task_dup)
KMP_EXPORT void * __kmpc_taskred_modifier_init(ident_t *loc, int gtid, int is_ws, int num, void *data)
KMP_EXPORT void * __kmpc_taskred_init(int gtid, int num_data, void *data)
KMP_EXPORT void * __kmpc_task_reduction_init(int gtid, int num_data, void *data)
KMP_EXPORT void __kmpc_proxy_task_completed_ooo(kmp_task_t *ptask)
KMP_EXPORT void __kmpc_task_reduction_modifier_fini(ident_t *loc, int gtid, int is_ws)
KMP_EXPORT kmp_int32 __kmpc_omp_task_with_deps(ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *new_task, kmp_int32 ndeps, kmp_depend_info_t *dep_list, kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list)
KMP_EXPORT kmp_int32 __kmpc_omp_reg_task_with_affinity(ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *new_task, kmp_int32 naffins, kmp_task_affinity_info_t *affin_list)
KMP_EXPORT void * __kmpc_task_reduction_modifier_init(ident_t *loc, int gtid, int is_ws, int num, void *data)
void __kmpc_taskloop_5(ident_t *loc, int gtid, kmp_task_t *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int nogroup, int sched, kmp_uint64 grainsize, int modifier, void *task_dup)
KMP_EXPORT void __kmpc_proxy_task_completed(kmp_int32 gtid, kmp_task_t *ptask)
KMP_EXPORT void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32 gtid, kmp_int32 ndeps, kmp_depend_info_t *dep_list, kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list)
KMP_EXPORT void * __kmpc_task_reduction_get_th_data(int gtid, void *tg, void *d)
void(* kmpc_dtor)(void *)
Definition: kmp.h:1617
KMP_EXPORT void __kmpc_threadprivate_register(ident_t *, void *data, kmpc_ctor ctor, kmpc_cctor cctor, kmpc_dtor dtor)
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)
void *(* kmpc_ctor)(void *)
Definition: kmp.h:1611
void *(* kmpc_ctor_vec)(void *, size_t)
Definition: kmp.h:1634
void *(* kmpc_cctor)(void *, void *)
Definition: kmp.h:1624
KMP_EXPORT void * __kmpc_threadprivate_cached(ident_t *loc, kmp_int32 global_tid, void *data, size_t size, void ***cache)
void *(* kmpc_cctor_vec)(void *, void *, size_t)
Definition: kmp.h:1646
void(* kmpc_dtor_vec)(void *, size_t)
Definition: kmp.h:1640
KMP_EXPORT void __kmpc_threadprivate_register_vec(ident_t *, void *data, kmpc_ctor_vec ctor, kmpc_cctor_vec cctor, kmpc_dtor_vec dtor, size_t vector_length)
KMP_EXPORT kmp_int32 __kmpc_global_num_threads(ident_t *)
KMP_EXPORT kmp_int32 __kmpc_global_thread_num(ident_t *)
KMP_EXPORT kmp_int32 __kmpc_in_parallel(ident_t *loc)
KMP_EXPORT kmp_int32 __kmpc_bound_thread_num(ident_t *)
KMP_EXPORT kmp_int32 __kmpc_bound_num_threads(ident_t *)
KMP_EXPORT void __kmpc_end_ordered(ident_t *, kmp_int32 global_tid)
KMP_EXPORT void __kmpc_end_critical(ident_t *, kmp_int32 global_tid, kmp_critical_name *)
KMP_EXPORT void __kmpc_for_static_fini(ident_t *loc, kmp_int32 global_tid)
int __kmpc_dispatch_next_4(ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last, kmp_int32 *p_lb, kmp_int32 *p_ub, kmp_int32 *p_st)
sched_type
Definition: kmp.h:351
KMP_EXPORT void __kmpc_end_masked(ident_t *, kmp_int32 global_tid)
void __kmpc_dispatch_fini_4(ident_t *loc, kmp_int32 gtid)
KMP_EXPORT kmp_int32 __kmpc_master(ident_t *, kmp_int32 global_tid)
KMP_EXPORT void __kmpc_critical_with_hint(ident_t *, kmp_int32 global_tid, kmp_critical_name *, uint32_t hint)
KMP_EXPORT kmp_int32 __kmpc_single(ident_t *, kmp_int32 global_tid)
void __kmpc_doacross_init(ident_t *loc, int gtid, int num_dims, const struct kmp_dim *dims)
int __kmpc_dispatch_next_4u(ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last, kmp_uint32 *p_lb, kmp_uint32 *p_ub, kmp_int32 *p_st)
KMP_EXPORT void __kmpc_end_master(ident_t *, kmp_int32 global_tid)
KMP_EXPORT void __kmpc_end_single(ident_t *, kmp_int32 global_tid)
int __kmpc_dispatch_next_8u(ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last, kmp_uint64 *p_lb, kmp_uint64 *p_ub, kmp_int64 *p_st)
void __kmpc_dispatch_fini_8(ident_t *loc, kmp_int32 gtid)
int __kmpc_dispatch_next_8(ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last, kmp_int64 *p_lb, kmp_int64 *p_ub, kmp_int64 *p_st)
void __kmpc_dispatch_fini_8u(ident_t *loc, kmp_int32 gtid)
KMP_EXPORT void __kmpc_ordered(ident_t *, kmp_int32 global_tid)
KMP_EXPORT kmp_int32 __kmpc_masked(ident_t *, kmp_int32 global_tid, kmp_int32 filter)
void __kmpc_dispatch_init_4(ident_t *loc, kmp_int32 gtid, enum sched_type schedule, kmp_int32 lb, kmp_int32 ub, kmp_int32 st, kmp_int32 chunk)
void __kmpc_dispatch_init_4u(ident_t *loc, kmp_int32 gtid, enum sched_type schedule, kmp_uint32 lb, kmp_uint32 ub, kmp_int32 st, kmp_int32 chunk)
void __kmpc_dispatch_init_8u(ident_t *loc, kmp_int32 gtid, enum sched_type schedule, kmp_uint64 lb, kmp_uint64 ub, kmp_int64 st, kmp_int64 chunk)
void __kmpc_dispatch_fini_4u(ident_t *loc, kmp_int32 gtid)
void __kmpc_dispatch_init_8(ident_t *loc, kmp_int32 gtid, enum sched_type schedule, kmp_int64 lb, kmp_int64 ub, kmp_int64 st, kmp_int64 chunk)
KMP_EXPORT void __kmpc_critical(ident_t *, kmp_int32 global_tid, kmp_critical_name *)
@ kmp_nm_guided_chunked
Definition: kmp.h:402
@ kmp_sch_runtime_simd
Definition: kmp.h:373
@ kmp_nm_ord_auto
Definition: kmp.h:421
@ kmp_sch_auto
Definition: kmp.h:358
@ kmp_nm_auto
Definition: kmp.h:404
@ kmp_distribute_static_chunked
Definition: kmp.h:389
@ kmp_sch_static
Definition: kmp.h:354
@ kmp_sch_guided_simd
Definition: kmp.h:372
@ kmp_sch_modifier_monotonic
Definition: kmp.h:439
@ kmp_sch_default
Definition: kmp.h:459
@ kmp_sch_modifier_nonmonotonic
Definition: kmp.h:441
@ kmp_nm_ord_static
Definition: kmp.h:417
@ kmp_distribute_static
Definition: kmp.h:390
@ kmp_sch_guided_chunked
Definition: kmp.h:356
@ kmp_nm_static
Definition: kmp.h:400
@ kmp_sch_lower
Definition: kmp.h:352
@ kmp_nm_upper
Definition: kmp.h:423
@ kmp_ord_lower
Definition: kmp.h:378
@ kmp_ord_static
Definition: kmp.h:380
@ kmp_sch_upper
Definition: kmp.h:376
@ kmp_ord_upper
Definition: kmp.h:386
@ kmp_nm_lower
Definition: kmp.h:396
@ kmp_ord_auto
Definition: kmp.h:384
Definition: kmp.h:228
kmp_int32 reserved_1
Definition: kmp.h:229
char const * psource
Definition: kmp.h:238
kmp_int32 reserved_2
Definition: kmp.h:232
kmp_int32 reserved_3
Definition: kmp.h:237
kmp_int32 flags
Definition: kmp.h:230