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