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