LLVM OpenMP* Runtime Library
kmp_settings.c
1 /*
2  * kmp_settings.c -- Initialize environment variables
3  */
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"
24 #include "kmp_lock.h"
25 #include "kmp_io.h"
26 
27 static int __kmp_env_toPrint( char const * name, int flag );
28 
29 bool __kmp_env_format = 0; // 0 - old format; 1 - new format
30 // -------------------------------------------------------------------------------------------------
31 // Helper string functions. Subject to move to kmp_str.
32 // -------------------------------------------------------------------------------------------------
33 
34 static double
35 __kmp_convert_to_double( char const * s )
36 {
37  double result;
38 
39  if ( KMP_SSCANF( s, "%lf", &result ) < 1 ) {
40  result = 0.0;
41  }
42 
43  return result;
44 }
45 
46 #ifdef KMP_DEBUG
47 static 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 }
59 #endif
60 
61 static 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 
111 static 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 
137 
138 static 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 
151 /*
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
155  matches "infinit*". Returns -1 if specified string is invalid.
156 */
157 int
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);
165  if ( __kmp_str_match( "infinit", -1, data)) return (INT_MAX);
166  value = (double) 0.0;
167  mult = '\0';
168  nvalues = KMP_SSCANF (data, "%lf%c%c", &value, &mult, &extra);
169  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 
204 
205 static 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 
233 typedef struct __kmp_setting kmp_setting_t;
234 typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
235 typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
236 typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
237 
238 typedef void ( * kmp_stg_parse_func_t )( char const * name, char const * value, void * data );
239 typedef void ( * kmp_stg_print_func_t )( kmp_str_buf_t * buffer, char const * name, void * data );
240 
241 struct __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 
251 struct __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 
256 struct __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 
261 struct __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 
266 static 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 
278 static 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 
298 static 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 {
335  // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to size_max silently.
336  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 
355 #if KMP_AFFINITY_SUPPORTED
356 static 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
365 #endif
366 
367 static 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 {
387  // If overflow occurred msg contains error message and uint is very big. Cut tmp it
388  // 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 
409 #if KMP_DEBUG_ADAPTIVE_LOCKS
410 static 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
428 #endif
429 
430 #ifdef KMP_DEBUG
431 static char * par_range_to_print = NULL;
432 
433 static 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 ) {
443  size_t len = KMP_STRLEN( value + 1 );
444  par_range_to_print = (char *) KMP_INTERNAL_MALLOC( len +1 );
445  KMP_STRNCPY_S( par_range_to_print, len + 1, value, len + 1);
446  __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;
483  if ( KMP_SSCANF( value, "%d:%d", out_lb, out_ub ) != 2 ) {
484  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;
495  if ( KMP_SSCANF( value, "%d:%d", out_lb, out_ub) != 2 ) {
496  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
511 #endif
512 
513 int
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 
531 int
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 
554 static 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 
563 static 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 
572 static 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 
581 static 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 
590 static 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 
613 static 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 
633 static 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 
642 static 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 
671 static 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 
680 static 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 
687 static 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 
698 static 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 
703 static 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 
716 static char const *blocktime_str = NULL;
717 
718 static 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 ) ) {
731  __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  }
736  } else if ( __kmp_str_match( "PASSIVE", 1, value ) ) {
737  __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  }
742  } 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 
764 static 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 
802 static 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 
815 static 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 
840 static 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 
845 static 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 // -------------------------------------------------------------------------------------------------
851 // KMP_STACKPAD
852 // -------------------------------------------------------------------------------------------------
853 
854 static 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 
865 static 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 // -------------------------------------------------------------------------------------------------
871 // KMP_STACKOFFSET
872 // -------------------------------------------------------------------------------------------------
873 
874 static 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 
887 static 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 
896 static 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.
921 static 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 
939 static 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 
944 static 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 
953 static 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 
961 static 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 
970 static 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 
975 static 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 
980 static 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 
1108 static 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 
1128 static 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 
1155 static 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 
1160 static 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 
1165 static 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 
1170 static 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 
1175 static void
1176 __kmp_stg_parse_max_active_levels( char const * name, char const * value, void * data ) {
1177  __kmp_stg_parse_int( name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT, & __kmp_dflt_max_active_levels );
1178 } // __kmp_stg_parse_max_active_levels
1179 
1180 static 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
1184 
1185 #if OMP_45_ENABLED
1186 // -------------------------------------------------------------------------------------------------
1187 // OpenMP 4.5: OMP_MAX_TASK_PRIORITY
1188 // -------------------------------------------------------------------------------------------------
1189 static 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 
1194 static 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_45_ENABLED
1199 
1200 // -------------------------------------------------------------------------------------------------
1201 // KMP_DISP_NUM_BUFFERS
1202 // -------------------------------------------------------------------------------------------------
1203 static void
1204 __kmp_stg_parse_disp_buffers( char const * name, char const * value, void * data ) {
1205  if ( TCR_4(__kmp_init_serial) ) {
1206  KMP_WARNING( EnvSerialWarn, name );
1207  return;
1208  } // read value before serial initialization only
1209  __kmp_stg_parse_int( name, value, 1, KMP_MAX_NTH, & __kmp_dispatch_num_buffers );
1210 } // __kmp_stg_parse_disp_buffers
1211 
1212 static void
1213 __kmp_stg_print_disp_buffers( kmp_str_buf_t * buffer, char const * name, void * data ) {
1214  __kmp_stg_print_int( buffer, name, __kmp_dispatch_num_buffers );
1215 } // __kmp_stg_print_disp_buffers
1216 
1217 #if KMP_NESTED_HOT_TEAMS
1218 // -------------------------------------------------------------------------------------------------
1219 // KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
1220 // -------------------------------------------------------------------------------------------------
1221 
1222 static void
1223 __kmp_stg_parse_hot_teams_level( char const * name, char const * value, void * data ) {
1224  if ( TCR_4(__kmp_init_parallel) ) {
1225  KMP_WARNING( EnvParallelWarn, name );
1226  return;
1227  } // read value before first parallel only
1228  __kmp_stg_parse_int( name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT, & __kmp_hot_teams_max_level );
1229 } // __kmp_stg_parse_hot_teams_level
1230 
1231 static void
1232 __kmp_stg_print_hot_teams_level( kmp_str_buf_t * buffer, char const * name, void * data ) {
1233  __kmp_stg_print_int( buffer, name, __kmp_hot_teams_max_level );
1234 } // __kmp_stg_print_hot_teams_level
1235 
1236 static void
1237 __kmp_stg_parse_hot_teams_mode( char const * name, char const * value, void * data ) {
1238  if ( TCR_4(__kmp_init_parallel) ) {
1239  KMP_WARNING( EnvParallelWarn, name );
1240  return;
1241  } // read value before first parallel only
1242  __kmp_stg_parse_int( name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT, & __kmp_hot_teams_mode );
1243 } // __kmp_stg_parse_hot_teams_mode
1244 
1245 static void
1246 __kmp_stg_print_hot_teams_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
1247  __kmp_stg_print_int( buffer, name, __kmp_hot_teams_mode );
1248 } // __kmp_stg_print_hot_teams_mode
1249 
1250 #endif // KMP_NESTED_HOT_TEAMS
1251 
1252 // -------------------------------------------------------------------------------------------------
1253 // KMP_HANDLE_SIGNALS
1254 // -------------------------------------------------------------------------------------------------
1255 
1256 #if KMP_HANDLE_SIGNALS
1257 
1258 static void
1259 __kmp_stg_parse_handle_signals( char const * name, char const * value, void * data ) {
1260  __kmp_stg_parse_bool( name, value, & __kmp_handle_signals );
1261 } // __kmp_stg_parse_handle_signals
1262 
1263 static void
1264 __kmp_stg_print_handle_signals( kmp_str_buf_t * buffer, char const * name, void * data ) {
1265  __kmp_stg_print_bool( buffer, name, __kmp_handle_signals );
1266 } // __kmp_stg_print_handle_signals
1267 
1268 #endif // KMP_HANDLE_SIGNALS
1269 
1270 // -------------------------------------------------------------------------------------------------
1271 // KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
1272 // -------------------------------------------------------------------------------------------------
1273 
1274 #ifdef KMP_DEBUG
1275 
1276 #define KMP_STG_X_DEBUG( x ) \
1277  static void __kmp_stg_parse_##x##_debug( char const * name, char const * value, void * data ) { \
1278  __kmp_stg_parse_int( name, value, 0, INT_MAX, & kmp_##x##_debug ); \
1279  } /* __kmp_stg_parse_x_debug */ \
1280  static void __kmp_stg_print_##x##_debug( kmp_str_buf_t * buffer, char const * name, void * data ) { \
1281  __kmp_stg_print_int( buffer, name, kmp_##x##_debug ); \
1282  } /* __kmp_stg_print_x_debug */
1283 
1284 KMP_STG_X_DEBUG( a )
1285 KMP_STG_X_DEBUG( b )
1286 KMP_STG_X_DEBUG( c )
1287 KMP_STG_X_DEBUG( d )
1288 KMP_STG_X_DEBUG( e )
1289 KMP_STG_X_DEBUG( f )
1290 
1291 #undef KMP_STG_X_DEBUG
1292 
1293 static void
1294 __kmp_stg_parse_debug( char const * name, char const * value, void * data ) {
1295  int debug = 0;
1296  __kmp_stg_parse_int( name, value, 0, INT_MAX, & debug );
1297  if ( kmp_a_debug < debug ) {
1298  kmp_a_debug = debug;
1299  }; // if
1300  if ( kmp_b_debug < debug ) {
1301  kmp_b_debug = debug;
1302  }; // if
1303  if ( kmp_c_debug < debug ) {
1304  kmp_c_debug = debug;
1305  }; // if
1306  if ( kmp_d_debug < debug ) {
1307  kmp_d_debug = debug;
1308  }; // if
1309  if ( kmp_e_debug < debug ) {
1310  kmp_e_debug = debug;
1311  }; // if
1312  if ( kmp_f_debug < debug ) {
1313  kmp_f_debug = debug;
1314  }; // if
1315 } // __kmp_stg_parse_debug
1316 
1317 static void
1318 __kmp_stg_parse_debug_buf( char const * name, char const * value, void * data ) {
1319  __kmp_stg_parse_bool( name, value, & __kmp_debug_buf );
1320  // !!! TODO: Move buffer initialization of of this file! It may works incorrectly if
1321  // KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or KMP_DEBUG_BUF_CHARS.
1322  if ( __kmp_debug_buf ) {
1323  int i;
1324  int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
1325 
1326  /* allocate and initialize all entries in debug buffer to empty */
1327  __kmp_debug_buffer = (char *) __kmp_page_allocate( elements * sizeof( char ) );
1328  for ( i = 0; i < elements; i += __kmp_debug_buf_chars )
1329  __kmp_debug_buffer[i] = '\0';
1330 
1331  __kmp_debug_count = 0;
1332  }
1333  K_DIAG( 1, ( "__kmp_debug_buf = %d\n", __kmp_debug_buf ) );
1334 } // __kmp_stg_parse_debug_buf
1335 
1336 static void
1337 __kmp_stg_print_debug_buf( kmp_str_buf_t * buffer, char const * name, void * data ) {
1338  __kmp_stg_print_bool( buffer, name, __kmp_debug_buf );
1339 } // __kmp_stg_print_debug_buf
1340 
1341 static void
1342 __kmp_stg_parse_debug_buf_atomic( char const * name, char const * value, void * data ) {
1343  __kmp_stg_parse_bool( name, value, & __kmp_debug_buf_atomic );
1344 } // __kmp_stg_parse_debug_buf_atomic
1345 
1346 static void
1347 __kmp_stg_print_debug_buf_atomic( kmp_str_buf_t * buffer, char const * name, void * data ) {
1348  __kmp_stg_print_bool( buffer, name, __kmp_debug_buf_atomic );
1349 } // __kmp_stg_print_debug_buf_atomic
1350 
1351 static void
1352 __kmp_stg_parse_debug_buf_chars( char const * name, char const * value, void * data ) {
1353  __kmp_stg_parse_int(
1354  name,
1355  value,
1356  KMP_DEBUG_BUF_CHARS_MIN,
1357  INT_MAX,
1358  & __kmp_debug_buf_chars
1359  );
1360 } // __kmp_stg_debug_parse_buf_chars
1361 
1362 static void
1363 __kmp_stg_print_debug_buf_chars( kmp_str_buf_t * buffer, char const * name, void * data ) {
1364  __kmp_stg_print_int( buffer, name, __kmp_debug_buf_chars );
1365 } // __kmp_stg_print_debug_buf_chars
1366 
1367 static void
1368 __kmp_stg_parse_debug_buf_lines( char const * name, char const * value, void * data ) {
1369  __kmp_stg_parse_int(
1370  name,
1371  value,
1372  KMP_DEBUG_BUF_LINES_MIN,
1373  INT_MAX,
1374  & __kmp_debug_buf_lines
1375  );
1376 } // __kmp_stg_parse_debug_buf_lines
1377 
1378 static void
1379 __kmp_stg_print_debug_buf_lines( kmp_str_buf_t * buffer, char const * name, void * data ) {
1380  __kmp_stg_print_int( buffer, name, __kmp_debug_buf_lines );
1381 } // __kmp_stg_print_debug_buf_lines
1382 
1383 static void
1384 __kmp_stg_parse_diag( char const * name, char const * value, void * data ) {
1385  __kmp_stg_parse_int( name, value, 0, INT_MAX, & kmp_diag );
1386 } // __kmp_stg_parse_diag
1387 
1388 static void
1389 __kmp_stg_print_diag( kmp_str_buf_t * buffer, char const * name, void * data ) {
1390  __kmp_stg_print_int( buffer, name, kmp_diag );
1391 } // __kmp_stg_print_diag
1392 
1393 #endif // KMP_DEBUG
1394 
1395 // -------------------------------------------------------------------------------------------------
1396 // KMP_ALIGN_ALLOC
1397 // -------------------------------------------------------------------------------------------------
1398 
1399 static void
1400 __kmp_stg_parse_align_alloc( char const * name, char const * value, void * data ) {
1401  __kmp_stg_parse_size(
1402  name,
1403  value,
1404  CACHE_LINE,
1405  INT_MAX,
1406  NULL,
1407  & __kmp_align_alloc,
1408  1
1409  );
1410 } // __kmp_stg_parse_align_alloc
1411 
1412 static void
1413 __kmp_stg_print_align_alloc( kmp_str_buf_t * buffer, char const * name, void * data ) {
1414  __kmp_stg_print_size( buffer, name, __kmp_align_alloc );
1415 } // __kmp_stg_print_align_alloc
1416 
1417 // -------------------------------------------------------------------------------------------------
1418 // KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
1419 // -------------------------------------------------------------------------------------------------
1420 
1421 // TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from parse and print
1422 // functions, pass required info through data argument.
1423 
1424 static void
1425 __kmp_stg_parse_barrier_branch_bit( char const * name, char const * value, void * data ) {
1426  const char *var;
1427 
1428  /* ---------- Barrier branch bit control ------------ */
1429  for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
1430  var = __kmp_barrier_branch_bit_env_name[ i ];
1431  if ( ( strcmp( var, name) == 0 ) && ( value != 0 ) ) {
1432  char *comma;
1433 
1434  comma = (char *) strchr( value, ',' );
1435  __kmp_barrier_gather_branch_bits[ i ] = ( kmp_uint32 ) __kmp_str_to_int( value, ',' );
1436  /* is there a specified release parameter? */
1437  if ( comma == NULL ) {
1438  __kmp_barrier_release_branch_bits[ i ] = __kmp_barrier_release_bb_dflt;
1439  } else {
1440  __kmp_barrier_release_branch_bits[ i ] = (kmp_uint32) __kmp_str_to_int( comma + 1, 0 );
1441 
1442  if ( __kmp_barrier_release_branch_bits[ i ] > KMP_MAX_BRANCH_BITS ) {
1443  __kmp_msg( kmp_ms_warning, KMP_MSG( BarrReleaseValueInvalid, name, comma + 1 ), __kmp_msg_null );
1444  __kmp_barrier_release_branch_bits[ i ] = __kmp_barrier_release_bb_dflt;
1445  }
1446  }
1447  if ( __kmp_barrier_gather_branch_bits[ i ] > KMP_MAX_BRANCH_BITS ) {
1448  KMP_WARNING( BarrGatherValueInvalid, name, value );
1449  KMP_INFORM( Using_uint_Value, name, __kmp_barrier_gather_bb_dflt );
1450  __kmp_barrier_gather_branch_bits[ i ] = __kmp_barrier_gather_bb_dflt;
1451  }
1452  }
1453  K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[ i ], \
1454  __kmp_barrier_gather_branch_bits [ i ], \
1455  __kmp_barrier_release_branch_bits [ i ]))
1456  }
1457 } // __kmp_stg_parse_barrier_branch_bit
1458 
1459 static void
1460 __kmp_stg_print_barrier_branch_bit( kmp_str_buf_t * buffer, char const * name, void * data ) {
1461  const char *var;
1462  for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
1463  var = __kmp_barrier_branch_bit_env_name[ i ];
1464  if ( strcmp( var, name) == 0 ) {
1465  if( __kmp_env_format ) {
1466  KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[ i ]);
1467  } else {
1468  __kmp_str_buf_print( buffer, " %s='", __kmp_barrier_branch_bit_env_name[ i ] );
1469  }
1470  __kmp_str_buf_print( buffer, "%d,%d'\n", __kmp_barrier_gather_branch_bits [ i ], __kmp_barrier_release_branch_bits [ i ]);
1471  }
1472  }
1473 } // __kmp_stg_print_barrier_branch_bit
1474 
1475 
1476 // -------------------------------------------------------------------------------------------------
1477 // KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN, KMP_REDUCTION_BARRIER_PATTERN
1478 // -------------------------------------------------------------------------------------------------
1479 
1480 // TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and print functions,
1481 // pass required data to functions through data argument.
1482 
1483 static void
1484 __kmp_stg_parse_barrier_pattern( char const * name, char const * value, void * data ) {
1485  const char *var;
1486  /* ---------- Barrier method control ------------ */
1487 
1488  for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
1489  var = __kmp_barrier_pattern_env_name[ i ];
1490 
1491  if ( ( strcmp ( var, name ) == 0 ) && ( value != 0 ) ) {
1492  int j;
1493  char *comma = (char *) strchr( value, ',' );
1494 
1495  /* handle first parameter: gather pattern */
1496  for ( j = bp_linear_bar; j<bp_last_bar; j++ ) {
1497  if (__kmp_match_with_sentinel( __kmp_barrier_pattern_name[j], value, 1, ',' )) {
1498  __kmp_barrier_gather_pattern[ i ] = (kmp_bar_pat_e) j;
1499  break;
1500  }
1501  }
1502  if ( j == bp_last_bar ) {
1503  KMP_WARNING( BarrGatherValueInvalid, name, value );
1504  KMP_INFORM( Using_str_Value, name, __kmp_barrier_pattern_name[ bp_linear_bar ] );
1505  }
1506 
1507  /* handle second parameter: release pattern */
1508  if ( comma != NULL ) {
1509  for ( j = bp_linear_bar; j < bp_last_bar; j++ ) {
1510  if ( __kmp_str_match( __kmp_barrier_pattern_name[j], 1, comma + 1 ) ) {
1511  __kmp_barrier_release_pattern[ i ] = (kmp_bar_pat_e) j;
1512  break;
1513  }
1514  }
1515  if (j == bp_last_bar) {
1516  __kmp_msg( kmp_ms_warning, KMP_MSG( BarrReleaseValueInvalid, name, comma + 1 ), __kmp_msg_null );
1517  KMP_INFORM( Using_str_Value, name, __kmp_barrier_pattern_name[ bp_linear_bar ] );
1518  }
1519  }
1520  }
1521  }
1522 } // __kmp_stg_parse_barrier_pattern
1523 
1524 static void
1525 __kmp_stg_print_barrier_pattern( kmp_str_buf_t * buffer, char const * name, void * data ) {
1526  const char *var;
1527  for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
1528  var = __kmp_barrier_pattern_env_name[ i ];
1529  if ( strcmp ( var, name ) == 0 ) {
1530  int j = __kmp_barrier_gather_pattern [ i ];
1531  int k = __kmp_barrier_release_pattern [ i ];
1532  if( __kmp_env_format ) {
1533  KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[ i ]);
1534  } else {
1535  __kmp_str_buf_print( buffer, " %s='", __kmp_barrier_pattern_env_name[ i ] );
1536  }
1537  __kmp_str_buf_print( buffer, "%s,%s'\n", __kmp_barrier_pattern_name [ j ], __kmp_barrier_pattern_name [ k ]);
1538  }
1539  }
1540 } // __kmp_stg_print_barrier_pattern
1541 
1542 // -------------------------------------------------------------------------------------------------
1543 // KMP_ABORT_DELAY
1544 // -------------------------------------------------------------------------------------------------
1545 
1546 static void
1547 __kmp_stg_parse_abort_delay( char const * name, char const * value, void * data ) {
1548  // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is milliseconds.
1549  int delay = __kmp_abort_delay / 1000;
1550  __kmp_stg_parse_int( name, value, 0, INT_MAX / 1000, & delay );
1551  __kmp_abort_delay = delay * 1000;
1552 } // __kmp_stg_parse_abort_delay
1553 
1554 static void
1555 __kmp_stg_print_abort_delay( kmp_str_buf_t * buffer, char const * name, void * data ) {
1556  __kmp_stg_print_int( buffer, name, __kmp_abort_delay );
1557 } // __kmp_stg_print_abort_delay
1558 
1559 // -------------------------------------------------------------------------------------------------
1560 // KMP_CPUINFO_FILE
1561 // -------------------------------------------------------------------------------------------------
1562 
1563 static void
1564 __kmp_stg_parse_cpuinfo_file( char const * name, char const * value, void * data ) {
1565  #if KMP_AFFINITY_SUPPORTED
1566  __kmp_stg_parse_str( name, value, & __kmp_cpuinfo_file );
1567  K_DIAG( 1, ( "__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file ) );
1568  #endif
1569 } //__kmp_stg_parse_cpuinfo_file
1570 
1571 static void
1572 __kmp_stg_print_cpuinfo_file( kmp_str_buf_t * buffer, char const * name, void * data ) {
1573  #if KMP_AFFINITY_SUPPORTED
1574  if( __kmp_env_format ) {
1575  KMP_STR_BUF_PRINT_NAME;
1576  } else {
1577  __kmp_str_buf_print( buffer, " %s", name );
1578  }
1579  if ( __kmp_cpuinfo_file ) {
1580  __kmp_str_buf_print( buffer, "='%s'\n", __kmp_cpuinfo_file );
1581  } else {
1582  __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
1583  }
1584  #endif
1585 } //__kmp_stg_print_cpuinfo_file
1586 
1587 // -------------------------------------------------------------------------------------------------
1588 // KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
1589 // -------------------------------------------------------------------------------------------------
1590 
1591 static void
1592 __kmp_stg_parse_force_reduction( char const * name, char const * value, void * data )
1593 {
1594  kmp_stg_fr_data_t * reduction = (kmp_stg_fr_data_t *) data;
1595  int rc;
1596 
1597  rc = __kmp_stg_check_rivals( name, value, reduction->rivals );
1598  if ( rc ) {
1599  return;
1600  }; // if
1601  if ( reduction->force ) {
1602  if( value != 0 ) {
1603  if( __kmp_str_match( "critical", 0, value ) )
1604  __kmp_force_reduction_method = critical_reduce_block;
1605  else if( __kmp_str_match( "atomic", 0, value ) )
1606  __kmp_force_reduction_method = atomic_reduce_block;
1607  else if( __kmp_str_match( "tree", 0, value ) )
1608  __kmp_force_reduction_method = tree_reduce_block;
1609  else {
1610  KMP_FATAL( UnknownForceReduction, name, value );
1611  }
1612  }
1613  } else {
1614  __kmp_stg_parse_bool( name, value, & __kmp_determ_red );
1615  if( __kmp_determ_red ) {
1616  __kmp_force_reduction_method = tree_reduce_block;
1617  } else {
1618  __kmp_force_reduction_method = reduction_method_not_defined;
1619  }
1620  }
1621  K_DIAG( 1, ( "__kmp_force_reduction_method == %d\n", __kmp_force_reduction_method ) );
1622 } // __kmp_stg_parse_force_reduction
1623 
1624 static void
1625 __kmp_stg_print_force_reduction( kmp_str_buf_t * buffer, char const * name, void * data ) {
1626 
1627  kmp_stg_fr_data_t * reduction = (kmp_stg_fr_data_t *) data;
1628  if ( reduction->force ) {
1629  if( __kmp_force_reduction_method == critical_reduce_block) {
1630  __kmp_stg_print_str( buffer, name, "critical");
1631  } else if ( __kmp_force_reduction_method == atomic_reduce_block ) {
1632  __kmp_stg_print_str( buffer, name, "atomic");
1633  } else if ( __kmp_force_reduction_method == tree_reduce_block ) {
1634  __kmp_stg_print_str( buffer, name, "tree");
1635  } else {
1636  if( __kmp_env_format ) {
1637  KMP_STR_BUF_PRINT_NAME;
1638  } else {
1639  __kmp_str_buf_print( buffer, " %s", name );
1640  }
1641  __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
1642  }
1643  } else {
1644  __kmp_stg_print_bool( buffer, name, __kmp_determ_red );
1645  }
1646 
1647 
1648 } // __kmp_stg_print_force_reduction
1649 
1650 // -------------------------------------------------------------------------------------------------
1651 // KMP_STORAGE_MAP
1652 // -------------------------------------------------------------------------------------------------
1653 
1654 static void
1655 __kmp_stg_parse_storage_map( char const * name, char const * value, void * data ) {
1656  if ( __kmp_str_match( "verbose", 1, value ) ) {
1657  __kmp_storage_map = TRUE;
1658  __kmp_storage_map_verbose = TRUE;
1659  __kmp_storage_map_verbose_specified = TRUE;
1660 
1661  } else {
1662  __kmp_storage_map_verbose = FALSE;
1663  __kmp_stg_parse_bool( name, value, & __kmp_storage_map ); // !!!
1664  }; // if
1665 } // __kmp_stg_parse_storage_map
1666 
1667 static void
1668 __kmp_stg_print_storage_map( kmp_str_buf_t * buffer, char const * name, void * data ) {
1669  if ( __kmp_storage_map_verbose || __kmp_storage_map_verbose_specified ) {
1670  __kmp_stg_print_str( buffer, name, "verbose" );
1671  } else {
1672  __kmp_stg_print_bool( buffer, name, __kmp_storage_map );
1673  }
1674 } // __kmp_stg_print_storage_map
1675 
1676 // -------------------------------------------------------------------------------------------------
1677 // KMP_ALL_THREADPRIVATE
1678 // -------------------------------------------------------------------------------------------------
1679 
1680 static void
1681 __kmp_stg_parse_all_threadprivate( char const * name, char const * value, void * data ) {
1682  __kmp_stg_parse_int( name, value, __kmp_allThreadsSpecified ? __kmp_max_nth : 1, __kmp_max_nth,
1683  & __kmp_tp_capacity );
1684 } // __kmp_stg_parse_all_threadprivate
1685 
1686 static void
1687 __kmp_stg_print_all_threadprivate( kmp_str_buf_t * buffer, char const * name, void * data ) {
1688  __kmp_stg_print_int( buffer, name, __kmp_tp_capacity );
1689 
1690 }
1691 
1692 // -------------------------------------------------------------------------------------------------
1693 // KMP_FOREIGN_THREADS_THREADPRIVATE
1694 // -------------------------------------------------------------------------------------------------
1695 
1696 static void
1697 __kmp_stg_parse_foreign_threads_threadprivate( char const * name, char const * value, void * data ) {
1698  __kmp_stg_parse_bool( name, value, & __kmp_foreign_tp );
1699 } // __kmp_stg_parse_foreign_threads_threadprivate
1700 
1701 static void
1702 __kmp_stg_print_foreign_threads_threadprivate( kmp_str_buf_t * buffer, char const * name, void * data ) {
1703  __kmp_stg_print_bool( buffer, name, __kmp_foreign_tp );
1704 } // __kmp_stg_print_foreign_threads_threadprivate
1705 
1706 
1707 // -------------------------------------------------------------------------------------------------
1708 // KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
1709 // -------------------------------------------------------------------------------------------------
1710 
1711 #if KMP_AFFINITY_SUPPORTED
1712 //
1713 // Parse the proc id list. Return TRUE if successful, FALSE otherwise.
1714 //
1715 static int
1716 __kmp_parse_affinity_proc_id_list( const char *var, const char *env,
1717  const char **nextEnv, char **proclist )
1718 {
1719  const char *scan = env;
1720  const char *next = scan;
1721  int empty = TRUE;
1722 
1723  *proclist = NULL;
1724 
1725  for (;;) {
1726  int start, end, stride;
1727 
1728  SKIP_WS(scan);
1729  next = scan;
1730  if (*next == '\0') {
1731  break;
1732  }
1733 
1734  if (*next == '{') {
1735  int num;
1736  next++; // skip '{'
1737  SKIP_WS(next);
1738  scan = next;
1739 
1740  //
1741  // Read the first integer in the set.
1742  //
1743  if ((*next < '0') || (*next > '9')) {
1744  KMP_WARNING( AffSyntaxError, var );
1745  return FALSE;
1746  }
1747  SKIP_DIGITS(next);
1748  num = __kmp_str_to_int(scan, *next);
1749  KMP_ASSERT(num >= 0);
1750 
1751  for (;;) {
1752  //
1753  // Check for end of set.
1754  //
1755  SKIP_WS(next);
1756  if (*next == '}') {
1757  next++; // skip '}'
1758  break;
1759  }
1760 
1761  //
1762  // Skip optional comma.
1763  //
1764  if (*next == ',') {
1765  next++;
1766  }
1767  SKIP_WS(next);
1768 
1769  //
1770  // Read the next integer in the set.
1771  //
1772  scan = next;
1773  if ((*next < '0') || (*next > '9')) {
1774  KMP_WARNING( AffSyntaxError, var );
1775  return FALSE;
1776  }
1777 
1778  SKIP_DIGITS(next);
1779  num = __kmp_str_to_int(scan, *next);
1780  KMP_ASSERT(num >= 0);
1781  }
1782  empty = FALSE;
1783 
1784  SKIP_WS(next);
1785  if (*next == ',') {
1786  next++;
1787  }
1788  scan = next;
1789  continue;
1790  }
1791 
1792  //
1793  // Next character is not an integer => end of list
1794  //
1795  if ((*next < '0') || (*next > '9')) {
1796  if (empty) {
1797  KMP_WARNING( AffSyntaxError, var );
1798  return FALSE;
1799  }
1800  break;
1801  }
1802 
1803  //
1804  // Read the first integer.
1805  //
1806  SKIP_DIGITS(next);
1807  start = __kmp_str_to_int(scan, *next);
1808  KMP_ASSERT(start >= 0);
1809  SKIP_WS(next);
1810 
1811  //
1812  // If this isn't a range, then go on.
1813  //
1814  if (*next != '-') {
1815  empty = FALSE;
1816 
1817  //
1818  // Skip optional comma.
1819  //
1820  if (*next == ',') {
1821  next++;
1822  }
1823  scan = next;
1824  continue;
1825  }
1826 
1827  //
1828  // This is a range. Skip over the '-' and read in the 2nd int.
1829  //
1830  next++; // skip '-'
1831  SKIP_WS(next);
1832  scan = next;
1833  if ((*next < '0') || (*next > '9')) {
1834  KMP_WARNING( AffSyntaxError, var );
1835  return FALSE;
1836  }
1837  SKIP_DIGITS(next);
1838  end = __kmp_str_to_int(scan, *next);
1839  KMP_ASSERT(end >= 0);
1840 
1841  //
1842  // Check for a stride parameter
1843  //
1844  stride = 1;
1845  SKIP_WS(next);
1846  if (*next == ':') {
1847  //
1848  // A stride is specified. Skip over the ':" and read the 3rd int.
1849  //
1850  int sign = +1;
1851  next++; // skip ':'
1852  SKIP_WS(next);
1853  scan = next;
1854  if (*next == '-') {
1855  sign = -1;
1856  next++;
1857  SKIP_WS(next);
1858  scan = next;
1859  }
1860  if ((*next < '0') || (*next > '9')) {
1861  KMP_WARNING( AffSyntaxError, var );
1862  return FALSE;
1863  }
1864  SKIP_DIGITS(next);
1865  stride = __kmp_str_to_int(scan, *next);
1866  KMP_ASSERT(stride >= 0);
1867  stride *= sign;
1868  }
1869 
1870  //
1871  // Do some range checks.
1872  //
1873  if (stride == 0) {
1874  KMP_WARNING( AffZeroStride, var );
1875  return FALSE;
1876  }
1877  if (stride > 0) {
1878  if (start > end) {
1879  KMP_WARNING( AffStartGreaterEnd, var, start, end );
1880  return FALSE;
1881  }
1882  }
1883  else {
1884  if (start < end) {
1885  KMP_WARNING( AffStrideLessZero, var, start, end );
1886  return FALSE;
1887  }
1888  }
1889  if ((end - start) / stride > 65536 ) {
1890  KMP_WARNING( AffRangeTooBig, var, end, start, stride );
1891  return FALSE;
1892  }
1893 
1894  empty = FALSE;
1895 
1896  //
1897  // Skip optional comma.
1898  //
1899  SKIP_WS(next);
1900  if (*next == ',') {
1901  next++;
1902  }
1903  scan = next;
1904  }
1905 
1906  *nextEnv = next;
1907 
1908  {
1909  int len = next - env;
1910  char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
1911  KMP_MEMCPY_S(retlist, (len+1)*sizeof(char), env, len * sizeof(char));
1912  retlist[len] = '\0';
1913  *proclist = retlist;
1914  }
1915  return TRUE;
1916 }
1917 
1918 
1919 //
1920 // If KMP_AFFINITY is specified without a type, then
1921 // __kmp_affinity_notype should point to its setting.
1922 //
1923 static kmp_setting_t *__kmp_affinity_notype = NULL;
1924 
1925 static void
1926 __kmp_parse_affinity_env( char const * name, char const * value,
1927  enum affinity_type * out_type,
1928  char ** out_proclist,
1929  int * out_verbose,
1930  int * out_warn,
1931  int * out_respect,
1932  enum affinity_gran * out_gran,
1933  int * out_gran_levels,
1934  int * out_dups,
1935  int * out_compact,
1936  int * out_offset
1937 )
1938 {
1939  char * buffer = NULL; // Copy of env var value.
1940  char * buf = NULL; // Buffer for strtok_r() function.
1941  char * next = NULL; // end of token / start of next.
1942  const char * start; // start of current token (for err msgs)
1943  int count = 0; // Counter of parsed integer numbers.
1944  int number[ 2 ]; // Parsed numbers.
1945 
1946  // Guards.
1947  int type = 0;
1948  int proclist = 0;
1949  int max_proclist = 0;
1950  int verbose = 0;
1951  int warnings = 0;
1952  int respect = 0;
1953  int gran = 0;
1954  int dups = 0;
1955 
1956  KMP_ASSERT( value != NULL );
1957 
1958  if ( TCR_4(__kmp_init_middle) ) {
1959  KMP_WARNING( EnvMiddleWarn, name );
1960  __kmp_env_toPrint( name, 0 );
1961  return;
1962  }
1963  __kmp_env_toPrint( name, 1 );
1964 
1965  buffer = __kmp_str_format( "%s", value ); // Copy env var to keep original intact.
1966  buf = buffer;
1967  SKIP_WS(buf);
1968 
1969  // Helper macros.
1970 
1971  //
1972  // If we see a parse error, emit a warning and scan to the next ",".
1973  //
1974  // FIXME - there's got to be a better way to print an error
1975  // message, hopefully without overwritting peices of buf.
1976  //
1977  #define EMIT_WARN(skip,errlist) \
1978  { \
1979  char ch; \
1980  if (skip) { \
1981  SKIP_TO(next, ','); \
1982  } \
1983  ch = *next; \
1984  *next = '\0'; \
1985  KMP_WARNING errlist; \
1986  *next = ch; \
1987  if (skip) { \
1988  if (ch == ',') next++; \
1989  } \
1990  buf = next; \
1991  }
1992 
1993  #define _set_param(_guard,_var,_val) \
1994  { \
1995  if ( _guard == 0 ) { \
1996  _var = _val; \
1997  } else { \
1998  EMIT_WARN( FALSE, ( AffParamDefined, name, start ) ); \
1999  }; \
2000  ++ _guard; \
2001  }
2002 
2003  #define set_type(val) _set_param( type, *out_type, val )
2004  #define set_verbose(val) _set_param( verbose, *out_verbose, val )
2005  #define set_warnings(val) _set_param( warnings, *out_warn, val )
2006  #define set_respect(val) _set_param( respect, *out_respect, val )
2007  #define set_dups(val) _set_param( dups, *out_dups, val )
2008  #define set_proclist(val) _set_param( proclist, *out_proclist, val )
2009 
2010  #define set_gran(val,levels) \
2011  { \
2012  if ( gran == 0 ) { \
2013  *out_gran = val; \
2014  *out_gran_levels = levels; \
2015  } else { \
2016  EMIT_WARN( FALSE, ( AffParamDefined, name, start ) ); \
2017  }; \
2018  ++ gran; \
2019  }
2020 
2021 # if OMP_40_ENABLED
2022  KMP_DEBUG_ASSERT( ( __kmp_nested_proc_bind.bind_types != NULL )
2023  && ( __kmp_nested_proc_bind.used > 0 ) );
2024 # endif
2025 
2026  while ( *buf != '\0' ) {
2027  start = next = buf;
2028 
2029  if (__kmp_match_str("none", buf, (const char **)&next)) {
2030  set_type( affinity_none );
2031 # if OMP_40_ENABLED
2032  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2033 # endif
2034  buf = next;
2035  } else if (__kmp_match_str("scatter", buf, (const char **)&next)) {
2036  set_type( affinity_scatter );
2037 # if OMP_40_ENABLED
2038  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2039 # endif
2040  buf = next;
2041  } else if (__kmp_match_str("compact", buf, (const char **)&next)) {
2042  set_type( affinity_compact );
2043 # if OMP_40_ENABLED
2044  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2045 # endif
2046  buf = next;
2047  } else if (__kmp_match_str("logical", buf, (const char **)&next)) {
2048  set_type( affinity_logical );
2049 # if OMP_40_ENABLED
2050  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2051 # endif
2052  buf = next;
2053  } else if (__kmp_match_str("physical", buf, (const char **)&next)) {
2054  set_type( affinity_physical );
2055 # if OMP_40_ENABLED
2056  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2057 # endif
2058  buf = next;
2059  } else if (__kmp_match_str("explicit", buf, (const char **)&next)) {
2060  set_type( affinity_explicit );
2061 # if OMP_40_ENABLED
2062  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2063 # endif
2064  buf = next;
2065  } else if (__kmp_match_str("balanced", buf, (const char **)&next)) {
2066  set_type( affinity_balanced );
2067 # if OMP_40_ENABLED
2068  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2069 # endif
2070  buf = next;
2071  } else if (__kmp_match_str("disabled", buf, (const char **)&next)) {
2072  set_type( affinity_disabled );
2073 # if OMP_40_ENABLED
2074  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2075 # endif
2076  buf = next;
2077  } else if (__kmp_match_str("verbose", buf, (const char **)&next)) {
2078  set_verbose( TRUE );
2079  buf = next;
2080  } else if (__kmp_match_str("noverbose", buf, (const char **)&next)) {
2081  set_verbose( FALSE );
2082  buf = next;
2083  } else if (__kmp_match_str("warnings", buf, (const char **)&next)) {
2084  set_warnings( TRUE );
2085  buf = next;
2086  } else if (__kmp_match_str("nowarnings", buf, (const char **)&next)) {
2087  set_warnings( FALSE );
2088  buf = next;
2089  } else if (__kmp_match_str("respect", buf, (const char **)&next)) {
2090  set_respect( TRUE );
2091  buf = next;
2092  } else if (__kmp_match_str("norespect", buf, (const char **)&next)) {
2093  set_respect( FALSE );
2094  buf = next;
2095  } else if (__kmp_match_str("duplicates", buf, (const char **)&next)
2096  || __kmp_match_str("dups", buf, (const char **)&next)) {
2097  set_dups( TRUE );
2098  buf = next;
2099  } else if (__kmp_match_str("noduplicates", buf, (const char **)&next)
2100  || __kmp_match_str("nodups", buf, (const char **)&next)) {
2101  set_dups( FALSE );
2102  buf = next;
2103  } else if (__kmp_match_str("granularity", buf, (const char **)&next)
2104  || __kmp_match_str("gran", buf, (const char **)&next)) {
2105  SKIP_WS(next);
2106  if (*next != '=') {
2107  EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2108  continue;
2109  }
2110  next++; // skip '='
2111  SKIP_WS(next);
2112 
2113  buf = next;
2114  if (__kmp_match_str("fine", buf, (const char **)&next)) {
2115  set_gran( affinity_gran_fine, -1 );
2116  buf = next;
2117  } else if (__kmp_match_str("thread", buf, (const char **)&next)) {
2118  set_gran( affinity_gran_thread, -1 );
2119  buf = next;
2120  } else if (__kmp_match_str("core", buf, (const char **)&next)) {
2121  set_gran( affinity_gran_core, -1 );
2122  buf = next;
2123  } else if (__kmp_match_str("package", buf, (const char **)&next)) {
2124  set_gran( affinity_gran_package, -1 );
2125  buf = next;
2126  } else if (__kmp_match_str("node", buf, (const char **)&next)) {
2127  set_gran( affinity_gran_node, -1 );
2128  buf = next;
2129 # if KMP_GROUP_AFFINITY
2130  } else if (__kmp_match_str("group", buf, (const char **)&next)) {
2131  set_gran( affinity_gran_group, -1 );
2132  buf = next;
2133 # endif /* KMP_GROUP AFFINITY */
2134  } else if ((*buf >= '0') && (*buf <= '9')) {
2135  int n;
2136  next = buf;
2137  SKIP_DIGITS(next);
2138  n = __kmp_str_to_int( buf, *next );
2139  KMP_ASSERT(n >= 0);
2140  buf = next;
2141  set_gran( affinity_gran_default, n );
2142  } else {
2143  EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2144  continue;
2145  }
2146  } else if (__kmp_match_str("proclist", buf, (const char **)&next)) {
2147  char *temp_proclist;
2148 
2149  SKIP_WS(next);
2150  if (*next != '=') {
2151  EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2152  continue;
2153  }
2154  next++; // skip '='
2155  SKIP_WS(next);
2156  if (*next != '[') {
2157  EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2158  continue;
2159  }
2160  next++; // skip '['
2161  buf = next;
2162  if (! __kmp_parse_affinity_proc_id_list(name, buf,
2163  (const char **)&next, &temp_proclist)) {
2164  //
2165  // warning already emitted.
2166  //
2167  SKIP_TO(next, ']');
2168  if (*next == ']') next++;
2169  SKIP_TO(next, ',');
2170  if (*next == ',') next++;
2171  buf = next;
2172  continue;
2173  }
2174  if (*next != ']') {
2175  EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2176  continue;
2177  }
2178  next++; // skip ']'
2179  set_proclist( temp_proclist );
2180  } else if ((*buf >= '0') && (*buf <= '9')) {
2181  // Parse integer numbers -- permute and offset.
2182  int n;
2183  next = buf;
2184  SKIP_DIGITS(next);
2185  n = __kmp_str_to_int( buf, *next );
2186  KMP_ASSERT(n >= 0);
2187  buf = next;
2188  if ( count < 2 ) {
2189  number[ count ] = n;
2190  } else {
2191  KMP_WARNING( AffManyParams, name, start );
2192  }; // if
2193  ++ count;
2194  } else {
2195  EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
2196  continue;
2197  }
2198 
2199  SKIP_WS(next);
2200  if (*next == ',') {
2201  next++;
2202  SKIP_WS(next);
2203  }
2204  else if (*next != '\0') {
2205  const char *temp = next;
2206  EMIT_WARN( TRUE, ( ParseExtraCharsWarn, name, temp ) );
2207  continue;
2208  }
2209  buf = next;
2210  } // while
2211 
2212  #undef EMIT_WARN
2213  #undef _set_param
2214  #undef set_type
2215  #undef set_verbose
2216  #undef set_warnings
2217  #undef set_respect
2218  #undef set_granularity
2219 
2220  KMP_INTERNAL_FREE( buffer );
2221 
2222  if ( proclist ) {
2223  if ( ! type ) {
2224  KMP_WARNING( AffProcListNoType, name );
2225  __kmp_affinity_type = affinity_explicit;
2226  }
2227  else if ( __kmp_affinity_type != affinity_explicit ) {
2228  KMP_WARNING( AffProcListNotExplicit, name );
2229  KMP_ASSERT( *out_proclist != NULL );
2230  KMP_INTERNAL_FREE( *out_proclist );
2231  *out_proclist = NULL;
2232  }
2233  }
2234  switch ( *out_type ) {
2235  case affinity_logical:
2236  case affinity_physical: {
2237  if ( count > 0 ) {
2238  *out_offset = number[ 0 ];
2239  }; // if
2240  if ( count > 1 ) {
2241  KMP_WARNING( AffManyParamsForLogic, name, number[ 1 ] );
2242  }; // if
2243  } break;
2244  case affinity_balanced: {
2245  if ( count > 0 ) {
2246  *out_compact = number[ 0 ];
2247  }; // if
2248  if ( count > 1 ) {
2249  *out_offset = number[ 1 ];
2250  }; // if
2251 
2252  if ( __kmp_affinity_gran == affinity_gran_default ) {
2253 #if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
2254  if( __kmp_mic_type != non_mic ) {
2255  if( __kmp_affinity_verbose || __kmp_affinity_warnings ) {
2256  KMP_WARNING( AffGranUsing, "KMP_AFFINITY", "fine" );
2257  }
2258  __kmp_affinity_gran = affinity_gran_fine;
2259  } else
2260 #endif
2261  {
2262  if( __kmp_affinity_verbose || __kmp_affinity_warnings ) {
2263  KMP_WARNING( AffGranUsing, "KMP_AFFINITY", "core" );
2264  }
2265  __kmp_affinity_gran = affinity_gran_core;
2266  }
2267  }
2268  } break;
2269  case affinity_scatter:
2270  case affinity_compact: {
2271  if ( count > 0 ) {
2272  *out_compact = number[ 0 ];
2273  }; // if
2274  if ( count > 1 ) {
2275  *out_offset = number[ 1 ];
2276  }; // if
2277  } break;
2278  case affinity_explicit: {
2279  if ( *out_proclist == NULL ) {
2280  KMP_WARNING( AffNoProcList, name );
2281  __kmp_affinity_type = affinity_none;
2282  }
2283  if ( count > 0 ) {
2284  KMP_WARNING( AffNoParam, name, "explicit" );
2285  }
2286  } break;
2287  case affinity_none: {
2288  if ( count > 0 ) {
2289  KMP_WARNING( AffNoParam, name, "none" );
2290  }; // if
2291  } break;
2292  case affinity_disabled: {
2293  if ( count > 0 ) {
2294  KMP_WARNING( AffNoParam, name, "disabled" );
2295  }; // if
2296  } break;
2297  case affinity_default: {
2298  if ( count > 0 ) {
2299  KMP_WARNING( AffNoParam, name, "default" );
2300  }; // if
2301  } break;
2302  default: {
2303  KMP_ASSERT( 0 );
2304  };
2305  }; // switch
2306 } // __kmp_parse_affinity_env
2307 
2308 static void
2309 __kmp_stg_parse_affinity( char const * name, char const * value, void * data )
2310 {
2311  kmp_setting_t **rivals = (kmp_setting_t **) data;
2312  int rc;
2313 
2314  rc = __kmp_stg_check_rivals( name, value, rivals );
2315  if ( rc ) {
2316  return;
2317  }
2318 
2319  __kmp_parse_affinity_env( name, value, & __kmp_affinity_type,
2320  & __kmp_affinity_proclist, & __kmp_affinity_verbose,
2321  & __kmp_affinity_warnings, & __kmp_affinity_respect_mask,
2322  & __kmp_affinity_gran, & __kmp_affinity_gran_levels,
2323  & __kmp_affinity_dups, & __kmp_affinity_compact,
2324  & __kmp_affinity_offset );
2325 
2326 } // __kmp_stg_parse_affinity
2327 
2328 static void
2329 __kmp_stg_print_affinity( kmp_str_buf_t * buffer, char const * name, void * data ) {
2330  if( __kmp_env_format ) {
2331  KMP_STR_BUF_PRINT_NAME_EX(name);
2332  } else {
2333  __kmp_str_buf_print( buffer, " %s='", name );
2334  }
2335  if ( __kmp_affinity_verbose ) {
2336  __kmp_str_buf_print( buffer, "%s,", "verbose");
2337  } else {
2338  __kmp_str_buf_print( buffer, "%s,", "noverbose");
2339  }
2340  if ( __kmp_affinity_warnings ) {
2341  __kmp_str_buf_print( buffer, "%s,", "warnings");
2342  } else {
2343  __kmp_str_buf_print( buffer, "%s,", "nowarnings");
2344  }
2345  if ( KMP_AFFINITY_CAPABLE() ) {
2346  if ( __kmp_affinity_respect_mask ) {
2347  __kmp_str_buf_print( buffer, "%s,", "respect");
2348  } else {
2349  __kmp_str_buf_print( buffer, "%s,", "norespect");
2350  }
2351  switch ( __kmp_affinity_gran ) {
2352  case affinity_gran_default:
2353  __kmp_str_buf_print( buffer, "%s", "granularity=default,");
2354  break;
2355  case affinity_gran_fine:
2356  __kmp_str_buf_print( buffer, "%s", "granularity=fine,");
2357  break;
2358  case affinity_gran_thread:
2359  __kmp_str_buf_print( buffer, "%s", "granularity=thread,");
2360  break;
2361  case affinity_gran_core:
2362  __kmp_str_buf_print( buffer, "%s", "granularity=core,");
2363  break;
2364  case affinity_gran_package:
2365  __kmp_str_buf_print( buffer, "%s", "granularity=package,");
2366  break;
2367  case affinity_gran_node:
2368  __kmp_str_buf_print( buffer, "%s", "granularity=node,");
2369  break;
2370 # if KMP_GROUP_AFFINITY
2371  case affinity_gran_group:
2372  __kmp_str_buf_print( buffer, "%s", "granularity=group,");
2373  break;
2374 # endif /* KMP_GROUP_AFFINITY */
2375  }
2376  if ( __kmp_affinity_dups ) {
2377  __kmp_str_buf_print( buffer, "%s,", "duplicates");
2378  } else {
2379  __kmp_str_buf_print( buffer, "%s,", "noduplicates");
2380  }
2381  }
2382  if ( ! KMP_AFFINITY_CAPABLE() ) {
2383  __kmp_str_buf_print( buffer, "%s", "disabled" );
2384  }
2385  else switch ( __kmp_affinity_type ){
2386  case affinity_none:
2387  __kmp_str_buf_print( buffer, "%s", "none");
2388  break;
2389  case affinity_physical:
2390  __kmp_str_buf_print( buffer, "%s,%d", "physical",
2391  __kmp_affinity_offset );
2392  break;
2393  case affinity_logical:
2394  __kmp_str_buf_print( buffer, "%s,%d", "logical",
2395  __kmp_affinity_offset );
2396  break;
2397  case affinity_compact:
2398  __kmp_str_buf_print( buffer, "%s,%d,%d", "compact",
2399  __kmp_affinity_compact, __kmp_affinity_offset );
2400  break;
2401  case affinity_scatter:
2402  __kmp_str_buf_print( buffer, "%s,%d,%d", "scatter",
2403  __kmp_affinity_compact, __kmp_affinity_offset );
2404  break;
2405  case affinity_explicit:
2406  __kmp_str_buf_print( buffer, "%s=[%s],%s", "proclist",
2407  __kmp_affinity_proclist, "explicit" );
2408  break;
2409  case affinity_balanced:
2410  __kmp_str_buf_print( buffer, "%s,%d,%d", "balanced",
2411  __kmp_affinity_compact, __kmp_affinity_offset );
2412  break;
2413  case affinity_disabled:
2414  __kmp_str_buf_print( buffer, "%s", "disabled");
2415  break;
2416  case affinity_default:
2417  __kmp_str_buf_print( buffer, "%s", "default");
2418  break;
2419  default:
2420  __kmp_str_buf_print( buffer, "%s", "<unknown>");
2421  break;
2422  }
2423  __kmp_str_buf_print( buffer, "'\n" );
2424 } //__kmp_stg_print_affinity
2425 
2426 # ifdef KMP_GOMP_COMPAT
2427 
2428 static void
2429 __kmp_stg_parse_gomp_cpu_affinity( char const * name, char const * value, void * data )
2430 {
2431  const char * next = NULL;
2432  char * temp_proclist;
2433  kmp_setting_t **rivals = (kmp_setting_t **) data;
2434  int rc;
2435 
2436  rc = __kmp_stg_check_rivals( name, value, rivals );
2437  if ( rc ) {
2438  return;
2439  }
2440 
2441  if ( TCR_4(__kmp_init_middle) ) {
2442  KMP_WARNING( EnvMiddleWarn, name );
2443  __kmp_env_toPrint( name, 0 );
2444  return;
2445  }
2446 
2447  __kmp_env_toPrint( name, 1 );
2448 
2449  if ( __kmp_parse_affinity_proc_id_list( name, value, &next,
2450  &temp_proclist )) {
2451  SKIP_WS(next);
2452  if (*next == '\0') {
2453  //
2454  // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2455  //
2456  __kmp_affinity_proclist = temp_proclist;
2457  __kmp_affinity_type = affinity_explicit;
2458  __kmp_affinity_gran = affinity_gran_fine;
2459 # if OMP_40_ENABLED
2460  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2461 # endif
2462  }
2463  else {
2464  KMP_WARNING( AffSyntaxError, name );
2465  if (temp_proclist != NULL) {
2466  KMP_INTERNAL_FREE((void *)temp_proclist);
2467  }
2468  }
2469  }
2470  else {
2471  //
2472  // Warning already emitted
2473  //
2474  __kmp_affinity_type = affinity_none;
2475 # if OMP_40_ENABLED
2476  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2477 # endif
2478  }
2479 } // __kmp_stg_parse_gomp_cpu_affinity
2480 
2481 # endif /* KMP_GOMP_COMPAT */
2482 
2483 
2484 # if OMP_40_ENABLED
2485 
2486 /*-----------------------------------------------------------------------------
2487 
2488 The OMP_PLACES proc id list parser. Here is the grammar:
2489 
2490 place_list := place
2491 place_list := place , place_list
2492 place := num
2493 place := place : num
2494 place := place : num : signed
2495 place := { subplacelist }
2496 place := ! place // (lowest priority)
2497 subplace_list := subplace
2498 subplace_list := subplace , subplace_list
2499 subplace := num
2500 subplace := num : num
2501 subplace := num : num : signed
2502 signed := num
2503 signed := + signed
2504 signed := - signed
2505 
2506 -----------------------------------------------------------------------------*/
2507 
2508 static int
2509 __kmp_parse_subplace_list( const char *var, const char **scan )
2510 {
2511  const char *next;
2512 
2513  for (;;) {
2514  int start, count, stride;
2515 
2516  //
2517  // Read in the starting proc id
2518  //
2519  SKIP_WS(*scan);
2520  if ((**scan < '0') || (**scan > '9')) {
2521  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2522  return FALSE;
2523  }
2524  next = *scan;
2525  SKIP_DIGITS(next);
2526  start = __kmp_str_to_int(*scan, *next);
2527  KMP_ASSERT(start >= 0);
2528  *scan = next;
2529 
2530  //
2531  // valid follow sets are ',' ':' and '}'
2532  //
2533  SKIP_WS(*scan);
2534  if (**scan == '}') {
2535  break;
2536  }
2537  if (**scan == ',') {
2538  (*scan)++; // skip ','
2539  continue;
2540  }
2541  if (**scan != ':') {
2542  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2543  return FALSE;
2544  }
2545  (*scan)++; // skip ':'
2546 
2547  //
2548  // Read count parameter
2549  //
2550  SKIP_WS(*scan);
2551  if ((**scan < '0') || (**scan > '9')) {
2552  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2553  return FALSE;
2554  }
2555  next = *scan;
2556  SKIP_DIGITS(next);
2557  count = __kmp_str_to_int(*scan, *next);
2558  KMP_ASSERT(count >= 0);
2559  *scan = next;
2560 
2561  //
2562  // valid follow sets are ',' ':' and '}'
2563  //
2564  SKIP_WS(*scan);
2565  if (**scan == '}') {
2566  break;
2567  }
2568  if (**scan == ',') {
2569  (*scan)++; // skip ','
2570  continue;
2571  }
2572  if (**scan != ':') {
2573  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2574  return FALSE;
2575  }
2576  (*scan)++; // skip ':'
2577 
2578  //
2579  // Read stride parameter
2580  //
2581  int sign = +1;
2582  for (;;) {
2583  SKIP_WS(*scan);
2584  if (**scan == '+') {
2585  (*scan)++; // skip '+'
2586  continue;
2587  }
2588  if (**scan == '-') {
2589  sign *= -1;
2590  (*scan)++; // skip '-'
2591  continue;
2592  }
2593  break;
2594  }
2595  SKIP_WS(*scan);
2596  if ((**scan < '0') || (**scan > '9')) {
2597  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2598  return FALSE;
2599  }
2600  next = *scan;
2601  SKIP_DIGITS(next);
2602  stride = __kmp_str_to_int(*scan, *next);
2603  KMP_ASSERT(stride >= 0);
2604  *scan = next;
2605  stride *= sign;
2606 
2607  //
2608  // valid follow sets are ',' and '}'
2609  //
2610  SKIP_WS(*scan);
2611  if (**scan == '}') {
2612  break;
2613  }
2614  if (**scan == ',') {
2615  (*scan)++; // skip ','
2616  continue;
2617  }
2618 
2619  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2620  return FALSE;
2621  }
2622  return TRUE;
2623 }
2624 
2625 static int
2626 __kmp_parse_place( const char *var, const char ** scan )
2627 {
2628  const char *next;
2629 
2630  //
2631  // valid follow sets are '{' '!' and num
2632  //
2633  SKIP_WS(*scan);
2634  if (**scan == '{') {
2635  (*scan)++; // skip '{'
2636  if (! __kmp_parse_subplace_list(var, scan)) {
2637  return FALSE;
2638  }
2639  if (**scan != '}') {
2640  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2641  return FALSE;
2642  }
2643  (*scan)++; // skip '}'
2644  }
2645  else if (**scan == '!') {
2646  (*scan)++; // skip '!'
2647  return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2648  }
2649  else if ((**scan >= '0') && (**scan <= '9')) {
2650  next = *scan;
2651  SKIP_DIGITS(next);
2652  int proc = __kmp_str_to_int(*scan, *next);
2653  KMP_ASSERT(proc >= 0);
2654  *scan = next;
2655  }
2656  else {
2657  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2658  return FALSE;
2659  }
2660  return TRUE;
2661 }
2662 
2663 static int
2664 __kmp_parse_place_list( const char *var, const char *env, char **place_list )
2665 {
2666  const char *scan = env;
2667  const char *next = scan;
2668 
2669  for (;;) {
2670  int start, count, stride;
2671 
2672  if (! __kmp_parse_place(var, &scan)) {
2673  return FALSE;
2674  }
2675 
2676  //
2677  // valid follow sets are ',' ':' and EOL
2678  //
2679  SKIP_WS(scan);
2680  if (*scan == '\0') {
2681  break;
2682  }
2683  if (*scan == ',') {
2684  scan++; // skip ','
2685  continue;
2686  }
2687  if (*scan != ':') {
2688  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2689  return FALSE;
2690  }
2691  scan++; // skip ':'
2692 
2693  //
2694  // Read count parameter
2695  //
2696  SKIP_WS(scan);
2697  if ((*scan < '0') || (*scan > '9')) {
2698  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2699  return FALSE;
2700  }
2701  next = scan;
2702  SKIP_DIGITS(next);
2703  count = __kmp_str_to_int(scan, *next);
2704  KMP_ASSERT(count >= 0);
2705  scan = next;
2706 
2707  //
2708  // valid follow sets are ',' ':' and EOL
2709  //
2710  SKIP_WS(scan);
2711  if (*scan == '\0') {
2712  break;
2713  }
2714  if (*scan == ',') {
2715  scan++; // skip ','
2716  continue;
2717  }
2718  if (*scan != ':') {
2719  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2720  return FALSE;
2721  }
2722  scan++; // skip ':'
2723 
2724  //
2725  // Read stride parameter
2726  //
2727  int sign = +1;
2728  for (;;) {
2729  SKIP_WS(scan);
2730  if (*scan == '+') {
2731  scan++; // skip '+'
2732  continue;
2733  }
2734  if (*scan == '-') {
2735  sign *= -1;
2736  scan++; // skip '-'
2737  continue;
2738  }
2739  break;
2740  }
2741  SKIP_WS(scan);
2742  if ((*scan < '0') || (*scan > '9')) {
2743  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2744  return FALSE;
2745  }
2746  next = scan;
2747  SKIP_DIGITS(next);
2748  stride = __kmp_str_to_int(scan, *next);
2749  KMP_ASSERT(stride >= 0);
2750  scan = next;
2751  stride *= sign;
2752 
2753  //
2754  // valid follow sets are ',' and EOL
2755  //
2756  SKIP_WS(scan);
2757  if (*scan == '\0') {
2758  break;
2759  }
2760  if (*scan == ',') {
2761  scan++; // skip ','
2762  continue;
2763  }
2764 
2765  KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
2766  return FALSE;
2767  }
2768 
2769  {
2770  int len = scan - env;
2771  char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
2772  KMP_MEMCPY_S(retlist, (len+1)*sizeof(char), env, len * sizeof(char));
2773  retlist[len] = '\0';
2774  *place_list = retlist;
2775  }
2776  return TRUE;
2777 }
2778 
2779 static void
2780 __kmp_stg_parse_places( char const * name, char const * value, void * data )
2781 {
2782  int count;
2783  const char *scan = value;
2784  const char *next = scan;
2785  const char *kind = "\"threads\"";
2786  kmp_setting_t **rivals = (kmp_setting_t **) data;
2787  int rc;
2788 
2789  rc = __kmp_stg_check_rivals( name, value, rivals );
2790  if ( rc ) {
2791  return;
2792  }
2793 
2794  //
2795  // If OMP_PROC_BIND is not specified but OMP_PLACES is,
2796  // then let OMP_PROC_BIND default to true.
2797  //
2798  if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) {
2799  __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2800  }
2801 
2802  //__kmp_affinity_num_places = 0;
2803 
2804  if ( __kmp_match_str( "threads", scan, &next ) ) {
2805  scan = next;
2806  __kmp_affinity_type = affinity_compact;
2807  __kmp_affinity_gran = affinity_gran_thread;
2808  __kmp_affinity_dups = FALSE;
2809  kind = "\"threads\"";
2810  }
2811  else if ( __kmp_match_str( "cores", scan, &next ) ) {
2812  scan = next;
2813  __kmp_affinity_type = affinity_compact;
2814  __kmp_affinity_gran = affinity_gran_core;
2815  __kmp_affinity_dups = FALSE;
2816  kind = "\"cores\"";
2817  }
2818  else if ( __kmp_match_str( "sockets", scan, &next ) ) {
2819  scan = next;
2820  __kmp_affinity_type = affinity_compact;
2821  __kmp_affinity_gran = affinity_gran_package;
2822  __kmp_affinity_dups = FALSE;
2823  kind = "\"sockets\"";
2824  }
2825  else {
2826  if ( __kmp_affinity_proclist != NULL ) {
2827  KMP_INTERNAL_FREE( (void *)__kmp_affinity_proclist );
2828  __kmp_affinity_proclist = NULL;
2829  }
2830  if ( __kmp_parse_place_list( name, value, &__kmp_affinity_proclist ) ) {
2831  __kmp_affinity_type = affinity_explicit;
2832  __kmp_affinity_gran = affinity_gran_fine;
2833  __kmp_affinity_dups = FALSE;
2834  if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) {
2835  __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2836  }
2837  }
2838  return;
2839  }
2840 
2841  if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) {
2842  __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2843  }
2844 
2845  SKIP_WS(scan);
2846  if ( *scan == '\0' ) {
2847  return;
2848  }
2849 
2850  //
2851  // Parse option count parameter in parentheses
2852  //
2853  if ( *scan != '(' ) {
2854  KMP_WARNING( SyntaxErrorUsing, name, kind );
2855  return;
2856  }
2857  scan++; // skip '('
2858 
2859  SKIP_WS(scan);
2860  next = scan;
2861  SKIP_DIGITS(next);
2862  count = __kmp_str_to_int(scan, *next);
2863  KMP_ASSERT(count >= 0);
2864  scan = next;
2865 
2866  SKIP_WS(scan);
2867  if ( *scan != ')' ) {
2868  KMP_WARNING( SyntaxErrorUsing, name, kind );
2869  return;
2870  }
2871  scan++; // skip ')'
2872 
2873  SKIP_WS(scan);
2874  if ( *scan != '\0' ) {
2875  KMP_WARNING( ParseExtraCharsWarn, name, scan );
2876  }
2877  __kmp_affinity_num_places = count;
2878 }
2879 
2880 static void
2881 __kmp_stg_print_places( kmp_str_buf_t * buffer, char const * name,
2882  void * data )
2883 {
2884  if( __kmp_env_format ) {
2885  KMP_STR_BUF_PRINT_NAME;
2886  } else {
2887  __kmp_str_buf_print( buffer, " %s", name );
2888  }
2889  if ( ( __kmp_nested_proc_bind.used == 0 )
2890  || ( __kmp_nested_proc_bind.bind_types == NULL )
2891  || ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_false ) ) {
2892  __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
2893  }
2894  else if ( __kmp_affinity_type == affinity_explicit ) {
2895  if ( __kmp_affinity_proclist != NULL ) {
2896  __kmp_str_buf_print( buffer, "='%s'\n", __kmp_affinity_proclist );
2897  }
2898  else {
2899  __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
2900  }
2901  }
2902  else if ( __kmp_affinity_type == affinity_compact ) {
2903  int num;
2904  if ( __kmp_affinity_num_masks > 0 ) {
2905  num = __kmp_affinity_num_masks;
2906  }
2907  else if ( __kmp_affinity_num_places > 0 ) {
2908  num = __kmp_affinity_num_places;
2909  }
2910  else {
2911  num = 0;
2912  }
2913  if ( __kmp_affinity_gran == affinity_gran_thread ) {
2914  if ( num > 0 ) {
2915  __kmp_str_buf_print( buffer, "='threads(%d)'\n", num );
2916  }
2917  else {
2918  __kmp_str_buf_print( buffer, "='threads'\n" );
2919  }
2920  }
2921  else if ( __kmp_affinity_gran == affinity_gran_core ) {
2922  if ( num > 0 ) {
2923  __kmp_str_buf_print( buffer, "='cores(%d)' \n", num );
2924  }
2925  else {
2926  __kmp_str_buf_print( buffer, "='cores'\n" );
2927  }
2928  }
2929  else if ( __kmp_affinity_gran == affinity_gran_package ) {
2930  if ( num > 0 ) {
2931  __kmp_str_buf_print( buffer, "='sockets(%d)'\n", num );
2932  }
2933  else {
2934  __kmp_str_buf_print( buffer, "='sockets'\n" );
2935  }
2936  }
2937  else {
2938  __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
2939  }
2940  }
2941  else {
2942  __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
2943  }
2944 }
2945 
2946 # endif /* OMP_40_ENABLED */
2947 
2948 # if (! OMP_40_ENABLED)
2949 
2950 static void
2951 __kmp_stg_parse_proc_bind( char const * name, char const * value, void * data )
2952 {
2953  int enabled;
2954  kmp_setting_t **rivals = (kmp_setting_t **) data;
2955  int rc;
2956 
2957  rc = __kmp_stg_check_rivals( name, value, rivals );
2958  if ( rc ) {
2959  return;
2960  }
2961 
2962  //
2963  // in OMP 3.1, OMP_PROC_BIND is strictly a boolean
2964  //
2965  __kmp_stg_parse_bool( name, value, & enabled );
2966  if ( enabled ) {
2967  //
2968  // OMP_PROC_BIND => granularity=fine,scatter on MIC
2969  // OMP_PROC_BIND => granularity=core,scatter elsewhere
2970  //
2971  __kmp_affinity_type = affinity_scatter;
2972 # if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
2973  if( __kmp_mic_type != non_mic )
2974  __kmp_affinity_gran = affinity_gran_fine;
2975  else
2976 # endif
2977  __kmp_affinity_gran = affinity_gran_core;
2978  }
2979  else {
2980  __kmp_affinity_type = affinity_none;
2981  }
2982 } // __kmp_parse_proc_bind
2983 
2984 # endif /* if (! OMP_40_ENABLED) */
2985 
2986 
2987 static void
2988 __kmp_stg_parse_topology_method( char const * name, char const * value,
2989  void * data ) {
2990  if ( __kmp_str_match( "all", 1, value ) ) {
2991  __kmp_affinity_top_method = affinity_top_method_all;
2992  }
2993 # if KMP_ARCH_X86 || KMP_ARCH_X86_64
2994  else if ( __kmp_str_match( "x2apic id", 9, value )
2995  || __kmp_str_match( "x2apic_id", 9, value )
2996  || __kmp_str_match( "x2apic-id", 9, value )
2997  || __kmp_str_match( "x2apicid", 8, value )
2998  || __kmp_str_match( "cpuid leaf 11", 13, value )
2999  || __kmp_str_match( "cpuid_leaf_11", 13, value )
3000  || __kmp_str_match( "cpuid-leaf-11", 13, value )
3001  || __kmp_str_match( "cpuid leaf11", 12, value )
3002  || __kmp_str_match( "cpuid_leaf11", 12, value )
3003  || __kmp_str_match( "cpuid-leaf11", 12, value )
3004  || __kmp_str_match( "cpuidleaf 11", 12, value )
3005  || __kmp_str_match( "cpuidleaf_11", 12, value )
3006  || __kmp_str_match( "cpuidleaf-11", 12, value )
3007  || __kmp_str_match( "cpuidleaf11", 11, value )
3008  || __kmp_str_match( "cpuid 11", 8, value )
3009  || __kmp_str_match( "cpuid_11", 8, value )
3010  || __kmp_str_match( "cpuid-11", 8, value )
3011  || __kmp_str_match( "cpuid11", 7, value )
3012  || __kmp_str_match( "leaf 11", 7, value )
3013  || __kmp_str_match( "leaf_11", 7, value )
3014  || __kmp_str_match( "leaf-11", 7, value )
3015  || __kmp_str_match( "leaf11", 6, value ) ) {
3016  __kmp_affinity_top_method = affinity_top_method_x2apicid;
3017  }
3018  else if ( __kmp_str_match( "apic id", 7, value )
3019  || __kmp_str_match( "apic_id", 7, value )
3020  || __kmp_str_match( "apic-id", 7, value )
3021  || __kmp_str_match( "apicid", 6, value )
3022  || __kmp_str_match( "cpuid leaf 4", 12, value )
3023  || __kmp_str_match( "cpuid_leaf_4", 12, value )
3024  || __kmp_str_match( "cpuid-leaf-4", 12, value )
3025  || __kmp_str_match( "cpuid leaf4", 11, value )
3026  || __kmp_str_match( "cpuid_leaf4", 11, value )
3027  || __kmp_str_match( "cpuid-leaf4", 11, value )
3028  || __kmp_str_match( "cpuidleaf 4", 11, value )
3029  || __kmp_str_match( "cpuidleaf_4", 11, value )
3030  || __kmp_str_match( "cpuidleaf-4", 11, value )
3031  || __kmp_str_match( "cpuidleaf4", 10, value )
3032  || __kmp_str_match( "cpuid 4", 7, value )
3033  || __kmp_str_match( "cpuid_4", 7, value )
3034  || __kmp_str_match( "cpuid-4", 7, value )
3035  || __kmp_str_match( "cpuid4", 6, value )
3036  || __kmp_str_match( "leaf 4", 6, value )
3037  || __kmp_str_match( "leaf_4", 6, value )
3038  || __kmp_str_match( "leaf-4", 6, value )
3039  || __kmp_str_match( "leaf4", 5, value ) ) {
3040  __kmp_affinity_top_method = affinity_top_method_apicid;
3041  }
3042 # endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
3043  else if ( __kmp_str_match( "/proc/cpuinfo", 2, value )
3044  || __kmp_str_match( "cpuinfo", 5, value )) {
3045  __kmp_affinity_top_method = affinity_top_method_cpuinfo;
3046  }
3047 # if KMP_GROUP_AFFINITY
3048  else if ( __kmp_str_match( "group", 1, value ) ) {
3049  __kmp_affinity_top_method = affinity_top_method_group;
3050  }
3051 # endif /* KMP_GROUP_AFFINITY */
3052  else if ( __kmp_str_match( "flat", 1, value ) ) {
3053  __kmp_affinity_top_method = affinity_top_method_flat;
3054  }
3055 # if KMP_USE_HWLOC
3056  else if ( __kmp_str_match( "hwloc", 1, value) ) {
3057  __kmp_affinity_top_method = affinity_top_method_hwloc;
3058  }
3059 # endif
3060  else {
3061  KMP_WARNING( StgInvalidValue, name, value );
3062  }
3063 } // __kmp_stg_parse_topology_method
3064 
3065 static void
3066 __kmp_stg_print_topology_method( kmp_str_buf_t * buffer, char const * name,
3067  void * data ) {
3068 # if KMP_DEBUG
3069  char const * value = NULL;
3070 
3071  switch ( __kmp_affinity_top_method ) {
3072  case affinity_top_method_default:
3073  value = "default";
3074  break;
3075 
3076  case affinity_top_method_all:
3077  value = "all";
3078  break;
3079 
3080 # if KMP_ARCH_X86 || KMP_ARCH_X86_64
3081  case affinity_top_method_x2apicid:
3082  value = "x2APIC id";
3083  break;
3084 
3085  case affinity_top_method_apicid:
3086  value = "APIC id";
3087  break;
3088 # endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
3089 
3090  case affinity_top_method_cpuinfo:
3091  value = "cpuinfo";
3092  break;
3093 
3094 # if KMP_GROUP_AFFINITY
3095  case affinity_top_method_group:
3096  value = "group";
3097  break;
3098 # endif /* KMP_GROUP_AFFINITY */
3099 
3100  case affinity_top_method_flat:
3101  value = "flat";
3102  break;
3103  }
3104 
3105  if ( value != NULL ) {
3106  __kmp_stg_print_str( buffer, name, value );
3107  }
3108 # endif /* KMP_DEBUG */
3109 } // __kmp_stg_print_topology_method
3110 
3111 #endif /* KMP_AFFINITY_SUPPORTED */
3112 
3113 
3114 #if OMP_40_ENABLED
3115 
3116 //
3117 // OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
3118 // OMP_PLACES / place-partition-var is not.
3119 //
3120 static void
3121 __kmp_stg_parse_proc_bind( char const * name, char const * value, void * data )
3122 {
3123  kmp_setting_t **rivals = (kmp_setting_t **) data;
3124  int rc;
3125 
3126  rc = __kmp_stg_check_rivals( name, value, rivals );
3127  if ( rc ) {
3128  return;
3129  }
3130 
3131  //
3132  // in OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
3133  //
3134  KMP_DEBUG_ASSERT( (__kmp_nested_proc_bind.bind_types != NULL)
3135  && ( __kmp_nested_proc_bind.used > 0 ) );
3136 
3137  const char *buf = value;
3138  const char *next;
3139  int num;
3140  SKIP_WS( buf );
3141  if ( (*buf >= '0') && (*buf <= '9') ) {
3142  next = buf;
3143  SKIP_DIGITS( next );
3144  num = __kmp_str_to_int( buf, *next );
3145  KMP_ASSERT( num >= 0 );
3146  buf = next;
3147  SKIP_WS( buf );
3148  }
3149  else {
3150  num = -1;
3151  }
3152 
3153  next = buf;
3154  if ( __kmp_match_str( "disabled", buf, &next ) ) {
3155  buf = next;
3156  SKIP_WS( buf );
3157 # if KMP_AFFINITY_SUPPORTED
3158  __kmp_affinity_type = affinity_disabled;
3159 # endif /* KMP_AFFINITY_SUPPORTED */
3160  __kmp_nested_proc_bind.used = 1;
3161  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3162  }
3163  else if ( ( num == (int)proc_bind_false )
3164  || __kmp_match_str( "false", buf, &next ) ) {
3165  buf = next;
3166  SKIP_WS( buf );
3167 # if KMP_AFFINITY_SUPPORTED
3168  __kmp_affinity_type = affinity_none;
3169 # endif /* KMP_AFFINITY_SUPPORTED */
3170  __kmp_nested_proc_bind.used = 1;
3171  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3172  }
3173  else if ( ( num == (int)proc_bind_true )
3174  || __kmp_match_str( "true", buf, &next ) ) {
3175  buf = next;
3176  SKIP_WS( buf );
3177  __kmp_nested_proc_bind.used = 1;
3178  __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3179  }
3180  else {
3181  //
3182  // Count the number of values in the env var string
3183  //
3184  const char *scan;
3185  int nelem = 1;
3186  for ( scan = buf; *scan != '\0'; scan++ ) {
3187  if ( *scan == ',' ) {
3188  nelem++;
3189  }
3190  }
3191 
3192  //
3193  // Create / expand the nested proc_bind array as needed
3194  //
3195  if ( __kmp_nested_proc_bind.size < nelem ) {
3196  __kmp_nested_proc_bind.bind_types = (kmp_proc_bind_t *)
3197  KMP_INTERNAL_REALLOC( __kmp_nested_proc_bind.bind_types,
3198  sizeof(kmp_proc_bind_t) * nelem );
3199  if ( __kmp_nested_proc_bind.bind_types == NULL ) {
3200  KMP_FATAL( MemoryAllocFailed );
3201  }
3202  __kmp_nested_proc_bind.size = nelem;
3203  }
3204  __kmp_nested_proc_bind.used = nelem;
3205 
3206  //
3207  // Save values in the nested proc_bind array
3208  //
3209  int i = 0;
3210  for (;;) {
3211  enum kmp_proc_bind_t bind;
3212 
3213  if ( ( num == (int)proc_bind_master )
3214  || __kmp_match_str( "master", buf, &next ) ) {
3215  buf = next;
3216  SKIP_WS( buf );
3217  bind = proc_bind_master;
3218  }
3219  else if ( ( num == (int)proc_bind_close )
3220  || __kmp_match_str( "close", buf, &next ) ) {
3221  buf = next;
3222  SKIP_WS( buf );
3223  bind = proc_bind_close;
3224  }
3225  else if ( ( num == (int)proc_bind_spread )
3226  || __kmp_match_str( "spread", buf, &next ) ) {
3227  buf = next;
3228  SKIP_WS( buf );
3229  bind = proc_bind_spread;
3230  }
3231  else {
3232  KMP_WARNING( StgInvalidValue, name, value );
3233  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3234  __kmp_nested_proc_bind.used = 1;
3235  return;
3236  }
3237 
3238  __kmp_nested_proc_bind.bind_types[i++] = bind;
3239  if ( i >= nelem ) {
3240  break;
3241  }
3242  KMP_DEBUG_ASSERT( *buf == ',' );
3243  buf++;
3244  SKIP_WS( buf );
3245 
3246  //
3247  // Read next value if it was specified as an integer
3248  //
3249  if ( (*buf >= '0') && (*buf <= '9') ) {
3250  next = buf;
3251  SKIP_DIGITS( next );
3252  num = __kmp_str_to_int( buf, *next );
3253  KMP_ASSERT( num >= 0 );
3254  buf = next;
3255  SKIP_WS( buf );
3256  }
3257  else {
3258  num = -1;
3259  }
3260  }
3261  SKIP_WS( buf );
3262  }
3263  if ( *buf != '\0' ) {
3264  KMP_WARNING( ParseExtraCharsWarn, name, buf );
3265  }
3266 }
3267 
3268 
3269 static void
3270 __kmp_stg_print_proc_bind( kmp_str_buf_t * buffer, char const * name,
3271  void * data )
3272 {
3273  int nelem = __kmp_nested_proc_bind.used;
3274  if( __kmp_env_format ) {
3275  KMP_STR_BUF_PRINT_NAME;
3276  } else {
3277  __kmp_str_buf_print( buffer, " %s", name );
3278  }
3279  if ( nelem == 0 ) {
3280  __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
3281  }
3282  else {
3283  int i;
3284  __kmp_str_buf_print( buffer, "='", name );
3285  for ( i = 0; i < nelem; i++ ) {
3286  switch ( __kmp_nested_proc_bind.bind_types[i] ) {
3287  case proc_bind_false:
3288  __kmp_str_buf_print( buffer, "false" );
3289  break;
3290 
3291  case proc_bind_true:
3292  __kmp_str_buf_print( buffer, "true" );
3293  break;
3294 
3295  case proc_bind_master:
3296  __kmp_str_buf_print( buffer, "master" );
3297  break;
3298 
3299  case proc_bind_close:
3300  __kmp_str_buf_print( buffer, "close" );
3301  break;
3302 
3303  case proc_bind_spread:
3304  __kmp_str_buf_print( buffer, "spread" );
3305  break;
3306 
3307  case proc_bind_intel:
3308  __kmp_str_buf_print( buffer, "intel" );
3309  break;
3310 
3311  case proc_bind_default:
3312  __kmp_str_buf_print( buffer, "default" );
3313  break;
3314  }
3315  if ( i < nelem - 1 ) {
3316  __kmp_str_buf_print( buffer, "," );
3317  }
3318  }
3319  __kmp_str_buf_print( buffer, "'\n" );
3320  }
3321 }
3322 
3323 #endif /* OMP_40_ENABLED */
3324 
3325 
3326 // -------------------------------------------------------------------------------------------------
3327 // OMP_DYNAMIC
3328 // -------------------------------------------------------------------------------------------------
3329 
3330 static void
3331 __kmp_stg_parse_omp_dynamic( char const * name, char const * value, void * data )
3332 {
3333  __kmp_stg_parse_bool( name, value, & (__kmp_global.g.g_dynamic) );
3334 } // __kmp_stg_parse_omp_dynamic
3335 
3336 static void
3337 __kmp_stg_print_omp_dynamic( kmp_str_buf_t * buffer, char const * name, void * data )
3338 {
3339  __kmp_stg_print_bool( buffer, name, __kmp_global.g.g_dynamic );
3340 } // __kmp_stg_print_omp_dynamic
3341 
3342 static void
3343 __kmp_stg_parse_kmp_dynamic_mode( char const * name, char const * value, void * data )
3344 {
3345  if ( TCR_4(__kmp_init_parallel) ) {
3346  KMP_WARNING( EnvParallelWarn, name );
3347  __kmp_env_toPrint( name, 0 );
3348  return;
3349  }
3350 #ifdef USE_LOAD_BALANCE
3351  else if ( __kmp_str_match( "load balance", 2, value )
3352  || __kmp_str_match( "load_balance", 2, value )
3353  || __kmp_str_match( "load-balance", 2, value )
3354  || __kmp_str_match( "loadbalance", 2, value )
3355  || __kmp_str_match( "balance", 1, value ) ) {
3356  __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3357  }
3358 #endif /* USE_LOAD_BALANCE */
3359  else if ( __kmp_str_match( "thread limit", 1, value )
3360  || __kmp_str_match( "thread_limit", 1, value )
3361  || __kmp_str_match( "thread-limit", 1, value )
3362  || __kmp_str_match( "threadlimit", 1, value )
3363  || __kmp_str_match( "limit", 2, value ) ) {
3364  __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3365  }
3366  else if ( __kmp_str_match( "random", 1, value ) ) {
3367  __kmp_global.g.g_dynamic_mode = dynamic_random;
3368  }
3369  else {
3370  KMP_WARNING( StgInvalidValue, name, value );
3371  }
3372 } //__kmp_stg_parse_kmp_dynamic_mode
3373 
3374 static void
3375 __kmp_stg_print_kmp_dynamic_mode( kmp_str_buf_t * buffer, char const * name, void * data )
3376 {
3377 #if KMP_DEBUG
3378  if ( __kmp_global.g.g_dynamic_mode == dynamic_default ) {
3379  __kmp_str_buf_print( buffer, " %s: %s \n", name, KMP_I18N_STR( NotDefined ) );
3380  }
3381 # ifdef USE_LOAD_BALANCE
3382  else if ( __kmp_global.g.g_dynamic_mode == dynamic_load_balance ) {
3383  __kmp_stg_print_str( buffer, name, "load balance" );
3384  }
3385 # endif /* USE_LOAD_BALANCE */
3386  else if ( __kmp_global.g.g_dynamic_mode == dynamic_thread_limit ) {
3387  __kmp_stg_print_str( buffer, name, "thread limit" );
3388  }
3389  else if ( __kmp_global.g.g_dynamic_mode == dynamic_random ) {
3390  __kmp_stg_print_str( buffer, name, "random" );
3391  }
3392  else {
3393  KMP_ASSERT(0);
3394  }
3395 #endif /* KMP_DEBUG */
3396 } // __kmp_stg_print_kmp_dynamic_mode
3397 
3398 
3399 #ifdef USE_LOAD_BALANCE
3400 
3401 // -------------------------------------------------------------------------------------------------
3402 // KMP_LOAD_BALANCE_INTERVAL
3403 // -------------------------------------------------------------------------------------------------
3404 
3405 static void
3406 __kmp_stg_parse_ld_balance_interval( char const * name, char const * value, void * data )
3407 {
3408  double interval = __kmp_convert_to_double( value );
3409  if ( interval >= 0 ) {
3410  __kmp_load_balance_interval = interval;
3411  } else {
3412  KMP_WARNING( StgInvalidValue, name, value );
3413  }; // if
3414 } // __kmp_stg_parse_load_balance_interval
3415 
3416 static void
3417 __kmp_stg_print_ld_balance_interval( kmp_str_buf_t * buffer, char const * name, void * data ) {
3418 #if KMP_DEBUG
3419  __kmp_str_buf_print( buffer, " %s=%8.6f\n", name, __kmp_load_balance_interval );
3420 #endif /* KMP_DEBUG */
3421 } // __kmp_stg_print_load_balance_interval
3422 
3423 #endif /* USE_LOAD_BALANCE */
3424 
3425 // -------------------------------------------------------------------------------------------------
3426 // KMP_INIT_AT_FORK
3427 // -------------------------------------------------------------------------------------------------
3428 
3429 static void
3430 __kmp_stg_parse_init_at_fork( char const * name, char const * value, void * data ) {
3431  __kmp_stg_parse_bool( name, value, & __kmp_need_register_atfork );
3432  if ( __kmp_need_register_atfork ) {
3433  __kmp_need_register_atfork_specified = TRUE;
3434  };
3435 } // __kmp_stg_parse_init_at_fork
3436 
3437 static void
3438 __kmp_stg_print_init_at_fork( kmp_str_buf_t * buffer, char const * name, void * data ) {
3439  __kmp_stg_print_bool( buffer, name, __kmp_need_register_atfork_specified );
3440 } // __kmp_stg_print_init_at_fork
3441 
3442 // -------------------------------------------------------------------------------------------------
3443 // KMP_SCHEDULE
3444 // -------------------------------------------------------------------------------------------------
3445 
3446 static void
3447 __kmp_stg_parse_schedule( char const * name, char const * value, void * data ) {
3448 
3449  if ( value != NULL ) {
3450  size_t length = KMP_STRLEN( value );
3451  if ( length > INT_MAX ) {
3452  KMP_WARNING( LongValue, name );
3453  } else {
3454  char *semicolon;
3455  if( value[ length - 1 ] == '"' || value[ length -1 ] == '\'' )
3456  KMP_WARNING( UnbalancedQuotes, name );
3457  do {
3458  char sentinel;
3459 
3460  semicolon = (char *) strchr( value, ';' );
3461  if( *value && semicolon != value ) {
3462  char *comma = (char *) strchr( value, ',' );
3463 
3464  if ( comma ) {
3465  ++comma;
3466  sentinel = ',';
3467  } else
3468  sentinel = ';';
3469  if ( !__kmp_strcasecmp_with_sentinel( "static", value, sentinel ) ) {
3470  if( !__kmp_strcasecmp_with_sentinel( "greedy", comma, ';' ) ) {
3471  __kmp_static = kmp_sch_static_greedy;
3472  continue;
3473  } else if( !__kmp_strcasecmp_with_sentinel( "balanced", comma, ';' ) ) {
3474  __kmp_static = kmp_sch_static_balanced;
3475  continue;
3476  }
3477  } else if ( !__kmp_strcasecmp_with_sentinel( "guided", value, sentinel ) ) {
3478  if ( !__kmp_strcasecmp_with_sentinel( "iterative", comma, ';' ) ) {
3479  __kmp_guided = kmp_sch_guided_iterative_chunked;
3480  continue;
3481  } else if ( !__kmp_strcasecmp_with_sentinel( "analytical", comma, ';' ) ) {
3482  /* analytical not allowed for too many threads */
3483  __kmp_guided = kmp_sch_guided_analytical_chunked;
3484  continue;
3485  }
3486  }
3487  KMP_WARNING( InvalidClause, name, value );
3488  } else
3489  KMP_WARNING( EmptyClause, name );
3490  } while ( (value = semicolon ? semicolon + 1 : NULL) );
3491  }
3492  }; // if
3493 
3494 } // __kmp_stg_parse__schedule
3495 
3496 static void
3497 __kmp_stg_print_schedule( kmp_str_buf_t * buffer, char const * name, void * data ) {
3498  if( __kmp_env_format ) {
3499  KMP_STR_BUF_PRINT_NAME_EX(name);
3500  } else {
3501  __kmp_str_buf_print( buffer, " %s='", name );
3502  }
3503  if ( __kmp_static == kmp_sch_static_greedy ) {
3504  __kmp_str_buf_print( buffer, "%s", "static,greedy");
3505  } else if ( __kmp_static == kmp_sch_static_balanced ) {
3506  __kmp_str_buf_print ( buffer, "%s", "static,balanced");
3507  }
3508  if ( __kmp_guided == kmp_sch_guided_iterative_chunked ) {
3509  __kmp_str_buf_print( buffer, ";%s'\n", "guided,iterative");
3510  } else if ( __kmp_guided == kmp_sch_guided_analytical_chunked ) {
3511  __kmp_str_buf_print( buffer, ";%s'\n", "guided,analytical");
3512  }
3513 } // __kmp_stg_print_schedule
3514 
3515 // -------------------------------------------------------------------------------------------------
3516 // OMP_SCHEDULE
3517 // -------------------------------------------------------------------------------------------------
3518 
3519 static void
3520 __kmp_stg_parse_omp_schedule( char const * name, char const * value, void * data )
3521 {
3522  size_t length;
3523  if( value ) {
3524  length = KMP_STRLEN( value );
3525  if( length ) {
3526  char *comma = (char *) strchr( value, ',' );
3527  if( value[ length - 1 ] == '"' || value[ length -1 ] == '\'')
3528  KMP_WARNING( UnbalancedQuotes, name );
3529  /* get the specified scheduling style */
3530  if (!__kmp_strcasecmp_with_sentinel("dynamic", value, ',')) /* DYNAMIC */
3531  __kmp_sched = kmp_sch_dynamic_chunked;
3532  else if (!__kmp_strcasecmp_with_sentinel("guided", value, ',')) /* GUIDED */
3533  __kmp_sched = kmp_sch_guided_chunked;
3534 // AC: TODO: add AUTO schedule, and pprobably remove TRAPEZOIDAL (OMP 3.0 does not allow it)
3535  else if (!__kmp_strcasecmp_with_sentinel("auto", value, ',')) { /* AUTO */
3536  __kmp_sched = kmp_sch_auto;
3537  if( comma ) {
3538  __kmp_msg( kmp_ms_warning, KMP_MSG( IgnoreChunk, name, comma ), __kmp_msg_null );
3539  comma = NULL;
3540  }
3541  }
3542  else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", value, ',')) /* TRAPEZOIDAL */
3543  __kmp_sched = kmp_sch_trapezoidal;
3544  else if (!__kmp_strcasecmp_with_sentinel("static", value, ',')) /* STATIC */
3545  __kmp_sched = kmp_sch_static;
3546 #if KMP_STATIC_STEAL_ENABLED
3547  else if (!__kmp_strcasecmp_with_sentinel("static_steal", value, ','))
3548  __kmp_sched = kmp_sch_static_steal;
3549 #endif
3550  else {
3551  KMP_WARNING( StgInvalidValue, name, value );
3552  value = NULL; /* skip processing of comma */
3553  }
3554  if( value && comma ) {
3555  __kmp_env_chunk = TRUE;
3556 
3557  if(__kmp_sched == kmp_sch_static)
3558  __kmp_sched = kmp_sch_static_chunked;
3559  ++comma;
3560  __kmp_chunk = __kmp_str_to_int( comma, 0 );
3561  if ( __kmp_chunk < 1 ) {
3562  __kmp_chunk = KMP_DEFAULT_CHUNK;
3563  __kmp_msg( kmp_ms_warning, KMP_MSG( InvalidChunk, name, comma ), __kmp_msg_null );
3564  KMP_INFORM( Using_int_Value, name, __kmp_chunk );
3565 // AC: next block commented out until KMP_DEFAULT_CHUNK != KMP_MIN_CHUNK (to improve code coverage :)
3566 // The default chunk size is 1 according to standard, thus making KMP_MIN_CHUNK not 1 we would introduce mess:
3567 // wrong chunk becomes 1, but it will be impossible to explicitely set 1, because it becomes KMP_MIN_CHUNK...
3568 // } else if ( __kmp_chunk < KMP_MIN_CHUNK ) {
3569 // __kmp_chunk = KMP_MIN_CHUNK;
3570  } else if ( __kmp_chunk > KMP_MAX_CHUNK ) {
3571  __kmp_chunk = KMP_MAX_CHUNK;
3572  __kmp_msg( kmp_ms_warning, KMP_MSG( LargeChunk, name, comma ), __kmp_msg_null );
3573  KMP_INFORM( Using_int_Value, name, __kmp_chunk );
3574  }
3575  } else
3576  __kmp_env_chunk = FALSE;
3577  } else
3578  KMP_WARNING( EmptyString, name );
3579  }
3580  K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
3581  K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
3582  K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
3583  K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
3584 } // __kmp_stg_parse_omp_schedule
3585 
3586 static void
3587 __kmp_stg_print_omp_schedule( kmp_str_buf_t * buffer, char const * name, void * data ) {
3588  if( __kmp_env_format ) {
3589  KMP_STR_BUF_PRINT_NAME_EX(name);
3590  } else {
3591  __kmp_str_buf_print( buffer, " %s='", name );
3592  }
3593  if ( __kmp_chunk ) {
3594  switch ( __kmp_sched ) {
3595  case kmp_sch_dynamic_chunked:
3596  __kmp_str_buf_print( buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
3597  break;
3598  case kmp_sch_guided_iterative_chunked:
3599  case kmp_sch_guided_analytical_chunked:
3600  __kmp_str_buf_print( buffer, "%s,%d'\n", "guided", __kmp_chunk);
3601  break;
3602  case kmp_sch_trapezoidal:
3603  __kmp_str_buf_print( buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
3604  break;
3605  case kmp_sch_static:
3606  case kmp_sch_static_chunked:
3607  case kmp_sch_static_balanced:
3608  case kmp_sch_static_greedy:
3609  __kmp_str_buf_print( buffer, "%s,%d'\n", "static", __kmp_chunk);
3610  break;
3611  case kmp_sch_static_steal:
3612  __kmp_str_buf_print( buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
3613  break;
3614  case kmp_sch_auto:
3615  __kmp_str_buf_print( buffer, "%s,%d'\n", "auto", __kmp_chunk);
3616  break;
3617  }
3618  } else {
3619  switch ( __kmp_sched ) {
3620  case kmp_sch_dynamic_chunked:
3621  __kmp_str_buf_print( buffer, "%s'\n", "dynamic");
3622  break;
3623  case kmp_sch_guided_iterative_chunked:
3624  case kmp_sch_guided_analytical_chunked:
3625  __kmp_str_buf_print( buffer, "%s'\n", "guided");
3626  break;
3627  case kmp_sch_trapezoidal:
3628  __kmp_str_buf_print( buffer, "%s'\n", "trapezoidal");
3629  break;
3630  case kmp_sch_static:
3631  case kmp_sch_static_chunked:
3632  case kmp_sch_static_balanced:
3633  case kmp_sch_static_greedy:
3634  __kmp_str_buf_print( buffer, "%s'\n", "static");
3635  break;
3636  case kmp_sch_static_steal:
3637  __kmp_str_buf_print( buffer, "%s'\n", "static_steal");
3638  break;
3639  case kmp_sch_auto:
3640  __kmp_str_buf_print( buffer, "%s'\n", "auto");
3641  break;
3642  }
3643  }
3644 } // __kmp_stg_print_omp_schedule
3645 
3646 // -------------------------------------------------------------------------------------------------
3647 // KMP_ATOMIC_MODE
3648 // -------------------------------------------------------------------------------------------------
3649 
3650 static void
3651 __kmp_stg_parse_atomic_mode( char const * name, char const * value, void * data ) {
3652  // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP compatibility mode.
3653  int mode = 0;
3654  int max = 1;
3655  #ifdef KMP_GOMP_COMPAT
3656  max = 2;
3657  #endif /* KMP_GOMP_COMPAT */
3658  __kmp_stg_parse_int( name, value, 0, max, & mode );
3659  // TODO; parse_int is not very suitable for this case. In case of overflow it is better to use
3660  // 0 rather that max value.
3661  if ( mode > 0 ) {
3662  __kmp_atomic_mode = mode;
3663  }; // if
3664 } // __kmp_stg_parse_atomic_mode
3665 
3666 static void
3667 __kmp_stg_print_atomic_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
3668  __kmp_stg_print_int( buffer, name, __kmp_atomic_mode );
3669 } // __kmp_stg_print_atomic_mode
3670 
3671 
3672 // -------------------------------------------------------------------------------------------------
3673 // KMP_CONSISTENCY_CHECK
3674 // -------------------------------------------------------------------------------------------------
3675 
3676 static void
3677 __kmp_stg_parse_consistency_check( char const * name, char const * value, void * data ) {
3678  if ( ! __kmp_strcasecmp_with_sentinel( "all", value, 0 ) ) {
3679  // Note, this will not work from kmp_set_defaults because th_cons stack was not allocated
3680  // for existed thread(s) thus the first __kmp_push_<construct> will break with assertion.
3681  // TODO: allocate th_cons if called from kmp_set_defaults.
3682  __kmp_env_consistency_check = TRUE;
3683  } else if ( ! __kmp_strcasecmp_with_sentinel( "none", value, 0 ) ) {
3684  __kmp_env_consistency_check = FALSE;
3685  } else {
3686  KMP_WARNING( StgInvalidValue, name, value );
3687  }; // if
3688 } // __kmp_stg_parse_consistency_check
3689 
3690 static void
3691 __kmp_stg_print_consistency_check( kmp_str_buf_t * buffer, char const * name, void * data ) {
3692 #if KMP_DEBUG
3693  const char *value = NULL;
3694 
3695  if ( __kmp_env_consistency_check ) {
3696  value = "all";
3697  } else {
3698  value = "none";
3699  }
3700 
3701  if ( value != NULL ) {
3702  __kmp_stg_print_str( buffer, name, value );
3703  }
3704 #endif /* KMP_DEBUG */
3705 } // __kmp_stg_print_consistency_check
3706 
3707 
3708 #if USE_ITT_BUILD
3709 // -------------------------------------------------------------------------------------------------
3710 // KMP_ITT_PREPARE_DELAY
3711 // -------------------------------------------------------------------------------------------------
3712 
3713 #if USE_ITT_NOTIFY
3714 
3715 static void
3716 __kmp_stg_parse_itt_prepare_delay( char const * name, char const * value, void * data )
3717 {
3718  // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop iterations.
3719  int delay = 0;
3720  __kmp_stg_parse_int( name, value, 0, INT_MAX, & delay );
3721  __kmp_itt_prepare_delay = delay;
3722 } // __kmp_str_parse_itt_prepare_delay
3723 
3724 static void
3725 __kmp_stg_print_itt_prepare_delay( kmp_str_buf_t * buffer, char const * name, void * data ) {
3726  __kmp_stg_print_uint64( buffer, name, __kmp_itt_prepare_delay );
3727 
3728 } // __kmp_str_print_itt_prepare_delay
3729 
3730 #endif // USE_ITT_NOTIFY
3731 #endif /* USE_ITT_BUILD */
3732 
3733 // -------------------------------------------------------------------------------------------------
3734 // KMP_MALLOC_POOL_INCR
3735 // -------------------------------------------------------------------------------------------------
3736 
3737 static void
3738 __kmp_stg_parse_malloc_pool_incr( char const * name, char const * value, void * data ) {
3739  __kmp_stg_parse_size(
3740  name,
3741  value,
3742  KMP_MIN_MALLOC_POOL_INCR,
3743  KMP_MAX_MALLOC_POOL_INCR,
3744  NULL,
3745  & __kmp_malloc_pool_incr,
3746  1
3747  );
3748 } // __kmp_stg_parse_malloc_pool_incr
3749 
3750 static void
3751 __kmp_stg_print_malloc_pool_incr( kmp_str_buf_t * buffer, char const * name, void * data ) {
3752  __kmp_stg_print_size( buffer, name, __kmp_malloc_pool_incr );
3753 
3754 } // _kmp_stg_print_malloc_pool_incr
3755 
3756 
3757 #ifdef KMP_DEBUG
3758 
3759 // -------------------------------------------------------------------------------------------------
3760 // KMP_PAR_RANGE
3761 // -------------------------------------------------------------------------------------------------
3762 
3763 static void
3764 __kmp_stg_parse_par_range_env( char const * name, char const * value, void * data ) {
3765  __kmp_stg_parse_par_range(
3766  name,
3767  value,
3768  & __kmp_par_range,
3769  __kmp_par_range_routine,
3770  __kmp_par_range_filename,
3771  & __kmp_par_range_lb,
3772  & __kmp_par_range_ub
3773  );
3774 } // __kmp_stg_parse_par_range_env
3775 
3776 static void
3777 __kmp_stg_print_par_range_env( kmp_str_buf_t * buffer, char const * name, void * data ) {
3778  if (__kmp_par_range != 0) {
3779  __kmp_stg_print_str( buffer, name, par_range_to_print );
3780  }
3781 } // __kmp_stg_print_par_range_env
3782 
3783 // -------------------------------------------------------------------------------------------------
3784 // KMP_YIELD_CYCLE, KMP_YIELD_ON, KMP_YIELD_OFF
3785 // -------------------------------------------------------------------------------------------------
3786 
3787 static void
3788 __kmp_stg_parse_yield_cycle( char const * name, char const * value, void * data ) {
3789  int flag = __kmp_yield_cycle;
3790  __kmp_stg_parse_bool( name, value, & flag );
3791  __kmp_yield_cycle = flag;
3792 } // __kmp_stg_parse_yield_cycle
3793 
3794 static void
3795 __kmp_stg_print_yield_cycle( kmp_str_buf_t * buffer, char const * name, void * data ) {
3796  __kmp_stg_print_bool( buffer, name, __kmp_yield_cycle );
3797 } // __kmp_stg_print_yield_cycle
3798 
3799 static void
3800 __kmp_stg_parse_yield_on( char const * name, char const * value, void * data ) {
3801  __kmp_stg_parse_int( name, value, 2, INT_MAX, & __kmp_yield_on_count );
3802 } // __kmp_stg_parse_yield_on
3803 
3804 static void
3805 __kmp_stg_print_yield_on( kmp_str_buf_t * buffer, char const * name, void * data ) {
3806  __kmp_stg_print_int( buffer, name, __kmp_yield_on_count );
3807 } // __kmp_stg_print_yield_on
3808 
3809 static void
3810 __kmp_stg_parse_yield_off( char const * name, char const * value, void * data ) {
3811  __kmp_stg_parse_int( name, value, 2, INT_MAX, & __kmp_yield_off_count );
3812 } // __kmp_stg_parse_yield_off
3813 
3814 static void
3815 __kmp_stg_print_yield_off( kmp_str_buf_t * buffer, char const * name, void * data ) {
3816  __kmp_stg_print_int( buffer, name, __kmp_yield_off_count );
3817 } // __kmp_stg_print_yield_off
3818 
3819 #endif
3820 
3821 // -------------------------------------------------------------------------------------------------
3822 // KMP_INIT_WAIT, KMP_NEXT_WAIT
3823 // -------------------------------------------------------------------------------------------------
3824 
3825 static void
3826 __kmp_stg_parse_init_wait( char const * name, char const * value, void * data ) {
3827  int wait;
3828  KMP_ASSERT( ( __kmp_init_wait & 1 ) == 0 );
3829  wait = __kmp_init_wait / 2;
3830  __kmp_stg_parse_int( name, value, KMP_MIN_INIT_WAIT, KMP_MAX_INIT_WAIT, & wait );
3831  __kmp_init_wait = wait * 2;
3832  KMP_ASSERT( ( __kmp_init_wait & 1 ) == 0 );
3833  __kmp_yield_init = __kmp_init_wait;
3834 } // __kmp_stg_parse_init_wait
3835 
3836 static void
3837 __kmp_stg_print_init_wait( kmp_str_buf_t * buffer, char const * name, void * data ) {
3838  __kmp_stg_print_int( buffer, name, __kmp_init_wait );
3839 } // __kmp_stg_print_init_wait
3840 
3841 static void
3842 __kmp_stg_parse_next_wait( char const * name, char const * value, void * data ) {
3843  int wait;
3844  KMP_ASSERT( ( __kmp_next_wait & 1 ) == 0 );
3845  wait = __kmp_next_wait / 2;
3846  __kmp_stg_parse_int( name, value, KMP_MIN_NEXT_WAIT, KMP_MAX_NEXT_WAIT, & wait );
3847  __kmp_next_wait = wait * 2;
3848  KMP_ASSERT( ( __kmp_next_wait & 1 ) == 0 );
3849  __kmp_yield_next = __kmp_next_wait;
3850 } // __kmp_stg_parse_next_wait
3851 
3852 static void
3853 __kmp_stg_print_next_wait( kmp_str_buf_t * buffer, char const * name, void * data ) {
3854  __kmp_stg_print_int( buffer, name, __kmp_next_wait );
3855 } //__kmp_stg_print_next_wait
3856 
3857 
3858 // -------------------------------------------------------------------------------------------------
3859 // KMP_GTID_MODE
3860 // -------------------------------------------------------------------------------------------------
3861 
3862 static void
3863 __kmp_stg_parse_gtid_mode( char const * name, char const * value, void * data ) {
3864  //
3865  // Modes:
3866  // 0 -- do not change default
3867  // 1 -- sp search
3868  // 2 -- use "keyed" TLS var, i.e.
3869  // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
3870  // 3 -- __declspec(thread) TLS var in tdata section
3871  //
3872  int mode = 0;
3873  int max = 2;
3874  #ifdef KMP_TDATA_GTID
3875  max = 3;
3876  #endif /* KMP_TDATA_GTID */
3877  __kmp_stg_parse_int( name, value, 0, max, & mode );
3878  // TODO; parse_int is not very suitable for this case. In case of overflow it is better to use
3879  // 0 rather that max value.
3880  if ( mode == 0 ) {
3881  __kmp_adjust_gtid_mode = TRUE;
3882  }
3883  else {
3884  __kmp_gtid_mode = mode;
3885  __kmp_adjust_gtid_mode = FALSE;
3886  }; // if
3887 } // __kmp_str_parse_gtid_mode
3888 
3889 static void
3890 __kmp_stg_print_gtid_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
3891  if ( __kmp_adjust_gtid_mode ) {
3892  __kmp_stg_print_int( buffer, name, 0 );
3893  }
3894  else {
3895  __kmp_stg_print_int( buffer, name, __kmp_gtid_mode );
3896  }
3897 } // __kmp_stg_print_gtid_mode
3898 
3899 // -------------------------------------------------------------------------------------------------
3900 // KMP_NUM_LOCKS_IN_BLOCK
3901 // -------------------------------------------------------------------------------------------------
3902 
3903 static void
3904 __kmp_stg_parse_lock_block( char const * name, char const * value, void * data ) {
3905  __kmp_stg_parse_int( name, value, 0, KMP_INT_MAX, & __kmp_num_locks_in_block );
3906 } // __kmp_str_parse_lock_block
3907 
3908 static void
3909 __kmp_stg_print_lock_block( kmp_str_buf_t * buffer, char const * name, void * data ) {
3910  __kmp_stg_print_int( buffer, name, __kmp_num_locks_in_block );
3911 } // __kmp_stg_print_lock_block
3912 
3913 // -------------------------------------------------------------------------------------------------
3914 // KMP_LOCK_KIND
3915 // -------------------------------------------------------------------------------------------------
3916 
3917 #if KMP_USE_DYNAMIC_LOCK
3918 # define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
3919 #else
3920 # define KMP_STORE_LOCK_SEQ(a)
3921 #endif
3922 
3923 static void
3924 __kmp_stg_parse_lock_kind( char const * name, char const * value, void * data ) {
3925  if ( __kmp_init_user_locks ) {
3926  KMP_WARNING( EnvLockWarn, name );
3927  return;
3928  }
3929 
3930  if ( __kmp_str_match( "tas", 2, value )
3931  || __kmp_str_match( "test and set", 2, value )
3932  || __kmp_str_match( "test_and_set", 2, value )
3933  || __kmp_str_match( "test-and-set", 2, value )
3934  || __kmp_str_match( "test andset", 2, value )
3935  || __kmp_str_match( "test_andset", 2, value )
3936  || __kmp_str_match( "test-andset", 2, value )
3937  || __kmp_str_match( "testand set", 2, value )
3938  || __kmp_str_match( "testand_set", 2, value )
3939  || __kmp_str_match( "testand-set", 2, value )
3940  || __kmp_str_match( "testandset", 2, value ) ) {
3941  __kmp_user_lock_kind = lk_tas;
3942  KMP_STORE_LOCK_SEQ(tas);
3943  }
3944 #if KMP_USE_FUTEX
3945  else if ( __kmp_str_match( "futex", 1, value ) ) {
3946  if ( __kmp_futex_determine_capable() ) {
3947  __kmp_user_lock_kind = lk_futex;
3948  KMP_STORE_LOCK_SEQ(futex);
3949  }
3950  else {
3951  KMP_WARNING( FutexNotSupported, name, value );
3952  }
3953  }
3954 #endif
3955  else if ( __kmp_str_match( "ticket", 2, value ) ) {
3956  __kmp_user_lock_kind = lk_ticket;
3957  KMP_STORE_LOCK_SEQ(ticket);
3958  }
3959  else if ( __kmp_str_match( "queuing", 1, value )
3960  || __kmp_str_match( "queue", 1, value ) ) {
3961  __kmp_user_lock_kind = lk_queuing;
3962  KMP_STORE_LOCK_SEQ(queuing);
3963  }
3964  else if ( __kmp_str_match( "drdpa ticket", 1, value )
3965  || __kmp_str_match( "drdpa_ticket", 1, value )
3966  || __kmp_str_match( "drdpa-ticket", 1, value )
3967  || __kmp_str_match( "drdpaticket", 1, value )
3968  || __kmp_str_match( "drdpa", 1, value ) ) {
3969  __kmp_user_lock_kind = lk_drdpa;
3970  KMP_STORE_LOCK_SEQ(drdpa);
3971  }
3972 #if KMP_USE_ADAPTIVE_LOCKS
3973  else if ( __kmp_str_match( "adaptive", 1, value ) ) {
3974  if( __kmp_cpuinfo.rtm ) { // ??? Is cpuinfo available here?
3975  __kmp_user_lock_kind = lk_adaptive;
3976  KMP_STORE_LOCK_SEQ(adaptive);
3977  } else {
3978  KMP_WARNING( AdaptiveNotSupported, name, value );
3979  __kmp_user_lock_kind = lk_queuing;
3980  KMP_STORE_LOCK_SEQ(queuing);
3981  }
3982  }
3983 #endif // KMP_USE_ADAPTIVE_LOCKS
3984 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
3985  else if ( __kmp_str_match("rtm", 1, value) ) {
3986  if ( __kmp_cpuinfo.rtm ) {
3987  __kmp_user_lock_kind = lk_rtm;
3988  KMP_STORE_LOCK_SEQ(rtm);
3989  } else {
3990  KMP_WARNING( AdaptiveNotSupported, name, value );
3991  __kmp_user_lock_kind = lk_queuing;
3992  KMP_STORE_LOCK_SEQ(queuing);
3993  }
3994  }
3995  else if ( __kmp_str_match("hle", 1, value) ) {
3996  __kmp_user_lock_kind = lk_hle;
3997  KMP_STORE_LOCK_SEQ(hle);
3998  }
3999 #endif
4000  else {
4001  KMP_WARNING( StgInvalidValue, name, value );
4002  }
4003 }
4004 
4005 static void
4006 __kmp_stg_print_lock_kind( kmp_str_buf_t * buffer, char const * name, void * data ) {
4007  const char *value = NULL;
4008 
4009  switch ( __kmp_user_lock_kind ) {
4010  case lk_default:
4011  value = "default";
4012  break;
4013 
4014  case lk_tas:
4015  value = "tas";
4016  break;
4017 
4018 #if KMP_USE_FUTEX
4019  case lk_futex:
4020  value = "futex";
4021  break;
4022 #endif
4023 
4024 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4025  case lk_rtm:
4026  value = "rtm";
4027  break;
4028 
4029  case lk_hle:
4030  value = "hle";
4031  break;
4032 #endif
4033 
4034  case lk_ticket:
4035  value = "ticket";
4036  break;
4037 
4038  case lk_queuing:
4039  value = "queuing";
4040  break;
4041 
4042  case lk_drdpa:
4043  value = "drdpa";
4044  break;
4045 #if KMP_USE_ADAPTIVE_LOCKS
4046  case lk_adaptive:
4047  value = "adaptive";
4048  break;
4049 #endif
4050  }
4051 
4052  if ( value != NULL ) {
4053  __kmp_stg_print_str( buffer, name, value );
4054  }
4055 }
4056 
4057 // -------------------------------------------------------------------------------------------------
4058 // KMP_SPIN_BACKOFF_PARAMS
4059 // -------------------------------------------------------------------------------------------------
4060 
4061 // KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick for machine pause)
4062 static void
4063 __kmp_stg_parse_spin_backoff_params(const char* name, const char* value, void* data)
4064 {
4065  const char *next = value;
4066 
4067  int total = 0; // Count elements that were set. It'll be used as an array size
4068  int prev_comma = FALSE; // For correct processing sequential commas
4069  int i;
4070 
4071  kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
4072  kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
4073 
4074  // Run only 3 iterations because it is enough to read two values or find a syntax error
4075  for ( i = 0; i < 3 ; i++) {
4076  SKIP_WS( next );
4077 
4078  if ( *next == '\0' ) {
4079  break;
4080  }
4081  // Next character is not an integer or not a comma OR number of values > 2 => end of list
4082  if ( ( ( *next < '0' || *next > '9' ) && *next !=',' ) || total > 2 ) {
4083  KMP_WARNING( EnvSyntaxError, name, value );
4084  return;
4085  }
4086  // The next character is ','
4087  if ( *next == ',' ) {
4088  // ',' is the fisrt character
4089  if ( total == 0 || prev_comma ) {
4090  total++;
4091  }
4092  prev_comma = TRUE;
4093  next++; //skip ','
4094  SKIP_WS( next );
4095  }
4096  // Next character is a digit
4097  if ( *next >= '0' && *next <= '9' ) {
4098  int num;
4099  const char *buf = next;
4100  char const * msg = NULL;
4101  prev_comma = FALSE;
4102  SKIP_DIGITS( next );
4103  total++;
4104 
4105  const char *tmp = next;
4106  SKIP_WS( tmp );
4107  if ( ( *next == ' ' || *next == '\t' ) && ( *tmp >= '0' && *tmp <= '9' ) ) {
4108  KMP_WARNING( EnvSpacesNotAllowed, name, value );
4109  return;
4110  }
4111 
4112  num = __kmp_str_to_int( buf, *next );
4113  if ( num <= 0 ) { // The number of retries should be > 0
4114  msg = KMP_I18N_STR( ValueTooSmall );
4115  num = 1;
4116  } else if ( num > KMP_INT_MAX ) {
4117  msg = KMP_I18N_STR( ValueTooLarge );
4118  num = KMP_INT_MAX;
4119  }
4120  if ( msg != NULL ) {
4121  // Message is not empty. Print warning.
4122  KMP_WARNING( ParseSizeIntWarn, name, value, msg );
4123  KMP_INFORM( Using_int_Value, name, num );
4124  }
4125  if( total == 1 ) {
4126  max_backoff = num;
4127  } else if( total == 2 ) {
4128  min_tick = num;
4129  }
4130  }
4131  }
4132  KMP_DEBUG_ASSERT( total > 0 );
4133  if( total <= 0 ) {
4134  KMP_WARNING( EnvSyntaxError, name, value );
4135  return;
4136  }
4137  __kmp_spin_backoff_params.max_backoff = max_backoff;
4138  __kmp_spin_backoff_params.min_tick = min_tick;
4139 }
4140 
4141 static void
4142 __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer, char const* name, void* data)
4143 {
4144  if( __kmp_env_format ) {
4145  KMP_STR_BUF_PRINT_NAME_EX(name);
4146  } else {
4147  __kmp_str_buf_print( buffer, " %s='", name );
4148  }
4149  __kmp_str_buf_print( buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
4150  __kmp_spin_backoff_params.min_tick );
4151 }
4152 
4153 #if KMP_USE_ADAPTIVE_LOCKS
4154 
4155 // -------------------------------------------------------------------------------------------------
4156 // KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
4157 // -------------------------------------------------------------------------------------------------
4158 
4159 // Parse out values for the tunable parameters from a string of the form
4160 // KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
4161 static void
4162 __kmp_stg_parse_adaptive_lock_props( const char *name, const char *value, void *data )
4163 {
4164  int max_retries = 0;
4165  int max_badness = 0;
4166 
4167  const char *next = value;
4168 
4169  int total = 0; // Count elements that were set. It'll be used as an array size
4170  int prev_comma = FALSE; // For correct processing sequential commas
4171  int i;
4172 
4173  // Save values in the structure __kmp_speculative_backoff_params
4174  // Run only 3 iterations because it is enough to read two values or find a syntax error
4175  for ( i = 0; i < 3 ; i++) {
4176  SKIP_WS( next );
4177 
4178  if ( *next == '\0' ) {
4179  break;
4180  }
4181  // Next character is not an integer or not a comma OR number of values > 2 => end of list
4182  if ( ( ( *next < '0' || *next > '9' ) && *next !=',' ) || total > 2 ) {
4183  KMP_WARNING( EnvSyntaxError, name, value );
4184  return;
4185  }
4186  // The next character is ','
4187  if ( *next == ',' ) {
4188  // ',' is the fisrt character
4189  if ( total == 0 || prev_comma ) {
4190  total++;
4191  }
4192  prev_comma = TRUE;
4193  next++; //skip ','
4194  SKIP_WS( next );
4195  }
4196  // Next character is a digit
4197  if ( *next >= '0' && *next <= '9' ) {
4198  int num;
4199  const char *buf = next;
4200  char const * msg = NULL;
4201  prev_comma = FALSE;
4202  SKIP_DIGITS( next );
4203  total++;
4204 
4205  const char *tmp = next;
4206  SKIP_WS( tmp );
4207  if ( ( *next == ' ' || *next == '\t' ) && ( *tmp >= '0' && *tmp <= '9' ) ) {
4208  KMP_WARNING( EnvSpacesNotAllowed, name, value );
4209  return;
4210  }
4211 
4212  num = __kmp_str_to_int( buf, *next );
4213  if ( num < 0 ) { // The number of retries should be >= 0
4214  msg = KMP_I18N_STR( ValueTooSmall );
4215  num = 1;
4216  } else if ( num > KMP_INT_MAX ) {
4217  msg = KMP_I18N_STR( ValueTooLarge );
4218  num = KMP_INT_MAX;
4219  }
4220  if ( msg != NULL ) {
4221  // Message is not empty. Print warning.
4222  KMP_WARNING( ParseSizeIntWarn, name, value, msg );
4223  KMP_INFORM( Using_int_Value, name, num );
4224  }
4225  if( total == 1 ) {
4226  max_retries = num;
4227  } else if( total == 2 ) {
4228  max_badness = num;
4229  }
4230  }
4231  }
4232  KMP_DEBUG_ASSERT( total > 0 );
4233  if( total <= 0 ) {
4234  KMP_WARNING( EnvSyntaxError, name, value );
4235  return;
4236  }
4237  __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4238  __kmp_adaptive_backoff_params.max_badness = max_badness;
4239 }
4240 
4241 
4242 static void
4243 __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t * buffer, char const * name, void * data )
4244 {
4245  if( __kmp_env_format ) {
4246  KMP_STR_BUF_PRINT_NAME_EX(name);
4247  } else {
4248  __kmp_str_buf_print( buffer, " %s='", name );
4249  }
4250  __kmp_str_buf_print( buffer, "%d,%d'\n", __kmp_adaptive_backoff_params.max_soft_retries,
4251  __kmp_adaptive_backoff_params.max_badness );
4252 } // __kmp_stg_print_adaptive_lock_props
4253 
4254 #if KMP_DEBUG_ADAPTIVE_LOCKS
4255 
4256 static void
4257 __kmp_stg_parse_speculative_statsfile( char const * name, char const * value, void * data ) {
4258  __kmp_stg_parse_file( name, value, "", & __kmp_speculative_statsfile );
4259 } // __kmp_stg_parse_speculative_statsfile
4260 
4261 static void
4262 __kmp_stg_print_speculative_statsfile( kmp_str_buf_t * buffer, char const * name, void * data ) {
4263  if ( __kmp_str_match( "-", 0, __kmp_speculative_statsfile ) ) {
4264  __kmp_stg_print_str( buffer, name, "stdout" );
4265  } else {
4266  __kmp_stg_print_str( buffer, name, __kmp_speculative_statsfile );
4267  }
4268 
4269 } // __kmp_stg_print_speculative_statsfile
4270 
4271 #endif // KMP_DEBUG_ADAPTIVE_LOCKS
4272 
4273 #endif // KMP_USE_ADAPTIVE_LOCKS
4274 
4275 // -------------------------------------------------------------------------------------------------
4276 // KMP_HW_SUBSET (was KMP_PLACE_THREADS)
4277 // -------------------------------------------------------------------------------------------------
4278 
4279 static void
4280 __kmp_stg_parse_hw_subset( char const * name, char const * value, void * data ) {
4281  // Value example: 5Cx2Tx15O
4282  // Which means "use 5 cores with offset 15, 2 threads per core"
4283  // AC: extended to sockets level, examples of
4284  // "use 2 sockets with offset 6, 2 cores with offset 2 per socket, 2 threads per core":
4285  // 2s,6o,2c,2o,2t; 2s,6o,2c,2t,2o; 2s@6,2c@2,2t
4286  // To not break legacy code core-offset can be last;
4287  // postfix "o" or prefix @ can be offset designator.
4288  // Note: not all syntax errors are analyzed, some may be skipped.
4289 #define CHECK_DELIM(_x) (*(_x) == ',' || *(_x) == 'x')
4290  static int parsed = 0;
4291  int num;
4292  int single_warning = 0;
4293  int flagS = 0, flagC = 0, flagT = 0, flagSO = 0, flagCO = 0;
4294  const char *next = value;
4295  const char *prev;
4296 
4297  if( strcmp(name, "KMP_PLACE_THREADS") == 0 ) {
4298  KMP_INFORM(EnvVarDeprecated,name,"KMP_HW_SUBSET");
4299  if( parsed == 1 ) {
4300  return; // already parsed KMP_HW_SUBSET
4301  }
4302  }
4303  parsed = 1;
4304 
4305  SKIP_WS(next); // skip white spaces
4306  if (*next == '\0')
4307  return; // no data provided, retain default values
4308  if( strcmp(name, "KMP_PLACE_THREADS") == 0 ) {
4309  KMP_INFORM(EnvVarDeprecated,name,"KMP_HW_SUBSET");
4310  if( parsed == 1 ) {
4311  return; // already parsed KMP_HW_SUBSET
4312  }
4313  }
4314  parsed = 1;
4315 
4316  SKIP_WS(next); // skip white spaces
4317  if (*next == '\0')
4318  return; // no data provided, retain default values
4319  // Get num_sockets first (or whatever specified)
4320  if (*next >= '0' && *next <= '9') {
4321  prev = next;
4322  SKIP_DIGITS(next);
4323  num = __kmp_str_to_int(prev, *next);
4324  SKIP_WS(next);
4325  if (*next == 's' || *next == 'S') { // e.g. "2s"
4326  __kmp_place_num_sockets = num;
4327  flagS = 1; // got num sockets
4328  next++;
4329  if (*next == '@') { // socket offset, e.g. "2s@4"
4330  flagSO = 1;
4331  prev = ++next; // don't allow spaces for simplicity
4332  if (!(*next >= '0' && *next <= '9')) {
4333  KMP_WARNING(AffHWSubsetInvalid, name, value);
4334  return;
4335  }
4336  SKIP_DIGITS(next);
4337  num = __kmp_str_to_int(prev, *next);
4338  __kmp_place_socket_offset = num;
4339  }
4340  } else if (*next == 'c' || *next == 'C') {
4341  __kmp_place_num_cores = num;
4342  flagS = flagC = 1; // sockets were not specified - use default
4343  next++;
4344  if (*next == '@') { // core offset, e.g. "2c@6"
4345  flagCO = 1;
4346  prev = ++next; // don't allow spaces for simplicity
4347  if (!(*next >= '0' && *next <= '9')) {
4348  KMP_WARNING(AffHWSubsetInvalid, name, value);
4349  return;
4350  }
4351  SKIP_DIGITS(next);
4352  num = __kmp_str_to_int(prev, *next);
4353  __kmp_place_core_offset = num;
4354  }
4355  } else if (CHECK_DELIM(next)) {
4356  __kmp_place_num_cores = num; // no letter-designator - num cores
4357  flagS = flagC = 1; // sockets were not specified - use default
4358  next++;
4359  } else if (*next == 't' || *next == 'T') {
4360  __kmp_place_num_threads_per_core = num;
4361  // sockets, cores were not specified - use default
4362  return; // we ignore offset value in case all cores are used
4363  } else if (*next == '\0') {
4364  __kmp_place_num_cores = num;
4365  return; // the only value provided - set num cores
4366  } else {
4367  KMP_WARNING(AffHWSubsetInvalid, name, value);
4368  return;
4369  }
4370  } else {
4371  KMP_WARNING(AffHWSubsetInvalid, name, value);
4372  return;
4373  }
4374  KMP_DEBUG_ASSERT(flagS); // num sockets should already be set here
4375  SKIP_WS(next);
4376  if (*next == '\0')
4377  return; // " n " - something like this
4378  if (CHECK_DELIM(next)) {
4379  next++; // skip delimiter
4380  SKIP_WS(next);
4381  }
4382 
4383  // Get second value (could be offset, num_cores, num_threads)
4384  if (*next >= '0' && *next <= '9') {
4385  prev = next;
4386  SKIP_DIGITS(next);
4387  num = __kmp_str_to_int(prev, *next);
4388  SKIP_WS(next);
4389  if (*next == 'c' || *next == 'C') {
4390  KMP_DEBUG_ASSERT(flagC == 0);
4391  __kmp_place_num_cores = num;
4392  flagC = 1;
4393  next++;
4394  if (*next == '@') { // core offset, e.g. "2c@6"
4395  flagCO = 1;
4396  prev = ++next; // don't allow spaces for simplicity
4397  if (!(*next >= '0' && *next <= '9')) {
4398  KMP_WARNING(AffHWSubsetInvalid, name, value);
4399  return;
4400  }
4401  SKIP_DIGITS(next);
4402  num = __kmp_str_to_int(prev, *next);
4403  __kmp_place_core_offset = num;
4404  }
4405  } else if (*next == 'o' || *next == 'O') { // offset specified
4406  KMP_WARNING(AffHWSubsetDeprecated);
4407  single_warning = 1;
4408  if (flagC) { // whether num_cores already specified (sockets skipped)
4409  KMP_DEBUG_ASSERT(!flagCO); // either "o" or @, not both
4410  __kmp_place_core_offset = num;
4411  } else {
4412  KMP_DEBUG_ASSERT(!flagSO); // either "o" or @, not both
4413  __kmp_place_socket_offset = num;
4414  }
4415  next++;
4416  } else if (*next == 't' || *next == 'T') {
4417  KMP_DEBUG_ASSERT(flagT == 0);
4418  __kmp_place_num_threads_per_core = num;
4419  flagC = 1; // num_cores could be skipped ?
4420  flagT = 1;
4421  next++; // can have core-offset specified after num threads
4422  } else if (*next == '\0') {
4423  KMP_DEBUG_ASSERT(flagC); // 4x2 means 4 cores 2 threads per core
4424  __kmp_place_num_threads_per_core = num;
4425  return; // two values provided without letter-designator
4426  } else {
4427  KMP_WARNING(AffHWSubsetInvalid, name, value);
4428  return;
4429  }
4430  } else {
4431  KMP_WARNING(AffHWSubsetInvalid, name, value);
4432  return;
4433  }
4434  SKIP_WS(next);
4435  if (*next == '\0')
4436  return; // " Ns,Nc " - something like this
4437  if (CHECK_DELIM(next)) {
4438  next++; // skip delimiter
4439  SKIP_WS(next);
4440  }
4441 
4442  // Get third value (could be core-offset, num_cores, num_threads)
4443  if (*next >= '0' && *next <= '9') {
4444  prev = next;
4445  SKIP_DIGITS(next);
4446  num = __kmp_str_to_int(prev, *next);
4447  SKIP_WS(next);
4448  if (*next == 't' || *next == 'T') {
4449  KMP_DEBUG_ASSERT(flagT == 0);
4450  __kmp_place_num_threads_per_core = num;
4451  if (flagC == 0)
4452  return; // num_cores could be skipped (e.g. 2s,4o,2t)
4453  flagT = 1;
4454  next++; // can have core-offset specified later (e.g. 2s,1c,2t,3o)
4455  } else if (*next == 'c' || *next == 'C') {
4456  KMP_DEBUG_ASSERT(flagC == 0);
4457  __kmp_place_num_cores = num;
4458  flagC = 1;
4459  next++;
4460  //KMP_DEBUG_ASSERT(*next != '@'); // socket offset used "o" designator
4461  } else if (*next == 'o' || *next == 'O') {
4462  KMP_WARNING(AffHWSubsetDeprecated);
4463  single_warning = 1;
4464  KMP_DEBUG_ASSERT(flagC);
4465  //KMP_DEBUG_ASSERT(!flagSO); // socket offset couldn't use @ designator
4466  __kmp_place_core_offset = num;
4467  next++;
4468  } else {
4469  KMP_WARNING(AffHWSubsetInvalid, name, value);
4470  return;
4471  }
4472  } else {
4473  KMP_WARNING(AffHWSubsetInvalid, name, value);
4474  return;
4475  }
4476  KMP_DEBUG_ASSERT(flagC);
4477  SKIP_WS(next);
4478  if ( *next == '\0' )
4479  return;
4480  if (CHECK_DELIM(next)) {
4481  next++; // skip delimiter
4482  SKIP_WS(next);
4483  }
4484 
4485  // Get 4-th value (could be core-offset, num_threads)
4486  if (*next >= '0' && *next <= '9') {
4487  prev = next;
4488  SKIP_DIGITS(next);
4489  num = __kmp_str_to_int(prev, *next);
4490  SKIP_WS(next);
4491  if (*next == 'o' || *next == 'O') {
4492  if (!single_warning) { // warn once
4493  KMP_WARNING(AffHWSubsetDeprecated);
4494  }
4495  KMP_DEBUG_ASSERT(!flagSO); // socket offset couldn't use @ designator
4496  __kmp_place_core_offset = num;
4497  next++;
4498  } else if (*next == 't' || *next == 'T') {
4499  KMP_DEBUG_ASSERT(flagT == 0);
4500  __kmp_place_num_threads_per_core = num;
4501  flagT = 1;
4502  next++; // can have core-offset specified after num threads
4503  } else {
4504  KMP_WARNING(AffHWSubsetInvalid, name, value);
4505  return;
4506  }
4507  } else {
4508  KMP_WARNING(AffHWSubsetInvalid, name, value);
4509  return;
4510  }
4511  SKIP_WS(next);
4512  if ( *next == '\0' )
4513  return;
4514  if (CHECK_DELIM(next)) {
4515  next++; // skip delimiter
4516  SKIP_WS(next);
4517  }
4518 
4519  // Get 5-th value (could be core-offset, num_threads)
4520  if (*next >= '0' && *next <= '9') {
4521  prev = next;
4522  SKIP_DIGITS(next);
4523  num = __kmp_str_to_int(prev, *next);
4524  SKIP_WS(next);
4525  if (*next == 'o' || *next == 'O') {
4526  if (!single_warning) { // warn once
4527  KMP_WARNING(AffHWSubsetDeprecated);
4528  }
4529  KMP_DEBUG_ASSERT(flagT);
4530  KMP_DEBUG_ASSERT(!flagSO); // socket offset couldn't use @ designator
4531  __kmp_place_core_offset = num;
4532  } else if (*next == 't' || *next == 'T') {
4533  KMP_DEBUG_ASSERT(flagT == 0);
4534  __kmp_place_num_threads_per_core = num;
4535  } else {
4536  KMP_WARNING(AffHWSubsetInvalid, name, value);
4537  }
4538  } else {
4539  KMP_WARNING(AffHWSubsetInvalid, name, value);
4540  }
4541  return;
4542 #undef CHECK_DELIM
4543 }
4544 
4545 static void
4546 __kmp_stg_print_hw_subset( kmp_str_buf_t * buffer, char const * name, void * data ) {
4547  if (__kmp_place_num_sockets + __kmp_place_num_cores + __kmp_place_num_threads_per_core) {
4548  int comma = 0;
4549  kmp_str_buf_t buf;
4550  __kmp_str_buf_init(&buf);
4551  if(__kmp_env_format)
4552  KMP_STR_BUF_PRINT_NAME_EX(name);
4553  else
4554  __kmp_str_buf_print(buffer, " %s='", name);
4555  if (__kmp_place_num_sockets) {
4556  __kmp_str_buf_print(&buf, "%ds", __kmp_place_num_sockets);
4557  if (__kmp_place_socket_offset)
4558  __kmp_str_buf_print(&buf, "@%d", __kmp_place_socket_offset);
4559  comma = 1;
4560  }
4561  if (__kmp_place_num_cores) {
4562  __kmp_str_buf_print(&buf, "%s%dc", comma?",":"", __kmp_place_num_cores);
4563  if (__kmp_place_core_offset)
4564  __kmp_str_buf_print(&buf, "@%d", __kmp_place_core_offset);
4565  comma = 1;
4566  }
4567  if (__kmp_place_num_threads_per_core)
4568  __kmp_str_buf_print(&buf, "%s%dt", comma?",":"", __kmp_place_num_threads_per_core);
4569  __kmp_str_buf_print(buffer, "%s'\n", buf.str );
4570  __kmp_str_buf_free(&buf);
4571 /*
4572  } else {
4573  __kmp_str_buf_print( buffer, " %s: %s \n", name, KMP_I18N_STR( NotDefined ) );
4574 */
4575  }
4576 }
4577 
4578 #if USE_ITT_BUILD
4579 // -------------------------------------------------------------------------------------------------
4580 // KMP_FORKJOIN_FRAMES
4581 // -------------------------------------------------------------------------------------------------
4582 
4583 static void
4584 __kmp_stg_parse_forkjoin_frames( char const * name, char const * value, void * data ) {
4585  __kmp_stg_parse_bool( name, value, & __kmp_forkjoin_frames );
4586 } // __kmp_stg_parse_forkjoin_frames
4587 
4588 static void
4589 __kmp_stg_print_forkjoin_frames( kmp_str_buf_t * buffer, char const * name, void * data ) {
4590  __kmp_stg_print_bool( buffer, name, __kmp_forkjoin_frames );
4591 } // __kmp_stg_print_forkjoin_frames
4592 
4593 // -------------------------------------------------------------------------------------------------
4594 // KMP_FORKJOIN_FRAMES_MODE
4595 // -------------------------------------------------------------------------------------------------
4596 
4597 static void
4598 __kmp_stg_parse_forkjoin_frames_mode( char const * name, char const * value, void * data ) {
4599  __kmp_stg_parse_int( name, value, 0, 3, & __kmp_forkjoin_frames_mode );
4600 } // __kmp_stg_parse_forkjoin_frames
4601 
4602 static void
4603 __kmp_stg_print_forkjoin_frames_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
4604  __kmp_stg_print_int( buffer, name, __kmp_forkjoin_frames_mode );
4605 } // __kmp_stg_print_forkjoin_frames
4606 #endif /* USE_ITT_BUILD */
4607 
4608 // -------------------------------------------------------------------------------------------------
4609 // OMP_DISPLAY_ENV
4610 // -------------------------------------------------------------------------------------------------
4611 
4612 #if OMP_40_ENABLED
4613 
4614 static void
4615 __kmp_stg_parse_omp_display_env( char const * name, char const * value, void * data )
4616 {
4617  if ( __kmp_str_match( "VERBOSE", 1, value ) )
4618  {
4619  __kmp_display_env_verbose = TRUE;
4620  } else {
4621  __kmp_stg_parse_bool( name, value, & __kmp_display_env );
4622  }
4623 
4624 } // __kmp_stg_parse_omp_display_env
4625 
4626 static void
4627 __kmp_stg_print_omp_display_env( kmp_str_buf_t * buffer, char const * name, void * data )
4628 {
4629  if ( __kmp_display_env_verbose )
4630  {
4631  __kmp_stg_print_str( buffer, name, "VERBOSE" );
4632  } else {
4633  __kmp_stg_print_bool( buffer, name, __kmp_display_env );
4634  }
4635 } // __kmp_stg_print_omp_display_env
4636 
4637 static void
4638 __kmp_stg_parse_omp_cancellation( char const * name, char const * value, void * data ) {
4639  if ( TCR_4(__kmp_init_parallel) ) {
4640  KMP_WARNING( EnvParallelWarn, name );
4641  return;
4642  } // read value before first parallel only
4643  __kmp_stg_parse_bool( name, value, & __kmp_omp_cancellation );
4644 } // __kmp_stg_parse_omp_cancellation
4645 
4646 static void
4647 __kmp_stg_print_omp_cancellation( kmp_str_buf_t * buffer, char const * name, void * data ) {
4648  __kmp_stg_print_bool( buffer, name, __kmp_omp_cancellation );
4649 } // __kmp_stg_print_omp_cancellation
4650 
4651 #endif
4652 
4653 // -------------------------------------------------------------------------------------------------
4654 // Table.
4655 // -------------------------------------------------------------------------------------------------
4656 
4657 
4658 static kmp_setting_t __kmp_stg_table[] = {
4659 
4660  { "KMP_ALL_THREADS", __kmp_stg_parse_all_threads, __kmp_stg_print_all_threads, NULL, 0, 0 },
4661  { "KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime, NULL, 0, 0 },
4662  { "KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok, __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0 },
4663  { "KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy, NULL, 0, 0 },
4664  { "KMP_MAX_THREADS", __kmp_stg_parse_all_threads, NULL, NULL, 0, 0 }, // For backward compatibility
4665  { "KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize, __kmp_stg_print_monitor_stacksize, NULL, 0, 0 },
4666  { "KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL, 0, 0 },
4667  { "KMP_STACKOFFSET", __kmp_stg_parse_stackoffset, __kmp_stg_print_stackoffset, NULL, 0, 0 },
4668  { "KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize, NULL, 0, 0 },
4669  { "KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL, 0, 0 },
4670  { "KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0, 0 },
4671  { "KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL, 0, 0 },
4672 
4673  { "OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0 },
4674  { "OMP_NUM_THREADS", __kmp_stg_parse_num_threads, __kmp_stg_print_num_threads, NULL, 0, 0 },
4675  { "OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize, NULL, 0, 0 },
4676 
4677  { "KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0, 0 },
4678  { "KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing, __kmp_stg_print_task_stealing, NULL, 0, 0 },
4679  { "OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels, __kmp_stg_print_max_active_levels, NULL, 0, 0 },
4680 #if OMP_45_ENABLED
4681  { "OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority, __kmp_stg_print_max_task_priority, NULL, 0, 0 },
4682 #endif
4683  { "OMP_THREAD_LIMIT", __kmp_stg_parse_all_threads, __kmp_stg_print_all_threads, NULL, 0, 0 },
4684  { "OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy, NULL, 0, 0 },
4685  { "KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers, __kmp_stg_print_disp_buffers, NULL, 0, 0 },
4686 #if KMP_NESTED_HOT_TEAMS
4687  { "KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level, __kmp_stg_print_hot_teams_level, NULL, 0, 0 },
4688  { "KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode, __kmp_stg_print_hot_teams_mode, NULL, 0, 0 },
4689 #endif // KMP_NESTED_HOT_TEAMS
4690 
4691 #if KMP_HANDLE_SIGNALS
4692  { "KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals, __kmp_stg_print_handle_signals, NULL, 0, 0 },
4693 #endif
4694 
4695 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
4696  { "KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control, __kmp_stg_print_inherit_fp_control, NULL, 0, 0 },
4697 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
4698 
4699 #ifdef KMP_GOMP_COMPAT
4700  { "GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0 },
4701 #endif
4702 
4703 #ifdef KMP_DEBUG
4704  { "KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0, 0 },
4705  { "KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0, 0 },
4706  { "KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0, 0 },
4707  { "KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0, 0 },
4708  { "KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0, 0 },
4709  { "KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0, 0 },
4710  { "KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0 },
4711  { "KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf, NULL, 0, 0 },
4712  { "KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic, __kmp_stg_print_debug_buf_atomic, NULL, 0, 0 },
4713  { "KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars, __kmp_stg_print_debug_buf_chars, NULL, 0, 0 },
4714  { "KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines, __kmp_stg_print_debug_buf_lines, NULL, 0, 0 },
4715  { "KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0 },
4716 
4717  { "KMP_PAR_RANGE", __kmp_stg_parse_par_range_env, __kmp_stg_print_par_range_env, NULL, 0, 0 },
4718  { "KMP_YIELD_CYCLE", __kmp_stg_parse_yield_cycle, __kmp_stg_print_yield_cycle, NULL, 0, 0 },
4719  { "KMP_YIELD_ON", __kmp_stg_parse_yield_on, __kmp_stg_print_yield_on, NULL, 0, 0 },
4720  { "KMP_YIELD_OFF", __kmp_stg_parse_yield_off, __kmp_stg_print_yield_off, NULL, 0, 0 },
4721 #endif // KMP_DEBUG
4722 
4723  { "KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc, __kmp_stg_print_align_alloc, NULL, 0, 0 },
4724 
4725  { "KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit, __kmp_stg_print_barrier_branch_bit, NULL, 0, 0 },
4726  { "KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, __kmp_stg_print_barrier_pattern, NULL, 0, 0 },
4727  { "KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit, __kmp_stg_print_barrier_branch_bit, NULL, 0, 0 },
4728  { "KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, __kmp_stg_print_barrier_pattern, NULL, 0, 0 },
4729 #if KMP_FAST_REDUCTION_BARRIER
4730  { "KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit, __kmp_stg_print_barrier_branch_bit, NULL, 0, 0 },
4731  { "KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, __kmp_stg_print_barrier_pattern, NULL, 0, 0 },
4732 #endif
4733 
4734  { "KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay, __kmp_stg_print_abort_delay, NULL, 0, 0 },
4735  { "KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file, __kmp_stg_print_cpuinfo_file, NULL, 0, 0 },
4736  { "KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction, __kmp_stg_print_force_reduction, NULL, 0, 0 },
4737  { "KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction, __kmp_stg_print_force_reduction, NULL, 0, 0 },
4738  { "KMP_STORAGE_MAP", __kmp_stg_parse_storage_map, __kmp_stg_print_storage_map, NULL, 0, 0 },
4739  { "KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate, __kmp_stg_print_all_threadprivate, NULL, 0, 0 },
4740  { "KMP_FOREIGN_THREADS_THREADPRIVATE", __kmp_stg_parse_foreign_threads_threadprivate, __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0 },
4741 
4742 #if KMP_AFFINITY_SUPPORTED
4743  { "KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL, 0, 0 },
4744 # ifdef KMP_GOMP_COMPAT
4745  { "GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL, /* no print */ NULL, 0, 0 },
4746 # endif /* KMP_GOMP_COMPAT */
4747 # if OMP_40_ENABLED
4748  { "OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind, NULL, 0, 0 },
4749  { "OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0 },
4750 # else
4751  { "OMP_PROC_BIND", __kmp_stg_parse_proc_bind, NULL, /* no print */ NULL, 0, 0 },
4752 # endif /* OMP_40_ENABLED */
4753 
4754  { "KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method, __kmp_stg_print_topology_method, NULL, 0, 0 },
4755 
4756 #else
4757 
4758  //
4759  // KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
4760  // OMP_PROC_BIND and proc-bind-var are supported, however.
4761  //
4762 # if OMP_40_ENABLED
4763  { "OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind, NULL, 0, 0 },
4764 # endif
4765 
4766 #endif // KMP_AFFINITY_SUPPORTED
4767 
4768  { "KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork, __kmp_stg_print_init_at_fork, NULL, 0, 0 },
4769  { "KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL, 0, 0 },
4770  { "OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule, NULL, 0, 0 },
4771  { "KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode, __kmp_stg_print_atomic_mode, NULL, 0, 0 },
4772  { "KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check, __kmp_stg_print_consistency_check, NULL, 0, 0 },
4773 
4774 #if USE_ITT_BUILD && USE_ITT_NOTIFY
4775  { "KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay, __kmp_stg_print_itt_prepare_delay, NULL, 0, 0 },
4776 #endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
4777  { "KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr, __kmp_stg_print_malloc_pool_incr, NULL, 0, 0 },
4778  { "KMP_INIT_WAIT", __kmp_stg_parse_init_wait, __kmp_stg_print_init_wait, NULL, 0, 0 },
4779  { "KMP_NEXT_WAIT", __kmp_stg_parse_next_wait, __kmp_stg_print_next_wait, NULL, 0, 0 },
4780  { "KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode, NULL, 0, 0 },
4781  { "OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic, NULL, 0, 0 },
4782  { "KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode, __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0 },
4783 
4784 #ifdef USE_LOAD_BALANCE
4785  { "KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,__kmp_stg_print_ld_balance_interval,NULL, 0, 0 },
4786 #endif
4787 
4788  { "KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block, __kmp_stg_print_lock_block, NULL, 0, 0 },
4789  { "KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind, NULL, 0, 0 },
4790  { "KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params, __kmp_stg_print_spin_backoff_params, NULL, 0, 0 },
4791 #if KMP_USE_ADAPTIVE_LOCKS
4792  { "KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,__kmp_stg_print_adaptive_lock_props, NULL, 0, 0 },
4793 #if KMP_DEBUG_ADAPTIVE_LOCKS
4794  { "KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,__kmp_stg_print_speculative_statsfile, NULL, 0, 0 },
4795 #endif
4796 #endif // KMP_USE_ADAPTIVE_LOCKS
4797  { "KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset, NULL, 0, 0 },
4798  { "KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset, NULL, 0, 0 },
4799 #if USE_ITT_BUILD
4800  { "KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames, __kmp_stg_print_forkjoin_frames, NULL, 0, 0 },
4801  { "KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,__kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0 },
4802 #endif
4803 
4804 # if OMP_40_ENABLED
4805  { "OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env, __kmp_stg_print_omp_display_env, NULL, 0, 0 },
4806  { "OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation, __kmp_stg_print_omp_cancellation, NULL, 0, 0 },
4807 #endif
4808  { "", NULL, NULL, NULL, 0, 0 }
4809 }; // settings
4810 
4811 static int const __kmp_stg_count = sizeof( __kmp_stg_table ) / sizeof( kmp_setting_t );
4812 
4813 static inline
4814 kmp_setting_t *
4815 __kmp_stg_find( char const * name ) {
4816 
4817  int i;
4818  if ( name != NULL ) {
4819  for ( i = 0; i < __kmp_stg_count; ++ i ) {
4820  if ( strcmp( __kmp_stg_table[ i ].name, name ) == 0 ) {
4821  return & __kmp_stg_table[ i ];
4822  }; // if
4823  }; // for
4824  }; // if
4825  return NULL;
4826 
4827 } // __kmp_stg_find
4828 
4829 
4830 static int
4831 __kmp_stg_cmp( void const * _a, void const * _b ) {
4832  kmp_setting_t * a = (kmp_setting_t *) _a;
4833  kmp_setting_t * b = (kmp_setting_t *) _b;
4834 
4835  //
4836  // Process KMP_AFFINITY last.
4837  // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
4838  //
4839  if ( strcmp( a->name, "KMP_AFFINITY" ) == 0 ) {
4840  if ( strcmp( b->name, "KMP_AFFINITY" ) == 0 ) {
4841  return 0;
4842  }
4843  return 1;
4844  }
4845  else if ( strcmp( b->name, "KMP_AFFINITY" ) == 0 ) {
4846  return -1;
4847  }
4848  return strcmp( a->name, b->name );
4849 } // __kmp_stg_cmp
4850 
4851 
4852 static void
4853 __kmp_stg_init( void
4854 ) {
4855 
4856  static int initialized = 0;
4857 
4858  if ( ! initialized ) {
4859 
4860  // Sort table.
4861  qsort( __kmp_stg_table, __kmp_stg_count - 1, sizeof( kmp_setting_t ), __kmp_stg_cmp );
4862 
4863  { // Initialize *_STACKSIZE data.
4864 
4865  kmp_setting_t * kmp_stacksize = __kmp_stg_find( "KMP_STACKSIZE" ); // 1st priority.
4866 #ifdef KMP_GOMP_COMPAT
4867  kmp_setting_t * gomp_stacksize = __kmp_stg_find( "GOMP_STACKSIZE" ); // 2nd priority.
4868 #endif
4869  kmp_setting_t * omp_stacksize = __kmp_stg_find( "OMP_STACKSIZE" ); // 3rd priority.
4870 
4871  // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4872  // !!! Compiler does not understand rivals is used and optimizes out assignments
4873  // !!! rivals[ i ++ ] = ...;
4874  static kmp_setting_t * volatile rivals[ 4 ];
4875  static kmp_stg_ss_data_t kmp_data = { 1, (kmp_setting_t **)rivals };
4876 #ifdef KMP_GOMP_COMPAT
4877  static kmp_stg_ss_data_t gomp_data = { 1024, (kmp_setting_t **)rivals };
4878 #endif
4879  static kmp_stg_ss_data_t omp_data = { 1024, (kmp_setting_t **)rivals };
4880  int i = 0;
4881 
4882  rivals[ i ++ ] = kmp_stacksize;
4883 #ifdef KMP_GOMP_COMPAT
4884  if ( gomp_stacksize != NULL ) {
4885  rivals[ i ++ ] = gomp_stacksize;
4886  }; // if
4887 #endif
4888  rivals[ i ++ ] = omp_stacksize;
4889  rivals[ i ++ ] = NULL;
4890 
4891  kmp_stacksize->data = & kmp_data;
4892 #ifdef KMP_GOMP_COMPAT
4893  if ( gomp_stacksize != NULL ) {
4894  gomp_stacksize->data = & gomp_data;
4895  }; // if
4896 #endif
4897  omp_stacksize->data = & omp_data;
4898 
4899  }
4900 
4901  { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
4902 
4903  kmp_setting_t * kmp_library = __kmp_stg_find( "KMP_LIBRARY" ); // 1st priority.
4904  kmp_setting_t * omp_wait_policy = __kmp_stg_find( "OMP_WAIT_POLICY" ); // 2nd priority.
4905 
4906  // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4907  static kmp_setting_t * volatile rivals[ 3 ];
4908  static kmp_stg_wp_data_t kmp_data = { 0, (kmp_setting_t **)rivals };
4909  static kmp_stg_wp_data_t omp_data = { 1, (kmp_setting_t **)rivals };
4910  int i = 0;
4911 
4912  rivals[ i ++ ] = kmp_library;
4913  if ( omp_wait_policy != NULL ) {
4914  rivals[ i ++ ] = omp_wait_policy;
4915  }; // if
4916  rivals[ i ++ ] = NULL;
4917 
4918  kmp_library->data = & kmp_data;
4919  if ( omp_wait_policy != NULL ) {
4920  omp_wait_policy->data = & omp_data;
4921  }; // if
4922 
4923  }
4924 
4925  { // Initialize KMP_ALL_THREADS, KMP_MAX_THREADS, and OMP_THREAD_LIMIT data.
4926 
4927  kmp_setting_t * kmp_all_threads = __kmp_stg_find( "KMP_ALL_THREADS" ); // 1st priority.
4928  kmp_setting_t * kmp_max_threads = __kmp_stg_find( "KMP_MAX_THREADS" ); // 2nd priority.
4929  kmp_setting_t * omp_thread_limit = __kmp_stg_find( "OMP_THREAD_LIMIT" ); // 3rd priority.
4930 
4931  // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4932  static kmp_setting_t * volatile rivals[ 4 ];
4933  int i = 0;
4934 
4935  rivals[ i ++ ] = kmp_all_threads;
4936  rivals[ i ++ ] = kmp_max_threads;
4937  if ( omp_thread_limit != NULL ) {
4938  rivals[ i ++ ] = omp_thread_limit;
4939  }; // if
4940  rivals[ i ++ ] = NULL;
4941 
4942  kmp_all_threads->data = (void*)& rivals;
4943  kmp_max_threads->data = (void*)& rivals;
4944  if ( omp_thread_limit != NULL ) {
4945  omp_thread_limit->data = (void*)& rivals;
4946  }; // if
4947 
4948  }
4949 
4950 #if KMP_AFFINITY_SUPPORTED
4951  { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
4952 
4953  kmp_setting_t * kmp_affinity = __kmp_stg_find( "KMP_AFFINITY" ); // 1st priority.
4954  KMP_DEBUG_ASSERT( kmp_affinity != NULL );
4955 
4956 # ifdef KMP_GOMP_COMPAT
4957  kmp_setting_t * gomp_cpu_affinity = __kmp_stg_find( "GOMP_CPU_AFFINITY" ); // 2nd priority.
4958  KMP_DEBUG_ASSERT( gomp_cpu_affinity != NULL );
4959 # endif
4960 
4961  kmp_setting_t * omp_proc_bind = __kmp_stg_find( "OMP_PROC_BIND" ); // 3rd priority.
4962  KMP_DEBUG_ASSERT( omp_proc_bind != NULL );
4963 
4964  // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4965  static kmp_setting_t * volatile rivals[ 4 ];
4966  int i = 0;
4967 
4968  rivals[ i ++ ] = kmp_affinity;
4969 
4970 # ifdef KMP_GOMP_COMPAT
4971  rivals[ i ++ ] = gomp_cpu_affinity;
4972  gomp_cpu_affinity->data = (void*)& rivals;
4973 # endif
4974 
4975  rivals[ i ++ ] = omp_proc_bind;
4976  omp_proc_bind->data = (void*)& rivals;
4977  rivals[ i ++ ] = NULL;
4978 
4979 # if OMP_40_ENABLED
4980  static kmp_setting_t * volatile places_rivals[ 4 ];
4981  i = 0;
4982 
4983  kmp_setting_t * omp_places = __kmp_stg_find( "OMP_PLACES" ); // 3rd priority.
4984  KMP_DEBUG_ASSERT( omp_places != NULL );
4985 
4986  places_rivals[ i ++ ] = kmp_affinity;
4987 # ifdef KMP_GOMP_COMPAT
4988  places_rivals[ i ++ ] = gomp_cpu_affinity;
4989 # endif
4990  places_rivals[ i ++ ] = omp_places;
4991  omp_places->data = (void*)& places_rivals;
4992  places_rivals[ i ++ ] = NULL;
4993 # endif
4994  }
4995 #else
4996  // KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
4997  // OMP_PLACES not supported yet.
4998 #endif // KMP_AFFINITY_SUPPORTED
4999 
5000  { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
5001 
5002  kmp_setting_t * kmp_force_red = __kmp_stg_find( "KMP_FORCE_REDUCTION" ); // 1st priority.
5003  kmp_setting_t * kmp_determ_red = __kmp_stg_find( "KMP_DETERMINISTIC_REDUCTION" ); // 2nd priority.
5004 
5005  // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
5006  static kmp_setting_t * volatile rivals[ 3 ];
5007  static kmp_stg_fr_data_t force_data = { 1, (kmp_setting_t **)rivals };
5008  static kmp_stg_fr_data_t determ_data = { 0, (kmp_setting_t **)rivals };
5009  int i = 0;
5010 
5011  rivals[ i ++ ] = kmp_force_red;
5012  if ( kmp_determ_red != NULL ) {
5013  rivals[ i ++ ] = kmp_determ_red;
5014  }; // if
5015  rivals[ i ++ ] = NULL;
5016 
5017  kmp_force_red->data = & force_data;
5018  if ( kmp_determ_red != NULL ) {
5019  kmp_determ_red->data = & determ_data;
5020  }; // if
5021  }
5022 
5023  initialized = 1;
5024 
5025  }; // if
5026 
5027  // Reset flags.
5028  int i;
5029  for ( i = 0; i < __kmp_stg_count; ++ i ) {
5030  __kmp_stg_table[ i ].set = 0;
5031  }; // for
5032 
5033 } // __kmp_stg_init
5034 
5035 
5036 static void
5037 __kmp_stg_parse(
5038  char const * name,
5039  char const * value
5040 ) {
5041 
5042  // On Windows* OS there are some nameless variables like "C:=C:\" (yeah, really nameless, they are
5043  // presented in environment block as "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
5044  if ( name[ 0 ] == 0 ) {
5045  return;
5046  }; // if
5047 
5048  if ( value != NULL ) {
5049  kmp_setting_t * setting = __kmp_stg_find( name );
5050  if ( setting != NULL ) {
5051  setting->parse( name, value, setting->data );
5052  setting->defined = 1;
5053  }; // if
5054  }; // if
5055 
5056 } // __kmp_stg_parse
5057 
5058 
5059 static int
5060 __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
5061  char const * name, // Name of variable.
5062  char const * value, // Value of the variable.
5063  kmp_setting_t * * rivals // List of rival settings (the list must include current one).
5064 ) {
5065 
5066  if ( rivals == NULL ) {
5067  return 0;
5068  }
5069 
5070  // Loop thru higher priority settings (listed before current).
5071  int i = 0;
5072  for ( ; strcmp( rivals[ i ]->name, name ) != 0; i++ ) {
5073  KMP_DEBUG_ASSERT( rivals[ i ] != NULL );
5074 
5075 #if KMP_AFFINITY_SUPPORTED
5076  if ( rivals[ i ] == __kmp_affinity_notype ) {
5077  //
5078  // If KMP_AFFINITY is specified without a type name,
5079  // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
5080  //
5081  continue;
5082  }
5083 #endif
5084 
5085  if ( rivals[ i ]->set ) {
5086  KMP_WARNING( StgIgnored, name, rivals[ i ]->name );
5087  return 1;
5088  }; // if
5089  }; // while
5090 
5091  ++ i; // Skip current setting.
5092  return 0;
5093 
5094 }; // __kmp_stg_check_rivals
5095 
5096 
5097 static int
5098 __kmp_env_toPrint( char const * name, int flag ) {
5099  int rc = 0;
5100  kmp_setting_t * setting = __kmp_stg_find( name );
5101  if ( setting != NULL ) {
5102  rc = setting->defined;
5103  if ( flag >= 0 ) {
5104  setting->defined = flag;
5105  }; // if
5106  }; // if
5107  return rc;
5108 }
5109 
5110 
5111 static void
5112 __kmp_aux_env_initialize( kmp_env_blk_t* block ) {
5113 
5114  char const * value;
5115 
5116  /* OMP_NUM_THREADS */
5117  value = __kmp_env_blk_var( block, "OMP_NUM_THREADS" );
5118  if ( value ) {
5119  ompc_set_num_threads( __kmp_dflt_team_nth );
5120  }
5121 
5122  /* KMP_BLOCKTIME */
5123  value = __kmp_env_blk_var( block, "KMP_BLOCKTIME" );
5124  if ( value ) {
5125  kmpc_set_blocktime( __kmp_dflt_blocktime );
5126  }
5127 
5128  /* OMP_NESTED */
5129  value = __kmp_env_blk_var( block, "OMP_NESTED" );
5130  if ( value ) {
5131  ompc_set_nested( __kmp_dflt_nested );
5132  }
5133 
5134  /* OMP_DYNAMIC */
5135  value = __kmp_env_blk_var( block, "OMP_DYNAMIC" );
5136  if ( value ) {
5137  ompc_set_dynamic( __kmp_global.g.g_dynamic );
5138  }
5139 
5140 }
5141 
5142 void
5143 __kmp_env_initialize( char const * string ) {
5144 
5145  kmp_env_blk_t block;
5146  int i;
5147 
5148  __kmp_stg_init();
5149 
5150  // Hack!!!
5151  if ( string == NULL ) {
5152  // __kmp_max_nth = __kmp_sys_max_nth;
5153  __kmp_threads_capacity = __kmp_initial_threads_capacity( __kmp_dflt_team_nth_ub );
5154  }; // if
5155  __kmp_env_blk_init( & block, string );
5156 
5157  //
5158  // update the set flag on all entries that have an env var
5159  //
5160  for ( i = 0; i < block.count; ++ i ) {
5161  if (( block.vars[ i ].name == NULL )
5162  || ( *block.vars[ i ].name == '\0')) {
5163  continue;
5164  }
5165  if ( block.vars[ i ].value == NULL ) {
5166  continue;
5167  }
5168  kmp_setting_t * setting = __kmp_stg_find( block.vars[ i ].name );
5169  if ( setting != NULL ) {
5170  setting->set = 1;
5171  }
5172  }; // for i
5173 
5174  // We need to know if blocktime was set when processing OMP_WAIT_POLICY
5175  blocktime_str = __kmp_env_blk_var( & block, "KMP_BLOCKTIME" );
5176 
5177  // Special case. If we parse environment, not a string, process KMP_WARNINGS first.
5178  if ( string == NULL ) {
5179  char const * name = "KMP_WARNINGS";
5180  char const * value = __kmp_env_blk_var( & block, name );
5181  __kmp_stg_parse( name, value );
5182  }; // if
5183 
5184 #if KMP_AFFINITY_SUPPORTED
5185  //
5186  // Special case. KMP_AFFINITY is not a rival to other affinity env vars
5187  // if no affinity type is specified. We want to allow
5188  // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
5189  // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
5190  // affinity mechanism.
5191  //
5192  __kmp_affinity_notype = NULL;
5193  char const *aff_str = __kmp_env_blk_var( & block, "KMP_AFFINITY" );
5194  if ( aff_str != NULL ) {
5195  //
5196  // Check if the KMP_AFFINITY type is specified in the string.
5197  // We just search the string for "compact", "scatter", etc.
5198  // without really parsing the string. The syntax of the
5199  // KMP_AFFINITY env var is such that none of the affinity
5200  // type names can appear anywhere other that the type
5201  // specifier, even as substrings.
5202  //
5203  // I can't find a case-insensitive version of strstr on Windows* OS.
5204  // Use the case-sensitive version for now.
5205  //
5206 
5207 # if KMP_OS_WINDOWS
5208 # define FIND strstr
5209 # else
5210 # define FIND strcasestr
5211 # endif
5212 
5213  if ( ( FIND( aff_str, "none" ) == NULL )
5214  && ( FIND( aff_str, "physical" ) == NULL )
5215  && ( FIND( aff_str, "logical" ) == NULL )
5216  && ( FIND( aff_str, "compact" ) == NULL )
5217  && ( FIND( aff_str, "scatter" ) == NULL )
5218  && ( FIND( aff_str, "explicit" ) == NULL )
5219  && ( FIND( aff_str, "balanced" ) == NULL )
5220  && ( FIND( aff_str, "disabled" ) == NULL ) ) {
5221  __kmp_affinity_notype = __kmp_stg_find( "KMP_AFFINITY" );
5222  }
5223  else {
5224  //
5225  // A new affinity type is specified.
5226  // Reset the affinity flags to their default values,
5227  // in case this is called from kmp_set_defaults().
5228  //
5229  __kmp_affinity_type = affinity_default;
5230  __kmp_affinity_gran = affinity_gran_default;
5231  __kmp_affinity_top_method = affinity_top_method_default;
5232  __kmp_affinity_respect_mask = affinity_respect_mask_default;
5233  }
5234 # undef FIND
5235 
5236 #if OMP_40_ENABLED
5237  //
5238  // Also reset the affinity flags if OMP_PROC_BIND is specified.
5239  //
5240  aff_str = __kmp_env_blk_var( & block, "OMP_PROC_BIND" );
5241  if ( aff_str != NULL ) {
5242  __kmp_affinity_type = affinity_default;
5243  __kmp_affinity_gran = affinity_gran_default;
5244  __kmp_affinity_top_method = affinity_top_method_default;
5245  __kmp_affinity_respect_mask = affinity_respect_mask_default;
5246  }
5247 #endif /* OMP_40_ENABLED */
5248  }
5249 
5250 #endif /* KMP_AFFINITY_SUPPORTED */
5251 
5252 #if OMP_40_ENABLED
5253  //
5254  // Set up the nested proc bind type vector.
5255  //
5256  if ( __kmp_nested_proc_bind.bind_types == NULL ) {
5257  __kmp_nested_proc_bind.bind_types = (kmp_proc_bind_t *)
5258  KMP_INTERNAL_MALLOC( sizeof(kmp_proc_bind_t) );
5259  if ( __kmp_nested_proc_bind.bind_types == NULL ) {
5260  KMP_FATAL( MemoryAllocFailed );
5261  }
5262  __kmp_nested_proc_bind.size = 1;
5263  __kmp_nested_proc_bind.used = 1;
5264 # if KMP_AFFINITY_SUPPORTED
5265  __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
5266 # else
5267  // default proc bind is false if affinity not supported
5268  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5269 # endif
5270 
5271  }
5272 #endif /* OMP_40_ENABLED */
5273 
5274  //
5275  // Now process all of the settings.
5276  //
5277  for ( i = 0; i < block.count; ++ i ) {
5278  __kmp_stg_parse( block.vars[ i ].name, block.vars[ i ].value );
5279  }; // for i
5280 
5281  //
5282  // If user locks have been allocated yet, don't reset the lock vptr table.
5283  //
5284  if ( ! __kmp_init_user_locks ) {
5285  if ( __kmp_user_lock_kind == lk_default ) {
5286  __kmp_user_lock_kind = lk_queuing;
5287  }
5288 #if KMP_USE_DYNAMIC_LOCK
5289  __kmp_init_dynamic_user_locks();
5290 #else
5291  __kmp_set_user_lock_vptrs( __kmp_user_lock_kind );
5292 #endif
5293  }
5294  else {
5295  KMP_DEBUG_ASSERT( string != NULL); // kmp_set_defaults() was called
5296  KMP_DEBUG_ASSERT( __kmp_user_lock_kind != lk_default );
5297  // Binds lock functions again to follow the transition between different
5298  // KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
5299  // as we do not allow lock kind changes after making a call to any
5300  // user lock functions (true).
5301 #if KMP_USE_DYNAMIC_LOCK
5302  __kmp_init_dynamic_user_locks();
5303 #else
5304  __kmp_set_user_lock_vptrs( __kmp_user_lock_kind );
5305 #endif
5306  }
5307 
5308 #if KMP_AFFINITY_SUPPORTED
5309 
5310  if ( ! TCR_4(__kmp_init_middle) ) {
5311  //
5312  // Determine if the machine/OS is actually capable of supporting
5313  // affinity.
5314  //
5315  const char *var = "KMP_AFFINITY";
5316 # if KMP_USE_HWLOC
5317  if(__kmp_hwloc_topology == NULL) {
5318  if(hwloc_topology_init(&__kmp_hwloc_topology) < 0) {
5319  __kmp_hwloc_error = TRUE;
5320  if(__kmp_affinity_verbose)
5321  KMP_WARNING(AffHwlocErrorOccurred, var, "hwloc_topology_init()");
5322  }
5323  if(hwloc_topology_load(__kmp_hwloc_topology) < 0) {
5324  __kmp_hwloc_error = TRUE;
5325  if(__kmp_affinity_verbose)
5326  KMP_WARNING(AffHwlocErrorOccurred, var, "hwloc_topology_load()");
5327  }
5328  }
5329 # endif
5330  if ( __kmp_affinity_type == affinity_disabled ) {
5331  KMP_AFFINITY_DISABLE();
5332  }
5333  else if ( ! KMP_AFFINITY_CAPABLE() ) {
5334 # if KMP_USE_HWLOC
5335  const hwloc_topology_support* topology_support = hwloc_topology_get_support(__kmp_hwloc_topology);
5336  // Is the system capable of setting/getting this thread's affinity?
5337  // also, is topology discovery possible? (pu indicates ability to discover processing units)
5338  // and finally, were there no errors when calling any hwloc_* API functions?
5339  if(topology_support && topology_support->cpubind->set_thisthread_cpubind &&
5340  topology_support->cpubind->get_thisthread_cpubind &&
5341  topology_support->discovery->pu &&
5342  !__kmp_hwloc_error)
5343  {
5344  // enables affinity according to KMP_AFFINITY_CAPABLE() macro
5345  KMP_AFFINITY_ENABLE(TRUE);
5346  } else {
5347  // indicate that hwloc didn't work and disable affinity
5348  __kmp_hwloc_error = TRUE;
5349  KMP_AFFINITY_DISABLE();
5350  }
5351 # else
5352  __kmp_affinity_determine_capable( var );
5353 # endif // KMP_USE_HWLOC
5354  if ( ! KMP_AFFINITY_CAPABLE() ) {
5355  if ( __kmp_affinity_verbose || ( __kmp_affinity_warnings
5356  && ( __kmp_affinity_type != affinity_default )
5357  && ( __kmp_affinity_type != affinity_none )
5358  && ( __kmp_affinity_type != affinity_disabled ) ) ) {
5359  KMP_WARNING( AffNotSupported, var );
5360  }
5361  __kmp_affinity_type = affinity_disabled;
5362  __kmp_affinity_respect_mask = 0;
5363  __kmp_affinity_gran = affinity_gran_fine;
5364  }
5365  }
5366 
5367 # if OMP_40_ENABLED
5368  if ( __kmp_affinity_type == affinity_disabled ) {
5369  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5370  }
5371  else if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_true ) {
5372  //
5373  // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
5374  //
5375  __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
5376  }
5377 # endif /* OMP_40_ENABLED */
5378 
5379  if ( KMP_AFFINITY_CAPABLE() ) {
5380 
5381 # if KMP_GROUP_AFFINITY
5382 
5383  //
5384  // Handle the Win 64 group affinity stuff if there are multiple
5385  // processor groups, or if the user requested it, and OMP 4.0
5386  // affinity is not in effect.
5387  //
5388  if ( ( ( __kmp_num_proc_groups > 1 )
5389  && ( __kmp_affinity_type == affinity_default )
5390 # if OMP_40_ENABLED
5391  && ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) )
5392 # endif
5393  || ( __kmp_affinity_top_method == affinity_top_method_group ) ) {
5394  if ( __kmp_affinity_respect_mask == affinity_respect_mask_default ) {
5395  __kmp_affinity_respect_mask = FALSE;
5396  }
5397  if ( __kmp_affinity_type == affinity_default ) {
5398  __kmp_affinity_type = affinity_compact;
5399 # if OMP_40_ENABLED
5400  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5401 # endif
5402  }
5403  if ( __kmp_affinity_top_method == affinity_top_method_default ) {
5404  if ( __kmp_affinity_gran == affinity_gran_default ) {
5405  __kmp_affinity_top_method = affinity_top_method_group;
5406  __kmp_affinity_gran = affinity_gran_group;
5407  }
5408  else if ( __kmp_affinity_gran == affinity_gran_group ) {
5409  __kmp_affinity_top_method = affinity_top_method_group;
5410  }
5411  else {
5412  __kmp_affinity_top_method = affinity_top_method_all;
5413  }
5414  }
5415  else if ( __kmp_affinity_top_method == affinity_top_method_group ) {
5416  if ( __kmp_affinity_gran == affinity_gran_default ) {
5417  __kmp_affinity_gran = affinity_gran_group;
5418  }
5419  else if ( ( __kmp_affinity_gran != affinity_gran_group )
5420  && ( __kmp_affinity_gran != affinity_gran_fine )
5421  && ( __kmp_affinity_gran != affinity_gran_thread ) ) {
5422  const char *str = NULL;
5423  switch ( __kmp_affinity_gran ) {
5424  case affinity_gran_core: str = "core"; break;
5425  case affinity_gran_package: str = "package"; break;
5426  case affinity_gran_node: str = "node"; break;
5427  default: KMP_DEBUG_ASSERT( 0 );
5428  }
5429  KMP_WARNING( AffGranTopGroup, var, str );
5430  __kmp_affinity_gran = affinity_gran_fine;
5431  }
5432  }
5433  else {
5434  if ( __kmp_affinity_gran == affinity_gran_default ) {
5435  __kmp_affinity_gran = affinity_gran_core;
5436  }
5437  else if ( __kmp_affinity_gran == affinity_gran_group ) {
5438  const char *str = NULL;
5439  switch ( __kmp_affinity_type ) {
5440  case affinity_physical: str = "physical"; break;
5441  case affinity_logical: str = "logical"; break;
5442  case affinity_compact: str = "compact"; break;
5443  case affinity_scatter: str = "scatter"; break;
5444  case affinity_explicit: str = "explicit"; break;
5445  // No MIC on windows, so no affinity_balanced case
5446  default: KMP_DEBUG_ASSERT( 0 );
5447  }
5448  KMP_WARNING( AffGranGroupType, var, str );
5449  __kmp_affinity_gran = affinity_gran_core;
5450  }
5451  }
5452  }
5453  else
5454 
5455 # endif /* KMP_GROUP_AFFINITY */
5456 
5457  {
5458  if ( __kmp_affinity_respect_mask == affinity_respect_mask_default ) {
5459 # if KMP_GROUP_AFFINITY
5460  if ( __kmp_num_proc_groups > 1 ) {
5461  __kmp_affinity_respect_mask = FALSE;
5462  }
5463  else
5464 # endif /* KMP_GROUP_AFFINITY */
5465  {
5466  __kmp_affinity_respect_mask = TRUE;
5467  }
5468  }
5469 # if OMP_40_ENABLED
5470  if ( ( __kmp_nested_proc_bind.bind_types[0] != proc_bind_intel )
5471  && ( __kmp_nested_proc_bind.bind_types[0] != proc_bind_default ) ) {
5472  if ( __kmp_affinity_type == affinity_default ) {
5473  __kmp_affinity_type = affinity_compact;
5474  __kmp_affinity_dups = FALSE;
5475  }
5476  }
5477  else
5478 # endif /* OMP_40_ENABLED */
5479  if ( __kmp_affinity_type == affinity_default ) {
5480 #if OMP_40_ENABLED
5481 #if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
5482  if( __kmp_mic_type != non_mic ) {
5483  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5484  } else
5485 #endif
5486  {
5487  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5488  }
5489 #endif /* OMP_40_ENABLED */
5490 #if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
5491  if( __kmp_mic_type != non_mic ) {
5492  __kmp_affinity_type = affinity_scatter;
5493  } else
5494 #endif
5495  {
5496  __kmp_affinity_type = affinity_none;
5497  }
5498 
5499  }
5500  if ( ( __kmp_affinity_gran == affinity_gran_default )
5501  && ( __kmp_affinity_gran_levels < 0 ) ) {
5502 #if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
5503  if( __kmp_mic_type != non_mic ) {
5504  __kmp_affinity_gran = affinity_gran_fine;
5505  } else
5506 #endif
5507  {
5508  __kmp_affinity_gran = affinity_gran_core;
5509  }
5510  }
5511  if ( __kmp_affinity_top_method == affinity_top_method_default ) {
5512  __kmp_affinity_top_method = affinity_top_method_all;
5513  }
5514  }
5515  }
5516 
5517  K_DIAG( 1, ( "__kmp_affinity_type == %d\n", __kmp_affinity_type ) );
5518  K_DIAG( 1, ( "__kmp_affinity_compact == %d\n", __kmp_affinity_compact ) );
5519  K_DIAG( 1, ( "__kmp_affinity_offset == %d\n", __kmp_affinity_offset ) );
5520  K_DIAG( 1, ( "__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose ) );
5521  K_DIAG( 1, ( "__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings ) );
5522  K_DIAG( 1, ( "__kmp_affinity_respect_mask == %d\n", __kmp_affinity_respect_mask ) );
5523  K_DIAG( 1, ( "__kmp_affinity_gran == %d\n", __kmp_affinity_gran ) );
5524 
5525  KMP_DEBUG_ASSERT( __kmp_affinity_type != affinity_default);
5526 # if OMP_40_ENABLED
5527  KMP_DEBUG_ASSERT( __kmp_nested_proc_bind.bind_types[0] != proc_bind_default );
5528 # endif
5529  }
5530 
5531 #endif /* KMP_AFFINITY_SUPPORTED */
5532 
5533  if ( __kmp_version ) {
5534  __kmp_print_version_1();
5535  }; // if
5536 
5537  // Post-initialization step: some env. vars need their value's further processing
5538  if ( string != NULL) { // kmp_set_defaults() was called
5539  __kmp_aux_env_initialize( &block );
5540  }
5541 
5542  __kmp_env_blk_free( & block );
5543 
5544  KMP_MB();
5545 
5546 } // __kmp_env_initialize
5547 
5548 
5549 void
5550 __kmp_env_print() {
5551 
5552  kmp_env_blk_t block;
5553  int i;
5554  kmp_str_buf_t buffer;
5555 
5556  __kmp_stg_init();
5557  __kmp_str_buf_init( & buffer );
5558 
5559  __kmp_env_blk_init( & block, NULL );
5560  __kmp_env_blk_sort( & block );
5561 
5562  // Print real environment values.
5563  __kmp_str_buf_print( & buffer, "\n%s\n\n", KMP_I18N_STR( UserSettings ) );
5564  for ( i = 0; i < block.count; ++ i ) {
5565  char const * name = block.vars[ i ].name;
5566  char const * value = block.vars[ i ].value;
5567  if (
5568  ( KMP_STRLEN( name ) > 4 && strncmp( name, "KMP_", 4 ) == 0 )
5569  || strncmp( name, "OMP_", 4 ) == 0
5570  #ifdef KMP_GOMP_COMPAT
5571  || strncmp( name, "GOMP_", 5 ) == 0
5572  #endif // KMP_GOMP_COMPAT
5573  ) {
5574  __kmp_str_buf_print( & buffer, " %s=%s\n", name, value );
5575  }; // if
5576  }; // for
5577  __kmp_str_buf_print( & buffer, "\n" );
5578 
5579  // Print internal (effective) settings.
5580  __kmp_str_buf_print( & buffer, "%s\n\n", KMP_I18N_STR( EffectiveSettings ) );
5581  for ( int i = 0; i < __kmp_stg_count; ++ i ) {
5582  if ( __kmp_stg_table[ i ].print != NULL ) {
5583  __kmp_stg_table[ i ].print( & buffer, __kmp_stg_table[ i ].name, __kmp_stg_table[ i ].data );
5584  }; // if
5585  }; // for
5586 
5587  __kmp_printf( "%s", buffer.str );
5588 
5589  __kmp_env_blk_free( & block );
5590  __kmp_str_buf_free( & buffer );
5591 
5592  __kmp_printf("\n");
5593 
5594 } // __kmp_env_print
5595 
5596 
5597 #if OMP_40_ENABLED
5598 void
5599 __kmp_env_print_2() {
5600 
5601  kmp_env_blk_t block;
5602  kmp_str_buf_t buffer;
5603 
5604  __kmp_env_format = 1;
5605 
5606  __kmp_stg_init();
5607  __kmp_str_buf_init( & buffer );
5608 
5609  __kmp_env_blk_init( & block, NULL );
5610  __kmp_env_blk_sort( & block );
5611 
5612  __kmp_str_buf_print( & buffer, "\n%s\n", KMP_I18N_STR( DisplayEnvBegin ) );
5613  __kmp_str_buf_print( & buffer, " _OPENMP='%d'\n", __kmp_openmp_version );
5614 
5615  for ( int i = 0; i < __kmp_stg_count; ++ i ) {
5616  if ( __kmp_stg_table[ i ].print != NULL &&
5617  ( ( __kmp_display_env && strncmp( __kmp_stg_table[ i ].name, "OMP_", 4 ) == 0 ) || __kmp_display_env_verbose ) ) {
5618  __kmp_stg_table[ i ].print( & buffer, __kmp_stg_table[ i ].name, __kmp_stg_table[ i ].data );
5619  }; // if
5620  }; // for
5621 
5622  __kmp_str_buf_print( & buffer, "%s\n", KMP_I18N_STR( DisplayEnvEnd ) );
5623  __kmp_str_buf_print( & buffer, "\n" );
5624 
5625  __kmp_printf( "%s", buffer.str );
5626 
5627  __kmp_env_blk_free( & block );
5628  __kmp_str_buf_free( & buffer );
5629 
5630  __kmp_printf("\n");
5631 
5632 } // __kmp_env_print_2
5633 #endif // OMP_40_ENABLED
5634 
5635 // end of file
5636