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