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