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