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_DEBUG_ASSERT(j < bs_last_barrier && k < bs_last_barrier); 1718 __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j], 1719 __kmp_barrier_pattern_name[k]); 1720 } 1721 } 1722 } // __kmp_stg_print_barrier_pattern 1723 1724 // ----------------------------------------------------------------------------- 1725 // KMP_ABORT_DELAY 1726 1727 static void __kmp_stg_parse_abort_delay(char const *name, char const *value, 1728 void *data) { 1729 // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is 1730 // milliseconds. 1731 int delay = __kmp_abort_delay / 1000; 1732 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay); 1733 __kmp_abort_delay = delay * 1000; 1734 } // __kmp_stg_parse_abort_delay 1735 1736 static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name, 1737 void *data) { 1738 __kmp_stg_print_int(buffer, name, __kmp_abort_delay); 1739 } // __kmp_stg_print_abort_delay 1740 1741 // ----------------------------------------------------------------------------- 1742 // KMP_CPUINFO_FILE 1743 1744 static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value, 1745 void *data) { 1746 #if KMP_AFFINITY_SUPPORTED 1747 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file); 1748 K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file)); 1749 #endif 1750 } //__kmp_stg_parse_cpuinfo_file 1751 1752 static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer, 1753 char const *name, void *data) { 1754 #if KMP_AFFINITY_SUPPORTED 1755 if (__kmp_env_format) { 1756 KMP_STR_BUF_PRINT_NAME; 1757 } else { 1758 __kmp_str_buf_print(buffer, " %s", name); 1759 } 1760 if (__kmp_cpuinfo_file) { 1761 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file); 1762 } else { 1763 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined)); 1764 } 1765 #endif 1766 } //__kmp_stg_print_cpuinfo_file 1767 1768 // ----------------------------------------------------------------------------- 1769 // KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION 1770 1771 static void __kmp_stg_parse_force_reduction(char const *name, char const *value, 1772 void *data) { 1773 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data; 1774 int rc; 1775 1776 rc = __kmp_stg_check_rivals(name, value, reduction->rivals); 1777 if (rc) { 1778 return; 1779 } 1780 if (reduction->force) { 1781 if (value != 0) { 1782 if (__kmp_str_match("critical", 0, value)) 1783 __kmp_force_reduction_method = critical_reduce_block; 1784 else if (__kmp_str_match("atomic", 0, value)) 1785 __kmp_force_reduction_method = atomic_reduce_block; 1786 else if (__kmp_str_match("tree", 0, value)) 1787 __kmp_force_reduction_method = tree_reduce_block; 1788 else { 1789 KMP_FATAL(UnknownForceReduction, name, value); 1790 } 1791 } 1792 } else { 1793 __kmp_stg_parse_bool(name, value, &__kmp_determ_red); 1794 if (__kmp_determ_red) { 1795 __kmp_force_reduction_method = tree_reduce_block; 1796 } else { 1797 __kmp_force_reduction_method = reduction_method_not_defined; 1798 } 1799 } 1800 K_DIAG(1, ("__kmp_force_reduction_method == %d\n", 1801 __kmp_force_reduction_method)); 1802 } // __kmp_stg_parse_force_reduction 1803 1804 static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer, 1805 char const *name, void *data) { 1806 1807 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data; 1808 if (reduction->force) { 1809 if (__kmp_force_reduction_method == critical_reduce_block) { 1810 __kmp_stg_print_str(buffer, name, "critical"); 1811 } else if (__kmp_force_reduction_method == atomic_reduce_block) { 1812 __kmp_stg_print_str(buffer, name, "atomic"); 1813 } else if (__kmp_force_reduction_method == tree_reduce_block) { 1814 __kmp_stg_print_str(buffer, name, "tree"); 1815 } else { 1816 if (__kmp_env_format) { 1817 KMP_STR_BUF_PRINT_NAME; 1818 } else { 1819 __kmp_str_buf_print(buffer, " %s", name); 1820 } 1821 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined)); 1822 } 1823 } else { 1824 __kmp_stg_print_bool(buffer, name, __kmp_determ_red); 1825 } 1826 1827 } // __kmp_stg_print_force_reduction 1828 1829 // ----------------------------------------------------------------------------- 1830 // KMP_STORAGE_MAP 1831 1832 static void __kmp_stg_parse_storage_map(char const *name, char const *value, 1833 void *data) { 1834 if (__kmp_str_match("verbose", 1, value)) { 1835 __kmp_storage_map = TRUE; 1836 __kmp_storage_map_verbose = TRUE; 1837 __kmp_storage_map_verbose_specified = TRUE; 1838 1839 } else { 1840 __kmp_storage_map_verbose = FALSE; 1841 __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!! 1842 } 1843 } // __kmp_stg_parse_storage_map 1844 1845 static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name, 1846 void *data) { 1847 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) { 1848 __kmp_stg_print_str(buffer, name, "verbose"); 1849 } else { 1850 __kmp_stg_print_bool(buffer, name, __kmp_storage_map); 1851 } 1852 } // __kmp_stg_print_storage_map 1853 1854 // ----------------------------------------------------------------------------- 1855 // KMP_ALL_THREADPRIVATE 1856 1857 static void __kmp_stg_parse_all_threadprivate(char const *name, 1858 char const *value, void *data) { 1859 __kmp_stg_parse_int(name, value, 1860 __kmp_allThreadsSpecified ? __kmp_max_nth : 1, 1861 __kmp_max_nth, &__kmp_tp_capacity); 1862 } // __kmp_stg_parse_all_threadprivate 1863 1864 static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer, 1865 char const *name, void *data) { 1866 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity); 1867 } 1868 1869 // ----------------------------------------------------------------------------- 1870 // KMP_FOREIGN_THREADS_THREADPRIVATE 1871 1872 static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name, 1873 char const *value, 1874 void *data) { 1875 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp); 1876 } // __kmp_stg_parse_foreign_threads_threadprivate 1877 1878 static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer, 1879 char const *name, 1880 void *data) { 1881 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp); 1882 } // __kmp_stg_print_foreign_threads_threadprivate 1883 1884 // ----------------------------------------------------------------------------- 1885 // KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD 1886 1887 #if KMP_AFFINITY_SUPPORTED 1888 // Parse the proc id list. Return TRUE if successful, FALSE otherwise. 1889 static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env, 1890 const char **nextEnv, 1891 char **proclist) { 1892 const char *scan = env; 1893 const char *next = scan; 1894 int empty = TRUE; 1895 1896 *proclist = NULL; 1897 1898 for (;;) { 1899 int start, end, stride; 1900 1901 SKIP_WS(scan); 1902 next = scan; 1903 if (*next == '\0') { 1904 break; 1905 } 1906 1907 if (*next == '{') { 1908 int num; 1909 next++; // skip '{' 1910 SKIP_WS(next); 1911 scan = next; 1912 1913 // Read the first integer in the set. 1914 if ((*next < '0') || (*next > '9')) { 1915 KMP_WARNING(AffSyntaxError, var); 1916 return FALSE; 1917 } 1918 SKIP_DIGITS(next); 1919 num = __kmp_str_to_int(scan, *next); 1920 KMP_ASSERT(num >= 0); 1921 1922 for (;;) { 1923 // Check for end of set. 1924 SKIP_WS(next); 1925 if (*next == '}') { 1926 next++; // skip '}' 1927 break; 1928 } 1929 1930 // Skip optional comma. 1931 if (*next == ',') { 1932 next++; 1933 } 1934 SKIP_WS(next); 1935 1936 // Read the next integer in the set. 1937 scan = next; 1938 if ((*next < '0') || (*next > '9')) { 1939 KMP_WARNING(AffSyntaxError, var); 1940 return FALSE; 1941 } 1942 1943 SKIP_DIGITS(next); 1944 num = __kmp_str_to_int(scan, *next); 1945 KMP_ASSERT(num >= 0); 1946 } 1947 empty = FALSE; 1948 1949 SKIP_WS(next); 1950 if (*next == ',') { 1951 next++; 1952 } 1953 scan = next; 1954 continue; 1955 } 1956 1957 // Next character is not an integer => end of list 1958 if ((*next < '0') || (*next > '9')) { 1959 if (empty) { 1960 KMP_WARNING(AffSyntaxError, var); 1961 return FALSE; 1962 } 1963 break; 1964 } 1965 1966 // Read the first integer. 1967 SKIP_DIGITS(next); 1968 start = __kmp_str_to_int(scan, *next); 1969 KMP_ASSERT(start >= 0); 1970 SKIP_WS(next); 1971 1972 // If this isn't a range, then go on. 1973 if (*next != '-') { 1974 empty = FALSE; 1975 1976 // Skip optional comma. 1977 if (*next == ',') { 1978 next++; 1979 } 1980 scan = next; 1981 continue; 1982 } 1983 1984 // This is a range. Skip over the '-' and read in the 2nd int. 1985 next++; // skip '-' 1986 SKIP_WS(next); 1987 scan = next; 1988 if ((*next < '0') || (*next > '9')) { 1989 KMP_WARNING(AffSyntaxError, var); 1990 return FALSE; 1991 } 1992 SKIP_DIGITS(next); 1993 end = __kmp_str_to_int(scan, *next); 1994 KMP_ASSERT(end >= 0); 1995 1996 // Check for a stride parameter 1997 stride = 1; 1998 SKIP_WS(next); 1999 if (*next == ':') { 2000 // A stride is specified. Skip over the ':" and read the 3rd int. 2001 int sign = +1; 2002 next++; // skip ':' 2003 SKIP_WS(next); 2004 scan = next; 2005 if (*next == '-') { 2006 sign = -1; 2007 next++; 2008 SKIP_WS(next); 2009 scan = next; 2010 } 2011 if ((*next < '0') || (*next > '9')) { 2012 KMP_WARNING(AffSyntaxError, var); 2013 return FALSE; 2014 } 2015 SKIP_DIGITS(next); 2016 stride = __kmp_str_to_int(scan, *next); 2017 KMP_ASSERT(stride >= 0); 2018 stride *= sign; 2019 } 2020 2021 // Do some range checks. 2022 if (stride == 0) { 2023 KMP_WARNING(AffZeroStride, var); 2024 return FALSE; 2025 } 2026 if (stride > 0) { 2027 if (start > end) { 2028 KMP_WARNING(AffStartGreaterEnd, var, start, end); 2029 return FALSE; 2030 } 2031 } else { 2032 if (start < end) { 2033 KMP_WARNING(AffStrideLessZero, var, start, end); 2034 return FALSE; 2035 } 2036 } 2037 if ((end - start) / stride > 65536) { 2038 KMP_WARNING(AffRangeTooBig, var, end, start, stride); 2039 return FALSE; 2040 } 2041 2042 empty = FALSE; 2043 2044 // Skip optional comma. 2045 SKIP_WS(next); 2046 if (*next == ',') { 2047 next++; 2048 } 2049 scan = next; 2050 } 2051 2052 *nextEnv = next; 2053 2054 { 2055 ptrdiff_t len = next - env; 2056 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char)); 2057 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char)); 2058 retlist[len] = '\0'; 2059 *proclist = retlist; 2060 } 2061 return TRUE; 2062 } 2063 2064 // If KMP_AFFINITY is specified without a type, then 2065 // __kmp_affinity_notype should point to its setting. 2066 static kmp_setting_t *__kmp_affinity_notype = NULL; 2067 2068 static void __kmp_parse_affinity_env(char const *name, char const *value, 2069 enum affinity_type *out_type, 2070 char **out_proclist, int *out_verbose, 2071 int *out_warn, int *out_respect, 2072 enum affinity_gran *out_gran, 2073 int *out_gran_levels, int *out_dups, 2074 int *out_compact, int *out_offset) { 2075 char *buffer = NULL; // Copy of env var value. 2076 char *buf = NULL; // Buffer for strtok_r() function. 2077 char *next = NULL; // end of token / start of next. 2078 const char *start; // start of current token (for err msgs) 2079 int count = 0; // Counter of parsed integer numbers. 2080 int number[2]; // Parsed numbers. 2081 2082 // Guards. 2083 int type = 0; 2084 int proclist = 0; 2085 int verbose = 0; 2086 int warnings = 0; 2087 int respect = 0; 2088 int gran = 0; 2089 int dups = 0; 2090 2091 KMP_ASSERT(value != NULL); 2092 2093 if (TCR_4(__kmp_init_middle)) { 2094 KMP_WARNING(EnvMiddleWarn, name); 2095 __kmp_env_toPrint(name, 0); 2096 return; 2097 } 2098 __kmp_env_toPrint(name, 1); 2099 2100 buffer = 2101 __kmp_str_format("%s", value); // Copy env var to keep original intact. 2102 buf = buffer; 2103 SKIP_WS(buf); 2104 2105 // Helper macros. 2106 2107 // If we see a parse error, emit a warning and scan to the next ",". 2108 // 2109 // FIXME - there's got to be a better way to print an error 2110 // message, hopefully without overwriting peices of buf. 2111 #define EMIT_WARN(skip, errlist) \ 2112 { \ 2113 char ch; \ 2114 if (skip) { \ 2115 SKIP_TO(next, ','); \ 2116 } \ 2117 ch = *next; \ 2118 *next = '\0'; \ 2119 KMP_WARNING errlist; \ 2120 *next = ch; \ 2121 if (skip) { \ 2122 if (ch == ',') \ 2123 next++; \ 2124 } \ 2125 buf = next; \ 2126 } 2127 2128 #define _set_param(_guard, _var, _val) \ 2129 { \ 2130 if (_guard == 0) { \ 2131 _var = _val; \ 2132 } else { \ 2133 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \ 2134 } \ 2135 ++_guard; \ 2136 } 2137 2138 #define set_type(val) _set_param(type, *out_type, val) 2139 #define set_verbose(val) _set_param(verbose, *out_verbose, val) 2140 #define set_warnings(val) _set_param(warnings, *out_warn, val) 2141 #define set_respect(val) _set_param(respect, *out_respect, val) 2142 #define set_dups(val) _set_param(dups, *out_dups, val) 2143 #define set_proclist(val) _set_param(proclist, *out_proclist, val) 2144 2145 #define set_gran(val, levels) \ 2146 { \ 2147 if (gran == 0) { \ 2148 *out_gran = val; \ 2149 *out_gran_levels = levels; \ 2150 } else { \ 2151 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \ 2152 } \ 2153 ++gran; \ 2154 } 2155 2156 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) && 2157 (__kmp_nested_proc_bind.used > 0)); 2158 2159 while (*buf != '\0') { 2160 start = next = buf; 2161 2162 if (__kmp_match_str("none", buf, CCAST(const char **, &next))) { 2163 set_type(affinity_none); 2164 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false; 2165 buf = next; 2166 } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) { 2167 set_type(affinity_scatter); 2168 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel; 2169 buf = next; 2170 } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) { 2171 set_type(affinity_compact); 2172 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel; 2173 buf = next; 2174 } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) { 2175 set_type(affinity_logical); 2176 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel; 2177 buf = next; 2178 } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) { 2179 set_type(affinity_physical); 2180 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel; 2181 buf = next; 2182 } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) { 2183 set_type(affinity_explicit); 2184 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel; 2185 buf = next; 2186 } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) { 2187 set_type(affinity_balanced); 2188 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel; 2189 buf = next; 2190 } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) { 2191 set_type(affinity_disabled); 2192 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false; 2193 buf = next; 2194 } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) { 2195 set_verbose(TRUE); 2196 buf = next; 2197 } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) { 2198 set_verbose(FALSE); 2199 buf = next; 2200 } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) { 2201 set_warnings(TRUE); 2202 buf = next; 2203 } else if (__kmp_match_str("nowarnings", buf, 2204 CCAST(const char **, &next))) { 2205 set_warnings(FALSE); 2206 buf = next; 2207 } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) { 2208 set_respect(TRUE); 2209 buf = next; 2210 } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) { 2211 set_respect(FALSE); 2212 buf = next; 2213 } else if (__kmp_match_str("duplicates", buf, 2214 CCAST(const char **, &next)) || 2215 __kmp_match_str("dups", buf, CCAST(const char **, &next))) { 2216 set_dups(TRUE); 2217 buf = next; 2218 } else if (__kmp_match_str("noduplicates", buf, 2219 CCAST(const char **, &next)) || 2220 __kmp_match_str("nodups", buf, CCAST(const char **, &next))) { 2221 set_dups(FALSE); 2222 buf = next; 2223 } else if (__kmp_match_str("granularity", buf, 2224 CCAST(const char **, &next)) || 2225 __kmp_match_str("gran", buf, CCAST(const char **, &next))) { 2226 SKIP_WS(next); 2227 if (*next != '=') { 2228 EMIT_WARN(TRUE, (AffInvalidParam, name, start)); 2229 continue; 2230 } 2231 next++; // skip '=' 2232 SKIP_WS(next); 2233 2234 buf = next; 2235 if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) { 2236 set_gran(affinity_gran_fine, -1); 2237 buf = next; 2238 } else if (__kmp_match_str("thread", buf, CCAST(const char **, &next))) { 2239 set_gran(affinity_gran_thread, -1); 2240 buf = next; 2241 } else if (__kmp_match_str("core", buf, CCAST(const char **, &next))) { 2242 set_gran(affinity_gran_core, -1); 2243 buf = next; 2244 #if KMP_USE_HWLOC 2245 } else if (__kmp_match_str("tile", buf, CCAST(const char **, &next))) { 2246 set_gran(affinity_gran_tile, -1); 2247 buf = next; 2248 #endif 2249 } else if (__kmp_match_str("die", buf, CCAST(const char **, &next))) { 2250 set_gran(affinity_gran_die, -1); 2251 buf = next; 2252 } else if (__kmp_match_str("package", buf, CCAST(const char **, &next))) { 2253 set_gran(affinity_gran_package, -1); 2254 buf = next; 2255 } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) { 2256 set_gran(affinity_gran_node, -1); 2257 buf = next; 2258 #if KMP_GROUP_AFFINITY 2259 } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) { 2260 set_gran(affinity_gran_group, -1); 2261 buf = next; 2262 #endif /* KMP_GROUP AFFINITY */ 2263 } else if ((*buf >= '0') && (*buf <= '9')) { 2264 int n; 2265 next = buf; 2266 SKIP_DIGITS(next); 2267 n = __kmp_str_to_int(buf, *next); 2268 KMP_ASSERT(n >= 0); 2269 buf = next; 2270 set_gran(affinity_gran_default, n); 2271 } else { 2272 EMIT_WARN(TRUE, (AffInvalidParam, name, start)); 2273 continue; 2274 } 2275 } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) { 2276 char *temp_proclist; 2277 2278 SKIP_WS(next); 2279 if (*next != '=') { 2280 EMIT_WARN(TRUE, (AffInvalidParam, name, start)); 2281 continue; 2282 } 2283 next++; // skip '=' 2284 SKIP_WS(next); 2285 if (*next != '[') { 2286 EMIT_WARN(TRUE, (AffInvalidParam, name, start)); 2287 continue; 2288 } 2289 next++; // skip '[' 2290 buf = next; 2291 if (!__kmp_parse_affinity_proc_id_list( 2292 name, buf, CCAST(const char **, &next), &temp_proclist)) { 2293 // warning already emitted. 2294 SKIP_TO(next, ']'); 2295 if (*next == ']') 2296 next++; 2297 SKIP_TO(next, ','); 2298 if (*next == ',') 2299 next++; 2300 buf = next; 2301 continue; 2302 } 2303 if (*next != ']') { 2304 EMIT_WARN(TRUE, (AffInvalidParam, name, start)); 2305 continue; 2306 } 2307 next++; // skip ']' 2308 set_proclist(temp_proclist); 2309 } else if ((*buf >= '0') && (*buf <= '9')) { 2310 // Parse integer numbers -- permute and offset. 2311 int n; 2312 next = buf; 2313 SKIP_DIGITS(next); 2314 n = __kmp_str_to_int(buf, *next); 2315 KMP_ASSERT(n >= 0); 2316 buf = next; 2317 if (count < 2) { 2318 number[count] = n; 2319 } else { 2320 KMP_WARNING(AffManyParams, name, start); 2321 } 2322 ++count; 2323 } else { 2324 EMIT_WARN(TRUE, (AffInvalidParam, name, start)); 2325 continue; 2326 } 2327 2328 SKIP_WS(next); 2329 if (*next == ',') { 2330 next++; 2331 SKIP_WS(next); 2332 } else if (*next != '\0') { 2333 const char *temp = next; 2334 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp)); 2335 continue; 2336 } 2337 buf = next; 2338 } // while 2339 2340 #undef EMIT_WARN 2341 #undef _set_param 2342 #undef set_type 2343 #undef set_verbose 2344 #undef set_warnings 2345 #undef set_respect 2346 #undef set_granularity 2347 2348 __kmp_str_free(&buffer); 2349 2350 if (proclist) { 2351 if (!type) { 2352 KMP_WARNING(AffProcListNoType, name); 2353 *out_type = affinity_explicit; 2354 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel; 2355 } else if (*out_type != affinity_explicit) { 2356 KMP_WARNING(AffProcListNotExplicit, name); 2357 KMP_ASSERT(*out_proclist != NULL); 2358 KMP_INTERNAL_FREE(*out_proclist); 2359 *out_proclist = NULL; 2360 } 2361 } 2362 switch (*out_type) { 2363 case affinity_logical: 2364 case affinity_physical: { 2365 if (count > 0) { 2366 *out_offset = number[0]; 2367 } 2368 if (count > 1) { 2369 KMP_WARNING(AffManyParamsForLogic, name, number[1]); 2370 } 2371 } break; 2372 case affinity_balanced: { 2373 if (count > 0) { 2374 *out_compact = number[0]; 2375 } 2376 if (count > 1) { 2377 *out_offset = number[1]; 2378 } 2379 2380 if (__kmp_affinity_gran == affinity_gran_default) { 2381 #if KMP_MIC_SUPPORTED 2382 if (__kmp_mic_type != non_mic) { 2383 if (__kmp_affinity_verbose || __kmp_affinity_warnings) { 2384 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine"); 2385 } 2386 __kmp_affinity_gran = affinity_gran_fine; 2387 } else 2388 #endif 2389 { 2390 if (__kmp_affinity_verbose || __kmp_affinity_warnings) { 2391 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core"); 2392 } 2393 __kmp_affinity_gran = affinity_gran_core; 2394 } 2395 } 2396 } break; 2397 case affinity_scatter: 2398 case affinity_compact: { 2399 if (count > 0) { 2400 *out_compact = number[0]; 2401 } 2402 if (count > 1) { 2403 *out_offset = number[1]; 2404 } 2405 } break; 2406 case affinity_explicit: { 2407 if (*out_proclist == NULL) { 2408 KMP_WARNING(AffNoProcList, name); 2409 __kmp_affinity_type = affinity_none; 2410 } 2411 if (count > 0) { 2412 KMP_WARNING(AffNoParam, name, "explicit"); 2413 } 2414 } break; 2415 case affinity_none: { 2416 if (count > 0) { 2417 KMP_WARNING(AffNoParam, name, "none"); 2418 } 2419 } break; 2420 case affinity_disabled: { 2421 if (count > 0) { 2422 KMP_WARNING(AffNoParam, name, "disabled"); 2423 } 2424 } break; 2425 case affinity_default: { 2426 if (count > 0) { 2427 KMP_WARNING(AffNoParam, name, "default"); 2428 } 2429 } break; 2430 default: { 2431 KMP_ASSERT(0); 2432 } 2433 } 2434 } // __kmp_parse_affinity_env 2435 2436 static void __kmp_stg_parse_affinity(char const *name, char const *value, 2437 void *data) { 2438 kmp_setting_t **rivals = (kmp_setting_t **)data; 2439 int rc; 2440 2441 rc = __kmp_stg_check_rivals(name, value, rivals); 2442 if (rc) { 2443 return; 2444 } 2445 2446 __kmp_parse_affinity_env(name, value, &__kmp_affinity_type, 2447 &__kmp_affinity_proclist, &__kmp_affinity_verbose, 2448 &__kmp_affinity_warnings, 2449 &__kmp_affinity_respect_mask, &__kmp_affinity_gran, 2450 &__kmp_affinity_gran_levels, &__kmp_affinity_dups, 2451 &__kmp_affinity_compact, &__kmp_affinity_offset); 2452 2453 } // __kmp_stg_parse_affinity 2454 2455 static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name, 2456 void *data) { 2457 if (__kmp_env_format) { 2458 KMP_STR_BUF_PRINT_NAME_EX(name); 2459 } else { 2460 __kmp_str_buf_print(buffer, " %s='", name); 2461 } 2462 if (__kmp_affinity_verbose) { 2463 __kmp_str_buf_print(buffer, "%s,", "verbose"); 2464 } else { 2465 __kmp_str_buf_print(buffer, "%s,", "noverbose"); 2466 } 2467 if (__kmp_affinity_warnings) { 2468 __kmp_str_buf_print(buffer, "%s,", "warnings"); 2469 } else { 2470 __kmp_str_buf_print(buffer, "%s,", "nowarnings"); 2471 } 2472 if (KMP_AFFINITY_CAPABLE()) { 2473 if (__kmp_affinity_respect_mask) { 2474 __kmp_str_buf_print(buffer, "%s,", "respect"); 2475 } else { 2476 __kmp_str_buf_print(buffer, "%s,", "norespect"); 2477 } 2478 switch (__kmp_affinity_gran) { 2479 case affinity_gran_default: 2480 __kmp_str_buf_print(buffer, "%s", "granularity=default,"); 2481 break; 2482 case affinity_gran_fine: 2483 __kmp_str_buf_print(buffer, "%s", "granularity=fine,"); 2484 break; 2485 case affinity_gran_thread: 2486 __kmp_str_buf_print(buffer, "%s", "granularity=thread,"); 2487 break; 2488 case affinity_gran_core: 2489 __kmp_str_buf_print(buffer, "%s", "granularity=core,"); 2490 break; 2491 case affinity_gran_package: 2492 __kmp_str_buf_print(buffer, "%s", "granularity=package,"); 2493 break; 2494 case affinity_gran_node: 2495 __kmp_str_buf_print(buffer, "%s", "granularity=node,"); 2496 break; 2497 #if KMP_GROUP_AFFINITY 2498 case affinity_gran_group: 2499 __kmp_str_buf_print(buffer, "%s", "granularity=group,"); 2500 break; 2501 #endif /* KMP_GROUP_AFFINITY */ 2502 } 2503 } 2504 if (!KMP_AFFINITY_CAPABLE()) { 2505 __kmp_str_buf_print(buffer, "%s", "disabled"); 2506 } else 2507 switch (__kmp_affinity_type) { 2508 case affinity_none: 2509 __kmp_str_buf_print(buffer, "%s", "none"); 2510 break; 2511 case affinity_physical: 2512 __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset); 2513 break; 2514 case affinity_logical: 2515 __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset); 2516 break; 2517 case affinity_compact: 2518 __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact, 2519 __kmp_affinity_offset); 2520 break; 2521 case affinity_scatter: 2522 __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact, 2523 __kmp_affinity_offset); 2524 break; 2525 case affinity_explicit: 2526 __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist", 2527 __kmp_affinity_proclist, "explicit"); 2528 break; 2529 case affinity_balanced: 2530 __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced", 2531 __kmp_affinity_compact, __kmp_affinity_offset); 2532 break; 2533 case affinity_disabled: 2534 __kmp_str_buf_print(buffer, "%s", "disabled"); 2535 break; 2536 case affinity_default: 2537 __kmp_str_buf_print(buffer, "%s", "default"); 2538 break; 2539 default: 2540 __kmp_str_buf_print(buffer, "%s", "<unknown>"); 2541 break; 2542 } 2543 __kmp_str_buf_print(buffer, "'\n"); 2544 } //__kmp_stg_print_affinity 2545 2546 #ifdef KMP_GOMP_COMPAT 2547 2548 static void __kmp_stg_parse_gomp_cpu_affinity(char const *name, 2549 char const *value, void *data) { 2550 const char *next = NULL; 2551 char *temp_proclist; 2552 kmp_setting_t **rivals = (kmp_setting_t **)data; 2553 int rc; 2554 2555 rc = __kmp_stg_check_rivals(name, value, rivals); 2556 if (rc) { 2557 return; 2558 } 2559 2560 if (TCR_4(__kmp_init_middle)) { 2561 KMP_WARNING(EnvMiddleWarn, name); 2562 __kmp_env_toPrint(name, 0); 2563 return; 2564 } 2565 2566 __kmp_env_toPrint(name, 1); 2567 2568 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) { 2569 SKIP_WS(next); 2570 if (*next == '\0') { 2571 // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=... 2572 __kmp_affinity_proclist = temp_proclist; 2573 __kmp_affinity_type = affinity_explicit; 2574 __kmp_affinity_gran = affinity_gran_fine; 2575 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel; 2576 } else { 2577 KMP_WARNING(AffSyntaxError, name); 2578 if (temp_proclist != NULL) { 2579 KMP_INTERNAL_FREE((void *)temp_proclist); 2580 } 2581 } 2582 } else { 2583 // Warning already emitted 2584 __kmp_affinity_type = affinity_none; 2585 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false; 2586 } 2587 } // __kmp_stg_parse_gomp_cpu_affinity 2588 2589 #endif /* KMP_GOMP_COMPAT */ 2590 2591 /*----------------------------------------------------------------------------- 2592 The OMP_PLACES proc id list parser. Here is the grammar: 2593 2594 place_list := place 2595 place_list := place , place_list 2596 place := num 2597 place := place : num 2598 place := place : num : signed 2599 place := { subplacelist } 2600 place := ! place // (lowest priority) 2601 subplace_list := subplace 2602 subplace_list := subplace , subplace_list 2603 subplace := num 2604 subplace := num : num 2605 subplace := num : num : signed 2606 signed := num 2607 signed := + signed 2608 signed := - signed 2609 -----------------------------------------------------------------------------*/ 2610 2611 // Warning to issue for syntax error during parsing of OMP_PLACES 2612 static inline void __kmp_omp_places_syntax_warn(const char *var) { 2613 KMP_WARNING(SyntaxErrorUsing, var, "\"cores\""); 2614 } 2615 2616 static int __kmp_parse_subplace_list(const char *var, const char **scan) { 2617 const char *next; 2618 2619 for (;;) { 2620 int start, count, stride; 2621 2622 // 2623 // Read in the starting proc id 2624 // 2625 SKIP_WS(*scan); 2626 if ((**scan < '0') || (**scan > '9')) { 2627 __kmp_omp_places_syntax_warn(var); 2628 return FALSE; 2629 } 2630 next = *scan; 2631 SKIP_DIGITS(next); 2632 start = __kmp_str_to_int(*scan, *next); 2633 KMP_ASSERT(start >= 0); 2634 *scan = next; 2635 2636 // valid follow sets are ',' ':' and '}' 2637 SKIP_WS(*scan); 2638 if (**scan == '}') { 2639 break; 2640 } 2641 if (**scan == ',') { 2642 (*scan)++; // skip ',' 2643 continue; 2644 } 2645 if (**scan != ':') { 2646 __kmp_omp_places_syntax_warn(var); 2647 return FALSE; 2648 } 2649 (*scan)++; // skip ':' 2650 2651 // Read count parameter 2652 SKIP_WS(*scan); 2653 if ((**scan < '0') || (**scan > '9')) { 2654 __kmp_omp_places_syntax_warn(var); 2655 return FALSE; 2656 } 2657 next = *scan; 2658 SKIP_DIGITS(next); 2659 count = __kmp_str_to_int(*scan, *next); 2660 KMP_ASSERT(count >= 0); 2661 *scan = next; 2662 2663 // valid follow sets are ',' ':' and '}' 2664 SKIP_WS(*scan); 2665 if (**scan == '}') { 2666 break; 2667 } 2668 if (**scan == ',') { 2669 (*scan)++; // skip ',' 2670 continue; 2671 } 2672 if (**scan != ':') { 2673 __kmp_omp_places_syntax_warn(var); 2674 return FALSE; 2675 } 2676 (*scan)++; // skip ':' 2677 2678 // Read stride parameter 2679 int sign = +1; 2680 for (;;) { 2681 SKIP_WS(*scan); 2682 if (**scan == '+') { 2683 (*scan)++; // skip '+' 2684 continue; 2685 } 2686 if (**scan == '-') { 2687 sign *= -1; 2688 (*scan)++; // skip '-' 2689 continue; 2690 } 2691 break; 2692 } 2693 SKIP_WS(*scan); 2694 if ((**scan < '0') || (**scan > '9')) { 2695 __kmp_omp_places_syntax_warn(var); 2696 return FALSE; 2697 } 2698 next = *scan; 2699 SKIP_DIGITS(next); 2700 stride = __kmp_str_to_int(*scan, *next); 2701 KMP_ASSERT(stride >= 0); 2702 *scan = next; 2703 stride *= sign; 2704 2705 // valid follow sets are ',' and '}' 2706 SKIP_WS(*scan); 2707 if (**scan == '}') { 2708 break; 2709 } 2710 if (**scan == ',') { 2711 (*scan)++; // skip ',' 2712 continue; 2713 } 2714 2715 __kmp_omp_places_syntax_warn(var); 2716 return FALSE; 2717 } 2718 return TRUE; 2719 } 2720 2721 static int __kmp_parse_place(const char *var, const char **scan) { 2722 const char *next; 2723 2724 // valid follow sets are '{' '!' and num 2725 SKIP_WS(*scan); 2726 if (**scan == '{') { 2727 (*scan)++; // skip '{' 2728 if (!__kmp_parse_subplace_list(var, scan)) { 2729 return FALSE; 2730 } 2731 if (**scan != '}') { 2732 __kmp_omp_places_syntax_warn(var); 2733 return FALSE; 2734 } 2735 (*scan)++; // skip '}' 2736 } else if (**scan == '!') { 2737 (*scan)++; // skip '!' 2738 return __kmp_parse_place(var, scan); //'!' has lower precedence than ':' 2739 } else if ((**scan >= '0') && (**scan <= '9')) { 2740 next = *scan; 2741 SKIP_DIGITS(next); 2742 int proc = __kmp_str_to_int(*scan, *next); 2743 KMP_ASSERT(proc >= 0); 2744 *scan = next; 2745 } else { 2746 __kmp_omp_places_syntax_warn(var); 2747 return FALSE; 2748 } 2749 return TRUE; 2750 } 2751 2752 static int __kmp_parse_place_list(const char *var, const char *env, 2753 char **place_list) { 2754 const char *scan = env; 2755 const char *next = scan; 2756 2757 for (;;) { 2758 int count, stride; 2759 2760 if (!__kmp_parse_place(var, &scan)) { 2761 return FALSE; 2762 } 2763 2764 // valid follow sets are ',' ':' and EOL 2765 SKIP_WS(scan); 2766 if (*scan == '\0') { 2767 break; 2768 } 2769 if (*scan == ',') { 2770 scan++; // skip ',' 2771 continue; 2772 } 2773 if (*scan != ':') { 2774 __kmp_omp_places_syntax_warn(var); 2775 return FALSE; 2776 } 2777 scan++; // skip ':' 2778 2779 // Read count parameter 2780 SKIP_WS(scan); 2781 if ((*scan < '0') || (*scan > '9')) { 2782 __kmp_omp_places_syntax_warn(var); 2783 return FALSE; 2784 } 2785 next = scan; 2786 SKIP_DIGITS(next); 2787 count = __kmp_str_to_int(scan, *next); 2788 KMP_ASSERT(count >= 0); 2789 scan = next; 2790 2791 // valid follow sets are ',' ':' and EOL 2792 SKIP_WS(scan); 2793 if (*scan == '\0') { 2794 break; 2795 } 2796 if (*scan == ',') { 2797 scan++; // skip ',' 2798 continue; 2799 } 2800 if (*scan != ':') { 2801 __kmp_omp_places_syntax_warn(var); 2802 return FALSE; 2803 } 2804 scan++; // skip ':' 2805 2806 // Read stride parameter 2807 int sign = +1; 2808 for (;;) { 2809 SKIP_WS(scan); 2810 if (*scan == '+') { 2811 scan++; // skip '+' 2812 continue; 2813 } 2814 if (*scan == '-') { 2815 sign *= -1; 2816 scan++; // skip '-' 2817 continue; 2818 } 2819 break; 2820 } 2821 SKIP_WS(scan); 2822 if ((*scan < '0') || (*scan > '9')) { 2823 __kmp_omp_places_syntax_warn(var); 2824 return FALSE; 2825 } 2826 next = scan; 2827 SKIP_DIGITS(next); 2828 stride = __kmp_str_to_int(scan, *next); 2829 KMP_ASSERT(stride >= 0); 2830 scan = next; 2831 stride *= sign; 2832 2833 // valid follow sets are ',' and EOL 2834 SKIP_WS(scan); 2835 if (*scan == '\0') { 2836 break; 2837 } 2838 if (*scan == ',') { 2839 scan++; // skip ',' 2840 continue; 2841 } 2842 2843 __kmp_omp_places_syntax_warn(var); 2844 return FALSE; 2845 } 2846 2847 { 2848 ptrdiff_t len = scan - env; 2849 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char)); 2850 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char)); 2851 retlist[len] = '\0'; 2852 *place_list = retlist; 2853 } 2854 return TRUE; 2855 } 2856 2857 static void __kmp_stg_parse_places(char const *name, char const *value, 2858 void *data) { 2859 int count; 2860 const char *scan = value; 2861 const char *next = scan; 2862 const char *kind = "\"threads\""; 2863 kmp_setting_t **rivals = (kmp_setting_t **)data; 2864 int rc; 2865 2866 rc = __kmp_stg_check_rivals(name, value, rivals); 2867 if (rc) { 2868 return; 2869 } 2870 2871 if (__kmp_match_str("threads", scan, &next)) { 2872 scan = next; 2873 __kmp_affinity_type = affinity_compact; 2874 __kmp_affinity_gran = affinity_gran_thread; 2875 __kmp_affinity_dups = FALSE; 2876 kind = "\"threads\""; 2877 } else if (__kmp_match_str("cores", scan, &next)) { 2878 scan = next; 2879 __kmp_affinity_type = affinity_compact; 2880 __kmp_affinity_gran = affinity_gran_core; 2881 __kmp_affinity_dups = FALSE; 2882 kind = "\"cores\""; 2883 #if KMP_USE_HWLOC 2884 } else if (__kmp_match_str("tiles", scan, &next)) { 2885 scan = next; 2886 __kmp_affinity_type = affinity_compact; 2887 __kmp_affinity_gran = affinity_gran_tile; 2888 __kmp_affinity_dups = FALSE; 2889 kind = "\"tiles\""; 2890 #endif 2891 } else if (__kmp_match_str("dice", scan, &next) || 2892 __kmp_match_str("dies", scan, &next)) { 2893 scan = next; 2894 __kmp_affinity_type = affinity_compact; 2895 __kmp_affinity_gran = affinity_gran_die; 2896 __kmp_affinity_dups = FALSE; 2897 kind = "\"dice\""; 2898 } else if (__kmp_match_str("sockets", scan, &next)) { 2899 scan = next; 2900 __kmp_affinity_type = affinity_compact; 2901 __kmp_affinity_gran = affinity_gran_package; 2902 __kmp_affinity_dups = FALSE; 2903 kind = "\"sockets\""; 2904 } else { 2905 if (__kmp_affinity_proclist != NULL) { 2906 KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist); 2907 __kmp_affinity_proclist = NULL; 2908 } 2909 if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) { 2910 __kmp_affinity_type = affinity_explicit; 2911 __kmp_affinity_gran = affinity_gran_fine; 2912 __kmp_affinity_dups = FALSE; 2913 } else { 2914 // Syntax error fallback 2915 __kmp_affinity_type = affinity_compact; 2916 __kmp_affinity_gran = affinity_gran_core; 2917 __kmp_affinity_dups = FALSE; 2918 } 2919 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) { 2920 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true; 2921 } 2922 return; 2923 } 2924 2925 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) { 2926 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true; 2927 } 2928 2929 SKIP_WS(scan); 2930 if (*scan == '\0') { 2931 return; 2932 } 2933 2934 // Parse option count parameter in parentheses 2935 if (*scan != '(') { 2936 KMP_WARNING(SyntaxErrorUsing, name, kind); 2937 return; 2938 } 2939 scan++; // skip '(' 2940 2941 SKIP_WS(scan); 2942 next = scan; 2943 SKIP_DIGITS(next); 2944 count = __kmp_str_to_int(scan, *next); 2945 KMP_ASSERT(count >= 0); 2946 scan = next; 2947 2948 SKIP_WS(scan); 2949 if (*scan != ')') { 2950 KMP_WARNING(SyntaxErrorUsing, name, kind); 2951 return; 2952 } 2953 scan++; // skip ')' 2954 2955 SKIP_WS(scan); 2956 if (*scan != '\0') { 2957 KMP_WARNING(ParseExtraCharsWarn, name, scan); 2958 } 2959 __kmp_affinity_num_places = count; 2960 } 2961 2962 static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name, 2963 void *data) { 2964 if (__kmp_env_format) { 2965 KMP_STR_BUF_PRINT_NAME; 2966 } else { 2967 __kmp_str_buf_print(buffer, " %s", name); 2968 } 2969 if ((__kmp_nested_proc_bind.used == 0) || 2970 (__kmp_nested_proc_bind.bind_types == NULL) || 2971 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) { 2972 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined)); 2973 } else if (__kmp_affinity_type == affinity_explicit) { 2974 if (__kmp_affinity_proclist != NULL) { 2975 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist); 2976 } else { 2977 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined)); 2978 } 2979 } else if (__kmp_affinity_type == affinity_compact) { 2980 int num; 2981 if (__kmp_affinity_num_masks > 0) { 2982 num = __kmp_affinity_num_masks; 2983 } else if (__kmp_affinity_num_places > 0) { 2984 num = __kmp_affinity_num_places; 2985 } else { 2986 num = 0; 2987 } 2988 if (__kmp_affinity_gran == affinity_gran_thread) { 2989 if (num > 0) { 2990 __kmp_str_buf_print(buffer, "='threads(%d)'\n", num); 2991 } else { 2992 __kmp_str_buf_print(buffer, "='threads'\n"); 2993 } 2994 } else if (__kmp_affinity_gran == affinity_gran_core) { 2995 if (num > 0) { 2996 __kmp_str_buf_print(buffer, "='cores(%d)' \n", num); 2997 } else { 2998 __kmp_str_buf_print(buffer, "='cores'\n"); 2999 } 3000 #if KMP_USE_HWLOC 3001 } else if (__kmp_affinity_gran == affinity_gran_tile) { 3002 if (num > 0) { 3003 __kmp_str_buf_print(buffer, "='tiles(%d)' \n", num); 3004 } else { 3005 __kmp_str_buf_print(buffer, "='tiles'\n"); 3006 } 3007 #endif 3008 } else if (__kmp_affinity_gran == affinity_gran_package) { 3009 if (num > 0) { 3010 __kmp_str_buf_print(buffer, "='sockets(%d)'\n", num); 3011 } else { 3012 __kmp_str_buf_print(buffer, "='sockets'\n"); 3013 } 3014 } else { 3015 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined)); 3016 } 3017 } else { 3018 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined)); 3019 } 3020 } 3021 3022 static void __kmp_stg_parse_topology_method(char const *name, char const *value, 3023 void *data) { 3024 if (__kmp_str_match("all", 1, value)) { 3025 __kmp_affinity_top_method = affinity_top_method_all; 3026 } 3027 #if KMP_USE_HWLOC 3028 else if (__kmp_str_match("hwloc", 1, value)) { 3029 __kmp_affinity_top_method = affinity_top_method_hwloc; 3030 } 3031 #endif 3032 #if KMP_ARCH_X86 || KMP_ARCH_X86_64 3033 else if (__kmp_str_match("cpuid_leaf31", 12, value) || 3034 __kmp_str_match("cpuid 1f", 8, value) || 3035 __kmp_str_match("cpuid 31", 8, value) || 3036 __kmp_str_match("cpuid1f", 7, value) || 3037 __kmp_str_match("cpuid31", 7, value) || 3038 __kmp_str_match("leaf 1f", 7, value) || 3039 __kmp_str_match("leaf 31", 7, value) || 3040 __kmp_str_match("leaf1f", 6, value) || 3041 __kmp_str_match("leaf31", 6, value)) { 3042 __kmp_affinity_top_method = affinity_top_method_x2apicid_1f; 3043 } else if (__kmp_str_match("x2apic id", 9, value) || 3044 __kmp_str_match("x2apic_id", 9, value) || 3045 __kmp_str_match("x2apic-id", 9, value) || 3046 __kmp_str_match("x2apicid", 8, value) || 3047 __kmp_str_match("cpuid leaf 11", 13, value) || 3048 __kmp_str_match("cpuid_leaf_11", 13, value) || 3049 __kmp_str_match("cpuid-leaf-11", 13, value) || 3050 __kmp_str_match("cpuid leaf11", 12, value) || 3051 __kmp_str_match("cpuid_leaf11", 12, value) || 3052 __kmp_str_match("cpuid-leaf11", 12, value) || 3053 __kmp_str_match("cpuidleaf 11", 12, value) || 3054 __kmp_str_match("cpuidleaf_11", 12, value) || 3055 __kmp_str_match("cpuidleaf-11", 12, value) || 3056 __kmp_str_match("cpuidleaf11", 11, value) || 3057 __kmp_str_match("cpuid 11", 8, value) || 3058 __kmp_str_match("cpuid_11", 8, value) || 3059 __kmp_str_match("cpuid-11", 8, value) || 3060 __kmp_str_match("cpuid11", 7, value) || 3061 __kmp_str_match("leaf 11", 7, value) || 3062 __kmp_str_match("leaf_11", 7, value) || 3063 __kmp_str_match("leaf-11", 7, value) || 3064 __kmp_str_match("leaf11", 6, value)) { 3065 __kmp_affinity_top_method = affinity_top_method_x2apicid; 3066 } else if (__kmp_str_match("apic id", 7, value) || 3067 __kmp_str_match("apic_id", 7, value) || 3068 __kmp_str_match("apic-id", 7, value) || 3069 __kmp_str_match("apicid", 6, value) || 3070 __kmp_str_match("cpuid leaf 4", 12, value) || 3071 __kmp_str_match("cpuid_leaf_4", 12, value) || 3072 __kmp_str_match("cpuid-leaf-4", 12, value) || 3073 __kmp_str_match("cpuid leaf4", 11, value) || 3074 __kmp_str_match("cpuid_leaf4", 11, value) || 3075 __kmp_str_match("cpuid-leaf4", 11, value) || 3076 __kmp_str_match("cpuidleaf 4", 11, value) || 3077 __kmp_str_match("cpuidleaf_4", 11, value) || 3078 __kmp_str_match("cpuidleaf-4", 11, value) || 3079 __kmp_str_match("cpuidleaf4", 10, value) || 3080 __kmp_str_match("cpuid 4", 7, value) || 3081 __kmp_str_match("cpuid_4", 7, value) || 3082 __kmp_str_match("cpuid-4", 7, value) || 3083 __kmp_str_match("cpuid4", 6, value) || 3084 __kmp_str_match("leaf 4", 6, value) || 3085 __kmp_str_match("leaf_4", 6, value) || 3086 __kmp_str_match("leaf-4", 6, value) || 3087 __kmp_str_match("leaf4", 5, value)) { 3088 __kmp_affinity_top_method = affinity_top_method_apicid; 3089 } 3090 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */ 3091 else if (__kmp_str_match("/proc/cpuinfo", 2, value) || 3092 __kmp_str_match("cpuinfo", 5, value)) { 3093 __kmp_affinity_top_method = affinity_top_method_cpuinfo; 3094 } 3095 #if KMP_GROUP_AFFINITY 3096 else if (__kmp_str_match("group", 1, value)) { 3097 __kmp_affinity_top_method = affinity_top_method_group; 3098 } 3099 #endif /* KMP_GROUP_AFFINITY */ 3100 else if (__kmp_str_match("flat", 1, value)) { 3101 __kmp_affinity_top_method = affinity_top_method_flat; 3102 } else { 3103 KMP_WARNING(StgInvalidValue, name, value); 3104 } 3105 } // __kmp_stg_parse_topology_method 3106 3107 static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer, 3108 char const *name, void *data) { 3109 char const *value = NULL; 3110 3111 switch (__kmp_affinity_top_method) { 3112 case affinity_top_method_default: 3113 value = "default"; 3114 break; 3115 3116 case affinity_top_method_all: 3117 value = "all"; 3118 break; 3119 3120 #if KMP_ARCH_X86 || KMP_ARCH_X86_64 3121 case affinity_top_method_x2apicid: 3122 value = "x2APIC id"; 3123 break; 3124 3125 case affinity_top_method_apicid: 3126 value = "APIC id"; 3127 break; 3128 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */ 3129 3130 #if KMP_USE_HWLOC 3131 case affinity_top_method_hwloc: 3132 value = "hwloc"; 3133 break; 3134 #endif 3135 3136 case affinity_top_method_cpuinfo: 3137 value = "cpuinfo"; 3138 break; 3139 3140 #if KMP_GROUP_AFFINITY 3141 case affinity_top_method_group: 3142 value = "group"; 3143 break; 3144 #endif /* KMP_GROUP_AFFINITY */ 3145 3146 case affinity_top_method_flat: 3147 value = "flat"; 3148 break; 3149 } 3150 3151 if (value != NULL) { 3152 __kmp_stg_print_str(buffer, name, value); 3153 } 3154 } // __kmp_stg_print_topology_method 3155 3156 #endif /* KMP_AFFINITY_SUPPORTED */ 3157 3158 // OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X* 3159 // OMP_PLACES / place-partition-var is not. 3160 static void __kmp_stg_parse_proc_bind(char const *name, char const *value, 3161 void *data) { 3162 kmp_setting_t **rivals = (kmp_setting_t **)data; 3163 int rc; 3164 3165 rc = __kmp_stg_check_rivals(name, value, rivals); 3166 if (rc) { 3167 return; 3168 } 3169 3170 // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types. 3171 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) && 3172 (__kmp_nested_proc_bind.used > 0)); 3173 3174 const char *buf = value; 3175 const char *next; 3176 int num; 3177 SKIP_WS(buf); 3178 if ((*buf >= '0') && (*buf <= '9')) { 3179 next = buf; 3180 SKIP_DIGITS(next); 3181 num = __kmp_str_to_int(buf, *next); 3182 KMP_ASSERT(num >= 0); 3183 buf = next; 3184 SKIP_WS(buf); 3185 } else { 3186 num = -1; 3187 } 3188 3189 next = buf; 3190 if (__kmp_match_str("disabled", buf, &next)) { 3191 buf = next; 3192 SKIP_WS(buf); 3193 #if KMP_AFFINITY_SUPPORTED 3194 __kmp_affinity_type = affinity_disabled; 3195 #endif /* KMP_AFFINITY_SUPPORTED */ 3196 __kmp_nested_proc_bind.used = 1; 3197 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false; 3198 } else if ((num == (int)proc_bind_false) || 3199 __kmp_match_str("false", buf, &next)) { 3200 buf = next; 3201 SKIP_WS(buf); 3202 #if KMP_AFFINITY_SUPPORTED 3203 __kmp_affinity_type = affinity_none; 3204 #endif /* KMP_AFFINITY_SUPPORTED */ 3205 __kmp_nested_proc_bind.used = 1; 3206 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false; 3207 } else if ((num == (int)proc_bind_true) || 3208 __kmp_match_str("true", buf, &next)) { 3209 buf = next; 3210 SKIP_WS(buf); 3211 __kmp_nested_proc_bind.used = 1; 3212 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true; 3213 } else { 3214 // Count the number of values in the env var string 3215 const char *scan; 3216 int nelem = 1; 3217 for (scan = buf; *scan != '\0'; scan++) { 3218 if (*scan == ',') { 3219 nelem++; 3220 } 3221 } 3222 3223 // Create / expand the nested proc_bind array as needed 3224 if (__kmp_nested_proc_bind.size < nelem) { 3225 __kmp_nested_proc_bind.bind_types = 3226 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC( 3227 __kmp_nested_proc_bind.bind_types, 3228 sizeof(kmp_proc_bind_t) * nelem); 3229 if (__kmp_nested_proc_bind.bind_types == NULL) { 3230 KMP_FATAL(MemoryAllocFailed); 3231 } 3232 __kmp_nested_proc_bind.size = nelem; 3233 } 3234 __kmp_nested_proc_bind.used = nelem; 3235 3236 if (nelem > 1 && !__kmp_dflt_max_active_levels_set) 3237 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT; 3238 3239 // Save values in the nested proc_bind array 3240 int i = 0; 3241 for (;;) { 3242 enum kmp_proc_bind_t bind; 3243 3244 if ((num == (int)proc_bind_primary) || 3245 __kmp_match_str("master", buf, &next) || 3246 __kmp_match_str("primary", buf, &next)) { 3247 buf = next; 3248 SKIP_WS(buf); 3249 bind = proc_bind_primary; 3250 } else if ((num == (int)proc_bind_close) || 3251 __kmp_match_str("close", buf, &next)) { 3252 buf = next; 3253 SKIP_WS(buf); 3254 bind = proc_bind_close; 3255 } else if ((num == (int)proc_bind_spread) || 3256 __kmp_match_str("spread", buf, &next)) { 3257 buf = next; 3258 SKIP_WS(buf); 3259 bind = proc_bind_spread; 3260 } else { 3261 KMP_WARNING(StgInvalidValue, name, value); 3262 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false; 3263 __kmp_nested_proc_bind.used = 1; 3264 return; 3265 } 3266 3267 __kmp_nested_proc_bind.bind_types[i++] = bind; 3268 if (i >= nelem) { 3269 break; 3270 } 3271 KMP_DEBUG_ASSERT(*buf == ','); 3272 buf++; 3273 SKIP_WS(buf); 3274 3275 // Read next value if it was specified as an integer 3276 if ((*buf >= '0') && (*buf <= '9')) { 3277 next = buf; 3278 SKIP_DIGITS(next); 3279 num = __kmp_str_to_int(buf, *next); 3280 KMP_ASSERT(num >= 0); 3281 buf = next; 3282 SKIP_WS(buf); 3283 } else { 3284 num = -1; 3285 } 3286 } 3287 SKIP_WS(buf); 3288 } 3289 if (*buf != '\0') { 3290 KMP_WARNING(ParseExtraCharsWarn, name, buf); 3291 } 3292 } 3293 3294 static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name, 3295 void *data) { 3296 int nelem = __kmp_nested_proc_bind.used; 3297 if (__kmp_env_format) { 3298 KMP_STR_BUF_PRINT_NAME; 3299 } else { 3300 __kmp_str_buf_print(buffer, " %s", name); 3301 } 3302 if (nelem == 0) { 3303 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined)); 3304 } else { 3305 int i; 3306 __kmp_str_buf_print(buffer, "='", name); 3307 for (i = 0; i < nelem; i++) { 3308 switch (__kmp_nested_proc_bind.bind_types[i]) { 3309 case proc_bind_false: 3310 __kmp_str_buf_print(buffer, "false"); 3311 break; 3312 3313 case proc_bind_true: 3314 __kmp_str_buf_print(buffer, "true"); 3315 break; 3316 3317 case proc_bind_primary: 3318 __kmp_str_buf_print(buffer, "primary"); 3319 break; 3320 3321 case proc_bind_close: 3322 __kmp_str_buf_print(buffer, "close"); 3323 break; 3324 3325 case proc_bind_spread: 3326 __kmp_str_buf_print(buffer, "spread"); 3327 break; 3328 3329 case proc_bind_intel: 3330 __kmp_str_buf_print(buffer, "intel"); 3331 break; 3332 3333 case proc_bind_default: 3334 __kmp_str_buf_print(buffer, "default"); 3335 break; 3336 } 3337 if (i < nelem - 1) { 3338 __kmp_str_buf_print(buffer, ","); 3339 } 3340 } 3341 __kmp_str_buf_print(buffer, "'\n"); 3342 } 3343 } 3344 3345 static void __kmp_stg_parse_display_affinity(char const *name, 3346 char const *value, void *data) { 3347 __kmp_stg_parse_bool(name, value, &__kmp_display_affinity); 3348 } 3349 static void __kmp_stg_print_display_affinity(kmp_str_buf_t *buffer, 3350 char const *name, void *data) { 3351 __kmp_stg_print_bool(buffer, name, __kmp_display_affinity); 3352 } 3353 static void __kmp_stg_parse_affinity_format(char const *name, char const *value, 3354 void *data) { 3355 size_t length = KMP_STRLEN(value); 3356 __kmp_strncpy_truncate(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, value, 3357 length); 3358 } 3359 static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer, 3360 char const *name, void *data) { 3361 if (__kmp_env_format) { 3362 KMP_STR_BUF_PRINT_NAME_EX(name); 3363 } else { 3364 __kmp_str_buf_print(buffer, " %s='", name); 3365 } 3366 __kmp_str_buf_print(buffer, "%s'\n", __kmp_affinity_format); 3367 } 3368 3369 /*----------------------------------------------------------------------------- 3370 OMP_ALLOCATOR sets default allocator. Here is the grammar: 3371 3372 <allocator> |= <predef-allocator> | <predef-mem-space> | 3373 <predef-mem-space>:<traits> 3374 <traits> |= <trait>=<value> | <trait>=<value>,<traits> 3375 <predef-allocator> |= omp_default_mem_alloc | omp_large_cap_mem_alloc | 3376 omp_const_mem_alloc | omp_high_bw_mem_alloc | 3377 omp_low_lat_mem_alloc | omp_cgroup_mem_alloc | 3378 omp_pteam_mem_alloc | omp_thread_mem_alloc 3379 <predef-mem-space> |= omp_default_mem_space | omp_large_cap_mem_space | 3380 omp_const_mem_space | omp_high_bw_mem_space | 3381 omp_low_lat_mem_space 3382 <trait> |= sync_hint | alignment | access | pool_size | fallback | 3383 fb_data | pinned | partition 3384 <value> |= one of the allowed values of trait | 3385 non-negative integer | <predef-allocator> 3386 -----------------------------------------------------------------------------*/ 3387 3388 static void __kmp_stg_parse_allocator(char const *name, char const *value, 3389 void *data) { 3390 const char *buf = value; 3391 const char *next, *scan, *start; 3392 char *key; 3393 omp_allocator_handle_t al; 3394 omp_memspace_handle_t ms = omp_default_mem_space; 3395 bool is_memspace = false; 3396 int ntraits = 0, count = 0; 3397 3398 SKIP_WS(buf); 3399 next = buf; 3400 const char *delim = strchr(buf, ':'); 3401 const char *predef_mem_space = strstr(buf, "mem_space"); 3402 3403 bool is_memalloc = (!predef_mem_space && !delim) ? true : false; 3404 3405 // Count the number of traits in the env var string 3406 if (delim) { 3407 ntraits = 1; 3408 for (scan = buf; *scan != '\0'; scan++) { 3409 if (*scan == ',') 3410 ntraits++; 3411 } 3412 } 3413 omp_alloctrait_t *traits = 3414 (omp_alloctrait_t *)KMP_ALLOCA(ntraits * sizeof(omp_alloctrait_t)); 3415 3416 // Helper macros 3417 #define IS_POWER_OF_TWO(n) (((n) & ((n)-1)) == 0) 3418 3419 #define GET_NEXT(sentinel) \ 3420 { \ 3421 SKIP_WS(next); \ 3422 if (*next == sentinel) \ 3423 next++; \ 3424 SKIP_WS(next); \ 3425 scan = next; \ 3426 } 3427 3428 #define SKIP_PAIR(key) \ 3429 { \ 3430 char const str_delimiter[] = {',', 0}; \ 3431 char *value = __kmp_str_token(CCAST(char *, scan), str_delimiter, \ 3432 CCAST(char **, &next)); \ 3433 KMP_WARNING(StgInvalidValue, key, value); \ 3434 ntraits--; \ 3435 SKIP_WS(next); \ 3436 scan = next; \ 3437 } 3438 3439 #define SET_KEY() \ 3440 { \ 3441 char const str_delimiter[] = {'=', 0}; \ 3442 key = __kmp_str_token(CCAST(char *, start), str_delimiter, \ 3443 CCAST(char **, &next)); \ 3444 scan = next; \ 3445 } 3446 3447 scan = next; 3448 while (*next != '\0') { 3449 if (is_memalloc || 3450 __kmp_match_str("fb_data", scan, &next)) { // allocator check 3451 start = scan; 3452 GET_NEXT('='); 3453 // check HBW and LCAP first as the only non-default supported 3454 if (__kmp_match_str("omp_high_bw_mem_alloc", scan, &next)) { 3455 SKIP_WS(next); 3456 if (is_memalloc) { 3457 if (__kmp_memkind_available) { 3458 __kmp_def_allocator = omp_high_bw_mem_alloc; 3459 return; 3460 } else { 3461 KMP_WARNING(OmpNoAllocator, "omp_high_bw_mem_alloc"); 3462 } 3463 } else { 3464 traits[count].key = omp_atk_fb_data; 3465 traits[count].value = RCAST(omp_uintptr_t, omp_high_bw_mem_alloc); 3466 } 3467 } else if (__kmp_match_str("omp_large_cap_mem_alloc", scan, &next)) { 3468 SKIP_WS(next); 3469 if (is_memalloc) { 3470 if (__kmp_memkind_available) { 3471 __kmp_def_allocator = omp_large_cap_mem_alloc; 3472 return; 3473 } else { 3474 KMP_WARNING(OmpNoAllocator, "omp_large_cap_mem_alloc"); 3475 } 3476 } else { 3477 traits[count].key = omp_atk_fb_data; 3478 traits[count].value = RCAST(omp_uintptr_t, omp_large_cap_mem_alloc); 3479 } 3480 } else if (__kmp_match_str("omp_default_mem_alloc", scan, &next)) { 3481 // default requested 3482 SKIP_WS(next); 3483 if (!is_memalloc) { 3484 traits[count].key = omp_atk_fb_data; 3485 traits[count].value = RCAST(omp_uintptr_t, omp_default_mem_alloc); 3486 } 3487 } else if (__kmp_match_str("omp_const_mem_alloc", scan, &next)) { 3488 SKIP_WS(next); 3489 if (is_memalloc) { 3490 KMP_WARNING(OmpNoAllocator, "omp_const_mem_alloc"); 3491 } else { 3492 traits[count].key = omp_atk_fb_data; 3493 traits[count].value = RCAST(omp_uintptr_t, omp_const_mem_alloc); 3494 } 3495 } else if (__kmp_match_str("omp_low_lat_mem_alloc", scan, &next)) { 3496 SKIP_WS(next); 3497 if (is_memalloc) { 3498 KMP_WARNING(OmpNoAllocator, "omp_low_lat_mem_alloc"); 3499 } else { 3500 traits[count].key = omp_atk_fb_data; 3501 traits[count].value = RCAST(omp_uintptr_t, omp_low_lat_mem_alloc); 3502 } 3503 } else if (__kmp_match_str("omp_cgroup_mem_alloc", scan, &next)) { 3504 SKIP_WS(next); 3505 if (is_memalloc) { 3506 KMP_WARNING(OmpNoAllocator, "omp_cgroup_mem_alloc"); 3507 } else { 3508 traits[count].key = omp_atk_fb_data; 3509 traits[count].value = RCAST(omp_uintptr_t, omp_cgroup_mem_alloc); 3510 } 3511 } else if (__kmp_match_str("omp_pteam_mem_alloc", scan, &next)) { 3512 SKIP_WS(next); 3513 if (is_memalloc) { 3514 KMP_WARNING(OmpNoAllocator, "omp_pteam_mem_alloc"); 3515 } else { 3516 traits[count].key = omp_atk_fb_data; 3517 traits[count].value = RCAST(omp_uintptr_t, omp_pteam_mem_alloc); 3518 } 3519 } else if (__kmp_match_str("omp_thread_mem_alloc", scan, &next)) { 3520 SKIP_WS(next); 3521 if (is_memalloc) { 3522 KMP_WARNING(OmpNoAllocator, "omp_thread_mem_alloc"); 3523 } else { 3524 traits[count].key = omp_atk_fb_data; 3525 traits[count].value = RCAST(omp_uintptr_t, omp_thread_mem_alloc); 3526 } 3527 } else { 3528 if (!is_memalloc) { 3529 SET_KEY(); 3530 SKIP_PAIR(key); 3531 continue; 3532 } 3533 } 3534 if (is_memalloc) { 3535 __kmp_def_allocator = omp_default_mem_alloc; 3536 if (next == buf || *next != '\0') { 3537 // either no match or extra symbols present after the matched token 3538 KMP_WARNING(StgInvalidValue, name, value); 3539 } 3540 return; 3541 } else { 3542 ++count; 3543 if (count == ntraits) 3544 break; 3545 GET_NEXT(','); 3546 } 3547 } else { // memspace 3548 if (!is_memspace) { 3549 if (__kmp_match_str("omp_default_mem_space", scan, &next)) { 3550 SKIP_WS(next); 3551 ms = omp_default_mem_space; 3552 } else if (__kmp_match_str("omp_large_cap_mem_space", scan, &next)) { 3553 SKIP_WS(next); 3554 ms = omp_large_cap_mem_space; 3555 } else if (__kmp_match_str("omp_const_mem_space", scan, &next)) { 3556 SKIP_WS(next); 3557 ms = omp_const_mem_space; 3558 } else if (__kmp_match_str("omp_high_bw_mem_space", scan, &next)) { 3559 SKIP_WS(next); 3560 ms = omp_high_bw_mem_space; 3561 } else if (__kmp_match_str("omp_low_lat_mem_space", scan, &next)) { 3562 SKIP_WS(next); 3563 ms = omp_low_lat_mem_space; 3564 } else { 3565 __kmp_def_allocator = omp_default_mem_alloc; 3566 if (next == buf || *next != '\0') { 3567 // either no match or extra symbols present after the matched token 3568 KMP_WARNING(StgInvalidValue, name, value); 3569 } 3570 return; 3571 } 3572 is_memspace = true; 3573 } 3574 if (delim) { // traits 3575 GET_NEXT(':'); 3576 start = scan; 3577 if (__kmp_match_str("sync_hint", scan, &next)) { 3578 GET_NEXT('='); 3579 traits[count].key = omp_atk_sync_hint; 3580 if (__kmp_match_str("contended", scan, &next)) { 3581 traits[count].value = omp_atv_contended; 3582 } else if (__kmp_match_str("uncontended", scan, &next)) { 3583 traits[count].value = omp_atv_uncontended; 3584 } else if (__kmp_match_str("serialized", scan, &next)) { 3585 traits[count].value = omp_atv_serialized; 3586 } else if (__kmp_match_str("private", scan, &next)) { 3587 traits[count].value = omp_atv_private; 3588 } else { 3589 SET_KEY(); 3590 SKIP_PAIR(key); 3591 continue; 3592 } 3593 } else if (__kmp_match_str("alignment", scan, &next)) { 3594 GET_NEXT('='); 3595 if (!isdigit(*next)) { 3596 SET_KEY(); 3597 SKIP_PAIR(key); 3598 continue; 3599 } 3600 SKIP_DIGITS(next); 3601 int n = __kmp_str_to_int(scan, ','); 3602 if (n < 0 || !IS_POWER_OF_TWO(n)) { 3603 SET_KEY(); 3604 SKIP_PAIR(key); 3605 continue; 3606 } 3607 traits[count].key = omp_atk_alignment; 3608 traits[count].value = n; 3609 } else if (__kmp_match_str("access", scan, &next)) { 3610 GET_NEXT('='); 3611 traits[count].key = omp_atk_access; 3612 if (__kmp_match_str("all", scan, &next)) { 3613 traits[count].value = omp_atv_all; 3614 } else if (__kmp_match_str("cgroup", scan, &next)) { 3615 traits[count].value = omp_atv_cgroup; 3616 } else if (__kmp_match_str("pteam", scan, &next)) { 3617 traits[count].value = omp_atv_pteam; 3618 } else if (__kmp_match_str("thread", scan, &next)) { 3619 traits[count].value = omp_atv_thread; 3620 } else { 3621 SET_KEY(); 3622 SKIP_PAIR(key); 3623 continue; 3624 } 3625 } else if (__kmp_match_str("pool_size", scan, &next)) { 3626 GET_NEXT('='); 3627 if (!isdigit(*next)) { 3628 SET_KEY(); 3629 SKIP_PAIR(key); 3630 continue; 3631 } 3632 SKIP_DIGITS(next); 3633 int n = __kmp_str_to_int(scan, ','); 3634 if (n < 0) { 3635 SET_KEY(); 3636 SKIP_PAIR(key); 3637 continue; 3638 } 3639 traits[count].key = omp_atk_pool_size; 3640 traits[count].value = n; 3641 } else if (__kmp_match_str("fallback", scan, &next)) { 3642 GET_NEXT('='); 3643 traits[count].key = omp_atk_fallback; 3644 if (__kmp_match_str("default_mem_fb", scan, &next)) { 3645 traits[count].value = omp_atv_default_mem_fb; 3646 } else if (__kmp_match_str("null_fb", scan, &next)) { 3647 traits[count].value = omp_atv_null_fb; 3648 } else if (__kmp_match_str("abort_fb", scan, &next)) { 3649 traits[count].value = omp_atv_abort_fb; 3650 } else if (__kmp_match_str("allocator_fb", scan, &next)) { 3651 traits[count].value = omp_atv_allocator_fb; 3652 } else { 3653 SET_KEY(); 3654 SKIP_PAIR(key); 3655 continue; 3656 } 3657 } else if (__kmp_match_str("pinned", scan, &next)) { 3658 GET_NEXT('='); 3659 traits[count].key = omp_atk_pinned; 3660 if (__kmp_str_match_true(next)) { 3661 traits[count].value = omp_atv_true; 3662 } else if (__kmp_str_match_false(next)) { 3663 traits[count].value = omp_atv_false; 3664 } else { 3665 SET_KEY(); 3666 SKIP_PAIR(key); 3667 continue; 3668 } 3669 } else if (__kmp_match_str("partition", scan, &next)) { 3670 GET_NEXT('='); 3671 traits[count].key = omp_atk_partition; 3672 if (__kmp_match_str("environment", scan, &next)) { 3673 traits[count].value = omp_atv_environment; 3674 } else if (__kmp_match_str("nearest", scan, &next)) { 3675 traits[count].value = omp_atv_nearest; 3676 } else if (__kmp_match_str("blocked", scan, &next)) { 3677 traits[count].value = omp_atv_blocked; 3678 } else if (__kmp_match_str("interleaved", scan, &next)) { 3679 traits[count].value = omp_atv_interleaved; 3680 } else { 3681 SET_KEY(); 3682 SKIP_PAIR(key); 3683 continue; 3684 } 3685 } else { 3686 SET_KEY(); 3687 SKIP_PAIR(key); 3688 continue; 3689 } 3690 SKIP_WS(next); 3691 ++count; 3692 if (count == ntraits) 3693 break; 3694 GET_NEXT(','); 3695 } // traits 3696 } // memspace 3697 } // while 3698 al = __kmpc_init_allocator(__kmp_get_gtid(), ms, ntraits, traits); 3699 __kmp_def_allocator = (al == omp_null_allocator) ? omp_default_mem_alloc : al; 3700 } 3701 3702 static void __kmp_stg_print_allocator(kmp_str_buf_t *buffer, char const *name, 3703 void *data) { 3704 if (__kmp_def_allocator == omp_default_mem_alloc) { 3705 __kmp_stg_print_str(buffer, name, "omp_default_mem_alloc"); 3706 } else if (__kmp_def_allocator == omp_high_bw_mem_alloc) { 3707 __kmp_stg_print_str(buffer, name, "omp_high_bw_mem_alloc"); 3708 } else if (__kmp_def_allocator == omp_large_cap_mem_alloc) { 3709 __kmp_stg_print_str(buffer, name, "omp_large_cap_mem_alloc"); 3710 } else if (__kmp_def_allocator == omp_const_mem_alloc) { 3711 __kmp_stg_print_str(buffer, name, "omp_const_mem_alloc"); 3712 } else if (__kmp_def_allocator == omp_low_lat_mem_alloc) { 3713 __kmp_stg_print_str(buffer, name, "omp_low_lat_mem_alloc"); 3714 } else if (__kmp_def_allocator == omp_cgroup_mem_alloc) { 3715 __kmp_stg_print_str(buffer, name, "omp_cgroup_mem_alloc"); 3716 } else if (__kmp_def_allocator == omp_pteam_mem_alloc) { 3717 __kmp_stg_print_str(buffer, name, "omp_pteam_mem_alloc"); 3718 } else if (__kmp_def_allocator == omp_thread_mem_alloc) { 3719 __kmp_stg_print_str(buffer, name, "omp_thread_mem_alloc"); 3720 } 3721 } 3722 3723 // ----------------------------------------------------------------------------- 3724 // OMP_DYNAMIC 3725 3726 static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value, 3727 void *data) { 3728 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic)); 3729 } // __kmp_stg_parse_omp_dynamic 3730 3731 static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name, 3732 void *data) { 3733 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic); 3734 } // __kmp_stg_print_omp_dynamic 3735 3736 static void __kmp_stg_parse_kmp_dynamic_mode(char const *name, 3737 char const *value, void *data) { 3738 if (TCR_4(__kmp_init_parallel)) { 3739 KMP_WARNING(EnvParallelWarn, name); 3740 __kmp_env_toPrint(name, 0); 3741 return; 3742 } 3743 #ifdef USE_LOAD_BALANCE 3744 else if (__kmp_str_match("load balance", 2, value) || 3745 __kmp_str_match("load_balance", 2, value) || 3746 __kmp_str_match("load-balance", 2, value) || 3747 __kmp_str_match("loadbalance", 2, value) || 3748 __kmp_str_match("balance", 1, value)) { 3749 __kmp_global.g.g_dynamic_mode = dynamic_load_balance; 3750 } 3751 #endif /* USE_LOAD_BALANCE */ 3752 else if (__kmp_str_match("thread limit", 1, value) || 3753 __kmp_str_match("thread_limit", 1, value) || 3754 __kmp_str_match("thread-limit", 1, value) || 3755 __kmp_str_match("threadlimit", 1, value) || 3756 __kmp_str_match("limit", 2, value)) { 3757 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit; 3758 } else if (__kmp_str_match("random", 1, value)) { 3759 __kmp_global.g.g_dynamic_mode = dynamic_random; 3760 } else { 3761 KMP_WARNING(StgInvalidValue, name, value); 3762 } 3763 } //__kmp_stg_parse_kmp_dynamic_mode 3764 3765 static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer, 3766 char const *name, void *data) { 3767 #if KMP_DEBUG 3768 if (__kmp_global.g.g_dynamic_mode == dynamic_default) { 3769 __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined)); 3770 } 3771 #ifdef USE_LOAD_BALANCE 3772 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) { 3773 __kmp_stg_print_str(buffer, name, "load balance"); 3774 } 3775 #endif /* USE_LOAD_BALANCE */ 3776 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) { 3777 __kmp_stg_print_str(buffer, name, "thread limit"); 3778 } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) { 3779 __kmp_stg_print_str(buffer, name, "random"); 3780 } else { 3781 KMP_ASSERT(0); 3782 } 3783 #endif /* KMP_DEBUG */ 3784 } // __kmp_stg_print_kmp_dynamic_mode 3785 3786 #ifdef USE_LOAD_BALANCE 3787 3788 // ----------------------------------------------------------------------------- 3789 // KMP_LOAD_BALANCE_INTERVAL 3790 3791 static void __kmp_stg_parse_ld_balance_interval(char const *name, 3792 char const *value, void *data) { 3793 double interval = __kmp_convert_to_double(value); 3794 if (interval >= 0) { 3795 __kmp_load_balance_interval = interval; 3796 } else { 3797 KMP_WARNING(StgInvalidValue, name, value); 3798 } 3799 } // __kmp_stg_parse_load_balance_interval 3800 3801 static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer, 3802 char const *name, void *data) { 3803 #if KMP_DEBUG 3804 __kmp_str_buf_print(buffer, " %s=%8.6f\n", name, 3805 __kmp_load_balance_interval); 3806 #endif /* KMP_DEBUG */ 3807 } // __kmp_stg_print_load_balance_interval 3808 3809 #endif /* USE_LOAD_BALANCE */ 3810 3811 // ----------------------------------------------------------------------------- 3812 // KMP_INIT_AT_FORK 3813 3814 static void __kmp_stg_parse_init_at_fork(char const *name, char const *value, 3815 void *data) { 3816 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork); 3817 if (__kmp_need_register_atfork) { 3818 __kmp_need_register_atfork_specified = TRUE; 3819 } 3820 } // __kmp_stg_parse_init_at_fork 3821 3822 static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer, 3823 char const *name, void *data) { 3824 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified); 3825 } // __kmp_stg_print_init_at_fork 3826 3827 // ----------------------------------------------------------------------------- 3828 // KMP_SCHEDULE 3829 3830 static void __kmp_stg_parse_schedule(char const *name, char const *value, 3831 void *data) { 3832 3833 if (value != NULL) { 3834 size_t length = KMP_STRLEN(value); 3835 if (length > INT_MAX) { 3836 KMP_WARNING(LongValue, name); 3837 } else { 3838 const char *semicolon; 3839 if (value[length - 1] == '"' || value[length - 1] == '\'') 3840 KMP_WARNING(UnbalancedQuotes, name); 3841 do { 3842 char sentinel; 3843 3844 semicolon = strchr(value, ';'); 3845 if (*value && semicolon != value) { 3846 const char *comma = strchr(value, ','); 3847 3848 if (comma) { 3849 ++comma; 3850 sentinel = ','; 3851 } else 3852 sentinel = ';'; 3853 if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) { 3854 if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) { 3855 __kmp_static = kmp_sch_static_greedy; 3856 continue; 3857 } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma, 3858 ';')) { 3859 __kmp_static = kmp_sch_static_balanced; 3860 continue; 3861 } 3862 } else if (!__kmp_strcasecmp_with_sentinel("guided", value, 3863 sentinel)) { 3864 if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) { 3865 __kmp_guided = kmp_sch_guided_iterative_chunked; 3866 continue; 3867 } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma, 3868 ';')) { 3869 /* analytical not allowed for too many threads */ 3870 __kmp_guided = kmp_sch_guided_analytical_chunked; 3871 continue; 3872 } 3873 } 3874 KMP_WARNING(InvalidClause, name, value); 3875 } else 3876 KMP_WARNING(EmptyClause, name); 3877 } while ((value = semicolon ? semicolon + 1 : NULL)); 3878 } 3879 } 3880 3881 } // __kmp_stg_parse__schedule 3882 3883 static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name, 3884 void *data) { 3885 if (__kmp_env_format) { 3886 KMP_STR_BUF_PRINT_NAME_EX(name); 3887 } else { 3888 __kmp_str_buf_print(buffer, " %s='", name); 3889 } 3890 if (__kmp_static == kmp_sch_static_greedy) { 3891 __kmp_str_buf_print(buffer, "%s", "static,greedy"); 3892 } else if (__kmp_static == kmp_sch_static_balanced) { 3893 __kmp_str_buf_print(buffer, "%s", "static,balanced"); 3894 } 3895 if (__kmp_guided == kmp_sch_guided_iterative_chunked) { 3896 __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative"); 3897 } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) { 3898 __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical"); 3899 } 3900 } // __kmp_stg_print_schedule 3901 3902 // ----------------------------------------------------------------------------- 3903 // OMP_SCHEDULE 3904 3905 static inline void __kmp_omp_schedule_restore() { 3906 #if KMP_USE_HIER_SCHED 3907 __kmp_hier_scheds.deallocate(); 3908 #endif 3909 __kmp_chunk = 0; 3910 __kmp_sched = kmp_sch_default; 3911 } 3912 3913 // if parse_hier = true: 3914 // Parse [HW,][modifier:]kind[,chunk] 3915 // else: 3916 // Parse [modifier:]kind[,chunk] 3917 static const char *__kmp_parse_single_omp_schedule(const char *name, 3918 const char *value, 3919 bool parse_hier = false) { 3920 /* get the specified scheduling style */ 3921 const char *ptr = value; 3922 const char *delim; 3923 int chunk = 0; 3924 enum sched_type sched = kmp_sch_default; 3925 if (*ptr == '\0') 3926 return NULL; 3927 delim = ptr; 3928 while (*delim != ',' && *delim != ':' && *delim != '\0') 3929 delim++; 3930 #if KMP_USE_HIER_SCHED 3931 kmp_hier_layer_e layer = kmp_hier_layer_e::LAYER_THREAD; 3932 if (parse_hier) { 3933 if (*delim == ',') { 3934 if (!__kmp_strcasecmp_with_sentinel("L1", ptr, ',')) { 3935 layer = kmp_hier_layer_e::LAYER_L1; 3936 } else if (!__kmp_strcasecmp_with_sentinel("L2", ptr, ',')) { 3937 layer = kmp_hier_layer_e::LAYER_L2; 3938 } else if (!__kmp_strcasecmp_with_sentinel("L3", ptr, ',')) { 3939 layer = kmp_hier_layer_e::LAYER_L3; 3940 } else if (!__kmp_strcasecmp_with_sentinel("NUMA", ptr, ',')) { 3941 layer = kmp_hier_layer_e::LAYER_NUMA; 3942 } 3943 } 3944 if (layer != kmp_hier_layer_e::LAYER_THREAD && *delim != ',') { 3945 // If there is no comma after the layer, then this schedule is invalid 3946 KMP_WARNING(StgInvalidValue, name, value); 3947 __kmp_omp_schedule_restore(); 3948 return NULL; 3949 } else if (layer != kmp_hier_layer_e::LAYER_THREAD) { 3950 ptr = ++delim; 3951 while (*delim != ',' && *delim != ':' && *delim != '\0') 3952 delim++; 3953 } 3954 } 3955 #endif // KMP_USE_HIER_SCHED 3956 // Read in schedule modifier if specified 3957 enum sched_type sched_modifier = (enum sched_type)0; 3958 if (*delim == ':') { 3959 if (!__kmp_strcasecmp_with_sentinel("monotonic", ptr, *delim)) { 3960 sched_modifier = sched_type::kmp_sch_modifier_monotonic; 3961 ptr = ++delim; 3962 while (*delim != ',' && *delim != ':' && *delim != '\0') 3963 delim++; 3964 } else if (!__kmp_strcasecmp_with_sentinel("nonmonotonic", ptr, *delim)) { 3965 sched_modifier = sched_type::kmp_sch_modifier_nonmonotonic; 3966 ptr = ++delim; 3967 while (*delim != ',' && *delim != ':' && *delim != '\0') 3968 delim++; 3969 } else if (!parse_hier) { 3970 // If there is no proper schedule modifier, then this schedule is invalid 3971 KMP_WARNING(StgInvalidValue, name, value); 3972 __kmp_omp_schedule_restore(); 3973 return NULL; 3974 } 3975 } 3976 // Read in schedule kind (required) 3977 if (!__kmp_strcasecmp_with_sentinel("dynamic", ptr, *delim)) 3978 sched = kmp_sch_dynamic_chunked; 3979 else if (!__kmp_strcasecmp_with_sentinel("guided", ptr, *delim)) 3980 sched = kmp_sch_guided_chunked; 3981 // AC: TODO: probably remove TRAPEZOIDAL (OMP 3.0 does not allow it) 3982 else if (!__kmp_strcasecmp_with_sentinel("auto", ptr, *delim)) 3983 sched = kmp_sch_auto; 3984 else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", ptr, *delim)) 3985 sched = kmp_sch_trapezoidal; 3986 else if (!__kmp_strcasecmp_with_sentinel("static", ptr, *delim)) 3987 sched = kmp_sch_static; 3988 #if KMP_STATIC_STEAL_ENABLED 3989 else if (!__kmp_strcasecmp_with_sentinel("static_steal", ptr, *delim)) 3990 sched = kmp_sch_static_steal; 3991 #endif 3992 else { 3993 // If there is no proper schedule kind, then this schedule is invalid 3994 KMP_WARNING(StgInvalidValue, name, value); 3995 __kmp_omp_schedule_restore(); 3996 return NULL; 3997 } 3998 3999 // Read in schedule chunk size if specified 4000 if (*delim == ',') { 4001 ptr = delim + 1; 4002 SKIP_WS(ptr); 4003 if (!isdigit(*ptr)) { 4004 // If there is no chunk after comma, then this schedule is invalid 4005 KMP_WARNING(StgInvalidValue, name, value); 4006 __kmp_omp_schedule_restore(); 4007 return NULL; 4008 } 4009 SKIP_DIGITS(ptr); 4010 // auto schedule should not specify chunk size 4011 if (sched == kmp_sch_auto) { 4012 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, delim), 4013 __kmp_msg_null); 4014 } else { 4015 if (sched == kmp_sch_static) 4016 sched = kmp_sch_static_chunked; 4017 chunk = __kmp_str_to_int(delim + 1, *ptr); 4018 if (chunk < 1) { 4019 chunk = KMP_DEFAULT_CHUNK; 4020 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, delim), 4021 __kmp_msg_null); 4022 KMP_INFORM(Using_int_Value, name, __kmp_chunk); 4023 // AC: next block commented out until KMP_DEFAULT_CHUNK != KMP_MIN_CHUNK 4024 // (to improve code coverage :) 4025 // The default chunk size is 1 according to standard, thus making 4026 // KMP_MIN_CHUNK not 1 we would introduce mess: 4027 // wrong chunk becomes 1, but it will be impossible to explicitly set 4028 // to 1 because it becomes KMP_MIN_CHUNK... 4029 // } else if ( chunk < KMP_MIN_CHUNK ) { 4030 // chunk = KMP_MIN_CHUNK; 4031 } else if (chunk > KMP_MAX_CHUNK) { 4032 chunk = KMP_MAX_CHUNK; 4033 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, delim), 4034 __kmp_msg_null); 4035 KMP_INFORM(Using_int_Value, name, chunk); 4036 } 4037 } 4038 } else { 4039 ptr = delim; 4040 } 4041 4042 SCHEDULE_SET_MODIFIERS(sched, sched_modifier); 4043 4044 #if KMP_USE_HIER_SCHED 4045 if (layer != kmp_hier_layer_e::LAYER_THREAD) { 4046 __kmp_hier_scheds.append(sched, chunk, layer); 4047 } else 4048 #endif 4049 { 4050 __kmp_chunk = chunk; 4051 __kmp_sched = sched; 4052 } 4053 return ptr; 4054 } 4055 4056 static void __kmp_stg_parse_omp_schedule(char const *name, char const *value, 4057 void *data) { 4058 size_t length; 4059 const char *ptr = value; 4060 SKIP_WS(ptr); 4061 if (value) { 4062 length = KMP_STRLEN(value); 4063 if (length) { 4064 if (value[length - 1] == '"' || value[length - 1] == '\'') 4065 KMP_WARNING(UnbalancedQuotes, name); 4066 /* get the specified scheduling style */ 4067 #if KMP_USE_HIER_SCHED 4068 if (!__kmp_strcasecmp_with_sentinel("EXPERIMENTAL", ptr, ' ')) { 4069 SKIP_TOKEN(ptr); 4070 SKIP_WS(ptr); 4071 while ((ptr = __kmp_parse_single_omp_schedule(name, ptr, true))) { 4072 while (*ptr == ' ' || *ptr == '\t' || *ptr == ':') 4073 ptr++; 4074 if (*ptr == '\0') 4075 break; 4076 } 4077 } else 4078 #endif 4079 __kmp_parse_single_omp_schedule(name, ptr); 4080 } else 4081 KMP_WARNING(EmptyString, name); 4082 } 4083 #if KMP_USE_HIER_SCHED 4084 __kmp_hier_scheds.sort(); 4085 #endif 4086 K_DIAG(1, ("__kmp_static == %d\n", __kmp_static)) 4087 K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided)) 4088 K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched)) 4089 K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk)) 4090 } // __kmp_stg_parse_omp_schedule 4091 4092 static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer, 4093 char const *name, void *data) { 4094 if (__kmp_env_format) { 4095 KMP_STR_BUF_PRINT_NAME_EX(name); 4096 } else { 4097 __kmp_str_buf_print(buffer, " %s='", name); 4098 } 4099 enum sched_type sched = SCHEDULE_WITHOUT_MODIFIERS(__kmp_sched); 4100 if (SCHEDULE_HAS_MONOTONIC(__kmp_sched)) { 4101 __kmp_str_buf_print(buffer, "monotonic:"); 4102 } else if (SCHEDULE_HAS_NONMONOTONIC(__kmp_sched)) { 4103 __kmp_str_buf_print(buffer, "nonmonotonic:"); 4104 } 4105 if (__kmp_chunk) { 4106 switch (sched) { 4107 case kmp_sch_dynamic_chunked: 4108 __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk); 4109 break; 4110 case kmp_sch_guided_iterative_chunked: 4111 case kmp_sch_guided_analytical_chunked: 4112 __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk); 4113 break; 4114 case kmp_sch_trapezoidal: 4115 __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk); 4116 break; 4117 case kmp_sch_static: 4118 case kmp_sch_static_chunked: 4119 case kmp_sch_static_balanced: 4120 case kmp_sch_static_greedy: 4121 __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk); 4122 break; 4123 case kmp_sch_static_steal: 4124 __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk); 4125 break; 4126 case kmp_sch_auto: 4127 __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk); 4128 break; 4129 } 4130 } else { 4131 switch (sched) { 4132 case kmp_sch_dynamic_chunked: 4133 __kmp_str_buf_print(buffer, "%s'\n", "dynamic"); 4134 break; 4135 case kmp_sch_guided_iterative_chunked: 4136 case kmp_sch_guided_analytical_chunked: 4137 __kmp_str_buf_print(buffer, "%s'\n", "guided"); 4138 break; 4139 case kmp_sch_trapezoidal: 4140 __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal"); 4141 break; 4142 case kmp_sch_static: 4143 case kmp_sch_static_chunked: 4144 case kmp_sch_static_balanced: 4145 case kmp_sch_static_greedy: 4146 __kmp_str_buf_print(buffer, "%s'\n", "static"); 4147 break; 4148 case kmp_sch_static_steal: 4149 __kmp_str_buf_print(buffer, "%s'\n", "static_steal"); 4150 break; 4151 case kmp_sch_auto: 4152 __kmp_str_buf_print(buffer, "%s'\n", "auto"); 4153 break; 4154 } 4155 } 4156 } // __kmp_stg_print_omp_schedule 4157 4158 #if KMP_USE_HIER_SCHED 4159 // ----------------------------------------------------------------------------- 4160 // KMP_DISP_HAND_THREAD 4161 static void __kmp_stg_parse_kmp_hand_thread(char const *name, char const *value, 4162 void *data) { 4163 __kmp_stg_parse_bool(name, value, &(__kmp_dispatch_hand_threading)); 4164 } // __kmp_stg_parse_kmp_hand_thread 4165 4166 static void __kmp_stg_print_kmp_hand_thread(kmp_str_buf_t *buffer, 4167 char const *name, void *data) { 4168 __kmp_stg_print_bool(buffer, name, __kmp_dispatch_hand_threading); 4169 } // __kmp_stg_print_kmp_hand_thread 4170 #endif 4171 4172 // ----------------------------------------------------------------------------- 4173 // KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE 4174 static void __kmp_stg_parse_kmp_force_monotonic(char const *name, 4175 char const *value, void *data) { 4176 __kmp_stg_parse_bool(name, value, &(__kmp_force_monotonic)); 4177 } // __kmp_stg_parse_kmp_force_monotonic 4178 4179 static void __kmp_stg_print_kmp_force_monotonic(kmp_str_buf_t *buffer, 4180 char const *name, void *data) { 4181 __kmp_stg_print_bool(buffer, name, __kmp_force_monotonic); 4182 } // __kmp_stg_print_kmp_force_monotonic 4183 4184 // ----------------------------------------------------------------------------- 4185 // KMP_ATOMIC_MODE 4186 4187 static void __kmp_stg_parse_atomic_mode(char const *name, char const *value, 4188 void *data) { 4189 // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP 4190 // compatibility mode. 4191 int mode = 0; 4192 int max = 1; 4193 #ifdef KMP_GOMP_COMPAT 4194 max = 2; 4195 #endif /* KMP_GOMP_COMPAT */ 4196 __kmp_stg_parse_int(name, value, 0, max, &mode); 4197 // TODO; parse_int is not very suitable for this case. In case of overflow it 4198 // is better to use 4199 // 0 rather that max value. 4200 if (mode > 0) { 4201 __kmp_atomic_mode = mode; 4202 } 4203 } // __kmp_stg_parse_atomic_mode 4204 4205 static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name, 4206 void *data) { 4207 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode); 4208 } // __kmp_stg_print_atomic_mode 4209 4210 // ----------------------------------------------------------------------------- 4211 // KMP_CONSISTENCY_CHECK 4212 4213 static void __kmp_stg_parse_consistency_check(char const *name, 4214 char const *value, void *data) { 4215 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) { 4216 // Note, this will not work from kmp_set_defaults because th_cons stack was 4217 // not allocated 4218 // for existed thread(s) thus the first __kmp_push_<construct> will break 4219 // with assertion. 4220 // TODO: allocate th_cons if called from kmp_set_defaults. 4221 __kmp_env_consistency_check = TRUE; 4222 } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) { 4223 __kmp_env_consistency_check = FALSE; 4224 } else { 4225 KMP_WARNING(StgInvalidValue, name, value); 4226 } 4227 } // __kmp_stg_parse_consistency_check 4228 4229 static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer, 4230 char const *name, void *data) { 4231 #if KMP_DEBUG 4232 const char *value = NULL; 4233 4234 if (__kmp_env_consistency_check) { 4235 value = "all"; 4236 } else { 4237 value = "none"; 4238 } 4239 4240 if (value != NULL) { 4241 __kmp_stg_print_str(buffer, name, value); 4242 } 4243 #endif /* KMP_DEBUG */ 4244 } // __kmp_stg_print_consistency_check 4245 4246 #if USE_ITT_BUILD 4247 // ----------------------------------------------------------------------------- 4248 // KMP_ITT_PREPARE_DELAY 4249 4250 #if USE_ITT_NOTIFY 4251 4252 static void __kmp_stg_parse_itt_prepare_delay(char const *name, 4253 char const *value, void *data) { 4254 // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop 4255 // iterations. 4256 int delay = 0; 4257 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay); 4258 __kmp_itt_prepare_delay = delay; 4259 } // __kmp_str_parse_itt_prepare_delay 4260 4261 static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer, 4262 char const *name, void *data) { 4263 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay); 4264 4265 } // __kmp_str_print_itt_prepare_delay 4266 4267 #endif // USE_ITT_NOTIFY 4268 #endif /* USE_ITT_BUILD */ 4269 4270 // ----------------------------------------------------------------------------- 4271 // KMP_MALLOC_POOL_INCR 4272 4273 static void __kmp_stg_parse_malloc_pool_incr(char const *name, 4274 char const *value, void *data) { 4275 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR, 4276 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr, 4277 1); 4278 } // __kmp_stg_parse_malloc_pool_incr 4279 4280 static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer, 4281 char const *name, void *data) { 4282 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr); 4283 4284 } // _kmp_stg_print_malloc_pool_incr 4285 4286 #ifdef KMP_DEBUG 4287 4288 // ----------------------------------------------------------------------------- 4289 // KMP_PAR_RANGE 4290 4291 static void __kmp_stg_parse_par_range_env(char const *name, char const *value, 4292 void *data) { 4293 __kmp_stg_parse_par_range(name, value, &__kmp_par_range, 4294 __kmp_par_range_routine, __kmp_par_range_filename, 4295 &__kmp_par_range_lb, &__kmp_par_range_ub); 4296 } // __kmp_stg_parse_par_range_env 4297 4298 static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer, 4299 char const *name, void *data) { 4300 if (__kmp_par_range != 0) { 4301 __kmp_stg_print_str(buffer, name, par_range_to_print); 4302 } 4303 } // __kmp_stg_print_par_range_env 4304 4305 #endif 4306 4307 // ----------------------------------------------------------------------------- 4308 // KMP_GTID_MODE 4309 4310 static void __kmp_stg_parse_gtid_mode(char const *name, char const *value, 4311 void *data) { 4312 // Modes: 4313 // 0 -- do not change default 4314 // 1 -- sp search 4315 // 2 -- use "keyed" TLS var, i.e. 4316 // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS) 4317 // 3 -- __declspec(thread) TLS var in tdata section 4318 int mode = 0; 4319 int max = 2; 4320 #ifdef KMP_TDATA_GTID 4321 max = 3; 4322 #endif /* KMP_TDATA_GTID */ 4323 __kmp_stg_parse_int(name, value, 0, max, &mode); 4324 // TODO; parse_int is not very suitable for this case. In case of overflow it 4325 // is better to use 0 rather that max value. 4326 if (mode == 0) { 4327 __kmp_adjust_gtid_mode = TRUE; 4328 } else { 4329 __kmp_gtid_mode = mode; 4330 __kmp_adjust_gtid_mode = FALSE; 4331 } 4332 } // __kmp_str_parse_gtid_mode 4333 4334 static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name, 4335 void *data) { 4336 if (__kmp_adjust_gtid_mode) { 4337 __kmp_stg_print_int(buffer, name, 0); 4338 } else { 4339 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode); 4340 } 4341 } // __kmp_stg_print_gtid_mode 4342 4343 // ----------------------------------------------------------------------------- 4344 // KMP_NUM_LOCKS_IN_BLOCK 4345 4346 static void __kmp_stg_parse_lock_block(char const *name, char const *value, 4347 void *data) { 4348 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block); 4349 } // __kmp_str_parse_lock_block 4350 4351 static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name, 4352 void *data) { 4353 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block); 4354 } // __kmp_stg_print_lock_block 4355 4356 // ----------------------------------------------------------------------------- 4357 // KMP_LOCK_KIND 4358 4359 #if KMP_USE_DYNAMIC_LOCK 4360 #define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a) 4361 #else 4362 #define KMP_STORE_LOCK_SEQ(a) 4363 #endif 4364 4365 static void __kmp_stg_parse_lock_kind(char const *name, char const *value, 4366 void *data) { 4367 if (__kmp_init_user_locks) { 4368 KMP_WARNING(EnvLockWarn, name); 4369 return; 4370 } 4371 4372 if (__kmp_str_match("tas", 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-and-set", 2, value) || 4376 __kmp_str_match("test andset", 2, value) || 4377 __kmp_str_match("test_andset", 2, value) || 4378 __kmp_str_match("test-andset", 2, value) || 4379 __kmp_str_match("testand set", 2, value) || 4380 __kmp_str_match("testand_set", 2, value) || 4381 __kmp_str_match("testand-set", 2, value) || 4382 __kmp_str_match("testandset", 2, value)) { 4383 __kmp_user_lock_kind = lk_tas; 4384 KMP_STORE_LOCK_SEQ(tas); 4385 } 4386 #if KMP_USE_FUTEX 4387 else if (__kmp_str_match("futex", 1, value)) { 4388 if (__kmp_futex_determine_capable()) { 4389 __kmp_user_lock_kind = lk_futex; 4390 KMP_STORE_LOCK_SEQ(futex); 4391 } else { 4392 KMP_WARNING(FutexNotSupported, name, value); 4393 } 4394 } 4395 #endif 4396 else if (__kmp_str_match("ticket", 2, value)) { 4397 __kmp_user_lock_kind = lk_ticket; 4398 KMP_STORE_LOCK_SEQ(ticket); 4399 } else if (__kmp_str_match("queuing", 1, value) || 4400 __kmp_str_match("queue", 1, value)) { 4401 __kmp_user_lock_kind = lk_queuing; 4402 KMP_STORE_LOCK_SEQ(queuing); 4403 } else if (__kmp_str_match("drdpa ticket", 1, value) || 4404 __kmp_str_match("drdpa_ticket", 1, value) || 4405 __kmp_str_match("drdpa-ticket", 1, value) || 4406 __kmp_str_match("drdpaticket", 1, value) || 4407 __kmp_str_match("drdpa", 1, value)) { 4408 __kmp_user_lock_kind = lk_drdpa; 4409 KMP_STORE_LOCK_SEQ(drdpa); 4410 } 4411 #if KMP_USE_ADAPTIVE_LOCKS 4412 else if (__kmp_str_match("adaptive", 1, value)) { 4413 if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here? 4414 __kmp_user_lock_kind = lk_adaptive; 4415 KMP_STORE_LOCK_SEQ(adaptive); 4416 } else { 4417 KMP_WARNING(AdaptiveNotSupported, name, value); 4418 __kmp_user_lock_kind = lk_queuing; 4419 KMP_STORE_LOCK_SEQ(queuing); 4420 } 4421 } 4422 #endif // KMP_USE_ADAPTIVE_LOCKS 4423 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX 4424 else if (__kmp_str_match("rtm_queuing", 1, value)) { 4425 if (__kmp_cpuinfo.rtm) { 4426 __kmp_user_lock_kind = lk_rtm_queuing; 4427 KMP_STORE_LOCK_SEQ(rtm_queuing); 4428 } else { 4429 KMP_WARNING(AdaptiveNotSupported, name, value); 4430 __kmp_user_lock_kind = lk_queuing; 4431 KMP_STORE_LOCK_SEQ(queuing); 4432 } 4433 } else if (__kmp_str_match("rtm_spin", 1, value)) { 4434 if (__kmp_cpuinfo.rtm) { 4435 __kmp_user_lock_kind = lk_rtm_spin; 4436 KMP_STORE_LOCK_SEQ(rtm_spin); 4437 } else { 4438 KMP_WARNING(AdaptiveNotSupported, name, value); 4439 __kmp_user_lock_kind = lk_tas; 4440 KMP_STORE_LOCK_SEQ(queuing); 4441 } 4442 } else if (__kmp_str_match("hle", 1, value)) { 4443 __kmp_user_lock_kind = lk_hle; 4444 KMP_STORE_LOCK_SEQ(hle); 4445 } 4446 #endif 4447 else { 4448 KMP_WARNING(StgInvalidValue, name, value); 4449 } 4450 } 4451 4452 static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name, 4453 void *data) { 4454 const char *value = NULL; 4455 4456 switch (__kmp_user_lock_kind) { 4457 case lk_default: 4458 value = "default"; 4459 break; 4460 4461 case lk_tas: 4462 value = "tas"; 4463 break; 4464 4465 #if KMP_USE_FUTEX 4466 case lk_futex: 4467 value = "futex"; 4468 break; 4469 #endif 4470 4471 #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX 4472 case lk_rtm_queuing: 4473 value = "rtm_queuing"; 4474 break; 4475 4476 case lk_rtm_spin: 4477 value = "rtm_spin"; 4478 break; 4479 4480 case lk_hle: 4481 value = "hle"; 4482 break; 4483 #endif 4484 4485 case lk_ticket: 4486 value = "ticket"; 4487 break; 4488 4489 case lk_queuing: 4490 value = "queuing"; 4491 break; 4492 4493 case lk_drdpa: 4494 value = "drdpa"; 4495 break; 4496 #if KMP_USE_ADAPTIVE_LOCKS 4497 case lk_adaptive: 4498 value = "adaptive"; 4499 break; 4500 #endif 4501 } 4502 4503 if (value != NULL) { 4504 __kmp_stg_print_str(buffer, name, value); 4505 } 4506 } 4507 4508 // ----------------------------------------------------------------------------- 4509 // KMP_SPIN_BACKOFF_PARAMS 4510 4511 // KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick 4512 // for machine pause) 4513 static void __kmp_stg_parse_spin_backoff_params(const char *name, 4514 const char *value, void *data) { 4515 const char *next = value; 4516 4517 int total = 0; // Count elements that were set. It'll be used as an array size 4518 int prev_comma = FALSE; // For correct processing sequential commas 4519 int i; 4520 4521 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff; 4522 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick; 4523 4524 // Run only 3 iterations because it is enough to read two values or find a 4525 // syntax error 4526 for (i = 0; i < 3; i++) { 4527 SKIP_WS(next); 4528 4529 if (*next == '\0') { 4530 break; 4531 } 4532 // Next character is not an integer or not a comma OR number of values > 2 4533 // => end of list 4534 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) { 4535 KMP_WARNING(EnvSyntaxError, name, value); 4536 return; 4537 } 4538 // The next character is ',' 4539 if (*next == ',') { 4540 // ',' is the first character 4541 if (total == 0 || prev_comma) { 4542 total++; 4543 } 4544 prev_comma = TRUE; 4545 next++; // skip ',' 4546 SKIP_WS(next); 4547 } 4548 // Next character is a digit 4549 if (*next >= '0' && *next <= '9') { 4550 int num; 4551 const char *buf = next; 4552 char const *msg = NULL; 4553 prev_comma = FALSE; 4554 SKIP_DIGITS(next); 4555 total++; 4556 4557 const char *tmp = next; 4558 SKIP_WS(tmp); 4559 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) { 4560 KMP_WARNING(EnvSpacesNotAllowed, name, value); 4561 return; 4562 } 4563 4564 num = __kmp_str_to_int(buf, *next); 4565 if (num <= 0) { // The number of retries should be > 0 4566 msg = KMP_I18N_STR(ValueTooSmall); 4567 num = 1; 4568 } else if (num > KMP_INT_MAX) { 4569 msg = KMP_I18N_STR(ValueTooLarge); 4570 num = KMP_INT_MAX; 4571 } 4572 if (msg != NULL) { 4573 // Message is not empty. Print warning. 4574 KMP_WARNING(ParseSizeIntWarn, name, value, msg); 4575 KMP_INFORM(Using_int_Value, name, num); 4576 } 4577 if (total == 1) { 4578 max_backoff = num; 4579 } else if (total == 2) { 4580 min_tick = num; 4581 } 4582 } 4583 } 4584 KMP_DEBUG_ASSERT(total > 0); 4585 if (total <= 0) { 4586 KMP_WARNING(EnvSyntaxError, name, value); 4587 return; 4588 } 4589 __kmp_spin_backoff_params.max_backoff = max_backoff; 4590 __kmp_spin_backoff_params.min_tick = min_tick; 4591 } 4592 4593 static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer, 4594 char const *name, void *data) { 4595 if (__kmp_env_format) { 4596 KMP_STR_BUF_PRINT_NAME_EX(name); 4597 } else { 4598 __kmp_str_buf_print(buffer, " %s='", name); 4599 } 4600 __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff, 4601 __kmp_spin_backoff_params.min_tick); 4602 } 4603 4604 #if KMP_USE_ADAPTIVE_LOCKS 4605 4606 // ----------------------------------------------------------------------------- 4607 // KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE 4608 4609 // Parse out values for the tunable parameters from a string of the form 4610 // KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness] 4611 static void __kmp_stg_parse_adaptive_lock_props(const char *name, 4612 const char *value, void *data) { 4613 int max_retries = 0; 4614 int max_badness = 0; 4615 4616 const char *next = value; 4617 4618 int total = 0; // Count elements that were set. It'll be used as an array size 4619 int prev_comma = FALSE; // For correct processing sequential commas 4620 int i; 4621 4622 // Save values in the structure __kmp_speculative_backoff_params 4623 // Run only 3 iterations because it is enough to read two values or find a 4624 // syntax error 4625 for (i = 0; i < 3; i++) { 4626 SKIP_WS(next); 4627 4628 if (*next == '\0') { 4629 break; 4630 } 4631 // Next character is not an integer or not a comma OR number of values > 2 4632 // => end of list 4633 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) { 4634 KMP_WARNING(EnvSyntaxError, name, value); 4635 return; 4636 } 4637 // The next character is ',' 4638 if (*next == ',') { 4639 // ',' is the first character 4640 if (total == 0 || prev_comma) { 4641 total++; 4642 } 4643 prev_comma = TRUE; 4644 next++; // skip ',' 4645 SKIP_WS(next); 4646 } 4647 // Next character is a digit 4648 if (*next >= '0' && *next <= '9') { 4649 int num; 4650 const char *buf = next; 4651 char const *msg = NULL; 4652 prev_comma = FALSE; 4653 SKIP_DIGITS(next); 4654 total++; 4655 4656 const char *tmp = next; 4657 SKIP_WS(tmp); 4658 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) { 4659 KMP_WARNING(EnvSpacesNotAllowed, name, value); 4660 return; 4661 } 4662 4663 num = __kmp_str_to_int(buf, *next); 4664 if (num < 0) { // The number of retries should be >= 0 4665 msg = KMP_I18N_STR(ValueTooSmall); 4666 num = 1; 4667 } else if (num > KMP_INT_MAX) { 4668 msg = KMP_I18N_STR(ValueTooLarge); 4669 num = KMP_INT_MAX; 4670 } 4671 if (msg != NULL) { 4672 // Message is not empty. Print warning. 4673 KMP_WARNING(ParseSizeIntWarn, name, value, msg); 4674 KMP_INFORM(Using_int_Value, name, num); 4675 } 4676 if (total == 1) { 4677 max_retries = num; 4678 } else if (total == 2) { 4679 max_badness = num; 4680 } 4681 } 4682 } 4683 KMP_DEBUG_ASSERT(total > 0); 4684 if (total <= 0) { 4685 KMP_WARNING(EnvSyntaxError, name, value); 4686 return; 4687 } 4688 __kmp_adaptive_backoff_params.max_soft_retries = max_retries; 4689 __kmp_adaptive_backoff_params.max_badness = max_badness; 4690 } 4691 4692 static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer, 4693 char const *name, void *data) { 4694 if (__kmp_env_format) { 4695 KMP_STR_BUF_PRINT_NAME_EX(name); 4696 } else { 4697 __kmp_str_buf_print(buffer, " %s='", name); 4698 } 4699 __kmp_str_buf_print(buffer, "%d,%d'\n", 4700 __kmp_adaptive_backoff_params.max_soft_retries, 4701 __kmp_adaptive_backoff_params.max_badness); 4702 } // __kmp_stg_print_adaptive_lock_props 4703 4704 #if KMP_DEBUG_ADAPTIVE_LOCKS 4705 4706 static void __kmp_stg_parse_speculative_statsfile(char const *name, 4707 char const *value, 4708 void *data) { 4709 __kmp_stg_parse_file(name, value, "", 4710 CCAST(char **, &__kmp_speculative_statsfile)); 4711 } // __kmp_stg_parse_speculative_statsfile 4712 4713 static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer, 4714 char const *name, 4715 void *data) { 4716 if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) { 4717 __kmp_stg_print_str(buffer, name, "stdout"); 4718 } else { 4719 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile); 4720 } 4721 4722 } // __kmp_stg_print_speculative_statsfile 4723 4724 #endif // KMP_DEBUG_ADAPTIVE_LOCKS 4725 4726 #endif // KMP_USE_ADAPTIVE_LOCKS 4727 4728 // ----------------------------------------------------------------------------- 4729 // KMP_HW_SUBSET (was KMP_PLACE_THREADS) 4730 4731 // The longest observable sequence of items is 4732 // Socket-Node-Tile-Core-Thread 4733 // So, let's limit to 5 levels for now 4734 // The input string is usually short enough, let's use 512 limit for now 4735 #define MAX_T_LEVEL 5 4736 #define MAX_STR_LEN 512 4737 static void __kmp_stg_parse_hw_subset(char const *name, char const *value, 4738 void *data) { 4739 // Value example: 1s,5c@3,2T 4740 // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core" 4741 kmp_setting_t **rivals = (kmp_setting_t **)data; 4742 if (strcmp(name, "KMP_PLACE_THREADS") == 0) { 4743 KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET"); 4744 } 4745 if (__kmp_stg_check_rivals(name, value, rivals)) { 4746 return; 4747 } 4748 4749 char *components[MAX_T_LEVEL]; 4750 char const *digits = "0123456789"; 4751 char input[MAX_STR_LEN]; 4752 size_t len = 0, mlen = MAX_STR_LEN; 4753 int level = 0; 4754 // Canonize the string (remove spaces, unify delimiters, etc.) 4755 char *pos = CCAST(char *, value); 4756 while (*pos && mlen) { 4757 if (*pos != ' ') { // skip spaces 4758 if (len == 0 && *pos == ':') { 4759 __kmp_hws_abs_flag = 1; // if the first symbol is ":", skip it 4760 } else { 4761 input[len] = (char)(toupper(*pos)); 4762 if (input[len] == 'X') 4763 input[len] = ','; // unify delimiters of levels 4764 if (input[len] == 'O' && strchr(digits, *(pos + 1))) 4765 input[len] = '@'; // unify delimiters of offset 4766 len++; 4767 } 4768 } 4769 mlen--; 4770 pos++; 4771 } 4772 if (len == 0 || mlen == 0) 4773 goto err; // contents is either empty or too long 4774 input[len] = '\0'; 4775 __kmp_hws_requested = 1; // mark that subset requested 4776 // Split by delimiter 4777 pos = input; 4778 components[level++] = pos; 4779 while ((pos = strchr(pos, ','))) { 4780 if (level >= MAX_T_LEVEL) 4781 goto err; // too many components provided 4782 *pos = '\0'; // modify input and avoid more copying 4783 components[level++] = ++pos; // expect something after "," 4784 } 4785 // Check each component 4786 for (int i = 0; i < level; ++i) { 4787 int offset = 0; 4788 int num = atoi(components[i]); // each component should start with a number 4789 if ((pos = strchr(components[i], '@'))) { 4790 offset = atoi(pos + 1); // save offset 4791 *pos = '\0'; // cut the offset from the component 4792 } 4793 pos = components[i] + strspn(components[i], digits); 4794 if (pos == components[i]) 4795 goto err; 4796 // detect the component type 4797 switch (*pos) { 4798 case 'S': // Socket 4799 if (__kmp_hws_socket.num > 0) 4800 goto err; // duplicate is not allowed 4801 __kmp_hws_socket.num = num; 4802 __kmp_hws_socket.offset = offset; 4803 break; 4804 case 'N': // NUMA Node 4805 if (__kmp_hws_node.num > 0) 4806 goto err; // duplicate is not allowed 4807 __kmp_hws_node.num = num; 4808 __kmp_hws_node.offset = offset; 4809 break; 4810 case 'D': // Die 4811 if (__kmp_hws_die.num > 0) 4812 goto err; // duplicate is not allowed 4813 __kmp_hws_die.num = num; 4814 __kmp_hws_die.offset = offset; 4815 break; 4816 case 'L': // Cache 4817 if (*(pos + 1) == '2') { // L2 - Tile 4818 if (__kmp_hws_tile.num > 0) 4819 goto err; // duplicate is not allowed 4820 __kmp_hws_tile.num = num; 4821 __kmp_hws_tile.offset = offset; 4822 } else if (*(pos + 1) == '3') { // L3 - Socket 4823 if (__kmp_hws_socket.num > 0 || __kmp_hws_die.num > 0) 4824 goto err; // duplicate is not allowed 4825 __kmp_hws_socket.num = num; 4826 __kmp_hws_socket.offset = offset; 4827 } else if (*(pos + 1) == '1') { // L1 - Core 4828 if (__kmp_hws_core.num > 0) 4829 goto err; // duplicate is not allowed 4830 __kmp_hws_core.num = num; 4831 __kmp_hws_core.offset = offset; 4832 } 4833 break; 4834 case 'C': // Core (or Cache?) 4835 if (*(pos + 1) != 'A') { 4836 if (__kmp_hws_core.num > 0) 4837 goto err; // duplicate is not allowed 4838 __kmp_hws_core.num = num; 4839 __kmp_hws_core.offset = offset; 4840 } else { // Cache 4841 char *d = pos + strcspn(pos, digits); // find digit 4842 if (*d == '2') { // L2 - Tile 4843 if (__kmp_hws_tile.num > 0) 4844 goto err; // duplicate is not allowed 4845 __kmp_hws_tile.num = num; 4846 __kmp_hws_tile.offset = offset; 4847 } else if (*d == '3') { // L3 - Socket 4848 if (__kmp_hws_socket.num > 0 || __kmp_hws_die.num > 0) 4849 goto err; // duplicate is not allowed 4850 __kmp_hws_socket.num = num; 4851 __kmp_hws_socket.offset = offset; 4852 } else if (*d == '1') { // L1 - Core 4853 if (__kmp_hws_core.num > 0) 4854 goto err; // duplicate is not allowed 4855 __kmp_hws_core.num = num; 4856 __kmp_hws_core.offset = offset; 4857 } else { 4858 goto err; 4859 } 4860 } 4861 break; 4862 case 'T': // Thread 4863 if (__kmp_hws_proc.num > 0) 4864 goto err; // duplicate is not allowed 4865 __kmp_hws_proc.num = num; 4866 __kmp_hws_proc.offset = offset; 4867 break; 4868 default: 4869 goto err; 4870 } 4871 } 4872 return; 4873 err: 4874 KMP_WARNING(AffHWSubsetInvalid, name, value); 4875 __kmp_hws_requested = 0; // mark that subset not requested 4876 return; 4877 } 4878 4879 static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name, 4880 void *data) { 4881 if (__kmp_hws_requested) { 4882 int comma = 0; 4883 kmp_str_buf_t buf; 4884 __kmp_str_buf_init(&buf); 4885 if (__kmp_env_format) 4886 KMP_STR_BUF_PRINT_NAME_EX(name); 4887 else 4888 __kmp_str_buf_print(buffer, " %s='", name); 4889 if (__kmp_hws_socket.num) { 4890 __kmp_str_buf_print(&buf, "%ds", __kmp_hws_socket.num); 4891 if (__kmp_hws_socket.offset) 4892 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_socket.offset); 4893 comma = 1; 4894 } 4895 if (__kmp_hws_die.num) { 4896 __kmp_str_buf_print(&buf, "%s%dd", comma ? "," : "", __kmp_hws_die.num); 4897 if (__kmp_hws_die.offset) 4898 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_die.offset); 4899 comma = 1; 4900 } 4901 if (__kmp_hws_node.num) { 4902 __kmp_str_buf_print(&buf, "%s%dn", comma ? "," : "", __kmp_hws_node.num); 4903 if (__kmp_hws_node.offset) 4904 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_node.offset); 4905 comma = 1; 4906 } 4907 if (__kmp_hws_tile.num) { 4908 __kmp_str_buf_print(&buf, "%s%dL2", comma ? "," : "", __kmp_hws_tile.num); 4909 if (__kmp_hws_tile.offset) 4910 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_tile.offset); 4911 comma = 1; 4912 } 4913 if (__kmp_hws_core.num) { 4914 __kmp_str_buf_print(&buf, "%s%dc", comma ? "," : "", __kmp_hws_core.num); 4915 if (__kmp_hws_core.offset) 4916 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_core.offset); 4917 comma = 1; 4918 } 4919 if (__kmp_hws_proc.num) 4920 __kmp_str_buf_print(&buf, "%s%dt", comma ? "," : "", __kmp_hws_proc.num); 4921 __kmp_str_buf_print(buffer, "%s'\n", buf.str); 4922 __kmp_str_buf_free(&buf); 4923 } 4924 } 4925 4926 #if USE_ITT_BUILD 4927 // ----------------------------------------------------------------------------- 4928 // KMP_FORKJOIN_FRAMES 4929 4930 static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value, 4931 void *data) { 4932 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames); 4933 } // __kmp_stg_parse_forkjoin_frames 4934 4935 static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer, 4936 char const *name, void *data) { 4937 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames); 4938 } // __kmp_stg_print_forkjoin_frames 4939 4940 // ----------------------------------------------------------------------------- 4941 // KMP_FORKJOIN_FRAMES_MODE 4942 4943 static void __kmp_stg_parse_forkjoin_frames_mode(char const *name, 4944 char const *value, 4945 void *data) { 4946 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode); 4947 } // __kmp_stg_parse_forkjoin_frames 4948 4949 static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer, 4950 char const *name, void *data) { 4951 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode); 4952 } // __kmp_stg_print_forkjoin_frames 4953 #endif /* USE_ITT_BUILD */ 4954 4955 // ----------------------------------------------------------------------------- 4956 // KMP_ENABLE_TASK_THROTTLING 4957 4958 static void __kmp_stg_parse_task_throttling(char const *name, char const *value, 4959 void *data) { 4960 __kmp_stg_parse_bool(name, value, &__kmp_enable_task_throttling); 4961 } // __kmp_stg_parse_task_throttling 4962 4963 static void __kmp_stg_print_task_throttling(kmp_str_buf_t *buffer, 4964 char const *name, void *data) { 4965 __kmp_stg_print_bool(buffer, name, __kmp_enable_task_throttling); 4966 } // __kmp_stg_print_task_throttling 4967 4968 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT 4969 // ----------------------------------------------------------------------------- 4970 // KMP_USER_LEVEL_MWAIT 4971 4972 static void __kmp_stg_parse_user_level_mwait(char const *name, 4973 char const *value, void *data) { 4974 __kmp_stg_parse_bool(name, value, &__kmp_user_level_mwait); 4975 } // __kmp_stg_parse_user_level_mwait 4976 4977 static void __kmp_stg_print_user_level_mwait(kmp_str_buf_t *buffer, 4978 char const *name, void *data) { 4979 __kmp_stg_print_bool(buffer, name, __kmp_user_level_mwait); 4980 } // __kmp_stg_print_user_level_mwait 4981 4982 // ----------------------------------------------------------------------------- 4983 // KMP_MWAIT_HINTS 4984 4985 static void __kmp_stg_parse_mwait_hints(char const *name, char const *value, 4986 void *data) { 4987 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_mwait_hints); 4988 } // __kmp_stg_parse_mwait_hints 4989 4990 static void __kmp_stg_print_mwait_hints(kmp_str_buf_t *buffer, char const *name, 4991 void *data) { 4992 __kmp_stg_print_int(buffer, name, __kmp_mwait_hints); 4993 } // __kmp_stg_print_mwait_hints 4994 4995 #endif // KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT 4996 4997 // ----------------------------------------------------------------------------- 4998 // OMP_DISPLAY_ENV 4999 5000 static void __kmp_stg_parse_omp_display_env(char const *name, char const *value, 5001 void *data) { 5002 if (__kmp_str_match("VERBOSE", 1, value)) { 5003 __kmp_display_env_verbose = TRUE; 5004 } else { 5005 __kmp_stg_parse_bool(name, value, &__kmp_display_env); 5006 } 5007 } // __kmp_stg_parse_omp_display_env 5008 5009 static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer, 5010 char const *name, void *data) { 5011 if (__kmp_display_env_verbose) { 5012 __kmp_stg_print_str(buffer, name, "VERBOSE"); 5013 } else { 5014 __kmp_stg_print_bool(buffer, name, __kmp_display_env); 5015 } 5016 } // __kmp_stg_print_omp_display_env 5017 5018 static void __kmp_stg_parse_omp_cancellation(char const *name, 5019 char const *value, void *data) { 5020 if (TCR_4(__kmp_init_parallel)) { 5021 KMP_WARNING(EnvParallelWarn, name); 5022 return; 5023 } // read value before first parallel only 5024 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation); 5025 } // __kmp_stg_parse_omp_cancellation 5026 5027 static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer, 5028 char const *name, void *data) { 5029 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation); 5030 } // __kmp_stg_print_omp_cancellation 5031 5032 #if OMPT_SUPPORT 5033 static int __kmp_tool = 1; 5034 5035 static void __kmp_stg_parse_omp_tool(char const *name, char const *value, 5036 void *data) { 5037 __kmp_stg_parse_bool(name, value, &__kmp_tool); 5038 } // __kmp_stg_parse_omp_tool 5039 5040 static void __kmp_stg_print_omp_tool(kmp_str_buf_t *buffer, char const *name, 5041 void *data) { 5042 if (__kmp_env_format) { 5043 KMP_STR_BUF_PRINT_BOOL_EX(name, __kmp_tool, "enabled", "disabled"); 5044 } else { 5045 __kmp_str_buf_print(buffer, " %s=%s\n", name, 5046 __kmp_tool ? "enabled" : "disabled"); 5047 } 5048 } // __kmp_stg_print_omp_tool 5049 5050 static char *__kmp_tool_libraries = NULL; 5051 5052 static void __kmp_stg_parse_omp_tool_libraries(char const *name, 5053 char const *value, void *data) { 5054 __kmp_stg_parse_str(name, value, &__kmp_tool_libraries); 5055 } // __kmp_stg_parse_omp_tool_libraries 5056 5057 static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer, 5058 char const *name, void *data) { 5059 if (__kmp_tool_libraries) 5060 __kmp_stg_print_str(buffer, name, __kmp_tool_libraries); 5061 else { 5062 if (__kmp_env_format) { 5063 KMP_STR_BUF_PRINT_NAME; 5064 } else { 5065 __kmp_str_buf_print(buffer, " %s", name); 5066 } 5067 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined)); 5068 } 5069 } // __kmp_stg_print_omp_tool_libraries 5070 5071 static char *__kmp_tool_verbose_init = NULL; 5072 5073 static void __kmp_stg_parse_omp_tool_verbose_init(char const *name, 5074 char const *value, 5075 void *data) { 5076 __kmp_stg_parse_str(name, value, &__kmp_tool_verbose_init); 5077 } // __kmp_stg_parse_omp_tool_libraries 5078 5079 static void __kmp_stg_print_omp_tool_verbose_init(kmp_str_buf_t *buffer, 5080 char const *name, 5081 void *data) { 5082 if (__kmp_tool_verbose_init) 5083 __kmp_stg_print_str(buffer, name, __kmp_tool_libraries); 5084 else { 5085 if (__kmp_env_format) { 5086 KMP_STR_BUF_PRINT_NAME; 5087 } else { 5088 __kmp_str_buf_print(buffer, " %s", name); 5089 } 5090 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined)); 5091 } 5092 } // __kmp_stg_print_omp_tool_verbose_init 5093 5094 #endif 5095 5096 // Table. 5097 5098 static kmp_setting_t __kmp_stg_table[] = { 5099 5100 {"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0}, 5101 {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime, 5102 NULL, 0, 0}, 5103 {"KMP_USE_YIELD", __kmp_stg_parse_use_yield, __kmp_stg_print_use_yield, 5104 NULL, 0, 0}, 5105 {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok, 5106 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0}, 5107 {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy, 5108 NULL, 0, 0}, 5109 {"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit, 5110 __kmp_stg_print_device_thread_limit, NULL, 0, 0}, 5111 #if KMP_USE_MONITOR 5112 {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize, 5113 __kmp_stg_print_monitor_stacksize, NULL, 0, 0}, 5114 #endif 5115 {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL, 5116 0, 0}, 5117 {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset, 5118 __kmp_stg_print_stackoffset, NULL, 0, 0}, 5119 {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize, 5120 NULL, 0, 0}, 5121 {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL, 5122 0, 0}, 5123 {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0, 5124 0}, 5125 {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL, 5126 0, 0}, 5127 5128 {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0}, 5129 {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads, 5130 __kmp_stg_print_num_threads, NULL, 0, 0}, 5131 {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize, 5132 NULL, 0, 0}, 5133 5134 {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0, 5135 0}, 5136 {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing, 5137 __kmp_stg_print_task_stealing, NULL, 0, 0}, 5138 {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels, 5139 __kmp_stg_print_max_active_levels, NULL, 0, 0}, 5140 {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device, 5141 __kmp_stg_print_default_device, NULL, 0, 0}, 5142 {"OMP_TARGET_OFFLOAD", __kmp_stg_parse_target_offload, 5143 __kmp_stg_print_target_offload, NULL, 0, 0}, 5144 {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority, 5145 __kmp_stg_print_max_task_priority, NULL, 0, 0}, 5146 {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks, 5147 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0}, 5148 {"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit, 5149 __kmp_stg_print_thread_limit, NULL, 0, 0}, 5150 {"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit, 5151 __kmp_stg_print_teams_thread_limit, NULL, 0, 0}, 5152 {"OMP_NUM_TEAMS", __kmp_stg_parse_nteams, __kmp_stg_print_nteams, NULL, 0, 5153 0}, 5154 {"OMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_th_limit, 5155 __kmp_stg_print_teams_th_limit, NULL, 0, 0}, 5156 {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy, 5157 __kmp_stg_print_wait_policy, NULL, 0, 0}, 5158 {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers, 5159 __kmp_stg_print_disp_buffers, NULL, 0, 0}, 5160 #if KMP_NESTED_HOT_TEAMS 5161 {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level, 5162 __kmp_stg_print_hot_teams_level, NULL, 0, 0}, 5163 {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode, 5164 __kmp_stg_print_hot_teams_mode, NULL, 0, 0}, 5165 #endif // KMP_NESTED_HOT_TEAMS 5166 5167 #if KMP_HANDLE_SIGNALS 5168 {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals, 5169 __kmp_stg_print_handle_signals, NULL, 0, 0}, 5170 #endif 5171 5172 #if KMP_ARCH_X86 || KMP_ARCH_X86_64 5173 {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control, 5174 __kmp_stg_print_inherit_fp_control, NULL, 0, 0}, 5175 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */ 5176 5177 #ifdef KMP_GOMP_COMPAT 5178 {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0}, 5179 #endif 5180 5181 #ifdef KMP_DEBUG 5182 {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0, 5183 0}, 5184 {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0, 5185 0}, 5186 {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0, 5187 0}, 5188 {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0, 5189 0}, 5190 {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0, 5191 0}, 5192 {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0, 5193 0}, 5194 {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0}, 5195 {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf, 5196 NULL, 0, 0}, 5197 {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic, 5198 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0}, 5199 {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars, 5200 __kmp_stg_print_debug_buf_chars, NULL, 0, 0}, 5201 {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines, 5202 __kmp_stg_print_debug_buf_lines, NULL, 0, 0}, 5203 {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0}, 5204 5205 {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env, 5206 __kmp_stg_print_par_range_env, NULL, 0, 0}, 5207 #endif // KMP_DEBUG 5208 5209 {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc, 5210 __kmp_stg_print_align_alloc, NULL, 0, 0}, 5211 5212 {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit, 5213 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0}, 5214 {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, 5215 __kmp_stg_print_barrier_pattern, NULL, 0, 0}, 5216 {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit, 5217 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0}, 5218 {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, 5219 __kmp_stg_print_barrier_pattern, NULL, 0, 0}, 5220 #if KMP_FAST_REDUCTION_BARRIER 5221 {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit, 5222 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0}, 5223 {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, 5224 __kmp_stg_print_barrier_pattern, NULL, 0, 0}, 5225 #endif 5226 5227 {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay, 5228 __kmp_stg_print_abort_delay, NULL, 0, 0}, 5229 {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file, 5230 __kmp_stg_print_cpuinfo_file, NULL, 0, 0}, 5231 {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction, 5232 __kmp_stg_print_force_reduction, NULL, 0, 0}, 5233 {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction, 5234 __kmp_stg_print_force_reduction, NULL, 0, 0}, 5235 {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map, 5236 __kmp_stg_print_storage_map, NULL, 0, 0}, 5237 {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate, 5238 __kmp_stg_print_all_threadprivate, NULL, 0, 0}, 5239 {"KMP_FOREIGN_THREADS_THREADPRIVATE", 5240 __kmp_stg_parse_foreign_threads_threadprivate, 5241 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0}, 5242 5243 #if KMP_AFFINITY_SUPPORTED 5244 {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL, 5245 0, 0}, 5246 #ifdef KMP_GOMP_COMPAT 5247 {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL, 5248 /* no print */ NULL, 0, 0}, 5249 #endif /* KMP_GOMP_COMPAT */ 5250 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind, 5251 NULL, 0, 0}, 5252 {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0}, 5253 {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method, 5254 __kmp_stg_print_topology_method, NULL, 0, 0}, 5255 5256 #else 5257 5258 // KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES. 5259 // OMP_PROC_BIND and proc-bind-var are supported, however. 5260 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind, 5261 NULL, 0, 0}, 5262 5263 #endif // KMP_AFFINITY_SUPPORTED 5264 {"OMP_DISPLAY_AFFINITY", __kmp_stg_parse_display_affinity, 5265 __kmp_stg_print_display_affinity, NULL, 0, 0}, 5266 {"OMP_AFFINITY_FORMAT", __kmp_stg_parse_affinity_format, 5267 __kmp_stg_print_affinity_format, NULL, 0, 0}, 5268 {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork, 5269 __kmp_stg_print_init_at_fork, NULL, 0, 0}, 5270 {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL, 5271 0, 0}, 5272 {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule, 5273 NULL, 0, 0}, 5274 #if KMP_USE_HIER_SCHED 5275 {"KMP_DISP_HAND_THREAD", __kmp_stg_parse_kmp_hand_thread, 5276 __kmp_stg_print_kmp_hand_thread, NULL, 0, 0}, 5277 #endif 5278 {"KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE", 5279 __kmp_stg_parse_kmp_force_monotonic, __kmp_stg_print_kmp_force_monotonic, 5280 NULL, 0, 0}, 5281 {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode, 5282 __kmp_stg_print_atomic_mode, NULL, 0, 0}, 5283 {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check, 5284 __kmp_stg_print_consistency_check, NULL, 0, 0}, 5285 5286 #if USE_ITT_BUILD && USE_ITT_NOTIFY 5287 {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay, 5288 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0}, 5289 #endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */ 5290 {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr, 5291 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0}, 5292 {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode, 5293 NULL, 0, 0}, 5294 {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic, 5295 NULL, 0, 0}, 5296 {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode, 5297 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0}, 5298 5299 #ifdef USE_LOAD_BALANCE 5300 {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval, 5301 __kmp_stg_print_ld_balance_interval, NULL, 0, 0}, 5302 #endif 5303 5304 {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block, 5305 __kmp_stg_print_lock_block, NULL, 0, 0}, 5306 {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind, 5307 NULL, 0, 0}, 5308 {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params, 5309 __kmp_stg_print_spin_backoff_params, NULL, 0, 0}, 5310 #if KMP_USE_ADAPTIVE_LOCKS 5311 {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props, 5312 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0}, 5313 #if KMP_DEBUG_ADAPTIVE_LOCKS 5314 {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile, 5315 __kmp_stg_print_speculative_statsfile, NULL, 0, 0}, 5316 #endif 5317 #endif // KMP_USE_ADAPTIVE_LOCKS 5318 {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset, 5319 NULL, 0, 0}, 5320 {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset, 5321 NULL, 0, 0}, 5322 #if USE_ITT_BUILD 5323 {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames, 5324 __kmp_stg_print_forkjoin_frames, NULL, 0, 0}, 5325 {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode, 5326 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0}, 5327 #endif 5328 {"KMP_ENABLE_TASK_THROTTLING", __kmp_stg_parse_task_throttling, 5329 __kmp_stg_print_task_throttling, NULL, 0, 0}, 5330 5331 {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env, 5332 __kmp_stg_print_omp_display_env, NULL, 0, 0}, 5333 {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation, 5334 __kmp_stg_print_omp_cancellation, NULL, 0, 0}, 5335 {"OMP_ALLOCATOR", __kmp_stg_parse_allocator, __kmp_stg_print_allocator, 5336 NULL, 0, 0}, 5337 {"LIBOMP_USE_HIDDEN_HELPER_TASK", __kmp_stg_parse_use_hidden_helper, 5338 __kmp_stg_print_use_hidden_helper, NULL, 0, 0}, 5339 {"LIBOMP_NUM_HIDDEN_HELPER_THREADS", 5340 __kmp_stg_parse_num_hidden_helper_threads, 5341 __kmp_stg_print_num_hidden_helper_threads, NULL, 0, 0}, 5342 5343 #if OMPT_SUPPORT 5344 {"OMP_TOOL", __kmp_stg_parse_omp_tool, __kmp_stg_print_omp_tool, NULL, 0, 5345 0}, 5346 {"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries, 5347 __kmp_stg_print_omp_tool_libraries, NULL, 0, 0}, 5348 {"OMP_TOOL_VERBOSE_INIT", __kmp_stg_parse_omp_tool_verbose_init, 5349 __kmp_stg_print_omp_tool_verbose_init, NULL, 0, 0}, 5350 #endif 5351 5352 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT 5353 {"KMP_USER_LEVEL_MWAIT", __kmp_stg_parse_user_level_mwait, 5354 __kmp_stg_print_user_level_mwait, NULL, 0, 0}, 5355 {"KMP_MWAIT_HINTS", __kmp_stg_parse_mwait_hints, 5356 __kmp_stg_print_mwait_hints, NULL, 0, 0}, 5357 #endif 5358 {"", NULL, NULL, NULL, 0, 0}}; // settings 5359 5360 static int const __kmp_stg_count = 5361 sizeof(__kmp_stg_table) / sizeof(kmp_setting_t); 5362 5363 static inline kmp_setting_t *__kmp_stg_find(char const *name) { 5364 5365 int i; 5366 if (name != NULL) { 5367 for (i = 0; i < __kmp_stg_count; ++i) { 5368 if (strcmp(__kmp_stg_table[i].name, name) == 0) { 5369 return &__kmp_stg_table[i]; 5370 } 5371 } 5372 } 5373 return NULL; 5374 5375 } // __kmp_stg_find 5376 5377 static int __kmp_stg_cmp(void const *_a, void const *_b) { 5378 const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a); 5379 const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b); 5380 5381 // Process KMP_AFFINITY last. 5382 // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY. 5383 if (strcmp(a->name, "KMP_AFFINITY") == 0) { 5384 if (strcmp(b->name, "KMP_AFFINITY") == 0) { 5385 return 0; 5386 } 5387 return 1; 5388 } else if (strcmp(b->name, "KMP_AFFINITY") == 0) { 5389 return -1; 5390 } 5391 return strcmp(a->name, b->name); 5392 } // __kmp_stg_cmp 5393 5394 static void __kmp_stg_init(void) { 5395 5396 static int initialized = 0; 5397 5398 if (!initialized) { 5399 5400 // Sort table. 5401 qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t), 5402 __kmp_stg_cmp); 5403 5404 { // Initialize *_STACKSIZE data. 5405 kmp_setting_t *kmp_stacksize = 5406 __kmp_stg_find("KMP_STACKSIZE"); // 1st priority. 5407 #ifdef KMP_GOMP_COMPAT 5408 kmp_setting_t *gomp_stacksize = 5409 __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority. 5410 #endif 5411 kmp_setting_t *omp_stacksize = 5412 __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority. 5413 5414 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround. 5415 // !!! Compiler does not understand rivals is used and optimizes out 5416 // assignments 5417 // !!! rivals[ i ++ ] = ...; 5418 static kmp_setting_t *volatile rivals[4]; 5419 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)}; 5420 #ifdef KMP_GOMP_COMPAT 5421 static kmp_stg_ss_data_t gomp_data = {1024, 5422 CCAST(kmp_setting_t **, rivals)}; 5423 #endif 5424 static kmp_stg_ss_data_t omp_data = {1024, 5425 CCAST(kmp_setting_t **, rivals)}; 5426 int i = 0; 5427 5428 rivals[i++] = kmp_stacksize; 5429 #ifdef KMP_GOMP_COMPAT 5430 if (gomp_stacksize != NULL) { 5431 rivals[i++] = gomp_stacksize; 5432 } 5433 #endif 5434 rivals[i++] = omp_stacksize; 5435 rivals[i++] = NULL; 5436 5437 kmp_stacksize->data = &kmp_data; 5438 #ifdef KMP_GOMP_COMPAT 5439 if (gomp_stacksize != NULL) { 5440 gomp_stacksize->data = &gomp_data; 5441 } 5442 #endif 5443 omp_stacksize->data = &omp_data; 5444 } 5445 5446 { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data. 5447 kmp_setting_t *kmp_library = 5448 __kmp_stg_find("KMP_LIBRARY"); // 1st priority. 5449 kmp_setting_t *omp_wait_policy = 5450 __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority. 5451 5452 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround. 5453 static kmp_setting_t *volatile rivals[3]; 5454 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)}; 5455 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)}; 5456 int i = 0; 5457 5458 rivals[i++] = kmp_library; 5459 if (omp_wait_policy != NULL) { 5460 rivals[i++] = omp_wait_policy; 5461 } 5462 rivals[i++] = NULL; 5463 5464 kmp_library->data = &kmp_data; 5465 if (omp_wait_policy != NULL) { 5466 omp_wait_policy->data = &omp_data; 5467 } 5468 } 5469 5470 { // Initialize KMP_DEVICE_THREAD_LIMIT and KMP_ALL_THREADS 5471 kmp_setting_t *kmp_device_thread_limit = 5472 __kmp_stg_find("KMP_DEVICE_THREAD_LIMIT"); // 1st priority. 5473 kmp_setting_t *kmp_all_threads = 5474 __kmp_stg_find("KMP_ALL_THREADS"); // 2nd priority. 5475 5476 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround. 5477 static kmp_setting_t *volatile rivals[3]; 5478 int i = 0; 5479 5480 rivals[i++] = kmp_device_thread_limit; 5481 rivals[i++] = kmp_all_threads; 5482 rivals[i++] = NULL; 5483 5484 kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals); 5485 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals); 5486 } 5487 5488 { // Initialize KMP_HW_SUBSET and KMP_PLACE_THREADS 5489 // 1st priority 5490 kmp_setting_t *kmp_hw_subset = __kmp_stg_find("KMP_HW_SUBSET"); 5491 // 2nd priority 5492 kmp_setting_t *kmp_place_threads = __kmp_stg_find("KMP_PLACE_THREADS"); 5493 5494 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround. 5495 static kmp_setting_t *volatile rivals[3]; 5496 int i = 0; 5497 5498 rivals[i++] = kmp_hw_subset; 5499 rivals[i++] = kmp_place_threads; 5500 rivals[i++] = NULL; 5501 5502 kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals); 5503 kmp_place_threads->data = CCAST(kmp_setting_t **, rivals); 5504 } 5505 5506 #if KMP_AFFINITY_SUPPORTED 5507 { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data. 5508 kmp_setting_t *kmp_affinity = 5509 __kmp_stg_find("KMP_AFFINITY"); // 1st priority. 5510 KMP_DEBUG_ASSERT(kmp_affinity != NULL); 5511 5512 #ifdef KMP_GOMP_COMPAT 5513 kmp_setting_t *gomp_cpu_affinity = 5514 __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority. 5515 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL); 5516 #endif 5517 5518 kmp_setting_t *omp_proc_bind = 5519 __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority. 5520 KMP_DEBUG_ASSERT(omp_proc_bind != NULL); 5521 5522 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround. 5523 static kmp_setting_t *volatile rivals[4]; 5524 int i = 0; 5525 5526 rivals[i++] = kmp_affinity; 5527 5528 #ifdef KMP_GOMP_COMPAT 5529 rivals[i++] = gomp_cpu_affinity; 5530 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals); 5531 #endif 5532 5533 rivals[i++] = omp_proc_bind; 5534 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals); 5535 rivals[i++] = NULL; 5536 5537 static kmp_setting_t *volatile places_rivals[4]; 5538 i = 0; 5539 5540 kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority. 5541 KMP_DEBUG_ASSERT(omp_places != NULL); 5542 5543 places_rivals[i++] = kmp_affinity; 5544 #ifdef KMP_GOMP_COMPAT 5545 places_rivals[i++] = gomp_cpu_affinity; 5546 #endif 5547 places_rivals[i++] = omp_places; 5548 omp_places->data = CCAST(kmp_setting_t **, places_rivals); 5549 places_rivals[i++] = NULL; 5550 } 5551 #else 5552 // KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals. 5553 // OMP_PLACES not supported yet. 5554 #endif // KMP_AFFINITY_SUPPORTED 5555 5556 { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data. 5557 kmp_setting_t *kmp_force_red = 5558 __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority. 5559 kmp_setting_t *kmp_determ_red = 5560 __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority. 5561 5562 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround. 5563 static kmp_setting_t *volatile rivals[3]; 5564 static kmp_stg_fr_data_t force_data = {1, 5565 CCAST(kmp_setting_t **, rivals)}; 5566 static kmp_stg_fr_data_t determ_data = {0, 5567 CCAST(kmp_setting_t **, rivals)}; 5568 int i = 0; 5569 5570 rivals[i++] = kmp_force_red; 5571 if (kmp_determ_red != NULL) { 5572 rivals[i++] = kmp_determ_red; 5573 } 5574 rivals[i++] = NULL; 5575 5576 kmp_force_red->data = &force_data; 5577 if (kmp_determ_red != NULL) { 5578 kmp_determ_red->data = &determ_data; 5579 } 5580 } 5581 5582 initialized = 1; 5583 } 5584 5585 // Reset flags. 5586 int i; 5587 for (i = 0; i < __kmp_stg_count; ++i) { 5588 __kmp_stg_table[i].set = 0; 5589 } 5590 5591 } // __kmp_stg_init 5592 5593 static void __kmp_stg_parse(char const *name, char const *value) { 5594 // On Windows* OS there are some nameless variables like "C:=C:\" (yeah, 5595 // really nameless, they are presented in environment block as 5596 // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them. 5597 if (name[0] == 0) { 5598 return; 5599 } 5600 5601 if (value != NULL) { 5602 kmp_setting_t *setting = __kmp_stg_find(name); 5603 if (setting != NULL) { 5604 setting->parse(name, value, setting->data); 5605 setting->defined = 1; 5606 } 5607 } 5608 5609 } // __kmp_stg_parse 5610 5611 static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found. 5612 char const *name, // Name of variable. 5613 char const *value, // Value of the variable. 5614 kmp_setting_t **rivals // List of rival settings (must include current one). 5615 ) { 5616 5617 if (rivals == NULL) { 5618 return 0; 5619 } 5620 5621 // Loop thru higher priority settings (listed before current). 5622 int i = 0; 5623 for (; strcmp(rivals[i]->name, name) != 0; i++) { 5624 KMP_DEBUG_ASSERT(rivals[i] != NULL); 5625 5626 #if KMP_AFFINITY_SUPPORTED 5627 if (rivals[i] == __kmp_affinity_notype) { 5628 // If KMP_AFFINITY is specified without a type name, 5629 // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY. 5630 continue; 5631 } 5632 #endif 5633 5634 if (rivals[i]->set) { 5635 KMP_WARNING(StgIgnored, name, rivals[i]->name); 5636 return 1; 5637 } 5638 } 5639 5640 ++i; // Skip current setting. 5641 return 0; 5642 5643 } // __kmp_stg_check_rivals 5644 5645 static int __kmp_env_toPrint(char const *name, int flag) { 5646 int rc = 0; 5647 kmp_setting_t *setting = __kmp_stg_find(name); 5648 if (setting != NULL) { 5649 rc = setting->defined; 5650 if (flag >= 0) { 5651 setting->defined = flag; 5652 } 5653 } 5654 return rc; 5655 } 5656 5657 static void __kmp_aux_env_initialize(kmp_env_blk_t *block) { 5658 5659 char const *value; 5660 5661 /* OMP_NUM_THREADS */ 5662 value = __kmp_env_blk_var(block, "OMP_NUM_THREADS"); 5663 if (value) { 5664 ompc_set_num_threads(__kmp_dflt_team_nth); 5665 } 5666 5667 /* KMP_BLOCKTIME */ 5668 value = __kmp_env_blk_var(block, "KMP_BLOCKTIME"); 5669 if (value) { 5670 kmpc_set_blocktime(__kmp_dflt_blocktime); 5671 } 5672 5673 /* OMP_NESTED */ 5674 value = __kmp_env_blk_var(block, "OMP_NESTED"); 5675 if (value) { 5676 ompc_set_nested(__kmp_dflt_max_active_levels > 1); 5677 } 5678 5679 /* OMP_DYNAMIC */ 5680 value = __kmp_env_blk_var(block, "OMP_DYNAMIC"); 5681 if (value) { 5682 ompc_set_dynamic(__kmp_global.g.g_dynamic); 5683 } 5684 } 5685 5686 void __kmp_env_initialize(char const *string) { 5687 5688 kmp_env_blk_t block; 5689 int i; 5690 5691 __kmp_stg_init(); 5692 5693 // Hack!!! 5694 if (string == NULL) { 5695 // __kmp_max_nth = __kmp_sys_max_nth; 5696 __kmp_threads_capacity = 5697 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub); 5698 } 5699 __kmp_env_blk_init(&block, string); 5700 5701 // update the set flag on all entries that have an env var 5702 for (i = 0; i < block.count; ++i) { 5703 if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) { 5704 continue; 5705 } 5706 if (block.vars[i].value == NULL) { 5707 continue; 5708 } 5709 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name); 5710 if (setting != NULL) { 5711 setting->set = 1; 5712 } 5713 } 5714 5715 // We need to know if blocktime was set when processing OMP_WAIT_POLICY 5716 blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME"); 5717 5718 // Special case. If we parse environment, not a string, process KMP_WARNINGS 5719 // first. 5720 if (string == NULL) { 5721 char const *name = "KMP_WARNINGS"; 5722 char const *value = __kmp_env_blk_var(&block, name); 5723 __kmp_stg_parse(name, value); 5724 } 5725 5726 #if KMP_AFFINITY_SUPPORTED 5727 // Special case. KMP_AFFINITY is not a rival to other affinity env vars 5728 // if no affinity type is specified. We want to allow 5729 // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when 5730 // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0 5731 // affinity mechanism. 5732 __kmp_affinity_notype = NULL; 5733 char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY"); 5734 if (aff_str != NULL) { 5735 // Check if the KMP_AFFINITY type is specified in the string. 5736 // We just search the string for "compact", "scatter", etc. 5737 // without really parsing the string. The syntax of the 5738 // KMP_AFFINITY env var is such that none of the affinity 5739 // type names can appear anywhere other that the type 5740 // specifier, even as substrings. 5741 // 5742 // I can't find a case-insensitive version of strstr on Windows* OS. 5743 // Use the case-sensitive version for now. 5744 5745 #if KMP_OS_WINDOWS 5746 #define FIND strstr 5747 #else 5748 #define FIND strcasestr 5749 #endif 5750 5751 if ((FIND(aff_str, "none") == NULL) && 5752 (FIND(aff_str, "physical") == NULL) && 5753 (FIND(aff_str, "logical") == NULL) && 5754 (FIND(aff_str, "compact") == NULL) && 5755 (FIND(aff_str, "scatter") == NULL) && 5756 (FIND(aff_str, "explicit") == NULL) && 5757 (FIND(aff_str, "balanced") == NULL) && 5758 (FIND(aff_str, "disabled") == NULL)) { 5759 __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY"); 5760 } else { 5761 // A new affinity type is specified. 5762 // Reset the affinity flags to their default values, 5763 // in case this is called from kmp_set_defaults(). 5764 __kmp_affinity_type = affinity_default; 5765 __kmp_affinity_gran = affinity_gran_default; 5766 __kmp_affinity_top_method = affinity_top_method_default; 5767 __kmp_affinity_respect_mask = affinity_respect_mask_default; 5768 } 5769 #undef FIND 5770 5771 // Also reset the affinity flags if OMP_PROC_BIND is specified. 5772 aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND"); 5773 if (aff_str != NULL) { 5774 __kmp_affinity_type = affinity_default; 5775 __kmp_affinity_gran = affinity_gran_default; 5776 __kmp_affinity_top_method = affinity_top_method_default; 5777 __kmp_affinity_respect_mask = affinity_respect_mask_default; 5778 } 5779 } 5780 5781 #endif /* KMP_AFFINITY_SUPPORTED */ 5782 5783 // Set up the nested proc bind type vector. 5784 if (__kmp_nested_proc_bind.bind_types == NULL) { 5785 __kmp_nested_proc_bind.bind_types = 5786 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t)); 5787 if (__kmp_nested_proc_bind.bind_types == NULL) { 5788 KMP_FATAL(MemoryAllocFailed); 5789 } 5790 __kmp_nested_proc_bind.size = 1; 5791 __kmp_nested_proc_bind.used = 1; 5792 #if KMP_AFFINITY_SUPPORTED 5793 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default; 5794 #else 5795 // default proc bind is false if affinity not supported 5796 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false; 5797 #endif 5798 } 5799 5800 // Set up the affinity format ICV 5801 // Grab the default affinity format string from the message catalog 5802 kmp_msg_t m = 5803 __kmp_msg_format(kmp_i18n_msg_AffFormatDefault, "%P", "%i", "%n", "%A"); 5804 KMP_DEBUG_ASSERT(KMP_STRLEN(m.str) < KMP_AFFINITY_FORMAT_SIZE); 5805 5806 if (__kmp_affinity_format == NULL) { 5807 __kmp_affinity_format = 5808 (char *)KMP_INTERNAL_MALLOC(sizeof(char) * KMP_AFFINITY_FORMAT_SIZE); 5809 } 5810 KMP_STRCPY_S(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, m.str); 5811 __kmp_str_free(&m.str); 5812 5813 // Now process all of the settings. 5814 for (i = 0; i < block.count; ++i) { 5815 __kmp_stg_parse(block.vars[i].name, block.vars[i].value); 5816 } 5817 5818 // If user locks have been allocated yet, don't reset the lock vptr table. 5819 if (!__kmp_init_user_locks) { 5820 if (__kmp_user_lock_kind == lk_default) { 5821 __kmp_user_lock_kind = lk_queuing; 5822 } 5823 #if KMP_USE_DYNAMIC_LOCK 5824 __kmp_init_dynamic_user_locks(); 5825 #else 5826 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind); 5827 #endif 5828 } else { 5829 KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called 5830 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default); 5831 // Binds lock functions again to follow the transition between different 5832 // KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long 5833 // as we do not allow lock kind changes after making a call to any 5834 // user lock functions (true). 5835 #if KMP_USE_DYNAMIC_LOCK 5836 __kmp_init_dynamic_user_locks(); 5837 #else 5838 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind); 5839 #endif 5840 } 5841 5842 #if KMP_AFFINITY_SUPPORTED 5843 5844 if (!TCR_4(__kmp_init_middle)) { 5845 #if KMP_USE_HWLOC 5846 // Force using hwloc when either tiles or numa nodes requested within 5847 // KMP_HW_SUBSET and no other topology method is requested 5848 if ((__kmp_hws_node.num > 0 || __kmp_hws_tile.num > 0 || 5849 __kmp_affinity_gran == affinity_gran_tile) && 5850 (__kmp_affinity_top_method == affinity_top_method_default)) { 5851 __kmp_affinity_top_method = affinity_top_method_hwloc; 5852 } 5853 #endif 5854 // Determine if the machine/OS is actually capable of supporting 5855 // affinity. 5856 const char *var = "KMP_AFFINITY"; 5857 KMPAffinity::pick_api(); 5858 #if KMP_USE_HWLOC 5859 // If Hwloc topology discovery was requested but affinity was also disabled, 5860 // then tell user that Hwloc request is being ignored and use default 5861 // topology discovery method. 5862 if (__kmp_affinity_top_method == affinity_top_method_hwloc && 5863 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) { 5864 KMP_WARNING(AffIgnoringHwloc, var); 5865 __kmp_affinity_top_method = affinity_top_method_all; 5866 } 5867 #endif 5868 if (__kmp_affinity_type == affinity_disabled) { 5869 KMP_AFFINITY_DISABLE(); 5870 } else if (!KMP_AFFINITY_CAPABLE()) { 5871 __kmp_affinity_dispatch->determine_capable(var); 5872 if (!KMP_AFFINITY_CAPABLE()) { 5873 if (__kmp_affinity_verbose || 5874 (__kmp_affinity_warnings && 5875 (__kmp_affinity_type != affinity_default) && 5876 (__kmp_affinity_type != affinity_none) && 5877 (__kmp_affinity_type != affinity_disabled))) { 5878 KMP_WARNING(AffNotSupported, var); 5879 } 5880 __kmp_affinity_type = affinity_disabled; 5881 __kmp_affinity_respect_mask = 0; 5882 __kmp_affinity_gran = affinity_gran_fine; 5883 } 5884 } 5885 5886 if (__kmp_affinity_type == affinity_disabled) { 5887 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false; 5888 } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) { 5889 // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread. 5890 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread; 5891 } 5892 5893 if (KMP_AFFINITY_CAPABLE()) { 5894 5895 #if KMP_GROUP_AFFINITY 5896 // This checks to see if the initial affinity mask is equal 5897 // to a single windows processor group. If it is, then we do 5898 // not respect the initial affinity mask and instead, use the 5899 // entire machine. 5900 bool exactly_one_group = false; 5901 if (__kmp_num_proc_groups > 1) { 5902 int group; 5903 bool within_one_group; 5904 // Get the initial affinity mask and determine if it is 5905 // contained within a single group. 5906 kmp_affin_mask_t *init_mask; 5907 KMP_CPU_ALLOC(init_mask); 5908 __kmp_get_system_affinity(init_mask, TRUE); 5909 group = __kmp_get_proc_group(init_mask); 5910 within_one_group = (group >= 0); 5911 // If the initial affinity is within a single group, 5912 // then determine if it is equal to that single group. 5913 if (within_one_group) { 5914 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group); 5915 DWORD num_bits_in_mask = 0; 5916 for (int bit = init_mask->begin(); bit != init_mask->end(); 5917 bit = init_mask->next(bit)) 5918 num_bits_in_mask++; 5919 exactly_one_group = (num_bits_in_group == num_bits_in_mask); 5920 } 5921 KMP_CPU_FREE(init_mask); 5922 } 5923 5924 // Handle the Win 64 group affinity stuff if there are multiple 5925 // processor groups, or if the user requested it, and OMP 4.0 5926 // affinity is not in effect. 5927 if (((__kmp_num_proc_groups > 1) && 5928 (__kmp_affinity_type == affinity_default) && 5929 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default)) || 5930 (__kmp_affinity_top_method == affinity_top_method_group)) { 5931 if (__kmp_affinity_respect_mask == affinity_respect_mask_default && 5932 exactly_one_group) { 5933 __kmp_affinity_respect_mask = FALSE; 5934 } 5935 if (__kmp_affinity_type == affinity_default) { 5936 __kmp_affinity_type = affinity_compact; 5937 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel; 5938 } 5939 if (__kmp_affinity_top_method == affinity_top_method_default) { 5940 if (__kmp_affinity_gran == affinity_gran_default) { 5941 __kmp_affinity_top_method = affinity_top_method_group; 5942 __kmp_affinity_gran = affinity_gran_group; 5943 } else if (__kmp_affinity_gran == affinity_gran_group) { 5944 __kmp_affinity_top_method = affinity_top_method_group; 5945 } else { 5946 __kmp_affinity_top_method = affinity_top_method_all; 5947 } 5948 } else if (__kmp_affinity_top_method == affinity_top_method_group) { 5949 if (__kmp_affinity_gran == affinity_gran_default) { 5950 __kmp_affinity_gran = affinity_gran_group; 5951 } else if ((__kmp_affinity_gran != affinity_gran_group) && 5952 (__kmp_affinity_gran != affinity_gran_fine) && 5953 (__kmp_affinity_gran != affinity_gran_thread)) { 5954 const char *str = NULL; 5955 switch (__kmp_affinity_gran) { 5956 case affinity_gran_core: 5957 str = "core"; 5958 break; 5959 case affinity_gran_package: 5960 str = "package"; 5961 break; 5962 case affinity_gran_node: 5963 str = "node"; 5964 break; 5965 case affinity_gran_tile: 5966 str = "tile"; 5967 break; 5968 default: 5969 KMP_DEBUG_ASSERT(0); 5970 } 5971 KMP_WARNING(AffGranTopGroup, var, str); 5972 __kmp_affinity_gran = affinity_gran_fine; 5973 } 5974 } else { 5975 if (__kmp_affinity_gran == affinity_gran_default) { 5976 __kmp_affinity_gran = affinity_gran_core; 5977 } else if (__kmp_affinity_gran == affinity_gran_group) { 5978 const char *str = NULL; 5979 switch (__kmp_affinity_type) { 5980 case affinity_physical: 5981 str = "physical"; 5982 break; 5983 case affinity_logical: 5984 str = "logical"; 5985 break; 5986 case affinity_compact: 5987 str = "compact"; 5988 break; 5989 case affinity_scatter: 5990 str = "scatter"; 5991 break; 5992 case affinity_explicit: 5993 str = "explicit"; 5994 break; 5995 // No MIC on windows, so no affinity_balanced case 5996 default: 5997 KMP_DEBUG_ASSERT(0); 5998 } 5999 KMP_WARNING(AffGranGroupType, var, str); 6000 __kmp_affinity_gran = affinity_gran_core; 6001 } 6002 } 6003 } else 6004 6005 #endif /* KMP_GROUP_AFFINITY */ 6006 6007 { 6008 if (__kmp_affinity_respect_mask == affinity_respect_mask_default) { 6009 #if KMP_GROUP_AFFINITY 6010 if (__kmp_num_proc_groups > 1 && exactly_one_group) { 6011 __kmp_affinity_respect_mask = FALSE; 6012 } else 6013 #endif /* KMP_GROUP_AFFINITY */ 6014 { 6015 __kmp_affinity_respect_mask = TRUE; 6016 } 6017 } 6018 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) && 6019 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) { 6020 if (__kmp_affinity_type == affinity_default) { 6021 __kmp_affinity_type = affinity_compact; 6022 __kmp_affinity_dups = FALSE; 6023 } 6024 } else if (__kmp_affinity_type == affinity_default) { 6025 #if KMP_MIC_SUPPORTED 6026 if (__kmp_mic_type != non_mic) { 6027 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel; 6028 } else 6029 #endif 6030 { 6031 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false; 6032 } 6033 #if KMP_MIC_SUPPORTED 6034 if (__kmp_mic_type != non_mic) { 6035 __kmp_affinity_type = affinity_scatter; 6036 } else 6037 #endif 6038 { 6039 __kmp_affinity_type = affinity_none; 6040 } 6041 } 6042 if ((__kmp_affinity_gran == affinity_gran_default) && 6043 (__kmp_affinity_gran_levels < 0)) { 6044 #if KMP_MIC_SUPPORTED 6045 if (__kmp_mic_type != non_mic) { 6046 __kmp_affinity_gran = affinity_gran_fine; 6047 } else 6048 #endif 6049 { 6050 __kmp_affinity_gran = affinity_gran_core; 6051 } 6052 } 6053 if (__kmp_affinity_top_method == affinity_top_method_default) { 6054 __kmp_affinity_top_method = affinity_top_method_all; 6055 } 6056 } 6057 } 6058 6059 K_DIAG(1, ("__kmp_affinity_type == %d\n", __kmp_affinity_type)); 6060 K_DIAG(1, ("__kmp_affinity_compact == %d\n", __kmp_affinity_compact)); 6061 K_DIAG(1, ("__kmp_affinity_offset == %d\n", __kmp_affinity_offset)); 6062 K_DIAG(1, ("__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose)); 6063 K_DIAG(1, ("__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings)); 6064 K_DIAG(1, ("__kmp_affinity_respect_mask == %d\n", 6065 __kmp_affinity_respect_mask)); 6066 K_DIAG(1, ("__kmp_affinity_gran == %d\n", __kmp_affinity_gran)); 6067 6068 KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default); 6069 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default); 6070 K_DIAG(1, ("__kmp_nested_proc_bind.bind_types[0] == %d\n", 6071 __kmp_nested_proc_bind.bind_types[0])); 6072 } 6073 6074 #endif /* KMP_AFFINITY_SUPPORTED */ 6075 6076 if (__kmp_version) { 6077 __kmp_print_version_1(); 6078 } 6079 6080 // Post-initialization step: some env. vars need their value's further 6081 // processing 6082 if (string != NULL) { // kmp_set_defaults() was called 6083 __kmp_aux_env_initialize(&block); 6084 } 6085 6086 __kmp_env_blk_free(&block); 6087 6088 KMP_MB(); 6089 6090 } // __kmp_env_initialize 6091 6092 void __kmp_env_print() { 6093 6094 kmp_env_blk_t block; 6095 int i; 6096 kmp_str_buf_t buffer; 6097 6098 __kmp_stg_init(); 6099 __kmp_str_buf_init(&buffer); 6100 6101 __kmp_env_blk_init(&block, NULL); 6102 __kmp_env_blk_sort(&block); 6103 6104 // Print real environment values. 6105 __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings)); 6106 for (i = 0; i < block.count; ++i) { 6107 char const *name = block.vars[i].name; 6108 char const *value = block.vars[i].value; 6109 if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) || 6110 strncmp(name, "OMP_", 4) == 0 6111 #ifdef KMP_GOMP_COMPAT 6112 || strncmp(name, "GOMP_", 5) == 0 6113 #endif // KMP_GOMP_COMPAT 6114 ) { 6115 __kmp_str_buf_print(&buffer, " %s=%s\n", name, value); 6116 } 6117 } 6118 __kmp_str_buf_print(&buffer, "\n"); 6119 6120 // Print internal (effective) settings. 6121 __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings)); 6122 for (int i = 0; i < __kmp_stg_count; ++i) { 6123 if (__kmp_stg_table[i].print != NULL) { 6124 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name, 6125 __kmp_stg_table[i].data); 6126 } 6127 } 6128 6129 __kmp_printf("%s", buffer.str); 6130 6131 __kmp_env_blk_free(&block); 6132 __kmp_str_buf_free(&buffer); 6133 6134 __kmp_printf("\n"); 6135 6136 } // __kmp_env_print 6137 6138 void __kmp_env_print_2() { 6139 __kmp_display_env_impl(__kmp_display_env, __kmp_display_env_verbose); 6140 } // __kmp_env_print_2 6141 6142 void __kmp_display_env_impl(int display_env, int display_env_verbose) { 6143 kmp_env_blk_t block; 6144 kmp_str_buf_t buffer; 6145 6146 __kmp_env_format = 1; 6147 6148 __kmp_stg_init(); 6149 __kmp_str_buf_init(&buffer); 6150 6151 __kmp_env_blk_init(&block, NULL); 6152 __kmp_env_blk_sort(&block); 6153 6154 __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin)); 6155 __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version); 6156 6157 for (int i = 0; i < __kmp_stg_count; ++i) { 6158 if (__kmp_stg_table[i].print != NULL && 6159 ((display_env && strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) || 6160 display_env_verbose)) { 6161 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name, 6162 __kmp_stg_table[i].data); 6163 } 6164 } 6165 6166 __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd)); 6167 __kmp_str_buf_print(&buffer, "\n"); 6168 6169 __kmp_printf("%s", buffer.str); 6170 6171 __kmp_env_blk_free(&block); 6172 __kmp_str_buf_free(&buffer); 6173 6174 __kmp_printf("\n"); 6175 } 6176 6177 // end of file 6178