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