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