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