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