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