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