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