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