14#include "kmp_affinity.h"
15#include "kmp_atomic.h"
17#include "kmp_dispatch_hier.h"
19#include "kmp_environment.h"
24#include "kmp_settings.h"
26#include "kmp_wrapper_getpid.h"
29#include "ompd-specific.h"
32static int __kmp_env_toPrint(
char const *name,
int flag);
34bool __kmp_env_format = 0;
39#ifdef USE_LOAD_BALANCE
40static double __kmp_convert_to_double(
char const *s) {
43 if (KMP_SSCANF(s,
"%lf", &result) < 1) {
52static unsigned int __kmp_readstr_with_sentinel(
char *dest,
char const *src,
53 size_t len,
char sentinel) {
55 for (i = 0; i < len; i++) {
56 if ((*src ==
'\0') || (*src == sentinel)) {
66static int __kmp_match_with_sentinel(
char const *a,
char const *b,
size_t len,
74 while (*a && *b && *b != sentinel) {
75 char ca = *a, cb = *b;
77 if (ca >=
'a' && ca <=
'z')
79 if (cb >=
'a' && cb <=
'z')
113static int __kmp_match_str(
char const *token,
char const *buf,
116 KMP_ASSERT(token != NULL);
117 KMP_ASSERT(buf != NULL);
118 KMP_ASSERT(end != NULL);
120 while (*token && *buf) {
121 char ct = *token, cb = *buf;
123 if (ct >=
'a' && ct <=
'z')
125 if (cb >=
'a' && cb <=
'z')
140static size_t __kmp_round4k(
size_t size) {
141 size_t _4k = 4 * 1024;
142 if (size & (_4k - 1)) {
144 if (size <= KMP_SIZE_T_MAX - _4k) {
152static int __kmp_strcasecmp_with_sentinel(
char const *a,
char const *b,
158 while (*a && *b && *b != sentinel) {
159 char ca = *a, cb = *b;
161 if (ca >=
'a' && ca <=
'z')
163 if (cb >=
'a' && cb <=
'z')
166 return (
int)(
unsigned char)*a - (
int)(
unsigned char)*b;
170 return *a ? (*b && *b != sentinel)
171 ? (
int)(
unsigned char)*a - (
int)(
unsigned char)*b
173 : (*b && *b != sentinel) ? -1
180typedef struct __kmp_setting kmp_setting_t;
181typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
182typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
183typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
185typedef void (*kmp_stg_parse_func_t)(
char const *name,
char const *value,
187typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer,
char const *name,
190struct __kmp_setting {
192 kmp_stg_parse_func_t parse;
193 kmp_stg_print_func_t print;
200struct __kmp_stg_ss_data {
202 kmp_setting_t **rivals;
205struct __kmp_stg_wp_data {
207 kmp_setting_t **rivals;
210struct __kmp_stg_fr_data {
212 kmp_setting_t **rivals;
215static int __kmp_stg_check_rivals(
218 kmp_setting_t **rivals
222struct kmp_trimmed_str_t {
224 kmp_trimmed_str_t(
const char *str) {
225 __kmp_str_buf_init(&buf);
226 size_t len = KMP_STRLEN(str);
229 const char *begin = str;
230 const char *end = str + KMP_STRLEN(str) - 1;
232 while (begin < end && *end ==
' ')
234 __kmp_str_buf_cat(&buf, begin, end - begin + 1);
236 ~kmp_trimmed_str_t() { __kmp_str_buf_free(&buf); }
237 const char *get() {
return buf.str; }
243static void __kmp_stg_parse_bool(
char const *name,
char const *value,
245 if (__kmp_str_match_true(value)) {
247 }
else if (__kmp_str_match_false(value)) {
250 __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
251 KMP_HNT(ValidBoolValues), __kmp_msg_null);
256void __kmp_check_stksize(
size_t *val) {
258 if (*val > KMP_DEFAULT_STKSIZE * 16)
259 *val = KMP_DEFAULT_STKSIZE * 16;
260 if (*val < __kmp_sys_min_stksize)
261 *val = __kmp_sys_min_stksize;
262 if (*val > KMP_MAX_STKSIZE)
263 *val = KMP_MAX_STKSIZE;
265 *val = __kmp_round4k(*val);
269static void __kmp_stg_parse_size(
char const *name,
char const *value,
270 size_t size_min,
size_t size_max,
271 int *is_specified,
size_t *out,
273 char const *msg = NULL;
275 size_min = __kmp_round4k(size_min);
276 size_max = __kmp_round4k(size_max);
279 if (is_specified != NULL) {
282 __kmp_str_to_size(value, out, factor, &msg);
284 if (*out > size_max) {
286 msg = KMP_I18N_STR(ValueTooLarge);
287 }
else if (*out < size_min) {
289 msg = KMP_I18N_STR(ValueTooSmall);
292 size_t round4k = __kmp_round4k(*out);
293 if (*out != round4k) {
295 msg = KMP_I18N_STR(NotMultiple4K);
302 if (*out < size_min) {
304 }
else if (*out > size_max) {
311 __kmp_str_buf_init(&buf);
312 __kmp_str_buf_print_size(&buf, *out);
313 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
314 KMP_INFORM(Using_str_Value, name, buf.str);
315 __kmp_str_buf_free(&buf);
320static void __kmp_stg_parse_str(
char const *name,
char const *value,
323 *out = __kmp_str_format(
"%s", value);
326static void __kmp_stg_parse_int(
334 char const *msg = NULL;
335 kmp_uint64 uint = *out;
336 __kmp_str_to_uint(value, &uint, &msg);
338 if (uint < (
unsigned int)min) {
339 msg = KMP_I18N_STR(ValueTooSmall);
341 }
else if (uint > (
unsigned int)max) {
342 msg = KMP_I18N_STR(ValueTooLarge);
348 if (uint < (
unsigned int)min) {
350 }
else if (uint > (
unsigned int)max) {
357 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
358 __kmp_str_buf_init(&buf);
359 __kmp_str_buf_print(&buf,
"%" KMP_UINT64_SPEC
"", uint);
360 KMP_INFORM(Using_uint64_Value, name, buf.str);
361 __kmp_str_buf_free(&buf);
363 __kmp_type_convert(uint, out);
366#if KMP_DEBUG_ADAPTIVE_LOCKS
367static void __kmp_stg_parse_file(
char const *name,
char const *value,
368 const char *suffix,
char **out) {
373 t = (
char *)strrchr(value,
'.');
374 hasSuffix = t && __kmp_str_eqf(t, suffix);
375 t = __kmp_str_format(
"%s%s", value, hasSuffix ?
"" : suffix);
376 __kmp_expand_file_name(buffer,
sizeof(buffer), t);
378 *out = __kmp_str_format(
"%s", buffer);
383static char *par_range_to_print = NULL;
385static void __kmp_stg_parse_par_range(
char const *name,
char const *value,
386 int *out_range,
char *out_routine,
387 char *out_file,
int *out_lb,
389 const char *par_range_value;
390 size_t len = KMP_STRLEN(value) + 1;
391 par_range_to_print = (
char *)KMP_INTERNAL_MALLOC(len + 1);
392 KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
393 __kmp_par_range = +1;
394 __kmp_par_range_lb = 0;
395 __kmp_par_range_ub = INT_MAX;
398 if (!value || *value ==
'\0') {
401 if (!__kmp_strcasecmp_with_sentinel(
"routine", value,
'=')) {
402 par_range_value = strchr(value,
'=') + 1;
403 if (!par_range_value)
404 goto par_range_error;
405 value = par_range_value;
406 len = __kmp_readstr_with_sentinel(out_routine, value,
407 KMP_PAR_RANGE_ROUTINE_LEN - 1,
',');
409 goto par_range_error;
411 value = strchr(value,
',');
417 if (!__kmp_strcasecmp_with_sentinel(
"filename", value,
'=')) {
418 par_range_value = strchr(value,
'=') + 1;
419 if (!par_range_value)
420 goto par_range_error;
421 value = par_range_value;
422 len = __kmp_readstr_with_sentinel(out_file, value,
423 KMP_PAR_RANGE_FILENAME_LEN - 1,
',');
425 goto par_range_error;
427 value = strchr(value,
',');
433 if ((!__kmp_strcasecmp_with_sentinel(
"range", value,
'=')) ||
434 (!__kmp_strcasecmp_with_sentinel(
"incl_range", value,
'='))) {
435 par_range_value = strchr(value,
'=') + 1;
436 if (!par_range_value)
437 goto par_range_error;
438 value = par_range_value;
439 if (KMP_SSCANF(value,
"%d:%d", out_lb, out_ub) != 2) {
440 goto par_range_error;
443 value = strchr(value,
',');
449 if (!__kmp_strcasecmp_with_sentinel(
"excl_range", value,
'=')) {
450 par_range_value = strchr(value,
'=') + 1;
451 if (!par_range_value)
452 goto par_range_error;
453 value = par_range_value;
454 if (KMP_SSCANF(value,
"%d:%d", out_lb, out_ub) != 2) {
455 goto par_range_error;
458 value = strchr(value,
',');
465 KMP_WARNING(ParRangeSyntax, name);
472int __kmp_initial_threads_capacity(
int req_nproc) {
477 if (nth < (4 * req_nproc))
478 nth = (4 * req_nproc);
479 if (nth < (4 * __kmp_xproc))
480 nth = (4 * __kmp_xproc);
484 if (__kmp_enable_hidden_helper) {
485 nth += __kmp_hidden_helper_threads_num;
488 if (nth > __kmp_max_nth)
494int __kmp_default_tp_capacity(
int req_nproc,
int max_nth,
495 int all_threads_specified) {
498 if (all_threads_specified)
502 if (nth < (4 * req_nproc))
503 nth = (4 * req_nproc);
504 if (nth < (4 * __kmp_xproc))
505 nth = (4 * __kmp_xproc);
507 if (nth > __kmp_max_nth)
516static void __kmp_stg_print_bool(kmp_str_buf_t *buffer,
char const *name,
518 if (__kmp_env_format) {
519 KMP_STR_BUF_PRINT_BOOL;
521 __kmp_str_buf_print(buffer,
" %s=%s\n", name, value ?
"true" :
"false");
525static void __kmp_stg_print_int(kmp_str_buf_t *buffer,
char const *name,
527 if (__kmp_env_format) {
528 KMP_STR_BUF_PRINT_INT;
530 __kmp_str_buf_print(buffer,
" %s=%d\n", name, value);
534static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer,
char const *name,
536 if (__kmp_env_format) {
537 KMP_STR_BUF_PRINT_UINT64;
539 __kmp_str_buf_print(buffer,
" %s=%" KMP_UINT64_SPEC
"\n", name, value);
543static void __kmp_stg_print_str(kmp_str_buf_t *buffer,
char const *name,
545 if (__kmp_env_format) {
546 KMP_STR_BUF_PRINT_STR;
548 __kmp_str_buf_print(buffer,
" %s=%s\n", name, value);
552static void __kmp_stg_print_size(kmp_str_buf_t *buffer,
char const *name,
554 if (__kmp_env_format) {
555 KMP_STR_BUF_PRINT_NAME_EX(name);
556 __kmp_str_buf_print_size(buffer, value);
557 __kmp_str_buf_print(buffer,
"'\n");
559 __kmp_str_buf_print(buffer,
" %s=", name);
560 __kmp_str_buf_print_size(buffer, value);
561 __kmp_str_buf_print(buffer,
"\n");
572static void __kmp_stg_parse_device_thread_limit(
char const *name,
573 char const *value,
void *data) {
574 kmp_setting_t **rivals = (kmp_setting_t **)data;
576 if (strcmp(name,
"KMP_ALL_THREADS") == 0) {
577 KMP_INFORM(EnvVarDeprecated, name,
"KMP_DEVICE_THREAD_LIMIT");
579 rc = __kmp_stg_check_rivals(name, value, rivals);
583 if (!__kmp_strcasecmp_with_sentinel(
"all", value, 0)) {
584 __kmp_max_nth = __kmp_xproc;
585 __kmp_allThreadsSpecified = 1;
587 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
588 __kmp_allThreadsSpecified = 0;
590 K_DIAG(1, (
"__kmp_max_nth == %d\n", __kmp_max_nth));
594static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
595 char const *name,
void *data) {
596 __kmp_stg_print_int(buffer, name, __kmp_max_nth);
601static void __kmp_stg_parse_thread_limit(
char const *name,
char const *value,
603 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
604 K_DIAG(1, (
"__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));
608static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
609 char const *name,
void *data) {
610 __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
615static void __kmp_stg_parse_nteams(
char const *name,
char const *value,
617 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_nteams);
618 K_DIAG(1, (
"__kmp_nteams == %d\n", __kmp_nteams));
621static void __kmp_stg_print_nteams(kmp_str_buf_t *buffer,
char const *name,
623 __kmp_stg_print_int(buffer, name, __kmp_nteams);
628static void __kmp_stg_parse_teams_th_limit(
char const *name,
char const *value,
630 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth,
631 &__kmp_teams_thread_limit);
632 K_DIAG(1, (
"__kmp_teams_thread_limit == %d\n", __kmp_teams_thread_limit));
635static void __kmp_stg_print_teams_th_limit(kmp_str_buf_t *buffer,
636 char const *name,
void *data) {
637 __kmp_stg_print_int(buffer, name, __kmp_teams_thread_limit);
642static void __kmp_stg_parse_teams_thread_limit(
char const *name,
643 char const *value,
void *data) {
644 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
647static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
648 char const *name,
void *data) {
649 __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
654static void __kmp_stg_parse_use_yield(
char const *name,
char const *value,
656 __kmp_stg_parse_int(name, value, 0, 2, &__kmp_use_yield);
657 __kmp_use_yield_exp_set = 1;
660static void __kmp_stg_print_use_yield(kmp_str_buf_t *buffer,
char const *name,
662 __kmp_stg_print_int(buffer, name, __kmp_use_yield);
668static void __kmp_stg_parse_blocktime(
char const *name,
char const *value,
670 const char *buf = value;
672 const int ms_mult = 1000;
678 if ((*buf >=
'0') && (*buf <=
'9')) {
681 num = __kmp_basic_str_to_int(buf);
682 KMP_ASSERT(num >= 0);
691 if (*buf ==
'\0' || __kmp_match_str(
"ms", buf, &next)) {
693 __kmp_dflt_blocktime = ms_mult * num;
694 __kmp_blocktime_units =
'm';
695 multiplier = ms_mult;
696 }
else if (__kmp_match_str(
"us", buf, &next)) {
698 __kmp_dflt_blocktime = num;
699 __kmp_blocktime_units =
'u';
700 }
else if (__kmp_match_str(
"infinite", buf, &next) ||
701 __kmp_match_str(
"infinity", buf, &next)) {
703 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
704 __kmp_blocktime_units =
'm';
705 multiplier = ms_mult;
707 KMP_WARNING(StgInvalidValue, name, value);
709 __kmp_dflt_blocktime = ms_mult * num;
710 __kmp_blocktime_units =
'm';
711 multiplier = ms_mult;
714 if (num < 0 && __kmp_dflt_blocktime < 0) {
715 __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
716 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
719 KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime / multiplier);
720 __kmp_env_blocktime = FALSE;
721 }
else if (num > 0 && __kmp_dflt_blocktime < 0) {
722 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
723 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value), __kmp_msg_null);
724 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime / multiplier);
725 __kmp_env_blocktime = TRUE;
727 if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
728 __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
729 __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
731 KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime / multiplier);
732 }
else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
733 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
734 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
736 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime / multiplier);
738 __kmp_env_blocktime = TRUE;
743 __kmp_monitor_wakeups =
744 KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
746 KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
748 K_DIAG(1, (
"__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
749 if (__kmp_env_blocktime) {
750 K_DIAG(1, (
"__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
754static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer,
char const *name,
756 int num = __kmp_dflt_blocktime;
757 if (__kmp_blocktime_units ==
'm') {
760 if (__kmp_env_format) {
761 KMP_STR_BUF_PRINT_NAME_EX(name);
763 __kmp_str_buf_print(buffer,
" %s=", name);
765 __kmp_str_buf_print(buffer,
"%d", num);
766 __kmp_str_buf_print(buffer,
"%cs\n", __kmp_blocktime_units);
772static void __kmp_stg_parse_duplicate_lib_ok(
char const *name,
773 char const *value,
void *data) {
776 __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
779static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
780 char const *name,
void *data) {
781 __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
787#if KMP_ARCH_X86 || KMP_ARCH_X86_64
789static void __kmp_stg_parse_inherit_fp_control(
char const *name,
790 char const *value,
void *data) {
791 __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
794static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
795 char const *name,
void *data) {
797 __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
804static char const *blocktime_str = NULL;
809static void __kmp_stg_parse_wait_policy(
char const *name,
char const *value,
812 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
815 rc = __kmp_stg_check_rivals(name, value, wait->rivals);
821 if (__kmp_str_match(
"ACTIVE", 1, value)) {
822 __kmp_library = library_turnaround;
823 if (blocktime_str == NULL) {
825 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
827 }
else if (__kmp_str_match(
"PASSIVE", 1, value)) {
828 __kmp_library = library_throughput;
829 __kmp_wpolicy_passive =
true;
830 if (blocktime_str == NULL) {
832 __kmp_dflt_blocktime = 0;
835 KMP_WARNING(StgInvalidValue, name, value);
838 if (__kmp_str_match(
"serial", 1, value)) {
839 __kmp_library = library_serial;
840 }
else if (__kmp_str_match(
"throughput", 2, value)) {
841 __kmp_library = library_throughput;
842 if (blocktime_str == NULL) {
844 __kmp_dflt_blocktime = 0;
846 }
else if (__kmp_str_match(
"turnaround", 2, value)) {
847 __kmp_library = library_turnaround;
848 }
else if (__kmp_str_match(
"dedicated", 1, value)) {
849 __kmp_library = library_turnaround;
850 }
else if (__kmp_str_match(
"multiuser", 1, value)) {
851 __kmp_library = library_throughput;
852 if (blocktime_str == NULL) {
854 __kmp_dflt_blocktime = 0;
857 KMP_WARNING(StgInvalidValue, name, value);
862static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer,
char const *name,
865 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
866 char const *value = NULL;
869 switch (__kmp_library) {
870 case library_turnaround: {
873 case library_throughput: {
877 case library_serial: {
882 switch (__kmp_library) {
883 case library_serial: {
886 case library_turnaround: {
887 value =
"turnaround";
889 case library_throughput: {
890 value =
"throughput";
898 __kmp_stg_print_str(buffer, name, value);
907static void __kmp_stg_parse_monitor_stacksize(
char const *name,
908 char const *value,
void *data) {
909 __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
910 NULL, &__kmp_monitor_stksize, 1);
913static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
914 char const *name,
void *data) {
915 if (__kmp_env_format) {
916 if (__kmp_monitor_stksize > 0)
917 KMP_STR_BUF_PRINT_NAME_EX(name);
919 KMP_STR_BUF_PRINT_NAME;
921 __kmp_str_buf_print(buffer,
" %s", name);
923 if (__kmp_monitor_stksize > 0) {
924 __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
926 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
928 if (__kmp_env_format && __kmp_monitor_stksize) {
929 __kmp_str_buf_print(buffer,
"'\n");
937static void __kmp_stg_parse_settings(
char const *name,
char const *value,
939 __kmp_stg_parse_bool(name, value, &__kmp_settings);
942static void __kmp_stg_print_settings(kmp_str_buf_t *buffer,
char const *name,
944 __kmp_stg_print_bool(buffer, name, __kmp_settings);
950static void __kmp_stg_parse_stackpad(
char const *name,
char const *value,
952 __kmp_stg_parse_int(name,
960static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer,
char const *name,
962 __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
968static void __kmp_stg_parse_stackoffset(
char const *name,
char const *value,
970 __kmp_stg_parse_size(name,
979static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer,
char const *name,
981 __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
987static void __kmp_stg_parse_stacksize(
char const *name,
char const *value,
990 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
993 rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
997 __kmp_stg_parse_size(name,
999 __kmp_sys_min_stksize,
1011static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer,
char const *name,
1013 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
1014 if (__kmp_env_format) {
1015 KMP_STR_BUF_PRINT_NAME_EX(name);
1016 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
1017 ? __kmp_stksize / stacksize->factor
1019 __kmp_str_buf_print(buffer,
"'\n");
1021 __kmp_str_buf_print(buffer,
" %s=", name);
1022 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
1023 ? __kmp_stksize / stacksize->factor
1025 __kmp_str_buf_print(buffer,
"\n");
1032static void __kmp_stg_parse_version(
char const *name,
char const *value,
1034 __kmp_stg_parse_bool(name, value, &__kmp_version);
1037static void __kmp_stg_print_version(kmp_str_buf_t *buffer,
char const *name,
1039 __kmp_stg_print_bool(buffer, name, __kmp_version);
1045static void __kmp_stg_parse_warnings(
char const *name,
char const *value,
1047 __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
1048 if (__kmp_generate_warnings != kmp_warnings_off) {
1051 __kmp_generate_warnings = kmp_warnings_explicit;
1055static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer,
char const *name,
1058 __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
1064static void __kmp_stg_parse_nesting_mode(
char const *name,
char const *value,
1066 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_nesting_mode);
1067#if KMP_AFFINITY_SUPPORTED && KMP_USE_HWLOC
1068 if (__kmp_nesting_mode > 0)
1069 __kmp_affinity_top_method = affinity_top_method_hwloc;
1073static void __kmp_stg_print_nesting_mode(kmp_str_buf_t *buffer,
1074 char const *name,
void *data) {
1075 if (__kmp_env_format) {
1076 KMP_STR_BUF_PRINT_NAME;
1078 __kmp_str_buf_print(buffer,
" %s", name);
1080 __kmp_str_buf_print(buffer,
"=%d\n", __kmp_nesting_mode);
1086static void __kmp_stg_parse_nested(
char const *name,
char const *value,
1089 KMP_INFORM(EnvVarDeprecated, name,
"OMP_MAX_ACTIVE_LEVELS");
1090 __kmp_stg_parse_bool(name, value, &nested);
1092 if (!__kmp_dflt_max_active_levels_set)
1093 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1095 __kmp_dflt_max_active_levels = 1;
1096 __kmp_dflt_max_active_levels_set =
true;
1100static void __kmp_stg_print_nested(kmp_str_buf_t *buffer,
char const *name,
1102 if (__kmp_env_format) {
1103 KMP_STR_BUF_PRINT_NAME;
1105 __kmp_str_buf_print(buffer,
" %s", name);
1107 __kmp_str_buf_print(buffer,
": deprecated; max-active-levels-var=%d\n",
1108 __kmp_dflt_max_active_levels);
1111static void __kmp_parse_nested_num_threads(
const char *var,
const char *env,
1112 kmp_nested_nthreads_t *nth_array) {
1113 const char *next = env;
1114 const char *scan = next;
1117 int prev_comma = FALSE;
1123 if (*next ==
'\0') {
1127 if (((*next <
'0') || (*next >
'9')) && (*next !=
',')) {
1128 KMP_WARNING(NthSyntaxError, var, env);
1134 if (total == 0 || prev_comma) {
1142 if (*next >=
'0' && *next <=
'9') {
1146 const char *tmp = next;
1148 if ((*next ==
' ' || *next ==
'\t') && (*tmp >=
'0' && *tmp <=
'9')) {
1149 KMP_WARNING(NthSpacesNotAllowed, var, env);
1154 if (!__kmp_dflt_max_active_levels_set && total > 1)
1155 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1156 KMP_DEBUG_ASSERT(total > 0);
1158 KMP_WARNING(NthSyntaxError, var, env);
1163 if (!nth_array->nth) {
1165 nth_array->nth = (
int *)KMP_INTERNAL_MALLOC(
sizeof(
int) * total * 2);
1166 if (nth_array->nth == NULL) {
1167 KMP_FATAL(MemoryAllocFailed);
1169 nth_array->size = total * 2;
1171 if (nth_array->size < total) {
1174 nth_array->size *= 2;
1175 }
while (nth_array->size < total);
1177 nth_array->nth = (
int *)KMP_INTERNAL_REALLOC(
1178 nth_array->nth,
sizeof(
int) * nth_array->size);
1179 if (nth_array->nth == NULL) {
1180 KMP_FATAL(MemoryAllocFailed);
1184 nth_array->used = total;
1192 if (*scan ==
'\0') {
1202 nth_array->nth[i++] = 0;
1204 }
else if (prev_comma) {
1206 nth_array->nth[i] = nth_array->nth[i - 1];
1215 if (*scan >=
'0' && *scan <=
'9') {
1217 const char *buf = scan;
1218 char const *msg = NULL;
1223 num = __kmp_str_to_int(buf, *scan);
1224 if (num < KMP_MIN_NTH) {
1225 msg = KMP_I18N_STR(ValueTooSmall);
1227 }
else if (num > __kmp_sys_max_nth) {
1228 msg = KMP_I18N_STR(ValueTooLarge);
1229 num = __kmp_sys_max_nth;
1233 KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1234 KMP_INFORM(Using_int_Value, var, num);
1236 nth_array->nth[i++] = num;
1241static void __kmp_stg_parse_num_threads(
char const *name,
char const *value,
1244 if (!__kmp_strcasecmp_with_sentinel(
"all", value, 0)) {
1246 __kmp_nested_nth.nth = (
int *)KMP_INTERNAL_MALLOC(
sizeof(
int));
1247 __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1248 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1251 __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1252 if (__kmp_nested_nth.nth) {
1253 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1254 if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1255 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1259 K_DIAG(1, (
"__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
1263static void __kmp_stg_parse_max_tdgs(
char const *name,
char const *value,
1265 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_max_tdgs);
1268static void __kmp_std_print_max_tdgs(kmp_str_buf_t *buffer,
char const *name,
1270 __kmp_stg_print_int(buffer, name, __kmp_max_tdgs);
1273static void __kmp_stg_parse_tdg_dot(
char const *name,
char const *value,
1275 __kmp_stg_parse_bool(name, value, &__kmp_tdg_dot);
1278static void __kmp_stg_print_tdg_dot(kmp_str_buf_t *buffer,
char const *name,
1280 __kmp_stg_print_bool(buffer, name, __kmp_tdg_dot);
1284static void __kmp_stg_parse_num_hidden_helper_threads(
char const *name,
1287 __kmp_stg_parse_int(name, value, 0, 16, &__kmp_hidden_helper_threads_num);
1290 if (__kmp_hidden_helper_threads_num == 0) {
1291 __kmp_enable_hidden_helper = FALSE;
1296 __kmp_hidden_helper_threads_num++;
1300static void __kmp_stg_print_num_hidden_helper_threads(kmp_str_buf_t *buffer,
1303 if (__kmp_hidden_helper_threads_num == 0) {
1304 __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num);
1306 KMP_DEBUG_ASSERT(__kmp_hidden_helper_threads_num > 1);
1309 __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num - 1);
1313static void __kmp_stg_parse_use_hidden_helper(
char const *name,
1314 char const *value,
void *data) {
1315 __kmp_stg_parse_bool(name, value, &__kmp_enable_hidden_helper);
1317 __kmp_enable_hidden_helper = FALSE;
1319 (
"__kmp_stg_parse_use_hidden_helper: Disable hidden helper task on "
1320 "non-Linux platform although it is enabled by user explicitly.\n"));
1324static void __kmp_stg_print_use_hidden_helper(kmp_str_buf_t *buffer,
1325 char const *name,
void *data) {
1326 __kmp_stg_print_bool(buffer, name, __kmp_enable_hidden_helper);
1329static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer,
char const *name,
1331 if (__kmp_env_format) {
1332 KMP_STR_BUF_PRINT_NAME;
1334 __kmp_str_buf_print(buffer,
" %s", name);
1336 if (__kmp_nested_nth.used) {
1338 __kmp_str_buf_init(&buf);
1339 for (
int i = 0; i < __kmp_nested_nth.used; i++) {
1340 __kmp_str_buf_print(&buf,
"%d", __kmp_nested_nth.nth[i]);
1341 if (i < __kmp_nested_nth.used - 1) {
1342 __kmp_str_buf_print(&buf,
",");
1345 __kmp_str_buf_print(buffer,
"='%s'\n", buf.str);
1346 __kmp_str_buf_free(&buf);
1348 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
1355static void __kmp_stg_parse_tasking(
char const *name,
char const *value,
1357 __kmp_stg_parse_int(name, value, 0, (
int)tskm_max,
1358 (
int *)&__kmp_tasking_mode);
1361static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer,
char const *name,
1363 __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
1366static void __kmp_stg_parse_task_stealing(
char const *name,
char const *value,
1368 __kmp_stg_parse_int(name, value, 0, 1,
1369 (
int *)&__kmp_task_stealing_constraint);
1372static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1373 char const *name,
void *data) {
1374 __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
1377static void __kmp_stg_parse_max_active_levels(
char const *name,
1378 char const *value,
void *data) {
1379 kmp_uint64 tmp_dflt = 0;
1380 char const *msg = NULL;
1381 if (!__kmp_dflt_max_active_levels_set) {
1383 __kmp_str_to_uint(value, &tmp_dflt, &msg);
1385 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1386 }
else if (tmp_dflt > KMP_MAX_ACTIVE_LEVELS_LIMIT) {
1388 msg = KMP_I18N_STR(ValueTooLarge);
1389 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1391 __kmp_type_convert(tmp_dflt, &(__kmp_dflt_max_active_levels));
1392 __kmp_dflt_max_active_levels_set =
true;
1397static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1398 char const *name,
void *data) {
1399 __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
1404static void __kmp_stg_parse_default_device(
char const *name,
char const *value,
1406 __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1407 &__kmp_default_device);
1410static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1411 char const *name,
void *data) {
1412 __kmp_stg_print_int(buffer, name, __kmp_default_device);
1417static void __kmp_stg_parse_target_offload(
char const *name,
char const *value,
1419 kmp_trimmed_str_t value_str(value);
1420 const char *scan = value_str.get();
1421 __kmp_target_offload = tgt_default;
1426 if (!__kmp_strcasecmp_with_sentinel(
"mandatory", scan, 0)) {
1427 __kmp_target_offload = tgt_mandatory;
1428 }
else if (!__kmp_strcasecmp_with_sentinel(
"disabled", scan, 0)) {
1429 __kmp_target_offload = tgt_disabled;
1430 }
else if (!__kmp_strcasecmp_with_sentinel(
"default", scan, 0)) {
1431 __kmp_target_offload = tgt_default;
1433 KMP_WARNING(SyntaxErrorUsing, name,
"DEFAULT");
1437static void __kmp_stg_print_target_offload(kmp_str_buf_t *buffer,
1438 char const *name,
void *data) {
1439 const char *value = NULL;
1440 if (__kmp_target_offload == tgt_default)
1442 else if (__kmp_target_offload == tgt_mandatory)
1443 value =
"MANDATORY";
1444 else if (__kmp_target_offload == tgt_disabled)
1446 KMP_DEBUG_ASSERT(value);
1447 if (__kmp_env_format) {
1448 KMP_STR_BUF_PRINT_NAME;
1450 __kmp_str_buf_print(buffer,
" %s", name);
1452 __kmp_str_buf_print(buffer,
"=%s\n", value);
1457static void __kmp_stg_parse_max_task_priority(
char const *name,
1458 char const *value,
void *data) {
1459 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1460 &__kmp_max_task_priority);
1463static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1464 char const *name,
void *data) {
1465 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
1470static void __kmp_stg_parse_taskloop_min_tasks(
char const *name,
1471 char const *value,
void *data) {
1473 __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1474 __kmp_taskloop_min_tasks = tmp;
1477static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
1478 char const *name,
void *data) {
1479 __kmp_stg_print_uint64(buffer, name, __kmp_taskloop_min_tasks);
1484static void __kmp_stg_parse_disp_buffers(
char const *name,
char const *value,
1486 if (TCR_4(__kmp_init_serial)) {
1487 KMP_WARNING(EnvSerialWarn, name);
1490 __kmp_stg_parse_int(name, value, KMP_MIN_DISP_NUM_BUFF, KMP_MAX_DISP_NUM_BUFF,
1491 &__kmp_dispatch_num_buffers);
1494static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1495 char const *name,
void *data) {
1496 __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
1499#if KMP_NESTED_HOT_TEAMS
1503static void __kmp_stg_parse_hot_teams_level(
char const *name,
char const *value,
1505 if (TCR_4(__kmp_init_parallel)) {
1506 KMP_WARNING(EnvParallelWarn, name);
1509 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1510 &__kmp_hot_teams_max_level);
1513static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1514 char const *name,
void *data) {
1515 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
1518static void __kmp_stg_parse_hot_teams_mode(
char const *name,
char const *value,
1520 if (TCR_4(__kmp_init_parallel)) {
1521 KMP_WARNING(EnvParallelWarn, name);
1524 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1525 &__kmp_hot_teams_mode);
1528static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1529 char const *name,
void *data) {
1530 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
1538#if KMP_HANDLE_SIGNALS
1540static void __kmp_stg_parse_handle_signals(
char const *name,
char const *value,
1542 __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
1545static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1546 char const *name,
void *data) {
1547 __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
1557#define KMP_STG_X_DEBUG(x) \
1558 static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1560 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1562 static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1563 char const *name, void *data) { \
1564 __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1574#undef KMP_STG_X_DEBUG
1576static void __kmp_stg_parse_debug(
char const *name,
char const *value,
1579 __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1580 if (kmp_a_debug < debug) {
1581 kmp_a_debug = debug;
1583 if (kmp_b_debug < debug) {
1584 kmp_b_debug = debug;
1586 if (kmp_c_debug < debug) {
1587 kmp_c_debug = debug;
1589 if (kmp_d_debug < debug) {
1590 kmp_d_debug = debug;
1592 if (kmp_e_debug < debug) {
1593 kmp_e_debug = debug;
1595 if (kmp_f_debug < debug) {
1596 kmp_f_debug = debug;
1600static void __kmp_stg_parse_debug_buf(
char const *name,
char const *value,
1602 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1606 if (__kmp_debug_buf) {
1608 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
1611 __kmp_debug_buffer = (
char *)__kmp_page_allocate(elements *
sizeof(
char));
1612 for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1613 __kmp_debug_buffer[i] =
'\0';
1615 __kmp_debug_count = 0;
1617 K_DIAG(1, (
"__kmp_debug_buf = %d\n", __kmp_debug_buf));
1620static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer,
char const *name,
1622 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
1625static void __kmp_stg_parse_debug_buf_atomic(
char const *name,
1626 char const *value,
void *data) {
1627 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
1630static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1631 char const *name,
void *data) {
1632 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
1635static void __kmp_stg_parse_debug_buf_chars(
char const *name,
char const *value,
1637 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1638 &__kmp_debug_buf_chars);
1641static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1642 char const *name,
void *data) {
1643 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
1646static void __kmp_stg_parse_debug_buf_lines(
char const *name,
char const *value,
1648 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1649 &__kmp_debug_buf_lines);
1652static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1653 char const *name,
void *data) {
1654 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
1657static void __kmp_stg_parse_diag(
char const *name,
char const *value,
1659 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
1662static void __kmp_stg_print_diag(kmp_str_buf_t *buffer,
char const *name,
1664 __kmp_stg_print_int(buffer, name, kmp_diag);
1672static void __kmp_stg_parse_align_alloc(
char const *name,
char const *value,
1674 __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1675 &__kmp_align_alloc, 1);
1678static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer,
char const *name,
1680 __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
1689static void __kmp_stg_parse_barrier_branch_bit(
char const *name,
1690 char const *value,
void *data) {
1694 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1695 var = __kmp_barrier_branch_bit_env_name[i];
1696 if ((strcmp(var, name) == 0) && (value != 0)) {
1699 comma = CCAST(
char *, strchr(value,
','));
1700 __kmp_barrier_gather_branch_bits[i] =
1701 (kmp_uint32)__kmp_str_to_int(value,
',');
1703 if (comma == NULL) {
1704 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1706 __kmp_barrier_release_branch_bits[i] =
1707 (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
1709 if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1710 __kmp_msg(kmp_ms_warning,
1711 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1713 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1716 if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1717 KMP_WARNING(BarrGatherValueInvalid, name, value);
1718 KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1719 __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1722 K_DIAG(1, (
"%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1723 __kmp_barrier_gather_branch_bits[i],
1724 __kmp_barrier_release_branch_bits[i]))
1728static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1729 char const *name,
void *data) {
1731 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1732 var = __kmp_barrier_branch_bit_env_name[i];
1733 if (strcmp(var, name) == 0) {
1734 if (__kmp_env_format) {
1735 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1737 __kmp_str_buf_print(buffer,
" %s='",
1738 __kmp_barrier_branch_bit_env_name[i]);
1740 __kmp_str_buf_print(buffer,
"%d,%d'\n",
1741 __kmp_barrier_gather_branch_bits[i],
1742 __kmp_barrier_release_branch_bits[i]);
1754static void __kmp_stg_parse_barrier_pattern(
char const *name,
char const *value,
1759 static int dist_req = 0, non_dist_req = 0;
1760 static bool warn = 1;
1761 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1762 var = __kmp_barrier_pattern_env_name[i];
1764 if ((strcmp(var, name) == 0) && (value != 0)) {
1766 char *comma = CCAST(
char *, strchr(value,
','));
1769 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1770 if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1772 if (j == bp_dist_bar) {
1777 __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1781 if (j == bp_last_bar) {
1782 KMP_WARNING(BarrGatherValueInvalid, name, value);
1783 KMP_INFORM(Using_str_Value, name,
1784 __kmp_barrier_pattern_name[bp_linear_bar]);
1788 if (comma != NULL) {
1789 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1790 if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1791 if (j == bp_dist_bar) {
1796 __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1800 if (j == bp_last_bar) {
1801 __kmp_msg(kmp_ms_warning,
1802 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1804 KMP_INFORM(Using_str_Value, name,
1805 __kmp_barrier_pattern_name[bp_linear_bar]);
1810 if (dist_req != 0) {
1812 if ((non_dist_req != 0) && warn) {
1813 KMP_INFORM(BarrierPatternOverride, name,
1814 __kmp_barrier_pattern_name[bp_dist_bar]);
1817 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1818 if (__kmp_barrier_release_pattern[i] != bp_dist_bar)
1819 __kmp_barrier_release_pattern[i] = bp_dist_bar;
1820 if (__kmp_barrier_gather_pattern[i] != bp_dist_bar)
1821 __kmp_barrier_gather_pattern[i] = bp_dist_bar;
1826static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1827 char const *name,
void *data) {
1829 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1830 var = __kmp_barrier_pattern_env_name[i];
1831 if (strcmp(var, name) == 0) {
1832 int j = __kmp_barrier_gather_pattern[i];
1833 int k = __kmp_barrier_release_pattern[i];
1834 if (__kmp_env_format) {
1835 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1837 __kmp_str_buf_print(buffer,
" %s='",
1838 __kmp_barrier_pattern_env_name[i]);
1840 KMP_DEBUG_ASSERT(j < bp_last_bar && k < bp_last_bar);
1841 __kmp_str_buf_print(buffer,
"%s,%s'\n", __kmp_barrier_pattern_name[j],
1842 __kmp_barrier_pattern_name[k]);
1850static void __kmp_stg_parse_abort_delay(
char const *name,
char const *value,
1854 int delay = __kmp_abort_delay / 1000;
1855 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1856 __kmp_abort_delay = delay * 1000;
1859static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer,
char const *name,
1861 __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
1867static void __kmp_stg_parse_cpuinfo_file(
char const *name,
char const *value,
1869#if KMP_AFFINITY_SUPPORTED
1870 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1871 K_DIAG(1, (
"__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1875static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1876 char const *name,
void *data) {
1877#if KMP_AFFINITY_SUPPORTED
1878 if (__kmp_env_format) {
1879 KMP_STR_BUF_PRINT_NAME;
1881 __kmp_str_buf_print(buffer,
" %s", name);
1883 if (__kmp_cpuinfo_file) {
1884 __kmp_str_buf_print(buffer,
"='%s'\n", __kmp_cpuinfo_file);
1886 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
1894static void __kmp_stg_parse_force_reduction(
char const *name,
char const *value,
1896 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1899 rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1903 if (reduction->force) {
1905 if (__kmp_str_match(
"critical", 0, value))
1906 __kmp_force_reduction_method = critical_reduce_block;
1907 else if (__kmp_str_match(
"atomic", 0, value))
1908 __kmp_force_reduction_method = atomic_reduce_block;
1909 else if (__kmp_str_match(
"tree", 0, value))
1910 __kmp_force_reduction_method = tree_reduce_block;
1912 KMP_FATAL(UnknownForceReduction, name, value);
1916 __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1917 if (__kmp_determ_red) {
1918 __kmp_force_reduction_method = tree_reduce_block;
1920 __kmp_force_reduction_method = reduction_method_not_defined;
1923 K_DIAG(1, (
"__kmp_force_reduction_method == %d\n",
1924 __kmp_force_reduction_method));
1927static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1928 char const *name,
void *data) {
1930 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1931 if (reduction->force) {
1932 if (__kmp_force_reduction_method == critical_reduce_block) {
1933 __kmp_stg_print_str(buffer, name,
"critical");
1934 }
else if (__kmp_force_reduction_method == atomic_reduce_block) {
1935 __kmp_stg_print_str(buffer, name,
"atomic");
1936 }
else if (__kmp_force_reduction_method == tree_reduce_block) {
1937 __kmp_stg_print_str(buffer, name,
"tree");
1939 if (__kmp_env_format) {
1940 KMP_STR_BUF_PRINT_NAME;
1942 __kmp_str_buf_print(buffer,
" %s", name);
1944 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
1947 __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1955static void __kmp_stg_parse_storage_map(
char const *name,
char const *value,
1957 if (__kmp_str_match(
"verbose", 1, value)) {
1958 __kmp_storage_map = TRUE;
1959 __kmp_storage_map_verbose = TRUE;
1960 __kmp_storage_map_verbose_specified = TRUE;
1963 __kmp_storage_map_verbose = FALSE;
1964 __kmp_stg_parse_bool(name, value, &__kmp_storage_map);
1968static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer,
char const *name,
1970 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1971 __kmp_stg_print_str(buffer, name,
"verbose");
1973 __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1980static void __kmp_stg_parse_all_threadprivate(
char const *name,
1981 char const *value,
void *data) {
1982 __kmp_stg_parse_int(name, value,
1983 __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1984 __kmp_max_nth, &__kmp_tp_capacity);
1987static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1988 char const *name,
void *data) {
1989 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
1995static void __kmp_stg_parse_foreign_threads_threadprivate(
char const *name,
1998 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
2001static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
2004 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
2010static inline const char *
2011__kmp_hw_get_core_type_keyword(kmp_hw_core_type_t type) {
2013 case KMP_HW_CORE_TYPE_UNKNOWN:
2014 case KMP_HW_MAX_NUM_CORE_TYPES:
2016#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2017 case KMP_HW_CORE_TYPE_ATOM:
2018 return "intel_atom";
2019 case KMP_HW_CORE_TYPE_CORE:
2020 return "intel_core";
2023 KMP_ASSERT2(
false,
"Unhandled kmp_hw_core_type_t enumeration");
2024 KMP_BUILTIN_UNREACHABLE;
2027#if KMP_AFFINITY_SUPPORTED
2029static int __kmp_parse_affinity_proc_id_list(
const char *var,
const char *env,
2030 const char **nextEnv,
2032 const char *scan = env;
2033 const char *next = scan;
2039 int start, end, stride;
2043 if (*next ==
'\0') {
2054 if ((*next <
'0') || (*next >
'9')) {
2055 KMP_WARNING(AffSyntaxError, var);
2059 num = __kmp_str_to_int(scan, *next);
2060 KMP_ASSERT(num >= 0);
2078 if ((*next <
'0') || (*next >
'9')) {
2079 KMP_WARNING(AffSyntaxError, var);
2084 num = __kmp_str_to_int(scan, *next);
2085 KMP_ASSERT(num >= 0);
2098 if ((*next <
'0') || (*next >
'9')) {
2100 KMP_WARNING(AffSyntaxError, var);
2108 start = __kmp_str_to_int(scan, *next);
2109 KMP_ASSERT(start >= 0);
2128 if ((*next <
'0') || (*next >
'9')) {
2129 KMP_WARNING(AffSyntaxError, var);
2133 end = __kmp_str_to_int(scan, *next);
2134 KMP_ASSERT(end >= 0);
2151 if ((*next <
'0') || (*next >
'9')) {
2152 KMP_WARNING(AffSyntaxError, var);
2156 stride = __kmp_str_to_int(scan, *next);
2157 KMP_ASSERT(stride >= 0);
2163 KMP_WARNING(AffZeroStride, var);
2168 KMP_WARNING(AffStartGreaterEnd, var, start, end);
2173 KMP_WARNING(AffStrideLessZero, var, start, end);
2177 if ((end - start) / stride > 65536) {
2178 KMP_WARNING(AffRangeTooBig, var, end, start, stride);
2195 ptrdiff_t len = next - env;
2196 char *retlist = (
char *)__kmp_allocate((len + 1) *
sizeof(char));
2197 KMP_MEMCPY_S(retlist, (len + 1) *
sizeof(
char), env, len *
sizeof(
char));
2198 retlist[len] =
'\0';
2199 *proclist = retlist;
2206static kmp_setting_t *__kmp_affinity_notype = NULL;
2208static void __kmp_parse_affinity_env(
char const *name,
char const *value,
2209 kmp_affinity_t *out_affinity) {
2210 char *buffer = NULL;
2228 KMP_ASSERT(value != NULL);
2230 if (TCR_4(__kmp_init_middle)) {
2231 KMP_WARNING(EnvMiddleWarn, name);
2232 __kmp_env_toPrint(name, 0);
2235 __kmp_env_toPrint(name, 1);
2238 __kmp_str_format(
"%s", value);
2248#define EMIT_WARN(skip, errlist) \
2252 SKIP_TO(next, ','); \
2256 KMP_WARNING errlist; \
2265#define _set_param(_guard, _var, _val) \
2267 if (_guard == 0) { \
2270 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2275#define set_type(val) _set_param(type, out_affinity->type, val)
2276#define set_verbose(val) _set_param(verbose, out_affinity->flags.verbose, val)
2277#define set_warnings(val) \
2278 _set_param(warnings, out_affinity->flags.warnings, val)
2279#define set_respect(val) _set_param(respect, out_affinity->flags.respect, val)
2280#define set_dups(val) _set_param(dups, out_affinity->flags.dups, val)
2281#define set_proclist(val) _set_param(proclist, out_affinity->proclist, val)
2282#define set_reset(val) _set_param(reset, out_affinity->flags.reset, val)
2284#define set_gran(val, levels) \
2287 out_affinity->gran = val; \
2288 out_affinity->gran_levels = levels; \
2290 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2295 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
2296 (__kmp_nested_proc_bind.used > 0));
2298 while (*buf !=
'\0') {
2301 if (__kmp_match_str(
"none", buf, CCAST(
const char **, &next))) {
2302 set_type(affinity_none);
2303 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2305 }
else if (__kmp_match_str(
"scatter", buf, CCAST(
const char **, &next))) {
2306 set_type(affinity_scatter);
2307 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2309 }
else if (__kmp_match_str(
"compact", buf, CCAST(
const char **, &next))) {
2310 set_type(affinity_compact);
2311 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2313 }
else if (__kmp_match_str(
"logical", buf, CCAST(
const char **, &next))) {
2314 set_type(affinity_logical);
2315 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2317 }
else if (__kmp_match_str(
"physical", buf, CCAST(
const char **, &next))) {
2318 set_type(affinity_physical);
2319 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2321 }
else if (__kmp_match_str(
"explicit", buf, CCAST(
const char **, &next))) {
2322 set_type(affinity_explicit);
2323 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2325 }
else if (__kmp_match_str(
"balanced", buf, CCAST(
const char **, &next))) {
2326 set_type(affinity_balanced);
2327 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2329 }
else if (__kmp_match_str(
"disabled", buf, CCAST(
const char **, &next))) {
2330 set_type(affinity_disabled);
2331 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2333 }
else if (__kmp_match_str(
"verbose", buf, CCAST(
const char **, &next))) {
2336 }
else if (__kmp_match_str(
"noverbose", buf, CCAST(
const char **, &next))) {
2339 }
else if (__kmp_match_str(
"warnings", buf, CCAST(
const char **, &next))) {
2342 }
else if (__kmp_match_str(
"nowarnings", buf,
2343 CCAST(
const char **, &next))) {
2344 set_warnings(FALSE);
2346 }
else if (__kmp_match_str(
"respect", buf, CCAST(
const char **, &next))) {
2349 }
else if (__kmp_match_str(
"norespect", buf, CCAST(
const char **, &next))) {
2352 }
else if (__kmp_match_str(
"reset", buf, CCAST(
const char **, &next))) {
2355 }
else if (__kmp_match_str(
"noreset", buf, CCAST(
const char **, &next))) {
2358 }
else if (__kmp_match_str(
"duplicates", buf,
2359 CCAST(
const char **, &next)) ||
2360 __kmp_match_str(
"dups", buf, CCAST(
const char **, &next))) {
2363 }
else if (__kmp_match_str(
"noduplicates", buf,
2364 CCAST(
const char **, &next)) ||
2365 __kmp_match_str(
"nodups", buf, CCAST(
const char **, &next))) {
2368 }
else if (__kmp_match_str(
"granularity", buf,
2369 CCAST(
const char **, &next)) ||
2370 __kmp_match_str(
"gran", buf, CCAST(
const char **, &next))) {
2373 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2383 if (__kmp_match_str(
"core_type", buf, CCAST(
const char **, &next))) {
2384 set_gran(KMP_HW_CORE, -1);
2385 out_affinity->flags.core_types_gran = 1;
2388 }
else if (__kmp_match_str(
"core_efficiency", buf,
2389 CCAST(
const char **, &next)) ||
2390 __kmp_match_str(
"core_eff", buf,
2391 CCAST(
const char **, &next))) {
2392 set_gran(KMP_HW_CORE, -1);
2393 out_affinity->flags.core_effs_gran = 1;
2399 KMP_FOREACH_HW_TYPE(type) {
2400 const char *name = __kmp_hw_get_keyword(type);
2401 if (__kmp_match_str(name, buf, CCAST(
const char **, &next))) {
2411 if (__kmp_match_str(
"fine", buf, CCAST(
const char **, &next))) {
2412 set_gran(KMP_HW_THREAD, -1);
2415 }
else if (__kmp_match_str(
"package", buf,
2416 CCAST(
const char **, &next))) {
2417 set_gran(KMP_HW_SOCKET, -1);
2420 }
else if (__kmp_match_str(
"node", buf, CCAST(
const char **, &next))) {
2421 set_gran(KMP_HW_NUMA, -1);
2424#if KMP_GROUP_AFFINITY
2425 }
else if (__kmp_match_str(
"group", buf, CCAST(
const char **, &next))) {
2426 set_gran(KMP_HW_PROC_GROUP, -1);
2430 }
else if ((*buf >=
'0') && (*buf <=
'9')) {
2434 n = __kmp_str_to_int(buf, *next);
2437 set_gran(KMP_HW_UNKNOWN, n);
2440 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2444 }
else if (__kmp_match_str(
"proclist", buf, CCAST(
const char **, &next))) {
2445 char *temp_proclist;
2449 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2455 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2460 if (!__kmp_parse_affinity_proc_id_list(
2461 name, buf, CCAST(
const char **, &next), &temp_proclist)) {
2473 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2477 set_proclist(temp_proclist);
2478 }
else if ((*buf >=
'0') && (*buf <=
'9')) {
2483 n = __kmp_str_to_int(buf, *next);
2489 KMP_WARNING(AffManyParams, name, start);
2493 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2501 }
else if (*next !=
'\0') {
2502 const char *temp = next;
2503 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2515#undef set_granularity
2518 __kmp_str_free(&buffer);
2522 KMP_WARNING(AffProcListNoType, name);
2523 out_affinity->type = affinity_explicit;
2524 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2525 }
else if (out_affinity->type != affinity_explicit) {
2526 KMP_WARNING(AffProcListNotExplicit, name);
2527 KMP_ASSERT(out_affinity->proclist != NULL);
2528 KMP_INTERNAL_FREE(out_affinity->proclist);
2529 out_affinity->proclist = NULL;
2532 switch (out_affinity->type) {
2533 case affinity_logical:
2534 case affinity_physical: {
2536 out_affinity->offset = number[0];
2539 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
2542 case affinity_balanced: {
2544 out_affinity->compact = number[0];
2547 out_affinity->offset = number[1];
2550 if (__kmp_affinity.gran == KMP_HW_UNKNOWN) {
2551 int verbose = out_affinity->flags.verbose;
2552 int warnings = out_affinity->flags.warnings;
2553#if KMP_MIC_SUPPORTED
2554 if (__kmp_mic_type != non_mic) {
2555 if (verbose || warnings) {
2556 KMP_WARNING(AffGranUsing, out_affinity->env_var,
"fine");
2558 out_affinity->gran = KMP_HW_THREAD;
2562 if (verbose || warnings) {
2563 KMP_WARNING(AffGranUsing, out_affinity->env_var,
"core");
2565 out_affinity->gran = KMP_HW_CORE;
2569 case affinity_scatter:
2570 case affinity_compact: {
2572 out_affinity->compact = number[0];
2575 out_affinity->offset = number[1];
2578 case affinity_explicit: {
2579 if (out_affinity->proclist == NULL) {
2580 KMP_WARNING(AffNoProcList, name);
2581 out_affinity->type = affinity_none;
2584 KMP_WARNING(AffNoParam, name,
"explicit");
2587 case affinity_none: {
2589 KMP_WARNING(AffNoParam, name,
"none");
2592 case affinity_disabled: {
2594 KMP_WARNING(AffNoParam, name,
"disabled");
2597 case affinity_default: {
2599 KMP_WARNING(AffNoParam, name,
"default");
2608static void __kmp_stg_parse_affinity(
char const *name,
char const *value,
2610 kmp_setting_t **rivals = (kmp_setting_t **)data;
2613 rc = __kmp_stg_check_rivals(name, value, rivals);
2618 __kmp_parse_affinity_env(name, value, &__kmp_affinity);
2621static void __kmp_stg_parse_hh_affinity(
char const *name,
char const *value,
2623 __kmp_parse_affinity_env(name, value, &__kmp_hh_affinity);
2625 if (__kmp_hh_affinity.flags.reset) {
2626 KMP_WARNING(AffInvalidParam, name,
"reset");
2628 if (__kmp_hh_affinity.flags.respect != affinity_respect_mask_default) {
2629 KMP_WARNING(AffInvalidParam, name,
"respect");
2633static void __kmp_print_affinity_env(kmp_str_buf_t *buffer,
char const *name,
2634 const kmp_affinity_t &affinity) {
2635 bool is_hh_affinity = (&affinity == &__kmp_hh_affinity);
2636 if (__kmp_env_format) {
2637 KMP_STR_BUF_PRINT_NAME_EX(name);
2639 __kmp_str_buf_print(buffer,
" %s='", name);
2641 if (affinity.flags.verbose) {
2642 __kmp_str_buf_print(buffer,
"%s,",
"verbose");
2644 __kmp_str_buf_print(buffer,
"%s,",
"noverbose");
2646 if (affinity.flags.warnings) {
2647 __kmp_str_buf_print(buffer,
"%s,",
"warnings");
2649 __kmp_str_buf_print(buffer,
"%s,",
"nowarnings");
2651 if (KMP_AFFINITY_CAPABLE()) {
2654 if (!is_hh_affinity) {
2655 if (affinity.flags.respect) {
2656 __kmp_str_buf_print(buffer,
"%s,",
"respect");
2658 __kmp_str_buf_print(buffer,
"%s,",
"norespect");
2660 if (affinity.flags.reset) {
2661 __kmp_str_buf_print(buffer,
"%s,",
"reset");
2663 __kmp_str_buf_print(buffer,
"%s,",
"noreset");
2666 __kmp_str_buf_print(buffer,
"granularity=");
2667 if (affinity.flags.core_types_gran)
2668 __kmp_str_buf_print(buffer,
"core_type,");
2669 else if (affinity.flags.core_effs_gran) {
2670 __kmp_str_buf_print(buffer,
"core_eff,");
2672 __kmp_str_buf_print(
2673 buffer,
"%s,", __kmp_hw_get_keyword(affinity.gran,
false));
2676 if (!KMP_AFFINITY_CAPABLE()) {
2677 __kmp_str_buf_print(buffer,
"%s",
"disabled");
2679 int compact = affinity.compact;
2680 int offset = affinity.offset;
2681 switch (affinity.type) {
2683 __kmp_str_buf_print(buffer,
"%s",
"none");
2685 case affinity_physical:
2686 __kmp_str_buf_print(buffer,
"%s,%d",
"physical", offset);
2688 case affinity_logical:
2689 __kmp_str_buf_print(buffer,
"%s,%d",
"logical", offset);
2691 case affinity_compact:
2692 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"compact", compact, offset);
2694 case affinity_scatter:
2695 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"scatter", compact, offset);
2697 case affinity_explicit:
2698 __kmp_str_buf_print(buffer,
"%s=[%s],%s",
"proclist", affinity.proclist,
2701 case affinity_balanced:
2702 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"balanced", compact, offset);
2704 case affinity_disabled:
2705 __kmp_str_buf_print(buffer,
"%s",
"disabled");
2707 case affinity_default:
2708 __kmp_str_buf_print(buffer,
"%s",
"default");
2711 __kmp_str_buf_print(buffer,
"%s",
"<unknown>");
2715 __kmp_str_buf_print(buffer,
"'\n");
2718static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer,
char const *name,
2720 __kmp_print_affinity_env(buffer, name, __kmp_affinity);
2722static void __kmp_stg_print_hh_affinity(kmp_str_buf_t *buffer,
char const *name,
2724 __kmp_print_affinity_env(buffer, name, __kmp_hh_affinity);
2727#ifdef KMP_GOMP_COMPAT
2729static void __kmp_stg_parse_gomp_cpu_affinity(
char const *name,
2730 char const *value,
void *data) {
2731 const char *next = NULL;
2732 char *temp_proclist;
2733 kmp_setting_t **rivals = (kmp_setting_t **)data;
2736 rc = __kmp_stg_check_rivals(name, value, rivals);
2741 if (TCR_4(__kmp_init_middle)) {
2742 KMP_WARNING(EnvMiddleWarn, name);
2743 __kmp_env_toPrint(name, 0);
2747 __kmp_env_toPrint(name, 1);
2749 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2751 if (*next ==
'\0') {
2753 __kmp_affinity.proclist = temp_proclist;
2754 __kmp_affinity.type = affinity_explicit;
2755 __kmp_affinity.gran = KMP_HW_THREAD;
2756 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2758 KMP_WARNING(AffSyntaxError, name);
2759 if (temp_proclist != NULL) {
2760 KMP_INTERNAL_FREE((
void *)temp_proclist);
2765 __kmp_affinity.type = affinity_none;
2766 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2793static int __kmp_parse_subplace_list(
const char *var,
const char **scan) {
2797 int start, count, stride;
2803 if ((**scan <
'0') || (**scan >
'9')) {
2808 start = __kmp_str_to_int(*scan, *next);
2809 KMP_ASSERT(start >= 0);
2814 if (**scan ==
'}') {
2817 if (**scan ==
',') {
2821 if (**scan !=
':') {
2828 if ((**scan <
'0') || (**scan >
'9')) {
2833 count = __kmp_str_to_int(*scan, *next);
2834 KMP_ASSERT(count >= 0);
2839 if (**scan ==
'}') {
2842 if (**scan ==
',') {
2846 if (**scan !=
':') {
2855 if (**scan ==
'+') {
2859 if (**scan ==
'-') {
2867 if ((**scan <
'0') || (**scan >
'9')) {
2872 stride = __kmp_str_to_int(*scan, *next);
2873 KMP_ASSERT(stride >= 0);
2879 if (**scan ==
'}') {
2882 if (**scan ==
',') {
2892static int __kmp_parse_place(
const char *var,
const char **scan) {
2897 if (**scan ==
'{') {
2899 if (!__kmp_parse_subplace_list(var, scan)) {
2902 if (**scan !=
'}') {
2906 }
else if (**scan ==
'!') {
2908 return __kmp_parse_place(var, scan);
2909 }
else if ((**scan >=
'0') && (**scan <=
'9')) {
2912 int proc = __kmp_str_to_int(*scan, *next);
2913 KMP_ASSERT(proc >= 0);
2922static int __kmp_parse_place_list(
const char *var,
const char *env,
2923 char **place_list) {
2924 const char *scan = env;
2925 const char *next = scan;
2930 if (!__kmp_parse_place(var, &scan)) {
2936 if (*scan ==
'\0') {
2950 if ((*scan <
'0') || (*scan >
'9')) {
2955 count = __kmp_str_to_int(scan, *next);
2956 KMP_ASSERT(count >= 0);
2961 if (*scan ==
'\0') {
2989 if ((*scan <
'0') || (*scan >
'9')) {
2994 stride = __kmp_str_to_int(scan, *next);
2995 KMP_ASSERT(stride >= 0);
3001 if (*scan ==
'\0') {
3013 ptrdiff_t len = scan - env;
3014 char *retlist = (
char *)__kmp_allocate((len + 1) *
sizeof(char));
3015 KMP_MEMCPY_S(retlist, (len + 1) *
sizeof(
char), env, len *
sizeof(
char));
3016 retlist[len] =
'\0';
3017 *place_list = retlist;
3022static inline void __kmp_places_set(
enum affinity_type type, kmp_hw_t kind) {
3023 __kmp_affinity.type = type;
3024 __kmp_affinity.gran = kind;
3025 __kmp_affinity.flags.dups = FALSE;
3026 __kmp_affinity.flags.omp_places = TRUE;
3029static void __kmp_places_syntax_error_fallback(
char const *name,
3031 const char *str = __kmp_hw_get_catalog_string(kind,
true);
3032 KMP_WARNING(SyntaxErrorUsing, name, str);
3033 __kmp_places_set(affinity_compact, kind);
3034 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default)
3035 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3038static void __kmp_stg_parse_places(
char const *name,
char const *value,
3040 struct kmp_place_t {
3046 const char *scan = value;
3047 const char *next = scan;
3048 kmp_place_t std_places[] = {{
"threads", KMP_HW_THREAD},
3049 {
"cores", KMP_HW_CORE},
3050 {
"numa_domains", KMP_HW_NUMA},
3051 {
"ll_caches", KMP_HW_LLC},
3052 {
"sockets", KMP_HW_SOCKET}};
3053 kmp_setting_t **rivals = (kmp_setting_t **)data;
3056 rc = __kmp_stg_check_rivals(name, value, rivals);
3062 for (
size_t i = 0; i <
sizeof(std_places) /
sizeof(std_places[0]); ++i) {
3063 const kmp_place_t &place = std_places[i];
3064 if (__kmp_match_str(place.name, scan, &next)) {
3066 __kmp_places_set(affinity_compact, place.type);
3069 if (KMP_HW_MAX_NUM_CORE_TYPES > 1) {
3072 if (place.type != KMP_HW_CORE) {
3073 __kmp_places_syntax_error_fallback(name, place.type);
3078#if KMP_ARCH_X86 || KMP_ARCH_X86_64
3079 if (__kmp_match_str(
"intel_core", scan, &next)) {
3080 __kmp_affinity.core_attr_gran.core_type = KMP_HW_CORE_TYPE_CORE;
3081 __kmp_affinity.core_attr_gran.valid = 1;
3083 }
else if (__kmp_match_str(
"intel_atom", scan, &next)) {
3084 __kmp_affinity.core_attr_gran.core_type = KMP_HW_CORE_TYPE_ATOM;
3085 __kmp_affinity.core_attr_gran.valid = 1;
3089 if (__kmp_match_str(
"eff", scan, &next)) {
3091 if (!isdigit(*next)) {
3092 __kmp_places_syntax_error_fallback(name, place.type);
3097 eff = __kmp_str_to_int(scan, *next);
3099 __kmp_places_syntax_error_fallback(name, place.type);
3102 if (eff >= KMP_HW_MAX_NUM_CORE_EFFS)
3103 eff = KMP_HW_MAX_NUM_CORE_EFFS - 1;
3104 __kmp_affinity.core_attr_gran.core_eff = eff;
3105 __kmp_affinity.core_attr_gran.valid = 1;
3108 if (!__kmp_affinity.core_attr_gran.valid) {
3109 __kmp_places_syntax_error_fallback(name, place.type);
3119 KMP_FOREACH_HW_TYPE(type) {
3120 const char *name = __kmp_hw_get_keyword(type,
true);
3121 if (__kmp_match_str(
"unknowns", scan, &next))
3123 if (__kmp_match_str(name, scan, &next)) {
3125 __kmp_places_set(affinity_compact, type);
3133 if (__kmp_match_str(
"core_types", scan, &next)) {
3135 if (*scan !=
'\0') {
3136 KMP_WARNING(ParseExtraCharsWarn, name, scan);
3138 __kmp_places_set(affinity_compact, KMP_HW_CORE);
3139 __kmp_affinity.flags.core_types_gran = 1;
3141 }
else if (__kmp_match_str(
"core_effs", scan, &next) ||
3142 __kmp_match_str(
"core_efficiencies", scan, &next)) {
3144 if (*scan !=
'\0') {
3145 KMP_WARNING(ParseExtraCharsWarn, name, scan);
3147 __kmp_places_set(affinity_compact, KMP_HW_CORE);
3148 __kmp_affinity.flags.core_effs_gran = 1;
3154 if (__kmp_affinity.proclist != NULL) {
3155 KMP_INTERNAL_FREE((
void *)__kmp_affinity.proclist);
3156 __kmp_affinity.proclist = NULL;
3158 if (__kmp_parse_place_list(name, value, &__kmp_affinity.proclist)) {
3159 __kmp_places_set(affinity_explicit, KMP_HW_THREAD);
3162 __kmp_places_syntax_error_fallback(name, KMP_HW_CORE);
3164 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
3165 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3170 kmp_hw_t gran = __kmp_affinity.gran;
3171 if (__kmp_affinity.gran != KMP_HW_UNKNOWN) {
3172 gran = __kmp_affinity.gran;
3177 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
3178 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3182 if (*scan ==
'\0') {
3188 __kmp_places_syntax_error_fallback(name, gran);
3196 count = __kmp_str_to_int(scan, *next);
3197 KMP_ASSERT(count >= 0);
3202 __kmp_places_syntax_error_fallback(name, gran);
3208 if (*scan !=
'\0') {
3209 KMP_WARNING(ParseExtraCharsWarn, name, scan);
3211 __kmp_affinity_num_places = count;
3214static void __kmp_stg_print_places(kmp_str_buf_t *buffer,
char const *name,
3216 enum affinity_type type = __kmp_affinity.type;
3217 const char *proclist = __kmp_affinity.proclist;
3218 kmp_hw_t gran = __kmp_affinity.gran;
3220 if (__kmp_env_format) {
3221 KMP_STR_BUF_PRINT_NAME;
3223 __kmp_str_buf_print(buffer,
" %s", name);
3225 if ((__kmp_nested_proc_bind.used == 0) ||
3226 (__kmp_nested_proc_bind.bind_types == NULL) ||
3227 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
3228 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3229 }
else if (type == affinity_explicit) {
3230 if (proclist != NULL) {
3231 __kmp_str_buf_print(buffer,
"='%s'\n", proclist);
3233 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3235 }
else if (type == affinity_compact) {
3237 if (__kmp_affinity.num_masks > 0) {
3238 num = __kmp_affinity.num_masks;
3239 }
else if (__kmp_affinity_num_places > 0) {
3240 num = __kmp_affinity_num_places;
3244 if (gran != KMP_HW_UNKNOWN) {
3246 if (__kmp_affinity.flags.core_types_gran) {
3247 __kmp_str_buf_print(buffer,
"='%s'\n",
"core_types");
3250 if (__kmp_affinity.flags.core_effs_gran) {
3251 __kmp_str_buf_print(buffer,
"='%s'\n",
"core_effs");
3256 const char *name = __kmp_hw_get_keyword(gran,
true);
3257 __kmp_str_buf_print(buffer,
"='%s", name);
3260 if (__kmp_affinity.core_attr_gran.valid) {
3261 kmp_hw_core_type_t ct =
3262 (kmp_hw_core_type_t)__kmp_affinity.core_attr_gran.core_type;
3263 int eff = __kmp_affinity.core_attr_gran.core_eff;
3264 if (ct != KMP_HW_CORE_TYPE_UNKNOWN) {
3265 const char *ct_name = __kmp_hw_get_core_type_keyword(ct);
3266 __kmp_str_buf_print(buffer,
":%s", name, ct_name);
3267 }
else if (eff >= 0 && eff < KMP_HW_MAX_NUM_CORE_EFFS) {
3268 __kmp_str_buf_print(buffer,
":eff%d", name, eff);
3274 __kmp_str_buf_print(buffer,
"(%d)", num);
3275 __kmp_str_buf_print(buffer,
"'\n");
3277 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3280 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3284static void __kmp_stg_parse_topology_method(
char const *name,
char const *value,
3286 if (__kmp_str_match(
"all", 1, value)) {
3287 __kmp_affinity_top_method = affinity_top_method_all;
3290 else if (__kmp_str_match(
"hwloc", 1, value)) {
3291 __kmp_affinity_top_method = affinity_top_method_hwloc;
3294#if KMP_ARCH_X86 || KMP_ARCH_X86_64
3295 else if (__kmp_str_match(
"cpuid_leaf31", 12, value) ||
3296 __kmp_str_match(
"cpuid 1f", 8, value) ||
3297 __kmp_str_match(
"cpuid 31", 8, value) ||
3298 __kmp_str_match(
"cpuid1f", 7, value) ||
3299 __kmp_str_match(
"cpuid31", 7, value) ||
3300 __kmp_str_match(
"leaf 1f", 7, value) ||
3301 __kmp_str_match(
"leaf 31", 7, value) ||
3302 __kmp_str_match(
"leaf1f", 6, value) ||
3303 __kmp_str_match(
"leaf31", 6, value)) {
3304 __kmp_affinity_top_method = affinity_top_method_x2apicid_1f;
3305 }
else if (__kmp_str_match(
"x2apic id", 9, value) ||
3306 __kmp_str_match(
"x2apic_id", 9, value) ||
3307 __kmp_str_match(
"x2apic-id", 9, value) ||
3308 __kmp_str_match(
"x2apicid", 8, value) ||
3309 __kmp_str_match(
"cpuid leaf 11", 13, value) ||
3310 __kmp_str_match(
"cpuid_leaf_11", 13, value) ||
3311 __kmp_str_match(
"cpuid-leaf-11", 13, value) ||
3312 __kmp_str_match(
"cpuid leaf11", 12, value) ||
3313 __kmp_str_match(
"cpuid_leaf11", 12, value) ||
3314 __kmp_str_match(
"cpuid-leaf11", 12, value) ||
3315 __kmp_str_match(
"cpuidleaf 11", 12, value) ||
3316 __kmp_str_match(
"cpuidleaf_11", 12, value) ||
3317 __kmp_str_match(
"cpuidleaf-11", 12, value) ||
3318 __kmp_str_match(
"cpuidleaf11", 11, value) ||
3319 __kmp_str_match(
"cpuid 11", 8, value) ||
3320 __kmp_str_match(
"cpuid_11", 8, value) ||
3321 __kmp_str_match(
"cpuid-11", 8, value) ||
3322 __kmp_str_match(
"cpuid11", 7, value) ||
3323 __kmp_str_match(
"leaf 11", 7, value) ||
3324 __kmp_str_match(
"leaf_11", 7, value) ||
3325 __kmp_str_match(
"leaf-11", 7, value) ||
3326 __kmp_str_match(
"leaf11", 6, value)) {
3327 __kmp_affinity_top_method = affinity_top_method_x2apicid;
3328 }
else if (__kmp_str_match(
"apic id", 7, value) ||
3329 __kmp_str_match(
"apic_id", 7, value) ||
3330 __kmp_str_match(
"apic-id", 7, value) ||
3331 __kmp_str_match(
"apicid", 6, value) ||
3332 __kmp_str_match(
"cpuid leaf 4", 12, value) ||
3333 __kmp_str_match(
"cpuid_leaf_4", 12, value) ||
3334 __kmp_str_match(
"cpuid-leaf-4", 12, value) ||
3335 __kmp_str_match(
"cpuid leaf4", 11, value) ||
3336 __kmp_str_match(
"cpuid_leaf4", 11, value) ||
3337 __kmp_str_match(
"cpuid-leaf4", 11, value) ||
3338 __kmp_str_match(
"cpuidleaf 4", 11, value) ||
3339 __kmp_str_match(
"cpuidleaf_4", 11, value) ||
3340 __kmp_str_match(
"cpuidleaf-4", 11, value) ||
3341 __kmp_str_match(
"cpuidleaf4", 10, value) ||
3342 __kmp_str_match(
"cpuid 4", 7, value) ||
3343 __kmp_str_match(
"cpuid_4", 7, value) ||
3344 __kmp_str_match(
"cpuid-4", 7, value) ||
3345 __kmp_str_match(
"cpuid4", 6, value) ||
3346 __kmp_str_match(
"leaf 4", 6, value) ||
3347 __kmp_str_match(
"leaf_4", 6, value) ||
3348 __kmp_str_match(
"leaf-4", 6, value) ||
3349 __kmp_str_match(
"leaf4", 5, value)) {
3350 __kmp_affinity_top_method = affinity_top_method_apicid;
3353 else if (__kmp_str_match(
"/proc/cpuinfo", 2, value) ||
3354 __kmp_str_match(
"cpuinfo", 5, value)) {
3355 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
3357#if KMP_GROUP_AFFINITY
3358 else if (__kmp_str_match(
"group", 1, value)) {
3359 KMP_WARNING(StgDeprecatedValue, name, value,
"all");
3360 __kmp_affinity_top_method = affinity_top_method_group;
3363 else if (__kmp_str_match(
"flat", 1, value)) {
3364 __kmp_affinity_top_method = affinity_top_method_flat;
3366 KMP_WARNING(StgInvalidValue, name, value);
3370static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
3371 char const *name,
void *data) {
3372 char const *value = NULL;
3374 switch (__kmp_affinity_top_method) {
3375 case affinity_top_method_default:
3379 case affinity_top_method_all:
3383#if KMP_ARCH_X86 || KMP_ARCH_X86_64
3384 case affinity_top_method_x2apicid_1f:
3385 value =
"x2APIC id leaf 0x1f";
3388 case affinity_top_method_x2apicid:
3389 value =
"x2APIC id leaf 0xb";
3392 case affinity_top_method_apicid:
3398 case affinity_top_method_hwloc:
3403 case affinity_top_method_cpuinfo:
3407#if KMP_GROUP_AFFINITY
3408 case affinity_top_method_group:
3413 case affinity_top_method_flat:
3418 if (value != NULL) {
3419 __kmp_stg_print_str(buffer, name, value);
3424struct kmp_proc_bind_info_t {
3426 kmp_proc_bind_t proc_bind;
3428static kmp_proc_bind_info_t proc_bind_table[] = {
3429 {
"spread", proc_bind_spread},
3430 {
"true", proc_bind_spread},
3431 {
"close", proc_bind_close},
3433 {
"false", proc_bind_primary},
3434 {
"primary", proc_bind_primary}};
3435static void __kmp_stg_parse_teams_proc_bind(
char const *name,
char const *value,
3440 for (
size_t i = 0; i <
sizeof(proc_bind_table) /
sizeof(proc_bind_table[0]);
3442 if (__kmp_match_str(proc_bind_table[i].name, value, &end)) {
3443 __kmp_teams_proc_bind = proc_bind_table[i].proc_bind;
3449 KMP_WARNING(StgInvalidValue, name, value);
3452static void __kmp_stg_print_teams_proc_bind(kmp_str_buf_t *buffer,
3453 char const *name,
void *data) {
3454 const char *value = KMP_I18N_STR(NotDefined);
3455 for (
size_t i = 0; i <
sizeof(proc_bind_table) /
sizeof(proc_bind_table[0]);
3457 if (__kmp_teams_proc_bind == proc_bind_table[i].proc_bind) {
3458 value = proc_bind_table[i].name;
3462 __kmp_stg_print_str(buffer, name, value);
3468static void __kmp_stg_parse_proc_bind(
char const *name,
char const *value,
3470 kmp_setting_t **rivals = (kmp_setting_t **)data;
3473 rc = __kmp_stg_check_rivals(name, value, rivals);
3479 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
3480 (__kmp_nested_proc_bind.used > 0));
3482 const char *buf = value;
3486 if ((*buf >=
'0') && (*buf <=
'9')) {
3489 num = __kmp_str_to_int(buf, *next);
3490 KMP_ASSERT(num >= 0);
3498 if (__kmp_match_str(
"disabled", buf, &next)) {
3501#if KMP_AFFINITY_SUPPORTED
3502 __kmp_affinity.type = affinity_disabled;
3504 __kmp_nested_proc_bind.used = 1;
3505 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3506 }
else if ((num == (
int)proc_bind_false) ||
3507 __kmp_match_str(
"false", buf, &next)) {
3510#if KMP_AFFINITY_SUPPORTED
3511 __kmp_affinity.type = affinity_none;
3513 __kmp_nested_proc_bind.used = 1;
3514 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3515 }
else if ((num == (
int)proc_bind_true) ||
3516 __kmp_match_str(
"true", buf, &next)) {
3519 __kmp_nested_proc_bind.used = 1;
3520 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3525 for (scan = buf; *scan !=
'\0'; scan++) {
3532 if (__kmp_nested_proc_bind.size < nelem) {
3533 __kmp_nested_proc_bind.bind_types =
3534 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3535 __kmp_nested_proc_bind.bind_types,
3536 sizeof(kmp_proc_bind_t) * nelem);
3537 if (__kmp_nested_proc_bind.bind_types == NULL) {
3538 KMP_FATAL(MemoryAllocFailed);
3540 __kmp_nested_proc_bind.size = nelem;
3542 __kmp_nested_proc_bind.used = nelem;
3544 if (nelem > 1 && !__kmp_dflt_max_active_levels_set)
3545 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
3550 enum kmp_proc_bind_t bind;
3552 if ((num == (
int)proc_bind_primary) ||
3553 __kmp_match_str(
"master", buf, &next) ||
3554 __kmp_match_str(
"primary", buf, &next)) {
3557 bind = proc_bind_primary;
3558 }
else if ((num == (
int)proc_bind_close) ||
3559 __kmp_match_str(
"close", buf, &next)) {
3562 bind = proc_bind_close;
3563 }
else if ((num == (
int)proc_bind_spread) ||
3564 __kmp_match_str(
"spread", buf, &next)) {
3567 bind = proc_bind_spread;
3569 KMP_WARNING(StgInvalidValue, name, value);
3570 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3571 __kmp_nested_proc_bind.used = 1;
3575 __kmp_nested_proc_bind.bind_types[i++] = bind;
3579 KMP_DEBUG_ASSERT(*buf ==
',');
3584 if ((*buf >=
'0') && (*buf <=
'9')) {
3587 num = __kmp_str_to_int(buf, *next);
3588 KMP_ASSERT(num >= 0);
3598 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3602static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer,
char const *name,
3604 int nelem = __kmp_nested_proc_bind.used;
3605 if (__kmp_env_format) {
3606 KMP_STR_BUF_PRINT_NAME;
3608 __kmp_str_buf_print(buffer,
" %s", name);
3611 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3614 __kmp_str_buf_print(buffer,
"='", name);
3615 for (i = 0; i < nelem; i++) {
3616 switch (__kmp_nested_proc_bind.bind_types[i]) {
3617 case proc_bind_false:
3618 __kmp_str_buf_print(buffer,
"false");
3621 case proc_bind_true:
3622 __kmp_str_buf_print(buffer,
"true");
3625 case proc_bind_primary:
3626 __kmp_str_buf_print(buffer,
"primary");
3629 case proc_bind_close:
3630 __kmp_str_buf_print(buffer,
"close");
3633 case proc_bind_spread:
3634 __kmp_str_buf_print(buffer,
"spread");
3637 case proc_bind_intel:
3638 __kmp_str_buf_print(buffer,
"intel");
3641 case proc_bind_default:
3642 __kmp_str_buf_print(buffer,
"default");
3645 if (i < nelem - 1) {
3646 __kmp_str_buf_print(buffer,
",");
3649 __kmp_str_buf_print(buffer,
"'\n");
3653static void __kmp_stg_parse_display_affinity(
char const *name,
3654 char const *value,
void *data) {
3655 __kmp_stg_parse_bool(name, value, &__kmp_display_affinity);
3657static void __kmp_stg_print_display_affinity(kmp_str_buf_t *buffer,
3658 char const *name,
void *data) {
3659 __kmp_stg_print_bool(buffer, name, __kmp_display_affinity);
3661static void __kmp_stg_parse_affinity_format(
char const *name,
char const *value,
3663 size_t length = KMP_STRLEN(value);
3664 __kmp_strncpy_truncate(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, value,
3667static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer,
3668 char const *name,
void *data) {
3669 if (__kmp_env_format) {
3670 KMP_STR_BUF_PRINT_NAME_EX(name);
3672 __kmp_str_buf_print(buffer,
" %s='", name);
3674 __kmp_str_buf_print(buffer,
"%s'\n", __kmp_affinity_format);
3696static void __kmp_stg_parse_allocator(
char const *name,
char const *value,
3698 const char *buf = value;
3699 const char *next, *scan, *start;
3701 omp_allocator_handle_t al;
3702 omp_memspace_handle_t ms = omp_default_mem_space;
3703 bool is_memspace =
false;
3704 int ntraits = 0, count = 0;
3708 const char *delim = strchr(buf,
':');
3709 const char *predef_mem_space = strstr(buf,
"mem_space");
3711 bool is_memalloc = (!predef_mem_space && !delim) ?
true : false;
3716 for (scan = buf; *scan !=
'\0'; scan++) {
3721 omp_alloctrait_t *traits =
3722 (omp_alloctrait_t *)KMP_ALLOCA(ntraits *
sizeof(omp_alloctrait_t));
3725#define IS_POWER_OF_TWO(n) (((n) & ((n)-1)) == 0)
3727#define GET_NEXT(sentinel) \
3730 if (*next == sentinel) \
3736#define SKIP_PAIR(key) \
3738 char const str_delimiter[] = {',', 0}; \
3739 char *value = __kmp_str_token(CCAST(char *, scan), str_delimiter, \
3740 CCAST(char **, &next)); \
3741 KMP_WARNING(StgInvalidValue, key, value); \
3749 char const str_delimiter[] = {'=', 0}; \
3750 key = __kmp_str_token(CCAST(char *, start), str_delimiter, \
3751 CCAST(char **, &next)); \
3756 while (*next !=
'\0') {
3758 __kmp_match_str(
"fb_data", scan, &next)) {
3762 if (__kmp_match_str(
"omp_high_bw_mem_alloc", scan, &next)) {
3765 if (__kmp_memkind_available) {
3766 __kmp_def_allocator = omp_high_bw_mem_alloc;
3769 KMP_WARNING(OmpNoAllocator,
"omp_high_bw_mem_alloc");
3772 traits[count].key = omp_atk_fb_data;
3773 traits[count].value = RCAST(omp_uintptr_t, omp_high_bw_mem_alloc);
3775 }
else if (__kmp_match_str(
"omp_large_cap_mem_alloc", scan, &next)) {
3778 if (__kmp_memkind_available) {
3779 __kmp_def_allocator = omp_large_cap_mem_alloc;
3782 KMP_WARNING(OmpNoAllocator,
"omp_large_cap_mem_alloc");
3785 traits[count].key = omp_atk_fb_data;
3786 traits[count].value = RCAST(omp_uintptr_t, omp_large_cap_mem_alloc);
3788 }
else if (__kmp_match_str(
"omp_default_mem_alloc", scan, &next)) {
3792 traits[count].key = omp_atk_fb_data;
3793 traits[count].value = RCAST(omp_uintptr_t, omp_default_mem_alloc);
3795 }
else if (__kmp_match_str(
"omp_const_mem_alloc", scan, &next)) {
3798 KMP_WARNING(OmpNoAllocator,
"omp_const_mem_alloc");
3800 traits[count].key = omp_atk_fb_data;
3801 traits[count].value = RCAST(omp_uintptr_t, omp_const_mem_alloc);
3803 }
else if (__kmp_match_str(
"omp_low_lat_mem_alloc", scan, &next)) {
3806 KMP_WARNING(OmpNoAllocator,
"omp_low_lat_mem_alloc");
3808 traits[count].key = omp_atk_fb_data;
3809 traits[count].value = RCAST(omp_uintptr_t, omp_low_lat_mem_alloc);
3811 }
else if (__kmp_match_str(
"omp_cgroup_mem_alloc", scan, &next)) {
3814 KMP_WARNING(OmpNoAllocator,
"omp_cgroup_mem_alloc");
3816 traits[count].key = omp_atk_fb_data;
3817 traits[count].value = RCAST(omp_uintptr_t, omp_cgroup_mem_alloc);
3819 }
else if (__kmp_match_str(
"omp_pteam_mem_alloc", scan, &next)) {
3822 KMP_WARNING(OmpNoAllocator,
"omp_pteam_mem_alloc");
3824 traits[count].key = omp_atk_fb_data;
3825 traits[count].value = RCAST(omp_uintptr_t, omp_pteam_mem_alloc);
3827 }
else if (__kmp_match_str(
"omp_thread_mem_alloc", scan, &next)) {
3830 KMP_WARNING(OmpNoAllocator,
"omp_thread_mem_alloc");
3832 traits[count].key = omp_atk_fb_data;
3833 traits[count].value = RCAST(omp_uintptr_t, omp_thread_mem_alloc);
3843 __kmp_def_allocator = omp_default_mem_alloc;
3844 if (next == buf || *next !=
'\0') {
3846 KMP_WARNING(StgInvalidValue, name, value);
3851 if (count == ntraits)
3857 if (__kmp_match_str(
"omp_default_mem_space", scan, &next)) {
3859 ms = omp_default_mem_space;
3860 }
else if (__kmp_match_str(
"omp_large_cap_mem_space", scan, &next)) {
3862 ms = omp_large_cap_mem_space;
3863 }
else if (__kmp_match_str(
"omp_const_mem_space", scan, &next)) {
3865 ms = omp_const_mem_space;
3866 }
else if (__kmp_match_str(
"omp_high_bw_mem_space", scan, &next)) {
3868 ms = omp_high_bw_mem_space;
3869 }
else if (__kmp_match_str(
"omp_low_lat_mem_space", scan, &next)) {
3871 ms = omp_low_lat_mem_space;
3873 __kmp_def_allocator = omp_default_mem_alloc;
3874 if (next == buf || *next !=
'\0') {
3876 KMP_WARNING(StgInvalidValue, name, value);
3885 if (__kmp_match_str(
"sync_hint", scan, &next)) {
3887 traits[count].key = omp_atk_sync_hint;
3888 if (__kmp_match_str(
"contended", scan, &next)) {
3889 traits[count].value = omp_atv_contended;
3890 }
else if (__kmp_match_str(
"uncontended", scan, &next)) {
3891 traits[count].value = omp_atv_uncontended;
3892 }
else if (__kmp_match_str(
"serialized", scan, &next)) {
3893 traits[count].value = omp_atv_serialized;
3894 }
else if (__kmp_match_str(
"private", scan, &next)) {
3895 traits[count].value = omp_atv_private;
3901 }
else if (__kmp_match_str(
"alignment", scan, &next)) {
3903 if (!isdigit(*next)) {
3909 int n = __kmp_str_to_int(scan,
',');
3910 if (n < 0 || !IS_POWER_OF_TWO(n)) {
3915 traits[count].key = omp_atk_alignment;
3916 traits[count].value = n;
3917 }
else if (__kmp_match_str(
"access", scan, &next)) {
3919 traits[count].key = omp_atk_access;
3920 if (__kmp_match_str(
"all", scan, &next)) {
3921 traits[count].value = omp_atv_all;
3922 }
else if (__kmp_match_str(
"cgroup", scan, &next)) {
3923 traits[count].value = omp_atv_cgroup;
3924 }
else if (__kmp_match_str(
"pteam", scan, &next)) {
3925 traits[count].value = omp_atv_pteam;
3926 }
else if (__kmp_match_str(
"thread", scan, &next)) {
3927 traits[count].value = omp_atv_thread;
3933 }
else if (__kmp_match_str(
"pool_size", scan, &next)) {
3935 if (!isdigit(*next)) {
3941 int n = __kmp_str_to_int(scan,
',');
3947 traits[count].key = omp_atk_pool_size;
3948 traits[count].value = n;
3949 }
else if (__kmp_match_str(
"fallback", scan, &next)) {
3951 traits[count].key = omp_atk_fallback;
3952 if (__kmp_match_str(
"default_mem_fb", scan, &next)) {
3953 traits[count].value = omp_atv_default_mem_fb;
3954 }
else if (__kmp_match_str(
"null_fb", scan, &next)) {
3955 traits[count].value = omp_atv_null_fb;
3956 }
else if (__kmp_match_str(
"abort_fb", scan, &next)) {
3957 traits[count].value = omp_atv_abort_fb;
3958 }
else if (__kmp_match_str(
"allocator_fb", scan, &next)) {
3959 traits[count].value = omp_atv_allocator_fb;
3965 }
else if (__kmp_match_str(
"pinned", scan, &next)) {
3967 traits[count].key = omp_atk_pinned;
3968 if (__kmp_str_match_true(next)) {
3969 traits[count].value = omp_atv_true;
3970 }
else if (__kmp_str_match_false(next)) {
3971 traits[count].value = omp_atv_false;
3977 }
else if (__kmp_match_str(
"partition", scan, &next)) {
3979 traits[count].key = omp_atk_partition;
3980 if (__kmp_match_str(
"environment", scan, &next)) {
3981 traits[count].value = omp_atv_environment;
3982 }
else if (__kmp_match_str(
"nearest", scan, &next)) {
3983 traits[count].value = omp_atv_nearest;
3984 }
else if (__kmp_match_str(
"blocked", scan, &next)) {
3985 traits[count].value = omp_atv_blocked;
3986 }
else if (__kmp_match_str(
"interleaved", scan, &next)) {
3987 traits[count].value = omp_atv_interleaved;
4000 if (count == ntraits)
4006 al = __kmpc_init_allocator(__kmp_get_gtid(), ms, ntraits, traits);
4007 __kmp_def_allocator = (al == omp_null_allocator) ? omp_default_mem_alloc : al;
4010static void __kmp_stg_print_allocator(kmp_str_buf_t *buffer,
char const *name,
4012 if (__kmp_def_allocator == omp_default_mem_alloc) {
4013 __kmp_stg_print_str(buffer, name,
"omp_default_mem_alloc");
4014 }
else if (__kmp_def_allocator == omp_high_bw_mem_alloc) {
4015 __kmp_stg_print_str(buffer, name,
"omp_high_bw_mem_alloc");
4016 }
else if (__kmp_def_allocator == omp_large_cap_mem_alloc) {
4017 __kmp_stg_print_str(buffer, name,
"omp_large_cap_mem_alloc");
4018 }
else if (__kmp_def_allocator == omp_const_mem_alloc) {
4019 __kmp_stg_print_str(buffer, name,
"omp_const_mem_alloc");
4020 }
else if (__kmp_def_allocator == omp_low_lat_mem_alloc) {
4021 __kmp_stg_print_str(buffer, name,
"omp_low_lat_mem_alloc");
4022 }
else if (__kmp_def_allocator == omp_cgroup_mem_alloc) {
4023 __kmp_stg_print_str(buffer, name,
"omp_cgroup_mem_alloc");
4024 }
else if (__kmp_def_allocator == omp_pteam_mem_alloc) {
4025 __kmp_stg_print_str(buffer, name,
"omp_pteam_mem_alloc");
4026 }
else if (__kmp_def_allocator == omp_thread_mem_alloc) {
4027 __kmp_stg_print_str(buffer, name,
"omp_thread_mem_alloc");
4034static void __kmp_stg_parse_omp_dynamic(
char const *name,
char const *value,
4036 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
4039static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer,
char const *name,
4041 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
4044static void __kmp_stg_parse_kmp_dynamic_mode(
char const *name,
4045 char const *value,
void *data) {
4046 if (TCR_4(__kmp_init_parallel)) {
4047 KMP_WARNING(EnvParallelWarn, name);
4048 __kmp_env_toPrint(name, 0);
4051#ifdef USE_LOAD_BALANCE
4052 else if (__kmp_str_match(
"load balance", 2, value) ||
4053 __kmp_str_match(
"load_balance", 2, value) ||
4054 __kmp_str_match(
"load-balance", 2, value) ||
4055 __kmp_str_match(
"loadbalance", 2, value) ||
4056 __kmp_str_match(
"balance", 1, value)) {
4057 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
4060 else if (__kmp_str_match(
"thread limit", 1, value) ||
4061 __kmp_str_match(
"thread_limit", 1, value) ||
4062 __kmp_str_match(
"thread-limit", 1, value) ||
4063 __kmp_str_match(
"threadlimit", 1, value) ||
4064 __kmp_str_match(
"limit", 2, value)) {
4065 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
4066 }
else if (__kmp_str_match(
"random", 1, value)) {
4067 __kmp_global.g.g_dynamic_mode = dynamic_random;
4069 KMP_WARNING(StgInvalidValue, name, value);
4073static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
4074 char const *name,
void *data) {
4076 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
4077 __kmp_str_buf_print(buffer,
" %s: %s \n", name, KMP_I18N_STR(NotDefined));
4079#ifdef USE_LOAD_BALANCE
4080 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
4081 __kmp_stg_print_str(buffer, name,
"load balance");
4084 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
4085 __kmp_stg_print_str(buffer, name,
"thread limit");
4086 }
else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
4087 __kmp_stg_print_str(buffer, name,
"random");
4094#ifdef USE_LOAD_BALANCE
4099static void __kmp_stg_parse_ld_balance_interval(
char const *name,
4100 char const *value,
void *data) {
4101 double interval = __kmp_convert_to_double(value);
4102 if (interval >= 0) {
4103 __kmp_load_balance_interval = interval;
4105 KMP_WARNING(StgInvalidValue, name, value);
4109static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
4110 char const *name,
void *data) {
4112 __kmp_str_buf_print(buffer,
" %s=%8.6f\n", name,
4113 __kmp_load_balance_interval);
4122static void __kmp_stg_parse_init_at_fork(
char const *name,
char const *value,
4124 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
4125 if (__kmp_need_register_atfork) {
4126 __kmp_need_register_atfork_specified = TRUE;
4130static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
4131 char const *name,
void *data) {
4132 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
4138static void __kmp_stg_parse_schedule(
char const *name,
char const *value,
4141 if (value != NULL) {
4142 size_t length = KMP_STRLEN(value);
4143 if (length > INT_MAX) {
4144 KMP_WARNING(LongValue, name);
4146 const char *semicolon;
4147 if (value[length - 1] ==
'"' || value[length - 1] ==
'\'')
4148 KMP_WARNING(UnbalancedQuotes, name);
4152 semicolon = strchr(value,
';');
4153 if (*value && semicolon != value) {
4154 const char *comma = strchr(value,
',');
4161 if (!__kmp_strcasecmp_with_sentinel(
"static", value, sentinel)) {
4162 if (!__kmp_strcasecmp_with_sentinel(
"greedy", comma,
';')) {
4163 __kmp_static = kmp_sch_static_greedy;
4165 }
else if (!__kmp_strcasecmp_with_sentinel(
"balanced", comma,
4167 __kmp_static = kmp_sch_static_balanced;
4170 }
else if (!__kmp_strcasecmp_with_sentinel(
"guided", value,
4172 if (!__kmp_strcasecmp_with_sentinel(
"iterative", comma,
';')) {
4173 __kmp_guided = kmp_sch_guided_iterative_chunked;
4175 }
else if (!__kmp_strcasecmp_with_sentinel(
"analytical", comma,
4178 __kmp_guided = kmp_sch_guided_analytical_chunked;
4182 KMP_WARNING(InvalidClause, name, value);
4184 KMP_WARNING(EmptyClause, name);
4185 }
while ((value = semicolon ? semicolon + 1 : NULL));
4191static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer,
char const *name,
4193 if (__kmp_env_format) {
4194 KMP_STR_BUF_PRINT_NAME_EX(name);
4196 __kmp_str_buf_print(buffer,
" %s='", name);
4198 if (__kmp_static == kmp_sch_static_greedy) {
4199 __kmp_str_buf_print(buffer,
"%s",
"static,greedy");
4200 }
else if (__kmp_static == kmp_sch_static_balanced) {
4201 __kmp_str_buf_print(buffer,
"%s",
"static,balanced");
4203 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
4204 __kmp_str_buf_print(buffer,
";%s'\n",
"guided,iterative");
4205 }
else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
4206 __kmp_str_buf_print(buffer,
";%s'\n",
"guided,analytical");
4213static inline void __kmp_omp_schedule_restore() {
4214#if KMP_USE_HIER_SCHED
4215 __kmp_hier_scheds.deallocate();
4225static const char *__kmp_parse_single_omp_schedule(
const char *name,
4227 bool parse_hier =
false) {
4229 const char *ptr = value;
4236 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4238#if KMP_USE_HIER_SCHED
4239 kmp_hier_layer_e layer = kmp_hier_layer_e::LAYER_THREAD;
4241 if (*delim ==
',') {
4242 if (!__kmp_strcasecmp_with_sentinel(
"L1", ptr,
',')) {
4243 layer = kmp_hier_layer_e::LAYER_L1;
4244 }
else if (!__kmp_strcasecmp_with_sentinel(
"L2", ptr,
',')) {
4245 layer = kmp_hier_layer_e::LAYER_L2;
4246 }
else if (!__kmp_strcasecmp_with_sentinel(
"L3", ptr,
',')) {
4247 layer = kmp_hier_layer_e::LAYER_L3;
4248 }
else if (!__kmp_strcasecmp_with_sentinel(
"NUMA", ptr,
',')) {
4249 layer = kmp_hier_layer_e::LAYER_NUMA;
4252 if (layer != kmp_hier_layer_e::LAYER_THREAD && *delim !=
',') {
4254 KMP_WARNING(StgInvalidValue, name, value);
4255 __kmp_omp_schedule_restore();
4257 }
else if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4259 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4266 if (*delim ==
':') {
4267 if (!__kmp_strcasecmp_with_sentinel(
"monotonic", ptr, *delim)) {
4270 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4272 }
else if (!__kmp_strcasecmp_with_sentinel(
"nonmonotonic", ptr, *delim)) {
4275 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4277 }
else if (!parse_hier) {
4279 KMP_WARNING(StgInvalidValue, name, value);
4280 __kmp_omp_schedule_restore();
4285 if (!__kmp_strcasecmp_with_sentinel(
"dynamic", ptr, *delim))
4286 sched = kmp_sch_dynamic_chunked;
4287 else if (!__kmp_strcasecmp_with_sentinel(
"guided", ptr, *delim))
4290 else if (!__kmp_strcasecmp_with_sentinel(
"auto", ptr, *delim))
4292 else if (!__kmp_strcasecmp_with_sentinel(
"trapezoidal", ptr, *delim))
4293 sched = kmp_sch_trapezoidal;
4294 else if (!__kmp_strcasecmp_with_sentinel(
"static", ptr, *delim))
4296#if KMP_STATIC_STEAL_ENABLED
4297 else if (!__kmp_strcasecmp_with_sentinel(
"static_steal", ptr, *delim)) {
4299 sched = kmp_sch_dynamic_chunked;
4305 KMP_WARNING(StgInvalidValue, name, value);
4306 __kmp_omp_schedule_restore();
4311 if (*delim ==
',') {
4314 if (!isdigit(*ptr)) {
4316 KMP_WARNING(StgInvalidValue, name, value);
4317 __kmp_omp_schedule_restore();
4323 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, delim),
4327 sched = kmp_sch_static_chunked;
4328 chunk = __kmp_str_to_int(delim + 1, *ptr);
4330 chunk = KMP_DEFAULT_CHUNK;
4331 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, delim),
4333 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
4342 }
else if (chunk > KMP_MAX_CHUNK) {
4343 chunk = KMP_MAX_CHUNK;
4344 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, delim),
4346 KMP_INFORM(Using_int_Value, name, chunk);
4353 SCHEDULE_SET_MODIFIERS(sched, sched_modifier);
4355#if KMP_USE_HIER_SCHED
4356 if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4357 __kmp_hier_scheds.append(sched, chunk, layer);
4361 __kmp_chunk = chunk;
4362 __kmp_sched = sched;
4367static void __kmp_stg_parse_omp_schedule(
char const *name,
char const *value,
4370 const char *ptr = value;
4373 length = KMP_STRLEN(value);
4375 if (value[length - 1] ==
'"' || value[length - 1] ==
'\'')
4376 KMP_WARNING(UnbalancedQuotes, name);
4378#if KMP_USE_HIER_SCHED
4379 if (!__kmp_strcasecmp_with_sentinel(
"EXPERIMENTAL", ptr,
' ')) {
4382 while ((ptr = __kmp_parse_single_omp_schedule(name, ptr,
true))) {
4383 while (*ptr ==
' ' || *ptr ==
'\t' || *ptr ==
':')
4390 __kmp_parse_single_omp_schedule(name, ptr);
4392 KMP_WARNING(EmptyString, name);
4394#if KMP_USE_HIER_SCHED
4395 __kmp_hier_scheds.sort();
4397 K_DIAG(1, (
"__kmp_static == %d\n", __kmp_static))
4398 K_DIAG(1, (
"__kmp_guided == %d\n", __kmp_guided))
4399 K_DIAG(1, (
"__kmp_sched == %d\n", __kmp_sched))
4400 K_DIAG(1, (
"__kmp_chunk == %d\n", __kmp_chunk))
4403static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
4404 char const *name,
void *data) {
4405 if (__kmp_env_format) {
4406 KMP_STR_BUF_PRINT_NAME_EX(name);
4408 __kmp_str_buf_print(buffer,
" %s='", name);
4410 enum sched_type sched = SCHEDULE_WITHOUT_MODIFIERS(__kmp_sched);
4411 if (SCHEDULE_HAS_MONOTONIC(__kmp_sched)) {
4412 __kmp_str_buf_print(buffer,
"monotonic:");
4413 }
else if (SCHEDULE_HAS_NONMONOTONIC(__kmp_sched)) {
4414 __kmp_str_buf_print(buffer,
"nonmonotonic:");
4418 case kmp_sch_dynamic_chunked:
4419 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"dynamic", __kmp_chunk);
4421 case kmp_sch_guided_iterative_chunked:
4422 case kmp_sch_guided_analytical_chunked:
4423 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"guided", __kmp_chunk);
4425 case kmp_sch_trapezoidal:
4426 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"trapezoidal", __kmp_chunk);
4429 case kmp_sch_static_chunked:
4430 case kmp_sch_static_balanced:
4431 case kmp_sch_static_greedy:
4432 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"static", __kmp_chunk);
4434 case kmp_sch_static_steal:
4435 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"static_steal", __kmp_chunk);
4438 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"auto", __kmp_chunk);
4441 KMP_ASSERT2(
false,
"Unhandled sched_type enumeration");
4442 KMP_BUILTIN_UNREACHABLE;
4447 case kmp_sch_dynamic_chunked:
4448 __kmp_str_buf_print(buffer,
"%s'\n",
"dynamic");
4450 case kmp_sch_guided_iterative_chunked:
4451 case kmp_sch_guided_analytical_chunked:
4452 __kmp_str_buf_print(buffer,
"%s'\n",
"guided");
4454 case kmp_sch_trapezoidal:
4455 __kmp_str_buf_print(buffer,
"%s'\n",
"trapezoidal");
4458 case kmp_sch_static_chunked:
4459 case kmp_sch_static_balanced:
4460 case kmp_sch_static_greedy:
4461 __kmp_str_buf_print(buffer,
"%s'\n",
"static");
4463 case kmp_sch_static_steal:
4464 __kmp_str_buf_print(buffer,
"%s'\n",
"static_steal");
4467 __kmp_str_buf_print(buffer,
"%s'\n",
"auto");
4470 KMP_ASSERT2(
false,
"Unhandled sched_type enumeration");
4471 KMP_BUILTIN_UNREACHABLE;
4477#if KMP_USE_HIER_SCHED
4480static void __kmp_stg_parse_kmp_hand_thread(
char const *name,
char const *value,
4482 __kmp_stg_parse_bool(name, value, &(__kmp_dispatch_hand_threading));
4485static void __kmp_stg_print_kmp_hand_thread(kmp_str_buf_t *buffer,
4486 char const *name,
void *data) {
4487 __kmp_stg_print_bool(buffer, name, __kmp_dispatch_hand_threading);
4493static void __kmp_stg_parse_kmp_force_monotonic(
char const *name,
4494 char const *value,
void *data) {
4495 __kmp_stg_parse_bool(name, value, &(__kmp_force_monotonic));
4498static void __kmp_stg_print_kmp_force_monotonic(kmp_str_buf_t *buffer,
4499 char const *name,
void *data) {
4500 __kmp_stg_print_bool(buffer, name, __kmp_force_monotonic);
4506static void __kmp_stg_parse_atomic_mode(
char const *name,
char const *value,
4512#ifdef KMP_GOMP_COMPAT
4515 __kmp_stg_parse_int(name, value, 0, max, &mode);
4520 __kmp_atomic_mode = mode;
4524static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer,
char const *name,
4526 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
4532static void __kmp_stg_parse_consistency_check(
char const *name,
4533 char const *value,
void *data) {
4534 if (!__kmp_strcasecmp_with_sentinel(
"all", value, 0)) {
4540 __kmp_env_consistency_check = TRUE;
4541 }
else if (!__kmp_strcasecmp_with_sentinel(
"none", value, 0)) {
4542 __kmp_env_consistency_check = FALSE;
4544 KMP_WARNING(StgInvalidValue, name, value);
4548static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
4549 char const *name,
void *data) {
4551 const char *value = NULL;
4553 if (__kmp_env_consistency_check) {
4559 if (value != NULL) {
4560 __kmp_stg_print_str(buffer, name, value);
4571static void __kmp_stg_parse_itt_prepare_delay(
char const *name,
4572 char const *value,
void *data) {
4576 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
4577 __kmp_itt_prepare_delay = delay;
4580static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
4581 char const *name,
void *data) {
4582 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
4592static void __kmp_stg_parse_malloc_pool_incr(
char const *name,
4593 char const *value,
void *data) {
4594 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
4595 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
4599static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
4600 char const *name,
void *data) {
4601 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
4610static void __kmp_stg_parse_par_range_env(
char const *name,
char const *value,
4612 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
4613 __kmp_par_range_routine, __kmp_par_range_filename,
4614 &__kmp_par_range_lb, &__kmp_par_range_ub);
4617static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
4618 char const *name,
void *data) {
4619 if (__kmp_par_range != 0) {
4620 __kmp_stg_print_str(buffer, name, par_range_to_print);
4629static void __kmp_stg_parse_gtid_mode(
char const *name,
char const *value,
4639#ifdef KMP_TDATA_GTID
4642 __kmp_stg_parse_int(name, value, 0, max, &mode);
4646 __kmp_adjust_gtid_mode = TRUE;
4648 __kmp_gtid_mode = mode;
4649 __kmp_adjust_gtid_mode = FALSE;
4653static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer,
char const *name,
4655 if (__kmp_adjust_gtid_mode) {
4656 __kmp_stg_print_int(buffer, name, 0);
4658 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
4665static void __kmp_stg_parse_lock_block(
char const *name,
char const *value,
4667 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
4670static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer,
char const *name,
4672 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
4678#if KMP_USE_DYNAMIC_LOCK
4679#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
4681#define KMP_STORE_LOCK_SEQ(a)
4684static void __kmp_stg_parse_lock_kind(
char const *name,
char const *value,
4686 if (__kmp_init_user_locks) {
4687 KMP_WARNING(EnvLockWarn, name);
4691 if (__kmp_str_match(
"tas", 2, value) ||
4692 __kmp_str_match(
"test and set", 2, value) ||
4693 __kmp_str_match(
"test_and_set", 2, value) ||
4694 __kmp_str_match(
"test-and-set", 2, value) ||
4695 __kmp_str_match(
"test andset", 2, value) ||
4696 __kmp_str_match(
"test_andset", 2, value) ||
4697 __kmp_str_match(
"test-andset", 2, value) ||
4698 __kmp_str_match(
"testand set", 2, value) ||
4699 __kmp_str_match(
"testand_set", 2, value) ||
4700 __kmp_str_match(
"testand-set", 2, value) ||
4701 __kmp_str_match(
"testandset", 2, value)) {
4702 __kmp_user_lock_kind = lk_tas;
4703 KMP_STORE_LOCK_SEQ(tas);
4706 else if (__kmp_str_match(
"futex", 1, value)) {
4707 if (__kmp_futex_determine_capable()) {
4708 __kmp_user_lock_kind = lk_futex;
4709 KMP_STORE_LOCK_SEQ(futex);
4711 KMP_WARNING(FutexNotSupported, name, value);
4715 else if (__kmp_str_match(
"ticket", 2, value)) {
4716 __kmp_user_lock_kind = lk_ticket;
4717 KMP_STORE_LOCK_SEQ(ticket);
4718 }
else if (__kmp_str_match(
"queuing", 1, value) ||
4719 __kmp_str_match(
"queue", 1, value)) {
4720 __kmp_user_lock_kind = lk_queuing;
4721 KMP_STORE_LOCK_SEQ(queuing);
4722 }
else if (__kmp_str_match(
"drdpa ticket", 1, value) ||
4723 __kmp_str_match(
"drdpa_ticket", 1, value) ||
4724 __kmp_str_match(
"drdpa-ticket", 1, value) ||
4725 __kmp_str_match(
"drdpaticket", 1, value) ||
4726 __kmp_str_match(
"drdpa", 1, value)) {
4727 __kmp_user_lock_kind = lk_drdpa;
4728 KMP_STORE_LOCK_SEQ(drdpa);
4730#if KMP_USE_ADAPTIVE_LOCKS
4731 else if (__kmp_str_match(
"adaptive", 1, value)) {
4732 if (__kmp_cpuinfo.flags.rtm) {
4733 __kmp_user_lock_kind = lk_adaptive;
4734 KMP_STORE_LOCK_SEQ(adaptive);
4736 KMP_WARNING(AdaptiveNotSupported, name, value);
4737 __kmp_user_lock_kind = lk_queuing;
4738 KMP_STORE_LOCK_SEQ(queuing);
4742#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4743 else if (__kmp_str_match(
"rtm_queuing", 1, value)) {
4744 if (__kmp_cpuinfo.flags.rtm) {
4745 __kmp_user_lock_kind = lk_rtm_queuing;
4746 KMP_STORE_LOCK_SEQ(rtm_queuing);
4748 KMP_WARNING(AdaptiveNotSupported, name, value);
4749 __kmp_user_lock_kind = lk_queuing;
4750 KMP_STORE_LOCK_SEQ(queuing);
4752 }
else if (__kmp_str_match(
"rtm_spin", 1, value)) {
4753 if (__kmp_cpuinfo.flags.rtm) {
4754 __kmp_user_lock_kind = lk_rtm_spin;
4755 KMP_STORE_LOCK_SEQ(rtm_spin);
4757 KMP_WARNING(AdaptiveNotSupported, name, value);
4758 __kmp_user_lock_kind = lk_tas;
4759 KMP_STORE_LOCK_SEQ(queuing);
4761 }
else if (__kmp_str_match(
"hle", 1, value)) {
4762 __kmp_user_lock_kind = lk_hle;
4763 KMP_STORE_LOCK_SEQ(hle);
4767 KMP_WARNING(StgInvalidValue, name, value);
4771static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer,
char const *name,
4773 const char *value = NULL;
4775 switch (__kmp_user_lock_kind) {
4790#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4791 case lk_rtm_queuing:
4792 value =
"rtm_queuing";
4815#if KMP_USE_ADAPTIVE_LOCKS
4822 if (value != NULL) {
4823 __kmp_stg_print_str(buffer, name, value);
4832static void __kmp_stg_parse_spin_backoff_params(
const char *name,
4833 const char *value,
void *data) {
4834 const char *next = value;
4837 int prev_comma = FALSE;
4840 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
4841 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
4845 for (i = 0; i < 3; i++) {
4848 if (*next ==
'\0') {
4853 if (((*next <
'0' || *next >
'9') && *next !=
',') || total > 2) {
4854 KMP_WARNING(EnvSyntaxError, name, value);
4860 if (total == 0 || prev_comma) {
4868 if (*next >=
'0' && *next <=
'9') {
4870 const char *buf = next;
4871 char const *msg = NULL;
4876 const char *tmp = next;
4878 if ((*next ==
' ' || *next ==
'\t') && (*tmp >=
'0' && *tmp <=
'9')) {
4879 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4883 num = __kmp_str_to_int(buf, *next);
4885 msg = KMP_I18N_STR(ValueTooSmall);
4887 }
else if (num > KMP_INT_MAX) {
4888 msg = KMP_I18N_STR(ValueTooLarge);
4893 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4894 KMP_INFORM(Using_int_Value, name, num);
4898 }
else if (total == 2) {
4903 KMP_DEBUG_ASSERT(total > 0);
4905 KMP_WARNING(EnvSyntaxError, name, value);
4908 __kmp_spin_backoff_params.max_backoff = max_backoff;
4909 __kmp_spin_backoff_params.min_tick = min_tick;
4912static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
4913 char const *name,
void *data) {
4914 if (__kmp_env_format) {
4915 KMP_STR_BUF_PRINT_NAME_EX(name);
4917 __kmp_str_buf_print(buffer,
" %s='", name);
4919 __kmp_str_buf_print(buffer,
"%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
4920 __kmp_spin_backoff_params.min_tick);
4923#if KMP_USE_ADAPTIVE_LOCKS
4930static void __kmp_stg_parse_adaptive_lock_props(
const char *name,
4931 const char *value,
void *data) {
4932 int max_retries = 0;
4933 int max_badness = 0;
4935 const char *next = value;
4938 int prev_comma = FALSE;
4944 for (i = 0; i < 3; i++) {
4947 if (*next ==
'\0') {
4952 if (((*next <
'0' || *next >
'9') && *next !=
',') || total > 2) {
4953 KMP_WARNING(EnvSyntaxError, name, value);
4959 if (total == 0 || prev_comma) {
4967 if (*next >=
'0' && *next <=
'9') {
4969 const char *buf = next;
4970 char const *msg = NULL;
4975 const char *tmp = next;
4977 if ((*next ==
' ' || *next ==
'\t') && (*tmp >=
'0' && *tmp <=
'9')) {
4978 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4982 num = __kmp_str_to_int(buf, *next);
4984 msg = KMP_I18N_STR(ValueTooSmall);
4986 }
else if (num > KMP_INT_MAX) {
4987 msg = KMP_I18N_STR(ValueTooLarge);
4992 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4993 KMP_INFORM(Using_int_Value, name, num);
4997 }
else if (total == 2) {
5002 KMP_DEBUG_ASSERT(total > 0);
5004 KMP_WARNING(EnvSyntaxError, name, value);
5007 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
5008 __kmp_adaptive_backoff_params.max_badness = max_badness;
5011static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
5012 char const *name,
void *data) {
5013 if (__kmp_env_format) {
5014 KMP_STR_BUF_PRINT_NAME_EX(name);
5016 __kmp_str_buf_print(buffer,
" %s='", name);
5018 __kmp_str_buf_print(buffer,
"%d,%d'\n",
5019 __kmp_adaptive_backoff_params.max_soft_retries,
5020 __kmp_adaptive_backoff_params.max_badness);
5023#if KMP_DEBUG_ADAPTIVE_LOCKS
5025static void __kmp_stg_parse_speculative_statsfile(
char const *name,
5028 __kmp_stg_parse_file(name, value,
"",
5029 CCAST(
char **, &__kmp_speculative_statsfile));
5032static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
5035 if (__kmp_str_match(
"-", 0, __kmp_speculative_statsfile)) {
5036 __kmp_stg_print_str(buffer, name,
"stdout");
5038 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
5054static kmp_hw_t __kmp_hw_subset_break_tie(
const kmp_hw_t *possible,
5055 size_t num_possible) {
5056 for (
size_t i = 0; i < num_possible; ++i) {
5057 if (possible[i] == KMP_HW_THREAD)
5058 return KMP_HW_THREAD;
5059 else if (possible[i] == KMP_HW_CORE)
5061 else if (possible[i] == KMP_HW_SOCKET)
5062 return KMP_HW_SOCKET;
5064 return KMP_HW_UNKNOWN;
5071static kmp_hw_t __kmp_stg_parse_hw_subset_name(
char const *token) {
5072 size_t index, num_possible, token_length;
5073 kmp_hw_t possible[KMP_HW_LAST];
5079 while (isalnum(*end) || *end ==
'_') {
5086 KMP_FOREACH_HW_TYPE(type) { possible[num_possible++] = type; }
5093 while (num_possible > 1 && index < token_length) {
5094 size_t n = num_possible;
5095 char token_char = (char)toupper(token[index]);
5096 for (
size_t i = 0; i < n; ++i) {
5098 kmp_hw_t type = possible[i];
5099 s = __kmp_hw_get_keyword(type,
false);
5100 if (index < KMP_STRLEN(s)) {
5101 char c = (char)toupper(s[index]);
5103 if (c != token_char) {
5104 possible[i] = KMP_HW_UNKNOWN;
5111 for (
size_t i = 0; i < n; ++i) {
5112 if (possible[i] != KMP_HW_UNKNOWN) {
5113 kmp_hw_t temp = possible[i];
5114 possible[i] = possible[start];
5115 possible[start] = temp;
5119 KMP_ASSERT(start == num_possible);
5125 if (num_possible > 1)
5126 return __kmp_hw_subset_break_tie(possible, num_possible);
5127 if (num_possible == 1)
5129 return KMP_HW_UNKNOWN;
5134#define MAX_T_LEVEL KMP_HW_LAST
5135#define MAX_STR_LEN 512
5136static void __kmp_stg_parse_hw_subset(
char const *name,
char const *value,
5140 kmp_setting_t **rivals = (kmp_setting_t **)data;
5141 if (strcmp(name,
"KMP_PLACE_THREADS") == 0) {
5142 KMP_INFORM(EnvVarDeprecated, name,
"KMP_HW_SUBSET");
5144 if (__kmp_stg_check_rivals(name, value, rivals)) {
5148 char *components[MAX_T_LEVEL];
5149 char const *digits =
"0123456789";
5150 char input[MAX_STR_LEN];
5151 size_t len = 0, mlen = MAX_STR_LEN;
5153 bool absolute =
false;
5155 char *pos = CCAST(
char *, value);
5156 while (*pos && mlen) {
5158 if (len == 0 && *pos ==
':') {
5161 input[len] = (char)(toupper(*pos));
5162 if (input[len] ==
'X')
5164 if (input[len] ==
'O' && strchr(digits, *(pos + 1)))
5172 if (len == 0 || mlen == 0) {
5178 components[level++] = pos;
5179 while ((pos = strchr(pos,
','))) {
5180 if (level >= MAX_T_LEVEL)
5183 components[level++] = ++pos;
5186 __kmp_hw_subset = kmp_hw_subset_t::allocate();
5188 __kmp_hw_subset->set_absolute();
5191 for (
int i = 0; i < level; ++i) {
5193 char *core_components[MAX_T_LEVEL];
5195 pos = components[i];
5196 core_components[core_level++] = pos;
5197 while ((pos = strchr(pos,
'&'))) {
5198 if (core_level >= MAX_T_LEVEL)
5201 core_components[core_level++] = ++pos;
5204 for (
int j = 0; j < core_level; ++j) {
5211 if (isdigit(*core_components[j])) {
5212 num = atoi(core_components[j]);
5216 pos = core_components[j] + strspn(core_components[j], digits);
5217 }
else if (*core_components[j] ==
'*') {
5218 num = kmp_hw_subset_t::USE_ALL;
5219 pos = core_components[j] + 1;
5221 num = kmp_hw_subset_t::USE_ALL;
5222 pos = core_components[j];
5225 offset_ptr = strchr(core_components[j],
'@');
5226 attr_ptr = strchr(core_components[j],
':');
5229 offset = atoi(offset_ptr + 1);
5235#if KMP_ARCH_X86 || KMP_ARCH_X86_64
5236 if (__kmp_str_match(
"intel_core", -1, attr_ptr + 1)) {
5237 attr.set_core_type(KMP_HW_CORE_TYPE_CORE);
5238 }
else if (__kmp_str_match(
"intel_atom", -1, attr_ptr + 1)) {
5239 attr.set_core_type(KMP_HW_CORE_TYPE_ATOM);
5242 if (__kmp_str_match(
"eff", 3, attr_ptr + 1)) {
5243 const char *number = attr_ptr + 1;
5245 while (isalpha(*number))
5247 if (!isdigit(*number)) {
5250 int efficiency = atoi(number);
5251 attr.set_core_eff(efficiency);
5258 kmp_hw_t type = __kmp_stg_parse_hw_subset_name(pos);
5259 if (type == KMP_HW_UNKNOWN) {
5263 if (attr && type != KMP_HW_CORE)
5266 if (type != KMP_HW_CORE && __kmp_hw_subset->specified(type)) {
5269 __kmp_hw_subset->push_back(num, type, offset, attr);
5274 KMP_WARNING(AffHWSubsetInvalid, name, value);
5275 if (__kmp_hw_subset) {
5276 kmp_hw_subset_t::deallocate(__kmp_hw_subset);
5277 __kmp_hw_subset =
nullptr;
5282static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer,
char const *name,
5286 if (!__kmp_hw_subset)
5288 __kmp_str_buf_init(&buf);
5289 if (__kmp_env_format)
5290 KMP_STR_BUF_PRINT_NAME_EX(name);
5292 __kmp_str_buf_print(buffer,
" %s='", name);
5294 depth = __kmp_hw_subset->get_depth();
5295 for (
int i = 0; i < depth; ++i) {
5296 const auto &item = __kmp_hw_subset->at(i);
5298 __kmp_str_buf_print(&buf,
"%c",
',');
5299 for (
int j = 0; j < item.num_attrs; ++j) {
5300 __kmp_str_buf_print(&buf,
"%s%d%s", (j > 0 ?
"&" :
""), item.num[j],
5301 __kmp_hw_get_keyword(item.type));
5302 if (item.attr[j].is_core_type_valid())
5303 __kmp_str_buf_print(
5305 __kmp_hw_get_core_type_keyword(item.attr[j].get_core_type()));
5306 if (item.attr[j].is_core_eff_valid())
5307 __kmp_str_buf_print(&buf,
":eff%d", item.attr[j].get_core_eff());
5309 __kmp_str_buf_print(&buf,
"@%d", item.offset[j]);
5312 __kmp_str_buf_print(buffer,
"%s'\n", buf.str);
5313 __kmp_str_buf_free(&buf);
5320static void __kmp_stg_parse_forkjoin_frames(
char const *name,
char const *value,
5322 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
5325static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
5326 char const *name,
void *data) {
5327 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
5333static void __kmp_stg_parse_forkjoin_frames_mode(
char const *name,
5336 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
5339static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
5340 char const *name,
void *data) {
5341 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
5348static void __kmp_stg_parse_task_throttling(
char const *name,
char const *value,
5350 __kmp_stg_parse_bool(name, value, &__kmp_enable_task_throttling);
5353static void __kmp_stg_print_task_throttling(kmp_str_buf_t *buffer,
5354 char const *name,
void *data) {
5355 __kmp_stg_print_bool(buffer, name, __kmp_enable_task_throttling);
5358#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5362static void __kmp_stg_parse_user_level_mwait(
char const *name,
5363 char const *value,
void *data) {
5364 __kmp_stg_parse_bool(name, value, &__kmp_user_level_mwait);
5367static void __kmp_stg_print_user_level_mwait(kmp_str_buf_t *buffer,
5368 char const *name,
void *data) {
5369 __kmp_stg_print_bool(buffer, name, __kmp_user_level_mwait);
5375static void __kmp_stg_parse_mwait_hints(
char const *name,
char const *value,
5377 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_mwait_hints);
5380static void __kmp_stg_print_mwait_hints(kmp_str_buf_t *buffer,
char const *name,
5382 __kmp_stg_print_int(buffer, name, __kmp_mwait_hints);
5392static void __kmp_stg_parse_tpause(
char const *name,
char const *value,
5394 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_tpause_state);
5395 if (__kmp_tpause_state != 0) {
5397 if (__kmp_tpause_state == 2)
5398 __kmp_tpause_hint = 0;
5402static void __kmp_stg_print_tpause(kmp_str_buf_t *buffer,
char const *name,
5404 __kmp_stg_print_int(buffer, name, __kmp_tpause_state);
5411static void __kmp_stg_parse_omp_display_env(
char const *name,
char const *value,
5413 if (__kmp_str_match(
"VERBOSE", 1, value)) {
5414 __kmp_display_env_verbose = TRUE;
5416 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
5420static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
5421 char const *name,
void *data) {
5422 if (__kmp_display_env_verbose) {
5423 __kmp_stg_print_str(buffer, name,
"VERBOSE");
5425 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
5429static void __kmp_stg_parse_omp_cancellation(
char const *name,
5430 char const *value,
void *data) {
5431 if (TCR_4(__kmp_init_parallel)) {
5432 KMP_WARNING(EnvParallelWarn, name);
5435 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
5438static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
5439 char const *name,
void *data) {
5440 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
5446static void __kmp_stg_parse_omp_tool(
char const *name,
char const *value,
5448 __kmp_stg_parse_bool(name, value, &__kmp_tool);
5451static void __kmp_stg_print_omp_tool(kmp_str_buf_t *buffer,
char const *name,
5453 if (__kmp_env_format) {
5454 KMP_STR_BUF_PRINT_BOOL_EX(name, __kmp_tool,
"enabled",
"disabled");
5456 __kmp_str_buf_print(buffer,
" %s=%s\n", name,
5457 __kmp_tool ?
"enabled" :
"disabled");
5461char *__kmp_tool_libraries = NULL;
5463static void __kmp_stg_parse_omp_tool_libraries(
char const *name,
5464 char const *value,
void *data) {
5465 __kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
5468static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer,
5469 char const *name,
void *data) {
5470 if (__kmp_tool_libraries)
5471 __kmp_stg_print_str(buffer, name, __kmp_tool_libraries);
5473 if (__kmp_env_format) {
5474 KMP_STR_BUF_PRINT_NAME;
5476 __kmp_str_buf_print(buffer,
" %s", name);
5478 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
5482char *__kmp_tool_verbose_init = NULL;
5484static void __kmp_stg_parse_omp_tool_verbose_init(
char const *name,
5487 __kmp_stg_parse_str(name, value, &__kmp_tool_verbose_init);
5490static void __kmp_stg_print_omp_tool_verbose_init(kmp_str_buf_t *buffer,
5493 if (__kmp_tool_verbose_init)
5494 __kmp_stg_print_str(buffer, name, __kmp_tool_verbose_init);
5496 if (__kmp_env_format) {
5497 KMP_STR_BUF_PRINT_NAME;
5499 __kmp_str_buf_print(buffer,
" %s", name);
5501 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
5509static kmp_setting_t __kmp_stg_table[] = {
5511 {
"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
5512 {
"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
5514 {
"KMP_USE_YIELD", __kmp_stg_parse_use_yield, __kmp_stg_print_use_yield,
5516 {
"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
5517 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
5518 {
"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
5520 {
"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
5521 __kmp_stg_print_device_thread_limit, NULL, 0, 0},
5523 {
"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
5524 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
5526 {
"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
5528 {
"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
5529 __kmp_stg_print_stackoffset, NULL, 0, 0},
5530 {
"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5532 {
"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
5534 {
"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
5536 {
"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
5539 {
"KMP_NESTING_MODE", __kmp_stg_parse_nesting_mode,
5540 __kmp_stg_print_nesting_mode, NULL, 0, 0},
5541 {
"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
5542 {
"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
5543 __kmp_stg_print_num_threads, NULL, 0, 0},
5544 {
"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5547 {
"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
5549 {
"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
5550 __kmp_stg_print_task_stealing, NULL, 0, 0},
5551 {
"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
5552 __kmp_stg_print_max_active_levels, NULL, 0, 0},
5553 {
"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
5554 __kmp_stg_print_default_device, NULL, 0, 0},
5555 {
"OMP_TARGET_OFFLOAD", __kmp_stg_parse_target_offload,
5556 __kmp_stg_print_target_offload, NULL, 0, 0},
5557 {
"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
5558 __kmp_stg_print_max_task_priority, NULL, 0, 0},
5559 {
"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
5560 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
5561 {
"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
5562 __kmp_stg_print_thread_limit, NULL, 0, 0},
5563 {
"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
5564 __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
5565 {
"OMP_NUM_TEAMS", __kmp_stg_parse_nteams, __kmp_stg_print_nteams, NULL, 0,
5567 {
"OMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_th_limit,
5568 __kmp_stg_print_teams_th_limit, NULL, 0, 0},
5569 {
"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
5570 __kmp_stg_print_wait_policy, NULL, 0, 0},
5571 {
"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
5572 __kmp_stg_print_disp_buffers, NULL, 0, 0},
5573#if KMP_NESTED_HOT_TEAMS
5574 {
"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
5575 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
5576 {
"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
5577 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
5580#if KMP_HANDLE_SIGNALS
5581 {
"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
5582 __kmp_stg_print_handle_signals, NULL, 0, 0},
5585#if KMP_ARCH_X86 || KMP_ARCH_X86_64
5586 {
"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
5587 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
5590#ifdef KMP_GOMP_COMPAT
5591 {
"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
5595 {
"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
5597 {
"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
5599 {
"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
5601 {
"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
5603 {
"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
5605 {
"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
5607 {
"KMP_DEBUG", __kmp_stg_parse_debug, NULL, NULL, 0, 0},
5608 {
"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
5610 {
"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
5611 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
5612 {
"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
5613 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
5614 {
"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
5615 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
5616 {
"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
5618 {
"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
5619 __kmp_stg_print_par_range_env, NULL, 0, 0},
5622 {
"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
5623 __kmp_stg_print_align_alloc, NULL, 0, 0},
5625 {
"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5626 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5627 {
"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5628 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5629 {
"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5630 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5631 {
"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5632 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5633#if KMP_FAST_REDUCTION_BARRIER
5634 {
"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5635 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5636 {
"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5637 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5640 {
"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
5641 __kmp_stg_print_abort_delay, NULL, 0, 0},
5642 {
"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
5643 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
5644 {
"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
5645 __kmp_stg_print_force_reduction, NULL, 0, 0},
5646 {
"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
5647 __kmp_stg_print_force_reduction, NULL, 0, 0},
5648 {
"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
5649 __kmp_stg_print_storage_map, NULL, 0, 0},
5650 {
"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
5651 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
5652 {
"KMP_FOREIGN_THREADS_THREADPRIVATE",
5653 __kmp_stg_parse_foreign_threads_threadprivate,
5654 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
5656#if KMP_AFFINITY_SUPPORTED
5657 {
"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
5659 {
"KMP_HIDDEN_HELPER_AFFINITY", __kmp_stg_parse_hh_affinity,
5660 __kmp_stg_print_hh_affinity, NULL, 0, 0},
5661#ifdef KMP_GOMP_COMPAT
5662 {
"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
5665 {
"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5667 {
"KMP_TEAMS_PROC_BIND", __kmp_stg_parse_teams_proc_bind,
5668 __kmp_stg_print_teams_proc_bind, NULL, 0, 0},
5669 {
"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
5670 {
"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
5671 __kmp_stg_print_topology_method, NULL, 0, 0},
5677 {
"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5681 {
"OMP_DISPLAY_AFFINITY", __kmp_stg_parse_display_affinity,
5682 __kmp_stg_print_display_affinity, NULL, 0, 0},
5683 {
"OMP_AFFINITY_FORMAT", __kmp_stg_parse_affinity_format,
5684 __kmp_stg_print_affinity_format, NULL, 0, 0},
5685 {
"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
5686 __kmp_stg_print_init_at_fork, NULL, 0, 0},
5687 {
"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
5689 {
"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
5691#if KMP_USE_HIER_SCHED
5692 {
"KMP_DISP_HAND_THREAD", __kmp_stg_parse_kmp_hand_thread,
5693 __kmp_stg_print_kmp_hand_thread, NULL, 0, 0},
5695 {
"KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE",
5696 __kmp_stg_parse_kmp_force_monotonic, __kmp_stg_print_kmp_force_monotonic,
5698 {
"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
5699 __kmp_stg_print_atomic_mode, NULL, 0, 0},
5700 {
"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
5701 __kmp_stg_print_consistency_check, NULL, 0, 0},
5703#if USE_ITT_BUILD && USE_ITT_NOTIFY
5704 {
"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
5705 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
5707 {
"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
5708 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
5709 {
"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
5711 {
"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
5713 {
"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
5714 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
5716#ifdef USE_LOAD_BALANCE
5717 {
"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
5718 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
5721 {
"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
5722 __kmp_stg_print_lock_block, NULL, 0, 0},
5723 {
"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
5725 {
"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
5726 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
5727#if KMP_USE_ADAPTIVE_LOCKS
5728 {
"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
5729 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
5730#if KMP_DEBUG_ADAPTIVE_LOCKS
5731 {
"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
5732 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
5735 {
"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5737 {
"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5740 {
"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
5741 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
5742 {
"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
5743 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
5745 {
"KMP_ENABLE_TASK_THROTTLING", __kmp_stg_parse_task_throttling,
5746 __kmp_stg_print_task_throttling, NULL, 0, 0},
5748 {
"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
5749 __kmp_stg_print_omp_display_env, NULL, 0, 0},
5750 {
"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
5751 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
5752 {
"OMP_ALLOCATOR", __kmp_stg_parse_allocator, __kmp_stg_print_allocator,
5754 {
"LIBOMP_USE_HIDDEN_HELPER_TASK", __kmp_stg_parse_use_hidden_helper,
5755 __kmp_stg_print_use_hidden_helper, NULL, 0, 0},
5756 {
"LIBOMP_NUM_HIDDEN_HELPER_THREADS",
5757 __kmp_stg_parse_num_hidden_helper_threads,
5758 __kmp_stg_print_num_hidden_helper_threads, NULL, 0, 0},
5760 {
"KMP_MAX_TDGS", __kmp_stg_parse_max_tdgs, __kmp_std_print_max_tdgs, NULL,
5762 {
"KMP_TDG_DOT", __kmp_stg_parse_tdg_dot, __kmp_stg_print_tdg_dot, NULL, 0, 0},
5766 {
"OMP_TOOL", __kmp_stg_parse_omp_tool, __kmp_stg_print_omp_tool, NULL, 0,
5768 {
"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries,
5769 __kmp_stg_print_omp_tool_libraries, NULL, 0, 0},
5770 {
"OMP_TOOL_VERBOSE_INIT", __kmp_stg_parse_omp_tool_verbose_init,
5771 __kmp_stg_print_omp_tool_verbose_init, NULL, 0, 0},
5774#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5775 {
"KMP_USER_LEVEL_MWAIT", __kmp_stg_parse_user_level_mwait,
5776 __kmp_stg_print_user_level_mwait, NULL, 0, 0},
5777 {
"KMP_MWAIT_HINTS", __kmp_stg_parse_mwait_hints,
5778 __kmp_stg_print_mwait_hints, NULL, 0, 0},
5782 {
"KMP_TPAUSE", __kmp_stg_parse_tpause, __kmp_stg_print_tpause, NULL, 0, 0},
5784 {
"", NULL, NULL, NULL, 0, 0}};
5786static int const __kmp_stg_count =
5787 sizeof(__kmp_stg_table) /
sizeof(kmp_setting_t);
5789static inline kmp_setting_t *__kmp_stg_find(
char const *name) {
5793 for (i = 0; i < __kmp_stg_count; ++i) {
5794 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
5795 return &__kmp_stg_table[i];
5803static int __kmp_stg_cmp(
void const *_a,
void const *_b) {
5804 const kmp_setting_t *a = RCAST(
const kmp_setting_t *, _a);
5805 const kmp_setting_t *b = RCAST(
const kmp_setting_t *, _b);
5809 if (strcmp(a->name,
"KMP_AFFINITY") == 0) {
5810 if (strcmp(b->name,
"KMP_AFFINITY") == 0) {
5814 }
else if (strcmp(b->name,
"KMP_AFFINITY") == 0) {
5817 return strcmp(a->name, b->name);
5820static void __kmp_stg_init(
void) {
5822 static int initialized = 0;
5827 qsort(__kmp_stg_table, __kmp_stg_count - 1,
sizeof(kmp_setting_t),
5831 kmp_setting_t *kmp_stacksize =
5832 __kmp_stg_find(
"KMP_STACKSIZE");
5833#ifdef KMP_GOMP_COMPAT
5834 kmp_setting_t *gomp_stacksize =
5835 __kmp_stg_find(
"GOMP_STACKSIZE");
5837 kmp_setting_t *omp_stacksize =
5838 __kmp_stg_find(
"OMP_STACKSIZE");
5844 static kmp_setting_t *
volatile rivals[4];
5845 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
5846#ifdef KMP_GOMP_COMPAT
5847 static kmp_stg_ss_data_t gomp_data = {1024,
5848 CCAST(kmp_setting_t **, rivals)};
5850 static kmp_stg_ss_data_t omp_data = {1024,
5851 CCAST(kmp_setting_t **, rivals)};
5854 rivals[i++] = kmp_stacksize;
5855#ifdef KMP_GOMP_COMPAT
5856 if (gomp_stacksize != NULL) {
5857 rivals[i++] = gomp_stacksize;
5860 rivals[i++] = omp_stacksize;
5863 kmp_stacksize->data = &kmp_data;
5864#ifdef KMP_GOMP_COMPAT
5865 if (gomp_stacksize != NULL) {
5866 gomp_stacksize->data = &gomp_data;
5869 omp_stacksize->data = &omp_data;
5873 kmp_setting_t *kmp_library =
5874 __kmp_stg_find(
"KMP_LIBRARY");
5875 kmp_setting_t *omp_wait_policy =
5876 __kmp_stg_find(
"OMP_WAIT_POLICY");
5879 static kmp_setting_t *
volatile rivals[3];
5880 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
5881 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
5884 rivals[i++] = kmp_library;
5885 if (omp_wait_policy != NULL) {
5886 rivals[i++] = omp_wait_policy;
5890 kmp_library->data = &kmp_data;
5891 if (omp_wait_policy != NULL) {
5892 omp_wait_policy->data = &omp_data;
5897 kmp_setting_t *kmp_device_thread_limit =
5898 __kmp_stg_find(
"KMP_DEVICE_THREAD_LIMIT");
5899 kmp_setting_t *kmp_all_threads =
5900 __kmp_stg_find(
"KMP_ALL_THREADS");
5903 static kmp_setting_t *
volatile rivals[3];
5906 rivals[i++] = kmp_device_thread_limit;
5907 rivals[i++] = kmp_all_threads;
5910 kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
5911 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
5916 kmp_setting_t *kmp_hw_subset = __kmp_stg_find(
"KMP_HW_SUBSET");
5918 kmp_setting_t *kmp_place_threads = __kmp_stg_find(
"KMP_PLACE_THREADS");
5921 static kmp_setting_t *
volatile rivals[3];
5924 rivals[i++] = kmp_hw_subset;
5925 rivals[i++] = kmp_place_threads;
5928 kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
5929 kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
5932#if KMP_AFFINITY_SUPPORTED
5934 kmp_setting_t *kmp_affinity =
5935 __kmp_stg_find(
"KMP_AFFINITY");
5936 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
5938#ifdef KMP_GOMP_COMPAT
5939 kmp_setting_t *gomp_cpu_affinity =
5940 __kmp_stg_find(
"GOMP_CPU_AFFINITY");
5941 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
5944 kmp_setting_t *omp_proc_bind =
5945 __kmp_stg_find(
"OMP_PROC_BIND");
5946 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
5949 static kmp_setting_t *
volatile rivals[4];
5952 rivals[i++] = kmp_affinity;
5954#ifdef KMP_GOMP_COMPAT
5955 rivals[i++] = gomp_cpu_affinity;
5956 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
5959 rivals[i++] = omp_proc_bind;
5960 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
5963 static kmp_setting_t *
volatile places_rivals[4];
5966 kmp_setting_t *omp_places = __kmp_stg_find(
"OMP_PLACES");
5967 KMP_DEBUG_ASSERT(omp_places != NULL);
5969 places_rivals[i++] = kmp_affinity;
5970#ifdef KMP_GOMP_COMPAT
5971 places_rivals[i++] = gomp_cpu_affinity;
5973 places_rivals[i++] = omp_places;
5974 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
5975 places_rivals[i++] = NULL;
5983 kmp_setting_t *kmp_force_red =
5984 __kmp_stg_find(
"KMP_FORCE_REDUCTION");
5985 kmp_setting_t *kmp_determ_red =
5986 __kmp_stg_find(
"KMP_DETERMINISTIC_REDUCTION");
5989 static kmp_setting_t *
volatile rivals[3];
5990 static kmp_stg_fr_data_t force_data = {1,
5991 CCAST(kmp_setting_t **, rivals)};
5992 static kmp_stg_fr_data_t determ_data = {0,
5993 CCAST(kmp_setting_t **, rivals)};
5996 rivals[i++] = kmp_force_red;
5997 if (kmp_determ_red != NULL) {
5998 rivals[i++] = kmp_determ_red;
6002 kmp_force_red->data = &force_data;
6003 if (kmp_determ_red != NULL) {
6004 kmp_determ_red->data = &determ_data;
6013 for (i = 0; i < __kmp_stg_count; ++i) {
6014 __kmp_stg_table[i].set = 0;
6019static void __kmp_stg_parse(
char const *name,
char const *value) {
6027 if (value != NULL) {
6028 kmp_setting_t *setting = __kmp_stg_find(name);
6029 if (setting != NULL) {
6030 setting->parse(name, value, setting->data);
6031 setting->defined = 1;
6037static int __kmp_stg_check_rivals(
6040 kmp_setting_t **rivals
6043 if (rivals == NULL) {
6049 for (; strcmp(rivals[i]->name, name) != 0; i++) {
6050 KMP_DEBUG_ASSERT(rivals[i] != NULL);
6052#if KMP_AFFINITY_SUPPORTED
6053 if (rivals[i] == __kmp_affinity_notype) {
6060 if (rivals[i]->set) {
6061 KMP_WARNING(StgIgnored, name, rivals[i]->name);
6071static int __kmp_env_toPrint(
char const *name,
int flag) {
6073 kmp_setting_t *setting = __kmp_stg_find(name);
6074 if (setting != NULL) {
6075 rc = setting->defined;
6077 setting->defined = flag;
6083#if defined(KMP_DEBUG) && KMP_AFFINITY_SUPPORTED
6084static void __kmp_print_affinity_settings(
const kmp_affinity_t *affinity) {
6085 K_DIAG(1, (
"%s:\n", affinity->env_var));
6086 K_DIAG(1, (
" type : %d\n", affinity->type));
6087 K_DIAG(1, (
" compact : %d\n", affinity->compact));
6088 K_DIAG(1, (
" offset : %d\n", affinity->offset));
6089 K_DIAG(1, (
" verbose : %u\n", affinity->flags.verbose));
6090 K_DIAG(1, (
" warnings : %u\n", affinity->flags.warnings));
6091 K_DIAG(1, (
" respect : %u\n", affinity->flags.respect));
6092 K_DIAG(1, (
" reset : %u\n", affinity->flags.reset));
6093 K_DIAG(1, (
" dups : %u\n", affinity->flags.dups));
6094 K_DIAG(1, (
" gran : %d\n", (
int)affinity->gran));
6095 KMP_DEBUG_ASSERT(affinity->type != affinity_default);
6099static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
6104 value = __kmp_env_blk_var(block,
"OMP_NUM_THREADS");
6106 ompc_set_num_threads(__kmp_dflt_team_nth);
6110 value = __kmp_env_blk_var(block,
"KMP_BLOCKTIME");
6115 gtid = __kmp_entry_gtid();
6116 tid = __kmp_tid_from_gtid(gtid);
6117 thread = __kmp_thread_from_gtid(gtid);
6118 __kmp_aux_set_blocktime(__kmp_dflt_blocktime, thread, tid);
6122 value = __kmp_env_blk_var(block,
"OMP_NESTED");
6124 ompc_set_nested(__kmp_dflt_max_active_levels > 1);
6128 value = __kmp_env_blk_var(block,
"OMP_DYNAMIC");
6130 ompc_set_dynamic(__kmp_global.g.g_dynamic);
6134void __kmp_env_initialize(
char const *
string) {
6136 kmp_env_blk_t block;
6142 if (
string == NULL) {
6144 __kmp_threads_capacity =
6145 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
6147 __kmp_env_blk_init(&block,
string);
6150 for (i = 0; i < block.count; ++i) {
6151 if ((block.vars[i].name == NULL) || (*block.vars[i].name ==
'\0')) {
6154 if (block.vars[i].value == NULL) {
6157 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
6158 if (setting != NULL) {
6164 blocktime_str = __kmp_env_blk_var(&block,
"KMP_BLOCKTIME");
6168 if (
string == NULL) {
6169 char const *name =
"KMP_WARNINGS";
6170 char const *value = __kmp_env_blk_var(&block, name);
6171 __kmp_stg_parse(name, value);
6174#if KMP_AFFINITY_SUPPORTED
6180 __kmp_affinity_notype = NULL;
6181 char const *aff_str = __kmp_env_blk_var(&block,
"KMP_AFFINITY");
6182 if (aff_str != NULL) {
6193#if KMP_OS_WINDOWS || KMP_OS_AIX
6196#define FIND strcasestr
6199 if ((FIND(aff_str,
"none") == NULL) &&
6200 (FIND(aff_str,
"physical") == NULL) &&
6201 (FIND(aff_str,
"logical") == NULL) &&
6202 (FIND(aff_str,
"compact") == NULL) &&
6203 (FIND(aff_str,
"scatter") == NULL) &&
6204 (FIND(aff_str,
"explicit") == NULL) &&
6205 (FIND(aff_str,
"balanced") == NULL) &&
6206 (FIND(aff_str,
"disabled") == NULL)) {
6207 __kmp_affinity_notype = __kmp_stg_find(
"KMP_AFFINITY");
6212 __kmp_affinity.type = affinity_default;
6213 __kmp_affinity.gran = KMP_HW_UNKNOWN;
6214 __kmp_affinity_top_method = affinity_top_method_default;
6215 __kmp_affinity.flags.respect = affinity_respect_mask_default;
6220 aff_str = __kmp_env_blk_var(&block,
"OMP_PROC_BIND");
6221 if (aff_str != NULL) {
6222 __kmp_affinity.type = affinity_default;
6223 __kmp_affinity.gran = KMP_HW_UNKNOWN;
6224 __kmp_affinity_top_method = affinity_top_method_default;
6225 __kmp_affinity.flags.respect = affinity_respect_mask_default;
6232 if (__kmp_nested_proc_bind.bind_types == NULL) {
6233 __kmp_nested_proc_bind.bind_types =
6234 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(
sizeof(kmp_proc_bind_t));
6235 if (__kmp_nested_proc_bind.bind_types == NULL) {
6236 KMP_FATAL(MemoryAllocFailed);
6238 __kmp_nested_proc_bind.size = 1;
6239 __kmp_nested_proc_bind.used = 1;
6240#if KMP_AFFINITY_SUPPORTED
6241 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
6244 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6251 __kmp_msg_format(kmp_i18n_msg_AffFormatDefault,
"%P",
"%i",
"%n",
"%A");
6252 KMP_DEBUG_ASSERT(KMP_STRLEN(m.str) < KMP_AFFINITY_FORMAT_SIZE);
6254 if (__kmp_affinity_format == NULL) {
6255 __kmp_affinity_format =
6256 (
char *)KMP_INTERNAL_MALLOC(
sizeof(
char) * KMP_AFFINITY_FORMAT_SIZE);
6258 KMP_STRCPY_S(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, m.str);
6259 __kmp_str_free(&m.str);
6262 for (i = 0; i < block.count; ++i) {
6263 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
6267 if (!__kmp_init_user_locks) {
6268 if (__kmp_user_lock_kind == lk_default) {
6269 __kmp_user_lock_kind = lk_queuing;
6271#if KMP_USE_DYNAMIC_LOCK
6272 __kmp_init_dynamic_user_locks();
6274 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
6277 KMP_DEBUG_ASSERT(
string != NULL);
6278 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
6283#if KMP_USE_DYNAMIC_LOCK
6284 __kmp_init_dynamic_user_locks();
6286 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
6290#if KMP_AFFINITY_SUPPORTED
6292 if (!TCR_4(__kmp_init_middle)) {
6297 if (__kmp_hw_subset &&
6298 __kmp_affinity_top_method == affinity_top_method_default)
6299 if (__kmp_hw_subset->specified(KMP_HW_NUMA) ||
6300 __kmp_hw_subset->specified(KMP_HW_TILE) ||
6301 __kmp_affinity.gran == KMP_HW_TILE ||
6302 __kmp_affinity.gran == KMP_HW_NUMA)
6303 __kmp_affinity_top_method = affinity_top_method_hwloc;
6305 if (__kmp_affinity.gran == KMP_HW_NUMA ||
6306 __kmp_affinity.gran == KMP_HW_TILE)
6307 __kmp_affinity_top_method = affinity_top_method_hwloc;
6311 const char *var =
"KMP_AFFINITY";
6312 KMPAffinity::pick_api();
6317 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
6318 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
6319 KMP_WARNING(AffIgnoringHwloc, var);
6320 __kmp_affinity_top_method = affinity_top_method_all;
6323 if (__kmp_affinity.type == affinity_disabled) {
6324 KMP_AFFINITY_DISABLE();
6325 }
else if (!KMP_AFFINITY_CAPABLE()) {
6326 __kmp_affinity_dispatch->determine_capable(var);
6327 if (!KMP_AFFINITY_CAPABLE()) {
6328 if (__kmp_affinity.flags.verbose ||
6329 (__kmp_affinity.flags.warnings &&
6330 (__kmp_affinity.type != affinity_default) &&
6331 (__kmp_affinity.type != affinity_none) &&
6332 (__kmp_affinity.type != affinity_disabled))) {
6333 KMP_WARNING(AffNotSupported, var);
6335 __kmp_affinity.type = affinity_disabled;
6336 __kmp_affinity.flags.respect = FALSE;
6337 __kmp_affinity.gran = KMP_HW_THREAD;
6341 if (__kmp_affinity.type == affinity_disabled) {
6342 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6343 }
else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
6345 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
6348 if (KMP_AFFINITY_CAPABLE()) {
6350#if KMP_GROUP_AFFINITY
6355 bool exactly_one_group =
false;
6356 if (__kmp_num_proc_groups > 1) {
6358 bool within_one_group;
6361 kmp_affin_mask_t *init_mask;
6362 KMP_CPU_ALLOC(init_mask);
6363 __kmp_get_system_affinity(init_mask, TRUE);
6364 group = __kmp_get_proc_group(init_mask);
6365 within_one_group = (group >= 0);
6368 if (within_one_group) {
6369 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
6370 DWORD num_bits_in_mask = 0;
6371 for (
int bit = init_mask->begin(); bit != init_mask->end();
6372 bit = init_mask->next(bit))
6374 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
6376 KMP_CPU_FREE(init_mask);
6382 if (__kmp_num_proc_groups > 1 &&
6383 __kmp_affinity.type == affinity_default &&
6384 __kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
6389 if (__kmp_affinity.flags.respect == affinity_respect_mask_default &&
6390 exactly_one_group) {
6391 __kmp_affinity.flags.respect = FALSE;
6395 if (__kmp_affinity.type == affinity_default) {
6396 __kmp_affinity.type = affinity_compact;
6397 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6399 if (__kmp_hh_affinity.type == affinity_default)
6400 __kmp_hh_affinity.type = affinity_compact;
6401 if (__kmp_affinity_top_method == affinity_top_method_default)
6402 __kmp_affinity_top_method = affinity_top_method_all;
6403 if (__kmp_affinity.gran == KMP_HW_UNKNOWN)
6404 __kmp_affinity.gran = KMP_HW_PROC_GROUP;
6405 if (__kmp_hh_affinity.gran == KMP_HW_UNKNOWN)
6406 __kmp_hh_affinity.gran = KMP_HW_PROC_GROUP;
6412 if (__kmp_affinity.flags.respect == affinity_respect_mask_default) {
6413#if KMP_GROUP_AFFINITY
6414 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
6415 __kmp_affinity.flags.respect = FALSE;
6419 __kmp_affinity.flags.respect = TRUE;
6422 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
6423 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
6424 if (__kmp_affinity.type == affinity_default) {
6425 __kmp_affinity.type = affinity_compact;
6426 __kmp_affinity.flags.dups = FALSE;
6428 }
else if (__kmp_affinity.type == affinity_default) {
6429#if KMP_MIC_SUPPORTED
6430 if (__kmp_mic_type != non_mic) {
6431 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6435 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6437#if KMP_MIC_SUPPORTED
6438 if (__kmp_mic_type != non_mic) {
6439 __kmp_affinity.type = affinity_scatter;
6443 __kmp_affinity.type = affinity_none;
6446 if (__kmp_hh_affinity.type == affinity_default)
6447 __kmp_hh_affinity.type = affinity_none;
6448 if ((__kmp_affinity.gran == KMP_HW_UNKNOWN) &&
6449 (__kmp_affinity.gran_levels < 0)) {
6450#if KMP_MIC_SUPPORTED
6451 if (__kmp_mic_type != non_mic) {
6452 __kmp_affinity.gran = KMP_HW_THREAD;
6456 __kmp_affinity.gran = KMP_HW_CORE;
6459 if ((__kmp_hh_affinity.gran == KMP_HW_UNKNOWN) &&
6460 (__kmp_hh_affinity.gran_levels < 0)) {
6461#if KMP_MIC_SUPPORTED
6462 if (__kmp_mic_type != non_mic) {
6463 __kmp_hh_affinity.gran = KMP_HW_THREAD;
6467 __kmp_hh_affinity.gran = KMP_HW_CORE;
6470 if (__kmp_affinity_top_method == affinity_top_method_default) {
6471 __kmp_affinity_top_method = affinity_top_method_all;
6477 if (__kmp_affinity_top_method == affinity_top_method_default)
6478 __kmp_affinity_top_method = affinity_top_method_all;
6479 if (__kmp_affinity.type == affinity_default)
6480 __kmp_affinity.type = affinity_disabled;
6481 if (__kmp_hh_affinity.type == affinity_default)
6482 __kmp_hh_affinity.type = affinity_disabled;
6486 for (
const kmp_affinity_t *affinity : __kmp_affinities)
6487 __kmp_print_affinity_settings(affinity);
6488 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
6489 K_DIAG(1, (
"__kmp_nested_proc_bind.bind_types[0] == %d\n",
6490 __kmp_nested_proc_bind.bind_types[0]));
6498 if (
string != NULL) {
6499 __kmp_aux_env_initialize(&block);
6502 __kmp_env_blk_free(&block);
6508void __kmp_env_print() {
6510 kmp_env_blk_t block;
6512 kmp_str_buf_t buffer;
6515 __kmp_str_buf_init(&buffer);
6517 __kmp_env_blk_init(&block, NULL);
6518 __kmp_env_blk_sort(&block);
6521 __kmp_str_buf_print(&buffer,
"\n%s\n\n", KMP_I18N_STR(UserSettings));
6522 for (i = 0; i < block.count; ++i) {
6523 char const *name = block.vars[i].name;
6524 char const *value = block.vars[i].value;
6525 if ((KMP_STRLEN(name) > 4 && strncmp(name,
"KMP_", 4) == 0) ||
6526 strncmp(name,
"OMP_", 4) == 0
6527#ifdef KMP_GOMP_COMPAT
6528 || strncmp(name,
"GOMP_", 5) == 0
6531 __kmp_str_buf_print(&buffer,
" %s=%s\n", name, value);
6534 __kmp_str_buf_print(&buffer,
"\n");
6537 __kmp_str_buf_print(&buffer,
"%s\n\n", KMP_I18N_STR(EffectiveSettings));
6538 for (
int i = 0; i < __kmp_stg_count; ++i) {
6539 if (__kmp_stg_table[i].print != NULL) {
6540 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6541 __kmp_stg_table[i].data);
6545 __kmp_printf(
"%s", buffer.str);
6547 __kmp_env_blk_free(&block);
6548 __kmp_str_buf_free(&buffer);
6554void __kmp_env_print_2() {
6555 __kmp_display_env_impl(__kmp_display_env, __kmp_display_env_verbose);
6558void __kmp_display_env_impl(
int display_env,
int display_env_verbose) {
6559 kmp_env_blk_t block;
6560 kmp_str_buf_t buffer;
6562 __kmp_env_format = 1;
6565 __kmp_str_buf_init(&buffer);
6567 __kmp_env_blk_init(&block, NULL);
6568 __kmp_env_blk_sort(&block);
6570 __kmp_str_buf_print(&buffer,
"\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
6571 __kmp_str_buf_print(&buffer,
" _OPENMP='%d'\n", __kmp_openmp_version);
6573 for (
int i = 0; i < __kmp_stg_count; ++i) {
6574 if (__kmp_stg_table[i].print != NULL &&
6575 ((display_env && strncmp(__kmp_stg_table[i].name,
"OMP_", 4) == 0) ||
6576 display_env_verbose)) {
6577 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6578 __kmp_stg_table[i].data);
6582 __kmp_str_buf_print(&buffer,
"%s\n", KMP_I18N_STR(DisplayEnvEnd));
6583 __kmp_str_buf_print(&buffer,
"\n");
6585 __kmp_printf(
"%s", buffer.str);
6587 __kmp_env_blk_free(&block);
6588 __kmp_str_buf_free(&buffer);
6595void __kmp_env_dump() {
6597 kmp_env_blk_t block;
6598 kmp_str_buf_t buffer, env, notdefined;
6601 __kmp_str_buf_init(&buffer);
6602 __kmp_str_buf_init(&env);
6603 __kmp_str_buf_init(¬defined);
6605 __kmp_env_blk_init(&block, NULL);
6606 __kmp_env_blk_sort(&block);
6608 __kmp_str_buf_print(¬defined,
": %s", KMP_I18N_STR(NotDefined));
6610 for (
int i = 0; i < __kmp_stg_count; ++i) {
6611 if (__kmp_stg_table[i].print == NULL)
6613 __kmp_str_buf_clear(&env);
6614 __kmp_stg_table[i].print(&env, __kmp_stg_table[i].name,
6615 __kmp_stg_table[i].data);
6618 if (strstr(env.str, notdefined.str))
6620 __kmp_str_buf_print(&buffer,
"%s=undefined\n", __kmp_stg_table[i].name);
6622 __kmp_str_buf_cat(&buffer, env.str + 3, env.used - 3);
6625 ompd_env_block = (
char *)__kmp_allocate(buffer.used + 1);
6626 KMP_MEMCPY(ompd_env_block, buffer.str, buffer.used + 1);
6627 ompd_env_block_size = (ompd_size_t)KMP_STRLEN(ompd_env_block);
6629 __kmp_env_blk_free(&block);
6630 __kmp_str_buf_free(&buffer);
6631 __kmp_str_buf_free(&env);
6632 __kmp_str_buf_free(¬defined);
@ kmp_sch_modifier_monotonic
@ kmp_sch_modifier_nonmonotonic