14 #include "kmp_affinity.h"
15 #include "kmp_atomic.h"
16 #if KMP_USE_HIER_SCHED
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"
32 static int __kmp_env_toPrint(
char const *name,
int flag);
34 bool __kmp_env_format = 0;
39 #ifdef USE_LOAD_BALANCE
40 static double __kmp_convert_to_double(
char const *s) {
43 if (KMP_SSCANF(s,
"%lf", &result) < 1) {
52 static 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)) {
66 static 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')
113 static 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')
140 static 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) {
156 int __kmp_convert_to_milliseconds(
char const *data) {
157 int ret, nvalues, factor;
163 if (__kmp_str_match(
"infinit", -1, data))
167 #if KMP_OS_WINDOWS && KMP_MSVC_COMPAT
169 nvalues = KMP_SSCANF(data,
"%lf%c%c", &value, &mult, 1, &extra, 1);
171 nvalues = KMP_SSCANF(data,
"%lf%c%c", &value, &mult, &extra);
198 factor = 1000 * 60 * 60;
202 factor = 1000 * 24 * 60 * 60;
208 if (value >= ((INT_MAX - 1) / factor))
211 ret = (int)(value * (
double)factor);
216 static int __kmp_strcasecmp_with_sentinel(
char const *a,
char const *b,
222 while (*a && *b && *b != sentinel) {
223 char ca = *a, cb = *b;
225 if (ca >=
'a' && ca <=
'z')
227 if (cb >=
'a' && cb <=
'z')
230 return (
int)(
unsigned char)*a - (
int)(
unsigned char)*b;
234 return *a ? (*b && *b != sentinel)
235 ? (
int)(
unsigned char)*a - (
int)(
unsigned char)*b
237 : (*b && *b != sentinel) ? -1
244 typedef struct __kmp_setting kmp_setting_t;
245 typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
246 typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
247 typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
249 typedef void (*kmp_stg_parse_func_t)(
char const *name,
char const *value,
251 typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer,
char const *name,
254 struct __kmp_setting {
256 kmp_stg_parse_func_t parse;
257 kmp_stg_print_func_t print;
264 struct __kmp_stg_ss_data {
266 kmp_setting_t **rivals;
269 struct __kmp_stg_wp_data {
271 kmp_setting_t **rivals;
274 struct __kmp_stg_fr_data {
276 kmp_setting_t **rivals;
279 static int __kmp_stg_check_rivals(
282 kmp_setting_t **rivals
288 static void __kmp_stg_parse_bool(
char const *name,
char const *value,
290 if (__kmp_str_match_true(value)) {
292 }
else if (__kmp_str_match_false(value)) {
295 __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
296 KMP_HNT(ValidBoolValues), __kmp_msg_null);
301 void __kmp_check_stksize(
size_t *val) {
303 if (*val > KMP_DEFAULT_STKSIZE * 16)
304 *val = KMP_DEFAULT_STKSIZE * 16;
305 if (*val < KMP_MIN_STKSIZE)
306 *val = KMP_MIN_STKSIZE;
307 if (*val > KMP_MAX_STKSIZE)
308 *val = KMP_MAX_STKSIZE;
310 *val = __kmp_round4k(*val);
314 static void __kmp_stg_parse_size(
char const *name,
char const *value,
315 size_t size_min,
size_t size_max,
316 int *is_specified,
size_t *out,
318 char const *msg = NULL;
320 size_min = __kmp_round4k(size_min);
321 size_max = __kmp_round4k(size_max);
324 if (is_specified != NULL) {
327 __kmp_str_to_size(value, out, factor, &msg);
329 if (*out > size_max) {
331 msg = KMP_I18N_STR(ValueTooLarge);
332 }
else if (*out < size_min) {
334 msg = KMP_I18N_STR(ValueTooSmall);
337 size_t round4k = __kmp_round4k(*out);
338 if (*out != round4k) {
340 msg = KMP_I18N_STR(NotMultiple4K);
347 if (*out < size_min) {
349 }
else if (*out > size_max) {
356 __kmp_str_buf_init(&buf);
357 __kmp_str_buf_print_size(&buf, *out);
358 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
359 KMP_INFORM(Using_str_Value, name, buf.str);
360 __kmp_str_buf_free(&buf);
365 static void __kmp_stg_parse_str(
char const *name,
char const *value,
368 *out = __kmp_str_format(
"%s", value);
371 static void __kmp_stg_parse_int(
379 char const *msg = NULL;
380 kmp_uint64 uint = *out;
381 __kmp_str_to_uint(value, &uint, &msg);
383 if (uint < (
unsigned int)min) {
384 msg = KMP_I18N_STR(ValueTooSmall);
386 }
else if (uint > (
unsigned int)max) {
387 msg = KMP_I18N_STR(ValueTooLarge);
393 if (uint < (
unsigned int)min) {
395 }
else if (uint > (
unsigned int)max) {
402 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
403 __kmp_str_buf_init(&buf);
404 __kmp_str_buf_print(&buf,
"%" KMP_UINT64_SPEC
"", uint);
405 KMP_INFORM(Using_uint64_Value, name, buf.str);
406 __kmp_str_buf_free(&buf);
408 __kmp_type_convert(uint, out);
411 #if KMP_DEBUG_ADAPTIVE_LOCKS
412 static void __kmp_stg_parse_file(
char const *name,
char const *value,
413 const char *suffix,
char **out) {
418 t = (
char *)strrchr(value,
'.');
419 hasSuffix = t && __kmp_str_eqf(t, suffix);
420 t = __kmp_str_format(
"%s%s", value, hasSuffix ?
"" : suffix);
421 __kmp_expand_file_name(buffer,
sizeof(buffer), t);
423 *out = __kmp_str_format(
"%s", buffer);
428 static char *par_range_to_print = NULL;
430 static void __kmp_stg_parse_par_range(
char const *name,
char const *value,
431 int *out_range,
char *out_routine,
432 char *out_file,
int *out_lb,
434 const char *par_range_value;
435 size_t len = KMP_STRLEN(value) + 1;
436 par_range_to_print = (
char *)KMP_INTERNAL_MALLOC(len + 1);
437 KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
438 __kmp_par_range = +1;
439 __kmp_par_range_lb = 0;
440 __kmp_par_range_ub = INT_MAX;
443 if (!value || *value ==
'\0') {
446 if (!__kmp_strcasecmp_with_sentinel(
"routine", value,
'=')) {
447 par_range_value = strchr(value,
'=') + 1;
448 if (!par_range_value)
449 goto par_range_error;
450 value = par_range_value;
451 len = __kmp_readstr_with_sentinel(out_routine, value,
452 KMP_PAR_RANGE_ROUTINE_LEN - 1,
',');
454 goto par_range_error;
456 value = strchr(value,
',');
462 if (!__kmp_strcasecmp_with_sentinel(
"filename", value,
'=')) {
463 par_range_value = strchr(value,
'=') + 1;
464 if (!par_range_value)
465 goto par_range_error;
466 value = par_range_value;
467 len = __kmp_readstr_with_sentinel(out_file, value,
468 KMP_PAR_RANGE_FILENAME_LEN - 1,
',');
470 goto par_range_error;
472 value = strchr(value,
',');
478 if ((!__kmp_strcasecmp_with_sentinel(
"range", value,
'=')) ||
479 (!__kmp_strcasecmp_with_sentinel(
"incl_range", value,
'='))) {
480 par_range_value = strchr(value,
'=') + 1;
481 if (!par_range_value)
482 goto par_range_error;
483 value = par_range_value;
484 if (KMP_SSCANF(value,
"%d:%d", out_lb, out_ub) != 2) {
485 goto par_range_error;
488 value = strchr(value,
',');
494 if (!__kmp_strcasecmp_with_sentinel(
"excl_range", value,
'=')) {
495 par_range_value = strchr(value,
'=') + 1;
496 if (!par_range_value)
497 goto par_range_error;
498 value = par_range_value;
499 if (KMP_SSCANF(value,
"%d:%d", out_lb, out_ub) != 2) {
500 goto par_range_error;
503 value = strchr(value,
',');
510 KMP_WARNING(ParRangeSyntax, name);
517 int __kmp_initial_threads_capacity(
int req_nproc) {
522 if (nth < (4 * req_nproc))
523 nth = (4 * req_nproc);
524 if (nth < (4 * __kmp_xproc))
525 nth = (4 * __kmp_xproc);
529 if (__kmp_enable_hidden_helper) {
530 nth += __kmp_hidden_helper_threads_num;
533 if (nth > __kmp_max_nth)
539 int __kmp_default_tp_capacity(
int req_nproc,
int max_nth,
540 int all_threads_specified) {
543 if (all_threads_specified)
547 if (nth < (4 * req_nproc))
548 nth = (4 * req_nproc);
549 if (nth < (4 * __kmp_xproc))
550 nth = (4 * __kmp_xproc);
552 if (nth > __kmp_max_nth)
561 static void __kmp_stg_print_bool(kmp_str_buf_t *buffer,
char const *name,
563 if (__kmp_env_format) {
564 KMP_STR_BUF_PRINT_BOOL;
566 __kmp_str_buf_print(buffer,
" %s=%s\n", name, value ?
"true" :
"false");
570 static void __kmp_stg_print_int(kmp_str_buf_t *buffer,
char const *name,
572 if (__kmp_env_format) {
573 KMP_STR_BUF_PRINT_INT;
575 __kmp_str_buf_print(buffer,
" %s=%d\n", name, value);
579 static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer,
char const *name,
581 if (__kmp_env_format) {
582 KMP_STR_BUF_PRINT_UINT64;
584 __kmp_str_buf_print(buffer,
" %s=%" KMP_UINT64_SPEC
"\n", name, value);
588 static void __kmp_stg_print_str(kmp_str_buf_t *buffer,
char const *name,
590 if (__kmp_env_format) {
591 KMP_STR_BUF_PRINT_STR;
593 __kmp_str_buf_print(buffer,
" %s=%s\n", name, value);
597 static void __kmp_stg_print_size(kmp_str_buf_t *buffer,
char const *name,
599 if (__kmp_env_format) {
600 KMP_STR_BUF_PRINT_NAME_EX(name);
601 __kmp_str_buf_print_size(buffer, value);
602 __kmp_str_buf_print(buffer,
"'\n");
604 __kmp_str_buf_print(buffer,
" %s=", name);
605 __kmp_str_buf_print_size(buffer, value);
606 __kmp_str_buf_print(buffer,
"\n");
617 static void __kmp_stg_parse_device_thread_limit(
char const *name,
618 char const *value,
void *data) {
619 kmp_setting_t **rivals = (kmp_setting_t **)data;
621 if (strcmp(name,
"KMP_ALL_THREADS") == 0) {
622 KMP_INFORM(EnvVarDeprecated, name,
"KMP_DEVICE_THREAD_LIMIT");
624 rc = __kmp_stg_check_rivals(name, value, rivals);
628 if (!__kmp_strcasecmp_with_sentinel(
"all", value, 0)) {
629 __kmp_max_nth = __kmp_xproc;
630 __kmp_allThreadsSpecified = 1;
632 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
633 __kmp_allThreadsSpecified = 0;
635 K_DIAG(1, (
"__kmp_max_nth == %d\n", __kmp_max_nth));
639 static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
640 char const *name,
void *data) {
641 __kmp_stg_print_int(buffer, name, __kmp_max_nth);
646 static void __kmp_stg_parse_thread_limit(
char const *name,
char const *value,
648 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
649 K_DIAG(1, (
"__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));
653 static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
654 char const *name,
void *data) {
655 __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
660 static void __kmp_stg_parse_nteams(
char const *name,
char const *value,
662 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_nteams);
663 K_DIAG(1, (
"__kmp_nteams == %d\n", __kmp_nteams));
666 static void __kmp_stg_print_nteams(kmp_str_buf_t *buffer,
char const *name,
668 __kmp_stg_print_int(buffer, name, __kmp_nteams);
673 static void __kmp_stg_parse_teams_th_limit(
char const *name,
char const *value,
675 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth,
676 &__kmp_teams_thread_limit);
677 K_DIAG(1, (
"__kmp_teams_thread_limit == %d\n", __kmp_teams_thread_limit));
680 static void __kmp_stg_print_teams_th_limit(kmp_str_buf_t *buffer,
681 char const *name,
void *data) {
682 __kmp_stg_print_int(buffer, name, __kmp_teams_thread_limit);
687 static void __kmp_stg_parse_teams_thread_limit(
char const *name,
688 char const *value,
void *data) {
689 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
692 static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
693 char const *name,
void *data) {
694 __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
699 static void __kmp_stg_parse_use_yield(
char const *name,
char const *value,
701 __kmp_stg_parse_int(name, value, 0, 2, &__kmp_use_yield);
702 __kmp_use_yield_exp_set = 1;
705 static void __kmp_stg_print_use_yield(kmp_str_buf_t *buffer,
char const *name,
707 __kmp_stg_print_int(buffer, name, __kmp_use_yield);
713 static void __kmp_stg_parse_blocktime(
char const *name,
char const *value,
715 __kmp_dflt_blocktime = __kmp_convert_to_milliseconds(value);
716 if (__kmp_dflt_blocktime < 0) {
717 __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
718 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
720 KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime);
721 __kmp_env_blocktime = FALSE;
723 if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
724 __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
725 __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
727 KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime);
728 }
else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
729 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
730 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
732 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime);
734 __kmp_env_blocktime = TRUE;
739 __kmp_monitor_wakeups =
740 KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
742 KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
744 K_DIAG(1, (
"__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
745 if (__kmp_env_blocktime) {
746 K_DIAG(1, (
"__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
750 static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer,
char const *name,
752 __kmp_stg_print_int(buffer, name, __kmp_dflt_blocktime);
758 static void __kmp_stg_parse_duplicate_lib_ok(
char const *name,
759 char const *value,
void *data) {
762 __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
765 static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
766 char const *name,
void *data) {
767 __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
773 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
775 static void __kmp_stg_parse_inherit_fp_control(
char const *name,
776 char const *value,
void *data) {
777 __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
780 static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
781 char const *name,
void *data) {
783 __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
790 static char const *blocktime_str = NULL;
795 static void __kmp_stg_parse_wait_policy(
char const *name,
char const *value,
798 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
801 rc = __kmp_stg_check_rivals(name, value, wait->rivals);
807 if (__kmp_str_match(
"ACTIVE", 1, value)) {
808 __kmp_library = library_turnaround;
809 if (blocktime_str == NULL) {
811 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
813 }
else if (__kmp_str_match(
"PASSIVE", 1, value)) {
814 __kmp_library = library_throughput;
815 if (blocktime_str == NULL) {
817 __kmp_dflt_blocktime = 0;
820 KMP_WARNING(StgInvalidValue, name, value);
823 if (__kmp_str_match(
"serial", 1, value)) {
824 __kmp_library = library_serial;
825 }
else if (__kmp_str_match(
"throughput", 2, value)) {
826 __kmp_library = library_throughput;
827 if (blocktime_str == NULL) {
829 __kmp_dflt_blocktime = 0;
831 }
else if (__kmp_str_match(
"turnaround", 2, value)) {
832 __kmp_library = library_turnaround;
833 }
else if (__kmp_str_match(
"dedicated", 1, value)) {
834 __kmp_library = library_turnaround;
835 }
else if (__kmp_str_match(
"multiuser", 1, value)) {
836 __kmp_library = library_throughput;
837 if (blocktime_str == NULL) {
839 __kmp_dflt_blocktime = 0;
842 KMP_WARNING(StgInvalidValue, name, value);
847 static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer,
char const *name,
850 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
851 char const *value = NULL;
854 switch (__kmp_library) {
855 case library_turnaround: {
858 case library_throughput: {
863 switch (__kmp_library) {
864 case library_serial: {
867 case library_turnaround: {
868 value =
"turnaround";
870 case library_throughput: {
871 value =
"throughput";
876 __kmp_stg_print_str(buffer, name, value);
885 static void __kmp_stg_parse_monitor_stacksize(
char const *name,
886 char const *value,
void *data) {
887 __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
888 NULL, &__kmp_monitor_stksize, 1);
891 static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
892 char const *name,
void *data) {
893 if (__kmp_env_format) {
894 if (__kmp_monitor_stksize > 0)
895 KMP_STR_BUF_PRINT_NAME_EX(name);
897 KMP_STR_BUF_PRINT_NAME;
899 __kmp_str_buf_print(buffer,
" %s", name);
901 if (__kmp_monitor_stksize > 0) {
902 __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
904 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
906 if (__kmp_env_format && __kmp_monitor_stksize) {
907 __kmp_str_buf_print(buffer,
"'\n");
915 static void __kmp_stg_parse_settings(
char const *name,
char const *value,
917 __kmp_stg_parse_bool(name, value, &__kmp_settings);
920 static void __kmp_stg_print_settings(kmp_str_buf_t *buffer,
char const *name,
922 __kmp_stg_print_bool(buffer, name, __kmp_settings);
928 static void __kmp_stg_parse_stackpad(
char const *name,
char const *value,
930 __kmp_stg_parse_int(name,
938 static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer,
char const *name,
940 __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
946 static void __kmp_stg_parse_stackoffset(
char const *name,
char const *value,
948 __kmp_stg_parse_size(name,
957 static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer,
char const *name,
959 __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
965 static void __kmp_stg_parse_stacksize(
char const *name,
char const *value,
968 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
971 rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
975 __kmp_stg_parse_size(name,
977 __kmp_sys_min_stksize,
989 static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer,
char const *name,
991 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
992 if (__kmp_env_format) {
993 KMP_STR_BUF_PRINT_NAME_EX(name);
994 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
995 ? __kmp_stksize / stacksize->factor
997 __kmp_str_buf_print(buffer,
"'\n");
999 __kmp_str_buf_print(buffer,
" %s=", name);
1000 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
1001 ? __kmp_stksize / stacksize->factor
1003 __kmp_str_buf_print(buffer,
"\n");
1010 static void __kmp_stg_parse_version(
char const *name,
char const *value,
1012 __kmp_stg_parse_bool(name, value, &__kmp_version);
1015 static void __kmp_stg_print_version(kmp_str_buf_t *buffer,
char const *name,
1017 __kmp_stg_print_bool(buffer, name, __kmp_version);
1023 static void __kmp_stg_parse_warnings(
char const *name,
char const *value,
1025 __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
1026 if (__kmp_generate_warnings != kmp_warnings_off) {
1029 __kmp_generate_warnings = kmp_warnings_explicit;
1033 static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer,
char const *name,
1036 __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
1042 static void __kmp_stg_parse_nesting_mode(
char const *name,
char const *value,
1044 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_nesting_mode);
1045 #if KMP_AFFINITY_SUPPORTED && KMP_USE_HWLOC
1046 if (__kmp_nesting_mode > 0)
1047 __kmp_affinity_top_method = affinity_top_method_hwloc;
1051 static void __kmp_stg_print_nesting_mode(kmp_str_buf_t *buffer,
1052 char const *name,
void *data) {
1053 if (__kmp_env_format) {
1054 KMP_STR_BUF_PRINT_NAME;
1056 __kmp_str_buf_print(buffer,
" %s", name);
1058 __kmp_str_buf_print(buffer,
"=%d\n", __kmp_nesting_mode);
1064 static void __kmp_stg_parse_nested(
char const *name,
char const *value,
1067 KMP_INFORM(EnvVarDeprecated, name,
"OMP_MAX_ACTIVE_LEVELS");
1068 __kmp_stg_parse_bool(name, value, &nested);
1070 if (!__kmp_dflt_max_active_levels_set)
1071 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1073 __kmp_dflt_max_active_levels = 1;
1074 __kmp_dflt_max_active_levels_set =
true;
1078 static void __kmp_stg_print_nested(kmp_str_buf_t *buffer,
char const *name,
1080 if (__kmp_env_format) {
1081 KMP_STR_BUF_PRINT_NAME;
1083 __kmp_str_buf_print(buffer,
" %s", name);
1085 __kmp_str_buf_print(buffer,
": deprecated; max-active-levels-var=%d\n",
1086 __kmp_dflt_max_active_levels);
1089 static void __kmp_parse_nested_num_threads(
const char *var,
const char *env,
1090 kmp_nested_nthreads_t *nth_array) {
1091 const char *next = env;
1092 const char *scan = next;
1095 int prev_comma = FALSE;
1101 if (*next ==
'\0') {
1105 if (((*next <
'0') || (*next >
'9')) && (*next !=
',')) {
1106 KMP_WARNING(NthSyntaxError, var, env);
1112 if (total == 0 || prev_comma) {
1120 if (*next >=
'0' && *next <=
'9') {
1124 const char *tmp = next;
1126 if ((*next ==
' ' || *next ==
'\t') && (*tmp >=
'0' && *tmp <=
'9')) {
1127 KMP_WARNING(NthSpacesNotAllowed, var, env);
1132 if (!__kmp_dflt_max_active_levels_set && total > 1)
1133 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1134 KMP_DEBUG_ASSERT(total > 0);
1136 KMP_WARNING(NthSyntaxError, var, env);
1141 if (!nth_array->nth) {
1143 nth_array->nth = (
int *)KMP_INTERNAL_MALLOC(
sizeof(
int) * total * 2);
1144 if (nth_array->nth == NULL) {
1145 KMP_FATAL(MemoryAllocFailed);
1147 nth_array->size = total * 2;
1149 if (nth_array->size < total) {
1152 nth_array->size *= 2;
1153 }
while (nth_array->size < total);
1155 nth_array->nth = (
int *)KMP_INTERNAL_REALLOC(
1156 nth_array->nth,
sizeof(
int) * nth_array->size);
1157 if (nth_array->nth == NULL) {
1158 KMP_FATAL(MemoryAllocFailed);
1162 nth_array->used = total;
1170 if (*scan ==
'\0') {
1180 nth_array->nth[i++] = 0;
1182 }
else if (prev_comma) {
1184 nth_array->nth[i] = nth_array->nth[i - 1];
1193 if (*scan >=
'0' && *scan <=
'9') {
1195 const char *buf = scan;
1196 char const *msg = NULL;
1201 num = __kmp_str_to_int(buf, *scan);
1202 if (num < KMP_MIN_NTH) {
1203 msg = KMP_I18N_STR(ValueTooSmall);
1205 }
else if (num > __kmp_sys_max_nth) {
1206 msg = KMP_I18N_STR(ValueTooLarge);
1207 num = __kmp_sys_max_nth;
1211 KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1212 KMP_INFORM(Using_int_Value, var, num);
1214 nth_array->nth[i++] = num;
1219 static void __kmp_stg_parse_num_threads(
char const *name,
char const *value,
1222 if (!__kmp_strcasecmp_with_sentinel(
"all", value, 0)) {
1224 __kmp_nested_nth.nth = (
int *)KMP_INTERNAL_MALLOC(
sizeof(
int));
1225 __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1226 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1229 __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1230 if (__kmp_nested_nth.nth) {
1231 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1232 if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1233 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1237 K_DIAG(1, (
"__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
1240 static void __kmp_stg_parse_num_hidden_helper_threads(
char const *name,
1243 __kmp_stg_parse_int(name, value, 0, 16, &__kmp_hidden_helper_threads_num);
1246 if (__kmp_hidden_helper_threads_num == 0) {
1247 __kmp_enable_hidden_helper = FALSE;
1251 static void __kmp_stg_print_num_hidden_helper_threads(kmp_str_buf_t *buffer,
1254 __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num);
1257 static void __kmp_stg_parse_use_hidden_helper(
char const *name,
1258 char const *value,
void *data) {
1259 __kmp_stg_parse_bool(name, value, &__kmp_enable_hidden_helper);
1261 __kmp_enable_hidden_helper = FALSE;
1263 (
"__kmp_stg_parse_use_hidden_helper: Disable hidden helper task on "
1264 "non-Linux platform although it is enabled by user explicitly.\n"));
1268 static void __kmp_stg_print_use_hidden_helper(kmp_str_buf_t *buffer,
1269 char const *name,
void *data) {
1270 __kmp_stg_print_bool(buffer, name, __kmp_enable_hidden_helper);
1273 static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer,
char const *name,
1275 if (__kmp_env_format) {
1276 KMP_STR_BUF_PRINT_NAME;
1278 __kmp_str_buf_print(buffer,
" %s", name);
1280 if (__kmp_nested_nth.used) {
1282 __kmp_str_buf_init(&buf);
1283 for (
int i = 0; i < __kmp_nested_nth.used; i++) {
1284 __kmp_str_buf_print(&buf,
"%d", __kmp_nested_nth.nth[i]);
1285 if (i < __kmp_nested_nth.used - 1) {
1286 __kmp_str_buf_print(&buf,
",");
1289 __kmp_str_buf_print(buffer,
"='%s'\n", buf.str);
1290 __kmp_str_buf_free(&buf);
1292 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
1299 static void __kmp_stg_parse_tasking(
char const *name,
char const *value,
1301 __kmp_stg_parse_int(name, value, 0, (
int)tskm_max,
1302 (
int *)&__kmp_tasking_mode);
1305 static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer,
char const *name,
1307 __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
1310 static void __kmp_stg_parse_task_stealing(
char const *name,
char const *value,
1312 __kmp_stg_parse_int(name, value, 0, 1,
1313 (
int *)&__kmp_task_stealing_constraint);
1316 static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1317 char const *name,
void *data) {
1318 __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
1321 static void __kmp_stg_parse_max_active_levels(
char const *name,
1322 char const *value,
void *data) {
1323 kmp_uint64 tmp_dflt = 0;
1324 char const *msg = NULL;
1325 if (!__kmp_dflt_max_active_levels_set) {
1327 __kmp_str_to_uint(value, &tmp_dflt, &msg);
1329 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1330 }
else if (tmp_dflt > KMP_MAX_ACTIVE_LEVELS_LIMIT) {
1332 msg = KMP_I18N_STR(ValueTooLarge);
1333 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1335 __kmp_type_convert(tmp_dflt, &(__kmp_dflt_max_active_levels));
1336 __kmp_dflt_max_active_levels_set =
true;
1341 static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1342 char const *name,
void *data) {
1343 __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
1348 static void __kmp_stg_parse_default_device(
char const *name,
char const *value,
1350 __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1351 &__kmp_default_device);
1354 static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1355 char const *name,
void *data) {
1356 __kmp_stg_print_int(buffer, name, __kmp_default_device);
1361 static void __kmp_stg_parse_target_offload(
char const *name,
char const *value,
1363 const char *next = value;
1364 const char *scan = next;
1366 __kmp_target_offload = tgt_default;
1371 if (!__kmp_strcasecmp_with_sentinel(
"mandatory", scan, 0)) {
1372 __kmp_target_offload = tgt_mandatory;
1373 }
else if (!__kmp_strcasecmp_with_sentinel(
"disabled", scan, 0)) {
1374 __kmp_target_offload = tgt_disabled;
1375 }
else if (!__kmp_strcasecmp_with_sentinel(
"default", scan, 0)) {
1376 __kmp_target_offload = tgt_default;
1378 KMP_WARNING(SyntaxErrorUsing, name,
"DEFAULT");
1383 static void __kmp_stg_print_target_offload(kmp_str_buf_t *buffer,
1384 char const *name,
void *data) {
1385 const char *value = NULL;
1386 if (__kmp_target_offload == tgt_default)
1388 else if (__kmp_target_offload == tgt_mandatory)
1389 value =
"MANDATORY";
1390 else if (__kmp_target_offload == tgt_disabled)
1392 KMP_DEBUG_ASSERT(value);
1393 if (__kmp_env_format) {
1394 KMP_STR_BUF_PRINT_NAME;
1396 __kmp_str_buf_print(buffer,
" %s", name);
1398 __kmp_str_buf_print(buffer,
"=%s\n", value);
1403 static void __kmp_stg_parse_max_task_priority(
char const *name,
1404 char const *value,
void *data) {
1405 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1406 &__kmp_max_task_priority);
1409 static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1410 char const *name,
void *data) {
1411 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
1416 static void __kmp_stg_parse_taskloop_min_tasks(
char const *name,
1417 char const *value,
void *data) {
1419 __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1420 __kmp_taskloop_min_tasks = tmp;
1423 static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
1424 char const *name,
void *data) {
1425 __kmp_stg_print_uint64(buffer, name, __kmp_taskloop_min_tasks);
1430 static void __kmp_stg_parse_disp_buffers(
char const *name,
char const *value,
1432 if (TCR_4(__kmp_init_serial)) {
1433 KMP_WARNING(EnvSerialWarn, name);
1436 __kmp_stg_parse_int(name, value, KMP_MIN_DISP_NUM_BUFF, KMP_MAX_DISP_NUM_BUFF,
1437 &__kmp_dispatch_num_buffers);
1440 static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1441 char const *name,
void *data) {
1442 __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
1445 #if KMP_NESTED_HOT_TEAMS
1449 static void __kmp_stg_parse_hot_teams_level(
char const *name,
char const *value,
1451 if (TCR_4(__kmp_init_parallel)) {
1452 KMP_WARNING(EnvParallelWarn, name);
1455 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1456 &__kmp_hot_teams_max_level);
1459 static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1460 char const *name,
void *data) {
1461 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
1464 static void __kmp_stg_parse_hot_teams_mode(
char const *name,
char const *value,
1466 if (TCR_4(__kmp_init_parallel)) {
1467 KMP_WARNING(EnvParallelWarn, name);
1470 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1471 &__kmp_hot_teams_mode);
1474 static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1475 char const *name,
void *data) {
1476 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
1484 #if KMP_HANDLE_SIGNALS
1486 static void __kmp_stg_parse_handle_signals(
char const *name,
char const *value,
1488 __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
1491 static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1492 char const *name,
void *data) {
1493 __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
1503 #define KMP_STG_X_DEBUG(x) \
1504 static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1506 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1508 static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1509 char const *name, void *data) { \
1510 __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1520 #undef KMP_STG_X_DEBUG
1522 static void __kmp_stg_parse_debug(
char const *name,
char const *value,
1525 __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1526 if (kmp_a_debug < debug) {
1527 kmp_a_debug = debug;
1529 if (kmp_b_debug < debug) {
1530 kmp_b_debug = debug;
1532 if (kmp_c_debug < debug) {
1533 kmp_c_debug = debug;
1535 if (kmp_d_debug < debug) {
1536 kmp_d_debug = debug;
1538 if (kmp_e_debug < debug) {
1539 kmp_e_debug = debug;
1541 if (kmp_f_debug < debug) {
1542 kmp_f_debug = debug;
1546 static void __kmp_stg_parse_debug_buf(
char const *name,
char const *value,
1548 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1552 if (__kmp_debug_buf) {
1554 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
1557 __kmp_debug_buffer = (
char *)__kmp_page_allocate(elements *
sizeof(
char));
1558 for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1559 __kmp_debug_buffer[i] =
'\0';
1561 __kmp_debug_count = 0;
1563 K_DIAG(1, (
"__kmp_debug_buf = %d\n", __kmp_debug_buf));
1566 static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer,
char const *name,
1568 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
1571 static void __kmp_stg_parse_debug_buf_atomic(
char const *name,
1572 char const *value,
void *data) {
1573 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
1576 static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1577 char const *name,
void *data) {
1578 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
1581 static void __kmp_stg_parse_debug_buf_chars(
char const *name,
char const *value,
1583 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1584 &__kmp_debug_buf_chars);
1587 static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1588 char const *name,
void *data) {
1589 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
1592 static void __kmp_stg_parse_debug_buf_lines(
char const *name,
char const *value,
1594 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1595 &__kmp_debug_buf_lines);
1598 static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1599 char const *name,
void *data) {
1600 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
1603 static void __kmp_stg_parse_diag(
char const *name,
char const *value,
1605 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
1608 static void __kmp_stg_print_diag(kmp_str_buf_t *buffer,
char const *name,
1610 __kmp_stg_print_int(buffer, name, kmp_diag);
1618 static void __kmp_stg_parse_align_alloc(
char const *name,
char const *value,
1620 __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1621 &__kmp_align_alloc, 1);
1624 static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer,
char const *name,
1626 __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
1635 static void __kmp_stg_parse_barrier_branch_bit(
char const *name,
1636 char const *value,
void *data) {
1640 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1641 var = __kmp_barrier_branch_bit_env_name[i];
1642 if ((strcmp(var, name) == 0) && (value != 0)) {
1645 comma = CCAST(
char *, strchr(value,
','));
1646 __kmp_barrier_gather_branch_bits[i] =
1647 (kmp_uint32)__kmp_str_to_int(value,
',');
1649 if (comma == NULL) {
1650 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1652 __kmp_barrier_release_branch_bits[i] =
1653 (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
1655 if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1656 __kmp_msg(kmp_ms_warning,
1657 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1659 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1662 if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1663 KMP_WARNING(BarrGatherValueInvalid, name, value);
1664 KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1665 __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1668 K_DIAG(1, (
"%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1669 __kmp_barrier_gather_branch_bits[i],
1670 __kmp_barrier_release_branch_bits[i]))
1674 static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1675 char const *name,
void *data) {
1677 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1678 var = __kmp_barrier_branch_bit_env_name[i];
1679 if (strcmp(var, name) == 0) {
1680 if (__kmp_env_format) {
1681 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1683 __kmp_str_buf_print(buffer,
" %s='",
1684 __kmp_barrier_branch_bit_env_name[i]);
1686 __kmp_str_buf_print(buffer,
"%d,%d'\n",
1687 __kmp_barrier_gather_branch_bits[i],
1688 __kmp_barrier_release_branch_bits[i]);
1700 static void __kmp_stg_parse_barrier_pattern(
char const *name,
char const *value,
1705 static int dist_req = 0, non_dist_req = 0;
1706 static bool warn = 1;
1707 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1708 var = __kmp_barrier_pattern_env_name[i];
1710 if ((strcmp(var, name) == 0) && (value != 0)) {
1712 char *comma = CCAST(
char *, strchr(value,
','));
1715 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1716 if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1718 if (j == bp_dist_bar) {
1723 __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1727 if (j == bp_last_bar) {
1728 KMP_WARNING(BarrGatherValueInvalid, name, value);
1729 KMP_INFORM(Using_str_Value, name,
1730 __kmp_barrier_pattern_name[bp_linear_bar]);
1734 if (comma != NULL) {
1735 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1736 if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1737 if (j == bp_dist_bar) {
1742 __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1746 if (j == bp_last_bar) {
1747 __kmp_msg(kmp_ms_warning,
1748 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1750 KMP_INFORM(Using_str_Value, name,
1751 __kmp_barrier_pattern_name[bp_linear_bar]);
1756 if ((dist_req == 0) && (non_dist_req != 0)) {
1758 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1759 if (__kmp_barrier_release_pattern[i] == bp_dist_bar)
1760 __kmp_barrier_release_pattern[i] = bp_hyper_bar;
1761 if (__kmp_barrier_gather_pattern[i] == bp_dist_bar)
1762 __kmp_barrier_gather_pattern[i] = bp_hyper_bar;
1764 }
else if (non_dist_req != 0) {
1766 if (non_dist_req > 0 && dist_req > 0 && warn) {
1767 KMP_INFORM(BarrierPatternOverride, name,
1768 __kmp_barrier_pattern_name[bp_dist_bar]);
1771 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1772 if (__kmp_barrier_release_pattern[i] != bp_dist_bar)
1773 __kmp_barrier_release_pattern[i] = bp_dist_bar;
1774 if (__kmp_barrier_gather_pattern[i] != bp_dist_bar)
1775 __kmp_barrier_gather_pattern[i] = bp_dist_bar;
1780 static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1781 char const *name,
void *data) {
1783 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1784 var = __kmp_barrier_pattern_env_name[i];
1785 if (strcmp(var, name) == 0) {
1786 int j = __kmp_barrier_gather_pattern[i];
1787 int k = __kmp_barrier_release_pattern[i];
1788 if (__kmp_env_format) {
1789 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1791 __kmp_str_buf_print(buffer,
" %s='",
1792 __kmp_barrier_pattern_env_name[i]);
1794 KMP_DEBUG_ASSERT(j < bp_last_bar && k < bp_last_bar);
1795 __kmp_str_buf_print(buffer,
"%s,%s'\n", __kmp_barrier_pattern_name[j],
1796 __kmp_barrier_pattern_name[k]);
1804 static void __kmp_stg_parse_abort_delay(
char const *name,
char const *value,
1808 int delay = __kmp_abort_delay / 1000;
1809 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1810 __kmp_abort_delay = delay * 1000;
1813 static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer,
char const *name,
1815 __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
1821 static void __kmp_stg_parse_cpuinfo_file(
char const *name,
char const *value,
1823 #if KMP_AFFINITY_SUPPORTED
1824 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1825 K_DIAG(1, (
"__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1829 static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1830 char const *name,
void *data) {
1831 #if KMP_AFFINITY_SUPPORTED
1832 if (__kmp_env_format) {
1833 KMP_STR_BUF_PRINT_NAME;
1835 __kmp_str_buf_print(buffer,
" %s", name);
1837 if (__kmp_cpuinfo_file) {
1838 __kmp_str_buf_print(buffer,
"='%s'\n", __kmp_cpuinfo_file);
1840 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
1848 static void __kmp_stg_parse_force_reduction(
char const *name,
char const *value,
1850 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1853 rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1857 if (reduction->force) {
1859 if (__kmp_str_match(
"critical", 0, value))
1860 __kmp_force_reduction_method = critical_reduce_block;
1861 else if (__kmp_str_match(
"atomic", 0, value))
1862 __kmp_force_reduction_method = atomic_reduce_block;
1863 else if (__kmp_str_match(
"tree", 0, value))
1864 __kmp_force_reduction_method = tree_reduce_block;
1866 KMP_FATAL(UnknownForceReduction, name, value);
1870 __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1871 if (__kmp_determ_red) {
1872 __kmp_force_reduction_method = tree_reduce_block;
1874 __kmp_force_reduction_method = reduction_method_not_defined;
1877 K_DIAG(1, (
"__kmp_force_reduction_method == %d\n",
1878 __kmp_force_reduction_method));
1881 static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1882 char const *name,
void *data) {
1884 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1885 if (reduction->force) {
1886 if (__kmp_force_reduction_method == critical_reduce_block) {
1887 __kmp_stg_print_str(buffer, name,
"critical");
1888 }
else if (__kmp_force_reduction_method == atomic_reduce_block) {
1889 __kmp_stg_print_str(buffer, name,
"atomic");
1890 }
else if (__kmp_force_reduction_method == tree_reduce_block) {
1891 __kmp_stg_print_str(buffer, name,
"tree");
1893 if (__kmp_env_format) {
1894 KMP_STR_BUF_PRINT_NAME;
1896 __kmp_str_buf_print(buffer,
" %s", name);
1898 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
1901 __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1909 static void __kmp_stg_parse_storage_map(
char const *name,
char const *value,
1911 if (__kmp_str_match(
"verbose", 1, value)) {
1912 __kmp_storage_map = TRUE;
1913 __kmp_storage_map_verbose = TRUE;
1914 __kmp_storage_map_verbose_specified = TRUE;
1917 __kmp_storage_map_verbose = FALSE;
1918 __kmp_stg_parse_bool(name, value, &__kmp_storage_map);
1922 static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer,
char const *name,
1924 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1925 __kmp_stg_print_str(buffer, name,
"verbose");
1927 __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1934 static void __kmp_stg_parse_all_threadprivate(
char const *name,
1935 char const *value,
void *data) {
1936 __kmp_stg_parse_int(name, value,
1937 __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1938 __kmp_max_nth, &__kmp_tp_capacity);
1941 static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1942 char const *name,
void *data) {
1943 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
1949 static void __kmp_stg_parse_foreign_threads_threadprivate(
char const *name,
1952 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
1955 static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
1958 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
1964 #if KMP_AFFINITY_SUPPORTED
1966 static int __kmp_parse_affinity_proc_id_list(
const char *var,
const char *env,
1967 const char **nextEnv,
1969 const char *scan = env;
1970 const char *next = scan;
1976 int start, end, stride;
1980 if (*next ==
'\0') {
1991 if ((*next <
'0') || (*next >
'9')) {
1992 KMP_WARNING(AffSyntaxError, var);
1996 num = __kmp_str_to_int(scan, *next);
1997 KMP_ASSERT(num >= 0);
2015 if ((*next <
'0') || (*next >
'9')) {
2016 KMP_WARNING(AffSyntaxError, var);
2021 num = __kmp_str_to_int(scan, *next);
2022 KMP_ASSERT(num >= 0);
2035 if ((*next <
'0') || (*next >
'9')) {
2037 KMP_WARNING(AffSyntaxError, var);
2045 start = __kmp_str_to_int(scan, *next);
2046 KMP_ASSERT(start >= 0);
2065 if ((*next <
'0') || (*next >
'9')) {
2066 KMP_WARNING(AffSyntaxError, var);
2070 end = __kmp_str_to_int(scan, *next);
2071 KMP_ASSERT(end >= 0);
2088 if ((*next <
'0') || (*next >
'9')) {
2089 KMP_WARNING(AffSyntaxError, var);
2093 stride = __kmp_str_to_int(scan, *next);
2094 KMP_ASSERT(stride >= 0);
2100 KMP_WARNING(AffZeroStride, var);
2105 KMP_WARNING(AffStartGreaterEnd, var, start, end);
2110 KMP_WARNING(AffStrideLessZero, var, start, end);
2114 if ((end - start) / stride > 65536) {
2115 KMP_WARNING(AffRangeTooBig, var, end, start, stride);
2132 ptrdiff_t len = next - env;
2133 char *retlist = (
char *)__kmp_allocate((len + 1) *
sizeof(char));
2134 KMP_MEMCPY_S(retlist, (len + 1) *
sizeof(
char), env, len *
sizeof(
char));
2135 retlist[len] =
'\0';
2136 *proclist = retlist;
2143 static kmp_setting_t *__kmp_affinity_notype = NULL;
2145 static void __kmp_parse_affinity_env(
char const *name,
char const *value,
2146 enum affinity_type *out_type,
2147 char **out_proclist,
int *out_verbose,
2148 int *out_warn,
int *out_respect,
2149 kmp_hw_t *out_gran,
int *out_gran_levels,
2150 int *out_dups,
int *out_compact,
2152 char *buffer = NULL;
2169 KMP_ASSERT(value != NULL);
2171 if (TCR_4(__kmp_init_middle)) {
2172 KMP_WARNING(EnvMiddleWarn, name);
2173 __kmp_env_toPrint(name, 0);
2176 __kmp_env_toPrint(name, 1);
2179 __kmp_str_format(
"%s", value);
2189 #define EMIT_WARN(skip, errlist) \
2193 SKIP_TO(next, ','); \
2197 KMP_WARNING errlist; \
2206 #define _set_param(_guard, _var, _val) \
2208 if (_guard == 0) { \
2211 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2216 #define set_type(val) _set_param(type, *out_type, val)
2217 #define set_verbose(val) _set_param(verbose, *out_verbose, val)
2218 #define set_warnings(val) _set_param(warnings, *out_warn, val)
2219 #define set_respect(val) _set_param(respect, *out_respect, val)
2220 #define set_dups(val) _set_param(dups, *out_dups, val)
2221 #define set_proclist(val) _set_param(proclist, *out_proclist, val)
2223 #define set_gran(val, levels) \
2227 *out_gran_levels = levels; \
2229 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2234 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
2235 (__kmp_nested_proc_bind.used > 0));
2237 while (*buf !=
'\0') {
2240 if (__kmp_match_str(
"none", buf, CCAST(
const char **, &next))) {
2241 set_type(affinity_none);
2242 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2244 }
else if (__kmp_match_str(
"scatter", buf, CCAST(
const char **, &next))) {
2245 set_type(affinity_scatter);
2246 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2248 }
else if (__kmp_match_str(
"compact", buf, CCAST(
const char **, &next))) {
2249 set_type(affinity_compact);
2250 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2252 }
else if (__kmp_match_str(
"logical", buf, CCAST(
const char **, &next))) {
2253 set_type(affinity_logical);
2254 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2256 }
else if (__kmp_match_str(
"physical", buf, CCAST(
const char **, &next))) {
2257 set_type(affinity_physical);
2258 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2260 }
else if (__kmp_match_str(
"explicit", buf, CCAST(
const char **, &next))) {
2261 set_type(affinity_explicit);
2262 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2264 }
else if (__kmp_match_str(
"balanced", buf, CCAST(
const char **, &next))) {
2265 set_type(affinity_balanced);
2266 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2268 }
else if (__kmp_match_str(
"disabled", buf, CCAST(
const char **, &next))) {
2269 set_type(affinity_disabled);
2270 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2272 }
else if (__kmp_match_str(
"verbose", buf, CCAST(
const char **, &next))) {
2275 }
else if (__kmp_match_str(
"noverbose", buf, CCAST(
const char **, &next))) {
2278 }
else if (__kmp_match_str(
"warnings", buf, CCAST(
const char **, &next))) {
2281 }
else if (__kmp_match_str(
"nowarnings", buf,
2282 CCAST(
const char **, &next))) {
2283 set_warnings(FALSE);
2285 }
else if (__kmp_match_str(
"respect", buf, CCAST(
const char **, &next))) {
2288 }
else if (__kmp_match_str(
"norespect", buf, CCAST(
const char **, &next))) {
2291 }
else if (__kmp_match_str(
"duplicates", buf,
2292 CCAST(
const char **, &next)) ||
2293 __kmp_match_str(
"dups", buf, CCAST(
const char **, &next))) {
2296 }
else if (__kmp_match_str(
"noduplicates", buf,
2297 CCAST(
const char **, &next)) ||
2298 __kmp_match_str(
"nodups", buf, CCAST(
const char **, &next))) {
2301 }
else if (__kmp_match_str(
"granularity", buf,
2302 CCAST(
const char **, &next)) ||
2303 __kmp_match_str(
"gran", buf, CCAST(
const char **, &next))) {
2306 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2315 KMP_FOREACH_HW_TYPE(type) {
2316 const char *name = __kmp_hw_get_keyword(type);
2317 if (__kmp_match_str(name, buf, CCAST(
const char **, &next))) {
2326 if (__kmp_match_str(
"fine", buf, CCAST(
const char **, &next))) {
2327 set_gran(KMP_HW_THREAD, -1);
2330 }
else if (__kmp_match_str(
"package", buf,
2331 CCAST(
const char **, &next))) {
2332 set_gran(KMP_HW_SOCKET, -1);
2335 }
else if (__kmp_match_str(
"node", buf, CCAST(
const char **, &next))) {
2336 set_gran(KMP_HW_NUMA, -1);
2339 #if KMP_GROUP_AFFINITY
2340 }
else if (__kmp_match_str(
"group", buf, CCAST(
const char **, &next))) {
2341 set_gran(KMP_HW_PROC_GROUP, -1);
2345 }
else if ((*buf >=
'0') && (*buf <=
'9')) {
2349 n = __kmp_str_to_int(buf, *next);
2352 set_gran(KMP_HW_UNKNOWN, n);
2355 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2359 }
else if (__kmp_match_str(
"proclist", buf, CCAST(
const char **, &next))) {
2360 char *temp_proclist;
2364 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2370 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2375 if (!__kmp_parse_affinity_proc_id_list(
2376 name, buf, CCAST(
const char **, &next), &temp_proclist)) {
2388 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2392 set_proclist(temp_proclist);
2393 }
else if ((*buf >=
'0') && (*buf <=
'9')) {
2398 n = __kmp_str_to_int(buf, *next);
2404 KMP_WARNING(AffManyParams, name, start);
2408 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2416 }
else if (*next !=
'\0') {
2417 const char *temp = next;
2418 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2430 #undef set_granularity
2432 __kmp_str_free(&buffer);
2436 KMP_WARNING(AffProcListNoType, name);
2437 *out_type = affinity_explicit;
2438 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2439 }
else if (*out_type != affinity_explicit) {
2440 KMP_WARNING(AffProcListNotExplicit, name);
2441 KMP_ASSERT(*out_proclist != NULL);
2442 KMP_INTERNAL_FREE(*out_proclist);
2443 *out_proclist = NULL;
2446 switch (*out_type) {
2447 case affinity_logical:
2448 case affinity_physical: {
2450 *out_offset = number[0];
2453 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
2456 case affinity_balanced: {
2458 *out_compact = number[0];
2461 *out_offset = number[1];
2464 if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
2465 #if KMP_MIC_SUPPORTED
2466 if (__kmp_mic_type != non_mic) {
2467 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2468 KMP_WARNING(AffGranUsing,
"KMP_AFFINITY",
"fine");
2470 __kmp_affinity_gran = KMP_HW_THREAD;
2474 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2475 KMP_WARNING(AffGranUsing,
"KMP_AFFINITY",
"core");
2477 __kmp_affinity_gran = KMP_HW_CORE;
2481 case affinity_scatter:
2482 case affinity_compact: {
2484 *out_compact = number[0];
2487 *out_offset = number[1];
2490 case affinity_explicit: {
2491 if (*out_proclist == NULL) {
2492 KMP_WARNING(AffNoProcList, name);
2493 __kmp_affinity_type = affinity_none;
2496 KMP_WARNING(AffNoParam, name,
"explicit");
2499 case affinity_none: {
2501 KMP_WARNING(AffNoParam, name,
"none");
2504 case affinity_disabled: {
2506 KMP_WARNING(AffNoParam, name,
"disabled");
2509 case affinity_default: {
2511 KMP_WARNING(AffNoParam, name,
"default");
2520 static void __kmp_stg_parse_affinity(
char const *name,
char const *value,
2522 kmp_setting_t **rivals = (kmp_setting_t **)data;
2525 rc = __kmp_stg_check_rivals(name, value, rivals);
2530 __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2531 &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2532 &__kmp_affinity_warnings,
2533 &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2534 &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2535 &__kmp_affinity_compact, &__kmp_affinity_offset);
2539 static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer,
char const *name,
2541 if (__kmp_env_format) {
2542 KMP_STR_BUF_PRINT_NAME_EX(name);
2544 __kmp_str_buf_print(buffer,
" %s='", name);
2546 if (__kmp_affinity_verbose) {
2547 __kmp_str_buf_print(buffer,
"%s,",
"verbose");
2549 __kmp_str_buf_print(buffer,
"%s,",
"noverbose");
2551 if (__kmp_affinity_warnings) {
2552 __kmp_str_buf_print(buffer,
"%s,",
"warnings");
2554 __kmp_str_buf_print(buffer,
"%s,",
"nowarnings");
2556 if (KMP_AFFINITY_CAPABLE()) {
2557 if (__kmp_affinity_respect_mask) {
2558 __kmp_str_buf_print(buffer,
"%s,",
"respect");
2560 __kmp_str_buf_print(buffer,
"%s,",
"norespect");
2562 __kmp_str_buf_print(buffer,
"granularity=%s,",
2563 __kmp_hw_get_keyword(__kmp_affinity_gran,
false));
2565 if (!KMP_AFFINITY_CAPABLE()) {
2566 __kmp_str_buf_print(buffer,
"%s",
"disabled");
2568 switch (__kmp_affinity_type) {
2570 __kmp_str_buf_print(buffer,
"%s",
"none");
2572 case affinity_physical:
2573 __kmp_str_buf_print(buffer,
"%s,%d",
"physical", __kmp_affinity_offset);
2575 case affinity_logical:
2576 __kmp_str_buf_print(buffer,
"%s,%d",
"logical", __kmp_affinity_offset);
2578 case affinity_compact:
2579 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"compact", __kmp_affinity_compact,
2580 __kmp_affinity_offset);
2582 case affinity_scatter:
2583 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"scatter", __kmp_affinity_compact,
2584 __kmp_affinity_offset);
2586 case affinity_explicit:
2587 __kmp_str_buf_print(buffer,
"%s=[%s],%s",
"proclist",
2588 __kmp_affinity_proclist,
"explicit");
2590 case affinity_balanced:
2591 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"balanced",
2592 __kmp_affinity_compact, __kmp_affinity_offset);
2594 case affinity_disabled:
2595 __kmp_str_buf_print(buffer,
"%s",
"disabled");
2597 case affinity_default:
2598 __kmp_str_buf_print(buffer,
"%s",
"default");
2601 __kmp_str_buf_print(buffer,
"%s",
"<unknown>");
2604 __kmp_str_buf_print(buffer,
"'\n");
2607 #ifdef KMP_GOMP_COMPAT
2609 static void __kmp_stg_parse_gomp_cpu_affinity(
char const *name,
2610 char const *value,
void *data) {
2611 const char *next = NULL;
2612 char *temp_proclist;
2613 kmp_setting_t **rivals = (kmp_setting_t **)data;
2616 rc = __kmp_stg_check_rivals(name, value, rivals);
2621 if (TCR_4(__kmp_init_middle)) {
2622 KMP_WARNING(EnvMiddleWarn, name);
2623 __kmp_env_toPrint(name, 0);
2627 __kmp_env_toPrint(name, 1);
2629 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2631 if (*next ==
'\0') {
2633 __kmp_affinity_proclist = temp_proclist;
2634 __kmp_affinity_type = affinity_explicit;
2635 __kmp_affinity_gran = KMP_HW_THREAD;
2636 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2638 KMP_WARNING(AffSyntaxError, name);
2639 if (temp_proclist != NULL) {
2640 KMP_INTERNAL_FREE((
void *)temp_proclist);
2645 __kmp_affinity_type = affinity_none;
2646 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2673 static inline void __kmp_omp_places_syntax_warn(
const char *var) {
2674 KMP_WARNING(SyntaxErrorUsing, var,
"\"cores\"");
2677 static int __kmp_parse_subplace_list(
const char *var,
const char **scan) {
2681 int start, count, stride;
2687 if ((**scan <
'0') || (**scan >
'9')) {
2688 __kmp_omp_places_syntax_warn(var);
2693 start = __kmp_str_to_int(*scan, *next);
2694 KMP_ASSERT(start >= 0);
2699 if (**scan ==
'}') {
2702 if (**scan ==
',') {
2706 if (**scan !=
':') {
2707 __kmp_omp_places_syntax_warn(var);
2714 if ((**scan <
'0') || (**scan >
'9')) {
2715 __kmp_omp_places_syntax_warn(var);
2720 count = __kmp_str_to_int(*scan, *next);
2721 KMP_ASSERT(count >= 0);
2726 if (**scan ==
'}') {
2729 if (**scan ==
',') {
2733 if (**scan !=
':') {
2734 __kmp_omp_places_syntax_warn(var);
2743 if (**scan ==
'+') {
2747 if (**scan ==
'-') {
2755 if ((**scan <
'0') || (**scan >
'9')) {
2756 __kmp_omp_places_syntax_warn(var);
2761 stride = __kmp_str_to_int(*scan, *next);
2762 KMP_ASSERT(stride >= 0);
2768 if (**scan ==
'}') {
2771 if (**scan ==
',') {
2776 __kmp_omp_places_syntax_warn(var);
2782 static int __kmp_parse_place(
const char *var,
const char **scan) {
2787 if (**scan ==
'{') {
2789 if (!__kmp_parse_subplace_list(var, scan)) {
2792 if (**scan !=
'}') {
2793 __kmp_omp_places_syntax_warn(var);
2797 }
else if (**scan ==
'!') {
2799 return __kmp_parse_place(var, scan);
2800 }
else if ((**scan >=
'0') && (**scan <=
'9')) {
2803 int proc = __kmp_str_to_int(*scan, *next);
2804 KMP_ASSERT(proc >= 0);
2807 __kmp_omp_places_syntax_warn(var);
2813 static int __kmp_parse_place_list(
const char *var,
const char *env,
2814 char **place_list) {
2815 const char *scan = env;
2816 const char *next = scan;
2821 if (!__kmp_parse_place(var, &scan)) {
2827 if (*scan ==
'\0') {
2835 __kmp_omp_places_syntax_warn(var);
2842 if ((*scan <
'0') || (*scan >
'9')) {
2843 __kmp_omp_places_syntax_warn(var);
2848 count = __kmp_str_to_int(scan, *next);
2849 KMP_ASSERT(count >= 0);
2854 if (*scan ==
'\0') {
2862 __kmp_omp_places_syntax_warn(var);
2883 if ((*scan <
'0') || (*scan >
'9')) {
2884 __kmp_omp_places_syntax_warn(var);
2889 stride = __kmp_str_to_int(scan, *next);
2890 KMP_ASSERT(stride >= 0);
2896 if (*scan ==
'\0') {
2904 __kmp_omp_places_syntax_warn(var);
2909 ptrdiff_t len = scan - env;
2910 char *retlist = (
char *)__kmp_allocate((len + 1) *
sizeof(char));
2911 KMP_MEMCPY_S(retlist, (len + 1) *
sizeof(
char), env, len *
sizeof(
char));
2912 retlist[len] =
'\0';
2913 *place_list = retlist;
2918 static void __kmp_stg_parse_places(
char const *name,
char const *value,
2920 struct kmp_place_t {
2926 const char *scan = value;
2927 const char *next = scan;
2928 const char *kind =
"\"threads\"";
2929 kmp_place_t std_places[] = {{
"threads", KMP_HW_THREAD},
2930 {
"cores", KMP_HW_CORE},
2931 {
"numa_domains", KMP_HW_NUMA},
2932 {
"ll_caches", KMP_HW_LLC},
2933 {
"sockets", KMP_HW_SOCKET}};
2934 kmp_setting_t **rivals = (kmp_setting_t **)data;
2937 rc = __kmp_stg_check_rivals(name, value, rivals);
2943 for (
size_t i = 0; i <
sizeof(std_places) /
sizeof(std_places[0]); ++i) {
2944 const kmp_place_t &place = std_places[i];
2945 if (__kmp_match_str(place.name, scan, &next)) {
2947 __kmp_affinity_type = affinity_compact;
2948 __kmp_affinity_gran = place.type;
2949 __kmp_affinity_dups = FALSE;
2956 KMP_FOREACH_HW_TYPE(type) {
2957 const char *name = __kmp_hw_get_keyword(type,
true);
2958 if (__kmp_match_str(
"unknowns", scan, &next))
2960 if (__kmp_match_str(name, scan, &next)) {
2962 __kmp_affinity_type = affinity_compact;
2963 __kmp_affinity_gran = type;
2964 __kmp_affinity_dups = FALSE;
2971 if (__kmp_affinity_proclist != NULL) {
2972 KMP_INTERNAL_FREE((
void *)__kmp_affinity_proclist);
2973 __kmp_affinity_proclist = NULL;
2975 if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2976 __kmp_affinity_type = affinity_explicit;
2977 __kmp_affinity_gran = KMP_HW_THREAD;
2978 __kmp_affinity_dups = FALSE;
2981 __kmp_affinity_type = affinity_compact;
2982 __kmp_affinity_gran = KMP_HW_CORE;
2983 __kmp_affinity_dups = FALSE;
2985 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2986 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2990 if (__kmp_affinity_gran != KMP_HW_UNKNOWN) {
2991 kind = __kmp_hw_get_keyword(__kmp_affinity_gran);
2994 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2995 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2999 if (*scan ==
'\0') {
3005 KMP_WARNING(SyntaxErrorUsing, name, kind);
3013 count = __kmp_str_to_int(scan, *next);
3014 KMP_ASSERT(count >= 0);
3019 KMP_WARNING(SyntaxErrorUsing, name, kind);
3025 if (*scan !=
'\0') {
3026 KMP_WARNING(ParseExtraCharsWarn, name, scan);
3028 __kmp_affinity_num_places = count;
3031 static void __kmp_stg_print_places(kmp_str_buf_t *buffer,
char const *name,
3033 if (__kmp_env_format) {
3034 KMP_STR_BUF_PRINT_NAME;
3036 __kmp_str_buf_print(buffer,
" %s", name);
3038 if ((__kmp_nested_proc_bind.used == 0) ||
3039 (__kmp_nested_proc_bind.bind_types == NULL) ||
3040 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
3041 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3042 }
else if (__kmp_affinity_type == affinity_explicit) {
3043 if (__kmp_affinity_proclist != NULL) {
3044 __kmp_str_buf_print(buffer,
"='%s'\n", __kmp_affinity_proclist);
3046 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3048 }
else if (__kmp_affinity_type == affinity_compact) {
3050 if (__kmp_affinity_num_masks > 0) {
3051 num = __kmp_affinity_num_masks;
3052 }
else if (__kmp_affinity_num_places > 0) {
3053 num = __kmp_affinity_num_places;
3057 if (__kmp_affinity_gran != KMP_HW_UNKNOWN) {
3058 const char *name = __kmp_hw_get_keyword(__kmp_affinity_gran,
true);
3060 __kmp_str_buf_print(buffer,
"='%s(%d)'\n", name, num);
3062 __kmp_str_buf_print(buffer,
"='%s'\n", name);
3065 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3068 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3072 static void __kmp_stg_parse_topology_method(
char const *name,
char const *value,
3074 if (__kmp_str_match(
"all", 1, value)) {
3075 __kmp_affinity_top_method = affinity_top_method_all;
3078 else if (__kmp_str_match(
"hwloc", 1, value)) {
3079 __kmp_affinity_top_method = affinity_top_method_hwloc;
3082 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3083 else if (__kmp_str_match(
"cpuid_leaf31", 12, value) ||
3084 __kmp_str_match(
"cpuid 1f", 8, value) ||
3085 __kmp_str_match(
"cpuid 31", 8, value) ||
3086 __kmp_str_match(
"cpuid1f", 7, value) ||
3087 __kmp_str_match(
"cpuid31", 7, value) ||
3088 __kmp_str_match(
"leaf 1f", 7, value) ||
3089 __kmp_str_match(
"leaf 31", 7, value) ||
3090 __kmp_str_match(
"leaf1f", 6, value) ||
3091 __kmp_str_match(
"leaf31", 6, value)) {
3092 __kmp_affinity_top_method = affinity_top_method_x2apicid_1f;
3093 }
else if (__kmp_str_match(
"x2apic id", 9, value) ||
3094 __kmp_str_match(
"x2apic_id", 9, value) ||
3095 __kmp_str_match(
"x2apic-id", 9, value) ||
3096 __kmp_str_match(
"x2apicid", 8, value) ||
3097 __kmp_str_match(
"cpuid leaf 11", 13, value) ||
3098 __kmp_str_match(
"cpuid_leaf_11", 13, value) ||
3099 __kmp_str_match(
"cpuid-leaf-11", 13, value) ||
3100 __kmp_str_match(
"cpuid leaf11", 12, value) ||
3101 __kmp_str_match(
"cpuid_leaf11", 12, value) ||
3102 __kmp_str_match(
"cpuid-leaf11", 12, value) ||
3103 __kmp_str_match(
"cpuidleaf 11", 12, value) ||
3104 __kmp_str_match(
"cpuidleaf_11", 12, value) ||
3105 __kmp_str_match(
"cpuidleaf-11", 12, value) ||
3106 __kmp_str_match(
"cpuidleaf11", 11, value) ||
3107 __kmp_str_match(
"cpuid 11", 8, value) ||
3108 __kmp_str_match(
"cpuid_11", 8, value) ||
3109 __kmp_str_match(
"cpuid-11", 8, value) ||
3110 __kmp_str_match(
"cpuid11", 7, value) ||
3111 __kmp_str_match(
"leaf 11", 7, value) ||
3112 __kmp_str_match(
"leaf_11", 7, value) ||
3113 __kmp_str_match(
"leaf-11", 7, value) ||
3114 __kmp_str_match(
"leaf11", 6, value)) {
3115 __kmp_affinity_top_method = affinity_top_method_x2apicid;
3116 }
else if (__kmp_str_match(
"apic id", 7, value) ||
3117 __kmp_str_match(
"apic_id", 7, value) ||
3118 __kmp_str_match(
"apic-id", 7, value) ||
3119 __kmp_str_match(
"apicid", 6, value) ||
3120 __kmp_str_match(
"cpuid leaf 4", 12, value) ||
3121 __kmp_str_match(
"cpuid_leaf_4", 12, value) ||
3122 __kmp_str_match(
"cpuid-leaf-4", 12, value) ||
3123 __kmp_str_match(
"cpuid leaf4", 11, value) ||
3124 __kmp_str_match(
"cpuid_leaf4", 11, value) ||
3125 __kmp_str_match(
"cpuid-leaf4", 11, value) ||
3126 __kmp_str_match(
"cpuidleaf 4", 11, value) ||
3127 __kmp_str_match(
"cpuidleaf_4", 11, value) ||
3128 __kmp_str_match(
"cpuidleaf-4", 11, value) ||
3129 __kmp_str_match(
"cpuidleaf4", 10, value) ||
3130 __kmp_str_match(
"cpuid 4", 7, value) ||
3131 __kmp_str_match(
"cpuid_4", 7, value) ||
3132 __kmp_str_match(
"cpuid-4", 7, value) ||
3133 __kmp_str_match(
"cpuid4", 6, value) ||
3134 __kmp_str_match(
"leaf 4", 6, value) ||
3135 __kmp_str_match(
"leaf_4", 6, value) ||
3136 __kmp_str_match(
"leaf-4", 6, value) ||
3137 __kmp_str_match(
"leaf4", 5, value)) {
3138 __kmp_affinity_top_method = affinity_top_method_apicid;
3141 else if (__kmp_str_match(
"/proc/cpuinfo", 2, value) ||
3142 __kmp_str_match(
"cpuinfo", 5, value)) {
3143 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
3145 #if KMP_GROUP_AFFINITY
3146 else if (__kmp_str_match(
"group", 1, value)) {
3147 __kmp_affinity_top_method = affinity_top_method_group;
3150 else if (__kmp_str_match(
"flat", 1, value)) {
3151 __kmp_affinity_top_method = affinity_top_method_flat;
3153 KMP_WARNING(StgInvalidValue, name, value);
3157 static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
3158 char const *name,
void *data) {
3159 char const *value = NULL;
3161 switch (__kmp_affinity_top_method) {
3162 case affinity_top_method_default:
3166 case affinity_top_method_all:
3170 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3171 case affinity_top_method_x2apicid_1f:
3172 value =
"x2APIC id leaf 0x1f";
3175 case affinity_top_method_x2apicid:
3176 value =
"x2APIC id leaf 0xb";
3179 case affinity_top_method_apicid:
3185 case affinity_top_method_hwloc:
3190 case affinity_top_method_cpuinfo:
3194 #if KMP_GROUP_AFFINITY
3195 case affinity_top_method_group:
3200 case affinity_top_method_flat:
3205 if (value != NULL) {
3206 __kmp_stg_print_str(buffer, name, value);
3214 static void __kmp_stg_parse_proc_bind(
char const *name,
char const *value,
3216 kmp_setting_t **rivals = (kmp_setting_t **)data;
3219 rc = __kmp_stg_check_rivals(name, value, rivals);
3225 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
3226 (__kmp_nested_proc_bind.used > 0));
3228 const char *buf = value;
3232 if ((*buf >=
'0') && (*buf <=
'9')) {
3235 num = __kmp_str_to_int(buf, *next);
3236 KMP_ASSERT(num >= 0);
3244 if (__kmp_match_str(
"disabled", buf, &next)) {
3247 #if KMP_AFFINITY_SUPPORTED
3248 __kmp_affinity_type = affinity_disabled;
3250 __kmp_nested_proc_bind.used = 1;
3251 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3252 }
else if ((num == (
int)proc_bind_false) ||
3253 __kmp_match_str(
"false", buf, &next)) {
3256 #if KMP_AFFINITY_SUPPORTED
3257 __kmp_affinity_type = affinity_none;
3259 __kmp_nested_proc_bind.used = 1;
3260 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3261 }
else if ((num == (
int)proc_bind_true) ||
3262 __kmp_match_str(
"true", buf, &next)) {
3265 __kmp_nested_proc_bind.used = 1;
3266 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3271 for (scan = buf; *scan !=
'\0'; scan++) {
3278 if (__kmp_nested_proc_bind.size < nelem) {
3279 __kmp_nested_proc_bind.bind_types =
3280 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3281 __kmp_nested_proc_bind.bind_types,
3282 sizeof(kmp_proc_bind_t) * nelem);
3283 if (__kmp_nested_proc_bind.bind_types == NULL) {
3284 KMP_FATAL(MemoryAllocFailed);
3286 __kmp_nested_proc_bind.size = nelem;
3288 __kmp_nested_proc_bind.used = nelem;
3290 if (nelem > 1 && !__kmp_dflt_max_active_levels_set)
3291 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
3296 enum kmp_proc_bind_t bind;
3298 if ((num == (
int)proc_bind_primary) ||
3299 __kmp_match_str(
"master", buf, &next) ||
3300 __kmp_match_str(
"primary", buf, &next)) {
3303 bind = proc_bind_primary;
3304 }
else if ((num == (
int)proc_bind_close) ||
3305 __kmp_match_str(
"close", buf, &next)) {
3308 bind = proc_bind_close;
3309 }
else if ((num == (
int)proc_bind_spread) ||
3310 __kmp_match_str(
"spread", buf, &next)) {
3313 bind = proc_bind_spread;
3315 KMP_WARNING(StgInvalidValue, name, value);
3316 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3317 __kmp_nested_proc_bind.used = 1;
3321 __kmp_nested_proc_bind.bind_types[i++] = bind;
3325 KMP_DEBUG_ASSERT(*buf ==
',');
3330 if ((*buf >=
'0') && (*buf <=
'9')) {
3333 num = __kmp_str_to_int(buf, *next);
3334 KMP_ASSERT(num >= 0);
3344 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3348 static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer,
char const *name,
3350 int nelem = __kmp_nested_proc_bind.used;
3351 if (__kmp_env_format) {
3352 KMP_STR_BUF_PRINT_NAME;
3354 __kmp_str_buf_print(buffer,
" %s", name);
3357 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3360 __kmp_str_buf_print(buffer,
"='", name);
3361 for (i = 0; i < nelem; i++) {
3362 switch (__kmp_nested_proc_bind.bind_types[i]) {
3363 case proc_bind_false:
3364 __kmp_str_buf_print(buffer,
"false");
3367 case proc_bind_true:
3368 __kmp_str_buf_print(buffer,
"true");
3371 case proc_bind_primary:
3372 __kmp_str_buf_print(buffer,
"primary");
3375 case proc_bind_close:
3376 __kmp_str_buf_print(buffer,
"close");
3379 case proc_bind_spread:
3380 __kmp_str_buf_print(buffer,
"spread");
3383 case proc_bind_intel:
3384 __kmp_str_buf_print(buffer,
"intel");
3387 case proc_bind_default:
3388 __kmp_str_buf_print(buffer,
"default");
3391 if (i < nelem - 1) {
3392 __kmp_str_buf_print(buffer,
",");
3395 __kmp_str_buf_print(buffer,
"'\n");
3399 static void __kmp_stg_parse_display_affinity(
char const *name,
3400 char const *value,
void *data) {
3401 __kmp_stg_parse_bool(name, value, &__kmp_display_affinity);
3403 static void __kmp_stg_print_display_affinity(kmp_str_buf_t *buffer,
3404 char const *name,
void *data) {
3405 __kmp_stg_print_bool(buffer, name, __kmp_display_affinity);
3407 static void __kmp_stg_parse_affinity_format(
char const *name,
char const *value,
3409 size_t length = KMP_STRLEN(value);
3410 __kmp_strncpy_truncate(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, value,
3413 static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer,
3414 char const *name,
void *data) {
3415 if (__kmp_env_format) {
3416 KMP_STR_BUF_PRINT_NAME_EX(name);
3418 __kmp_str_buf_print(buffer,
" %s='", name);
3420 __kmp_str_buf_print(buffer,
"%s'\n", __kmp_affinity_format);
3442 static void __kmp_stg_parse_allocator(
char const *name,
char const *value,
3444 const char *buf = value;
3445 const char *next, *scan, *start;
3447 omp_allocator_handle_t al;
3448 omp_memspace_handle_t ms = omp_default_mem_space;
3449 bool is_memspace =
false;
3450 int ntraits = 0, count = 0;
3454 const char *delim = strchr(buf,
':');
3455 const char *predef_mem_space = strstr(buf,
"mem_space");
3457 bool is_memalloc = (!predef_mem_space && !delim) ?
true :
false;
3462 for (scan = buf; *scan !=
'\0'; scan++) {
3467 omp_alloctrait_t *traits =
3468 (omp_alloctrait_t *)KMP_ALLOCA(ntraits *
sizeof(omp_alloctrait_t));
3471 #define IS_POWER_OF_TWO(n) (((n) & ((n)-1)) == 0)
3473 #define GET_NEXT(sentinel) \
3476 if (*next == sentinel) \
3482 #define SKIP_PAIR(key) \
3484 char const str_delimiter[] = {',', 0}; \
3485 char *value = __kmp_str_token(CCAST(char *, scan), str_delimiter, \
3486 CCAST(char **, &next)); \
3487 KMP_WARNING(StgInvalidValue, key, value); \
3495 char const str_delimiter[] = {'=', 0}; \
3496 key = __kmp_str_token(CCAST(char *, start), str_delimiter, \
3497 CCAST(char **, &next)); \
3502 while (*next !=
'\0') {
3504 __kmp_match_str(
"fb_data", scan, &next)) {
3508 if (__kmp_match_str(
"omp_high_bw_mem_alloc", scan, &next)) {
3511 if (__kmp_memkind_available) {
3512 __kmp_def_allocator = omp_high_bw_mem_alloc;
3515 KMP_WARNING(OmpNoAllocator,
"omp_high_bw_mem_alloc");
3518 traits[count].key = omp_atk_fb_data;
3519 traits[count].value = RCAST(omp_uintptr_t, omp_high_bw_mem_alloc);
3521 }
else if (__kmp_match_str(
"omp_large_cap_mem_alloc", scan, &next)) {
3524 if (__kmp_memkind_available) {
3525 __kmp_def_allocator = omp_large_cap_mem_alloc;
3528 KMP_WARNING(OmpNoAllocator,
"omp_large_cap_mem_alloc");
3531 traits[count].key = omp_atk_fb_data;
3532 traits[count].value = RCAST(omp_uintptr_t, omp_large_cap_mem_alloc);
3534 }
else if (__kmp_match_str(
"omp_default_mem_alloc", scan, &next)) {
3538 traits[count].key = omp_atk_fb_data;
3539 traits[count].value = RCAST(omp_uintptr_t, omp_default_mem_alloc);
3541 }
else if (__kmp_match_str(
"omp_const_mem_alloc", scan, &next)) {
3544 KMP_WARNING(OmpNoAllocator,
"omp_const_mem_alloc");
3546 traits[count].key = omp_atk_fb_data;
3547 traits[count].value = RCAST(omp_uintptr_t, omp_const_mem_alloc);
3549 }
else if (__kmp_match_str(
"omp_low_lat_mem_alloc", scan, &next)) {
3552 KMP_WARNING(OmpNoAllocator,
"omp_low_lat_mem_alloc");
3554 traits[count].key = omp_atk_fb_data;
3555 traits[count].value = RCAST(omp_uintptr_t, omp_low_lat_mem_alloc);
3557 }
else if (__kmp_match_str(
"omp_cgroup_mem_alloc", scan, &next)) {
3560 KMP_WARNING(OmpNoAllocator,
"omp_cgroup_mem_alloc");
3562 traits[count].key = omp_atk_fb_data;
3563 traits[count].value = RCAST(omp_uintptr_t, omp_cgroup_mem_alloc);
3565 }
else if (__kmp_match_str(
"omp_pteam_mem_alloc", scan, &next)) {
3568 KMP_WARNING(OmpNoAllocator,
"omp_pteam_mem_alloc");
3570 traits[count].key = omp_atk_fb_data;
3571 traits[count].value = RCAST(omp_uintptr_t, omp_pteam_mem_alloc);
3573 }
else if (__kmp_match_str(
"omp_thread_mem_alloc", scan, &next)) {
3576 KMP_WARNING(OmpNoAllocator,
"omp_thread_mem_alloc");
3578 traits[count].key = omp_atk_fb_data;
3579 traits[count].value = RCAST(omp_uintptr_t, omp_thread_mem_alloc);
3589 __kmp_def_allocator = omp_default_mem_alloc;
3590 if (next == buf || *next !=
'\0') {
3592 KMP_WARNING(StgInvalidValue, name, value);
3597 if (count == ntraits)
3603 if (__kmp_match_str(
"omp_default_mem_space", scan, &next)) {
3605 ms = omp_default_mem_space;
3606 }
else if (__kmp_match_str(
"omp_large_cap_mem_space", scan, &next)) {
3608 ms = omp_large_cap_mem_space;
3609 }
else if (__kmp_match_str(
"omp_const_mem_space", scan, &next)) {
3611 ms = omp_const_mem_space;
3612 }
else if (__kmp_match_str(
"omp_high_bw_mem_space", scan, &next)) {
3614 ms = omp_high_bw_mem_space;
3615 }
else if (__kmp_match_str(
"omp_low_lat_mem_space", scan, &next)) {
3617 ms = omp_low_lat_mem_space;
3619 __kmp_def_allocator = omp_default_mem_alloc;
3620 if (next == buf || *next !=
'\0') {
3622 KMP_WARNING(StgInvalidValue, name, value);
3631 if (__kmp_match_str(
"sync_hint", scan, &next)) {
3633 traits[count].key = omp_atk_sync_hint;
3634 if (__kmp_match_str(
"contended", scan, &next)) {
3635 traits[count].value = omp_atv_contended;
3636 }
else if (__kmp_match_str(
"uncontended", scan, &next)) {
3637 traits[count].value = omp_atv_uncontended;
3638 }
else if (__kmp_match_str(
"serialized", scan, &next)) {
3639 traits[count].value = omp_atv_serialized;
3640 }
else if (__kmp_match_str(
"private", scan, &next)) {
3641 traits[count].value = omp_atv_private;
3647 }
else if (__kmp_match_str(
"alignment", scan, &next)) {
3649 if (!isdigit(*next)) {
3655 int n = __kmp_str_to_int(scan,
',');
3656 if (n < 0 || !IS_POWER_OF_TWO(n)) {
3661 traits[count].key = omp_atk_alignment;
3662 traits[count].value = n;
3663 }
else if (__kmp_match_str(
"access", scan, &next)) {
3665 traits[count].key = omp_atk_access;
3666 if (__kmp_match_str(
"all", scan, &next)) {
3667 traits[count].value = omp_atv_all;
3668 }
else if (__kmp_match_str(
"cgroup", scan, &next)) {
3669 traits[count].value = omp_atv_cgroup;
3670 }
else if (__kmp_match_str(
"pteam", scan, &next)) {
3671 traits[count].value = omp_atv_pteam;
3672 }
else if (__kmp_match_str(
"thread", scan, &next)) {
3673 traits[count].value = omp_atv_thread;
3679 }
else if (__kmp_match_str(
"pool_size", scan, &next)) {
3681 if (!isdigit(*next)) {
3687 int n = __kmp_str_to_int(scan,
',');
3693 traits[count].key = omp_atk_pool_size;
3694 traits[count].value = n;
3695 }
else if (__kmp_match_str(
"fallback", scan, &next)) {
3697 traits[count].key = omp_atk_fallback;
3698 if (__kmp_match_str(
"default_mem_fb", scan, &next)) {
3699 traits[count].value = omp_atv_default_mem_fb;
3700 }
else if (__kmp_match_str(
"null_fb", scan, &next)) {
3701 traits[count].value = omp_atv_null_fb;
3702 }
else if (__kmp_match_str(
"abort_fb", scan, &next)) {
3703 traits[count].value = omp_atv_abort_fb;
3704 }
else if (__kmp_match_str(
"allocator_fb", scan, &next)) {
3705 traits[count].value = omp_atv_allocator_fb;
3711 }
else if (__kmp_match_str(
"pinned", scan, &next)) {
3713 traits[count].key = omp_atk_pinned;
3714 if (__kmp_str_match_true(next)) {
3715 traits[count].value = omp_atv_true;
3716 }
else if (__kmp_str_match_false(next)) {
3717 traits[count].value = omp_atv_false;
3723 }
else if (__kmp_match_str(
"partition", scan, &next)) {
3725 traits[count].key = omp_atk_partition;
3726 if (__kmp_match_str(
"environment", scan, &next)) {
3727 traits[count].value = omp_atv_environment;
3728 }
else if (__kmp_match_str(
"nearest", scan, &next)) {
3729 traits[count].value = omp_atv_nearest;
3730 }
else if (__kmp_match_str(
"blocked", scan, &next)) {
3731 traits[count].value = omp_atv_blocked;
3732 }
else if (__kmp_match_str(
"interleaved", scan, &next)) {
3733 traits[count].value = omp_atv_interleaved;
3746 if (count == ntraits)
3752 al = __kmpc_init_allocator(__kmp_get_gtid(), ms, ntraits, traits);
3753 __kmp_def_allocator = (al == omp_null_allocator) ? omp_default_mem_alloc : al;
3756 static void __kmp_stg_print_allocator(kmp_str_buf_t *buffer,
char const *name,
3758 if (__kmp_def_allocator == omp_default_mem_alloc) {
3759 __kmp_stg_print_str(buffer, name,
"omp_default_mem_alloc");
3760 }
else if (__kmp_def_allocator == omp_high_bw_mem_alloc) {
3761 __kmp_stg_print_str(buffer, name,
"omp_high_bw_mem_alloc");
3762 }
else if (__kmp_def_allocator == omp_large_cap_mem_alloc) {
3763 __kmp_stg_print_str(buffer, name,
"omp_large_cap_mem_alloc");
3764 }
else if (__kmp_def_allocator == omp_const_mem_alloc) {
3765 __kmp_stg_print_str(buffer, name,
"omp_const_mem_alloc");
3766 }
else if (__kmp_def_allocator == omp_low_lat_mem_alloc) {
3767 __kmp_stg_print_str(buffer, name,
"omp_low_lat_mem_alloc");
3768 }
else if (__kmp_def_allocator == omp_cgroup_mem_alloc) {
3769 __kmp_stg_print_str(buffer, name,
"omp_cgroup_mem_alloc");
3770 }
else if (__kmp_def_allocator == omp_pteam_mem_alloc) {
3771 __kmp_stg_print_str(buffer, name,
"omp_pteam_mem_alloc");
3772 }
else if (__kmp_def_allocator == omp_thread_mem_alloc) {
3773 __kmp_stg_print_str(buffer, name,
"omp_thread_mem_alloc");
3780 static void __kmp_stg_parse_omp_dynamic(
char const *name,
char const *value,
3782 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
3785 static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer,
char const *name,
3787 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
3790 static void __kmp_stg_parse_kmp_dynamic_mode(
char const *name,
3791 char const *value,
void *data) {
3792 if (TCR_4(__kmp_init_parallel)) {
3793 KMP_WARNING(EnvParallelWarn, name);
3794 __kmp_env_toPrint(name, 0);
3797 #ifdef USE_LOAD_BALANCE
3798 else if (__kmp_str_match(
"load balance", 2, value) ||
3799 __kmp_str_match(
"load_balance", 2, value) ||
3800 __kmp_str_match(
"load-balance", 2, value) ||
3801 __kmp_str_match(
"loadbalance", 2, value) ||
3802 __kmp_str_match(
"balance", 1, value)) {
3803 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3806 else if (__kmp_str_match(
"thread limit", 1, value) ||
3807 __kmp_str_match(
"thread_limit", 1, value) ||
3808 __kmp_str_match(
"thread-limit", 1, value) ||
3809 __kmp_str_match(
"threadlimit", 1, value) ||
3810 __kmp_str_match(
"limit", 2, value)) {
3811 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3812 }
else if (__kmp_str_match(
"random", 1, value)) {
3813 __kmp_global.g.g_dynamic_mode = dynamic_random;
3815 KMP_WARNING(StgInvalidValue, name, value);
3819 static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
3820 char const *name,
void *data) {
3822 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
3823 __kmp_str_buf_print(buffer,
" %s: %s \n", name, KMP_I18N_STR(NotDefined));
3825 #ifdef USE_LOAD_BALANCE
3826 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
3827 __kmp_stg_print_str(buffer, name,
"load balance");
3830 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
3831 __kmp_stg_print_str(buffer, name,
"thread limit");
3832 }
else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
3833 __kmp_stg_print_str(buffer, name,
"random");
3840 #ifdef USE_LOAD_BALANCE
3845 static void __kmp_stg_parse_ld_balance_interval(
char const *name,
3846 char const *value,
void *data) {
3847 double interval = __kmp_convert_to_double(value);
3848 if (interval >= 0) {
3849 __kmp_load_balance_interval = interval;
3851 KMP_WARNING(StgInvalidValue, name, value);
3855 static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
3856 char const *name,
void *data) {
3858 __kmp_str_buf_print(buffer,
" %s=%8.6f\n", name,
3859 __kmp_load_balance_interval);
3868 static void __kmp_stg_parse_init_at_fork(
char const *name,
char const *value,
3870 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
3871 if (__kmp_need_register_atfork) {
3872 __kmp_need_register_atfork_specified = TRUE;
3876 static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
3877 char const *name,
void *data) {
3878 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
3884 static void __kmp_stg_parse_schedule(
char const *name,
char const *value,
3887 if (value != NULL) {
3888 size_t length = KMP_STRLEN(value);
3889 if (length > INT_MAX) {
3890 KMP_WARNING(LongValue, name);
3892 const char *semicolon;
3893 if (value[length - 1] ==
'"' || value[length - 1] ==
'\'')
3894 KMP_WARNING(UnbalancedQuotes, name);
3898 semicolon = strchr(value,
';');
3899 if (*value && semicolon != value) {
3900 const char *comma = strchr(value,
',');
3907 if (!__kmp_strcasecmp_with_sentinel(
"static", value, sentinel)) {
3908 if (!__kmp_strcasecmp_with_sentinel(
"greedy", comma,
';')) {
3909 __kmp_static = kmp_sch_static_greedy;
3911 }
else if (!__kmp_strcasecmp_with_sentinel(
"balanced", comma,
3913 __kmp_static = kmp_sch_static_balanced;
3916 }
else if (!__kmp_strcasecmp_with_sentinel(
"guided", value,
3918 if (!__kmp_strcasecmp_with_sentinel(
"iterative", comma,
';')) {
3919 __kmp_guided = kmp_sch_guided_iterative_chunked;
3921 }
else if (!__kmp_strcasecmp_with_sentinel(
"analytical", comma,
3924 __kmp_guided = kmp_sch_guided_analytical_chunked;
3928 KMP_WARNING(InvalidClause, name, value);
3930 KMP_WARNING(EmptyClause, name);
3931 }
while ((value = semicolon ? semicolon + 1 : NULL));
3937 static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer,
char const *name,
3939 if (__kmp_env_format) {
3940 KMP_STR_BUF_PRINT_NAME_EX(name);
3942 __kmp_str_buf_print(buffer,
" %s='", name);
3944 if (__kmp_static == kmp_sch_static_greedy) {
3945 __kmp_str_buf_print(buffer,
"%s",
"static,greedy");
3946 }
else if (__kmp_static == kmp_sch_static_balanced) {
3947 __kmp_str_buf_print(buffer,
"%s",
"static,balanced");
3949 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
3950 __kmp_str_buf_print(buffer,
";%s'\n",
"guided,iterative");
3951 }
else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
3952 __kmp_str_buf_print(buffer,
";%s'\n",
"guided,analytical");
3959 static inline void __kmp_omp_schedule_restore() {
3960 #if KMP_USE_HIER_SCHED
3961 __kmp_hier_scheds.deallocate();
3971 static const char *__kmp_parse_single_omp_schedule(
const char *name,
3973 bool parse_hier =
false) {
3975 const char *ptr = value;
3982 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
3984 #if KMP_USE_HIER_SCHED
3985 kmp_hier_layer_e layer = kmp_hier_layer_e::LAYER_THREAD;
3987 if (*delim ==
',') {
3988 if (!__kmp_strcasecmp_with_sentinel(
"L1", ptr,
',')) {
3989 layer = kmp_hier_layer_e::LAYER_L1;
3990 }
else if (!__kmp_strcasecmp_with_sentinel(
"L2", ptr,
',')) {
3991 layer = kmp_hier_layer_e::LAYER_L2;
3992 }
else if (!__kmp_strcasecmp_with_sentinel(
"L3", ptr,
',')) {
3993 layer = kmp_hier_layer_e::LAYER_L3;
3994 }
else if (!__kmp_strcasecmp_with_sentinel(
"NUMA", ptr,
',')) {
3995 layer = kmp_hier_layer_e::LAYER_NUMA;
3998 if (layer != kmp_hier_layer_e::LAYER_THREAD && *delim !=
',') {
4000 KMP_WARNING(StgInvalidValue, name, value);
4001 __kmp_omp_schedule_restore();
4003 }
else if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4005 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4012 if (*delim ==
':') {
4013 if (!__kmp_strcasecmp_with_sentinel(
"monotonic", ptr, *delim)) {
4016 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4018 }
else if (!__kmp_strcasecmp_with_sentinel(
"nonmonotonic", ptr, *delim)) {
4021 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4023 }
else if (!parse_hier) {
4025 KMP_WARNING(StgInvalidValue, name, value);
4026 __kmp_omp_schedule_restore();
4031 if (!__kmp_strcasecmp_with_sentinel(
"dynamic", ptr, *delim))
4032 sched = kmp_sch_dynamic_chunked;
4033 else if (!__kmp_strcasecmp_with_sentinel(
"guided", ptr, *delim))
4036 else if (!__kmp_strcasecmp_with_sentinel(
"auto", ptr, *delim))
4038 else if (!__kmp_strcasecmp_with_sentinel(
"trapezoidal", ptr, *delim))
4039 sched = kmp_sch_trapezoidal;
4040 else if (!__kmp_strcasecmp_with_sentinel(
"static", ptr, *delim))
4042 #if KMP_STATIC_STEAL_ENABLED
4043 else if (!__kmp_strcasecmp_with_sentinel(
"static_steal", ptr, *delim)) {
4045 sched = kmp_sch_dynamic_chunked;
4051 KMP_WARNING(StgInvalidValue, name, value);
4052 __kmp_omp_schedule_restore();
4057 if (*delim ==
',') {
4060 if (!isdigit(*ptr)) {
4062 KMP_WARNING(StgInvalidValue, name, value);
4063 __kmp_omp_schedule_restore();
4069 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, delim),
4073 sched = kmp_sch_static_chunked;
4074 chunk = __kmp_str_to_int(delim + 1, *ptr);
4076 chunk = KMP_DEFAULT_CHUNK;
4077 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, delim),
4079 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
4088 }
else if (chunk > KMP_MAX_CHUNK) {
4089 chunk = KMP_MAX_CHUNK;
4090 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, delim),
4092 KMP_INFORM(Using_int_Value, name, chunk);
4099 SCHEDULE_SET_MODIFIERS(sched, sched_modifier);
4101 #if KMP_USE_HIER_SCHED
4102 if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4103 __kmp_hier_scheds.append(sched, chunk, layer);
4107 __kmp_chunk = chunk;
4108 __kmp_sched = sched;
4113 static void __kmp_stg_parse_omp_schedule(
char const *name,
char const *value,
4116 const char *ptr = value;
4119 length = KMP_STRLEN(value);
4121 if (value[length - 1] ==
'"' || value[length - 1] ==
'\'')
4122 KMP_WARNING(UnbalancedQuotes, name);
4124 #if KMP_USE_HIER_SCHED
4125 if (!__kmp_strcasecmp_with_sentinel(
"EXPERIMENTAL", ptr,
' ')) {
4128 while ((ptr = __kmp_parse_single_omp_schedule(name, ptr,
true))) {
4129 while (*ptr ==
' ' || *ptr ==
'\t' || *ptr ==
':')
4136 __kmp_parse_single_omp_schedule(name, ptr);
4138 KMP_WARNING(EmptyString, name);
4140 #if KMP_USE_HIER_SCHED
4141 __kmp_hier_scheds.sort();
4143 K_DIAG(1, (
"__kmp_static == %d\n", __kmp_static))
4144 K_DIAG(1, (
"__kmp_guided == %d\n", __kmp_guided))
4145 K_DIAG(1, (
"__kmp_sched == %d\n", __kmp_sched))
4146 K_DIAG(1, (
"__kmp_chunk == %d\n", __kmp_chunk))
4149 static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
4150 char const *name,
void *data) {
4151 if (__kmp_env_format) {
4152 KMP_STR_BUF_PRINT_NAME_EX(name);
4154 __kmp_str_buf_print(buffer,
" %s='", name);
4156 enum sched_type sched = SCHEDULE_WITHOUT_MODIFIERS(__kmp_sched);
4157 if (SCHEDULE_HAS_MONOTONIC(__kmp_sched)) {
4158 __kmp_str_buf_print(buffer,
"monotonic:");
4159 }
else if (SCHEDULE_HAS_NONMONOTONIC(__kmp_sched)) {
4160 __kmp_str_buf_print(buffer,
"nonmonotonic:");
4164 case kmp_sch_dynamic_chunked:
4165 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"dynamic", __kmp_chunk);
4167 case kmp_sch_guided_iterative_chunked:
4168 case kmp_sch_guided_analytical_chunked:
4169 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"guided", __kmp_chunk);
4171 case kmp_sch_trapezoidal:
4172 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"trapezoidal", __kmp_chunk);
4175 case kmp_sch_static_chunked:
4176 case kmp_sch_static_balanced:
4177 case kmp_sch_static_greedy:
4178 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"static", __kmp_chunk);
4180 case kmp_sch_static_steal:
4181 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"static_steal", __kmp_chunk);
4184 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"auto", __kmp_chunk);
4189 case kmp_sch_dynamic_chunked:
4190 __kmp_str_buf_print(buffer,
"%s'\n",
"dynamic");
4192 case kmp_sch_guided_iterative_chunked:
4193 case kmp_sch_guided_analytical_chunked:
4194 __kmp_str_buf_print(buffer,
"%s'\n",
"guided");
4196 case kmp_sch_trapezoidal:
4197 __kmp_str_buf_print(buffer,
"%s'\n",
"trapezoidal");
4200 case kmp_sch_static_chunked:
4201 case kmp_sch_static_balanced:
4202 case kmp_sch_static_greedy:
4203 __kmp_str_buf_print(buffer,
"%s'\n",
"static");
4205 case kmp_sch_static_steal:
4206 __kmp_str_buf_print(buffer,
"%s'\n",
"static_steal");
4209 __kmp_str_buf_print(buffer,
"%s'\n",
"auto");
4215 #if KMP_USE_HIER_SCHED
4218 static void __kmp_stg_parse_kmp_hand_thread(
char const *name,
char const *value,
4220 __kmp_stg_parse_bool(name, value, &(__kmp_dispatch_hand_threading));
4223 static void __kmp_stg_print_kmp_hand_thread(kmp_str_buf_t *buffer,
4224 char const *name,
void *data) {
4225 __kmp_stg_print_bool(buffer, name, __kmp_dispatch_hand_threading);
4231 static void __kmp_stg_parse_kmp_force_monotonic(
char const *name,
4232 char const *value,
void *data) {
4233 __kmp_stg_parse_bool(name, value, &(__kmp_force_monotonic));
4236 static void __kmp_stg_print_kmp_force_monotonic(kmp_str_buf_t *buffer,
4237 char const *name,
void *data) {
4238 __kmp_stg_print_bool(buffer, name, __kmp_force_monotonic);
4244 static void __kmp_stg_parse_atomic_mode(
char const *name,
char const *value,
4250 #ifdef KMP_GOMP_COMPAT
4253 __kmp_stg_parse_int(name, value, 0, max, &mode);
4258 __kmp_atomic_mode = mode;
4262 static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer,
char const *name,
4264 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
4270 static void __kmp_stg_parse_consistency_check(
char const *name,
4271 char const *value,
void *data) {
4272 if (!__kmp_strcasecmp_with_sentinel(
"all", value, 0)) {
4278 __kmp_env_consistency_check = TRUE;
4279 }
else if (!__kmp_strcasecmp_with_sentinel(
"none", value, 0)) {
4280 __kmp_env_consistency_check = FALSE;
4282 KMP_WARNING(StgInvalidValue, name, value);
4286 static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
4287 char const *name,
void *data) {
4289 const char *value = NULL;
4291 if (__kmp_env_consistency_check) {
4297 if (value != NULL) {
4298 __kmp_stg_print_str(buffer, name, value);
4309 static void __kmp_stg_parse_itt_prepare_delay(
char const *name,
4310 char const *value,
void *data) {
4314 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
4315 __kmp_itt_prepare_delay = delay;
4318 static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
4319 char const *name,
void *data) {
4320 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
4330 static void __kmp_stg_parse_malloc_pool_incr(
char const *name,
4331 char const *value,
void *data) {
4332 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
4333 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
4337 static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
4338 char const *name,
void *data) {
4339 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
4348 static void __kmp_stg_parse_par_range_env(
char const *name,
char const *value,
4350 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
4351 __kmp_par_range_routine, __kmp_par_range_filename,
4352 &__kmp_par_range_lb, &__kmp_par_range_ub);
4355 static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
4356 char const *name,
void *data) {
4357 if (__kmp_par_range != 0) {
4358 __kmp_stg_print_str(buffer, name, par_range_to_print);
4367 static void __kmp_stg_parse_gtid_mode(
char const *name,
char const *value,
4377 #ifdef KMP_TDATA_GTID
4380 __kmp_stg_parse_int(name, value, 0, max, &mode);
4384 __kmp_adjust_gtid_mode = TRUE;
4386 __kmp_gtid_mode = mode;
4387 __kmp_adjust_gtid_mode = FALSE;
4391 static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer,
char const *name,
4393 if (__kmp_adjust_gtid_mode) {
4394 __kmp_stg_print_int(buffer, name, 0);
4396 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
4403 static void __kmp_stg_parse_lock_block(
char const *name,
char const *value,
4405 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
4408 static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer,
char const *name,
4410 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
4416 #if KMP_USE_DYNAMIC_LOCK
4417 #define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
4419 #define KMP_STORE_LOCK_SEQ(a)
4422 static void __kmp_stg_parse_lock_kind(
char const *name,
char const *value,
4424 if (__kmp_init_user_locks) {
4425 KMP_WARNING(EnvLockWarn, name);
4429 if (__kmp_str_match(
"tas", 2, value) ||
4430 __kmp_str_match(
"test and set", 2, value) ||
4431 __kmp_str_match(
"test_and_set", 2, value) ||
4432 __kmp_str_match(
"test-and-set", 2, value) ||
4433 __kmp_str_match(
"test andset", 2, value) ||
4434 __kmp_str_match(
"test_andset", 2, value) ||
4435 __kmp_str_match(
"test-andset", 2, value) ||
4436 __kmp_str_match(
"testand set", 2, value) ||
4437 __kmp_str_match(
"testand_set", 2, value) ||
4438 __kmp_str_match(
"testand-set", 2, value) ||
4439 __kmp_str_match(
"testandset", 2, value)) {
4440 __kmp_user_lock_kind = lk_tas;
4441 KMP_STORE_LOCK_SEQ(tas);
4444 else if (__kmp_str_match(
"futex", 1, value)) {
4445 if (__kmp_futex_determine_capable()) {
4446 __kmp_user_lock_kind = lk_futex;
4447 KMP_STORE_LOCK_SEQ(futex);
4449 KMP_WARNING(FutexNotSupported, name, value);
4453 else if (__kmp_str_match(
"ticket", 2, value)) {
4454 __kmp_user_lock_kind = lk_ticket;
4455 KMP_STORE_LOCK_SEQ(ticket);
4456 }
else if (__kmp_str_match(
"queuing", 1, value) ||
4457 __kmp_str_match(
"queue", 1, value)) {
4458 __kmp_user_lock_kind = lk_queuing;
4459 KMP_STORE_LOCK_SEQ(queuing);
4460 }
else if (__kmp_str_match(
"drdpa ticket", 1, value) ||
4461 __kmp_str_match(
"drdpa_ticket", 1, value) ||
4462 __kmp_str_match(
"drdpa-ticket", 1, value) ||
4463 __kmp_str_match(
"drdpaticket", 1, value) ||
4464 __kmp_str_match(
"drdpa", 1, value)) {
4465 __kmp_user_lock_kind = lk_drdpa;
4466 KMP_STORE_LOCK_SEQ(drdpa);
4468 #if KMP_USE_ADAPTIVE_LOCKS
4469 else if (__kmp_str_match(
"adaptive", 1, value)) {
4470 if (__kmp_cpuinfo.rtm) {
4471 __kmp_user_lock_kind = lk_adaptive;
4472 KMP_STORE_LOCK_SEQ(adaptive);
4474 KMP_WARNING(AdaptiveNotSupported, name, value);
4475 __kmp_user_lock_kind = lk_queuing;
4476 KMP_STORE_LOCK_SEQ(queuing);
4480 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4481 else if (__kmp_str_match(
"rtm_queuing", 1, value)) {
4482 if (__kmp_cpuinfo.rtm) {
4483 __kmp_user_lock_kind = lk_rtm_queuing;
4484 KMP_STORE_LOCK_SEQ(rtm_queuing);
4486 KMP_WARNING(AdaptiveNotSupported, name, value);
4487 __kmp_user_lock_kind = lk_queuing;
4488 KMP_STORE_LOCK_SEQ(queuing);
4490 }
else if (__kmp_str_match(
"rtm_spin", 1, value)) {
4491 if (__kmp_cpuinfo.rtm) {
4492 __kmp_user_lock_kind = lk_rtm_spin;
4493 KMP_STORE_LOCK_SEQ(rtm_spin);
4495 KMP_WARNING(AdaptiveNotSupported, name, value);
4496 __kmp_user_lock_kind = lk_tas;
4497 KMP_STORE_LOCK_SEQ(queuing);
4499 }
else if (__kmp_str_match(
"hle", 1, value)) {
4500 __kmp_user_lock_kind = lk_hle;
4501 KMP_STORE_LOCK_SEQ(hle);
4505 KMP_WARNING(StgInvalidValue, name, value);
4509 static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer,
char const *name,
4511 const char *value = NULL;
4513 switch (__kmp_user_lock_kind) {
4528 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4529 case lk_rtm_queuing:
4530 value =
"rtm_queuing";
4553 #if KMP_USE_ADAPTIVE_LOCKS
4560 if (value != NULL) {
4561 __kmp_stg_print_str(buffer, name, value);
4570 static void __kmp_stg_parse_spin_backoff_params(
const char *name,
4571 const char *value,
void *data) {
4572 const char *next = value;
4575 int prev_comma = FALSE;
4578 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
4579 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
4583 for (i = 0; i < 3; i++) {
4586 if (*next ==
'\0') {
4591 if (((*next < '0' || *next >
'9') && *next !=
',') || total > 2) {
4592 KMP_WARNING(EnvSyntaxError, name, value);
4598 if (total == 0 || prev_comma) {
4606 if (*next >=
'0' && *next <=
'9') {
4608 const char *buf = next;
4609 char const *msg = NULL;
4614 const char *tmp = next;
4616 if ((*next ==
' ' || *next ==
'\t') && (*tmp >=
'0' && *tmp <=
'9')) {
4617 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4621 num = __kmp_str_to_int(buf, *next);
4623 msg = KMP_I18N_STR(ValueTooSmall);
4625 }
else if (num > KMP_INT_MAX) {
4626 msg = KMP_I18N_STR(ValueTooLarge);
4631 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4632 KMP_INFORM(Using_int_Value, name, num);
4636 }
else if (total == 2) {
4641 KMP_DEBUG_ASSERT(total > 0);
4643 KMP_WARNING(EnvSyntaxError, name, value);
4646 __kmp_spin_backoff_params.max_backoff = max_backoff;
4647 __kmp_spin_backoff_params.min_tick = min_tick;
4650 static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
4651 char const *name,
void *data) {
4652 if (__kmp_env_format) {
4653 KMP_STR_BUF_PRINT_NAME_EX(name);
4655 __kmp_str_buf_print(buffer,
" %s='", name);
4657 __kmp_str_buf_print(buffer,
"%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
4658 __kmp_spin_backoff_params.min_tick);
4661 #if KMP_USE_ADAPTIVE_LOCKS
4668 static void __kmp_stg_parse_adaptive_lock_props(
const char *name,
4669 const char *value,
void *data) {
4670 int max_retries = 0;
4671 int max_badness = 0;
4673 const char *next = value;
4676 int prev_comma = FALSE;
4682 for (i = 0; i < 3; i++) {
4685 if (*next ==
'\0') {
4690 if (((*next < '0' || *next >
'9') && *next !=
',') || total > 2) {
4691 KMP_WARNING(EnvSyntaxError, name, value);
4697 if (total == 0 || prev_comma) {
4705 if (*next >=
'0' && *next <=
'9') {
4707 const char *buf = next;
4708 char const *msg = NULL;
4713 const char *tmp = next;
4715 if ((*next ==
' ' || *next ==
'\t') && (*tmp >=
'0' && *tmp <=
'9')) {
4716 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4720 num = __kmp_str_to_int(buf, *next);
4722 msg = KMP_I18N_STR(ValueTooSmall);
4724 }
else if (num > KMP_INT_MAX) {
4725 msg = KMP_I18N_STR(ValueTooLarge);
4730 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4731 KMP_INFORM(Using_int_Value, name, num);
4735 }
else if (total == 2) {
4740 KMP_DEBUG_ASSERT(total > 0);
4742 KMP_WARNING(EnvSyntaxError, name, value);
4745 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4746 __kmp_adaptive_backoff_params.max_badness = max_badness;
4749 static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4750 char const *name,
void *data) {
4751 if (__kmp_env_format) {
4752 KMP_STR_BUF_PRINT_NAME_EX(name);
4754 __kmp_str_buf_print(buffer,
" %s='", name);
4756 __kmp_str_buf_print(buffer,
"%d,%d'\n",
4757 __kmp_adaptive_backoff_params.max_soft_retries,
4758 __kmp_adaptive_backoff_params.max_badness);
4761 #if KMP_DEBUG_ADAPTIVE_LOCKS
4763 static void __kmp_stg_parse_speculative_statsfile(
char const *name,
4766 __kmp_stg_parse_file(name, value,
"",
4767 CCAST(
char **, &__kmp_speculative_statsfile));
4770 static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
4773 if (__kmp_str_match(
"-", 0, __kmp_speculative_statsfile)) {
4774 __kmp_stg_print_str(buffer, name,
"stdout");
4776 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
4792 static kmp_hw_t __kmp_hw_subset_break_tie(
const kmp_hw_t *possible,
4793 size_t num_possible) {
4794 for (
size_t i = 0; i < num_possible; ++i) {
4795 if (possible[i] == KMP_HW_THREAD)
4796 return KMP_HW_THREAD;
4797 else if (possible[i] == KMP_HW_CORE)
4799 else if (possible[i] == KMP_HW_SOCKET)
4800 return KMP_HW_SOCKET;
4802 return KMP_HW_UNKNOWN;
4809 static kmp_hw_t __kmp_stg_parse_hw_subset_name(
char const *token) {
4810 size_t index, num_possible, token_length;
4811 kmp_hw_t possible[KMP_HW_LAST];
4817 while (isalnum(*end) || *end ==
'_') {
4824 KMP_FOREACH_HW_TYPE(type) { possible[num_possible++] = type; }
4831 while (num_possible > 1 && index < token_length) {
4832 size_t n = num_possible;
4833 char token_char = (char)toupper(token[index]);
4834 for (
size_t i = 0; i < n; ++i) {
4836 kmp_hw_t type = possible[i];
4837 s = __kmp_hw_get_keyword(type,
false);
4838 if (index < KMP_STRLEN(s)) {
4839 char c = (char)toupper(s[index]);
4841 if (c != token_char) {
4842 possible[i] = KMP_HW_UNKNOWN;
4849 for (
size_t i = 0; i < n; ++i) {
4850 if (possible[i] != KMP_HW_UNKNOWN) {
4851 kmp_hw_t temp = possible[i];
4852 possible[i] = possible[start];
4853 possible[start] = temp;
4857 KMP_ASSERT(start == num_possible);
4863 if (num_possible > 1)
4864 return __kmp_hw_subset_break_tie(possible, num_possible);
4865 if (num_possible == 1)
4867 return KMP_HW_UNKNOWN;
4872 #define MAX_T_LEVEL KMP_HW_LAST
4873 #define MAX_STR_LEN 512
4874 static void __kmp_stg_parse_hw_subset(
char const *name,
char const *value,
4878 kmp_setting_t **rivals = (kmp_setting_t **)data;
4879 if (strcmp(name,
"KMP_PLACE_THREADS") == 0) {
4880 KMP_INFORM(EnvVarDeprecated, name,
"KMP_HW_SUBSET");
4882 if (__kmp_stg_check_rivals(name, value, rivals)) {
4886 char *components[MAX_T_LEVEL];
4887 char const *digits =
"0123456789";
4888 char input[MAX_STR_LEN];
4889 size_t len = 0, mlen = MAX_STR_LEN;
4891 bool absolute =
false;
4893 char *pos = CCAST(
char *, value);
4894 while (*pos && mlen) {
4896 if (len == 0 && *pos ==
':') {
4899 input[len] = (char)(toupper(*pos));
4900 if (input[len] ==
'X')
4902 if (input[len] ==
'O' && strchr(digits, *(pos + 1)))
4910 if (len == 0 || mlen == 0) {
4916 components[level++] = pos;
4917 while ((pos = strchr(pos,
','))) {
4918 if (level >= MAX_T_LEVEL)
4921 components[level++] = ++pos;
4924 __kmp_hw_subset = kmp_hw_subset_t::allocate();
4926 __kmp_hw_subset->set_absolute();
4929 for (
int i = 0; i < level; ++i) {
4931 int num = atoi(components[i]);
4935 if ((pos = strchr(components[i],
'@'))) {
4936 offset = atoi(pos + 1);
4939 pos = components[i] + strspn(components[i], digits);
4940 if (pos == components[i]) {
4944 kmp_hw_t type = __kmp_stg_parse_hw_subset_name(pos);
4945 if (type == KMP_HW_UNKNOWN) {
4948 if (__kmp_hw_subset->specified(type)) {
4951 __kmp_hw_subset->push_back(num, type, offset);
4955 KMP_WARNING(AffHWSubsetInvalid, name, value);
4956 if (__kmp_hw_subset) {
4957 kmp_hw_subset_t::deallocate(__kmp_hw_subset);
4958 __kmp_hw_subset =
nullptr;
4963 static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer,
char const *name,
4967 if (!__kmp_hw_subset)
4969 __kmp_str_buf_init(&buf);
4970 if (__kmp_env_format)
4971 KMP_STR_BUF_PRINT_NAME_EX(name);
4973 __kmp_str_buf_print(buffer,
" %s='", name);
4975 depth = __kmp_hw_subset->get_depth();
4976 for (
int i = 0; i < depth; ++i) {
4977 const auto &item = __kmp_hw_subset->at(i);
4978 __kmp_str_buf_print(&buf,
"%s%d%s", (i > 0 ?
"," :
""), item.num,
4979 __kmp_hw_get_keyword(item.type));
4981 __kmp_str_buf_print(&buf,
"@%d", item.offset);
4983 __kmp_str_buf_print(buffer,
"%s'\n", buf.str);
4984 __kmp_str_buf_free(&buf);
4991 static void __kmp_stg_parse_forkjoin_frames(
char const *name,
char const *value,
4993 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
4996 static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
4997 char const *name,
void *data) {
4998 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
5004 static void __kmp_stg_parse_forkjoin_frames_mode(
char const *name,
5007 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
5010 static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
5011 char const *name,
void *data) {
5012 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
5019 static void __kmp_stg_parse_task_throttling(
char const *name,
char const *value,
5021 __kmp_stg_parse_bool(name, value, &__kmp_enable_task_throttling);
5024 static void __kmp_stg_print_task_throttling(kmp_str_buf_t *buffer,
5025 char const *name,
void *data) {
5026 __kmp_stg_print_bool(buffer, name, __kmp_enable_task_throttling);
5029 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5033 static void __kmp_stg_parse_user_level_mwait(
char const *name,
5034 char const *value,
void *data) {
5035 __kmp_stg_parse_bool(name, value, &__kmp_user_level_mwait);
5038 static void __kmp_stg_print_user_level_mwait(kmp_str_buf_t *buffer,
5039 char const *name,
void *data) {
5040 __kmp_stg_print_bool(buffer, name, __kmp_user_level_mwait);
5046 static void __kmp_stg_parse_mwait_hints(
char const *name,
char const *value,
5048 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_mwait_hints);
5051 static void __kmp_stg_print_mwait_hints(kmp_str_buf_t *buffer,
char const *name,
5053 __kmp_stg_print_int(buffer, name, __kmp_mwait_hints);
5061 static void __kmp_stg_parse_omp_display_env(
char const *name,
char const *value,
5063 if (__kmp_str_match(
"VERBOSE", 1, value)) {
5064 __kmp_display_env_verbose = TRUE;
5066 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
5070 static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
5071 char const *name,
void *data) {
5072 if (__kmp_display_env_verbose) {
5073 __kmp_stg_print_str(buffer, name,
"VERBOSE");
5075 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
5079 static void __kmp_stg_parse_omp_cancellation(
char const *name,
5080 char const *value,
void *data) {
5081 if (TCR_4(__kmp_init_parallel)) {
5082 KMP_WARNING(EnvParallelWarn, name);
5085 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
5088 static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
5089 char const *name,
void *data) {
5090 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
5096 static void __kmp_stg_parse_omp_tool(
char const *name,
char const *value,
5098 __kmp_stg_parse_bool(name, value, &__kmp_tool);
5101 static void __kmp_stg_print_omp_tool(kmp_str_buf_t *buffer,
char const *name,
5103 if (__kmp_env_format) {
5104 KMP_STR_BUF_PRINT_BOOL_EX(name, __kmp_tool,
"enabled",
"disabled");
5106 __kmp_str_buf_print(buffer,
" %s=%s\n", name,
5107 __kmp_tool ?
"enabled" :
"disabled");
5111 char *__kmp_tool_libraries = NULL;
5113 static void __kmp_stg_parse_omp_tool_libraries(
char const *name,
5114 char const *value,
void *data) {
5115 __kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
5118 static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer,
5119 char const *name,
void *data) {
5120 if (__kmp_tool_libraries)
5121 __kmp_stg_print_str(buffer, name, __kmp_tool_libraries);
5123 if (__kmp_env_format) {
5124 KMP_STR_BUF_PRINT_NAME;
5126 __kmp_str_buf_print(buffer,
" %s", name);
5128 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
5132 char *__kmp_tool_verbose_init = NULL;
5134 static void __kmp_stg_parse_omp_tool_verbose_init(
char const *name,
5137 __kmp_stg_parse_str(name, value, &__kmp_tool_verbose_init);
5140 static void __kmp_stg_print_omp_tool_verbose_init(kmp_str_buf_t *buffer,
5143 if (__kmp_tool_verbose_init)
5144 __kmp_stg_print_str(buffer, name, __kmp_tool_verbose_init);
5146 if (__kmp_env_format) {
5147 KMP_STR_BUF_PRINT_NAME;
5149 __kmp_str_buf_print(buffer,
" %s", name);
5151 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
5159 static kmp_setting_t __kmp_stg_table[] = {
5161 {
"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
5162 {
"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
5164 {
"KMP_USE_YIELD", __kmp_stg_parse_use_yield, __kmp_stg_print_use_yield,
5166 {
"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
5167 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
5168 {
"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
5170 {
"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
5171 __kmp_stg_print_device_thread_limit, NULL, 0, 0},
5173 {
"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
5174 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
5176 {
"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
5178 {
"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
5179 __kmp_stg_print_stackoffset, NULL, 0, 0},
5180 {
"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5182 {
"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
5184 {
"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
5186 {
"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
5189 {
"KMP_NESTING_MODE", __kmp_stg_parse_nesting_mode,
5190 __kmp_stg_print_nesting_mode, NULL, 0, 0},
5191 {
"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
5192 {
"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
5193 __kmp_stg_print_num_threads, NULL, 0, 0},
5194 {
"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5197 {
"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
5199 {
"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
5200 __kmp_stg_print_task_stealing, NULL, 0, 0},
5201 {
"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
5202 __kmp_stg_print_max_active_levels, NULL, 0, 0},
5203 {
"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
5204 __kmp_stg_print_default_device, NULL, 0, 0},
5205 {
"OMP_TARGET_OFFLOAD", __kmp_stg_parse_target_offload,
5206 __kmp_stg_print_target_offload, NULL, 0, 0},
5207 {
"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
5208 __kmp_stg_print_max_task_priority, NULL, 0, 0},
5209 {
"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
5210 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
5211 {
"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
5212 __kmp_stg_print_thread_limit, NULL, 0, 0},
5213 {
"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
5214 __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
5215 {
"OMP_NUM_TEAMS", __kmp_stg_parse_nteams, __kmp_stg_print_nteams, NULL, 0,
5217 {
"OMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_th_limit,
5218 __kmp_stg_print_teams_th_limit, NULL, 0, 0},
5219 {
"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
5220 __kmp_stg_print_wait_policy, NULL, 0, 0},
5221 {
"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
5222 __kmp_stg_print_disp_buffers, NULL, 0, 0},
5223 #if KMP_NESTED_HOT_TEAMS
5224 {
"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
5225 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
5226 {
"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
5227 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
5230 #if KMP_HANDLE_SIGNALS
5231 {
"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
5232 __kmp_stg_print_handle_signals, NULL, 0, 0},
5235 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
5236 {
"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
5237 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
5240 #ifdef KMP_GOMP_COMPAT
5241 {
"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
5245 {
"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
5247 {
"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
5249 {
"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
5251 {
"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
5253 {
"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
5255 {
"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
5257 {
"KMP_DEBUG", __kmp_stg_parse_debug, NULL, NULL, 0, 0},
5258 {
"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
5260 {
"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
5261 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
5262 {
"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
5263 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
5264 {
"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
5265 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
5266 {
"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
5268 {
"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
5269 __kmp_stg_print_par_range_env, NULL, 0, 0},
5272 {
"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
5273 __kmp_stg_print_align_alloc, NULL, 0, 0},
5275 {
"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5276 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5277 {
"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5278 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5279 {
"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5280 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5281 {
"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5282 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5283 #if KMP_FAST_REDUCTION_BARRIER
5284 {
"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5285 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5286 {
"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5287 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5290 {
"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
5291 __kmp_stg_print_abort_delay, NULL, 0, 0},
5292 {
"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
5293 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
5294 {
"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
5295 __kmp_stg_print_force_reduction, NULL, 0, 0},
5296 {
"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
5297 __kmp_stg_print_force_reduction, NULL, 0, 0},
5298 {
"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
5299 __kmp_stg_print_storage_map, NULL, 0, 0},
5300 {
"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
5301 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
5302 {
"KMP_FOREIGN_THREADS_THREADPRIVATE",
5303 __kmp_stg_parse_foreign_threads_threadprivate,
5304 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
5306 #if KMP_AFFINITY_SUPPORTED
5307 {
"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
5309 #ifdef KMP_GOMP_COMPAT
5310 {
"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
5313 {
"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5315 {
"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
5316 {
"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
5317 __kmp_stg_print_topology_method, NULL, 0, 0},
5323 {
"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5327 {
"OMP_DISPLAY_AFFINITY", __kmp_stg_parse_display_affinity,
5328 __kmp_stg_print_display_affinity, NULL, 0, 0},
5329 {
"OMP_AFFINITY_FORMAT", __kmp_stg_parse_affinity_format,
5330 __kmp_stg_print_affinity_format, NULL, 0, 0},
5331 {
"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
5332 __kmp_stg_print_init_at_fork, NULL, 0, 0},
5333 {
"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
5335 {
"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
5337 #if KMP_USE_HIER_SCHED
5338 {
"KMP_DISP_HAND_THREAD", __kmp_stg_parse_kmp_hand_thread,
5339 __kmp_stg_print_kmp_hand_thread, NULL, 0, 0},
5341 {
"KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE",
5342 __kmp_stg_parse_kmp_force_monotonic, __kmp_stg_print_kmp_force_monotonic,
5344 {
"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
5345 __kmp_stg_print_atomic_mode, NULL, 0, 0},
5346 {
"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
5347 __kmp_stg_print_consistency_check, NULL, 0, 0},
5349 #if USE_ITT_BUILD && USE_ITT_NOTIFY
5350 {
"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
5351 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
5353 {
"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
5354 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
5355 {
"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
5357 {
"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
5359 {
"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
5360 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
5362 #ifdef USE_LOAD_BALANCE
5363 {
"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
5364 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
5367 {
"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
5368 __kmp_stg_print_lock_block, NULL, 0, 0},
5369 {
"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
5371 {
"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
5372 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
5373 #if KMP_USE_ADAPTIVE_LOCKS
5374 {
"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
5375 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
5376 #if KMP_DEBUG_ADAPTIVE_LOCKS
5377 {
"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
5378 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
5381 {
"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5383 {
"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5386 {
"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
5387 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
5388 {
"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
5389 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
5391 {
"KMP_ENABLE_TASK_THROTTLING", __kmp_stg_parse_task_throttling,
5392 __kmp_stg_print_task_throttling, NULL, 0, 0},
5394 {
"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
5395 __kmp_stg_print_omp_display_env, NULL, 0, 0},
5396 {
"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
5397 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
5398 {
"OMP_ALLOCATOR", __kmp_stg_parse_allocator, __kmp_stg_print_allocator,
5400 {
"LIBOMP_USE_HIDDEN_HELPER_TASK", __kmp_stg_parse_use_hidden_helper,
5401 __kmp_stg_print_use_hidden_helper, NULL, 0, 0},
5402 {
"LIBOMP_NUM_HIDDEN_HELPER_THREADS",
5403 __kmp_stg_parse_num_hidden_helper_threads,
5404 __kmp_stg_print_num_hidden_helper_threads, NULL, 0, 0},
5407 {
"OMP_TOOL", __kmp_stg_parse_omp_tool, __kmp_stg_print_omp_tool, NULL, 0,
5409 {
"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries,
5410 __kmp_stg_print_omp_tool_libraries, NULL, 0, 0},
5411 {
"OMP_TOOL_VERBOSE_INIT", __kmp_stg_parse_omp_tool_verbose_init,
5412 __kmp_stg_print_omp_tool_verbose_init, NULL, 0, 0},
5415 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5416 {
"KMP_USER_LEVEL_MWAIT", __kmp_stg_parse_user_level_mwait,
5417 __kmp_stg_print_user_level_mwait, NULL, 0, 0},
5418 {
"KMP_MWAIT_HINTS", __kmp_stg_parse_mwait_hints,
5419 __kmp_stg_print_mwait_hints, NULL, 0, 0},
5421 {
"", NULL, NULL, NULL, 0, 0}};
5423 static int const __kmp_stg_count =
5424 sizeof(__kmp_stg_table) /
sizeof(kmp_setting_t);
5426 static inline kmp_setting_t *__kmp_stg_find(
char const *name) {
5430 for (i = 0; i < __kmp_stg_count; ++i) {
5431 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
5432 return &__kmp_stg_table[i];
5440 static int __kmp_stg_cmp(
void const *_a,
void const *_b) {
5441 const kmp_setting_t *a = RCAST(
const kmp_setting_t *, _a);
5442 const kmp_setting_t *b = RCAST(
const kmp_setting_t *, _b);
5446 if (strcmp(a->name,
"KMP_AFFINITY") == 0) {
5447 if (strcmp(b->name,
"KMP_AFFINITY") == 0) {
5451 }
else if (strcmp(b->name,
"KMP_AFFINITY") == 0) {
5454 return strcmp(a->name, b->name);
5457 static void __kmp_stg_init(
void) {
5459 static int initialized = 0;
5464 qsort(__kmp_stg_table, __kmp_stg_count - 1,
sizeof(kmp_setting_t),
5468 kmp_setting_t *kmp_stacksize =
5469 __kmp_stg_find(
"KMP_STACKSIZE");
5470 #ifdef KMP_GOMP_COMPAT
5471 kmp_setting_t *gomp_stacksize =
5472 __kmp_stg_find(
"GOMP_STACKSIZE");
5474 kmp_setting_t *omp_stacksize =
5475 __kmp_stg_find(
"OMP_STACKSIZE");
5481 static kmp_setting_t *
volatile rivals[4];
5482 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
5483 #ifdef KMP_GOMP_COMPAT
5484 static kmp_stg_ss_data_t gomp_data = {1024,
5485 CCAST(kmp_setting_t **, rivals)};
5487 static kmp_stg_ss_data_t omp_data = {1024,
5488 CCAST(kmp_setting_t **, rivals)};
5491 rivals[i++] = kmp_stacksize;
5492 #ifdef KMP_GOMP_COMPAT
5493 if (gomp_stacksize != NULL) {
5494 rivals[i++] = gomp_stacksize;
5497 rivals[i++] = omp_stacksize;
5500 kmp_stacksize->data = &kmp_data;
5501 #ifdef KMP_GOMP_COMPAT
5502 if (gomp_stacksize != NULL) {
5503 gomp_stacksize->data = &gomp_data;
5506 omp_stacksize->data = &omp_data;
5510 kmp_setting_t *kmp_library =
5511 __kmp_stg_find(
"KMP_LIBRARY");
5512 kmp_setting_t *omp_wait_policy =
5513 __kmp_stg_find(
"OMP_WAIT_POLICY");
5516 static kmp_setting_t *
volatile rivals[3];
5517 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
5518 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
5521 rivals[i++] = kmp_library;
5522 if (omp_wait_policy != NULL) {
5523 rivals[i++] = omp_wait_policy;
5527 kmp_library->data = &kmp_data;
5528 if (omp_wait_policy != NULL) {
5529 omp_wait_policy->data = &omp_data;
5534 kmp_setting_t *kmp_device_thread_limit =
5535 __kmp_stg_find(
"KMP_DEVICE_THREAD_LIMIT");
5536 kmp_setting_t *kmp_all_threads =
5537 __kmp_stg_find(
"KMP_ALL_THREADS");
5540 static kmp_setting_t *
volatile rivals[3];
5543 rivals[i++] = kmp_device_thread_limit;
5544 rivals[i++] = kmp_all_threads;
5547 kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
5548 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
5553 kmp_setting_t *kmp_hw_subset = __kmp_stg_find(
"KMP_HW_SUBSET");
5555 kmp_setting_t *kmp_place_threads = __kmp_stg_find(
"KMP_PLACE_THREADS");
5558 static kmp_setting_t *
volatile rivals[3];
5561 rivals[i++] = kmp_hw_subset;
5562 rivals[i++] = kmp_place_threads;
5565 kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
5566 kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
5569 #if KMP_AFFINITY_SUPPORTED
5571 kmp_setting_t *kmp_affinity =
5572 __kmp_stg_find(
"KMP_AFFINITY");
5573 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
5575 #ifdef KMP_GOMP_COMPAT
5576 kmp_setting_t *gomp_cpu_affinity =
5577 __kmp_stg_find(
"GOMP_CPU_AFFINITY");
5578 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
5581 kmp_setting_t *omp_proc_bind =
5582 __kmp_stg_find(
"OMP_PROC_BIND");
5583 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
5586 static kmp_setting_t *
volatile rivals[4];
5589 rivals[i++] = kmp_affinity;
5591 #ifdef KMP_GOMP_COMPAT
5592 rivals[i++] = gomp_cpu_affinity;
5593 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
5596 rivals[i++] = omp_proc_bind;
5597 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
5600 static kmp_setting_t *
volatile places_rivals[4];
5603 kmp_setting_t *omp_places = __kmp_stg_find(
"OMP_PLACES");
5604 KMP_DEBUG_ASSERT(omp_places != NULL);
5606 places_rivals[i++] = kmp_affinity;
5607 #ifdef KMP_GOMP_COMPAT
5608 places_rivals[i++] = gomp_cpu_affinity;
5610 places_rivals[i++] = omp_places;
5611 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
5612 places_rivals[i++] = NULL;
5620 kmp_setting_t *kmp_force_red =
5621 __kmp_stg_find(
"KMP_FORCE_REDUCTION");
5622 kmp_setting_t *kmp_determ_red =
5623 __kmp_stg_find(
"KMP_DETERMINISTIC_REDUCTION");
5626 static kmp_setting_t *
volatile rivals[3];
5627 static kmp_stg_fr_data_t force_data = {1,
5628 CCAST(kmp_setting_t **, rivals)};
5629 static kmp_stg_fr_data_t determ_data = {0,
5630 CCAST(kmp_setting_t **, rivals)};
5633 rivals[i++] = kmp_force_red;
5634 if (kmp_determ_red != NULL) {
5635 rivals[i++] = kmp_determ_red;
5639 kmp_force_red->data = &force_data;
5640 if (kmp_determ_red != NULL) {
5641 kmp_determ_red->data = &determ_data;
5650 for (i = 0; i < __kmp_stg_count; ++i) {
5651 __kmp_stg_table[i].set = 0;
5656 static void __kmp_stg_parse(
char const *name,
char const *value) {
5664 if (value != NULL) {
5665 kmp_setting_t *setting = __kmp_stg_find(name);
5666 if (setting != NULL) {
5667 setting->parse(name, value, setting->data);
5668 setting->defined = 1;
5674 static int __kmp_stg_check_rivals(
5677 kmp_setting_t **rivals
5680 if (rivals == NULL) {
5686 for (; strcmp(rivals[i]->name, name) != 0; i++) {
5687 KMP_DEBUG_ASSERT(rivals[i] != NULL);
5689 #if KMP_AFFINITY_SUPPORTED
5690 if (rivals[i] == __kmp_affinity_notype) {
5697 if (rivals[i]->set) {
5698 KMP_WARNING(StgIgnored, name, rivals[i]->name);
5708 static int __kmp_env_toPrint(
char const *name,
int flag) {
5710 kmp_setting_t *setting = __kmp_stg_find(name);
5711 if (setting != NULL) {
5712 rc = setting->defined;
5714 setting->defined = flag;
5720 static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
5725 value = __kmp_env_blk_var(block,
"OMP_NUM_THREADS");
5727 ompc_set_num_threads(__kmp_dflt_team_nth);
5731 value = __kmp_env_blk_var(block,
"KMP_BLOCKTIME");
5733 kmpc_set_blocktime(__kmp_dflt_blocktime);
5737 value = __kmp_env_blk_var(block,
"OMP_NESTED");
5739 ompc_set_nested(__kmp_dflt_max_active_levels > 1);
5743 value = __kmp_env_blk_var(block,
"OMP_DYNAMIC");
5745 ompc_set_dynamic(__kmp_global.g.g_dynamic);
5749 void __kmp_env_initialize(
char const *
string) {
5751 kmp_env_blk_t block;
5757 if (
string == NULL) {
5759 __kmp_threads_capacity =
5760 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
5762 __kmp_env_blk_init(&block,
string);
5765 for (i = 0; i < block.count; ++i) {
5766 if ((block.vars[i].name == NULL) || (*block.vars[i].name ==
'\0')) {
5769 if (block.vars[i].value == NULL) {
5772 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
5773 if (setting != NULL) {
5779 blocktime_str = __kmp_env_blk_var(&block,
"KMP_BLOCKTIME");
5783 if (
string == NULL) {
5784 char const *name =
"KMP_WARNINGS";
5785 char const *value = __kmp_env_blk_var(&block, name);
5786 __kmp_stg_parse(name, value);
5789 #if KMP_AFFINITY_SUPPORTED
5795 __kmp_affinity_notype = NULL;
5796 char const *aff_str = __kmp_env_blk_var(&block,
"KMP_AFFINITY");
5797 if (aff_str != NULL) {
5811 #define FIND strcasestr
5814 if ((FIND(aff_str,
"none") == NULL) &&
5815 (FIND(aff_str,
"physical") == NULL) &&
5816 (FIND(aff_str,
"logical") == NULL) &&
5817 (FIND(aff_str,
"compact") == NULL) &&
5818 (FIND(aff_str,
"scatter") == NULL) &&
5819 (FIND(aff_str,
"explicit") == NULL) &&
5820 (FIND(aff_str,
"balanced") == NULL) &&
5821 (FIND(aff_str,
"disabled") == NULL)) {
5822 __kmp_affinity_notype = __kmp_stg_find(
"KMP_AFFINITY");
5827 __kmp_affinity_type = affinity_default;
5828 __kmp_affinity_gran = KMP_HW_UNKNOWN;
5829 __kmp_affinity_top_method = affinity_top_method_default;
5830 __kmp_affinity_respect_mask = affinity_respect_mask_default;
5835 aff_str = __kmp_env_blk_var(&block,
"OMP_PROC_BIND");
5836 if (aff_str != NULL) {
5837 __kmp_affinity_type = affinity_default;
5838 __kmp_affinity_gran = KMP_HW_UNKNOWN;
5839 __kmp_affinity_top_method = affinity_top_method_default;
5840 __kmp_affinity_respect_mask = affinity_respect_mask_default;
5847 if (__kmp_nested_proc_bind.bind_types == NULL) {
5848 __kmp_nested_proc_bind.bind_types =
5849 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(
sizeof(kmp_proc_bind_t));
5850 if (__kmp_nested_proc_bind.bind_types == NULL) {
5851 KMP_FATAL(MemoryAllocFailed);
5853 __kmp_nested_proc_bind.size = 1;
5854 __kmp_nested_proc_bind.used = 1;
5855 #if KMP_AFFINITY_SUPPORTED
5856 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
5859 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5866 __kmp_msg_format(kmp_i18n_msg_AffFormatDefault,
"%P",
"%i",
"%n",
"%A");
5867 KMP_DEBUG_ASSERT(KMP_STRLEN(m.str) < KMP_AFFINITY_FORMAT_SIZE);
5869 if (__kmp_affinity_format == NULL) {
5870 __kmp_affinity_format =
5871 (
char *)KMP_INTERNAL_MALLOC(
sizeof(
char) * KMP_AFFINITY_FORMAT_SIZE);
5873 KMP_STRCPY_S(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, m.str);
5874 __kmp_str_free(&m.str);
5877 for (i = 0; i < block.count; ++i) {
5878 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
5882 if (!__kmp_init_user_locks) {
5883 if (__kmp_user_lock_kind == lk_default) {
5884 __kmp_user_lock_kind = lk_queuing;
5886 #if KMP_USE_DYNAMIC_LOCK
5887 __kmp_init_dynamic_user_locks();
5889 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5892 KMP_DEBUG_ASSERT(
string != NULL);
5893 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
5898 #if KMP_USE_DYNAMIC_LOCK
5899 __kmp_init_dynamic_user_locks();
5901 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5905 #if KMP_AFFINITY_SUPPORTED
5907 if (!TCR_4(__kmp_init_middle)) {
5912 if (__kmp_hw_subset &&
5913 __kmp_affinity_top_method == affinity_top_method_default)
5914 if (__kmp_hw_subset->specified(KMP_HW_NUMA) ||
5915 __kmp_hw_subset->specified(KMP_HW_TILE) ||
5916 __kmp_affinity_gran == KMP_HW_TILE ||
5917 __kmp_affinity_gran == KMP_HW_NUMA)
5918 __kmp_affinity_top_method = affinity_top_method_hwloc;
5920 if (__kmp_affinity_gran == KMP_HW_NUMA ||
5921 __kmp_affinity_gran == KMP_HW_TILE)
5922 __kmp_affinity_top_method = affinity_top_method_hwloc;
5926 const char *var =
"KMP_AFFINITY";
5927 KMPAffinity::pick_api();
5932 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
5933 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
5934 KMP_WARNING(AffIgnoringHwloc, var);
5935 __kmp_affinity_top_method = affinity_top_method_all;
5938 if (__kmp_affinity_type == affinity_disabled) {
5939 KMP_AFFINITY_DISABLE();
5940 }
else if (!KMP_AFFINITY_CAPABLE()) {
5941 __kmp_affinity_dispatch->determine_capable(var);
5942 if (!KMP_AFFINITY_CAPABLE()) {
5943 if (__kmp_affinity_verbose ||
5944 (__kmp_affinity_warnings &&
5945 (__kmp_affinity_type != affinity_default) &&
5946 (__kmp_affinity_type != affinity_none) &&
5947 (__kmp_affinity_type != affinity_disabled))) {
5948 KMP_WARNING(AffNotSupported, var);
5950 __kmp_affinity_type = affinity_disabled;
5951 __kmp_affinity_respect_mask = 0;
5952 __kmp_affinity_gran = KMP_HW_THREAD;
5956 if (__kmp_affinity_type == affinity_disabled) {
5957 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5958 }
else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
5960 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
5963 if (KMP_AFFINITY_CAPABLE()) {
5965 #if KMP_GROUP_AFFINITY
5970 bool exactly_one_group =
false;
5971 if (__kmp_num_proc_groups > 1) {
5973 bool within_one_group;
5976 kmp_affin_mask_t *init_mask;
5977 KMP_CPU_ALLOC(init_mask);
5978 __kmp_get_system_affinity(init_mask, TRUE);
5979 group = __kmp_get_proc_group(init_mask);
5980 within_one_group = (group >= 0);
5983 if (within_one_group) {
5984 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
5985 DWORD num_bits_in_mask = 0;
5986 for (
int bit = init_mask->begin(); bit != init_mask->end();
5987 bit = init_mask->next(bit))
5989 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
5991 KMP_CPU_FREE(init_mask);
5997 if (((__kmp_num_proc_groups > 1) &&
5998 (__kmp_affinity_type == affinity_default) &&
5999 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default)) ||
6000 (__kmp_affinity_top_method == affinity_top_method_group)) {
6001 if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
6002 exactly_one_group) {
6003 __kmp_affinity_respect_mask = FALSE;
6005 if (__kmp_affinity_type == affinity_default) {
6006 __kmp_affinity_type = affinity_compact;
6007 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6009 if (__kmp_affinity_top_method == affinity_top_method_default) {
6010 if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
6011 __kmp_affinity_top_method = affinity_top_method_group;
6012 __kmp_affinity_gran = KMP_HW_PROC_GROUP;
6013 }
else if (__kmp_affinity_gran == KMP_HW_PROC_GROUP) {
6014 __kmp_affinity_top_method = affinity_top_method_group;
6016 __kmp_affinity_top_method = affinity_top_method_all;
6018 }
else if (__kmp_affinity_top_method == affinity_top_method_group) {
6019 if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
6020 __kmp_affinity_gran = KMP_HW_PROC_GROUP;
6021 }
else if ((__kmp_affinity_gran != KMP_HW_PROC_GROUP) &&
6022 (__kmp_affinity_gran != KMP_HW_THREAD)) {
6023 const char *str = __kmp_hw_get_keyword(__kmp_affinity_gran);
6024 KMP_WARNING(AffGranTopGroup, var, str);
6025 __kmp_affinity_gran = KMP_HW_THREAD;
6028 if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
6029 __kmp_affinity_gran = KMP_HW_CORE;
6030 }
else if (__kmp_affinity_gran == KMP_HW_PROC_GROUP) {
6031 const char *str = NULL;
6032 switch (__kmp_affinity_type) {
6033 case affinity_physical:
6036 case affinity_logical:
6039 case affinity_compact:
6042 case affinity_scatter:
6045 case affinity_explicit:
6050 KMP_DEBUG_ASSERT(0);
6052 KMP_WARNING(AffGranGroupType, var, str);
6053 __kmp_affinity_gran = KMP_HW_CORE;
6061 if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
6062 #if KMP_GROUP_AFFINITY
6063 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
6064 __kmp_affinity_respect_mask = FALSE;
6068 __kmp_affinity_respect_mask = TRUE;
6071 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
6072 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
6073 if (__kmp_affinity_type == affinity_default) {
6074 __kmp_affinity_type = affinity_compact;
6075 __kmp_affinity_dups = FALSE;
6077 }
else if (__kmp_affinity_type == affinity_default) {
6078 #if KMP_MIC_SUPPORTED
6079 if (__kmp_mic_type != non_mic) {
6080 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6084 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6086 #if KMP_MIC_SUPPORTED
6087 if (__kmp_mic_type != non_mic) {
6088 __kmp_affinity_type = affinity_scatter;
6092 __kmp_affinity_type = affinity_none;
6095 if ((__kmp_affinity_gran == KMP_HW_UNKNOWN) &&
6096 (__kmp_affinity_gran_levels < 0)) {
6097 #if KMP_MIC_SUPPORTED
6098 if (__kmp_mic_type != non_mic) {
6099 __kmp_affinity_gran = KMP_HW_THREAD;
6103 __kmp_affinity_gran = KMP_HW_CORE;
6106 if (__kmp_affinity_top_method == affinity_top_method_default) {
6107 __kmp_affinity_top_method = affinity_top_method_all;
6112 K_DIAG(1, (
"__kmp_affinity_type == %d\n", __kmp_affinity_type));
6113 K_DIAG(1, (
"__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
6114 K_DIAG(1, (
"__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
6115 K_DIAG(1, (
"__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
6116 K_DIAG(1, (
"__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
6117 K_DIAG(1, (
"__kmp_affinity_respect_mask == %d\n",
6118 __kmp_affinity_respect_mask));
6119 K_DIAG(1, (
"__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
6121 KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
6122 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
6123 K_DIAG(1, (
"__kmp_nested_proc_bind.bind_types[0] == %d\n",
6124 __kmp_nested_proc_bind.bind_types[0]));
6129 if (__kmp_version) {
6130 __kmp_print_version_1();
6135 if (
string != NULL) {
6136 __kmp_aux_env_initialize(&block);
6139 __kmp_env_blk_free(&block);
6145 void __kmp_env_print() {
6147 kmp_env_blk_t block;
6149 kmp_str_buf_t buffer;
6152 __kmp_str_buf_init(&buffer);
6154 __kmp_env_blk_init(&block, NULL);
6155 __kmp_env_blk_sort(&block);
6158 __kmp_str_buf_print(&buffer,
"\n%s\n\n", KMP_I18N_STR(UserSettings));
6159 for (i = 0; i < block.count; ++i) {
6160 char const *name = block.vars[i].name;
6161 char const *value = block.vars[i].value;
6162 if ((KMP_STRLEN(name) > 4 && strncmp(name,
"KMP_", 4) == 0) ||
6163 strncmp(name,
"OMP_", 4) == 0
6164 #ifdef KMP_GOMP_COMPAT
6165 || strncmp(name,
"GOMP_", 5) == 0
6168 __kmp_str_buf_print(&buffer,
" %s=%s\n", name, value);
6171 __kmp_str_buf_print(&buffer,
"\n");
6174 __kmp_str_buf_print(&buffer,
"%s\n\n", KMP_I18N_STR(EffectiveSettings));
6175 for (
int i = 0; i < __kmp_stg_count; ++i) {
6176 if (__kmp_stg_table[i].print != NULL) {
6177 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6178 __kmp_stg_table[i].data);
6182 __kmp_printf(
"%s", buffer.str);
6184 __kmp_env_blk_free(&block);
6185 __kmp_str_buf_free(&buffer);
6191 void __kmp_env_print_2() {
6192 __kmp_display_env_impl(__kmp_display_env, __kmp_display_env_verbose);
6195 void __kmp_display_env_impl(
int display_env,
int display_env_verbose) {
6196 kmp_env_blk_t block;
6197 kmp_str_buf_t buffer;
6199 __kmp_env_format = 1;
6202 __kmp_str_buf_init(&buffer);
6204 __kmp_env_blk_init(&block, NULL);
6205 __kmp_env_blk_sort(&block);
6207 __kmp_str_buf_print(&buffer,
"\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
6208 __kmp_str_buf_print(&buffer,
" _OPENMP='%d'\n", __kmp_openmp_version);
6210 for (
int i = 0; i < __kmp_stg_count; ++i) {
6211 if (__kmp_stg_table[i].print != NULL &&
6212 ((display_env && strncmp(__kmp_stg_table[i].name,
"OMP_", 4) == 0) ||
6213 display_env_verbose)) {
6214 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6215 __kmp_stg_table[i].data);
6219 __kmp_str_buf_print(&buffer,
"%s\n", KMP_I18N_STR(DisplayEnvEnd));
6220 __kmp_str_buf_print(&buffer,
"\n");
6222 __kmp_printf(
"%s", buffer.str);
6224 __kmp_env_blk_free(&block);
6225 __kmp_str_buf_free(&buffer);
6232 void __kmp_env_dump() {
6234 kmp_env_blk_t block;
6235 kmp_str_buf_t buffer, env, notdefined;
6238 __kmp_str_buf_init(&buffer);
6239 __kmp_str_buf_init(&env);
6240 __kmp_str_buf_init(¬defined);
6242 __kmp_env_blk_init(&block, NULL);
6243 __kmp_env_blk_sort(&block);
6245 __kmp_str_buf_print(¬defined,
": %s", KMP_I18N_STR(NotDefined));
6247 for (
int i = 0; i < __kmp_stg_count; ++i) {
6248 if (__kmp_stg_table[i].print == NULL)
6250 __kmp_str_buf_clear(&env);
6251 __kmp_stg_table[i].print(&env, __kmp_stg_table[i].name,
6252 __kmp_stg_table[i].data);
6255 if (strstr(env.str, notdefined.str))
6257 __kmp_str_buf_print(&buffer,
"%s=undefined\n", __kmp_stg_table[i].name);
6259 __kmp_str_buf_cat(&buffer, env.str + 3, env.used - 3);
6262 ompd_env_block = (
char *)__kmp_allocate(buffer.used + 1);
6263 KMP_MEMCPY(ompd_env_block, buffer.str, buffer.used + 1);
6264 ompd_env_block_size = (ompd_size_t)KMP_STRLEN(ompd_env_block);
6266 __kmp_env_blk_free(&block);
6267 __kmp_str_buf_free(&buffer);
6268 __kmp_str_buf_free(&env);
6269 __kmp_str_buf_free(¬defined);
@ kmp_sch_modifier_monotonic
@ kmp_sch_modifier_nonmonotonic