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