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