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