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