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