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