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