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