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