LLVM OpenMP* Runtime Library
kmp_settings.cpp
1 /*
2  * kmp_settings.cpp -- Initialize environment variables
3  */
4 
5 //===----------------------------------------------------------------------===//
6 //
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "kmp.h"
14 #include "kmp_affinity.h"
15 #include "kmp_atomic.h"
16 #if KMP_USE_HIER_SCHED
17 #include "kmp_dispatch_hier.h"
18 #endif
19 #include "kmp_environment.h"
20 #include "kmp_i18n.h"
21 #include "kmp_io.h"
22 #include "kmp_itt.h"
23 #include "kmp_lock.h"
24 #include "kmp_settings.h"
25 #include "kmp_str.h"
26 #include "kmp_wrapper_getpid.h"
27 #include <ctype.h> // toupper()
28 
29 static int __kmp_env_toPrint(char const *name, int flag);
30 
31 bool __kmp_env_format = 0; // 0 - old format; 1 - new format
32 
33 // -----------------------------------------------------------------------------
34 // Helper string functions. Subject to move to kmp_str.
35 
36 #ifdef USE_LOAD_BALANCE
37 static double __kmp_convert_to_double(char const *s) {
38  double result;
39 
40  if (KMP_SSCANF(s, "%lf", &result) < 1) {
41  result = 0.0;
42  }
43 
44  return result;
45 }
46 #endif
47 
48 #ifdef KMP_DEBUG
49 static unsigned int __kmp_readstr_with_sentinel(char *dest, char const *src,
50  size_t len, char sentinel) {
51  unsigned int i;
52  for (i = 0; i < len; i++) {
53  if ((*src == '\0') || (*src == sentinel)) {
54  break;
55  }
56  *(dest++) = *(src++);
57  }
58  *dest = '\0';
59  return i;
60 }
61 #endif
62 
63 static int __kmp_match_with_sentinel(char const *a, char const *b, size_t len,
64  char sentinel) {
65  size_t l = 0;
66 
67  if (a == NULL)
68  a = "";
69  if (b == NULL)
70  b = "";
71  while (*a && *b && *b != sentinel) {
72  char ca = *a, cb = *b;
73 
74  if (ca >= 'a' && ca <= 'z')
75  ca -= 'a' - 'A';
76  if (cb >= 'a' && cb <= 'z')
77  cb -= 'a' - 'A';
78  if (ca != cb)
79  return FALSE;
80  ++l;
81  ++a;
82  ++b;
83  }
84  return l >= len;
85 }
86 
87 // Expected usage:
88 // token is the token to check for.
89 // buf is the string being parsed.
90 // *end returns the char after the end of the token.
91 // it is not modified unless a match occurs.
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 static int __kmp_match_str(char const *token, char const *buf,
111  const char **end) {
112 
113  KMP_ASSERT(token != NULL);
114  KMP_ASSERT(buf != NULL);
115  KMP_ASSERT(end != NULL);
116 
117  while (*token && *buf) {
118  char ct = *token, cb = *buf;
119 
120  if (ct >= 'a' && ct <= 'z')
121  ct -= 'a' - 'A';
122  if (cb >= 'a' && cb <= 'z')
123  cb -= 'a' - 'A';
124  if (ct != cb)
125  return FALSE;
126  ++token;
127  ++buf;
128  }
129  if (*token) {
130  return FALSE;
131  }
132  *end = buf;
133  return TRUE;
134 }
135 
136 #if KMP_OS_DARWIN
137 static size_t __kmp_round4k(size_t size) {
138  size_t _4k = 4 * 1024;
139  if (size & (_4k - 1)) {
140  size &= ~(_4k - 1);
141  if (size <= KMP_SIZE_T_MAX - _4k) {
142  size += _4k; // Round up if there is no overflow.
143  }
144  }
145  return size;
146 } // __kmp_round4k
147 #endif
148 
149 /* Here, multipliers are like __kmp_convert_to_seconds, but floating-point
150  values are allowed, and the return value is in milliseconds. The default
151  multiplier is milliseconds. Returns INT_MAX only if the value specified
152  matches "infinit*". Returns -1 if specified string is invalid. */
153 int __kmp_convert_to_milliseconds(char const *data) {
154  int ret, nvalues, factor;
155  char mult, extra;
156  double value;
157 
158  if (data == NULL)
159  return (-1);
160  if (__kmp_str_match("infinit", -1, data))
161  return (INT_MAX);
162  value = (double)0.0;
163  mult = '\0';
164  nvalues = KMP_SSCANF(data, "%lf%c%c", &value, &mult, &extra);
165  if (nvalues < 1)
166  return (-1);
167  if (nvalues == 1)
168  mult = '\0';
169  if (nvalues == 3)
170  return (-1);
171 
172  if (value < 0)
173  return (-1);
174 
175  switch (mult) {
176  case '\0':
177  /* default is milliseconds */
178  factor = 1;
179  break;
180  case 's':
181  case 'S':
182  factor = 1000;
183  break;
184  case 'm':
185  case 'M':
186  factor = 1000 * 60;
187  break;
188  case 'h':
189  case 'H':
190  factor = 1000 * 60 * 60;
191  break;
192  case 'd':
193  case 'D':
194  factor = 1000 * 24 * 60 * 60;
195  break;
196  default:
197  return (-1);
198  }
199 
200  if (value >= ((INT_MAX - 1) / factor))
201  ret = INT_MAX - 1; /* Don't allow infinite value here */
202  else
203  ret = (int)(value * (double)factor); /* truncate to int */
204 
205  return ret;
206 }
207 
208 static int __kmp_strcasecmp_with_sentinel(char const *a, char const *b,
209  char sentinel) {
210  if (a == NULL)
211  a = "";
212  if (b == NULL)
213  b = "";
214  while (*a && *b && *b != sentinel) {
215  char ca = *a, cb = *b;
216 
217  if (ca >= 'a' && ca <= 'z')
218  ca -= 'a' - 'A';
219  if (cb >= 'a' && cb <= 'z')
220  cb -= 'a' - 'A';
221  if (ca != cb)
222  return (int)(unsigned char)*a - (int)(unsigned char)*b;
223  ++a;
224  ++b;
225  }
226  return *a
227  ? (*b && *b != sentinel)
228  ? (int)(unsigned char)*a - (int)(unsigned char)*b
229  : 1
230  : (*b && *b != sentinel) ? -1 : 0;
231 }
232 
233 // =============================================================================
234 // Table structures and helper functions.
235 
236 typedef struct __kmp_setting kmp_setting_t;
237 typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
238 typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
239 typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
240 
241 typedef void (*kmp_stg_parse_func_t)(char const *name, char const *value,
242  void *data);
243 typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer, char const *name,
244  void *data);
245 
246 struct __kmp_setting {
247  char const *name; // Name of setting (environment variable).
248  kmp_stg_parse_func_t parse; // Parser function.
249  kmp_stg_print_func_t print; // Print function.
250  void *data; // Data passed to parser and printer.
251  int set; // Variable set during this "session"
252  // (__kmp_env_initialize() or kmp_set_defaults() call).
253  int defined; // Variable set in any "session".
254 }; // struct __kmp_setting
255 
256 struct __kmp_stg_ss_data {
257  size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
258  kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
259 }; // struct __kmp_stg_ss_data
260 
261 struct __kmp_stg_wp_data {
262  int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
263  kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
264 }; // struct __kmp_stg_wp_data
265 
266 struct __kmp_stg_fr_data {
267  int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
268  kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
269 }; // struct __kmp_stg_fr_data
270 
271 static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
272  char const *name, // Name of variable.
273  char const *value, // Value of the variable.
274  kmp_setting_t **rivals // List of rival settings (must include current one).
275  );
276 
277 // -----------------------------------------------------------------------------
278 // Helper parse functions.
279 
280 static void __kmp_stg_parse_bool(char const *name, char const *value,
281  int *out) {
282  if (__kmp_str_match_true(value)) {
283  *out = TRUE;
284  } else if (__kmp_str_match_false(value)) {
285  *out = FALSE;
286  } else {
287  __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
288  KMP_HNT(ValidBoolValues), __kmp_msg_null);
289  }
290 } // __kmp_stg_parse_bool
291 
292 // placed here in order to use __kmp_round4k static function
293 void __kmp_check_stksize(size_t *val) {
294  // if system stack size is too big then limit the size for worker threads
295  if (*val > KMP_DEFAULT_STKSIZE * 16) // just a heuristics...
296  *val = KMP_DEFAULT_STKSIZE * 16;
297  if (*val < KMP_MIN_STKSIZE)
298  *val = KMP_MIN_STKSIZE;
299  if (*val > KMP_MAX_STKSIZE)
300  *val = KMP_MAX_STKSIZE; // dead code currently, but may work in future
301 #if KMP_OS_DARWIN
302  *val = __kmp_round4k(*val);
303 #endif // KMP_OS_DARWIN
304 }
305 
306 static void __kmp_stg_parse_size(char const *name, char const *value,
307  size_t size_min, size_t size_max,
308  int *is_specified, size_t *out,
309  size_t factor) {
310  char const *msg = NULL;
311 #if KMP_OS_DARWIN
312  size_min = __kmp_round4k(size_min);
313  size_max = __kmp_round4k(size_max);
314 #endif // KMP_OS_DARWIN
315  if (value) {
316  if (is_specified != NULL) {
317  *is_specified = 1;
318  }
319  __kmp_str_to_size(value, out, factor, &msg);
320  if (msg == NULL) {
321  if (*out > size_max) {
322  *out = size_max;
323  msg = KMP_I18N_STR(ValueTooLarge);
324  } else if (*out < size_min) {
325  *out = size_min;
326  msg = KMP_I18N_STR(ValueTooSmall);
327  } else {
328 #if KMP_OS_DARWIN
329  size_t round4k = __kmp_round4k(*out);
330  if (*out != round4k) {
331  *out = round4k;
332  msg = KMP_I18N_STR(NotMultiple4K);
333  }
334 #endif
335  }
336  } else {
337  // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to
338  // size_max silently.
339  if (*out < size_min) {
340  *out = size_max;
341  } else if (*out > size_max) {
342  *out = size_max;
343  }
344  }
345  if (msg != NULL) {
346  // Message is not empty. Print warning.
347  kmp_str_buf_t buf;
348  __kmp_str_buf_init(&buf);
349  __kmp_str_buf_print_size(&buf, *out);
350  KMP_WARNING(ParseSizeIntWarn, name, value, msg);
351  KMP_INFORM(Using_str_Value, name, buf.str);
352  __kmp_str_buf_free(&buf);
353  }
354  }
355 } // __kmp_stg_parse_size
356 
357 static void __kmp_stg_parse_str(char const *name, char const *value,
358  char **out) {
359  __kmp_str_free(out);
360  *out = __kmp_str_format("%s", value);
361 } // __kmp_stg_parse_str
362 
363 static void __kmp_stg_parse_int(
364  char const
365  *name, // I: Name of environment variable (used in warning messages).
366  char const *value, // I: Value of environment variable to parse.
367  int min, // I: Minimum allowed value.
368  int max, // I: Maximum allowed value.
369  int *out // O: Output (parsed) value.
370  ) {
371  char const *msg = NULL;
372  kmp_uint64 uint = *out;
373  __kmp_str_to_uint(value, &uint, &msg);
374  if (msg == NULL) {
375  if (uint < (unsigned int)min) {
376  msg = KMP_I18N_STR(ValueTooSmall);
377  uint = min;
378  } else if (uint > (unsigned int)max) {
379  msg = KMP_I18N_STR(ValueTooLarge);
380  uint = max;
381  }
382  } else {
383  // If overflow occurred msg contains error message and uint is very big. Cut
384  // tmp it to INT_MAX.
385  if (uint < (unsigned int)min) {
386  uint = min;
387  } else if (uint > (unsigned int)max) {
388  uint = max;
389  }
390  }
391  if (msg != NULL) {
392  // Message is not empty. Print warning.
393  kmp_str_buf_t buf;
394  KMP_WARNING(ParseSizeIntWarn, name, value, msg);
395  __kmp_str_buf_init(&buf);
396  __kmp_str_buf_print(&buf, "%" KMP_UINT64_SPEC "", uint);
397  KMP_INFORM(Using_uint64_Value, name, buf.str);
398  __kmp_str_buf_free(&buf);
399  }
400  *out = uint;
401 } // __kmp_stg_parse_int
402 
403 #if KMP_DEBUG_ADAPTIVE_LOCKS
404 static void __kmp_stg_parse_file(char const *name, char const *value,
405  const char *suffix, char **out) {
406  char buffer[256];
407  char *t;
408  int hasSuffix;
409  __kmp_str_free(out);
410  t = (char *)strrchr(value, '.');
411  hasSuffix = t && __kmp_str_eqf(t, suffix);
412  t = __kmp_str_format("%s%s", value, hasSuffix ? "" : suffix);
413  __kmp_expand_file_name(buffer, sizeof(buffer), t);
414  __kmp_str_free(&t);
415  *out = __kmp_str_format("%s", buffer);
416 } // __kmp_stg_parse_file
417 #endif
418 
419 #ifdef KMP_DEBUG
420 static char *par_range_to_print = NULL;
421 
422 static void __kmp_stg_parse_par_range(char const *name, char const *value,
423  int *out_range, char *out_routine,
424  char *out_file, int *out_lb,
425  int *out_ub) {
426  size_t len = KMP_STRLEN(value) + 1;
427  par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
428  KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
429  __kmp_par_range = +1;
430  __kmp_par_range_lb = 0;
431  __kmp_par_range_ub = INT_MAX;
432  for (;;) {
433  unsigned int len;
434  if (*value == '\0') {
435  break;
436  }
437  if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
438  value = strchr(value, '=') + 1;
439  len = __kmp_readstr_with_sentinel(out_routine, value,
440  KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
441  if (len == 0) {
442  goto par_range_error;
443  }
444  value = strchr(value, ',');
445  if (value != NULL) {
446  value++;
447  }
448  continue;
449  }
450  if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
451  value = strchr(value, '=') + 1;
452  len = __kmp_readstr_with_sentinel(out_file, value,
453  KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
454  if (len == 0) {
455  goto par_range_error;
456  }
457  value = strchr(value, ',');
458  if (value != NULL) {
459  value++;
460  }
461  continue;
462  }
463  if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
464  (!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
465  value = strchr(value, '=') + 1;
466  if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
467  goto par_range_error;
468  }
469  *out_range = +1;
470  value = strchr(value, ',');
471  if (value != NULL) {
472  value++;
473  }
474  continue;
475  }
476  if (!__kmp_strcasecmp_with_sentinel("excl_range", value, '=')) {
477  value = strchr(value, '=') + 1;
478  if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
479  goto par_range_error;
480  }
481  *out_range = -1;
482  value = strchr(value, ',');
483  if (value != NULL) {
484  value++;
485  }
486  continue;
487  }
488  par_range_error:
489  KMP_WARNING(ParRangeSyntax, name);
490  __kmp_par_range = 0;
491  break;
492  }
493 } // __kmp_stg_parse_par_range
494 #endif
495 
496 int __kmp_initial_threads_capacity(int req_nproc) {
497  int nth = 32;
498 
499  /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
500  * __kmp_max_nth) */
501  if (nth < (4 * req_nproc))
502  nth = (4 * req_nproc);
503  if (nth < (4 * __kmp_xproc))
504  nth = (4 * __kmp_xproc);
505 
506  if (nth > __kmp_max_nth)
507  nth = __kmp_max_nth;
508 
509  return nth;
510 }
511 
512 int __kmp_default_tp_capacity(int req_nproc, int max_nth,
513  int all_threads_specified) {
514  int nth = 128;
515 
516  if (all_threads_specified)
517  return max_nth;
518  /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
519  * __kmp_max_nth ) */
520  if (nth < (4 * req_nproc))
521  nth = (4 * req_nproc);
522  if (nth < (4 * __kmp_xproc))
523  nth = (4 * __kmp_xproc);
524 
525  if (nth > __kmp_max_nth)
526  nth = __kmp_max_nth;
527 
528  return nth;
529 }
530 
531 // -----------------------------------------------------------------------------
532 // Helper print functions.
533 
534 static void __kmp_stg_print_bool(kmp_str_buf_t *buffer, char const *name,
535  int value) {
536  if (__kmp_env_format) {
537  KMP_STR_BUF_PRINT_BOOL;
538  } else {
539  __kmp_str_buf_print(buffer, " %s=%s\n", name, value ? "true" : "false");
540  }
541 } // __kmp_stg_print_bool
542 
543 static void __kmp_stg_print_int(kmp_str_buf_t *buffer, char const *name,
544  int value) {
545  if (__kmp_env_format) {
546  KMP_STR_BUF_PRINT_INT;
547  } else {
548  __kmp_str_buf_print(buffer, " %s=%d\n", name, value);
549  }
550 } // __kmp_stg_print_int
551 
552 #if USE_ITT_BUILD && USE_ITT_NOTIFY
553 static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer, char const *name,
554  kmp_uint64 value) {
555  if (__kmp_env_format) {
556  KMP_STR_BUF_PRINT_UINT64;
557  } else {
558  __kmp_str_buf_print(buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value);
559  }
560 } // __kmp_stg_print_uint64
561 #endif
562 
563 static void __kmp_stg_print_str(kmp_str_buf_t *buffer, char const *name,
564  char const *value) {
565  if (__kmp_env_format) {
566  KMP_STR_BUF_PRINT_STR;
567  } else {
568  __kmp_str_buf_print(buffer, " %s=%s\n", name, value);
569  }
570 } // __kmp_stg_print_str
571 
572 static void __kmp_stg_print_size(kmp_str_buf_t *buffer, char const *name,
573  size_t value) {
574  if (__kmp_env_format) {
575  KMP_STR_BUF_PRINT_NAME_EX(name);
576  __kmp_str_buf_print_size(buffer, value);
577  __kmp_str_buf_print(buffer, "'\n");
578  } else {
579  __kmp_str_buf_print(buffer, " %s=", name);
580  __kmp_str_buf_print_size(buffer, value);
581  __kmp_str_buf_print(buffer, "\n");
582  return;
583  }
584 } // __kmp_stg_print_size
585 
586 // =============================================================================
587 // Parse and print functions.
588 
589 // -----------------------------------------------------------------------------
590 // KMP_DEVICE_THREAD_LIMIT, KMP_ALL_THREADS
591 
592 static void __kmp_stg_parse_device_thread_limit(char const *name,
593  char const *value, void *data) {
594  kmp_setting_t **rivals = (kmp_setting_t **)data;
595  int rc;
596  if (strcmp(name, "KMP_ALL_THREADS") == 0) {
597  KMP_INFORM(EnvVarDeprecated, name, "KMP_DEVICE_THREAD_LIMIT");
598  }
599  rc = __kmp_stg_check_rivals(name, value, rivals);
600  if (rc) {
601  return;
602  }
603  if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
604  __kmp_max_nth = __kmp_xproc;
605  __kmp_allThreadsSpecified = 1;
606  } else {
607  __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
608  __kmp_allThreadsSpecified = 0;
609  }
610  K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));
611 
612 } // __kmp_stg_parse_device_thread_limit
613 
614 static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
615  char const *name, void *data) {
616  __kmp_stg_print_int(buffer, name, __kmp_max_nth);
617 } // __kmp_stg_print_device_thread_limit
618 
619 // -----------------------------------------------------------------------------
620 // OMP_THREAD_LIMIT
621 static void __kmp_stg_parse_thread_limit(char const *name, char const *value,
622  void *data) {
623  __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
624  K_DIAG(1, ("__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));
625 
626 } // __kmp_stg_parse_thread_limit
627 
628 static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
629  char const *name, void *data) {
630  __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
631 } // __kmp_stg_print_thread_limit
632 
633 // -----------------------------------------------------------------------------
634 // KMP_TEAMS_THREAD_LIMIT
635 static void __kmp_stg_parse_teams_thread_limit(char const *name,
636  char const *value, void *data) {
637  __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
638 } // __kmp_stg_teams_thread_limit
639 
640 static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
641  char const *name, void *data) {
642  __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
643 } // __kmp_stg_print_teams_thread_limit
644 
645 // -----------------------------------------------------------------------------
646 // KMP_USE_YIELD
647 static void __kmp_stg_parse_use_yield(char const *name, char const *value,
648  void *data) {
649  __kmp_stg_parse_int(name, value, 0, 2, &__kmp_use_yield);
650  __kmp_use_yield_exp_set = 1;
651 } // __kmp_stg_parse_use_yield
652 
653 static void __kmp_stg_print_use_yield(kmp_str_buf_t *buffer, char const *name,
654  void *data) {
655  __kmp_stg_print_int(buffer, name, __kmp_use_yield);
656 } // __kmp_stg_print_use_yield
657 
658 // -----------------------------------------------------------------------------
659 // KMP_BLOCKTIME
660 
661 static void __kmp_stg_parse_blocktime(char const *name, char const *value,
662  void *data) {
663  __kmp_dflt_blocktime = __kmp_convert_to_milliseconds(value);
664  if (__kmp_dflt_blocktime < 0) {
665  __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
666  __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
667  __kmp_msg_null);
668  KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime);
669  __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
670  } else {
671  if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
672  __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
673  __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
674  __kmp_msg_null);
675  KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime);
676  } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
677  __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
678  __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
679  __kmp_msg_null);
680  KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime);
681  }
682  __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
683  }
684 #if KMP_USE_MONITOR
685  // calculate number of monitor thread wakeup intervals corresponding to
686  // blocktime.
687  __kmp_monitor_wakeups =
688  KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
689  __kmp_bt_intervals =
690  KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
691 #endif
692  K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
693  if (__kmp_env_blocktime) {
694  K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
695  }
696 } // __kmp_stg_parse_blocktime
697 
698 static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
699  void *data) {
700  __kmp_stg_print_int(buffer, name, __kmp_dflt_blocktime);
701 } // __kmp_stg_print_blocktime
702 
703 // -----------------------------------------------------------------------------
704 // KMP_DUPLICATE_LIB_OK
705 
706 static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
707  char const *value, void *data) {
708  /* actually this variable is not supported, put here for compatibility with
709  earlier builds and for static/dynamic combination */
710  __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
711 } // __kmp_stg_parse_duplicate_lib_ok
712 
713 static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
714  char const *name, void *data) {
715  __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
716 } // __kmp_stg_print_duplicate_lib_ok
717 
718 // -----------------------------------------------------------------------------
719 // KMP_INHERIT_FP_CONTROL
720 
721 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
722 
723 static void __kmp_stg_parse_inherit_fp_control(char const *name,
724  char const *value, void *data) {
725  __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
726 } // __kmp_stg_parse_inherit_fp_control
727 
728 static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
729  char const *name, void *data) {
730 #if KMP_DEBUG
731  __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
732 #endif /* KMP_DEBUG */
733 } // __kmp_stg_print_inherit_fp_control
734 
735 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
736 
737 // Used for OMP_WAIT_POLICY
738 static char const *blocktime_str = NULL;
739 
740 // -----------------------------------------------------------------------------
741 // KMP_LIBRARY, OMP_WAIT_POLICY
742 
743 static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
744  void *data) {
745 
746  kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
747  int rc;
748 
749  rc = __kmp_stg_check_rivals(name, value, wait->rivals);
750  if (rc) {
751  return;
752  }
753 
754  if (wait->omp) {
755  if (__kmp_str_match("ACTIVE", 1, value)) {
756  __kmp_library = library_turnaround;
757  if (blocktime_str == NULL) {
758  // KMP_BLOCKTIME not specified, so set default to "infinite".
759  __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
760  }
761  } else if (__kmp_str_match("PASSIVE", 1, value)) {
762  __kmp_library = library_throughput;
763  if (blocktime_str == NULL) {
764  // KMP_BLOCKTIME not specified, so set default to 0.
765  __kmp_dflt_blocktime = 0;
766  }
767  } else {
768  KMP_WARNING(StgInvalidValue, name, value);
769  }
770  } else {
771  if (__kmp_str_match("serial", 1, value)) { /* S */
772  __kmp_library = library_serial;
773  } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
774  __kmp_library = library_throughput;
775  if (blocktime_str == NULL) {
776  // KMP_BLOCKTIME not specified, so set default to 0.
777  __kmp_dflt_blocktime = 0;
778  }
779  } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
780  __kmp_library = library_turnaround;
781  } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
782  __kmp_library = library_turnaround;
783  } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
784  __kmp_library = library_throughput;
785  if (blocktime_str == NULL) {
786  // KMP_BLOCKTIME not specified, so set default to 0.
787  __kmp_dflt_blocktime = 0;
788  }
789  } else {
790  KMP_WARNING(StgInvalidValue, name, value);
791  }
792  }
793 } // __kmp_stg_parse_wait_policy
794 
795 static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
796  void *data) {
797 
798  kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
799  char const *value = NULL;
800 
801  if (wait->omp) {
802  switch (__kmp_library) {
803  case library_turnaround: {
804  value = "ACTIVE";
805  } break;
806  case library_throughput: {
807  value = "PASSIVE";
808  } break;
809  }
810  } else {
811  switch (__kmp_library) {
812  case library_serial: {
813  value = "serial";
814  } break;
815  case library_turnaround: {
816  value = "turnaround";
817  } break;
818  case library_throughput: {
819  value = "throughput";
820  } break;
821  }
822  }
823  if (value != NULL) {
824  __kmp_stg_print_str(buffer, name, value);
825  }
826 
827 } // __kmp_stg_print_wait_policy
828 
829 #if KMP_USE_MONITOR
830 // -----------------------------------------------------------------------------
831 // KMP_MONITOR_STACKSIZE
832 
833 static void __kmp_stg_parse_monitor_stacksize(char const *name,
834  char const *value, void *data) {
835  __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
836  NULL, &__kmp_monitor_stksize, 1);
837 } // __kmp_stg_parse_monitor_stacksize
838 
839 static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
840  char const *name, void *data) {
841  if (__kmp_env_format) {
842  if (__kmp_monitor_stksize > 0)
843  KMP_STR_BUF_PRINT_NAME_EX(name);
844  else
845  KMP_STR_BUF_PRINT_NAME;
846  } else {
847  __kmp_str_buf_print(buffer, " %s", name);
848  }
849  if (__kmp_monitor_stksize > 0) {
850  __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
851  } else {
852  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
853  }
854  if (__kmp_env_format && __kmp_monitor_stksize) {
855  __kmp_str_buf_print(buffer, "'\n");
856  }
857 } // __kmp_stg_print_monitor_stacksize
858 #endif // KMP_USE_MONITOR
859 
860 // -----------------------------------------------------------------------------
861 // KMP_SETTINGS
862 
863 static void __kmp_stg_parse_settings(char const *name, char const *value,
864  void *data) {
865  __kmp_stg_parse_bool(name, value, &__kmp_settings);
866 } // __kmp_stg_parse_settings
867 
868 static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
869  void *data) {
870  __kmp_stg_print_bool(buffer, name, __kmp_settings);
871 } // __kmp_stg_print_settings
872 
873 // -----------------------------------------------------------------------------
874 // KMP_STACKPAD
875 
876 static void __kmp_stg_parse_stackpad(char const *name, char const *value,
877  void *data) {
878  __kmp_stg_parse_int(name, // Env var name
879  value, // Env var value
880  KMP_MIN_STKPADDING, // Min value
881  KMP_MAX_STKPADDING, // Max value
882  &__kmp_stkpadding // Var to initialize
883  );
884 } // __kmp_stg_parse_stackpad
885 
886 static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
887  void *data) {
888  __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
889 } // __kmp_stg_print_stackpad
890 
891 // -----------------------------------------------------------------------------
892 // KMP_STACKOFFSET
893 
894 static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
895  void *data) {
896  __kmp_stg_parse_size(name, // Env var name
897  value, // Env var value
898  KMP_MIN_STKOFFSET, // Min value
899  KMP_MAX_STKOFFSET, // Max value
900  NULL, //
901  &__kmp_stkoffset, // Var to initialize
902  1);
903 } // __kmp_stg_parse_stackoffset
904 
905 static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
906  void *data) {
907  __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
908 } // __kmp_stg_print_stackoffset
909 
910 // -----------------------------------------------------------------------------
911 // KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
912 
913 static void __kmp_stg_parse_stacksize(char const *name, char const *value,
914  void *data) {
915 
916  kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
917  int rc;
918 
919  rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
920  if (rc) {
921  return;
922  }
923  __kmp_stg_parse_size(name, // Env var name
924  value, // Env var value
925  __kmp_sys_min_stksize, // Min value
926  KMP_MAX_STKSIZE, // Max value
927  &__kmp_env_stksize, //
928  &__kmp_stksize, // Var to initialize
929  stacksize->factor);
930 
931 } // __kmp_stg_parse_stacksize
932 
933 // This function is called for printing both KMP_STACKSIZE (factor is 1) and
934 // OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
935 // OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
936 // customer request in future.
937 static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
938  void *data) {
939  kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
940  if (__kmp_env_format) {
941  KMP_STR_BUF_PRINT_NAME_EX(name);
942  __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
943  ? __kmp_stksize / stacksize->factor
944  : __kmp_stksize);
945  __kmp_str_buf_print(buffer, "'\n");
946  } else {
947  __kmp_str_buf_print(buffer, " %s=", name);
948  __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
949  ? __kmp_stksize / stacksize->factor
950  : __kmp_stksize);
951  __kmp_str_buf_print(buffer, "\n");
952  }
953 } // __kmp_stg_print_stacksize
954 
955 // -----------------------------------------------------------------------------
956 // KMP_VERSION
957 
958 static void __kmp_stg_parse_version(char const *name, char const *value,
959  void *data) {
960  __kmp_stg_parse_bool(name, value, &__kmp_version);
961 } // __kmp_stg_parse_version
962 
963 static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
964  void *data) {
965  __kmp_stg_print_bool(buffer, name, __kmp_version);
966 } // __kmp_stg_print_version
967 
968 // -----------------------------------------------------------------------------
969 // KMP_WARNINGS
970 
971 static void __kmp_stg_parse_warnings(char const *name, char const *value,
972  void *data) {
973  __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
974  if (__kmp_generate_warnings != kmp_warnings_off) {
975  // AC: only 0/1 values documented, so reset to explicit to distinguish from
976  // default setting
977  __kmp_generate_warnings = kmp_warnings_explicit;
978  }
979 } // __kmp_stg_parse_warnings
980 
981 static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
982  void *data) {
983  // AC: TODO: change to print_int? (needs documentation change)
984  __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
985 } // __kmp_stg_print_warnings
986 
987 // -----------------------------------------------------------------------------
988 // OMP_NESTED, OMP_NUM_THREADS
989 
990 static void __kmp_stg_parse_nested(char const *name, char const *value,
991  void *data) {
992  int nested;
993  KMP_INFORM(EnvVarDeprecated, name, "OMP_MAX_ACTIVE_LEVELS");
994  __kmp_stg_parse_bool(name, value, &nested);
995  if (nested) {
996  if (!__kmp_dflt_max_active_levels_set)
997  __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
998  } else { // nesting explicitly turned off
999  __kmp_dflt_max_active_levels = 1;
1000  __kmp_dflt_max_active_levels_set = true;
1001  }
1002 } // __kmp_stg_parse_nested
1003 
1004 static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
1005  void *data) {
1006  if (__kmp_env_format) {
1007  KMP_STR_BUF_PRINT_NAME;
1008  } else {
1009  __kmp_str_buf_print(buffer, " %s", name);
1010  }
1011  __kmp_str_buf_print(buffer, ": deprecated; max-active-levels-var=%d\n",
1012  __kmp_dflt_max_active_levels);
1013 } // __kmp_stg_print_nested
1014 
1015 static void __kmp_parse_nested_num_threads(const char *var, const char *env,
1016  kmp_nested_nthreads_t *nth_array) {
1017  const char *next = env;
1018  const char *scan = next;
1019 
1020  int total = 0; // Count elements that were set. It'll be used as an array size
1021  int prev_comma = FALSE; // For correct processing sequential commas
1022 
1023  // Count the number of values in the env. var string
1024  for (;;) {
1025  SKIP_WS(next);
1026 
1027  if (*next == '\0') {
1028  break;
1029  }
1030  // Next character is not an integer or not a comma => end of list
1031  if (((*next < '0') || (*next > '9')) && (*next != ',')) {
1032  KMP_WARNING(NthSyntaxError, var, env);
1033  return;
1034  }
1035  // The next character is ','
1036  if (*next == ',') {
1037  // ',' is the first character
1038  if (total == 0 || prev_comma) {
1039  total++;
1040  }
1041  prev_comma = TRUE;
1042  next++; // skip ','
1043  SKIP_WS(next);
1044  }
1045  // Next character is a digit
1046  if (*next >= '0' && *next <= '9') {
1047  prev_comma = FALSE;
1048  SKIP_DIGITS(next);
1049  total++;
1050  const char *tmp = next;
1051  SKIP_WS(tmp);
1052  if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
1053  KMP_WARNING(NthSpacesNotAllowed, var, env);
1054  return;
1055  }
1056  }
1057  }
1058  if (!__kmp_dflt_max_active_levels_set && total > 1)
1059  __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1060  KMP_DEBUG_ASSERT(total > 0);
1061  if (total <= 0) {
1062  KMP_WARNING(NthSyntaxError, var, env);
1063  return;
1064  }
1065 
1066  // Check if the nested nthreads array exists
1067  if (!nth_array->nth) {
1068  // Allocate an array of double size
1069  nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
1070  if (nth_array->nth == NULL) {
1071  KMP_FATAL(MemoryAllocFailed);
1072  }
1073  nth_array->size = total * 2;
1074  } else {
1075  if (nth_array->size < total) {
1076  // Increase the array size
1077  do {
1078  nth_array->size *= 2;
1079  } while (nth_array->size < total);
1080 
1081  nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
1082  nth_array->nth, sizeof(int) * nth_array->size);
1083  if (nth_array->nth == NULL) {
1084  KMP_FATAL(MemoryAllocFailed);
1085  }
1086  }
1087  }
1088  nth_array->used = total;
1089  int i = 0;
1090 
1091  prev_comma = FALSE;
1092  total = 0;
1093  // Save values in the array
1094  for (;;) {
1095  SKIP_WS(scan);
1096  if (*scan == '\0') {
1097  break;
1098  }
1099  // The next character is ','
1100  if (*scan == ',') {
1101  // ',' in the beginning of the list
1102  if (total == 0) {
1103  // The value is supposed to be equal to __kmp_avail_proc but it is
1104  // unknown at the moment.
1105  // So let's put a placeholder (#threads = 0) to correct it later.
1106  nth_array->nth[i++] = 0;
1107  total++;
1108  } else if (prev_comma) {
1109  // Num threads is inherited from the previous level
1110  nth_array->nth[i] = nth_array->nth[i - 1];
1111  i++;
1112  total++;
1113  }
1114  prev_comma = TRUE;
1115  scan++; // skip ','
1116  SKIP_WS(scan);
1117  }
1118  // Next character is a digit
1119  if (*scan >= '0' && *scan <= '9') {
1120  int num;
1121  const char *buf = scan;
1122  char const *msg = NULL;
1123  prev_comma = FALSE;
1124  SKIP_DIGITS(scan);
1125  total++;
1126 
1127  num = __kmp_str_to_int(buf, *scan);
1128  if (num < KMP_MIN_NTH) {
1129  msg = KMP_I18N_STR(ValueTooSmall);
1130  num = KMP_MIN_NTH;
1131  } else if (num > __kmp_sys_max_nth) {
1132  msg = KMP_I18N_STR(ValueTooLarge);
1133  num = __kmp_sys_max_nth;
1134  }
1135  if (msg != NULL) {
1136  // Message is not empty. Print warning.
1137  KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1138  KMP_INFORM(Using_int_Value, var, num);
1139  }
1140  nth_array->nth[i++] = num;
1141  }
1142  }
1143 }
1144 
1145 static void __kmp_stg_parse_num_threads(char const *name, char const *value,
1146  void *data) {
1147  // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
1148  if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
1149  // The array of 1 element
1150  __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
1151  __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1152  __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1153  __kmp_xproc;
1154  } else {
1155  __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1156  if (__kmp_nested_nth.nth) {
1157  __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1158  if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1159  __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1160  }
1161  }
1162  }
1163  K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
1164 } // __kmp_stg_parse_num_threads
1165 
1166 static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
1167  void *data) {
1168  if (__kmp_env_format) {
1169  KMP_STR_BUF_PRINT_NAME;
1170  } else {
1171  __kmp_str_buf_print(buffer, " %s", name);
1172  }
1173  if (__kmp_nested_nth.used) {
1174  kmp_str_buf_t buf;
1175  __kmp_str_buf_init(&buf);
1176  for (int i = 0; i < __kmp_nested_nth.used; i++) {
1177  __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
1178  if (i < __kmp_nested_nth.used - 1) {
1179  __kmp_str_buf_print(&buf, ",");
1180  }
1181  }
1182  __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
1183  __kmp_str_buf_free(&buf);
1184  } else {
1185  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1186  }
1187 } // __kmp_stg_print_num_threads
1188 
1189 // -----------------------------------------------------------------------------
1190 // OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
1191 
1192 static void __kmp_stg_parse_tasking(char const *name, char const *value,
1193  void *data) {
1194  __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
1195  (int *)&__kmp_tasking_mode);
1196 } // __kmp_stg_parse_tasking
1197 
1198 static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
1199  void *data) {
1200  __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
1201 } // __kmp_stg_print_tasking
1202 
1203 static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
1204  void *data) {
1205  __kmp_stg_parse_int(name, value, 0, 1,
1206  (int *)&__kmp_task_stealing_constraint);
1207 } // __kmp_stg_parse_task_stealing
1208 
1209 static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1210  char const *name, void *data) {
1211  __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
1212 } // __kmp_stg_print_task_stealing
1213 
1214 static void __kmp_stg_parse_max_active_levels(char const *name,
1215  char const *value, void *data) {
1216  kmp_uint64 tmp_dflt = 0;
1217  char const *msg = NULL;
1218  if (!__kmp_dflt_max_active_levels_set) {
1219  // Don't overwrite __kmp_dflt_max_active_levels if we get an invalid setting
1220  __kmp_str_to_uint(value, &tmp_dflt, &msg);
1221  if (msg != NULL) { // invalid setting; print warning and ignore
1222  KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1223  } else if (tmp_dflt > KMP_MAX_ACTIVE_LEVELS_LIMIT) {
1224  // invalid setting; print warning and ignore
1225  msg = KMP_I18N_STR(ValueTooLarge);
1226  KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1227  } else { // valid setting
1228  __kmp_dflt_max_active_levels = tmp_dflt;
1229  __kmp_dflt_max_active_levels_set = true;
1230  }
1231  }
1232 } // __kmp_stg_parse_max_active_levels
1233 
1234 static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1235  char const *name, void *data) {
1236  __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
1237 } // __kmp_stg_print_max_active_levels
1238 
1239 // -----------------------------------------------------------------------------
1240 // OpenMP 4.0: OMP_DEFAULT_DEVICE
1241 static void __kmp_stg_parse_default_device(char const *name, char const *value,
1242  void *data) {
1243  __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1244  &__kmp_default_device);
1245 } // __kmp_stg_parse_default_device
1246 
1247 static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1248  char const *name, void *data) {
1249  __kmp_stg_print_int(buffer, name, __kmp_default_device);
1250 } // __kmp_stg_print_default_device
1251 
1252 // -----------------------------------------------------------------------------
1253 // OpenMP 5.0: OMP_TARGET_OFFLOAD
1254 static void __kmp_stg_parse_target_offload(char const *name, char const *value,
1255  void *data) {
1256  const char *next = value;
1257  const char *scan = next;
1258 
1259  __kmp_target_offload = tgt_default;
1260  SKIP_WS(next);
1261  if (*next == '\0')
1262  return;
1263  scan = next;
1264  if (!__kmp_strcasecmp_with_sentinel("mandatory", scan, 0)) {
1265  __kmp_target_offload = tgt_mandatory;
1266  } else if (!__kmp_strcasecmp_with_sentinel("disabled", scan, 0)) {
1267  __kmp_target_offload = tgt_disabled;
1268  } else if (!__kmp_strcasecmp_with_sentinel("default", scan, 0)) {
1269  __kmp_target_offload = tgt_default;
1270  } else {
1271  KMP_WARNING(SyntaxErrorUsing, name, "DEFAULT");
1272  }
1273 
1274 } // __kmp_stg_parse_target_offload
1275 
1276 static void __kmp_stg_print_target_offload(kmp_str_buf_t *buffer,
1277  char const *name, void *data) {
1278  const char *value = NULL;
1279  if (__kmp_target_offload == tgt_default)
1280  value = "DEFAULT";
1281  else if (__kmp_target_offload == tgt_mandatory)
1282  value = "MANDATORY";
1283  else if (__kmp_target_offload == tgt_disabled)
1284  value = "DISABLED";
1285  KMP_DEBUG_ASSERT(value);
1286  if (__kmp_env_format) {
1287  KMP_STR_BUF_PRINT_NAME;
1288  } else {
1289  __kmp_str_buf_print(buffer, " %s", name);
1290  }
1291  __kmp_str_buf_print(buffer, "=%s\n", value);
1292 } // __kmp_stg_print_target_offload
1293 
1294 // -----------------------------------------------------------------------------
1295 // OpenMP 4.5: OMP_MAX_TASK_PRIORITY
1296 static void __kmp_stg_parse_max_task_priority(char const *name,
1297  char const *value, void *data) {
1298  __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1299  &__kmp_max_task_priority);
1300 } // __kmp_stg_parse_max_task_priority
1301 
1302 static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1303  char const *name, void *data) {
1304  __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
1305 } // __kmp_stg_print_max_task_priority
1306 
1307 // KMP_TASKLOOP_MIN_TASKS
1308 // taskloop threshold to switch from recursive to linear tasks creation
1309 static void __kmp_stg_parse_taskloop_min_tasks(char const *name,
1310  char const *value, void *data) {
1311  int tmp;
1312  __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1313  __kmp_taskloop_min_tasks = tmp;
1314 } // __kmp_stg_parse_taskloop_min_tasks
1315 
1316 static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
1317  char const *name, void *data) {
1318  __kmp_stg_print_int(buffer, name, __kmp_taskloop_min_tasks);
1319 } // __kmp_stg_print_taskloop_min_tasks
1320 
1321 // -----------------------------------------------------------------------------
1322 // KMP_DISP_NUM_BUFFERS
1323 static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
1324  void *data) {
1325  if (TCR_4(__kmp_init_serial)) {
1326  KMP_WARNING(EnvSerialWarn, name);
1327  return;
1328  } // read value before serial initialization only
1329  __kmp_stg_parse_int(name, value, 1, KMP_MAX_NTH, &__kmp_dispatch_num_buffers);
1330 } // __kmp_stg_parse_disp_buffers
1331 
1332 static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1333  char const *name, void *data) {
1334  __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
1335 } // __kmp_stg_print_disp_buffers
1336 
1337 #if KMP_NESTED_HOT_TEAMS
1338 // -----------------------------------------------------------------------------
1339 // KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
1340 
1341 static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
1342  void *data) {
1343  if (TCR_4(__kmp_init_parallel)) {
1344  KMP_WARNING(EnvParallelWarn, name);
1345  return;
1346  } // read value before first parallel only
1347  __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1348  &__kmp_hot_teams_max_level);
1349 } // __kmp_stg_parse_hot_teams_level
1350 
1351 static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1352  char const *name, void *data) {
1353  __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
1354 } // __kmp_stg_print_hot_teams_level
1355 
1356 static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
1357  void *data) {
1358  if (TCR_4(__kmp_init_parallel)) {
1359  KMP_WARNING(EnvParallelWarn, name);
1360  return;
1361  } // read value before first parallel only
1362  __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1363  &__kmp_hot_teams_mode);
1364 } // __kmp_stg_parse_hot_teams_mode
1365 
1366 static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1367  char const *name, void *data) {
1368  __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
1369 } // __kmp_stg_print_hot_teams_mode
1370 
1371 #endif // KMP_NESTED_HOT_TEAMS
1372 
1373 // -----------------------------------------------------------------------------
1374 // KMP_HANDLE_SIGNALS
1375 
1376 #if KMP_HANDLE_SIGNALS
1377 
1378 static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
1379  void *data) {
1380  __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
1381 } // __kmp_stg_parse_handle_signals
1382 
1383 static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1384  char const *name, void *data) {
1385  __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
1386 } // __kmp_stg_print_handle_signals
1387 
1388 #endif // KMP_HANDLE_SIGNALS
1389 
1390 // -----------------------------------------------------------------------------
1391 // KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
1392 
1393 #ifdef KMP_DEBUG
1394 
1395 #define KMP_STG_X_DEBUG(x) \
1396  static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1397  void *data) { \
1398  __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1399  } /* __kmp_stg_parse_x_debug */ \
1400  static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1401  char const *name, void *data) { \
1402  __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1403  } /* __kmp_stg_print_x_debug */
1404 
1405 KMP_STG_X_DEBUG(a)
1406 KMP_STG_X_DEBUG(b)
1407 KMP_STG_X_DEBUG(c)
1408 KMP_STG_X_DEBUG(d)
1409 KMP_STG_X_DEBUG(e)
1410 KMP_STG_X_DEBUG(f)
1411 
1412 #undef KMP_STG_X_DEBUG
1413 
1414 static void __kmp_stg_parse_debug(char const *name, char const *value,
1415  void *data) {
1416  int debug = 0;
1417  __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1418  if (kmp_a_debug < debug) {
1419  kmp_a_debug = debug;
1420  }
1421  if (kmp_b_debug < debug) {
1422  kmp_b_debug = debug;
1423  }
1424  if (kmp_c_debug < debug) {
1425  kmp_c_debug = debug;
1426  }
1427  if (kmp_d_debug < debug) {
1428  kmp_d_debug = debug;
1429  }
1430  if (kmp_e_debug < debug) {
1431  kmp_e_debug = debug;
1432  }
1433  if (kmp_f_debug < debug) {
1434  kmp_f_debug = debug;
1435  }
1436 } // __kmp_stg_parse_debug
1437 
1438 static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
1439  void *data) {
1440  __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1441  // !!! TODO: Move buffer initialization of of this file! It may works
1442  // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
1443  // KMP_DEBUG_BUF_CHARS.
1444  if (__kmp_debug_buf) {
1445  int i;
1446  int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
1447 
1448  /* allocate and initialize all entries in debug buffer to empty */
1449  __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
1450  for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1451  __kmp_debug_buffer[i] = '\0';
1452 
1453  __kmp_debug_count = 0;
1454  }
1455  K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
1456 } // __kmp_stg_parse_debug_buf
1457 
1458 static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
1459  void *data) {
1460  __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
1461 } // __kmp_stg_print_debug_buf
1462 
1463 static void __kmp_stg_parse_debug_buf_atomic(char const *name,
1464  char const *value, void *data) {
1465  __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
1466 } // __kmp_stg_parse_debug_buf_atomic
1467 
1468 static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1469  char const *name, void *data) {
1470  __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
1471 } // __kmp_stg_print_debug_buf_atomic
1472 
1473 static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
1474  void *data) {
1475  __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1476  &__kmp_debug_buf_chars);
1477 } // __kmp_stg_debug_parse_buf_chars
1478 
1479 static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1480  char const *name, void *data) {
1481  __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
1482 } // __kmp_stg_print_debug_buf_chars
1483 
1484 static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
1485  void *data) {
1486  __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1487  &__kmp_debug_buf_lines);
1488 } // __kmp_stg_parse_debug_buf_lines
1489 
1490 static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1491  char const *name, void *data) {
1492  __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
1493 } // __kmp_stg_print_debug_buf_lines
1494 
1495 static void __kmp_stg_parse_diag(char const *name, char const *value,
1496  void *data) {
1497  __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
1498 } // __kmp_stg_parse_diag
1499 
1500 static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
1501  void *data) {
1502  __kmp_stg_print_int(buffer, name, kmp_diag);
1503 } // __kmp_stg_print_diag
1504 
1505 #endif // KMP_DEBUG
1506 
1507 // -----------------------------------------------------------------------------
1508 // KMP_ALIGN_ALLOC
1509 
1510 static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
1511  void *data) {
1512  __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1513  &__kmp_align_alloc, 1);
1514 } // __kmp_stg_parse_align_alloc
1515 
1516 static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
1517  void *data) {
1518  __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
1519 } // __kmp_stg_print_align_alloc
1520 
1521 // -----------------------------------------------------------------------------
1522 // KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
1523 
1524 // TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
1525 // parse and print functions, pass required info through data argument.
1526 
1527 static void __kmp_stg_parse_barrier_branch_bit(char const *name,
1528  char const *value, void *data) {
1529  const char *var;
1530 
1531  /* ---------- Barrier branch bit control ------------ */
1532  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1533  var = __kmp_barrier_branch_bit_env_name[i];
1534  if ((strcmp(var, name) == 0) && (value != 0)) {
1535  char *comma;
1536 
1537  comma = CCAST(char *, strchr(value, ','));
1538  __kmp_barrier_gather_branch_bits[i] =
1539  (kmp_uint32)__kmp_str_to_int(value, ',');
1540  /* is there a specified release parameter? */
1541  if (comma == NULL) {
1542  __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1543  } else {
1544  __kmp_barrier_release_branch_bits[i] =
1545  (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
1546 
1547  if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1548  __kmp_msg(kmp_ms_warning,
1549  KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1550  __kmp_msg_null);
1551  __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1552  }
1553  }
1554  if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1555  KMP_WARNING(BarrGatherValueInvalid, name, value);
1556  KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1557  __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1558  }
1559  }
1560  K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1561  __kmp_barrier_gather_branch_bits[i],
1562  __kmp_barrier_release_branch_bits[i]))
1563  }
1564 } // __kmp_stg_parse_barrier_branch_bit
1565 
1566 static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1567  char const *name, void *data) {
1568  const char *var;
1569  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1570  var = __kmp_barrier_branch_bit_env_name[i];
1571  if (strcmp(var, name) == 0) {
1572  if (__kmp_env_format) {
1573  KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1574  } else {
1575  __kmp_str_buf_print(buffer, " %s='",
1576  __kmp_barrier_branch_bit_env_name[i]);
1577  }
1578  __kmp_str_buf_print(buffer, "%d,%d'\n",
1579  __kmp_barrier_gather_branch_bits[i],
1580  __kmp_barrier_release_branch_bits[i]);
1581  }
1582  }
1583 } // __kmp_stg_print_barrier_branch_bit
1584 
1585 // ----------------------------------------------------------------------------
1586 // KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
1587 // KMP_REDUCTION_BARRIER_PATTERN
1588 
1589 // TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
1590 // print functions, pass required data to functions through data argument.
1591 
1592 static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
1593  void *data) {
1594  const char *var;
1595  /* ---------- Barrier method control ------------ */
1596 
1597  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1598  var = __kmp_barrier_pattern_env_name[i];
1599 
1600  if ((strcmp(var, name) == 0) && (value != 0)) {
1601  int j;
1602  char *comma = CCAST(char *, strchr(value, ','));
1603 
1604  /* handle first parameter: gather pattern */
1605  for (j = bp_linear_bar; j < bp_last_bar; j++) {
1606  if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1607  ',')) {
1608  __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1609  break;
1610  }
1611  }
1612  if (j == bp_last_bar) {
1613  KMP_WARNING(BarrGatherValueInvalid, name, value);
1614  KMP_INFORM(Using_str_Value, name,
1615  __kmp_barrier_pattern_name[bp_linear_bar]);
1616  }
1617 
1618  /* handle second parameter: release pattern */
1619  if (comma != NULL) {
1620  for (j = bp_linear_bar; j < bp_last_bar; j++) {
1621  if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1622  __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1623  break;
1624  }
1625  }
1626  if (j == bp_last_bar) {
1627  __kmp_msg(kmp_ms_warning,
1628  KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1629  __kmp_msg_null);
1630  KMP_INFORM(Using_str_Value, name,
1631  __kmp_barrier_pattern_name[bp_linear_bar]);
1632  }
1633  }
1634  }
1635  }
1636 } // __kmp_stg_parse_barrier_pattern
1637 
1638 static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1639  char const *name, void *data) {
1640  const char *var;
1641  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1642  var = __kmp_barrier_pattern_env_name[i];
1643  if (strcmp(var, name) == 0) {
1644  int j = __kmp_barrier_gather_pattern[i];
1645  int k = __kmp_barrier_release_pattern[i];
1646  if (__kmp_env_format) {
1647  KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1648  } else {
1649  __kmp_str_buf_print(buffer, " %s='",
1650  __kmp_barrier_pattern_env_name[i]);
1651  }
1652  __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
1653  __kmp_barrier_pattern_name[k]);
1654  }
1655  }
1656 } // __kmp_stg_print_barrier_pattern
1657 
1658 // -----------------------------------------------------------------------------
1659 // KMP_ABORT_DELAY
1660 
1661 static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
1662  void *data) {
1663  // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
1664  // milliseconds.
1665  int delay = __kmp_abort_delay / 1000;
1666  __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1667  __kmp_abort_delay = delay * 1000;
1668 } // __kmp_stg_parse_abort_delay
1669 
1670 static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
1671  void *data) {
1672  __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
1673 } // __kmp_stg_print_abort_delay
1674 
1675 // -----------------------------------------------------------------------------
1676 // KMP_CPUINFO_FILE
1677 
1678 static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
1679  void *data) {
1680 #if KMP_AFFINITY_SUPPORTED
1681  __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1682  K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1683 #endif
1684 } //__kmp_stg_parse_cpuinfo_file
1685 
1686 static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1687  char const *name, void *data) {
1688 #if KMP_AFFINITY_SUPPORTED
1689  if (__kmp_env_format) {
1690  KMP_STR_BUF_PRINT_NAME;
1691  } else {
1692  __kmp_str_buf_print(buffer, " %s", name);
1693  }
1694  if (__kmp_cpuinfo_file) {
1695  __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
1696  } else {
1697  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1698  }
1699 #endif
1700 } //__kmp_stg_print_cpuinfo_file
1701 
1702 // -----------------------------------------------------------------------------
1703 // KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
1704 
1705 static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
1706  void *data) {
1707  kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1708  int rc;
1709 
1710  rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1711  if (rc) {
1712  return;
1713  }
1714  if (reduction->force) {
1715  if (value != 0) {
1716  if (__kmp_str_match("critical", 0, value))
1717  __kmp_force_reduction_method = critical_reduce_block;
1718  else if (__kmp_str_match("atomic", 0, value))
1719  __kmp_force_reduction_method = atomic_reduce_block;
1720  else if (__kmp_str_match("tree", 0, value))
1721  __kmp_force_reduction_method = tree_reduce_block;
1722  else {
1723  KMP_FATAL(UnknownForceReduction, name, value);
1724  }
1725  }
1726  } else {
1727  __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1728  if (__kmp_determ_red) {
1729  __kmp_force_reduction_method = tree_reduce_block;
1730  } else {
1731  __kmp_force_reduction_method = reduction_method_not_defined;
1732  }
1733  }
1734  K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
1735  __kmp_force_reduction_method));
1736 } // __kmp_stg_parse_force_reduction
1737 
1738 static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1739  char const *name, void *data) {
1740 
1741  kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1742  if (reduction->force) {
1743  if (__kmp_force_reduction_method == critical_reduce_block) {
1744  __kmp_stg_print_str(buffer, name, "critical");
1745  } else if (__kmp_force_reduction_method == atomic_reduce_block) {
1746  __kmp_stg_print_str(buffer, name, "atomic");
1747  } else if (__kmp_force_reduction_method == tree_reduce_block) {
1748  __kmp_stg_print_str(buffer, name, "tree");
1749  } else {
1750  if (__kmp_env_format) {
1751  KMP_STR_BUF_PRINT_NAME;
1752  } else {
1753  __kmp_str_buf_print(buffer, " %s", name);
1754  }
1755  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1756  }
1757  } else {
1758  __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1759  }
1760 
1761 } // __kmp_stg_print_force_reduction
1762 
1763 // -----------------------------------------------------------------------------
1764 // KMP_STORAGE_MAP
1765 
1766 static void __kmp_stg_parse_storage_map(char const *name, char const *value,
1767  void *data) {
1768  if (__kmp_str_match("verbose", 1, value)) {
1769  __kmp_storage_map = TRUE;
1770  __kmp_storage_map_verbose = TRUE;
1771  __kmp_storage_map_verbose_specified = TRUE;
1772 
1773  } else {
1774  __kmp_storage_map_verbose = FALSE;
1775  __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
1776  }
1777 } // __kmp_stg_parse_storage_map
1778 
1779 static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
1780  void *data) {
1781  if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1782  __kmp_stg_print_str(buffer, name, "verbose");
1783  } else {
1784  __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1785  }
1786 } // __kmp_stg_print_storage_map
1787 
1788 // -----------------------------------------------------------------------------
1789 // KMP_ALL_THREADPRIVATE
1790 
1791 static void __kmp_stg_parse_all_threadprivate(char const *name,
1792  char const *value, void *data) {
1793  __kmp_stg_parse_int(name, value,
1794  __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1795  __kmp_max_nth, &__kmp_tp_capacity);
1796 } // __kmp_stg_parse_all_threadprivate
1797 
1798 static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1799  char const *name, void *data) {
1800  __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
1801 }
1802 
1803 // -----------------------------------------------------------------------------
1804 // KMP_FOREIGN_THREADS_THREADPRIVATE
1805 
1806 static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
1807  char const *value,
1808  void *data) {
1809  __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
1810 } // __kmp_stg_parse_foreign_threads_threadprivate
1811 
1812 static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
1813  char const *name,
1814  void *data) {
1815  __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
1816 } // __kmp_stg_print_foreign_threads_threadprivate
1817 
1818 // -----------------------------------------------------------------------------
1819 // KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
1820 
1821 #if KMP_AFFINITY_SUPPORTED
1822 // Parse the proc id list. Return TRUE if successful, FALSE otherwise.
1823 static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
1824  const char **nextEnv,
1825  char **proclist) {
1826  const char *scan = env;
1827  const char *next = scan;
1828  int empty = TRUE;
1829 
1830  *proclist = NULL;
1831 
1832  for (;;) {
1833  int start, end, stride;
1834 
1835  SKIP_WS(scan);
1836  next = scan;
1837  if (*next == '\0') {
1838  break;
1839  }
1840 
1841  if (*next == '{') {
1842  int num;
1843  next++; // skip '{'
1844  SKIP_WS(next);
1845  scan = next;
1846 
1847  // Read the first integer in the set.
1848  if ((*next < '0') || (*next > '9')) {
1849  KMP_WARNING(AffSyntaxError, var);
1850  return FALSE;
1851  }
1852  SKIP_DIGITS(next);
1853  num = __kmp_str_to_int(scan, *next);
1854  KMP_ASSERT(num >= 0);
1855 
1856  for (;;) {
1857  // Check for end of set.
1858  SKIP_WS(next);
1859  if (*next == '}') {
1860  next++; // skip '}'
1861  break;
1862  }
1863 
1864  // Skip optional comma.
1865  if (*next == ',') {
1866  next++;
1867  }
1868  SKIP_WS(next);
1869 
1870  // Read the next integer in the set.
1871  scan = next;
1872  if ((*next < '0') || (*next > '9')) {
1873  KMP_WARNING(AffSyntaxError, var);
1874  return FALSE;
1875  }
1876 
1877  SKIP_DIGITS(next);
1878  num = __kmp_str_to_int(scan, *next);
1879  KMP_ASSERT(num >= 0);
1880  }
1881  empty = FALSE;
1882 
1883  SKIP_WS(next);
1884  if (*next == ',') {
1885  next++;
1886  }
1887  scan = next;
1888  continue;
1889  }
1890 
1891  // Next character is not an integer => end of list
1892  if ((*next < '0') || (*next > '9')) {
1893  if (empty) {
1894  KMP_WARNING(AffSyntaxError, var);
1895  return FALSE;
1896  }
1897  break;
1898  }
1899 
1900  // Read the first integer.
1901  SKIP_DIGITS(next);
1902  start = __kmp_str_to_int(scan, *next);
1903  KMP_ASSERT(start >= 0);
1904  SKIP_WS(next);
1905 
1906  // If this isn't a range, then go on.
1907  if (*next != '-') {
1908  empty = FALSE;
1909 
1910  // Skip optional comma.
1911  if (*next == ',') {
1912  next++;
1913  }
1914  scan = next;
1915  continue;
1916  }
1917 
1918  // This is a range. Skip over the '-' and read in the 2nd int.
1919  next++; // skip '-'
1920  SKIP_WS(next);
1921  scan = next;
1922  if ((*next < '0') || (*next > '9')) {
1923  KMP_WARNING(AffSyntaxError, var);
1924  return FALSE;
1925  }
1926  SKIP_DIGITS(next);
1927  end = __kmp_str_to_int(scan, *next);
1928  KMP_ASSERT(end >= 0);
1929 
1930  // Check for a stride parameter
1931  stride = 1;
1932  SKIP_WS(next);
1933  if (*next == ':') {
1934  // A stride is specified. Skip over the ':" and read the 3rd int.
1935  int sign = +1;
1936  next++; // skip ':'
1937  SKIP_WS(next);
1938  scan = next;
1939  if (*next == '-') {
1940  sign = -1;
1941  next++;
1942  SKIP_WS(next);
1943  scan = next;
1944  }
1945  if ((*next < '0') || (*next > '9')) {
1946  KMP_WARNING(AffSyntaxError, var);
1947  return FALSE;
1948  }
1949  SKIP_DIGITS(next);
1950  stride = __kmp_str_to_int(scan, *next);
1951  KMP_ASSERT(stride >= 0);
1952  stride *= sign;
1953  }
1954 
1955  // Do some range checks.
1956  if (stride == 0) {
1957  KMP_WARNING(AffZeroStride, var);
1958  return FALSE;
1959  }
1960  if (stride > 0) {
1961  if (start > end) {
1962  KMP_WARNING(AffStartGreaterEnd, var, start, end);
1963  return FALSE;
1964  }
1965  } else {
1966  if (start < end) {
1967  KMP_WARNING(AffStrideLessZero, var, start, end);
1968  return FALSE;
1969  }
1970  }
1971  if ((end - start) / stride > 65536) {
1972  KMP_WARNING(AffRangeTooBig, var, end, start, stride);
1973  return FALSE;
1974  }
1975 
1976  empty = FALSE;
1977 
1978  // Skip optional comma.
1979  SKIP_WS(next);
1980  if (*next == ',') {
1981  next++;
1982  }
1983  scan = next;
1984  }
1985 
1986  *nextEnv = next;
1987 
1988  {
1989  int len = next - env;
1990  char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
1991  KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
1992  retlist[len] = '\0';
1993  *proclist = retlist;
1994  }
1995  return TRUE;
1996 }
1997 
1998 // If KMP_AFFINITY is specified without a type, then
1999 // __kmp_affinity_notype should point to its setting.
2000 static kmp_setting_t *__kmp_affinity_notype = NULL;
2001 
2002 static void __kmp_parse_affinity_env(char const *name, char const *value,
2003  enum affinity_type *out_type,
2004  char **out_proclist, int *out_verbose,
2005  int *out_warn, int *out_respect,
2006  enum affinity_gran *out_gran,
2007  int *out_gran_levels, int *out_dups,
2008  int *out_compact, int *out_offset) {
2009  char *buffer = NULL; // Copy of env var value.
2010  char *buf = NULL; // Buffer for strtok_r() function.
2011  char *next = NULL; // end of token / start of next.
2012  const char *start; // start of current token (for err msgs)
2013  int count = 0; // Counter of parsed integer numbers.
2014  int number[2]; // Parsed numbers.
2015 
2016  // Guards.
2017  int type = 0;
2018  int proclist = 0;
2019  int verbose = 0;
2020  int warnings = 0;
2021  int respect = 0;
2022  int gran = 0;
2023  int dups = 0;
2024 
2025  KMP_ASSERT(value != NULL);
2026 
2027  if (TCR_4(__kmp_init_middle)) {
2028  KMP_WARNING(EnvMiddleWarn, name);
2029  __kmp_env_toPrint(name, 0);
2030  return;
2031  }
2032  __kmp_env_toPrint(name, 1);
2033 
2034  buffer =
2035  __kmp_str_format("%s", value); // Copy env var to keep original intact.
2036  buf = buffer;
2037  SKIP_WS(buf);
2038 
2039 // Helper macros.
2040 
2041 // If we see a parse error, emit a warning and scan to the next ",".
2042 //
2043 // FIXME - there's got to be a better way to print an error
2044 // message, hopefully without overwriting peices of buf.
2045 #define EMIT_WARN(skip, errlist) \
2046  { \
2047  char ch; \
2048  if (skip) { \
2049  SKIP_TO(next, ','); \
2050  } \
2051  ch = *next; \
2052  *next = '\0'; \
2053  KMP_WARNING errlist; \
2054  *next = ch; \
2055  if (skip) { \
2056  if (ch == ',') \
2057  next++; \
2058  } \
2059  buf = next; \
2060  }
2061 
2062 #define _set_param(_guard, _var, _val) \
2063  { \
2064  if (_guard == 0) { \
2065  _var = _val; \
2066  } else { \
2067  EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2068  } \
2069  ++_guard; \
2070  }
2071 
2072 #define set_type(val) _set_param(type, *out_type, val)
2073 #define set_verbose(val) _set_param(verbose, *out_verbose, val)
2074 #define set_warnings(val) _set_param(warnings, *out_warn, val)
2075 #define set_respect(val) _set_param(respect, *out_respect, val)
2076 #define set_dups(val) _set_param(dups, *out_dups, val)
2077 #define set_proclist(val) _set_param(proclist, *out_proclist, val)
2078 
2079 #define set_gran(val, levels) \
2080  { \
2081  if (gran == 0) { \
2082  *out_gran = val; \
2083  *out_gran_levels = levels; \
2084  } else { \
2085  EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2086  } \
2087  ++gran; \
2088  }
2089 
2090  KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
2091  (__kmp_nested_proc_bind.used > 0));
2092 
2093  while (*buf != '\0') {
2094  start = next = buf;
2095 
2096  if (__kmp_match_str("none", buf, CCAST(const char **, &next))) {
2097  set_type(affinity_none);
2098  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2099  buf = next;
2100  } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) {
2101  set_type(affinity_scatter);
2102  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2103  buf = next;
2104  } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) {
2105  set_type(affinity_compact);
2106  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2107  buf = next;
2108  } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) {
2109  set_type(affinity_logical);
2110  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2111  buf = next;
2112  } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) {
2113  set_type(affinity_physical);
2114  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2115  buf = next;
2116  } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) {
2117  set_type(affinity_explicit);
2118  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2119  buf = next;
2120  } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) {
2121  set_type(affinity_balanced);
2122  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2123  buf = next;
2124  } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) {
2125  set_type(affinity_disabled);
2126  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2127  buf = next;
2128  } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) {
2129  set_verbose(TRUE);
2130  buf = next;
2131  } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) {
2132  set_verbose(FALSE);
2133  buf = next;
2134  } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) {
2135  set_warnings(TRUE);
2136  buf = next;
2137  } else if (__kmp_match_str("nowarnings", buf,
2138  CCAST(const char **, &next))) {
2139  set_warnings(FALSE);
2140  buf = next;
2141  } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) {
2142  set_respect(TRUE);
2143  buf = next;
2144  } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) {
2145  set_respect(FALSE);
2146  buf = next;
2147  } else if (__kmp_match_str("duplicates", buf,
2148  CCAST(const char **, &next)) ||
2149  __kmp_match_str("dups", buf, CCAST(const char **, &next))) {
2150  set_dups(TRUE);
2151  buf = next;
2152  } else if (__kmp_match_str("noduplicates", buf,
2153  CCAST(const char **, &next)) ||
2154  __kmp_match_str("nodups", buf, CCAST(const char **, &next))) {
2155  set_dups(FALSE);
2156  buf = next;
2157  } else if (__kmp_match_str("granularity", buf,
2158  CCAST(const char **, &next)) ||
2159  __kmp_match_str("gran", buf, CCAST(const char **, &next))) {
2160  SKIP_WS(next);
2161  if (*next != '=') {
2162  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2163  continue;
2164  }
2165  next++; // skip '='
2166  SKIP_WS(next);
2167 
2168  buf = next;
2169  if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) {
2170  set_gran(affinity_gran_fine, -1);
2171  buf = next;
2172  } else if (__kmp_match_str("thread", buf, CCAST(const char **, &next))) {
2173  set_gran(affinity_gran_thread, -1);
2174  buf = next;
2175  } else if (__kmp_match_str("core", buf, CCAST(const char **, &next))) {
2176  set_gran(affinity_gran_core, -1);
2177  buf = next;
2178 #if KMP_USE_HWLOC
2179  } else if (__kmp_match_str("tile", buf, CCAST(const char **, &next))) {
2180  set_gran(affinity_gran_tile, -1);
2181  buf = next;
2182 #endif
2183  } else if (__kmp_match_str("package", buf, CCAST(const char **, &next))) {
2184  set_gran(affinity_gran_package, -1);
2185  buf = next;
2186  } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
2187  set_gran(affinity_gran_node, -1);
2188  buf = next;
2189 #if KMP_GROUP_AFFINITY
2190  } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
2191  set_gran(affinity_gran_group, -1);
2192  buf = next;
2193 #endif /* KMP_GROUP AFFINITY */
2194  } else if ((*buf >= '0') && (*buf <= '9')) {
2195  int n;
2196  next = buf;
2197  SKIP_DIGITS(next);
2198  n = __kmp_str_to_int(buf, *next);
2199  KMP_ASSERT(n >= 0);
2200  buf = next;
2201  set_gran(affinity_gran_default, n);
2202  } else {
2203  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2204  continue;
2205  }
2206  } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
2207  char *temp_proclist;
2208 
2209  SKIP_WS(next);
2210  if (*next != '=') {
2211  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2212  continue;
2213  }
2214  next++; // skip '='
2215  SKIP_WS(next);
2216  if (*next != '[') {
2217  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2218  continue;
2219  }
2220  next++; // skip '['
2221  buf = next;
2222  if (!__kmp_parse_affinity_proc_id_list(
2223  name, buf, CCAST(const char **, &next), &temp_proclist)) {
2224  // warning already emitted.
2225  SKIP_TO(next, ']');
2226  if (*next == ']')
2227  next++;
2228  SKIP_TO(next, ',');
2229  if (*next == ',')
2230  next++;
2231  buf = next;
2232  continue;
2233  }
2234  if (*next != ']') {
2235  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2236  continue;
2237  }
2238  next++; // skip ']'
2239  set_proclist(temp_proclist);
2240  } else if ((*buf >= '0') && (*buf <= '9')) {
2241  // Parse integer numbers -- permute and offset.
2242  int n;
2243  next = buf;
2244  SKIP_DIGITS(next);
2245  n = __kmp_str_to_int(buf, *next);
2246  KMP_ASSERT(n >= 0);
2247  buf = next;
2248  if (count < 2) {
2249  number[count] = n;
2250  } else {
2251  KMP_WARNING(AffManyParams, name, start);
2252  }
2253  ++count;
2254  } else {
2255  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2256  continue;
2257  }
2258 
2259  SKIP_WS(next);
2260  if (*next == ',') {
2261  next++;
2262  SKIP_WS(next);
2263  } else if (*next != '\0') {
2264  const char *temp = next;
2265  EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2266  continue;
2267  }
2268  buf = next;
2269  } // while
2270 
2271 #undef EMIT_WARN
2272 #undef _set_param
2273 #undef set_type
2274 #undef set_verbose
2275 #undef set_warnings
2276 #undef set_respect
2277 #undef set_granularity
2278 
2279  __kmp_str_free(&buffer);
2280 
2281  if (proclist) {
2282  if (!type) {
2283  KMP_WARNING(AffProcListNoType, name);
2284  *out_type = affinity_explicit;
2285  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2286  } else if (*out_type != affinity_explicit) {
2287  KMP_WARNING(AffProcListNotExplicit, name);
2288  KMP_ASSERT(*out_proclist != NULL);
2289  KMP_INTERNAL_FREE(*out_proclist);
2290  *out_proclist = NULL;
2291  }
2292  }
2293  switch (*out_type) {
2294  case affinity_logical:
2295  case affinity_physical: {
2296  if (count > 0) {
2297  *out_offset = number[0];
2298  }
2299  if (count > 1) {
2300  KMP_WARNING(AffManyParamsForLogic, name, number[1]);
2301  }
2302  } break;
2303  case affinity_balanced: {
2304  if (count > 0) {
2305  *out_compact = number[0];
2306  }
2307  if (count > 1) {
2308  *out_offset = number[1];
2309  }
2310 
2311  if (__kmp_affinity_gran == affinity_gran_default) {
2312 #if KMP_MIC_SUPPORTED
2313  if (__kmp_mic_type != non_mic) {
2314  if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2315  KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine");
2316  }
2317  __kmp_affinity_gran = affinity_gran_fine;
2318  } else
2319 #endif
2320  {
2321  if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2322  KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core");
2323  }
2324  __kmp_affinity_gran = affinity_gran_core;
2325  }
2326  }
2327  } break;
2328  case affinity_scatter:
2329  case affinity_compact: {
2330  if (count > 0) {
2331  *out_compact = number[0];
2332  }
2333  if (count > 1) {
2334  *out_offset = number[1];
2335  }
2336  } break;
2337  case affinity_explicit: {
2338  if (*out_proclist == NULL) {
2339  KMP_WARNING(AffNoProcList, name);
2340  __kmp_affinity_type = affinity_none;
2341  }
2342  if (count > 0) {
2343  KMP_WARNING(AffNoParam, name, "explicit");
2344  }
2345  } break;
2346  case affinity_none: {
2347  if (count > 0) {
2348  KMP_WARNING(AffNoParam, name, "none");
2349  }
2350  } break;
2351  case affinity_disabled: {
2352  if (count > 0) {
2353  KMP_WARNING(AffNoParam, name, "disabled");
2354  }
2355  } break;
2356  case affinity_default: {
2357  if (count > 0) {
2358  KMP_WARNING(AffNoParam, name, "default");
2359  }
2360  } break;
2361  default: { KMP_ASSERT(0); }
2362  }
2363 } // __kmp_parse_affinity_env
2364 
2365 static void __kmp_stg_parse_affinity(char const *name, char const *value,
2366  void *data) {
2367  kmp_setting_t **rivals = (kmp_setting_t **)data;
2368  int rc;
2369 
2370  rc = __kmp_stg_check_rivals(name, value, rivals);
2371  if (rc) {
2372  return;
2373  }
2374 
2375  __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2376  &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2377  &__kmp_affinity_warnings,
2378  &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2379  &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2380  &__kmp_affinity_compact, &__kmp_affinity_offset);
2381 
2382 } // __kmp_stg_parse_affinity
2383 
2384 static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
2385  void *data) {
2386  if (__kmp_env_format) {
2387  KMP_STR_BUF_PRINT_NAME_EX(name);
2388  } else {
2389  __kmp_str_buf_print(buffer, " %s='", name);
2390  }
2391  if (__kmp_affinity_verbose) {
2392  __kmp_str_buf_print(buffer, "%s,", "verbose");
2393  } else {
2394  __kmp_str_buf_print(buffer, "%s,", "noverbose");
2395  }
2396  if (__kmp_affinity_warnings) {
2397  __kmp_str_buf_print(buffer, "%s,", "warnings");
2398  } else {
2399  __kmp_str_buf_print(buffer, "%s,", "nowarnings");
2400  }
2401  if (KMP_AFFINITY_CAPABLE()) {
2402  if (__kmp_affinity_respect_mask) {
2403  __kmp_str_buf_print(buffer, "%s,", "respect");
2404  } else {
2405  __kmp_str_buf_print(buffer, "%s,", "norespect");
2406  }
2407  switch (__kmp_affinity_gran) {
2408  case affinity_gran_default:
2409  __kmp_str_buf_print(buffer, "%s", "granularity=default,");
2410  break;
2411  case affinity_gran_fine:
2412  __kmp_str_buf_print(buffer, "%s", "granularity=fine,");
2413  break;
2414  case affinity_gran_thread:
2415  __kmp_str_buf_print(buffer, "%s", "granularity=thread,");
2416  break;
2417  case affinity_gran_core:
2418  __kmp_str_buf_print(buffer, "%s", "granularity=core,");
2419  break;
2420  case affinity_gran_package:
2421  __kmp_str_buf_print(buffer, "%s", "granularity=package,");
2422  break;
2423  case affinity_gran_node:
2424  __kmp_str_buf_print(buffer, "%s", "granularity=node,");
2425  break;
2426 #if KMP_GROUP_AFFINITY
2427  case affinity_gran_group:
2428  __kmp_str_buf_print(buffer, "%s", "granularity=group,");
2429  break;
2430 #endif /* KMP_GROUP_AFFINITY */
2431  }
2432  }
2433  if (!KMP_AFFINITY_CAPABLE()) {
2434  __kmp_str_buf_print(buffer, "%s", "disabled");
2435  } else
2436  switch (__kmp_affinity_type) {
2437  case affinity_none:
2438  __kmp_str_buf_print(buffer, "%s", "none");
2439  break;
2440  case affinity_physical:
2441  __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset);
2442  break;
2443  case affinity_logical:
2444  __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset);
2445  break;
2446  case affinity_compact:
2447  __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact,
2448  __kmp_affinity_offset);
2449  break;
2450  case affinity_scatter:
2451  __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact,
2452  __kmp_affinity_offset);
2453  break;
2454  case affinity_explicit:
2455  __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist",
2456  __kmp_affinity_proclist, "explicit");
2457  break;
2458  case affinity_balanced:
2459  __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced",
2460  __kmp_affinity_compact, __kmp_affinity_offset);
2461  break;
2462  case affinity_disabled:
2463  __kmp_str_buf_print(buffer, "%s", "disabled");
2464  break;
2465  case affinity_default:
2466  __kmp_str_buf_print(buffer, "%s", "default");
2467  break;
2468  default:
2469  __kmp_str_buf_print(buffer, "%s", "<unknown>");
2470  break;
2471  }
2472  __kmp_str_buf_print(buffer, "'\n");
2473 } //__kmp_stg_print_affinity
2474 
2475 #ifdef KMP_GOMP_COMPAT
2476 
2477 static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
2478  char const *value, void *data) {
2479  const char *next = NULL;
2480  char *temp_proclist;
2481  kmp_setting_t **rivals = (kmp_setting_t **)data;
2482  int rc;
2483 
2484  rc = __kmp_stg_check_rivals(name, value, rivals);
2485  if (rc) {
2486  return;
2487  }
2488 
2489  if (TCR_4(__kmp_init_middle)) {
2490  KMP_WARNING(EnvMiddleWarn, name);
2491  __kmp_env_toPrint(name, 0);
2492  return;
2493  }
2494 
2495  __kmp_env_toPrint(name, 1);
2496 
2497  if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2498  SKIP_WS(next);
2499  if (*next == '\0') {
2500  // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2501  __kmp_affinity_proclist = temp_proclist;
2502  __kmp_affinity_type = affinity_explicit;
2503  __kmp_affinity_gran = affinity_gran_fine;
2504  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2505  } else {
2506  KMP_WARNING(AffSyntaxError, name);
2507  if (temp_proclist != NULL) {
2508  KMP_INTERNAL_FREE((void *)temp_proclist);
2509  }
2510  }
2511  } else {
2512  // Warning already emitted
2513  __kmp_affinity_type = affinity_none;
2514  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2515  }
2516 } // __kmp_stg_parse_gomp_cpu_affinity
2517 
2518 #endif /* KMP_GOMP_COMPAT */
2519 
2520 /*-----------------------------------------------------------------------------
2521 The OMP_PLACES proc id list parser. Here is the grammar:
2522 
2523 place_list := place
2524 place_list := place , place_list
2525 place := num
2526 place := place : num
2527 place := place : num : signed
2528 place := { subplacelist }
2529 place := ! place // (lowest priority)
2530 subplace_list := subplace
2531 subplace_list := subplace , subplace_list
2532 subplace := num
2533 subplace := num : num
2534 subplace := num : num : signed
2535 signed := num
2536 signed := + signed
2537 signed := - signed
2538 -----------------------------------------------------------------------------*/
2539 
2540 static int __kmp_parse_subplace_list(const char *var, const char **scan) {
2541  const char *next;
2542 
2543  for (;;) {
2544  int start, count, stride;
2545 
2546  //
2547  // Read in the starting proc id
2548  //
2549  SKIP_WS(*scan);
2550  if ((**scan < '0') || (**scan > '9')) {
2551  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2552  return FALSE;
2553  }
2554  next = *scan;
2555  SKIP_DIGITS(next);
2556  start = __kmp_str_to_int(*scan, *next);
2557  KMP_ASSERT(start >= 0);
2558  *scan = next;
2559 
2560  // valid follow sets are ',' ':' and '}'
2561  SKIP_WS(*scan);
2562  if (**scan == '}') {
2563  break;
2564  }
2565  if (**scan == ',') {
2566  (*scan)++; // skip ','
2567  continue;
2568  }
2569  if (**scan != ':') {
2570  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2571  return FALSE;
2572  }
2573  (*scan)++; // skip ':'
2574 
2575  // Read count parameter
2576  SKIP_WS(*scan);
2577  if ((**scan < '0') || (**scan > '9')) {
2578  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2579  return FALSE;
2580  }
2581  next = *scan;
2582  SKIP_DIGITS(next);
2583  count = __kmp_str_to_int(*scan, *next);
2584  KMP_ASSERT(count >= 0);
2585  *scan = next;
2586 
2587  // valid follow sets are ',' ':' and '}'
2588  SKIP_WS(*scan);
2589  if (**scan == '}') {
2590  break;
2591  }
2592  if (**scan == ',') {
2593  (*scan)++; // skip ','
2594  continue;
2595  }
2596  if (**scan != ':') {
2597  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2598  return FALSE;
2599  }
2600  (*scan)++; // skip ':'
2601 
2602  // Read stride parameter
2603  int sign = +1;
2604  for (;;) {
2605  SKIP_WS(*scan);
2606  if (**scan == '+') {
2607  (*scan)++; // skip '+'
2608  continue;
2609  }
2610  if (**scan == '-') {
2611  sign *= -1;
2612  (*scan)++; // skip '-'
2613  continue;
2614  }
2615  break;
2616  }
2617  SKIP_WS(*scan);
2618  if ((**scan < '0') || (**scan > '9')) {
2619  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2620  return FALSE;
2621  }
2622  next = *scan;
2623  SKIP_DIGITS(next);
2624  stride = __kmp_str_to_int(*scan, *next);
2625  KMP_ASSERT(stride >= 0);
2626  *scan = next;
2627  stride *= sign;
2628 
2629  // valid follow sets are ',' and '}'
2630  SKIP_WS(*scan);
2631  if (**scan == '}') {
2632  break;
2633  }
2634  if (**scan == ',') {
2635  (*scan)++; // skip ','
2636  continue;
2637  }
2638 
2639  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2640  return FALSE;
2641  }
2642  return TRUE;
2643 }
2644 
2645 static int __kmp_parse_place(const char *var, const char **scan) {
2646  const char *next;
2647 
2648  // valid follow sets are '{' '!' and num
2649  SKIP_WS(*scan);
2650  if (**scan == '{') {
2651  (*scan)++; // skip '{'
2652  if (!__kmp_parse_subplace_list(var, scan)) {
2653  return FALSE;
2654  }
2655  if (**scan != '}') {
2656  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2657  return FALSE;
2658  }
2659  (*scan)++; // skip '}'
2660  } else if (**scan == '!') {
2661  (*scan)++; // skip '!'
2662  return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2663  } else if ((**scan >= '0') && (**scan <= '9')) {
2664  next = *scan;
2665  SKIP_DIGITS(next);
2666  int proc = __kmp_str_to_int(*scan, *next);
2667  KMP_ASSERT(proc >= 0);
2668  *scan = next;
2669  } else {
2670  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2671  return FALSE;
2672  }
2673  return TRUE;
2674 }
2675 
2676 static int __kmp_parse_place_list(const char *var, const char *env,
2677  char **place_list) {
2678  const char *scan = env;
2679  const char *next = scan;
2680 
2681  for (;;) {
2682  int count, stride;
2683 
2684  if (!__kmp_parse_place(var, &scan)) {
2685  return FALSE;
2686  }
2687 
2688  // valid follow sets are ',' ':' and EOL
2689  SKIP_WS(scan);
2690  if (*scan == '\0') {
2691  break;
2692  }
2693  if (*scan == ',') {
2694  scan++; // skip ','
2695  continue;
2696  }
2697  if (*scan != ':') {
2698  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2699  return FALSE;
2700  }
2701  scan++; // skip ':'
2702 
2703  // Read count parameter
2704  SKIP_WS(scan);
2705  if ((*scan < '0') || (*scan > '9')) {
2706  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2707  return FALSE;
2708  }
2709  next = scan;
2710  SKIP_DIGITS(next);
2711  count = __kmp_str_to_int(scan, *next);
2712  KMP_ASSERT(count >= 0);
2713  scan = next;
2714 
2715  // valid follow sets are ',' ':' and EOL
2716  SKIP_WS(scan);
2717  if (*scan == '\0') {
2718  break;
2719  }
2720  if (*scan == ',') {
2721  scan++; // skip ','
2722  continue;
2723  }
2724  if (*scan != ':') {
2725  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2726  return FALSE;
2727  }
2728  scan++; // skip ':'
2729 
2730  // Read stride parameter
2731  int sign = +1;
2732  for (;;) {
2733  SKIP_WS(scan);
2734  if (*scan == '+') {
2735  scan++; // skip '+'
2736  continue;
2737  }
2738  if (*scan == '-') {
2739  sign *= -1;
2740  scan++; // skip '-'
2741  continue;
2742  }
2743  break;
2744  }
2745  SKIP_WS(scan);
2746  if ((*scan < '0') || (*scan > '9')) {
2747  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2748  return FALSE;
2749  }
2750  next = scan;
2751  SKIP_DIGITS(next);
2752  stride = __kmp_str_to_int(scan, *next);
2753  KMP_ASSERT(stride >= 0);
2754  scan = next;
2755  stride *= sign;
2756 
2757  // valid follow sets are ',' and EOL
2758  SKIP_WS(scan);
2759  if (*scan == '\0') {
2760  break;
2761  }
2762  if (*scan == ',') {
2763  scan++; // skip ','
2764  continue;
2765  }
2766 
2767  KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2768  return FALSE;
2769  }
2770 
2771  {
2772  int len = scan - env;
2773  char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
2774  KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
2775  retlist[len] = '\0';
2776  *place_list = retlist;
2777  }
2778  return TRUE;
2779 }
2780 
2781 static void __kmp_stg_parse_places(char const *name, char const *value,
2782  void *data) {
2783  int count;
2784  const char *scan = value;
2785  const char *next = scan;
2786  const char *kind = "\"threads\"";
2787  kmp_setting_t **rivals = (kmp_setting_t **)data;
2788  int rc;
2789 
2790  rc = __kmp_stg_check_rivals(name, value, rivals);
2791  if (rc) {
2792  return;
2793  }
2794 
2795  // If OMP_PROC_BIND is not specified but OMP_PLACES is,
2796  // then let OMP_PROC_BIND default to true.
2797  if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2798  __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2799  }
2800 
2801  //__kmp_affinity_num_places = 0;
2802 
2803  if (__kmp_match_str("threads", scan, &next)) {
2804  scan = next;
2805  __kmp_affinity_type = affinity_compact;
2806  __kmp_affinity_gran = affinity_gran_thread;
2807  __kmp_affinity_dups = FALSE;
2808  kind = "\"threads\"";
2809  } else if (__kmp_match_str("cores", scan, &next)) {
2810  scan = next;
2811  __kmp_affinity_type = affinity_compact;
2812  __kmp_affinity_gran = affinity_gran_core;
2813  __kmp_affinity_dups = FALSE;
2814  kind = "\"cores\"";
2815 #if KMP_USE_HWLOC
2816  } else if (__kmp_match_str("tiles", scan, &next)) {
2817  scan = next;
2818  __kmp_affinity_type = affinity_compact;
2819  __kmp_affinity_gran = affinity_gran_tile;
2820  __kmp_affinity_dups = FALSE;
2821  kind = "\"tiles\"";
2822 #endif
2823  } else if (__kmp_match_str("sockets", scan, &next)) {
2824  scan = next;
2825  __kmp_affinity_type = affinity_compact;
2826  __kmp_affinity_gran = affinity_gran_package;
2827  __kmp_affinity_dups = FALSE;
2828  kind = "\"sockets\"";
2829  } else {
2830  if (__kmp_affinity_proclist != NULL) {
2831  KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist);
2832  __kmp_affinity_proclist = NULL;
2833  }
2834  if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2835  __kmp_affinity_type = affinity_explicit;
2836  __kmp_affinity_gran = affinity_gran_fine;
2837  __kmp_affinity_dups = FALSE;
2838  if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2839  __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2840  }
2841  }
2842  return;
2843  }
2844 
2845  if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2846  __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2847  }
2848 
2849  SKIP_WS(scan);
2850  if (*scan == '\0') {
2851  return;
2852  }
2853 
2854  // Parse option count parameter in parentheses
2855  if (*scan != '(') {
2856  KMP_WARNING(SyntaxErrorUsing, name, kind);
2857  return;
2858  }
2859  scan++; // skip '('
2860 
2861  SKIP_WS(scan);
2862  next = scan;
2863  SKIP_DIGITS(next);
2864  count = __kmp_str_to_int(scan, *next);
2865  KMP_ASSERT(count >= 0);
2866  scan = next;
2867 
2868  SKIP_WS(scan);
2869  if (*scan != ')') {
2870  KMP_WARNING(SyntaxErrorUsing, name, kind);
2871  return;
2872  }
2873  scan++; // skip ')'
2874 
2875  SKIP_WS(scan);
2876  if (*scan != '\0') {
2877  KMP_WARNING(ParseExtraCharsWarn, name, scan);
2878  }
2879  __kmp_affinity_num_places = count;
2880 }
2881 
2882 static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
2883  void *data) {
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  } else if (__kmp_affinity_type == affinity_explicit) {
2894  if (__kmp_affinity_proclist != NULL) {
2895  __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist);
2896  } else {
2897  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2898  }
2899  } else if (__kmp_affinity_type == affinity_compact) {
2900  int num;
2901  if (__kmp_affinity_num_masks > 0) {
2902  num = __kmp_affinity_num_masks;
2903  } else if (__kmp_affinity_num_places > 0) {
2904  num = __kmp_affinity_num_places;
2905  } else {
2906  num = 0;
2907  }
2908  if (__kmp_affinity_gran == affinity_gran_thread) {
2909  if (num > 0) {
2910  __kmp_str_buf_print(buffer, "='threads(%d)'\n", num);
2911  } else {
2912  __kmp_str_buf_print(buffer, "='threads'\n");
2913  }
2914  } else if (__kmp_affinity_gran == affinity_gran_core) {
2915  if (num > 0) {
2916  __kmp_str_buf_print(buffer, "='cores(%d)' \n", num);
2917  } else {
2918  __kmp_str_buf_print(buffer, "='cores'\n");
2919  }
2920 #if KMP_USE_HWLOC
2921  } else if (__kmp_affinity_gran == affinity_gran_tile) {
2922  if (num > 0) {
2923  __kmp_str_buf_print(buffer, "='tiles(%d)' \n", num);
2924  } else {
2925  __kmp_str_buf_print(buffer, "='tiles'\n");
2926  }
2927 #endif
2928  } else if (__kmp_affinity_gran == affinity_gran_package) {
2929  if (num > 0) {
2930  __kmp_str_buf_print(buffer, "='sockets(%d)'\n", num);
2931  } else {
2932  __kmp_str_buf_print(buffer, "='sockets'\n");
2933  }
2934  } else {
2935  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2936  }
2937  } else {
2938  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2939  }
2940 }
2941 
2942 static void __kmp_stg_parse_topology_method(char const *name, char const *value,
2943  void *data) {
2944  if (__kmp_str_match("all", 1, value)) {
2945  __kmp_affinity_top_method = affinity_top_method_all;
2946  }
2947 #if KMP_USE_HWLOC
2948  else if (__kmp_str_match("hwloc", 1, value)) {
2949  __kmp_affinity_top_method = affinity_top_method_hwloc;
2950  }
2951 #endif
2952 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
2953  else if (__kmp_str_match("x2apic id", 9, value) ||
2954  __kmp_str_match("x2apic_id", 9, value) ||
2955  __kmp_str_match("x2apic-id", 9, value) ||
2956  __kmp_str_match("x2apicid", 8, value) ||
2957  __kmp_str_match("cpuid leaf 11", 13, value) ||
2958  __kmp_str_match("cpuid_leaf_11", 13, value) ||
2959  __kmp_str_match("cpuid-leaf-11", 13, value) ||
2960  __kmp_str_match("cpuid leaf11", 12, value) ||
2961  __kmp_str_match("cpuid_leaf11", 12, value) ||
2962  __kmp_str_match("cpuid-leaf11", 12, value) ||
2963  __kmp_str_match("cpuidleaf 11", 12, value) ||
2964  __kmp_str_match("cpuidleaf_11", 12, value) ||
2965  __kmp_str_match("cpuidleaf-11", 12, value) ||
2966  __kmp_str_match("cpuidleaf11", 11, value) ||
2967  __kmp_str_match("cpuid 11", 8, value) ||
2968  __kmp_str_match("cpuid_11", 8, value) ||
2969  __kmp_str_match("cpuid-11", 8, value) ||
2970  __kmp_str_match("cpuid11", 7, value) ||
2971  __kmp_str_match("leaf 11", 7, value) ||
2972  __kmp_str_match("leaf_11", 7, value) ||
2973  __kmp_str_match("leaf-11", 7, value) ||
2974  __kmp_str_match("leaf11", 6, value)) {
2975  __kmp_affinity_top_method = affinity_top_method_x2apicid;
2976  } else if (__kmp_str_match("apic id", 7, value) ||
2977  __kmp_str_match("apic_id", 7, value) ||
2978  __kmp_str_match("apic-id", 7, value) ||
2979  __kmp_str_match("apicid", 6, value) ||
2980  __kmp_str_match("cpuid leaf 4", 12, value) ||
2981  __kmp_str_match("cpuid_leaf_4", 12, value) ||
2982  __kmp_str_match("cpuid-leaf-4", 12, value) ||
2983  __kmp_str_match("cpuid leaf4", 11, value) ||
2984  __kmp_str_match("cpuid_leaf4", 11, value) ||
2985  __kmp_str_match("cpuid-leaf4", 11, value) ||
2986  __kmp_str_match("cpuidleaf 4", 11, value) ||
2987  __kmp_str_match("cpuidleaf_4", 11, value) ||
2988  __kmp_str_match("cpuidleaf-4", 11, value) ||
2989  __kmp_str_match("cpuidleaf4", 10, value) ||
2990  __kmp_str_match("cpuid 4", 7, value) ||
2991  __kmp_str_match("cpuid_4", 7, value) ||
2992  __kmp_str_match("cpuid-4", 7, value) ||
2993  __kmp_str_match("cpuid4", 6, value) ||
2994  __kmp_str_match("leaf puid4", 6, value) ||
2160;"cpuidleaf_4",ne"> 2990  __kmp_str_match( (root->r.r_uber_thread) {