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