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