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 nvalues = KMP_SSCANF(data,
"%lf%c%c", &value, &mult, &extra);
193 factor = 1000 * 60 * 60;
197 factor = 1000 * 24 * 60 * 60;
203 if (value >= ((INT_MAX - 1) / factor))
206 ret = (int)(value * (
double)factor);
211 static int __kmp_strcasecmp_with_sentinel(
char const *a,
char const *b,
217 while (*a && *b && *b != sentinel) {
218 char ca = *a, cb = *b;
220 if (ca >=
'a' && ca <=
'z')
222 if (cb >=
'a' && cb <=
'z')
225 return (
int)(
unsigned char)*a - (
int)(
unsigned char)*b;
229 return *a ? (*b && *b != sentinel)
230 ? (
int)(
unsigned char)*a - (
int)(
unsigned char)*b
232 : (*b && *b != sentinel) ? -1
239 typedef struct __kmp_setting kmp_setting_t;
240 typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
241 typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
242 typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
244 typedef void (*kmp_stg_parse_func_t)(
char const *name,
char const *value,
246 typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer,
char const *name,
249 struct __kmp_setting {
251 kmp_stg_parse_func_t parse;
252 kmp_stg_print_func_t print;
259 struct __kmp_stg_ss_data {
261 kmp_setting_t **rivals;
264 struct __kmp_stg_wp_data {
266 kmp_setting_t **rivals;
269 struct __kmp_stg_fr_data {
271 kmp_setting_t **rivals;
274 static int __kmp_stg_check_rivals(
277 kmp_setting_t **rivals
283 static void __kmp_stg_parse_bool(
char const *name,
char const *value,
285 if (__kmp_str_match_true(value)) {
287 }
else if (__kmp_str_match_false(value)) {
290 __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
291 KMP_HNT(ValidBoolValues), __kmp_msg_null);
296 void __kmp_check_stksize(
size_t *val) {
298 if (*val > KMP_DEFAULT_STKSIZE * 16)
299 *val = KMP_DEFAULT_STKSIZE * 16;
300 if (*val < KMP_MIN_STKSIZE)
301 *val = KMP_MIN_STKSIZE;
302 if (*val > KMP_MAX_STKSIZE)
303 *val = KMP_MAX_STKSIZE;
305 *val = __kmp_round4k(*val);
309 static void __kmp_stg_parse_size(
char const *name,
char const *value,
310 size_t size_min,
size_t size_max,
311 int *is_specified,
size_t *out,
313 char const *msg = NULL;
315 size_min = __kmp_round4k(size_min);
316 size_max = __kmp_round4k(size_max);
319 if (is_specified != NULL) {
322 __kmp_str_to_size(value, out, factor, &msg);
324 if (*out > size_max) {
326 msg = KMP_I18N_STR(ValueTooLarge);
327 }
else if (*out < size_min) {
329 msg = KMP_I18N_STR(ValueTooSmall);
332 size_t round4k = __kmp_round4k(*out);
333 if (*out != round4k) {
335 msg = KMP_I18N_STR(NotMultiple4K);
342 if (*out < size_min) {
344 }
else if (*out > size_max) {
351 __kmp_str_buf_init(&buf);
352 __kmp_str_buf_print_size(&buf, *out);
353 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
354 KMP_INFORM(Using_str_Value, name, buf.str);
355 __kmp_str_buf_free(&buf);
360 static void __kmp_stg_parse_str(
char const *name,
char const *value,
363 *out = __kmp_str_format(
"%s", value);
366 static void __kmp_stg_parse_int(
374 char const *msg = NULL;
375 kmp_uint64 uint = *out;
376 __kmp_str_to_uint(value, &uint, &msg);
378 if (uint < (
unsigned int)min) {
379 msg = KMP_I18N_STR(ValueTooSmall);
381 }
else if (uint > (
unsigned int)max) {
382 msg = KMP_I18N_STR(ValueTooLarge);
388 if (uint < (
unsigned int)min) {
390 }
else if (uint > (
unsigned int)max) {
397 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
398 __kmp_str_buf_init(&buf);
399 __kmp_str_buf_print(&buf,
"%" KMP_UINT64_SPEC
"", uint);
400 KMP_INFORM(Using_uint64_Value, name, buf.str);
401 __kmp_str_buf_free(&buf);
403 __kmp_type_convert(uint, out);
406 #if KMP_DEBUG_ADAPTIVE_LOCKS
407 static void __kmp_stg_parse_file(
char const *name,
char const *value,
408 const char *suffix,
char **out) {
413 t = (
char *)strrchr(value,
'.');
414 hasSuffix = t && __kmp_str_eqf(t, suffix);
415 t = __kmp_str_format(
"%s%s", value, hasSuffix ?
"" : suffix);
416 __kmp_expand_file_name(buffer,
sizeof(buffer), t);
418 *out = __kmp_str_format(
"%s", buffer);
423 static char *par_range_to_print = NULL;
425 static void __kmp_stg_parse_par_range(
char const *name,
char const *value,
426 int *out_range,
char *out_routine,
427 char *out_file,
int *out_lb,
429 size_t len = KMP_STRLEN(value) + 1;
430 par_range_to_print = (
char *)KMP_INTERNAL_MALLOC(len + 1);
431 KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
432 __kmp_par_range = +1;
433 __kmp_par_range_lb = 0;
434 __kmp_par_range_ub = INT_MAX;
437 if (*value ==
'\0') {
440 if (!__kmp_strcasecmp_with_sentinel(
"routine", value,
'=')) {
441 value = strchr(value,
'=') + 1;
442 len = __kmp_readstr_with_sentinel(out_routine, value,
443 KMP_PAR_RANGE_ROUTINE_LEN - 1,
',');
445 goto par_range_error;
447 value = strchr(value,
',');
453 if (!__kmp_strcasecmp_with_sentinel(
"filename", value,
'=')) {
454 value = strchr(value,
'=') + 1;
455 len = __kmp_readstr_with_sentinel(out_file, value,
456 KMP_PAR_RANGE_FILENAME_LEN - 1,
',');
458 goto par_range_error;
460 value = strchr(value,
',');
466 if ((!__kmp_strcasecmp_with_sentinel(
"range", value,
'=')) ||
467 (!__kmp_strcasecmp_with_sentinel(
"incl_range", value,
'='))) {
468 value = strchr(value,
'=') + 1;
469 if (KMP_SSCANF(value,
"%d:%d", out_lb, out_ub) != 2) {
470 goto par_range_error;
473 value = strchr(value,
',');
479 if (!__kmp_strcasecmp_with_sentinel(
"excl_range", value,
'=')) {
480 value = strchr(value,
'=') + 1;
481 if (KMP_SSCANF(value,
"%d:%d", out_lb, out_ub) != 2) {
482 goto par_range_error;
485 value = strchr(value,
',');
492 KMP_WARNING(ParRangeSyntax, name);
499 int __kmp_initial_threads_capacity(
int req_nproc) {
504 if (nth < (4 * req_nproc))
505 nth = (4 * req_nproc);
506 if (nth < (4 * __kmp_xproc))
507 nth = (4 * __kmp_xproc);
511 if (__kmp_enable_hidden_helper) {
512 nth += __kmp_hidden_helper_threads_num;
515 if (nth > __kmp_max_nth)
521 int __kmp_default_tp_capacity(
int req_nproc,
int max_nth,
522 int all_threads_specified) {
525 if (all_threads_specified)
529 if (nth < (4 * req_nproc))
530 nth = (4 * req_nproc);
531 if (nth < (4 * __kmp_xproc))
532 nth = (4 * __kmp_xproc);
534 if (nth > __kmp_max_nth)
543 static void __kmp_stg_print_bool(kmp_str_buf_t *buffer,
char const *name,
545 if (__kmp_env_format) {
546 KMP_STR_BUF_PRINT_BOOL;
548 __kmp_str_buf_print(buffer,
" %s=%s\n", name, value ?
"true" :
"false");
552 static void __kmp_stg_print_int(kmp_str_buf_t *buffer,
char const *name,
554 if (__kmp_env_format) {
555 KMP_STR_BUF_PRINT_INT;
557 __kmp_str_buf_print(buffer,
" %s=%d\n", name, value);
561 static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer,
char const *name,
563 if (__kmp_env_format) {
564 KMP_STR_BUF_PRINT_UINT64;
566 __kmp_str_buf_print(buffer,
" %s=%" KMP_UINT64_SPEC
"\n", name, value);
570 static void __kmp_stg_print_str(kmp_str_buf_t *buffer,
char const *name,
572 if (__kmp_env_format) {
573 KMP_STR_BUF_PRINT_STR;
575 __kmp_str_buf_print(buffer,
" %s=%s\n", name, value);
579 static void __kmp_stg_print_size(kmp_str_buf_t *buffer,
char const *name,
581 if (__kmp_env_format) {
582 KMP_STR_BUF_PRINT_NAME_EX(name);
583 __kmp_str_buf_print_size(buffer, value);
584 __kmp_str_buf_print(buffer,
"'\n");
586 __kmp_str_buf_print(buffer,
" %s=", name);
587 __kmp_str_buf_print_size(buffer, value);
588 __kmp_str_buf_print(buffer,
"\n");
599 static void __kmp_stg_parse_device_thread_limit(
char const *name,
600 char const *value,
void *data) {
601 kmp_setting_t **rivals = (kmp_setting_t **)data;
603 if (strcmp(name,
"KMP_ALL_THREADS") == 0) {
604 KMP_INFORM(EnvVarDeprecated, name,
"KMP_DEVICE_THREAD_LIMIT");
606 rc = __kmp_stg_check_rivals(name, value, rivals);
610 if (!__kmp_strcasecmp_with_sentinel(
"all", value, 0)) {
611 __kmp_max_nth = __kmp_xproc;
612 __kmp_allThreadsSpecified = 1;
614 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
615 __kmp_allThreadsSpecified = 0;
617 K_DIAG(1, (
"__kmp_max_nth == %d\n", __kmp_max_nth));
621 static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
622 char const *name,
void *data) {
623 __kmp_stg_print_int(buffer, name, __kmp_max_nth);
628 static void __kmp_stg_parse_thread_limit(
char const *name,
char const *value,
630 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
631 K_DIAG(1, (
"__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));
635 static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
636 char const *name,
void *data) {
637 __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
642 static void __kmp_stg_parse_nteams(
char const *name,
char const *value,
644 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_nteams);
645 K_DIAG(1, (
"__kmp_nteams == %d\n", __kmp_nteams));
648 static void __kmp_stg_print_nteams(kmp_str_buf_t *buffer,
char const *name,
650 __kmp_stg_print_int(buffer, name, __kmp_nteams);
655 static void __kmp_stg_parse_teams_th_limit(
char const *name,
char const *value,
657 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth,
658 &__kmp_teams_thread_limit);
659 K_DIAG(1, (
"__kmp_teams_thread_limit == %d\n", __kmp_teams_thread_limit));
662 static void __kmp_stg_print_teams_th_limit(kmp_str_buf_t *buffer,
663 char const *name,
void *data) {
664 __kmp_stg_print_int(buffer, name, __kmp_teams_thread_limit);
669 static void __kmp_stg_parse_teams_thread_limit(
char const *name,
670 char const *value,
void *data) {
671 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
674 static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
675 char const *name,
void *data) {
676 __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
681 static void __kmp_stg_parse_use_yield(
char const *name,
char const *value,
683 __kmp_stg_parse_int(name, value, 0, 2, &__kmp_use_yield);
684 __kmp_use_yield_exp_set = 1;
687 static void __kmp_stg_print_use_yield(kmp_str_buf_t *buffer,
char const *name,
689 __kmp_stg_print_int(buffer, name, __kmp_use_yield);
695 static void __kmp_stg_parse_blocktime(
char const *name,
char const *value,
697 __kmp_dflt_blocktime = __kmp_convert_to_milliseconds(value);
698 if (__kmp_dflt_blocktime < 0) {
699 __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
700 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
702 KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime);
703 __kmp_env_blocktime = FALSE;
705 if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
706 __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
707 __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
709 KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime);
710 }
else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
711 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
712 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
714 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime);
716 __kmp_env_blocktime = TRUE;
721 __kmp_monitor_wakeups =
722 KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
724 KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
726 K_DIAG(1, (
"__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
727 if (__kmp_env_blocktime) {
728 K_DIAG(1, (
"__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
732 static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer,
char const *name,
734 __kmp_stg_print_int(buffer, name, __kmp_dflt_blocktime);
740 static void __kmp_stg_parse_duplicate_lib_ok(
char const *name,
741 char const *value,
void *data) {
744 __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
747 static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
748 char const *name,
void *data) {
749 __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
755 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
757 static void __kmp_stg_parse_inherit_fp_control(
char const *name,
758 char const *value,
void *data) {
759 __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
762 static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
763 char const *name,
void *data) {
765 __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
772 static char const *blocktime_str = NULL;
777 static void __kmp_stg_parse_wait_policy(
char const *name,
char const *value,
780 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
783 rc = __kmp_stg_check_rivals(name, value, wait->rivals);
789 if (__kmp_str_match(
"ACTIVE", 1, value)) {
790 __kmp_library = library_turnaround;
791 if (blocktime_str == NULL) {
793 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
795 }
else if (__kmp_str_match(
"PASSIVE", 1, value)) {
796 __kmp_library = library_throughput;
797 if (blocktime_str == NULL) {
799 __kmp_dflt_blocktime = 0;
802 KMP_WARNING(StgInvalidValue, name, value);
805 if (__kmp_str_match(
"serial", 1, value)) {
806 __kmp_library = library_serial;
807 }
else if (__kmp_str_match(
"throughput", 2, value)) {
808 __kmp_library = library_throughput;
809 if (blocktime_str == NULL) {
811 __kmp_dflt_blocktime = 0;
813 }
else if (__kmp_str_match(
"turnaround", 2, value)) {
814 __kmp_library = library_turnaround;
815 }
else if (__kmp_str_match(
"dedicated", 1, value)) {
816 __kmp_library = library_turnaround;
817 }
else if (__kmp_str_match(
"multiuser", 1, value)) {
818 __kmp_library = library_throughput;
819 if (blocktime_str == NULL) {
821 __kmp_dflt_blocktime = 0;
824 KMP_WARNING(StgInvalidValue, name, value);
829 static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer,
char const *name,
832 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
833 char const *value = NULL;
836 switch (__kmp_library) {
837 case library_turnaround: {
840 case library_throughput: {
845 switch (__kmp_library) {
846 case library_serial: {
849 case library_turnaround: {
850 value =
"turnaround";
852 case library_throughput: {
853 value =
"throughput";
858 __kmp_stg_print_str(buffer, name, value);
867 static void __kmp_stg_parse_monitor_stacksize(
char const *name,
868 char const *value,
void *data) {
869 __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
870 NULL, &__kmp_monitor_stksize, 1);
873 static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
874 char const *name,
void *data) {
875 if (__kmp_env_format) {
876 if (__kmp_monitor_stksize > 0)
877 KMP_STR_BUF_PRINT_NAME_EX(name);
879 KMP_STR_BUF_PRINT_NAME;
881 __kmp_str_buf_print(buffer,
" %s", name);
883 if (__kmp_monitor_stksize > 0) {
884 __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
886 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
888 if (__kmp_env_format && __kmp_monitor_stksize) {
889 __kmp_str_buf_print(buffer,
"'\n");
897 static void __kmp_stg_parse_settings(
char const *name,
char const *value,
899 __kmp_stg_parse_bool(name, value, &__kmp_settings);
902 static void __kmp_stg_print_settings(kmp_str_buf_t *buffer,
char const *name,
904 __kmp_stg_print_bool(buffer, name, __kmp_settings);
910 static void __kmp_stg_parse_stackpad(
char const *name,
char const *value,
912 __kmp_stg_parse_int(name,
920 static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer,
char const *name,
922 __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
928 static void __kmp_stg_parse_stackoffset(
char const *name,
char const *value,
930 __kmp_stg_parse_size(name,
939 static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer,
char const *name,
941 __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
947 static void __kmp_stg_parse_stacksize(
char const *name,
char const *value,
950 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
953 rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
957 __kmp_stg_parse_size(name,
959 __kmp_sys_min_stksize,
971 static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer,
char const *name,
973 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
974 if (__kmp_env_format) {
975 KMP_STR_BUF_PRINT_NAME_EX(name);
976 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
977 ? __kmp_stksize / stacksize->factor
979 __kmp_str_buf_print(buffer,
"'\n");
981 __kmp_str_buf_print(buffer,
" %s=", name);
982 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
983 ? __kmp_stksize / stacksize->factor
985 __kmp_str_buf_print(buffer,
"\n");
992 static void __kmp_stg_parse_version(
char const *name,
char const *value,
994 __kmp_stg_parse_bool(name, value, &__kmp_version);
997 static void __kmp_stg_print_version(kmp_str_buf_t *buffer,
char const *name,
999 __kmp_stg_print_bool(buffer, name, __kmp_version);
1005 static void __kmp_stg_parse_warnings(
char const *name,
char const *value,
1007 __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
1008 if (__kmp_generate_warnings != kmp_warnings_off) {
1011 __kmp_generate_warnings = kmp_warnings_explicit;
1015 static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer,
char const *name,
1018 __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
1024 static void __kmp_stg_parse_nesting_mode(
char const *name,
char const *value,
1026 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_nesting_mode);
1027 #if KMP_AFFINITY_SUPPORTED && KMP_USE_HWLOC
1028 if (__kmp_nesting_mode > 0)
1029 __kmp_affinity_top_method = affinity_top_method_hwloc;
1033 static void __kmp_stg_print_nesting_mode(kmp_str_buf_t *buffer,
1034 char const *name,
void *data) {
1035 if (__kmp_env_format) {
1036 KMP_STR_BUF_PRINT_NAME;
1038 __kmp_str_buf_print(buffer,
" %s", name);
1040 __kmp_str_buf_print(buffer,
"=%d\n", __kmp_nesting_mode);
1046 static void __kmp_stg_parse_nested(
char const *name,
char const *value,
1049 KMP_INFORM(EnvVarDeprecated, name,
"OMP_MAX_ACTIVE_LEVELS");
1050 __kmp_stg_parse_bool(name, value, &nested);
1052 if (!__kmp_dflt_max_active_levels_set)
1053 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1055 __kmp_dflt_max_active_levels = 1;
1056 __kmp_dflt_max_active_levels_set =
true;
1060 static void __kmp_stg_print_nested(kmp_str_buf_t *buffer,
char const *name,
1062 if (__kmp_env_format) {
1063 KMP_STR_BUF_PRINT_NAME;
1065 __kmp_str_buf_print(buffer,
" %s", name);
1067 __kmp_str_buf_print(buffer,
": deprecated; max-active-levels-var=%d\n",
1068 __kmp_dflt_max_active_levels);
1071 static void __kmp_parse_nested_num_threads(
const char *var,
const char *env,
1072 kmp_nested_nthreads_t *nth_array) {
1073 const char *next = env;
1074 const char *scan = next;
1077 int prev_comma = FALSE;
1083 if (*next ==
'\0') {
1087 if (((*next <
'0') || (*next >
'9')) && (*next !=
',')) {
1088 KMP_WARNING(NthSyntaxError, var, env);
1094 if (total == 0 || prev_comma) {
1102 if (*next >=
'0' && *next <=
'9') {
1106 const char *tmp = next;
1108 if ((*next ==
' ' || *next ==
'\t') && (*tmp >=
'0' && *tmp <=
'9')) {
1109 KMP_WARNING(NthSpacesNotAllowed, var, env);
1114 if (!__kmp_dflt_max_active_levels_set && total > 1)
1115 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1116 KMP_DEBUG_ASSERT(total > 0);
1118 KMP_WARNING(NthSyntaxError, var, env);
1123 if (!nth_array->nth) {
1125 nth_array->nth = (
int *)KMP_INTERNAL_MALLOC(
sizeof(
int) * total * 2);
1126 if (nth_array->nth == NULL) {
1127 KMP_FATAL(MemoryAllocFailed);
1129 nth_array->size = total * 2;
1131 if (nth_array->size < total) {
1134 nth_array->size *= 2;
1135 }
while (nth_array->size < total);
1137 nth_array->nth = (
int *)KMP_INTERNAL_REALLOC(
1138 nth_array->nth,
sizeof(
int) * nth_array->size);
1139 if (nth_array->nth == NULL) {
1140 KMP_FATAL(MemoryAllocFailed);
1144 nth_array->used = total;
1152 if (*scan ==
'\0') {
1162 nth_array->nth[i++] = 0;
1164 }
else if (prev_comma) {
1166 nth_array->nth[i] = nth_array->nth[i - 1];
1175 if (*scan >=
'0' && *scan <=
'9') {
1177 const char *buf = scan;
1178 char const *msg = NULL;
1183 num = __kmp_str_to_int(buf, *scan);
1184 if (num < KMP_MIN_NTH) {
1185 msg = KMP_I18N_STR(ValueTooSmall);
1187 }
else if (num > __kmp_sys_max_nth) {
1188 msg = KMP_I18N_STR(ValueTooLarge);
1189 num = __kmp_sys_max_nth;
1193 KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1194 KMP_INFORM(Using_int_Value, var, num);
1196 nth_array->nth[i++] = num;
1201 static void __kmp_stg_parse_num_threads(
char const *name,
char const *value,
1204 if (!__kmp_strcasecmp_with_sentinel(
"all", value, 0)) {
1206 __kmp_nested_nth.nth = (
int *)KMP_INTERNAL_MALLOC(
sizeof(
int));
1207 __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1208 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1211 __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1212 if (__kmp_nested_nth.nth) {
1213 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1214 if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1215 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1219 K_DIAG(1, (
"__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
1222 static void __kmp_stg_parse_num_hidden_helper_threads(
char const *name,
1225 __kmp_stg_parse_int(name, value, 0, 16, &__kmp_hidden_helper_threads_num);
1228 if (__kmp_hidden_helper_threads_num == 0) {
1229 __kmp_enable_hidden_helper = FALSE;
1233 static void __kmp_stg_print_num_hidden_helper_threads(kmp_str_buf_t *buffer,
1236 __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num);
1239 static void __kmp_stg_parse_use_hidden_helper(
char const *name,
1240 char const *value,
void *data) {
1241 __kmp_stg_parse_bool(name, value, &__kmp_enable_hidden_helper);
1243 __kmp_enable_hidden_helper = FALSE;
1245 (
"__kmp_stg_parse_use_hidden_helper: Disable hidden helper task on "
1246 "non-Linux platform although it is enabled by user explicitly.\n"));
1250 static void __kmp_stg_print_use_hidden_helper(kmp_str_buf_t *buffer,
1251 char const *name,
void *data) {
1252 __kmp_stg_print_bool(buffer, name, __kmp_enable_hidden_helper);
1255 static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer,
char const *name,
1257 if (__kmp_env_format) {
1258 KMP_STR_BUF_PRINT_NAME;
1260 __kmp_str_buf_print(buffer,
" %s", name);
1262 if (__kmp_nested_nth.used) {
1264 __kmp_str_buf_init(&buf);
1265 for (
int i = 0; i < __kmp_nested_nth.used; i++) {
1266 __kmp_str_buf_print(&buf,
"%d", __kmp_nested_nth.nth[i]);
1267 if (i < __kmp_nested_nth.used - 1) {
1268 __kmp_str_buf_print(&buf,
",");
1271 __kmp_str_buf_print(buffer,
"='%s'\n", buf.str);
1272 __kmp_str_buf_free(&buf);
1274 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
1281 static void __kmp_stg_parse_tasking(
char const *name,
char const *value,
1283 __kmp_stg_parse_int(name, value, 0, (
int)tskm_max,
1284 (
int *)&__kmp_tasking_mode);
1287 static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer,
char const *name,
1289 __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
1292 static void __kmp_stg_parse_task_stealing(
char const *name,
char const *value,
1294 __kmp_stg_parse_int(name, value, 0, 1,
1295 (
int *)&__kmp_task_stealing_constraint);
1298 static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1299 char const *name,
void *data) {
1300 __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
1303 static void __kmp_stg_parse_max_active_levels(
char const *name,
1304 char const *value,
void *data) {
1305 kmp_uint64 tmp_dflt = 0;
1306 char const *msg = NULL;
1307 if (!__kmp_dflt_max_active_levels_set) {
1309 __kmp_str_to_uint(value, &tmp_dflt, &msg);
1311 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1312 }
else if (tmp_dflt > KMP_MAX_ACTIVE_LEVELS_LIMIT) {
1314 msg = KMP_I18N_STR(ValueTooLarge);
1315 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1317 __kmp_type_convert(tmp_dflt, &(__kmp_dflt_max_active_levels));
1318 __kmp_dflt_max_active_levels_set =
true;
1323 static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1324 char const *name,
void *data) {
1325 __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
1330 static void __kmp_stg_parse_default_device(
char const *name,
char const *value,
1332 __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1333 &__kmp_default_device);
1336 static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1337 char const *name,
void *data) {
1338 __kmp_stg_print_int(buffer, name, __kmp_default_device);
1343 static void __kmp_stg_parse_target_offload(
char const *name,
char const *value,
1345 const char *next = value;
1346 const char *scan = next;
1348 __kmp_target_offload = tgt_default;
1353 if (!__kmp_strcasecmp_with_sentinel(
"mandatory", scan, 0)) {
1354 __kmp_target_offload = tgt_mandatory;
1355 }
else if (!__kmp_strcasecmp_with_sentinel(
"disabled", scan, 0)) {
1356 __kmp_target_offload = tgt_disabled;
1357 }
else if (!__kmp_strcasecmp_with_sentinel(
"default", scan, 0)) {
1358 __kmp_target_offload = tgt_default;
1360 KMP_WARNING(SyntaxErrorUsing, name,
"DEFAULT");
1365 static void __kmp_stg_print_target_offload(kmp_str_buf_t *buffer,
1366 char const *name,
void *data) {
1367 const char *value = NULL;
1368 if (__kmp_target_offload == tgt_default)
1370 else if (__kmp_target_offload == tgt_mandatory)
1371 value =
"MANDATORY";
1372 else if (__kmp_target_offload == tgt_disabled)
1374 KMP_DEBUG_ASSERT(value);
1375 if (__kmp_env_format) {
1376 KMP_STR_BUF_PRINT_NAME;
1378 __kmp_str_buf_print(buffer,
" %s", name);
1380 __kmp_str_buf_print(buffer,
"=%s\n", value);
1385 static void __kmp_stg_parse_max_task_priority(
char const *name,
1386 char const *value,
void *data) {
1387 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1388 &__kmp_max_task_priority);
1391 static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1392 char const *name,
void *data) {
1393 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
1398 static void __kmp_stg_parse_taskloop_min_tasks(
char const *name,
1399 char const *value,
void *data) {
1401 __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1402 __kmp_taskloop_min_tasks = tmp;
1405 static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
1406 char const *name,
void *data) {
1407 __kmp_stg_print_uint64(buffer, name, __kmp_taskloop_min_tasks);
1412 static void __kmp_stg_parse_disp_buffers(
char const *name,
char const *value,
1414 if (TCR_4(__kmp_init_serial)) {
1415 KMP_WARNING(EnvSerialWarn, name);
1418 __kmp_stg_parse_int(name, value, KMP_MIN_DISP_NUM_BUFF, KMP_MAX_DISP_NUM_BUFF,
1419 &__kmp_dispatch_num_buffers);
1422 static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1423 char const *name,
void *data) {
1424 __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
1427 #if KMP_NESTED_HOT_TEAMS
1431 static void __kmp_stg_parse_hot_teams_level(
char const *name,
char const *value,
1433 if (TCR_4(__kmp_init_parallel)) {
1434 KMP_WARNING(EnvParallelWarn, name);
1437 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1438 &__kmp_hot_teams_max_level);
1441 static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1442 char const *name,
void *data) {
1443 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
1446 static void __kmp_stg_parse_hot_teams_mode(
char const *name,
char const *value,
1448 if (TCR_4(__kmp_init_parallel)) {
1449 KMP_WARNING(EnvParallelWarn, name);
1452 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1453 &__kmp_hot_teams_mode);
1456 static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1457 char const *name,
void *data) {
1458 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
1466 #if KMP_HANDLE_SIGNALS
1468 static void __kmp_stg_parse_handle_signals(
char const *name,
char const *value,
1470 __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
1473 static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1474 char const *name,
void *data) {
1475 __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
1485 #define KMP_STG_X_DEBUG(x) \
1486 static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1488 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1490 static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1491 char const *name, void *data) { \
1492 __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1502 #undef KMP_STG_X_DEBUG
1504 static void __kmp_stg_parse_debug(
char const *name,
char const *value,
1507 __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1508 if (kmp_a_debug < debug) {
1509 kmp_a_debug = debug;
1511 if (kmp_b_debug < debug) {
1512 kmp_b_debug = debug;
1514 if (kmp_c_debug < debug) {
1515 kmp_c_debug = debug;
1517 if (kmp_d_debug < debug) {
1518 kmp_d_debug = debug;
1520 if (kmp_e_debug < debug) {
1521 kmp_e_debug = debug;
1523 if (kmp_f_debug < debug) {
1524 kmp_f_debug = debug;
1528 static void __kmp_stg_parse_debug_buf(
char const *name,
char const *value,
1530 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1534 if (__kmp_debug_buf) {
1536 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
1539 __kmp_debug_buffer = (
char *)__kmp_page_allocate(elements *
sizeof(
char));
1540 for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1541 __kmp_debug_buffer[i] =
'\0';
1543 __kmp_debug_count = 0;
1545 K_DIAG(1, (
"__kmp_debug_buf = %d\n", __kmp_debug_buf));
1548 static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer,
char const *name,
1550 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
1553 static void __kmp_stg_parse_debug_buf_atomic(
char const *name,
1554 char const *value,
void *data) {
1555 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
1558 static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1559 char const *name,
void *data) {
1560 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
1563 static void __kmp_stg_parse_debug_buf_chars(
char const *name,
char const *value,
1565 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1566 &__kmp_debug_buf_chars);
1569 static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1570 char const *name,
void *data) {
1571 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
1574 static void __kmp_stg_parse_debug_buf_lines(
char const *name,
char const *value,
1576 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1577 &__kmp_debug_buf_lines);
1580 static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1581 char const *name,
void *data) {
1582 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
1585 static void __kmp_stg_parse_diag(
char const *name,
char const *value,
1587 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
1590 static void __kmp_stg_print_diag(kmp_str_buf_t *buffer,
char const *name,
1592 __kmp_stg_print_int(buffer, name, kmp_diag);
1600 static void __kmp_stg_parse_align_alloc(
char const *name,
char const *value,
1602 __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1603 &__kmp_align_alloc, 1);
1606 static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer,
char const *name,
1608 __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
1617 static void __kmp_stg_parse_barrier_branch_bit(
char const *name,
1618 char const *value,
void *data) {
1622 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1623 var = __kmp_barrier_branch_bit_env_name[i];
1624 if ((strcmp(var, name) == 0) && (value != 0)) {
1627 comma = CCAST(
char *, strchr(value,
','));
1628 __kmp_barrier_gather_branch_bits[i] =
1629 (kmp_uint32)__kmp_str_to_int(value,
',');
1631 if (comma == NULL) {
1632 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1634 __kmp_barrier_release_branch_bits[i] =
1635 (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
1637 if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1638 __kmp_msg(kmp_ms_warning,
1639 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1641 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1644 if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1645 KMP_WARNING(BarrGatherValueInvalid, name, value);
1646 KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1647 __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1650 K_DIAG(1, (
"%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1651 __kmp_barrier_gather_branch_bits[i],
1652 __kmp_barrier_release_branch_bits[i]))
1656 static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1657 char const *name,
void *data) {
1659 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1660 var = __kmp_barrier_branch_bit_env_name[i];
1661 if (strcmp(var, name) == 0) {
1662 if (__kmp_env_format) {
1663 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1665 __kmp_str_buf_print(buffer,
" %s='",
1666 __kmp_barrier_branch_bit_env_name[i]);
1668 __kmp_str_buf_print(buffer,
"%d,%d'\n",
1669 __kmp_barrier_gather_branch_bits[i],
1670 __kmp_barrier_release_branch_bits[i]);
1682 static void __kmp_stg_parse_barrier_pattern(
char const *name,
char const *value,
1687 static int dist_req = 0, non_dist_req = 0;
1688 static bool warn = 1;
1689 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1690 var = __kmp_barrier_pattern_env_name[i];
1692 if ((strcmp(var, name) == 0) && (value != 0)) {
1694 char *comma = CCAST(
char *, strchr(value,
','));
1697 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1698 if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1700 if (j == bp_dist_bar) {
1705 __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1709 if (j == bp_last_bar) {
1710 KMP_WARNING(BarrGatherValueInvalid, name, value);
1711 KMP_INFORM(Using_str_Value, name,
1712 __kmp_barrier_pattern_name[bp_linear_bar]);
1716 if (comma != NULL) {
1717 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1718 if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1719 if (j == bp_dist_bar) {
1724 __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1728 if (j == bp_last_bar) {
1729 __kmp_msg(kmp_ms_warning,
1730 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1732 KMP_INFORM(Using_str_Value, name,
1733 __kmp_barrier_pattern_name[bp_linear_bar]);
1738 if ((dist_req == 0) && (non_dist_req != 0)) {
1740 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1741 if (__kmp_barrier_release_pattern[i] == bp_dist_bar)
1742 __kmp_barrier_release_pattern[i] = bp_hyper_bar;
1743 if (__kmp_barrier_gather_pattern[i] == bp_dist_bar)
1744 __kmp_barrier_gather_pattern[i] = bp_hyper_bar;
1746 }
else if (non_dist_req != 0) {
1748 if (non_dist_req > 0 && dist_req > 0 && warn) {
1749 KMP_INFORM(BarrierPatternOverride, name,
1750 __kmp_barrier_pattern_name[bp_dist_bar]);
1753 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1754 if (__kmp_barrier_release_pattern[i] != bp_dist_bar)
1755 __kmp_barrier_release_pattern[i] = bp_dist_bar;
1756 if (__kmp_barrier_gather_pattern[i] != bp_dist_bar)
1757 __kmp_barrier_gather_pattern[i] = bp_dist_bar;
1762 static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1763 char const *name,
void *data) {
1765 for (
int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1766 var = __kmp_barrier_pattern_env_name[i];
1767 if (strcmp(var, name) == 0) {
1768 int j = __kmp_barrier_gather_pattern[i];
1769 int k = __kmp_barrier_release_pattern[i];
1770 if (__kmp_env_format) {
1771 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1773 __kmp_str_buf_print(buffer,
" %s='",
1774 __kmp_barrier_pattern_env_name[i]);
1776 KMP_DEBUG_ASSERT(j < bp_last_bar && k < bp_last_bar);
1777 __kmp_str_buf_print(buffer,
"%s,%s'\n", __kmp_barrier_pattern_name[j],
1778 __kmp_barrier_pattern_name[k]);
1786 static void __kmp_stg_parse_abort_delay(
char const *name,
char const *value,
1790 int delay = __kmp_abort_delay / 1000;
1791 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1792 __kmp_abort_delay = delay * 1000;
1795 static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer,
char const *name,
1797 __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
1803 static void __kmp_stg_parse_cpuinfo_file(
char const *name,
char const *value,
1805 #if KMP_AFFINITY_SUPPORTED
1806 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1807 K_DIAG(1, (
"__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1811 static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1812 char const *name,
void *data) {
1813 #if KMP_AFFINITY_SUPPORTED
1814 if (__kmp_env_format) {
1815 KMP_STR_BUF_PRINT_NAME;
1817 __kmp_str_buf_print(buffer,
" %s", name);
1819 if (__kmp_cpuinfo_file) {
1820 __kmp_str_buf_print(buffer,
"='%s'\n", __kmp_cpuinfo_file);
1822 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
1830 static void __kmp_stg_parse_force_reduction(
char const *name,
char const *value,
1832 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1835 rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1839 if (reduction->force) {
1841 if (__kmp_str_match(
"critical", 0, value))
1842 __kmp_force_reduction_method = critical_reduce_block;
1843 else if (__kmp_str_match(
"atomic", 0, value))
1844 __kmp_force_reduction_method = atomic_reduce_block;
1845 else if (__kmp_str_match(
"tree", 0, value))
1846 __kmp_force_reduction_method = tree_reduce_block;
1848 KMP_FATAL(UnknownForceReduction, name, value);
1852 __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1853 if (__kmp_determ_red) {
1854 __kmp_force_reduction_method = tree_reduce_block;
1856 __kmp_force_reduction_method = reduction_method_not_defined;
1859 K_DIAG(1, (
"__kmp_force_reduction_method == %d\n",
1860 __kmp_force_reduction_method));
1863 static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1864 char const *name,
void *data) {
1866 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1867 if (reduction->force) {
1868 if (__kmp_force_reduction_method == critical_reduce_block) {
1869 __kmp_stg_print_str(buffer, name,
"critical");
1870 }
else if (__kmp_force_reduction_method == atomic_reduce_block) {
1871 __kmp_stg_print_str(buffer, name,
"atomic");
1872 }
else if (__kmp_force_reduction_method == tree_reduce_block) {
1873 __kmp_stg_print_str(buffer, name,
"tree");
1875 if (__kmp_env_format) {
1876 KMP_STR_BUF_PRINT_NAME;
1878 __kmp_str_buf_print(buffer,
" %s", name);
1880 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
1883 __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1891 static void __kmp_stg_parse_storage_map(
char const *name,
char const *value,
1893 if (__kmp_str_match(
"verbose", 1, value)) {
1894 __kmp_storage_map = TRUE;
1895 __kmp_storage_map_verbose = TRUE;
1896 __kmp_storage_map_verbose_specified = TRUE;
1899 __kmp_storage_map_verbose = FALSE;
1900 __kmp_stg_parse_bool(name, value, &__kmp_storage_map);
1904 static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer,
char const *name,
1906 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1907 __kmp_stg_print_str(buffer, name,
"verbose");
1909 __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1916 static void __kmp_stg_parse_all_threadprivate(
char const *name,
1917 char const *value,
void *data) {
1918 __kmp_stg_parse_int(name, value,
1919 __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1920 __kmp_max_nth, &__kmp_tp_capacity);
1923 static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1924 char const *name,
void *data) {
1925 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
1931 static void __kmp_stg_parse_foreign_threads_threadprivate(
char const *name,
1934 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
1937 static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
1940 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
1946 #if KMP_AFFINITY_SUPPORTED
1948 static int __kmp_parse_affinity_proc_id_list(
const char *var,
const char *env,
1949 const char **nextEnv,
1951 const char *scan = env;
1952 const char *next = scan;
1958 int start, end, stride;
1962 if (*next ==
'\0') {
1973 if ((*next <
'0') || (*next >
'9')) {
1974 KMP_WARNING(AffSyntaxError, var);
1978 num = __kmp_str_to_int(scan, *next);
1979 KMP_ASSERT(num >= 0);
1997 if ((*next <
'0') || (*next >
'9')) {
1998 KMP_WARNING(AffSyntaxError, var);
2003 num = __kmp_str_to_int(scan, *next);
2004 KMP_ASSERT(num >= 0);
2017 if ((*next <
'0') || (*next >
'9')) {
2019 KMP_WARNING(AffSyntaxError, var);
2027 start = __kmp_str_to_int(scan, *next);
2028 KMP_ASSERT(start >= 0);
2047 if ((*next <
'0') || (*next >
'9')) {
2048 KMP_WARNING(AffSyntaxError, var);
2052 end = __kmp_str_to_int(scan, *next);
2053 KMP_ASSERT(end >= 0);
2070 if ((*next <
'0') || (*next >
'9')) {
2071 KMP_WARNING(AffSyntaxError, var);
2075 stride = __kmp_str_to_int(scan, *next);
2076 KMP_ASSERT(stride >= 0);
2082 KMP_WARNING(AffZeroStride, var);
2087 KMP_WARNING(AffStartGreaterEnd, var, start, end);
2092 KMP_WARNING(AffStrideLessZero, var, start, end);
2096 if ((end - start) / stride > 65536) {
2097 KMP_WARNING(AffRangeTooBig, var, end, start, stride);
2114 ptrdiff_t len = next - env;
2115 char *retlist = (
char *)__kmp_allocate((len + 1) *
sizeof(char));
2116 KMP_MEMCPY_S(retlist, (len + 1) *
sizeof(
char), env, len *
sizeof(
char));
2117 retlist[len] =
'\0';
2118 *proclist = retlist;
2125 static kmp_setting_t *__kmp_affinity_notype = NULL;
2127 static void __kmp_parse_affinity_env(
char const *name,
char const *value,
2128 enum affinity_type *out_type,
2129 char **out_proclist,
int *out_verbose,
2130 int *out_warn,
int *out_respect,
2131 kmp_hw_t *out_gran,
int *out_gran_levels,
2132 int *out_dups,
int *out_compact,
2134 char *buffer = NULL;
2151 KMP_ASSERT(value != NULL);
2153 if (TCR_4(__kmp_init_middle)) {
2154 KMP_WARNING(EnvMiddleWarn, name);
2155 __kmp_env_toPrint(name, 0);
2158 __kmp_env_toPrint(name, 1);
2161 __kmp_str_format(
"%s", value);
2171 #define EMIT_WARN(skip, errlist) \
2175 SKIP_TO(next, ','); \
2179 KMP_WARNING errlist; \
2188 #define _set_param(_guard, _var, _val) \
2190 if (_guard == 0) { \
2193 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2198 #define set_type(val) _set_param(type, *out_type, val)
2199 #define set_verbose(val) _set_param(verbose, *out_verbose, val)
2200 #define set_warnings(val) _set_param(warnings, *out_warn, val)
2201 #define set_respect(val) _set_param(respect, *out_respect, val)
2202 #define set_dups(val) _set_param(dups, *out_dups, val)
2203 #define set_proclist(val) _set_param(proclist, *out_proclist, val)
2205 #define set_gran(val, levels) \
2209 *out_gran_levels = levels; \
2211 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2216 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
2217 (__kmp_nested_proc_bind.used > 0));
2219 while (*buf !=
'\0') {
2222 if (__kmp_match_str(
"none", buf, CCAST(
const char **, &next))) {
2223 set_type(affinity_none);
2224 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2226 }
else if (__kmp_match_str(
"scatter", buf, CCAST(
const char **, &next))) {
2227 set_type(affinity_scatter);
2228 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2230 }
else if (__kmp_match_str(
"compact", buf, CCAST(
const char **, &next))) {
2231 set_type(affinity_compact);
2232 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2234 }
else if (__kmp_match_str(
"logical", buf, CCAST(
const char **, &next))) {
2235 set_type(affinity_logical);
2236 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2238 }
else if (__kmp_match_str(
"physical", buf, CCAST(
const char **, &next))) {
2239 set_type(affinity_physical);
2240 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2242 }
else if (__kmp_match_str(
"explicit", buf, CCAST(
const char **, &next))) {
2243 set_type(affinity_explicit);
2244 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2246 }
else if (__kmp_match_str(
"balanced", buf, CCAST(
const char **, &next))) {
2247 set_type(affinity_balanced);
2248 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2250 }
else if (__kmp_match_str(
"disabled", buf, CCAST(
const char **, &next))) {
2251 set_type(affinity_disabled);
2252 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2254 }
else if (__kmp_match_str(
"verbose", buf, CCAST(
const char **, &next))) {
2257 }
else if (__kmp_match_str(
"noverbose", buf, CCAST(
const char **, &next))) {
2260 }
else if (__kmp_match_str(
"warnings", buf, CCAST(
const char **, &next))) {
2263 }
else if (__kmp_match_str(
"nowarnings", buf,
2264 CCAST(
const char **, &next))) {
2265 set_warnings(FALSE);
2267 }
else if (__kmp_match_str(
"respect", buf, CCAST(
const char **, &next))) {
2270 }
else if (__kmp_match_str(
"norespect", buf, CCAST(
const char **, &next))) {
2273 }
else if (__kmp_match_str(
"duplicates", buf,
2274 CCAST(
const char **, &next)) ||
2275 __kmp_match_str(
"dups", buf, CCAST(
const char **, &next))) {
2278 }
else if (__kmp_match_str(
"noduplicates", buf,
2279 CCAST(
const char **, &next)) ||
2280 __kmp_match_str(
"nodups", buf, CCAST(
const char **, &next))) {
2283 }
else if (__kmp_match_str(
"granularity", buf,
2284 CCAST(
const char **, &next)) ||
2285 __kmp_match_str(
"gran", buf, CCAST(
const char **, &next))) {
2288 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2297 KMP_FOREACH_HW_TYPE(type) {
2298 const char *name = __kmp_hw_get_keyword(type);
2299 if (__kmp_match_str(name, buf, CCAST(
const char **, &next))) {
2308 if (__kmp_match_str(
"fine", buf, CCAST(
const char **, &next))) {
2309 set_gran(KMP_HW_THREAD, -1);
2312 }
else if (__kmp_match_str(
"package", buf,
2313 CCAST(
const char **, &next))) {
2314 set_gran(KMP_HW_SOCKET, -1);
2317 }
else if (__kmp_match_str(
"node", buf, CCAST(
const char **, &next))) {
2318 set_gran(KMP_HW_NUMA, -1);
2321 #if KMP_GROUP_AFFINITY
2322 }
else if (__kmp_match_str(
"group", buf, CCAST(
const char **, &next))) {
2323 set_gran(KMP_HW_PROC_GROUP, -1);
2327 }
else if ((*buf >=
'0') && (*buf <=
'9')) {
2331 n = __kmp_str_to_int(buf, *next);
2334 set_gran(KMP_HW_UNKNOWN, n);
2337 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2341 }
else if (__kmp_match_str(
"proclist", buf, CCAST(
const char **, &next))) {
2342 char *temp_proclist;
2346 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2352 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2357 if (!__kmp_parse_affinity_proc_id_list(
2358 name, buf, CCAST(
const char **, &next), &temp_proclist)) {
2370 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2374 set_proclist(temp_proclist);
2375 }
else if ((*buf >=
'0') && (*buf <=
'9')) {
2380 n = __kmp_str_to_int(buf, *next);
2386 KMP_WARNING(AffManyParams, name, start);
2390 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2398 }
else if (*next !=
'\0') {
2399 const char *temp = next;
2400 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2412 #undef set_granularity
2414 __kmp_str_free(&buffer);
2418 KMP_WARNING(AffProcListNoType, name);
2419 *out_type = affinity_explicit;
2420 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2421 }
else if (*out_type != affinity_explicit) {
2422 KMP_WARNING(AffProcListNotExplicit, name);
2423 KMP_ASSERT(*out_proclist != NULL);
2424 KMP_INTERNAL_FREE(*out_proclist);
2425 *out_proclist = NULL;
2428 switch (*out_type) {
2429 case affinity_logical:
2430 case affinity_physical: {
2432 *out_offset = number[0];
2435 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
2438 case affinity_balanced: {
2440 *out_compact = number[0];
2443 *out_offset = number[1];
2446 if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
2447 #if KMP_MIC_SUPPORTED
2448 if (__kmp_mic_type != non_mic) {
2449 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2450 KMP_WARNING(AffGranUsing,
"KMP_AFFINITY",
"fine");
2452 __kmp_affinity_gran = KMP_HW_THREAD;
2456 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2457 KMP_WARNING(AffGranUsing,
"KMP_AFFINITY",
"core");
2459 __kmp_affinity_gran = KMP_HW_CORE;
2463 case affinity_scatter:
2464 case affinity_compact: {
2466 *out_compact = number[0];
2469 *out_offset = number[1];
2472 case affinity_explicit: {
2473 if (*out_proclist == NULL) {
2474 KMP_WARNING(AffNoProcList, name);
2475 __kmp_affinity_type = affinity_none;
2478 KMP_WARNING(AffNoParam, name,
"explicit");
2481 case affinity_none: {
2483 KMP_WARNING(AffNoParam, name,
"none");
2486 case affinity_disabled: {
2488 KMP_WARNING(AffNoParam, name,
"disabled");
2491 case affinity_default: {
2493 KMP_WARNING(AffNoParam, name,
"default");
2502 static void __kmp_stg_parse_affinity(
char const *name,
char const *value,
2504 kmp_setting_t **rivals = (kmp_setting_t **)data;
2507 rc = __kmp_stg_check_rivals(name, value, rivals);
2512 __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2513 &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2514 &__kmp_affinity_warnings,
2515 &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2516 &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2517 &__kmp_affinity_compact, &__kmp_affinity_offset);
2521 static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer,
char const *name,
2523 if (__kmp_env_format) {
2524 KMP_STR_BUF_PRINT_NAME_EX(name);
2526 __kmp_str_buf_print(buffer,
" %s='", name);
2528 if (__kmp_affinity_verbose) {
2529 __kmp_str_buf_print(buffer,
"%s,",
"verbose");
2531 __kmp_str_buf_print(buffer,
"%s,",
"noverbose");
2533 if (__kmp_affinity_warnings) {
2534 __kmp_str_buf_print(buffer,
"%s,",
"warnings");
2536 __kmp_str_buf_print(buffer,
"%s,",
"nowarnings");
2538 if (KMP_AFFINITY_CAPABLE()) {
2539 if (__kmp_affinity_respect_mask) {
2540 __kmp_str_buf_print(buffer,
"%s,",
"respect");
2542 __kmp_str_buf_print(buffer,
"%s,",
"norespect");
2544 __kmp_str_buf_print(buffer,
"granularity=%s,",
2545 __kmp_hw_get_keyword(__kmp_affinity_gran,
false));
2547 if (!KMP_AFFINITY_CAPABLE()) {
2548 __kmp_str_buf_print(buffer,
"%s",
"disabled");
2550 switch (__kmp_affinity_type) {
2552 __kmp_str_buf_print(buffer,
"%s",
"none");
2554 case affinity_physical:
2555 __kmp_str_buf_print(buffer,
"%s,%d",
"physical", __kmp_affinity_offset);
2557 case affinity_logical:
2558 __kmp_str_buf_print(buffer,
"%s,%d",
"logical", __kmp_affinity_offset);
2560 case affinity_compact:
2561 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"compact", __kmp_affinity_compact,
2562 __kmp_affinity_offset);
2564 case affinity_scatter:
2565 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"scatter", __kmp_affinity_compact,
2566 __kmp_affinity_offset);
2568 case affinity_explicit:
2569 __kmp_str_buf_print(buffer,
"%s=[%s],%s",
"proclist",
2570 __kmp_affinity_proclist,
"explicit");
2572 case affinity_balanced:
2573 __kmp_str_buf_print(buffer,
"%s,%d,%d",
"balanced",
2574 __kmp_affinity_compact, __kmp_affinity_offset);
2576 case affinity_disabled:
2577 __kmp_str_buf_print(buffer,
"%s",
"disabled");
2579 case affinity_default:
2580 __kmp_str_buf_print(buffer,
"%s",
"default");
2583 __kmp_str_buf_print(buffer,
"%s",
"<unknown>");
2586 __kmp_str_buf_print(buffer,
"'\n");
2589 #ifdef KMP_GOMP_COMPAT
2591 static void __kmp_stg_parse_gomp_cpu_affinity(
char const *name,
2592 char const *value,
void *data) {
2593 const char *next = NULL;
2594 char *temp_proclist;
2595 kmp_setting_t **rivals = (kmp_setting_t **)data;
2598 rc = __kmp_stg_check_rivals(name, value, rivals);
2603 if (TCR_4(__kmp_init_middle)) {
2604 KMP_WARNING(EnvMiddleWarn, name);
2605 __kmp_env_toPrint(name, 0);
2609 __kmp_env_toPrint(name, 1);
2611 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2613 if (*next ==
'\0') {
2615 __kmp_affinity_proclist = temp_proclist;
2616 __kmp_affinity_type = affinity_explicit;
2617 __kmp_affinity_gran = KMP_HW_THREAD;
2618 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2620 KMP_WARNING(AffSyntaxError, name);
2621 if (temp_proclist != NULL) {
2622 KMP_INTERNAL_FREE((
void *)temp_proclist);
2627 __kmp_affinity_type = affinity_none;
2628 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2655 static inline void __kmp_omp_places_syntax_warn(
const char *var) {
2656 KMP_WARNING(SyntaxErrorUsing, var,
"\"cores\"");
2659 static int __kmp_parse_subplace_list(
const char *var,
const char **scan) {
2663 int start, count, stride;
2669 if ((**scan <
'0') || (**scan >
'9')) {
2670 __kmp_omp_places_syntax_warn(var);
2675 start = __kmp_str_to_int(*scan, *next);
2676 KMP_ASSERT(start >= 0);
2681 if (**scan ==
'}') {
2684 if (**scan ==
',') {
2688 if (**scan !=
':') {
2689 __kmp_omp_places_syntax_warn(var);
2696 if ((**scan <
'0') || (**scan >
'9')) {
2697 __kmp_omp_places_syntax_warn(var);
2702 count = __kmp_str_to_int(*scan, *next);
2703 KMP_ASSERT(count >= 0);
2708 if (**scan ==
'}') {
2711 if (**scan ==
',') {
2715 if (**scan !=
':') {
2716 __kmp_omp_places_syntax_warn(var);
2725 if (**scan ==
'+') {
2729 if (**scan ==
'-') {
2737 if ((**scan <
'0') || (**scan >
'9')) {
2738 __kmp_omp_places_syntax_warn(var);
2743 stride = __kmp_str_to_int(*scan, *next);
2744 KMP_ASSERT(stride >= 0);
2750 if (**scan ==
'}') {
2753 if (**scan ==
',') {
2758 __kmp_omp_places_syntax_warn(var);
2764 static int __kmp_parse_place(
const char *var,
const char **scan) {
2769 if (**scan ==
'{') {
2771 if (!__kmp_parse_subplace_list(var, scan)) {
2774 if (**scan !=
'}') {
2775 __kmp_omp_places_syntax_warn(var);
2779 }
else if (**scan ==
'!') {
2781 return __kmp_parse_place(var, scan);
2782 }
else if ((**scan >=
'0') && (**scan <=
'9')) {
2785 int proc = __kmp_str_to_int(*scan, *next);
2786 KMP_ASSERT(proc >= 0);
2789 __kmp_omp_places_syntax_warn(var);
2795 static int __kmp_parse_place_list(
const char *var,
const char *env,
2796 char **place_list) {
2797 const char *scan = env;
2798 const char *next = scan;
2803 if (!__kmp_parse_place(var, &scan)) {
2809 if (*scan ==
'\0') {
2817 __kmp_omp_places_syntax_warn(var);
2824 if ((*scan <
'0') || (*scan >
'9')) {
2825 __kmp_omp_places_syntax_warn(var);
2830 count = __kmp_str_to_int(scan, *next);
2831 KMP_ASSERT(count >= 0);
2836 if (*scan ==
'\0') {
2844 __kmp_omp_places_syntax_warn(var);
2865 if ((*scan <
'0') || (*scan >
'9')) {
2866 __kmp_omp_places_syntax_warn(var);
2871 stride = __kmp_str_to_int(scan, *next);
2872 KMP_ASSERT(stride >= 0);
2878 if (*scan ==
'\0') {
2886 __kmp_omp_places_syntax_warn(var);
2891 ptrdiff_t len = scan - env;
2892 char *retlist = (
char *)__kmp_allocate((len + 1) *
sizeof(char));
2893 KMP_MEMCPY_S(retlist, (len + 1) *
sizeof(
char), env, len *
sizeof(
char));
2894 retlist[len] =
'\0';
2895 *place_list = retlist;
2900 static void __kmp_stg_parse_places(
char const *name,
char const *value,
2902 struct kmp_place_t {
2908 const char *scan = value;
2909 const char *next = scan;
2910 const char *kind =
"\"threads\"";
2911 kmp_place_t std_places[] = {{
"threads", KMP_HW_THREAD},
2912 {
"cores", KMP_HW_CORE},
2913 {
"numa_domains", KMP_HW_NUMA},
2914 {
"ll_caches", KMP_HW_LLC},
2915 {
"sockets", KMP_HW_SOCKET}};
2916 kmp_setting_t **rivals = (kmp_setting_t **)data;
2919 rc = __kmp_stg_check_rivals(name, value, rivals);
2925 for (
size_t i = 0; i <
sizeof(std_places) /
sizeof(std_places[0]); ++i) {
2926 const kmp_place_t &place = std_places[i];
2927 if (__kmp_match_str(place.name, scan, &next)) {
2929 __kmp_affinity_type = affinity_compact;
2930 __kmp_affinity_gran = place.type;
2931 __kmp_affinity_dups = FALSE;
2938 KMP_FOREACH_HW_TYPE(type) {
2939 const char *name = __kmp_hw_get_keyword(type,
true);
2940 if (__kmp_match_str(
"unknowns", scan, &next))
2942 if (__kmp_match_str(name, scan, &next)) {
2944 __kmp_affinity_type = affinity_compact;
2945 __kmp_affinity_gran = type;
2946 __kmp_affinity_dups = FALSE;
2953 if (__kmp_affinity_proclist != NULL) {
2954 KMP_INTERNAL_FREE((
void *)__kmp_affinity_proclist);
2955 __kmp_affinity_proclist = NULL;
2957 if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2958 __kmp_affinity_type = affinity_explicit;
2959 __kmp_affinity_gran = KMP_HW_THREAD;
2960 __kmp_affinity_dups = FALSE;
2963 __kmp_affinity_type = affinity_compact;
2964 __kmp_affinity_gran = KMP_HW_CORE;
2965 __kmp_affinity_dups = FALSE;
2967 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2968 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2972 if (__kmp_affinity_gran != KMP_HW_UNKNOWN) {
2973 kind = __kmp_hw_get_keyword(__kmp_affinity_gran);
2976 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2977 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2981 if (*scan ==
'\0') {
2987 KMP_WARNING(SyntaxErrorUsing, name, kind);
2995 count = __kmp_str_to_int(scan, *next);
2996 KMP_ASSERT(count >= 0);
3001 KMP_WARNING(SyntaxErrorUsing, name, kind);
3007 if (*scan !=
'\0') {
3008 KMP_WARNING(ParseExtraCharsWarn, name, scan);
3010 __kmp_affinity_num_places = count;
3013 static void __kmp_stg_print_places(kmp_str_buf_t *buffer,
char const *name,
3015 if (__kmp_env_format) {
3016 KMP_STR_BUF_PRINT_NAME;
3018 __kmp_str_buf_print(buffer,
" %s", name);
3020 if ((__kmp_nested_proc_bind.used == 0) ||
3021 (__kmp_nested_proc_bind.bind_types == NULL) ||
3022 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
3023 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3024 }
else if (__kmp_affinity_type == affinity_explicit) {
3025 if (__kmp_affinity_proclist != NULL) {
3026 __kmp_str_buf_print(buffer,
"='%s'\n", __kmp_affinity_proclist);
3028 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3030 }
else if (__kmp_affinity_type == affinity_compact) {
3032 if (__kmp_affinity_num_masks > 0) {
3033 num = __kmp_affinity_num_masks;
3034 }
else if (__kmp_affinity_num_places > 0) {
3035 num = __kmp_affinity_num_places;
3039 if (__kmp_affinity_gran != KMP_HW_UNKNOWN) {
3040 const char *name = __kmp_hw_get_keyword(__kmp_affinity_gran,
true);
3042 __kmp_str_buf_print(buffer,
"='%s(%d)'\n", name, num);
3044 __kmp_str_buf_print(buffer,
"='%s'\n", name);
3047 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3050 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3054 static void __kmp_stg_parse_topology_method(
char const *name,
char const *value,
3056 if (__kmp_str_match(
"all", 1, value)) {
3057 __kmp_affinity_top_method = affinity_top_method_all;
3060 else if (__kmp_str_match(
"hwloc", 1, value)) {
3061 __kmp_affinity_top_method = affinity_top_method_hwloc;
3064 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3065 else if (__kmp_str_match(
"cpuid_leaf31", 12, value) ||
3066 __kmp_str_match(
"cpuid 1f", 8, value) ||
3067 __kmp_str_match(
"cpuid 31", 8, value) ||
3068 __kmp_str_match(
"cpuid1f", 7, value) ||
3069 __kmp_str_match(
"cpuid31", 7, value) ||
3070 __kmp_str_match(
"leaf 1f", 7, value) ||
3071 __kmp_str_match(
"leaf 31", 7, value) ||
3072 __kmp_str_match(
"leaf1f", 6, value) ||
3073 __kmp_str_match(
"leaf31", 6, value)) {
3074 __kmp_affinity_top_method = affinity_top_method_x2apicid_1f;
3075 }
else if (__kmp_str_match(
"x2apic id", 9, value) ||
3076 __kmp_str_match(
"x2apic_id", 9, value) ||
3077 __kmp_str_match(
"x2apic-id", 9, value) ||
3078 __kmp_str_match(
"x2apicid", 8, value) ||
3079 __kmp_str_match(
"cpuid leaf 11", 13, value) ||
3080 __kmp_str_match(
"cpuid_leaf_11", 13, value) ||
3081 __kmp_str_match(
"cpuid-leaf-11", 13, value) ||
3082 __kmp_str_match(
"cpuid leaf11", 12, value) ||
3083 __kmp_str_match(
"cpuid_leaf11", 12, value) ||
3084 __kmp_str_match(
"cpuid-leaf11", 12, value) ||
3085 __kmp_str_match(
"cpuidleaf 11", 12, value) ||
3086 __kmp_str_match(
"cpuidleaf_11", 12, value) ||
3087 __kmp_str_match(
"cpuidleaf-11", 12, value) ||
3088 __kmp_str_match(
"cpuidleaf11", 11, value) ||
3089 __kmp_str_match(
"cpuid 11", 8, value) ||
3090 __kmp_str_match(
"cpuid_11", 8, value) ||
3091 __kmp_str_match(
"cpuid-11", 8, value) ||
3092 __kmp_str_match(
"cpuid11", 7, value) ||
3093 __kmp_str_match(
"leaf 11", 7, value) ||
3094 __kmp_str_match(
"leaf_11", 7, value) ||
3095 __kmp_str_match(
"leaf-11", 7, value) ||
3096 __kmp_str_match(
"leaf11", 6, value)) {
3097 __kmp_affinity_top_method = affinity_top_method_x2apicid;
3098 }
else if (__kmp_str_match(
"apic id", 7, value) ||
3099 __kmp_str_match(
"apic_id", 7, value) ||
3100 __kmp_str_match(
"apic-id", 7, value) ||
3101 __kmp_str_match(
"apicid", 6, value) ||
3102 __kmp_str_match(
"cpuid leaf 4", 12, value) ||
3103 __kmp_str_match(
"cpuid_leaf_4", 12, value) ||
3104 __kmp_str_match(
"cpuid-leaf-4", 12, value) ||
3105 __kmp_str_match(
"cpuid leaf4", 11, value) ||
3106 __kmp_str_match(
"cpuid_leaf4", 11, value) ||
3107 __kmp_str_match(
"cpuid-leaf4", 11, value) ||
3108 __kmp_str_match(
"cpuidleaf 4", 11, value) ||
3109 __kmp_str_match(
"cpuidleaf_4", 11, value) ||
3110 __kmp_str_match(
"cpuidleaf-4", 11, value) ||
3111 __kmp_str_match(
"cpuidleaf4", 10, value) ||
3112 __kmp_str_match(
"cpuid 4", 7, value) ||
3113 __kmp_str_match(
"cpuid_4", 7, value) ||
3114 __kmp_str_match(
"cpuid-4", 7, value) ||
3115 __kmp_str_match(
"cpuid4", 6, value) ||
3116 __kmp_str_match(
"leaf 4", 6, value) ||
3117 __kmp_str_match(
"leaf_4", 6, value) ||
3118 __kmp_str_match(
"leaf-4", 6, value) ||
3119 __kmp_str_match(
"leaf4", 5, value)) {
3120 __kmp_affinity_top_method = affinity_top_method_apicid;
3123 else if (__kmp_str_match(
"/proc/cpuinfo", 2, value) ||
3124 __kmp_str_match(
"cpuinfo", 5, value)) {
3125 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
3127 #if KMP_GROUP_AFFINITY
3128 else if (__kmp_str_match(
"group", 1, value)) {
3129 __kmp_affinity_top_method = affinity_top_method_group;
3132 else if (__kmp_str_match(
"flat", 1, value)) {
3133 __kmp_affinity_top_method = affinity_top_method_flat;
3135 KMP_WARNING(StgInvalidValue, name, value);
3139 static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
3140 char const *name,
void *data) {
3141 char const *value = NULL;
3143 switch (__kmp_affinity_top_method) {
3144 case affinity_top_method_default:
3148 case affinity_top_method_all:
3152 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3153 case affinity_top_method_x2apicid_1f:
3154 value =
"x2APIC id leaf 0x1f";
3157 case affinity_top_method_x2apicid:
3158 value =
"x2APIC id leaf 0xb";
3161 case affinity_top_method_apicid:
3167 case affinity_top_method_hwloc:
3172 case affinity_top_method_cpuinfo:
3176 #if KMP_GROUP_AFFINITY
3177 case affinity_top_method_group:
3182 case affinity_top_method_flat:
3187 if (value != NULL) {
3188 __kmp_stg_print_str(buffer, name, value);
3196 static void __kmp_stg_parse_proc_bind(
char const *name,
char const *value,
3198 kmp_setting_t **rivals = (kmp_setting_t **)data;
3201 rc = __kmp_stg_check_rivals(name, value, rivals);
3207 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
3208 (__kmp_nested_proc_bind.used > 0));
3210 const char *buf = value;
3214 if ((*buf >=
'0') && (*buf <=
'9')) {
3217 num = __kmp_str_to_int(buf, *next);
3218 KMP_ASSERT(num >= 0);
3226 if (__kmp_match_str(
"disabled", buf, &next)) {
3229 #if KMP_AFFINITY_SUPPORTED
3230 __kmp_affinity_type = affinity_disabled;
3232 __kmp_nested_proc_bind.used = 1;
3233 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3234 }
else if ((num == (
int)proc_bind_false) ||
3235 __kmp_match_str(
"false", buf, &next)) {
3238 #if KMP_AFFINITY_SUPPORTED
3239 __kmp_affinity_type = affinity_none;
3241 __kmp_nested_proc_bind.used = 1;
3242 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3243 }
else if ((num == (
int)proc_bind_true) ||
3244 __kmp_match_str(
"true", buf, &next)) {
3247 __kmp_nested_proc_bind.used = 1;
3248 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3253 for (scan = buf; *scan !=
'\0'; scan++) {
3260 if (__kmp_nested_proc_bind.size < nelem) {
3261 __kmp_nested_proc_bind.bind_types =
3262 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3263 __kmp_nested_proc_bind.bind_types,
3264 sizeof(kmp_proc_bind_t) * nelem);
3265 if (__kmp_nested_proc_bind.bind_types == NULL) {
3266 KMP_FATAL(MemoryAllocFailed);
3268 __kmp_nested_proc_bind.size = nelem;
3270 __kmp_nested_proc_bind.used = nelem;
3272 if (nelem > 1 && !__kmp_dflt_max_active_levels_set)
3273 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
3278 enum kmp_proc_bind_t bind;
3280 if ((num == (
int)proc_bind_primary) ||
3281 __kmp_match_str(
"master", buf, &next) ||
3282 __kmp_match_str(
"primary", buf, &next)) {
3285 bind = proc_bind_primary;
3286 }
else if ((num == (
int)proc_bind_close) ||
3287 __kmp_match_str(
"close", buf, &next)) {
3290 bind = proc_bind_close;
3291 }
else if ((num == (
int)proc_bind_spread) ||
3292 __kmp_match_str(
"spread", buf, &next)) {
3295 bind = proc_bind_spread;
3297 KMP_WARNING(StgInvalidValue, name, value);
3298 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3299 __kmp_nested_proc_bind.used = 1;
3303 __kmp_nested_proc_bind.bind_types[i++] = bind;
3307 KMP_DEBUG_ASSERT(*buf ==
',');
3312 if ((*buf >=
'0') && (*buf <=
'9')) {
3315 num = __kmp_str_to_int(buf, *next);
3316 KMP_ASSERT(num >= 0);
3326 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3330 static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer,
char const *name,
3332 int nelem = __kmp_nested_proc_bind.used;
3333 if (__kmp_env_format) {
3334 KMP_STR_BUF_PRINT_NAME;
3336 __kmp_str_buf_print(buffer,
" %s", name);
3339 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
3342 __kmp_str_buf_print(buffer,
"='", name);
3343 for (i = 0; i < nelem; i++) {
3344 switch (__kmp_nested_proc_bind.bind_types[i]) {
3345 case proc_bind_false:
3346 __kmp_str_buf_print(buffer,
"false");
3349 case proc_bind_true:
3350 __kmp_str_buf_print(buffer,
"true");
3353 case proc_bind_primary:
3354 __kmp_str_buf_print(buffer,
"primary");
3357 case proc_bind_close:
3358 __kmp_str_buf_print(buffer,
"close");
3361 case proc_bind_spread:
3362 __kmp_str_buf_print(buffer,
"spread");
3365 case proc_bind_intel:
3366 __kmp_str_buf_print(buffer,
"intel");
3369 case proc_bind_default:
3370 __kmp_str_buf_print(buffer,
"default");
3373 if (i < nelem - 1) {
3374 __kmp_str_buf_print(buffer,
",");
3377 __kmp_str_buf_print(buffer,
"'\n");
3381 static void __kmp_stg_parse_display_affinity(
char const *name,
3382 char const *value,
void *data) {
3383 __kmp_stg_parse_bool(name, value, &__kmp_display_affinity);
3385 static void __kmp_stg_print_display_affinity(kmp_str_buf_t *buffer,
3386 char const *name,
void *data) {
3387 __kmp_stg_print_bool(buffer, name, __kmp_display_affinity);
3389 static void __kmp_stg_parse_affinity_format(
char const *name,
char const *value,
3391 size_t length = KMP_STRLEN(value);
3392 __kmp_strncpy_truncate(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, value,
3395 static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer,
3396 char const *name,
void *data) {
3397 if (__kmp_env_format) {
3398 KMP_STR_BUF_PRINT_NAME_EX(name);
3400 __kmp_str_buf_print(buffer,
" %s='", name);
3402 __kmp_str_buf_print(buffer,
"%s'\n", __kmp_affinity_format);
3424 static void __kmp_stg_parse_allocator(
char const *name,
char const *value,
3426 const char *buf = value;
3427 const char *next, *scan, *start;
3429 omp_allocator_handle_t al;
3430 omp_memspace_handle_t ms = omp_default_mem_space;
3431 bool is_memspace =
false;
3432 int ntraits = 0, count = 0;
3436 const char *delim = strchr(buf,
':');
3437 const char *predef_mem_space = strstr(buf,
"mem_space");
3439 bool is_memalloc = (!predef_mem_space && !delim) ?
true :
false;
3444 for (scan = buf; *scan !=
'\0'; scan++) {
3449 omp_alloctrait_t *traits =
3450 (omp_alloctrait_t *)KMP_ALLOCA(ntraits *
sizeof(omp_alloctrait_t));
3453 #define IS_POWER_OF_TWO(n) (((n) & ((n)-1)) == 0)
3455 #define GET_NEXT(sentinel) \
3458 if (*next == sentinel) \
3464 #define SKIP_PAIR(key) \
3466 char const str_delimiter[] = {',', 0}; \
3467 char *value = __kmp_str_token(CCAST(char *, scan), str_delimiter, \
3468 CCAST(char **, &next)); \
3469 KMP_WARNING(StgInvalidValue, key, value); \
3477 char const str_delimiter[] = {'=', 0}; \
3478 key = __kmp_str_token(CCAST(char *, start), str_delimiter, \
3479 CCAST(char **, &next)); \
3484 while (*next !=
'\0') {
3486 __kmp_match_str(
"fb_data", scan, &next)) {
3490 if (__kmp_match_str(
"omp_high_bw_mem_alloc", scan, &next)) {
3493 if (__kmp_memkind_available) {
3494 __kmp_def_allocator = omp_high_bw_mem_alloc;
3497 KMP_WARNING(OmpNoAllocator,
"omp_high_bw_mem_alloc");
3500 traits[count].key = omp_atk_fb_data;
3501 traits[count].value = RCAST(omp_uintptr_t, omp_high_bw_mem_alloc);
3503 }
else if (__kmp_match_str(
"omp_large_cap_mem_alloc", scan, &next)) {
3506 if (__kmp_memkind_available) {
3507 __kmp_def_allocator = omp_large_cap_mem_alloc;
3510 KMP_WARNING(OmpNoAllocator,
"omp_large_cap_mem_alloc");
3513 traits[count].key = omp_atk_fb_data;
3514 traits[count].value = RCAST(omp_uintptr_t, omp_large_cap_mem_alloc);
3516 }
else if (__kmp_match_str(
"omp_default_mem_alloc", scan, &next)) {
3520 traits[count].key = omp_atk_fb_data;
3521 traits[count].value = RCAST(omp_uintptr_t, omp_default_mem_alloc);
3523 }
else if (__kmp_match_str(
"omp_const_mem_alloc", scan, &next)) {
3526 KMP_WARNING(OmpNoAllocator,
"omp_const_mem_alloc");
3528 traits[count].key = omp_atk_fb_data;
3529 traits[count].value = RCAST(omp_uintptr_t, omp_const_mem_alloc);
3531 }
else if (__kmp_match_str(
"omp_low_lat_mem_alloc", scan, &next)) {
3534 KMP_WARNING(OmpNoAllocator,
"omp_low_lat_mem_alloc");
3536 traits[count].key = omp_atk_fb_data;
3537 traits[count].value = RCAST(omp_uintptr_t, omp_low_lat_mem_alloc);
3539 }
else if (__kmp_match_str(
"omp_cgroup_mem_alloc", scan, &next)) {
3542 KMP_WARNING(OmpNoAllocator,
"omp_cgroup_mem_alloc");
3544 traits[count].key = omp_atk_fb_data;
3545 traits[count].value = RCAST(omp_uintptr_t, omp_cgroup_mem_alloc);
3547 }
else if (__kmp_match_str(
"omp_pteam_mem_alloc", scan, &next)) {
3550 KMP_WARNING(OmpNoAllocator,
"omp_pteam_mem_alloc");
3552 traits[count].key = omp_atk_fb_data;
3553 traits[count].value = RCAST(omp_uintptr_t, omp_pteam_mem_alloc);
3555 }
else if (__kmp_match_str(
"omp_thread_mem_alloc", scan, &next)) {
3558 KMP_WARNING(OmpNoAllocator,
"omp_thread_mem_alloc");
3560 traits[count].key = omp_atk_fb_data;
3561 traits[count].value = RCAST(omp_uintptr_t, omp_thread_mem_alloc);
3571 __kmp_def_allocator = omp_default_mem_alloc;
3572 if (next == buf || *next !=
'\0') {
3574 KMP_WARNING(StgInvalidValue, name, value);
3579 if (count == ntraits)
3585 if (__kmp_match_str(
"omp_default_mem_space", scan, &next)) {
3587 ms = omp_default_mem_space;
3588 }
else if (__kmp_match_str(
"omp_large_cap_mem_space", scan, &next)) {
3590 ms = omp_large_cap_mem_space;
3591 }
else if (__kmp_match_str(
"omp_const_mem_space", scan, &next)) {
3593 ms = omp_const_mem_space;
3594 }
else if (__kmp_match_str(
"omp_high_bw_mem_space", scan, &next)) {
3596 ms = omp_high_bw_mem_space;
3597 }
else if (__kmp_match_str(
"omp_low_lat_mem_space", scan, &next)) {
3599 ms = omp_low_lat_mem_space;
3601 __kmp_def_allocator = omp_default_mem_alloc;
3602 if (next == buf || *next !=
'\0') {
3604 KMP_WARNING(StgInvalidValue, name, value);
3613 if (__kmp_match_str(
"sync_hint", scan, &next)) {
3615 traits[count].key = omp_atk_sync_hint;
3616 if (__kmp_match_str(
"contended", scan, &next)) {
3617 traits[count].value = omp_atv_contended;
3618 }
else if (__kmp_match_str(
"uncontended", scan, &next)) {
3619 traits[count].value = omp_atv_uncontended;
3620 }
else if (__kmp_match_str(
"serialized", scan, &next)) {
3621 traits[count].value = omp_atv_serialized;
3622 }
else if (__kmp_match_str(
"private", scan, &next)) {
3623 traits[count].value = omp_atv_private;
3629 }
else if (__kmp_match_str(
"alignment", scan, &next)) {
3631 if (!isdigit(*next)) {
3637 int n = __kmp_str_to_int(scan,
',');
3638 if (n < 0 || !IS_POWER_OF_TWO(n)) {
3643 traits[count].key = omp_atk_alignment;
3644 traits[count].value = n;
3645 }
else if (__kmp_match_str(
"access", scan, &next)) {
3647 traits[count].key = omp_atk_access;
3648 if (__kmp_match_str(
"all", scan, &next)) {
3649 traits[count].value = omp_atv_all;
3650 }
else if (__kmp_match_str(
"cgroup", scan, &next)) {
3651 traits[count].value = omp_atv_cgroup;
3652 }
else if (__kmp_match_str(
"pteam", scan, &next)) {
3653 traits[count].value = omp_atv_pteam;
3654 }
else if (__kmp_match_str(
"thread", scan, &next)) {
3655 traits[count].value = omp_atv_thread;
3661 }
else if (__kmp_match_str(
"pool_size", scan, &next)) {
3663 if (!isdigit(*next)) {
3669 int n = __kmp_str_to_int(scan,
',');
3675 traits[count].key = omp_atk_pool_size;
3676 traits[count].value = n;
3677 }
else if (__kmp_match_str(
"fallback", scan, &next)) {
3679 traits[count].key = omp_atk_fallback;
3680 if (__kmp_match_str(
"default_mem_fb", scan, &next)) {
3681 traits[count].value = omp_atv_default_mem_fb;
3682 }
else if (__kmp_match_str(
"null_fb", scan, &next)) {
3683 traits[count].value = omp_atv_null_fb;
3684 }
else if (__kmp_match_str(
"abort_fb", scan, &next)) {
3685 traits[count].value = omp_atv_abort_fb;
3686 }
else if (__kmp_match_str(
"allocator_fb", scan, &next)) {
3687 traits[count].value = omp_atv_allocator_fb;
3693 }
else if (__kmp_match_str(
"pinned", scan, &next)) {
3695 traits[count].key = omp_atk_pinned;
3696 if (__kmp_str_match_true(next)) {
3697 traits[count].value = omp_atv_true;
3698 }
else if (__kmp_str_match_false(next)) {
3699 traits[count].value = omp_atv_false;
3705 }
else if (__kmp_match_str(
"partition", scan, &next)) {
3707 traits[count].key = omp_atk_partition;
3708 if (__kmp_match_str(
"environment", scan, &next)) {
3709 traits[count].value = omp_atv_environment;
3710 }
else if (__kmp_match_str(
"nearest", scan, &next)) {
3711 traits[count].value = omp_atv_nearest;
3712 }
else if (__kmp_match_str(
"blocked", scan, &next)) {
3713 traits[count].value = omp_atv_blocked;
3714 }
else if (__kmp_match_str(
"interleaved", scan, &next)) {
3715 traits[count].value = omp_atv_interleaved;
3728 if (count == ntraits)
3734 al = __kmpc_init_allocator(__kmp_get_gtid(), ms, ntraits, traits);
3735 __kmp_def_allocator = (al == omp_null_allocator) ? omp_default_mem_alloc : al;
3738 static void __kmp_stg_print_allocator(kmp_str_buf_t *buffer,
char const *name,
3740 if (__kmp_def_allocator == omp_default_mem_alloc) {
3741 __kmp_stg_print_str(buffer, name,
"omp_default_mem_alloc");
3742 }
else if (__kmp_def_allocator == omp_high_bw_mem_alloc) {
3743 __kmp_stg_print_str(buffer, name,
"omp_high_bw_mem_alloc");
3744 }
else if (__kmp_def_allocator == omp_large_cap_mem_alloc) {
3745 __kmp_stg_print_str(buffer, name,
"omp_large_cap_mem_alloc");
3746 }
else if (__kmp_def_allocator == omp_const_mem_alloc) {
3747 __kmp_stg_print_str(buffer, name,
"omp_const_mem_alloc");
3748 }
else if (__kmp_def_allocator == omp_low_lat_mem_alloc) {
3749 __kmp_stg_print_str(buffer, name,
"omp_low_lat_mem_alloc");
3750 }
else if (__kmp_def_allocator == omp_cgroup_mem_alloc) {
3751 __kmp_stg_print_str(buffer, name,
"omp_cgroup_mem_alloc");
3752 }
else if (__kmp_def_allocator == omp_pteam_mem_alloc) {
3753 __kmp_stg_print_str(buffer, name,
"omp_pteam_mem_alloc");
3754 }
else if (__kmp_def_allocator == omp_thread_mem_alloc) {
3755 __kmp_stg_print_str(buffer, name,
"omp_thread_mem_alloc");
3762 static void __kmp_stg_parse_omp_dynamic(
char const *name,
char const *value,
3764 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
3767 static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer,
char const *name,
3769 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
3772 static void __kmp_stg_parse_kmp_dynamic_mode(
char const *name,
3773 char const *value,
void *data) {
3774 if (TCR_4(__kmp_init_parallel)) {
3775 KMP_WARNING(EnvParallelWarn, name);
3776 __kmp_env_toPrint(name, 0);
3779 #ifdef USE_LOAD_BALANCE
3780 else if (__kmp_str_match(
"load balance", 2, value) ||
3781 __kmp_str_match(
"load_balance", 2, value) ||
3782 __kmp_str_match(
"load-balance", 2, value) ||
3783 __kmp_str_match(
"loadbalance", 2, value) ||
3784 __kmp_str_match(
"balance", 1, value)) {
3785 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3788 else if (__kmp_str_match(
"thread limit", 1, value) ||
3789 __kmp_str_match(
"thread_limit", 1, value) ||
3790 __kmp_str_match(
"thread-limit", 1, value) ||
3791 __kmp_str_match(
"threadlimit", 1, value) ||
3792 __kmp_str_match(
"limit", 2, value)) {
3793 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3794 }
else if (__kmp_str_match(
"random", 1, value)) {
3795 __kmp_global.g.g_dynamic_mode = dynamic_random;
3797 KMP_WARNING(StgInvalidValue, name, value);
3801 static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
3802 char const *name,
void *data) {
3804 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
3805 __kmp_str_buf_print(buffer,
" %s: %s \n", name, KMP_I18N_STR(NotDefined));
3807 #ifdef USE_LOAD_BALANCE
3808 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
3809 __kmp_stg_print_str(buffer, name,
"load balance");
3812 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
3813 __kmp_stg_print_str(buffer, name,
"thread limit");
3814 }
else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
3815 __kmp_stg_print_str(buffer, name,
"random");
3822 #ifdef USE_LOAD_BALANCE
3827 static void __kmp_stg_parse_ld_balance_interval(
char const *name,
3828 char const *value,
void *data) {
3829 double interval = __kmp_convert_to_double(value);
3830 if (interval >= 0) {
3831 __kmp_load_balance_interval = interval;
3833 KMP_WARNING(StgInvalidValue, name, value);
3837 static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
3838 char const *name,
void *data) {
3840 __kmp_str_buf_print(buffer,
" %s=%8.6f\n", name,
3841 __kmp_load_balance_interval);
3850 static void __kmp_stg_parse_init_at_fork(
char const *name,
char const *value,
3852 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
3853 if (__kmp_need_register_atfork) {
3854 __kmp_need_register_atfork_specified = TRUE;
3858 static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
3859 char const *name,
void *data) {
3860 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
3866 static void __kmp_stg_parse_schedule(
char const *name,
char const *value,
3869 if (value != NULL) {
3870 size_t length = KMP_STRLEN(value);
3871 if (length > INT_MAX) {
3872 KMP_WARNING(LongValue, name);
3874 const char *semicolon;
3875 if (value[length - 1] ==
'"' || value[length - 1] ==
'\'')
3876 KMP_WARNING(UnbalancedQuotes, name);
3880 semicolon = strchr(value,
';');
3881 if (*value && semicolon != value) {
3882 const char *comma = strchr(value,
',');
3889 if (!__kmp_strcasecmp_with_sentinel(
"static", value, sentinel)) {
3890 if (!__kmp_strcasecmp_with_sentinel(
"greedy", comma,
';')) {
3891 __kmp_static = kmp_sch_static_greedy;
3893 }
else if (!__kmp_strcasecmp_with_sentinel(
"balanced", comma,
3895 __kmp_static = kmp_sch_static_balanced;
3898 }
else if (!__kmp_strcasecmp_with_sentinel(
"guided", value,
3900 if (!__kmp_strcasecmp_with_sentinel(
"iterative", comma,
';')) {
3901 __kmp_guided = kmp_sch_guided_iterative_chunked;
3903 }
else if (!__kmp_strcasecmp_with_sentinel(
"analytical", comma,
3906 __kmp_guided = kmp_sch_guided_analytical_chunked;
3910 KMP_WARNING(InvalidClause, name, value);
3912 KMP_WARNING(EmptyClause, name);
3913 }
while ((value = semicolon ? semicolon + 1 : NULL));
3919 static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer,
char const *name,
3921 if (__kmp_env_format) {
3922 KMP_STR_BUF_PRINT_NAME_EX(name);
3924 __kmp_str_buf_print(buffer,
" %s='", name);
3926 if (__kmp_static == kmp_sch_static_greedy) {
3927 __kmp_str_buf_print(buffer,
"%s",
"static,greedy");
3928 }
else if (__kmp_static == kmp_sch_static_balanced) {
3929 __kmp_str_buf_print(buffer,
"%s",
"static,balanced");
3931 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
3932 __kmp_str_buf_print(buffer,
";%s'\n",
"guided,iterative");
3933 }
else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
3934 __kmp_str_buf_print(buffer,
";%s'\n",
"guided,analytical");
3941 static inline void __kmp_omp_schedule_restore() {
3942 #if KMP_USE_HIER_SCHED
3943 __kmp_hier_scheds.deallocate();
3953 static const char *__kmp_parse_single_omp_schedule(
const char *name,
3955 bool parse_hier =
false) {
3957 const char *ptr = value;
3964 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
3966 #if KMP_USE_HIER_SCHED
3967 kmp_hier_layer_e layer = kmp_hier_layer_e::LAYER_THREAD;
3969 if (*delim ==
',') {
3970 if (!__kmp_strcasecmp_with_sentinel(
"L1", ptr,
',')) {
3971 layer = kmp_hier_layer_e::LAYER_L1;
3972 }
else if (!__kmp_strcasecmp_with_sentinel(
"L2", ptr,
',')) {
3973 layer = kmp_hier_layer_e::LAYER_L2;
3974 }
else if (!__kmp_strcasecmp_with_sentinel(
"L3", ptr,
',')) {
3975 layer = kmp_hier_layer_e::LAYER_L3;
3976 }
else if (!__kmp_strcasecmp_with_sentinel(
"NUMA", ptr,
',')) {
3977 layer = kmp_hier_layer_e::LAYER_NUMA;
3980 if (layer != kmp_hier_layer_e::LAYER_THREAD && *delim !=
',') {
3982 KMP_WARNING(StgInvalidValue, name, value);
3983 __kmp_omp_schedule_restore();
3985 }
else if (layer != kmp_hier_layer_e::LAYER_THREAD) {
3987 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
3994 if (*delim ==
':') {
3995 if (!__kmp_strcasecmp_with_sentinel(
"monotonic", ptr, *delim)) {
3998 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4000 }
else if (!__kmp_strcasecmp_with_sentinel(
"nonmonotonic", ptr, *delim)) {
4003 while (*delim !=
',' && *delim !=
':' && *delim !=
'\0')
4005 }
else if (!parse_hier) {
4007 KMP_WARNING(StgInvalidValue, name, value);
4008 __kmp_omp_schedule_restore();
4013 if (!__kmp_strcasecmp_with_sentinel(
"dynamic", ptr, *delim))
4014 sched = kmp_sch_dynamic_chunked;
4015 else if (!__kmp_strcasecmp_with_sentinel(
"guided", ptr, *delim))
4018 else if (!__kmp_strcasecmp_with_sentinel(
"auto", ptr, *delim))
4020 else if (!__kmp_strcasecmp_with_sentinel(
"trapezoidal", ptr, *delim))
4021 sched = kmp_sch_trapezoidal;
4022 else if (!__kmp_strcasecmp_with_sentinel(
"static", ptr, *delim))
4024 #if KMP_STATIC_STEAL_ENABLED
4025 else if (!__kmp_strcasecmp_with_sentinel(
"static_steal", ptr, *delim)) {
4027 sched = kmp_sch_dynamic_chunked;
4033 KMP_WARNING(StgInvalidValue, name, value);
4034 __kmp_omp_schedule_restore();
4039 if (*delim ==
',') {
4042 if (!isdigit(*ptr)) {
4044 KMP_WARNING(StgInvalidValue, name, value);
4045 __kmp_omp_schedule_restore();
4051 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, delim),
4055 sched = kmp_sch_static_chunked;
4056 chunk = __kmp_str_to_int(delim + 1, *ptr);
4058 chunk = KMP_DEFAULT_CHUNK;
4059 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, delim),
4061 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
4070 }
else if (chunk > KMP_MAX_CHUNK) {
4071 chunk = KMP_MAX_CHUNK;
4072 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, delim),
4074 KMP_INFORM(Using_int_Value, name, chunk);
4081 SCHEDULE_SET_MODIFIERS(sched, sched_modifier);
4083 #if KMP_USE_HIER_SCHED
4084 if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4085 __kmp_hier_scheds.append(sched, chunk, layer);
4089 __kmp_chunk = chunk;
4090 __kmp_sched = sched;
4095 static void __kmp_stg_parse_omp_schedule(
char const *name,
char const *value,
4098 const char *ptr = value;
4101 length = KMP_STRLEN(value);
4103 if (value[length - 1] ==
'"' || value[length - 1] ==
'\'')
4104 KMP_WARNING(UnbalancedQuotes, name);
4106 #if KMP_USE_HIER_SCHED
4107 if (!__kmp_strcasecmp_with_sentinel(
"EXPERIMENTAL", ptr,
' ')) {
4110 while ((ptr = __kmp_parse_single_omp_schedule(name, ptr,
true))) {
4111 while (*ptr ==
' ' || *ptr ==
'\t' || *ptr ==
':')
4118 __kmp_parse_single_omp_schedule(name, ptr);
4120 KMP_WARNING(EmptyString, name);
4122 #if KMP_USE_HIER_SCHED
4123 __kmp_hier_scheds.sort();
4125 K_DIAG(1, (
"__kmp_static == %d\n", __kmp_static))
4126 K_DIAG(1, (
"__kmp_guided == %d\n", __kmp_guided))
4127 K_DIAG(1, (
"__kmp_sched == %d\n", __kmp_sched))
4128 K_DIAG(1, (
"__kmp_chunk == %d\n", __kmp_chunk))
4131 static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
4132 char const *name,
void *data) {
4133 if (__kmp_env_format) {
4134 KMP_STR_BUF_PRINT_NAME_EX(name);
4136 __kmp_str_buf_print(buffer,
" %s='", name);
4138 enum sched_type sched = SCHEDULE_WITHOUT_MODIFIERS(__kmp_sched);
4139 if (SCHEDULE_HAS_MONOTONIC(__kmp_sched)) {
4140 __kmp_str_buf_print(buffer,
"monotonic:");
4141 }
else if (SCHEDULE_HAS_NONMONOTONIC(__kmp_sched)) {
4142 __kmp_str_buf_print(buffer,
"nonmonotonic:");
4146 case kmp_sch_dynamic_chunked:
4147 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"dynamic", __kmp_chunk);
4149 case kmp_sch_guided_iterative_chunked:
4150 case kmp_sch_guided_analytical_chunked:
4151 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"guided", __kmp_chunk);
4153 case kmp_sch_trapezoidal:
4154 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"trapezoidal", __kmp_chunk);
4157 case kmp_sch_static_chunked:
4158 case kmp_sch_static_balanced:
4159 case kmp_sch_static_greedy:
4160 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"static", __kmp_chunk);
4162 case kmp_sch_static_steal:
4163 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"static_steal", __kmp_chunk);
4166 __kmp_str_buf_print(buffer,
"%s,%d'\n",
"auto", __kmp_chunk);
4171 case kmp_sch_dynamic_chunked:
4172 __kmp_str_buf_print(buffer,
"%s'\n",
"dynamic");
4174 case kmp_sch_guided_iterative_chunked:
4175 case kmp_sch_guided_analytical_chunked:
4176 __kmp_str_buf_print(buffer,
"%s'\n",
"guided");
4178 case kmp_sch_trapezoidal:
4179 __kmp_str_buf_print(buffer,
"%s'\n",
"trapezoidal");
4182 case kmp_sch_static_chunked:
4183 case kmp_sch_static_balanced:
4184 case kmp_sch_static_greedy:
4185 __kmp_str_buf_print(buffer,
"%s'\n",
"static");
4187 case kmp_sch_static_steal:
4188 __kmp_str_buf_print(buffer,
"%s'\n",
"static_steal");
4191 __kmp_str_buf_print(buffer,
"%s'\n",
"auto");
4197 #if KMP_USE_HIER_SCHED
4200 static void __kmp_stg_parse_kmp_hand_thread(
char const *name,
char const *value,
4202 __kmp_stg_parse_bool(name, value, &(__kmp_dispatch_hand_threading));
4205 static void __kmp_stg_print_kmp_hand_thread(kmp_str_buf_t *buffer,
4206 char const *name,
void *data) {
4207 __kmp_stg_print_bool(buffer, name, __kmp_dispatch_hand_threading);
4213 static void __kmp_stg_parse_kmp_force_monotonic(
char const *name,
4214 char const *value,
void *data) {
4215 __kmp_stg_parse_bool(name, value, &(__kmp_force_monotonic));
4218 static void __kmp_stg_print_kmp_force_monotonic(kmp_str_buf_t *buffer,
4219 char const *name,
void *data) {
4220 __kmp_stg_print_bool(buffer, name, __kmp_force_monotonic);
4226 static void __kmp_stg_parse_atomic_mode(
char const *name,
char const *value,
4232 #ifdef KMP_GOMP_COMPAT
4235 __kmp_stg_parse_int(name, value, 0, max, &mode);
4240 __kmp_atomic_mode = mode;
4244 static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer,
char const *name,
4246 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
4252 static void __kmp_stg_parse_consistency_check(
char const *name,
4253 char const *value,
void *data) {
4254 if (!__kmp_strcasecmp_with_sentinel(
"all", value, 0)) {
4260 __kmp_env_consistency_check = TRUE;
4261 }
else if (!__kmp_strcasecmp_with_sentinel(
"none", value, 0)) {
4262 __kmp_env_consistency_check = FALSE;
4264 KMP_WARNING(StgInvalidValue, name, value);
4268 static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
4269 char const *name,
void *data) {
4271 const char *value = NULL;
4273 if (__kmp_env_consistency_check) {
4279 if (value != NULL) {
4280 __kmp_stg_print_str(buffer, name, value);
4291 static void __kmp_stg_parse_itt_prepare_delay(
char const *name,
4292 char const *value,
void *data) {
4296 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
4297 __kmp_itt_prepare_delay = delay;
4300 static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
4301 char const *name,
void *data) {
4302 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
4312 static void __kmp_stg_parse_malloc_pool_incr(
char const *name,
4313 char const *value,
void *data) {
4314 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
4315 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
4319 static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
4320 char const *name,
void *data) {
4321 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
4330 static void __kmp_stg_parse_par_range_env(
char const *name,
char const *value,
4332 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
4333 __kmp_par_range_routine, __kmp_par_range_filename,
4334 &__kmp_par_range_lb, &__kmp_par_range_ub);
4337 static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
4338 char const *name,
void *data) {
4339 if (__kmp_par_range != 0) {
4340 __kmp_stg_print_str(buffer, name, par_range_to_print);
4349 static void __kmp_stg_parse_gtid_mode(
char const *name,
char const *value,
4359 #ifdef KMP_TDATA_GTID
4362 __kmp_stg_parse_int(name, value, 0, max, &mode);
4366 __kmp_adjust_gtid_mode = TRUE;
4368 __kmp_gtid_mode = mode;
4369 __kmp_adjust_gtid_mode = FALSE;
4373 static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer,
char const *name,
4375 if (__kmp_adjust_gtid_mode) {
4376 __kmp_stg_print_int(buffer, name, 0);
4378 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
4385 static void __kmp_stg_parse_lock_block(
char const *name,
char const *value,
4387 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
4390 static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer,
char const *name,
4392 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
4398 #if KMP_USE_DYNAMIC_LOCK
4399 #define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
4401 #define KMP_STORE_LOCK_SEQ(a)
4404 static void __kmp_stg_parse_lock_kind(
char const *name,
char const *value,
4406 if (__kmp_init_user_locks) {
4407 KMP_WARNING(EnvLockWarn, name);
4411 if (__kmp_str_match(
"tas", 2, value) ||
4412 __kmp_str_match(
"test and set", 2, value) ||
4413 __kmp_str_match(
"test_and_set", 2, value) ||
4414 __kmp_str_match(
"test-and-set", 2, value) ||
4415 __kmp_str_match(
"test andset", 2, value) ||
4416 __kmp_str_match(
"test_andset", 2, value) ||
4417 __kmp_str_match(
"test-andset", 2, value) ||
4418 __kmp_str_match(
"testand set", 2, value) ||
4419 __kmp_str_match(
"testand_set", 2, value) ||
4420 __kmp_str_match(
"testand-set", 2, value) ||
4421 __kmp_str_match(
"testandset", 2, value)) {
4422 __kmp_user_lock_kind = lk_tas;
4423 KMP_STORE_LOCK_SEQ(tas);
4426 else if (__kmp_str_match(
"futex", 1, value)) {
4427 if (__kmp_futex_determine_capable()) {
4428 __kmp_user_lock_kind = lk_futex;
4429 KMP_STORE_LOCK_SEQ(futex);
4431 KMP_WARNING(FutexNotSupported, name, value);
4435 else if (__kmp_str_match(
"ticket", 2, value)) {
4436 __kmp_user_lock_kind = lk_ticket;
4437 KMP_STORE_LOCK_SEQ(ticket);
4438 }
else if (__kmp_str_match(
"queuing", 1, value) ||
4439 __kmp_str_match(
"queue", 1, value)) {
4440 __kmp_user_lock_kind = lk_queuing;
4441 KMP_STORE_LOCK_SEQ(queuing);
4442 }
else if (__kmp_str_match(
"drdpa ticket", 1, value) ||
4443 __kmp_str_match(
"drdpa_ticket", 1, value) ||
4444 __kmp_str_match(
"drdpa-ticket", 1, value) ||
4445 __kmp_str_match(
"drdpaticket", 1, value) ||
4446 __kmp_str_match(
"drdpa", 1, value)) {
4447 __kmp_user_lock_kind = lk_drdpa;
4448 KMP_STORE_LOCK_SEQ(drdpa);
4450 #if KMP_USE_ADAPTIVE_LOCKS
4451 else if (__kmp_str_match(
"adaptive", 1, value)) {
4452 if (__kmp_cpuinfo.rtm) {
4453 __kmp_user_lock_kind = lk_adaptive;
4454 KMP_STORE_LOCK_SEQ(adaptive);
4456 KMP_WARNING(AdaptiveNotSupported, name, value);
4457 __kmp_user_lock_kind = lk_queuing;
4458 KMP_STORE_LOCK_SEQ(queuing);
4462 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4463 else if (__kmp_str_match(
"rtm_queuing", 1, value)) {
4464 if (__kmp_cpuinfo.rtm) {
4465 __kmp_user_lock_kind = lk_rtm_queuing;
4466 KMP_STORE_LOCK_SEQ(rtm_queuing);
4468 KMP_WARNING(AdaptiveNotSupported, name, value);
4469 __kmp_user_lock_kind = lk_queuing;
4470 KMP_STORE_LOCK_SEQ(queuing);
4472 }
else if (__kmp_str_match(
"rtm_spin", 1, value)) {
4473 if (__kmp_cpuinfo.rtm) {
4474 __kmp_user_lock_kind = lk_rtm_spin;
4475 KMP_STORE_LOCK_SEQ(rtm_spin);
4477 KMP_WARNING(AdaptiveNotSupported, name, value);
4478 __kmp_user_lock_kind = lk_tas;
4479 KMP_STORE_LOCK_SEQ(queuing);
4481 }
else if (__kmp_str_match(
"hle", 1, value)) {
4482 __kmp_user_lock_kind = lk_hle;
4483 KMP_STORE_LOCK_SEQ(hle);
4487 KMP_WARNING(StgInvalidValue, name, value);
4491 static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer,
char const *name,
4493 const char *value = NULL;
4495 switch (__kmp_user_lock_kind) {
4510 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4511 case lk_rtm_queuing:
4512 value =
"rtm_queuing";
4535 #if KMP_USE_ADAPTIVE_LOCKS
4542 if (value != NULL) {
4543 __kmp_stg_print_str(buffer, name, value);
4552 static void __kmp_stg_parse_spin_backoff_params(
const char *name,
4553 const char *value,
void *data) {
4554 const char *next = value;
4557 int prev_comma = FALSE;
4560 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
4561 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
4565 for (i = 0; i < 3; i++) {
4568 if (*next ==
'\0') {
4573 if (((*next < '0' || *next >
'9') && *next !=
',') || total > 2) {
4574 KMP_WARNING(EnvSyntaxError, name, value);
4580 if (total == 0 || prev_comma) {
4588 if (*next >=
'0' && *next <=
'9') {
4590 const char *buf = next;
4591 char const *msg = NULL;
4596 const char *tmp = next;
4598 if ((*next ==
' ' || *next ==
'\t') && (*tmp >=
'0' && *tmp <=
'9')) {
4599 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4603 num = __kmp_str_to_int(buf, *next);
4605 msg = KMP_I18N_STR(ValueTooSmall);
4607 }
else if (num > KMP_INT_MAX) {
4608 msg = KMP_I18N_STR(ValueTooLarge);
4613 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4614 KMP_INFORM(Using_int_Value, name, num);
4618 }
else if (total == 2) {
4623 KMP_DEBUG_ASSERT(total > 0);
4625 KMP_WARNING(EnvSyntaxError, name, value);
4628 __kmp_spin_backoff_params.max_backoff = max_backoff;
4629 __kmp_spin_backoff_params.min_tick = min_tick;
4632 static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
4633 char const *name,
void *data) {
4634 if (__kmp_env_format) {
4635 KMP_STR_BUF_PRINT_NAME_EX(name);
4637 __kmp_str_buf_print(buffer,
" %s='", name);
4639 __kmp_str_buf_print(buffer,
"%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
4640 __kmp_spin_backoff_params.min_tick);
4643 #if KMP_USE_ADAPTIVE_LOCKS
4650 static void __kmp_stg_parse_adaptive_lock_props(
const char *name,
4651 const char *value,
void *data) {
4652 int max_retries = 0;
4653 int max_badness = 0;
4655 const char *next = value;
4658 int prev_comma = FALSE;
4664 for (i = 0; i < 3; i++) {
4667 if (*next ==
'\0') {
4672 if (((*next < '0' || *next >
'9') && *next !=
',') || total > 2) {
4673 KMP_WARNING(EnvSyntaxError, name, value);
4679 if (total == 0 || prev_comma) {
4687 if (*next >=
'0' && *next <=
'9') {
4689 const char *buf = next;
4690 char const *msg = NULL;
4695 const char *tmp = next;
4697 if ((*next ==
' ' || *next ==
'\t') && (*tmp >=
'0' && *tmp <=
'9')) {
4698 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4702 num = __kmp_str_to_int(buf, *next);
4704 msg = KMP_I18N_STR(ValueTooSmall);
4706 }
else if (num > KMP_INT_MAX) {
4707 msg = KMP_I18N_STR(ValueTooLarge);
4712 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4713 KMP_INFORM(Using_int_Value, name, num);
4717 }
else if (total == 2) {
4722 KMP_DEBUG_ASSERT(total > 0);
4724 KMP_WARNING(EnvSyntaxError, name, value);
4727 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4728 __kmp_adaptive_backoff_params.max_badness = max_badness;
4731 static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4732 char const *name,
void *data) {
4733 if (__kmp_env_format) {
4734 KMP_STR_BUF_PRINT_NAME_EX(name);
4736 __kmp_str_buf_print(buffer,
" %s='", name);
4738 __kmp_str_buf_print(buffer,
"%d,%d'\n",
4739 __kmp_adaptive_backoff_params.max_soft_retries,
4740 __kmp_adaptive_backoff_params.max_badness);
4743 #if KMP_DEBUG_ADAPTIVE_LOCKS
4745 static void __kmp_stg_parse_speculative_statsfile(
char const *name,
4748 __kmp_stg_parse_file(name, value,
"",
4749 CCAST(
char **, &__kmp_speculative_statsfile));
4752 static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
4755 if (__kmp_str_match(
"-", 0, __kmp_speculative_statsfile)) {
4756 __kmp_stg_print_str(buffer, name,
"stdout");
4758 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
4774 static kmp_hw_t __kmp_hw_subset_break_tie(
const kmp_hw_t *possible,
4775 size_t num_possible) {
4776 for (
size_t i = 0; i < num_possible; ++i) {
4777 if (possible[i] == KMP_HW_THREAD)
4778 return KMP_HW_THREAD;
4779 else if (possible[i] == KMP_HW_CORE)
4781 else if (possible[i] == KMP_HW_SOCKET)
4782 return KMP_HW_SOCKET;
4784 return KMP_HW_UNKNOWN;
4791 static kmp_hw_t __kmp_stg_parse_hw_subset_name(
char const *token) {
4792 size_t index, num_possible, token_length;
4793 kmp_hw_t possible[KMP_HW_LAST];
4799 while (isalnum(*end) || *end ==
'_') {
4806 KMP_FOREACH_HW_TYPE(type) { possible[num_possible++] = type; }
4813 while (num_possible > 1 && index < token_length) {
4814 size_t n = num_possible;
4815 char token_char = (char)toupper(token[index]);
4816 for (
size_t i = 0; i < n; ++i) {
4818 kmp_hw_t type = possible[i];
4819 s = __kmp_hw_get_keyword(type,
false);
4820 if (index < KMP_STRLEN(s)) {
4821 char c = (char)toupper(s[index]);
4823 if (c != token_char) {
4824 possible[i] = KMP_HW_UNKNOWN;
4831 for (
size_t i = 0; i < n; ++i) {
4832 if (possible[i] != KMP_HW_UNKNOWN) {
4833 kmp_hw_t temp = possible[i];
4834 possible[i] = possible[start];
4835 possible[start] = temp;
4839 KMP_ASSERT(start == num_possible);
4845 if (num_possible > 1)
4846 return __kmp_hw_subset_break_tie(possible, num_possible);
4847 if (num_possible == 1)
4849 return KMP_HW_UNKNOWN;
4854 #define MAX_T_LEVEL KMP_HW_LAST
4855 #define MAX_STR_LEN 512
4856 static void __kmp_stg_parse_hw_subset(
char const *name,
char const *value,
4860 kmp_setting_t **rivals = (kmp_setting_t **)data;
4861 if (strcmp(name,
"KMP_PLACE_THREADS") == 0) {
4862 KMP_INFORM(EnvVarDeprecated, name,
"KMP_HW_SUBSET");
4864 if (__kmp_stg_check_rivals(name, value, rivals)) {
4868 char *components[MAX_T_LEVEL];
4869 char const *digits =
"0123456789";
4870 char input[MAX_STR_LEN];
4871 size_t len = 0, mlen = MAX_STR_LEN;
4873 bool absolute =
false;
4875 char *pos = CCAST(
char *, value);
4876 while (*pos && mlen) {
4878 if (len == 0 && *pos ==
':') {
4881 input[len] = (char)(toupper(*pos));
4882 if (input[len] ==
'X')
4884 if (input[len] ==
'O' && strchr(digits, *(pos + 1)))
4892 if (len == 0 || mlen == 0) {
4898 components[level++] = pos;
4899 while ((pos = strchr(pos,
','))) {
4900 if (level >= MAX_T_LEVEL)
4903 components[level++] = ++pos;
4906 __kmp_hw_subset = kmp_hw_subset_t::allocate();
4908 __kmp_hw_subset->set_absolute();
4911 for (
int i = 0; i < level; ++i) {
4913 int num = atoi(components[i]);
4917 if ((pos = strchr(components[i],
'@'))) {
4918 offset = atoi(pos + 1);
4921 pos = components[i] + strspn(components[i], digits);
4922 if (pos == components[i]) {
4926 kmp_hw_t type = __kmp_stg_parse_hw_subset_name(pos);
4927 if (type == KMP_HW_UNKNOWN) {
4930 if (__kmp_hw_subset->specified(type)) {
4933 __kmp_hw_subset->push_back(num, type, offset);
4937 KMP_WARNING(AffHWSubsetInvalid, name, value);
4938 if (__kmp_hw_subset) {
4939 kmp_hw_subset_t::deallocate(__kmp_hw_subset);
4940 __kmp_hw_subset =
nullptr;
4945 static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer,
char const *name,
4949 if (!__kmp_hw_subset)
4951 __kmp_str_buf_init(&buf);
4952 if (__kmp_env_format)
4953 KMP_STR_BUF_PRINT_NAME_EX(name);
4955 __kmp_str_buf_print(buffer,
" %s='", name);
4957 depth = __kmp_hw_subset->get_depth();
4958 for (
int i = 0; i < depth; ++i) {
4959 const auto &item = __kmp_hw_subset->at(i);
4960 __kmp_str_buf_print(&buf,
"%s%d%s", (i > 0 ?
"," :
""), item.num,
4961 __kmp_hw_get_keyword(item.type));
4963 __kmp_str_buf_print(&buf,
"@%d", item.offset);
4965 __kmp_str_buf_print(buffer,
"%s'\n", buf.str);
4966 __kmp_str_buf_free(&buf);
4973 static void __kmp_stg_parse_forkjoin_frames(
char const *name,
char const *value,
4975 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
4978 static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
4979 char const *name,
void *data) {
4980 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
4986 static void __kmp_stg_parse_forkjoin_frames_mode(
char const *name,
4989 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
4992 static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
4993 char const *name,
void *data) {
4994 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
5001 static void __kmp_stg_parse_task_throttling(
char const *name,
char const *value,
5003 __kmp_stg_parse_bool(name, value, &__kmp_enable_task_throttling);
5006 static void __kmp_stg_print_task_throttling(kmp_str_buf_t *buffer,
5007 char const *name,
void *data) {
5008 __kmp_stg_print_bool(buffer, name, __kmp_enable_task_throttling);
5011 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5015 static void __kmp_stg_parse_user_level_mwait(
char const *name,
5016 char const *value,
void *data) {
5017 __kmp_stg_parse_bool(name, value, &__kmp_user_level_mwait);
5020 static void __kmp_stg_print_user_level_mwait(kmp_str_buf_t *buffer,
5021 char const *name,
void *data) {
5022 __kmp_stg_print_bool(buffer, name, __kmp_user_level_mwait);
5028 static void __kmp_stg_parse_mwait_hints(
char const *name,
char const *value,
5030 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_mwait_hints);
5033 static void __kmp_stg_print_mwait_hints(kmp_str_buf_t *buffer,
char const *name,
5035 __kmp_stg_print_int(buffer, name, __kmp_mwait_hints);
5043 static void __kmp_stg_parse_omp_display_env(
char const *name,
char const *value,
5045 if (__kmp_str_match(
"VERBOSE", 1, value)) {
5046 __kmp_display_env_verbose = TRUE;
5048 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
5052 static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
5053 char const *name,
void *data) {
5054 if (__kmp_display_env_verbose) {
5055 __kmp_stg_print_str(buffer, name,
"VERBOSE");
5057 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
5061 static void __kmp_stg_parse_omp_cancellation(
char const *name,
5062 char const *value,
void *data) {
5063 if (TCR_4(__kmp_init_parallel)) {
5064 KMP_WARNING(EnvParallelWarn, name);
5067 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
5070 static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
5071 char const *name,
void *data) {
5072 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
5078 static void __kmp_stg_parse_omp_tool(
char const *name,
char const *value,
5080 __kmp_stg_parse_bool(name, value, &__kmp_tool);
5083 static void __kmp_stg_print_omp_tool(kmp_str_buf_t *buffer,
char const *name,
5085 if (__kmp_env_format) {
5086 KMP_STR_BUF_PRINT_BOOL_EX(name, __kmp_tool,
"enabled",
"disabled");
5088 __kmp_str_buf_print(buffer,
" %s=%s\n", name,
5089 __kmp_tool ?
"enabled" :
"disabled");
5093 char *__kmp_tool_libraries = NULL;
5095 static void __kmp_stg_parse_omp_tool_libraries(
char const *name,
5096 char const *value,
void *data) {
5097 __kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
5100 static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer,
5101 char const *name,
void *data) {
5102 if (__kmp_tool_libraries)
5103 __kmp_stg_print_str(buffer, name, __kmp_tool_libraries);
5105 if (__kmp_env_format) {
5106 KMP_STR_BUF_PRINT_NAME;
5108 __kmp_str_buf_print(buffer,
" %s", name);
5110 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
5114 char *__kmp_tool_verbose_init = NULL;
5116 static void __kmp_stg_parse_omp_tool_verbose_init(
char const *name,
5119 __kmp_stg_parse_str(name, value, &__kmp_tool_verbose_init);
5122 static void __kmp_stg_print_omp_tool_verbose_init(kmp_str_buf_t *buffer,
5125 if (__kmp_tool_verbose_init)
5126 __kmp_stg_print_str(buffer, name, __kmp_tool_verbose_init);
5128 if (__kmp_env_format) {
5129 KMP_STR_BUF_PRINT_NAME;
5131 __kmp_str_buf_print(buffer,
" %s", name);
5133 __kmp_str_buf_print(buffer,
": %s\n", KMP_I18N_STR(NotDefined));
5141 static kmp_setting_t __kmp_stg_table[] = {
5143 {
"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
5144 {
"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
5146 {
"KMP_USE_YIELD", __kmp_stg_parse_use_yield, __kmp_stg_print_use_yield,
5148 {
"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
5149 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
5150 {
"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
5152 {
"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
5153 __kmp_stg_print_device_thread_limit, NULL, 0, 0},
5155 {
"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
5156 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
5158 {
"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
5160 {
"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
5161 __kmp_stg_print_stackoffset, NULL, 0, 0},
5162 {
"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5164 {
"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
5166 {
"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
5168 {
"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
5171 {
"KMP_NESTING_MODE", __kmp_stg_parse_nesting_mode,
5172 __kmp_stg_print_nesting_mode, NULL, 0, 0},
5173 {
"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
5174 {
"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
5175 __kmp_stg_print_num_threads, NULL, 0, 0},
5176 {
"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5179 {
"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
5181 {
"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
5182 __kmp_stg_print_task_stealing, NULL, 0, 0},
5183 {
"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
5184 __kmp_stg_print_max_active_levels, NULL, 0, 0},
5185 {
"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
5186 __kmp_stg_print_default_device, NULL, 0, 0},
5187 {
"OMP_TARGET_OFFLOAD", __kmp_stg_parse_target_offload,
5188 __kmp_stg_print_target_offload, NULL, 0, 0},
5189 {
"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
5190 __kmp_stg_print_max_task_priority, NULL, 0, 0},
5191 {
"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
5192 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
5193 {
"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
5194 __kmp_stg_print_thread_limit, NULL, 0, 0},
5195 {
"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
5196 __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
5197 {
"OMP_NUM_TEAMS", __kmp_stg_parse_nteams, __kmp_stg_print_nteams, NULL, 0,
5199 {
"OMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_th_limit,
5200 __kmp_stg_print_teams_th_limit, NULL, 0, 0},
5201 {
"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
5202 __kmp_stg_print_wait_policy, NULL, 0, 0},
5203 {
"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
5204 __kmp_stg_print_disp_buffers, NULL, 0, 0},
5205 #if KMP_NESTED_HOT_TEAMS
5206 {
"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
5207 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
5208 {
"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
5209 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
5212 #if KMP_HANDLE_SIGNALS
5213 {
"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
5214 __kmp_stg_print_handle_signals, NULL, 0, 0},
5217 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
5218 {
"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
5219 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
5222 #ifdef KMP_GOMP_COMPAT
5223 {
"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
5227 {
"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
5229 {
"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
5231 {
"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
5233 {
"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
5235 {
"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
5237 {
"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
5239 {
"KMP_DEBUG", __kmp_stg_parse_debug, NULL, NULL, 0, 0},
5240 {
"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
5242 {
"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
5243 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
5244 {
"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
5245 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
5246 {
"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
5247 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
5248 {
"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
5250 {
"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
5251 __kmp_stg_print_par_range_env, NULL, 0, 0},
5254 {
"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
5255 __kmp_stg_print_align_alloc, NULL, 0, 0},
5257 {
"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5258 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5259 {
"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5260 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5261 {
"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5262 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5263 {
"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5264 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5265 #if KMP_FAST_REDUCTION_BARRIER
5266 {
"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5267 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5268 {
"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5269 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5272 {
"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
5273 __kmp_stg_print_abort_delay, NULL, 0, 0},
5274 {
"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
5275 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
5276 {
"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
5277 __kmp_stg_print_force_reduction, NULL, 0, 0},
5278 {
"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
5279 __kmp_stg_print_force_reduction, NULL, 0, 0},
5280 {
"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
5281 __kmp_stg_print_storage_map, NULL, 0, 0},
5282 {
"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
5283 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
5284 {
"KMP_FOREIGN_THREADS_THREADPRIVATE",
5285 __kmp_stg_parse_foreign_threads_threadprivate,
5286 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
5288 #if KMP_AFFINITY_SUPPORTED
5289 {
"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
5291 #ifdef KMP_GOMP_COMPAT
5292 {
"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
5295 {
"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5297 {
"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
5298 {
"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
5299 __kmp_stg_print_topology_method, NULL, 0, 0},
5305 {
"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5309 {
"OMP_DISPLAY_AFFINITY", __kmp_stg_parse_display_affinity,
5310 __kmp_stg_print_display_affinity, NULL, 0, 0},
5311 {
"OMP_AFFINITY_FORMAT", __kmp_stg_parse_affinity_format,
5312 __kmp_stg_print_affinity_format, NULL, 0, 0},
5313 {
"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
5314 __kmp_stg_print_init_at_fork, NULL, 0, 0},
5315 {
"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
5317 {
"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
5319 #if KMP_USE_HIER_SCHED
5320 {
"KMP_DISP_HAND_THREAD", __kmp_stg_parse_kmp_hand_thread,
5321 __kmp_stg_print_kmp_hand_thread, NULL, 0, 0},
5323 {
"KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE",
5324 __kmp_stg_parse_kmp_force_monotonic, __kmp_stg_print_kmp_force_monotonic,
5326 {
"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
5327 __kmp_stg_print_atomic_mode, NULL, 0, 0},
5328 {
"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
5329 __kmp_stg_print_consistency_check, NULL, 0, 0},
5331 #if USE_ITT_BUILD && USE_ITT_NOTIFY
5332 {
"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
5333 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
5335 {
"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
5336 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
5337 {
"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
5339 {
"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
5341 {
"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
5342 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
5344 #ifdef USE_LOAD_BALANCE
5345 {
"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
5346 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
5349 {
"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
5350 __kmp_stg_print_lock_block, NULL, 0, 0},
5351 {
"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
5353 {
"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
5354 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
5355 #if KMP_USE_ADAPTIVE_LOCKS
5356 {
"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
5357 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
5358 #if KMP_DEBUG_ADAPTIVE_LOCKS
5359 {
"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
5360 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
5363 {
"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5365 {
"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5368 {
"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
5369 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
5370 {
"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
5371 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
5373 {
"KMP_ENABLE_TASK_THROTTLING", __kmp_stg_parse_task_throttling,
5374 __kmp_stg_print_task_throttling, NULL, 0, 0},
5376 {
"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
5377 __kmp_stg_print_omp_display_env, NULL, 0, 0},
5378 {
"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
5379 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
5380 {
"OMP_ALLOCATOR", __kmp_stg_parse_allocator, __kmp_stg_print_allocator,
5382 {
"LIBOMP_USE_HIDDEN_HELPER_TASK", __kmp_stg_parse_use_hidden_helper,
5383 __kmp_stg_print_use_hidden_helper, NULL, 0, 0},
5384 {
"LIBOMP_NUM_HIDDEN_HELPER_THREADS",
5385 __kmp_stg_parse_num_hidden_helper_threads,
5386 __kmp_stg_print_num_hidden_helper_threads, NULL, 0, 0},
5389 {
"OMP_TOOL", __kmp_stg_parse_omp_tool, __kmp_stg_print_omp_tool, NULL, 0,
5391 {
"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries,
5392 __kmp_stg_print_omp_tool_libraries, NULL, 0, 0},
5393 {
"OMP_TOOL_VERBOSE_INIT", __kmp_stg_parse_omp_tool_verbose_init,
5394 __kmp_stg_print_omp_tool_verbose_init, NULL, 0, 0},
5397 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5398 {
"KMP_USER_LEVEL_MWAIT", __kmp_stg_parse_user_level_mwait,
5399 __kmp_stg_print_user_level_mwait, NULL, 0, 0},
5400 {
"KMP_MWAIT_HINTS", __kmp_stg_parse_mwait_hints,
5401 __kmp_stg_print_mwait_hints, NULL, 0, 0},
5403 {
"", NULL, NULL, NULL, 0, 0}};
5405 static int const __kmp_stg_count =
5406 sizeof(__kmp_stg_table) /
sizeof(kmp_setting_t);
5408 static inline kmp_setting_t *__kmp_stg_find(
char const *name) {
5412 for (i = 0; i < __kmp_stg_count; ++i) {
5413 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
5414 return &__kmp_stg_table[i];
5422 static int __kmp_stg_cmp(
void const *_a,
void const *_b) {
5423 const kmp_setting_t *a = RCAST(
const kmp_setting_t *, _a);
5424 const kmp_setting_t *b = RCAST(
const kmp_setting_t *, _b);
5428 if (strcmp(a->name,
"KMP_AFFINITY") == 0) {
5429 if (strcmp(b->name,
"KMP_AFFINITY") == 0) {
5433 }
else if (strcmp(b->name,
"KMP_AFFINITY") == 0) {
5436 return strcmp(a->name, b->name);
5439 static void __kmp_stg_init(
void) {
5441 static int initialized = 0;
5446 qsort(__kmp_stg_table, __kmp_stg_count - 1,
sizeof(kmp_setting_t),
5450 kmp_setting_t *kmp_stacksize =
5451 __kmp_stg_find(
"KMP_STACKSIZE");
5452 #ifdef KMP_GOMP_COMPAT
5453 kmp_setting_t *gomp_stacksize =
5454 __kmp_stg_find(
"GOMP_STACKSIZE");
5456 kmp_setting_t *omp_stacksize =
5457 __kmp_stg_find(
"OMP_STACKSIZE");
5463 static kmp_setting_t *
volatile rivals[4];
5464 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
5465 #ifdef KMP_GOMP_COMPAT
5466 static kmp_stg_ss_data_t gomp_data = {1024,
5467 CCAST(kmp_setting_t **, rivals)};
5469 static kmp_stg_ss_data_t omp_data = {1024,
5470 CCAST(kmp_setting_t **, rivals)};
5473 rivals[i++] = kmp_stacksize;
5474 #ifdef KMP_GOMP_COMPAT
5475 if (gomp_stacksize != NULL) {
5476 rivals[i++] = gomp_stacksize;
5479 rivals[i++] = omp_stacksize;
5482 kmp_stacksize->data = &kmp_data;
5483 #ifdef KMP_GOMP_COMPAT
5484 if (gomp_stacksize != NULL) {
5485 gomp_stacksize->data = &gomp_data;
5488 omp_stacksize->data = &omp_data;
5492 kmp_setting_t *kmp_library =
5493 __kmp_stg_find(
"KMP_LIBRARY");
5494 kmp_setting_t *omp_wait_policy =
5495 __kmp_stg_find(
"OMP_WAIT_POLICY");
5498 static kmp_setting_t *
volatile rivals[3];
5499 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
5500 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
5503 rivals[i++] = kmp_library;
5504 if (omp_wait_policy != NULL) {
5505 rivals[i++] = omp_wait_policy;
5509 kmp_library->data = &kmp_data;
5510 if (omp_wait_policy != NULL) {
5511 omp_wait_policy->data = &omp_data;
5516 kmp_setting_t *kmp_device_thread_limit =
5517 __kmp_stg_find(
"KMP_DEVICE_THREAD_LIMIT");
5518 kmp_setting_t *kmp_all_threads =
5519 __kmp_stg_find(
"KMP_ALL_THREADS");
5522 static kmp_setting_t *
volatile rivals[3];
5525 rivals[i++] = kmp_device_thread_limit;
5526 rivals[i++] = kmp_all_threads;
5529 kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
5530 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
5535 kmp_setting_t *kmp_hw_subset = __kmp_stg_find(
"KMP_HW_SUBSET");
5537 kmp_setting_t *kmp_place_threads = __kmp_stg_find(
"KMP_PLACE_THREADS");
5540 static kmp_setting_t *
volatile rivals[3];
5543 rivals[i++] = kmp_hw_subset;
5544 rivals[i++] = kmp_place_threads;
5547 kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
5548 kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
5551 #if KMP_AFFINITY_SUPPORTED
5553 kmp_setting_t *kmp_affinity =
5554 __kmp_stg_find(
"KMP_AFFINITY");
5555 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
5557 #ifdef KMP_GOMP_COMPAT
5558 kmp_setting_t *gomp_cpu_affinity =
5559 __kmp_stg_find(
"GOMP_CPU_AFFINITY");
5560 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
5563 kmp_setting_t *omp_proc_bind =
5564 __kmp_stg_find(
"OMP_PROC_BIND");
5565 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
5568 static kmp_setting_t *
volatile rivals[4];
5571 rivals[i++] = kmp_affinity;
5573 #ifdef KMP_GOMP_COMPAT
5574 rivals[i++] = gomp_cpu_affinity;
5575 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
5578 rivals[i++] = omp_proc_bind;
5579 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
5582 static kmp_setting_t *
volatile places_rivals[4];
5585 kmp_setting_t *omp_places = __kmp_stg_find(
"OMP_PLACES");
5586 KMP_DEBUG_ASSERT(omp_places != NULL);
5588 places_rivals[i++] = kmp_affinity;
5589 #ifdef KMP_GOMP_COMPAT
5590 places_rivals[i++] = gomp_cpu_affinity;
5592 places_rivals[i++] = omp_places;
5593 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
5594 places_rivals[i++] = NULL;
5602 kmp_setting_t *kmp_force_red =
5603 __kmp_stg_find(
"KMP_FORCE_REDUCTION");
5604 kmp_setting_t *kmp_determ_red =
5605 __kmp_stg_find(
"KMP_DETERMINISTIC_REDUCTION");
5608 static kmp_setting_t *
volatile rivals[3];
5609 static kmp_stg_fr_data_t force_data = {1,
5610 CCAST(kmp_setting_t **, rivals)};
5611 static kmp_stg_fr_data_t determ_data = {0,
5612 CCAST(kmp_setting_t **, rivals)};
5615 rivals[i++] = kmp_force_red;
5616 if (kmp_determ_red != NULL) {
5617 rivals[i++] = kmp_determ_red;
5621 kmp_force_red->data = &force_data;
5622 if (kmp_determ_red != NULL) {
5623 kmp_determ_red->data = &determ_data;
5632 for (i = 0; i < __kmp_stg_count; ++i) {
5633 __kmp_stg_table[i].set = 0;
5638 static void __kmp_stg_parse(
char const *name,
char const *value) {
5646 if (value != NULL) {
5647 kmp_setting_t *setting = __kmp_stg_find(name);
5648 if (setting != NULL) {
5649 setting->parse(name, value, setting->data);
5650 setting->defined = 1;
5656 static int __kmp_stg_check_rivals(
5659 kmp_setting_t **rivals
5662 if (rivals == NULL) {
5668 for (; strcmp(rivals[i]->name, name) != 0; i++) {
5669 KMP_DEBUG_ASSERT(rivals[i] != NULL);
5671 #if KMP_AFFINITY_SUPPORTED
5672 if (rivals[i] == __kmp_affinity_notype) {
5679 if (rivals[i]->set) {
5680 KMP_WARNING(StgIgnored, name, rivals[i]->name);
5690 static int __kmp_env_toPrint(
char const *name,
int flag) {
5692 kmp_setting_t *setting = __kmp_stg_find(name);
5693 if (setting != NULL) {
5694 rc = setting->defined;
5696 setting->defined = flag;
5702 static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
5707 value = __kmp_env_blk_var(block,
"OMP_NUM_THREADS");
5709 ompc_set_num_threads(__kmp_dflt_team_nth);
5713 value = __kmp_env_blk_var(block,
"KMP_BLOCKTIME");
5715 kmpc_set_blocktime(__kmp_dflt_blocktime);
5719 value = __kmp_env_blk_var(block,
"OMP_NESTED");
5721 ompc_set_nested(__kmp_dflt_max_active_levels > 1);
5725 value = __kmp_env_blk_var(block,
"OMP_DYNAMIC");
5727 ompc_set_dynamic(__kmp_global.g.g_dynamic);
5731 void __kmp_env_initialize(
char const *
string) {
5733 kmp_env_blk_t block;
5739 if (
string == NULL) {
5741 __kmp_threads_capacity =
5742 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
5744 __kmp_env_blk_init(&block,
string);
5747 for (i = 0; i < block.count; ++i) {
5748 if ((block.vars[i].name == NULL) || (*block.vars[i].name ==
'\0')) {
5751 if (block.vars[i].value == NULL) {
5754 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
5755 if (setting != NULL) {
5761 blocktime_str = __kmp_env_blk_var(&block,
"KMP_BLOCKTIME");
5765 if (
string == NULL) {
5766 char const *name =
"KMP_WARNINGS";
5767 char const *value = __kmp_env_blk_var(&block, name);
5768 __kmp_stg_parse(name, value);
5771 #if KMP_AFFINITY_SUPPORTED
5777 __kmp_affinity_notype = NULL;
5778 char const *aff_str = __kmp_env_blk_var(&block,
"KMP_AFFINITY");
5779 if (aff_str != NULL) {
5793 #define FIND strcasestr
5796 if ((FIND(aff_str,
"none") == NULL) &&
5797 (FIND(aff_str,
"physical") == NULL) &&
5798 (FIND(aff_str,
"logical") == NULL) &&
5799 (FIND(aff_str,
"compact") == NULL) &&
5800 (FIND(aff_str,
"scatter") == NULL) &&
5801 (FIND(aff_str,
"explicit") == NULL) &&
5802 (FIND(aff_str,
"balanced") == NULL) &&
5803 (FIND(aff_str,
"disabled") == NULL)) {
5804 __kmp_affinity_notype = __kmp_stg_find(
"KMP_AFFINITY");
5809 __kmp_affinity_type = affinity_default;
5810 __kmp_affinity_gran = KMP_HW_UNKNOWN;
5811 __kmp_affinity_top_method = affinity_top_method_default;
5812 __kmp_affinity_respect_mask = affinity_respect_mask_default;
5817 aff_str = __kmp_env_blk_var(&block,
"OMP_PROC_BIND");
5818 if (aff_str != NULL) {
5819 __kmp_affinity_type = affinity_default;
5820 __kmp_affinity_gran = KMP_HW_UNKNOWN;
5821 __kmp_affinity_top_method = affinity_top_method_default;
5822 __kmp_affinity_respect_mask = affinity_respect_mask_default;
5829 if (__kmp_nested_proc_bind.bind_types == NULL) {
5830 __kmp_nested_proc_bind.bind_types =
5831 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(
sizeof(kmp_proc_bind_t));
5832 if (__kmp_nested_proc_bind.bind_types == NULL) {
5833 KMP_FATAL(MemoryAllocFailed);
5835 __kmp_nested_proc_bind.size = 1;
5836 __kmp_nested_proc_bind.used = 1;
5837 #if KMP_AFFINITY_SUPPORTED
5838 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
5841 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5848 __kmp_msg_format(kmp_i18n_msg_AffFormatDefault,
"%P",
"%i",
"%n",
"%A");
5849 KMP_DEBUG_ASSERT(KMP_STRLEN(m.str) < KMP_AFFINITY_FORMAT_SIZE);
5851 if (__kmp_affinity_format == NULL) {
5852 __kmp_affinity_format =
5853 (
char *)KMP_INTERNAL_MALLOC(
sizeof(
char) * KMP_AFFINITY_FORMAT_SIZE);
5855 KMP_STRCPY_S(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, m.str);
5856 __kmp_str_free(&m.str);
5859 for (i = 0; i < block.count; ++i) {
5860 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
5864 if (!__kmp_init_user_locks) {
5865 if (__kmp_user_lock_kind == lk_default) {
5866 __kmp_user_lock_kind = lk_queuing;
5868 #if KMP_USE_DYNAMIC_LOCK
5869 __kmp_init_dynamic_user_locks();
5871 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5874 KMP_DEBUG_ASSERT(
string != NULL);
5875 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
5880 #if KMP_USE_DYNAMIC_LOCK
5881 __kmp_init_dynamic_user_locks();
5883 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5887 #if KMP_AFFINITY_SUPPORTED
5889 if (!TCR_4(__kmp_init_middle)) {
5894 if (__kmp_hw_subset &&
5895 __kmp_affinity_top_method == affinity_top_method_default)
5896 if (__kmp_hw_subset->specified(KMP_HW_NUMA) ||
5897 __kmp_hw_subset->specified(KMP_HW_TILE) ||
5898 __kmp_affinity_gran == KMP_HW_TILE ||
5899 __kmp_affinity_gran == KMP_HW_NUMA)
5900 __kmp_affinity_top_method = affinity_top_method_hwloc;
5902 if (__kmp_affinity_gran == KMP_HW_NUMA ||
5903 __kmp_affinity_gran == KMP_HW_TILE)
5904 __kmp_affinity_top_method = affinity_top_method_hwloc;
5908 const char *var =
"KMP_AFFINITY";
5909 KMPAffinity::pick_api();
5914 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
5915 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
5916 KMP_WARNING(AffIgnoringHwloc, var);
5917 __kmp_affinity_top_method = affinity_top_method_all;
5920 if (__kmp_affinity_type == affinity_disabled) {
5921 KMP_AFFINITY_DISABLE();
5922 }
else if (!KMP_AFFINITY_CAPABLE()) {
5923 __kmp_affinity_dispatch->determine_capable(var);
5924 if (!KMP_AFFINITY_CAPABLE()) {
5925 if (__kmp_affinity_verbose ||
5926 (__kmp_affinity_warnings &&
5927 (__kmp_affinity_type != affinity_default) &&
5928 (__kmp_affinity_type != affinity_none) &&
5929 (__kmp_affinity_type != affinity_disabled))) {
5930 KMP_WARNING(AffNotSupported, var);
5932 __kmp_affinity_type = affinity_disabled;
5933 __kmp_affinity_respect_mask = 0;
5934 __kmp_affinity_gran = KMP_HW_THREAD;
5938 if (__kmp_affinity_type == affinity_disabled) {
5939 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5940 }
else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
5942 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
5945 if (KMP_AFFINITY_CAPABLE()) {
5947 #if KMP_GROUP_AFFINITY
5952 bool exactly_one_group =
false;
5953 if (__kmp_num_proc_groups > 1) {
5955 bool within_one_group;
5958 kmp_affin_mask_t *init_mask;
5959 KMP_CPU_ALLOC(init_mask);
5960 __kmp_get_system_affinity(init_mask, TRUE);
5961 group = __kmp_get_proc_group(init_mask);
5962 within_one_group = (group >= 0);
5965 if (within_one_group) {
5966 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
5967 DWORD num_bits_in_mask = 0;
5968 for (
int bit = init_mask->begin(); bit != init_mask->end();
5969 bit = init_mask->next(bit))
5971 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
5973 KMP_CPU_FREE(init_mask);
5979 if (((__kmp_num_proc_groups > 1) &&
5980 (__kmp_affinity_type == affinity_default) &&
5981 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default)) ||
5982 (__kmp_affinity_top_method == affinity_top_method_group)) {
5983 if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
5984 exactly_one_group) {
5985 __kmp_affinity_respect_mask = FALSE;
5987 if (__kmp_affinity_type == affinity_default) {
5988 __kmp_affinity_type = affinity_compact;
5989 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5991 if (__kmp_affinity_top_method == affinity_top_method_default) {
5992 if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
5993 __kmp_affinity_top_method = affinity_top_method_group;
5994 __kmp_affinity_gran = KMP_HW_PROC_GROUP;
5995 }
else if (__kmp_affinity_gran == KMP_HW_PROC_GROUP) {
5996 __kmp_affinity_top_method = affinity_top_method_group;
5998 __kmp_affinity_top_method = affinity_top_method_all;
6000 }
else if (__kmp_affinity_top_method == affinity_top_method_group) {
6001 if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
6002 __kmp_affinity_gran = KMP_HW_PROC_GROUP;
6003 }
else if ((__kmp_affinity_gran != KMP_HW_PROC_GROUP) &&
6004 (__kmp_affinity_gran != KMP_HW_THREAD)) {
6005 const char *str = __kmp_hw_get_keyword(__kmp_affinity_gran);
6006 KMP_WARNING(AffGranTopGroup, var, str);
6007 __kmp_affinity_gran = KMP_HW_THREAD;
6010 if (__kmp_affinity_gran == KMP_HW_UNKNOWN) {
6011 __kmp_affinity_gran = KMP_HW_CORE;
6012 }
else if (__kmp_affinity_gran == KMP_HW_PROC_GROUP) {
6013 const char *str = NULL;
6014 switch (__kmp_affinity_type) {
6015 case affinity_physical:
6018 case affinity_logical:
6021 case affinity_compact:
6024 case affinity_scatter:
6027 case affinity_explicit:
6032 KMP_DEBUG_ASSERT(0);
6034 KMP_WARNING(AffGranGroupType, var, str);
6035 __kmp_affinity_gran = KMP_HW_CORE;
6043 if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
6044 #if KMP_GROUP_AFFINITY
6045 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
6046 __kmp_affinity_respect_mask = FALSE;
6050 __kmp_affinity_respect_mask = TRUE;
6053 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
6054 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
6055 if (__kmp_affinity_type == affinity_default) {
6056 __kmp_affinity_type = affinity_compact;
6057 __kmp_affinity_dups = FALSE;
6059 }
else if (__kmp_affinity_type == affinity_default) {
6060 #if KMP_MIC_SUPPORTED
6061 if (__kmp_mic_type != non_mic) {
6062 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6066 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6068 #if KMP_MIC_SUPPORTED
6069 if (__kmp_mic_type != non_mic) {
6070 __kmp_affinity_type = affinity_scatter;
6074 __kmp_affinity_type = affinity_none;
6077 if ((__kmp_affinity_gran == KMP_HW_UNKNOWN) &&
6078 (__kmp_affinity_gran_levels < 0)) {
6079 #if KMP_MIC_SUPPORTED
6080 if (__kmp_mic_type != non_mic) {
6081 __kmp_affinity_gran = KMP_HW_THREAD;
6085 __kmp_affinity_gran = KMP_HW_CORE;
6088 if (__kmp_affinity_top_method == affinity_top_method_default) {
6089 __kmp_affinity_top_method = affinity_top_method_all;
6094 K_DIAG(1, (
"__kmp_affinity_type == %d\n", __kmp_affinity_type));
6095 K_DIAG(1, (
"__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
6096 K_DIAG(1, (
"__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
6097 K_DIAG(1, (
"__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
6098 K_DIAG(1, (
"__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
6099 K_DIAG(1, (
"__kmp_affinity_respect_mask == %d\n",
6100 __kmp_affinity_respect_mask));
6101 K_DIAG(1, (
"__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
6103 KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
6104 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
6105 K_DIAG(1, (
"__kmp_nested_proc_bind.bind_types[0] == %d\n",
6106 __kmp_nested_proc_bind.bind_types[0]));
6111 if (__kmp_version) {
6112 __kmp_print_version_1();
6117 if (
string != NULL) {
6118 __kmp_aux_env_initialize(&block);
6121 __kmp_env_blk_free(&block);
6127 void __kmp_env_print() {
6129 kmp_env_blk_t block;
6131 kmp_str_buf_t buffer;
6134 __kmp_str_buf_init(&buffer);
6136 __kmp_env_blk_init(&block, NULL);
6137 __kmp_env_blk_sort(&block);
6140 __kmp_str_buf_print(&buffer,
"\n%s\n\n", KMP_I18N_STR(UserSettings));
6141 for (i = 0; i < block.count; ++i) {
6142 char const *name = block.vars[i].name;
6143 char const *value = block.vars[i].value;
6144 if ((KMP_STRLEN(name) > 4 && strncmp(name,
"KMP_", 4) == 0) ||
6145 strncmp(name,
"OMP_", 4) == 0
6146 #ifdef KMP_GOMP_COMPAT
6147 || strncmp(name,
"GOMP_", 5) == 0
6150 __kmp_str_buf_print(&buffer,
" %s=%s\n", name, value);
6153 __kmp_str_buf_print(&buffer,
"\n");
6156 __kmp_str_buf_print(&buffer,
"%s\n\n", KMP_I18N_STR(EffectiveSettings));
6157 for (
int i = 0; i < __kmp_stg_count; ++i) {
6158 if (__kmp_stg_table[i].print != NULL) {
6159 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6160 __kmp_stg_table[i].data);
6164 __kmp_printf(
"%s", buffer.str);
6166 __kmp_env_blk_free(&block);
6167 __kmp_str_buf_free(&buffer);
6173 void __kmp_env_print_2() {
6174 __kmp_display_env_impl(__kmp_display_env, __kmp_display_env_verbose);
6177 void __kmp_display_env_impl(
int display_env,
int display_env_verbose) {
6178 kmp_env_blk_t block;
6179 kmp_str_buf_t buffer;
6181 __kmp_env_format = 1;
6184 __kmp_str_buf_init(&buffer);
6186 __kmp_env_blk_init(&block, NULL);
6187 __kmp_env_blk_sort(&block);
6189 __kmp_str_buf_print(&buffer,
"\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
6190 __kmp_str_buf_print(&buffer,
" _OPENMP='%d'\n", __kmp_openmp_version);
6192 for (
int i = 0; i < __kmp_stg_count; ++i) {
6193 if (__kmp_stg_table[i].print != NULL &&
6194 ((display_env && strncmp(__kmp_stg_table[i].name,
"OMP_", 4) == 0) ||
6195 display_env_verbose)) {
6196 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6197 __kmp_stg_table[i].data);
6201 __kmp_str_buf_print(&buffer,
"%s\n", KMP_I18N_STR(DisplayEnvEnd));
6202 __kmp_str_buf_print(&buffer,
"\n");
6204 __kmp_printf(
"%s", buffer.str);
6206 __kmp_env_blk_free(&block);
6207 __kmp_str_buf_free(&buffer);
6214 void __kmp_env_dump() {
6216 kmp_env_blk_t block;
6217 kmp_str_buf_t buffer, env, notdefined;
6220 __kmp_str_buf_init(&buffer);
6221 __kmp_str_buf_init(&env);
6222 __kmp_str_buf_init(¬defined);
6224 __kmp_env_blk_init(&block, NULL);
6225 __kmp_env_blk_sort(&block);
6227 __kmp_str_buf_print(¬defined,
": %s", KMP_I18N_STR(NotDefined));
6229 for (
int i = 0; i < __kmp_stg_count; ++i) {
6230 if (__kmp_stg_table[i].print == NULL)
6232 __kmp_str_buf_clear(&env);
6233 __kmp_stg_table[i].print(&env, __kmp_stg_table[i].name,
6234 __kmp_stg_table[i].data);
6237 if (strstr(env.str, notdefined.str))
6239 __kmp_str_buf_print(&buffer,
"%s=undefined\n", __kmp_stg_table[i].name);
6241 __kmp_str_buf_cat(&buffer, env.str + 3, env.used - 3);
6244 ompd_env_block = (
char *)__kmp_allocate(buffer.used + 1);
6245 KMP_MEMCPY(ompd_env_block, buffer.str, buffer.used + 1);
6246 ompd_env_block_size = (ompd_size_t)KMP_STRLEN(ompd_env_block);
6248 __kmp_env_blk_free(&block);
6249 __kmp_str_buf_free(&buffer);
6250 __kmp_str_buf_free(&env);
6251 __kmp_str_buf_free(¬defined);
@ kmp_sch_modifier_monotonic
@ kmp_sch_modifier_nonmonotonic