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