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