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 #if OMPD_SUPPORT
29 #include "ompd-specific.h"
30 #endif
31 
32 static int __kmp_env_toPrint(char const *name, int flag);
33 
34 bool __kmp_env_format = 0; // 0 - old format; 1 - new format
35 
36 // -----------------------------------------------------------------------------
37 // Helper string functions. Subject to move to kmp_str.
38 
39 #ifdef USE_LOAD_BALANCE
40 static double __kmp_convert_to_double(char const *s) {
41  double result;
42 
43  if (KMP_SSCANF(s, "%lf", &result) < 1) {
44  result = 0.0;
45  }
46 
47  return result;
48 }
49 #endif
50 
51 #ifdef KMP_DEBUG
52 static unsigned int __kmp_readstr_with_sentinel(char *dest, char const *src,
53  size_t len, char sentinel) {
54  unsigned int i;
55  for (i = 0; i < len; i++) {
56  if ((*src == '\0') || (*src == sentinel)) {
57  break;
58  }
59  *(dest++) = *(src++);
60  }
61  *dest = '\0';
62  return i;
63 }
64 #endif
65 
66 static int __kmp_match_with_sentinel(char const *a, char const *b, size_t len,
67  char sentinel) {
68  size_t l = 0;
69 
70  if (a == NULL)
71  a = "";
72  if (b == NULL)
73  b = "";
74  while (*a && *b && *b != sentinel) {
75  char ca = *a, cb = *b;
76 
77  if (ca >= 'a' && ca <= 'z')
78  ca -= 'a' - 'A';
79  if (cb >= 'a' && cb <= 'z')
80  cb -= 'a' - 'A';
81  if (ca != cb)
82  return FALSE;
83  ++l;
84  ++a;
85  ++b;
86  }
87  return l >= len;
88 }
89 
90 // Expected usage:
91 // token is the token to check for.
92 // buf is the string being parsed.
93 // *end returns the char after the end of the token.
94 // it is not modified unless a match occurs.
95 //
96 // Example 1:
97 //
98 // if (__kmp_match_str("token", buf, *end) {
99 // <do something>
100 // buf = end;
101 // }
102 //
103 // Example 2:
104 //
105 // if (__kmp_match_str("token", buf, *end) {
106 // char *save = **end;
107 // **end = sentinel;
108 // <use any of the __kmp*_with_sentinel() functions>
109 // **end = save;
110 // buf = end;
111 // }
112 
113 static int __kmp_match_str(char const *token, char const *buf,
114  const char **end) {
115 
116  KMP_ASSERT(token != NULL);
117  KMP_ASSERT(buf != NULL);
118  KMP_ASSERT(end != NULL);
119 
120  while (*token && *buf) {
121  char ct = *token, cb = *buf;
122 
123  if (ct >= 'a' && ct <= 'z')
124  ct -= 'a' - 'A';
125  if (cb >= 'a' && cb <= 'z')
126  cb -= 'a' - 'A';
127  if (ct != cb)
128  return FALSE;
129  ++token;
130  ++buf;
131  }
132  if (*token) {
133  return FALSE;
134  }
135  *end = buf;
136  return TRUE;
137 }
138 
139 #if KMP_OS_DARWIN
140 static size_t __kmp_round4k(size_t size) {
141  size_t _4k = 4 * 1024;
142  if (size & (_4k - 1)) {
143  size &= ~(_4k - 1);
144  if (size <= KMP_SIZE_T_MAX - _4k) {
145  size += _4k; // Round up if there is no overflow.
146  }
147  }
148  return size;
149 } // __kmp_round4k
150 #endif
151 
152 /* Here, multipliers are like __kmp_convert_to_seconds, but floating-point
153  values are allowed, and the return value is in milliseconds. The default
154  multiplier is milliseconds. Returns INT_MAX only if the value specified
155  matches "infinit*". Returns -1 if specified string is invalid. */
156 int __kmp_convert_to_milliseconds(char const *data) {
157  int ret, nvalues, factor;
158  char mult, extra;
159  double value;
160 
161  if (data == NULL)
162  return (-1);
163  if (__kmp_str_match("infinit", -1, data))
164  return (INT_MAX);
165  value = (double)0.0;
166  mult = '\0';
167  nvalues = KMP_SSCANF(data, "%lf%c%c", &value, &mult, &extra);
168  if (nvalues < 1)
169  return (-1);
170  if (nvalues == 1)
171  mult = '\0';
172  if (nvalues == 3)
173  return (-1);
174 
175  if (value < 0)
176  return (-1);
177 
178  switch (mult) {
179  case '\0':
180  /* default is milliseconds */
181  factor = 1;
182  break;
183  case 's':
184  case 'S':
185  factor = 1000;
186  break;
187  case 'm':
188  case 'M':
189  factor = 1000 * 60;
190  break;
191  case 'h':
192  case 'H':
193  factor = 1000 * 60 * 60;
194  break;
195  case 'd':
196  case 'D':
197  factor = 1000 * 24 * 60 * 60;
198  break;
199  default:
200  return (-1);
201  }
202 
203  if (value >= ((INT_MAX - 1) / factor))
204  ret = INT_MAX - 1; /* Don't allow infinite value here */
205  else
206  ret = (int)(value * (double)factor); /* truncate to int */
207 
208  return ret;
209 }
210 
211 static int __kmp_strcasecmp_with_sentinel(char const *a, char const *b,
212  char sentinel) {
213  if (a == NULL)
214  a = "";
215  if (b == NULL)
216  b = "";
217  while (*a && *b && *b != sentinel) {
218  char ca = *a, cb = *b;
219 
220  if (ca >= 'a' && ca <= 'z')
221  ca -= 'a' - 'A';
222  if (cb >= 'a' && cb <= 'z')
223  cb -= 'a' - 'A';
224  if (ca != cb)
225  return (int)(unsigned char)*a - (int)(unsigned char)*b;
226  ++a;
227  ++b;
228  }
229  return *a ? (*b && *b != sentinel)
230  ? (int)(unsigned char)*a - (int)(unsigned char)*b
231  : 1
232  : (*b && *b != sentinel) ? -1
233  : 0;
234 }
235 
236 // =============================================================================
237 // Table structures and helper functions.
238 
239 typedef struct __kmp_setting kmp_setting_t;
240 typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
241 typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
242 typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
243 
244 typedef void (*kmp_stg_parse_func_t)(char const *name, char const *value,
245  void *data);
246 typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer, char const *name,
247  void *data);
248 
249 struct __kmp_setting {
250  char const *name; // Name of setting (environment variable).
251  kmp_stg_parse_func_t parse; // Parser function.
252  kmp_stg_print_func_t print; // Print function.
253  void *data; // Data passed to parser and printer.
254  int set; // Variable set during this "session"
255  // (__kmp_env_initialize() or kmp_set_defaults() call).
256  int defined; // Variable set in any "session".
257 }; // struct __kmp_setting
258 
259 struct __kmp_stg_ss_data {
260  size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
261  kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
262 }; // struct __kmp_stg_ss_data
263 
264 struct __kmp_stg_wp_data {
265  int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
266  kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
267 }; // struct __kmp_stg_wp_data
268 
269 struct __kmp_stg_fr_data {
270  int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
271  kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
272 }; // struct __kmp_stg_fr_data
273 
274 static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
275  char const *name, // Name of variable.
276  char const *value, // Value of the variable.
277  kmp_setting_t **rivals // List of rival settings (must include current one).
278 );
279 
280 // -----------------------------------------------------------------------------
281 // Helper parse functions.
282 
283 static void __kmp_stg_parse_bool(char const *name, char const *value,
284  int *out) {
285  if (__kmp_str_match_true(value)) {
286  *out = TRUE;
287  } else if (__kmp_str_match_false(value)) {
288  *out = FALSE;
289  } else {
290  __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
291  KMP_HNT(ValidBoolValues), __kmp_msg_null);
292  }
293 } // __kmp_stg_parse_bool
294 
295 // placed here in order to use __kmp_round4k static function
296 void __kmp_check_stksize(size_t *val) {
297  // if system stack size is too big then limit the size for worker threads
298  if (*val > KMP_DEFAULT_STKSIZE * 16) // just a heuristics...
299  *val = KMP_DEFAULT_STKSIZE * 16;
300  if (*val < KMP_MIN_STKSIZE)
301  *val = KMP_MIN_STKSIZE;
302  if (*val > KMP_MAX_STKSIZE)
303  *val = KMP_MAX_STKSIZE; // dead code currently, but may work in future
304 #if KMP_OS_DARWIN
305  *val = __kmp_round4k(*val);
306 #endif // KMP_OS_DARWIN
307 }
308 
309 static void __kmp_stg_parse_size(char const *name, char const *value,
310  size_t size_min, size_t size_max,
311  int *is_specified, size_t *out,
312  size_t factor) {
313  char const *msg = NULL;
314 #if KMP_OS_DARWIN
315  size_min = __kmp_round4k(size_min);
316  size_max = __kmp_round4k(size_max);
317 #endif // KMP_OS_DARWIN
318  if (value) {
319  if (is_specified != NULL) {
320  *is_specified = 1;
321  }
322  __kmp_str_to_size(value, out, factor, &msg);
323  if (msg == NULL) {
324  if (*out > size_max) {
325  *out = size_max;
326  msg = KMP_I18N_STR(ValueTooLarge);
327  } else if (*out < size_min) {
328  *out = size_min;
329  msg = KMP_I18N_STR(ValueTooSmall);
330  } else {
331 #if KMP_OS_DARWIN
332  size_t round4k = __kmp_round4k(*out);
333  if (*out != round4k) {
334  *out = round4k;
335  msg = KMP_I18N_STR(NotMultiple4K);
336  }
337 #endif
338  }
339  } else {
340  // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to
341  // size_max silently.
342  if (*out < size_min) {
343  *out = size_max;
344  } else if (*out > size_max) {
345  *out = size_max;
346  }
347  }
348  if (msg != NULL) {
349  // Message is not empty. Print warning.
350  kmp_str_buf_t buf;
351  __kmp_str_buf_init(&buf);
352  __kmp_str_buf_print_size(&buf, *out);
353  KMP_WARNING(ParseSizeIntWarn, name, value, msg);
354  KMP_INFORM(Using_str_Value, name, buf.str);
355  __kmp_str_buf_free(&buf);
356  }
357  }
358 } // __kmp_stg_parse_size
359 
360 static void __kmp_stg_parse_str(char const *name, char const *value,
361  char **out) {
362  __kmp_str_free(out);
363  *out = __kmp_str_format("%s", value);
364 } // __kmp_stg_parse_str
365 
366 static void __kmp_stg_parse_int(
367  char const
368  *name, // I: Name of environment variable (used in warning messages).
369  char const *value, // I: Value of environment variable to parse.
370  int min, // I: Minimum allowed value.
371  int max, // I: Maximum allowed value.
372  int *out // O: Output (parsed) value.
373 ) {
374  char const *msg = NULL;
375  kmp_uint64 uint = *out;
376  __kmp_str_to_uint(value, &uint, &msg);
377  if (msg == NULL) {
378  if (uint < (unsigned int)min) {
379  msg = KMP_I18N_STR(ValueTooSmall);
380  uint = min;
381  } else if (uint > (unsigned int)max) {
382  msg = KMP_I18N_STR(ValueTooLarge);
383  uint = max;
384  }
385  } else {
386  // If overflow occurred msg contains error message and uint is very big. Cut
387  // tmp it to INT_MAX.
388  if (uint < (unsigned int)min) {
389  uint = min;
390  } else if (uint > (unsigned int)max) {
391  uint = max;
392  }
393  }
394  if (msg != NULL) {
395  // Message is not empty. Print warning.
396  kmp_str_buf_t buf;
397  KMP_WARNING(ParseSizeIntWarn, name, value, msg);
398  __kmp_str_buf_init(&buf);
399  __kmp_str_buf_print(&buf, "%" KMP_UINT64_SPEC "", uint);
400  KMP_INFORM(Using_uint64_Value, name, buf.str);
401  __kmp_str_buf_free(&buf);
402  }
403  __kmp_type_convert(uint, out);
404 } // __kmp_stg_parse_int
405 
406 #if KMP_DEBUG_ADAPTIVE_LOCKS
407 static void __kmp_stg_parse_file(char const *name, char const *value,
408  const char *suffix, char **out) {
409  char buffer[256];
410  char *t;
411  int hasSuffix;
412  __kmp_str_free(out);
413  t = (char *)strrchr(value, '.');
414  hasSuffix = t && __kmp_str_eqf(t, suffix);
415  t = __kmp_str_format("%s%s", value, hasSuffix ? "" : suffix);
416  __kmp_expand_file_name(buffer, sizeof(buffer), t);
417  __kmp_str_free(&t);
418  *out = __kmp_str_format("%s", buffer);
419 } // __kmp_stg_parse_file
420 #endif
421 
422 #ifdef KMP_DEBUG
423 static char *par_range_to_print = NULL;
424 
425 static void __kmp_stg_parse_par_range(char const *name, char const *value,
426  int *out_range, char *out_routine,
427  char *out_file, int *out_lb,
428  int *out_ub) {
429  size_t len = KMP_STRLEN(value) + 1;
430  par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
431  KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
432  __kmp_par_range = +1;
433  __kmp_par_range_lb = 0;
434  __kmp_par_range_ub = INT_MAX;
435  for (;;) {
436  unsigned int len;
437  if (*value == '\0') {
438  break;
439  }
440  if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
441  value = strchr(value, '=') + 1;
442  len = __kmp_readstr_with_sentinel(out_routine, value,
443  KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
444  if (len == 0) {
445  goto par_range_error;
446  }
447  value = strchr(value, ',');
448  if (value != NULL) {
449  value++;
450  }
451  continue;
452  }
453  if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
454  value = strchr(value, '=') + 1;
455  len = __kmp_readstr_with_sentinel(out_file, value,
456  KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
457  if (len == 0) {
458  goto par_range_error;
459  }
460  value = strchr(value, ',');
461  if (value != NULL) {
462  value++;
463  }
464  continue;
465  }
466  if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
467  (!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
468  value = strchr(value, '=') + 1;
469  if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
470  goto par_range_error;
471  }
472  *out_range = +1;
473  value = strchr(value, ',');
474  if (value != NULL) {
475  value++;
476  }
477  continue;
478  }
479  if (!__kmp_strcasecmp_with_sentinel("excl_range", value, '=')) {
480  value = strchr(value, '=') + 1;
481  if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
482  goto par_range_error;
483  }
484  *out_range = -1;
485  value = strchr(value, ',');
486  if (value != NULL) {
487  value++;
488  }
489  continue;
490  }
491  par_range_error:
492  KMP_WARNING(ParRangeSyntax, name);
493  __kmp_par_range = 0;
494  break;
495  }
496 } // __kmp_stg_parse_par_range
497 #endif
498 
499 int __kmp_initial_threads_capacity(int req_nproc) {
500  int nth = 32;
501 
502  /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
503  * __kmp_max_nth) */
504  if (nth < (4 * req_nproc))
505  nth = (4 * req_nproc);
506  if (nth < (4 * __kmp_xproc))
507  nth = (4 * __kmp_xproc);
508 
509  // If hidden helper task is enabled, we initialize the thread capacity with
510  // extra __kmp_hidden_helper_threads_num.
511  if (__kmp_enable_hidden_helper) {
512  nth += __kmp_hidden_helper_threads_num;
513  }
514 
515  if (nth > __kmp_max_nth)
516  nth = __kmp_max_nth;
517 
518  return nth;
519 }
520 
521 int __kmp_default_tp_capacity(int req_nproc, int max_nth,
522  int all_threads_specified) {
523  int nth = 128;
524 
525  if (all_threads_specified)
526  return max_nth;
527  /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
528  * __kmp_max_nth ) */
529  if (nth < (4 * req_nproc))
530  nth = (4 * req_nproc);
531  if (nth < (4 * __kmp_xproc))
532  nth = (4 * __kmp_xproc);
533 
534  if (nth > __kmp_max_nth)
535  nth = __kmp_max_nth;
536 
537  return nth;
538 }
539 
540 // -----------------------------------------------------------------------------
541 // Helper print functions.
542 
543 static void __kmp_stg_print_bool(kmp_str_buf_t *buffer, char const *name,
544  int value) {
545  if (__kmp_env_format) {
546  KMP_STR_BUF_PRINT_BOOL;
547  } else {
548  __kmp_str_buf_print(buffer, " %s=%s\n", name, value ? "true" : "false");
549  }
550 } // __kmp_stg_print_bool
551 
552 static void __kmp_stg_print_int(kmp_str_buf_t *buffer, char const *name,
553  int value) {
554  if (__kmp_env_format) {
555  KMP_STR_BUF_PRINT_INT;
556  } else {
557  __kmp_str_buf_print(buffer, " %s=%d\n", name, value);
558  }
559 } // __kmp_stg_print_int
560 
561 static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer, char const *name,
562  kmp_uint64 value) {
563  if (__kmp_env_format) {
564  KMP_STR_BUF_PRINT_UINT64;
565  } else {
566  __kmp_str_buf_print(buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value);
567  }
568 } // __kmp_stg_print_uint64
569 
570 static void __kmp_stg_print_str(kmp_str_buf_t *buffer, char const *name,
571  char const *value) {
572  if (__kmp_env_format) {
573  KMP_STR_BUF_PRINT_STR;
574  } else {
575  __kmp_str_buf_print(buffer, " %s=%s\n", name, value);
576  }
577 } // __kmp_stg_print_str
578 
579 static void __kmp_stg_print_size(kmp_str_buf_t *buffer, char const *name,
580  size_t value) {
581  if (__kmp_env_format) {
582  KMP_STR_BUF_PRINT_NAME_EX(name);
583  __kmp_str_buf_print_size(buffer, value);
584  __kmp_str_buf_print(buffer, "'\n");
585  } else {
586  __kmp_str_buf_print(buffer, " %s=", name);
587  __kmp_str_buf_print_size(buffer, value);
588  __kmp_str_buf_print(buffer, "\n");
589  return;
590  }
591 } // __kmp_stg_print_size
592 
593 // =============================================================================
594 // Parse and print functions.
595 
596 // -----------------------------------------------------------------------------
597 // KMP_DEVICE_THREAD_LIMIT, KMP_ALL_THREADS
598 
599 static void __kmp_stg_parse_device_thread_limit(char const *name,
600  char const *value, void *data) {
601  kmp_setting_t **rivals = (kmp_setting_t **)data;
602  int rc;
603  if (strcmp(name, "KMP_ALL_THREADS") == 0) {
604  KMP_INFORM(EnvVarDeprecated, name, "KMP_DEVICE_THREAD_LIMIT");
605  }
606  rc = __kmp_stg_check_rivals(name, value, rivals);
607  if (rc) {
608  return;
609  }
610  if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
611  __kmp_max_nth = __kmp_xproc;
612  __kmp_allThreadsSpecified = 1;
613  } else {
614  __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
615  __kmp_allThreadsSpecified = 0;
616  }
617  K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));
618 
619 } // __kmp_stg_parse_device_thread_limit
620 
621 static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
622  char const *name, void *data) {
623  __kmp_stg_print_int(buffer, name, __kmp_max_nth);
624 } // __kmp_stg_print_device_thread_limit
625 
626 // -----------------------------------------------------------------------------
627 // OMP_THREAD_LIMIT
628 static void __kmp_stg_parse_thread_limit(char const *name, char const *value,
629  void *data) {
630  __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
631  K_DIAG(1, ("__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));
632 
633 } // __kmp_stg_parse_thread_limit
634 
635 static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
636  char const *name, void *data) {
637  __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
638 } // __kmp_stg_print_thread_limit
639 
640 // -----------------------------------------------------------------------------
641 // OMP_NUM_TEAMS
642 static void __kmp_stg_parse_nteams(char const *name, char const *value,
643  void *data) {
644  __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_nteams);
645  K_DIAG(1, ("__kmp_nteams == %d\n", __kmp_nteams));
646 } // __kmp_stg_parse_nteams
647 
648 static void __kmp_stg_print_nteams(kmp_str_buf_t *buffer, char const *name,
649  void *data) {
650  __kmp_stg_print_int(buffer, name, __kmp_nteams);
651 } // __kmp_stg_print_nteams
652 
653 // -----------------------------------------------------------------------------
654 // OMP_TEAMS_THREAD_LIMIT
655 static void __kmp_stg_parse_teams_th_limit(char const *name, char const *value,
656  void *data) {
657  __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth,
658  &__kmp_teams_thread_limit);
659  K_DIAG(1, ("__kmp_teams_thread_limit == %d\n", __kmp_teams_thread_limit));
660 } // __kmp_stg_parse_teams_th_limit
661 
662 static void __kmp_stg_print_teams_th_limit(kmp_str_buf_t *buffer,
663  char const *name, void *data) {
664  __kmp_stg_print_int(buffer, name, __kmp_teams_thread_limit);
665 } // __kmp_stg_print_teams_th_limit
666 
667 // -----------------------------------------------------------------------------
668 // KMP_TEAMS_THREAD_LIMIT
669 static void __kmp_stg_parse_teams_thread_limit(char const *name,
670  char const *value, void *data) {
671  __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
672 } // __kmp_stg_teams_thread_limit
673 
674 static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
675  char const *name, void *data) {
676  __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
677 } // __kmp_stg_print_teams_thread_limit
678 
679 // -----------------------------------------------------------------------------
680 // KMP_USE_YIELD
681 static void __kmp_stg_parse_use_yield(char const *name, char const *value,
682  void *data) {
683  __kmp_stg_parse_int(name, value, 0, 2, &__kmp_use_yield);
684  __kmp_use_yield_exp_set = 1;
685 } // __kmp_stg_parse_use_yield
686 
687 static void __kmp_stg_print_use_yield(kmp_str_buf_t *buffer, char const *name,
688  void *data) {
689  __kmp_stg_print_int(buffer, name, __kmp_use_yield);
690 } // __kmp_stg_print_use_yield
691 
692 // -----------------------------------------------------------------------------
693 // KMP_BLOCKTIME
694 
695 static void __kmp_stg_parse_blocktime(char const *name, char const *value,
696  void *data) {
697  __kmp_dflt_blocktime = __kmp_convert_to_milliseconds(value);
698  if (__kmp_dflt_blocktime < 0) {
699  __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
700  __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
701  __kmp_msg_null);
702  KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime);
703  __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
704  } else {
705  if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
706  __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
707  __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
708  __kmp_msg_null);
709  KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime);
710  } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
711  __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
712  __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
713  __kmp_msg_null);
714  KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime);
715  }
716  __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
717  }
718 #if KMP_USE_MONITOR
719  // calculate number of monitor thread wakeup intervals corresponding to
720  // blocktime.
721  __kmp_monitor_wakeups =
722  KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
723  __kmp_bt_intervals =
724  KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
725 #endif
726  K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
727  if (__kmp_env_blocktime) {
728  K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
729  }
730 } // __kmp_stg_parse_blocktime
731 
732 static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
733  void *data) {
734  __kmp_stg_print_int(buffer, name, __kmp_dflt_blocktime);
735 } // __kmp_stg_print_blocktime
736 
737 // -----------------------------------------------------------------------------
738 // KMP_DUPLICATE_LIB_OK
739 
740 static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
741  char const *value, void *data) {
742  /* actually this variable is not supported, put here for compatibility with
743  earlier builds and for static/dynamic combination */
744  __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
745 } // __kmp_stg_parse_duplicate_lib_ok
746 
747 static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
748  char const *name, void *data) {
749  __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
750 } // __kmp_stg_print_duplicate_lib_ok
751 
752 // -----------------------------------------------------------------------------
753 // KMP_INHERIT_FP_CONTROL
754 
755 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
756 
757 static void __kmp_stg_parse_inherit_fp_control(char const *name,
758  char const *value, void *data) {
759  __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
760 } // __kmp_stg_parse_inherit_fp_control
761 
762 static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
763  char const *name, void *data) {
764 #if KMP_DEBUG
765  __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
766 #endif /* KMP_DEBUG */
767 } // __kmp_stg_print_inherit_fp_control
768 
769 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
770 
771 // Used for OMP_WAIT_POLICY
772 static char const *blocktime_str = NULL;
773 
774 // -----------------------------------------------------------------------------
775 // KMP_LIBRARY, OMP_WAIT_POLICY
776 
777 static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
778  void *data) {
779 
780  kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
781  int rc;
782 
783  rc = __kmp_stg_check_rivals(name, value, wait->rivals);
784  if (rc) {
785  return;
786  }
787 
788  if (wait->omp) {
789  if (__kmp_str_match("ACTIVE", 1, value)) {
790  __kmp_library = library_turnaround;
791  if (blocktime_str == NULL) {
792  // KMP_BLOCKTIME not specified, so set default to "infinite".
793  __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
794  }
795  } else if (__kmp_str_match("PASSIVE", 1, value)) {
796  __kmp_library = library_throughput;
797  if (blocktime_str == NULL) {
798  // KMP_BLOCKTIME not specified, so set default to 0.
799  __kmp_dflt_blocktime = 0;
800  }
801  } else {
802  KMP_WARNING(StgInvalidValue, name, value);
803  }
804  } else {
805  if (__kmp_str_match("serial", 1, value)) { /* S */
806  __kmp_library = library_serial;
807  } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
808  __kmp_library = library_throughput;
809  if (blocktime_str == NULL) {
810  // KMP_BLOCKTIME not specified, so set default to 0.
811  __kmp_dflt_blocktime = 0;
812  }
813  } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
814  __kmp_library = library_turnaround;
815  } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
816  __kmp_library = library_turnaround;
817  } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
818  __kmp_library = library_throughput;
819  if (blocktime_str == NULL) {
820  // KMP_BLOCKTIME not specified, so set default to 0.
821  __kmp_dflt_blocktime = 0;
822  }
823  } else {
824  KMP_WARNING(StgInvalidValue, name, value);
825  }
826  }
827 } // __kmp_stg_parse_wait_policy
828 
829 static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
830  void *data) {
831 
832  kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
833  char const *value = NULL;
834 
835  if (wait->omp) {
836  switch (__kmp_library) {
837  case library_turnaround: {
838  value = "ACTIVE";
839  } break;
840  case library_throughput: {
841  value = "PASSIVE";
842  } break;
843  }
844  } else {
845  switch (__kmp_library) {
846  case library_serial: {
847  value = "serial";
848  } break;
849  case library_turnaround: {
850  value = "turnaround";
851  } break;
852  case library_throughput: {
853  value = "throughput";
854  } break;
855  }
856  }
857  if (value != NULL) {
858  __kmp_stg_print_str(buffer, name, value);
859  }
860 
861 } // __kmp_stg_print_wait_policy
862 
863 #if KMP_USE_MONITOR
864 // -----------------------------------------------------------------------------
865 // KMP_MONITOR_STACKSIZE
866 
867 static void __kmp_stg_parse_monitor_stacksize(char const *name,
868  char const *value, void *data) {
869  __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
870  NULL, &__kmp_monitor_stksize, 1);
871 } // __kmp_stg_parse_monitor_stacksize
872 
873 static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
874  char const *name, void *data) {
875  if (__kmp_env_format) {
876  if (__kmp_monitor_stksize > 0)
877  KMP_STR_BUF_PRINT_NAME_EX(name);
878  else
879  KMP_STR_BUF_PRINT_NAME;
880  } else {
881  __kmp_str_buf_print(buffer, " %s", name);
882  }
883  if (__kmp_monitor_stksize > 0) {
884  __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
885  } else {
886  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
887  }
888  if (__kmp_env_format && __kmp_monitor_stksize) {
889  __kmp_str_buf_print(buffer, "'\n");
890  }
891 } // __kmp_stg_print_monitor_stacksize
892 #endif // KMP_USE_MONITOR
893 
894 // -----------------------------------------------------------------------------
895 // KMP_SETTINGS
896 
897 static void __kmp_stg_parse_settings(char const *name, char const *value,
898  void *data) {
899  __kmp_stg_parse_bool(name, value, &__kmp_settings);
900 } // __kmp_stg_parse_settings
901 
902 static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
903  void *data) {
904  __kmp_stg_print_bool(buffer, name, __kmp_settings);
905 } // __kmp_stg_print_settings
906 
907 // -----------------------------------------------------------------------------
908 // KMP_STACKPAD
909 
910 static void __kmp_stg_parse_stackpad(char const *name, char const *value,
911  void *data) {
912  __kmp_stg_parse_int(name, // Env var name
913  value, // Env var value
914  KMP_MIN_STKPADDING, // Min value
915  KMP_MAX_STKPADDING, // Max value
916  &__kmp_stkpadding // Var to initialize
917  );
918 } // __kmp_stg_parse_stackpad
919 
920 static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
921  void *data) {
922  __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
923 } // __kmp_stg_print_stackpad
924 
925 // -----------------------------------------------------------------------------
926 // KMP_STACKOFFSET
927 
928 static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
929  void *data) {
930  __kmp_stg_parse_size(name, // Env var name
931  value, // Env var value
932  KMP_MIN_STKOFFSET, // Min value
933  KMP_MAX_STKOFFSET, // Max value
934  NULL, //
935  &__kmp_stkoffset, // Var to initialize
936  1);
937 } // __kmp_stg_parse_stackoffset
938 
939 static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
940  void *data) {
941  __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
942 } // __kmp_stg_print_stackoffset
943 
944 // -----------------------------------------------------------------------------
945 // KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
946 
947 static void __kmp_stg_parse_stacksize(char const *name, char const *value,
948  void *data) {
949 
950  kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
951  int rc;
952 
953  rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
954  if (rc) {
955  return;
956  }
957  __kmp_stg_parse_size(name, // Env var name
958  value, // Env var value
959  __kmp_sys_min_stksize, // Min value
960  KMP_MAX_STKSIZE, // Max value
961  &__kmp_env_stksize, //
962  &__kmp_stksize, // Var to initialize
963  stacksize->factor);
964 
965 } // __kmp_stg_parse_stacksize
966 
967 // This function is called for printing both KMP_STACKSIZE (factor is 1) and
968 // OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
969 // OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
970 // customer request in future.
971 static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
972  void *data) {
973  kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
974  if (__kmp_env_format) {
975  KMP_STR_BUF_PRINT_NAME_EX(name);
976  __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
977  ? __kmp_stksize / stacksize->factor
978  : __kmp_stksize);
979  __kmp_str_buf_print(buffer, "'\n");
980  } else {
981  __kmp_str_buf_print(buffer, " %s=", name);
982  __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
983  ? __kmp_stksize / stacksize->factor
984  : __kmp_stksize);
985  __kmp_str_buf_print(buffer, "\n");
986  }
987 } // __kmp_stg_print_stacksize
988 
989 // -----------------------------------------------------------------------------
990 // KMP_VERSION
991 
992 static void __kmp_stg_parse_version(char const *name, char const *value,
993  void *data) {
994  __kmp_stg_parse_bool(name, value, &__kmp_version);
995 } // __kmp_stg_parse_version
996 
997 static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
998  void *data) {
999  __kmp_stg_print_bool(buffer, name, __kmp_version);
1000 } // __kmp_stg_print_version
1001 
1002 // -----------------------------------------------------------------------------
1003 // KMP_WARNINGS
1004 
1005 static void __kmp_stg_parse_warnings(char const *name, char const *value,
1006  void *data) {
1007  __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
1008  if (__kmp_generate_warnings != kmp_warnings_off) {
1009  // AC: only 0/1 values documented, so reset to explicit to distinguish from
1010  // default setting
1011  __kmp_generate_warnings = kmp_warnings_explicit;
1012  }
1013 } // __kmp_stg_parse_warnings
1014 
1015 static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
1016  void *data) {
1017  // AC: TODO: change to print_int? (needs documentation change)
1018  __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
1019 } // __kmp_stg_print_warnings
1020 
1021 // -----------------------------------------------------------------------------
1022 // KMP_NESTING_MODE
1023 
1024 static void __kmp_stg_parse_nesting_mode(char const *name, char const *value,
1025  void *data) {
1026  __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_nesting_mode);
1027 #if KMP_AFFINITY_SUPPORTED && KMP_USE_HWLOC
1028  if (__kmp_nesting_mode > 0)
1029  __kmp_affinity_top_method = affinity_top_method_hwloc;
1030 #endif
1031 } // __kmp_stg_parse_nesting_mode
1032 
1033 static void __kmp_stg_print_nesting_mode(kmp_str_buf_t *buffer,
1034  char const *name, void *data) {
1035  if (__kmp_env_format) {
1036  KMP_STR_BUF_PRINT_NAME;
1037  } else {
1038  __kmp_str_buf_print(buffer, " %s", name);
1039  }
1040  __kmp_str_buf_print(buffer, "=%d\n", __kmp_nesting_mode);
1041 } // __kmp_stg_print_nesting_mode
1042 
1043 // -----------------------------------------------------------------------------
1044 // OMP_NESTED, OMP_NUM_THREADS
1045 
1046 static void __kmp_stg_parse_nested(char const *name, char const *value,
1047  void *data) {
1048  int nested;
1049  KMP_INFORM(EnvVarDeprecated, name, "OMP_MAX_ACTIVE_LEVELS");
1050  __kmp_stg_parse_bool(name, value, &nested);
1051  if (nested) {
1052  if (!__kmp_dflt_max_active_levels_set)
1053  __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1054  } else { // nesting explicitly turned off
1055  __kmp_dflt_max_active_levels = 1;
1056  __kmp_dflt_max_active_levels_set = true;
1057  }
1058 } // __kmp_stg_parse_nested
1059 
1060 static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
1061  void *data) {
1062  if (__kmp_env_format) {
1063  KMP_STR_BUF_PRINT_NAME;
1064  } else {
1065  __kmp_str_buf_print(buffer, " %s", name);
1066  }
1067  __kmp_str_buf_print(buffer, ": deprecated; max-active-levels-var=%d\n",
1068  __kmp_dflt_max_active_levels);
1069 } // __kmp_stg_print_nested
1070 
1071 static void __kmp_parse_nested_num_threads(const char *var, const char *env,
1072  kmp_nested_nthreads_t *nth_array) {
1073  const char *next = env;
1074  const char *scan = next;
1075 
1076  int total = 0; // Count elements that were set. It'll be used as an array size
1077  int prev_comma = FALSE; // For correct processing sequential commas
1078 
1079  // Count the number of values in the env. var string
1080  for (;;) {
1081  SKIP_WS(next);
1082 
1083  if (*next == '\0') {
1084  break;
1085  }
1086  // Next character is not an integer or not a comma => end of list
1087  if (((*next < '0') || (*next > '9')) && (*next != ',')) {
1088  KMP_WARNING(NthSyntaxError, var, env);
1089  return;
1090  }
1091  // The next character is ','
1092  if (*next == ',') {
1093  // ',' is the first character
1094  if (total == 0 || prev_comma) {
1095  total++;
1096  }
1097  prev_comma = TRUE;
1098  next++; // skip ','
1099  SKIP_WS(next);
1100  }
1101  // Next character is a digit
1102  if (*next >= '0' && *next <= '9') {
1103  prev_comma = FALSE;
1104  SKIP_DIGITS(next);
1105  total++;
1106  const char *tmp = next;
1107  SKIP_WS(tmp);
1108  if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
1109  KMP_WARNING(NthSpacesNotAllowed, var, env);
1110  return;
1111  }
1112  }
1113  }
1114  if (!__kmp_dflt_max_active_levels_set && total > 1)
1115  __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1116  KMP_DEBUG_ASSERT(total > 0);
1117  if (total <= 0) {
1118  KMP_WARNING(NthSyntaxError, var, env);
1119  return;
1120  }
1121 
1122  // Check if the nested nthreads array exists
1123  if (!nth_array->nth) {
1124  // Allocate an array of double size
1125  nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
1126  if (nth_array->nth == NULL) {
1127  KMP_FATAL(MemoryAllocFailed);
1128  }
1129  nth_array->size = total * 2;
1130  } else {
1131  if (nth_array->size < total) {
1132  // Increase the array size
1133  do {
1134  nth_array->size *= 2;
1135  } while (nth_array->size < total);
1136 
1137  nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
1138  nth_array->nth, sizeof(int) * nth_array->size);
1139  if (nth_array->nth == NULL) {
1140  KMP_FATAL(MemoryAllocFailed);
1141  }
1142  }
1143  }
1144  nth_array->used = total;
1145  int i = 0;
1146 
1147  prev_comma = FALSE;
1148  total = 0;
1149  // Save values in the array
1150  for (;;) {
1151  SKIP_WS(scan);
1152  if (*scan == '\0') {
1153  break;
1154  }
1155  // The next character is ','
1156  if (*scan == ',') {
1157  // ',' in the beginning of the list
1158  if (total == 0) {
1159  // The value is supposed to be equal to __kmp_avail_proc but it is
1160  // unknown at the moment.
1161  // So let's put a placeholder (#threads = 0) to correct it later.
1162  nth_array->nth[i++] = 0;
1163  total++;
1164  } else if (prev_comma) {
1165  // Num threads is inherited from the previous level
1166  nth_array->nth[i] = nth_array->nth[i - 1];
1167  i++;
1168  total++;
1169  }
1170  prev_comma = TRUE;
1171  scan++; // skip ','
1172  SKIP_WS(scan);
1173  }
1174  // Next character is a digit
1175  if (*scan >= '0' && *scan <= '9') {
1176  int num;
1177  const char *buf = scan;
1178  char const *msg = NULL;
1179  prev_comma = FALSE;
1180  SKIP_DIGITS(scan);
1181  total++;
1182 
1183  num = __kmp_str_to_int(buf, *scan);
1184  if (num < KMP_MIN_NTH) {
1185  msg = KMP_I18N_STR(ValueTooSmall);
1186  num = KMP_MIN_NTH;
1187  } else if (num > __kmp_sys_max_nth) {
1188  msg = KMP_I18N_STR(ValueTooLarge);
1189  num = __kmp_sys_max_nth;
1190  }
1191  if (msg != NULL) {
1192  // Message is not empty. Print warning.
1193  KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1194  KMP_INFORM(Using_int_Value, var, num);
1195  }
1196  nth_array->nth[i++] = num;
1197  }
1198  }
1199 }
1200 
1201 static void __kmp_stg_parse_num_threads(char const *name, char const *value,
1202  void *data) {
1203  // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
1204  if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
1205  // The array of 1 element
1206  __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
1207  __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1208  __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1209  __kmp_xproc;
1210  } else {
1211  __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1212  if (__kmp_nested_nth.nth) {
1213  __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1214  if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1215  __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1216  }
1217  }
1218  }
1219  K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
1220 } // __kmp_stg_parse_num_threads
1221 
1222 static void __kmp_stg_parse_num_hidden_helper_threads(char const *name,
1223  char const *value,
1224  void *data) {
1225  __kmp_stg_parse_int(name, value, 0, 16, &__kmp_hidden_helper_threads_num);
1226  // If the number of hidden helper threads is zero, we disable hidden helper
1227  // task
1228  if (__kmp_hidden_helper_threads_num == 0) {
1229  __kmp_enable_hidden_helper = FALSE;
1230  }
1231 } // __kmp_stg_parse_num_hidden_helper_threads
1232 
1233 static void __kmp_stg_print_num_hidden_helper_threads(kmp_str_buf_t *buffer,
1234  char const *name,
1235  void *data) {
1236  __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num);
1237 } // __kmp_stg_print_num_hidden_helper_threads
1238 
1239 static void __kmp_stg_parse_use_hidden_helper(char const *name,
1240  char const *value, void *data) {
1241  __kmp_stg_parse_bool(name, value, &__kmp_enable_hidden_helper);
1242 #if !KMP_OS_LINUX
1243  __kmp_enable_hidden_helper = FALSE;
1244  K_DIAG(1,
1245  ("__kmp_stg_parse_use_hidden_helper: Disable hidden helper task on "
1246  "non-Linux platform although it is enabled by user explicitly.\n"));
1247 #endif
1248 } // __kmp_stg_parse_use_hidden_helper
1249 
1250 static void __kmp_stg_print_use_hidden_helper(kmp_str_buf_t *buffer,
1251  char const *name, void *data) {
1252  __kmp_stg_print_bool(buffer, name, __kmp_enable_hidden_helper);
1253 } // __kmp_stg_print_use_hidden_helper
1254 
1255 static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
1256  void *data) {
1257  if (__kmp_env_format) {
1258  KMP_STR_BUF_PRINT_NAME;
1259  } else {
1260  __kmp_str_buf_print(buffer, " %s", name);
1261  }
1262  if (__kmp_nested_nth.used) {
1263  kmp_str_buf_t buf;
1264  __kmp_str_buf_init(&buf);
1265  for (int i = 0; i < __kmp_nested_nth.used; i++) {
1266  __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
1267  if (i < __kmp_nested_nth.used - 1) {
1268  __kmp_str_buf_print(&buf, ",");
1269  }
1270  }
1271  __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
1272  __kmp_str_buf_free(&buf);
1273  } else {
1274  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1275  }
1276 } // __kmp_stg_print_num_threads
1277 
1278 // -----------------------------------------------------------------------------
1279 // OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
1280 
1281 static void __kmp_stg_parse_tasking(char const *name, char const *value,
1282  void *data) {
1283  __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
1284  (int *)&__kmp_tasking_mode);
1285 } // __kmp_stg_parse_tasking
1286 
1287 static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
1288  void *data) {
1289  __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
1290 } // __kmp_stg_print_tasking
1291 
1292 static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
1293  void *data) {
1294  __kmp_stg_parse_int(name, value, 0, 1,
1295  (int *)&__kmp_task_stealing_constraint);
1296 } // __kmp_stg_parse_task_stealing
1297 
1298 static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1299  char const *name, void *data) {
1300  __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
1301 } // __kmp_stg_print_task_stealing
1302 
1303 static void __kmp_stg_parse_max_active_levels(char const *name,
1304  char const *value, void *data) {
1305  kmp_uint64 tmp_dflt = 0;
1306  char const *msg = NULL;
1307  if (!__kmp_dflt_max_active_levels_set) {
1308  // Don't overwrite __kmp_dflt_max_active_levels if we get an invalid setting
1309  __kmp_str_to_uint(value, &tmp_dflt, &msg);
1310  if (msg != NULL) { // invalid setting; print warning and ignore
1311  KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1312  } else if (tmp_dflt > KMP_MAX_ACTIVE_LEVELS_LIMIT) {
1313  // invalid setting; print warning and ignore
1314  msg = KMP_I18N_STR(ValueTooLarge);
1315  KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1316  } else { // valid setting
1317  __kmp_type_convert(tmp_dflt, &(__kmp_dflt_max_active_levels));
1318  __kmp_dflt_max_active_levels_set = true;
1319  }
1320  }
1321 } // __kmp_stg_parse_max_active_levels
1322 
1323 static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1324  char const *name, void *data) {
1325  __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
1326 } // __kmp_stg_print_max_active_levels
1327 
1328 // -----------------------------------------------------------------------------
1329 // OpenMP 4.0: OMP_DEFAULT_DEVICE
1330 static void __kmp_stg_parse_default_device(char const *name, char const *value,
1331  void *data) {
1332  __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1333  &__kmp_default_device);
1334 } // __kmp_stg_parse_default_device
1335 
1336 static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1337  char const *name, void *data) {
1338  __kmp_stg_print_int(buffer, name, __kmp_default_device);
1339 } // __kmp_stg_print_default_device
1340 
1341 // -----------------------------------------------------------------------------
1342 // OpenMP 5.0: OMP_TARGET_OFFLOAD
1343 static void __kmp_stg_parse_target_offload(char const *name, char const *value,
1344  void *data) {
1345  const char *next = value;
1346  const char *scan = next;
1347 
1348  __kmp_target_offload = tgt_default;
1349  SKIP_WS(next);
1350  if (*next == '\0')
1351  return;
1352  scan = next;
1353  if (!__kmp_strcasecmp_with_sentinel("mandatory", scan, 0)) {
1354  __kmp_target_offload = tgt_mandatory;
1355  } else if (!__kmp_strcasecmp_with_sentinel("disabled", scan, 0)) {
1356  __kmp_target_offload = tgt_disabled;
1357  } else if (!__kmp_strcasecmp_with_sentinel("default", scan, 0)) {
1358  __kmp_target_offload = tgt_default;
1359  } else {
1360  KMP_WARNING(SyntaxErrorUsing, name, "DEFAULT");
1361  }
1362 
1363 } // __kmp_stg_parse_target_offload
1364 
1365 static void __kmp_stg_print_target_offload(kmp_str_buf_t *buffer,
1366  char const *name, void *data) {
1367  const char *value = NULL;
1368  if (__kmp_target_offload == tgt_default)
1369  value = "DEFAULT";
1370  else if (__kmp_target_offload == tgt_mandatory)
1371  value = "MANDATORY";
1372  else if (__kmp_target_offload == tgt_disabled)
1373  value = "DISABLED";
1374  KMP_DEBUG_ASSERT(value);
1375  if (__kmp_env_format) {
1376  KMP_STR_BUF_PRINT_NAME;
1377  } else {
1378  __kmp_str_buf_print(buffer, " %s", name);
1379  }
1380  __kmp_str_buf_print(buffer, "=%s\n", value);
1381 } // __kmp_stg_print_target_offload
1382 
1383 // -----------------------------------------------------------------------------
1384 // OpenMP 4.5: OMP_MAX_TASK_PRIORITY
1385 static void __kmp_stg_parse_max_task_priority(char const *name,
1386  char const *value, void *data) {
1387  __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1388  &__kmp_max_task_priority);
1389 } // __kmp_stg_parse_max_task_priority
1390 
1391 static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1392  char const *name, void *data) {
1393  __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
1394 } // __kmp_stg_print_max_task_priority
1395 
1396 // KMP_TASKLOOP_MIN_TASKS
1397 // taskloop threshold to switch from recursive to linear tasks creation
1398 static void __kmp_stg_parse_taskloop_min_tasks(char const *name,
1399  char const *value, void *data) {
1400  int tmp;
1401  __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1402  __kmp_taskloop_min_tasks = tmp;
1403 } // __kmp_stg_parse_taskloop_min_tasks
1404 
1405 static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
1406  char const *name, void *data) {
1407  __kmp_stg_print_uint64(buffer, name, __kmp_taskloop_min_tasks);
1408 } // __kmp_stg_print_taskloop_min_tasks
1409 
1410 // -----------------------------------------------------------------------------
1411 // KMP_DISP_NUM_BUFFERS
1412 static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
1413  void *data) {
1414  if (TCR_4(__kmp_init_serial)) {
1415  KMP_WARNING(EnvSerialWarn, name);
1416  return;
1417  } // read value before serial initialization only
1418  __kmp_stg_parse_int(name, value, KMP_MIN_DISP_NUM_BUFF, KMP_MAX_DISP_NUM_BUFF,
1419  &__kmp_dispatch_num_buffers);
1420 } // __kmp_stg_parse_disp_buffers
1421 
1422 static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1423  char const *name, void *data) {
1424  __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
1425 } // __kmp_stg_print_disp_buffers
1426 
1427 #if KMP_NESTED_HOT_TEAMS
1428 // -----------------------------------------------------------------------------
1429 // KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
1430 
1431 static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
1432  void *data) {
1433  if (TCR_4(__kmp_init_parallel)) {
1434  KMP_WARNING(EnvParallelWarn, name);
1435  return;
1436  } // read value before first parallel only
1437  __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1438  &__kmp_hot_teams_max_level);
1439 } // __kmp_stg_parse_hot_teams_level
1440 
1441 static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1442  char const *name, void *data) {
1443  __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
1444 } // __kmp_stg_print_hot_teams_level
1445 
1446 static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
1447  void *data) {
1448  if (TCR_4(__kmp_init_parallel)) {
1449  KMP_WARNING(EnvParallelWarn, name);
1450  return;
1451  } // read value before first parallel only
1452  __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1453  &__kmp_hot_teams_mode);
1454 } // __kmp_stg_parse_hot_teams_mode
1455 
1456 static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1457  char const *name, void *data) {
1458  __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
1459 } // __kmp_stg_print_hot_teams_mode
1460 
1461 #endif // KMP_NESTED_HOT_TEAMS
1462 
1463 // -----------------------------------------------------------------------------
1464 // KMP_HANDLE_SIGNALS
1465 
1466 #if KMP_HANDLE_SIGNALS
1467 
1468 static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
1469  void *data) {
1470  __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
1471 } // __kmp_stg_parse_handle_signals
1472 
1473 static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1474  char const *name, void *data) {
1475  __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
1476 } // __kmp_stg_print_handle_signals
1477 
1478 #endif // KMP_HANDLE_SIGNALS
1479 
1480 // -----------------------------------------------------------------------------
1481 // KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
1482 
1483 #ifdef KMP_DEBUG
1484 
1485 #define KMP_STG_X_DEBUG(x) \
1486  static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1487  void *data) { \
1488  __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1489  } /* __kmp_stg_parse_x_debug */ \
1490  static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1491  char const *name, void *data) { \
1492  __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1493  } /* __kmp_stg_print_x_debug */
1494 
1495 KMP_STG_X_DEBUG(a)
1496 KMP_STG_X_DEBUG(b)
1497 KMP_STG_X_DEBUG(c)
1498 KMP_STG_X_DEBUG(d)
1499 KMP_STG_X_DEBUG(e)
1500 KMP_STG_X_DEBUG(f)
1501 
1502 #undef KMP_STG_X_DEBUG
1503 
1504 static void __kmp_stg_parse_debug(char const *name, char const *value,
1505  void *data) {
1506  int debug = 0;
1507  __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1508  if (kmp_a_debug < debug) {
1509  kmp_a_debug = debug;
1510  }
1511  if (kmp_b_debug < debug) {
1512  kmp_b_debug = debug;
1513  }
1514  if (kmp_c_debug < debug) {
1515  kmp_c_debug = debug;
1516  }
1517  if (kmp_d_debug < debug) {
1518  kmp_d_debug = debug;
1519  }
1520  if (kmp_e_debug < debug) {
1521  kmp_e_debug = debug;
1522  }
1523  if (kmp_f_debug < debug) {
1524  kmp_f_debug = debug;
1525  }
1526 } // __kmp_stg_parse_debug
1527 
1528 static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
1529  void *data) {
1530  __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1531  // !!! TODO: Move buffer initialization of of this file! It may works
1532  // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
1533  // KMP_DEBUG_BUF_CHARS.
1534  if (__kmp_debug_buf) {
1535  int i;
1536  int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
1537 
1538  /* allocate and initialize all entries in debug buffer to empty */
1539  __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
1540  for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1541  __kmp_debug_buffer[i] = '\0';
1542 
1543  __kmp_debug_count = 0;
1544  }
1545  K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
1546 } // __kmp_stg_parse_debug_buf
1547 
1548 static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
1549  void *data) {
1550  __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
1551 } // __kmp_stg_print_debug_buf
1552 
1553 static void __kmp_stg_parse_debug_buf_atomic(char const *name,
1554  char const *value, void *data) {
1555  __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
1556 } // __kmp_stg_parse_debug_buf_atomic
1557 
1558 static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1559  char const *name, void *data) {
1560  __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
1561 } // __kmp_stg_print_debug_buf_atomic
1562 
1563 static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
1564  void *data) {
1565  __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1566  &__kmp_debug_buf_chars);
1567 } // __kmp_stg_debug_parse_buf_chars
1568 
1569 static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1570  char const *name, void *data) {
1571  __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
1572 } // __kmp_stg_print_debug_buf_chars
1573 
1574 static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
1575  void *data) {
1576  __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1577  &__kmp_debug_buf_lines);
1578 } // __kmp_stg_parse_debug_buf_lines
1579 
1580 static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1581  char const *name, void *data) {
1582  __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
1583 } // __kmp_stg_print_debug_buf_lines
1584 
1585 static void __kmp_stg_parse_diag(char const *name, char const *value,
1586  void *data) {
1587  __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
1588 } // __kmp_stg_parse_diag
1589 
1590 static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
1591  void *data) {
1592  __kmp_stg_print_int(buffer, name, kmp_diag);
1593 } // __kmp_stg_print_diag
1594 
1595 #endif // KMP_DEBUG
1596 
1597 // -----------------------------------------------------------------------------
1598 // KMP_ALIGN_ALLOC
1599 
1600 static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
1601  void *data) {
1602  __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1603  &__kmp_align_alloc, 1);
1604 } // __kmp_stg_parse_align_alloc
1605 
1606 static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
1607  void *data) {
1608  __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
1609 } // __kmp_stg_print_align_alloc
1610 
1611 // -----------------------------------------------------------------------------
1612 // KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
1613 
1614 // TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
1615 // parse and print functions, pass required info through data argument.
1616 
1617 static void __kmp_stg_parse_barrier_branch_bit(char const *name,
1618  char const *value, void *data) {
1619  const char *var;
1620 
1621  /* ---------- Barrier branch bit control ------------ */
1622  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1623  var = __kmp_barrier_branch_bit_env_name[i];
1624  if ((strcmp(var, name) == 0) && (value != 0)) {
1625  char *comma;
1626 
1627  comma = CCAST(char *, strchr(value, ','));
1628  __kmp_barrier_gather_branch_bits[i] =
1629  (kmp_uint32)__kmp_str_to_int(value, ',');
1630  /* is there a specified release parameter? */
1631  if (comma == NULL) {
1632  __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1633  } else {
1634  __kmp_barrier_release_branch_bits[i] =
1635  (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
1636 
1637  if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1638  __kmp_msg(kmp_ms_warning,
1639  KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1640  __kmp_msg_null);
1641  __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1642  }
1643  }
1644  if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1645  KMP_WARNING(BarrGatherValueInvalid, name, value);
1646  KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1647  __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1648  }
1649  }
1650  K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1651  __kmp_barrier_gather_branch_bits[i],
1652  __kmp_barrier_release_branch_bits[i]))
1653  }
1654 } // __kmp_stg_parse_barrier_branch_bit
1655 
1656 static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1657  char const *name, void *data) {
1658  const char *var;
1659  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1660  var = __kmp_barrier_branch_bit_env_name[i];
1661  if (strcmp(var, name) == 0) {
1662  if (__kmp_env_format) {
1663  KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1664  } else {
1665  __kmp_str_buf_print(buffer, " %s='",
1666  __kmp_barrier_branch_bit_env_name[i]);
1667  }
1668  __kmp_str_buf_print(buffer, "%d,%d'\n",
1669  __kmp_barrier_gather_branch_bits[i],
1670  __kmp_barrier_release_branch_bits[i]);
1671  }
1672  }
1673 } // __kmp_stg_print_barrier_branch_bit
1674 
1675 // ----------------------------------------------------------------------------
1676 // KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
1677 // KMP_REDUCTION_BARRIER_PATTERN
1678 
1679 // TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
1680 // print functions, pass required data to functions through data argument.
1681 
1682 static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
1683  void *data) {
1684  const char *var;
1685  /* ---------- Barrier method control ------------ */
1686 
1687  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1688  var = __kmp_barrier_pattern_env_name[i];
1689 
1690  if ((strcmp(var, name) == 0) && (value != 0)) {
1691  int j;
1692  char *comma = CCAST(char *, strchr(value, ','));
1693 
1694  /* handle first parameter: gather pattern */
1695  for (j = bp_linear_bar; j < bp_last_bar; j++) {
1696  if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1697  ',')) {
1698  __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1699  break;
1700  }
1701  }
1702  if (j == bp_last_bar) {
1703  KMP_WARNING(BarrGatherValueInvalid, name, value);
1704  KMP_INFORM(Using_str_Value, name,
1705  __kmp_barrier_pattern_name[bp_linear_bar]);
1706  }
1707 
1708  /* handle second parameter: release pattern */
1709  if (comma != NULL) {
1710  for (j = bp_linear_bar; j < bp_last_bar; j++) {
1711  if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1712  __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1713  break;
1714  }
1715  }
1716  if (j == bp_last_bar) {
1717  __kmp_msg(kmp_ms_warning,
1718  KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1719  __kmp_msg_null);
1720  KMP_INFORM(Using_str_Value, name,
1721  __kmp_barrier_pattern_name[bp_linear_bar]);
1722  }
1723  }
1724  }
1725  }
1726 } // __kmp_stg_parse_barrier_pattern
1727 
1728 static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1729  char const *name, void *data) {
1730  const char *var;
1731  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1732  var = __kmp_barrier_pattern_env_name[i];
1733  if (strcmp(var, name) == 0) {
1734  int j = __kmp_barrier_gather_pattern[i];
1735  int k = __kmp_barrier_release_pattern[i];
1736  if (__kmp_env_format) {
1737  KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1738  } else {
1739  __kmp_str_buf_print(buffer, " %s='",
1740  __kmp_barrier_pattern_env_name[i]);
1741  }
1742  KMP_DEBUG_ASSERT(j < bs_last_barrier && k < bs_last_barrier);
1743  __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
1744  __kmp_barrier_pattern_name[k]);
1745  }
1746  }
1747 } // __kmp_stg_print_barrier_pattern
1748 
1749 // -----------------------------------------------------------------------------
1750 // KMP_ABORT_DELAY
1751 
1752 static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
1753  void *data) {
1754  // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
1755  // milliseconds.
1756  int delay = __kmp_abort_delay / 1000;
1757  __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1758  __kmp_abort_delay = delay * 1000;
1759 } // __kmp_stg_parse_abort_delay
1760 
1761 static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
1762  void *data) {
1763  __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
1764 } // __kmp_stg_print_abort_delay
1765 
1766 // -----------------------------------------------------------------------------
1767 // KMP_CPUINFO_FILE
1768 
1769 static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
1770  void *data) {
1771 #if KMP_AFFINITY_SUPPORTED
1772  __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1773  K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1774 #endif
1775 } //__kmp_stg_parse_cpuinfo_file
1776 
1777 static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1778  char const *name, void *data) {
1779 #if KMP_AFFINITY_SUPPORTED
1780  if (__kmp_env_format) {
1781  KMP_STR_BUF_PRINT_NAME;
1782  } else {
1783  __kmp_str_buf_print(buffer, " %s", name);
1784  }
1785  if (__kmp_cpuinfo_file) {
1786  __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
1787  } else {
1788  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1789  }
1790 #endif
1791 } //__kmp_stg_print_cpuinfo_file
1792 
1793 // -----------------------------------------------------------------------------
1794 // KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
1795 
1796 static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
1797  void *data) {
1798  kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1799  int rc;
1800 
1801  rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1802  if (rc) {
1803  return;
1804  }
1805  if (reduction->force) {
1806  if (value != 0) {
1807  if (__kmp_str_match("critical", 0, value))
1808  __kmp_force_reduction_method = critical_reduce_block;
1809  else if (__kmp_str_match("atomic", 0, value))
1810  __kmp_force_reduction_method = atomic_reduce_block;
1811  else if (__kmp_str_match("tree", 0, value))
1812  __kmp_force_reduction_method = tree_reduce_block;
1813  else {
1814  KMP_FATAL(UnknownForceReduction, name, value);
1815  }
1816  }
1817  } else {
1818  __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1819  if (__kmp_determ_red) {
1820  __kmp_force_reduction_method = tree_reduce_block;
1821  } else {
1822  __kmp_force_reduction_method = reduction_method_not_defined;
1823  }
1824  }
1825  K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
1826  __kmp_force_reduction_method));
1827 } // __kmp_stg_parse_force_reduction
1828 
1829 static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1830  char const *name, void *data) {
1831 
1832  kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1833  if (reduction->force) {
1834  if (__kmp_force_reduction_method == critical_reduce_block) {
1835  __kmp_stg_print_str(buffer, name, "critical");
1836  } else if (__kmp_force_reduction_method == atomic_reduce_block) {
1837  __kmp_stg_print_str(buffer, name, "atomic");
1838  } else if (__kmp_force_reduction_method == tree_reduce_block) {
1839  __kmp_stg_print_str(buffer, name, "tree");
1840  } else {
1841  if (__kmp_env_format) {
1842  KMP_STR_BUF_PRINT_NAME;
1843  } else {
1844  __kmp_str_buf_print(buffer, " %s", name);
1845  }
1846  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1847  }
1848  } else {
1849  __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1850  }
1851 
1852 } // __kmp_stg_print_force_reduction
1853 
1854 // -----------------------------------------------------------------------------
1855 // KMP_STORAGE_MAP
1856 
1857 static void __kmp_stg_parse_storage_map(char const *name, char const *value,
1858  void *data) {
1859  if (__kmp_str_match("verbose", 1, value)) {
1860  __kmp_storage_map = TRUE;
1861  __kmp_storage_map_verbose = TRUE;
1862  __kmp_storage_map_verbose_specified = TRUE;
1863 
1864  } else {
1865  __kmp_storage_map_verbose = FALSE;
1866  __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
1867  }
1868 } // __kmp_stg_parse_storage_map
1869 
1870 static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
1871  void *data) {
1872  if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1873  __kmp_stg_print_str(buffer, name, "verbose");
1874  } else {
1875  __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1876  }
1877 } // __kmp_stg_print_storage_map
1878 
1879 // -----------------------------------------------------------------------------
1880 // KMP_ALL_THREADPRIVATE
1881 
1882 static void __kmp_stg_parse_all_threadprivate(char const *name,
1883  char const *value, void *data) {
1884  __kmp_stg_parse_int(name, value,
1885  __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1886  __kmp_max_nth, &__kmp_tp_capacity);
1887 } // __kmp_stg_parse_all_threadprivate
1888 
1889 static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1890  char const *name, void *data) {
1891  __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
1892 }
1893 
1894 // -----------------------------------------------------------------------------
1895 // KMP_FOREIGN_THREADS_THREADPRIVATE
1896 
1897 static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
1898  char const *value,
1899  void *data) {
1900  __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
1901 } // __kmp_stg_parse_foreign_threads_threadprivate
1902 
1903 static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
1904  char const *name,
1905  void *data) {
1906  __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
1907 } // __kmp_stg_print_foreign_threads_threadprivate
1908 
1909 // -----------------------------------------------------------------------------
1910 // KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
1911 
1912 #if KMP_AFFINITY_SUPPORTED
1913 // Parse the proc id list. Return TRUE if successful, FALSE otherwise.
1914 static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
1915  const char **nextEnv,
1916  char **proclist) {
1917  const char *scan = env;
1918  const char *next = scan;
1919  int empty = TRUE;
1920 
1921  *proclist = NULL;
1922 
1923  for (;;) {
1924  int start, end, stride;
1925 
1926  SKIP_WS(scan);
1927  next = scan;
1928  if (*next == '\0') {
1929  break;
1930  }
1931 
1932  if (*next == '{') {
1933  int num;
1934  next++; // skip '{'
1935  SKIP_WS(next);
1936  scan = next;
1937 
1938  // Read the first integer in the set.
1939  if ((*next < '0') || (*next > '9')) {
1940  KMP_WARNING(AffSyntaxError, var);
1941  return FALSE;
1942  }
1943  SKIP_DIGITS(next);
1944  num = __kmp_str_to_int(scan, *next);
1945  KMP_ASSERT(num >= 0);
1946 
1947  for (;;) {
1948  // Check for end of set.
1949  SKIP_WS(next);
1950  if (*next == '}') {
1951  next++; // skip '}'
1952  break;
1953  }
1954 
1955  // Skip optional comma.
1956  if (*next == ',') {
1957  next++;
1958  }
1959  SKIP_WS(next);
1960 
1961  // Read the next integer in the set.
1962  scan = next;
1963  if ((*next < '0') || (*next > '9')) {
1964  KMP_WARNING(AffSyntaxError, var);
1965  return FALSE;
1966  }
1967 
1968  SKIP_DIGITS(next);
1969  num = __kmp_str_to_int(scan, *next);
1970  KMP_ASSERT(num >= 0);
1971  }
1972  empty = FALSE;
1973 
1974  SKIP_WS(next);
1975  if (*next == ',') {
1976  next++;
1977  }
1978  scan = next;
1979  continue;
1980  }
1981 
1982  // Next character is not an integer => end of list
1983  if ((*next < '0') || (*next > '9')) {
1984  if (empty) {
1985  KMP_WARNING(AffSyntaxError, var);
1986  return FALSE;
1987  }
1988  break;
1989  }
1990 
1991  // Read the first integer.
1992  SKIP_DIGITS(next);
1993  start = __kmp_str_to_int(scan, *next);
1994  KMP_ASSERT(start >= 0);
1995  SKIP_WS(next);
1996 
1997  // If this isn't a range, then go on.
1998  if (*next != '-') {
1999  empty = FALSE;
2000 
2001  // Skip optional comma.
2002  if (*next == ',') {
2003  next++;
2004  }
2005  scan = next;
2006  continue;
2007  }
2008 
2009  // This is a range. Skip over the '-' and read in the 2nd int.
2010  next++; // skip '-'
2011  SKIP_WS(next);
2012  scan = next;
2013  if ((*next < '0') || (*next > '9')) {
2014  KMP_WARNING(AffSyntaxError, var);
2015  return FALSE;
2016  }
2017  SKIP_DIGITS(next);
2018  end = __kmp_str_to_int(scan, *next);
2019  KMP_ASSERT(end >= 0);
2020 
2021  // Check for a stride parameter
2022  stride = 1;
2023  SKIP_WS(next);
2024  if (*next == ':') {
2025  // A stride is specified. Skip over the ':" and read the 3rd int.
2026  int sign = +1;
2027  next++; // skip ':'
2028  SKIP_WS(next);
2029  scan = next;
2030  if (*next == '-') {
2031  sign = -1;
2032  next++;
2033  SKIP_WS(next);
2034  scan = next;
2035  }
2036  if ((*next < '0') || (*next > '9')) {
2037  KMP_WARNING(AffSyntaxError, var);
2038  return FALSE;
2039  }
2040  SKIP_DIGITS(next);
2041  stride = __kmp_str_to_int(scan, *next);
2042  KMP_ASSERT(stride >= 0);
2043  stride *= sign;
2044  }
2045 
2046  // Do some range checks.
2047  if (stride == 0) {
2048  KMP_WARNING(AffZeroStride, var);
2049  return FALSE;
2050  }
2051  if (stride > 0) {
2052  if (start > end) {
2053  KMP_WARNING(AffStartGreaterEnd, var, start, end);
2054  return FALSE;
2055  }
2056  } else {
2057  if (start < end) {
2058  KMP_WARNING(AffStrideLessZero, var, start, end);
2059  return FALSE;
2060  }
2061  }
2062  if ((end - start) / stride > 65536) {
2063  KMP_WARNING(AffRangeTooBig, var, end, start, stride);
2064  return FALSE;
2065  }
2066 
2067  empty = FALSE;
2068 
2069  // Skip optional comma.
2070  SKIP_WS(next);
2071  if (*next == ',') {
2072  next++;
2073  }
2074  scan = next;
2075  }
2076 
2077  *nextEnv = next;
2078 
2079  {
2080  ptrdiff_t len = next - env;
2081  char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
2082  KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
2083  retlist[len] = '\0';
2084  *proclist = retlist;
2085  }
2086  return TRUE;
2087 }
2088 
2089 // If KMP_AFFINITY is specified without a type, then
2090 // __kmp_affinity_notype should point to its setting.
2091 static kmp_setting_t *__kmp_affinity_notype = NULL;
2092 
2093 static void __kmp_parse_affinity_env(char const *name, char const *value,
2094  enum affinity_type *out_type,
2095  char **out_proclist, int *out_verbose,
2096  int *out_warn, int *out_respect,
2097  kmp_hw_t *out_gran, int *out_gran_levels,
2098  int *out_dups, int *out_compact,
2099  int *out_offset) {
2100  char *buffer = NULL; // Copy of env var value.
2101  char *buf = NULL; // Buffer for strtok_r() function.
2102  char *next = NULL; // end of token / start of next.
2103  const char *start; // start of current token (for err msgs)
2104  int count = 0; // Counter of parsed integer numbers.
2105  int number[2]; // Parsed numbers.
2106 
2107  // Guards.
2108  int type = 0;
2109  int proclist = 0;
2110  int verbose = 0;
2111  int warnings = 0;
2112  int respect = 0;
2113  int gran = 0;
2114  int dups = 0;
2115  bool set = false;
2116 
2117  KMP_ASSERT(value != NULL);
2118 
2119  if (TCR_4(__kmp_init_middle)) {
2120  KMP_WARNING(EnvMiddleWarn, name);
2121  __kmp_env_toPrint(name, 0);
2122  return;
2123  }
2124  __kmp_env_toPrint(name, 1);
2125 
2126  buffer =
2127  __kmp_str_format("%s", value); // Copy env var to keep original intact.
2128  buf = buffer;
2129  SKIP_WS(buf);
2130 
2131 // Helper macros.
2132 
2133 // If we see a parse error, emit a warning and scan to the next ",".
2134 //
2135 // FIXME - there's got to be a better way to print an error
2136 // message, hopefully without overwriting peices of buf.
2137 #define EMIT_WARN(skip, errlist) \
2138  { \
2139  char ch; \
2140  if (skip) { \
2141  SKIP_TO(next, ','); \
2142  } \
2143  ch = *next; \
2144  *next = '\0'; \
2145  KMP_WARNING errlist; \
2146  *next = ch; \
2147  if (skip) { \
2148  if (ch == ',') \
2149  next++; \
2150  } \
2151  buf = next; \
2152  }
2153 
2154 #define _set_param(_guard, _var, _val) \
2155  { \
2156  if (_guard == 0) { \
2157  _var = _val; \
2158  } else { \
2159  EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2160  } \
2161  ++_guard; \
2162  }
2163 
2164 #define set_type(val) _set_param(type, *out_type, val)
2165 #define set_verbose(val) _set_param(verbose, *out_verbose, val)
2166 #define set_warnings(val) _set_param(warnings, *out_warn, val)
2167 #define set_respect(val) _set_param(respect, *out_respect, val)
2168 #define set_dups(val) _set_param(dups, *out_dups, val)
2169 #define set_proclist(val) _set_param(proclist, *out_proclist, val)
2170 
2171 #define set_gran(val, levels) \
2172  { \
2173  if (gran == 0) { \
2174  *out_gran = val; \
2175  *out_gran_levels = levels; \
2176  } else { \
2177  EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2178  } \
2179  ++gran; \
2180  }
2181 
2182  KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
2183  (__kmp_nested_proc_bind.used > 0));
2184 
2185  while (*buf != '\0') {
2186  start = next = buf;
2187 
2188  if (__kmp_match_str("none", buf, CCAST(const char **, &next))) {
2189  set_type(affinity_none);
2190  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2191  buf = next;
2192  } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) {
2193  set_type(affinity_scatter);
2194  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2195  buf = next;
2196  } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) {
2197  set_type(affinity_compact);
2198  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2199  buf = next;
2200  } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) {
2201  set_type(affinity_logical);
2202  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2203  buf = next;
2204  } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) {
2205  set_type(affinity_physical);
2206  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2207  buf = next;
2208  } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) {
2209  set_type(affinity_explicit);
2210  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2211  buf = next;
2212  } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) {
2213  set_type(affinity_balanced);
2214  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2215  buf = next;
2216  } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) {
2217  set_type(affinity_disabled);
2218  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2219  buf = next;
2220  } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) {
2221  set_verbose(TRUE);
2222  buf = next;
2223  } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) {
2224  set_verbose(FALSE);
2225  buf = next;
2226  } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) {
2227  set_warnings(TRUE);
2228  buf = next;
2229  } else if (__kmp_match_str("nowarnings", buf,
2230  CCAST(const char **, &next))) {
2231  set_warnings(FALSE);
2232  buf = next;
2233  } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) {
2234  set_respect(TRUE);
2235  buf = next;
2236  } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) {
2237  set_respect(FALSE);
2238  buf = next;
2239  } else if (__kmp_match_str("duplicates", buf,
2240  CCAST(const char **, &next)) ||
2241  __kmp_match_str("dups", buf, CCAST(const char **, &next))) {
2242  set_dups(TRUE);
2243  buf = next;
2244  } else if (__kmp_match_str("noduplicates", buf,
2245  CCAST(const char **, &next)) ||
2246  __kmp_match_str("nodups", buf, CCAST(const char **, &next))) {
2247  set_dups(FALSE);
2248  buf = next;
2249  } else if (__kmp_match_str("granularity", buf,
2250  CCAST(const char **, &next)) ||
2251  __kmp_match_str("gran", buf, CCAST(const char **, &next))) {
2252  SKIP_WS(next);
2253  if (*next != '=') {
2254  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2255  continue;
2256  }
2257  next++; // skip '='
2258  SKIP_WS(next);
2259 
2260  buf = next;
2261 
2262  // Try any hardware topology type for granularity
2263  KMP_FOREACH_HW_TYPE(type) {
2264  const char *name = __kmp_hw_get_keyword(type);
2265  if (__kmp_match_str(name, buf, CCAST(const char **, &next))) {
2266  set_gran(type, -1);
2267  buf = next;
2268  set = true;
2269  break;
2270  }
2271  }
2272  if (!set) {
2273  // Support older names for different granularity layers
2274  if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) {
2275  set_gran(KMP_HW_THREAD, -1);
2276  buf = next;
2277  set = true;
2278  } else if (__kmp_match_str("package", buf,
2279  CCAST(const char **, &next))) {
2280  set_gran(KMP_HW_SOCKET, -1);
2281  buf = next;
2282  set = true;
2283  } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
2284  set_gran(KMP_HW_NUMA, -1);
2285  buf = next;
2286  set = true;
2287 #if KMP_GROUP_AFFINITY
2288  } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
2289  set_gran(KMP_HW_PROC_GROUP, -1);
2290  buf = next;
2291  set = true;
2292 #endif /* KMP_GROUP AFFINITY */
2293  } else if ((*buf >= '0') && (*buf <= '9')) {
2294  int n;
2295  next = buf;
2296  SKIP_DIGITS(next);
2297  n = __kmp_str_to_int(buf, *next);
2298  KMP_ASSERT(n >= 0);
2299  buf = next;
2300  set_gran(KMP_HW_UNKNOWN, n);
2301  set = true;
2302  } else {
2303  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2304  continue;
2305  }
2306  }
2307  } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
2308  char *temp_proclist;
2309 
2310  SKIP_WS(next);
2311  if (*next != '=') {
2312  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2313  continue;
2314  }
2315  next++; // skip '='
2316  SKIP_WS(next);
2317  if (*next != '[') {
2318  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2319  continue;
2320  }
2321  next++; // skip '['
2322  buf = next;
2323  if (!__kmp_parse_affinity_proc_id_list(
2324  name, buf, CCAST(const char **, &next), &temp_proclist)) {
2325  // warning already emitted.
2326  SKIP_TO(next, ']');
2327  if (*next == ']')
2328  next++;
2329  SKIP_TO(next, ',');
2330  if (*next == ',')
2331  next++;
2332  buf = next;
2333  continue;
2334  }
2335  if (*next != ']') {
2336  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2337  continue;
2338  }
2339  next++; // skip ']'
2340  set_proclist(temp_proclist);
2341  } else if ((*buf >= '0') && (*buf <= '9')) {
2342  // Parse integer numbers -- permute and offset.
2343  int n;
2344  next = buf;
2345  SKIP_DIGITS(next);
2346  n = __kmp_str_to_int(buf, *next);
2347  KMP_ASSERT(n >= 0);
2348  buf = next;
2349  if (count < 2) {
2350  number[count] = n;
2351  } else {
2352  KMP_WARNING(AffManyParams, name, start);
2353  }
2354  ++count;
2355  } else {
2356  EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2357  continue;
2358  }
2359 
2360  SKIP_WS(next);
2361  if (*next == ',') {
2362  next++;
2363  SKIP_WS(next);
2364  } else if (*next != '\0') {
2365  const char *temp = next;
2366  EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2367  continue;
2368  }
2369  buf = next;
2370  } // while
2371 
2372 #undef EMIT_WARN
2373 #undef _set_param
2374 #undef set_type
2375 #undef set_verbose
2376 #undef set_warnings
2377 #undef set_respect
2378 #undef set_granularity
2379 
2380  __kmp_str_free(&buffer);
2381 
2382  if (proclist) {
2383  if (!type) {
2384  KMP_WARNING(AffProcListNoType, name);
2385  *out_type = affinity_explicit;
2386  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2387  } else if (*out_type != affinity_explicit) {
2388  KMP_WARNING(AffProcListNotExplicit, name);
2389  KMP_ASSERT(*out_proclist != NULL);
2390  KMP_INTERNAL_FREE(*out_proclist);
2391  *out_proclist = NULL;
2392  }
2393  }
2394  switch (*out_type) {
2395  case affinity_logical:
2396  case affinity_physical: {
2397  if (count > 0) {
2398  *out_offset = number[0];
2399  }
2400  if (count > 1) {
2401  KMP_WARNING(AffManyParamsForLogic, name, number[1]);
2402  }
2403  } break;
2404  case affinity_balanced: {
2405  if (count > 0) {
2406  *out_compact = number[0];
2407  }
2408  if (count > 1) {
2409  *out_offset = number[1];
2410  }
2411 
2412  if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
2413 #if KMP_MIC_SUPPORTED
2414  if (__kmp_mic_type != non_mic) {
2415  if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2416  KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine");
2417  }
2418  __kmp_affinity_gran = KMP_HW_THREAD;
2419  } else
2420 #endif
2421  {
2422  if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2423  KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core");
2424  }
2425  __kmp_affinity_gran = KMP_HW_CORE;
2426  }
2427  }
2428  } break;
2429  case affinity_scatter:
2430  case affinity_compact: {
2431  if (count > 0) {
2432  *out_compact = number[0];
2433  }
2434  if (count > 1) {
2435  *out_offset = number[1];
2436  }
2437  } break;
2438  case affinity_explicit: {
2439  if (*out_proclist == NULL) {
2440  KMP_WARNING(AffNoProcList, name);
2441  __kmp_affinity_type = affinity_none;
2442  }
2443  if (count > 0) {
2444  KMP_WARNING(AffNoParam, name, "explicit");
2445  }
2446  } break;
2447  case affinity_none: {
2448  if (count > 0) {
2449  KMP_WARNING(AffNoParam, name, "none");
2450  }
2451  } break;
2452  case affinity_disabled: {
2453  if (count > 0) {
2454  KMP_WARNING(AffNoParam, name, "disabled");
2455  }
2456  } break;
2457  case affinity_default: {
2458  if (count > 0) {
2459  KMP_WARNING(AffNoParam, name, "default");
2460  }
2461  } break;
2462  default: {
2463  KMP_ASSERT(0);
2464  }
2465  }
2466 } // __kmp_parse_affinity_env
2467 
2468 static void __kmp_stg_parse_affinity(char const *name, char const *value,
2469  void *data) {
2470  kmp_setting_t **rivals = (kmp_setting_t **)data;
2471  int rc;
2472 
2473  rc = __kmp_stg_check_rivals(name, value, rivals);
2474  if (rc) {
2475  return;
2476  }
2477 
2478  __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2479  &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2480  &__kmp_affinity_warnings,
2481  &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2482  &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2483  &__kmp_affinity_compact, &__kmp_affinity_offset);
2484 
2485 } // __kmp_stg_parse_affinity
2486 
2487 static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
2488  void *data) {
2489  if (__kmp_env_format) {
2490  KMP_STR_BUF_PRINT_NAME_EX(name);
2491  } else {
2492  __kmp_str_buf_print(buffer, " %s='", name);
2493  }
2494  if (__kmp_affinity_verbose) {
2495  __kmp_str_buf_print(buffer, "%s,", "verbose");
2496  } else {
2497  __kmp_str_buf_print(buffer, "%s,", "noverbose");
2498  }
2499  if (__kmp_affinity_warnings) {
2500  __kmp_str_buf_print(buffer, "%s,", "warnings");
2501  } else {
2502  __kmp_str_buf_print(buffer, "%s,", "nowarnings");
2503  }
2504  if (KMP_AFFINITY_CAPABLE()) {
2505  if (__kmp_affinity_respect_mask) {
2506  __kmp_str_buf_print(buffer, "%s,", "respect");
2507  } else {
2508  __kmp_str_buf_print(buffer, "%s,", "norespect");
2509  }
2510  __kmp_str_buf_print(buffer, "granularity=%s,",
2511  __kmp_hw_get_keyword(__kmp_affinity_gran, false));
2512  }
2513  if (!KMP_AFFINITY_CAPABLE()) {
2514  __kmp_str_buf_print(buffer, "%s", "disabled");
2515  } else
2516  switch (__kmp_affinity_type) {
2517  case affinity_none:
2518  __kmp_str_buf_print(buffer, "%s", "none");
2519  break;
2520  case affinity_physical:
2521  __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset);
2522  break;
2523  case affinity_logical:
2524  __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset);
2525  break;
2526  case affinity_compact:
2527  __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact,
2528  __kmp_affinity_offset);
2529  break;
2530  case affinity_scatter:
2531  __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact,
2532  __kmp_affinity_offset);
2533  break;
2534  case affinity_explicit:
2535  __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist",
2536  __kmp_affinity_proclist, "explicit");
2537  break;
2538  case affinity_balanced:
2539  __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced",
2540  __kmp_affinity_compact, __kmp_affinity_offset);
2541  break;
2542  case affinity_disabled:
2543  __kmp_str_buf_print(buffer, "%s", "disabled");
2544  break;
2545  case affinity_default:
2546  __kmp_str_buf_print(buffer, "%s", "default");
2547  break;
2548  default:
2549  __kmp_str_buf_print(buffer, "%s", "<unknown>");
2550  break;
2551  }
2552  __kmp_str_buf_print(buffer, "'\n");
2553 } //__kmp_stg_print_affinity
2554 
2555 #ifdef KMP_GOMP_COMPAT
2556 
2557 static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
2558  char const *value, void *data) {
2559  const char *next = NULL;
2560  char *temp_proclist;
2561  kmp_setting_t **rivals = (kmp_setting_t **)data;
2562  int rc;
2563 
2564  rc = __kmp_stg_check_rivals(name, value, rivals);
2565  if (rc) {
2566  return;
2567  }
2568 
2569  if (TCR_4(__kmp_init_middle)) {
2570  KMP_WARNING(EnvMiddleWarn, name);
2571  __kmp_env_toPrint(name, 0);
2572  return;
2573  }
2574 
2575  __kmp_env_toPrint(name, 1);
2576 
2577  if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2578  SKIP_WS(next);
2579  if (*next == '\0') {
2580  // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2581  __kmp_affinity_proclist = temp_proclist;
2582  __kmp_affinity_type = affinity_explicit;
2583  __kmp_affinity_gran = KMP_HW_THREAD;
2584  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2585  } else {
2586  KMP_WARNING(AffSyntaxError, name);
2587  if (temp_proclist != NULL) {
2588  KMP_INTERNAL_FREE((void *)temp_proclist);
2589  }
2590  }
2591  } else {
2592  // Warning already emitted
2593  __kmp_affinity_type = affinity_none;
2594  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2595  }
2596 } // __kmp_stg_parse_gomp_cpu_affinity
2597 
2598 #endif /* KMP_GOMP_COMPAT */
2599 
2600 /*-----------------------------------------------------------------------------
2601 The OMP_PLACES proc id list parser. Here is the grammar:
2602 
2603 place_list := place
2604 place_list := place , place_list
2605 place := num
2606 place := place : num
2607 place := place : num : signed
2608 place := { subplacelist }
2609 place := ! place // (lowest priority)
2610 subplace_list := subplace
2611 subplace_list := subplace , subplace_list
2612 subplace := num
2613 subplace := num : num
2614 subplace := num : num : signed
2615 signed := num
2616 signed := + signed
2617 signed := - signed
2618 -----------------------------------------------------------------------------*/
2619 
2620 // Warning to issue for syntax error during parsing of OMP_PLACES
2621 static inline void __kmp_omp_places_syntax_warn(const char *var) {
2622  KMP_WARNING(SyntaxErrorUsing, var, "\"cores\"");
2623 }
2624 
2625 static int __kmp_parse_subplace_list(const char *var, const char **scan) {
2626  const char *next;
2627 
2628  for (;;) {
2629  int start, count, stride;
2630 
2631  //
2632  // Read in the starting proc id
2633  //
2634  SKIP_WS(*scan);
2635  if ((**scan < '0') || (**scan > '9')) {
2636  __kmp_omp_places_syntax_warn(var);
2637  return FALSE;
2638  }
2639  next = *scan;
2640  SKIP_DIGITS(next);
2641  start = __kmp_str_to_int(*scan, *next);
2642  KMP_ASSERT(start >= 0);
2643  *scan = next;
2644 
2645  // valid follow sets are ',' ':' and '}'
2646  SKIP_WS(*scan);
2647  if (**scan == '}') {
2648  break;
2649  }
2650  if (**scan == ',') {
2651  (*scan)++; // skip ','
2652  continue;
2653  }
2654  if (**scan != ':') {
2655  __kmp_omp_places_syntax_warn(var);
2656  return FALSE;
2657  }
2658  (*scan)++; // skip ':'
2659 
2660  // Read count parameter
2661  SKIP_WS(*scan);
2662  if ((**scan < '0') || (**scan > '9')) {
2663  __kmp_omp_places_syntax_warn(var);
2664  return FALSE;
2665  }
2666  next = *scan;
2667  SKIP_DIGITS(next);
2668  count = __kmp_str_to_int(*scan, *next);
2669  KMP_ASSERT(count >= 0);
2670  *scan = next;
2671 
2672  // valid follow sets are ',' ':' and '}'
2673  SKIP_WS(*scan);
2674  if (**scan == '}') {
2675  break;
2676  }
2677  if (**scan == ',') {
2678  (*scan)++; // skip ','
2679  continue;
2680  }
2681  if (**scan != ':') {
2682  __kmp_omp_places_syntax_warn(var);
2683  return FALSE;
2684  }
2685  (*scan)++; // skip ':'
2686 
2687  // Read stride parameter
2688  int sign = +1;
2689  for (;;) {
2690  SKIP_WS(*scan);
2691  if (**scan == '+') {
2692  (*scan)++; // skip '+'
2693  continue;
2694  }
2695  if (**scan == '-') {
2696  sign *= -1;
2697  (*scan)++; // skip '-'
2698  continue;
2699  }
2700  break;
2701  }
2702  SKIP_WS(*scan);
2703  if ((**scan < '0') || (**scan > '9')) {
2704  __kmp_omp_places_syntax_warn(var);
2705  return FALSE;
2706  }
2707  next = *scan;
2708  SKIP_DIGITS(next);
2709  stride = __kmp_str_to_int(*scan, *next);
2710  KMP_ASSERT(stride >= 0);
2711  *scan = next;
2712  stride *= sign;
2713 
2714  // valid follow sets are ',' and '}'
2715  SKIP_WS(*scan);
2716  if (**scan == '}') {
2717  break;
2718  }
2719  if (**scan == ',') {
2720  (*scan)++; // skip ','
2721  continue;
2722  }
2723 
2724  __kmp_omp_places_syntax_warn(var);
2725  return FALSE;
2726  }
2727  return TRUE;
2728 }
2729 
2730 static int __kmp_parse_place(const char *var, const char **scan) {
2731  const char *next;
2732 
2733  // valid follow sets are '{' '!' and num
2734  SKIP_WS(*scan);
2735  if (**scan == '{') {
2736  (*scan)++; // skip '{'
2737  if (!__kmp_parse_subplace_list(var, scan)) {
2738  return FALSE;
2739  }
2740  if (**scan != '}') {
2741  __kmp_omp_places_syntax_warn(var);
2742  return FALSE;
2743  }
2744  (*scan)++; // skip '}'
2745  } else if (**scan == '!') {
2746  (*scan)++; // skip '!'
2747  return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2748  } else if ((**scan >= '0') && (**scan <= '9')) {
2749  next = *scan;
2750  SKIP_DIGITS(next);
2751  int proc = __kmp_str_to_int(*scan, *next);
2752  KMP_ASSERT(proc >= 0);
2753  *scan = next;
2754  } else {
2755  __kmp_omp_places_syntax_warn(var);
2756  return FALSE;
2757  }
2758  return TRUE;
2759 }
2760 
2761 static int __kmp_parse_place_list(const char *var, const char *env,
2762  char **place_list) {
2763  const char *scan = env;
2764  const char *next = scan;
2765 
2766  for (;;) {
2767  int count, stride;
2768 
2769  if (!__kmp_parse_place(var, &scan)) {
2770  return FALSE;
2771  }
2772 
2773  // valid follow sets are ',' ':' and EOL
2774  SKIP_WS(scan);
2775  if (*scan == '\0') {
2776  break;
2777  }
2778  if (*scan == ',') {
2779  scan++; // skip ','
2780  continue;
2781  }
2782  if (*scan != ':') {
2783  __kmp_omp_places_syntax_warn(var);
2784  return FALSE;
2785  }
2786  scan++; // skip ':'
2787 
2788  // Read count parameter
2789  SKIP_WS(scan);
2790  if ((*scan < '0') || (*scan > '9')) {
2791  __kmp_omp_places_syntax_warn(var);
2792  return FALSE;
2793  }
2794  next = scan;
2795  SKIP_DIGITS(next);
2796  count = __kmp_str_to_int(scan, *next);
2797  KMP_ASSERT(count >= 0);
2798  scan = next;
2799 
2800  // valid follow sets are ',' ':' and EOL
2801  SKIP_WS(scan);
2802  if (*scan == '\0') {
2803  break;
2804  }
2805  if (*scan == ',') {
2806  scan++; // skip ','
2807  continue;
2808  }
2809  if (*scan != ':') {
2810  __kmp_omp_places_syntax_warn(var);
2811  return FALSE;
2812  }
2813  scan++; // skip ':'
2814 
2815  // Read stride parameter
2816  int sign = +1;
2817  for (;;) {
2818  SKIP_WS(scan);
2819  if (*scan == '+') {
2820  scan++; // skip '+'
2821  continue;
2822  }
2823  if (*scan == '-') {
2824  sign *= -1;
2825  scan++; // skip '-'
2826  continue;
2827  }
2828  break;
2829  }
2830  SKIP_WS(scan);
2831  if ((*scan < '0') || (*scan > '9')) {
2832  __kmp_omp_places_syntax_warn(var);
2833  return FALSE;
2834  }
2835  next = scan;
2836  SKIP_DIGITS(next);
2837  stride = __kmp_str_to_int(scan, *next);
2838  KMP_ASSERT(stride >= 0);
2839  scan = next;
2840  stride *= sign;
2841 
2842  // valid follow sets are ',' and EOL
2843  SKIP_WS(scan);
2844  if (*scan == '\0') {
2845  break;
2846  }
2847  if (*scan == ',') {
2848  scan++; // skip ','
2849  continue;
2850  }
2851 
2852  __kmp_omp_places_syntax_warn(var);
2853  return FALSE;
2854  }
2855 
2856  {
2857  ptrdiff_t len = scan - env;
2858  char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
2859  KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
2860  retlist[len] = '\0';
2861  *place_list = retlist;
2862  }
2863  return TRUE;
2864 }
2865 
2866 static void __kmp_stg_parse_places(char const *name, char const *value,
2867  void *data) {
2868  struct kmp_place_t {
2869  const char *name;
2870  kmp_hw_t type;
2871  };
2872  int count;
2873  bool set = false;
2874  const char *scan = value;
2875  const char *next = scan;
2876  const char *kind = "\"threads\"";
2877  kmp_place_t std_places[] = {{"threads", KMP_HW_THREAD},
2878  {"cores", KMP_HW_CORE},
2879  {"numa_domains", KMP_HW_NUMA},
2880  {"ll_caches", KMP_HW_LLC},
2881  {"sockets", KMP_HW_SOCKET}};
2882  kmp_setting_t **rivals = (kmp_setting_t **)data;
2883  int rc;
2884 
2885  rc = __kmp_stg_check_rivals(name, value, rivals);
2886  if (rc) {
2887  return;
2888  }
2889 
2890  // Standard choices
2891  for (size_t i = 0; i < sizeof(std_places) / sizeof(std_places[0]); ++i) {
2892  const kmp_place_t &place = std_places[i];
2893  if (__kmp_match_str(place.name, scan, &next)) {
2894  scan = next;
2895  __kmp_affinity_type = affinity_compact;
2896  __kmp_affinity_gran = place.type;
2897  __kmp_affinity_dups = FALSE;
2898  set = true;
2899  break;
2900  }
2901  }
2902  // Implementation choices for OMP_PLACES based on internal types
2903  if (!set) {
2904  KMP_FOREACH_HW_TYPE(type) {
2905  const char *name = __kmp_hw_get_keyword(type, true);
2906  if (__kmp_match_str("unknowns", scan, &next))
2907  continue;
2908  if (__kmp_match_str(name, scan, &next)) {
2909  scan = next;
2910  __kmp_affinity_type = affinity_compact;
2911  __kmp_affinity_gran = type;
2912  __kmp_affinity_dups = FALSE;
2913  set = true;
2914  break;
2915  }
2916  }
2917  }
2918  if (!set) {
2919  if (__kmp_affinity_proclist != NULL) {
2920  KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist);
2921  __kmp_affinity_proclist = NULL;
2922  }
2923  if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2924  __kmp_affinity_type = affinity_explicit;
2925  __kmp_affinity_gran = KMP_HW_THREAD;
2926  __kmp_affinity_dups = FALSE;
2927  } else {
2928  // Syntax error fallback
2929  __kmp_affinity_type = affinity_compact;
2930  __kmp_affinity_gran = KMP_HW_CORE;
2931  __kmp_affinity_dups = FALSE;
2932  }
2933  if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2934  __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2935  }
2936  return;
2937  }
2938  if (__kmp_affinity_gran != KMP_HW_UNKNOWN) {
2939  kind = __kmp_hw_get_keyword(__kmp_affinity_gran);
2940  }
2941 
2942  if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2943  __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2944  }
2945 
2946  SKIP_WS(scan);
2947  if (*scan == '\0') {
2948  return;
2949  }
2950 
2951  // Parse option count parameter in parentheses
2952  if (*scan != '(') {
2953  KMP_WARNING(SyntaxErrorUsing, name, kind);
2954  return;
2955  }
2956  scan++; // skip '('
2957 
2958  SKIP_WS(scan);
2959  next = scan;
2960  SKIP_DIGITS(next);
2961  count = __kmp_str_to_int(scan, *next);
2962  KMP_ASSERT(count >= 0);
2963  scan = next;
2964 
2965  SKIP_WS(scan);
2966  if (*scan != ')') {
2967  KMP_WARNING(SyntaxErrorUsing, name, kind);
2968  return;
2969  }
2970  scan++; // skip ')'
2971 
2972  SKIP_WS(scan);
2973  if (*scan != '\0') {
2974  KMP_WARNING(ParseExtraCharsWarn, name, scan);
2975  }
2976  __kmp_affinity_num_places = count;
2977 }
2978 
2979 static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
2980  void *data) {
2981  if (__kmp_env_format) {
2982  KMP_STR_BUF_PRINT_NAME;
2983  } else {
2984  __kmp_str_buf_print(buffer, " %s", name);
2985  }
2986  if ((__kmp_nested_proc_bind.used == 0) ||
2987  (__kmp_nested_proc_bind.bind_types == NULL) ||
2988  (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
2989  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2990  } else if (__kmp_affinity_type == affinity_explicit) {
2991  if (__kmp_affinity_proclist != NULL) {
2992  __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist);
2993  } else {
2994  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2995  }
2996  } else if (__kmp_affinity_type == affinity_compact) {
2997  int num;
2998  if (__kmp_affinity_num_masks > 0) {
2999  num = __kmp_affinity_num_masks;
3000  } else if (__kmp_affinity_num_places > 0) {
3001  num = __kmp_affinity_num_places;
3002  } else {
3003  num = 0;
3004  }
3005  if (__kmp_affinity_gran != KMP_HW_UNKNOWN) {
3006  const char *name = __kmp_hw_get_keyword(__kmp_affinity_gran, true);
3007  if (num > 0) {
3008  __kmp_str_buf_print(buffer, "='%s(%d)'\n", name, num);
3009  } else {
3010  __kmp_str_buf_print(buffer, "='%s'\n", name);
3011  }
3012  } else {
3013  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3014  }
3015  } else {
3016  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3017  }
3018 }
3019 
3020 static void __kmp_stg_parse_topology_method(char const *name, char const *value,
3021  void *data) {
3022  if (__kmp_str_match("all", 1, value)) {
3023  __kmp_affinity_top_method = affinity_top_method_all;
3024  }
3025 #if KMP_USE_HWLOC
3026  else if (__kmp_str_match("hwloc", 1, value)) {
3027  __kmp_affinity_top_method = affinity_top_method_hwloc;
3028  }
3029 #endif
3030 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3031  else if (__kmp_str_match("cpuid_leaf31", 12, value) ||
3032  __kmp_str_match("cpuid 1f", 8, value) ||
3033  __kmp_str_match("cpuid 31", 8, value) ||
3034  __kmp_str_match("cpuid1f", 7, value) ||
3035  __kmp_str_match("cpuid31", 7, value) ||
3036  __kmp_str_match("leaf 1f", 7, value) ||
3037  __kmp_str_match("leaf 31", 7, value) ||
3038  __kmp_str_match("leaf1f", 6, value) ||
3039  __kmp_str_match("leaf31", 6, value)) {
3040  __kmp_affinity_top_method = affinity_top_method_x2apicid_1f;
3041  } else if (__kmp_str_match("x2apic id", 9, value) ||
3042  __kmp_str_match("x2apic_id", 9, value) ||
3043  __kmp_str_match("x2apic-id", 9, value) ||
3044  __kmp_str_match("x2apicid", 8, value) ||
3045  __kmp_str_match("cpuid leaf 11", 13, value) ||
3046  __kmp_str_match("cpuid_leaf_11", 13, value) ||
3047  __kmp_str_match("cpuid-leaf-11", 13, value) ||
3048  __kmp_str_match("cpuid leaf11", 12, value) ||
3049  __kmp_str_match("cpuid_leaf11", 12, value) ||
3050  __kmp_str_match("cpuid-leaf11", 12, value) ||
3051  __kmp_str_match("cpuidleaf 11", 12, value) ||
3052  __kmp_str_match("cpuidleaf_11", 12, value) ||
3053  __kmp_str_match("cpuidleaf-11", 12, value) ||
3054  __kmp_str_match("cpuidleaf11", 11, value) ||
3055  __kmp_str_match("cpuid 11", 8, value) ||
3056  __kmp_str_match("cpuid_11", 8, value) ||
3057  __kmp_str_match("cpuid-11", 8, value) ||
3058  __kmp_str_match("cpuid11", 7, value) ||
3059  __kmp_str_match("leaf 11", 7, value) ||
3060  __kmp_str_match("leaf_11", 7, value) ||
3061  __kmp_str_match("leaf-11", 7, value) ||
3062  __kmp_str_match("leaf11", 6, value)) {
3063  __kmp_affinity_top_method = affinity_top_method_x2apicid;
3064  } else if (__kmp_str_match("apic id", 7, value) ||
3065  __kmp_str_match("apic_id", 7, value) ||
3066  __kmp_str_match("apic-id", 7, value) ||
3067  __kmp_str_match("apicid", 6, value) ||
3068  __kmp_str_match("cpuid leaf 4", 12, value) ||
3069  __kmp_str_match("cpuid_leaf_4", 12, value) ||
3070  __kmp_str_match("cpuid-leaf-4", 12, value) ||
3071  __kmp_str_match("cpuid leaf4", 11, value) ||
3072  __kmp_str_match("cpuid_leaf4", 11, value) ||
3073  __kmp_str_match("cpuid-leaf4", 11, value) ||
3074  __kmp_str_match("cpuidleaf 4", 11, value) ||
3075  __kmp_str_match("cpuidleaf_4", 11, value) ||
3076  __kmp_str_match("cpuidleaf-4", 11, value) ||
3077  __kmp_str_match("cpuidleaf4", 10, value) ||
3078  __kmp_str_match("cpuid 4", 7, value) ||
3079  __kmp_str_match("cpuid_4", 7, value) ||
3080  __kmp_str_match("cpuid-4", 7, value) ||
3081  __kmp_str_match("cpuid4", 6, value) ||
3082  __kmp_str_match("leaf 4", 6, value) ||
3083  __kmp_str_match("leaf_4", 6, value) ||
3084  __kmp_str_match("leaf-4", 6, value) ||
3085  __kmp_str_match("leaf4", 5, value)) {
3086  __kmp_affinity_top_method = affinity_top_method_apicid;
3087  }
3088 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
3089  else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
3090  __kmp_str_match("cpuinfo", 5, value)) {
3091  __kmp_affinity_top_method = affinity_top_method_cpuinfo;
3092  }
3093 #if KMP_GROUP_AFFINITY
3094  else if (__kmp_str_match("group", 1, value)) {
3095  __kmp_affinity_top_method = affinity_top_method_group;
3096  }
3097 #endif /* KMP_GROUP_AFFINITY */
3098  else if (__kmp_str_match("flat", 1, value)) {
3099  __kmp_affinity_top_method = affinity_top_method_flat;
3100  } else {
3101  KMP_WARNING(StgInvalidValue, name, value);
3102  }
3103 } // __kmp_stg_parse_topology_method
3104 
3105 static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
3106  char const *name, void *data) {
3107  char const *value = NULL;
3108 
3109  switch (__kmp_affinity_top_method) {
3110  case affinity_top_method_default:
3111  value = "default";
3112  break;
3113 
3114  case affinity_top_method_all:
3115  value = "all";
3116  break;
3117 
3118 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3119  case affinity_top_method_x2apicid_1f:
3120  value = "x2APIC id leaf 0x1f";
3121  break;
3122 
3123  case affinity_top_method_x2apicid:
3124  value = "x2APIC id leaf 0xb";
3125  break;
3126 
3127  case affinity_top_method_apicid:
3128  value = "APIC id";
3129  break;
3130 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
3131 
3132 #if KMP_USE_HWLOC
3133  case affinity_top_method_hwloc:
3134  value = "hwloc";
3135  break;
3136 #endif
3137 
3138  case affinity_top_method_cpuinfo:
3139  value = "cpuinfo";
3140  break;
3141 
3142 #if KMP_GROUP_AFFINITY
3143  case affinity_top_method_group:
3144  value = "group";
3145  break;
3146 #endif /* KMP_GROUP_AFFINITY */
3147 
3148  case affinity_top_method_flat:
3149  value = "flat";
3150  break;
3151  }
3152 
3153  if (value != NULL) {
3154  __kmp_stg_print_str(buffer, name, value);
3155  }
3156 } // __kmp_stg_print_topology_method
3157 
3158 #endif /* KMP_AFFINITY_SUPPORTED */
3159 
3160 // OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
3161 // OMP_PLACES / place-partition-var is not.
3162 static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
3163  void *data) {
3164  kmp_setting_t **rivals = (kmp_setting_t **)data;
3165  int rc;
3166 
3167  rc = __kmp_stg_check_rivals(name, value, rivals);
3168  if (rc) {
3169  return;
3170  }
3171 
3172  // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
3173  KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
3174  (__kmp_nested_proc_bind.used > 0));
3175 
3176  const char *buf = value;
3177  const char *next;
3178  int num;
3179  SKIP_WS(buf);
3180  if ((*buf >= '0') && (*buf <= '9')) {
3181  next = buf;
3182  SKIP_DIGITS(next);
3183  num = __kmp_str_to_int(buf, *next);
3184  KMP_ASSERT(num >= 0);
3185  buf = next;
3186  SKIP_WS(buf);
3187  } else {
3188  num = -1;
3189  }
3190 
3191  next = buf;
3192  if (__kmp_match_str("disabled", buf, &next)) {
3193  buf = next;
3194  SKIP_WS(buf);
3195 #if KMP_AFFINITY_SUPPORTED
3196  __kmp_affinity_type = affinity_disabled;
3197 #endif /* KMP_AFFINITY_SUPPORTED */
3198  __kmp_nested_proc_bind.used = 1;
3199  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3200  } else if ((num == (int)proc_bind_false) ||
3201  __kmp_match_str("false", buf, &next)) {
3202  buf = next;
3203  SKIP_WS(buf);
3204 #if KMP_AFFINITY_SUPPORTED
3205  __kmp_affinity_type = affinity_none;
3206 #endif /* KMP_AFFINITY_SUPPORTED */
3207  __kmp_nested_proc_bind.used = 1;
3208  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3209  } else if ((num == (int)proc_bind_true) ||
3210  __kmp_match_str("true", buf, &next)) {
3211  buf = next;
3212  SKIP_WS(buf);
3213  __kmp_nested_proc_bind.used = 1;
3214  __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3215  } else {
3216  // Count the number of values in the env var string
3217  const char *scan;
3218  int nelem = 1;
3219  for (scan = buf; *scan != '\0'; scan++) {
3220  if (*scan == ',') {
3221  nelem++;
3222  }
3223  }
3224 
3225  // Create / expand the nested proc_bind array as needed
3226  if (__kmp_nested_proc_bind.size < nelem) {
3227  __kmp_nested_proc_bind.bind_types =
3228  (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3229  __kmp_nested_proc_bind.bind_types,
3230  sizeof(kmp_proc_bind_t) * nelem);
3231  if (__kmp_nested_proc_bind.bind_types == NULL) {
3232  KMP_FATAL(MemoryAllocFailed);
3233  }
3234  __kmp_nested_proc_bind.size = nelem;
3235  }
3236  __kmp_nested_proc_bind.used = nelem;
3237 
3238  if (nelem > 1 && !__kmp_dflt_max_active_levels_set)
3239  __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
3240 
3241  // Save values in the nested proc_bind array
3242  int i = 0;
3243  for (;;) {
3244  enum kmp_proc_bind_t bind;
3245 
3246  if ((num == (int)proc_bind_primary) ||
3247  __kmp_match_str("master", buf, &next) ||
3248  __kmp_match_str("primary", buf, &next)) {
3249  buf = next;
3250  SKIP_WS(buf);
3251  bind = proc_bind_primary;
3252  } else if ((num == (int)proc_bind_close) ||
3253  __kmp_match_str("close", buf, &next)) {
3254  buf = next;
3255  SKIP_WS(buf);
3256  bind = proc_bind_close;
3257  } else if ((num == (int)proc_bind_spread) ||
3258  __kmp_match_str("spread", buf, &next)) {
3259  buf = next;
3260  SKIP_WS(buf);
3261  bind = proc_bind_spread;
3262  } else {
3263  KMP_WARNING(StgInvalidValue, name, value);
3264  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3265  __kmp_nested_proc_bind.used = 1;
3266  return;
3267  }
3268 
3269  __kmp_nested_proc_bind.bind_types[i++] = bind;
3270  if (i >= nelem) {
3271  break;
3272  }
3273  KMP_DEBUG_ASSERT(*buf == ',');
3274  buf++;
3275  SKIP_WS(buf);
3276 
3277  // Read next value if it was specified as an integer
3278  if ((*buf >= '0') && (*buf <= '9')) {
3279  next = buf;
3280  SKIP_DIGITS(next);
3281  num = __kmp_str_to_int(buf, *next);
3282  KMP_ASSERT(num >= 0);
3283  buf = next;
3284  SKIP_WS(buf);
3285  } else {
3286  num = -1;
3287  }
3288  }
3289  SKIP_WS(buf);
3290  }
3291  if (*buf != '\0') {
3292  KMP_WARNING(ParseExtraCharsWarn, name, buf);
3293  }
3294 }
3295 
3296 static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
3297  void *data) {
3298  int nelem = __kmp_nested_proc_bind.used;
3299  if (__kmp_env_format) {
3300  KMP_STR_BUF_PRINT_NAME;
3301  } else {
3302  __kmp_str_buf_print(buffer, " %s", name);
3303  }
3304  if (nelem == 0) {
3305  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3306  } else {
3307  int i;
3308  __kmp_str_buf_print(buffer, "='", name);
3309  for (i = 0; i < nelem; i++) {
3310  switch (__kmp_nested_proc_bind.bind_types[i]) {
3311  case proc_bind_false:
3312  __kmp_str_buf_print(buffer, "false");
3313  break;
3314 
3315  case proc_bind_true:
3316  __kmp_str_buf_print(buffer, "true");
3317  break;
3318 
3319  case proc_bind_primary:
3320  __kmp_str_buf_print(buffer, "primary");
3321  break;
3322 
3323  case proc_bind_close:
3324  __kmp_str_buf_print(buffer, "close");
3325  break;
3326 
3327  case proc_bind_spread:
3328  __kmp_str_buf_print(buffer, "spread");
3329  break;
3330 
3331  case proc_bind_intel:
3332  __kmp_str_buf_print(buffer, "intel");
3333  break;
3334 
3335  case proc_bind_default:
3336  __kmp_str_buf_print(buffer, "default");
3337  break;
3338  }
3339  if (i < nelem - 1) {
3340  __kmp_str_buf_print(buffer, ",");
3341  }
3342  }
3343  __kmp_str_buf_print(buffer, "'\n");
3344  }
3345 }
3346 
3347 static void __kmp_stg_parse_display_affinity(char const *name,
3348  char const *value, void *data) {
3349  __kmp_stg_parse_bool(name, value, &__kmp_display_affinity);
3350 }
3351 static void __kmp_stg_print_display_affinity(kmp_str_buf_t *buffer,
3352  char const *name, void *data) {
3353  __kmp_stg_print_bool(buffer, name, __kmp_display_affinity);
3354 }
3355 static void __kmp_stg_parse_affinity_format(char const *name, char const *value,
3356  void *data) {
3357  size_t length = KMP_STRLEN(value);
3358  __kmp_strncpy_truncate(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, value,
3359  length);
3360 }
3361 static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer,
3362  char const *name, void *data) {
3363  if (__kmp_env_format) {
3364  KMP_STR_BUF_PRINT_NAME_EX(name);
3365  } else {
3366  __kmp_str_buf_print(buffer, " %s='", name);
3367  }
3368  __kmp_str_buf_print(buffer, "%s'\n", __kmp_affinity_format);
3369 }
3370 
3371 /*-----------------------------------------------------------------------------
3372 OMP_ALLOCATOR sets default allocator. Here is the grammar:
3373 
3374 <allocator> |= <predef-allocator> | <predef-mem-space> |
3375  <predef-mem-space>:<traits>
3376 <traits> |= <trait>=<value> | <trait>=<value>,<traits>
3377 <predef-allocator> |= omp_default_mem_alloc | omp_large_cap_mem_alloc |
3378  omp_const_mem_alloc | omp_high_bw_mem_alloc |
3379  omp_low_lat_mem_alloc | omp_cgroup_mem_alloc |
3380  omp_pteam_mem_alloc | omp_thread_mem_alloc
3381 <predef-mem-space> |= omp_default_mem_space | omp_large_cap_mem_space |
3382  omp_const_mem_space | omp_high_bw_mem_space |
3383  omp_low_lat_mem_space
3384 <trait> |= sync_hint | alignment | access | pool_size | fallback |
3385  fb_data | pinned | partition
3386 <value> |= one of the allowed values of trait |
3387  non-negative integer | <predef-allocator>
3388 -----------------------------------------------------------------------------*/
3389 
3390 static void __kmp_stg_parse_allocator(char const *name, char const *value,
3391  void *data) {
3392  const char *buf = value;
3393  const char *next, *scan, *start;
3394  char *key;
3395  omp_allocator_handle_t al;
3396  omp_memspace_handle_t ms = omp_default_mem_space;
3397  bool is_memspace = false;
3398  int ntraits = 0, count = 0;
3399 
3400  SKIP_WS(buf);
3401  next = buf;
3402  const char *delim = strchr(buf, ':');
3403  const char *predef_mem_space = strstr(buf, "mem_space");
3404 
3405  bool is_memalloc = (!predef_mem_space && !delim) ? true : false;
3406 
3407  // Count the number of traits in the env var string
3408  if (delim) {
3409  ntraits = 1;
3410  for (scan = buf; *scan != '\0'; scan++) {
3411  if (*scan == ',')
3412  ntraits++;
3413  }
3414  }
3415  omp_alloctrait_t *traits =
3416  (omp_alloctrait_t *)KMP_ALLOCA(ntraits * sizeof(omp_alloctrait_t));
3417 
3418 // Helper macros
3419 #define IS_POWER_OF_TWO(n) (((n) & ((n)-1)) == 0)
3420 
3421 #define GET_NEXT(sentinel) \
3422  { \
3423  SKIP_WS(next); \
3424  if (*next == sentinel) \
3425  next++; \
3426  SKIP_WS(next); \
3427  scan = next; \
3428  }
3429 
3430 #define SKIP_PAIR(key) \
3431  { \
3432  char const str_delimiter[] = {',', 0}; \
3433  char *value = __kmp_str_token(CCAST(char *, scan), str_delimiter, \
3434  CCAST(char **, &next)); \
3435  KMP_WARNING(StgInvalidValue, key, value); \
3436  ntraits--; \
3437  SKIP_WS(next); \
3438  scan = next; \
3439  }
3440 
3441 #define SET_KEY() \
3442  { \
3443  char const str_delimiter[] = {'=', 0}; \
3444  key = __kmp_str_token(CCAST(char *, start), str_delimiter, \
3445  CCAST(char **, &next)); \
3446  scan = next; \
3447  }
3448 
3449  scan = next;
3450  while (*next != '\0') {
3451  if (is_memalloc ||
3452  __kmp_match_str("fb_data", scan, &next)) { // allocator check
3453  start = scan;
3454  GET_NEXT('=');
3455  // check HBW and LCAP first as the only non-default supported
3456  if (__kmp_match_str("omp_high_bw_mem_alloc", scan, &next)) {
3457  SKIP_WS(next);
3458  if (is_memalloc) {
3459  if (__kmp_memkind_available) {
3460  __kmp_def_allocator = omp_high_bw_mem_alloc;
3461  return;
3462  } else {
3463  KMP_WARNING(OmpNoAllocator, "omp_high_bw_mem_alloc");
3464  }
3465  } else {
3466  traits[count].key = omp_atk_fb_data;
3467  traits[count].value = RCAST(omp_uintptr_t, omp_high_bw_mem_alloc);
3468  }
3469  } else if (__kmp_match_str("omp_large_cap_mem_alloc", scan, &next)) {
3470  SKIP_WS(next);
3471  if (is_memalloc) {
3472  if (__kmp_memkind_available) {
3473  __kmp_def_allocator = omp_large_cap_mem_alloc;
3474  return;
3475  } else {
3476  KMP_WARNING(OmpNoAllocator, "omp_large_cap_mem_alloc");
3477  }
3478  } else {
3479  traits[count].key = omp_atk_fb_data;
3480  traits[count].value = RCAST(omp_uintptr_t, omp_large_cap_mem_alloc);
3481  }
3482  } else if (__kmp_match_str("omp_default_mem_alloc", scan, &next)) {
3483  // default requested
3484  SKIP_WS(next);
3485  if (!is_memalloc) {
3486  traits[count].key = omp_atk_fb_data;
3487  traits[count].value = RCAST(omp_uintptr_t, omp_default_mem_alloc);
3488  }
3489  } else if (__kmp_match_str("omp_const_mem_alloc", scan, &next)) {
3490  SKIP_WS(next);
3491  if (is_memalloc) {
3492  KMP_WARNING(OmpNoAllocator, "omp_const_mem_alloc");
3493  } else {
3494  traits[count].key = omp_atk_fb_data;
3495  traits[count].value = RCAST(omp_uintptr_t, omp_const_mem_alloc);
3496  }
3497  } else if (__kmp_match_str("omp_low_lat_mem_alloc", scan, &next)) {
3498  SKIP_WS(next);
3499  if (is_memalloc) {
3500  KMP_WARNING(OmpNoAllocator, "omp_low_lat_mem_alloc");
3501  } else {
3502  traits[count].key = omp_atk_fb_data;
3503  traits[count].value = RCAST(omp_uintptr_t, omp_low_lat_mem_alloc);
3504  }
3505  } else if (__kmp_match_str("omp_cgroup_mem_alloc", scan, &next)) {
3506  SKIP_WS(next);
3507  if (is_memalloc) {
3508  KMP_WARNING(OmpNoAllocator, "omp_cgroup_mem_alloc");
3509  } else {
3510  traits[count].key = omp_atk_fb_data;
3511  traits[count].value = RCAST(omp_uintptr_t, omp_cgroup_mem_alloc);
3512  }
3513  } else if (__kmp_match_str("omp_pteam_mem_alloc", scan, &next)) {
3514  SKIP_WS(next);
3515  if (is_memalloc) {
3516  KMP_WARNING(OmpNoAllocator, "omp_pteam_mem_alloc");
3517  } else {
3518  traits[count].key = omp_atk_fb_data;
3519  traits[count].value = RCAST(omp_uintptr_t, omp_pteam_mem_alloc);
3520  }
3521  } else if (__kmp_match_str("omp_thread_mem_alloc", scan, &next)) {
3522  SKIP_WS(next);
3523  if (is_memalloc) {
3524  KMP_WARNING(OmpNoAllocator, "omp_thread_mem_alloc");
3525  } else {
3526  traits[count].key = omp_atk_fb_data;
3527  traits[count].value = RCAST(omp_uintptr_t, omp_thread_mem_alloc);
3528  }
3529  } else {
3530  if (!is_memalloc) {
3531  SET_KEY();
3532  SKIP_PAIR(key);
3533  continue;
3534  }
3535  }
3536  if (is_memalloc) {
3537  __kmp_def_allocator = omp_default_mem_alloc;
3538  if (next == buf || *next != '\0') {
3539  // either no match or extra symbols present after the matched token
3540  KMP_WARNING(StgInvalidValue, name, value);
3541  }
3542  return;
3543  } else {
3544  ++count;
3545  if (count == ntraits)
3546  break;
3547  GET_NEXT(',');
3548  }
3549  } else { // memspace
3550  if (!is_memspace) {
3551  if (__kmp_match_str("omp_default_mem_space", scan, &next)) {
3552  SKIP_WS(next);
3553  ms = omp_default_mem_space;
3554  } else if (__kmp_match_str("omp_large_cap_mem_space", scan, &next)) {
3555  SKIP_WS(next);
3556  ms = omp_large_cap_mem_space;
3557  } else if (__kmp_match_str("omp_const_mem_space", scan, &next)) {
3558  SKIP_WS(next);
3559  ms = omp_const_mem_space;
3560  } else if (__kmp_match_str("omp_high_bw_mem_space", scan, &next)) {
3561  SKIP_WS(next);
3562  ms = omp_high_bw_mem_space;
3563  } else if (__kmp_match_str("omp_low_lat_mem_space", scan, &next)) {
3564  SKIP_WS(next);
3565  ms = omp_low_lat_mem_space;
3566  } else {
3567  __kmp_def_allocator = omp_default_mem_alloc;
3568  if (next == buf || *next != '\0') {
3569  // either no match or extra symbols present after the matched token
3570  KMP_WARNING(StgInvalidValue, name, value);
3571  }
3572  return;
3573  }
3574  is_memspace = true;
3575  }
3576  if (delim) { // traits
3577  GET_NEXT(':');
3578  start = scan;
3579  if (__kmp_match_str("sync_hint", scan, &next)) {
3580  GET_NEXT('=');
3581  traits[count].key = omp_atk_sync_hint;
3582  if (__kmp_match_str("contended", scan, &next)) {
3583  traits[count].value = omp_atv_contended;
3584  } else if (__kmp_match_str("uncontended", scan, &next)) {
3585  traits[count].value = omp_atv_uncontended;
3586  } else if (__kmp_match_str("serialized", scan, &next)) {
3587  traits[count].value = omp_atv_serialized;
3588  } else if (__kmp_match_str("private", scan, &next)) {
3589  traits[count].value = omp_atv_private;
3590  } else {
3591  SET_KEY();
3592  SKIP_PAIR(key);
3593  continue;
3594  }
3595  } else if (__kmp_match_str("alignment", scan, &next)) {
3596  GET_NEXT('=');
3597  if (!isdigit(*next)) {
3598  SET_KEY();
3599  SKIP_PAIR(key);
3600  continue;
3601  }
3602  SKIP_DIGITS(next);
3603  int n = __kmp_str_to_int(scan, ',');
3604  if (n < 0 || !IS_POWER_OF_TWO(n)) {
3605  SET_KEY();
3606  SKIP_PAIR(key);
3607  continue;
3608  }
3609  traits[count].key = omp_atk_alignment;
3610  traits[count].value = n;
3611  } else if (__kmp_match_str("access", scan, &next)) {
3612  GET_NEXT('=');
3613  traits[count].key = omp_atk_access;
3614  if (__kmp_match_str("all", scan, &next)) {
3615  traits[count].value = omp_atv_all;
3616  } else if (__kmp_match_str("cgroup", scan, &next)) {
3617  traits[count].value = omp_atv_cgroup;
3618  } else if (__kmp_match_str("pteam", scan, &next)) {
3619  traits[count].value = omp_atv_pteam;
3620  } else if (__kmp_match_str("thread", scan, &next)) {
3621  traits[count].value = omp_atv_thread;
3622  } else {
3623  SET_KEY();
3624  SKIP_PAIR(key);
3625  continue;
3626  }
3627  } else if (__kmp_match_str("pool_size", scan, &next)) {
3628  GET_NEXT('=');
3629  if (!isdigit(*next)) {
3630  SET_KEY();
3631  SKIP_PAIR(key);
3632  continue;
3633  }
3634  SKIP_DIGITS(next);
3635  int n = __kmp_str_to_int(scan, ',');
3636  if (n < 0) {
3637  SET_KEY();
3638  SKIP_PAIR(key);
3639  continue;
3640  }
3641  traits[count].key = omp_atk_pool_size;
3642  traits[count].value = n;
3643  } else if (__kmp_match_str("fallback", scan, &next)) {
3644  GET_NEXT('=');
3645  traits[count].key = omp_atk_fallback;
3646  if (__kmp_match_str("default_mem_fb", scan, &next)) {
3647  traits[count].value = omp_atv_default_mem_fb;
3648  } else if (__kmp_match_str("null_fb", scan, &next)) {
3649  traits[count].value = omp_atv_null_fb;
3650  } else if (__kmp_match_str("abort_fb", scan, &next)) {
3651  traits[count].value = omp_atv_abort_fb;
3652  } else if (__kmp_match_str("allocator_fb", scan, &next)) {
3653  traits[count].value = omp_atv_allocator_fb;
3654  } else {
3655  SET_KEY();
3656  SKIP_PAIR(key);
3657  continue;
3658  }
3659  } else if (__kmp_match_str("pinned", scan, &next)) {
3660  GET_NEXT('=');
3661  traits[count].key = omp_atk_pinned;
3662  if (__kmp_str_match_true(next)) {
3663  traits[count].value = omp_atv_true;
3664  } else if (__kmp_str_match_false(next)) {
3665  traits[count].value = omp_atv_false;
3666  } else {
3667  SET_KEY();
3668  SKIP_PAIR(key);
3669  continue;
3670  }
3671  } else if (__kmp_match_str("partition", scan, &next)) {
3672  GET_NEXT('=');
3673  traits[count].key = omp_atk_partition;
3674  if (__kmp_match_str("environment", scan, &next)) {
3675  traits[count].value = omp_atv_environment;
3676  } else if (__kmp_match_str("nearest", scan, &next)) {
3677  traits[count].value = omp_atv_nearest;
3678  } else if (__kmp_match_str("blocked", scan, &next)) {
3679  traits[count].value = omp_atv_blocked;
3680  } else if (__kmp_match_str("interleaved", scan, &next)) {
3681  traits[count].value = omp_atv_interleaved;
3682  } else {
3683  SET_KEY();
3684  SKIP_PAIR(key);
3685  continue;
3686  }
3687  } else {
3688  SET_KEY();
3689  SKIP_PAIR(key);
3690  continue;
3691  }
3692  SKIP_WS(next);
3693  ++count;
3694  if (count == ntraits)
3695  break;
3696  GET_NEXT(',');
3697  } // traits
3698  } // memspace
3699  } // while
3700  al = __kmpc_init_allocator(__kmp_get_gtid(), ms, ntraits, traits);
3701  __kmp_def_allocator = (al == omp_null_allocator) ? omp_default_mem_alloc : al;
3702 }
3703 
3704 static void __kmp_stg_print_allocator(kmp_str_buf_t *buffer, char const *name,
3705  void *data) {
3706  if (__kmp_def_allocator == omp_default_mem_alloc) {
3707  __kmp_stg_print_str(buffer, name, "omp_default_mem_alloc");
3708  } else if (__kmp_def_allocator == omp_high_bw_mem_alloc) {
3709  __kmp_stg_print_str(buffer, name, "omp_high_bw_mem_alloc");
3710  } else if (__kmp_def_allocator == omp_large_cap_mem_alloc) {
3711  __kmp_stg_print_str(buffer, name, "omp_large_cap_mem_alloc");
3712  } else if (__kmp_def_allocator == omp_const_mem_alloc) {
3713  __kmp_stg_print_str(buffer, name, "omp_const_mem_alloc");
3714  } else if (__kmp_def_allocator == omp_low_lat_mem_alloc) {
3715  __kmp_stg_print_str(buffer, name, "omp_low_lat_mem_alloc");
3716  } else if (__kmp_def_allocator == omp_cgroup_mem_alloc) {
3717  __kmp_stg_print_str(buffer, name, "omp_cgroup_mem_alloc");
3718  } else if (__kmp_def_allocator == omp_pteam_mem_alloc) {
3719  __kmp_stg_print_str(buffer, name, "omp_pteam_mem_alloc");
3720  } else if (__kmp_def_allocator == omp_thread_mem_alloc) {
3721  __kmp_stg_print_str(buffer, name, "omp_thread_mem_alloc");
3722  }
3723 }
3724 
3725 // -----------------------------------------------------------------------------
3726 // OMP_DYNAMIC
3727 
3728 static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
3729  void *data) {
3730  __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
3731 } // __kmp_stg_parse_omp_dynamic
3732 
3733 static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
3734  void *data) {
3735  __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
3736 } // __kmp_stg_print_omp_dynamic
3737 
3738 static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
3739  char const *value, void *data) {
3740  if (TCR_4(__kmp_init_parallel)) {
3741  KMP_WARNING(EnvParallelWarn, name);
3742  __kmp_env_toPrint(name, 0);
3743  return;
3744  }
3745 #ifdef USE_LOAD_BALANCE
3746  else if (__kmp_str_match("load balance", 2, value) ||
3747  __kmp_str_match("load_balance", 2, value) ||
3748  __kmp_str_match("load-balance", 2, value) ||
3749  __kmp_str_match("loadbalance", 2, value) ||
3750  __kmp_str_match("balance", 1, value)) {
3751  __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3752  }
3753 #endif /* USE_LOAD_BALANCE */
3754  else if (__kmp_str_match("thread limit", 1, value) ||
3755  __kmp_str_match("thread_limit", 1, value) ||
3756  __kmp_str_match("thread-limit", 1, value) ||
3757  __kmp_str_match("threadlimit", 1, value) ||
3758  __kmp_str_match("limit", 2, value)) {
3759  __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3760  } else if (__kmp_str_match("random", 1, value)) {
3761  __kmp_global.g.g_dynamic_mode = dynamic_random;
3762  } else {
3763  KMP_WARNING(StgInvalidValue, name, value);
3764  }
3765 } //__kmp_stg_parse_kmp_dynamic_mode
3766 
3767 static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
3768  char const *name, void *data) {
3769 #if KMP_DEBUG
3770  if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
3771  __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
3772  }
3773 #ifdef USE_LOAD_BALANCE
3774  else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
3775  __kmp_stg_print_str(buffer, name, "load balance");
3776  }
3777 #endif /* USE_LOAD_BALANCE */
3778  else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
3779  __kmp_stg_print_str(buffer, name, "thread limit");
3780  } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
3781  __kmp_stg_print_str(buffer, name, "random");
3782  } else {
3783  KMP_ASSERT(0);
3784  }
3785 #endif /* KMP_DEBUG */
3786 } // __kmp_stg_print_kmp_dynamic_mode
3787 
3788 #ifdef USE_LOAD_BALANCE
3789 
3790 // -----------------------------------------------------------------------------
3791 // KMP_LOAD_BALANCE_INTERVAL
3792 
3793 static void __kmp_stg_parse_ld_balance_interval(char const *name,
3794  char const *value, void *data) {
3795  double interval = __kmp_convert_to_double(value);
3796  if (interval >= 0) {
3797  __kmp_load_balance_interval = interval;
3798  } else {
3799  KMP_WARNING(StgInvalidValue, name, value);
3800  }
3801 } // __kmp_stg_parse_load_balance_interval
3802 
3803 static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
3804  char const *name, void *data) {
3805 #if KMP_DEBUG
3806  __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
3807  __kmp_load_balance_interval);
3808 #endif /* KMP_DEBUG */
3809 } // __kmp_stg_print_load_balance_interval
3810 
3811 #endif /* USE_LOAD_BALANCE */
3812 
3813 // -----------------------------------------------------------------------------
3814 // KMP_INIT_AT_FORK
3815 
3816 static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
3817  void *data) {
3818  __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
3819  if (__kmp_need_register_atfork) {
3820  __kmp_need_register_atfork_specified = TRUE;
3821  }
3822 } // __kmp_stg_parse_init_at_fork
3823 
3824 static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
3825  char const *name, void *data) {
3826  __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
3827 } // __kmp_stg_print_init_at_fork
3828 
3829 // -----------------------------------------------------------------------------
3830 // KMP_SCHEDULE
3831 
3832 static void __kmp_stg_parse_schedule(char const *name, char const *value,
3833  void *data) {
3834 
3835  if (value != NULL) {
3836  size_t length = KMP_STRLEN(value);
3837  if (length > INT_MAX) {
3838  KMP_WARNING(LongValue, name);
3839  } else {
3840  const char *semicolon;
3841  if (value[length - 1] == '"' || value[length - 1] == '\'')
3842  KMP_WARNING(UnbalancedQuotes, name);
3843  do {
3844  char sentinel;
3845 
3846  semicolon = strchr(value, ';');
3847  if (*value && semicolon != value) {
3848  const char *comma = strchr(value, ',');
3849 
3850  if (comma) {
3851  ++comma;
3852  sentinel = ',';
3853  } else
3854  sentinel = ';';
3855  if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
3856  if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
3857  __kmp_static = kmp_sch_static_greedy;
3858  continue;
3859  } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
3860  ';')) {
3861  __kmp_static = kmp_sch_static_balanced;
3862  continue;
3863  }
3864  } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3865  sentinel)) {
3866  if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
3867  __kmp_guided = kmp_sch_guided_iterative_chunked;
3868  continue;
3869  } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
3870  ';')) {
3871  /* analytical not allowed for too many threads */
3872  __kmp_guided = kmp_sch_guided_analytical_chunked;
3873  continue;
3874  }
3875  }
3876  KMP_WARNING(InvalidClause, name, value);
3877  } else
3878  KMP_WARNING(EmptyClause, name);
3879  } while ((value = semicolon ? semicolon + 1 : NULL));
3880  }
3881  }
3882 
3883 } // __kmp_stg_parse__schedule
3884 
3885 static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
3886  void *data) {
3887  if (__kmp_env_format) {
3888  KMP_STR_BUF_PRINT_NAME_EX(name);
3889  } else {
3890  __kmp_str_buf_print(buffer, " %s='", name);
3891  }
3892  if (__kmp_static == kmp_sch_static_greedy) {
3893  __kmp_str_buf_print(buffer, "%s", "static,greedy");
3894  } else if (__kmp_static == kmp_sch_static_balanced) {
3895  __kmp_str_buf_print(buffer, "%s", "static,balanced");
3896  }
3897  if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
3898  __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
3899  } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
3900  __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
3901  }
3902 } // __kmp_stg_print_schedule
3903 
3904 // -----------------------------------------------------------------------------
3905 // OMP_SCHEDULE
3906 
3907 static inline void __kmp_omp_schedule_restore() {
3908 #if KMP_USE_HIER_SCHED
3909  __kmp_hier_scheds.deallocate();
3910 #endif
3911  __kmp_chunk = 0;
3912  __kmp_sched = kmp_sch_default;
3913 }
3914 
3915 // if parse_hier = true:
3916 // Parse [HW,][modifier:]kind[,chunk]
3917 // else:
3918 // Parse [modifier:]kind[,chunk]
3919 static const char *__kmp_parse_single_omp_schedule(const char *name,
3920  const char *value,
3921  bool parse_hier = false) {
3922  /* get the specified scheduling style */
3923  const char *ptr = value;
3924  const char *delim;
3925  int chunk = 0;
3926  enum sched_type sched = kmp_sch_default;
3927  if (*ptr == '\0')
3928  return NULL;
3929  delim = ptr;
3930  while (*delim != ',' && *delim != ':' && *delim != '\0')
3931  delim++;
3932 #if KMP_USE_HIER_SCHED
3933  kmp_hier_layer_e layer = kmp_hier_layer_e::LAYER_THREAD;
3934  if (parse_hier) {
3935  if (*delim == ',') {
3936  if (!__kmp_strcasecmp_with_sentinel("L1", ptr, ',')) {
3937  layer = kmp_hier_layer_e::LAYER_L1;
3938  } else if (!__kmp_strcasecmp_with_sentinel("L2", ptr, ',')) {
3939  layer = kmp_hier_layer_e::LAYER_L2;
3940  } else if (!__kmp_strcasecmp_with_sentinel("L3", ptr, ',')) {
3941  layer = kmp_hier_layer_e::LAYER_L3;
3942  } else if (!__kmp_strcasecmp_with_sentinel("NUMA", ptr, ',')) {
3943  layer = kmp_hier_layer_e::LAYER_NUMA;
3944  }
3945  }
3946  if (layer != kmp_hier_layer_e::LAYER_THREAD && *delim != ',') {
3947  // If there is no comma after the layer, then this schedule is invalid
3948  KMP_WARNING(StgInvalidValue, name, value);
3949  __kmp_omp_schedule_restore();
3950  return NULL;
3951  } else if (layer != kmp_hier_layer_e::LAYER_THREAD) {
3952  ptr = ++delim;
3953  while (*delim != ',' && *delim != ':' && *delim != '\0')
3954  delim++;
3955  }
3956  }
3957 #endif // KMP_USE_HIER_SCHED
3958  // Read in schedule modifier if specified
3959  enum sched_type sched_modifier = (enum sched_type)0;
3960  if (*delim == ':') {
3961  if (!__kmp_strcasecmp_with_sentinel("monotonic", ptr, *delim)) {
3962  sched_modifier = sched_type::kmp_sch_modifier_monotonic;
3963  ptr = ++delim;
3964  while (*delim != ',' && *delim != ':' && *delim != '\0')
3965  delim++;
3966  } else if (!__kmp_strcasecmp_with_sentinel("nonmonotonic", ptr, *delim)) {
3968  ptr = ++delim;
3969  while (*delim != ',' && *delim != ':' && *delim != '\0')
3970  delim++;
3971  } else if (!parse_hier) {
3972  // If there is no proper schedule modifier, then this schedule is invalid
3973  KMP_WARNING(StgInvalidValue, name, value);
3974  __kmp_omp_schedule_restore();
3975  return NULL;
3976  }
3977  }
3978  // Read in schedule kind (required)
3979  if (!__kmp_strcasecmp_with_sentinel("dynamic", ptr, *delim))
3980  sched = kmp_sch_dynamic_chunked;
3981  else if (!__kmp_strcasecmp_with_sentinel("guided", ptr, *delim))
3982  sched = kmp_sch_guided_chunked;
3983  // AC: TODO: probably remove TRAPEZOIDAL (OMP 3.0 does not allow it)
3984  else if (!__kmp_strcasecmp_with_sentinel("auto", ptr, *delim))
3985  sched = kmp_sch_auto;
3986  else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", ptr, *delim))
3987  sched = kmp_sch_trapezoidal;
3988  else if (!__kmp_strcasecmp_with_sentinel("static", ptr, *delim))
3989  sched = kmp_sch_static;
3990 #if KMP_STATIC_STEAL_ENABLED
3991  else if (!__kmp_strcasecmp_with_sentinel("static_steal", ptr, *delim)) {
3992  // replace static_steal with dynamic to better cope with ordered loops
3993  sched = kmp_sch_dynamic_chunked;
3995  }
3996 #endif
3997  else {
3998  // If there is no proper schedule kind, then this schedule is invalid
3999  KMP_WARNING(StgInvalidValue, name, value);
4000  __kmp_omp_schedule_restore();
4001  return NULL;
4002  }
4003 
4004  // Read in schedule chunk size if specified
4005  if (*delim == ',') {
4006  ptr = delim + 1;
4007  SKIP_WS(ptr);
4008  if (!isdigit(*ptr)) {
4009  // If there is no chunk after comma, then this schedule is invalid
4010  KMP_WARNING(StgInvalidValue, name, value);
4011  __kmp_omp_schedule_restore();
4012  return NULL;
4013  }
4014  SKIP_DIGITS(ptr);
4015  // auto schedule should not specify chunk size
4016  if (sched == kmp_sch_auto) {
4017  __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, delim),
4018  __kmp_msg_null);
4019  } else {
4020  if (sched == kmp_sch_static)
4021  sched = kmp_sch_static_chunked;
4022  chunk = __kmp_str_to_int(delim + 1, *ptr);
4023  if (chunk < 1) {
4024  chunk = KMP_DEFAULT_CHUNK;
4025  __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, delim),
4026  __kmp_msg_null);
4027  KMP_INFORM(Using_int_Value, name, __kmp_chunk);
4028  // AC: next block commented out until KMP_DEFAULT_CHUNK != KMP_MIN_CHUNK
4029  // (to improve code coverage :)
4030  // The default chunk size is 1 according to standard, thus making
4031  // KMP_MIN_CHUNK not 1 we would introduce mess:
4032  // wrong chunk becomes 1, but it will be impossible to explicitly set
4033  // to 1 because it becomes KMP_MIN_CHUNK...
4034  // } else if ( chunk < KMP_MIN_CHUNK ) {
4035  // chunk = KMP_MIN_CHUNK;
4036  } else if (chunk > KMP_MAX_CHUNK) {
4037  chunk = KMP_MAX_CHUNK;
4038  __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, delim),
4039  __kmp_msg_null);
4040  KMP_INFORM(Using_int_Value, name, chunk);
4041  }
4042  }
4043  } else {
4044  ptr = delim;
4045  }
4046 
4047  SCHEDULE_SET_MODIFIERS(sched, sched_modifier);
4048 
4049 #if KMP_USE_HIER_SCHED
4050  if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4051  __kmp_hier_scheds.append(sched, chunk, layer);
4052  } else
4053 #endif
4054  {
4055  __kmp_chunk = chunk;
4056  __kmp_sched = sched;
4057  }
4058  return ptr;
4059 }
4060 
4061 static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
4062  void *data) {
4063  size_t length;
4064  const char *ptr = value;
4065  SKIP_WS(ptr);
4066  if (value) {
4067  length = KMP_STRLEN(value);
4068  if (length) {
4069  if (value[length - 1] == '"' || value[length - 1] == '\'')
4070  KMP_WARNING(UnbalancedQuotes, name);
4071 /* get the specified scheduling style */
4072 #if KMP_USE_HIER_SCHED
4073  if (!__kmp_strcasecmp_with_sentinel("EXPERIMENTAL", ptr, ' ')) {
4074  SKIP_TOKEN(ptr);
4075  SKIP_WS(ptr);
4076  while ((ptr = __kmp_parse_single_omp_schedule(name, ptr, true))) {
4077  while (*ptr == ' ' || *ptr == '\t' || *ptr == ':')
4078  ptr++;
4079  if (*ptr == '\0')
4080  break;
4081  }
4082  } else
4083 #endif
4084  __kmp_parse_single_omp_schedule(name, ptr);
4085  } else
4086  KMP_WARNING(EmptyString, name);
4087  }
4088 #if KMP_USE_HIER_SCHED
4089  __kmp_hier_scheds.sort();
4090 #endif
4091  K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
4092  K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
4093  K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
4094  K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
4095 } // __kmp_stg_parse_omp_schedule
4096 
4097 static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
4098  char const *name, void *data) {
4099  if (__kmp_env_format) {
4100  KMP_STR_BUF_PRINT_NAME_EX(name);
4101  } else {
4102  __kmp_str_buf_print(buffer, " %s='", name);
4103  }
4104  enum sched_type sched = SCHEDULE_WITHOUT_MODIFIERS(__kmp_sched);
4105  if (SCHEDULE_HAS_MONOTONIC(__kmp_sched)) {
4106  __kmp_str_buf_print(buffer, "monotonic:");
4107  } else if (SCHEDULE_HAS_NONMONOTONIC(__kmp_sched)) {
4108  __kmp_str_buf_print(buffer, "nonmonotonic:");
4109  }
4110  if (__kmp_chunk) {
4111  switch (sched) {
4112  case kmp_sch_dynamic_chunked:
4113  __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
4114  break;
4115  case kmp_sch_guided_iterative_chunked:
4116  case kmp_sch_guided_analytical_chunked:
4117  __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
4118  break;
4119  case kmp_sch_trapezoidal:
4120  __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
4121  break;
4122  case kmp_sch_static:
4123  case kmp_sch_static_chunked:
4124  case kmp_sch_static_balanced:
4125  case kmp_sch_static_greedy:
4126  __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
4127  break;
4128  case kmp_sch_static_steal:
4129  __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
4130  break;
4131  case kmp_sch_auto:
4132  __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
4133  break;
4134  }
4135  } else {
4136  switch (sched) {
4137  case kmp_sch_dynamic_chunked:
4138  __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
4139  break;
4140  case kmp_sch_guided_iterative_chunked:
4141  case kmp_sch_guided_analytical_chunked:
4142  __kmp_str_buf_print(buffer, "%s'\n", "guided");
4143  break;
4144  case kmp_sch_trapezoidal:
4145  __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
4146  break;
4147  case kmp_sch_static:
4148  case kmp_sch_static_chunked:
4149  case kmp_sch_static_balanced:
4150  case kmp_sch_static_greedy:
4151  __kmp_str_buf_print(buffer, "%s'\n", "static");
4152  break;
4153  case kmp_sch_static_steal:
4154  __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
4155  break;
4156  case kmp_sch_auto:
4157  __kmp_str_buf_print(buffer, "%s'\n", "auto");
4158  break;
4159  }
4160  }
4161 } // __kmp_stg_print_omp_schedule
4162 
4163 #if KMP_USE_HIER_SCHED
4164 // -----------------------------------------------------------------------------
4165 // KMP_DISP_HAND_THREAD
4166 static void __kmp_stg_parse_kmp_hand_thread(char const *name, char const *value,
4167  void *data) {
4168  __kmp_stg_parse_bool(name, value, &(__kmp_dispatch_hand_threading));
4169 } // __kmp_stg_parse_kmp_hand_thread
4170 
4171 static void __kmp_stg_print_kmp_hand_thread(kmp_str_buf_t *buffer,
4172  char const *name, void *data) {
4173  __kmp_stg_print_bool(buffer, name, __kmp_dispatch_hand_threading);
4174 } // __kmp_stg_print_kmp_hand_thread
4175 #endif
4176 
4177 // -----------------------------------------------------------------------------
4178 // KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE
4179 static void __kmp_stg_parse_kmp_force_monotonic(char const *name,
4180  char const *value, void *data) {
4181  __kmp_stg_parse_bool(name, value, &(__kmp_force_monotonic));
4182 } // __kmp_stg_parse_kmp_force_monotonic
4183 
4184 static void __kmp_stg_print_kmp_force_monotonic(kmp_str_buf_t *buffer,
4185  char const *name, void *data) {
4186  __kmp_stg_print_bool(buffer, name, __kmp_force_monotonic);
4187 } // __kmp_stg_print_kmp_force_monotonic
4188 
4189 // -----------------------------------------------------------------------------
4190 // KMP_ATOMIC_MODE
4191 
4192 static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
4193  void *data) {
4194  // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
4195  // compatibility mode.
4196  int mode = 0;
4197  int max = 1;
4198 #ifdef KMP_GOMP_COMPAT
4199  max = 2;
4200 #endif /* KMP_GOMP_COMPAT */
4201  __kmp_stg_parse_int(name, value, 0, max, &mode);
4202  // TODO; parse_int is not very suitable for this case. In case of overflow it
4203  // is better to use
4204  // 0 rather that max value.
4205  if (mode > 0) {
4206  __kmp_atomic_mode = mode;
4207  }
4208 } // __kmp_stg_parse_atomic_mode
4209 
4210 static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
4211  void *data) {
4212  __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
4213 } // __kmp_stg_print_atomic_mode
4214 
4215 // -----------------------------------------------------------------------------
4216 // KMP_CONSISTENCY_CHECK
4217 
4218 static void __kmp_stg_parse_consistency_check(char const *name,
4219  char const *value, void *data) {
4220  if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
4221  // Note, this will not work from kmp_set_defaults because th_cons stack was
4222  // not allocated
4223  // for existed thread(s) thus the first __kmp_push_<construct> will break
4224  // with assertion.
4225  // TODO: allocate th_cons if called from kmp_set_defaults.
4226  __kmp_env_consistency_check = TRUE;
4227  } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
4228  __kmp_env_consistency_check = FALSE;
4229  } else {
4230  KMP_WARNING(StgInvalidValue, name, value);
4231  }
4232 } // __kmp_stg_parse_consistency_check
4233 
4234 static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
4235  char const *name, void *data) {
4236 #if KMP_DEBUG
4237  const char *value = NULL;
4238 
4239  if (__kmp_env_consistency_check) {
4240  value = "all";
4241  } else {
4242  value = "none";
4243  }
4244 
4245  if (value != NULL) {
4246  __kmp_stg_print_str(buffer, name, value);
4247  }
4248 #endif /* KMP_DEBUG */
4249 } // __kmp_stg_print_consistency_check
4250 
4251 #if USE_ITT_BUILD
4252 // -----------------------------------------------------------------------------
4253 // KMP_ITT_PREPARE_DELAY
4254 
4255 #if USE_ITT_NOTIFY
4256 
4257 static void __kmp_stg_parse_itt_prepare_delay(char const *name,
4258  char const *value, void *data) {
4259  // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
4260  // iterations.
4261  int delay = 0;
4262  __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
4263  __kmp_itt_prepare_delay = delay;
4264 } // __kmp_str_parse_itt_prepare_delay
4265 
4266 static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
4267  char const *name, void *data) {
4268  __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
4269 
4270 } // __kmp_str_print_itt_prepare_delay
4271 
4272 #endif // USE_ITT_NOTIFY
4273 #endif /* USE_ITT_BUILD */
4274 
4275 // -----------------------------------------------------------------------------
4276 // KMP_MALLOC_POOL_INCR
4277 
4278 static void __kmp_stg_parse_malloc_pool_incr(char const *name,
4279  char const *value, void *data) {
4280  __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
4281  KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
4282  1);
4283 } // __kmp_stg_parse_malloc_pool_incr
4284 
4285 static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
4286  char const *name, void *data) {
4287  __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
4288 
4289 } // _kmp_stg_print_malloc_pool_incr
4290 
4291 #ifdef KMP_DEBUG
4292 
4293 // -----------------------------------------------------------------------------
4294 // KMP_PAR_RANGE
4295 
4296 static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
4297  void *data) {
4298  __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
4299  __kmp_par_range_routine, __kmp_par_range_filename,
4300  &__kmp_par_range_lb, &__kmp_par_range_ub);
4301 } // __kmp_stg_parse_par_range_env
4302 
4303 static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
4304  char const *name, void *data) {
4305  if (__kmp_par_range != 0) {
4306  __kmp_stg_print_str(buffer, name, par_range_to_print);
4307  }
4308 } // __kmp_stg_print_par_range_env
4309 
4310 #endif
4311 
4312 // -----------------------------------------------------------------------------
4313 // KMP_GTID_MODE
4314 
4315 static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
4316  void *data) {
4317  // Modes:
4318  // 0 -- do not change default
4319  // 1 -- sp search
4320  // 2 -- use "keyed" TLS var, i.e.
4321  // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
4322  // 3 -- __declspec(thread) TLS var in tdata section
4323  int mode = 0;
4324  int max = 2;
4325 #ifdef KMP_TDATA_GTID
4326  max = 3;
4327 #endif /* KMP_TDATA_GTID */
4328  __kmp_stg_parse_int(name, value, 0, max, &mode);
4329  // TODO; parse_int is not very suitable for this case. In case of overflow it
4330  // is better to use 0 rather that max value.
4331  if (mode == 0) {
4332  __kmp_adjust_gtid_mode = TRUE;
4333  } else {
4334  __kmp_gtid_mode = mode;
4335  __kmp_adjust_gtid_mode = FALSE;
4336  }
4337 } // __kmp_str_parse_gtid_mode
4338 
4339 static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
4340  void *data) {
4341  if (__kmp_adjust_gtid_mode) {
4342  __kmp_stg_print_int(buffer, name, 0);
4343  } else {
4344  __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
4345  }
4346 } // __kmp_stg_print_gtid_mode
4347 
4348 // -----------------------------------------------------------------------------
4349 // KMP_NUM_LOCKS_IN_BLOCK
4350 
4351 static void __kmp_stg_parse_lock_block(char const *name, char const *value,
4352  void *data) {
4353  __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
4354 } // __kmp_str_parse_lock_block
4355 
4356 static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
4357  void *data) {
4358  __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
4359 } // __kmp_stg_print_lock_block
4360 
4361 // -----------------------------------------------------------------------------
4362 // KMP_LOCK_KIND
4363 
4364 #if KMP_USE_DYNAMIC_LOCK
4365 #define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
4366 #else
4367 #define KMP_STORE_LOCK_SEQ(a)
4368 #endif
4369 
4370 static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
4371  void *data) {
4372  if (__kmp_init_user_locks) {
4373  KMP_WARNING(EnvLockWarn, name);
4374  return;
4375  }
4376 
4377  if (__kmp_str_match("tas", 2, value) ||
4378  __kmp_str_match("test and set", 2, value) ||
4379  __kmp_str_match("test_and_set", 2, value) ||
4380  __kmp_str_match("test-and-set", 2, value) ||
4381  __kmp_str_match("test andset", 2, value) ||
4382  __kmp_str_match("test_andset", 2, value) ||
4383  __kmp_str_match("test-andset", 2, value) ||
4384  __kmp_str_match("testand set", 2, value) ||
4385  __kmp_str_match("testand_set", 2, value) ||
4386  __kmp_str_match("testand-set", 2, value) ||
4387  __kmp_str_match("testandset", 2, value)) {
4388  __kmp_user_lock_kind = lk_tas;
4389  KMP_STORE_LOCK_SEQ(tas);
4390  }
4391 #if KMP_USE_FUTEX
4392  else if (__kmp_str_match("futex", 1, value)) {
4393  if (__kmp_futex_determine_capable()) {
4394  __kmp_user_lock_kind = lk_futex;
4395  KMP_STORE_LOCK_SEQ(futex);
4396  } else {
4397  KMP_WARNING(FutexNotSupported, name, value);
4398  }
4399  }
4400 #endif
4401  else if (__kmp_str_match("ticket", 2, value)) {
4402  __kmp_user_lock_kind = lk_ticket;
4403  KMP_STORE_LOCK_SEQ(ticket);
4404  } else if (__kmp_str_match("queuing", 1, value) ||
4405  __kmp_str_match("queue", 1, value)) {
4406  __kmp_user_lock_kind = lk_queuing;
4407  KMP_STORE_LOCK_SEQ(queuing);
4408  } else if (__kmp_str_match("drdpa ticket", 1, value) ||
4409  __kmp_str_match("drdpa_ticket", 1, value) ||
4410  __kmp_str_match("drdpa-ticket", 1, value) ||
4411  __kmp_str_match("drdpaticket", 1, value) ||
4412  __kmp_str_match("drdpa", 1, value)) {
4413  __kmp_user_lock_kind = lk_drdpa;
4414  KMP_STORE_LOCK_SEQ(drdpa);
4415  }
4416 #if KMP_USE_ADAPTIVE_LOCKS
4417  else if (__kmp_str_match("adaptive", 1, value)) {
4418  if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
4419  __kmp_user_lock_kind = lk_adaptive;
4420  KMP_STORE_LOCK_SEQ(adaptive);
4421  } else {
4422  KMP_WARNING(AdaptiveNotSupported, name, value);
4423  __kmp_user_lock_kind = lk_queuing;
4424  KMP_STORE_LOCK_SEQ(queuing);
4425  }
4426  }
4427 #endif // KMP_USE_ADAPTIVE_LOCKS
4428 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4429  else if (__kmp_str_match("rtm_queuing", 1, value)) {
4430  if (__kmp_cpuinfo.rtm) {
4431  __kmp_user_lock_kind = lk_rtm_queuing;
4432  KMP_STORE_LOCK_SEQ(rtm_queuing);
4433  } else {
4434  KMP_WARNING(AdaptiveNotSupported, name, value);
4435  __kmp_user_lock_kind = lk_queuing;
4436  KMP_STORE_LOCK_SEQ(queuing);
4437  }
4438  } else if (__kmp_str_match("rtm_spin", 1, value)) {
4439  if (__kmp_cpuinfo.rtm) {
4440  __kmp_user_lock_kind = lk_rtm_spin;
4441  KMP_STORE_LOCK_SEQ(rtm_spin);
4442  } else {
4443  KMP_WARNING(AdaptiveNotSupported, name, value);
4444  __kmp_user_lock_kind = lk_tas;
4445  KMP_STORE_LOCK_SEQ(queuing);
4446  }
4447  } else if (__kmp_str_match("hle", 1, value)) {
4448  __kmp_user_lock_kind = lk_hle;
4449  KMP_STORE_LOCK_SEQ(hle);
4450  }
4451 #endif
4452  else {
4453  KMP_WARNING(StgInvalidValue, name, value);
4454  }
4455 }
4456 
4457 static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
4458  void *data) {
4459  const char *value = NULL;
4460 
4461  switch (__kmp_user_lock_kind) {
4462  case lk_default:
4463  value = "default";
4464  break;
4465 
4466  case lk_tas:
4467  value = "tas";
4468  break;
4469 
4470 #if KMP_USE_FUTEX
4471  case lk_futex:
4472  value = "futex";
4473  break;
4474 #endif
4475 
4476 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4477  case lk_rtm_queuing:
4478  value = "rtm_queuing";
4479  break;
4480 
4481  case lk_rtm_spin:
4482  value = "rtm_spin";
4483  break;
4484 
4485  case lk_hle:
4486  value = "hle";
4487  break;
4488 #endif
4489 
4490  case lk_ticket:
4491  value = "ticket";
4492  break;
4493 
4494  case lk_queuing:
4495  value = "queuing";
4496  break;
4497 
4498  case lk_drdpa:
4499  value = "drdpa";
4500  break;
4501 #if KMP_USE_ADAPTIVE_LOCKS
4502  case lk_adaptive:
4503  value = "adaptive";
4504  break;
4505 #endif
4506  }
4507 
4508  if (value != NULL) {
4509  __kmp_stg_print_str(buffer, name, value);
4510  }
4511 }
4512 
4513 // -----------------------------------------------------------------------------
4514 // KMP_SPIN_BACKOFF_PARAMS
4515 
4516 // KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
4517 // for machine pause)
4518 static void __kmp_stg_parse_spin_backoff_params(const char *name,
4519  const char *value, void *data) {
4520  const char *next = value;
4521 
4522  int total = 0; // Count elements that were set. It'll be used as an array size
4523  int prev_comma = FALSE; // For correct processing sequential commas
4524  int i;
4525 
4526  kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
4527  kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
4528 
4529  // Run only 3 iterations because it is enough to read two values or find a
4530  // syntax error
4531  for (i = 0; i < 3; i++) {
4532  SKIP_WS(next);
4533 
4534  if (*next == '\0') {
4535  break;
4536  }
4537  // Next character is not an integer or not a comma OR number of values > 2
4538  // => end of list
4539  if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
4540  KMP_WARNING(EnvSyntaxError, name, value);
4541  return;
4542  }
4543  // The next character is ','
4544  if (*next == ',') {
4545  // ',' is the first character
4546  if (total == 0 || prev_comma) {
4547  total++;
4548  }
4549  prev_comma = TRUE;
4550  next++; // skip ','
4551  SKIP_WS(next);
4552  }
4553  // Next character is a digit
4554  if (*next >= '0' && *next <= '9') {
4555  int num;
4556  const char *buf = next;
4557  char const *msg = NULL;
4558  prev_comma = FALSE;
4559  SKIP_DIGITS(next);
4560  total++;
4561 
4562  const char *tmp = next;
4563  SKIP_WS(tmp);
4564  if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4565  KMP_WARNING(EnvSpacesNotAllowed, name, value);
4566  return;
4567  }
4568 
4569  num = __kmp_str_to_int(buf, *next);
4570  if (num <= 0) { // The number of retries should be > 0
4571  msg = KMP_I18N_STR(ValueTooSmall);
4572  num = 1;
4573  } else if (num > KMP_INT_MAX) {
4574  msg = KMP_I18N_STR(ValueTooLarge);
4575  num = KMP_INT_MAX;
4576  }
4577  if (msg != NULL) {
4578  // Message is not empty. Print warning.
4579  KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4580  KMP_INFORM(Using_int_Value, name, num);
4581  }
4582  if (total == 1) {
4583  max_backoff = num;
4584  } else if (total == 2) {
4585  min_tick = num;
4586  }
4587  }
4588  }
4589  KMP_DEBUG_ASSERT(total > 0);
4590  if (total <= 0) {
4591  KMP_WARNING(EnvSyntaxError, name, value);
4592  return;
4593  }
4594  __kmp_spin_backoff_params.max_backoff = max_backoff;
4595  __kmp_spin_backoff_params.min_tick = min_tick;
4596 }
4597 
4598 static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
4599  char const *name, void *data) {
4600  if (__kmp_env_format) {
4601  KMP_STR_BUF_PRINT_NAME_EX(name);
4602  } else {
4603  __kmp_str_buf_print(buffer, " %s='", name);
4604  }
4605  __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
4606  __kmp_spin_backoff_params.min_tick);
4607 }
4608 
4609 #if KMP_USE_ADAPTIVE_LOCKS
4610 
4611 // -----------------------------------------------------------------------------
4612 // KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
4613 
4614 // Parse out values for the tunable parameters from a string of the form
4615 // KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
4616 static void __kmp_stg_parse_adaptive_lock_props(const char *name,
4617  const char *value, void *data) {
4618  int max_retries = 0;
4619  int max_badness = 0;
4620 
4621  const char *next = value;
4622 
4623  int total = 0; // Count elements that were set. It'll be used as an array size
4624  int prev_comma = FALSE; // For correct processing sequential commas
4625  int i;
4626 
4627  // Save values in the structure __kmp_speculative_backoff_params
4628  // Run only 3 iterations because it is enough to read two values or find a
4629  // syntax error
4630  for (i = 0; i < 3; i++) {
4631  SKIP_WS(next);
4632 
4633  if (*next == '\0') {
4634  break;
4635  }
4636  // Next character is not an integer or not a comma OR number of values > 2
4637  // => end of list
4638  if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
4639  KMP_WARNING(EnvSyntaxError, name, value);
4640  return;
4641  }
4642  // The next character is ','
4643  if (*next == ',') {
4644  // ',' is the first character
4645  if (total == 0 || prev_comma) {
4646  total++;
4647  }
4648  prev_comma = TRUE;
4649  next++; // skip ','
4650  SKIP_WS(next);
4651  }
4652  // Next character is a digit
4653  if (*next >= '0' && *next <= '9') {
4654  int num;
4655  const char *buf = next;
4656  char const *msg = NULL;
4657  prev_comma = FALSE;
4658  SKIP_DIGITS(next);
4659  total++;
4660 
4661  const char *tmp = next;
4662  SKIP_WS(tmp);
4663  if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4664  KMP_WARNING(EnvSpacesNotAllowed, name, value);
4665  return;
4666  }
4667 
4668  num = __kmp_str_to_int(buf, *next);
4669  if (num < 0) { // The number of retries should be >= 0
4670  msg = KMP_I18N_STR(ValueTooSmall);
4671  num = 1;
4672  } else if (num > KMP_INT_MAX) {
4673  msg = KMP_I18N_STR(ValueTooLarge);
4674  num = KMP_INT_MAX;
4675  }
4676  if (msg != NULL) {
4677  // Message is not empty. Print warning.
4678  KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4679  KMP_INFORM(Using_int_Value, name, num);
4680  }
4681  if (total == 1) {
4682  max_retries = num;
4683  } else if (total == 2) {
4684  max_badness = num;
4685  }
4686  }
4687  }
4688  KMP_DEBUG_ASSERT(total > 0);
4689  if (total <= 0) {
4690  KMP_WARNING(EnvSyntaxError, name, value);
4691  return;
4692  }
4693  __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4694  __kmp_adaptive_backoff_params.max_badness = max_badness;
4695 }
4696 
4697 static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4698  char const *name, void *data) {
4699  if (__kmp_env_format) {
4700  KMP_STR_BUF_PRINT_NAME_EX(name);
4701  } else {
4702  __kmp_str_buf_print(buffer, " %s='", name);
4703  }
4704  __kmp_str_buf_print(buffer, "%d,%d'\n",
4705  __kmp_adaptive_backoff_params.max_soft_retries,
4706  __kmp_adaptive_backoff_params.max_badness);
4707 } // __kmp_stg_print_adaptive_lock_props
4708 
4709 #if KMP_DEBUG_ADAPTIVE_LOCKS
4710 
4711 static void __kmp_stg_parse_speculative_statsfile(char const *name,
4712  char const *value,
4713  void *data) {
4714  __kmp_stg_parse_file(name, value, "",
4715  CCAST(char **, &__kmp_speculative_statsfile));
4716 } // __kmp_stg_parse_speculative_statsfile
4717 
4718 static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
4719  char const *name,
4720  void *data) {
4721  if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
4722  __kmp_stg_print_str(buffer, name, "stdout");
4723  } else {
4724  __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
4725  }
4726 
4727 } // __kmp_stg_print_speculative_statsfile
4728 
4729 #endif // KMP_DEBUG_ADAPTIVE_LOCKS
4730 
4731 #endif // KMP_USE_ADAPTIVE_LOCKS
4732 
4733 // -----------------------------------------------------------------------------
4734 // KMP_HW_SUBSET (was KMP_PLACE_THREADS)
4735 // 2s16c,2t => 2S16C,2T => 2S16C \0 2T
4736 
4737 // Return KMP_HW_SUBSET preferred hardware type in case a token is ambiguously
4738 // short. The original KMP_HW_SUBSET environment variable had single letters:
4739 // s, c, t for sockets, cores, threads repsectively.
4740 static kmp_hw_t __kmp_hw_subset_break_tie(const kmp_hw_t *possible,
4741  size_t num_possible) {
4742  for (size_t i = 0; i < num_possible; ++i) {
4743  if (possible[i] == KMP_HW_THREAD)
4744  return KMP_HW_THREAD;
4745  else if (possible[i] == KMP_HW_CORE)
4746  return KMP_HW_CORE;
4747  else if (possible[i] == KMP_HW_SOCKET)
4748  return KMP_HW_SOCKET;
4749  }
4750  return KMP_HW_UNKNOWN;
4751 }
4752 
4753 // Return hardware type from string or HW_UNKNOWN if string cannot be parsed
4754 // This algorithm is very forgiving to the user in that, the instant it can
4755 // reduce the search space to one, it assumes that is the topology level the
4756 // user wanted, even if it is misspelled later in the token.
4757 static kmp_hw_t __kmp_stg_parse_hw_subset_name(char const *token) {
4758  size_t index, num_possible, token_length;
4759  kmp_hw_t possible[KMP_HW_LAST];
4760  const char *end;
4761 
4762  // Find the end of the hardware token string
4763  end = token;
4764  token_length = 0;
4765  while (isalnum(*end) || *end == '_') {
4766  token_length++;
4767  end++;
4768  }
4769 
4770  // Set the possibilities to all hardware types
4771  num_possible = 0;
4772  KMP_FOREACH_HW_TYPE(type) { possible[num_possible++] = type; }
4773 
4774  // Eliminate hardware types by comparing the front of the token
4775  // with hardware names
4776  // In most cases, the first letter in the token will indicate exactly
4777  // which hardware type is parsed, e.g., 'C' = Core
4778  index = 0;
4779  while (num_possible > 1 && index < token_length) {
4780  size_t n = num_possible;
4781  char token_char = (char)toupper(token[index]);
4782  for (size_t i = 0; i < n; ++i) {
4783  const char *s;
4784  kmp_hw_t type = possible[i];
4785  s = __kmp_hw_get_keyword(type, false);
4786  if (index < KMP_STRLEN(s)) {
4787  char c = (char)toupper(s[index]);
4788  // Mark hardware types for removal when the characters do not match
4789  if (c != token_char) {
4790  possible[i] = KMP_HW_UNKNOWN;
4791  num_possible--;
4792  }
4793  }
4794  }
4795  // Remove hardware types that this token cannot be
4796  size_t start = 0;
4797  for (size_t i = 0; i < n; ++i) {
4798  if (possible[i] != KMP_HW_UNKNOWN) {
4799  kmp_hw_t temp = possible[i];
4800  possible[i] = possible[start];
4801  possible[start] = temp;
4802  start++;
4803  }
4804  }
4805  KMP_ASSERT(start == num_possible);
4806  index++;
4807  }
4808 
4809  // Attempt to break a tie if user has very short token
4810  // (e.g., is 'T' tile or thread?)
4811  if (num_possible > 1)
4812  return __kmp_hw_subset_break_tie(possible, num_possible);
4813  if (num_possible == 1)
4814  return possible[0];
4815  return KMP_HW_UNKNOWN;
4816 }
4817 
4818 // The longest observable sequence of items can only be HW_LAST length
4819 // The input string is usually short enough, let's use 512 limit for now
4820 #define MAX_T_LEVEL KMP_HW_LAST
4821 #define MAX_STR_LEN 512
4822 static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
4823  void *data) {
4824  // Value example: 1s,5c@3,2T
4825  // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
4826  kmp_setting_t **rivals = (kmp_setting_t **)data;
4827  if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
4828  KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
4829  }
4830  if (__kmp_stg_check_rivals(name, value, rivals)) {
4831  return;
4832  }
4833 
4834  char *components[MAX_T_LEVEL];
4835  char const *digits = "0123456789";
4836  char input[MAX_STR_LEN];
4837  size_t len = 0, mlen = MAX_STR_LEN;
4838  int level = 0;
4839  bool absolute = false;
4840  // Canonicalize the string (remove spaces, unify delimiters, etc.)
4841  char *pos = CCAST(char *, value);
4842  while (*pos && mlen) {
4843  if (*pos != ' ') { // skip spaces
4844  if (len == 0 && *pos == ':') {
4845  absolute = true;
4846  } else {
4847  input[len] = (char)(toupper(*pos));
4848  if (input[len] == 'X')
4849  input[len] = ','; // unify delimiters of levels
4850  if (input[len] == 'O' && strchr(digits, *(pos + 1)))
4851  input[len] = '@'; // unify delimiters of offset
4852  len++;
4853  }
4854  }
4855  mlen--;
4856  pos++;
4857  }
4858  if (len == 0 || mlen == 0) {
4859  goto err; // contents is either empty or too long
4860  }
4861  input[len] = '\0';
4862  // Split by delimiter
4863  pos = input;
4864  components[level++] = pos;
4865  while ((pos = strchr(pos, ','))) {
4866  if (level >= MAX_T_LEVEL)
4867  goto err; // too many components provided
4868  *pos = '\0'; // modify input and avoid more copying
4869  components[level++] = ++pos; // expect something after ","
4870  }
4871 
4872  __kmp_hw_subset = kmp_hw_subset_t::allocate();
4873  if (absolute)
4874  __kmp_hw_subset->set_absolute();
4875 
4876  // Check each component
4877  for (int i = 0; i < level; ++i) {
4878  int offset = 0;
4879  int num = atoi(components[i]); // each component should start with a number
4880  if (num <= 0) {
4881  goto err; // only positive integers are valid for count
4882  }
4883  if ((pos = strchr(components[i], '@'))) {
4884  offset = atoi(pos + 1); // save offset
4885  *pos = '\0'; // cut the offset from the component
4886  }
4887  pos = components[i] + strspn(components[i], digits);
4888  if (pos == components[i]) {
4889  goto err;
4890  }
4891  // detect the component type
4892  kmp_hw_t type = __kmp_stg_parse_hw_subset_name(pos);
4893  if (type == KMP_HW_UNKNOWN) {
4894  goto err;
4895  }
4896  if (__kmp_hw_subset->specified(type)) {
4897  goto err;
4898  }
4899  __kmp_hw_subset->push_back(num, type, offset);
4900  }
4901  return;
4902 err:
4903  KMP_WARNING(AffHWSubsetInvalid, name, value);
4904  if (__kmp_hw_subset) {
4905  kmp_hw_subset_t::deallocate(__kmp_hw_subset);
4906  __kmp_hw_subset = nullptr;
4907  }
4908  return;
4909 }
4910 
4911 static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
4912  void *data) {
4913  kmp_str_buf_t buf;
4914  int depth;
4915  if (!__kmp_hw_subset)
4916  return;
4917  __kmp_str_buf_init(&buf);
4918  if (__kmp_env_format)
4919  KMP_STR_BUF_PRINT_NAME_EX(name);
4920  else
4921  __kmp_str_buf_print(buffer, " %s='", name);
4922 
4923  depth = __kmp_hw_subset->get_depth();
4924  for (int i = 0; i < depth; ++i) {
4925  const auto &item = __kmp_hw_subset->at(i);
4926  __kmp_str_buf_print(&buf, "%s%d%s", (i > 0 ? "," : ""), item.num,
4927  __kmp_hw_get_keyword(item.type));
4928  if (item.offset)
4929  __kmp_str_buf_print(&buf, "@%d", item.offset);
4930  }
4931  __kmp_str_buf_print(buffer, "%s'\n", buf.str);
4932  __kmp_str_buf_free(&buf);
4933 }
4934 
4935 #if USE_ITT_BUILD
4936 // -----------------------------------------------------------------------------
4937 // KMP_FORKJOIN_FRAMES
4938 
4939 static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
4940  void *data) {
4941  __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
4942 } // __kmp_stg_parse_forkjoin_frames
4943 
4944 static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
4945  char const *name, void *data) {
4946  __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
4947 } // __kmp_stg_print_forkjoin_frames
4948 
4949 // -----------------------------------------------------------------------------
4950 // KMP_FORKJOIN_FRAMES_MODE
4951 
4952 static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
4953  char const *value,
4954  void *data) {
4955  __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
4956 } // __kmp_stg_parse_forkjoin_frames
4957 
4958 static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
4959  char const *name, void *data) {
4960  __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
4961 } // __kmp_stg_print_forkjoin_frames
4962 #endif /* USE_ITT_BUILD */
4963 
4964 // -----------------------------------------------------------------------------
4965 // KMP_ENABLE_TASK_THROTTLING
4966 
4967 static void __kmp_stg_parse_task_throttling(char const *name, char const *value,
4968  void *data) {
4969  __kmp_stg_parse_bool(name, value, &__kmp_enable_task_throttling);
4970 } // __kmp_stg_parse_task_throttling
4971 
4972 static void __kmp_stg_print_task_throttling(kmp_str_buf_t *buffer,
4973  char const *name, void *data) {
4974  __kmp_stg_print_bool(buffer, name, __kmp_enable_task_throttling);
4975 } // __kmp_stg_print_task_throttling
4976 
4977 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
4978 // -----------------------------------------------------------------------------
4979 // KMP_USER_LEVEL_MWAIT
4980 
4981 static void __kmp_stg_parse_user_level_mwait(char const *name,
4982  char const *value, void *data) {
4983  __kmp_stg_parse_bool(name, value, &__kmp_user_level_mwait);
4984 } // __kmp_stg_parse_user_level_mwait
4985 
4986 static void __kmp_stg_print_user_level_mwait(kmp_str_buf_t *buffer,
4987  char const *name, void *data) {
4988  __kmp_stg_print_bool(buffer, name, __kmp_user_level_mwait);
4989 } // __kmp_stg_print_user_level_mwait
4990 
4991 // -----------------------------------------------------------------------------
4992 // KMP_MWAIT_HINTS
4993 
4994 static void __kmp_stg_parse_mwait_hints(char const *name, char const *value,
4995  void *data) {
4996  __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_mwait_hints);
4997 } // __kmp_stg_parse_mwait_hints
4998 
4999 static void __kmp_stg_print_mwait_hints(kmp_str_buf_t *buffer, char const *name,
5000  void *data) {
5001  __kmp_stg_print_int(buffer, name, __kmp_mwait_hints);
5002 } // __kmp_stg_print_mwait_hints
5003 
5004 #endif // KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5005 
5006 // -----------------------------------------------------------------------------
5007 // OMP_DISPLAY_ENV
5008 
5009 static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
5010  void *data) {
5011  if (__kmp_str_match("VERBOSE", 1, value)) {
5012  __kmp_display_env_verbose = TRUE;
5013  } else {
5014  __kmp_stg_parse_bool(name, value, &__kmp_display_env);
5015  }
5016 } // __kmp_stg_parse_omp_display_env
5017 
5018 static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
5019  char const *name, void *data) {
5020  if (__kmp_display_env_verbose) {
5021  __kmp_stg_print_str(buffer, name, "VERBOSE");
5022  } else {
5023  __kmp_stg_print_bool(buffer, name, __kmp_display_env);
5024  }
5025 } // __kmp_stg_print_omp_display_env
5026 
5027 static void __kmp_stg_parse_omp_cancellation(char const *name,
5028  char const *value, void *data) {
5029  if (TCR_4(__kmp_init_parallel)) {
5030  KMP_WARNING(EnvParallelWarn, name);
5031  return;
5032  } // read value before first parallel only
5033  __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
5034 } // __kmp_stg_parse_omp_cancellation
5035 
5036 static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
5037  char const *name, void *data) {
5038  __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
5039 } // __kmp_stg_print_omp_cancellation
5040 
5041 #if OMPT_SUPPORT
5042 int __kmp_tool = 1;
5043 
5044 static void __kmp_stg_parse_omp_tool(char const *name, char const *value,
5045  void *data) {
5046  __kmp_stg_parse_bool(name, value, &__kmp_tool);
5047 } // __kmp_stg_parse_omp_tool
5048 
5049 static void __kmp_stg_print_omp_tool(kmp_str_buf_t *buffer, char const *name,
5050  void *data) {
5051  if (__kmp_env_format) {
5052  KMP_STR_BUF_PRINT_BOOL_EX(name, __kmp_tool, "enabled", "disabled");
5053  } else {
5054  __kmp_str_buf_print(buffer, " %s=%s\n", name,
5055  __kmp_tool ? "enabled" : "disabled");
5056  }
5057 } // __kmp_stg_print_omp_tool
5058 
5059 char *__kmp_tool_libraries = NULL;
5060 
5061 static void __kmp_stg_parse_omp_tool_libraries(char const *name,
5062  char const *value, void *data) {
5063  __kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
5064 } // __kmp_stg_parse_omp_tool_libraries
5065 
5066 static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer,
5067  char const *name, void *data) {
5068  if (__kmp_tool_libraries)
5069  __kmp_stg_print_str(buffer, name, __kmp_tool_libraries);
5070  else {
5071  if (__kmp_env_format) {
5072  KMP_STR_BUF_PRINT_NAME;
5073  } else {
5074  __kmp_str_buf_print(buffer, " %s", name);
5075  }
5076  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
5077  }
5078 } // __kmp_stg_print_omp_tool_libraries
5079 
5080 char *__kmp_tool_verbose_init = NULL;
5081 
5082 static void __kmp_stg_parse_omp_tool_verbose_init(char const *name,
5083  char const *value,
5084  void *data) {
5085  __kmp_stg_parse_str(name, value, &__kmp_tool_verbose_init);
5086 } // __kmp_stg_parse_omp_tool_libraries
5087 
5088 static void __kmp_stg_print_omp_tool_verbose_init(kmp_str_buf_t *buffer,
5089  char const *name,
5090  void *data) {
5091  if (__kmp_tool_verbose_init)
5092  __kmp_stg_print_str(buffer, name, __kmp_tool_verbose_init);
5093  else {
5094  if (__kmp_env_format) {
5095  KMP_STR_BUF_PRINT_NAME;
5096  } else {
5097  __kmp_str_buf_print(buffer, " %s", name);
5098  }
5099  __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
5100  }
5101 } // __kmp_stg_print_omp_tool_verbose_init
5102 
5103 #endif
5104 
5105 // Table.
5106 
5107 static kmp_setting_t __kmp_stg_table[] = {
5108 
5109  {"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
5110  {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
5111  NULL, 0, 0},
5112  {"KMP_USE_YIELD", __kmp_stg_parse_use_yield, __kmp_stg_print_use_yield,
5113  NULL, 0, 0},
5114  {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
5115  __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
5116  {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
5117  NULL, 0, 0},
5118  {"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
5119  __kmp_stg_print_device_thread_limit, NULL, 0, 0},
5120 #if KMP_USE_MONITOR
5121  {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
5122  __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
5123 #endif
5124  {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
5125  0, 0},
5126  {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
5127  __kmp_stg_print_stackoffset, NULL, 0, 0},
5128  {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5129  NULL, 0, 0},
5130  {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
5131  0, 0},
5132  {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
5133  0},
5134  {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
5135  0, 0},
5136 
5137  {"KMP_NESTING_MODE", __kmp_stg_parse_nesting_mode,
5138  __kmp_stg_print_nesting_mode, NULL, 0, 0},
5139  {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
5140  {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
5141  __kmp_stg_print_num_threads, NULL, 0, 0},
5142  {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5143  NULL, 0, 0},
5144 
5145  {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
5146  0},
5147  {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
5148  __kmp_stg_print_task_stealing, NULL, 0, 0},
5149  {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
5150  __kmp_stg_print_max_active_levels, NULL, 0, 0},
5151  {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
5152  __kmp_stg_print_default_device, NULL, 0, 0},
5153  {"OMP_TARGET_OFFLOAD", __kmp_stg_parse_target_offload,
5154  __kmp_stg_print_target_offload, NULL, 0, 0},
5155  {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
5156  __kmp_stg_print_max_task_priority, NULL, 0, 0},
5157  {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
5158  __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
5159  {"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
5160  __kmp_stg_print_thread_limit, NULL, 0, 0},
5161  {"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
5162  __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
5163  {"OMP_NUM_TEAMS", __kmp_stg_parse_nteams, __kmp_stg_print_nteams, NULL, 0,
5164  0},
5165  {"OMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_th_limit,
5166  __kmp_stg_print_teams_th_limit, NULL, 0, 0},
5167  {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
5168  __kmp_stg_print_wait_policy, NULL, 0, 0},
5169  {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
5170  __kmp_stg_print_disp_buffers, NULL, 0, 0},
5171 #if KMP_NESTED_HOT_TEAMS
5172  {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
5173  __kmp_stg_print_hot_teams_level, NULL, 0, 0},
5174  {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
5175  __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
5176 #endif // KMP_NESTED_HOT_TEAMS
5177 
5178 #if KMP_HANDLE_SIGNALS
5179  {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
5180  __kmp_stg_print_handle_signals, NULL, 0, 0},
5181 #endif
5182 
5183 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
5184  {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
5185  __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
5186 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
5187 
5188 #ifdef KMP_GOMP_COMPAT
5189  {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
5190 #endif
5191 
5192 #ifdef KMP_DEBUG
5193  {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
5194  0},
5195  {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
5196  0},
5197  {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
5198  0},
5199  {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
5200  0},
5201  {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
5202  0},
5203  {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
5204  0},
5205  {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
5206  {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
5207  NULL, 0, 0},
5208  {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
5209  __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
5210  {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
5211  __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
5212  {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
5213  __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
5214  {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
5215 
5216  {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
5217  __kmp_stg_print_par_range_env, NULL, 0, 0},
5218 #endif // KMP_DEBUG
5219 
5220  {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
5221  __kmp_stg_print_align_alloc, NULL, 0, 0},
5222 
5223  {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5224  __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5225  {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5226  __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5227  {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5228  __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5229  {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5230  __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5231 #if KMP_FAST_REDUCTION_BARRIER
5232  {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5233  __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5234  {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5235  __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5236 #endif
5237 
5238  {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
5239  __kmp_stg_print_abort_delay, NULL, 0, 0},
5240  {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
5241  __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
5242  {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
5243  __kmp_stg_print_force_reduction, NULL, 0, 0},
5244  {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
5245  __kmp_stg_print_force_reduction, NULL, 0, 0},
5246  {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
5247  __kmp_stg_print_storage_map, NULL, 0, 0},
5248  {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
5249  __kmp_stg_print_all_threadprivate, NULL, 0, 0},
5250  {"KMP_FOREIGN_THREADS_THREADPRIVATE",
5251  __kmp_stg_parse_foreign_threads_threadprivate,
5252  __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
5253 
5254 #if KMP_AFFINITY_SUPPORTED
5255  {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
5256  0, 0},
5257 #ifdef KMP_GOMP_COMPAT
5258  {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
5259  /* no print */ NULL, 0, 0},
5260 #endif /* KMP_GOMP_COMPAT */
5261  {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5262  NULL, 0, 0},
5263  {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
5264  {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
5265  __kmp_stg_print_topology_method, NULL, 0, 0},
5266 
5267 #else
5268 
5269  // KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
5270  // OMP_PROC_BIND and proc-bind-var are supported, however.
5271  {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5272  NULL, 0, 0},
5273 
5274 #endif // KMP_AFFINITY_SUPPORTED
5275  {"OMP_DISPLAY_AFFINITY", __kmp_stg_parse_display_affinity,
5276  __kmp_stg_print_display_affinity, NULL, 0, 0},
5277  {"OMP_AFFINITY_FORMAT", __kmp_stg_parse_affinity_format,
5278  __kmp_stg_print_affinity_format, NULL, 0, 0},
5279  {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
5280  __kmp_stg_print_init_at_fork, NULL, 0, 0},
5281  {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
5282  0, 0},
5283  {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
5284  NULL, 0, 0},
5285 #if KMP_USE_HIER_SCHED
5286  {"KMP_DISP_HAND_THREAD", __kmp_stg_parse_kmp_hand_thread,
5287  __kmp_stg_print_kmp_hand_thread, NULL, 0, 0},
5288 #endif
5289  {"KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE",
5290  __kmp_stg_parse_kmp_force_monotonic, __kmp_stg_print_kmp_force_monotonic,
5291  NULL, 0, 0},
5292  {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
5293  __kmp_stg_print_atomic_mode, NULL, 0, 0},
5294  {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
5295  __kmp_stg_print_consistency_check, NULL, 0, 0},
5296 
5297 #if USE_ITT_BUILD && USE_ITT_NOTIFY
5298  {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
5299  __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
5300 #endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
5301  {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
5302  __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
5303  {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
5304  NULL, 0, 0},
5305  {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
5306  NULL, 0, 0},
5307  {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
5308  __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
5309 
5310 #ifdef USE_LOAD_BALANCE
5311  {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
5312  __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
5313 #endif
5314 
5315  {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
5316  __kmp_stg_print_lock_block, NULL, 0, 0},
5317  {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
5318  NULL, 0, 0},
5319  {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
5320  __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
5321 #if KMP_USE_ADAPTIVE_LOCKS
5322  {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
5323  __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
5324 #if KMP_DEBUG_ADAPTIVE_LOCKS
5325  {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
5326  __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
5327 #endif
5328 #endif // KMP_USE_ADAPTIVE_LOCKS
5329  {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5330  NULL, 0, 0},
5331  {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5332  NULL, 0, 0},
5333 #if USE_ITT_BUILD
5334  {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
5335  __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
5336  {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
5337  __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
5338 #endif
5339  {"KMP_ENABLE_TASK_THROTTLING", __kmp_stg_parse_task_throttling,
5340  __kmp_stg_print_task_throttling, NULL, 0, 0},
5341 
5342  {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
5343  __kmp_stg_print_omp_display_env, NULL, 0, 0},
5344  {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
5345  __kmp_stg_print_omp_cancellation, NULL, 0, 0},
5346  {"OMP_ALLOCATOR", __kmp_stg_parse_allocator, __kmp_stg_print_allocator,
5347  NULL, 0, 0},
5348  {"LIBOMP_USE_HIDDEN_HELPER_TASK", __kmp_stg_parse_use_hidden_helper,
5349  __kmp_stg_print_use_hidden_helper, NULL, 0, 0},
5350  {"LIBOMP_NUM_HIDDEN_HELPER_THREADS",
5351  __kmp_stg_parse_num_hidden_helper_threads,
5352  __kmp_stg_print_num_hidden_helper_threads, NULL, 0, 0},
5353 
5354 #if OMPT_SUPPORT
5355  {"OMP_TOOL", __kmp_stg_parse_omp_tool, __kmp_stg_print_omp_tool, NULL, 0,
5356  0},
5357  {"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries,
5358  __kmp_stg_print_omp_tool_libraries, NULL, 0, 0},
5359  {"OMP_TOOL_VERBOSE_INIT", __kmp_stg_parse_omp_tool_verbose_init,
5360  __kmp_stg_print_omp_tool_verbose_init, NULL, 0, 0},
5361 #endif
5362 
5363 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5364  {"KMP_USER_LEVEL_MWAIT", __kmp_stg_parse_user_level_mwait,
5365  __kmp_stg_print_user_level_mwait, NULL, 0, 0},
5366  {"KMP_MWAIT_HINTS", __kmp_stg_parse_mwait_hints,
5367  __kmp_stg_print_mwait_hints, NULL, 0, 0},
5368 #endif
5369  {"", NULL, NULL, NULL, 0, 0}}; // settings
5370 
5371 static int const __kmp_stg_count =
5372  sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
5373 
5374 static inline kmp_setting_t *__kmp_stg_find(char const *name) {
5375 
5376  int i;
5377  if (name != NULL) {
5378  for (i = 0; i < __kmp_stg_count; ++i) {
5379  if (strcmp(__kmp_stg_table[i].name, name) == 0) {
5380  return &__kmp_stg_table[i];
5381  }
5382  }
5383  }
5384  return NULL;
5385 
5386 } // __kmp_stg_find
5387 
5388 static int __kmp_stg_cmp(void const *_a, void const *_b) {
5389  const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
5390  const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);
5391 
5392  // Process KMP_AFFINITY last.
5393  // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
5394  if (strcmp(a->name, "KMP_AFFINITY") == 0) {
5395  if (strcmp(b->name, "KMP_AFFINITY") == 0) {
5396  return 0;
5397  }
5398  return 1;
5399  } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
5400  return -1;
5401  }
5402  return strcmp(a->name, b->name);
5403 } // __kmp_stg_cmp
5404 
5405 static void __kmp_stg_init(void) {
5406 
5407  static int initialized = 0;
5408 
5409  if (!initialized) {
5410 
5411  // Sort table.
5412  qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
5413  __kmp_stg_cmp);
5414 
5415  { // Initialize *_STACKSIZE data.
5416  kmp_setting_t *kmp_stacksize =
5417  __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
5418 #ifdef KMP_GOMP_COMPAT
5419  kmp_setting_t *gomp_stacksize =
5420  __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
5421 #endif
5422  kmp_setting_t *omp_stacksize =
5423  __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
5424 
5425  // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5426  // !!! Compiler does not understand rivals is used and optimizes out
5427  // assignments
5428  // !!! rivals[ i ++ ] = ...;
5429  static kmp_setting_t *volatile rivals[4];
5430  static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
5431 #ifdef KMP_GOMP_COMPAT
5432  static kmp_stg_ss_data_t gomp_data = {1024,
5433  CCAST(kmp_setting_t **, rivals)};
5434 #endif
5435  static kmp_stg_ss_data_t omp_data = {1024,
5436  CCAST(kmp_setting_t **, rivals)};
5437  int i = 0;
5438 
5439  rivals[i++] = kmp_stacksize;
5440 #ifdef KMP_GOMP_COMPAT
5441  if (gomp_stacksize != NULL) {
5442  rivals[i++] = gomp_stacksize;
5443  }
5444 #endif
5445  rivals[i++] = omp_stacksize;
5446  rivals[i++] = NULL;
5447 
5448  kmp_stacksize->data = &kmp_data;
5449 #ifdef KMP_GOMP_COMPAT
5450  if (gomp_stacksize != NULL) {
5451  gomp_stacksize->data = &gomp_data;
5452  }
5453 #endif
5454  omp_stacksize->data = &omp_data;
5455  }
5456 
5457  { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
5458  kmp_setting_t *kmp_library =
5459  __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
5460  kmp_setting_t *omp_wait_policy =
5461  __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
5462 
5463  // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5464  static kmp_setting_t *volatile rivals[3];
5465  static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
5466  static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
5467  int i = 0;
5468 
5469  rivals[i++] = kmp_library;
5470  if (omp_wait_policy != NULL) {
5471  rivals[i++] = omp_wait_policy;
5472  }
5473  rivals[i++] = NULL;
5474 
5475  kmp_library->data = &kmp_data;
5476  if (omp_wait_policy != NULL) {
5477  omp_wait_policy->data = &omp_data;
5478  }
5479  }
5480 
5481  { // Initialize KMP_DEVICE_THREAD_LIMIT and KMP_ALL_THREADS
5482  kmp_setting_t *kmp_device_thread_limit =
5483  __kmp_stg_find("KMP_DEVICE_THREAD_LIMIT"); // 1st priority.
5484  kmp_setting_t *kmp_all_threads =
5485  __kmp_stg_find("KMP_ALL_THREADS"); // 2nd priority.
5486 
5487  // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5488  static kmp_setting_t *volatile rivals[3];
5489  int i = 0;
5490 
5491  rivals[i++] = kmp_device_thread_limit;
5492  rivals[i++] = kmp_all_threads;
5493  rivals[i++] = NULL;
5494 
5495  kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
5496  kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
5497  }
5498 
5499  { // Initialize KMP_HW_SUBSET and KMP_PLACE_THREADS
5500  // 1st priority
5501  kmp_setting_t *kmp_hw_subset = __kmp_stg_find("KMP_HW_SUBSET");
5502  // 2nd priority
5503  kmp_setting_t *kmp_place_threads = __kmp_stg_find("KMP_PLACE_THREADS");
5504 
5505  // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5506  static kmp_setting_t *volatile rivals[3];
5507  int i = 0;
5508 
5509  rivals[i++] = kmp_hw_subset;
5510  rivals[i++] = kmp_place_threads;
5511  rivals[i++] = NULL;
5512 
5513  kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
5514  kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
5515  }
5516 
5517 #if KMP_AFFINITY_SUPPORTED
5518  { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
5519  kmp_setting_t *kmp_affinity =
5520  __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
5521  KMP_DEBUG_ASSERT(kmp_affinity != NULL);
5522 
5523 #ifdef KMP_GOMP_COMPAT
5524  kmp_setting_t *gomp_cpu_affinity =
5525  __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
5526  KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
5527 #endif
5528 
5529  kmp_setting_t *omp_proc_bind =
5530  __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
5531  KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
5532 
5533  // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5534  static kmp_setting_t *volatile rivals[4];
5535  int i = 0;
5536 
5537  rivals[i++] = kmp_affinity;
5538 
5539 #ifdef KMP_GOMP_COMPAT
5540  rivals[i++] = gomp_cpu_affinity;
5541  gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
5542 #endif
5543 
5544  rivals[i++] = omp_proc_bind;
5545  omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
5546  rivals[i++] = NULL;
5547 
5548  static kmp_setting_t *volatile places_rivals[4];
5549  i = 0;
5550 
5551  kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
5552  KMP_DEBUG_ASSERT(omp_places != NULL);
5553 
5554  places_rivals[i++] = kmp_affinity;
5555 #ifdef KMP_GOMP_COMPAT
5556  places_rivals[i++] = gomp_cpu_affinity;
5557 #endif
5558  places_rivals[i++] = omp_places;
5559  omp_places->data = CCAST(kmp_setting_t **, places_rivals);
5560  places_rivals[i++] = NULL;
5561  }
5562 #else
5563 // KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
5564 // OMP_PLACES not supported yet.
5565 #endif // KMP_AFFINITY_SUPPORTED
5566 
5567  { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
5568  kmp_setting_t *kmp_force_red =
5569  __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
5570  kmp_setting_t *kmp_determ_red =
5571  __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
5572 
5573  // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5574  static kmp_setting_t *volatile rivals[3];
5575  static kmp_stg_fr_data_t force_data = {1,
5576  CCAST(kmp_setting_t **, rivals)};
5577  static kmp_stg_fr_data_t determ_data = {0,
5578  CCAST(kmp_setting_t **, rivals)};
5579  int i = 0;
5580 
5581  rivals[i++] = kmp_force_red;
5582  if (kmp_determ_red != NULL) {
5583  rivals[i++] = kmp_determ_red;
5584  }
5585  rivals[i++] = NULL;
5586 
5587  kmp_force_red->data = &force_data;
5588  if (kmp_determ_red != NULL) {
5589  kmp_determ_red->data = &determ_data;
5590  }
5591  }
5592 
5593  initialized = 1;
5594  }
5595 
5596  // Reset flags.
5597  int i;
5598  for (i = 0; i < __kmp_stg_count; ++i) {
5599  __kmp_stg_table[i].set = 0;
5600  }
5601 
5602 } // __kmp_stg_init
5603 
5604 static void __kmp_stg_parse(char const *name, char const *value) {
5605  // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
5606  // really nameless, they are presented in environment block as
5607  // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
5608  if (name[0] == 0) {
5609  return;
5610  }
5611 
5612  if (value != NULL) {
5613  kmp_setting_t *setting = __kmp_stg_find(name);
5614  if (setting != NULL) {
5615  setting->parse(name, value, setting->data);
5616  setting->defined = 1;
5617  }
5618  }
5619 
5620 } // __kmp_stg_parse
5621 
5622 static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
5623  char const *name, // Name of variable.
5624  char const *value, // Value of the variable.
5625  kmp_setting_t **rivals // List of rival settings (must include current one).
5626 ) {
5627 
5628  if (rivals == NULL) {
5629  return 0;
5630  }
5631 
5632  // Loop thru higher priority settings (listed before current).
5633  int i = 0;
5634  for (; strcmp(rivals[i]->name, name) != 0; i++) {
5635  KMP_DEBUG_ASSERT(rivals[i] != NULL);
5636 
5637 #if KMP_AFFINITY_SUPPORTED
5638  if (rivals[i] == __kmp_affinity_notype) {
5639  // If KMP_AFFINITY is specified without a type name,
5640  // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
5641  continue;
5642  }
5643 #endif
5644 
5645  if (rivals[i]->set) {
5646  KMP_WARNING(StgIgnored, name, rivals[i]->name);
5647  return 1;
5648  }
5649  }
5650 
5651  ++i; // Skip current setting.
5652  return 0;
5653 
5654 } // __kmp_stg_check_rivals
5655 
5656 static int __kmp_env_toPrint(char const *name, int flag) {
5657  int rc = 0;
5658  kmp_setting_t *setting = __kmp_stg_find(name);
5659  if (setting != NULL) {
5660  rc = setting->defined;
5661  if (flag >= 0) {
5662  setting->defined = flag;
5663  }
5664  }
5665  return rc;
5666 }
5667 
5668 static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
5669 
5670  char const *value;
5671 
5672  /* OMP_NUM_THREADS */
5673  value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
5674  if (value) {
5675  ompc_set_num_threads(__kmp_dflt_team_nth);
5676  }
5677 
5678  /* KMP_BLOCKTIME */
5679  value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
5680  if (value) {
5681  kmpc_set_blocktime(__kmp_dflt_blocktime);
5682  }
5683 
5684  /* OMP_NESTED */
5685  value = __kmp_env_blk_var(block, "OMP_NESTED");
5686  if (value) {
5687  ompc_set_nested(__kmp_dflt_max_active_levels > 1);
5688  }
5689 
5690  /* OMP_DYNAMIC */
5691  value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
5692  if (value) {
5693  ompc_set_dynamic(__kmp_global.g.g_dynamic);
5694  }
5695 }
5696 
5697 void __kmp_env_initialize(char const *string) {
5698 
5699  kmp_env_blk_t block;
5700  int i;
5701 
5702  __kmp_stg_init();
5703 
5704  // Hack!!!
5705  if (string == NULL) {
5706  // __kmp_max_nth = __kmp_sys_max_nth;
5707  __kmp_threads_capacity =
5708  __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
5709  }
5710  __kmp_env_blk_init(&block, string);
5711 
5712  // update the set flag on all entries that have an env var
5713  for (i = 0; i < block.count; ++i) {
5714  if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
5715  continue;
5716  }
5717  if (block.vars[i].value == NULL) {
5718  continue;
5719  }
5720  kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
5721  if (setting != NULL) {
5722  setting->set = 1;
5723  }
5724  }
5725 
5726  // We need to know if blocktime was set when processing OMP_WAIT_POLICY
5727  blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
5728 
5729  // Special case. If we parse environment, not a string, process KMP_WARNINGS
5730  // first.
5731  if (string == NULL) {
5732  char const *name = "KMP_WARNINGS";
5733  char const *value = __kmp_env_blk_var(&block, name);
5734  __kmp_stg_parse(name, value);
5735  }
5736 
5737 #if KMP_AFFINITY_SUPPORTED
5738  // Special case. KMP_AFFINITY is not a rival to other affinity env vars
5739  // if no affinity type is specified. We want to allow
5740  // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
5741  // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
5742  // affinity mechanism.
5743  __kmp_affinity_notype = NULL;
5744  char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
5745  if (aff_str != NULL) {
5746  // Check if the KMP_AFFINITY type is specified in the string.
5747  // We just search the string for "compact", "scatter", etc.
5748  // without really parsing the string. The syntax of the
5749  // KMP_AFFINITY env var is such that none of the affinity
5750  // type names can appear anywhere other that the type
5751  // specifier, even as substrings.
5752  //
5753  // I can't find a case-insensitive version of strstr on Windows* OS.
5754  // Use the case-sensitive version for now.
5755 
5756 #if KMP_OS_WINDOWS
5757 #define FIND strstr
5758 #else
5759 #define FIND strcasestr
5760 #endif
5761 
5762  if ((FIND(aff_str, "none") == NULL) &&
5763  (FIND(aff_str, "physical") == NULL) &&
5764  (FIND(aff_str, "logical") == NULL) &&
5765  (FIND(aff_str, "compact") == NULL) &&
5766  (FIND(aff_str, "scatter") == NULL) &&
5767  (FIND(aff_str, "explicit") == NULL) &&
5768  (FIND(aff_str, "balanced") == NULL) &&
5769  (FIND(aff_str, "disabled") == NULL)) {
5770  __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
5771  } else {
5772  // A new affinity type is specified.
5773  // Reset the affinity flags to their default values,
5774  // in case this is called from kmp_set_defaults().
5775  __kmp_affinity_type = affinity_default;
5776  __kmp_affinity_gran = KMP_HW_UNKNOWN;
5777  __kmp_affinity_top_method = affinity_top_method_default;
5778  __kmp_affinity_respect_mask = affinity_respect_mask_default;
5779  }
5780 #undef FIND
5781 
5782  // Also reset the affinity flags if OMP_PROC_BIND is specified.
5783  aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
5784  if (aff_str != NULL) {
5785  __kmp_affinity_type = affinity_default;
5786  __kmp_affinity_gran = KMP_HW_UNKNOWN;
5787  __kmp_affinity_top_method = affinity_top_method_default;
5788  __kmp_affinity_respect_mask = affinity_respect_mask_default;
5789  }
5790  }
5791 
5792 #endif /* KMP_AFFINITY_SUPPORTED */
5793 
5794  // Set up the nested proc bind type vector.
5795  if (__kmp_nested_proc_bind.bind_types == NULL) {
5796  __kmp_nested_proc_bind.bind_types =
5797  (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
5798  if (__kmp_nested_proc_bind.bind_types == NULL) {
5799  KMP_FATAL(MemoryAllocFailed);
5800  }
5801  __kmp_nested_proc_bind.size = 1;
5802  __kmp_nested_proc_bind.used = 1;
5803 #if KMP_AFFINITY_SUPPORTED
5804  __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
5805 #else
5806  // default proc bind is false if affinity not supported
5807  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5808 #endif
5809  }
5810 
5811  // Set up the affinity format ICV
5812  // Grab the default affinity format string from the message catalog
5813  kmp_msg_t m =
5814  __kmp_msg_format(kmp_i18n_msg_AffFormatDefault, "%P", "%i", "%n", "%A");
5815  KMP_DEBUG_ASSERT(KMP_STRLEN(m.str) < KMP_AFFINITY_FORMAT_SIZE);
5816 
5817  if (__kmp_affinity_format == NULL) {
5818  __kmp_affinity_format =
5819  (char *)KMP_INTERNAL_MALLOC(sizeof(char) * KMP_AFFINITY_FORMAT_SIZE);
5820  }
5821  KMP_STRCPY_S(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, m.str);
5822  __kmp_str_free(&m.str);
5823 
5824  // Now process all of the settings.
5825  for (i = 0; i < block.count; ++i) {
5826  __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
5827  }
5828 
5829  // If user locks have been allocated yet, don't reset the lock vptr table.
5830  if (!__kmp_init_user_locks) {
5831  if (__kmp_user_lock_kind == lk_default) {
5832  __kmp_user_lock_kind = lk_queuing;
5833  }
5834 #if KMP_USE_DYNAMIC_LOCK
5835  __kmp_init_dynamic_user_locks();
5836 #else
5837  __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5838 #endif
5839  } else {
5840  KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
5841  KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
5842 // Binds lock functions again to follow the transition between different
5843 // KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
5844 // as we do not allow lock kind changes after making a call to any
5845 // user lock functions (true).
5846 #if KMP_USE_DYNAMIC_LOCK
5847  __kmp_init_dynamic_user_locks();
5848 #else
5849  __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5850 #endif
5851  }
5852 
5853 #if KMP_AFFINITY_SUPPORTED
5854 
5855  if (!TCR_4(__kmp_init_middle)) {
5856 #if KMP_USE_HWLOC
5857  // Force using hwloc when either tiles or numa nodes requested within
5858  // KMP_HW_SUBSET or granularity setting and no other topology method
5859  // is requested
5860  if (__kmp_hw_subset &&
5861  __kmp_affinity_top_method == affinity_top_method_default)
5862  if (__kmp_hw_subset->specified(KMP_HW_NUMA) ||
5863  __kmp_hw_subset->specified(KMP_HW_TILE) ||
5864  __kmp_affinity_gran == KMP_HW_TILE ||
5865  __kmp_affinity_gran == KMP_HW_NUMA)
5866  __kmp_affinity_top_method = affinity_top_method_hwloc;
5867  // Force using hwloc when tiles or numa nodes requested for OMP_PLACES
5868  if (__kmp_affinity_gran == KMP_HW_NUMA ||
5869  __kmp_affinity_gran == KMP_HW_TILE)
5870  __kmp_affinity_top_method = affinity_top_method_hwloc;
5871 #endif
5872  // Determine if the machine/OS is actually capable of supporting
5873  // affinity.
5874  const char *var = "KMP_AFFINITY";
5875  KMPAffinity::pick_api();
5876 #if KMP_USE_HWLOC
5877  // If Hwloc topology discovery was requested but affinity was also disabled,
5878  // then tell user that Hwloc request is being ignored and use default
5879  // topology discovery method.
5880  if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
5881  __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
5882  KMP_WARNING(AffIgnoringHwloc, var);
5883  __kmp_affinity_top_method = affinity_top_method_all;
5884  }
5885 #endif
5886  if (__kmp_affinity_type == affinity_disabled) {
5887  KMP_AFFINITY_DISABLE();
5888  } else if (!KMP_AFFINITY_CAPABLE()) {
5889  __kmp_affinity_dispatch->determine_capable(var);
5890  if (!KMP_AFFINITY_CAPABLE()) {
5891  if (__kmp_affinity_verbose ||
5892  (__kmp_affinity_warnings &&
5893  (__kmp_affinity_type != affinity_default) &&
5894  (__kmp_affinity_type != affinity_none) &&
5895  (__kmp_affinity_type != affinity_disabled))) {
5896  KMP_WARNING(AffNotSupported, var);
5897  }
5898  __kmp_affinity_type = affinity_disabled;
5899  __kmp_affinity_respect_mask = 0;
5900  __kmp_affinity_gran = KMP_HW_THREAD;
5901  }
5902  }
5903 
5904  if (__kmp_affinity_type == affinity_disabled) {
5905  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5906  } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
5907  // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
5908  __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
5909  }
5910 
5911  if (KMP_AFFINITY_CAPABLE()) {
5912 
5913 #if KMP_GROUP_AFFINITY
5914  // This checks to see if the initial affinity mask is equal
5915  // to a single windows processor group. If it is, then we do
5916  // not respect the initial affinity mask and instead, use the
5917  // entire machine.
5918  bool exactly_one_group = false;
5919  if (__kmp_num_proc_groups > 1) {
5920  int group;
5921  bool within_one_group;
5922  // Get the initial affinity mask and determine if it is
5923  // contained within a single group.
5924  kmp_affin_mask_t *init_mask;
5925  KMP_CPU_ALLOC(init_mask);
5926  __kmp_get_system_affinity(init_mask, TRUE);
5927  group = __kmp_get_proc_group(init_mask);
5928  within_one_group = (group >= 0);
5929  // If the initial affinity is within a single group,
5930  // then determine if it is equal to that single group.
5931  if (within_one_group) {
5932  DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
5933  DWORD num_bits_in_mask = 0;
5934  for (int bit = init_mask->begin(); bit != init_mask->end();
5935  bit = init_mask->next(bit))
5936  num_bits_in_mask++;
5937  exactly_one_group = (num_bits_in_group == num_bits_in_mask);
5938  }
5939  KMP_CPU_FREE(init_mask);
5940  }
5941 
5942  // Handle the Win 64 group affinity stuff if there are multiple
5943  // processor groups, or if the user requested it, and OMP 4.0
5944  // affinity is not in effect.
5945  if (((__kmp_num_proc_groups > 1) &&
5946  (__kmp_affinity_type == affinity_default) &&
5947  (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default)) ||
5948  (__kmp_affinity_top_method == affinity_top_method_group)) {
5949  if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
5950  exactly_one_group) {
5951  __kmp_affinity_respect_mask = FALSE;
5952  }
5953  if (__kmp_affinity_type == affinity_default) {
5954  __kmp_affinity_type = affinity_compact;
5955  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5956  }
5957  if (__kmp_affinity_top_method == affinity_top_method_default) {
5958  if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
5959  __kmp_affinity_top_method = affinity_top_method_group;
5960  __kmp_affinity_gran = KMP_HW_PROC_GROUP;
5961  } else if (__kmp_affinity_gran == KMP_HW_PROC_GROUP) {
5962  __kmp_affinity_top_method = affinity_top_method_group;
5963  } else {
5964  __kmp_affinity_top_method = affinity_top_method_all;
5965  }
5966  } else if (__kmp_affinity_top_method == affinity_top_method_group) {
5967  if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
5968  __kmp_affinity_gran = KMP_HW_PROC_GROUP;
5969  } else if ((__kmp_affinity_gran != KMP_HW_PROC_GROUP) &&
5970  (__kmp_affinity_gran != KMP_HW_THREAD)) {
5971  const char *str = __kmp_hw_get_keyword(__kmp_affinity_gran);
5972  KMP_WARNING(AffGranTopGroup, var, str);
5973  __kmp_affinity_gran = KMP_HW_THREAD;
5974  }
5975  } else {
5976  if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
5977  __kmp_affinity_gran = KMP_HW_CORE;
5978  } else if (__kmp_affinity_gran == KMP_HW_PROC_GROUP) {
5979  const char *str = NULL;
5980  switch (__kmp_affinity_type) {
5981  case affinity_physical:
5982  str = "physical";
5983  break;
5984  case affinity_logical:
5985  str = "logical";
5986  break;
5987  case affinity_compact:
5988  str = "compact";
5989  break;
5990  case affinity_scatter:
5991  str = "scatter";
5992  break;
5993  case affinity_explicit:
5994  str = "explicit";
5995  break;
5996  // No MIC on windows, so no affinity_balanced case
5997  default:
5998  KMP_DEBUG_ASSERT(0);
5999  }
6000  KMP_WARNING(AffGranGroupType, var, str);
6001  __kmp_affinity_gran = KMP_HW_CORE;
6002  }
6003  }
6004  } else
6005 
6006 #endif /* KMP_GROUP_AFFINITY */
6007 
6008  {
6009  if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
6010 #if KMP_GROUP_AFFINITY
6011  if (__kmp_num_proc_groups > 1 && exactly_one_group) {
6012  __kmp_affinity_respect_mask = FALSE;
6013  } else
6014 #endif /* KMP_GROUP_AFFINITY */
6015  {
6016  __kmp_affinity_respect_mask = TRUE;
6017  }
6018  }
6019  if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
6020  (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
6021  if (__kmp_affinity_type == affinity_default) {
6022  __kmp_affinity_type = affinity_compact;
6023  __kmp_affinity_dups = FALSE;
6024  }
6025  } else if (__kmp_affinity_type == affinity_default) {
6026 #if KMP_MIC_SUPPORTED
6027  if (__kmp_mic_type != non_mic) {
6028  __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6029  } else
6030 #endif
6031  {
6032  __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6033  }
6034 #if KMP_MIC_SUPPORTED
6035  if (__kmp_mic_type != non_mic) {
6036  __kmp_affinity_type = affinity_scatter;
6037  } else
6038 #endif
6039  {
6040  __kmp_affinity_type = affinity_none;
6041  }
6042  }
6043  if ((__kmp_affinity_gran == KMP_HW_UNKNOWN) &&
6044  (__kmp_affinity_gran_levels < 0)) {
6045 #if KMP_MIC_SUPPORTED
6046  if (__kmp_mic_type != non_mic) {
6047  __kmp_affinity_gran = KMP_HW_THREAD;
6048  } else
6049 #endif
6050  {
6051  __kmp_affinity_gran = KMP_HW_CORE;
6052  }
6053  }
6054  if (__kmp_affinity_top_method == affinity_top_method_default) {
6055  __kmp_affinity_top_method = affinity_top_method_all;
6056  }
6057  }
6058  }
6059 
6060  K_DIAG(1, ("__kmp_affinity_type == %d\n", __kmp_affinity_type));
6061  K_DIAG(1, ("__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
6062  K_DIAG(1, ("__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
6063  K_DIAG(1, ("__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
6064  K_DIAG(1, ("__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
6065  K_DIAG(1, ("__kmp_affinity_respect_mask == %d\n",
6066  __kmp_affinity_respect_mask));
6067  K_DIAG(1, ("__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
6068 
6069  KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
6070  KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
6071  K_DIAG(1, ("__kmp_nested_proc_bind.bind_types[0] == %d\n",
6072  __kmp_nested_proc_bind.bind_types[0]));
6073  }
6074 
6075 #endif /* KMP_AFFINITY_SUPPORTED */
6076 
6077  if (__kmp_version) {
6078  __kmp_print_version_1();
6079  }
6080 
6081  // Post-initialization step: some env. vars need their value's further
6082  // processing
6083  if (string != NULL) { // kmp_set_defaults() was called
6084  __kmp_aux_env_initialize(&block);
6085  }
6086 
6087  __kmp_env_blk_free(&block);
6088 
6089  KMP_MB();
6090 
6091 } // __kmp_env_initialize
6092 
6093 void __kmp_env_print() {
6094 
6095  kmp_env_blk_t block;
6096  int i;
6097  kmp_str_buf_t buffer;
6098 
6099  __kmp_stg_init();
6100  __kmp_str_buf_init(&buffer);
6101 
6102  __kmp_env_blk_init(&block, NULL);
6103  __kmp_env_blk_sort(&block);
6104 
6105  // Print real environment values.
6106  __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
6107  for (i = 0; i < block.count; ++i) {
6108  char const *name = block.vars[i].name;
6109  char const *value = block.vars[i].value;
6110  if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
6111  strncmp(name, "OMP_", 4) == 0
6112 #ifdef KMP_GOMP_COMPAT
6113  || strncmp(name, "GOMP_", 5) == 0
6114 #endif // KMP_GOMP_COMPAT
6115  ) {
6116  __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
6117  }
6118  }
6119  __kmp_str_buf_print(&buffer, "\n");
6120 
6121  // Print internal (effective) settings.
6122  __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
6123  for (int i = 0; i < __kmp_stg_count; ++i) {
6124  if (__kmp_stg_table[i].print != NULL) {
6125  __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6126  __kmp_stg_table[i].data);
6127  }
6128  }
6129 
6130  __kmp_printf("%s", buffer.str);
6131 
6132  __kmp_env_blk_free(&block);
6133  __kmp_str_buf_free(&buffer);
6134 
6135  __kmp_printf("\n");
6136 
6137 } // __kmp_env_print
6138 
6139 void __kmp_env_print_2() {
6140  __kmp_display_env_impl(__kmp_display_env, __kmp_display_env_verbose);
6141 } // __kmp_env_print_2
6142 
6143 void __kmp_display_env_impl(int display_env, int display_env_verbose) {
6144  kmp_env_blk_t block;
6145  kmp_str_buf_t buffer;
6146 
6147  __kmp_env_format = 1;
6148 
6149  __kmp_stg_init();
6150  __kmp_str_buf_init(&buffer);
6151 
6152  __kmp_env_blk_init(&block, NULL);
6153  __kmp_env_blk_sort(&block);
6154 
6155  __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
6156  __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
6157 
6158  for (int i = 0; i < __kmp_stg_count; ++i) {
6159  if (__kmp_stg_table[i].print != NULL &&
6160  ((display_env && strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
6161  display_env_verbose)) {
6162  __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6163  __kmp_stg_table[i].data);
6164  }
6165  }
6166 
6167  __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
6168  __kmp_str_buf_print(&buffer, "\n");
6169 
6170  __kmp_printf("%s", buffer.str);
6171 
6172  __kmp_env_blk_free(&block);
6173  __kmp_str_buf_free(&buffer);
6174 
6175  __kmp_printf("\n");
6176 }
6177 
6178 #if OMPD_SUPPORT
6179 // Dump environment variables for OMPD
6180 void __kmp_env_dump() {
6181 
6182  kmp_env_blk_t block;
6183  kmp_str_buf_t buffer, env, notdefined;
6184 
6185  __kmp_stg_init();
6186  __kmp_str_buf_init(&buffer);
6187  __kmp_str_buf_init(&env);
6188  __kmp_str_buf_init(&notdefined);
6189 
6190  __kmp_env_blk_init(&block, NULL);
6191  __kmp_env_blk_sort(&block);
6192 
6193  __kmp_str_buf_print(&notdefined, ": %s", KMP_I18N_STR(NotDefined));
6194 
6195  for (int i = 0; i < __kmp_stg_count; ++i) {
6196  if (__kmp_stg_table[i].print == NULL)
6197  continue;
6198  __kmp_str_buf_clear(&env);
6199  __kmp_stg_table[i].print(&env, __kmp_stg_table[i].name,
6200  __kmp_stg_table[i].data);
6201  if (env.used < 4) // valid definition must have indents (3) and a new line
6202  continue;
6203  if (strstr(env.str, notdefined.str))
6204  // normalize the string
6205  __kmp_str_buf_print(&buffer, "%s=undefined\n", __kmp_stg_table[i].name);
6206  else
6207  __kmp_str_buf_cat(&buffer, env.str + 3, env.used - 3);
6208  }
6209 
6210  ompd_env_block = (char *)__kmp_allocate(buffer.used + 1);
6211  KMP_MEMCPY(ompd_env_block, buffer.str, buffer.used + 1);
6212  ompd_env_block_size = (ompd_size_t)KMP_STRLEN(ompd_env_block);
6213 
6214  __kmp_env_blk_free(&block);
6215  __kmp_str_buf_free(&buffer);
6216  __kmp_str_buf_free(&env);
6217  __kmp_str_buf_free(&notdefined);
6218 }
6219 #endif // OMPD_SUPPORT
6220 
6221 // end of file
sched_type
Definition: kmp.h:355