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_sys_min_stksize)
306 *val = __kmp_sys_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) {
1758 if ((non_dist_req != 0) && warn) {
1759 KMP_INFORM(BarrierPatternOverride, name,
1760 __kmp_barrier_pattern_name[bp_dist_bar]);
1763 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1764 if (__kmp_barrier_release_pattern[i] != bp_dist_bar)
1765 __kmp_barrier_release_pattern[i] = bp_dist_bar;
1766 if (__kmp_barrier_gather_pattern[i] != bp_dist_bar)
1767 __kmp_barrier_gather_pattern[i] = bp_dist_bar;
1772 static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1773 char const *name,
void *data) {
1775 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1776 var = __kmp_barrier_pattern_env_name[i];
1777 if (strcmp(var, name) == 0) {
1778 int j = __kmp_barrier_gather_pattern[i];
1779 int k = __kmp_barrier_release_pattern[i];
1780 if (__kmp_env_format) {
1781 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1783 __kmp_str_buf_print(buffer,
" %s='",
1784 __kmp_barrier_pattern_env_name[i]);
1786 KMP_DEBUG_ASSERT(j < bp_last_bar && k < bp_last_bar);
1787 __kmp_str_buf_print(buffer,
"%s,%s'\n", __kmp_barrier_pattern_name[j],
1788 __kmp_barrier_pattern_name[k]);
1796 static void __kmp_stg_parse_abort_delay(
char const *name,
char const *value,
1800 int delay = __kmp_abort_delay / 1000;
1801 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1802 __kmp_abort_delay = delay * 1000;
1805 static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer,
char const *name,
1807 __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
1813 static void __kmp_stg_parse_cpuinfo_file(
char const *name,
char const *value,
1815 #if KMP_AFFINITY_SUPPORTED
1816 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1817 K_DIAG(1, (
"__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1821 static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1822 char const *name,
void *data) {
1823 #if KMP_AFFINITY_SUPPORTED
1824 if (__kmp_env_format) {
1825 KMP_STR_BUF_PRINT_NAME;
1827 __kmp_str_buf_print(buffer,
" %s", name);
1829 if (__kmp_cpuinfo_file) {
1830 __kmp_str_buf_print(buffer,
"='%s'\n", __kmp_cpuinfo_file);
1832 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
1840 static void __kmp_stg_parse_force_reduction(
char const *name,
char const *value,
1842 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1845 rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1849 if (reduction->force) {
1851 if (__kmp_str_match(
"critical", 0, value))
1852 __kmp_force_reduction_method = critical_reduce_block;
1853 else if (__kmp_str_match(
"atomic", 0, value))
1854 __kmp_force_reduction_method = atomic_reduce_block;
1855 else if (__kmp_str_match(
"tree", 0, value))
1856 __kmp_force_reduction_method = tree_reduce_block;
1858 KMP_FATAL(UnknownForceReduction, name, value);
1862 __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1863 if (__kmp_determ_red) {
1864 __kmp_force_reduction_method = tree_reduce_block;
1866 __kmp_force_reduction_method = reduction_method_not_defined;
1869 K_DIAG(1, (
"__kmp_force_reduction_method == %d\n",
1870 __kmp_force_reduction_method));
1873 static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1874 char const *name,
void *data) {
1876 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1877 if (reduction->force) {
1878 if (__kmp_force_reduction_method == critical_reduce_block) {
1879 __kmp_stg_print_str(buffer, name,
"critical");
1880 }
else if (__kmp_force_reduction_method == atomic_reduce_block) {
1881 __kmp_stg_print_str(buffer, name,
"atomic");
1882 }
else if (__kmp_force_reduction_method == tree_reduce_block) {
1883 __kmp_stg_print_str(buffer, name,
"tree");
1885 if (__kmp_env_format) {
1886 KMP_STR_BUF_PRINT_NAME;
1888 __kmp_str_buf_print(buffer,
" %s", name);
1890 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
1893 __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1901 static void __kmp_stg_parse_storage_map(
char const *name,
char const *value,
1903 if (__kmp_str_match(
"verbose", 1, value)) {
1904 __kmp_storage_map = TRUE;
1905 __kmp_storage_map_verbose = TRUE;
1906 __kmp_storage_map_verbose_specified = TRUE;
1909 __kmp_storage_map_verbose = FALSE;
1910 __kmp_stg_parse_bool(name, value, &__kmp_storage_map);
1914 static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer,
char const *name,
1916 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1917 __kmp_stg_print_str(buffer, name,
"verbose");
1919 __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1926 static void __kmp_stg_parse_all_threadprivate(
char const *name,
1927 char const *value,
void *data) {
1928 __kmp_stg_parse_int(name, value,
1929 __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1930 __kmp_max_nth, &__kmp_tp_capacity);
1933 static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1934 char const *name,
void *data) {
1935 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
1941 static void __kmp_stg_parse_foreign_threads_threadprivate(
char const *name,
1944 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
1947 static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
1950 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
1956 #if KMP_AFFINITY_SUPPORTED
1958 static int __kmp_parse_affinity_proc_id_list(
const char *var,
const char *env,
1959 const char **nextEnv,
1961 const char *scan = env;
1962 const char *next = scan;
1968 int start, end, stride;
1972 if (*next ==
'\0') {
1983 if ((*next <
'0') || (*next >
'9')) {
1984 KMP_WARNING(AffSyntaxError, var);
1988 num = __kmp_str_to_int(scan, *next);
1989 KMP_ASSERT(num >= 0);
2007 if ((*next <
'0') || (*next >
'9')) {
2008 KMP_WARNING(AffSyntaxError, var);
2013 num = __kmp_str_to_int(scan, *next);
2014 KMP_ASSERT(num >= 0);
2027 if ((*next <
'0') || (*next >
'9')) {
2029 KMP_WARNING(AffSyntaxError, var);
2037 start = __kmp_str_to_int(scan, *next);
2038 KMP_ASSERT(start >= 0);
2057 if ((*next <
'0') || (*next >
'9')) {
2058 KMP_WARNING(AffSyntaxError, var);
2062 end = __kmp_str_to_int(scan, *next);
2063 KMP_ASSERT(end >= 0);
2080 if ((*next <
'0') || (*next >
'9')) {
2081 KMP_WARNING(AffSyntaxError, var);
2085 stride = __kmp_str_to_int(scan, *next);
2086 KMP_ASSERT(stride >= 0);
2092 KMP_WARNING(AffZeroStride, var);
2097 KMP_WARNING(AffStartGreaterEnd, var, start, end);
2102 KMP_WARNING(AffStrideLessZero, var, start, end);
2106 if ((end - start) / stride > 65536) {
2107 KMP_WARNING(AffRangeTooBig, var, end, start, stride);
2124 ptrdiff_t len = next - env;
2125 char *retlist = (
char *)__kmp_allocate((len + 1) *
sizeof(char));
2126 KMP_MEMCPY_S(retlist, (len + 1) *
sizeof(
char), env, len *
sizeof(
char));
2127 retlist[len] =
'\0';
2128 *proclist = retlist;
2135 static kmp_setting_t *__kmp_affinity_notype = NULL;
2137 static void __kmp_parse_affinity_env(
char const *name,
char const *value,
2138 enum affinity_type *out_type,
2139 char **out_proclist,
int *out_verbose,
2140 int *out_warn,
int *out_respect,
2141 kmp_hw_t *out_gran,
int *out_gran_levels,
2142 int *out_dups,
int *out_compact,
2144 char *buffer = NULL;
2161 KMP_ASSERT(value != NULL);
2163 if (TCR_4(__kmp_init_middle)) {
2164 KMP_WARNING(EnvMiddleWarn, name);
2165 __kmp_env_toPrint(name, 0);
2168 __kmp_env_toPrint(name, 1);
2171 __kmp_str_format(
"%s", value);
2181 #define EMIT_WARN(skip, errlist) \
2185 SKIP_TO(next, ','); \
2189 KMP_WARNING errlist; \
2198 #define _set_param(_guard, _var, _val) \
2200 if (_guard == 0) { \
2203 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2208 #define set_type(val) _set_param(type, *out_type, val)
2209 #define set_verbose(val) _set_param(verbose, *out_verbose, val)
2210 #define set_warnings(val) _set_param(warnings, *out_warn, val)
2211 #define set_respect(val) _set_param(respect, *out_respect, val)
2212 #define set_dups(val) _set_param(dups, *out_dups, val)
2213 #define set_proclist(val) _set_param(proclist, *out_proclist, val)
2215 #define set_gran(val, levels) \
2219 *out_gran_levels = levels; \
2221 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2226 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
2227 (__kmp_nested_proc_bind.used > 0));
2229 while (*buf !=
'\0') {
2232 if (__kmp_match_str(
"none", buf, CCAST(
const char **, &next))) {
2233 set_type(affinity_none);
2234 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2236 }
else if (__kmp_match_str(
"scatter", buf, CCAST(
const char **, &next))) {
2237 set_type(affinity_scatter);
2238 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2240 }
else if (__kmp_match_str(
"compact", buf, CCAST(
const char **, &next))) {
2241 set_type(affinity_compact);
2242 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2244 }
else if (__kmp_match_str(
"logical", buf, CCAST(
const char **, &next))) {
2245 set_type(affinity_logical);
2246 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2248 }
else if (__kmp_match_str(
"physical", buf, CCAST(
const char **, &next))) {
2249 set_type(affinity_physical);
2250 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2252 }
else if (__kmp_match_str(
"explicit", buf, CCAST(
const char **, &next))) {
2253 set_type(affinity_explicit);
2254 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2256 }
else if (__kmp_match_str(
"balanced", buf, CCAST(
const char **, &next))) {
2257 set_type(affinity_balanced);
2258 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2260 }
else if (__kmp_match_str(
"disabled", buf, CCAST(
const char **, &next))) {
2261 set_type(affinity_disabled);
2262 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2264 }
else if (__kmp_match_str(
"verbose", buf, CCAST(
const char **, &next))) {
2267 }
else if (__kmp_match_str(
"noverbose", buf, CCAST(
const char **, &next))) {
2270 }
else if (__kmp_match_str(
"warnings", buf, CCAST(
const char **, &next))) {
2273 }
else if (__kmp_match_str(
"nowarnings", buf,
2274 CCAST(
const char **, &next))) {
2275 set_warnings(FALSE);
2277 }
else if (__kmp_match_str(
"respect", buf, CCAST(
const char **, &next))) {
2280 }
else if (__kmp_match_str(
"norespect", buf, CCAST(
const char **, &next))) {
2283 }
else if (__kmp_match_str(
"duplicates", buf,
2284 CCAST(
const char **, &next)) ||
2285 __kmp_match_str(
"dups", buf, CCAST(
const char **, &next))) {
2288 }
else if (__kmp_match_str(
"noduplicates", buf,
2289 CCAST(
const char **, &next)) ||
2290 __kmp_match_str(
"nodups", buf, CCAST(
const char **, &next))) {
2293 }
else if (__kmp_match_str(
"granularity", buf,
2294 CCAST(
const char **, &next)) ||
2295 __kmp_match_str(
"gran", buf, CCAST(
const char **, &next))) {
2298 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2307 KMP_FOREACH_HW_TYPE(type) {
2308 const char *name = __kmp_hw_get_keyword(type);
2309 if (__kmp_match_str(name, buf, CCAST(
const char **, &next))) {
2318 if (__kmp_match_str(
"fine", buf, CCAST(
const char **, &next))) {
2319 set_gran(KMP_HW_THREAD, -1);
2322 }
else if (__kmp_match_str(
"package", buf,
2323 CCAST(
const char **, &next))) {
2324 set_gran(KMP_HW_SOCKET, -1);
2327 }
else if (__kmp_match_str(
"node", buf, CCAST(
const char **, &next))) {
2328 set_gran(KMP_HW_NUMA, -1);
2331 #if KMP_GROUP_AFFINITY
2332 }
else if (__kmp_match_str(
"group", buf, CCAST(
const char **, &next))) {
2333 set_gran(KMP_HW_PROC_GROUP, -1);
2337 }
else if ((*buf >=
'0') && (*buf <=
'9')) {
2341 n = __kmp_str_to_int(buf, *next);
2344 set_gran(KMP_HW_UNKNOWN, n);
2347 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2351 }
else if (__kmp_match_str(
"proclist", buf, CCAST(
const char **, &next))) {
2352 char *temp_proclist;
2356 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2362 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2367 if (!__kmp_parse_affinity_proc_id_list(
2368 name, buf, CCAST(
const char **, &next), &temp_proclist)) {
2380 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2384 set_proclist(temp_proclist);
2385 }
else if ((*buf >=
'0') && (*buf <=
'9')) {
2390 n = __kmp_str_to_int(buf, *next);
2396 KMP_WARNING(AffManyParams, name, start);
2400 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2408 }
else if (*next !=
'\0') {
2409 const char *temp = next;
2410 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2422 #undef set_granularity
2424 __kmp_str_free(&buffer);
2428 KMP_WARNING(AffProcListNoType, name);
2429 *out_type = affinity_explicit;
2430 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2431 }
else if (*out_type != affinity_explicit) {
2432 KMP_WARNING(AffProcListNotExplicit, name);
2433 KMP_ASSERT(*out_proclist != NULL);
2434 KMP_INTERNAL_FREE(*out_proclist);
2435 *out_proclist = NULL;
2438 switch (*out_type) {
2439 case affinity_logical:
2440 case affinity_physical: {
2442 *out_offset = number[0];
2445 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
2448 case affinity_balanced: {
2450 *out_compact = number[0];
2453 *out_offset = number[1];
2456 if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
2457 #if KMP_MIC_SUPPORTED
2458 if (__kmp_mic_type != non_mic) {
2459 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2460 KMP_WARNING(AffGranUsing,
"KMP_AFFINITY",
"fine");
2462 __kmp_affinity_gran = KMP_HW_THREAD;
2466 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2467 KMP_WARNING(AffGranUsing,
"KMP_AFFINITY",
"core");
2469 __kmp_affinity_gran = KMP_HW_CORE;
2473 case affinity_scatter:
2474 case affinity_compact: {
2476 *out_compact = number[0];
2479 *out_offset = number[1];
2482 case affinity_explicit: {
2483 if (*out_proclist == NULL) {
2484 KMP_WARNING(AffNoProcList, name);
2485 __kmp_affinity_type = affinity_none;
2488 KMP_WARNING(AffNoParam, name,
"explicit");
2491 case affinity_none: {
2493 KMP_WARNING(AffNoParam, name,
"none");
2496 case affinity_disabled: {
2498 KMP_WARNING(AffNoParam, name,
"disabled");
2501 case affinity_default: {
2503 KMP_WARNING(AffNoParam, name,
"default");
2512 static void __kmp_stg_parse_affinity(
char const *name,
char const *value,
2514 kmp_setting_t **rivals = (kmp_setting_t **)data;
2517 rc = __kmp_stg_check_rivals(name, value, rivals);
2522 __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2523 &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2524 &__kmp_affinity_warnings,
2525 &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2526 &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2527 &__kmp_affinity_compact, &__kmp_affinity_offset);
2531 static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer,
char const *name,
2533 if (__kmp_env_format) {
2534 KMP_STR_BUF_PRINT_NAME_EX(name);
2536 __kmp_str_buf_print(buffer,
" %s='", name);
2538 if (__kmp_affinity_verbose) {
2539 __kmp_str_buf_print(buffer,
"%s,",
"verbose");
2541 __kmp_str_buf_print(buffer,
"%s,",
"noverbose");
2543 if (__kmp_affinity_warnings) {
2544 __kmp_str_buf_print(buffer,
"%s,",
"warnings");
2546 __kmp_str_buf_print(buffer,
"%s,",
"nowarnings");
2548 if (KMP_AFFINITY_CAPABLE()) {
2549 if (__kmp_affinity_respect_mask) {
2550 __kmp_str_buf_print(buffer,
"%s,",
"respect");
2552 __kmp_str_buf_print(buffer,
"%s,",
"norespect");
2554 __kmp_str_buf_print(buffer,
"granularity=%s,",
2555 __kmp_hw_get_keyword(__kmp_affinity_gran,
false));
2557 if (!KMP_AFFINITY_CAPABLE()) {
2558 __kmp_str_buf_print(buffer,
"%s",
"disabled");
2560 switch (__kmp_affinity_type) {
2562 __kmp_str_buf_print(buffer,
"%s",
"none");
2564 case affinity_physical:
2565 __kmp_str_buf_print(buffer,
"%s,%d",
"physical", __kmp_affinity_offset);
2567 case affinity_logical:
2568 __kmp_str_buf_print(buffer,
"%s,%d",
"logical", __kmp_affinity_offset);
2570 case affinity_compact:
2571 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"compact", __kmp_affinity_compact,
2572 __kmp_affinity_offset);
2574 case affinity_scatter:
2575 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"scatter", __kmp_affinity_compact,
2576 __kmp_affinity_offset);
2578 case affinity_explicit:
2579 __kmp_str_buf_print(buffer,
"%s=[%s],%s",
"proclist",
2580 __kmp_affinity_proclist,
"explicit");
2582 case affinity_balanced:
2583 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"balanced",
2584 __kmp_affinity_compact, __kmp_affinity_offset);
2586 case affinity_disabled:
2587 __kmp_str_buf_print(buffer,
"%s",
"disabled");
2589 case affinity_default:
2590 __kmp_str_buf_print(buffer,
"%s",
"default");
2593 __kmp_str_buf_print(buffer,
"%s",
"<unknown>");
2596 __kmp_str_buf_print(buffer,
"'\n");
2599 #ifdef KMP_GOMP_COMPAT
2601 static void __kmp_stg_parse_gomp_cpu_affinity(
char const *name,
2602 char const *value,
void *data) {
2603 const char *next = NULL;
2604 char *temp_proclist;
2605 kmp_setting_t **rivals = (kmp_setting_t **)data;
2608 rc = __kmp_stg_check_rivals(name, value, rivals);
2613 if (TCR_4(__kmp_init_middle)) {
2614 KMP_WARNING(EnvMiddleWarn, name);
2615 __kmp_env_toPrint(name, 0);
2619 __kmp_env_toPrint(name, 1);
2621 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2623 if (*next ==
'\0') {
2625 __kmp_affinity_proclist = temp_proclist;
2626 __kmp_affinity_type = affinity_explicit;
2627 __kmp_affinity_gran = KMP_HW_THREAD;
2628 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2630 KMP_WARNING(AffSyntaxError, name);
2631 if (temp_proclist != NULL) {
2632 KMP_INTERNAL_FREE((
void *)temp_proclist);
2637 __kmp_affinity_type = affinity_none;
2638 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2665 static inline void __kmp_omp_places_syntax_warn(
const char *var) {
2666 KMP_WARNING(SyntaxErrorUsing, var,
"\"cores\"");
2669 static int __kmp_parse_subplace_list(
const char *var,
const char **scan) {
2673 int start, count, stride;
2679 if ((**scan <
'0') || (**scan >
'9')) {
2680 __kmp_omp_places_syntax_warn(var);
2685 start = __kmp_str_to_int(*scan, *next);
2686 KMP_ASSERT(start >= 0);
2691 if (**scan ==
'}') {
2694 if (**scan ==
',') {
2698 if (**scan !=
':') {
2699 __kmp_omp_places_syntax_warn(var);
2706 if ((**scan <
'0') || (**scan >
'9')) {
2707 __kmp_omp_places_syntax_warn(var);
2712 count = __kmp_str_to_int(*scan, *next);
2713 KMP_ASSERT(count >= 0);
2718 if (**scan ==
'}') {
2721 if (**scan ==
',') {
2725 if (**scan !=
':') {
2726 __kmp_omp_places_syntax_warn(var);
2735 if (**scan ==
'+') {
2739 if (**scan ==
'-') {
2747 if ((**scan <
'0') || (**scan >
'9')) {
2748 __kmp_omp_places_syntax_warn(var);
2753 stride = __kmp_str_to_int(*scan, *next);
2754 KMP_ASSERT(stride >= 0);
2760 if (**scan ==
'}') {
2763 if (**scan ==
',') {
2768 __kmp_omp_places_syntax_warn(var);
2774 static int __kmp_parse_place(
const char *var,
const char **scan) {
2779 if (**scan ==
'{') {
2781 if (!__kmp_parse_subplace_list(var, scan)) {
2784 if (**scan !=
'}') {
2785 __kmp_omp_places_syntax_warn(var);
2789 }
else if (**scan ==
'!') {
2791 return __kmp_parse_place(var, scan);
2792 }
else if ((**scan >=
'0') && (**scan <=
'9')) {
2795 int proc = __kmp_str_to_int(*scan, *next);
2796 KMP_ASSERT(proc >= 0);
2799 __kmp_omp_places_syntax_warn(var);
2805 static int __kmp_parse_place_list(
const char *var,
const char *env,
2806 char **place_list) {
2807 const char *scan = env;
2808 const char *next = scan;
2813 if (!__kmp_parse_place(var, &scan)) {
2819 if (*scan ==
'\0') {
2827 __kmp_omp_places_syntax_warn(var);
2834 if ((*scan <
'0') || (*scan >
'9')) {
2835 __kmp_omp_places_syntax_warn(var);
2840 count = __kmp_str_to_int(scan, *next);
2841 KMP_ASSERT(count >= 0);
2846 if (*scan ==
'\0') {
2854 __kmp_omp_places_syntax_warn(var);
2875 if ((*scan <
'0') || (*scan >
'9')) {
2876 __kmp_omp_places_syntax_warn(var);
2881 stride = __kmp_str_to_int(scan, *next);
2882 KMP_ASSERT(stride >= 0);
2888 if (*scan ==
'\0') {
2896 __kmp_omp_places_syntax_warn(var);
2901 ptrdiff_t len = scan - env;
2902 char *retlist = (
char *)__kmp_allocate((len + 1) *
sizeof(char));
2903 KMP_MEMCPY_S(retlist, (len + 1) *
sizeof(
char), env, len *
sizeof(
char));
2904 retlist[len] =
'\0';
2905 *place_list = retlist;
2910 static void __kmp_stg_parse_places(
char const *name,
char const *value,
2912 struct kmp_place_t {
2918 const char *scan = value;
2919 const char *next = scan;
2920 const char *kind =
"\"threads\"";
2921 kmp_place_t std_places[] = {{
"threads", KMP_HW_THREAD},
2922 {
"cores", KMP_HW_CORE},
2923 {
"numa_domains", KMP_HW_NUMA},
2924 {
"ll_caches", KMP_HW_LLC},
2925 {
"sockets", KMP_HW_SOCKET}};
2926 kmp_setting_t **rivals = (kmp_setting_t **)data;
2929 rc = __kmp_stg_check_rivals(name, value, rivals);
2935 for (
size_t i = 0; i <
sizeof(std_places) /
sizeof(std_places[0]); ++i) {
2936 const kmp_place_t &place = std_places[i];
2937 if (__kmp_match_str(place.name, scan, &next)) {
2939 __kmp_affinity_type = affinity_compact;
2940 __kmp_affinity_gran = place.type;
2941 __kmp_affinity_dups = FALSE;
2948 KMP_FOREACH_HW_TYPE(type) {
2949 const char *name = __kmp_hw_get_keyword(type,
true);
2950 if (__kmp_match_str(
"unknowns", scan, &next))
2952 if (__kmp_match_str(name, scan, &next)) {
2954 __kmp_affinity_type = affinity_compact;
2955 __kmp_affinity_gran = type;
2956 __kmp_affinity_dups = FALSE;
2963 if (__kmp_affinity_proclist != NULL) {
2964 KMP_INTERNAL_FREE((
void *)__kmp_affinity_proclist);
2965 __kmp_affinity_proclist = NULL;
2967 if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2968 __kmp_affinity_type = affinity_explicit;
2969 __kmp_affinity_gran = KMP_HW_THREAD;
2970 __kmp_affinity_dups = FALSE;
2973 __kmp_affinity_type = affinity_compact;
2974 __kmp_affinity_gran = KMP_HW_CORE;
2975 __kmp_affinity_dups = FALSE;
2977 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2978 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2982 if (__kmp_affinity_gran != KMP_HW_UNKNOWN) {
2983 kind = __kmp_hw_get_keyword(__kmp_affinity_gran);
2986 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2987 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2991 if (*scan ==
'\0') {
2997 KMP_WARNING(SyntaxErrorUsing, name, kind);
3005 count = __kmp_str_to_int(scan, *next);
3006 KMP_ASSERT(count >= 0);
3011 KMP_WARNING(SyntaxErrorUsing, name, kind);
3017 if (*scan !=
'\0') {
3018 KMP_WARNING(ParseExtraCharsWarn, name, scan);
3020 __kmp_affinity_num_places = count;
3023 static void __kmp_stg_print_places(kmp_str_buf_t *buffer,
char const *name,
3025 if (__kmp_env_format) {
3026 KMP_STR_BUF_PRINT_NAME;
3028 __kmp_str_buf_print(buffer,
" %s", name);
3030 if ((__kmp_nested_proc_bind.used == 0) ||
3031 (__kmp_nested_proc_bind.bind_types == NULL) ||
3032 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
3033 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3034 }
else if (__kmp_affinity_type == affinity_explicit) {
3035 if (__kmp_affinity_proclist != NULL) {
3036 __kmp_str_buf_print(buffer,
"='%s'\n", __kmp_affinity_proclist);
3038 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3040 }
else if (__kmp_affinity_type == affinity_compact) {
3042 if (__kmp_affinity_num_masks > 0) {
3043 num = __kmp_affinity_num_masks;
3044 }
else if (__kmp_affinity_num_places > 0) {
3045 num = __kmp_affinity_num_places;
3049 if (__kmp_affinity_gran != KMP_HW_UNKNOWN) {
3050 const char *name = __kmp_hw_get_keyword(__kmp_affinity_gran,
true);
3052 __kmp_str_buf_print(buffer,
"='%s(%d)'\n", name, num);
3054 __kmp_str_buf_print(buffer,
"='%s'\n", name);
3057 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3060 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3064 static void __kmp_stg_parse_topology_method(
char const *name,
char const *value,
3066 if (__kmp_str_match(
"all", 1, value)) {
3067 __kmp_affinity_top_method = affinity_top_method_all;
3070 else if (__kmp_str_match(
"hwloc", 1, value)) {
3071 __kmp_affinity_top_method = affinity_top_method_hwloc;
3074 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3075 else if (__kmp_str_match(
"cpuid_leaf31", 12, value) ||
3076 __kmp_str_match(
"cpuid 1f", 8, value) ||
3077 __kmp_str_match(
"cpuid 31", 8, value) ||
3078 __kmp_str_match(
"cpuid1f", 7, value) ||
3079 __kmp_str_match(
"cpuid31", 7, value) ||
3080 __kmp_str_match(
"leaf 1f", 7, value) ||
3081 __kmp_str_match(
"leaf 31", 7, value) ||
3082 __kmp_str_match(
"leaf1f", 6, value) ||
3083 __kmp_str_match(
"leaf31", 6, value)) {
3084 __kmp_affinity_top_method = affinity_top_method_x2apicid_1f;
3085 }
else if (__kmp_str_match(
"x2apic id", 9, value) ||
3086 __kmp_str_match(
"x2apic_id", 9, value) ||
3087 __kmp_str_match(
"x2apic-id", 9, value) ||
3088 __kmp_str_match(
"x2apicid", 8, value) ||
3089 __kmp_str_match(
"cpuid leaf 11", 13, value) ||
3090 __kmp_str_match(
"cpuid_leaf_11", 13, value) ||
3091 __kmp_str_match(
"cpuid-leaf-11", 13, value) ||
3092 __kmp_str_match(
"cpuid leaf11", 12, value) ||
3093 __kmp_str_match(
"cpuid_leaf11", 12, value) ||
3094 __kmp_str_match(
"cpuid-leaf11", 12, value) ||
3095 __kmp_str_match(
"cpuidleaf 11", 12, value) ||
3096 __kmp_str_match(
"cpuidleaf_11", 12, value) ||
3097 __kmp_str_match(
"cpuidleaf-11", 12, value) ||
3098 __kmp_str_match(
"cpuidleaf11", 11, value) ||
3099 __kmp_str_match(
"cpuid 11", 8, value) ||
3100 __kmp_str_match(
"cpuid_11", 8, value) ||
3101 __kmp_str_match(
"cpuid-11", 8, value) ||
3102 __kmp_str_match(
"cpuid11", 7, value) ||
3103 __kmp_str_match(
"leaf 11", 7, value) ||
3104 __kmp_str_match(
"leaf_11", 7, value) ||
3105 __kmp_str_match(
"leaf-11", 7, value) ||
3106 __kmp_str_match(
"leaf11", 6, value)) {
3107 __kmp_affinity_top_method = affinity_top_method_x2apicid;
3108 }
else if (__kmp_str_match(
"apic id", 7, value) ||
3109 __kmp_str_match(
"apic_id", 7, value) ||
3110 __kmp_str_match(
"apic-id", 7, value) ||
3111 __kmp_str_match(
"apicid", 6, value) ||
3112 __kmp_str_match(
"cpuid leaf 4", 12, value) ||
3113 __kmp_str_match(
"cpuid_leaf_4", 12, value) ||
3114 __kmp_str_match(
"cpuid-leaf-4", 12, value) ||
3115 __kmp_str_match(
"cpuid leaf4", 11, value) ||
3116 __kmp_str_match(
"cpuid_leaf4", 11, value) ||
3117 __kmp_str_match(
"cpuid-leaf4", 11, value) ||
3118 __kmp_str_match(
"cpuidleaf 4", 11, value) ||
3119 __kmp_str_match(
"cpuidleaf_4", 11, value) ||
3120 __kmp_str_match(
"cpuidleaf-4", 11, value) ||
3121 __kmp_str_match(
"cpuidleaf4", 10, value) ||
3122 __kmp_str_match(
"cpuid 4", 7, value) ||
3123 __kmp_str_match(
"cpuid_4", 7, value) ||
3124 __kmp_str_match(
"cpuid-4", 7, value) ||
3125 __kmp_str_match(
"cpuid4", 6, value) ||
3126 __kmp_str_match(
"leaf 4", 6, value) ||
3127 __kmp_str_match(
"leaf_4", 6, value) ||
3128 __kmp_str_match(
"leaf-4", 6, value) ||
3129 __kmp_str_match(
"leaf4", 5, value)) {
3130 __kmp_affinity_top_method = affinity_top_method_apicid;
3133 else if (__kmp_str_match(
"/proc/cpuinfo", 2, value) ||
3134 __kmp_str_match(
"cpuinfo", 5, value)) {
3135 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
3137 #if KMP_GROUP_AFFINITY
3138 else if (__kmp_str_match(
"group", 1, value)) {
3139 KMP_WARNING(StgDeprecatedValue, name, value,
"all");
3140 __kmp_affinity_top_method = affinity_top_method_group;
3143 else if (__kmp_str_match(
"flat", 1, value)) {
3144 __kmp_affinity_top_method = affinity_top_method_flat;
3146 KMP_WARNING(StgInvalidValue, name, value);
3150 static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
3151 char const *name,
void *data) {
3152 char const *value = NULL;
3154 switch (__kmp_affinity_top_method) {
3155 case affinity_top_method_default:
3159 case affinity_top_method_all:
3163 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3164 case affinity_top_method_x2apicid_1f:
3165 value =
"x2APIC id leaf 0x1f";
3168 case affinity_top_method_x2apicid:
3169 value =
"x2APIC id leaf 0xb";
3172 case affinity_top_method_apicid:
3178 case affinity_top_method_hwloc:
3183 case affinity_top_method_cpuinfo:
3187 #if KMP_GROUP_AFFINITY
3188 case affinity_top_method_group:
3193 case affinity_top_method_flat:
3198 if (value != NULL) {
3199 __kmp_stg_print_str(buffer, name, value);
3204 struct kmp_proc_bind_info_t {
3206 kmp_proc_bind_t proc_bind;
3208 static kmp_proc_bind_info_t proc_bind_table[] = {
3209 {
"spread", proc_bind_spread},
3210 {
"true", proc_bind_spread},
3211 {
"close", proc_bind_close},
3213 {
"false", proc_bind_primary},
3214 {
"primary", proc_bind_primary}};
3215 static void __kmp_stg_parse_teams_proc_bind(
char const *name,
char const *value,
3220 for (
size_t i = 0; i <
sizeof(proc_bind_table) /
sizeof(proc_bind_table[0]);
3222 if (__kmp_match_str(proc_bind_table[i].name, value, &end)) {
3223 __kmp_teams_proc_bind = proc_bind_table[i].proc_bind;
3229 KMP_WARNING(StgInvalidValue, name, value);
3232 static void __kmp_stg_print_teams_proc_bind(kmp_str_buf_t *buffer,
3233 char const *name,
void *data) {
3234 const char *value = KMP_I18N_STR(NotDefined);
3235 for (
size_t i = 0; i <
sizeof(proc_bind_table) /
sizeof(proc_bind_table[0]);
3237 if (__kmp_teams_proc_bind == proc_bind_table[i].proc_bind) {
3238 value = proc_bind_table[i].name;
3242 __kmp_stg_print_str(buffer, name, value);
3248 static void __kmp_stg_parse_proc_bind(
char const *name,
char const *value,
3250 kmp_setting_t **rivals = (kmp_setting_t **)data;
3253 rc = __kmp_stg_check_rivals(name, value, rivals);
3259 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
3260 (__kmp_nested_proc_bind.used > 0));
3262 const char *buf = value;
3266 if ((*buf >=
'0') && (*buf <=
'9')) {
3269 num = __kmp_str_to_int(buf, *next);
3270 KMP_ASSERT(num >= 0);
3278 if (__kmp_match_str(
"disabled", buf, &next)) {
3281 #if KMP_AFFINITY_SUPPORTED
3282 __kmp_affinity_type = affinity_disabled;
3284 __kmp_nested_proc_bind.used = 1;
3285 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3286 }
else if ((num == (
int)proc_bind_false) ||
3287 __kmp_match_str(
"false", buf, &next)) {
3290 #if KMP_AFFINITY_SUPPORTED
3291 __kmp_affinity_type = affinity_none;
3293 __kmp_nested_proc_bind.used = 1;
3294 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3295 }
else if ((num == (
int)proc_bind_true) ||
3296 __kmp_match_str(
"true", buf, &next)) {
3299 __kmp_nested_proc_bind.used = 1;
3300 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3305 for (scan = buf; *scan !=
'\0'; scan++) {
3312 if (__kmp_nested_proc_bind.size < nelem) {
3313 __kmp_nested_proc_bind.bind_types =
3314 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3315 __kmp_nested_proc_bind.bind_types,
3316 sizeof(kmp_proc_bind_t) * nelem);
3317 if (__kmp_nested_proc_bind.bind_types == NULL) {
3318 KMP_FATAL(MemoryAllocFailed);
3320 __kmp_nested_proc_bind.size = nelem;
3322 __kmp_nested_proc_bind.used = nelem;
3324 if (nelem > 1 && !__kmp_dflt_max_active_levels_set)
3325 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
3330 enum kmp_proc_bind_t bind;
3332 if ((num == (
int)proc_bind_primary) ||
3333 __kmp_match_str(
"master", buf, &next) ||
3334 __kmp_match_str(
"primary", buf, &next)) {
3337 bind = proc_bind_primary;
3338 }
else if ((num == (
int)proc_bind_close) ||
3339 __kmp_match_str(
"close", buf, &next)) {
3342 bind = proc_bind_close;
3343 }
else if ((num == (
int)proc_bind_spread) ||
3344 __kmp_match_str(
"spread", buf, &next)) {
3347 bind = proc_bind_spread;
3349 KMP_WARNING(StgInvalidValue, name, value);
3350 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3351 __kmp_nested_proc_bind.used = 1;
3355 __kmp_nested_proc_bind.bind_types[i++] = bind;
3359 KMP_DEBUG_ASSERT(*buf ==
',');
3364 if ((*buf >=
'0') && (*buf <=
'9')) {
3367 num = __kmp_str_to_int(buf, *next);
3368 KMP_ASSERT(num >= 0);
3378 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3382 static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer,
char const *name,
3384 int nelem = __kmp_nested_proc_bind.used;
3385 if (__kmp_env_format) {
3386 KMP_STR_BUF_PRINT_NAME;
3388 __kmp_str_buf_print(buffer,
" %s", name);
3391 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3394 __kmp_str_buf_print(buffer,
"='", name);
3395 for (i = 0; i < nelem; i++) {
3396 switch (__kmp_nested_proc_bind.bind_types[i]) {
3397 case proc_bind_false:
3398 __kmp_str_buf_print(buffer,
"false");
3401 case proc_bind_true:
3402 __kmp_str_buf_print(buffer,
"true");
3405 case proc_bind_primary:
3406 __kmp_str_buf_print(buffer,
"primary");
3409 case proc_bind_close:
3410 __kmp_str_buf_print(buffer,
"close");
3413 case proc_bind_spread:
3414 __kmp_str_buf_print(buffer,
"spread");
3417 case proc_bind_intel:
3418 __kmp_str_buf_print(buffer,
"intel");
3421 case proc_bind_default:
3422 __kmp_str_buf_print(buffer,
"default");
3425 if (i < nelem - 1) {
3426 __kmp_str_buf_print(buffer,
",");
3429 __kmp_str_buf_print(buffer,
"'\n");
3433 static void __kmp_stg_parse_display_affinity(
char const *name,
3434 char const *value,
void *data) {
3435 __kmp_stg_parse_bool(name, value, &__kmp_display_affinity);
3437 static void __kmp_stg_print_display_affinity(kmp_str_buf_t *buffer,
3438 char const *name,
void *data) {
3439 __kmp_stg_print_bool(buffer, name, __kmp_display_affinity);
3441 static void __kmp_stg_parse_affinity_format(
char const *name,
char const *value,
3443 size_t length = KMP_STRLEN(value);
3444 __kmp_strncpy_truncate(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, value,
3447 static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer,
3448 char const *name,
void *data) {
3449 if (__kmp_env_format) {
3450 KMP_STR_BUF_PRINT_NAME_EX(name);
3452 __kmp_str_buf_print(buffer,
" %s='", name);
3454 __kmp_str_buf_print(buffer,
"%s'\n", __kmp_affinity_format);
3476 static void __kmp_stg_parse_allocator(
char const *name,
char const *value,
3478 const char *buf = value;
3479 const char *next, *scan, *start;
3481 omp_allocator_handle_t al;
3482 omp_memspace_handle_t ms = omp_default_mem_space;
3483 bool is_memspace =
false;
3484 int ntraits = 0, count = 0;
3488 const char *delim = strchr(buf,
':');
3489 const char *predef_mem_space = strstr(buf,
"mem_space");
3491 bool is_memalloc = (!predef_mem_space && !delim) ?
true :
false;
3496 for (scan = buf; *scan !=
'\0'; scan++) {
3501 omp_alloctrait_t *traits =
3502 (omp_alloctrait_t *)KMP_ALLOCA(ntraits *
sizeof(omp_alloctrait_t));
3505 #define IS_POWER_OF_TWO(n) (((n) & ((n)-1)) == 0)
3507 #define GET_NEXT(sentinel) \
3510 if (*next == sentinel) \
3516 #define SKIP_PAIR(key) \
3518 char const str_delimiter[] = {',', 0}; \
3519 char *value = __kmp_str_token(CCAST(char *, scan), str_delimiter, \
3520 CCAST(char **, &next)); \
3521 KMP_WARNING(StgInvalidValue, key, value); \
3529 char const str_delimiter[] = {'=', 0}; \
3530 key = __kmp_str_token(CCAST(char *, start), str_delimiter, \
3531 CCAST(char **, &next)); \
3536 while (*next !=
'\0') {
3538 __kmp_match_str(
"fb_data", scan, &next)) {
3542 if (__kmp_match_str(
"omp_high_bw_mem_alloc", scan, &next)) {
3545 if (__kmp_memkind_available) {
3546 __kmp_def_allocator = omp_high_bw_mem_alloc;
3549 KMP_WARNING(OmpNoAllocator,
"omp_high_bw_mem_alloc");
3552 traits[count].key = omp_atk_fb_data;
3553 traits[count].value = RCAST(omp_uintptr_t, omp_high_bw_mem_alloc);
3555 }
else if (__kmp_match_str(
"omp_large_cap_mem_alloc", scan, &next)) {
3558 if (__kmp_memkind_available) {
3559 __kmp_def_allocator = omp_large_cap_mem_alloc;
3562 KMP_WARNING(OmpNoAllocator,
"omp_large_cap_mem_alloc");
3565 traits[count].key = omp_atk_fb_data;
3566 traits[count].value = RCAST(omp_uintptr_t, omp_large_cap_mem_alloc);
3568 }
else if (__kmp_match_str(
"omp_default_mem_alloc", scan, &next)) {
3572 traits[count].key = omp_atk_fb_data;
3573 traits[count].value = RCAST(omp_uintptr_t, omp_default_mem_alloc);
3575 }
else if (__kmp_match_str(
"omp_const_mem_alloc", scan, &next)) {
3578 KMP_WARNING(OmpNoAllocator,
"omp_const_mem_alloc");
3580 traits[count].key = omp_atk_fb_data;
3581 traits[count].value = RCAST(omp_uintptr_t, omp_const_mem_alloc);
3583 }
else if (__kmp_match_str(
"omp_low_lat_mem_alloc", scan, &next)) {
3586 KMP_WARNING(OmpNoAllocator,
"omp_low_lat_mem_alloc");
3588 traits[count].key = omp_atk_fb_data;
3589 traits[count].value = RCAST(omp_uintptr_t, omp_low_lat_mem_alloc);
3591 }
else if (__kmp_match_str(
"omp_cgroup_mem_alloc", scan, &next)) {
3594 KMP_WARNING(OmpNoAllocator,
"omp_cgroup_mem_alloc");
3596 traits[count].key = omp_atk_fb_data;
3597 traits[count].value = RCAST(omp_uintptr_t, omp_cgroup_mem_alloc);
3599 }
else if (__kmp_match_str(
"omp_pteam_mem_alloc", scan, &next)) {
3602 KMP_WARNING(OmpNoAllocator,
"omp_pteam_mem_alloc");
3604 traits[count].key = omp_atk_fb_data;
3605 traits[count].value = RCAST(omp_uintptr_t, omp_pteam_mem_alloc);
3607 }
else if (__kmp_match_str(
"omp_thread_mem_alloc", scan, &next)) {
3610 KMP_WARNING(OmpNoAllocator,
"omp_thread_mem_alloc");
3612 traits[count].key = omp_atk_fb_data;
3613 traits[count].value = RCAST(omp_uintptr_t, omp_thread_mem_alloc);
3623 __kmp_def_allocator = omp_default_mem_alloc;
3624 if (next == buf || *next !=
'\0') {
3626 KMP_WARNING(StgInvalidValue, name, value);
3631 if (count == ntraits)
3637 if (__kmp_match_str(
"omp_default_mem_space", scan, &next)) {
3639 ms = omp_default_mem_space;
3640 }
else if (__kmp_match_str(
"omp_large_cap_mem_space", scan, &next)) {
3642 ms = omp_large_cap_mem_space;
3643 }
else if (__kmp_match_str(
"omp_const_mem_space", scan, &next)) {
3645 ms = omp_const_mem_space;
3646 }
else if (__kmp_match_str(
"omp_high_bw_mem_space", scan, &next)) {
3648 ms = omp_high_bw_mem_space;
3649 }
else if (__kmp_match_str(
"omp_low_lat_mem_space", scan, &next)) {
3651 ms = omp_low_lat_mem_space;
3653 __kmp_def_allocator = omp_default_mem_alloc;
3654 if (next == buf || *next !=
'\0') {
3656 KMP_WARNING(StgInvalidValue, name, value);
3665 if (__kmp_match_str(
"sync_hint", scan, &next)) {
3667 traits[count].key = omp_atk_sync_hint;
3668 if (__kmp_match_str(
"contended", scan, &next)) {
3669 traits[count].value = omp_atv_contended;
3670 }
else if (__kmp_match_str(
"uncontended", scan, &next)) {
3671 traits[count].value = omp_atv_uncontended;
3672 }
else if (__kmp_match_str(
"serialized", scan, &next)) {
3673 traits[count].value = omp_atv_serialized;
3674 }
else if (__kmp_match_str(
"private", scan, &next)) {
3675 traits[count].value = omp_atv_private;
3681 }
else if (__kmp_match_str(
"alignment", scan, &next)) {
3683 if (!isdigit(*next)) {
3689 int n = __kmp_str_to_int(scan,
',');
3690 if (n < 0 || !IS_POWER_OF_TWO(n)) {
3695 traits[count].key = omp_atk_alignment;
3696 traits[count].value = n;
3697 }
else if (__kmp_match_str(
"access", scan, &next)) {
3699 traits[count].key = omp_atk_access;
3700 if (__kmp_match_str(
"all", scan, &next)) {
3701 traits[count].value = omp_atv_all;
3702 }
else if (__kmp_match_str(
"cgroup", scan, &next)) {
3703 traits[count].value = omp_atv_cgroup;
3704 }
else if (__kmp_match_str(
"pteam", scan, &next)) {
3705 traits[count].value = omp_atv_pteam;
3706 }
else if (__kmp_match_str(
"thread", scan, &next)) {
3707 traits[count].value = omp_atv_thread;
3713 }
else if (__kmp_match_str(
"pool_size", scan, &next)) {
3715 if (!isdigit(*next)) {
3721 int n = __kmp_str_to_int(scan,
',');
3727 traits[count].key = omp_atk_pool_size;
3728 traits[count].value = n;
3729 }
else if (__kmp_match_str(
"fallback", scan, &next)) {
3731 traits[count].key = omp_atk_fallback;
3732 if (__kmp_match_str(
"default_mem_fb", scan, &next)) {
3733 traits[count].value = omp_atv_default_mem_fb;
3734 }
else if (__kmp_match_str(
"null_fb", scan, &next)) {
3735 traits[count].value = omp_atv_null_fb;
3736 }
else if (__kmp_match_str(
"abort_fb", scan, &next)) {
3737 traits[count].value = omp_atv_abort_fb;
3738 }
else if (__kmp_match_str(
"allocator_fb", scan, &next)) {
3739 traits[count].value = omp_atv_allocator_fb;
3745 }
else if (__kmp_match_str(
"pinned", scan, &next)) {
3747 traits[count].key = omp_atk_pinned;
3748 if (__kmp_str_match_true(next)) {
3749 traits[count].value = omp_atv_true;
3750 }
else if (__kmp_str_match_false(next)) {
3751 traits[count].value = omp_atv_false;
3757 }
else if (__kmp_match_str(
"partition", scan, &next)) {
3759 traits[count].key = omp_atk_partition;
3760 if (__kmp_match_str(
"environment", scan, &next)) {
3761 traits[count].value = omp_atv_environment;
3762 }
else if (__kmp_match_str(
"nearest", scan, &next)) {
3763 traits[count].value = omp_atv_nearest;
3764 }
else if (__kmp_match_str(
"blocked", scan, &next)) {
3765 traits[count].value = omp_atv_blocked;
3766 }
else if (__kmp_match_str(
"interleaved", scan, &next)) {
3767 traits[count].value = omp_atv_interleaved;
3780 if (count == ntraits)
3786 al = __kmpc_init_allocator(__kmp_get_gtid(), ms, ntraits, traits);
3787 __kmp_def_allocator = (al == omp_null_allocator) ? omp_default_mem_alloc : al;
3790 static void __kmp_stg_print_allocator(kmp_str_buf_t *buffer,
char const *name,
3792 if (__kmp_def_allocator == omp_default_mem_alloc) {
3793 __kmp_stg_print_str(buffer, name,
"omp_default_mem_alloc");
3794 }
else if (__kmp_def_allocator == omp_high_bw_mem_alloc) {
3795 __kmp_stg_print_str(buffer, name,
"omp_high_bw_mem_alloc");
3796 }
else if (__kmp_def_allocator == omp_large_cap_mem_alloc) {
3797 __kmp_stg_print_str(buffer, name,
"omp_large_cap_mem_alloc");
3798 }
else if (__kmp_def_allocator == omp_const_mem_alloc) {
3799 __kmp_stg_print_str(buffer, name,
"omp_const_mem_alloc");
3800 }
else if (__kmp_def_allocator == omp_low_lat_mem_alloc) {
3801 __kmp_stg_print_str(buffer, name,
"omp_low_lat_mem_alloc");
3802 }
else if (__kmp_def_allocator == omp_cgroup_mem_alloc) {
3803 __kmp_stg_print_str(buffer, name,
"omp_cgroup_mem_alloc");
3804 }
else if (__kmp_def_allocator == omp_pteam_mem_alloc) {
3805 __kmp_stg_print_str(buffer, name,
"omp_pteam_mem_alloc");
3806 }
else if (__kmp_def_allocator == omp_thread_mem_alloc) {
3807 __kmp_stg_print_str(buffer, name,
"omp_thread_mem_alloc");
3814 static void __kmp_stg_parse_omp_dynamic(
char const *name,
char const *value,
3816 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
3819 static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer,
char const *name,
3821 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
3824 static void __kmp_stg_parse_kmp_dynamic_mode(
char const *name,
3825 char const *value,
void *data) {
3826 if (TCR_4(__kmp_init_parallel)) {
3827 KMP_WARNING(EnvParallelWarn, name);
3828 __kmp_env_toPrint(name, 0);
3831 #ifdef USE_LOAD_BALANCE
3832 else if (__kmp_str_match(
"load balance", 2, value) ||
3833 __kmp_str_match(
"load_balance", 2, value) ||
3834 __kmp_str_match(
"load-balance", 2, value) ||
3835 __kmp_str_match(
"loadbalance", 2, value) ||
3836 __kmp_str_match(
"balance", 1, value)) {
3837 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3840 else if (__kmp_str_match(
"thread limit", 1, value) ||
3841 __kmp_str_match(
"thread_limit", 1, value) ||
3842 __kmp_str_match(
"thread-limit", 1, value) ||
3843 __kmp_str_match(
"threadlimit", 1, value) ||
3844 __kmp_str_match(
"limit", 2, value)) {
3845 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3846 }
else if (__kmp_str_match(
"random", 1, value)) {
3847 __kmp_global.g.g_dynamic_mode = dynamic_random;
3849 KMP_WARNING(StgInvalidValue, name, value);
3853 static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
3854 char const *name,
void *data) {
3856 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
3857 __kmp_str_buf_print(buffer,
" %s: %s \n", name, KMP_I18N_STR(NotDefined));
3859 #ifdef USE_LOAD_BALANCE
3860 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
3861 __kmp_stg_print_str(buffer, name,
"load balance");
3864 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
3865 __kmp_stg_print_str(buffer, name,
"thread limit");
3866 }
else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
3867 __kmp_stg_print_str(buffer, name,
"random");
3874 #ifdef USE_LOAD_BALANCE
3879 static void __kmp_stg_parse_ld_balance_interval(
char const *name,
3880 char const *value,
void *data) {
3881 double interval = __kmp_convert_to_double(value);
3882 if (interval >= 0) {
3883 __kmp_load_balance_interval = interval;
3885 KMP_WARNING(StgInvalidValue, name, value);
3889 static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
3890 char const *name,
void *data) {
3892 __kmp_str_buf_print(buffer,
" %s=%8.6f\n", name,
3893 __kmp_load_balance_interval);
3902 static void __kmp_stg_parse_init_at_fork(
char const *name,
char const *value,
3904 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
3905 if (__kmp_need_register_atfork) {
3906 __kmp_need_register_atfork_specified = TRUE;
3910 static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
3911 char const *name,
void *data) {
3912 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
3918 static void __kmp_stg_parse_schedule(
char const *name,
char const *value,
3921 if (value != NULL) {
3922 size_t length = KMP_STRLEN(value);
3923 if (length > INT_MAX) {
3924 KMP_WARNING(LongValue, name);
3926 const char *semicolon;
3927 if (value[length - 1] ==
'"' || value[length - 1] ==
'\'')
3928 KMP_WARNING(UnbalancedQuotes, name);
3932 semicolon = strchr(value,
';');
3933 if (*value && semicolon != value) {
3934 const char *comma = strchr(value,
',');
3941 if (!__kmp_strcasecmp_with_sentinel(
"static", value, sentinel)) {
3942 if (!__kmp_strcasecmp_with_sentinel(
"greedy", comma,
';')) {
3943 __kmp_static = kmp_sch_static_greedy;
3945 }
else if (!__kmp_strcasecmp_with_sentinel(
"balanced", comma,
3947 __kmp_static = kmp_sch_static_balanced;
3950 }
else if (!__kmp_strcasecmp_with_sentinel(
"guided", value,
3952 if (!__kmp_strcasecmp_with_sentinel(
"iterative", comma,
';')) {
3953 __kmp_guided = kmp_sch_guided_iterative_chunked;
3955 }
else if (!__kmp_strcasecmp_with_sentinel(
"analytical", comma,
3958 __kmp_guided = kmp_sch_guided_analytical_chunked;
3962 KMP_WARNING(InvalidClause, name, value);
3964 KMP_WARNING(EmptyClause, name);
3965 }
while ((value = semicolon ? semicolon + 1 : NULL));
3971 static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer,
char const *name,
3973 if (__kmp_env_format) {
3974 KMP_STR_BUF_PRINT_NAME_EX(name);
3976 __kmp_str_buf_print(buffer,
" %s='", name);
3978 if (__kmp_static == kmp_sch_static_greedy) {
3979 __kmp_str_buf_print(buffer,
"%s",
"static,greedy");
3980 }
else if (__kmp_static == kmp_sch_static_balanced) {
3981 __kmp_str_buf_print(buffer,
"%s",
"static,balanced");
3983 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
3984 __kmp_str_buf_print(buffer,
";%s'\n",
"guided,iterative");
3985 }
else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
3986 __kmp_str_buf_print(buffer,
";%s'\n",
"guided,analytical");
3993 static inline void __kmp_omp_schedule_restore() {
3994 #if KMP_USE_HIER_SCHED
3995 __kmp_hier_scheds.deallocate();
4005 static const char *__kmp_parse_single_omp_schedule(
const char *name,
4007 bool parse_hier =
false) {
4009 const char *ptr = value;
4016 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4018 #if KMP_USE_HIER_SCHED
4019 kmp_hier_layer_e layer = kmp_hier_layer_e::LAYER_THREAD;
4021 if (*delim ==
',') {
4022 if (!__kmp_strcasecmp_with_sentinel(
"L1", ptr,
',')) {
4023 layer = kmp_hier_layer_e::LAYER_L1;
4024 }
else if (!__kmp_strcasecmp_with_sentinel(
"L2", ptr,
',')) {
4025 layer = kmp_hier_layer_e::LAYER_L2;
4026 }
else if (!__kmp_strcasecmp_with_sentinel(
"L3", ptr,
',')) {
4027 layer = kmp_hier_layer_e::LAYER_L3;
4028 }
else if (!__kmp_strcasecmp_with_sentinel(
"NUMA", ptr,
',')) {
4029 layer = kmp_hier_layer_e::LAYER_NUMA;
4032 if (layer != kmp_hier_layer_e::LAYER_THREAD && *delim !=
',') {
4034 KMP_WARNING(StgInvalidValue, name, value);
4035 __kmp_omp_schedule_restore();
4037 }
else if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4039 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4046 if (*delim ==
':') {
4047 if (!__kmp_strcasecmp_with_sentinel(
"monotonic", ptr, *delim)) {
4050 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4052 }
else if (!__kmp_strcasecmp_with_sentinel(
"nonmonotonic", ptr, *delim)) {
4055 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4057 }
else if (!parse_hier) {
4059 KMP_WARNING(StgInvalidValue, name, value);
4060 __kmp_omp_schedule_restore();
4065 if (!__kmp_strcasecmp_with_sentinel(
"dynamic", ptr, *delim))
4066 sched = kmp_sch_dynamic_chunked;
4067 else if (!__kmp_strcasecmp_with_sentinel(
"guided", ptr, *delim))
4070 else if (!__kmp_strcasecmp_with_sentinel(
"auto", ptr, *delim))
4072 else if (!__kmp_strcasecmp_with_sentinel(
"trapezoidal", ptr, *delim))
4073 sched = kmp_sch_trapezoidal;
4074 else if (!__kmp_strcasecmp_with_sentinel(
"static", ptr, *delim))
4076 #if KMP_STATIC_STEAL_ENABLED
4077 else if (!__kmp_strcasecmp_with_sentinel(
"static_steal", ptr, *delim)) {
4079 sched = kmp_sch_dynamic_chunked;
4085 KMP_WARNING(StgInvalidValue, name, value);
4086 __kmp_omp_schedule_restore();
4091 if (*delim ==
',') {
4094 if (!isdigit(*ptr)) {
4096 KMP_WARNING(StgInvalidValue, name, value);
4097 __kmp_omp_schedule_restore();
4103 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, delim),
4107 sched = kmp_sch_static_chunked;
4108 chunk = __kmp_str_to_int(delim + 1, *ptr);
4110 chunk = KMP_DEFAULT_CHUNK;
4111 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, delim),
4113 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
4122 }
else if (chunk > KMP_MAX_CHUNK) {
4123 chunk = KMP_MAX_CHUNK;
4124 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, delim),
4126 KMP_INFORM(Using_int_Value, name, chunk);
4133 SCHEDULE_SET_MODIFIERS(sched, sched_modifier);
4135 #if KMP_USE_HIER_SCHED
4136 if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4137 __kmp_hier_scheds.append(sched, chunk, layer);
4141 __kmp_chunk = chunk;
4142 __kmp_sched = sched;
4147 static void __kmp_stg_parse_omp_schedule(
char const *name,
char const *value,
4150 const char *ptr = value;
4153 length = KMP_STRLEN(value);
4155 if (value[length - 1] ==
'"' || value[length - 1] ==
'\'')
4156 KMP_WARNING(UnbalancedQuotes, name);
4158 #if KMP_USE_HIER_SCHED
4159 if (!__kmp_strcasecmp_with_sentinel(
"EXPERIMENTAL", ptr,
' ')) {
4162 while ((ptr = __kmp_parse_single_omp_schedule(name, ptr,
true))) {
4163 while (*ptr ==
' ' || *ptr ==
'\t' || *ptr ==
':')
4170 __kmp_parse_single_omp_schedule(name, ptr);
4172 KMP_WARNING(EmptyString, name);
4174 #if KMP_USE_HIER_SCHED
4175 __kmp_hier_scheds.sort();
4177 K_DIAG(1, (
"__kmp_static == %d\n", __kmp_static))
4178 K_DIAG(1, (
"__kmp_guided == %d\n", __kmp_guided))
4179 K_DIAG(1, (
"__kmp_sched == %d\n", __kmp_sched))
4180 K_DIAG(1, (
"__kmp_chunk == %d\n", __kmp_chunk))
4183 static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
4184 char const *name,
void *data) {
4185 if (__kmp_env_format) {
4186 KMP_STR_BUF_PRINT_NAME_EX(name);
4188 __kmp_str_buf_print(buffer,
" %s='", name);
4190 enum sched_type sched = SCHEDULE_WITHOUT_MODIFIERS(__kmp_sched);
4191 if (SCHEDULE_HAS_MONOTONIC(__kmp_sched)) {
4192 __kmp_str_buf_print(buffer,
"monotonic:");
4193 }
else if (SCHEDULE_HAS_NONMONOTONIC(__kmp_sched)) {
4194 __kmp_str_buf_print(buffer,
"nonmonotonic:");
4198 case kmp_sch_dynamic_chunked:
4199 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"dynamic", __kmp_chunk);
4201 case kmp_sch_guided_iterative_chunked:
4202 case kmp_sch_guided_analytical_chunked:
4203 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"guided", __kmp_chunk);
4205 case kmp_sch_trapezoidal:
4206 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"trapezoidal", __kmp_chunk);
4209 case kmp_sch_static_chunked:
4210 case kmp_sch_static_balanced:
4211 case kmp_sch_static_greedy:
4212 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"static", __kmp_chunk);
4214 case kmp_sch_static_steal:
4215 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"static_steal", __kmp_chunk);
4218 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"auto", __kmp_chunk);
4223 case kmp_sch_dynamic_chunked:
4224 __kmp_str_buf_print(buffer,
"%s'\n",
"dynamic");
4226 case kmp_sch_guided_iterative_chunked:
4227 case kmp_sch_guided_analytical_chunked:
4228 __kmp_str_buf_print(buffer,
"%s'\n",
"guided");
4230 case kmp_sch_trapezoidal:
4231 __kmp_str_buf_print(buffer,
"%s'\n",
"trapezoidal");
4234 case kmp_sch_static_chunked:
4235 case kmp_sch_static_balanced:
4236 case kmp_sch_static_greedy:
4237 __kmp_str_buf_print(buffer,
"%s'\n",
"static");
4239 case kmp_sch_static_steal:
4240 __kmp_str_buf_print(buffer,
"%s'\n",
"static_steal");
4243 __kmp_str_buf_print(buffer,
"%s'\n",
"auto");
4249 #if KMP_USE_HIER_SCHED
4252 static void __kmp_stg_parse_kmp_hand_thread(
char const *name,
char const *value,
4254 __kmp_stg_parse_bool(name, value, &(__kmp_dispatch_hand_threading));
4257 static void __kmp_stg_print_kmp_hand_thread(kmp_str_buf_t *buffer,
4258 char const *name,
void *data) {
4259 __kmp_stg_print_bool(buffer, name, __kmp_dispatch_hand_threading);
4265 static void __kmp_stg_parse_kmp_force_monotonic(
char const *name,
4266 char const *value,
void *data) {
4267 __kmp_stg_parse_bool(name, value, &(__kmp_force_monotonic));
4270 static void __kmp_stg_print_kmp_force_monotonic(kmp_str_buf_t *buffer,
4271 char const *name,
void *data) {
4272 __kmp_stg_print_bool(buffer, name, __kmp_force_monotonic);
4278 static void __kmp_stg_parse_atomic_mode(
char const *name,
char const *value,
4284 #ifdef KMP_GOMP_COMPAT
4287 __kmp_stg_parse_int(name, value, 0, max, &mode);
4292 __kmp_atomic_mode = mode;
4296 static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer,
char const *name,
4298 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
4304 static void __kmp_stg_parse_consistency_check(
char const *name,
4305 char const *value,
void *data) {
4306 if (!__kmp_strcasecmp_with_sentinel(
"all", value, 0)) {
4312 __kmp_env_consistency_check = TRUE;
4313 }
else if (!__kmp_strcasecmp_with_sentinel(
"none", value, 0)) {
4314 __kmp_env_consistency_check = FALSE;
4316 KMP_WARNING(StgInvalidValue, name, value);
4320 static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
4321 char const *name,
void *data) {
4323 const char *value = NULL;
4325 if (__kmp_env_consistency_check) {
4331 if (value != NULL) {
4332 __kmp_stg_print_str(buffer, name, value);
4343 static void __kmp_stg_parse_itt_prepare_delay(
char const *name,
4344 char const *value,
void *data) {
4348 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
4349 __kmp_itt_prepare_delay = delay;
4352 static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
4353 char const *name,
void *data) {
4354 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
4364 static void __kmp_stg_parse_malloc_pool_incr(
char const *name,
4365 char const *value,
void *data) {
4366 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
4367 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
4371 static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
4372 char const *name,
void *data) {
4373 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
4382 static void __kmp_stg_parse_par_range_env(
char const *name,
char const *value,
4384 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
4385 __kmp_par_range_routine, __kmp_par_range_filename,
4386 &__kmp_par_range_lb, &__kmp_par_range_ub);
4389 static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
4390 char const *name,
void *data) {
4391 if (__kmp_par_range != 0) {
4392 __kmp_stg_print_str(buffer, name, par_range_to_print);
4401 static void __kmp_stg_parse_gtid_mode(
char const *name,
char const *value,
4411 #ifdef KMP_TDATA_GTID
4414 __kmp_stg_parse_int(name, value, 0, max, &mode);
4418 __kmp_adjust_gtid_mode = TRUE;
4420 __kmp_gtid_mode = mode;
4421 __kmp_adjust_gtid_mode = FALSE;
4425 static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer,
char const *name,
4427 if (__kmp_adjust_gtid_mode) {
4428 __kmp_stg_print_int(buffer, name, 0);
4430 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
4437 static void __kmp_stg_parse_lock_block(
char const *name,
char const *value,
4439 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
4442 static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer,
char const *name,
4444 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
4450 #if KMP_USE_DYNAMIC_LOCK
4451 #define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
4453 #define KMP_STORE_LOCK_SEQ(a)
4456 static void __kmp_stg_parse_lock_kind(
char const *name,
char const *value,
4458 if (__kmp_init_user_locks) {
4459 KMP_WARNING(EnvLockWarn, name);
4463 if (__kmp_str_match(
"tas", 2, value) ||
4464 __kmp_str_match(
"test and set", 2, value) ||
4465 __kmp_str_match(
"test_and_set", 2, value) ||
4466 __kmp_str_match(
"test-and-set", 2, value) ||
4467 __kmp_str_match(
"test andset", 2, value) ||
4468 __kmp_str_match(
"test_andset", 2, value) ||
4469 __kmp_str_match(
"test-andset", 2, value) ||
4470 __kmp_str_match(
"testand set", 2, value) ||
4471 __kmp_str_match(
"testand_set", 2, value) ||
4472 __kmp_str_match(
"testand-set", 2, value) ||
4473 __kmp_str_match(
"testandset", 2, value)) {
4474 __kmp_user_lock_kind = lk_tas;
4475 KMP_STORE_LOCK_SEQ(tas);
4478 else if (__kmp_str_match(
"futex", 1, value)) {
4479 if (__kmp_futex_determine_capable()) {
4480 __kmp_user_lock_kind = lk_futex;
4481 KMP_STORE_LOCK_SEQ(futex);
4483 KMP_WARNING(FutexNotSupported, name, value);
4487 else if (__kmp_str_match(
"ticket", 2, value)) {
4488 __kmp_user_lock_kind = lk_ticket;
4489 KMP_STORE_LOCK_SEQ(ticket);
4490 }
else if (__kmp_str_match(
"queuing", 1, value) ||
4491 __kmp_str_match(
"queue", 1, value)) {
4492 __kmp_user_lock_kind = lk_queuing;
4493 KMP_STORE_LOCK_SEQ(queuing);
4494 }
else if (__kmp_str_match(
"drdpa ticket", 1, value) ||
4495 __kmp_str_match(
"drdpa_ticket", 1, value) ||
4496 __kmp_str_match(
"drdpa-ticket", 1, value) ||
4497 __kmp_str_match(
"drdpaticket", 1, value) ||
4498 __kmp_str_match(
"drdpa", 1, value)) {
4499 __kmp_user_lock_kind = lk_drdpa;
4500 KMP_STORE_LOCK_SEQ(drdpa);
4502 #if KMP_USE_ADAPTIVE_LOCKS
4503 else if (__kmp_str_match(
"adaptive", 1, value)) {
4504 if (__kmp_cpuinfo.flags.rtm) {
4505 __kmp_user_lock_kind = lk_adaptive;
4506 KMP_STORE_LOCK_SEQ(adaptive);
4508 KMP_WARNING(AdaptiveNotSupported, name, value);
4509 __kmp_user_lock_kind = lk_queuing;
4510 KMP_STORE_LOCK_SEQ(queuing);
4514 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4515 else if (__kmp_str_match(
"rtm_queuing", 1, value)) {
4516 if (__kmp_cpuinfo.flags.rtm) {
4517 __kmp_user_lock_kind = lk_rtm_queuing;
4518 KMP_STORE_LOCK_SEQ(rtm_queuing);
4520 KMP_WARNING(AdaptiveNotSupported, name, value);
4521 __kmp_user_lock_kind = lk_queuing;
4522 KMP_STORE_LOCK_SEQ(queuing);
4524 }
else if (__kmp_str_match(
"rtm_spin", 1, value)) {
4525 if (__kmp_cpuinfo.flags.rtm) {
4526 __kmp_user_lock_kind = lk_rtm_spin;
4527 KMP_STORE_LOCK_SEQ(rtm_spin);
4529 KMP_WARNING(AdaptiveNotSupported, name, value);
4530 __kmp_user_lock_kind = lk_tas;
4531 KMP_STORE_LOCK_SEQ(queuing);
4533 }
else if (__kmp_str_match(
"hle", 1, value)) {
4534 __kmp_user_lock_kind = lk_hle;
4535 KMP_STORE_LOCK_SEQ(hle);
4539 KMP_WARNING(StgInvalidValue, name, value);
4543 static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer,
char const *name,
4545 const char *value = NULL;
4547 switch (__kmp_user_lock_kind) {
4562 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4563 case lk_rtm_queuing:
4564 value =
"rtm_queuing";
4587 #if KMP_USE_ADAPTIVE_LOCKS
4594 if (value != NULL) {
4595 __kmp_stg_print_str(buffer, name, value);
4604 static void __kmp_stg_parse_spin_backoff_params(
const char *name,
4605 const char *value,
void *data) {
4606 const char *next = value;
4609 int prev_comma = FALSE;
4612 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
4613 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
4617 for (i = 0; i < 3; i++) {
4620 if (*next ==
'\0') {
4625 if (((*next < '0' || *next >
'9') && *next !=
',') || total > 2) {
4626 KMP_WARNING(EnvSyntaxError, name, value);
4632 if (total == 0 || prev_comma) {
4640 if (*next >=
'0' && *next <=
'9') {
4642 const char *buf = next;
4643 char const *msg = NULL;
4648 const char *tmp = next;
4650 if ((*next ==
' ' || *next ==
'\t') && (*tmp >=
'0' && *tmp <=
'9')) {
4651 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4655 num = __kmp_str_to_int(buf, *next);
4657 msg = KMP_I18N_STR(ValueTooSmall);
4659 }
else if (num > KMP_INT_MAX) {
4660 msg = KMP_I18N_STR(ValueTooLarge);
4665 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4666 KMP_INFORM(Using_int_Value, name, num);
4670 }
else if (total == 2) {
4675 KMP_DEBUG_ASSERT(total > 0);
4677 KMP_WARNING(EnvSyntaxError, name, value);
4680 __kmp_spin_backoff_params.max_backoff = max_backoff;
4681 __kmp_spin_backoff_params.min_tick = min_tick;
4684 static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
4685 char const *name,
void *data) {
4686 if (__kmp_env_format) {
4687 KMP_STR_BUF_PRINT_NAME_EX(name);
4689 __kmp_str_buf_print(buffer,
" %s='", name);
4691 __kmp_str_buf_print(buffer,
"%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
4692 __kmp_spin_backoff_params.min_tick);
4695 #if KMP_USE_ADAPTIVE_LOCKS
4702 static void __kmp_stg_parse_adaptive_lock_props(
const char *name,
4703 const char *value,
void *data) {
4704 int max_retries = 0;
4705 int max_badness = 0;
4707 const char *next = value;
4710 int prev_comma = FALSE;
4716 for (i = 0; i < 3; i++) {
4719 if (*next ==
'\0') {
4724 if (((*next < '0' || *next >
'9') && *next !=
',') || total > 2) {
4725 KMP_WARNING(EnvSyntaxError, name, value);
4731 if (total == 0 || prev_comma) {
4739 if (*next >=
'0' && *next <=
'9') {
4741 const char *buf = next;
4742 char const *msg = NULL;
4747 const char *tmp = next;
4749 if ((*next ==
' ' || *next ==
'\t') && (*tmp >=
'0' && *tmp <=
'9')) {
4750 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4754 num = __kmp_str_to_int(buf, *next);
4756 msg = KMP_I18N_STR(ValueTooSmall);
4758 }
else if (num > KMP_INT_MAX) {
4759 msg = KMP_I18N_STR(ValueTooLarge);
4764 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4765 KMP_INFORM(Using_int_Value, name, num);
4769 }
else if (total == 2) {
4774 KMP_DEBUG_ASSERT(total > 0);
4776 KMP_WARNING(EnvSyntaxError, name, value);
4779 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4780 __kmp_adaptive_backoff_params.max_badness = max_badness;
4783 static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4784 char const *name,
void *data) {
4785 if (__kmp_env_format) {
4786 KMP_STR_BUF_PRINT_NAME_EX(name);
4788 __kmp_str_buf_print(buffer,
" %s='", name);
4790 __kmp_str_buf_print(buffer,
"%d,%d'\n",
4791 __kmp_adaptive_backoff_params.max_soft_retries,
4792 __kmp_adaptive_backoff_params.max_badness);
4795 #if KMP_DEBUG_ADAPTIVE_LOCKS
4797 static void __kmp_stg_parse_speculative_statsfile(
char const *name,
4800 __kmp_stg_parse_file(name, value,
"",
4801 CCAST(
char **, &__kmp_speculative_statsfile));
4804 static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
4807 if (__kmp_str_match(
"-", 0, __kmp_speculative_statsfile)) {
4808 __kmp_stg_print_str(buffer, name,
"stdout");
4810 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
4826 static kmp_hw_t __kmp_hw_subset_break_tie(
const kmp_hw_t *possible,
4827 size_t num_possible) {
4828 for (
size_t i = 0; i < num_possible; ++i) {
4829 if (possible[i] == KMP_HW_THREAD)
4830 return KMP_HW_THREAD;
4831 else if (possible[i] == KMP_HW_CORE)
4833 else if (possible[i] == KMP_HW_SOCKET)
4834 return KMP_HW_SOCKET;
4836 return KMP_HW_UNKNOWN;
4843 static kmp_hw_t __kmp_stg_parse_hw_subset_name(
char const *token) {
4844 size_t index, num_possible, token_length;
4845 kmp_hw_t possible[KMP_HW_LAST];
4851 while (isalnum(*end) || *end ==
'_') {
4858 KMP_FOREACH_HW_TYPE(type) { possible[num_possible++] = type; }
4865 while (num_possible > 1 && index < token_length) {
4866 size_t n = num_possible;
4867 char token_char = (char)toupper(token[index]);
4868 for (
size_t i = 0; i < n; ++i) {
4870 kmp_hw_t type = possible[i];
4871 s = __kmp_hw_get_keyword(type,
false);
4872 if (index < KMP_STRLEN(s)) {
4873 char c = (char)toupper(s[index]);
4875 if (c != token_char) {
4876 possible[i] = KMP_HW_UNKNOWN;
4883 for (
size_t i = 0; i < n; ++i) {
4884 if (possible[i] != KMP_HW_UNKNOWN) {
4885 kmp_hw_t temp = possible[i];
4886 possible[i] = possible[start];
4887 possible[start] = temp;
4891 KMP_ASSERT(start == num_possible);
4897 if (num_possible > 1)
4898 return __kmp_hw_subset_break_tie(possible, num_possible);
4899 if (num_possible == 1)
4901 return KMP_HW_UNKNOWN;
4906 #define MAX_T_LEVEL KMP_HW_LAST
4907 #define MAX_STR_LEN 512
4908 static void __kmp_stg_parse_hw_subset(
char const *name,
char const *value,
4912 kmp_setting_t **rivals = (kmp_setting_t **)data;
4913 if (strcmp(name,
"KMP_PLACE_THREADS") == 0) {
4914 KMP_INFORM(EnvVarDeprecated, name,
"KMP_HW_SUBSET");
4916 if (__kmp_stg_check_rivals(name, value, rivals)) {
4920 char *components[MAX_T_LEVEL];
4921 char const *digits =
"0123456789";
4922 char input[MAX_STR_LEN];
4923 size_t len = 0, mlen = MAX_STR_LEN;
4925 bool absolute =
false;
4927 char *pos = CCAST(
char *, value);
4928 while (*pos && mlen) {
4930 if (len == 0 && *pos ==
':') {
4933 input[len] = (char)(toupper(*pos));
4934 if (input[len] ==
'X')
4936 if (input[len] ==
'O' && strchr(digits, *(pos + 1)))
4944 if (len == 0 || mlen == 0) {
4950 components[level++] = pos;
4951 while ((pos = strchr(pos,
','))) {
4952 if (level >= MAX_T_LEVEL)
4955 components[level++] = ++pos;
4958 __kmp_hw_subset = kmp_hw_subset_t::allocate();
4960 __kmp_hw_subset->set_absolute();
4963 for (
int i = 0; i < level; ++i) {
4965 char *core_components[MAX_T_LEVEL];
4967 pos = components[i];
4968 core_components[core_level++] = pos;
4969 while ((pos = strchr(pos,
'&'))) {
4970 if (core_level >= MAX_T_LEVEL)
4973 core_components[core_level++] = ++pos;
4976 for (
int j = 0; j < core_level; ++j) {
4983 if (isdigit(*core_components[j])) {
4984 num = atoi(core_components[j]);
4988 pos = core_components[j] + strspn(core_components[j], digits);
4989 }
else if (*core_components[j] ==
'*') {
4990 num = kmp_hw_subset_t::USE_ALL;
4991 pos = core_components[j] + 1;
4993 num = kmp_hw_subset_t::USE_ALL;
4994 pos = core_components[j];
4997 offset_ptr = strchr(core_components[j],
'@');
4998 attr_ptr = strchr(core_components[j],
':');
5001 offset = atoi(offset_ptr + 1);
5007 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
5008 if (__kmp_str_match(
"intel_core", -1, attr_ptr + 1)) {
5009 attr.set_core_type(KMP_HW_CORE_TYPE_CORE);
5010 }
else if (__kmp_str_match(
"intel_atom", -1, attr_ptr + 1)) {
5011 attr.set_core_type(KMP_HW_CORE_TYPE_ATOM);
5014 if (__kmp_str_match(
"eff", 3, attr_ptr + 1)) {
5015 const char *number = attr_ptr + 1;
5017 while (isalpha(*number))
5019 if (!isdigit(*number)) {
5022 int efficiency = atoi(number);
5023 attr.set_core_eff(efficiency);
5030 kmp_hw_t type = __kmp_stg_parse_hw_subset_name(pos);
5031 if (type == KMP_HW_UNKNOWN) {
5035 if (attr && type != KMP_HW_CORE)
5038 if (type != KMP_HW_CORE && __kmp_hw_subset->specified(type)) {
5041 __kmp_hw_subset->push_back(num, type, offset, attr);
5046 KMP_WARNING(AffHWSubsetInvalid, name, value);
5047 if (__kmp_hw_subset) {
5048 kmp_hw_subset_t::deallocate(__kmp_hw_subset);
5049 __kmp_hw_subset =
nullptr;
5054 static inline const char *
5055 __kmp_hw_get_core_type_keyword(kmp_hw_core_type_t type) {
5057 case KMP_HW_CORE_TYPE_UNKNOWN:
5059 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
5060 case KMP_HW_CORE_TYPE_ATOM:
5061 return "intel_atom";
5062 case KMP_HW_CORE_TYPE_CORE:
5063 return "intel_core";
5069 static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer,
char const *name,
5073 if (!__kmp_hw_subset)
5075 __kmp_str_buf_init(&buf);
5076 if (__kmp_env_format)
5077 KMP_STR_BUF_PRINT_NAME_EX(name);
5079 __kmp_str_buf_print(buffer,
" %s='", name);
5081 depth = __kmp_hw_subset->get_depth();
5082 for (
int i = 0; i < depth; ++i) {
5083 const auto &item = __kmp_hw_subset->at(i);
5085 __kmp_str_buf_print(&buf,
"%c",
',');
5086 for (
int j = 0; j < item.num_attrs; ++j) {
5087 __kmp_str_buf_print(&buf,
"%s%d%s", (j > 0 ?
"&" :
""), item.num[j],
5088 __kmp_hw_get_keyword(item.type));
5089 if (item.attr[j].is_core_type_valid())
5090 __kmp_str_buf_print(
5092 __kmp_hw_get_core_type_keyword(item.attr[j].get_core_type()));
5093 if (item.attr[j].is_core_eff_valid())
5094 __kmp_str_buf_print(&buf,
":eff%d", item.attr[j].get_core_eff());
5096 __kmp_str_buf_print(&buf,
"@%d", item.offset[j]);
5099 __kmp_str_buf_print(buffer,
"%s'\n", buf.str);
5100 __kmp_str_buf_free(&buf);
5107 static void __kmp_stg_parse_forkjoin_frames(
char const *name,
char const *value,
5109 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
5112 static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
5113 char const *name,
void *data) {
5114 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
5120 static void __kmp_stg_parse_forkjoin_frames_mode(
char const *name,
5123 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
5126 static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
5127 char const *name,
void *data) {
5128 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
5135 static void __kmp_stg_parse_task_throttling(
char const *name,
char const *value,
5137 __kmp_stg_parse_bool(name, value, &__kmp_enable_task_throttling);
5140 static void __kmp_stg_print_task_throttling(kmp_str_buf_t *buffer,
5141 char const *name,
void *data) {
5142 __kmp_stg_print_bool(buffer, name, __kmp_enable_task_throttling);
5145 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5149 static void __kmp_stg_parse_user_level_mwait(
char const *name,
5150 char const *value,
void *data) {
5151 __kmp_stg_parse_bool(name, value, &__kmp_user_level_mwait);
5154 static void __kmp_stg_print_user_level_mwait(kmp_str_buf_t *buffer,
5155 char const *name,
void *data) {
5156 __kmp_stg_print_bool(buffer, name, __kmp_user_level_mwait);
5162 static void __kmp_stg_parse_mwait_hints(
char const *name,
char const *value,
5164 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_mwait_hints);
5167 static void __kmp_stg_print_mwait_hints(kmp_str_buf_t *buffer,
char const *name,
5169 __kmp_stg_print_int(buffer, name, __kmp_mwait_hints);
5179 static void __kmp_stg_parse_tpause(
char const *name,
char const *value,
5181 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_tpause_state);
5182 if (__kmp_tpause_state != 0) {
5184 if (__kmp_tpause_state == 2)
5185 __kmp_tpause_hint = 0;
5189 static void __kmp_stg_print_tpause(kmp_str_buf_t *buffer,
char const *name,
5191 __kmp_stg_print_int(buffer, name, __kmp_tpause_state);
5198 static void __kmp_stg_parse_omp_display_env(
char const *name,
char const *value,
5200 if (__kmp_str_match(
"VERBOSE", 1, value)) {
5201 __kmp_display_env_verbose = TRUE;
5203 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
5207 static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
5208 char const *name,
void *data) {
5209 if (__kmp_display_env_verbose) {
5210 __kmp_stg_print_str(buffer, name,
"VERBOSE");
5212 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
5216 static void __kmp_stg_parse_omp_cancellation(
char const *name,
5217 char const *value,
void *data) {
5218 if (TCR_4(__kmp_init_parallel)) {
5219 KMP_WARNING(EnvParallelWarn, name);
5222 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
5225 static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
5226 char const *name,
void *data) {
5227 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
5233 static void __kmp_stg_parse_omp_tool(
char const *name,
char const *value,
5235 __kmp_stg_parse_bool(name, value, &__kmp_tool);
5238 static void __kmp_stg_print_omp_tool(kmp_str_buf_t *buffer,
char const *name,
5240 if (__kmp_env_format) {
5241 KMP_STR_BUF_PRINT_BOOL_EX(name, __kmp_tool,
"enabled",
"disabled");
5243 __kmp_str_buf_print(buffer,
" %s=%s\n", name,
5244 __kmp_tool ?
"enabled" :
"disabled");
5248 char *__kmp_tool_libraries = NULL;
5250 static void __kmp_stg_parse_omp_tool_libraries(
char const *name,
5251 char const *value,
void *data) {
5252 __kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
5255 static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer,
5256 char const *name,
void *data) {
5257 if (__kmp_tool_libraries)
5258 __kmp_stg_print_str(buffer, name, __kmp_tool_libraries);
5260 if (__kmp_env_format) {
5261 KMP_STR_BUF_PRINT_NAME;
5263 __kmp_str_buf_print(buffer,
" %s", name);
5265 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
5269 char *__kmp_tool_verbose_init = NULL;
5271 static void __kmp_stg_parse_omp_tool_verbose_init(
char const *name,
5274 __kmp_stg_parse_str(name, value, &__kmp_tool_verbose_init);
5277 static void __kmp_stg_print_omp_tool_verbose_init(kmp_str_buf_t *buffer,
5280 if (__kmp_tool_verbose_init)
5281 __kmp_stg_print_str(buffer, name, __kmp_tool_verbose_init);
5283 if (__kmp_env_format) {
5284 KMP_STR_BUF_PRINT_NAME;
5286 __kmp_str_buf_print(buffer,
" %s", name);
5288 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
5296 static kmp_setting_t __kmp_stg_table[] = {
5298 {
"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
5299 {
"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
5301 {
"KMP_USE_YIELD", __kmp_stg_parse_use_yield, __kmp_stg_print_use_yield,
5303 {
"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
5304 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
5305 {
"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
5307 {
"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
5308 __kmp_stg_print_device_thread_limit, NULL, 0, 0},
5310 {
"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
5311 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
5313 {
"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
5315 {
"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
5316 __kmp_stg_print_stackoffset, NULL, 0, 0},
5317 {
"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5319 {
"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
5321 {
"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
5323 {
"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
5326 {
"KMP_NESTING_MODE", __kmp_stg_parse_nesting_mode,
5327 __kmp_stg_print_nesting_mode, NULL, 0, 0},
5328 {
"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
5329 {
"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
5330 __kmp_stg_print_num_threads, NULL, 0, 0},
5331 {
"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5334 {
"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
5336 {
"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
5337 __kmp_stg_print_task_stealing, NULL, 0, 0},
5338 {
"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
5339 __kmp_stg_print_max_active_levels, NULL, 0, 0},
5340 {
"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
5341 __kmp_stg_print_default_device, NULL, 0, 0},
5342 {
"OMP_TARGET_OFFLOAD", __kmp_stg_parse_target_offload,
5343 __kmp_stg_print_target_offload, NULL, 0, 0},
5344 {
"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
5345 __kmp_stg_print_max_task_priority, NULL, 0, 0},
5346 {
"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
5347 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
5348 {
"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
5349 __kmp_stg_print_thread_limit, NULL, 0, 0},
5350 {
"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
5351 __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
5352 {
"OMP_NUM_TEAMS", __kmp_stg_parse_nteams, __kmp_stg_print_nteams, NULL, 0,
5354 {
"OMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_th_limit,
5355 __kmp_stg_print_teams_th_limit, NULL, 0, 0},
5356 {
"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
5357 __kmp_stg_print_wait_policy, NULL, 0, 0},
5358 {
"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
5359 __kmp_stg_print_disp_buffers, NULL, 0, 0},
5360 #if KMP_NESTED_HOT_TEAMS
5361 {
"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
5362 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
5363 {
"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
5364 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
5367 #if KMP_HANDLE_SIGNALS
5368 {
"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
5369 __kmp_stg_print_handle_signals, NULL, 0, 0},
5372 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
5373 {
"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
5374 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
5377 #ifdef KMP_GOMP_COMPAT
5378 {
"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
5382 {
"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
5384 {
"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
5386 {
"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
5388 {
"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
5390 {
"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
5392 {
"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
5394 {
"KMP_DEBUG", __kmp_stg_parse_debug, NULL, NULL, 0, 0},
5395 {
"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
5397 {
"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
5398 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
5399 {
"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
5400 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
5401 {
"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
5402 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
5403 {
"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
5405 {
"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
5406 __kmp_stg_print_par_range_env, NULL, 0, 0},
5409 {
"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
5410 __kmp_stg_print_align_alloc, NULL, 0, 0},
5412 {
"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5413 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5414 {
"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5415 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5416 {
"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5417 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5418 {
"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5419 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5420 #if KMP_FAST_REDUCTION_BARRIER
5421 {
"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5422 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5423 {
"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5424 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5427 {
"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
5428 __kmp_stg_print_abort_delay, NULL, 0, 0},
5429 {
"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
5430 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
5431 {
"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
5432 __kmp_stg_print_force_reduction, NULL, 0, 0},
5433 {
"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
5434 __kmp_stg_print_force_reduction, NULL, 0, 0},
5435 {
"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
5436 __kmp_stg_print_storage_map, NULL, 0, 0},
5437 {
"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
5438 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
5439 {
"KMP_FOREIGN_THREADS_THREADPRIVATE",
5440 __kmp_stg_parse_foreign_threads_threadprivate,
5441 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
5443 #if KMP_AFFINITY_SUPPORTED
5444 {
"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
5446 #ifdef KMP_GOMP_COMPAT
5447 {
"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
5450 {
"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5452 {
"KMP_TEAMS_PROC_BIND", __kmp_stg_parse_teams_proc_bind,
5453 __kmp_stg_print_teams_proc_bind, NULL, 0, 0},
5454 {
"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
5455 {
"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
5456 __kmp_stg_print_topology_method, NULL, 0, 0},
5462 {
"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5466 {
"OMP_DISPLAY_AFFINITY", __kmp_stg_parse_display_affinity,
5467 __kmp_stg_print_display_affinity, NULL, 0, 0},
5468 {
"OMP_AFFINITY_FORMAT", __kmp_stg_parse_affinity_format,
5469 __kmp_stg_print_affinity_format, NULL, 0, 0},
5470 {
"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
5471 __kmp_stg_print_init_at_fork, NULL, 0, 0},
5472 {
"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
5474 {
"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
5476 #if KMP_USE_HIER_SCHED
5477 {
"KMP_DISP_HAND_THREAD", __kmp_stg_parse_kmp_hand_thread,
5478 __kmp_stg_print_kmp_hand_thread, NULL, 0, 0},
5480 {
"KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE",
5481 __kmp_stg_parse_kmp_force_monotonic, __kmp_stg_print_kmp_force_monotonic,
5483 {
"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
5484 __kmp_stg_print_atomic_mode, NULL, 0, 0},
5485 {
"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
5486 __kmp_stg_print_consistency_check, NULL, 0, 0},
5488 #if USE_ITT_BUILD && USE_ITT_NOTIFY
5489 {
"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
5490 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
5492 {
"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
5493 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
5494 {
"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
5496 {
"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
5498 {
"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
5499 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
5501 #ifdef USE_LOAD_BALANCE
5502 {
"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
5503 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
5506 {
"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
5507 __kmp_stg_print_lock_block, NULL, 0, 0},
5508 {
"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
5510 {
"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
5511 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
5512 #if KMP_USE_ADAPTIVE_LOCKS
5513 {
"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
5514 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
5515 #if KMP_DEBUG_ADAPTIVE_LOCKS
5516 {
"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
5517 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
5520 {
"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5522 {
"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5525 {
"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
5526 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
5527 {
"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
5528 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
5530 {
"KMP_ENABLE_TASK_THROTTLING", __kmp_stg_parse_task_throttling,
5531 __kmp_stg_print_task_throttling, NULL, 0, 0},
5533 {
"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
5534 __kmp_stg_print_omp_display_env, NULL, 0, 0},
5535 {
"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
5536 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
5537 {
"OMP_ALLOCATOR", __kmp_stg_parse_allocator, __kmp_stg_print_allocator,
5539 {
"LIBOMP_USE_HIDDEN_HELPER_TASK", __kmp_stg_parse_use_hidden_helper,
5540 __kmp_stg_print_use_hidden_helper, NULL, 0, 0},
5541 {
"LIBOMP_NUM_HIDDEN_HELPER_THREADS",
5542 __kmp_stg_parse_num_hidden_helper_threads,
5543 __kmp_stg_print_num_hidden_helper_threads, NULL, 0, 0},
5546 {
"OMP_TOOL", __kmp_stg_parse_omp_tool, __kmp_stg_print_omp_tool, NULL, 0,
5548 {
"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries,
5549 __kmp_stg_print_omp_tool_libraries, NULL, 0, 0},
5550 {
"OMP_TOOL_VERBOSE_INIT", __kmp_stg_parse_omp_tool_verbose_init,
5551 __kmp_stg_print_omp_tool_verbose_init, NULL, 0, 0},
5554 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5555 {
"KMP_USER_LEVEL_MWAIT", __kmp_stg_parse_user_level_mwait,
5556 __kmp_stg_print_user_level_mwait, NULL, 0, 0},
5557 {
"KMP_MWAIT_HINTS", __kmp_stg_parse_mwait_hints,
5558 __kmp_stg_print_mwait_hints, NULL, 0, 0},
5562 {
"KMP_TPAUSE", __kmp_stg_parse_tpause, __kmp_stg_print_tpause, NULL, 0, 0},
5564 {
"", NULL, NULL, NULL, 0, 0}};
5566 static int const __kmp_stg_count =
5567 sizeof(__kmp_stg_table) /
sizeof(kmp_setting_t);
5569 static inline kmp_setting_t *__kmp_stg_find(
char const *name) {
5573 for (i = 0; i < __kmp_stg_count; ++i) {
5574 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
5575 return &__kmp_stg_table[i];
5583 static int __kmp_stg_cmp(
void const *_a,
void const *_b) {
5584 const kmp_setting_t *a = RCAST(
const kmp_setting_t *, _a);
5585 const kmp_setting_t *b = RCAST(
const kmp_setting_t *, _b);
5589 if (strcmp(a->name,
"KMP_AFFINITY") == 0) {
5590 if (strcmp(b->name,
"KMP_AFFINITY") == 0) {
5594 }
else if (strcmp(b->name,
"KMP_AFFINITY") == 0) {
5597 return strcmp(a->name, b->name);
5600 static void __kmp_stg_init(
void) {
5602 static int initialized = 0;
5607 qsort(__kmp_stg_table, __kmp_stg_count - 1,
sizeof(kmp_setting_t),
5611 kmp_setting_t *kmp_stacksize =
5612 __kmp_stg_find(
"KMP_STACKSIZE");
5613 #ifdef KMP_GOMP_COMPAT
5614 kmp_setting_t *gomp_stacksize =
5615 __kmp_stg_find(
"GOMP_STACKSIZE");
5617 kmp_setting_t *omp_stacksize =
5618 __kmp_stg_find(
"OMP_STACKSIZE");
5624 static kmp_setting_t *
volatile rivals[4];
5625 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
5626 #ifdef KMP_GOMP_COMPAT
5627 static kmp_stg_ss_data_t gomp_data = {1024,
5628 CCAST(kmp_setting_t **, rivals)};
5630 static kmp_stg_ss_data_t omp_data = {1024,
5631 CCAST(kmp_setting_t **, rivals)};
5634 rivals[i++] = kmp_stacksize;
5635 #ifdef KMP_GOMP_COMPAT
5636 if (gomp_stacksize != NULL) {
5637 rivals[i++] = gomp_stacksize;
5640 rivals[i++] = omp_stacksize;
5643 kmp_stacksize->data = &kmp_data;
5644 #ifdef KMP_GOMP_COMPAT
5645 if (gomp_stacksize != NULL) {
5646 gomp_stacksize->data = &gomp_data;
5649 omp_stacksize->data = &omp_data;
5653 kmp_setting_t *kmp_library =
5654 __kmp_stg_find(
"KMP_LIBRARY");
5655 kmp_setting_t *omp_wait_policy =
5656 __kmp_stg_find(
"OMP_WAIT_POLICY");
5659 static kmp_setting_t *
volatile rivals[3];
5660 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
5661 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
5664 rivals[i++] = kmp_library;
5665 if (omp_wait_policy != NULL) {
5666 rivals[i++] = omp_wait_policy;
5670 kmp_library->data = &kmp_data;
5671 if (omp_wait_policy != NULL) {
5672 omp_wait_policy->data = &omp_data;
5677 kmp_setting_t *kmp_device_thread_limit =
5678 __kmp_stg_find(
"KMP_DEVICE_THREAD_LIMIT");
5679 kmp_setting_t *kmp_all_threads =
5680 __kmp_stg_find(
"KMP_ALL_THREADS");
5683 static kmp_setting_t *
volatile rivals[3];
5686 rivals[i++] = kmp_device_thread_limit;
5687 rivals[i++] = kmp_all_threads;
5690 kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
5691 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
5696 kmp_setting_t *kmp_hw_subset = __kmp_stg_find(
"KMP_HW_SUBSET");
5698 kmp_setting_t *kmp_place_threads = __kmp_stg_find(
"KMP_PLACE_THREADS");
5701 static kmp_setting_t *
volatile rivals[3];
5704 rivals[i++] = kmp_hw_subset;
5705 rivals[i++] = kmp_place_threads;
5708 kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
5709 kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
5712 #if KMP_AFFINITY_SUPPORTED
5714 kmp_setting_t *kmp_affinity =
5715 __kmp_stg_find(
"KMP_AFFINITY");
5716 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
5718 #ifdef KMP_GOMP_COMPAT
5719 kmp_setting_t *gomp_cpu_affinity =
5720 __kmp_stg_find(
"GOMP_CPU_AFFINITY");
5721 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
5724 kmp_setting_t *omp_proc_bind =
5725 __kmp_stg_find(
"OMP_PROC_BIND");
5726 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
5729 static kmp_setting_t *
volatile rivals[4];
5732 rivals[i++] = kmp_affinity;
5734 #ifdef KMP_GOMP_COMPAT
5735 rivals[i++] = gomp_cpu_affinity;
5736 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
5739 rivals[i++] = omp_proc_bind;
5740 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
5743 static kmp_setting_t *
volatile places_rivals[4];
5746 kmp_setting_t *omp_places = __kmp_stg_find(
"OMP_PLACES");
5747 KMP_DEBUG_ASSERT(omp_places != NULL);
5749 places_rivals[i++] = kmp_affinity;
5750 #ifdef KMP_GOMP_COMPAT
5751 places_rivals[i++] = gomp_cpu_affinity;
5753 places_rivals[i++] = omp_places;
5754 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
5755 places_rivals[i++] = NULL;
5763 kmp_setting_t *kmp_force_red =
5764 __kmp_stg_find(
"KMP_FORCE_REDUCTION");
5765 kmp_setting_t *kmp_determ_red =
5766 __kmp_stg_find(
"KMP_DETERMINISTIC_REDUCTION");
5769 static kmp_setting_t *
volatile rivals[3];
5770 static kmp_stg_fr_data_t force_data = {1,
5771 CCAST(kmp_setting_t **, rivals)};
5772 static kmp_stg_fr_data_t determ_data = {0,
5773 CCAST(kmp_setting_t **, rivals)};
5776 rivals[i++] = kmp_force_red;
5777 if (kmp_determ_red != NULL) {
5778 rivals[i++] = kmp_determ_red;
5782 kmp_force_red->data = &force_data;
5783 if (kmp_determ_red != NULL) {
5784 kmp_determ_red->data = &determ_data;
5793 for (i = 0; i < __kmp_stg_count; ++i) {
5794 __kmp_stg_table[i].set = 0;
5799 static void __kmp_stg_parse(
char const *name,
char const *value) {
5807 if (value != NULL) {
5808 kmp_setting_t *setting = __kmp_stg_find(name);
5809 if (setting != NULL) {
5810 setting->parse(name, value, setting->data);
5811 setting->defined = 1;
5817 static int __kmp_stg_check_rivals(
5820 kmp_setting_t **rivals
5823 if (rivals == NULL) {
5829 for (; strcmp(rivals[i]->name, name) != 0; i++) {
5830 KMP_DEBUG_ASSERT(rivals[i] != NULL);
5832 #if KMP_AFFINITY_SUPPORTED
5833 if (rivals[i] == __kmp_affinity_notype) {
5840 if (rivals[i]->set) {
5841 KMP_WARNING(StgIgnored, name, rivals[i]->name);
5851 static int __kmp_env_toPrint(
char const *name,
int flag) {
5853 kmp_setting_t *setting = __kmp_stg_find(name);
5854 if (setting != NULL) {
5855 rc = setting->defined;
5857 setting->defined = flag;
5863 static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
5868 value = __kmp_env_blk_var(block,
"OMP_NUM_THREADS");
5870 ompc_set_num_threads(__kmp_dflt_team_nth);
5874 value = __kmp_env_blk_var(block,
"KMP_BLOCKTIME");
5876 kmpc_set_blocktime(__kmp_dflt_blocktime);
5880 value = __kmp_env_blk_var(block,
"OMP_NESTED");
5882 ompc_set_nested(__kmp_dflt_max_active_levels > 1);
5886 value = __kmp_env_blk_var(block,
"OMP_DYNAMIC");
5888 ompc_set_dynamic(__kmp_global.g.g_dynamic);
5892 void __kmp_env_initialize(
char const *
string) {
5894 kmp_env_blk_t block;
5900 if (
string == NULL) {
5902 __kmp_threads_capacity =
5903 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
5905 __kmp_env_blk_init(&block,
string);
5908 for (i = 0; i < block.count; ++i) {
5909 if ((block.vars[i].name == NULL) || (*block.vars[i].name ==
'\0')) {
5912 if (block.vars[i].value == NULL) {
5915 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
5916 if (setting != NULL) {
5922 blocktime_str = __kmp_env_blk_var(&block,
"KMP_BLOCKTIME");
5926 if (
string == NULL) {
5927 char const *name =
"KMP_WARNINGS";
5928 char const *value = __kmp_env_blk_var(&block, name);
5929 __kmp_stg_parse(name, value);
5932 #if KMP_AFFINITY_SUPPORTED
5938 __kmp_affinity_notype = NULL;
5939 char const *aff_str = __kmp_env_blk_var(&block,
"KMP_AFFINITY");
5940 if (aff_str != NULL) {
5954 #define FIND strcasestr
5957 if ((FIND(aff_str,
"none") == NULL) &&
5958 (FIND(aff_str,
"physical") == NULL) &&
5959 (FIND(aff_str,
"logical") == NULL) &&
5960 (FIND(aff_str,
"compact") == NULL) &&
5961 (FIND(aff_str,
"scatter") == NULL) &&
5962 (FIND(aff_str,
"explicit") == NULL) &&
5963 (FIND(aff_str,
"balanced") == NULL) &&
5964 (FIND(aff_str,
"disabled") == NULL)) {
5965 __kmp_affinity_notype = __kmp_stg_find(
"KMP_AFFINITY");
5970 __kmp_affinity_type = affinity_default;
5971 __kmp_affinity_gran = KMP_HW_UNKNOWN;
5972 __kmp_affinity_top_method = affinity_top_method_default;
5973 __kmp_affinity_respect_mask = affinity_respect_mask_default;
5978 aff_str = __kmp_env_blk_var(&block,
"OMP_PROC_BIND");
5979 if (aff_str != NULL) {
5980 __kmp_affinity_type = affinity_default;
5981 __kmp_affinity_gran = KMP_HW_UNKNOWN;
5982 __kmp_affinity_top_method = affinity_top_method_default;
5983 __kmp_affinity_respect_mask = affinity_respect_mask_default;
5990 if (__kmp_nested_proc_bind.bind_types == NULL) {
5991 __kmp_nested_proc_bind.bind_types =
5992 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(
sizeof(kmp_proc_bind_t));
5993 if (__kmp_nested_proc_bind.bind_types == NULL) {
5994 KMP_FATAL(MemoryAllocFailed);
5996 __kmp_nested_proc_bind.size = 1;
5997 __kmp_nested_proc_bind.used = 1;
5998 #if KMP_AFFINITY_SUPPORTED
5999 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
6002 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6009 __kmp_msg_format(kmp_i18n_msg_AffFormatDefault,
"%P",
"%i",
"%n",
"%A");
6010 KMP_DEBUG_ASSERT(KMP_STRLEN(m.str) < KMP_AFFINITY_FORMAT_SIZE);
6012 if (__kmp_affinity_format == NULL) {
6013 __kmp_affinity_format =
6014 (
char *)KMP_INTERNAL_MALLOC(
sizeof(
char) * KMP_AFFINITY_FORMAT_SIZE);
6016 KMP_STRCPY_S(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, m.str);
6017 __kmp_str_free(&m.str);
6020 for (i = 0; i < block.count; ++i) {
6021 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
6025 if (!__kmp_init_user_locks) {
6026 if (__kmp_user_lock_kind == lk_default) {
6027 __kmp_user_lock_kind = lk_queuing;
6029 #if KMP_USE_DYNAMIC_LOCK
6030 __kmp_init_dynamic_user_locks();
6032 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
6035 KMP_DEBUG_ASSERT(
string != NULL);
6036 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
6041 #if KMP_USE_DYNAMIC_LOCK
6042 __kmp_init_dynamic_user_locks();
6044 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
6048 #if KMP_AFFINITY_SUPPORTED
6050 if (!TCR_4(__kmp_init_middle)) {
6055 if (__kmp_hw_subset &&
6056 __kmp_affinity_top_method == affinity_top_method_default)
6057 if (__kmp_hw_subset->specified(KMP_HW_NUMA) ||
6058 __kmp_hw_subset->specified(KMP_HW_TILE) ||
6059 __kmp_affinity_gran == KMP_HW_TILE ||
6060 __kmp_affinity_gran == KMP_HW_NUMA)
6061 __kmp_affinity_top_method = affinity_top_method_hwloc;
6063 if (__kmp_affinity_gran == KMP_HW_NUMA ||
6064 __kmp_affinity_gran == KMP_HW_TILE)
6065 __kmp_affinity_top_method = affinity_top_method_hwloc;
6069 const char *var =
"KMP_AFFINITY";
6070 KMPAffinity::pick_api();
6075 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
6076 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
6077 KMP_WARNING(AffIgnoringHwloc, var);
6078 __kmp_affinity_top_method = affinity_top_method_all;
6081 if (__kmp_affinity_type == affinity_disabled) {
6082 KMP_AFFINITY_DISABLE();
6083 }
else if (!KMP_AFFINITY_CAPABLE()) {
6084 __kmp_affinity_dispatch->determine_capable(var);
6085 if (!KMP_AFFINITY_CAPABLE()) {
6086 if (__kmp_affinity_verbose ||
6087 (__kmp_affinity_warnings &&
6088 (__kmp_affinity_type != affinity_default) &&
6089 (__kmp_affinity_type != affinity_none) &&
6090 (__kmp_affinity_type != affinity_disabled))) {
6091 KMP_WARNING(AffNotSupported, var);
6093 __kmp_affinity_type = affinity_disabled;
6094 __kmp_affinity_respect_mask = 0;
6095 __kmp_affinity_gran = KMP_HW_THREAD;
6099 if (__kmp_affinity_type == affinity_disabled) {
6100 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6101 }
else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
6103 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
6106 if (KMP_AFFINITY_CAPABLE()) {
6108 #if KMP_GROUP_AFFINITY
6113 bool exactly_one_group =
false;
6114 if (__kmp_num_proc_groups > 1) {
6116 bool within_one_group;
6119 kmp_affin_mask_t *init_mask;
6120 KMP_CPU_ALLOC(init_mask);
6121 __kmp_get_system_affinity(init_mask, TRUE);
6122 group = __kmp_get_proc_group(init_mask);
6123 within_one_group = (group >= 0);
6126 if (within_one_group) {
6127 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
6128 DWORD num_bits_in_mask = 0;
6129 for (
int bit = init_mask->begin(); bit != init_mask->end();
6130 bit = init_mask->next(bit))
6132 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
6134 KMP_CPU_FREE(init_mask);
6140 if (__kmp_num_proc_groups > 1 &&
6141 __kmp_affinity_type == affinity_default &&
6142 __kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
6147 if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
6148 exactly_one_group) {
6149 __kmp_affinity_respect_mask = FALSE;
6153 if (__kmp_affinity_type == affinity_default) {
6154 __kmp_affinity_type = affinity_compact;
6155 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6157 if (__kmp_affinity_top_method == affinity_top_method_default)
6158 __kmp_affinity_top_method = affinity_top_method_all;
6159 if (__kmp_affinity_gran == KMP_HW_UNKNOWN)
6160 __kmp_affinity_gran = KMP_HW_PROC_GROUP;
6166 if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
6167 #if KMP_GROUP_AFFINITY
6168 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
6169 __kmp_affinity_respect_mask = FALSE;
6173 __kmp_affinity_respect_mask = TRUE;
6176 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
6177 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
6178 if (__kmp_affinity_type == affinity_default) {
6179 __kmp_affinity_type = affinity_compact;
6180 __kmp_affinity_dups = FALSE;
6182 }
else if (__kmp_affinity_type == affinity_default) {
6183 #if KMP_MIC_SUPPORTED
6184 if (__kmp_mic_type != non_mic) {
6185 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6189 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6191 #if KMP_MIC_SUPPORTED
6192 if (__kmp_mic_type != non_mic) {
6193 __kmp_affinity_type = affinity_scatter;
6197 __kmp_affinity_type = affinity_none;
6200 if ((__kmp_affinity_gran == KMP_HW_UNKNOWN) &&
6201 (__kmp_affinity_gran_levels < 0)) {
6202 #if KMP_MIC_SUPPORTED
6203 if (__kmp_mic_type != non_mic) {
6204 __kmp_affinity_gran = KMP_HW_THREAD;
6208 __kmp_affinity_gran = KMP_HW_CORE;
6211 if (__kmp_affinity_top_method == affinity_top_method_default) {
6212 __kmp_affinity_top_method = affinity_top_method_all;
6217 K_DIAG(1, (
"__kmp_affinity_type == %d\n", __kmp_affinity_type));
6218 K_DIAG(1, (
"__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
6219 K_DIAG(1, (
"__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
6220 K_DIAG(1, (
"__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
6221 K_DIAG(1, (
"__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
6222 K_DIAG(1, (
"__kmp_affinity_respect_mask == %d\n",
6223 __kmp_affinity_respect_mask));
6224 K_DIAG(1, (
"__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
6226 KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
6227 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
6228 K_DIAG(1, (
"__kmp_nested_proc_bind.bind_types[0] == %d\n",
6229 __kmp_nested_proc_bind.bind_types[0]));
6234 if (__kmp_version) {
6235 __kmp_print_version_1();
6240 if (
string != NULL) {
6241 __kmp_aux_env_initialize(&block);
6244 __kmp_env_blk_free(&block);
6250 void __kmp_env_print() {
6252 kmp_env_blk_t block;
6254 kmp_str_buf_t buffer;
6257 __kmp_str_buf_init(&buffer);
6259 __kmp_env_blk_init(&block, NULL);
6260 __kmp_env_blk_sort(&block);
6263 __kmp_str_buf_print(&buffer,
"\n%s\n\n", KMP_I18N_STR(UserSettings));
6264 for (i = 0; i < block.count; ++i) {
6265 char const *name = block.vars[i].name;
6266 char const *value = block.vars[i].value;
6267 if ((KMP_STRLEN(name) > 4 && strncmp(name,
"KMP_", 4) == 0) ||
6268 strncmp(name,
"OMP_", 4) == 0
6269 #ifdef KMP_GOMP_COMPAT
6270 || strncmp(name,
"GOMP_", 5) == 0
6273 __kmp_str_buf_print(&buffer,
" %s=%s\n", name, value);
6276 __kmp_str_buf_print(&buffer,
"\n");
6279 __kmp_str_buf_print(&buffer,
"%s\n\n", KMP_I18N_STR(EffectiveSettings));
6280 for (
int i = 0; i < __kmp_stg_count; ++i) {
6281 if (__kmp_stg_table[i].print != NULL) {
6282 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6283 __kmp_stg_table[i].data);
6287 __kmp_printf(
"%s", buffer.str);
6289 __kmp_env_blk_free(&block);
6290 __kmp_str_buf_free(&buffer);
6296 void __kmp_env_print_2() {
6297 __kmp_display_env_impl(__kmp_display_env, __kmp_display_env_verbose);
6300 void __kmp_display_env_impl(
int display_env,
int display_env_verbose) {
6301 kmp_env_blk_t block;
6302 kmp_str_buf_t buffer;
6304 __kmp_env_format = 1;
6307 __kmp_str_buf_init(&buffer);
6309 __kmp_env_blk_init(&block, NULL);
6310 __kmp_env_blk_sort(&block);
6312 __kmp_str_buf_print(&buffer,
"\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
6313 __kmp_str_buf_print(&buffer,
" _OPENMP='%d'\n", __kmp_openmp_version);
6315 for (
int i = 0; i < __kmp_stg_count; ++i) {
6316 if (__kmp_stg_table[i].print != NULL &&
6317 ((display_env && strncmp(__kmp_stg_table[i].name,
"OMP_", 4) == 0) ||
6318 display_env_verbose)) {
6319 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6320 __kmp_stg_table[i].data);
6324 __kmp_str_buf_print(&buffer,
"%s\n", KMP_I18N_STR(DisplayEnvEnd));
6325 __kmp_str_buf_print(&buffer,
"\n");
6327 __kmp_printf(
"%s", buffer.str);
6329 __kmp_env_blk_free(&block);
6330 __kmp_str_buf_free(&buffer);
6337 void __kmp_env_dump() {
6339 kmp_env_blk_t block;
6340 kmp_str_buf_t buffer, env, notdefined;
6343 __kmp_str_buf_init(&buffer);
6344 __kmp_str_buf_init(&env);
6345 __kmp_str_buf_init(¬defined);
6347 __kmp_env_blk_init(&block, NULL);
6348 __kmp_env_blk_sort(&block);
6350 __kmp_str_buf_print(¬defined,
": %s", KMP_I18N_STR(NotDefined));
6352 for (
int i = 0; i < __kmp_stg_count; ++i) {
6353 if (__kmp_stg_table[i].print == NULL)
6355 __kmp_str_buf_clear(&env);
6356 __kmp_stg_table[i].print(&env, __kmp_stg_table[i].name,
6357 __kmp_stg_table[i].data);
6360 if (strstr(env.str, notdefined.str))
6362 __kmp_str_buf_print(&buffer,
"%s=undefined\n", __kmp_stg_table[i].name);
6364 __kmp_str_buf_cat(&buffer, env.str + 3, env.used - 3);
6367 ompd_env_block = (
char *)__kmp_allocate(buffer.used + 1);
6368 KMP_MEMCPY(ompd_env_block, buffer.str, buffer.used + 1);
6369 ompd_env_block_size = (ompd_size_t)KMP_STRLEN(ompd_env_block);
6371 __kmp_env_blk_free(&block);
6372 __kmp_str_buf_free(&buffer);
6373 __kmp_str_buf_free(&env);
6374 __kmp_str_buf_free(¬defined);
@ kmp_sch_modifier_monotonic
@ kmp_sch_modifier_nonmonotonic