blob: dc1d7aed864298a09bf40116beb8806743020921 [file] [log] [blame]
Jim Cownie5e8470a2013-09-27 10:38:44 +00001/*
2 * kmp_settings.c -- Initialize environment variables
Jim Cownie5e8470a2013-09-27 10:38:44 +00003 */
4
5
6//===----------------------------------------------------------------------===//
7//
8// The LLVM Compiler Infrastructure
9//
10// This file is dual licensed under the MIT and the University of Illinois Open
11// Source Licenses. See LICENSE.txt for details.
12//
13//===----------------------------------------------------------------------===//
14
15
16#include "kmp.h"
17#include "kmp_wrapper_getpid.h"
18#include "kmp_environment.h"
19#include "kmp_atomic.h"
20#include "kmp_itt.h"
21#include "kmp_str.h"
22#include "kmp_settings.h"
23#include "kmp_i18n.h"
Paul Osmialowskifb043fd2016-05-16 09:44:11 +000024#include "kmp_lock.h"
Jim Cownie5e8470a2013-09-27 10:38:44 +000025#include "kmp_io.h"
26
Jim Cownie5e8470a2013-09-27 10:38:44 +000027static int __kmp_env_toPrint( char const * name, int flag );
28
29bool __kmp_env_format = 0; // 0 - old format; 1 - new format
30// -------------------------------------------------------------------------------------------------
31// Helper string functions. Subject to move to kmp_str.
32// -------------------------------------------------------------------------------------------------
33
34static double
35__kmp_convert_to_double( char const * s )
36{
37 double result;
38
Andrey Churbanov74bf17b2015-04-02 13:27:08 +000039 if ( KMP_SSCANF( s, "%lf", &result ) < 1 ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +000040 result = 0.0;
41 }
42
43 return result;
44}
45
Jonathan Peyton2321d572015-06-08 19:25:25 +000046#ifdef KMP_DEBUG
Jim Cownie5e8470a2013-09-27 10:38:44 +000047static unsigned int
48__kmp_readstr_with_sentinel(char *dest, char const * src, size_t len, char sentinel) {
49 unsigned int i;
50 for (i = 0; i < len; i++) {
51 if ((*src == '\0') || (*src == sentinel)) {
52 break;
53 }
54 *(dest++) = *(src++);
55 }
56 *dest = '\0';
57 return i;
58}
Jonathan Peyton2321d572015-06-08 19:25:25 +000059#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +000060
61static int
62__kmp_match_with_sentinel( char const * a, char const * b, size_t len, char sentinel ) {
63 size_t l = 0;
64
65 if(a == NULL)
66 a = "";
67 if(b == NULL)
68 b = "";
69 while(*a && *b && *b != sentinel) {
70 char ca = *a, cb = *b;
71
72 if(ca >= 'a' && ca <= 'z')
73 ca -= 'a' - 'A';
74 if(cb >= 'a' && cb <= 'z')
75 cb -= 'a' - 'A';
76 if(ca != cb)
77 return FALSE;
78 ++l;
79 ++a;
80 ++b;
81 }
82 return l >= len;
83}
84
85//
86// Expected usage:
87// token is the token to check for.
88// buf is the string being parsed.
89// *end returns the char after the end of the token.
90// it is not modified unless a match occurs.
91//
92//
93// Example 1:
94//
95// if (__kmp_match_str("token", buf, *end) {
96// <do something>
97// buf = end;
98// }
99//
100// Example 2:
101//
102// if (__kmp_match_str("token", buf, *end) {
103// char *save = **end;
104// **end = sentinel;
105// <use any of the __kmp*_with_sentinel() functions>
106// **end = save;
107// buf = end;
108// }
109//
110
111static int
112__kmp_match_str( char const *token, char const *buf, const char **end) {
113
114 KMP_ASSERT(token != NULL);
115 KMP_ASSERT(buf != NULL);
116 KMP_ASSERT(end != NULL);
117
118 while (*token && *buf) {
119 char ct = *token, cb = *buf;
120
121 if(ct >= 'a' && ct <= 'z')
122 ct -= 'a' - 'A';
123 if(cb >= 'a' && cb <= 'z')
124 cb -= 'a' - 'A';
125 if (ct != cb)
126 return FALSE;
127 ++token;
128 ++buf;
129 }
130 if (*token) {
131 return FALSE;
132 }
133 *end = buf;
134 return TRUE;
135}
136
Jim Cownie5e8470a2013-09-27 10:38:44 +0000137
138static size_t
139__kmp_round4k( size_t size ) {
140 size_t _4k = 4 * 1024;
141 if ( size & ( _4k - 1 ) ) {
142 size &= ~ ( _4k - 1 );
143 if ( size <= KMP_SIZE_T_MAX - _4k ) {
144 size += _4k; // Round up if there is no overflow.
145 }; // if
146 }; // if
147 return size;
148} // __kmp_round4k
149
150
Jim Cownie5e8470a2013-09-27 10:38:44 +0000151/*
152 Here, multipliers are like __kmp_convert_to_seconds, but floating-point
153 values are allowed, and the return value is in milliseconds. The default
154 multiplier is milliseconds. Returns INT_MAX only if the value specified
Alp Tokerafc9eb32014-02-25 22:04:37 +0000155 matches "infinit*". Returns -1 if specified string is invalid.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000156*/
157int
158__kmp_convert_to_milliseconds( char const * data )
159{
160 int ret, nvalues, factor;
161 char mult, extra;
162 double value;
163
164 if (data == NULL) return (-1);
Alp Tokerafc9eb32014-02-25 22:04:37 +0000165 if ( __kmp_str_match( "infinit", -1, data)) return (INT_MAX);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000166 value = (double) 0.0;
167 mult = '\0';
Andrey Churbanov74bf17b2015-04-02 13:27:08 +0000168 nvalues = KMP_SSCANF (data, "%lf%c%c", &value, &mult, &extra);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000169 if (nvalues < 1) return (-1);
170 if (nvalues == 1) mult = '\0';
171 if (nvalues == 3) return (-1);
172
173 if (value < 0) return (-1);
174
175 switch (mult) {
176 case '\0':
177 /* default is milliseconds */
178 factor = 1;
179 break;
180 case 's': case 'S':
181 factor = 1000;
182 break;
183 case 'm': case 'M':
184 factor = 1000 * 60;
185 break;
186 case 'h': case 'H':
187 factor = 1000 * 60 * 60;
188 break;
189 case 'd': case 'D':
190 factor = 1000 * 24 * 60 * 60;
191 break;
192 default:
193 return (-1);
194 }
195
196 if ( value >= ( (INT_MAX-1) / factor) )
197 ret = INT_MAX-1; /* Don't allow infinite value here */
198 else
199 ret = (int) (value * (double) factor); /* truncate to int */
200
201 return ret;
202}
203
Jim Cownie5e8470a2013-09-27 10:38:44 +0000204
205static int
206__kmp_strcasecmp_with_sentinel( char const * a, char const * b, char sentinel ) {
207 if(a == NULL)
208 a = "";
209 if(b == NULL)
210 b = "";
211 while(*a && *b && *b != sentinel) {
212 char ca = *a, cb = *b;
213
214 if(ca >= 'a' && ca <= 'z')
215 ca -= 'a' - 'A';
216 if(cb >= 'a' && cb <= 'z')
217 cb -= 'a' - 'A';
218 if(ca != cb)
219 return (int)(unsigned char)*a - (int)(unsigned char)*b;
220 ++a;
221 ++b;
222 }
223 return *a ?
224 (*b && *b != sentinel) ? (int)(unsigned char)*a - (int)(unsigned char)*b : 1 :
225 (*b && *b != sentinel) ? -1 : 0;
226}
227
228
229// =================================================================================================
230// Table structures and helper functions.
231// =================================================================================================
232
233typedef struct __kmp_setting kmp_setting_t;
234typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
235typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
236typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
237
238typedef void ( * kmp_stg_parse_func_t )( char const * name, char const * value, void * data );
239typedef void ( * kmp_stg_print_func_t )( kmp_str_buf_t * buffer, char const * name, void * data );
240
241struct __kmp_setting {
242 char const * name; // Name of setting (environment variable).
243 kmp_stg_parse_func_t parse; // Parser function.
244 kmp_stg_print_func_t print; // Print function.
245 void * data; // Data passed to parser and printer.
246 int set; // Variable set during this "session"
247 // (__kmp_env_initialize() or kmp_set_defaults() call).
248 int defined; // Variable set in any "session".
249}; // struct __kmp_setting
250
251struct __kmp_stg_ss_data {
252 size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
253 kmp_setting_t * * rivals; // Array of pointers to rivals (including itself).
254}; // struct __kmp_stg_ss_data
255
256struct __kmp_stg_wp_data {
257 int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
258 kmp_setting_t * * rivals; // Array of pointers to rivals (including itself).
259}; // struct __kmp_stg_wp_data
260
261struct __kmp_stg_fr_data {
262 int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
263 kmp_setting_t * * rivals; // Array of pointers to rivals (including itself).
264}; // struct __kmp_stg_fr_data
265
266static int
267__kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
268 char const * name, // Name of variable.
269 char const * value, // Value of the variable.
270 kmp_setting_t * * rivals // List of rival settings (the list must include current one).
271);
272
273
274// -------------------------------------------------------------------------------------------------
275// Helper parse functions.
276// -------------------------------------------------------------------------------------------------
277
278static void
279__kmp_stg_parse_bool(
280 char const * name,
281 char const * value,
282 int * out
283) {
284 if ( __kmp_str_match_true( value ) ) {
285 * out = TRUE;
286 } else if (__kmp_str_match_false( value ) ) {
287 * out = FALSE;
288 } else {
289 __kmp_msg(
290 kmp_ms_warning,
291 KMP_MSG( BadBoolValue, name, value ),
292 KMP_HNT( ValidBoolValues ),
293 __kmp_msg_null
294 );
295 }; // if
296} // __kmp_stg_parse_bool
297
298static void
299__kmp_stg_parse_size(
300 char const * name,
301 char const * value,
302 size_t size_min,
303 size_t size_max,
304 int * is_specified,
305 size_t * out,
306 size_t factor
307) {
308 char const * msg = NULL;
309 #if KMP_OS_DARWIN
310 size_min = __kmp_round4k( size_min );
311 size_max = __kmp_round4k( size_max );
312 #endif // KMP_OS_DARWIN
313 if ( value ) {
314 if ( is_specified != NULL ) {
315 * is_specified = 1;
316 }; // if
317 __kmp_str_to_size( value, out, factor, & msg );
318 if ( msg == NULL ) {
319 if ( * out > size_max ) {
320 * out = size_max;
321 msg = KMP_I18N_STR( ValueTooLarge );
322 } else if ( * out < size_min ) {
323 * out = size_min;
324 msg = KMP_I18N_STR( ValueTooSmall );
325 } else {
326 #if KMP_OS_DARWIN
327 size_t round4k = __kmp_round4k( * out );
328 if ( * out != round4k ) {
329 * out = round4k;
330 msg = KMP_I18N_STR( NotMultiple4K );
331 }; // if
332 #endif
333 }; // if
334 } else {
Alp Toker8f2d3f02014-02-24 10:40:15 +0000335 // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to size_max silently.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000336 if ( * out < size_min ) {
337 * out = size_max;
338 }
339 else if ( * out > size_max ) {
340 * out = size_max;
341 }; // if
342 }; // if
343 if ( msg != NULL ) {
344 // Message is not empty. Print warning.
345 kmp_str_buf_t buf;
346 __kmp_str_buf_init( & buf );
347 __kmp_str_buf_print_size( & buf, * out );
348 KMP_WARNING( ParseSizeIntWarn, name, value, msg );
349 KMP_INFORM( Using_str_Value, name, buf.str );
350 __kmp_str_buf_free( & buf );
351 }; // if
352 }; // if
353} // __kmp_stg_parse_size
354
Jonathan Peyton2321d572015-06-08 19:25:25 +0000355#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +0000356static void
357__kmp_stg_parse_str(
358 char const * name,
359 char const * value,
360 char const * * out
361) {
362 KMP_INTERNAL_FREE( (void *) * out );
363 * out = __kmp_str_format( "%s", value );
364} // __kmp_stg_parse_str
Jonathan Peyton2321d572015-06-08 19:25:25 +0000365#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000366
367static void
368__kmp_stg_parse_int(
369 char const * name, // I: Name of environment variable (used in warning messages).
370 char const * value, // I: Value of environment variable to parse.
371 int min, // I: Miminal allowed value.
372 int max, // I: Maximum allowed value.
373 int * out // O: Output (parsed) value.
374) {
375 char const * msg = NULL;
376 kmp_uint64 uint = * out;
377 __kmp_str_to_uint( value, & uint, & msg );
378 if ( msg == NULL ) {
379 if ( uint < (unsigned int)min ) {
380 msg = KMP_I18N_STR( ValueTooSmall );
381 uint = min;
382 } else if ( uint > (unsigned int)max ) {
383 msg = KMP_I18N_STR( ValueTooLarge );
384 uint = max;
385 }; // if
386 } else {
Alp Toker8f2d3f02014-02-24 10:40:15 +0000387 // If overflow occurred msg contains error message and uint is very big. Cut tmp it
Jim Cownie5e8470a2013-09-27 10:38:44 +0000388 // to INT_MAX.
389 if ( uint < (unsigned int)min ) {
390 uint = min;
391 }
392 else if ( uint > (unsigned int)max ) {
393 uint = max;
394 }; // if
395 }; // if
396 if ( msg != NULL ) {
397 // Message is not empty. Print warning.
398 kmp_str_buf_t buf;
399 KMP_WARNING( ParseSizeIntWarn, name, value, msg );
400 __kmp_str_buf_init( & buf );
401 __kmp_str_buf_print( &buf, "%" KMP_UINT64_SPEC "", uint );
402 KMP_INFORM( Using_uint64_Value, name, buf.str );
403 __kmp_str_buf_free( &buf );
404 }; // if
405 * out = uint;
406} // __kmp_stg_parse_int
407
408
Jonathan Peyton2321d572015-06-08 19:25:25 +0000409#if KMP_DEBUG_ADAPTIVE_LOCKS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000410static void
411__kmp_stg_parse_file(
412 char const * name,
413 char const * value,
414 char * suffix,
415 char * * out
416) {
417 char buffer[256];
418 char *t;
419 int hasSuffix;
420 KMP_INTERNAL_FREE( (void *) * out );
421 t = (char *) strrchr(value, '.');
422 hasSuffix = t && __kmp_str_eqf( t, suffix );
423 t = __kmp_str_format( "%s%s", value, hasSuffix ? "" : suffix );
424 __kmp_expand_file_name( buffer, sizeof(buffer), t);
425 KMP_INTERNAL_FREE(t);
426 * out = __kmp_str_format( "%s", buffer );
427} // __kmp_stg_parse_file
Jonathan Peyton2321d572015-06-08 19:25:25 +0000428#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000429
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000430#ifdef KMP_DEBUG
Jim Cownie5e8470a2013-09-27 10:38:44 +0000431static char * par_range_to_print = NULL;
432
433static void
434__kmp_stg_parse_par_range(
435 char const * name,
436 char const * value,
437 int * out_range,
438 char * out_routine,
439 char * out_file,
440 int * out_lb,
441 int * out_ub
442) {
Andrey Churbanov74bf17b2015-04-02 13:27:08 +0000443 size_t len = KMP_STRLEN( value + 1 );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000444 par_range_to_print = (char *) KMP_INTERNAL_MALLOC( len +1 );
Andrey Churbanov74bf17b2015-04-02 13:27:08 +0000445 KMP_STRNCPY_S( par_range_to_print, len + 1, value, len + 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000446 __kmp_par_range = +1;
447 __kmp_par_range_lb = 0;
448 __kmp_par_range_ub = INT_MAX;
449 for (;;) {
450 unsigned int len;
451 if (( value == NULL ) || ( *value == '\0' )) {
452 break;
453 }
454 if ( ! __kmp_strcasecmp_with_sentinel( "routine", value, '=' )) {
455 value = strchr( value, '=' ) + 1;
456 len = __kmp_readstr_with_sentinel( out_routine,
457 value, KMP_PAR_RANGE_ROUTINE_LEN - 1, ',' );
458 if ( len == 0 ) {
459 goto par_range_error;
460 }
461 value = strchr( value, ',' );
462 if ( value != NULL ) {
463 value++;
464 }
465 continue;
466 }
467 if ( ! __kmp_strcasecmp_with_sentinel( "filename", value, '=' )) {
468 value = strchr( value, '=' ) + 1;
469 len = __kmp_readstr_with_sentinel( out_file,
470 value, KMP_PAR_RANGE_FILENAME_LEN - 1, ',' );
471 if ( len == 0) {
472 goto par_range_error;
473 }
474 value = strchr( value, ',' );
475 if ( value != NULL ) {
476 value++;
477 }
478 continue;
479 }
480 if (( ! __kmp_strcasecmp_with_sentinel( "range", value, '=' ))
481 || ( ! __kmp_strcasecmp_with_sentinel( "incl_range", value, '=' ))) {
482 value = strchr( value, '=' ) + 1;
Andrey Churbanov74bf17b2015-04-02 13:27:08 +0000483 if ( KMP_SSCANF( value, "%d:%d", out_lb, out_ub ) != 2 ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000484 goto par_range_error;
485 }
486 *out_range = +1;
487 value = strchr( value, ',' );
488 if ( value != NULL ) {
489 value++;
490 }
491 continue;
492 }
493 if ( ! __kmp_strcasecmp_with_sentinel( "excl_range", value, '=' )) {
494 value = strchr( value, '=' ) + 1;
Andrey Churbanov74bf17b2015-04-02 13:27:08 +0000495 if ( KMP_SSCANF( value, "%d:%d", out_lb, out_ub) != 2 ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000496 goto par_range_error;
497 }
498 *out_range = -1;
499 value = strchr( value, ',' );
500 if ( value != NULL ) {
501 value++;
502 }
503 continue;
504 }
505 par_range_error:
506 KMP_WARNING( ParRangeSyntax, name );
507 __kmp_par_range = 0;
508 break;
509 }
510} // __kmp_stg_parse_par_range
Jim Cownie3051f972014-08-07 10:12:54 +0000511#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000512
513int
514__kmp_initial_threads_capacity( int req_nproc )
515{
516 int nth = 32;
517
518 /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ), __kmp_max_nth) */
519 if (nth < (4 * req_nproc))
520 nth = (4 * req_nproc);
521 if (nth < (4 * __kmp_xproc))
522 nth = (4 * __kmp_xproc);
523
524 if (nth > __kmp_max_nth)
525 nth = __kmp_max_nth;
526
527 return nth;
528}
529
530
531int
532__kmp_default_tp_capacity( int req_nproc, int max_nth, int all_threads_specified) {
533 int nth = 128;
534
535 if(all_threads_specified)
536 return max_nth;
537 /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ), __kmp_max_nth ) */
538 if (nth < (4 * req_nproc))
539 nth = (4 * req_nproc);
540 if (nth < (4 * __kmp_xproc))
541 nth = (4 * __kmp_xproc);
542
543 if (nth > __kmp_max_nth)
544 nth = __kmp_max_nth;
545
546 return nth;
547}
548
549
550// -------------------------------------------------------------------------------------------------
551// Helper print functions.
552// -------------------------------------------------------------------------------------------------
553
554static void
555__kmp_stg_print_bool( kmp_str_buf_t * buffer, char const * name, int value ) {
556 if( __kmp_env_format ) {
557 KMP_STR_BUF_PRINT_BOOL;
558 } else {
559 __kmp_str_buf_print( buffer, " %s=%s\n", name, value ? "true" : "false" );
560 }
561} // __kmp_stg_print_bool
562
563static void
564__kmp_stg_print_int( kmp_str_buf_t * buffer, char const * name, int value ) {
565 if( __kmp_env_format ) {
566 KMP_STR_BUF_PRINT_INT;
567 } else {
568 __kmp_str_buf_print( buffer, " %s=%d\n", name, value );
569 }
570} // __kmp_stg_print_int
571
572static void
573__kmp_stg_print_uint64( kmp_str_buf_t * buffer, char const * name, kmp_uint64 value ) {
574 if( __kmp_env_format ) {
575 KMP_STR_BUF_PRINT_UINT64;
576 } else {
577 __kmp_str_buf_print( buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value );
578 }
579} // __kmp_stg_print_uint64
580
581static void
582__kmp_stg_print_str( kmp_str_buf_t * buffer, char const * name, char const * value ) {
583 if( __kmp_env_format ) {
584 KMP_STR_BUF_PRINT_STR;
585 } else {
586 __kmp_str_buf_print( buffer, " %s=%s\n", name, value );
587 }
588} // __kmp_stg_print_str
589
590static void
591__kmp_stg_print_size( kmp_str_buf_t * buffer, char const * name, size_t value ) {
592 if( __kmp_env_format ) {
593 KMP_STR_BUF_PRINT_NAME_EX(name);
594 __kmp_str_buf_print_size( buffer, value );
595 __kmp_str_buf_print( buffer, "'\n" );
596 } else {
597 __kmp_str_buf_print( buffer, " %s=", name );
598 __kmp_str_buf_print_size( buffer, value );
599 __kmp_str_buf_print( buffer, "\n" );
600 return;
601 }
602} // __kmp_stg_print_size
603
604
605// =================================================================================================
606// Parse and print functions.
607// =================================================================================================
608
609// -------------------------------------------------------------------------------------------------
610// KMP_ALL_THREADS, KMP_MAX_THREADS, OMP_THREAD_LIMIT
611// -------------------------------------------------------------------------------------------------
612
613static void
614__kmp_stg_parse_all_threads( char const * name, char const * value, void * data ) {
615
616 kmp_setting_t * * rivals = (kmp_setting_t * *) data;
617 int rc;
618 rc = __kmp_stg_check_rivals( name, value, rivals );
619 if ( rc ) {
620 return;
621 }; // if
622 if ( ! __kmp_strcasecmp_with_sentinel( "all", value, 0 ) ) {
623 __kmp_max_nth = __kmp_xproc;
624 __kmp_allThreadsSpecified = 1;
625 } else {
626 __kmp_stg_parse_int( name, value, 1, __kmp_sys_max_nth, & __kmp_max_nth );
627 __kmp_allThreadsSpecified = 0;
628 }
629 K_DIAG( 1, ( "__kmp_max_nth == %d\n", __kmp_max_nth ) );
630
631} // __kmp_stg_parse_all_threads
632
633static void
634__kmp_stg_print_all_threads( kmp_str_buf_t * buffer, char const * name, void * data ) {
635 __kmp_stg_print_int( buffer, name, __kmp_max_nth );
636} // __kmp_stg_print_all_threads
637
638// -------------------------------------------------------------------------------------------------
639// KMP_BLOCKTIME
640// -------------------------------------------------------------------------------------------------
641
642static void
643__kmp_stg_parse_blocktime( char const * name, char const * value, void * data ) {
644 __kmp_dflt_blocktime = __kmp_convert_to_milliseconds( value );
645 if ( __kmp_dflt_blocktime < 0 ) {
646 __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
647 __kmp_msg( kmp_ms_warning, KMP_MSG( InvalidValue, name, value ), __kmp_msg_null );
648 KMP_INFORM( Using_int_Value, name, __kmp_dflt_blocktime );
649 __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
650 } else {
651 if ( __kmp_dflt_blocktime < KMP_MIN_BLOCKTIME ) {
652 __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
653 __kmp_msg( kmp_ms_warning, KMP_MSG( SmallValue, name, value ), __kmp_msg_null );
654 KMP_INFORM( MinValueUsing, name, __kmp_dflt_blocktime );
655 } else if ( __kmp_dflt_blocktime > KMP_MAX_BLOCKTIME ) {
656 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
657 __kmp_msg( kmp_ms_warning, KMP_MSG( LargeValue, name, value ), __kmp_msg_null );
658 KMP_INFORM( MaxValueUsing, name, __kmp_dflt_blocktime );
659 }; // if
660 __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
661 }; // if
662 // calculate number of monitor thread wakeup intervals corresonding to blocktime.
663 __kmp_monitor_wakeups = KMP_WAKEUPS_FROM_BLOCKTIME( __kmp_dflt_blocktime, __kmp_monitor_wakeups );
664 __kmp_bt_intervals = KMP_INTERVALS_FROM_BLOCKTIME( __kmp_dflt_blocktime, __kmp_monitor_wakeups );
665 K_DIAG( 1, ( "__kmp_env_blocktime == %d\n", __kmp_env_blocktime ) );
666 if ( __kmp_env_blocktime ) {
667 K_DIAG( 1, ( "__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime ) );
668 }
669} // __kmp_stg_parse_blocktime
670
671static void
672__kmp_stg_print_blocktime( kmp_str_buf_t * buffer, char const * name, void * data ) {
673 __kmp_stg_print_int( buffer, name, __kmp_dflt_blocktime );
674} // __kmp_stg_print_blocktime
675
676// -------------------------------------------------------------------------------------------------
677// KMP_DUPLICATE_LIB_OK
678// -------------------------------------------------------------------------------------------------
679
680static void
681__kmp_stg_parse_duplicate_lib_ok( char const * name, char const * value, void * data ) {
682 /* actually this variable is not supported,
683 put here for compatibility with earlier builds and for static/dynamic combination */
684 __kmp_stg_parse_bool( name, value, & __kmp_duplicate_library_ok );
685} // __kmp_stg_parse_duplicate_lib_ok
686
687static void
688__kmp_stg_print_duplicate_lib_ok( kmp_str_buf_t * buffer, char const * name, void * data ) {
689 __kmp_stg_print_bool( buffer, name, __kmp_duplicate_library_ok );
690} // __kmp_stg_print_duplicate_lib_ok
691
692// -------------------------------------------------------------------------------------------------
693// KMP_INHERIT_FP_CONTROL
694// -------------------------------------------------------------------------------------------------
695
696#if KMP_ARCH_X86 || KMP_ARCH_X86_64
697
698static void
699__kmp_stg_parse_inherit_fp_control( char const * name, char const * value, void * data ) {
700 __kmp_stg_parse_bool( name, value, & __kmp_inherit_fp_control );
701} // __kmp_stg_parse_inherit_fp_control
702
703static void
704__kmp_stg_print_inherit_fp_control( kmp_str_buf_t * buffer, char const * name, void * data ) {
705#if KMP_DEBUG
706 __kmp_stg_print_bool( buffer, name, __kmp_inherit_fp_control );
707#endif /* KMP_DEBUG */
708} // __kmp_stg_print_inherit_fp_control
709
710#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
711
712// -------------------------------------------------------------------------------------------------
713// KMP_LIBRARY, OMP_WAIT_POLICY
714// -------------------------------------------------------------------------------------------------
715
Jonathan Peyton50e8f182016-04-04 19:38:32 +0000716static char const *blocktime_str = NULL;
717
Jim Cownie5e8470a2013-09-27 10:38:44 +0000718static void
719__kmp_stg_parse_wait_policy( char const * name, char const * value, void * data ) {
720
721 kmp_stg_wp_data_t * wait = (kmp_stg_wp_data_t *) data;
722 int rc;
723
724 rc = __kmp_stg_check_rivals( name, value, wait->rivals );
725 if ( rc ) {
726 return;
727 }; // if
728
729 if ( wait->omp ) {
730 if ( __kmp_str_match( "ACTIVE", 1, value ) ) {
Jonathan Peyton50e8f182016-04-04 19:38:32 +0000731 __kmp_library = library_turnaround;
732 if ( blocktime_str == NULL ) {
733 // KMP_BLOCKTIME not specified, so set default to "infinite".
734 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
735 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000736 } else if ( __kmp_str_match( "PASSIVE", 1, value ) ) {
Jonathan Peyton50e8f182016-04-04 19:38:32 +0000737 __kmp_library = library_throughput;
738 if ( blocktime_str == NULL ) {
739 // KMP_BLOCKTIME not specified, so set default to 0.
740 __kmp_dflt_blocktime = 0;
741 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000742 } else {
743 KMP_WARNING( StgInvalidValue, name, value );
744 }; // if
745 } else {
746 if ( __kmp_str_match( "serial", 1, value ) ) { /* S */
747 __kmp_library = library_serial;
748 } else if ( __kmp_str_match( "throughput", 2, value ) ) { /* TH */
749 __kmp_library = library_throughput;
750 } else if ( __kmp_str_match( "turnaround", 2, value ) ) { /* TU */
751 __kmp_library = library_turnaround;
752 } else if ( __kmp_str_match( "dedicated", 1, value ) ) { /* D */
753 __kmp_library = library_turnaround;
754 } else if ( __kmp_str_match( "multiuser", 1, value ) ) { /* M */
755 __kmp_library = library_throughput;
756 } else {
757 KMP_WARNING( StgInvalidValue, name, value );
758 }; // if
759 }; // if
760 __kmp_aux_set_library( __kmp_library );
761
762} // __kmp_stg_parse_wait_policy
763
764static void
765__kmp_stg_print_wait_policy( kmp_str_buf_t * buffer, char const * name, void * data ) {
766
767 kmp_stg_wp_data_t * wait = (kmp_stg_wp_data_t *) data;
768 char const * value = NULL;
769
770 if ( wait->omp ) {
771 switch ( __kmp_library ) {
772 case library_turnaround : {
773 value = "ACTIVE";
774 } break;
775 case library_throughput : {
776 value = "PASSIVE";
777 } break;
778 }; // switch
779 } else {
780 switch ( __kmp_library ) {
781 case library_serial : {
782 value = "serial";
783 } break;
784 case library_turnaround : {
785 value = "turnaround";
786 } break;
787 case library_throughput : {
788 value = "throughput";
789 } break;
790 }; // switch
791 }; // if
792 if ( value != NULL ) {
793 __kmp_stg_print_str( buffer, name, value );
794 }; // if
795
796} // __kmp_stg_print_wait_policy
797
798// -------------------------------------------------------------------------------------------------
799// KMP_MONITOR_STACKSIZE
800// -------------------------------------------------------------------------------------------------
801
802static void
803__kmp_stg_parse_monitor_stacksize( char const * name, char const * value, void * data ) {
804 __kmp_stg_parse_size(
805 name,
806 value,
807 __kmp_sys_min_stksize,
808 KMP_MAX_STKSIZE,
809 NULL,
810 & __kmp_monitor_stksize,
811 1
812 );
813} // __kmp_stg_parse_monitor_stacksize
814
815static void
816__kmp_stg_print_monitor_stacksize( kmp_str_buf_t * buffer, char const * name, void * data ) {
817 if( __kmp_env_format ) {
818 if ( __kmp_monitor_stksize > 0 )
819 KMP_STR_BUF_PRINT_NAME_EX(name);
820 else
821 KMP_STR_BUF_PRINT_NAME;
822 } else {
823 __kmp_str_buf_print( buffer, " %s", name );
824 }
825 if ( __kmp_monitor_stksize > 0 ) {
826 __kmp_str_buf_print_size( buffer, __kmp_monitor_stksize );
827 } else {
828 __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
829 }
830 if( __kmp_env_format && __kmp_monitor_stksize ) {
831 __kmp_str_buf_print( buffer, "'\n");
832 }
833
834} // __kmp_stg_print_monitor_stacksize
835
836// -------------------------------------------------------------------------------------------------
837// KMP_SETTINGS
838// -------------------------------------------------------------------------------------------------
839
840static void
841__kmp_stg_parse_settings( char const * name, char const * value, void * data ) {
842 __kmp_stg_parse_bool( name, value, & __kmp_settings );
843} // __kmp_stg_parse_settings
844
845static void
846__kmp_stg_print_settings( kmp_str_buf_t * buffer, char const * name, void * data ) {
847 __kmp_stg_print_bool( buffer, name, __kmp_settings );
848} // __kmp_stg_print_settings
849
850// -------------------------------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000851// KMP_STACKPAD
852// -------------------------------------------------------------------------------------------------
853
854static void
855__kmp_stg_parse_stackpad( char const * name, char const * value, void * data ) {
856 __kmp_stg_parse_int(
857 name, // Env var name
858 value, // Env var value
859 KMP_MIN_STKPADDING, // Min value
860 KMP_MAX_STKPADDING, // Max value
861 & __kmp_stkpadding // Var to initialize
862 );
863} // __kmp_stg_parse_stackpad
864
865static void
866__kmp_stg_print_stackpad( kmp_str_buf_t * buffer, char const * name, void * data ) {
867 __kmp_stg_print_int( buffer, name, __kmp_stkpadding );
868} // __kmp_stg_print_stackpad
869
870// -------------------------------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000871// KMP_STACKOFFSET
872// -------------------------------------------------------------------------------------------------
873
874static void
875__kmp_stg_parse_stackoffset( char const * name, char const * value, void * data ) {
876 __kmp_stg_parse_size(
877 name, // Env var name
878 value, // Env var value
879 KMP_MIN_STKOFFSET, // Min value
880 KMP_MAX_STKOFFSET, // Max value
881 NULL, //
882 & __kmp_stkoffset, // Var to initialize
883 1
884 );
885} // __kmp_stg_parse_stackoffset
886
887static void
888__kmp_stg_print_stackoffset( kmp_str_buf_t * buffer, char const * name, void * data ) {
889 __kmp_stg_print_size( buffer, name, __kmp_stkoffset );
890} // __kmp_stg_print_stackoffset
891
892// -------------------------------------------------------------------------------------------------
893// KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
894// -------------------------------------------------------------------------------------------------
895
896static void
897__kmp_stg_parse_stacksize( char const * name, char const * value, void * data ) {
898
899 kmp_stg_ss_data_t * stacksize = (kmp_stg_ss_data_t *) data;
900 int rc;
901
902 rc = __kmp_stg_check_rivals( name, value, stacksize->rivals );
903 if ( rc ) {
904 return;
905 }; // if
906 __kmp_stg_parse_size(
907 name, // Env var name
908 value, // Env var value
909 __kmp_sys_min_stksize, // Min value
910 KMP_MAX_STKSIZE, // Max value
911 & __kmp_env_stksize, //
912 & __kmp_stksize, // Var to initialize
913 stacksize->factor
914 );
915
916} // __kmp_stg_parse_stacksize
917
918// This function is called for printing both KMP_STACKSIZE (factor is 1) and OMP_STACKSIZE (factor is 1024).
919// Currently it is not possible to print OMP_STACKSIZE value in bytes. We can consider adding this
920// possibility by a customer request in future.
921static void
922__kmp_stg_print_stacksize( kmp_str_buf_t * buffer, char const * name, void * data ) {
923 kmp_stg_ss_data_t * stacksize = (kmp_stg_ss_data_t *) data;
924 if( __kmp_env_format ) {
925 KMP_STR_BUF_PRINT_NAME_EX(name);
926 __kmp_str_buf_print_size( buffer, (__kmp_stksize % 1024) ? __kmp_stksize / stacksize->factor : __kmp_stksize );
927 __kmp_str_buf_print( buffer, "'\n" );
928 } else {
929 __kmp_str_buf_print( buffer, " %s=", name );
930 __kmp_str_buf_print_size( buffer, (__kmp_stksize % 1024) ? __kmp_stksize / stacksize->factor : __kmp_stksize );
931 __kmp_str_buf_print( buffer, "\n" );
932 }
933} // __kmp_stg_print_stacksize
934
935// -------------------------------------------------------------------------------------------------
936// KMP_VERSION
937// -------------------------------------------------------------------------------------------------
938
939static void
940__kmp_stg_parse_version( char const * name, char const * value, void * data ) {
941 __kmp_stg_parse_bool( name, value, & __kmp_version );
942} // __kmp_stg_parse_version
943
944static void
945__kmp_stg_print_version( kmp_str_buf_t * buffer, char const * name, void * data ) {
946 __kmp_stg_print_bool( buffer, name, __kmp_version );
947} // __kmp_stg_print_version
948
949// -------------------------------------------------------------------------------------------------
950// KMP_WARNINGS
951// -------------------------------------------------------------------------------------------------
952
953static void
954__kmp_stg_parse_warnings( char const * name, char const * value, void * data ) {
955 __kmp_stg_parse_bool( name, value, & __kmp_generate_warnings );
956 if (__kmp_generate_warnings != kmp_warnings_off) { // AC: we have only 0/1 values documented,
957 __kmp_generate_warnings = kmp_warnings_explicit; // so reset it to explicit in order to
958 } // distinguish from default setting
959} // __kmp_env_parse_warnings
960
961static void
962__kmp_stg_print_warnings( kmp_str_buf_t * buffer, char const * name, void * data ) {
963 __kmp_stg_print_bool( buffer, name, __kmp_generate_warnings ); // AC: TODO: change to print_int?
964} // __kmp_env_print_warnings // (needs documentation change)...
965
966// -------------------------------------------------------------------------------------------------
967// OMP_NESTED, OMP_NUM_THREADS
968// -------------------------------------------------------------------------------------------------
969
970static void
971__kmp_stg_parse_nested( char const * name, char const * value, void * data ) {
972 __kmp_stg_parse_bool( name, value, & __kmp_dflt_nested );
973} // __kmp_stg_parse_nested
974
975static void
976__kmp_stg_print_nested( kmp_str_buf_t * buffer, char const * name, void * data ) {
977 __kmp_stg_print_bool( buffer, name, __kmp_dflt_nested );
978} // __kmp_stg_print_nested
979
980static void
981__kmp_parse_nested_num_threads( const char *var, const char *env, kmp_nested_nthreads_t *nth_array )
982{
983 const char *next = env;
984 const char *scan = next;
985
986 int total = 0; // Count elements that were set. It'll be used as an array size
987 int prev_comma = FALSE; // For correct processing sequential commas
988
989 // Count the number of values in the env. var string
990 for ( ; ; ) {
991 SKIP_WS( next );
992
993 if ( *next == '\0' ) {
994 break;
995 }
996 // Next character is not an integer or not a comma => end of list
997 if ( ( ( *next < '0' ) || ( *next > '9' ) ) && ( *next !=',') ) {
998 KMP_WARNING( NthSyntaxError, var, env );
999 return;
1000 }
1001 // The next character is ','
1002 if ( *next == ',' ) {
1003 // ',' is the fisrt character
1004 if ( total == 0 || prev_comma ) {
1005 total++;
1006 }
1007 prev_comma = TRUE;
1008 next++; //skip ','
1009 SKIP_WS( next );
1010 }
1011 // Next character is a digit
1012 if ( *next >= '0' && *next <= '9' ) {
1013 prev_comma = FALSE;
1014 SKIP_DIGITS( next );
1015 total++;
1016 const char *tmp = next;
1017 SKIP_WS( tmp );
1018 if ( ( *next == ' ' || *next == '\t' ) && ( *tmp >= '0' && *tmp <= '9' ) ) {
1019 KMP_WARNING( NthSpacesNotAllowed, var, env );
1020 return;
1021 }
1022 }
1023 }
1024 KMP_DEBUG_ASSERT( total > 0 );
1025 if( total <= 0 ) {
1026 KMP_WARNING( NthSyntaxError, var, env );
1027 return;
1028 }
1029
1030 // Check if the nested nthreads array exists
1031 if ( ! nth_array->nth ) {
1032 // Allocate an array of double size
1033 nth_array->nth = ( int * )KMP_INTERNAL_MALLOC( sizeof( int ) * total * 2 );
1034 if ( nth_array->nth == NULL ) {
1035 KMP_FATAL( MemoryAllocFailed );
1036 }
1037 nth_array->size = total * 2;
1038 } else {
1039 if ( nth_array->size < total ) {
1040 // Increase the array size
1041 do {
1042 nth_array->size *= 2;
1043 } while ( nth_array->size < total );
1044
1045 nth_array->nth = (int *) KMP_INTERNAL_REALLOC(
1046 nth_array->nth, sizeof( int ) * nth_array->size );
1047 if ( nth_array->nth == NULL ) {
1048 KMP_FATAL( MemoryAllocFailed );
1049 }
1050 }
1051 }
1052 nth_array->used = total;
1053 int i = 0;
1054
1055 prev_comma = FALSE;
1056 total = 0;
1057 // Save values in the array
1058 for ( ; ; ) {
1059 SKIP_WS( scan );
1060 if ( *scan == '\0' ) {
1061 break;
1062 }
1063 // The next character is ','
1064 if ( *scan == ',' ) {
1065 // ',' in the beginning of the list
1066 if ( total == 0 ) {
1067 // The value is supposed to be equal to __kmp_avail_proc but it is unknown at the moment.
1068 // So let's put a placeholder (#threads = 0) to correct it later.
1069 nth_array->nth[i++] = 0;
1070 total++;
1071 }else if ( prev_comma ) {
1072 // Num threads is inherited from the previous level
1073 nth_array->nth[i] = nth_array->nth[i - 1];
1074 i++;
1075 total++;
1076 }
1077 prev_comma = TRUE;
1078 scan++; //skip ','
1079 SKIP_WS( scan );
1080 }
1081 // Next character is a digit
1082 if ( *scan >= '0' && *scan <= '9' ) {
1083 int num;
1084 const char *buf = scan;
1085 char const * msg = NULL;
1086 prev_comma = FALSE;
1087 SKIP_DIGITS( scan );
1088 total++;
1089
1090 num = __kmp_str_to_int( buf, *scan );
1091 if ( num < KMP_MIN_NTH ) {
1092 msg = KMP_I18N_STR( ValueTooSmall );
1093 num = KMP_MIN_NTH;
1094 } else if ( num > __kmp_sys_max_nth ) {
1095 msg = KMP_I18N_STR( ValueTooLarge );
1096 num = __kmp_sys_max_nth;
1097 }
1098 if ( msg != NULL ) {
1099 // Message is not empty. Print warning.
1100 KMP_WARNING( ParseSizeIntWarn, var, env, msg );
1101 KMP_INFORM( Using_int_Value, var, num );
1102 }
1103 nth_array->nth[i++] = num;
1104 }
1105 }
1106}
1107
1108static void
1109__kmp_stg_parse_num_threads( char const * name, char const * value, void * data ) {
1110 // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
1111 if ( ! __kmp_strcasecmp_with_sentinel( "all", value, 0 ) ) {
1112 // The array of 1 element
1113 __kmp_nested_nth.nth = ( int* )KMP_INTERNAL_MALLOC( sizeof( int ) );
1114 __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1115 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub = __kmp_xproc;
1116 } else {
1117 __kmp_parse_nested_num_threads( name, value, & __kmp_nested_nth );
1118 if ( __kmp_nested_nth.nth ) {
1119 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1120 if ( __kmp_dflt_team_nth_ub < __kmp_dflt_team_nth ) {
1121 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1122 }
1123 }
1124 }; // if
1125 K_DIAG( 1, ( "__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth ) );
1126} // __kmp_stg_parse_num_threads
1127
1128static void
1129__kmp_stg_print_num_threads( kmp_str_buf_t * buffer, char const * name, void * data ) {
1130 if( __kmp_env_format ) {
1131 KMP_STR_BUF_PRINT_NAME;
1132 } else {
1133 __kmp_str_buf_print( buffer, " %s", name );
1134 }
1135 if ( __kmp_nested_nth.used ) {
1136 kmp_str_buf_t buf;
1137 __kmp_str_buf_init( &buf );
1138 for ( int i = 0; i < __kmp_nested_nth.used; i++) {
1139 __kmp_str_buf_print( &buf, "%d", __kmp_nested_nth.nth[i] );
1140 if ( i < __kmp_nested_nth.used - 1 ) {
1141 __kmp_str_buf_print( &buf, "," );
1142 }
1143 }
1144 __kmp_str_buf_print( buffer, "='%s'\n", buf.str );
1145 __kmp_str_buf_free(&buf);
1146 } else {
1147 __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
1148 }
1149} // __kmp_stg_print_num_threads
1150
1151// -------------------------------------------------------------------------------------------------
1152// OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
1153// -------------------------------------------------------------------------------------------------
1154
Jim Cownie5e8470a2013-09-27 10:38:44 +00001155static void
1156__kmp_stg_parse_tasking( char const * name, char const * value, void * data ) {
1157 __kmp_stg_parse_int( name, value, 0, (int)tskm_max, (int *)&__kmp_tasking_mode );
1158} // __kmp_stg_parse_tasking
1159
1160static void
1161__kmp_stg_print_tasking( kmp_str_buf_t * buffer, char const * name, void * data ) {
1162 __kmp_stg_print_int( buffer, name, __kmp_tasking_mode );
1163} // __kmp_stg_print_tasking
1164
1165static void
1166__kmp_stg_parse_task_stealing( char const * name, char const * value, void * data ) {
1167 __kmp_stg_parse_int( name, value, 0, 1, (int *)&__kmp_task_stealing_constraint );
1168} // __kmp_stg_parse_task_stealing
1169
1170static void
1171__kmp_stg_print_task_stealing( kmp_str_buf_t * buffer, char const * name, void * data ) {
1172 __kmp_stg_print_int( buffer, name, __kmp_task_stealing_constraint );
1173} // __kmp_stg_print_task_stealing
1174
1175static void
1176__kmp_stg_parse_max_active_levels( char const * name, char const * value, void * data ) {
Jonathan Peyton28510722016-02-25 18:04:09 +00001177 __kmp_stg_parse_int( name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT, & __kmp_dflt_max_active_levels );
Jim Cownie5e8470a2013-09-27 10:38:44 +00001178} // __kmp_stg_parse_max_active_levels
1179
1180static void
1181__kmp_stg_print_max_active_levels( kmp_str_buf_t * buffer, char const * name, void * data ) {
1182 __kmp_stg_print_int( buffer, name, __kmp_dflt_max_active_levels );
1183} // __kmp_stg_print_max_active_levels
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001184
Jonathan Peyton28510722016-02-25 18:04:09 +00001185#if OMP_41_ENABLED
1186// -------------------------------------------------------------------------------------------------
1187// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
1188// -------------------------------------------------------------------------------------------------
1189static void
1190__kmp_stg_parse_max_task_priority(char const *name, char const *value, void *data) {
1191 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT, &__kmp_max_task_priority);
1192} // __kmp_stg_parse_max_task_priority
1193
1194static void
1195__kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer, char const *name, void *data) {
1196 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
1197} // __kmp_stg_print_max_task_priority
1198#endif // OMP_41_ENABLED
1199
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001200#if KMP_NESTED_HOT_TEAMS
1201// -------------------------------------------------------------------------------------------------
1202// KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
1203// -------------------------------------------------------------------------------------------------
1204
1205static void
1206__kmp_stg_parse_hot_teams_level( char const * name, char const * value, void * data ) {
1207 if ( TCR_4(__kmp_init_parallel) ) {
1208 KMP_WARNING( EnvParallelWarn, name );
1209 return;
1210 } // read value before first parallel only
1211 __kmp_stg_parse_int( name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT, & __kmp_hot_teams_max_level );
1212} // __kmp_stg_parse_hot_teams_level
1213
1214static void
1215__kmp_stg_print_hot_teams_level( kmp_str_buf_t * buffer, char const * name, void * data ) {
1216 __kmp_stg_print_int( buffer, name, __kmp_hot_teams_max_level );
1217} // __kmp_stg_print_hot_teams_level
1218
1219static void
1220__kmp_stg_parse_hot_teams_mode( char const * name, char const * value, void * data ) {
1221 if ( TCR_4(__kmp_init_parallel) ) {
1222 KMP_WARNING( EnvParallelWarn, name );
1223 return;
1224 } // read value before first parallel only
1225 __kmp_stg_parse_int( name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT, & __kmp_hot_teams_mode );
1226} // __kmp_stg_parse_hot_teams_mode
1227
1228static void
1229__kmp_stg_print_hot_teams_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
1230 __kmp_stg_print_int( buffer, name, __kmp_hot_teams_mode );
1231} // __kmp_stg_print_hot_teams_mode
1232
1233#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001234
1235// -------------------------------------------------------------------------------------------------
1236// KMP_HANDLE_SIGNALS
1237// -------------------------------------------------------------------------------------------------
1238
1239#if KMP_HANDLE_SIGNALS
1240
1241static void
1242__kmp_stg_parse_handle_signals( char const * name, char const * value, void * data ) {
1243 __kmp_stg_parse_bool( name, value, & __kmp_handle_signals );
1244} // __kmp_stg_parse_handle_signals
1245
1246static void
1247__kmp_stg_print_handle_signals( kmp_str_buf_t * buffer, char const * name, void * data ) {
1248 __kmp_stg_print_bool( buffer, name, __kmp_handle_signals );
1249} // __kmp_stg_print_handle_signals
1250
1251#endif // KMP_HANDLE_SIGNALS
1252
1253// -------------------------------------------------------------------------------------------------
1254// KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
1255// -------------------------------------------------------------------------------------------------
1256
1257#ifdef KMP_DEBUG
1258
1259#define KMP_STG_X_DEBUG( x ) \
1260 static void __kmp_stg_parse_##x##_debug( char const * name, char const * value, void * data ) { \
1261 __kmp_stg_parse_int( name, value, 0, INT_MAX, & kmp_##x##_debug ); \
1262 } /* __kmp_stg_parse_x_debug */ \
1263 static void __kmp_stg_print_##x##_debug( kmp_str_buf_t * buffer, char const * name, void * data ) { \
1264 __kmp_stg_print_int( buffer, name, kmp_##x##_debug ); \
1265 } /* __kmp_stg_print_x_debug */
1266
1267KMP_STG_X_DEBUG( a )
1268KMP_STG_X_DEBUG( b )
1269KMP_STG_X_DEBUG( c )
1270KMP_STG_X_DEBUG( d )
1271KMP_STG_X_DEBUG( e )
1272KMP_STG_X_DEBUG( f )
1273
1274#undef KMP_STG_X_DEBUG
1275
1276static void
1277__kmp_stg_parse_debug( char const * name, char const * value, void * data ) {
1278 int debug = 0;
1279 __kmp_stg_parse_int( name, value, 0, INT_MAX, & debug );
1280 if ( kmp_a_debug < debug ) {
1281 kmp_a_debug = debug;
1282 }; // if
1283 if ( kmp_b_debug < debug ) {
1284 kmp_b_debug = debug;
1285 }; // if
1286 if ( kmp_c_debug < debug ) {
1287 kmp_c_debug = debug;
1288 }; // if
1289 if ( kmp_d_debug < debug ) {
1290 kmp_d_debug = debug;
1291 }; // if
1292 if ( kmp_e_debug < debug ) {
1293 kmp_e_debug = debug;
1294 }; // if
1295 if ( kmp_f_debug < debug ) {
1296 kmp_f_debug = debug;
1297 }; // if
1298} // __kmp_stg_parse_debug
1299
1300static void
1301__kmp_stg_parse_debug_buf( char const * name, char const * value, void * data ) {
1302 __kmp_stg_parse_bool( name, value, & __kmp_debug_buf );
1303 // !!! TODO: Move buffer initialization of of this file! It may works incorrectly if
1304 // KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or KMP_DEBUG_BUF_CHARS.
1305 if ( __kmp_debug_buf ) {
1306 int i;
1307 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
1308
1309 /* allocate and initialize all entries in debug buffer to empty */
1310 __kmp_debug_buffer = (char *) __kmp_page_allocate( elements * sizeof( char ) );
1311 for ( i = 0; i < elements; i += __kmp_debug_buf_chars )
1312 __kmp_debug_buffer[i] = '\0';
1313
1314 __kmp_debug_count = 0;
1315 }
1316 K_DIAG( 1, ( "__kmp_debug_buf = %d\n", __kmp_debug_buf ) );
1317} // __kmp_stg_parse_debug_buf
1318
1319static void
1320__kmp_stg_print_debug_buf( kmp_str_buf_t * buffer, char const * name, void * data ) {
1321 __kmp_stg_print_bool( buffer, name, __kmp_debug_buf );
1322} // __kmp_stg_print_debug_buf
1323
1324static void
1325__kmp_stg_parse_debug_buf_atomic( char const * name, char const * value, void * data ) {
1326 __kmp_stg_parse_bool( name, value, & __kmp_debug_buf_atomic );
1327} // __kmp_stg_parse_debug_buf_atomic
1328
1329static void
1330__kmp_stg_print_debug_buf_atomic( kmp_str_buf_t * buffer, char const * name, void * data ) {
1331 __kmp_stg_print_bool( buffer, name, __kmp_debug_buf_atomic );
1332} // __kmp_stg_print_debug_buf_atomic
1333
1334static void
1335__kmp_stg_parse_debug_buf_chars( char const * name, char const * value, void * data ) {
1336 __kmp_stg_parse_int(
1337 name,
1338 value,
1339 KMP_DEBUG_BUF_CHARS_MIN,
1340 INT_MAX,
1341 & __kmp_debug_buf_chars
1342 );
1343} // __kmp_stg_debug_parse_buf_chars
1344
1345static void
1346__kmp_stg_print_debug_buf_chars( kmp_str_buf_t * buffer, char const * name, void * data ) {
1347 __kmp_stg_print_int( buffer, name, __kmp_debug_buf_chars );
1348} // __kmp_stg_print_debug_buf_chars
1349
1350static void
1351__kmp_stg_parse_debug_buf_lines( char const * name, char const * value, void * data ) {
1352 __kmp_stg_parse_int(
1353 name,
1354 value,
1355 KMP_DEBUG_BUF_LINES_MIN,
1356 INT_MAX,
1357 & __kmp_debug_buf_lines
1358 );
1359} // __kmp_stg_parse_debug_buf_lines
1360
1361static void
1362__kmp_stg_print_debug_buf_lines( kmp_str_buf_t * buffer, char const * name, void * data ) {
1363 __kmp_stg_print_int( buffer, name, __kmp_debug_buf_lines );
1364} // __kmp_stg_print_debug_buf_lines
1365
1366static void
1367__kmp_stg_parse_diag( char const * name, char const * value, void * data ) {
1368 __kmp_stg_parse_int( name, value, 0, INT_MAX, & kmp_diag );
1369} // __kmp_stg_parse_diag
1370
1371static void
1372__kmp_stg_print_diag( kmp_str_buf_t * buffer, char const * name, void * data ) {
1373 __kmp_stg_print_int( buffer, name, kmp_diag );
1374} // __kmp_stg_print_diag
1375
1376#endif // KMP_DEBUG
1377
1378// -------------------------------------------------------------------------------------------------
1379// KMP_ALIGN_ALLOC
1380// -------------------------------------------------------------------------------------------------
1381
1382static void
1383__kmp_stg_parse_align_alloc( char const * name, char const * value, void * data ) {
1384 __kmp_stg_parse_size(
1385 name,
1386 value,
1387 CACHE_LINE,
1388 INT_MAX,
1389 NULL,
1390 & __kmp_align_alloc,
1391 1
1392 );
1393} // __kmp_stg_parse_align_alloc
1394
1395static void
1396__kmp_stg_print_align_alloc( kmp_str_buf_t * buffer, char const * name, void * data ) {
1397 __kmp_stg_print_size( buffer, name, __kmp_align_alloc );
1398} // __kmp_stg_print_align_alloc
1399
1400// -------------------------------------------------------------------------------------------------
1401// KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
1402// -------------------------------------------------------------------------------------------------
1403
1404// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from parse and print
1405// functions, pass required info through data argument.
1406
1407static void
1408__kmp_stg_parse_barrier_branch_bit( char const * name, char const * value, void * data ) {
1409 const char *var;
1410
1411 /* ---------- Barrier branch bit control ------------ */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001412 for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
1413 var = __kmp_barrier_branch_bit_env_name[ i ];
Jim Cownie5e8470a2013-09-27 10:38:44 +00001414 if ( ( strcmp( var, name) == 0 ) && ( value != 0 ) ) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001415 char *comma;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001416
1417 comma = (char *) strchr( value, ',' );
1418 __kmp_barrier_gather_branch_bits[ i ] = ( kmp_uint32 ) __kmp_str_to_int( value, ',' );
1419 /* is there a specified release parameter? */
1420 if ( comma == NULL ) {
1421 __kmp_barrier_release_branch_bits[ i ] = __kmp_barrier_release_bb_dflt;
1422 } else {
1423 __kmp_barrier_release_branch_bits[ i ] = (kmp_uint32) __kmp_str_to_int( comma + 1, 0 );
1424
1425 if ( __kmp_barrier_release_branch_bits[ i ] > KMP_MAX_BRANCH_BITS ) {
1426 __kmp_msg( kmp_ms_warning, KMP_MSG( BarrReleaseValueInvalid, name, comma + 1 ), __kmp_msg_null );
Jim Cownie5e8470a2013-09-27 10:38:44 +00001427 __kmp_barrier_release_branch_bits[ i ] = __kmp_barrier_release_bb_dflt;
1428 }
1429 }
1430 if ( __kmp_barrier_gather_branch_bits[ i ] > KMP_MAX_BRANCH_BITS ) {
1431 KMP_WARNING( BarrGatherValueInvalid, name, value );
1432 KMP_INFORM( Using_uint_Value, name, __kmp_barrier_gather_bb_dflt );
1433 __kmp_barrier_gather_branch_bits[ i ] = __kmp_barrier_gather_bb_dflt;
1434 }
1435 }
1436 K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[ i ], \
1437 __kmp_barrier_gather_branch_bits [ i ], \
1438 __kmp_barrier_release_branch_bits [ i ]))
1439 }
1440} // __kmp_stg_parse_barrier_branch_bit
1441
1442static void
1443__kmp_stg_print_barrier_branch_bit( kmp_str_buf_t * buffer, char const * name, void * data ) {
1444 const char *var;
1445 for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
1446 var = __kmp_barrier_branch_bit_env_name[ i ];
1447 if ( strcmp( var, name) == 0 ) {
1448 if( __kmp_env_format ) {
1449 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[ i ]);
1450 } else {
1451 __kmp_str_buf_print( buffer, " %s='", __kmp_barrier_branch_bit_env_name[ i ] );
1452 }
1453 __kmp_str_buf_print( buffer, "%d,%d'\n", __kmp_barrier_gather_branch_bits [ i ], __kmp_barrier_release_branch_bits [ i ]);
1454 }
1455 }
1456} // __kmp_stg_print_barrier_branch_bit
1457
1458
1459// -------------------------------------------------------------------------------------------------
1460// KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN, KMP_REDUCTION_BARRIER_PATTERN
1461// -------------------------------------------------------------------------------------------------
1462
1463// TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and print functions,
1464// pass required data to functions through data argument.
1465
1466static void
1467__kmp_stg_parse_barrier_pattern( char const * name, char const * value, void * data ) {
1468 const char *var;
1469 /* ---------- Barrier method control ------------ */
1470
1471 for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
1472 var = __kmp_barrier_pattern_env_name[ i ];
1473
1474 if ( ( strcmp ( var, name ) == 0 ) && ( value != 0 ) ) {
1475 int j;
1476 char *comma = (char *) strchr( value, ',' );
1477
1478 /* handle first parameter: gather pattern */
1479 for ( j = bp_linear_bar; j<bp_last_bar; j++ ) {
1480 if (__kmp_match_with_sentinel( __kmp_barrier_pattern_name[j], value, 1, ',' )) {
1481 __kmp_barrier_gather_pattern[ i ] = (kmp_bar_pat_e) j;
1482 break;
1483 }
1484 }
1485 if ( j == bp_last_bar ) {
1486 KMP_WARNING( BarrGatherValueInvalid, name, value );
1487 KMP_INFORM( Using_str_Value, name, __kmp_barrier_pattern_name[ bp_linear_bar ] );
1488 }
1489
1490 /* handle second parameter: release pattern */
1491 if ( comma != NULL ) {
1492 for ( j = bp_linear_bar; j < bp_last_bar; j++ ) {
1493 if ( __kmp_str_match( __kmp_barrier_pattern_name[j], 1, comma + 1 ) ) {
1494 __kmp_barrier_release_pattern[ i ] = (kmp_bar_pat_e) j;
1495 break;
1496 }
1497 }
1498 if (j == bp_last_bar) {
1499 __kmp_msg( kmp_ms_warning, KMP_MSG( BarrReleaseValueInvalid, name, comma + 1 ), __kmp_msg_null );
1500 KMP_INFORM( Using_str_Value, name, __kmp_barrier_pattern_name[ bp_linear_bar ] );
1501 }
1502 }
1503 }
1504 }
1505} // __kmp_stg_parse_barrier_pattern
1506
1507static void
1508__kmp_stg_print_barrier_pattern( kmp_str_buf_t * buffer, char const * name, void * data ) {
1509 const char *var;
1510 for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
1511 var = __kmp_barrier_pattern_env_name[ i ];
1512 if ( strcmp ( var, name ) == 0 ) {
1513 int j = __kmp_barrier_gather_pattern [ i ];
1514 int k = __kmp_barrier_release_pattern [ i ];
1515 if( __kmp_env_format ) {
1516 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[ i ]);
1517 } else {
1518 __kmp_str_buf_print( buffer, " %s='", __kmp_barrier_pattern_env_name[ i ] );
1519 }
1520 __kmp_str_buf_print( buffer, "%s,%s'\n", __kmp_barrier_pattern_name [ j ], __kmp_barrier_pattern_name [ k ]);
1521 }
1522 }
1523} // __kmp_stg_print_barrier_pattern
1524
1525// -------------------------------------------------------------------------------------------------
1526// KMP_ABORT_DELAY
1527// -------------------------------------------------------------------------------------------------
1528
1529static void
1530__kmp_stg_parse_abort_delay( char const * name, char const * value, void * data ) {
1531 // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is milliseconds.
1532 int delay = __kmp_abort_delay / 1000;
1533 __kmp_stg_parse_int( name, value, 0, INT_MAX / 1000, & delay );
1534 __kmp_abort_delay = delay * 1000;
1535} // __kmp_stg_parse_abort_delay
1536
1537static void
1538__kmp_stg_print_abort_delay( kmp_str_buf_t * buffer, char const * name, void * data ) {
1539 __kmp_stg_print_int( buffer, name, __kmp_abort_delay );
1540} // __kmp_stg_print_abort_delay
1541
1542// -------------------------------------------------------------------------------------------------
1543// KMP_CPUINFO_FILE
1544// -------------------------------------------------------------------------------------------------
1545
1546static void
1547__kmp_stg_parse_cpuinfo_file( char const * name, char const * value, void * data ) {
Alp Toker98758b02014-03-02 04:12:06 +00001548 #if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00001549 __kmp_stg_parse_str( name, value, & __kmp_cpuinfo_file );
1550 K_DIAG( 1, ( "__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file ) );
Jim Cownie5e8470a2013-09-27 10:38:44 +00001551 #endif
1552} //__kmp_stg_parse_cpuinfo_file
1553
1554static void
1555__kmp_stg_print_cpuinfo_file( kmp_str_buf_t * buffer, char const * name, void * data ) {
Alp Toker98758b02014-03-02 04:12:06 +00001556 #if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00001557 if( __kmp_env_format ) {
1558 KMP_STR_BUF_PRINT_NAME;
1559 } else {
1560 __kmp_str_buf_print( buffer, " %s", name );
1561 }
1562 if ( __kmp_cpuinfo_file ) {
1563 __kmp_str_buf_print( buffer, "='%s'\n", __kmp_cpuinfo_file );
1564 } else {
1565 __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
1566 }
1567 #endif
1568} //__kmp_stg_print_cpuinfo_file
1569
1570// -------------------------------------------------------------------------------------------------
1571// KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
1572// -------------------------------------------------------------------------------------------------
1573
1574static void
1575__kmp_stg_parse_force_reduction( char const * name, char const * value, void * data )
1576{
1577 kmp_stg_fr_data_t * reduction = (kmp_stg_fr_data_t *) data;
1578 int rc;
1579
1580 rc = __kmp_stg_check_rivals( name, value, reduction->rivals );
1581 if ( rc ) {
1582 return;
1583 }; // if
1584 if ( reduction->force ) {
1585 if( value != 0 ) {
1586 if( __kmp_str_match( "critical", 0, value ) )
1587 __kmp_force_reduction_method = critical_reduce_block;
1588 else if( __kmp_str_match( "atomic", 0, value ) )
1589 __kmp_force_reduction_method = atomic_reduce_block;
1590 else if( __kmp_str_match( "tree", 0, value ) )
1591 __kmp_force_reduction_method = tree_reduce_block;
1592 else {
1593 KMP_FATAL( UnknownForceReduction, name, value );
1594 }
1595 }
1596 } else {
1597 __kmp_stg_parse_bool( name, value, & __kmp_determ_red );
1598 if( __kmp_determ_red ) {
1599 __kmp_force_reduction_method = tree_reduce_block;
1600 } else {
1601 __kmp_force_reduction_method = reduction_method_not_defined;
1602 }
1603 }
1604 K_DIAG( 1, ( "__kmp_force_reduction_method == %d\n", __kmp_force_reduction_method ) );
1605} // __kmp_stg_parse_force_reduction
1606
1607static void
1608__kmp_stg_print_force_reduction( kmp_str_buf_t * buffer, char const * name, void * data ) {
1609
1610 kmp_stg_fr_data_t * reduction = (kmp_stg_fr_data_t *) data;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001611 if ( reduction->force ) {
1612 if( __kmp_force_reduction_method == critical_reduce_block) {
1613 __kmp_stg_print_str( buffer, name, "critical");
1614 } else if ( __kmp_force_reduction_method == atomic_reduce_block ) {
1615 __kmp_stg_print_str( buffer, name, "atomic");
1616 } else if ( __kmp_force_reduction_method == tree_reduce_block ) {
1617 __kmp_stg_print_str( buffer, name, "tree");
1618 } else {
1619 if( __kmp_env_format ) {
1620 KMP_STR_BUF_PRINT_NAME;
1621 } else {
1622 __kmp_str_buf_print( buffer, " %s", name );
1623 }
1624 __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
1625 }
1626 } else {
1627 __kmp_stg_print_bool( buffer, name, __kmp_determ_red );
1628 }
1629
1630
1631} // __kmp_stg_print_force_reduction
1632
1633// -------------------------------------------------------------------------------------------------
1634// KMP_STORAGE_MAP
1635// -------------------------------------------------------------------------------------------------
1636
1637static void
1638__kmp_stg_parse_storage_map( char const * name, char const * value, void * data ) {
1639 if ( __kmp_str_match( "verbose", 1, value ) ) {
1640 __kmp_storage_map = TRUE;
1641 __kmp_storage_map_verbose = TRUE;
1642 __kmp_storage_map_verbose_specified = TRUE;
1643
1644 } else {
1645 __kmp_storage_map_verbose = FALSE;
1646 __kmp_stg_parse_bool( name, value, & __kmp_storage_map ); // !!!
1647 }; // if
1648} // __kmp_stg_parse_storage_map
1649
1650static void
1651__kmp_stg_print_storage_map( kmp_str_buf_t * buffer, char const * name, void * data ) {
1652 if ( __kmp_storage_map_verbose || __kmp_storage_map_verbose_specified ) {
1653 __kmp_stg_print_str( buffer, name, "verbose" );
1654 } else {
1655 __kmp_stg_print_bool( buffer, name, __kmp_storage_map );
1656 }
1657} // __kmp_stg_print_storage_map
1658
1659// -------------------------------------------------------------------------------------------------
1660// KMP_ALL_THREADPRIVATE
1661// -------------------------------------------------------------------------------------------------
1662
1663static void
1664__kmp_stg_parse_all_threadprivate( char const * name, char const * value, void * data ) {
1665 __kmp_stg_parse_int( name, value, __kmp_allThreadsSpecified ? __kmp_max_nth : 1, __kmp_max_nth,
1666 & __kmp_tp_capacity );
1667} // __kmp_stg_parse_all_threadprivate
1668
1669static void
1670__kmp_stg_print_all_threadprivate( kmp_str_buf_t * buffer, char const * name, void * data ) {
1671 __kmp_stg_print_int( buffer, name, __kmp_tp_capacity );
1672
1673}
1674
1675// -------------------------------------------------------------------------------------------------
1676// KMP_FOREIGN_THREADS_THREADPRIVATE
1677// -------------------------------------------------------------------------------------------------
1678
1679static void
1680__kmp_stg_parse_foreign_threads_threadprivate( char const * name, char const * value, void * data ) {
1681 __kmp_stg_parse_bool( name, value, & __kmp_foreign_tp );
1682} // __kmp_stg_parse_foreign_threads_threadprivate
1683
1684static void
1685__kmp_stg_print_foreign_threads_threadprivate( kmp_str_buf_t * buffer, char const * name, void * data ) {
1686 __kmp_stg_print_bool( buffer, name, __kmp_foreign_tp );
1687} // __kmp_stg_print_foreign_threads_threadprivate
1688
1689
1690// -------------------------------------------------------------------------------------------------
1691// KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
1692// -------------------------------------------------------------------------------------------------
1693
Alp Toker98758b02014-03-02 04:12:06 +00001694#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00001695//
1696// Parse the proc id list. Return TRUE if successful, FALSE otherwise.
1697//
1698static int
1699__kmp_parse_affinity_proc_id_list( const char *var, const char *env,
1700 const char **nextEnv, char **proclist )
1701{
1702 const char *scan = env;
1703 const char *next = scan;
1704 int empty = TRUE;
1705
1706 *proclist = NULL;
1707
1708 for (;;) {
1709 int start, end, stride;
1710
1711 SKIP_WS(scan);
1712 next = scan;
1713 if (*next == '\0') {
1714 break;
1715 }
1716
1717 if (*next == '{') {
1718 int num;
1719 next++; // skip '{'
1720 SKIP_WS(next);
1721 scan = next;
1722
1723 //
1724 // Read the first integer in the set.
1725 //
1726 if ((*next < '0') || (*next > '9')) {
1727 KMP_WARNING( AffSyntaxError, var );
1728 return FALSE;
1729 }
1730 SKIP_DIGITS(next);
1731 num = __kmp_str_to_int(scan, *next);
1732 KMP_ASSERT(num >= 0);
1733
1734 for (;;) {
1735 //
1736 // Check for end of set.
1737 //
1738 SKIP_WS(next);
1739 if (*next == '}') {
1740 next++; // skip '}'
1741 break;
1742 }
1743
1744 //
1745 // Skip optional comma.
1746 //
1747 if (*next == ',') {
1748 next++;
1749 }
1750 SKIP_WS(next);
1751
1752 //
1753 // Read the next integer in the set.
1754 //
1755 scan = next;
1756 if ((*next < '0') || (*next > '9')) {
1757 KMP_WARNING( AffSyntaxError, var );
1758 return FALSE;
1759 }
1760
1761 SKIP_DIGITS(next);
1762 num = __kmp_str_to_int(scan, *next);
1763 KMP_ASSERT(num >= 0);
1764 }
1765 empty = FALSE;
1766
1767 SKIP_WS(next);
1768 if (*next == ',') {
1769 next++;
1770 }
1771 scan = next;
1772 continue;
1773 }
1774
1775 //
1776 // Next character is not an integer => end of list
1777 //
1778 if ((*next < '0') || (*next > '9')) {
1779 if (empty) {
1780 KMP_WARNING( AffSyntaxError, var );
1781 return FALSE;
1782 }
1783 break;
1784 }
1785
1786 //
1787 // Read the first integer.
1788 //
1789 SKIP_DIGITS(next);
1790 start = __kmp_str_to_int(scan, *next);
1791 KMP_ASSERT(start >= 0);
1792 SKIP_WS(next);
1793
1794 //
1795 // If this isn't a range, then go on.
1796 //
1797 if (*next != '-') {
1798 empty = FALSE;
1799
1800 //
1801 // Skip optional comma.
1802 //
1803 if (*next == ',') {
1804 next++;
1805 }
1806 scan = next;
1807 continue;
1808 }
1809
1810 //
1811 // This is a range. Skip over the '-' and read in the 2nd int.
1812 //
1813 next++; // skip '-'
1814 SKIP_WS(next);
1815 scan = next;
1816 if ((*next < '0') || (*next > '9')) {
1817 KMP_WARNING( AffSyntaxError, var );
1818 return FALSE;
1819 }
1820 SKIP_DIGITS(next);
1821 end = __kmp_str_to_int(scan, *next);
1822 KMP_ASSERT(end >= 0);
1823
1824 //
1825 // Check for a stride parameter
1826 //
1827 stride = 1;
1828 SKIP_WS(next);
1829 if (*next == ':') {
1830 //
1831 // A stride is specified. Skip over the ':" and read the 3rd int.
1832 //
1833 int sign = +1;
1834 next++; // skip ':'
1835 SKIP_WS(next);
1836 scan = next;
1837 if (*next == '-') {
1838 sign = -1;
1839 next++;
1840 SKIP_WS(next);
1841 scan = next;
1842 }
1843 if ((*next < '0') || (*next > '9')) {
1844 KMP_WARNING( AffSyntaxError, var );
1845 return FALSE;
1846 }
1847 SKIP_DIGITS(next);
1848 stride = __kmp_str_to_int(scan, *next);
1849 KMP_ASSERT(stride >= 0);
1850 stride *= sign;
1851 }
1852
1853 //
1854 // Do some range checks.
1855 //
1856 if (stride == 0) {
1857 KMP_WARNING( AffZeroStride, var );
1858 return FALSE;
1859 }
1860 if (stride > 0) {
1861 if (start > end) {
1862 KMP_WARNING( AffStartGreaterEnd, var, start, end );
1863 return FALSE;
1864 }
1865 }
1866 else {
1867 if (start < end) {
1868 KMP_WARNING( AffStrideLessZero, var, start, end );
1869 return FALSE;
1870 }
1871 }
1872 if ((end - start) / stride > 65536 ) {
1873 KMP_WARNING( AffRangeTooBig, var, end, start, stride );
1874 return FALSE;
1875 }
1876
1877 empty = FALSE;
1878
1879 //
1880 // Skip optional comma.
1881 //
1882 SKIP_WS(next);
1883 if (*next == ',') {
1884 next++;
1885 }
1886 scan = next;
1887 }
1888
1889 *nextEnv = next;
1890
1891 {
1892 int len = next - env;
1893 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
Andrey Churbanov74bf17b2015-04-02 13:27:08 +00001894 KMP_MEMCPY_S(retlist, (len+1)*sizeof(char), env, len * sizeof(char));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001895 retlist[len] = '\0';
1896 *proclist = retlist;
1897 }
1898 return TRUE;
1899}
1900
1901
1902//
1903// If KMP_AFFINITY is specified without a type, then
1904// __kmp_affinity_notype should point to its setting.
1905//
1906static kmp_setting_t *__kmp_affinity_notype = NULL;
1907
1908static void
1909__kmp_parse_affinity_env( char const * name, char const * value,
1910 enum affinity_type * out_type,
1911 char ** out_proclist,
1912 int * out_verbose,
1913 int * out_warn,
1914 int * out_respect,
1915 enum affinity_gran * out_gran,
1916 int * out_gran_levels,
1917 int * out_dups,
1918 int * out_compact,
1919 int * out_offset
1920)
1921{
1922 char * buffer = NULL; // Copy of env var value.
1923 char * buf = NULL; // Buffer for strtok_r() function.
1924 char * next = NULL; // end of token / start of next.
1925 const char * start; // start of current token (for err msgs)
1926 int count = 0; // Counter of parsed integer numbers.
1927 int number[ 2 ]; // Parsed numbers.
1928
1929 // Guards.
1930 int type = 0;
1931 int proclist = 0;
1932 int max_proclist = 0;
1933 int verbose = 0;
1934 int warnings = 0;
1935 int respect = 0;
1936 int gran = 0;
1937 int dups = 0;
1938
1939 KMP_ASSERT( value != NULL );
1940
1941 if ( TCR_4(__kmp_init_middle) ) {
1942 KMP_WARNING( EnvMiddleWarn, name );
1943 __kmp_env_toPrint( name, 0 );
1944 return;
1945 }
1946 __kmp_env_toPrint( name, 1 );
1947
1948 buffer = __kmp_str_format( "%s", value ); // Copy env var to keep original intact.
1949 buf = buffer;
1950 SKIP_WS(buf);
1951
1952 // Helper macros.
1953
1954 //
1955 // If we see a parse error, emit a warning and scan to the next ",".
1956 //
1957 // FIXME - there's got to be a better way to print an error
1958 // message, hopefully without overwritting peices of buf.
1959 //
1960 #define EMIT_WARN(skip,errlist) \
1961 { \
1962 char ch; \
1963 if (skip) { \
1964 SKIP_TO(next, ','); \
1965 } \
1966 ch = *next; \
1967 *next = '\0'; \
1968 KMP_WARNING errlist; \
1969 *next = ch; \
1970 if (skip) { \
1971 if (ch == ',') next++; \
1972 } \
1973 buf = next; \
1974 }
1975
1976 #define _set_param(_guard,_var,_val) \
1977 { \
1978 if ( _guard == 0 ) { \
1979 _var = _val; \
1980 } else { \
1981 EMIT_WARN( FALSE, ( AffParamDefined, name, start ) ); \
1982 }; \
1983 ++ _guard; \
1984 }
1985
1986 #define set_type(val) _set_param( type, *out_type, val )
1987 #define set_verbose(val) _set_param( verbose, *out_verbose, val )
1988 #define set_warnings(val) _set_param( warnings, *out_warn, val )
1989 #define set_respect(val) _set_param( respect, *out_respect, val )
1990 #define set_dups(val) _set_param( dups, *out_dups, val )
1991 #define set_proclist(val) _set_param( proclist, *out_proclist, val )
1992
1993 #define set_gran(val,levels) \
1994 { \
1995 if ( gran == 0 ) { \
1996 *out_gran = val; \
1997 *out_gran_levels = levels; \
1998 } else { \
1999 EMIT_WARN( FALSE, ( AffParamDefined, name, start ) ); \
2000 }; \
2001 ++ gran; \
2002 }
2003
2004# if OMP_40_ENABLED
2005 KMP_DEBUG_ASSERT( ( __kmp_nested_proc_bind.bind_types != NULL )
2006 && ( __kmp_nested_proc_bind.used > 0 ) );
Jim Cownie5e8470a2013-09-27 10:38:44 +00002007# endif
2008
2009 while ( *buf != '\0' ) {
2010 start = next = buf;
2011
2012 if (__kmp_match_str("none", buf, (const char **)&next)) {
2013 set_type( affinity_none );
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002014# if OMP_40_ENABLED
2015 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2016# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00002017 buf = next;
2018 } else if (__kmp_match_str("scatter", buf, (const char **)&next)) {
2019 set_type( affinity_scatter );
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002020# if OMP_40_ENABLED
2021 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2022# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00002023 buf = next;
2024 } else if (__kmp_match_str("compact", buf, (const char **)&next)) {
2025 set_type( affinity_compact );
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002026# if OMP_40_ENABLED
2027 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2028# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00002029 buf = next;
2030 } else if (__kmp_match_str("logical", buf, (const char **)&next)) {
2031 set_type( affinity_logical );
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002032# if OMP_40_ENABLED
2033 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2034# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00002035 buf = next;
2036 } else if (__kmp_match_str("physical", buf, (const char **)&next)) {
2037 set_type( affinity_physical );
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002038# if OMP_40_ENABLED
2039 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2040# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00002041 buf = next;
2042 } else if (__kmp_match_str("explicit", buf, (const char **)&next)) {
2043 set_type( affinity_explicit );
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002044# if OMP_40_ENABLED
2045 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2046# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00002047 buf = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002048 } else if (__kmp_match_str("balanced", buf, (const char **)&next)) {
2049 set_type( affinity_balanced );
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002050# if OMP_40_ENABLED
2051 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2052# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00002053 buf = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002054 } else if (__kmp_match_str("disabled", buf, (const char **)&next)) {
2055 set_type( affinity_disabled );
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002056# if OMP_40_ENABLED
2057 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2058# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00002059 buf = next;
2060 } else if (__kmp_match_str("verbose", buf, (const char **)&next)) {
2061 set_verbose( TRUE );
2062 buf = next;
2063 } else if (__kmp_match_str("noverbose", buf, (const char **)&next)) {
2064 set_verbose( FALSE );
2065 buf = next;
2066 } else if (__kmp_match_str("warnings", buf, (const char **)&next)) {
2067 set_warnings( TRUE );
2068 buf = next;
2069 } else if (__kmp_match_str("nowarnings", buf, (const char **)&next)) {
2070 set_warnings( FALSE );
2071 buf = next;
2072 } else if (__kmp_match_str("respect", buf, (const char **)&next)) {
2073 set_respect( TRUE );
2074 buf = next;
2075 } else if (__kmp_match_str("norespect", buf, (const char **)&next)) {
2076 set_respect( FALSE );
2077 buf = next;
2078 } else if (__kmp_match_str("duplicates", buf, (const char **)&next)
2079 || __kmp_match_str("dups", buf, (const char **)&next)) {
2080 set_dups( TRUE );
2081 buf = next;
2082 } else if (__kmp_match_str("noduplicates", buf, (const char **)&next)
2083 || __kmp_match_str("nodups", buf, (const char **)&next)) {
2084 set_dups( FALSE );
2085 buf = next;
2086 } else if (__kmp_match_str("granularity", buf, (const char **)&next)
2087 || __kmp_match_str("gran", buf, (const char **)&next)) {
2088 SKIP_WS(next);
2089 if (*next != '=') {
2090 EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2091 continue;
2092 }
2093 next++; // skip '='
2094 SKIP_WS(next);
2095
2096 buf = next;
2097 if (__kmp_match_str("fine", buf, (const char **)&next)) {
2098 set_gran( affinity_gran_fine, -1 );
2099 buf = next;
2100 } else if (__kmp_match_str("thread", buf, (const char **)&next)) {
2101 set_gran( affinity_gran_thread, -1 );
2102 buf = next;
2103 } else if (__kmp_match_str("core", buf, (const char **)&next)) {
2104 set_gran( affinity_gran_core, -1 );
2105 buf = next;
2106 } else if (__kmp_match_str("package", buf, (const char **)&next)) {
2107 set_gran( affinity_gran_package, -1 );
2108 buf = next;
2109 } else if (__kmp_match_str("node", buf, (const char **)&next)) {
2110 set_gran( affinity_gran_node, -1 );
2111 buf = next;
Andrey Churbanov7daf9802015-01-27 16:52:57 +00002112# if KMP_GROUP_AFFINITY
Jim Cownie5e8470a2013-09-27 10:38:44 +00002113 } else if (__kmp_match_str("group", buf, (const char **)&next)) {
2114 set_gran( affinity_gran_group, -1 );
2115 buf = next;
Andrey Churbanov7daf9802015-01-27 16:52:57 +00002116# endif /* KMP_GROUP AFFINITY */
Jim Cownie5e8470a2013-09-27 10:38:44 +00002117 } else if ((*buf >= '0') && (*buf <= '9')) {
2118 int n;
2119 next = buf;
2120 SKIP_DIGITS(next);
2121 n = __kmp_str_to_int( buf, *next );
2122 KMP_ASSERT(n >= 0);
2123 buf = next;
2124 set_gran( affinity_gran_default, n );
2125 } else {
2126 EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2127 continue;
2128 }
2129 } else if (__kmp_match_str("proclist", buf, (const char **)&next)) {
2130 char *temp_proclist;
2131
2132 SKIP_WS(next);
2133 if (*next != '=') {
2134 EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2135 continue;
2136 }
2137 next++; // skip '='
2138 SKIP_WS(next);
2139 if (*next != '[') {
2140 EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2141 continue;
2142 }
2143 next++; // skip '['
2144 buf = next;
2145 if (! __kmp_parse_affinity_proc_id_list(name, buf,
2146 (const char **)&next, &temp_proclist)) {
2147 //
2148 // warning already emitted.
2149 //
2150 SKIP_TO(next, ']');
2151 if (*next == ']') next++;
2152 SKIP_TO(next, ',');
2153 if (*next == ',') next++;
2154 buf = next;
2155 continue;
2156 }
2157 if (*next != ']') {
2158 EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2159 continue;
2160 }
2161 next++; // skip ']'
2162 set_proclist( temp_proclist );
2163 } else if ((*buf >= '0') && (*buf <= '9')) {
2164 // Parse integer numbers -- permute and offset.
2165 int n;
2166 next = buf;
2167 SKIP_DIGITS(next);
2168 n = __kmp_str_to_int( buf, *next );
2169 KMP_ASSERT(n >= 0);
2170 buf = next;
2171 if ( count < 2 ) {
2172 number[ count ] = n;
2173 } else {
2174 KMP_WARNING( AffManyParams, name, start );
2175 }; // if
2176 ++ count;
2177 } else {
2178 EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2179 continue;
2180 }
2181
2182 SKIP_WS(next);
2183 if (*next == ',') {
2184 next++;
2185 SKIP_WS(next);
2186 }
2187 else if (*next != '\0') {
2188 const char *temp = next;
2189 EMIT_WARN( TRUE, ( ParseExtraCharsWarn, name, temp ) );
2190 continue;
2191 }
2192 buf = next;
2193 } // while
2194
2195 #undef EMIT_WARN
2196 #undef _set_param
2197 #undef set_type
2198 #undef set_verbose
2199 #undef set_warnings
2200 #undef set_respect
2201 #undef set_granularity
2202
2203 KMP_INTERNAL_FREE( buffer );
2204
2205 if ( proclist ) {
2206 if ( ! type ) {
2207 KMP_WARNING( AffProcListNoType, name );
2208 __kmp_affinity_type = affinity_explicit;
2209 }
2210 else if ( __kmp_affinity_type != affinity_explicit ) {
2211 KMP_WARNING( AffProcListNotExplicit, name );
2212 KMP_ASSERT( *out_proclist != NULL );
2213 KMP_INTERNAL_FREE( *out_proclist );
2214 *out_proclist = NULL;
2215 }
2216 }
2217 switch ( *out_type ) {
2218 case affinity_logical:
2219 case affinity_physical: {
2220 if ( count > 0 ) {
2221 *out_offset = number[ 0 ];
2222 }; // if
2223 if ( count > 1 ) {
2224 KMP_WARNING( AffManyParamsForLogic, name, number[ 1 ] );
2225 }; // if
2226 } break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002227 case affinity_balanced: {
2228 if ( count > 0 ) {
2229 *out_compact = number[ 0 ];
2230 }; // if
2231 if ( count > 1 ) {
2232 *out_offset = number[ 1 ];
2233 }; // if
2234
Andrey Churbanovf28f6132015-01-13 14:54:00 +00002235 if ( __kmp_affinity_gran == affinity_gran_default ) {
Andrey Churbanov613edeb2015-02-20 18:14:43 +00002236#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
2237 if( __kmp_mic_type != non_mic ) {
2238 if( __kmp_affinity_verbose || __kmp_affinity_warnings ) {
2239 KMP_WARNING( AffGranUsing, "KMP_AFFINITY", "fine" );
2240 }
2241 __kmp_affinity_gran = affinity_gran_fine;
2242 } else
2243#endif
2244 {
2245 if( __kmp_affinity_verbose || __kmp_affinity_warnings ) {
2246 KMP_WARNING( AffGranUsing, "KMP_AFFINITY", "core" );
2247 }
2248 __kmp_affinity_gran = affinity_gran_core;
Andrey Churbanovf28f6132015-01-13 14:54:00 +00002249 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002250 }
2251 } break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002252 case affinity_scatter:
2253 case affinity_compact: {
2254 if ( count > 0 ) {
2255 *out_compact = number[ 0 ];
2256 }; // if
2257 if ( count > 1 ) {
2258 *out_offset = number[ 1 ];
2259 }; // if
2260 } break;
2261 case affinity_explicit: {
2262 if ( *out_proclist == NULL ) {
2263 KMP_WARNING( AffNoProcList, name );
2264 __kmp_affinity_type = affinity_none;
2265 }
2266 if ( count > 0 ) {
2267 KMP_WARNING( AffNoParam, name, "explicit" );
2268 }
2269 } break;
2270 case affinity_none: {
2271 if ( count > 0 ) {
2272 KMP_WARNING( AffNoParam, name, "none" );
2273 }; // if
2274 } break;
2275 case affinity_disabled: {
2276 if ( count > 0 ) {
2277 KMP_WARNING( AffNoParam, name, "disabled" );
2278 }; // if
2279 } break;
2280 case affinity_default: {
2281 if ( count > 0 ) {
2282 KMP_WARNING( AffNoParam, name, "default" );
2283 }; // if
2284 } break;
2285 default: {
2286 KMP_ASSERT( 0 );
2287 };
2288 }; // switch
2289} // __kmp_parse_affinity_env
2290
2291static void
2292__kmp_stg_parse_affinity( char const * name, char const * value, void * data )
2293{
2294 kmp_setting_t **rivals = (kmp_setting_t **) data;
2295 int rc;
2296
2297 rc = __kmp_stg_check_rivals( name, value, rivals );
2298 if ( rc ) {
2299 return;
2300 }
2301
2302 __kmp_parse_affinity_env( name, value, & __kmp_affinity_type,
2303 & __kmp_affinity_proclist, & __kmp_affinity_verbose,
2304 & __kmp_affinity_warnings, & __kmp_affinity_respect_mask,
2305 & __kmp_affinity_gran, & __kmp_affinity_gran_levels,
2306 & __kmp_affinity_dups, & __kmp_affinity_compact,
2307 & __kmp_affinity_offset );
2308
2309} // __kmp_stg_parse_affinity
2310
2311static void
2312__kmp_stg_print_affinity( kmp_str_buf_t * buffer, char const * name, void * data ) {
2313 if( __kmp_env_format ) {
2314 KMP_STR_BUF_PRINT_NAME_EX(name);
2315 } else {
2316 __kmp_str_buf_print( buffer, " %s='", name );
2317 }
2318 if ( __kmp_affinity_verbose ) {
2319 __kmp_str_buf_print( buffer, "%s,", "verbose");
2320 } else {
2321 __kmp_str_buf_print( buffer, "%s,", "noverbose");
2322 }
2323 if ( __kmp_affinity_warnings ) {
2324 __kmp_str_buf_print( buffer, "%s,", "warnings");
2325 } else {
2326 __kmp_str_buf_print( buffer, "%s,", "nowarnings");
2327 }
2328 if ( KMP_AFFINITY_CAPABLE() ) {
2329 if ( __kmp_affinity_respect_mask ) {
2330 __kmp_str_buf_print( buffer, "%s,", "respect");
2331 } else {
2332 __kmp_str_buf_print( buffer, "%s,", "norespect");
2333 }
2334 switch ( __kmp_affinity_gran ) {
2335 case affinity_gran_default:
2336 __kmp_str_buf_print( buffer, "%s", "granularity=default,");
2337 break;
2338 case affinity_gran_fine:
2339 __kmp_str_buf_print( buffer, "%s", "granularity=fine,");
2340 break;
2341 case affinity_gran_thread:
2342 __kmp_str_buf_print( buffer, "%s", "granularity=thread,");
2343 break;
2344 case affinity_gran_core:
2345 __kmp_str_buf_print( buffer, "%s", "granularity=core,");
2346 break;
2347 case affinity_gran_package:
2348 __kmp_str_buf_print( buffer, "%s", "granularity=package,");
2349 break;
2350 case affinity_gran_node:
2351 __kmp_str_buf_print( buffer, "%s", "granularity=node,");
2352 break;
Andrey Churbanov7daf9802015-01-27 16:52:57 +00002353# if KMP_GROUP_AFFINITY
Jim Cownie5e8470a2013-09-27 10:38:44 +00002354 case affinity_gran_group:
2355 __kmp_str_buf_print( buffer, "%s", "granularity=group,");
2356 break;
Andrey Churbanov7daf9802015-01-27 16:52:57 +00002357# endif /* KMP_GROUP_AFFINITY */
Jim Cownie5e8470a2013-09-27 10:38:44 +00002358 }
2359 if ( __kmp_affinity_dups ) {
2360 __kmp_str_buf_print( buffer, "%s,", "duplicates");
2361 } else {
2362 __kmp_str_buf_print( buffer, "%s,", "noduplicates");
2363 }
2364 }
2365 if ( ! KMP_AFFINITY_CAPABLE() ) {
2366 __kmp_str_buf_print( buffer, "%s", "disabled" );
2367 }
2368 else switch ( __kmp_affinity_type ){
2369 case affinity_none:
2370 __kmp_str_buf_print( buffer, "%s", "none");
2371 break;
2372 case affinity_physical:
2373 __kmp_str_buf_print( buffer, "%s,%d", "physical",
2374 __kmp_affinity_offset );
2375 break;
2376 case affinity_logical:
2377 __kmp_str_buf_print( buffer, "%s,%d", "logical",
2378 __kmp_affinity_offset );
2379 break;
2380 case affinity_compact:
2381 __kmp_str_buf_print( buffer, "%s,%d,%d", "compact",
2382 __kmp_affinity_compact, __kmp_affinity_offset );
2383 break;
2384 case affinity_scatter:
2385 __kmp_str_buf_print( buffer, "%s,%d,%d", "scatter",
2386 __kmp_affinity_compact, __kmp_affinity_offset );
2387 break;
2388 case affinity_explicit:
2389 __kmp_str_buf_print( buffer, "%s=[%s],%s", "proclist",
2390 __kmp_affinity_proclist, "explicit" );
2391 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002392 case affinity_balanced:
2393 __kmp_str_buf_print( buffer, "%s,%d,%d", "balanced",
2394 __kmp_affinity_compact, __kmp_affinity_offset );
2395 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002396 case affinity_disabled:
2397 __kmp_str_buf_print( buffer, "%s", "disabled");
2398 break;
2399 case affinity_default:
2400 __kmp_str_buf_print( buffer, "%s", "default");
2401 break;
2402 default:
2403 __kmp_str_buf_print( buffer, "%s", "<unknown>");
2404 break;
2405 }
2406 __kmp_str_buf_print( buffer, "'\n" );
2407} //__kmp_stg_print_affinity
2408
2409# ifdef KMP_GOMP_COMPAT
2410
2411static void
2412__kmp_stg_parse_gomp_cpu_affinity( char const * name, char const * value, void * data )
2413{
2414 const char * next = NULL;
2415 char * temp_proclist;
2416 kmp_setting_t **rivals = (kmp_setting_t **) data;
2417 int rc;
2418
2419 rc = __kmp_stg_check_rivals( name, value, rivals );
2420 if ( rc ) {
2421 return;
2422 }
2423
2424 if ( TCR_4(__kmp_init_middle) ) {
2425 KMP_WARNING( EnvMiddleWarn, name );
2426 __kmp_env_toPrint( name, 0 );
2427 return;
2428 }
2429
2430 __kmp_env_toPrint( name, 1 );
2431
2432 if ( __kmp_parse_affinity_proc_id_list( name, value, &next,
2433 &temp_proclist )) {
2434 SKIP_WS(next);
2435 if (*next == '\0') {
2436 //
2437 // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2438 //
2439 __kmp_affinity_proclist = temp_proclist;
2440 __kmp_affinity_type = affinity_explicit;
2441 __kmp_affinity_gran = affinity_gran_fine;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002442# if OMP_40_ENABLED
2443 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2444# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00002445 }
2446 else {
2447 KMP_WARNING( AffSyntaxError, name );
2448 if (temp_proclist != NULL) {
2449 KMP_INTERNAL_FREE((void *)temp_proclist);
2450 }
2451 }
2452 }
2453 else {
2454 //
2455 // Warning already emitted
2456 //
2457 __kmp_affinity_type = affinity_none;
Andrey Churbanova36de432015-01-27 16:58:08 +00002458# if OMP_40_ENABLED
2459 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2460# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00002461 }
2462} // __kmp_stg_parse_gomp_cpu_affinity
2463
2464# endif /* KMP_GOMP_COMPAT */
2465
2466
2467# if OMP_40_ENABLED
2468
2469/*-----------------------------------------------------------------------------
2470
2471The OMP_PLACES proc id list parser. Here is the grammar:
2472
2473place_list := place
2474place_list := place , place_list
2475place := num
2476place := place : num
2477place := place : num : signed
2478place := { subplacelist }
2479place := ! place // (lowest priority)
2480subplace_list := subplace
2481subplace_list := subplace , subplace_list
2482subplace := num
2483subplace := num : num
2484subplace := num : num : signed
2485signed := num
2486signed := + signed
2487signed := - signed
2488
2489-----------------------------------------------------------------------------*/
2490
2491static int
2492__kmp_parse_subplace_list( const char *var, const char **scan )
2493{
2494 const char *next;
2495
2496 for (;;) {
2497 int start, count, stride;
2498
2499 //
2500 // Read in the starting proc id
2501 //
2502 SKIP_WS(*scan);
2503 if ((**scan < '0') || (**scan > '9')) {
2504 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2505 return FALSE;
2506 }
2507 next = *scan;
2508 SKIP_DIGITS(next);
2509 start = __kmp_str_to_int(*scan, *next);
2510 KMP_ASSERT(start >= 0);
2511 *scan = next;
2512
2513 //
2514 // valid follow sets are ',' ':' and '}'
2515 //
2516 SKIP_WS(*scan);
2517 if (**scan == '}') {
2518 break;
2519 }
2520 if (**scan == ',') {
2521 (*scan)++; // skip ','
2522 continue;
2523 }
2524 if (**scan != ':') {
2525 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2526 return FALSE;
2527 }
2528 (*scan)++; // skip ':'
2529
2530 //
2531 // Read count parameter
2532 //
2533 SKIP_WS(*scan);
2534 if ((**scan < '0') || (**scan > '9')) {
2535 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2536 return FALSE;
2537 }
2538 next = *scan;
2539 SKIP_DIGITS(next);
2540 count = __kmp_str_to_int(*scan, *next);
2541 KMP_ASSERT(count >= 0);
2542 *scan = next;
2543
2544 //
2545 // valid follow sets are ',' ':' and '}'
2546 //
2547 SKIP_WS(*scan);
2548 if (**scan == '}') {
2549 break;
2550 }
2551 if (**scan == ',') {
2552 (*scan)++; // skip ','
2553 continue;
2554 }
2555 if (**scan != ':') {
2556 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2557 return FALSE;
2558 }
2559 (*scan)++; // skip ':'
2560
2561 //
2562 // Read stride parameter
2563 //
2564 int sign = +1;
2565 for (;;) {
2566 SKIP_WS(*scan);
2567 if (**scan == '+') {
2568 (*scan)++; // skip '+'
2569 continue;
2570 }
2571 if (**scan == '-') {
2572 sign *= -1;
2573 (*scan)++; // skip '-'
2574 continue;
2575 }
2576 break;
2577 }
2578 SKIP_WS(*scan);
2579 if ((**scan < '0') || (**scan > '9')) {
2580 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2581 return FALSE;
2582 }
2583 next = *scan;
2584 SKIP_DIGITS(next);
2585 stride = __kmp_str_to_int(*scan, *next);
2586 KMP_ASSERT(stride >= 0);
2587 *scan = next;
2588 stride *= sign;
2589
2590 //
2591 // valid follow sets are ',' and '}'
2592 //
2593 SKIP_WS(*scan);
2594 if (**scan == '}') {
2595 break;
2596 }
2597 if (**scan == ',') {
2598 (*scan)++; // skip ','
2599 continue;
2600 }
2601
2602 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2603 return FALSE;
2604 }
2605 return TRUE;
2606}
2607
2608static int
2609__kmp_parse_place( const char *var, const char ** scan )
2610{
2611 const char *next;
2612
2613 //
2614 // valid follow sets are '{' '!' and num
2615 //
2616 SKIP_WS(*scan);
2617 if (**scan == '{') {
2618 (*scan)++; // skip '{'
2619 if (! __kmp_parse_subplace_list(var, scan)) {
2620 return FALSE;
2621 }
2622 if (**scan != '}') {
2623 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2624 return FALSE;
2625 }
2626 (*scan)++; // skip '}'
2627 }
2628 else if (**scan == '!') {
2629 (*scan)++; // skip '!'
2630 return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2631 }
2632 else if ((**scan >= '0') && (**scan <= '9')) {
2633 next = *scan;
2634 SKIP_DIGITS(next);
2635 int proc = __kmp_str_to_int(*scan, *next);
2636 KMP_ASSERT(proc >= 0);
2637 *scan = next;
2638 }
2639 else {
2640 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2641 return FALSE;
2642 }
2643 return TRUE;
2644}
2645
2646static int
2647__kmp_parse_place_list( const char *var, const char *env, char **place_list )
2648{
2649 const char *scan = env;
2650 const char *next = scan;
2651
2652 for (;;) {
2653 int start, count, stride;
2654
2655 if (! __kmp_parse_place(var, &scan)) {
2656 return FALSE;
2657 }
2658
2659 //
2660 // valid follow sets are ',' ':' and EOL
2661 //
2662 SKIP_WS(scan);
2663 if (*scan == '\0') {
2664 break;
2665 }
2666 if (*scan == ',') {
2667 scan++; // skip ','
2668 continue;
2669 }
2670 if (*scan != ':') {
2671 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2672 return FALSE;
2673 }
2674 scan++; // skip ':'
2675
2676 //
2677 // Read count parameter
2678 //
2679 SKIP_WS(scan);
2680 if ((*scan < '0') || (*scan > '9')) {
2681 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2682 return FALSE;
2683 }
2684 next = scan;
2685 SKIP_DIGITS(next);
2686 count = __kmp_str_to_int(scan, *next);
2687 KMP_ASSERT(count >= 0);
2688 scan = next;
2689
2690 //
2691 // valid follow sets are ',' ':' and EOL
2692 //
2693 SKIP_WS(scan);
2694 if (*scan == '\0') {
2695 break;
2696 }
2697 if (*scan == ',') {
2698 scan++; // skip ','
2699 continue;
2700 }
2701 if (*scan != ':') {
2702 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2703 return FALSE;
2704 }
2705 scan++; // skip ':'
2706
2707 //
2708 // Read stride parameter
2709 //
2710 int sign = +1;
2711 for (;;) {
2712 SKIP_WS(scan);
2713 if (*scan == '+') {
2714 scan++; // skip '+'
2715 continue;
2716 }
2717 if (*scan == '-') {
2718 sign *= -1;
2719 scan++; // skip '-'
2720 continue;
2721 }
2722 break;
2723 }
2724 SKIP_WS(scan);
2725 if ((*scan < '0') || (*scan > '9')) {
2726 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2727 return FALSE;
2728 }
2729 next = scan;
2730 SKIP_DIGITS(next);
2731 stride = __kmp_str_to_int(scan, *next);
2732 KMP_ASSERT(stride >= 0);
2733 scan = next;
2734 stride *= sign;
2735
2736 //
2737 // valid follow sets are ',' and EOL
2738 //
2739 SKIP_WS(scan);
2740 if (*scan == '\0') {
2741 break;
2742 }
2743 if (*scan == ',') {
2744 scan++; // skip ','
2745 continue;
2746 }
2747
2748 KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2749 return FALSE;
2750 }
2751
2752 {
2753 int len = scan - env;
2754 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
Andrey Churbanov74bf17b2015-04-02 13:27:08 +00002755 KMP_MEMCPY_S(retlist, (len+1)*sizeof(char), env, len * sizeof(char));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002756 retlist[len] = '\0';
2757 *place_list = retlist;
2758 }
2759 return TRUE;
2760}
2761
2762static void
2763__kmp_stg_parse_places( char const * name, char const * value, void * data )
2764{
2765 int count;
2766 const char *scan = value;
2767 const char *next = scan;
2768 const char *kind = "\"threads\"";
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002769 kmp_setting_t **rivals = (kmp_setting_t **) data;
2770 int rc;
2771
2772 rc = __kmp_stg_check_rivals( name, value, rivals );
2773 if ( rc ) {
2774 return;
2775 }
2776
2777 //
2778 // If OMP_PROC_BIND is not specified but OMP_PLACES is,
2779 // then let OMP_PROC_BIND default to true.
2780 //
2781 if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) {
2782 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2783 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002784
2785 //__kmp_affinity_num_places = 0;
2786
2787 if ( __kmp_match_str( "threads", scan, &next ) ) {
2788 scan = next;
2789 __kmp_affinity_type = affinity_compact;
2790 __kmp_affinity_gran = affinity_gran_thread;
2791 __kmp_affinity_dups = FALSE;
2792 kind = "\"threads\"";
2793 }
2794 else if ( __kmp_match_str( "cores", scan, &next ) ) {
2795 scan = next;
2796 __kmp_affinity_type = affinity_compact;
2797 __kmp_affinity_gran = affinity_gran_core;
2798 __kmp_affinity_dups = FALSE;
2799 kind = "\"cores\"";
2800 }
2801 else if ( __kmp_match_str( "sockets", scan, &next ) ) {
2802 scan = next;
2803 __kmp_affinity_type = affinity_compact;
2804 __kmp_affinity_gran = affinity_gran_package;
2805 __kmp_affinity_dups = FALSE;
2806 kind = "\"sockets\"";
2807 }
2808 else {
2809 if ( __kmp_affinity_proclist != NULL ) {
2810 KMP_INTERNAL_FREE( (void *)__kmp_affinity_proclist );
2811 __kmp_affinity_proclist = NULL;
2812 }
2813 if ( __kmp_parse_place_list( name, value, &__kmp_affinity_proclist ) ) {
2814 __kmp_affinity_type = affinity_explicit;
2815 __kmp_affinity_gran = affinity_gran_fine;
2816 __kmp_affinity_dups = FALSE;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002817 if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) {
2818 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2819 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002820 }
2821 return;
2822 }
2823
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002824 if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) {
2825 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2826 }
2827
Jim Cownie5e8470a2013-09-27 10:38:44 +00002828 SKIP_WS(scan);
2829 if ( *scan == '\0' ) {
2830 return;
2831 }
2832
2833 //
2834 // Parse option count parameter in parentheses
2835 //
2836 if ( *scan != '(' ) {
2837 KMP_WARNING( SyntaxErrorUsing, name, kind );
2838 return;
2839 }
2840 scan++; // skip '('
2841
2842 SKIP_WS(scan);
2843 next = scan;
2844 SKIP_DIGITS(next);
2845 count = __kmp_str_to_int(scan, *next);
2846 KMP_ASSERT(count >= 0);
2847 scan = next;
2848
2849 SKIP_WS(scan);
2850 if ( *scan != ')' ) {
2851 KMP_WARNING( SyntaxErrorUsing, name, kind );
2852 return;
2853 }
2854 scan++; // skip ')'
2855
2856 SKIP_WS(scan);
2857 if ( *scan != '\0' ) {
2858 KMP_WARNING( ParseExtraCharsWarn, name, scan );
2859 }
2860 __kmp_affinity_num_places = count;
2861}
2862
2863static void
2864__kmp_stg_print_places( kmp_str_buf_t * buffer, char const * name,
2865 void * data )
2866{
2867 if( __kmp_env_format ) {
2868 KMP_STR_BUF_PRINT_NAME;
2869 } else {
2870 __kmp_str_buf_print( buffer, " %s", name );
2871 }
2872 if ( ( __kmp_nested_proc_bind.used == 0 )
2873 || ( __kmp_nested_proc_bind.bind_types == NULL )
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002874 || ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_false ) ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00002875 __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
2876 }
2877 else if ( __kmp_affinity_type == affinity_explicit ) {
2878 if ( __kmp_affinity_proclist != NULL ) {
2879 __kmp_str_buf_print( buffer, "='%s'\n", __kmp_affinity_proclist );
2880 }
2881 else {
2882 __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
2883 }
2884 }
2885 else if ( __kmp_affinity_type == affinity_compact ) {
2886 int num;
2887 if ( __kmp_affinity_num_masks > 0 ) {
2888 num = __kmp_affinity_num_masks;
2889 }
2890 else if ( __kmp_affinity_num_places > 0 ) {
2891 num = __kmp_affinity_num_places;
2892 }
2893 else {
2894 num = 0;
2895 }
2896 if ( __kmp_affinity_gran == affinity_gran_thread ) {
2897 if ( num > 0 ) {
2898 __kmp_str_buf_print( buffer, "='threads(%d)'\n", num );
2899 }
2900 else {
2901 __kmp_str_buf_print( buffer, "='threads'\n" );
2902 }
2903 }
2904 else if ( __kmp_affinity_gran == affinity_gran_core ) {
2905 if ( num > 0 ) {
2906 __kmp_str_buf_print( buffer, "='cores(%d)' \n", num );
2907 }
2908 else {
2909 __kmp_str_buf_print( buffer, "='cores'\n" );
2910 }
2911 }
2912 else if ( __kmp_affinity_gran == affinity_gran_package ) {
2913 if ( num > 0 ) {
2914 __kmp_str_buf_print( buffer, "='sockets(%d)'\n", num );
2915 }
2916 else {
2917 __kmp_str_buf_print( buffer, "='sockets'\n" );
2918 }
2919 }
2920 else {
2921 __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
2922 }
2923 }
2924 else {
2925 __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
2926 }
2927}
2928
2929# endif /* OMP_40_ENABLED */
2930
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002931# if (! OMP_40_ENABLED)
Jim Cownie5e8470a2013-09-27 10:38:44 +00002932
2933static void
2934__kmp_stg_parse_proc_bind( char const * name, char const * value, void * data )
2935{
2936 int enabled;
2937 kmp_setting_t **rivals = (kmp_setting_t **) data;
2938 int rc;
2939
2940 rc = __kmp_stg_check_rivals( name, value, rivals );
2941 if ( rc ) {
2942 return;
2943 }
2944
2945 //
2946 // in OMP 3.1, OMP_PROC_BIND is strictly a boolean
2947 //
2948 __kmp_stg_parse_bool( name, value, & enabled );
2949 if ( enabled ) {
2950 //
Andrey Churbanovf28f6132015-01-13 14:54:00 +00002951 // OMP_PROC_BIND => granularity=fine,scatter on MIC
2952 // OMP_PROC_BIND => granularity=core,scatter elsewhere
Jim Cownie5e8470a2013-09-27 10:38:44 +00002953 //
2954 __kmp_affinity_type = affinity_scatter;
Jonathan Peyton441f3372015-09-21 17:24:46 +00002955# if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
2956 if( __kmp_mic_type != non_mic )
Andrey Churbanov613edeb2015-02-20 18:14:43 +00002957 __kmp_affinity_gran = affinity_gran_fine;
Jonathan Peyton441f3372015-09-21 17:24:46 +00002958 else
2959# endif
Andrey Churbanov613edeb2015-02-20 18:14:43 +00002960 __kmp_affinity_gran = affinity_gran_core;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002961 }
2962 else {
2963 __kmp_affinity_type = affinity_none;
2964 }
2965} // __kmp_parse_proc_bind
2966
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002967# endif /* if (! OMP_40_ENABLED) */
Jim Cownie5e8470a2013-09-27 10:38:44 +00002968
2969
2970static void
2971__kmp_stg_parse_topology_method( char const * name, char const * value,
2972 void * data ) {
2973 if ( __kmp_str_match( "all", 1, value ) ) {
2974 __kmp_affinity_top_method = affinity_top_method_all;
2975 }
2976# if KMP_ARCH_X86 || KMP_ARCH_X86_64
2977 else if ( __kmp_str_match( "x2apic id", 9, value )
2978 || __kmp_str_match( "x2apic_id", 9, value )
2979 || __kmp_str_match( "x2apic-id", 9, value )
2980 || __kmp_str_match( "x2apicid", 8, value )
2981 || __kmp_str_match( "cpuid leaf 11", 13, value )
2982 || __kmp_str_match( "cpuid_leaf_11", 13, value )
2983 || __kmp_str_match( "cpuid-leaf-11", 13, value )
2984 || __kmp_str_match( "cpuid leaf11", 12, value )
2985 || __kmp_str_match( "cpuid_leaf11", 12, value )
2986 || __kmp_str_match( "cpuid-leaf11", 12, value )
2987 || __kmp_str_match( "cpuidleaf 11", 12, value )
2988 || __kmp_str_match( "cpuidleaf_11", 12, value )
2989 || __kmp_str_match( "cpuidleaf-11", 12, value )
2990 || __kmp_str_match( "cpuidleaf11", 11, value )
2991 || __kmp_str_match( "cpuid 11", 8, value )
2992 || __kmp_str_match( "cpuid_11", 8, value )
2993 || __kmp_str_match( "cpuid-11", 8, value )
2994 || __kmp_str_match( "cpuid11", 7, value )
2995 || __kmp_str_match( "leaf 11", 7, value )
2996 || __kmp_str_match( "leaf_11", 7, value )
2997 || __kmp_str_match( "leaf-11", 7, value )
2998 || __kmp_str_match( "leaf11", 6, value ) ) {
2999 __kmp_affinity_top_method = affinity_top_method_x2apicid;
3000 }
3001 else if ( __kmp_str_match( "apic id", 7, value )
3002 || __kmp_str_match( "apic_id", 7, value )
3003 || __kmp_str_match( "apic-id", 7, value )
3004 || __kmp_str_match( "apicid", 6, value )
3005 || __kmp_str_match( "cpuid leaf 4", 12, value )
3006 || __kmp_str_match( "cpuid_leaf_4", 12, value )
3007 || __kmp_str_match( "cpuid-leaf-4", 12, value )
3008 || __kmp_str_match( "cpuid leaf4", 11, value )
3009 || __kmp_str_match( "cpuid_leaf4", 11, value )
3010 || __kmp_str_match( "cpuid-leaf4", 11, value )
3011 || __kmp_str_match( "cpuidleaf 4", 11, value )
3012 || __kmp_str_match( "cpuidleaf_4", 11, value )
3013 || __kmp_str_match( "cpuidleaf-4", 11, value )
3014 || __kmp_str_match( "cpuidleaf4", 10, value )
3015 || __kmp_str_match( "cpuid 4", 7, value )
3016 || __kmp_str_match( "cpuid_4", 7, value )
3017 || __kmp_str_match( "cpuid-4", 7, value )
3018 || __kmp_str_match( "cpuid4", 6, value )
3019 || __kmp_str_match( "leaf 4", 6, value )
3020 || __kmp_str_match( "leaf_4", 6, value )
3021 || __kmp_str_match( "leaf-4", 6, value )
3022 || __kmp_str_match( "leaf4", 5, value ) ) {
3023 __kmp_affinity_top_method = affinity_top_method_apicid;
3024 }
3025# endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
3026 else if ( __kmp_str_match( "/proc/cpuinfo", 2, value )
3027 || __kmp_str_match( "cpuinfo", 5, value )) {
3028 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
3029 }
Andrey Churbanov7daf9802015-01-27 16:52:57 +00003030# if KMP_GROUP_AFFINITY
Jim Cownie5e8470a2013-09-27 10:38:44 +00003031 else if ( __kmp_str_match( "group", 1, value ) ) {
3032 __kmp_affinity_top_method = affinity_top_method_group;
3033 }
Andrey Churbanov7daf9802015-01-27 16:52:57 +00003034# endif /* KMP_GROUP_AFFINITY */
Jim Cownie5e8470a2013-09-27 10:38:44 +00003035 else if ( __kmp_str_match( "flat", 1, value ) ) {
3036 __kmp_affinity_top_method = affinity_top_method_flat;
3037 }
Jonathan Peyton01dcf362015-11-30 20:02:59 +00003038# if KMP_USE_HWLOC
3039 else if ( __kmp_str_match( "hwloc", 1, value) ) {
3040 __kmp_affinity_top_method = affinity_top_method_hwloc;
3041 }
3042# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00003043 else {
3044 KMP_WARNING( StgInvalidValue, name, value );
3045 }
3046} // __kmp_stg_parse_topology_method
3047
3048static void
3049__kmp_stg_print_topology_method( kmp_str_buf_t * buffer, char const * name,
3050 void * data ) {
3051# if KMP_DEBUG
3052 char const * value = NULL;
3053
3054 switch ( __kmp_affinity_top_method ) {
3055 case affinity_top_method_default:
3056 value = "default";
3057 break;
3058
3059 case affinity_top_method_all:
3060 value = "all";
3061 break;
3062
3063# if KMP_ARCH_X86 || KMP_ARCH_X86_64
3064 case affinity_top_method_x2apicid:
3065 value = "x2APIC id";
3066 break;
3067
3068 case affinity_top_method_apicid:
3069 value = "APIC id";
3070 break;
3071# endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
3072
3073 case affinity_top_method_cpuinfo:
3074 value = "cpuinfo";
3075 break;
3076
Andrey Churbanov7daf9802015-01-27 16:52:57 +00003077# if KMP_GROUP_AFFINITY
Jim Cownie5e8470a2013-09-27 10:38:44 +00003078 case affinity_top_method_group:
3079 value = "group";
3080 break;
Andrey Churbanov7daf9802015-01-27 16:52:57 +00003081# endif /* KMP_GROUP_AFFINITY */
Jim Cownie5e8470a2013-09-27 10:38:44 +00003082
3083 case affinity_top_method_flat:
3084 value = "flat";
3085 break;
3086 }
3087
3088 if ( value != NULL ) {
3089 __kmp_stg_print_str( buffer, name, value );
3090 }
3091# endif /* KMP_DEBUG */
3092} // __kmp_stg_print_topology_method
3093
Alp Toker98758b02014-03-02 04:12:06 +00003094#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00003095
3096
3097#if OMP_40_ENABLED
3098
3099//
3100// OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
3101// OMP_PLACES / place-partition-var is not.
3102//
3103static void
3104__kmp_stg_parse_proc_bind( char const * name, char const * value, void * data )
3105{
3106 kmp_setting_t **rivals = (kmp_setting_t **) data;
3107 int rc;
3108
3109 rc = __kmp_stg_check_rivals( name, value, rivals );
3110 if ( rc ) {
3111 return;
3112 }
3113
3114 //
3115 // in OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
3116 //
3117 KMP_DEBUG_ASSERT( (__kmp_nested_proc_bind.bind_types != NULL)
3118 && ( __kmp_nested_proc_bind.used > 0 ) );
3119
3120 const char *buf = value;
3121 const char *next;
3122 int num;
3123 SKIP_WS( buf );
3124 if ( (*buf >= '0') && (*buf <= '9') ) {
3125 next = buf;
3126 SKIP_DIGITS( next );
3127 num = __kmp_str_to_int( buf, *next );
3128 KMP_ASSERT( num >= 0 );
3129 buf = next;
3130 SKIP_WS( buf );
3131 }
3132 else {
3133 num = -1;
3134 }
3135
3136 next = buf;
3137 if ( __kmp_match_str( "disabled", buf, &next ) ) {
3138 buf = next;
3139 SKIP_WS( buf );
Alp Toker98758b02014-03-02 04:12:06 +00003140# if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00003141 __kmp_affinity_type = affinity_disabled;
Alp Toker98758b02014-03-02 04:12:06 +00003142# endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00003143 __kmp_nested_proc_bind.used = 1;
Andrey Churbanov94e569e2015-03-10 09:19:47 +00003144 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003145 }
3146 else if ( ( num == (int)proc_bind_false )
3147 || __kmp_match_str( "false", buf, &next ) ) {
3148 buf = next;
3149 SKIP_WS( buf );
Alp Toker98758b02014-03-02 04:12:06 +00003150# if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00003151 __kmp_affinity_type = affinity_none;
Alp Toker98758b02014-03-02 04:12:06 +00003152# endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00003153 __kmp_nested_proc_bind.used = 1;
3154 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3155 }
3156 else if ( ( num == (int)proc_bind_true )
3157 || __kmp_match_str( "true", buf, &next ) ) {
3158 buf = next;
3159 SKIP_WS( buf );
3160 __kmp_nested_proc_bind.used = 1;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00003161 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003162 }
3163 else {
3164 //
3165 // Count the number of values in the env var string
3166 //
3167 const char *scan;
3168 int nelem = 1;
3169 for ( scan = buf; *scan != '\0'; scan++ ) {
3170 if ( *scan == ',' ) {
3171 nelem++;
3172 }
3173 }
3174
3175 //
3176 // Create / expand the nested proc_bind array as needed
3177 //
3178 if ( __kmp_nested_proc_bind.size < nelem ) {
3179 __kmp_nested_proc_bind.bind_types = (kmp_proc_bind_t *)
3180 KMP_INTERNAL_REALLOC( __kmp_nested_proc_bind.bind_types,
3181 sizeof(kmp_proc_bind_t) * nelem );
3182 if ( __kmp_nested_proc_bind.bind_types == NULL ) {
3183 KMP_FATAL( MemoryAllocFailed );
3184 }
3185 __kmp_nested_proc_bind.size = nelem;
3186 }
3187 __kmp_nested_proc_bind.used = nelem;
3188
3189 //
3190 // Save values in the nested proc_bind array
3191 //
3192 int i = 0;
3193 for (;;) {
3194 enum kmp_proc_bind_t bind;
3195
3196 if ( ( num == (int)proc_bind_master )
3197 || __kmp_match_str( "master", buf, &next ) ) {
3198 buf = next;
3199 SKIP_WS( buf );
3200 bind = proc_bind_master;
3201 }
3202 else if ( ( num == (int)proc_bind_close )
3203 || __kmp_match_str( "close", buf, &next ) ) {
3204 buf = next;
3205 SKIP_WS( buf );
3206 bind = proc_bind_close;
3207 }
3208 else if ( ( num == (int)proc_bind_spread )
3209 || __kmp_match_str( "spread", buf, &next ) ) {
3210 buf = next;
3211 SKIP_WS( buf );
3212 bind = proc_bind_spread;
3213 }
3214 else {
3215 KMP_WARNING( StgInvalidValue, name, value );
3216 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3217 __kmp_nested_proc_bind.used = 1;
3218 return;
3219 }
3220
3221 __kmp_nested_proc_bind.bind_types[i++] = bind;
3222 if ( i >= nelem ) {
3223 break;
3224 }
3225 KMP_DEBUG_ASSERT( *buf == ',' );
3226 buf++;
3227 SKIP_WS( buf );
3228
3229 //
3230 // Read next value if it was specified as an integer
3231 //
3232 if ( (*buf >= '0') && (*buf <= '9') ) {
3233 next = buf;
3234 SKIP_DIGITS( next );
3235 num = __kmp_str_to_int( buf, *next );
3236 KMP_ASSERT( num >= 0 );
3237 buf = next;
3238 SKIP_WS( buf );
3239 }
3240 else {
3241 num = -1;
3242 }
3243 }
3244 SKIP_WS( buf );
3245 }
3246 if ( *buf != '\0' ) {
3247 KMP_WARNING( ParseExtraCharsWarn, name, buf );
3248 }
3249}
3250
3251
3252static void
3253__kmp_stg_print_proc_bind( kmp_str_buf_t * buffer, char const * name,
3254 void * data )
3255{
3256 int nelem = __kmp_nested_proc_bind.used;
3257 if( __kmp_env_format ) {
3258 KMP_STR_BUF_PRINT_NAME;
3259 } else {
3260 __kmp_str_buf_print( buffer, " %s", name );
3261 }
3262 if ( nelem == 0 ) {
3263 __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
3264 }
3265 else {
3266 int i;
3267 __kmp_str_buf_print( buffer, "='", name );
3268 for ( i = 0; i < nelem; i++ ) {
3269 switch ( __kmp_nested_proc_bind.bind_types[i] ) {
3270 case proc_bind_false:
3271 __kmp_str_buf_print( buffer, "false" );
3272 break;
3273
3274 case proc_bind_true:
3275 __kmp_str_buf_print( buffer, "true" );
3276 break;
3277
3278 case proc_bind_master:
3279 __kmp_str_buf_print( buffer, "master" );
3280 break;
3281
3282 case proc_bind_close:
3283 __kmp_str_buf_print( buffer, "close" );
3284 break;
3285
3286 case proc_bind_spread:
3287 __kmp_str_buf_print( buffer, "spread" );
3288 break;
3289
Jim Cownie5e8470a2013-09-27 10:38:44 +00003290 case proc_bind_intel:
3291 __kmp_str_buf_print( buffer, "intel" );
3292 break;
3293
3294 case proc_bind_default:
3295 __kmp_str_buf_print( buffer, "default" );
3296 break;
3297 }
3298 if ( i < nelem - 1 ) {
3299 __kmp_str_buf_print( buffer, "," );
3300 }
3301 }
3302 __kmp_str_buf_print( buffer, "'\n" );
3303 }
3304}
3305
3306#endif /* OMP_40_ENABLED */
3307
3308
3309// -------------------------------------------------------------------------------------------------
3310// OMP_DYNAMIC
3311// -------------------------------------------------------------------------------------------------
3312
3313static void
3314__kmp_stg_parse_omp_dynamic( char const * name, char const * value, void * data )
3315{
3316 __kmp_stg_parse_bool( name, value, & (__kmp_global.g.g_dynamic) );
3317} // __kmp_stg_parse_omp_dynamic
3318
3319static void
3320__kmp_stg_print_omp_dynamic( kmp_str_buf_t * buffer, char const * name, void * data )
3321{
3322 __kmp_stg_print_bool( buffer, name, __kmp_global.g.g_dynamic );
3323} // __kmp_stg_print_omp_dynamic
3324
3325static void
3326__kmp_stg_parse_kmp_dynamic_mode( char const * name, char const * value, void * data )
3327{
3328 if ( TCR_4(__kmp_init_parallel) ) {
3329 KMP_WARNING( EnvParallelWarn, name );
3330 __kmp_env_toPrint( name, 0 );
3331 return;
3332 }
3333#ifdef USE_LOAD_BALANCE
3334 else if ( __kmp_str_match( "load balance", 2, value )
3335 || __kmp_str_match( "load_balance", 2, value )
3336 || __kmp_str_match( "load-balance", 2, value )
3337 || __kmp_str_match( "loadbalance", 2, value )
3338 || __kmp_str_match( "balance", 1, value ) ) {
3339 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3340 }
3341#endif /* USE_LOAD_BALANCE */
3342 else if ( __kmp_str_match( "thread limit", 1, value )
3343 || __kmp_str_match( "thread_limit", 1, value )
3344 || __kmp_str_match( "thread-limit", 1, value )
3345 || __kmp_str_match( "threadlimit", 1, value )
3346 || __kmp_str_match( "limit", 2, value ) ) {
3347 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3348 }
3349 else if ( __kmp_str_match( "random", 1, value ) ) {
3350 __kmp_global.g.g_dynamic_mode = dynamic_random;
3351 }
3352 else {
3353 KMP_WARNING( StgInvalidValue, name, value );
3354 }
3355} //__kmp_stg_parse_kmp_dynamic_mode
3356
3357static void
3358__kmp_stg_print_kmp_dynamic_mode( kmp_str_buf_t * buffer, char const * name, void * data )
3359{
3360#if KMP_DEBUG
3361 if ( __kmp_global.g.g_dynamic_mode == dynamic_default ) {
3362 __kmp_str_buf_print( buffer, " %s: %s \n", name, KMP_I18N_STR( NotDefined ) );
3363 }
3364# ifdef USE_LOAD_BALANCE
3365 else if ( __kmp_global.g.g_dynamic_mode == dynamic_load_balance ) {
3366 __kmp_stg_print_str( buffer, name, "load balance" );
3367 }
3368# endif /* USE_LOAD_BALANCE */
3369 else if ( __kmp_global.g.g_dynamic_mode == dynamic_thread_limit ) {
3370 __kmp_stg_print_str( buffer, name, "thread limit" );
3371 }
3372 else if ( __kmp_global.g.g_dynamic_mode == dynamic_random ) {
3373 __kmp_stg_print_str( buffer, name, "random" );
3374 }
3375 else {
3376 KMP_ASSERT(0);
3377 }
3378#endif /* KMP_DEBUG */
3379} // __kmp_stg_print_kmp_dynamic_mode
3380
3381
3382#ifdef USE_LOAD_BALANCE
3383
3384// -------------------------------------------------------------------------------------------------
3385// KMP_LOAD_BALANCE_INTERVAL
3386// -------------------------------------------------------------------------------------------------
3387
3388static void
3389__kmp_stg_parse_ld_balance_interval( char const * name, char const * value, void * data )
3390{
3391 double interval = __kmp_convert_to_double( value );
3392 if ( interval >= 0 ) {
3393 __kmp_load_balance_interval = interval;
3394 } else {
3395 KMP_WARNING( StgInvalidValue, name, value );
3396 }; // if
3397} // __kmp_stg_parse_load_balance_interval
3398
3399static void
3400__kmp_stg_print_ld_balance_interval( kmp_str_buf_t * buffer, char const * name, void * data ) {
3401#if KMP_DEBUG
3402 __kmp_str_buf_print( buffer, " %s=%8.6f\n", name, __kmp_load_balance_interval );
3403#endif /* KMP_DEBUG */
3404} // __kmp_stg_print_load_balance_interval
3405
3406#endif /* USE_LOAD_BALANCE */
3407
Jim Cownie5e8470a2013-09-27 10:38:44 +00003408// -------------------------------------------------------------------------------------------------
3409// KMP_INIT_AT_FORK
3410// -------------------------------------------------------------------------------------------------
3411
3412static void
3413__kmp_stg_parse_init_at_fork( char const * name, char const * value, void * data ) {
3414 __kmp_stg_parse_bool( name, value, & __kmp_need_register_atfork );
3415 if ( __kmp_need_register_atfork ) {
3416 __kmp_need_register_atfork_specified = TRUE;
3417 };
3418} // __kmp_stg_parse_init_at_fork
3419
3420static void
3421__kmp_stg_print_init_at_fork( kmp_str_buf_t * buffer, char const * name, void * data ) {
3422 __kmp_stg_print_bool( buffer, name, __kmp_need_register_atfork_specified );
3423} // __kmp_stg_print_init_at_fork
3424
3425// -------------------------------------------------------------------------------------------------
3426// KMP_SCHEDULE
3427// -------------------------------------------------------------------------------------------------
3428
3429static void
3430__kmp_stg_parse_schedule( char const * name, char const * value, void * data ) {
3431
3432 if ( value != NULL ) {
Andrey Churbanov74bf17b2015-04-02 13:27:08 +00003433 size_t length = KMP_STRLEN( value );
Jim Cownie5e8470a2013-09-27 10:38:44 +00003434 if ( length > INT_MAX ) {
3435 KMP_WARNING( LongValue, name );
3436 } else {
3437 char *semicolon;
3438 if( value[ length - 1 ] == '"' || value[ length -1 ] == '\'' )
3439 KMP_WARNING( UnbalancedQuotes, name );
3440 do {
3441 char sentinel;
3442
3443 semicolon = (char *) strchr( value, ';' );
3444 if( *value && semicolon != value ) {
3445 char *comma = (char *) strchr( value, ',' );
3446
3447 if ( comma ) {
3448 ++comma;
3449 sentinel = ',';
3450 } else
3451 sentinel = ';';
3452 if ( !__kmp_strcasecmp_with_sentinel( "static", value, sentinel ) ) {
3453 if( !__kmp_strcasecmp_with_sentinel( "greedy", comma, ';' ) ) {
3454 __kmp_static = kmp_sch_static_greedy;
3455 continue;
3456 } else if( !__kmp_strcasecmp_with_sentinel( "balanced", comma, ';' ) ) {
3457 __kmp_static = kmp_sch_static_balanced;
3458 continue;
3459 }
3460 } else if ( !__kmp_strcasecmp_with_sentinel( "guided", value, sentinel ) ) {
3461 if ( !__kmp_strcasecmp_with_sentinel( "iterative", comma, ';' ) ) {
3462 __kmp_guided = kmp_sch_guided_iterative_chunked;
3463 continue;
3464 } else if ( !__kmp_strcasecmp_with_sentinel( "analytical", comma, ';' ) ) {
3465 /* analytical not allowed for too many threads */
3466 __kmp_guided = kmp_sch_guided_analytical_chunked;
3467 continue;
3468 }
3469 }
3470 KMP_WARNING( InvalidClause, name, value );
3471 } else
3472 KMP_WARNING( EmptyClause, name );
Jim Cownie4cc4bb42014-10-07 16:25:50 +00003473 } while ( (value = semicolon ? semicolon + 1 : NULL) );
Jim Cownie5e8470a2013-09-27 10:38:44 +00003474 }
3475 }; // if
3476
3477} // __kmp_stg_parse__schedule
3478
3479static void
3480__kmp_stg_print_schedule( kmp_str_buf_t * buffer, char const * name, void * data ) {
3481 if( __kmp_env_format ) {
3482 KMP_STR_BUF_PRINT_NAME_EX(name);
3483 } else {
3484 __kmp_str_buf_print( buffer, " %s='", name );
3485 }
3486 if ( __kmp_static == kmp_sch_static_greedy ) {
3487 __kmp_str_buf_print( buffer, "%s", "static,greedy");
3488 } else if ( __kmp_static == kmp_sch_static_balanced ) {
3489 __kmp_str_buf_print ( buffer, "%s", "static,balanced");
3490 }
3491 if ( __kmp_guided == kmp_sch_guided_iterative_chunked ) {
3492 __kmp_str_buf_print( buffer, ";%s'\n", "guided,iterative");
3493 } else if ( __kmp_guided == kmp_sch_guided_analytical_chunked ) {
3494 __kmp_str_buf_print( buffer, ";%s'\n", "guided,analytical");
3495 }
3496} // __kmp_stg_print_schedule
3497
3498// -------------------------------------------------------------------------------------------------
3499// OMP_SCHEDULE
3500// -------------------------------------------------------------------------------------------------
3501
3502static void
3503__kmp_stg_parse_omp_schedule( char const * name, char const * value, void * data )
3504{
3505 size_t length;
3506 if( value ) {
Andrey Churbanov74bf17b2015-04-02 13:27:08 +00003507 length = KMP_STRLEN( value );
Jim Cownie5e8470a2013-09-27 10:38:44 +00003508 if( length ) {
3509 char *comma = (char *) strchr( value, ',' );
3510 if( value[ length - 1 ] == '"' || value[ length -1 ] == '\'')
3511 KMP_WARNING( UnbalancedQuotes, name );
3512 /* get the specified scheduling style */
3513 if (!__kmp_strcasecmp_with_sentinel("dynamic", value, ',')) /* DYNAMIC */
3514 __kmp_sched = kmp_sch_dynamic_chunked;
3515 else if (!__kmp_strcasecmp_with_sentinel("guided", value, ',')) /* GUIDED */
3516 __kmp_sched = kmp_sch_guided_chunked;
3517// AC: TODO: add AUTO schedule, and pprobably remove TRAPEZOIDAL (OMP 3.0 does not allow it)
Jim Cownie5e8470a2013-09-27 10:38:44 +00003518 else if (!__kmp_strcasecmp_with_sentinel("auto", value, ',')) { /* AUTO */
3519 __kmp_sched = kmp_sch_auto;
3520 if( comma ) {
3521 __kmp_msg( kmp_ms_warning, KMP_MSG( IgnoreChunk, name, comma ), __kmp_msg_null );
3522 comma = NULL;
3523 }
3524 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003525 else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", value, ',')) /* TRAPEZOIDAL */
3526 __kmp_sched = kmp_sch_trapezoidal;
3527 else if (!__kmp_strcasecmp_with_sentinel("static", value, ',')) /* STATIC */
3528 __kmp_sched = kmp_sch_static;
3529#ifdef KMP_STATIC_STEAL_ENABLED
3530 else if (KMP_ARCH_X86_64 &&
3531 !__kmp_strcasecmp_with_sentinel("static_steal", value, ','))
3532 __kmp_sched = kmp_sch_static_steal;
3533#endif
3534 else {
3535 KMP_WARNING( StgInvalidValue, name, value );
3536 value = NULL; /* skip processing of comma */
3537 }
3538 if( value && comma ) {
3539 __kmp_env_chunk = TRUE;
3540
3541 if(__kmp_sched == kmp_sch_static)
3542 __kmp_sched = kmp_sch_static_chunked;
3543 ++comma;
3544 __kmp_chunk = __kmp_str_to_int( comma, 0 );
3545 if ( __kmp_chunk < 1 ) {
3546 __kmp_chunk = KMP_DEFAULT_CHUNK;
3547 __kmp_msg( kmp_ms_warning, KMP_MSG( InvalidChunk, name, comma ), __kmp_msg_null );
3548 KMP_INFORM( Using_int_Value, name, __kmp_chunk );
3549// AC: next block commented out until KMP_DEFAULT_CHUNK != KMP_MIN_CHUNK (to improve code coverage :)
3550// The default chunk size is 1 according to standard, thus making KMP_MIN_CHUNK not 1 we would introduce mess:
3551// wrong chunk becomes 1, but it will be impossible to explicitely set 1, because it becomes KMP_MIN_CHUNK...
3552// } else if ( __kmp_chunk < KMP_MIN_CHUNK ) {
3553// __kmp_chunk = KMP_MIN_CHUNK;
3554 } else if ( __kmp_chunk > KMP_MAX_CHUNK ) {
3555 __kmp_chunk = KMP_MAX_CHUNK;
3556 __kmp_msg( kmp_ms_warning, KMP_MSG( LargeChunk, name, comma ), __kmp_msg_null );
3557 KMP_INFORM( Using_int_Value, name, __kmp_chunk );
3558 }
3559 } else
3560 __kmp_env_chunk = FALSE;
3561 } else
3562 KMP_WARNING( EmptyString, name );
3563 }
3564 K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
3565 K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
3566 K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
3567 K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
3568} // __kmp_stg_parse_omp_schedule
3569
3570static void
3571__kmp_stg_print_omp_schedule( kmp_str_buf_t * buffer, char const * name, void * data ) {
3572 if( __kmp_env_format ) {
3573 KMP_STR_BUF_PRINT_NAME_EX(name);
3574 } else {
3575 __kmp_str_buf_print( buffer, " %s='", name );
3576 }
3577 if ( __kmp_chunk ) {
3578 switch ( __kmp_sched ) {
3579 case kmp_sch_dynamic_chunked:
3580 __kmp_str_buf_print( buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
3581 break;
3582 case kmp_sch_guided_iterative_chunked:
3583 case kmp_sch_guided_analytical_chunked:
3584 __kmp_str_buf_print( buffer, "%s,%d'\n", "guided", __kmp_chunk);
3585 break;
3586 case kmp_sch_trapezoidal:
3587 __kmp_str_buf_print( buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
3588 break;
3589 case kmp_sch_static:
3590 case kmp_sch_static_chunked:
3591 case kmp_sch_static_balanced:
3592 case kmp_sch_static_greedy:
3593 __kmp_str_buf_print( buffer, "%s,%d'\n", "static", __kmp_chunk);
3594 break;
3595 case kmp_sch_static_steal:
3596 __kmp_str_buf_print( buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
3597 break;
3598 case kmp_sch_auto:
3599 __kmp_str_buf_print( buffer, "%s,%d'\n", "auto", __kmp_chunk);
3600 break;
3601 }
3602 } else {
3603 switch ( __kmp_sched ) {
3604 case kmp_sch_dynamic_chunked:
3605 __kmp_str_buf_print( buffer, "%s'\n", "dynamic");
3606 break;
3607 case kmp_sch_guided_iterative_chunked:
3608 case kmp_sch_guided_analytical_chunked:
3609 __kmp_str_buf_print( buffer, "%s'\n", "guided");
3610 break;
3611 case kmp_sch_trapezoidal:
3612 __kmp_str_buf_print( buffer, "%s'\n", "trapezoidal");
3613 break;
3614 case kmp_sch_static:
3615 case kmp_sch_static_chunked:
3616 case kmp_sch_static_balanced:
3617 case kmp_sch_static_greedy:
3618 __kmp_str_buf_print( buffer, "%s'\n", "static");
3619 break;
3620 case kmp_sch_static_steal:
3621 __kmp_str_buf_print( buffer, "%s'\n", "static_steal");
3622 break;
3623 case kmp_sch_auto:
3624 __kmp_str_buf_print( buffer, "%s'\n", "auto");
3625 break;
3626 }
3627 }
3628} // __kmp_stg_print_omp_schedule
3629
3630// -------------------------------------------------------------------------------------------------
3631// KMP_ATOMIC_MODE
3632// -------------------------------------------------------------------------------------------------
3633
3634static void
3635__kmp_stg_parse_atomic_mode( char const * name, char const * value, void * data ) {
3636 // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP compatibility mode.
3637 int mode = 0;
3638 int max = 1;
3639 #ifdef KMP_GOMP_COMPAT
3640 max = 2;
3641 #endif /* KMP_GOMP_COMPAT */
3642 __kmp_stg_parse_int( name, value, 0, max, & mode );
3643 // TODO; parse_int is not very suitable for this case. In case of overflow it is better to use
3644 // 0 rather that max value.
3645 if ( mode > 0 ) {
3646 __kmp_atomic_mode = mode;
3647 }; // if
3648} // __kmp_stg_parse_atomic_mode
3649
3650static void
3651__kmp_stg_print_atomic_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
3652 __kmp_stg_print_int( buffer, name, __kmp_atomic_mode );
3653} // __kmp_stg_print_atomic_mode
3654
3655
3656// -------------------------------------------------------------------------------------------------
3657// KMP_CONSISTENCY_CHECK
3658// -------------------------------------------------------------------------------------------------
3659
3660static void
3661__kmp_stg_parse_consistency_check( char const * name, char const * value, void * data ) {
3662 if ( ! __kmp_strcasecmp_with_sentinel( "all", value, 0 ) ) {
3663 // Note, this will not work from kmp_set_defaults because th_cons stack was not allocated
3664 // for existed thread(s) thus the first __kmp_push_<construct> will break with assertion.
3665 // TODO: allocate th_cons if called from kmp_set_defaults.
3666 __kmp_env_consistency_check = TRUE;
3667 } else if ( ! __kmp_strcasecmp_with_sentinel( "none", value, 0 ) ) {
3668 __kmp_env_consistency_check = FALSE;
3669 } else {
3670 KMP_WARNING( StgInvalidValue, name, value );
3671 }; // if
3672} // __kmp_stg_parse_consistency_check
3673
3674static void
3675__kmp_stg_print_consistency_check( kmp_str_buf_t * buffer, char const * name, void * data ) {
3676#if KMP_DEBUG
3677 const char *value = NULL;
3678
3679 if ( __kmp_env_consistency_check ) {
3680 value = "all";
3681 } else {
3682 value = "none";
3683 }
3684
3685 if ( value != NULL ) {
3686 __kmp_stg_print_str( buffer, name, value );
3687 }
3688#endif /* KMP_DEBUG */
3689} // __kmp_stg_print_consistency_check
3690
3691
3692#if USE_ITT_BUILD
3693// -------------------------------------------------------------------------------------------------
3694// KMP_ITT_PREPARE_DELAY
3695// -------------------------------------------------------------------------------------------------
3696
3697#if USE_ITT_NOTIFY
3698
3699static void
3700__kmp_stg_parse_itt_prepare_delay( char const * name, char const * value, void * data )
3701{
3702 // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop iterations.
3703 int delay = 0;
3704 __kmp_stg_parse_int( name, value, 0, INT_MAX, & delay );
3705 __kmp_itt_prepare_delay = delay;
3706} // __kmp_str_parse_itt_prepare_delay
3707
3708static void
3709__kmp_stg_print_itt_prepare_delay( kmp_str_buf_t * buffer, char const * name, void * data ) {
3710 __kmp_stg_print_uint64( buffer, name, __kmp_itt_prepare_delay );
3711
3712} // __kmp_str_print_itt_prepare_delay
3713
3714#endif // USE_ITT_NOTIFY
3715#endif /* USE_ITT_BUILD */
3716
3717// -------------------------------------------------------------------------------------------------
3718// KMP_MALLOC_POOL_INCR
3719// -------------------------------------------------------------------------------------------------
3720
3721static void
3722__kmp_stg_parse_malloc_pool_incr( char const * name, char const * value, void * data ) {
3723 __kmp_stg_parse_size(
3724 name,
3725 value,
3726 KMP_MIN_MALLOC_POOL_INCR,
3727 KMP_MAX_MALLOC_POOL_INCR,
3728 NULL,
3729 & __kmp_malloc_pool_incr,
3730 1
3731 );
3732} // __kmp_stg_parse_malloc_pool_incr
3733
3734static void
3735__kmp_stg_print_malloc_pool_incr( kmp_str_buf_t * buffer, char const * name, void * data ) {
3736 __kmp_stg_print_size( buffer, name, __kmp_malloc_pool_incr );
3737
3738} // _kmp_stg_print_malloc_pool_incr
3739
3740
3741#ifdef KMP_DEBUG
3742
3743// -------------------------------------------------------------------------------------------------
3744// KMP_PAR_RANGE
3745// -------------------------------------------------------------------------------------------------
3746
3747static void
3748__kmp_stg_parse_par_range_env( char const * name, char const * value, void * data ) {
3749 __kmp_stg_parse_par_range(
3750 name,
3751 value,
3752 & __kmp_par_range,
3753 __kmp_par_range_routine,
3754 __kmp_par_range_filename,
3755 & __kmp_par_range_lb,
3756 & __kmp_par_range_ub
3757 );
3758} // __kmp_stg_parse_par_range_env
3759
3760static void
3761__kmp_stg_print_par_range_env( kmp_str_buf_t * buffer, char const * name, void * data ) {
3762 if (__kmp_par_range != 0) {
3763 __kmp_stg_print_str( buffer, name, par_range_to_print );
3764 }
3765} // __kmp_stg_print_par_range_env
3766
3767// -------------------------------------------------------------------------------------------------
3768// KMP_YIELD_CYCLE, KMP_YIELD_ON, KMP_YIELD_OFF
3769// -------------------------------------------------------------------------------------------------
3770
3771static void
3772__kmp_stg_parse_yield_cycle( char const * name, char const * value, void * data ) {
3773 int flag = __kmp_yield_cycle;
3774 __kmp_stg_parse_bool( name, value, & flag );
3775 __kmp_yield_cycle = flag;
3776} // __kmp_stg_parse_yield_cycle
3777
3778static void
3779__kmp_stg_print_yield_cycle( kmp_str_buf_t * buffer, char const * name, void * data ) {
3780 __kmp_stg_print_bool( buffer, name, __kmp_yield_cycle );
3781} // __kmp_stg_print_yield_cycle
3782
3783static void
3784__kmp_stg_parse_yield_on( char const * name, char const * value, void * data ) {
3785 __kmp_stg_parse_int( name, value, 2, INT_MAX, & __kmp_yield_on_count );
3786} // __kmp_stg_parse_yield_on
3787
3788static void
3789__kmp_stg_print_yield_on( kmp_str_buf_t * buffer, char const * name, void * data ) {
3790 __kmp_stg_print_int( buffer, name, __kmp_yield_on_count );
3791} // __kmp_stg_print_yield_on
3792
3793static void
3794__kmp_stg_parse_yield_off( char const * name, char const * value, void * data ) {
3795 __kmp_stg_parse_int( name, value, 2, INT_MAX, & __kmp_yield_off_count );
3796} // __kmp_stg_parse_yield_off
3797
3798static void
3799__kmp_stg_print_yield_off( kmp_str_buf_t * buffer, char const * name, void * data ) {
3800 __kmp_stg_print_int( buffer, name, __kmp_yield_off_count );
3801} // __kmp_stg_print_yield_off
3802
3803#endif
3804
3805// -------------------------------------------------------------------------------------------------
3806// KMP_INIT_WAIT, KMP_NEXT_WAIT
3807// -------------------------------------------------------------------------------------------------
3808
3809static void
3810__kmp_stg_parse_init_wait( char const * name, char const * value, void * data ) {
3811 int wait;
3812 KMP_ASSERT( ( __kmp_init_wait & 1 ) == 0 );
3813 wait = __kmp_init_wait / 2;
3814 __kmp_stg_parse_int( name, value, KMP_MIN_INIT_WAIT, KMP_MAX_INIT_WAIT, & wait );
3815 __kmp_init_wait = wait * 2;
3816 KMP_ASSERT( ( __kmp_init_wait & 1 ) == 0 );
3817 __kmp_yield_init = __kmp_init_wait;
3818} // __kmp_stg_parse_init_wait
3819
3820static void
3821__kmp_stg_print_init_wait( kmp_str_buf_t * buffer, char const * name, void * data ) {
3822 __kmp_stg_print_int( buffer, name, __kmp_init_wait );
3823} // __kmp_stg_print_init_wait
3824
3825static void
3826__kmp_stg_parse_next_wait( char const * name, char const * value, void * data ) {
3827 int wait;
3828 KMP_ASSERT( ( __kmp_next_wait & 1 ) == 0 );
3829 wait = __kmp_next_wait / 2;
3830 __kmp_stg_parse_int( name, value, KMP_MIN_NEXT_WAIT, KMP_MAX_NEXT_WAIT, & wait );
3831 __kmp_next_wait = wait * 2;
3832 KMP_ASSERT( ( __kmp_next_wait & 1 ) == 0 );
3833 __kmp_yield_next = __kmp_next_wait;
3834} // __kmp_stg_parse_next_wait
3835
3836static void
3837__kmp_stg_print_next_wait( kmp_str_buf_t * buffer, char const * name, void * data ) {
3838 __kmp_stg_print_int( buffer, name, __kmp_next_wait );
3839} //__kmp_stg_print_next_wait
3840
3841
3842// -------------------------------------------------------------------------------------------------
3843// KMP_GTID_MODE
3844// -------------------------------------------------------------------------------------------------
3845
3846static void
3847__kmp_stg_parse_gtid_mode( char const * name, char const * value, void * data ) {
3848 //
3849 // Modes:
3850 // 0 -- do not change default
3851 // 1 -- sp search
3852 // 2 -- use "keyed" TLS var, i.e.
3853 // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
3854 // 3 -- __declspec(thread) TLS var in tdata section
3855 //
3856 int mode = 0;
3857 int max = 2;
3858 #ifdef KMP_TDATA_GTID
3859 max = 3;
3860 #endif /* KMP_TDATA_GTID */
3861 __kmp_stg_parse_int( name, value, 0, max, & mode );
3862 // TODO; parse_int is not very suitable for this case. In case of overflow it is better to use
3863 // 0 rather that max value.
3864 if ( mode == 0 ) {
3865 __kmp_adjust_gtid_mode = TRUE;
3866 }
3867 else {
3868 __kmp_gtid_mode = mode;
3869 __kmp_adjust_gtid_mode = FALSE;
3870 }; // if
3871} // __kmp_str_parse_gtid_mode
3872
3873static void
3874__kmp_stg_print_gtid_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
3875 if ( __kmp_adjust_gtid_mode ) {
3876 __kmp_stg_print_int( buffer, name, 0 );
3877 }
3878 else {
3879 __kmp_stg_print_int( buffer, name, __kmp_gtid_mode );
3880 }
3881} // __kmp_stg_print_gtid_mode
3882
Jim Cownie5e8470a2013-09-27 10:38:44 +00003883// -------------------------------------------------------------------------------------------------
3884// KMP_NUM_LOCKS_IN_BLOCK
3885// -------------------------------------------------------------------------------------------------
3886
3887static void
3888__kmp_stg_parse_lock_block( char const * name, char const * value, void * data ) {
3889 __kmp_stg_parse_int( name, value, 0, KMP_INT_MAX, & __kmp_num_locks_in_block );
3890} // __kmp_str_parse_lock_block
3891
3892static void
3893__kmp_stg_print_lock_block( kmp_str_buf_t * buffer, char const * name, void * data ) {
3894 __kmp_stg_print_int( buffer, name, __kmp_num_locks_in_block );
3895} // __kmp_stg_print_lock_block
3896
3897// -------------------------------------------------------------------------------------------------
3898// KMP_LOCK_KIND
3899// -------------------------------------------------------------------------------------------------
3900
Jonathan Peytondae13d82015-12-11 21:57:06 +00003901#if KMP_USE_DYNAMIC_LOCK
3902# define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
3903#else
3904# define KMP_STORE_LOCK_SEQ(a)
3905#endif
3906
Jim Cownie5e8470a2013-09-27 10:38:44 +00003907static void
3908__kmp_stg_parse_lock_kind( char const * name, char const * value, void * data ) {
3909 if ( __kmp_init_user_locks ) {
3910 KMP_WARNING( EnvLockWarn, name );
3911 return;
3912 }
3913
3914 if ( __kmp_str_match( "tas", 2, value )
3915 || __kmp_str_match( "test and set", 2, value )
3916 || __kmp_str_match( "test_and_set", 2, value )
3917 || __kmp_str_match( "test-and-set", 2, value )
3918 || __kmp_str_match( "test andset", 2, value )
3919 || __kmp_str_match( "test_andset", 2, value )
3920 || __kmp_str_match( "test-andset", 2, value )
3921 || __kmp_str_match( "testand set", 2, value )
3922 || __kmp_str_match( "testand_set", 2, value )
3923 || __kmp_str_match( "testand-set", 2, value )
3924 || __kmp_str_match( "testandset", 2, value ) ) {
3925 __kmp_user_lock_kind = lk_tas;
Jonathan Peytonf2d119f2015-12-03 19:37:20 +00003926 KMP_STORE_LOCK_SEQ(tas);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003927 }
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003928#if KMP_USE_FUTEX
Jim Cownie5e8470a2013-09-27 10:38:44 +00003929 else if ( __kmp_str_match( "futex", 1, value ) ) {
3930 if ( __kmp_futex_determine_capable() ) {
3931 __kmp_user_lock_kind = lk_futex;
Jonathan Peytonf2d119f2015-12-03 19:37:20 +00003932 KMP_STORE_LOCK_SEQ(futex);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003933 }
3934 else {
3935 KMP_WARNING( FutexNotSupported, name, value );
3936 }
3937 }
3938#endif
3939 else if ( __kmp_str_match( "ticket", 2, value ) ) {
3940 __kmp_user_lock_kind = lk_ticket;
Jonathan Peytonf2d119f2015-12-03 19:37:20 +00003941 KMP_STORE_LOCK_SEQ(ticket);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003942 }
3943 else if ( __kmp_str_match( "queuing", 1, value )
3944 || __kmp_str_match( "queue", 1, value ) ) {
3945 __kmp_user_lock_kind = lk_queuing;
Jonathan Peytonf2d119f2015-12-03 19:37:20 +00003946 KMP_STORE_LOCK_SEQ(queuing);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003947 }
3948 else if ( __kmp_str_match( "drdpa ticket", 1, value )
3949 || __kmp_str_match( "drdpa_ticket", 1, value )
3950 || __kmp_str_match( "drdpa-ticket", 1, value )
3951 || __kmp_str_match( "drdpaticket", 1, value )
3952 || __kmp_str_match( "drdpa", 1, value ) ) {
3953 __kmp_user_lock_kind = lk_drdpa;
Jonathan Peytonf2d119f2015-12-03 19:37:20 +00003954 KMP_STORE_LOCK_SEQ(drdpa);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003955 }
3956#if KMP_USE_ADAPTIVE_LOCKS
3957 else if ( __kmp_str_match( "adaptive", 1, value ) ) {
3958 if( __kmp_cpuinfo.rtm ) { // ??? Is cpuinfo available here?
3959 __kmp_user_lock_kind = lk_adaptive;
Jonathan Peytonf2d119f2015-12-03 19:37:20 +00003960 KMP_STORE_LOCK_SEQ(adaptive);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003961 } else {
3962 KMP_WARNING( AdaptiveNotSupported, name, value );
3963 __kmp_user_lock_kind = lk_queuing;
Jonathan Peytonf2d119f2015-12-03 19:37:20 +00003964 KMP_STORE_LOCK_SEQ(queuing);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003965 }
3966 }
3967#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peytondae13d82015-12-11 21:57:06 +00003968#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
3969 else if ( __kmp_str_match("rtm", 1, value) ) {
3970 if ( __kmp_cpuinfo.rtm ) {
3971 __kmp_user_lock_kind = lk_rtm;
3972 KMP_STORE_LOCK_SEQ(rtm);
3973 } else {
3974 KMP_WARNING( AdaptiveNotSupported, name, value );
3975 __kmp_user_lock_kind = lk_queuing;
3976 KMP_STORE_LOCK_SEQ(queuing);
3977 }
3978 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00003979 else if ( __kmp_str_match("hle", 1, value) ) {
Jonathan Peytondae13d82015-12-11 21:57:06 +00003980 __kmp_user_lock_kind = lk_hle;
Jonathan Peytonf2d119f2015-12-03 19:37:20 +00003981 KMP_STORE_LOCK_SEQ(hle);
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00003982 }
3983#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00003984 else {
3985 KMP_WARNING( StgInvalidValue, name, value );
3986 }
3987}
3988
3989static void
3990__kmp_stg_print_lock_kind( kmp_str_buf_t * buffer, char const * name, void * data ) {
3991 const char *value = NULL;
3992
3993 switch ( __kmp_user_lock_kind ) {
3994 case lk_default:
3995 value = "default";
3996 break;
3997
3998 case lk_tas:
3999 value = "tas";
4000 break;
4001
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00004002#if KMP_USE_FUTEX
Jim Cownie5e8470a2013-09-27 10:38:44 +00004003 case lk_futex:
4004 value = "futex";
4005 break;
4006#endif
4007
Jonathan Peytondae13d82015-12-11 21:57:06 +00004008#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4009 case lk_rtm:
4010 value = "rtm";
4011 break;
4012
4013 case lk_hle:
4014 value = "hle";
4015 break;
4016#endif
4017
Jim Cownie5e8470a2013-09-27 10:38:44 +00004018 case lk_ticket:
4019 value = "ticket";
4020 break;
4021
4022 case lk_queuing:
4023 value = "queuing";
4024 break;
4025
4026 case lk_drdpa:
4027 value = "drdpa";
4028 break;
4029#if KMP_USE_ADAPTIVE_LOCKS
4030 case lk_adaptive:
4031 value = "adaptive";
4032 break;
4033#endif
4034 }
4035
4036 if ( value != NULL ) {
4037 __kmp_stg_print_str( buffer, name, value );
4038 }
4039}
4040
Jonathan Peyton377aa402016-04-14 16:00:37 +00004041// -------------------------------------------------------------------------------------------------
4042// KMP_SPIN_BACKOFF_PARAMS
4043// -------------------------------------------------------------------------------------------------
4044
4045// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick for machine pause)
4046static void
4047__kmp_stg_parse_spin_backoff_params(const char* name, const char* value, void* data)
4048{
4049 const char *next = value;
4050
4051 int total = 0; // Count elements that were set. It'll be used as an array size
4052 int prev_comma = FALSE; // For correct processing sequential commas
4053 int i;
4054
4055 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
4056 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
4057
4058 // Run only 3 iterations because it is enough to read two values or find a syntax error
4059 for ( i = 0; i < 3 ; i++) {
4060 SKIP_WS( next );
4061
4062 if ( *next == '\0' ) {
4063 break;
4064 }
4065 // Next character is not an integer or not a comma OR number of values > 2 => end of list
4066 if ( ( ( *next < '0' || *next > '9' ) && *next !=',' ) || total > 2 ) {
4067 KMP_WARNING( EnvSyntaxError, name, value );
4068 return;
4069 }
4070 // The next character is ','
4071 if ( *next == ',' ) {
4072 // ',' is the fisrt character
4073 if ( total == 0 || prev_comma ) {
4074 total++;
4075 }
4076 prev_comma = TRUE;
4077 next++; //skip ','
4078 SKIP_WS( next );
4079 }
4080 // Next character is a digit
4081 if ( *next >= '0' && *next <= '9' ) {
4082 int num;
4083 const char *buf = next;
4084 char const * msg = NULL;
4085 prev_comma = FALSE;
4086 SKIP_DIGITS( next );
4087 total++;
4088
4089 const char *tmp = next;
4090 SKIP_WS( tmp );
4091 if ( ( *next == ' ' || *next == '\t' ) && ( *tmp >= '0' && *tmp <= '9' ) ) {
4092 KMP_WARNING( EnvSpacesNotAllowed, name, value );
4093 return;
4094 }
4095
4096 num = __kmp_str_to_int( buf, *next );
4097 if ( num <= 0 ) { // The number of retries should be > 0
4098 msg = KMP_I18N_STR( ValueTooSmall );
4099 num = 1;
4100 } else if ( num > KMP_INT_MAX ) {
4101 msg = KMP_I18N_STR( ValueTooLarge );
4102 num = KMP_INT_MAX;
4103 }
4104 if ( msg != NULL ) {
4105 // Message is not empty. Print warning.
4106 KMP_WARNING( ParseSizeIntWarn, name, value, msg );
4107 KMP_INFORM( Using_int_Value, name, num );
4108 }
4109 if( total == 1 ) {
4110 max_backoff = num;
4111 } else if( total == 2 ) {
4112 min_tick = num;
4113 }
4114 }
4115 }
4116 KMP_DEBUG_ASSERT( total > 0 );
4117 if( total <= 0 ) {
4118 KMP_WARNING( EnvSyntaxError, name, value );
4119 return;
4120 }
4121 __kmp_spin_backoff_params.max_backoff = max_backoff;
4122 __kmp_spin_backoff_params.min_tick = min_tick;
4123}
4124
4125static void
4126__kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer, char const* name, void* data)
4127{
4128 if( __kmp_env_format ) {
4129 KMP_STR_BUF_PRINT_NAME_EX(name);
4130 } else {
4131 __kmp_str_buf_print( buffer, " %s='", name );
4132 }
4133 __kmp_str_buf_print( buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
4134 __kmp_spin_backoff_params.min_tick );
4135}
4136
Jim Cownie5e8470a2013-09-27 10:38:44 +00004137#if KMP_USE_ADAPTIVE_LOCKS
4138
4139// -------------------------------------------------------------------------------------------------
4140// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
4141// -------------------------------------------------------------------------------------------------
4142
4143// Parse out values for the tunable parameters from a string of the form
4144// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
4145static void
4146__kmp_stg_parse_adaptive_lock_props( const char *name, const char *value, void *data )
4147{
4148 int max_retries = 0;
4149 int max_badness = 0;
4150
4151 const char *next = value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004152
4153 int total = 0; // Count elements that were set. It'll be used as an array size
4154 int prev_comma = FALSE; // For correct processing sequential commas
4155 int i;
4156
4157 // Save values in the structure __kmp_speculative_backoff_params
4158 // Run only 3 iterations because it is enough to read two values or find a syntax error
4159 for ( i = 0; i < 3 ; i++) {
4160 SKIP_WS( next );
4161
4162 if ( *next == '\0' ) {
4163 break;
4164 }
4165 // Next character is not an integer or not a comma OR number of values > 2 => end of list
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004166 if ( ( ( *next < '0' || *next > '9' ) && *next !=',' ) || total > 2 ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004167 KMP_WARNING( EnvSyntaxError, name, value );
4168 return;
4169 }
4170 // The next character is ','
4171 if ( *next == ',' ) {
4172 // ',' is the fisrt character
4173 if ( total == 0 || prev_comma ) {
4174 total++;
4175 }
4176 prev_comma = TRUE;
4177 next++; //skip ','
4178 SKIP_WS( next );
4179 }
4180 // Next character is a digit
4181 if ( *next >= '0' && *next <= '9' ) {
4182 int num;
4183 const char *buf = next;
4184 char const * msg = NULL;
4185 prev_comma = FALSE;
4186 SKIP_DIGITS( next );
4187 total++;
4188
4189 const char *tmp = next;
4190 SKIP_WS( tmp );
4191 if ( ( *next == ' ' || *next == '\t' ) && ( *tmp >= '0' && *tmp <= '9' ) ) {
4192 KMP_WARNING( EnvSpacesNotAllowed, name, value );
4193 return;
4194 }
4195
4196 num = __kmp_str_to_int( buf, *next );
Jonathan Peytondae13d82015-12-11 21:57:06 +00004197 if ( num < 0 ) { // The number of retries should be >= 0
Jim Cownie5e8470a2013-09-27 10:38:44 +00004198 msg = KMP_I18N_STR( ValueTooSmall );
4199 num = 1;
4200 } else if ( num > KMP_INT_MAX ) {
4201 msg = KMP_I18N_STR( ValueTooLarge );
4202 num = KMP_INT_MAX;
4203 }
4204 if ( msg != NULL ) {
4205 // Message is not empty. Print warning.
4206 KMP_WARNING( ParseSizeIntWarn, name, value, msg );
4207 KMP_INFORM( Using_int_Value, name, num );
4208 }
4209 if( total == 1 ) {
4210 max_retries = num;
4211 } else if( total == 2 ) {
4212 max_badness = num;
4213 }
4214 }
4215 }
4216 KMP_DEBUG_ASSERT( total > 0 );
4217 if( total <= 0 ) {
4218 KMP_WARNING( EnvSyntaxError, name, value );
4219 return;
4220 }
Jonathan Peytondae13d82015-12-11 21:57:06 +00004221 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4222 __kmp_adaptive_backoff_params.max_badness = max_badness;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004223}
4224
4225
4226static void
4227__kmp_stg_print_adaptive_lock_props(kmp_str_buf_t * buffer, char const * name, void * data )
4228{
4229 if( __kmp_env_format ) {
4230 KMP_STR_BUF_PRINT_NAME_EX(name);
4231 } else {
4232 __kmp_str_buf_print( buffer, " %s='", name );
4233 }
4234 __kmp_str_buf_print( buffer, "%d,%d'\n", __kmp_adaptive_backoff_params.max_soft_retries,
4235 __kmp_adaptive_backoff_params.max_badness );
4236} // __kmp_stg_print_adaptive_lock_props
4237
4238#if KMP_DEBUG_ADAPTIVE_LOCKS
4239
4240static void
4241__kmp_stg_parse_speculative_statsfile( char const * name, char const * value, void * data ) {
4242 __kmp_stg_parse_file( name, value, "", & __kmp_speculative_statsfile );
4243} // __kmp_stg_parse_speculative_statsfile
4244
4245static void
4246__kmp_stg_print_speculative_statsfile( kmp_str_buf_t * buffer, char const * name, void * data ) {
4247 if ( __kmp_str_match( "-", 0, __kmp_speculative_statsfile ) ) {
4248 __kmp_stg_print_str( buffer, name, "stdout" );
4249 } else {
4250 __kmp_stg_print_str( buffer, name, __kmp_speculative_statsfile );
4251 }
4252
4253} // __kmp_stg_print_speculative_statsfile
4254
4255#endif // KMP_DEBUG_ADAPTIVE_LOCKS
4256
4257#endif // KMP_USE_ADAPTIVE_LOCKS
4258
Jim Cownie5e8470a2013-09-27 10:38:44 +00004259// -------------------------------------------------------------------------------------------------
4260// KMP_PLACE_THREADS
4261// -------------------------------------------------------------------------------------------------
4262
4263static void
4264__kmp_stg_parse_place_threads( char const * name, char const * value, void * data ) {
4265 // Value example: 5Cx2Tx15O
4266 // Which means "use 5 cores with offset 15, 2 threads per core"
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004267 // AC: extended to sockets level, examples of
4268 // "use 2 sockets with offset 6, 2 cores with offset 2 per socket, 2 threads per core":
4269 // 2s,6o,2c,2o,2t; 2s,6o,2c,2t,2o; 2s@6,2c@2,2t
4270 // To not break legacy code core-offset can be last;
4271 // postfix "o" or prefix @ can be offset designator.
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004272 // Note: not all syntax errors are analyzed, some may be skipped.
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004273#define CHECK_DELIM(_x) (*(_x) == ',' || *(_x) == 'x')
Jim Cownie5e8470a2013-09-27 10:38:44 +00004274 int num;
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004275 int single_warning = 0;
4276 int flagS = 0, flagC = 0, flagT = 0, flagSO = 0, flagCO = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004277 const char *next = value;
4278 const char *prev;
4279
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004280 SKIP_WS(next); // skip white spaces
4281 if (*next == '\0')
4282 return; // no data provided, retain default values
4283 // Get num_sockets first (or whatever specified)
4284 if (*next >= '0' && *next <= '9') {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004285 prev = next;
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004286 SKIP_DIGITS(next);
4287 num = __kmp_str_to_int(prev, *next);
4288 SKIP_WS(next);
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004289 if (*next == 's' || *next == 'S') { // e.g. "2s"
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004290 __kmp_place_num_sockets = num;
4291 flagS = 1; // got num sockets
Jim Cownie5e8470a2013-09-27 10:38:44 +00004292 next++;
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004293 if (*next == '@') { // socket offset, e.g. "2s@4"
4294 flagSO = 1;
4295 prev = ++next; // don't allow spaces for simplicity
4296 if (!(*next >= '0' && *next <= '9')) {
4297 KMP_WARNING(AffThrPlaceInvalid, name, value);
4298 return;
4299 }
4300 SKIP_DIGITS(next);
4301 num = __kmp_str_to_int(prev, *next);
4302 __kmp_place_socket_offset = num;
4303 }
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004304 } else if (*next == 'c' || *next == 'C') {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004305 __kmp_place_num_cores = num;
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004306 flagS = flagC = 1; // sockets were not specified - use default
Jim Cownie5e8470a2013-09-27 10:38:44 +00004307 next++;
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004308 if (*next == '@') { // core offset, e.g. "2c@6"
4309 flagCO = 1;
4310 prev = ++next; // don't allow spaces for simplicity
4311 if (!(*next >= '0' && *next <= '9')) {
4312 KMP_WARNING(AffThrPlaceInvalid, name, value);
4313 return;
4314 }
4315 SKIP_DIGITS(next);
4316 num = __kmp_str_to_int(prev, *next);
4317 __kmp_place_core_offset = num;
4318 }
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004319 } else if (CHECK_DELIM(next)) {
4320 __kmp_place_num_cores = num; // no letter-designator - num cores
4321 flagS = flagC = 1; // sockets were not specified - use default
4322 next++;
4323 } else if (*next == 't' || *next == 'T') {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004324 __kmp_place_num_threads_per_core = num;
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004325 // sockets, cores were not specified - use default
Jim Cownie5e8470a2013-09-27 10:38:44 +00004326 return; // we ignore offset value in case all cores are used
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004327 } else if (*next == '\0') {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004328 __kmp_place_num_cores = num;
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004329 return; // the only value provided - set num cores
Jim Cownie5e8470a2013-09-27 10:38:44 +00004330 } else {
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004331 KMP_WARNING(AffThrPlaceInvalid, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004332 return;
4333 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004334 } else {
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004335 KMP_WARNING(AffThrPlaceInvalid, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004336 return;
4337 }
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004338 KMP_DEBUG_ASSERT(flagS); // num sockets should already be set here
4339 SKIP_WS(next);
4340 if (*next == '\0')
Jim Cownie5e8470a2013-09-27 10:38:44 +00004341 return; // " n " - something like this
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004342 if (CHECK_DELIM(next)) {
4343 next++; // skip delimiter
4344 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004345 }
4346
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004347 // Get second value (could be offset, num_cores, num_threads)
4348 if (*next >= '0' && *next <= '9') {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004349 prev = next;
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004350 SKIP_DIGITS(next);
4351 num = __kmp_str_to_int(prev, *next);
4352 SKIP_WS(next);
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004353 if (*next == 'c' || *next == 'C') {
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004354 KMP_DEBUG_ASSERT(flagC == 0);
4355 __kmp_place_num_cores = num;
4356 flagC = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004357 next++;
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004358 if (*next == '@') { // core offset, e.g. "2c@6"
4359 flagCO = 1;
4360 prev = ++next; // don't allow spaces for simplicity
4361 if (!(*next >= '0' && *next <= '9')) {
4362 KMP_WARNING(AffThrPlaceInvalid, name, value);
4363 return;
4364 }
4365 SKIP_DIGITS(next);
4366 num = __kmp_str_to_int(prev, *next);
4367 __kmp_place_core_offset = num;
4368 }
4369 } else if (*next == 'o' || *next == 'O') { // offset specified
4370 KMP_WARNING(AffThrPlaceDeprecated);
4371 single_warning = 1;
4372 if (flagC) { // whether num_cores already specified (sockets skipped)
4373 KMP_DEBUG_ASSERT(!flagCO); // either "o" or @, not both
4374 __kmp_place_core_offset = num;
4375 } else {
4376 KMP_DEBUG_ASSERT(!flagSO); // either "o" or @, not both
4377 __kmp_place_socket_offset = num;
4378 }
4379 next++;
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004380 } else if (*next == 't' || *next == 'T') {
4381 KMP_DEBUG_ASSERT(flagT == 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004382 __kmp_place_num_threads_per_core = num;
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004383 flagC = 1; // num_cores could be skipped ?
4384 flagT = 1;
4385 next++; // can have core-offset specified after num threads
4386 } else if (*next == '\0') {
4387 KMP_DEBUG_ASSERT(flagC); // 4x2 means 4 cores 2 threads per core
4388 __kmp_place_num_threads_per_core = num;
4389 return; // two values provided without letter-designator
Jim Cownie5e8470a2013-09-27 10:38:44 +00004390 } else {
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004391 KMP_WARNING(AffThrPlaceInvalid, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004392 return;
4393 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004394 } else {
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004395 KMP_WARNING(AffThrPlaceInvalid, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004396 return;
4397 }
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004398 SKIP_WS(next);
4399 if (*next == '\0')
4400 return; // " Ns,Nc " - something like this
4401 if (CHECK_DELIM(next)) {
4402 next++; // skip delimiter
4403 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004404 }
4405
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004406 // Get third value (could be core-offset, num_cores, num_threads)
4407 if (*next >= '0' && *next <= '9') {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004408 prev = next;
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004409 SKIP_DIGITS(next);
4410 num = __kmp_str_to_int(prev, *next);
4411 SKIP_WS(next);
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004412 if (*next == 't' || *next == 'T') {
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004413 KMP_DEBUG_ASSERT(flagT == 0);
4414 __kmp_place_num_threads_per_core = num;
4415 if (flagC == 0)
4416 return; // num_cores could be skipped (e.g. 2s,4o,2t)
4417 flagT = 1;
4418 next++; // can have core-offset specified later (e.g. 2s,1c,2t,3o)
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004419 } else if (*next == 'c' || *next == 'C') {
4420 KMP_DEBUG_ASSERT(flagC == 0);
4421 __kmp_place_num_cores = num;
4422 flagC = 1;
4423 next++;
4424 //KMP_DEBUG_ASSERT(*next != '@'); // socket offset used "o" designator
4425 } else if (*next == 'o' || *next == 'O') {
4426 KMP_WARNING(AffThrPlaceDeprecated);
4427 single_warning = 1;
4428 KMP_DEBUG_ASSERT(flagC);
4429 //KMP_DEBUG_ASSERT(!flagSO); // socket offset couldn't use @ designator
4430 __kmp_place_core_offset = num;
4431 next++;
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004432 } else {
4433 KMP_WARNING(AffThrPlaceInvalid, name, value);
4434 return;
4435 }
4436 } else {
4437 KMP_WARNING(AffThrPlaceInvalid, name, value);
4438 return;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004439 }
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004440 KMP_DEBUG_ASSERT(flagC);
4441 SKIP_WS(next);
4442 if ( *next == '\0' )
4443 return;
4444 if (CHECK_DELIM(next)) {
4445 next++; // skip delimiter
4446 SKIP_WS(next);
4447 }
4448
4449 // Get 4-th value (could be core-offset, num_threads)
4450 if (*next >= '0' && *next <= '9') {
4451 prev = next;
4452 SKIP_DIGITS(next);
4453 num = __kmp_str_to_int(prev, *next);
4454 SKIP_WS(next);
4455 if (*next == 'o' || *next == 'O') {
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004456 if (!single_warning) { // warn once
4457 KMP_WARNING(AffThrPlaceDeprecated);
4458 }
4459 KMP_DEBUG_ASSERT(!flagSO); // socket offset couldn't use @ designator
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004460 __kmp_place_core_offset = num;
4461 next++;
4462 } else if (*next == 't' || *next == 'T') {
4463 KMP_DEBUG_ASSERT(flagT == 0);
4464 __kmp_place_num_threads_per_core = num;
4465 flagT = 1;
4466 next++; // can have core-offset specified after num threads
4467 } else {
4468 KMP_WARNING(AffThrPlaceInvalid, name, value);
4469 return;
4470 }
4471 } else {
4472 KMP_WARNING(AffThrPlaceInvalid, name, value);
4473 return;
4474 }
4475 SKIP_WS(next);
4476 if ( *next == '\0' )
4477 return;
4478 if (CHECK_DELIM(next)) {
4479 next++; // skip delimiter
4480 SKIP_WS(next);
4481 }
4482
4483 // Get 5-th value (could be core-offset, num_threads)
4484 if (*next >= '0' && *next <= '9') {
4485 prev = next;
4486 SKIP_DIGITS(next);
4487 num = __kmp_str_to_int(prev, *next);
4488 SKIP_WS(next);
4489 if (*next == 'o' || *next == 'O') {
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004490 if (!single_warning) { // warn once
4491 KMP_WARNING(AffThrPlaceDeprecated);
4492 }
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004493 KMP_DEBUG_ASSERT(flagT);
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004494 KMP_DEBUG_ASSERT(!flagSO); // socket offset couldn't use @ designator
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004495 __kmp_place_core_offset = num;
4496 } else if (*next == 't' || *next == 'T') {
4497 KMP_DEBUG_ASSERT(flagT == 0);
4498 __kmp_place_num_threads_per_core = num;
4499 } else {
4500 KMP_WARNING(AffThrPlaceInvalid, name, value);
4501 }
4502 } else {
4503 KMP_WARNING(AffThrPlaceInvalid, name, value);
4504 }
4505 return;
4506#undef CHECK_DELIM
Jim Cownie5e8470a2013-09-27 10:38:44 +00004507}
4508
4509static void
4510__kmp_stg_print_place_threads( kmp_str_buf_t * buffer, char const * name, void * data ) {
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004511 if (__kmp_place_num_sockets + __kmp_place_num_cores + __kmp_place_num_threads_per_core) {
4512 int comma = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004513 kmp_str_buf_t buf;
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004514 __kmp_str_buf_init(&buf);
4515 if(__kmp_env_format)
Jim Cownie5e8470a2013-09-27 10:38:44 +00004516 KMP_STR_BUF_PRINT_NAME_EX(name);
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004517 else
4518 __kmp_str_buf_print(buffer, " %s='", name);
4519 if (__kmp_place_num_sockets) {
4520 __kmp_str_buf_print(&buf, "%ds", __kmp_place_num_sockets);
4521 if (__kmp_place_socket_offset)
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004522 __kmp_str_buf_print(&buf, "@%d", __kmp_place_socket_offset);
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004523 comma = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004524 }
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004525 if (__kmp_place_num_cores) {
4526 __kmp_str_buf_print(&buf, "%s%dc", comma?",":"", __kmp_place_num_cores);
4527 if (__kmp_place_core_offset)
Jonathan Peyton55f027b2015-10-20 19:15:48 +00004528 __kmp_str_buf_print(&buf, "@%d", __kmp_place_core_offset);
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004529 comma = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004530 }
Jonathan Peytondd4aa9b2015-10-08 17:55:54 +00004531 if (__kmp_place_num_threads_per_core)
4532 __kmp_str_buf_print(&buf, "%s%dt", comma?",":"", __kmp_place_num_threads_per_core);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004533 __kmp_str_buf_print(buffer, "%s'\n", buf.str );
4534 __kmp_str_buf_free(&buf);
4535/*
4536 } else {
4537 __kmp_str_buf_print( buffer, " %s: %s \n", name, KMP_I18N_STR( NotDefined ) );
4538*/
4539 }
4540}
Jim Cownie5e8470a2013-09-27 10:38:44 +00004541
4542#if USE_ITT_BUILD
4543// -------------------------------------------------------------------------------------------------
4544// KMP_FORKJOIN_FRAMES
4545// -------------------------------------------------------------------------------------------------
4546
4547static void
4548__kmp_stg_parse_forkjoin_frames( char const * name, char const * value, void * data ) {
4549 __kmp_stg_parse_bool( name, value, & __kmp_forkjoin_frames );
4550} // __kmp_stg_parse_forkjoin_frames
4551
4552static void
4553__kmp_stg_print_forkjoin_frames( kmp_str_buf_t * buffer, char const * name, void * data ) {
4554 __kmp_stg_print_bool( buffer, name, __kmp_forkjoin_frames );
4555} // __kmp_stg_print_forkjoin_frames
4556
4557// -------------------------------------------------------------------------------------------------
4558// KMP_FORKJOIN_FRAMES_MODE
4559// -------------------------------------------------------------------------------------------------
4560
4561static void
4562__kmp_stg_parse_forkjoin_frames_mode( char const * name, char const * value, void * data ) {
4563 __kmp_stg_parse_int( name, value, 0, 3, & __kmp_forkjoin_frames_mode );
4564} // __kmp_stg_parse_forkjoin_frames
4565
4566static void
4567__kmp_stg_print_forkjoin_frames_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
4568 __kmp_stg_print_int( buffer, name, __kmp_forkjoin_frames_mode );
4569} // __kmp_stg_print_forkjoin_frames
4570#endif /* USE_ITT_BUILD */
4571
4572// -------------------------------------------------------------------------------------------------
4573// OMP_DISPLAY_ENV
4574// -------------------------------------------------------------------------------------------------
4575
4576#if OMP_40_ENABLED
4577
4578static void
4579__kmp_stg_parse_omp_display_env( char const * name, char const * value, void * data )
4580{
4581 if ( __kmp_str_match( "VERBOSE", 1, value ) )
4582 {
4583 __kmp_display_env_verbose = TRUE;
4584 } else {
4585 __kmp_stg_parse_bool( name, value, & __kmp_display_env );
4586 }
4587
4588} // __kmp_stg_parse_omp_display_env
4589
4590static void
4591__kmp_stg_print_omp_display_env( kmp_str_buf_t * buffer, char const * name, void * data )
4592{
4593 if ( __kmp_display_env_verbose )
4594 {
4595 __kmp_stg_print_str( buffer, name, "VERBOSE" );
4596 } else {
4597 __kmp_stg_print_bool( buffer, name, __kmp_display_env );
4598 }
4599} // __kmp_stg_print_omp_display_env
4600
Jim Cownie181b4bb2013-12-23 17:28:57 +00004601static void
4602__kmp_stg_parse_omp_cancellation( char const * name, char const * value, void * data ) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004603 if ( TCR_4(__kmp_init_parallel) ) {
4604 KMP_WARNING( EnvParallelWarn, name );
4605 return;
4606 } // read value before first parallel only
Jim Cownie181b4bb2013-12-23 17:28:57 +00004607 __kmp_stg_parse_bool( name, value, & __kmp_omp_cancellation );
4608} // __kmp_stg_parse_omp_cancellation
4609
4610static void
4611__kmp_stg_print_omp_cancellation( kmp_str_buf_t * buffer, char const * name, void * data ) {
4612 __kmp_stg_print_bool( buffer, name, __kmp_omp_cancellation );
4613} // __kmp_stg_print_omp_cancellation
4614
Jim Cownie5e8470a2013-09-27 10:38:44 +00004615#endif
4616
4617// -------------------------------------------------------------------------------------------------
4618// Table.
4619// -------------------------------------------------------------------------------------------------
4620
4621
4622static kmp_setting_t __kmp_stg_table[] = {
4623
4624 { "KMP_ALL_THREADS", __kmp_stg_parse_all_threads, __kmp_stg_print_all_threads, NULL, 0, 0 },
4625 { "KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime, NULL, 0, 0 },
4626 { "KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok, __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0 },
4627 { "KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy, NULL, 0, 0 },
4628 { "KMP_MAX_THREADS", __kmp_stg_parse_all_threads, NULL, NULL, 0, 0 }, // For backward compatibility
4629 { "KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize, __kmp_stg_print_monitor_stacksize, NULL, 0, 0 },
4630 { "KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL, 0, 0 },
4631 { "KMP_STACKOFFSET", __kmp_stg_parse_stackoffset, __kmp_stg_print_stackoffset, NULL, 0, 0 },
4632 { "KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize, NULL, 0, 0 },
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004633 { "KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL, 0, 0 },
Jim Cownie5e8470a2013-09-27 10:38:44 +00004634 { "KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0, 0 },
4635 { "KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL, 0, 0 },
4636
4637 { "OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0 },
4638 { "OMP_NUM_THREADS", __kmp_stg_parse_num_threads, __kmp_stg_print_num_threads, NULL, 0, 0 },
4639 { "OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize, NULL, 0, 0 },
4640
Jim Cownie5e8470a2013-09-27 10:38:44 +00004641 { "KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0, 0 },
4642 { "KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing, __kmp_stg_print_task_stealing, NULL, 0, 0 },
4643 { "OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels, __kmp_stg_print_max_active_levels, NULL, 0, 0 },
Jonathan Peyton28510722016-02-25 18:04:09 +00004644#if OMP_41_ENABLED
4645 { "OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority, __kmp_stg_print_max_task_priority, NULL, 0, 0 },
4646#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004647 { "OMP_THREAD_LIMIT", __kmp_stg_parse_all_threads, __kmp_stg_print_all_threads, NULL, 0, 0 },
4648 { "OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy, NULL, 0, 0 },
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004649#if KMP_NESTED_HOT_TEAMS
4650 { "KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level, __kmp_stg_print_hot_teams_level, NULL, 0, 0 },
4651 { "KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode, __kmp_stg_print_hot_teams_mode, NULL, 0, 0 },
4652#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00004653
4654#if KMP_HANDLE_SIGNALS
4655 { "KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals, __kmp_stg_print_handle_signals, NULL, 0, 0 },
4656#endif
4657
4658#if KMP_ARCH_X86 || KMP_ARCH_X86_64
4659 { "KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control, __kmp_stg_print_inherit_fp_control, NULL, 0, 0 },
4660#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
4661
4662#ifdef KMP_GOMP_COMPAT
4663 { "GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0 },
4664#endif
4665
4666#ifdef KMP_DEBUG
4667 { "KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0, 0 },
4668 { "KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0, 0 },
4669 { "KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0, 0 },
4670 { "KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0, 0 },
4671 { "KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0, 0 },
4672 { "KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0, 0 },
4673 { "KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0 },
4674 { "KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf, NULL, 0, 0 },
4675 { "KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic, __kmp_stg_print_debug_buf_atomic, NULL, 0, 0 },
4676 { "KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars, __kmp_stg_print_debug_buf_chars, NULL, 0, 0 },
4677 { "KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines, __kmp_stg_print_debug_buf_lines, NULL, 0, 0 },
4678 { "KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0 },
4679
4680 { "KMP_PAR_RANGE", __kmp_stg_parse_par_range_env, __kmp_stg_print_par_range_env, NULL, 0, 0 },
4681 { "KMP_YIELD_CYCLE", __kmp_stg_parse_yield_cycle, __kmp_stg_print_yield_cycle, NULL, 0, 0 },
4682 { "KMP_YIELD_ON", __kmp_stg_parse_yield_on, __kmp_stg_print_yield_on, NULL, 0, 0 },
4683 { "KMP_YIELD_OFF", __kmp_stg_parse_yield_off, __kmp_stg_print_yield_off, NULL, 0, 0 },
4684#endif // KMP_DEBUG
4685
4686 { "KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc, __kmp_stg_print_align_alloc, NULL, 0, 0 },
4687
4688 { "KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit, __kmp_stg_print_barrier_branch_bit, NULL, 0, 0 },
4689 { "KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, __kmp_stg_print_barrier_pattern, NULL, 0, 0 },
4690 { "KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit, __kmp_stg_print_barrier_branch_bit, NULL, 0, 0 },
4691 { "KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, __kmp_stg_print_barrier_pattern, NULL, 0, 0 },
4692#if KMP_FAST_REDUCTION_BARRIER
4693 { "KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit, __kmp_stg_print_barrier_branch_bit, NULL, 0, 0 },
4694 { "KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, __kmp_stg_print_barrier_pattern, NULL, 0, 0 },
4695#endif
4696
4697 { "KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay, __kmp_stg_print_abort_delay, NULL, 0, 0 },
4698 { "KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file, __kmp_stg_print_cpuinfo_file, NULL, 0, 0 },
4699 { "KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction, __kmp_stg_print_force_reduction, NULL, 0, 0 },
4700 { "KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction, __kmp_stg_print_force_reduction, NULL, 0, 0 },
4701 { "KMP_STORAGE_MAP", __kmp_stg_parse_storage_map, __kmp_stg_print_storage_map, NULL, 0, 0 },
4702 { "KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate, __kmp_stg_print_all_threadprivate, NULL, 0, 0 },
4703 { "KMP_FOREIGN_THREADS_THREADPRIVATE", __kmp_stg_parse_foreign_threads_threadprivate, __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0 },
4704
Alp Toker98758b02014-03-02 04:12:06 +00004705#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004706 { "KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL, 0, 0 },
4707# ifdef KMP_GOMP_COMPAT
4708 { "GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL, /* no print */ NULL, 0, 0 },
4709# endif /* KMP_GOMP_COMPAT */
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004710# if OMP_40_ENABLED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004711 { "OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind, NULL, 0, 0 },
4712 { "OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0 },
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004713# else
Jim Cownie5e8470a2013-09-27 10:38:44 +00004714 { "OMP_PROC_BIND", __kmp_stg_parse_proc_bind, NULL, /* no print */ NULL, 0, 0 },
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004715# endif /* OMP_40_ENABLED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00004716
4717 { "KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method, __kmp_stg_print_topology_method, NULL, 0, 0 },
4718
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004719#else
Jim Cownie5e8470a2013-09-27 10:38:44 +00004720
4721 //
4722 // KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
4723 // OMP_PROC_BIND and proc-bind-var are supported, however.
4724 //
4725# if OMP_40_ENABLED
4726 { "OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind, NULL, 0, 0 },
4727# endif
4728
Alp Toker98758b02014-03-02 04:12:06 +00004729#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004730
4731 { "KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork, __kmp_stg_print_init_at_fork, NULL, 0, 0 },
4732 { "KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL, 0, 0 },
4733 { "OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule, NULL, 0, 0 },
4734 { "KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode, __kmp_stg_print_atomic_mode, NULL, 0, 0 },
4735 { "KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check, __kmp_stg_print_consistency_check, NULL, 0, 0 },
4736
4737#if USE_ITT_BUILD && USE_ITT_NOTIFY
4738 { "KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay, __kmp_stg_print_itt_prepare_delay, NULL, 0, 0 },
4739#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
4740 { "KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr, __kmp_stg_print_malloc_pool_incr, NULL, 0, 0 },
4741 { "KMP_INIT_WAIT", __kmp_stg_parse_init_wait, __kmp_stg_print_init_wait, NULL, 0, 0 },
4742 { "KMP_NEXT_WAIT", __kmp_stg_parse_next_wait, __kmp_stg_print_next_wait, NULL, 0, 0 },
4743 { "KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode, NULL, 0, 0 },
4744 { "OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic, NULL, 0, 0 },
4745 { "KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode, __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0 },
4746
4747#ifdef USE_LOAD_BALANCE
4748 { "KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,__kmp_stg_print_ld_balance_interval,NULL, 0, 0 },
4749#endif
4750
Jim Cownie5e8470a2013-09-27 10:38:44 +00004751 { "KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block, __kmp_stg_print_lock_block, NULL, 0, 0 },
4752 { "KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind, NULL, 0, 0 },
Jonathan Peyton377aa402016-04-14 16:00:37 +00004753 { "KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params, __kmp_stg_print_spin_backoff_params, NULL, 0, 0 },
Jim Cownie5e8470a2013-09-27 10:38:44 +00004754#if KMP_USE_ADAPTIVE_LOCKS
4755 { "KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,__kmp_stg_print_adaptive_lock_props, NULL, 0, 0 },
4756#if KMP_DEBUG_ADAPTIVE_LOCKS
4757 { "KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,__kmp_stg_print_speculative_statsfile, NULL, 0, 0 },
4758#endif
4759#endif // KMP_USE_ADAPTIVE_LOCKS
Jim Cownie5e8470a2013-09-27 10:38:44 +00004760 { "KMP_PLACE_THREADS", __kmp_stg_parse_place_threads, __kmp_stg_print_place_threads, NULL, 0, 0 },
Jim Cownie5e8470a2013-09-27 10:38:44 +00004761#if USE_ITT_BUILD
4762 { "KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames, __kmp_stg_print_forkjoin_frames, NULL, 0, 0 },
4763 { "KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,__kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0 },
4764#endif
4765
4766# if OMP_40_ENABLED
4767 { "OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env, __kmp_stg_print_omp_display_env, NULL, 0, 0 },
Jim Cownie181b4bb2013-12-23 17:28:57 +00004768 { "OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation, __kmp_stg_print_omp_cancellation, NULL, 0, 0 },
Jim Cownie5e8470a2013-09-27 10:38:44 +00004769#endif
4770 { "", NULL, NULL, NULL, 0, 0 }
4771}; // settings
4772
4773static int const __kmp_stg_count = sizeof( __kmp_stg_table ) / sizeof( kmp_setting_t );
4774
4775static inline
4776kmp_setting_t *
4777__kmp_stg_find( char const * name ) {
4778
4779 int i;
4780 if ( name != NULL ) {
4781 for ( i = 0; i < __kmp_stg_count; ++ i ) {
4782 if ( strcmp( __kmp_stg_table[ i ].name, name ) == 0 ) {
4783 return & __kmp_stg_table[ i ];
4784 }; // if
4785 }; // for
4786 }; // if
4787 return NULL;
4788
4789} // __kmp_stg_find
4790
4791
4792static int
4793__kmp_stg_cmp( void const * _a, void const * _b ) {
4794 kmp_setting_t * a = (kmp_setting_t *) _a;
4795 kmp_setting_t * b = (kmp_setting_t *) _b;
4796
4797 //
4798 // Process KMP_AFFINITY last.
4799 // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
4800 //
4801 if ( strcmp( a->name, "KMP_AFFINITY" ) == 0 ) {
4802 if ( strcmp( b->name, "KMP_AFFINITY" ) == 0 ) {
4803 return 0;
4804 }
4805 return 1;
4806 }
4807 else if ( strcmp( b->name, "KMP_AFFINITY" ) == 0 ) {
4808 return -1;
4809 }
4810 return strcmp( a->name, b->name );
4811} // __kmp_stg_cmp
4812
4813
4814static void
4815__kmp_stg_init( void
4816) {
4817
4818 static int initialized = 0;
4819
4820 if ( ! initialized ) {
4821
4822 // Sort table.
4823 qsort( __kmp_stg_table, __kmp_stg_count - 1, sizeof( kmp_setting_t ), __kmp_stg_cmp );
4824
4825 { // Initialize *_STACKSIZE data.
4826
4827 kmp_setting_t * kmp_stacksize = __kmp_stg_find( "KMP_STACKSIZE" ); // 1st priority.
4828#ifdef KMP_GOMP_COMPAT
4829 kmp_setting_t * gomp_stacksize = __kmp_stg_find( "GOMP_STACKSIZE" ); // 2nd priority.
4830#endif
4831 kmp_setting_t * omp_stacksize = __kmp_stg_find( "OMP_STACKSIZE" ); // 3rd priority.
4832
4833 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4834 // !!! Compiler does not understand rivals is used and optimizes out assignments
4835 // !!! rivals[ i ++ ] = ...;
4836 static kmp_setting_t * volatile rivals[ 4 ];
4837 static kmp_stg_ss_data_t kmp_data = { 1, (kmp_setting_t **)rivals };
4838#ifdef KMP_GOMP_COMPAT
4839 static kmp_stg_ss_data_t gomp_data = { 1024, (kmp_setting_t **)rivals };
4840#endif
4841 static kmp_stg_ss_data_t omp_data = { 1024, (kmp_setting_t **)rivals };
4842 int i = 0;
4843
4844 rivals[ i ++ ] = kmp_stacksize;
4845#ifdef KMP_GOMP_COMPAT
4846 if ( gomp_stacksize != NULL ) {
4847 rivals[ i ++ ] = gomp_stacksize;
4848 }; // if
4849#endif
4850 rivals[ i ++ ] = omp_stacksize;
4851 rivals[ i ++ ] = NULL;
4852
4853 kmp_stacksize->data = & kmp_data;
4854#ifdef KMP_GOMP_COMPAT
4855 if ( gomp_stacksize != NULL ) {
4856 gomp_stacksize->data = & gomp_data;
4857 }; // if
4858#endif
4859 omp_stacksize->data = & omp_data;
4860
4861 }
4862
Jim Cownie5e8470a2013-09-27 10:38:44 +00004863 { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
4864
4865 kmp_setting_t * kmp_library = __kmp_stg_find( "KMP_LIBRARY" ); // 1st priority.
4866 kmp_setting_t * omp_wait_policy = __kmp_stg_find( "OMP_WAIT_POLICY" ); // 2nd priority.
4867
4868 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4869 static kmp_setting_t * volatile rivals[ 3 ];
4870 static kmp_stg_wp_data_t kmp_data = { 0, (kmp_setting_t **)rivals };
4871 static kmp_stg_wp_data_t omp_data = { 1, (kmp_setting_t **)rivals };
4872 int i = 0;
4873
4874 rivals[ i ++ ] = kmp_library;
4875 if ( omp_wait_policy != NULL ) {
4876 rivals[ i ++ ] = omp_wait_policy;
4877 }; // if
4878 rivals[ i ++ ] = NULL;
4879
4880 kmp_library->data = & kmp_data;
4881 if ( omp_wait_policy != NULL ) {
4882 omp_wait_policy->data = & omp_data;
4883 }; // if
4884
4885 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004886
4887 { // Initialize KMP_ALL_THREADS, KMP_MAX_THREADS, and OMP_THREAD_LIMIT data.
4888
4889 kmp_setting_t * kmp_all_threads = __kmp_stg_find( "KMP_ALL_THREADS" ); // 1st priority.
4890 kmp_setting_t * kmp_max_threads = __kmp_stg_find( "KMP_MAX_THREADS" ); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004891 kmp_setting_t * omp_thread_limit = __kmp_stg_find( "OMP_THREAD_LIMIT" ); // 3rd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004892
4893 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4894 static kmp_setting_t * volatile rivals[ 4 ];
4895 int i = 0;
4896
4897 rivals[ i ++ ] = kmp_all_threads;
4898 rivals[ i ++ ] = kmp_max_threads;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004899 if ( omp_thread_limit != NULL ) {
4900 rivals[ i ++ ] = omp_thread_limit;
4901 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004902 rivals[ i ++ ] = NULL;
4903
4904 kmp_all_threads->data = (void*)& rivals;
4905 kmp_max_threads->data = (void*)& rivals;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004906 if ( omp_thread_limit != NULL ) {
4907 omp_thread_limit->data = (void*)& rivals;
4908 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004909
4910 }
4911
Alp Toker98758b02014-03-02 04:12:06 +00004912#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004913 { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
4914
4915 kmp_setting_t * kmp_affinity = __kmp_stg_find( "KMP_AFFINITY" ); // 1st priority.
4916 KMP_DEBUG_ASSERT( kmp_affinity != NULL );
4917
4918# ifdef KMP_GOMP_COMPAT
4919 kmp_setting_t * gomp_cpu_affinity = __kmp_stg_find( "GOMP_CPU_AFFINITY" ); // 2nd priority.
4920 KMP_DEBUG_ASSERT( gomp_cpu_affinity != NULL );
4921# endif
4922
Jim Cownie5e8470a2013-09-27 10:38:44 +00004923 kmp_setting_t * omp_proc_bind = __kmp_stg_find( "OMP_PROC_BIND" ); // 3rd priority.
4924 KMP_DEBUG_ASSERT( omp_proc_bind != NULL );
Jim Cownie5e8470a2013-09-27 10:38:44 +00004925
4926 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004927 static kmp_setting_t * volatile rivals[ 4 ];
Jim Cownie5e8470a2013-09-27 10:38:44 +00004928 int i = 0;
4929
4930 rivals[ i ++ ] = kmp_affinity;
4931
4932# ifdef KMP_GOMP_COMPAT
4933 rivals[ i ++ ] = gomp_cpu_affinity;
4934 gomp_cpu_affinity->data = (void*)& rivals;
4935# endif
4936
Jim Cownie5e8470a2013-09-27 10:38:44 +00004937 rivals[ i ++ ] = omp_proc_bind;
4938 omp_proc_bind->data = (void*)& rivals;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004939 rivals[ i ++ ] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004940
4941# if OMP_40_ENABLED
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004942 static kmp_setting_t * volatile places_rivals[ 4 ];
4943 i = 0;
4944
4945 kmp_setting_t * omp_places = __kmp_stg_find( "OMP_PLACES" ); // 3rd priority.
4946 KMP_DEBUG_ASSERT( omp_places != NULL );
4947
4948 places_rivals[ i ++ ] = kmp_affinity;
4949# ifdef KMP_GOMP_COMPAT
4950 places_rivals[ i ++ ] = gomp_cpu_affinity;
4951# endif
4952 places_rivals[ i ++ ] = omp_places;
4953 omp_places->data = (void*)& places_rivals;
4954 places_rivals[ i ++ ] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004955# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004956 }
Alp Toker98758b02014-03-02 04:12:06 +00004957#else
Jim Cownie5e8470a2013-09-27 10:38:44 +00004958 // KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
4959 // OMP_PLACES not supported yet.
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004960#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004961
4962 { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
4963
4964 kmp_setting_t * kmp_force_red = __kmp_stg_find( "KMP_FORCE_REDUCTION" ); // 1st priority.
4965 kmp_setting_t * kmp_determ_red = __kmp_stg_find( "KMP_DETERMINISTIC_REDUCTION" ); // 2nd priority.
4966
4967 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4968 static kmp_setting_t * volatile rivals[ 3 ];
4969 static kmp_stg_fr_data_t force_data = { 1, (kmp_setting_t **)rivals };
4970 static kmp_stg_fr_data_t determ_data = { 0, (kmp_setting_t **)rivals };
4971 int i = 0;
4972
4973 rivals[ i ++ ] = kmp_force_red;
4974 if ( kmp_determ_red != NULL ) {
4975 rivals[ i ++ ] = kmp_determ_red;
4976 }; // if
4977 rivals[ i ++ ] = NULL;
4978
4979 kmp_force_red->data = & force_data;
4980 if ( kmp_determ_red != NULL ) {
4981 kmp_determ_red->data = & determ_data;
4982 }; // if
4983 }
4984
4985 initialized = 1;
4986
4987 }; // if
4988
4989 // Reset flags.
4990 int i;
4991 for ( i = 0; i < __kmp_stg_count; ++ i ) {
4992 __kmp_stg_table[ i ].set = 0;
4993 }; // for
4994
4995} // __kmp_stg_init
4996
4997
4998static void
4999__kmp_stg_parse(
5000 char const * name,
5001 char const * value
5002) {
5003
5004 // On Windows* OS there are some nameless variables like "C:=C:\" (yeah, really nameless, they are
5005 // presented in environment block as "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
5006 if ( name[ 0 ] == 0 ) {
5007 return;
5008 }; // if
5009
5010 if ( value != NULL ) {
5011 kmp_setting_t * setting = __kmp_stg_find( name );
5012 if ( setting != NULL ) {
5013 setting->parse( name, value, setting->data );
5014 setting->defined = 1;
5015 }; // if
5016 }; // if
5017
5018} // __kmp_stg_parse
5019
5020
5021static int
5022__kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
5023 char const * name, // Name of variable.
5024 char const * value, // Value of the variable.
5025 kmp_setting_t * * rivals // List of rival settings (the list must include current one).
5026) {
5027
5028 if ( rivals == NULL ) {
5029 return 0;
5030 }
5031
5032 // Loop thru higher priority settings (listed before current).
5033 int i = 0;
5034 for ( ; strcmp( rivals[ i ]->name, name ) != 0; i++ ) {
5035 KMP_DEBUG_ASSERT( rivals[ i ] != NULL );
5036
Alp Toker763b9392014-02-28 09:42:41 +00005037#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00005038 if ( rivals[ i ] == __kmp_affinity_notype ) {
5039 //
5040 // If KMP_AFFINITY is specified without a type name,
5041 // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
5042 //
5043 continue;
5044 }
5045#endif
5046
5047 if ( rivals[ i ]->set ) {
Andrey Churbanove8595de2015-02-20 18:19:41 +00005048 KMP_WARNING( StgIgnored, name, rivals[ i ]->name );
Jim Cownie5e8470a2013-09-27 10:38:44 +00005049 return 1;
5050 }; // if
5051 }; // while
5052
5053 ++ i; // Skip current setting.
5054 return 0;
5055
5056}; // __kmp_stg_check_rivals
5057
5058
Jim Cownie5e8470a2013-09-27 10:38:44 +00005059static int
5060__kmp_env_toPrint( char const * name, int flag ) {
5061 int rc = 0;
5062 kmp_setting_t * setting = __kmp_stg_find( name );
5063 if ( setting != NULL ) {
5064 rc = setting->defined;
5065 if ( flag >= 0 ) {
5066 setting->defined = flag;
5067 }; // if
5068 }; // if
5069 return rc;
5070}
5071
5072
5073static void
5074__kmp_aux_env_initialize( kmp_env_blk_t* block ) {
5075
5076 char const * value;
5077
5078 /* OMP_NUM_THREADS */
5079 value = __kmp_env_blk_var( block, "OMP_NUM_THREADS" );
5080 if ( value ) {
5081 ompc_set_num_threads( __kmp_dflt_team_nth );
5082 }
5083
5084 /* KMP_BLOCKTIME */
5085 value = __kmp_env_blk_var( block, "KMP_BLOCKTIME" );
5086 if ( value ) {
5087 kmpc_set_blocktime( __kmp_dflt_blocktime );
5088 }
5089
5090 /* OMP_NESTED */
5091 value = __kmp_env_blk_var( block, "OMP_NESTED" );
5092 if ( value ) {
5093 ompc_set_nested( __kmp_dflt_nested );
5094 }
5095
5096 /* OMP_DYNAMIC */
5097 value = __kmp_env_blk_var( block, "OMP_DYNAMIC" );
5098 if ( value ) {
5099 ompc_set_dynamic( __kmp_global.g.g_dynamic );
5100 }
5101
5102}
5103
5104void
5105__kmp_env_initialize( char const * string ) {
5106
5107 kmp_env_blk_t block;
5108 int i;
5109
5110 __kmp_stg_init();
5111
5112 // Hack!!!
5113 if ( string == NULL ) {
5114 // __kmp_max_nth = __kmp_sys_max_nth;
5115 __kmp_threads_capacity = __kmp_initial_threads_capacity( __kmp_dflt_team_nth_ub );
5116 }; // if
5117 __kmp_env_blk_init( & block, string );
5118
5119 //
5120 // update the set flag on all entries that have an env var
5121 //
5122 for ( i = 0; i < block.count; ++ i ) {
5123 if (( block.vars[ i ].name == NULL )
5124 || ( *block.vars[ i ].name == '\0')) {
5125 continue;
5126 }
5127 if ( block.vars[ i ].value == NULL ) {
5128 continue;
5129 }
5130 kmp_setting_t * setting = __kmp_stg_find( block.vars[ i ].name );
5131 if ( setting != NULL ) {
5132 setting->set = 1;
5133 }
5134 }; // for i
5135
Jonathan Peyton50e8f182016-04-04 19:38:32 +00005136 // We need to know if blocktime was set when processing OMP_WAIT_POLICY
5137 blocktime_str = __kmp_env_blk_var( & block, "KMP_BLOCKTIME" );
5138
Jim Cownie5e8470a2013-09-27 10:38:44 +00005139 // Special case. If we parse environment, not a string, process KMP_WARNINGS first.
5140 if ( string == NULL ) {
5141 char const * name = "KMP_WARNINGS";
5142 char const * value = __kmp_env_blk_var( & block, name );
5143 __kmp_stg_parse( name, value );
5144 }; // if
5145
Alp Toker763b9392014-02-28 09:42:41 +00005146#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00005147 //
5148 // Special case. KMP_AFFINITY is not a rival to other affinity env vars
5149 // if no affinity type is specified. We want to allow
5150 // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
5151 // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
5152 // affinity mechanism.
5153 //
5154 __kmp_affinity_notype = NULL;
5155 char const *aff_str = __kmp_env_blk_var( & block, "KMP_AFFINITY" );
5156 if ( aff_str != NULL ) {
5157 //
5158 // Check if the KMP_AFFINITY type is specified in the string.
5159 // We just search the string for "compact", "scatter", etc.
5160 // without really parsing the string. The syntax of the
5161 // KMP_AFFINITY env var is such that none of the affinity
5162 // type names can appear anywhere other that the type
5163 // specifier, even as substrings.
5164 //
5165 // I can't find a case-insensitive version of strstr on Windows* OS.
5166 // Use the case-sensitive version for now.
5167 //
5168
5169# if KMP_OS_WINDOWS
5170# define FIND strstr
5171# else
5172# define FIND strcasestr
5173# endif
5174
5175 if ( ( FIND( aff_str, "none" ) == NULL )
5176 && ( FIND( aff_str, "physical" ) == NULL )
5177 && ( FIND( aff_str, "logical" ) == NULL )
5178 && ( FIND( aff_str, "compact" ) == NULL )
5179 && ( FIND( aff_str, "scatter" ) == NULL )
5180 && ( FIND( aff_str, "explicit" ) == NULL )
Jim Cownie5e8470a2013-09-27 10:38:44 +00005181 && ( FIND( aff_str, "balanced" ) == NULL )
Jim Cownie5e8470a2013-09-27 10:38:44 +00005182 && ( FIND( aff_str, "disabled" ) == NULL ) ) {
5183 __kmp_affinity_notype = __kmp_stg_find( "KMP_AFFINITY" );
5184 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005185 else {
5186 //
5187 // A new affinity type is specified.
5188 // Reset the affinity flags to their default values,
5189 // in case this is called from kmp_set_defaults().
5190 //
5191 __kmp_affinity_type = affinity_default;
5192 __kmp_affinity_gran = affinity_gran_default;
5193 __kmp_affinity_top_method = affinity_top_method_default;
5194 __kmp_affinity_respect_mask = affinity_respect_mask_default;
5195 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005196# undef FIND
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005197
5198#if OMP_40_ENABLED
5199 //
5200 // Also reset the affinity flags if OMP_PROC_BIND is specified.
5201 //
5202 aff_str = __kmp_env_blk_var( & block, "OMP_PROC_BIND" );
5203 if ( aff_str != NULL ) {
5204 __kmp_affinity_type = affinity_default;
5205 __kmp_affinity_gran = affinity_gran_default;
5206 __kmp_affinity_top_method = affinity_top_method_default;
5207 __kmp_affinity_respect_mask = affinity_respect_mask_default;
5208 }
5209#endif /* OMP_40_ENABLED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005210 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005211
Alp Toker763b9392014-02-28 09:42:41 +00005212#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005213
5214#if OMP_40_ENABLED
5215 //
5216 // Set up the nested proc bind type vector.
5217 //
5218 if ( __kmp_nested_proc_bind.bind_types == NULL ) {
5219 __kmp_nested_proc_bind.bind_types = (kmp_proc_bind_t *)
5220 KMP_INTERNAL_MALLOC( sizeof(kmp_proc_bind_t) );
5221 if ( __kmp_nested_proc_bind.bind_types == NULL ) {
5222 KMP_FATAL( MemoryAllocFailed );
5223 }
5224 __kmp_nested_proc_bind.size = 1;
5225 __kmp_nested_proc_bind.used = 1;
Andrey Churbanov78bfb7c2015-01-29 15:52:20 +00005226# if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00005227 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
Andrey Churbanov78bfb7c2015-01-29 15:52:20 +00005228# else
5229 // default proc bind is false if affinity not supported
5230 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5231# endif
5232
Jim Cownie5e8470a2013-09-27 10:38:44 +00005233 }
5234#endif /* OMP_40_ENABLED */
5235
5236 //
5237 // Now process all of the settings.
5238 //
5239 for ( i = 0; i < block.count; ++ i ) {
5240 __kmp_stg_parse( block.vars[ i ].name, block.vars[ i ].value );
5241 }; // for i
5242
5243 //
5244 // If user locks have been allocated yet, don't reset the lock vptr table.
5245 //
5246 if ( ! __kmp_init_user_locks ) {
5247 if ( __kmp_user_lock_kind == lk_default ) {
5248 __kmp_user_lock_kind = lk_queuing;
5249 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005250#if KMP_USE_DYNAMIC_LOCK
5251 __kmp_init_dynamic_user_locks();
5252#else
Jim Cownie5e8470a2013-09-27 10:38:44 +00005253 __kmp_set_user_lock_vptrs( __kmp_user_lock_kind );
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005254#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00005255 }
5256 else {
5257 KMP_DEBUG_ASSERT( string != NULL); // kmp_set_defaults() was called
5258 KMP_DEBUG_ASSERT( __kmp_user_lock_kind != lk_default );
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005259 // Binds lock functions again to follow the transition between different
5260 // KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
5261 // as we do not allow lock kind changes after making a call to any
5262 // user lock functions (true).
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005263#if KMP_USE_DYNAMIC_LOCK
5264 __kmp_init_dynamic_user_locks();
5265#else
5266 __kmp_set_user_lock_vptrs( __kmp_user_lock_kind );
5267#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00005268 }
5269
Alp Toker763b9392014-02-28 09:42:41 +00005270#if KMP_AFFINITY_SUPPORTED
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005271
Jim Cownie5e8470a2013-09-27 10:38:44 +00005272 if ( ! TCR_4(__kmp_init_middle) ) {
5273 //
5274 // Determine if the machine/OS is actually capable of supporting
5275 // affinity.
5276 //
5277 const char *var = "KMP_AFFINITY";
Jonathan Peyton01dcf362015-11-30 20:02:59 +00005278# if KMP_USE_HWLOC
5279 if(hwloc_topology_init(&__kmp_hwloc_topology) < 0) {
5280 __kmp_hwloc_error = TRUE;
5281 if(__kmp_affinity_verbose)
5282 KMP_WARNING(AffHwlocErrorOccurred, var, "hwloc_topology_init()");
5283 }
Paul Osmialowski97ae10c2016-05-13 17:45:49 +00005284# if HWLOC_API_VERSION >= 0x00020000
Paul Osmialowski562a3c22016-05-12 11:46:40 +00005285 // new hwloc API
5286 hwloc_topology_set_type_filter(__kmp_hwloc_topology, HWLOC_OBJ_L1CACHE, HWLOC_TYPE_FILTER_KEEP_NONE);
5287 hwloc_topology_set_type_filter(__kmp_hwloc_topology, HWLOC_OBJ_L2CACHE, HWLOC_TYPE_FILTER_KEEP_NONE);
5288 hwloc_topology_set_type_filter(__kmp_hwloc_topology, HWLOC_OBJ_L3CACHE, HWLOC_TYPE_FILTER_KEEP_NONE);
5289 hwloc_topology_set_type_filter(__kmp_hwloc_topology, HWLOC_OBJ_L4CACHE, HWLOC_TYPE_FILTER_KEEP_NONE);
5290 hwloc_topology_set_type_filter(__kmp_hwloc_topology, HWLOC_OBJ_L5CACHE, HWLOC_TYPE_FILTER_KEEP_NONE);
5291 hwloc_topology_set_type_filter(__kmp_hwloc_topology, HWLOC_OBJ_L1ICACHE, HWLOC_TYPE_FILTER_KEEP_NONE);
5292 hwloc_topology_set_type_filter(__kmp_hwloc_topology, HWLOC_OBJ_L2ICACHE, HWLOC_TYPE_FILTER_KEEP_NONE);
5293 hwloc_topology_set_type_filter(__kmp_hwloc_topology, HWLOC_OBJ_L3ICACHE, HWLOC_TYPE_FILTER_KEEP_NONE);
Paul Osmialowski97ae10c2016-05-13 17:45:49 +00005294# else
Paul Osmialowski562a3c22016-05-12 11:46:40 +00005295 // old hwloc API
Jonathan Peyton01dcf362015-11-30 20:02:59 +00005296 hwloc_topology_ignore_type(__kmp_hwloc_topology, HWLOC_OBJ_CACHE);
Paul Osmialowski97ae10c2016-05-13 17:45:49 +00005297# endif
Paul Osmialowski562a3c22016-05-12 11:46:40 +00005298# endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00005299 if ( __kmp_affinity_type == affinity_disabled ) {
Andrey Churbanov1f037e42015-03-10 09:15:26 +00005300 KMP_AFFINITY_DISABLE();
Jim Cownie5e8470a2013-09-27 10:38:44 +00005301 }
5302 else if ( ! KMP_AFFINITY_CAPABLE() ) {
Jonathan Peyton01dcf362015-11-30 20:02:59 +00005303# if KMP_USE_HWLOC
5304 const hwloc_topology_support* topology_support = hwloc_topology_get_support(__kmp_hwloc_topology);
5305 if(hwloc_topology_load(__kmp_hwloc_topology) < 0) {
5306 __kmp_hwloc_error = TRUE;
5307 if(__kmp_affinity_verbose)
5308 KMP_WARNING(AffHwlocErrorOccurred, var, "hwloc_topology_load()");
5309 }
5310 // Is the system capable of setting/getting this thread's affinity?
5311 // also, is topology discovery possible? (pu indicates ability to discover processing units)
5312 // and finally, were there no errors when calling any hwloc_* API functions?
5313 if(topology_support->cpubind->set_thisthread_cpubind &&
5314 topology_support->cpubind->get_thisthread_cpubind &&
5315 topology_support->discovery->pu &&
5316 !__kmp_hwloc_error)
5317 {
5318 // enables affinity according to KMP_AFFINITY_CAPABLE() macro
5319 KMP_AFFINITY_ENABLE(TRUE);
5320 } else {
5321 // indicate that hwloc didn't work and disable affinity
5322 __kmp_hwloc_error = TRUE;
5323 KMP_AFFINITY_DISABLE();
5324 }
5325# else
Jim Cownie5e8470a2013-09-27 10:38:44 +00005326 __kmp_affinity_determine_capable( var );
Jonathan Peyton01dcf362015-11-30 20:02:59 +00005327# endif // KMP_USE_HWLOC
Jim Cownie5e8470a2013-09-27 10:38:44 +00005328 if ( ! KMP_AFFINITY_CAPABLE() ) {
5329 if ( __kmp_affinity_verbose || ( __kmp_affinity_warnings
5330 && ( __kmp_affinity_type != affinity_default )
5331 && ( __kmp_affinity_type != affinity_none )
5332 && ( __kmp_affinity_type != affinity_disabled ) ) ) {
5333 KMP_WARNING( AffNotSupported, var );
5334 }
5335 __kmp_affinity_type = affinity_disabled;
5336 __kmp_affinity_respect_mask = 0;
5337 __kmp_affinity_gran = affinity_gran_fine;
5338 }
5339 }
5340
5341# if OMP_40_ENABLED
Jim Cownie5e8470a2013-09-27 10:38:44 +00005342 if ( __kmp_affinity_type == affinity_disabled ) {
Andrey Churbanov94e569e2015-03-10 09:19:47 +00005343 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005344 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005345 else if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_true ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005346 //
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005347 // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
Jim Cownie5e8470a2013-09-27 10:38:44 +00005348 //
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005349 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005350 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005351# endif /* OMP_40_ENABLED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005352
5353 if ( KMP_AFFINITY_CAPABLE() ) {
5354
Andrey Churbanov7daf9802015-01-27 16:52:57 +00005355# if KMP_GROUP_AFFINITY
Jim Cownie5e8470a2013-09-27 10:38:44 +00005356
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005357 //
5358 // Handle the Win 64 group affinity stuff if there are multiple
5359 // processor groups, or if the user requested it, and OMP 4.0
5360 // affinity is not in effect.
5361 //
5362 if ( ( ( __kmp_num_proc_groups > 1 )
5363 && ( __kmp_affinity_type == affinity_default )
5364# if OMP_40_ENABLED
5365 && ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) )
5366# endif
5367 || ( __kmp_affinity_top_method == affinity_top_method_group ) ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005368 if ( __kmp_affinity_respect_mask == affinity_respect_mask_default ) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005369 __kmp_affinity_respect_mask = FALSE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005370 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005371 if ( __kmp_affinity_type == affinity_default ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005372 __kmp_affinity_type = affinity_compact;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005373# if OMP_40_ENABLED
5374 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5375# endif
5376 }
5377 if ( __kmp_affinity_top_method == affinity_top_method_default ) {
5378 if ( __kmp_affinity_gran == affinity_gran_default ) {
5379 __kmp_affinity_top_method = affinity_top_method_group;
5380 __kmp_affinity_gran = affinity_gran_group;
5381 }
5382 else if ( __kmp_affinity_gran == affinity_gran_group ) {
5383 __kmp_affinity_top_method = affinity_top_method_group;
5384 }
5385 else {
5386 __kmp_affinity_top_method = affinity_top_method_all;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005387 }
5388 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005389 else if ( __kmp_affinity_top_method == affinity_top_method_group ) {
5390 if ( __kmp_affinity_gran == affinity_gran_default ) {
5391 __kmp_affinity_gran = affinity_gran_group;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005392 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005393 else if ( ( __kmp_affinity_gran != affinity_gran_group )
5394 && ( __kmp_affinity_gran != affinity_gran_fine )
5395 && ( __kmp_affinity_gran != affinity_gran_thread ) ) {
Ismail Donmezc9655d92016-01-26 08:24:57 +00005396 const char *str = NULL;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005397 switch ( __kmp_affinity_gran ) {
5398 case affinity_gran_core: str = "core"; break;
5399 case affinity_gran_package: str = "package"; break;
5400 case affinity_gran_node: str = "node"; break;
5401 default: KMP_DEBUG_ASSERT( 0 );
5402 }
5403 KMP_WARNING( AffGranTopGroup, var, str );
5404 __kmp_affinity_gran = affinity_gran_fine;
5405 }
5406 }
5407 else {
5408 if ( __kmp_affinity_gran == affinity_gran_default ) {
5409 __kmp_affinity_gran = affinity_gran_core;
5410 }
5411 else if ( __kmp_affinity_gran == affinity_gran_group ) {
Ismail Donmezc9655d92016-01-26 08:24:57 +00005412 const char *str = NULL;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005413 switch ( __kmp_affinity_type ) {
5414 case affinity_physical: str = "physical"; break;
5415 case affinity_logical: str = "logical"; break;
5416 case affinity_compact: str = "compact"; break;
5417 case affinity_scatter: str = "scatter"; break;
5418 case affinity_explicit: str = "explicit"; break;
5419 // No MIC on windows, so no affinity_balanced case
5420 default: KMP_DEBUG_ASSERT( 0 );
5421 }
5422 KMP_WARNING( AffGranGroupType, var, str );
Jim Cownie5e8470a2013-09-27 10:38:44 +00005423 __kmp_affinity_gran = affinity_gran_core;
5424 }
5425 }
5426 }
5427 else
5428
Andrey Churbanov7daf9802015-01-27 16:52:57 +00005429# endif /* KMP_GROUP_AFFINITY */
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005430
Jim Cownie5e8470a2013-09-27 10:38:44 +00005431 {
5432 if ( __kmp_affinity_respect_mask == affinity_respect_mask_default ) {
Andrey Churbanov7daf9802015-01-27 16:52:57 +00005433# if KMP_GROUP_AFFINITY
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005434 if ( __kmp_num_proc_groups > 1 ) {
5435 __kmp_affinity_respect_mask = FALSE;
5436 }
5437 else
Andrey Churbanov7daf9802015-01-27 16:52:57 +00005438# endif /* KMP_GROUP_AFFINITY */
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005439 {
5440 __kmp_affinity_respect_mask = TRUE;
5441 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005442 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005443# if OMP_40_ENABLED
5444 if ( ( __kmp_nested_proc_bind.bind_types[0] != proc_bind_intel )
5445 && ( __kmp_nested_proc_bind.bind_types[0] != proc_bind_default ) ) {
5446 if ( __kmp_affinity_type == affinity_default ) {
5447 __kmp_affinity_type = affinity_compact;
5448 __kmp_affinity_dups = FALSE;
5449 }
5450 }
5451 else
5452# endif /* OMP_40_ENABLED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005453 if ( __kmp_affinity_type == affinity_default ) {
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005454#if OMP_40_ENABLED
5455#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
5456 if( __kmp_mic_type != non_mic ) {
5457 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5458 } else
5459#endif
5460 {
5461 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5462 }
5463#endif /* OMP_40_ENABLED */
5464#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
5465 if( __kmp_mic_type != non_mic ) {
5466 __kmp_affinity_type = affinity_scatter;
5467 } else
5468#endif
5469 {
5470 __kmp_affinity_type = affinity_none;
5471 }
5472
Jim Cownie5e8470a2013-09-27 10:38:44 +00005473 }
5474 if ( ( __kmp_affinity_gran == affinity_gran_default )
5475 && ( __kmp_affinity_gran_levels < 0 ) ) {
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005476#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
5477 if( __kmp_mic_type != non_mic ) {
5478 __kmp_affinity_gran = affinity_gran_fine;
5479 } else
5480#endif
5481 {
5482 __kmp_affinity_gran = affinity_gran_core;
5483 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005484 }
5485 if ( __kmp_affinity_top_method == affinity_top_method_default ) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005486 __kmp_affinity_top_method = affinity_top_method_all;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005487 }
5488 }
5489 }
5490
5491 K_DIAG( 1, ( "__kmp_affinity_type == %d\n", __kmp_affinity_type ) );
5492 K_DIAG( 1, ( "__kmp_affinity_compact == %d\n", __kmp_affinity_compact ) );
5493 K_DIAG( 1, ( "__kmp_affinity_offset == %d\n", __kmp_affinity_offset ) );
5494 K_DIAG( 1, ( "__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose ) );
5495 K_DIAG( 1, ( "__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings ) );
5496 K_DIAG( 1, ( "__kmp_affinity_respect_mask == %d\n", __kmp_affinity_respect_mask ) );
5497 K_DIAG( 1, ( "__kmp_affinity_gran == %d\n", __kmp_affinity_gran ) );
5498
5499 KMP_DEBUG_ASSERT( __kmp_affinity_type != affinity_default);
5500# if OMP_40_ENABLED
Andrey Churbanov7a3467a2015-01-27 17:06:18 +00005501 KMP_DEBUG_ASSERT( __kmp_nested_proc_bind.bind_types[0] != proc_bind_default );
Jim Cownie5e8470a2013-09-27 10:38:44 +00005502# endif
5503 }
5504
Alp Toker763b9392014-02-28 09:42:41 +00005505#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005506
5507 if ( __kmp_version ) {
5508 __kmp_print_version_1();
5509 }; // if
5510
5511 // Post-initialization step: some env. vars need their value's further processing
5512 if ( string != NULL) { // kmp_set_defaults() was called
5513 __kmp_aux_env_initialize( &block );
5514 }
5515
5516 __kmp_env_blk_free( & block );
5517
5518 KMP_MB();
5519
5520} // __kmp_env_initialize
5521
5522
5523void
5524__kmp_env_print() {
5525
5526 kmp_env_blk_t block;
5527 int i;
5528 kmp_str_buf_t buffer;
5529
5530 __kmp_stg_init();
5531 __kmp_str_buf_init( & buffer );
5532
5533 __kmp_env_blk_init( & block, NULL );
5534 __kmp_env_blk_sort( & block );
5535
5536 // Print real environment values.
5537 __kmp_str_buf_print( & buffer, "\n%s\n\n", KMP_I18N_STR( UserSettings ) );
5538 for ( i = 0; i < block.count; ++ i ) {
5539 char const * name = block.vars[ i ].name;
5540 char const * value = block.vars[ i ].value;
5541 if (
Andrey Churbanov74bf17b2015-04-02 13:27:08 +00005542 ( KMP_STRLEN( name ) > 4 && strncmp( name, "KMP_", 4 ) == 0 )
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005543 || strncmp( name, "OMP_", 4 ) == 0
Jim Cownie5e8470a2013-09-27 10:38:44 +00005544 #ifdef KMP_GOMP_COMPAT
5545 || strncmp( name, "GOMP_", 5 ) == 0
5546 #endif // KMP_GOMP_COMPAT
5547 ) {
5548 __kmp_str_buf_print( & buffer, " %s=%s\n", name, value );
5549 }; // if
5550 }; // for
5551 __kmp_str_buf_print( & buffer, "\n" );
5552
5553 // Print internal (effective) settings.
5554 __kmp_str_buf_print( & buffer, "%s\n\n", KMP_I18N_STR( EffectiveSettings ) );
5555 for ( int i = 0; i < __kmp_stg_count; ++ i ) {
5556 if ( __kmp_stg_table[ i ].print != NULL ) {
5557 __kmp_stg_table[ i ].print( & buffer, __kmp_stg_table[ i ].name, __kmp_stg_table[ i ].data );
5558 }; // if
5559 }; // for
5560
5561 __kmp_printf( "%s", buffer.str );
5562
5563 __kmp_env_blk_free( & block );
5564 __kmp_str_buf_free( & buffer );
5565
5566 __kmp_printf("\n");
5567
5568} // __kmp_env_print
5569
5570
5571#if OMP_40_ENABLED
5572void
5573__kmp_env_print_2() {
5574
5575 kmp_env_blk_t block;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005576 kmp_str_buf_t buffer;
5577
5578 __kmp_env_format = 1;
5579
5580 __kmp_stg_init();
5581 __kmp_str_buf_init( & buffer );
5582
5583 __kmp_env_blk_init( & block, NULL );
5584 __kmp_env_blk_sort( & block );
5585
5586 __kmp_str_buf_print( & buffer, "\n%s\n", KMP_I18N_STR( DisplayEnvBegin ) );
5587 __kmp_str_buf_print( & buffer, " _OPENMP='%d'\n", __kmp_openmp_version );
5588
5589 for ( int i = 0; i < __kmp_stg_count; ++ i ) {
5590 if ( __kmp_stg_table[ i ].print != NULL &&
5591 ( ( __kmp_display_env && strncmp( __kmp_stg_table[ i ].name, "OMP_", 4 ) == 0 ) || __kmp_display_env_verbose ) ) {
5592 __kmp_stg_table[ i ].print( & buffer, __kmp_stg_table[ i ].name, __kmp_stg_table[ i ].data );
5593 }; // if
5594 }; // for
5595
5596 __kmp_str_buf_print( & buffer, "%s\n", KMP_I18N_STR( DisplayEnvEnd ) );
5597 __kmp_str_buf_print( & buffer, "\n" );
5598
5599 __kmp_printf( "%s", buffer.str );
5600
5601 __kmp_env_blk_free( & block );
5602 __kmp_str_buf_free( & buffer );
5603
5604 __kmp_printf("\n");
5605
5606} // __kmp_env_print_2
5607#endif // OMP_40_ENABLED
5608
Jim Cownie5e8470a2013-09-27 10:38:44 +00005609// end of file
5610