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