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