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