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