10b57cec5SDimitry Andric /*
20b57cec5SDimitry Andric * kmp_settings.cpp -- Initialize environment variables
30b57cec5SDimitry Andric */
40b57cec5SDimitry Andric
50b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
80b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
90b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric #include "kmp.h"
140b57cec5SDimitry Andric #include "kmp_affinity.h"
150b57cec5SDimitry Andric #include "kmp_atomic.h"
160b57cec5SDimitry Andric #if KMP_USE_HIER_SCHED
170b57cec5SDimitry Andric #include "kmp_dispatch_hier.h"
180b57cec5SDimitry Andric #endif
190b57cec5SDimitry Andric #include "kmp_environment.h"
200b57cec5SDimitry Andric #include "kmp_i18n.h"
210b57cec5SDimitry Andric #include "kmp_io.h"
220b57cec5SDimitry Andric #include "kmp_itt.h"
230b57cec5SDimitry Andric #include "kmp_lock.h"
240b57cec5SDimitry Andric #include "kmp_settings.h"
250b57cec5SDimitry Andric #include "kmp_str.h"
260b57cec5SDimitry Andric #include "kmp_wrapper_getpid.h"
270b57cec5SDimitry Andric #include <ctype.h> // toupper()
28fe6060f1SDimitry Andric #if OMPD_SUPPORT
29fe6060f1SDimitry Andric #include "ompd-specific.h"
30fe6060f1SDimitry Andric #endif
310b57cec5SDimitry Andric
320b57cec5SDimitry Andric static int __kmp_env_toPrint(char const *name, int flag);
330b57cec5SDimitry Andric
340b57cec5SDimitry Andric bool __kmp_env_format = 0; // 0 - old format; 1 - new format
350b57cec5SDimitry Andric
360b57cec5SDimitry Andric // -----------------------------------------------------------------------------
370b57cec5SDimitry Andric // Helper string functions. Subject to move to kmp_str.
380b57cec5SDimitry Andric
390b57cec5SDimitry Andric #ifdef USE_LOAD_BALANCE
__kmp_convert_to_double(char const * s)400b57cec5SDimitry Andric static double __kmp_convert_to_double(char const *s) {
410b57cec5SDimitry Andric double result;
420b57cec5SDimitry Andric
430b57cec5SDimitry Andric if (KMP_SSCANF(s, "%lf", &result) < 1) {
440b57cec5SDimitry Andric result = 0.0;
450b57cec5SDimitry Andric }
460b57cec5SDimitry Andric
470b57cec5SDimitry Andric return result;
480b57cec5SDimitry Andric }
490b57cec5SDimitry Andric #endif
500b57cec5SDimitry Andric
510b57cec5SDimitry Andric #ifdef KMP_DEBUG
__kmp_readstr_with_sentinel(char * dest,char const * src,size_t len,char sentinel)520b57cec5SDimitry Andric static unsigned int __kmp_readstr_with_sentinel(char *dest, char const *src,
530b57cec5SDimitry Andric size_t len, char sentinel) {
540b57cec5SDimitry Andric unsigned int i;
550b57cec5SDimitry Andric for (i = 0; i < len; i++) {
560b57cec5SDimitry Andric if ((*src == '\0') || (*src == sentinel)) {
570b57cec5SDimitry Andric break;
580b57cec5SDimitry Andric }
590b57cec5SDimitry Andric *(dest++) = *(src++);
600b57cec5SDimitry Andric }
610b57cec5SDimitry Andric *dest = '\0';
620b57cec5SDimitry Andric return i;
630b57cec5SDimitry Andric }
640b57cec5SDimitry Andric #endif
650b57cec5SDimitry Andric
__kmp_match_with_sentinel(char const * a,char const * b,size_t len,char sentinel)660b57cec5SDimitry Andric static int __kmp_match_with_sentinel(char const *a, char const *b, size_t len,
670b57cec5SDimitry Andric char sentinel) {
680b57cec5SDimitry Andric size_t l = 0;
690b57cec5SDimitry Andric
700b57cec5SDimitry Andric if (a == NULL)
710b57cec5SDimitry Andric a = "";
720b57cec5SDimitry Andric if (b == NULL)
730b57cec5SDimitry Andric b = "";
740b57cec5SDimitry Andric while (*a && *b && *b != sentinel) {
750b57cec5SDimitry Andric char ca = *a, cb = *b;
760b57cec5SDimitry Andric
770b57cec5SDimitry Andric if (ca >= 'a' && ca <= 'z')
780b57cec5SDimitry Andric ca -= 'a' - 'A';
790b57cec5SDimitry Andric if (cb >= 'a' && cb <= 'z')
800b57cec5SDimitry Andric cb -= 'a' - 'A';
810b57cec5SDimitry Andric if (ca != cb)
820b57cec5SDimitry Andric return FALSE;
830b57cec5SDimitry Andric ++l;
840b57cec5SDimitry Andric ++a;
850b57cec5SDimitry Andric ++b;
860b57cec5SDimitry Andric }
870b57cec5SDimitry Andric return l >= len;
880b57cec5SDimitry Andric }
890b57cec5SDimitry Andric
900b57cec5SDimitry Andric // Expected usage:
910b57cec5SDimitry Andric // token is the token to check for.
920b57cec5SDimitry Andric // buf is the string being parsed.
930b57cec5SDimitry Andric // *end returns the char after the end of the token.
940b57cec5SDimitry Andric // it is not modified unless a match occurs.
950b57cec5SDimitry Andric //
960b57cec5SDimitry Andric // Example 1:
970b57cec5SDimitry Andric //
980b57cec5SDimitry Andric // if (__kmp_match_str("token", buf, *end) {
990b57cec5SDimitry Andric // <do something>
1000b57cec5SDimitry Andric // buf = end;
1010b57cec5SDimitry Andric // }
1020b57cec5SDimitry Andric //
1030b57cec5SDimitry Andric // Example 2:
1040b57cec5SDimitry Andric //
1050b57cec5SDimitry Andric // if (__kmp_match_str("token", buf, *end) {
1060b57cec5SDimitry Andric // char *save = **end;
1070b57cec5SDimitry Andric // **end = sentinel;
1080b57cec5SDimitry Andric // <use any of the __kmp*_with_sentinel() functions>
1090b57cec5SDimitry Andric // **end = save;
1100b57cec5SDimitry Andric // buf = end;
1110b57cec5SDimitry Andric // }
1120b57cec5SDimitry Andric
__kmp_match_str(char const * token,char const * buf,const char ** end)1130b57cec5SDimitry Andric static int __kmp_match_str(char const *token, char const *buf,
1140b57cec5SDimitry Andric const char **end) {
1150b57cec5SDimitry Andric
1160b57cec5SDimitry Andric KMP_ASSERT(token != NULL);
1170b57cec5SDimitry Andric KMP_ASSERT(buf != NULL);
1180b57cec5SDimitry Andric KMP_ASSERT(end != NULL);
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andric while (*token && *buf) {
1210b57cec5SDimitry Andric char ct = *token, cb = *buf;
1220b57cec5SDimitry Andric
1230b57cec5SDimitry Andric if (ct >= 'a' && ct <= 'z')
1240b57cec5SDimitry Andric ct -= 'a' - 'A';
1250b57cec5SDimitry Andric if (cb >= 'a' && cb <= 'z')
1260b57cec5SDimitry Andric cb -= 'a' - 'A';
1270b57cec5SDimitry Andric if (ct != cb)
1280b57cec5SDimitry Andric return FALSE;
1290b57cec5SDimitry Andric ++token;
1300b57cec5SDimitry Andric ++buf;
1310b57cec5SDimitry Andric }
1320b57cec5SDimitry Andric if (*token) {
1330b57cec5SDimitry Andric return FALSE;
1340b57cec5SDimitry Andric }
1350b57cec5SDimitry Andric *end = buf;
1360b57cec5SDimitry Andric return TRUE;
1370b57cec5SDimitry Andric }
1380b57cec5SDimitry Andric
1390b57cec5SDimitry Andric #if KMP_OS_DARWIN
__kmp_round4k(size_t size)1400b57cec5SDimitry Andric static size_t __kmp_round4k(size_t size) {
1410b57cec5SDimitry Andric size_t _4k = 4 * 1024;
1420b57cec5SDimitry Andric if (size & (_4k - 1)) {
1430b57cec5SDimitry Andric size &= ~(_4k - 1);
1440b57cec5SDimitry Andric if (size <= KMP_SIZE_T_MAX - _4k) {
1450b57cec5SDimitry Andric size += _4k; // Round up if there is no overflow.
1460b57cec5SDimitry Andric }
1470b57cec5SDimitry Andric }
1480b57cec5SDimitry Andric return size;
1490b57cec5SDimitry Andric } // __kmp_round4k
1500b57cec5SDimitry Andric #endif
1510b57cec5SDimitry Andric
__kmp_strcasecmp_with_sentinel(char const * a,char const * b,char sentinel)1520b57cec5SDimitry Andric static int __kmp_strcasecmp_with_sentinel(char const *a, char const *b,
1530b57cec5SDimitry Andric char sentinel) {
1540b57cec5SDimitry Andric if (a == NULL)
1550b57cec5SDimitry Andric a = "";
1560b57cec5SDimitry Andric if (b == NULL)
1570b57cec5SDimitry Andric b = "";
1580b57cec5SDimitry Andric while (*a && *b && *b != sentinel) {
1590b57cec5SDimitry Andric char ca = *a, cb = *b;
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andric if (ca >= 'a' && ca <= 'z')
1620b57cec5SDimitry Andric ca -= 'a' - 'A';
1630b57cec5SDimitry Andric if (cb >= 'a' && cb <= 'z')
1640b57cec5SDimitry Andric cb -= 'a' - 'A';
1650b57cec5SDimitry Andric if (ca != cb)
1660b57cec5SDimitry Andric return (int)(unsigned char)*a - (int)(unsigned char)*b;
1670b57cec5SDimitry Andric ++a;
1680b57cec5SDimitry Andric ++b;
1690b57cec5SDimitry Andric }
170fe6060f1SDimitry Andric return *a ? (*b && *b != sentinel)
1710b57cec5SDimitry Andric ? (int)(unsigned char)*a - (int)(unsigned char)*b
1720b57cec5SDimitry Andric : 1
173fe6060f1SDimitry Andric : (*b && *b != sentinel) ? -1
174fe6060f1SDimitry Andric : 0;
1750b57cec5SDimitry Andric }
1760b57cec5SDimitry Andric
1770b57cec5SDimitry Andric // =============================================================================
1780b57cec5SDimitry Andric // Table structures and helper functions.
1790b57cec5SDimitry Andric
1800b57cec5SDimitry Andric typedef struct __kmp_setting kmp_setting_t;
1810b57cec5SDimitry Andric typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
1820b57cec5SDimitry Andric typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
1830b57cec5SDimitry Andric typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
1840b57cec5SDimitry Andric
1850b57cec5SDimitry Andric typedef void (*kmp_stg_parse_func_t)(char const *name, char const *value,
1860b57cec5SDimitry Andric void *data);
1870b57cec5SDimitry Andric typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer, char const *name,
1880b57cec5SDimitry Andric void *data);
1890b57cec5SDimitry Andric
1900b57cec5SDimitry Andric struct __kmp_setting {
1910b57cec5SDimitry Andric char const *name; // Name of setting (environment variable).
1920b57cec5SDimitry Andric kmp_stg_parse_func_t parse; // Parser function.
1930b57cec5SDimitry Andric kmp_stg_print_func_t print; // Print function.
1940b57cec5SDimitry Andric void *data; // Data passed to parser and printer.
1950b57cec5SDimitry Andric int set; // Variable set during this "session"
1960b57cec5SDimitry Andric // (__kmp_env_initialize() or kmp_set_defaults() call).
1970b57cec5SDimitry Andric int defined; // Variable set in any "session".
1980b57cec5SDimitry Andric }; // struct __kmp_setting
1990b57cec5SDimitry Andric
2000b57cec5SDimitry Andric struct __kmp_stg_ss_data {
2010b57cec5SDimitry Andric size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
2020b57cec5SDimitry Andric kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
2030b57cec5SDimitry Andric }; // struct __kmp_stg_ss_data
2040b57cec5SDimitry Andric
2050b57cec5SDimitry Andric struct __kmp_stg_wp_data {
2060b57cec5SDimitry Andric int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
2070b57cec5SDimitry Andric kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
2080b57cec5SDimitry Andric }; // struct __kmp_stg_wp_data
2090b57cec5SDimitry Andric
2100b57cec5SDimitry Andric struct __kmp_stg_fr_data {
2110b57cec5SDimitry Andric int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
2120b57cec5SDimitry Andric kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
2130b57cec5SDimitry Andric }; // struct __kmp_stg_fr_data
2140b57cec5SDimitry Andric
2150b57cec5SDimitry Andric static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
2160b57cec5SDimitry Andric char const *name, // Name of variable.
2170b57cec5SDimitry Andric char const *value, // Value of the variable.
2180b57cec5SDimitry Andric kmp_setting_t **rivals // List of rival settings (must include current one).
2190b57cec5SDimitry Andric );
2200b57cec5SDimitry Andric
22106c3fb27SDimitry Andric // Helper struct that trims heading/trailing white spaces
22206c3fb27SDimitry Andric struct kmp_trimmed_str_t {
22306c3fb27SDimitry Andric kmp_str_buf_t buf;
kmp_trimmed_str_tkmp_trimmed_str_t22406c3fb27SDimitry Andric kmp_trimmed_str_t(const char *str) {
22506c3fb27SDimitry Andric __kmp_str_buf_init(&buf);
22606c3fb27SDimitry Andric size_t len = KMP_STRLEN(str);
22706c3fb27SDimitry Andric if (len == 0)
22806c3fb27SDimitry Andric return;
22906c3fb27SDimitry Andric const char *begin = str;
23006c3fb27SDimitry Andric const char *end = str + KMP_STRLEN(str) - 1;
23106c3fb27SDimitry Andric SKIP_WS(begin);
23206c3fb27SDimitry Andric while (begin < end && *end == ' ')
23306c3fb27SDimitry Andric end--;
23406c3fb27SDimitry Andric __kmp_str_buf_cat(&buf, begin, end - begin + 1);
23506c3fb27SDimitry Andric }
~kmp_trimmed_str_tkmp_trimmed_str_t23606c3fb27SDimitry Andric ~kmp_trimmed_str_t() { __kmp_str_buf_free(&buf); }
getkmp_trimmed_str_t23706c3fb27SDimitry Andric const char *get() { return buf.str; }
23806c3fb27SDimitry Andric };
23906c3fb27SDimitry Andric
2400b57cec5SDimitry Andric // -----------------------------------------------------------------------------
2410b57cec5SDimitry Andric // Helper parse functions.
2420b57cec5SDimitry Andric
__kmp_stg_parse_bool(char const * name,char const * value,int * out)2430b57cec5SDimitry Andric static void __kmp_stg_parse_bool(char const *name, char const *value,
2440b57cec5SDimitry Andric int *out) {
2450b57cec5SDimitry Andric if (__kmp_str_match_true(value)) {
2460b57cec5SDimitry Andric *out = TRUE;
2470b57cec5SDimitry Andric } else if (__kmp_str_match_false(value)) {
2480b57cec5SDimitry Andric *out = FALSE;
2490b57cec5SDimitry Andric } else {
2500b57cec5SDimitry Andric __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
2510b57cec5SDimitry Andric KMP_HNT(ValidBoolValues), __kmp_msg_null);
2520b57cec5SDimitry Andric }
2530b57cec5SDimitry Andric } // __kmp_stg_parse_bool
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andric // placed here in order to use __kmp_round4k static function
__kmp_check_stksize(size_t * val)2560b57cec5SDimitry Andric void __kmp_check_stksize(size_t *val) {
2570b57cec5SDimitry Andric // if system stack size is too big then limit the size for worker threads
25874626c16SDimitry Andric #if KMP_OS_AIX
25974626c16SDimitry Andric if (*val > KMP_DEFAULT_STKSIZE * 2) // Use 2 times, 16 is too large for AIX.
26074626c16SDimitry Andric *val = KMP_DEFAULT_STKSIZE * 2;
26174626c16SDimitry Andric #else
2620b57cec5SDimitry Andric if (*val > KMP_DEFAULT_STKSIZE * 16) // just a heuristics...
2630b57cec5SDimitry Andric *val = KMP_DEFAULT_STKSIZE * 16;
26474626c16SDimitry Andric #endif
265349cc55cSDimitry Andric if (*val < __kmp_sys_min_stksize)
266349cc55cSDimitry Andric *val = __kmp_sys_min_stksize;
2670b57cec5SDimitry Andric if (*val > KMP_MAX_STKSIZE)
2680b57cec5SDimitry Andric *val = KMP_MAX_STKSIZE; // dead code currently, but may work in future
2690b57cec5SDimitry Andric #if KMP_OS_DARWIN
2700b57cec5SDimitry Andric *val = __kmp_round4k(*val);
2710b57cec5SDimitry Andric #endif // KMP_OS_DARWIN
2720b57cec5SDimitry Andric }
2730b57cec5SDimitry Andric
__kmp_stg_parse_size(char const * name,char const * value,size_t size_min,size_t size_max,int * is_specified,size_t * out,size_t factor)2740b57cec5SDimitry Andric static void __kmp_stg_parse_size(char const *name, char const *value,
2750b57cec5SDimitry Andric size_t size_min, size_t size_max,
2760b57cec5SDimitry Andric int *is_specified, size_t *out,
2770b57cec5SDimitry Andric size_t factor) {
2780b57cec5SDimitry Andric char const *msg = NULL;
2790b57cec5SDimitry Andric #if KMP_OS_DARWIN
2800b57cec5SDimitry Andric size_min = __kmp_round4k(size_min);
2810b57cec5SDimitry Andric size_max = __kmp_round4k(size_max);
2820b57cec5SDimitry Andric #endif // KMP_OS_DARWIN
2830b57cec5SDimitry Andric if (value) {
2840b57cec5SDimitry Andric if (is_specified != NULL) {
2850b57cec5SDimitry Andric *is_specified = 1;
2860b57cec5SDimitry Andric }
2870b57cec5SDimitry Andric __kmp_str_to_size(value, out, factor, &msg);
2880b57cec5SDimitry Andric if (msg == NULL) {
2890b57cec5SDimitry Andric if (*out > size_max) {
2900b57cec5SDimitry Andric *out = size_max;
2910b57cec5SDimitry Andric msg = KMP_I18N_STR(ValueTooLarge);
2920b57cec5SDimitry Andric } else if (*out < size_min) {
2930b57cec5SDimitry Andric *out = size_min;
2940b57cec5SDimitry Andric msg = KMP_I18N_STR(ValueTooSmall);
2950b57cec5SDimitry Andric } else {
2960b57cec5SDimitry Andric #if KMP_OS_DARWIN
2970b57cec5SDimitry Andric size_t round4k = __kmp_round4k(*out);
2980b57cec5SDimitry Andric if (*out != round4k) {
2990b57cec5SDimitry Andric *out = round4k;
3000b57cec5SDimitry Andric msg = KMP_I18N_STR(NotMultiple4K);
3010b57cec5SDimitry Andric }
3020b57cec5SDimitry Andric #endif
3030b57cec5SDimitry Andric }
3040b57cec5SDimitry Andric } else {
3050b57cec5SDimitry Andric // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to
3060b57cec5SDimitry Andric // size_max silently.
3070b57cec5SDimitry Andric if (*out < size_min) {
3080b57cec5SDimitry Andric *out = size_max;
3090b57cec5SDimitry Andric } else if (*out > size_max) {
3100b57cec5SDimitry Andric *out = size_max;
3110b57cec5SDimitry Andric }
3120b57cec5SDimitry Andric }
3130b57cec5SDimitry Andric if (msg != NULL) {
3140b57cec5SDimitry Andric // Message is not empty. Print warning.
3150b57cec5SDimitry Andric kmp_str_buf_t buf;
3160b57cec5SDimitry Andric __kmp_str_buf_init(&buf);
3170b57cec5SDimitry Andric __kmp_str_buf_print_size(&buf, *out);
3180b57cec5SDimitry Andric KMP_WARNING(ParseSizeIntWarn, name, value, msg);
3190b57cec5SDimitry Andric KMP_INFORM(Using_str_Value, name, buf.str);
3200b57cec5SDimitry Andric __kmp_str_buf_free(&buf);
3210b57cec5SDimitry Andric }
3220b57cec5SDimitry Andric }
3230b57cec5SDimitry Andric } // __kmp_stg_parse_size
3240b57cec5SDimitry Andric
__kmp_stg_parse_str(char const * name,char const * value,char ** out)3250b57cec5SDimitry Andric static void __kmp_stg_parse_str(char const *name, char const *value,
3260b57cec5SDimitry Andric char **out) {
3270b57cec5SDimitry Andric __kmp_str_free(out);
3280b57cec5SDimitry Andric *out = __kmp_str_format("%s", value);
3290b57cec5SDimitry Andric } // __kmp_stg_parse_str
3300b57cec5SDimitry Andric
__kmp_stg_parse_int(char const * name,char const * value,int min,int max,int * out)3310b57cec5SDimitry Andric static void __kmp_stg_parse_int(
3320b57cec5SDimitry Andric char const
3330b57cec5SDimitry Andric *name, // I: Name of environment variable (used in warning messages).
3340b57cec5SDimitry Andric char const *value, // I: Value of environment variable to parse.
3355ffd83dbSDimitry Andric int min, // I: Minimum allowed value.
3360b57cec5SDimitry Andric int max, // I: Maximum allowed value.
3370b57cec5SDimitry Andric int *out // O: Output (parsed) value.
3380b57cec5SDimitry Andric ) {
3390b57cec5SDimitry Andric char const *msg = NULL;
3400b57cec5SDimitry Andric kmp_uint64 uint = *out;
3410b57cec5SDimitry Andric __kmp_str_to_uint(value, &uint, &msg);
3420b57cec5SDimitry Andric if (msg == NULL) {
3430b57cec5SDimitry Andric if (uint < (unsigned int)min) {
3440b57cec5SDimitry Andric msg = KMP_I18N_STR(ValueTooSmall);
3450b57cec5SDimitry Andric uint = min;
3460b57cec5SDimitry Andric } else if (uint > (unsigned int)max) {
3470b57cec5SDimitry Andric msg = KMP_I18N_STR(ValueTooLarge);
3480b57cec5SDimitry Andric uint = max;
3490b57cec5SDimitry Andric }
3500b57cec5SDimitry Andric } else {
3510b57cec5SDimitry Andric // If overflow occurred msg contains error message and uint is very big. Cut
3520b57cec5SDimitry Andric // tmp it to INT_MAX.
3530b57cec5SDimitry Andric if (uint < (unsigned int)min) {
3540b57cec5SDimitry Andric uint = min;
3550b57cec5SDimitry Andric } else if (uint > (unsigned int)max) {
3560b57cec5SDimitry Andric uint = max;
3570b57cec5SDimitry Andric }
3580b57cec5SDimitry Andric }
3590b57cec5SDimitry Andric if (msg != NULL) {
3600b57cec5SDimitry Andric // Message is not empty. Print warning.
3610b57cec5SDimitry Andric kmp_str_buf_t buf;
3620b57cec5SDimitry Andric KMP_WARNING(ParseSizeIntWarn, name, value, msg);
3630b57cec5SDimitry Andric __kmp_str_buf_init(&buf);
3640b57cec5SDimitry Andric __kmp_str_buf_print(&buf, "%" KMP_UINT64_SPEC "", uint);
3650b57cec5SDimitry Andric KMP_INFORM(Using_uint64_Value, name, buf.str);
3660b57cec5SDimitry Andric __kmp_str_buf_free(&buf);
3670b57cec5SDimitry Andric }
368e8d8bef9SDimitry Andric __kmp_type_convert(uint, out);
3690b57cec5SDimitry Andric } // __kmp_stg_parse_int
3700b57cec5SDimitry Andric
3710b57cec5SDimitry Andric #if KMP_DEBUG_ADAPTIVE_LOCKS
__kmp_stg_parse_file(char const * name,char const * value,const char * suffix,char ** out)3720b57cec5SDimitry Andric static void __kmp_stg_parse_file(char const *name, char const *value,
3730b57cec5SDimitry Andric const char *suffix, char **out) {
3740b57cec5SDimitry Andric char buffer[256];
3750b57cec5SDimitry Andric char *t;
3760b57cec5SDimitry Andric int hasSuffix;
3770b57cec5SDimitry Andric __kmp_str_free(out);
3780b57cec5SDimitry Andric t = (char *)strrchr(value, '.');
3790b57cec5SDimitry Andric hasSuffix = t && __kmp_str_eqf(t, suffix);
3800b57cec5SDimitry Andric t = __kmp_str_format("%s%s", value, hasSuffix ? "" : suffix);
3810b57cec5SDimitry Andric __kmp_expand_file_name(buffer, sizeof(buffer), t);
3820b57cec5SDimitry Andric __kmp_str_free(&t);
3830b57cec5SDimitry Andric *out = __kmp_str_format("%s", buffer);
3840b57cec5SDimitry Andric } // __kmp_stg_parse_file
3850b57cec5SDimitry Andric #endif
3860b57cec5SDimitry Andric
3870b57cec5SDimitry Andric #ifdef KMP_DEBUG
3880b57cec5SDimitry Andric static char *par_range_to_print = NULL;
3890b57cec5SDimitry Andric
__kmp_stg_parse_par_range(char const * name,char const * value,int * out_range,char * out_routine,char * out_file,int * out_lb,int * out_ub)3900b57cec5SDimitry Andric static void __kmp_stg_parse_par_range(char const *name, char const *value,
3910b57cec5SDimitry Andric int *out_range, char *out_routine,
3920b57cec5SDimitry Andric char *out_file, int *out_lb,
3930b57cec5SDimitry Andric int *out_ub) {
394349cc55cSDimitry Andric const char *par_range_value;
3950b57cec5SDimitry Andric size_t len = KMP_STRLEN(value) + 1;
3960b57cec5SDimitry Andric par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
3970b57cec5SDimitry Andric KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
3980b57cec5SDimitry Andric __kmp_par_range = +1;
3990b57cec5SDimitry Andric __kmp_par_range_lb = 0;
4000b57cec5SDimitry Andric __kmp_par_range_ub = INT_MAX;
4010b57cec5SDimitry Andric for (;;) {
4020b57cec5SDimitry Andric unsigned int len;
403349cc55cSDimitry Andric if (!value || *value == '\0') {
4040b57cec5SDimitry Andric break;
4050b57cec5SDimitry Andric }
4060b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
407349cc55cSDimitry Andric par_range_value = strchr(value, '=') + 1;
408349cc55cSDimitry Andric if (!par_range_value)
409349cc55cSDimitry Andric goto par_range_error;
410349cc55cSDimitry Andric value = par_range_value;
4110b57cec5SDimitry Andric len = __kmp_readstr_with_sentinel(out_routine, value,
4120b57cec5SDimitry Andric KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
4130b57cec5SDimitry Andric if (len == 0) {
4140b57cec5SDimitry Andric goto par_range_error;
4150b57cec5SDimitry Andric }
4160b57cec5SDimitry Andric value = strchr(value, ',');
4170b57cec5SDimitry Andric if (value != NULL) {
4180b57cec5SDimitry Andric value++;
4190b57cec5SDimitry Andric }
4200b57cec5SDimitry Andric continue;
4210b57cec5SDimitry Andric }
4220b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
423349cc55cSDimitry Andric par_range_value = strchr(value, '=') + 1;
424349cc55cSDimitry Andric if (!par_range_value)
425349cc55cSDimitry Andric goto par_range_error;
426349cc55cSDimitry Andric value = par_range_value;
4270b57cec5SDimitry Andric len = __kmp_readstr_with_sentinel(out_file, value,
4280b57cec5SDimitry Andric KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
4290b57cec5SDimitry Andric if (len == 0) {
4300b57cec5SDimitry Andric goto par_range_error;
4310b57cec5SDimitry Andric }
4320b57cec5SDimitry Andric value = strchr(value, ',');
4330b57cec5SDimitry Andric if (value != NULL) {
4340b57cec5SDimitry Andric value++;
4350b57cec5SDimitry Andric }
4360b57cec5SDimitry Andric continue;
4370b57cec5SDimitry Andric }
4380b57cec5SDimitry Andric if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
4390b57cec5SDimitry Andric (!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
440349cc55cSDimitry Andric par_range_value = strchr(value, '=') + 1;
441349cc55cSDimitry Andric if (!par_range_value)
442349cc55cSDimitry Andric goto par_range_error;
443349cc55cSDimitry Andric value = par_range_value;
4440b57cec5SDimitry Andric if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
4450b57cec5SDimitry Andric goto par_range_error;
4460b57cec5SDimitry Andric }
4470b57cec5SDimitry Andric *out_range = +1;
4480b57cec5SDimitry Andric value = strchr(value, ',');
4490b57cec5SDimitry Andric if (value != NULL) {
4500b57cec5SDimitry Andric value++;
4510b57cec5SDimitry Andric }
4520b57cec5SDimitry Andric continue;
4530b57cec5SDimitry Andric }
4540b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("excl_range", value, '=')) {
455349cc55cSDimitry Andric par_range_value = strchr(value, '=') + 1;
456349cc55cSDimitry Andric if (!par_range_value)
457349cc55cSDimitry Andric goto par_range_error;
458349cc55cSDimitry Andric value = par_range_value;
4590b57cec5SDimitry Andric if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
4600b57cec5SDimitry Andric goto par_range_error;
4610b57cec5SDimitry Andric }
4620b57cec5SDimitry Andric *out_range = -1;
4630b57cec5SDimitry Andric value = strchr(value, ',');
4640b57cec5SDimitry Andric if (value != NULL) {
4650b57cec5SDimitry Andric value++;
4660b57cec5SDimitry Andric }
4670b57cec5SDimitry Andric continue;
4680b57cec5SDimitry Andric }
4690b57cec5SDimitry Andric par_range_error:
4700b57cec5SDimitry Andric KMP_WARNING(ParRangeSyntax, name);
4710b57cec5SDimitry Andric __kmp_par_range = 0;
4720b57cec5SDimitry Andric break;
4730b57cec5SDimitry Andric }
4740b57cec5SDimitry Andric } // __kmp_stg_parse_par_range
4750b57cec5SDimitry Andric #endif
4760b57cec5SDimitry Andric
__kmp_initial_threads_capacity(int req_nproc)4770b57cec5SDimitry Andric int __kmp_initial_threads_capacity(int req_nproc) {
4780b57cec5SDimitry Andric int nth = 32;
4790b57cec5SDimitry Andric
4800b57cec5SDimitry Andric /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
4810b57cec5SDimitry Andric * __kmp_max_nth) */
4820b57cec5SDimitry Andric if (nth < (4 * req_nproc))
4830b57cec5SDimitry Andric nth = (4 * req_nproc);
4840b57cec5SDimitry Andric if (nth < (4 * __kmp_xproc))
4850b57cec5SDimitry Andric nth = (4 * __kmp_xproc);
4860b57cec5SDimitry Andric
487e8d8bef9SDimitry Andric // If hidden helper task is enabled, we initialize the thread capacity with
488d409305fSDimitry Andric // extra __kmp_hidden_helper_threads_num.
489d409305fSDimitry Andric if (__kmp_enable_hidden_helper) {
490e8d8bef9SDimitry Andric nth += __kmp_hidden_helper_threads_num;
491d409305fSDimitry Andric }
492e8d8bef9SDimitry Andric
4930b57cec5SDimitry Andric if (nth > __kmp_max_nth)
4940b57cec5SDimitry Andric nth = __kmp_max_nth;
4950b57cec5SDimitry Andric
4960b57cec5SDimitry Andric return nth;
4970b57cec5SDimitry Andric }
4980b57cec5SDimitry Andric
__kmp_default_tp_capacity(int req_nproc,int max_nth,int all_threads_specified)4990b57cec5SDimitry Andric int __kmp_default_tp_capacity(int req_nproc, int max_nth,
5000b57cec5SDimitry Andric int all_threads_specified) {
5010b57cec5SDimitry Andric int nth = 128;
5020b57cec5SDimitry Andric
5030b57cec5SDimitry Andric if (all_threads_specified)
5040b57cec5SDimitry Andric return max_nth;
5050b57cec5SDimitry Andric /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
5060b57cec5SDimitry Andric * __kmp_max_nth ) */
5070b57cec5SDimitry Andric if (nth < (4 * req_nproc))
5080b57cec5SDimitry Andric nth = (4 * req_nproc);
5090b57cec5SDimitry Andric if (nth < (4 * __kmp_xproc))
5100b57cec5SDimitry Andric nth = (4 * __kmp_xproc);
5110b57cec5SDimitry Andric
5120b57cec5SDimitry Andric if (nth > __kmp_max_nth)
5130b57cec5SDimitry Andric nth = __kmp_max_nth;
5140b57cec5SDimitry Andric
5150b57cec5SDimitry Andric return nth;
5160b57cec5SDimitry Andric }
5170b57cec5SDimitry Andric
5180b57cec5SDimitry Andric // -----------------------------------------------------------------------------
5190b57cec5SDimitry Andric // Helper print functions.
5200b57cec5SDimitry Andric
__kmp_stg_print_bool(kmp_str_buf_t * buffer,char const * name,int value)5210b57cec5SDimitry Andric static void __kmp_stg_print_bool(kmp_str_buf_t *buffer, char const *name,
5220b57cec5SDimitry Andric int value) {
5230b57cec5SDimitry Andric if (__kmp_env_format) {
5240b57cec5SDimitry Andric KMP_STR_BUF_PRINT_BOOL;
5250b57cec5SDimitry Andric } else {
5260b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s=%s\n", name, value ? "true" : "false");
5270b57cec5SDimitry Andric }
5280b57cec5SDimitry Andric } // __kmp_stg_print_bool
5290b57cec5SDimitry Andric
__kmp_stg_print_int(kmp_str_buf_t * buffer,char const * name,int value)5300b57cec5SDimitry Andric static void __kmp_stg_print_int(kmp_str_buf_t *buffer, char const *name,
5310b57cec5SDimitry Andric int value) {
5320b57cec5SDimitry Andric if (__kmp_env_format) {
5330b57cec5SDimitry Andric KMP_STR_BUF_PRINT_INT;
5340b57cec5SDimitry Andric } else {
5350b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s=%d\n", name, value);
5360b57cec5SDimitry Andric }
5370b57cec5SDimitry Andric } // __kmp_stg_print_int
5380b57cec5SDimitry Andric
__kmp_stg_print_uint64(kmp_str_buf_t * buffer,char const * name,kmp_uint64 value)5390b57cec5SDimitry Andric static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer, char const *name,
5400b57cec5SDimitry Andric kmp_uint64 value) {
5410b57cec5SDimitry Andric if (__kmp_env_format) {
5420b57cec5SDimitry Andric KMP_STR_BUF_PRINT_UINT64;
5430b57cec5SDimitry Andric } else {
5440b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value);
5450b57cec5SDimitry Andric }
5460b57cec5SDimitry Andric } // __kmp_stg_print_uint64
5470b57cec5SDimitry Andric
__kmp_stg_print_str(kmp_str_buf_t * buffer,char const * name,char const * value)5480b57cec5SDimitry Andric static void __kmp_stg_print_str(kmp_str_buf_t *buffer, char const *name,
5490b57cec5SDimitry Andric char const *value) {
5500b57cec5SDimitry Andric if (__kmp_env_format) {
5510b57cec5SDimitry Andric KMP_STR_BUF_PRINT_STR;
5520b57cec5SDimitry Andric } else {
5530b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s=%s\n", name, value);
5540b57cec5SDimitry Andric }
5550b57cec5SDimitry Andric } // __kmp_stg_print_str
5560b57cec5SDimitry Andric
__kmp_stg_print_size(kmp_str_buf_t * buffer,char const * name,size_t value)5570b57cec5SDimitry Andric static void __kmp_stg_print_size(kmp_str_buf_t *buffer, char const *name,
5580b57cec5SDimitry Andric size_t value) {
5590b57cec5SDimitry Andric if (__kmp_env_format) {
5600b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(name);
5610b57cec5SDimitry Andric __kmp_str_buf_print_size(buffer, value);
5620b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "'\n");
5630b57cec5SDimitry Andric } else {
5640b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s=", name);
5650b57cec5SDimitry Andric __kmp_str_buf_print_size(buffer, value);
5660b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "\n");
5670b57cec5SDimitry Andric return;
5680b57cec5SDimitry Andric }
5690b57cec5SDimitry Andric } // __kmp_stg_print_size
5700b57cec5SDimitry Andric
5710b57cec5SDimitry Andric // =============================================================================
5720b57cec5SDimitry Andric // Parse and print functions.
5730b57cec5SDimitry Andric
5740b57cec5SDimitry Andric // -----------------------------------------------------------------------------
5750b57cec5SDimitry Andric // KMP_DEVICE_THREAD_LIMIT, KMP_ALL_THREADS
5760b57cec5SDimitry Andric
__kmp_stg_parse_device_thread_limit(char const * name,char const * value,void * data)5770b57cec5SDimitry Andric static void __kmp_stg_parse_device_thread_limit(char const *name,
5780b57cec5SDimitry Andric char const *value, void *data) {
5790b57cec5SDimitry Andric kmp_setting_t **rivals = (kmp_setting_t **)data;
5800b57cec5SDimitry Andric int rc;
5810b57cec5SDimitry Andric if (strcmp(name, "KMP_ALL_THREADS") == 0) {
5820b57cec5SDimitry Andric KMP_INFORM(EnvVarDeprecated, name, "KMP_DEVICE_THREAD_LIMIT");
5830b57cec5SDimitry Andric }
5840b57cec5SDimitry Andric rc = __kmp_stg_check_rivals(name, value, rivals);
5850b57cec5SDimitry Andric if (rc) {
5860b57cec5SDimitry Andric return;
5870b57cec5SDimitry Andric }
5880b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
5890b57cec5SDimitry Andric __kmp_max_nth = __kmp_xproc;
5900b57cec5SDimitry Andric __kmp_allThreadsSpecified = 1;
5910b57cec5SDimitry Andric } else {
5920b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
5930b57cec5SDimitry Andric __kmp_allThreadsSpecified = 0;
5940b57cec5SDimitry Andric }
5950b57cec5SDimitry Andric K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));
5960b57cec5SDimitry Andric
5970b57cec5SDimitry Andric } // __kmp_stg_parse_device_thread_limit
5980b57cec5SDimitry Andric
__kmp_stg_print_device_thread_limit(kmp_str_buf_t * buffer,char const * name,void * data)5990b57cec5SDimitry Andric static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
6000b57cec5SDimitry Andric char const *name, void *data) {
6010b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_max_nth);
6020b57cec5SDimitry Andric } // __kmp_stg_print_device_thread_limit
6030b57cec5SDimitry Andric
6040b57cec5SDimitry Andric // -----------------------------------------------------------------------------
6050b57cec5SDimitry Andric // OMP_THREAD_LIMIT
__kmp_stg_parse_thread_limit(char const * name,char const * value,void * data)6060b57cec5SDimitry Andric static void __kmp_stg_parse_thread_limit(char const *name, char const *value,
6070b57cec5SDimitry Andric void *data) {
6080b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
6090b57cec5SDimitry Andric K_DIAG(1, ("__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));
6100b57cec5SDimitry Andric
6110b57cec5SDimitry Andric } // __kmp_stg_parse_thread_limit
6120b57cec5SDimitry Andric
__kmp_stg_print_thread_limit(kmp_str_buf_t * buffer,char const * name,void * data)6130b57cec5SDimitry Andric static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
6140b57cec5SDimitry Andric char const *name, void *data) {
6150b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
6160b57cec5SDimitry Andric } // __kmp_stg_print_thread_limit
6170b57cec5SDimitry Andric
6180b57cec5SDimitry Andric // -----------------------------------------------------------------------------
619fe6060f1SDimitry Andric // OMP_NUM_TEAMS
__kmp_stg_parse_nteams(char const * name,char const * value,void * data)620fe6060f1SDimitry Andric static void __kmp_stg_parse_nteams(char const *name, char const *value,
621fe6060f1SDimitry Andric void *data) {
622fe6060f1SDimitry Andric __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_nteams);
623fe6060f1SDimitry Andric K_DIAG(1, ("__kmp_nteams == %d\n", __kmp_nteams));
624fe6060f1SDimitry Andric } // __kmp_stg_parse_nteams
625fe6060f1SDimitry Andric
__kmp_stg_print_nteams(kmp_str_buf_t * buffer,char const * name,void * data)626fe6060f1SDimitry Andric static void __kmp_stg_print_nteams(kmp_str_buf_t *buffer, char const *name,
627fe6060f1SDimitry Andric void *data) {
628fe6060f1SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_nteams);
629fe6060f1SDimitry Andric } // __kmp_stg_print_nteams
630fe6060f1SDimitry Andric
631fe6060f1SDimitry Andric // -----------------------------------------------------------------------------
632fe6060f1SDimitry Andric // OMP_TEAMS_THREAD_LIMIT
__kmp_stg_parse_teams_th_limit(char const * name,char const * value,void * data)633fe6060f1SDimitry Andric static void __kmp_stg_parse_teams_th_limit(char const *name, char const *value,
634fe6060f1SDimitry Andric void *data) {
635fe6060f1SDimitry Andric __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth,
636fe6060f1SDimitry Andric &__kmp_teams_thread_limit);
637fe6060f1SDimitry Andric K_DIAG(1, ("__kmp_teams_thread_limit == %d\n", __kmp_teams_thread_limit));
638fe6060f1SDimitry Andric } // __kmp_stg_parse_teams_th_limit
639fe6060f1SDimitry Andric
__kmp_stg_print_teams_th_limit(kmp_str_buf_t * buffer,char const * name,void * data)640fe6060f1SDimitry Andric static void __kmp_stg_print_teams_th_limit(kmp_str_buf_t *buffer,
641fe6060f1SDimitry Andric char const *name, void *data) {
642fe6060f1SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_teams_thread_limit);
643fe6060f1SDimitry Andric } // __kmp_stg_print_teams_th_limit
644fe6060f1SDimitry Andric
645fe6060f1SDimitry Andric // -----------------------------------------------------------------------------
6460b57cec5SDimitry Andric // KMP_TEAMS_THREAD_LIMIT
__kmp_stg_parse_teams_thread_limit(char const * name,char const * value,void * data)6470b57cec5SDimitry Andric static void __kmp_stg_parse_teams_thread_limit(char const *name,
6480b57cec5SDimitry Andric char const *value, void *data) {
6490b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
6500b57cec5SDimitry Andric } // __kmp_stg_teams_thread_limit
6510b57cec5SDimitry Andric
__kmp_stg_print_teams_thread_limit(kmp_str_buf_t * buffer,char const * name,void * data)6520b57cec5SDimitry Andric static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
6530b57cec5SDimitry Andric char const *name, void *data) {
6540b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
6550b57cec5SDimitry Andric } // __kmp_stg_print_teams_thread_limit
6560b57cec5SDimitry Andric
6570b57cec5SDimitry Andric // -----------------------------------------------------------------------------
6580b57cec5SDimitry Andric // KMP_USE_YIELD
__kmp_stg_parse_use_yield(char const * name,char const * value,void * data)6590b57cec5SDimitry Andric static void __kmp_stg_parse_use_yield(char const *name, char const *value,
6600b57cec5SDimitry Andric void *data) {
6610b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, 2, &__kmp_use_yield);
6620b57cec5SDimitry Andric __kmp_use_yield_exp_set = 1;
6630b57cec5SDimitry Andric } // __kmp_stg_parse_use_yield
6640b57cec5SDimitry Andric
__kmp_stg_print_use_yield(kmp_str_buf_t * buffer,char const * name,void * data)6650b57cec5SDimitry Andric static void __kmp_stg_print_use_yield(kmp_str_buf_t *buffer, char const *name,
6660b57cec5SDimitry Andric void *data) {
6670b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_use_yield);
6680b57cec5SDimitry Andric } // __kmp_stg_print_use_yield
6690b57cec5SDimitry Andric
6700b57cec5SDimitry Andric // -----------------------------------------------------------------------------
6710b57cec5SDimitry Andric // KMP_BLOCKTIME
6720b57cec5SDimitry Andric
__kmp_stg_parse_blocktime(char const * name,char const * value,void * data)6730b57cec5SDimitry Andric static void __kmp_stg_parse_blocktime(char const *name, char const *value,
6740b57cec5SDimitry Andric void *data) {
6755f757f3fSDimitry Andric const char *buf = value;
6765f757f3fSDimitry Andric const char *next;
6775f757f3fSDimitry Andric const int ms_mult = 1000;
6785f757f3fSDimitry Andric int multiplier = 1;
6795f757f3fSDimitry Andric int num;
6805f757f3fSDimitry Andric
6815f757f3fSDimitry Andric // Read integer blocktime value
6825f757f3fSDimitry Andric SKIP_WS(buf);
6835f757f3fSDimitry Andric if ((*buf >= '0') && (*buf <= '9')) {
6845f757f3fSDimitry Andric next = buf;
6855f757f3fSDimitry Andric SKIP_DIGITS(next);
6865f757f3fSDimitry Andric num = __kmp_basic_str_to_int(buf);
6875f757f3fSDimitry Andric KMP_ASSERT(num >= 0);
6885f757f3fSDimitry Andric buf = next;
6895f757f3fSDimitry Andric SKIP_WS(buf);
6905f757f3fSDimitry Andric } else {
6915f757f3fSDimitry Andric num = -1;
6925f757f3fSDimitry Andric }
6935f757f3fSDimitry Andric
6945f757f3fSDimitry Andric // Read units: note that __kmp_dflt_blocktime units is now us
6955f757f3fSDimitry Andric next = buf;
6965f757f3fSDimitry Andric if (*buf == '\0' || __kmp_match_str("ms", buf, &next)) {
6975f757f3fSDimitry Andric // units are in ms; convert
6985f757f3fSDimitry Andric __kmp_dflt_blocktime = ms_mult * num;
6995f757f3fSDimitry Andric __kmp_blocktime_units = 'm';
7005f757f3fSDimitry Andric multiplier = ms_mult;
7015f757f3fSDimitry Andric } else if (__kmp_match_str("us", buf, &next)) {
7025f757f3fSDimitry Andric // units are in us
7035f757f3fSDimitry Andric __kmp_dflt_blocktime = num;
7045f757f3fSDimitry Andric __kmp_blocktime_units = 'u';
7055f757f3fSDimitry Andric } else if (__kmp_match_str("infinite", buf, &next) ||
7065f757f3fSDimitry Andric __kmp_match_str("infinity", buf, &next)) {
7075f757f3fSDimitry Andric // units are in ms
7085f757f3fSDimitry Andric __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
7095f757f3fSDimitry Andric __kmp_blocktime_units = 'm';
7105f757f3fSDimitry Andric multiplier = ms_mult;
7115f757f3fSDimitry Andric } else {
7125f757f3fSDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
7135f757f3fSDimitry Andric // default units are in ms
7145f757f3fSDimitry Andric __kmp_dflt_blocktime = ms_mult * num;
7155f757f3fSDimitry Andric __kmp_blocktime_units = 'm';
7165f757f3fSDimitry Andric multiplier = ms_mult;
7175f757f3fSDimitry Andric }
7185f757f3fSDimitry Andric
7195f757f3fSDimitry Andric if (num < 0 && __kmp_dflt_blocktime < 0) { // num out of range
7205f757f3fSDimitry Andric __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME; // now in us
7210b57cec5SDimitry Andric __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
7220b57cec5SDimitry Andric __kmp_msg_null);
7235f757f3fSDimitry Andric // Inform in appropriate units
7245f757f3fSDimitry Andric KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime / multiplier);
7250b57cec5SDimitry Andric __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
7265f757f3fSDimitry Andric } else if (num > 0 && __kmp_dflt_blocktime < 0) { // overflow
7275f757f3fSDimitry Andric __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
7285f757f3fSDimitry Andric __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value), __kmp_msg_null);
7295f757f3fSDimitry Andric KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime / multiplier);
7305f757f3fSDimitry Andric __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
7310b57cec5SDimitry Andric } else {
7320b57cec5SDimitry Andric if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
7330b57cec5SDimitry Andric __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
7340b57cec5SDimitry Andric __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
7350b57cec5SDimitry Andric __kmp_msg_null);
7365f757f3fSDimitry Andric KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime / multiplier);
7370b57cec5SDimitry Andric } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
7380b57cec5SDimitry Andric __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
7390b57cec5SDimitry Andric __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
7400b57cec5SDimitry Andric __kmp_msg_null);
7415f757f3fSDimitry Andric KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime / multiplier);
7420b57cec5SDimitry Andric }
7430b57cec5SDimitry Andric __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
7440b57cec5SDimitry Andric }
7450b57cec5SDimitry Andric #if KMP_USE_MONITOR
7460b57cec5SDimitry Andric // calculate number of monitor thread wakeup intervals corresponding to
7470b57cec5SDimitry Andric // blocktime.
7480b57cec5SDimitry Andric __kmp_monitor_wakeups =
7490b57cec5SDimitry Andric KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
7500b57cec5SDimitry Andric __kmp_bt_intervals =
7510b57cec5SDimitry Andric KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
7520b57cec5SDimitry Andric #endif
7530b57cec5SDimitry Andric K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
7540b57cec5SDimitry Andric if (__kmp_env_blocktime) {
7550b57cec5SDimitry Andric K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
7560b57cec5SDimitry Andric }
7570b57cec5SDimitry Andric } // __kmp_stg_parse_blocktime
7580b57cec5SDimitry Andric
__kmp_stg_print_blocktime(kmp_str_buf_t * buffer,char const * name,void * data)7590b57cec5SDimitry Andric static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
7600b57cec5SDimitry Andric void *data) {
7615f757f3fSDimitry Andric int num = __kmp_dflt_blocktime;
7625f757f3fSDimitry Andric if (__kmp_blocktime_units == 'm') {
7635f757f3fSDimitry Andric num = num / 1000;
7645f757f3fSDimitry Andric }
7655f757f3fSDimitry Andric if (__kmp_env_format) {
7665f757f3fSDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(name);
7675f757f3fSDimitry Andric } else {
7685f757f3fSDimitry Andric __kmp_str_buf_print(buffer, " %s=", name);
7695f757f3fSDimitry Andric }
7705f757f3fSDimitry Andric __kmp_str_buf_print(buffer, "%d", num);
7715f757f3fSDimitry Andric __kmp_str_buf_print(buffer, "%cs\n", __kmp_blocktime_units);
7720b57cec5SDimitry Andric } // __kmp_stg_print_blocktime
7730b57cec5SDimitry Andric
7740b57cec5SDimitry Andric // -----------------------------------------------------------------------------
7750b57cec5SDimitry Andric // KMP_DUPLICATE_LIB_OK
7760b57cec5SDimitry Andric
__kmp_stg_parse_duplicate_lib_ok(char const * name,char const * value,void * data)7770b57cec5SDimitry Andric static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
7780b57cec5SDimitry Andric char const *value, void *data) {
7790b57cec5SDimitry Andric /* actually this variable is not supported, put here for compatibility with
7800b57cec5SDimitry Andric earlier builds and for static/dynamic combination */
7810b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
7820b57cec5SDimitry Andric } // __kmp_stg_parse_duplicate_lib_ok
7830b57cec5SDimitry Andric
__kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t * buffer,char const * name,void * data)7840b57cec5SDimitry Andric static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
7850b57cec5SDimitry Andric char const *name, void *data) {
7860b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
7870b57cec5SDimitry Andric } // __kmp_stg_print_duplicate_lib_ok
7880b57cec5SDimitry Andric
7890b57cec5SDimitry Andric // -----------------------------------------------------------------------------
7900b57cec5SDimitry Andric // KMP_INHERIT_FP_CONTROL
7910b57cec5SDimitry Andric
7920b57cec5SDimitry Andric #if KMP_ARCH_X86 || KMP_ARCH_X86_64
7930b57cec5SDimitry Andric
__kmp_stg_parse_inherit_fp_control(char const * name,char const * value,void * data)7940b57cec5SDimitry Andric static void __kmp_stg_parse_inherit_fp_control(char const *name,
7950b57cec5SDimitry Andric char const *value, void *data) {
7960b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
7970b57cec5SDimitry Andric } // __kmp_stg_parse_inherit_fp_control
7980b57cec5SDimitry Andric
__kmp_stg_print_inherit_fp_control(kmp_str_buf_t * buffer,char const * name,void * data)7990b57cec5SDimitry Andric static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
8000b57cec5SDimitry Andric char const *name, void *data) {
8010b57cec5SDimitry Andric #if KMP_DEBUG
8020b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
8030b57cec5SDimitry Andric #endif /* KMP_DEBUG */
8040b57cec5SDimitry Andric } // __kmp_stg_print_inherit_fp_control
8050b57cec5SDimitry Andric
8060b57cec5SDimitry Andric #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
8070b57cec5SDimitry Andric
8080b57cec5SDimitry Andric // Used for OMP_WAIT_POLICY
8090b57cec5SDimitry Andric static char const *blocktime_str = NULL;
8100b57cec5SDimitry Andric
8110b57cec5SDimitry Andric // -----------------------------------------------------------------------------
8120b57cec5SDimitry Andric // KMP_LIBRARY, OMP_WAIT_POLICY
8130b57cec5SDimitry Andric
__kmp_stg_parse_wait_policy(char const * name,char const * value,void * data)8140b57cec5SDimitry Andric static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
8150b57cec5SDimitry Andric void *data) {
8160b57cec5SDimitry Andric
8170b57cec5SDimitry Andric kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
8180b57cec5SDimitry Andric int rc;
8190b57cec5SDimitry Andric
8200b57cec5SDimitry Andric rc = __kmp_stg_check_rivals(name, value, wait->rivals);
8210b57cec5SDimitry Andric if (rc) {
8220b57cec5SDimitry Andric return;
8230b57cec5SDimitry Andric }
8240b57cec5SDimitry Andric
8250b57cec5SDimitry Andric if (wait->omp) {
8260b57cec5SDimitry Andric if (__kmp_str_match("ACTIVE", 1, value)) {
8270b57cec5SDimitry Andric __kmp_library = library_turnaround;
8280b57cec5SDimitry Andric if (blocktime_str == NULL) {
8290b57cec5SDimitry Andric // KMP_BLOCKTIME not specified, so set default to "infinite".
8300b57cec5SDimitry Andric __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
8310b57cec5SDimitry Andric }
8320b57cec5SDimitry Andric } else if (__kmp_str_match("PASSIVE", 1, value)) {
8330b57cec5SDimitry Andric __kmp_library = library_throughput;
83481ad6265SDimitry Andric __kmp_wpolicy_passive = true; /* allow sleep while active tasking */
8350b57cec5SDimitry Andric if (blocktime_str == NULL) {
8360b57cec5SDimitry Andric // KMP_BLOCKTIME not specified, so set default to 0.
8370b57cec5SDimitry Andric __kmp_dflt_blocktime = 0;
8380b57cec5SDimitry Andric }
8390b57cec5SDimitry Andric } else {
8400b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
8410b57cec5SDimitry Andric }
8420b57cec5SDimitry Andric } else {
8430b57cec5SDimitry Andric if (__kmp_str_match("serial", 1, value)) { /* S */
8440b57cec5SDimitry Andric __kmp_library = library_serial;
8450b57cec5SDimitry Andric } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
8460b57cec5SDimitry Andric __kmp_library = library_throughput;
8470b57cec5SDimitry Andric if (blocktime_str == NULL) {
8480b57cec5SDimitry Andric // KMP_BLOCKTIME not specified, so set default to 0.
8490b57cec5SDimitry Andric __kmp_dflt_blocktime = 0;
8500b57cec5SDimitry Andric }
8510b57cec5SDimitry Andric } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
8520b57cec5SDimitry Andric __kmp_library = library_turnaround;
8530b57cec5SDimitry Andric } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
8540b57cec5SDimitry Andric __kmp_library = library_turnaround;
8550b57cec5SDimitry Andric } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
8560b57cec5SDimitry Andric __kmp_library = library_throughput;
8570b57cec5SDimitry Andric if (blocktime_str == NULL) {
8580b57cec5SDimitry Andric // KMP_BLOCKTIME not specified, so set default to 0.
8590b57cec5SDimitry Andric __kmp_dflt_blocktime = 0;
8600b57cec5SDimitry Andric }
8610b57cec5SDimitry Andric } else {
8620b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
8630b57cec5SDimitry Andric }
8640b57cec5SDimitry Andric }
8650b57cec5SDimitry Andric } // __kmp_stg_parse_wait_policy
8660b57cec5SDimitry Andric
__kmp_stg_print_wait_policy(kmp_str_buf_t * buffer,char const * name,void * data)8670b57cec5SDimitry Andric static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
8680b57cec5SDimitry Andric void *data) {
8690b57cec5SDimitry Andric
8700b57cec5SDimitry Andric kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
8710b57cec5SDimitry Andric char const *value = NULL;
8720b57cec5SDimitry Andric
8730b57cec5SDimitry Andric if (wait->omp) {
8740b57cec5SDimitry Andric switch (__kmp_library) {
8750b57cec5SDimitry Andric case library_turnaround: {
8760b57cec5SDimitry Andric value = "ACTIVE";
8770b57cec5SDimitry Andric } break;
8780b57cec5SDimitry Andric case library_throughput: {
8790b57cec5SDimitry Andric value = "PASSIVE";
8800b57cec5SDimitry Andric } break;
8817a6dacacSDimitry Andric case library_none:
8827a6dacacSDimitry Andric case library_serial: {
8837a6dacacSDimitry Andric value = NULL;
8847a6dacacSDimitry Andric } break;
8850b57cec5SDimitry Andric }
8860b57cec5SDimitry Andric } else {
8870b57cec5SDimitry Andric switch (__kmp_library) {
8880b57cec5SDimitry Andric case library_serial: {
8890b57cec5SDimitry Andric value = "serial";
8900b57cec5SDimitry Andric } break;
8910b57cec5SDimitry Andric case library_turnaround: {
8920b57cec5SDimitry Andric value = "turnaround";
8930b57cec5SDimitry Andric } break;
8940b57cec5SDimitry Andric case library_throughput: {
8950b57cec5SDimitry Andric value = "throughput";
8960b57cec5SDimitry Andric } break;
8977a6dacacSDimitry Andric case library_none: {
8987a6dacacSDimitry Andric value = NULL;
8997a6dacacSDimitry Andric } break;
9000b57cec5SDimitry Andric }
9010b57cec5SDimitry Andric }
9020b57cec5SDimitry Andric if (value != NULL) {
9030b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, value);
9040b57cec5SDimitry Andric }
9050b57cec5SDimitry Andric
9060b57cec5SDimitry Andric } // __kmp_stg_print_wait_policy
9070b57cec5SDimitry Andric
9080b57cec5SDimitry Andric #if KMP_USE_MONITOR
9090b57cec5SDimitry Andric // -----------------------------------------------------------------------------
9100b57cec5SDimitry Andric // KMP_MONITOR_STACKSIZE
9110b57cec5SDimitry Andric
__kmp_stg_parse_monitor_stacksize(char const * name,char const * value,void * data)9120b57cec5SDimitry Andric static void __kmp_stg_parse_monitor_stacksize(char const *name,
9130b57cec5SDimitry Andric char const *value, void *data) {
9140b57cec5SDimitry Andric __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
9150b57cec5SDimitry Andric NULL, &__kmp_monitor_stksize, 1);
9160b57cec5SDimitry Andric } // __kmp_stg_parse_monitor_stacksize
9170b57cec5SDimitry Andric
__kmp_stg_print_monitor_stacksize(kmp_str_buf_t * buffer,char const * name,void * data)9180b57cec5SDimitry Andric static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
9190b57cec5SDimitry Andric char const *name, void *data) {
9200b57cec5SDimitry Andric if (__kmp_env_format) {
9210b57cec5SDimitry Andric if (__kmp_monitor_stksize > 0)
9220b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(name);
9230b57cec5SDimitry Andric else
9240b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME;
9250b57cec5SDimitry Andric } else {
9260b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s", name);
9270b57cec5SDimitry Andric }
9280b57cec5SDimitry Andric if (__kmp_monitor_stksize > 0) {
9290b57cec5SDimitry Andric __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
9300b57cec5SDimitry Andric } else {
9310b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
9320b57cec5SDimitry Andric }
9330b57cec5SDimitry Andric if (__kmp_env_format && __kmp_monitor_stksize) {
9340b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "'\n");
9350b57cec5SDimitry Andric }
9360b57cec5SDimitry Andric } // __kmp_stg_print_monitor_stacksize
9370b57cec5SDimitry Andric #endif // KMP_USE_MONITOR
9380b57cec5SDimitry Andric
9390b57cec5SDimitry Andric // -----------------------------------------------------------------------------
9400b57cec5SDimitry Andric // KMP_SETTINGS
9410b57cec5SDimitry Andric
__kmp_stg_parse_settings(char const * name,char const * value,void * data)9420b57cec5SDimitry Andric static void __kmp_stg_parse_settings(char const *name, char const *value,
9430b57cec5SDimitry Andric void *data) {
9440b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_settings);
9450b57cec5SDimitry Andric } // __kmp_stg_parse_settings
9460b57cec5SDimitry Andric
__kmp_stg_print_settings(kmp_str_buf_t * buffer,char const * name,void * data)9470b57cec5SDimitry Andric static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
9480b57cec5SDimitry Andric void *data) {
9490b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_settings);
9500b57cec5SDimitry Andric } // __kmp_stg_print_settings
9510b57cec5SDimitry Andric
9520b57cec5SDimitry Andric // -----------------------------------------------------------------------------
9530b57cec5SDimitry Andric // KMP_STACKPAD
9540b57cec5SDimitry Andric
__kmp_stg_parse_stackpad(char const * name,char const * value,void * data)9550b57cec5SDimitry Andric static void __kmp_stg_parse_stackpad(char const *name, char const *value,
9560b57cec5SDimitry Andric void *data) {
9570b57cec5SDimitry Andric __kmp_stg_parse_int(name, // Env var name
9580b57cec5SDimitry Andric value, // Env var value
9590b57cec5SDimitry Andric KMP_MIN_STKPADDING, // Min value
9600b57cec5SDimitry Andric KMP_MAX_STKPADDING, // Max value
9610b57cec5SDimitry Andric &__kmp_stkpadding // Var to initialize
9620b57cec5SDimitry Andric );
9630b57cec5SDimitry Andric } // __kmp_stg_parse_stackpad
9640b57cec5SDimitry Andric
__kmp_stg_print_stackpad(kmp_str_buf_t * buffer,char const * name,void * data)9650b57cec5SDimitry Andric static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
9660b57cec5SDimitry Andric void *data) {
9670b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
9680b57cec5SDimitry Andric } // __kmp_stg_print_stackpad
9690b57cec5SDimitry Andric
9700b57cec5SDimitry Andric // -----------------------------------------------------------------------------
9710b57cec5SDimitry Andric // KMP_STACKOFFSET
9720b57cec5SDimitry Andric
__kmp_stg_parse_stackoffset(char const * name,char const * value,void * data)9730b57cec5SDimitry Andric static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
9740b57cec5SDimitry Andric void *data) {
9750b57cec5SDimitry Andric __kmp_stg_parse_size(name, // Env var name
9760b57cec5SDimitry Andric value, // Env var value
9770b57cec5SDimitry Andric KMP_MIN_STKOFFSET, // Min value
9780b57cec5SDimitry Andric KMP_MAX_STKOFFSET, // Max value
9790b57cec5SDimitry Andric NULL, //
9800b57cec5SDimitry Andric &__kmp_stkoffset, // Var to initialize
9810b57cec5SDimitry Andric 1);
9820b57cec5SDimitry Andric } // __kmp_stg_parse_stackoffset
9830b57cec5SDimitry Andric
__kmp_stg_print_stackoffset(kmp_str_buf_t * buffer,char const * name,void * data)9840b57cec5SDimitry Andric static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
9850b57cec5SDimitry Andric void *data) {
9860b57cec5SDimitry Andric __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
9870b57cec5SDimitry Andric } // __kmp_stg_print_stackoffset
9880b57cec5SDimitry Andric
9890b57cec5SDimitry Andric // -----------------------------------------------------------------------------
9900b57cec5SDimitry Andric // KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
9910b57cec5SDimitry Andric
__kmp_stg_parse_stacksize(char const * name,char const * value,void * data)9920b57cec5SDimitry Andric static void __kmp_stg_parse_stacksize(char const *name, char const *value,
9930b57cec5SDimitry Andric void *data) {
9940b57cec5SDimitry Andric
9950b57cec5SDimitry Andric kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
9960b57cec5SDimitry Andric int rc;
9970b57cec5SDimitry Andric
9980b57cec5SDimitry Andric rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
9990b57cec5SDimitry Andric if (rc) {
10000b57cec5SDimitry Andric return;
10010b57cec5SDimitry Andric }
10020b57cec5SDimitry Andric __kmp_stg_parse_size(name, // Env var name
10030b57cec5SDimitry Andric value, // Env var value
10040b57cec5SDimitry Andric __kmp_sys_min_stksize, // Min value
10050b57cec5SDimitry Andric KMP_MAX_STKSIZE, // Max value
10060b57cec5SDimitry Andric &__kmp_env_stksize, //
10070b57cec5SDimitry Andric &__kmp_stksize, // Var to initialize
10080b57cec5SDimitry Andric stacksize->factor);
10090b57cec5SDimitry Andric
10100b57cec5SDimitry Andric } // __kmp_stg_parse_stacksize
10110b57cec5SDimitry Andric
10120b57cec5SDimitry Andric // This function is called for printing both KMP_STACKSIZE (factor is 1) and
10130b57cec5SDimitry Andric // OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
10140b57cec5SDimitry Andric // OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
10150b57cec5SDimitry Andric // customer request in future.
__kmp_stg_print_stacksize(kmp_str_buf_t * buffer,char const * name,void * data)10160b57cec5SDimitry Andric static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
10170b57cec5SDimitry Andric void *data) {
10180b57cec5SDimitry Andric kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
10190b57cec5SDimitry Andric if (__kmp_env_format) {
10200b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(name);
10210b57cec5SDimitry Andric __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
10220b57cec5SDimitry Andric ? __kmp_stksize / stacksize->factor
10230b57cec5SDimitry Andric : __kmp_stksize);
10240b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "'\n");
10250b57cec5SDimitry Andric } else {
10260b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s=", name);
10270b57cec5SDimitry Andric __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
10280b57cec5SDimitry Andric ? __kmp_stksize / stacksize->factor
10290b57cec5SDimitry Andric : __kmp_stksize);
10300b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "\n");
10310b57cec5SDimitry Andric }
10320b57cec5SDimitry Andric } // __kmp_stg_print_stacksize
10330b57cec5SDimitry Andric
10340b57cec5SDimitry Andric // -----------------------------------------------------------------------------
10350b57cec5SDimitry Andric // KMP_VERSION
10360b57cec5SDimitry Andric
__kmp_stg_parse_version(char const * name,char const * value,void * data)10370b57cec5SDimitry Andric static void __kmp_stg_parse_version(char const *name, char const *value,
10380b57cec5SDimitry Andric void *data) {
10390b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_version);
10400b57cec5SDimitry Andric } // __kmp_stg_parse_version
10410b57cec5SDimitry Andric
__kmp_stg_print_version(kmp_str_buf_t * buffer,char const * name,void * data)10420b57cec5SDimitry Andric static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
10430b57cec5SDimitry Andric void *data) {
10440b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_version);
10450b57cec5SDimitry Andric } // __kmp_stg_print_version
10460b57cec5SDimitry Andric
10470b57cec5SDimitry Andric // -----------------------------------------------------------------------------
10480b57cec5SDimitry Andric // KMP_WARNINGS
10490b57cec5SDimitry Andric
__kmp_stg_parse_warnings(char const * name,char const * value,void * data)10500b57cec5SDimitry Andric static void __kmp_stg_parse_warnings(char const *name, char const *value,
10510b57cec5SDimitry Andric void *data) {
10520b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
10530b57cec5SDimitry Andric if (__kmp_generate_warnings != kmp_warnings_off) {
10540b57cec5SDimitry Andric // AC: only 0/1 values documented, so reset to explicit to distinguish from
10550b57cec5SDimitry Andric // default setting
10560b57cec5SDimitry Andric __kmp_generate_warnings = kmp_warnings_explicit;
10570b57cec5SDimitry Andric }
10580b57cec5SDimitry Andric } // __kmp_stg_parse_warnings
10590b57cec5SDimitry Andric
__kmp_stg_print_warnings(kmp_str_buf_t * buffer,char const * name,void * data)10600b57cec5SDimitry Andric static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
10610b57cec5SDimitry Andric void *data) {
10620b57cec5SDimitry Andric // AC: TODO: change to print_int? (needs documentation change)
10630b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
10640b57cec5SDimitry Andric } // __kmp_stg_print_warnings
10650b57cec5SDimitry Andric
10660b57cec5SDimitry Andric // -----------------------------------------------------------------------------
1067fe6060f1SDimitry Andric // KMP_NESTING_MODE
1068fe6060f1SDimitry Andric
__kmp_stg_parse_nesting_mode(char const * name,char const * value,void * data)1069fe6060f1SDimitry Andric static void __kmp_stg_parse_nesting_mode(char const *name, char const *value,
1070fe6060f1SDimitry Andric void *data) {
1071fe6060f1SDimitry Andric __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_nesting_mode);
1072fe6060f1SDimitry Andric #if KMP_AFFINITY_SUPPORTED && KMP_USE_HWLOC
1073fe6060f1SDimitry Andric if (__kmp_nesting_mode > 0)
1074fe6060f1SDimitry Andric __kmp_affinity_top_method = affinity_top_method_hwloc;
1075fe6060f1SDimitry Andric #endif
1076fe6060f1SDimitry Andric } // __kmp_stg_parse_nesting_mode
1077fe6060f1SDimitry Andric
__kmp_stg_print_nesting_mode(kmp_str_buf_t * buffer,char const * name,void * data)1078fe6060f1SDimitry Andric static void __kmp_stg_print_nesting_mode(kmp_str_buf_t *buffer,
1079fe6060f1SDimitry Andric char const *name, void *data) {
1080fe6060f1SDimitry Andric if (__kmp_env_format) {
1081fe6060f1SDimitry Andric KMP_STR_BUF_PRINT_NAME;
1082fe6060f1SDimitry Andric } else {
1083fe6060f1SDimitry Andric __kmp_str_buf_print(buffer, " %s", name);
1084fe6060f1SDimitry Andric }
1085fe6060f1SDimitry Andric __kmp_str_buf_print(buffer, "=%d\n", __kmp_nesting_mode);
1086fe6060f1SDimitry Andric } // __kmp_stg_print_nesting_mode
1087fe6060f1SDimitry Andric
1088fe6060f1SDimitry Andric // -----------------------------------------------------------------------------
10890b57cec5SDimitry Andric // OMP_NESTED, OMP_NUM_THREADS
10900b57cec5SDimitry Andric
__kmp_stg_parse_nested(char const * name,char const * value,void * data)10910b57cec5SDimitry Andric static void __kmp_stg_parse_nested(char const *name, char const *value,
10920b57cec5SDimitry Andric void *data) {
10930b57cec5SDimitry Andric int nested;
10940b57cec5SDimitry Andric KMP_INFORM(EnvVarDeprecated, name, "OMP_MAX_ACTIVE_LEVELS");
10950b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &nested);
10960b57cec5SDimitry Andric if (nested) {
10970b57cec5SDimitry Andric if (!__kmp_dflt_max_active_levels_set)
10980b57cec5SDimitry Andric __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
10990b57cec5SDimitry Andric } else { // nesting explicitly turned off
11000b57cec5SDimitry Andric __kmp_dflt_max_active_levels = 1;
11010b57cec5SDimitry Andric __kmp_dflt_max_active_levels_set = true;
11020b57cec5SDimitry Andric }
11030b57cec5SDimitry Andric } // __kmp_stg_parse_nested
11040b57cec5SDimitry Andric
__kmp_stg_print_nested(kmp_str_buf_t * buffer,char const * name,void * data)11050b57cec5SDimitry Andric static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
11060b57cec5SDimitry Andric void *data) {
11070b57cec5SDimitry Andric if (__kmp_env_format) {
11080b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME;
11090b57cec5SDimitry Andric } else {
11100b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s", name);
11110b57cec5SDimitry Andric }
11120b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ": deprecated; max-active-levels-var=%d\n",
11130b57cec5SDimitry Andric __kmp_dflt_max_active_levels);
11140b57cec5SDimitry Andric } // __kmp_stg_print_nested
11150b57cec5SDimitry Andric
__kmp_parse_nested_num_threads(const char * var,const char * env,kmp_nested_nthreads_t * nth_array)11160b57cec5SDimitry Andric static void __kmp_parse_nested_num_threads(const char *var, const char *env,
11170b57cec5SDimitry Andric kmp_nested_nthreads_t *nth_array) {
11180b57cec5SDimitry Andric const char *next = env;
11190b57cec5SDimitry Andric const char *scan = next;
11200b57cec5SDimitry Andric
11210b57cec5SDimitry Andric int total = 0; // Count elements that were set. It'll be used as an array size
11220b57cec5SDimitry Andric int prev_comma = FALSE; // For correct processing sequential commas
11230b57cec5SDimitry Andric
11240b57cec5SDimitry Andric // Count the number of values in the env. var string
11250b57cec5SDimitry Andric for (;;) {
11260b57cec5SDimitry Andric SKIP_WS(next);
11270b57cec5SDimitry Andric
11280b57cec5SDimitry Andric if (*next == '\0') {
11290b57cec5SDimitry Andric break;
11300b57cec5SDimitry Andric }
11310b57cec5SDimitry Andric // Next character is not an integer or not a comma => end of list
11320b57cec5SDimitry Andric if (((*next < '0') || (*next > '9')) && (*next != ',')) {
11330b57cec5SDimitry Andric KMP_WARNING(NthSyntaxError, var, env);
11340b57cec5SDimitry Andric return;
11350b57cec5SDimitry Andric }
11360b57cec5SDimitry Andric // The next character is ','
11370b57cec5SDimitry Andric if (*next == ',') {
1138480093f4SDimitry Andric // ',' is the first character
11390b57cec5SDimitry Andric if (total == 0 || prev_comma) {
11400b57cec5SDimitry Andric total++;
11410b57cec5SDimitry Andric }
11420b57cec5SDimitry Andric prev_comma = TRUE;
11430b57cec5SDimitry Andric next++; // skip ','
11440b57cec5SDimitry Andric SKIP_WS(next);
11450b57cec5SDimitry Andric }
11460b57cec5SDimitry Andric // Next character is a digit
11470b57cec5SDimitry Andric if (*next >= '0' && *next <= '9') {
11480b57cec5SDimitry Andric prev_comma = FALSE;
11490b57cec5SDimitry Andric SKIP_DIGITS(next);
11500b57cec5SDimitry Andric total++;
11510b57cec5SDimitry Andric const char *tmp = next;
11520b57cec5SDimitry Andric SKIP_WS(tmp);
11530b57cec5SDimitry Andric if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
11540b57cec5SDimitry Andric KMP_WARNING(NthSpacesNotAllowed, var, env);
11550b57cec5SDimitry Andric return;
11560b57cec5SDimitry Andric }
11570b57cec5SDimitry Andric }
11580b57cec5SDimitry Andric }
11590b57cec5SDimitry Andric if (!__kmp_dflt_max_active_levels_set && total > 1)
11600b57cec5SDimitry Andric __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
11610b57cec5SDimitry Andric KMP_DEBUG_ASSERT(total > 0);
11620b57cec5SDimitry Andric if (total <= 0) {
11630b57cec5SDimitry Andric KMP_WARNING(NthSyntaxError, var, env);
11640b57cec5SDimitry Andric return;
11650b57cec5SDimitry Andric }
11660b57cec5SDimitry Andric
11670b57cec5SDimitry Andric // Check if the nested nthreads array exists
11680b57cec5SDimitry Andric if (!nth_array->nth) {
11690b57cec5SDimitry Andric // Allocate an array of double size
11700b57cec5SDimitry Andric nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
11710b57cec5SDimitry Andric if (nth_array->nth == NULL) {
11720b57cec5SDimitry Andric KMP_FATAL(MemoryAllocFailed);
11730b57cec5SDimitry Andric }
11740b57cec5SDimitry Andric nth_array->size = total * 2;
11750b57cec5SDimitry Andric } else {
11760b57cec5SDimitry Andric if (nth_array->size < total) {
11770b57cec5SDimitry Andric // Increase the array size
11780b57cec5SDimitry Andric do {
11790b57cec5SDimitry Andric nth_array->size *= 2;
11800b57cec5SDimitry Andric } while (nth_array->size < total);
11810b57cec5SDimitry Andric
11820b57cec5SDimitry Andric nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
11830b57cec5SDimitry Andric nth_array->nth, sizeof(int) * nth_array->size);
11840b57cec5SDimitry Andric if (nth_array->nth == NULL) {
11850b57cec5SDimitry Andric KMP_FATAL(MemoryAllocFailed);
11860b57cec5SDimitry Andric }
11870b57cec5SDimitry Andric }
11880b57cec5SDimitry Andric }
11890b57cec5SDimitry Andric nth_array->used = total;
11900b57cec5SDimitry Andric int i = 0;
11910b57cec5SDimitry Andric
11920b57cec5SDimitry Andric prev_comma = FALSE;
11930b57cec5SDimitry Andric total = 0;
11940b57cec5SDimitry Andric // Save values in the array
11950b57cec5SDimitry Andric for (;;) {
11960b57cec5SDimitry Andric SKIP_WS(scan);
11970b57cec5SDimitry Andric if (*scan == '\0') {
11980b57cec5SDimitry Andric break;
11990b57cec5SDimitry Andric }
12000b57cec5SDimitry Andric // The next character is ','
12010b57cec5SDimitry Andric if (*scan == ',') {
12020b57cec5SDimitry Andric // ',' in the beginning of the list
12030b57cec5SDimitry Andric if (total == 0) {
12040b57cec5SDimitry Andric // The value is supposed to be equal to __kmp_avail_proc but it is
12050b57cec5SDimitry Andric // unknown at the moment.
12060b57cec5SDimitry Andric // So let's put a placeholder (#threads = 0) to correct it later.
12070b57cec5SDimitry Andric nth_array->nth[i++] = 0;
12080b57cec5SDimitry Andric total++;
12090b57cec5SDimitry Andric } else if (prev_comma) {
12100b57cec5SDimitry Andric // Num threads is inherited from the previous level
12110b57cec5SDimitry Andric nth_array->nth[i] = nth_array->nth[i - 1];
12120b57cec5SDimitry Andric i++;
12130b57cec5SDimitry Andric total++;
12140b57cec5SDimitry Andric }
12150b57cec5SDimitry Andric prev_comma = TRUE;
12160b57cec5SDimitry Andric scan++; // skip ','
12170b57cec5SDimitry Andric SKIP_WS(scan);
12180b57cec5SDimitry Andric }
12190b57cec5SDimitry Andric // Next character is a digit
12200b57cec5SDimitry Andric if (*scan >= '0' && *scan <= '9') {
12210b57cec5SDimitry Andric int num;
12220b57cec5SDimitry Andric const char *buf = scan;
12230b57cec5SDimitry Andric char const *msg = NULL;
12240b57cec5SDimitry Andric prev_comma = FALSE;
12250b57cec5SDimitry Andric SKIP_DIGITS(scan);
12260b57cec5SDimitry Andric total++;
12270b57cec5SDimitry Andric
12280b57cec5SDimitry Andric num = __kmp_str_to_int(buf, *scan);
12290b57cec5SDimitry Andric if (num < KMP_MIN_NTH) {
12300b57cec5SDimitry Andric msg = KMP_I18N_STR(ValueTooSmall);
12310b57cec5SDimitry Andric num = KMP_MIN_NTH;
12320b57cec5SDimitry Andric } else if (num > __kmp_sys_max_nth) {
12330b57cec5SDimitry Andric msg = KMP_I18N_STR(ValueTooLarge);
12340b57cec5SDimitry Andric num = __kmp_sys_max_nth;
12350b57cec5SDimitry Andric }
12360b57cec5SDimitry Andric if (msg != NULL) {
12370b57cec5SDimitry Andric // Message is not empty. Print warning.
12380b57cec5SDimitry Andric KMP_WARNING(ParseSizeIntWarn, var, env, msg);
12390b57cec5SDimitry Andric KMP_INFORM(Using_int_Value, var, num);
12400b57cec5SDimitry Andric }
12410b57cec5SDimitry Andric nth_array->nth[i++] = num;
12420b57cec5SDimitry Andric }
12430b57cec5SDimitry Andric }
12440b57cec5SDimitry Andric }
12450b57cec5SDimitry Andric
__kmp_stg_parse_num_threads(char const * name,char const * value,void * data)12460b57cec5SDimitry Andric static void __kmp_stg_parse_num_threads(char const *name, char const *value,
12470b57cec5SDimitry Andric void *data) {
12480b57cec5SDimitry Andric // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
12490b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
12500b57cec5SDimitry Andric // The array of 1 element
12510b57cec5SDimitry Andric __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
12520b57cec5SDimitry Andric __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
12530b57cec5SDimitry Andric __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
12540b57cec5SDimitry Andric __kmp_xproc;
12550b57cec5SDimitry Andric } else {
12560b57cec5SDimitry Andric __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
12570b57cec5SDimitry Andric if (__kmp_nested_nth.nth) {
12580b57cec5SDimitry Andric __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
12590b57cec5SDimitry Andric if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
12600b57cec5SDimitry Andric __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
12610b57cec5SDimitry Andric }
12620b57cec5SDimitry Andric }
12630b57cec5SDimitry Andric }
12640b57cec5SDimitry Andric K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
12650b57cec5SDimitry Andric } // __kmp_stg_parse_num_threads
12660b57cec5SDimitry Andric
126706c3fb27SDimitry Andric #if OMPX_TASKGRAPH
__kmp_stg_parse_max_tdgs(char const * name,char const * value,void * data)126806c3fb27SDimitry Andric static void __kmp_stg_parse_max_tdgs(char const *name, char const *value,
126906c3fb27SDimitry Andric void *data) {
127006c3fb27SDimitry Andric __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_max_tdgs);
127106c3fb27SDimitry Andric } // __kmp_stg_parse_max_tdgs
127206c3fb27SDimitry Andric
__kmp_std_print_max_tdgs(kmp_str_buf_t * buffer,char const * name,void * data)127306c3fb27SDimitry Andric static void __kmp_std_print_max_tdgs(kmp_str_buf_t *buffer, char const *name,
127406c3fb27SDimitry Andric void *data) {
127506c3fb27SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_max_tdgs);
127606c3fb27SDimitry Andric } // __kmp_std_print_max_tdgs
127706c3fb27SDimitry Andric
__kmp_stg_parse_tdg_dot(char const * name,char const * value,void * data)127806c3fb27SDimitry Andric static void __kmp_stg_parse_tdg_dot(char const *name, char const *value,
127906c3fb27SDimitry Andric void *data) {
128006c3fb27SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_tdg_dot);
128106c3fb27SDimitry Andric } // __kmp_stg_parse_tdg_dot
128206c3fb27SDimitry Andric
__kmp_stg_print_tdg_dot(kmp_str_buf_t * buffer,char const * name,void * data)128306c3fb27SDimitry Andric static void __kmp_stg_print_tdg_dot(kmp_str_buf_t *buffer, char const *name,
128406c3fb27SDimitry Andric void *data) {
128506c3fb27SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_tdg_dot);
128606c3fb27SDimitry Andric } // __kmp_stg_print_tdg_dot
128706c3fb27SDimitry Andric #endif
128806c3fb27SDimitry Andric
__kmp_stg_parse_num_hidden_helper_threads(char const * name,char const * value,void * data)1289e8d8bef9SDimitry Andric static void __kmp_stg_parse_num_hidden_helper_threads(char const *name,
1290e8d8bef9SDimitry Andric char const *value,
1291e8d8bef9SDimitry Andric void *data) {
1292e8d8bef9SDimitry Andric __kmp_stg_parse_int(name, value, 0, 16, &__kmp_hidden_helper_threads_num);
1293e8d8bef9SDimitry Andric // If the number of hidden helper threads is zero, we disable hidden helper
1294e8d8bef9SDimitry Andric // task
1295e8d8bef9SDimitry Andric if (__kmp_hidden_helper_threads_num == 0) {
1296e8d8bef9SDimitry Andric __kmp_enable_hidden_helper = FALSE;
129781ad6265SDimitry Andric } else {
1298bdd1243dSDimitry Andric // Since the main thread of hidden helper team does not participate
129981ad6265SDimitry Andric // in tasks execution let's increment the number of threads by one
130081ad6265SDimitry Andric // so that requested number of threads do actual job.
130181ad6265SDimitry Andric __kmp_hidden_helper_threads_num++;
1302e8d8bef9SDimitry Andric }
1303e8d8bef9SDimitry Andric } // __kmp_stg_parse_num_hidden_helper_threads
1304e8d8bef9SDimitry Andric
__kmp_stg_print_num_hidden_helper_threads(kmp_str_buf_t * buffer,char const * name,void * data)1305e8d8bef9SDimitry Andric static void __kmp_stg_print_num_hidden_helper_threads(kmp_str_buf_t *buffer,
1306e8d8bef9SDimitry Andric char const *name,
1307e8d8bef9SDimitry Andric void *data) {
130881ad6265SDimitry Andric if (__kmp_hidden_helper_threads_num == 0) {
1309e8d8bef9SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num);
131081ad6265SDimitry Andric } else {
131181ad6265SDimitry Andric KMP_DEBUG_ASSERT(__kmp_hidden_helper_threads_num > 1);
131281ad6265SDimitry Andric // Let's exclude the main thread of hidden helper team and print
131381ad6265SDimitry Andric // number of worker threads those do actual job.
131481ad6265SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num - 1);
131581ad6265SDimitry Andric }
1316e8d8bef9SDimitry Andric } // __kmp_stg_print_num_hidden_helper_threads
1317e8d8bef9SDimitry Andric
__kmp_stg_parse_use_hidden_helper(char const * name,char const * value,void * data)1318e8d8bef9SDimitry Andric static void __kmp_stg_parse_use_hidden_helper(char const *name,
1319e8d8bef9SDimitry Andric char const *value, void *data) {
1320e8d8bef9SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_enable_hidden_helper);
1321e8d8bef9SDimitry Andric #if !KMP_OS_LINUX
1322e8d8bef9SDimitry Andric __kmp_enable_hidden_helper = FALSE;
1323e8d8bef9SDimitry Andric K_DIAG(1,
1324e8d8bef9SDimitry Andric ("__kmp_stg_parse_use_hidden_helper: Disable hidden helper task on "
1325e8d8bef9SDimitry Andric "non-Linux platform although it is enabled by user explicitly.\n"));
1326e8d8bef9SDimitry Andric #endif
1327e8d8bef9SDimitry Andric } // __kmp_stg_parse_use_hidden_helper
1328e8d8bef9SDimitry Andric
__kmp_stg_print_use_hidden_helper(kmp_str_buf_t * buffer,char const * name,void * data)1329e8d8bef9SDimitry Andric static void __kmp_stg_print_use_hidden_helper(kmp_str_buf_t *buffer,
1330e8d8bef9SDimitry Andric char const *name, void *data) {
1331e8d8bef9SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_enable_hidden_helper);
1332e8d8bef9SDimitry Andric } // __kmp_stg_print_use_hidden_helper
1333e8d8bef9SDimitry Andric
__kmp_stg_print_num_threads(kmp_str_buf_t * buffer,char const * name,void * data)13340b57cec5SDimitry Andric static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
13350b57cec5SDimitry Andric void *data) {
13360b57cec5SDimitry Andric if (__kmp_env_format) {
13370b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME;
13380b57cec5SDimitry Andric } else {
13390b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s", name);
13400b57cec5SDimitry Andric }
13410b57cec5SDimitry Andric if (__kmp_nested_nth.used) {
13420b57cec5SDimitry Andric kmp_str_buf_t buf;
13430b57cec5SDimitry Andric __kmp_str_buf_init(&buf);
13440b57cec5SDimitry Andric for (int i = 0; i < __kmp_nested_nth.used; i++) {
13450b57cec5SDimitry Andric __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
13460b57cec5SDimitry Andric if (i < __kmp_nested_nth.used - 1) {
13470b57cec5SDimitry Andric __kmp_str_buf_print(&buf, ",");
13480b57cec5SDimitry Andric }
13490b57cec5SDimitry Andric }
13500b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
13510b57cec5SDimitry Andric __kmp_str_buf_free(&buf);
13520b57cec5SDimitry Andric } else {
13530b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
13540b57cec5SDimitry Andric }
13550b57cec5SDimitry Andric } // __kmp_stg_print_num_threads
13560b57cec5SDimitry Andric
13570b57cec5SDimitry Andric // -----------------------------------------------------------------------------
13580b57cec5SDimitry Andric // OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
13590b57cec5SDimitry Andric
__kmp_stg_parse_tasking(char const * name,char const * value,void * data)13600b57cec5SDimitry Andric static void __kmp_stg_parse_tasking(char const *name, char const *value,
13610b57cec5SDimitry Andric void *data) {
13620b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
13630b57cec5SDimitry Andric (int *)&__kmp_tasking_mode);
13640b57cec5SDimitry Andric } // __kmp_stg_parse_tasking
13650b57cec5SDimitry Andric
__kmp_stg_print_tasking(kmp_str_buf_t * buffer,char const * name,void * data)13660b57cec5SDimitry Andric static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
13670b57cec5SDimitry Andric void *data) {
13680b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
13690b57cec5SDimitry Andric } // __kmp_stg_print_tasking
13700b57cec5SDimitry Andric
__kmp_stg_parse_task_stealing(char const * name,char const * value,void * data)13710b57cec5SDimitry Andric static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
13720b57cec5SDimitry Andric void *data) {
13730b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, 1,
13740b57cec5SDimitry Andric (int *)&__kmp_task_stealing_constraint);
13750b57cec5SDimitry Andric } // __kmp_stg_parse_task_stealing
13760b57cec5SDimitry Andric
__kmp_stg_print_task_stealing(kmp_str_buf_t * buffer,char const * name,void * data)13770b57cec5SDimitry Andric static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
13780b57cec5SDimitry Andric char const *name, void *data) {
13790b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
13800b57cec5SDimitry Andric } // __kmp_stg_print_task_stealing
13810b57cec5SDimitry Andric
__kmp_stg_parse_max_active_levels(char const * name,char const * value,void * data)13820b57cec5SDimitry Andric static void __kmp_stg_parse_max_active_levels(char const *name,
13830b57cec5SDimitry Andric char const *value, void *data) {
13840b57cec5SDimitry Andric kmp_uint64 tmp_dflt = 0;
13850b57cec5SDimitry Andric char const *msg = NULL;
13860b57cec5SDimitry Andric if (!__kmp_dflt_max_active_levels_set) {
13870b57cec5SDimitry Andric // Don't overwrite __kmp_dflt_max_active_levels if we get an invalid setting
13880b57cec5SDimitry Andric __kmp_str_to_uint(value, &tmp_dflt, &msg);
13890b57cec5SDimitry Andric if (msg != NULL) { // invalid setting; print warning and ignore
13900b57cec5SDimitry Andric KMP_WARNING(ParseSizeIntWarn, name, value, msg);
13910b57cec5SDimitry Andric } else if (tmp_dflt > KMP_MAX_ACTIVE_LEVELS_LIMIT) {
13920b57cec5SDimitry Andric // invalid setting; print warning and ignore
13930b57cec5SDimitry Andric msg = KMP_I18N_STR(ValueTooLarge);
13940b57cec5SDimitry Andric KMP_WARNING(ParseSizeIntWarn, name, value, msg);
13950b57cec5SDimitry Andric } else { // valid setting
1396e8d8bef9SDimitry Andric __kmp_type_convert(tmp_dflt, &(__kmp_dflt_max_active_levels));
13970b57cec5SDimitry Andric __kmp_dflt_max_active_levels_set = true;
13980b57cec5SDimitry Andric }
13990b57cec5SDimitry Andric }
14000b57cec5SDimitry Andric } // __kmp_stg_parse_max_active_levels
14010b57cec5SDimitry Andric
__kmp_stg_print_max_active_levels(kmp_str_buf_t * buffer,char const * name,void * data)14020b57cec5SDimitry Andric static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
14030b57cec5SDimitry Andric char const *name, void *data) {
14040b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
14050b57cec5SDimitry Andric } // __kmp_stg_print_max_active_levels
14060b57cec5SDimitry Andric
14070b57cec5SDimitry Andric // -----------------------------------------------------------------------------
14080b57cec5SDimitry Andric // OpenMP 4.0: OMP_DEFAULT_DEVICE
__kmp_stg_parse_default_device(char const * name,char const * value,void * data)14090b57cec5SDimitry Andric static void __kmp_stg_parse_default_device(char const *name, char const *value,
14100b57cec5SDimitry Andric void *data) {
14110b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
14120b57cec5SDimitry Andric &__kmp_default_device);
14130b57cec5SDimitry Andric } // __kmp_stg_parse_default_device
14140b57cec5SDimitry Andric
__kmp_stg_print_default_device(kmp_str_buf_t * buffer,char const * name,void * data)14150b57cec5SDimitry Andric static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
14160b57cec5SDimitry Andric char const *name, void *data) {
14170b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_default_device);
14180b57cec5SDimitry Andric } // __kmp_stg_print_default_device
14190b57cec5SDimitry Andric
14200b57cec5SDimitry Andric // -----------------------------------------------------------------------------
14210b57cec5SDimitry Andric // OpenMP 5.0: OMP_TARGET_OFFLOAD
__kmp_stg_parse_target_offload(char const * name,char const * value,void * data)14220b57cec5SDimitry Andric static void __kmp_stg_parse_target_offload(char const *name, char const *value,
14230b57cec5SDimitry Andric void *data) {
142406c3fb27SDimitry Andric kmp_trimmed_str_t value_str(value);
142506c3fb27SDimitry Andric const char *scan = value_str.get();
14260b57cec5SDimitry Andric __kmp_target_offload = tgt_default;
142706c3fb27SDimitry Andric
142806c3fb27SDimitry Andric if (*scan == '\0')
14290b57cec5SDimitry Andric return;
143006c3fb27SDimitry Andric
14310b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("mandatory", scan, 0)) {
14320b57cec5SDimitry Andric __kmp_target_offload = tgt_mandatory;
14330b57cec5SDimitry Andric } else if (!__kmp_strcasecmp_with_sentinel("disabled", scan, 0)) {
14340b57cec5SDimitry Andric __kmp_target_offload = tgt_disabled;
14350b57cec5SDimitry Andric } else if (!__kmp_strcasecmp_with_sentinel("default", scan, 0)) {
14360b57cec5SDimitry Andric __kmp_target_offload = tgt_default;
14370b57cec5SDimitry Andric } else {
14380b57cec5SDimitry Andric KMP_WARNING(SyntaxErrorUsing, name, "DEFAULT");
14390b57cec5SDimitry Andric }
14400b57cec5SDimitry Andric } // __kmp_stg_parse_target_offload
14410b57cec5SDimitry Andric
__kmp_stg_print_target_offload(kmp_str_buf_t * buffer,char const * name,void * data)14420b57cec5SDimitry Andric static void __kmp_stg_print_target_offload(kmp_str_buf_t *buffer,
14430b57cec5SDimitry Andric char const *name, void *data) {
14440b57cec5SDimitry Andric const char *value = NULL;
14450b57cec5SDimitry Andric if (__kmp_target_offload == tgt_default)
14460b57cec5SDimitry Andric value = "DEFAULT";
14470b57cec5SDimitry Andric else if (__kmp_target_offload == tgt_mandatory)
14480b57cec5SDimitry Andric value = "MANDATORY";
14490b57cec5SDimitry Andric else if (__kmp_target_offload == tgt_disabled)
14500b57cec5SDimitry Andric value = "DISABLED";
14510b57cec5SDimitry Andric KMP_DEBUG_ASSERT(value);
14520b57cec5SDimitry Andric if (__kmp_env_format) {
14530b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME;
14540b57cec5SDimitry Andric } else {
14550b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s", name);
14560b57cec5SDimitry Andric }
14570b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "=%s\n", value);
14580b57cec5SDimitry Andric } // __kmp_stg_print_target_offload
14590b57cec5SDimitry Andric
14600b57cec5SDimitry Andric // -----------------------------------------------------------------------------
14610b57cec5SDimitry Andric // OpenMP 4.5: OMP_MAX_TASK_PRIORITY
__kmp_stg_parse_max_task_priority(char const * name,char const * value,void * data)14620b57cec5SDimitry Andric static void __kmp_stg_parse_max_task_priority(char const *name,
14630b57cec5SDimitry Andric char const *value, void *data) {
14640b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
14650b57cec5SDimitry Andric &__kmp_max_task_priority);
14660b57cec5SDimitry Andric } // __kmp_stg_parse_max_task_priority
14670b57cec5SDimitry Andric
__kmp_stg_print_max_task_priority(kmp_str_buf_t * buffer,char const * name,void * data)14680b57cec5SDimitry Andric static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
14690b57cec5SDimitry Andric char const *name, void *data) {
14700b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
14710b57cec5SDimitry Andric } // __kmp_stg_print_max_task_priority
14720b57cec5SDimitry Andric
14730b57cec5SDimitry Andric // KMP_TASKLOOP_MIN_TASKS
14745ffd83dbSDimitry Andric // taskloop threshold to switch from recursive to linear tasks creation
__kmp_stg_parse_taskloop_min_tasks(char const * name,char const * value,void * data)14750b57cec5SDimitry Andric static void __kmp_stg_parse_taskloop_min_tasks(char const *name,
14760b57cec5SDimitry Andric char const *value, void *data) {
147706c3fb27SDimitry Andric int tmp = 0;
14780b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
14790b57cec5SDimitry Andric __kmp_taskloop_min_tasks = tmp;
14800b57cec5SDimitry Andric } // __kmp_stg_parse_taskloop_min_tasks
14810b57cec5SDimitry Andric
__kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t * buffer,char const * name,void * data)14820b57cec5SDimitry Andric static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
14830b57cec5SDimitry Andric char const *name, void *data) {
1484e8d8bef9SDimitry Andric __kmp_stg_print_uint64(buffer, name, __kmp_taskloop_min_tasks);
14850b57cec5SDimitry Andric } // __kmp_stg_print_taskloop_min_tasks
14860b57cec5SDimitry Andric
14870b57cec5SDimitry Andric // -----------------------------------------------------------------------------
14880b57cec5SDimitry Andric // KMP_DISP_NUM_BUFFERS
__kmp_stg_parse_disp_buffers(char const * name,char const * value,void * data)14890b57cec5SDimitry Andric static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
14900b57cec5SDimitry Andric void *data) {
14910b57cec5SDimitry Andric if (TCR_4(__kmp_init_serial)) {
14920b57cec5SDimitry Andric KMP_WARNING(EnvSerialWarn, name);
14930b57cec5SDimitry Andric return;
14940b57cec5SDimitry Andric } // read value before serial initialization only
1495fe6060f1SDimitry Andric __kmp_stg_parse_int(name, value, KMP_MIN_DISP_NUM_BUFF, KMP_MAX_DISP_NUM_BUFF,
1496fe6060f1SDimitry Andric &__kmp_dispatch_num_buffers);
14970b57cec5SDimitry Andric } // __kmp_stg_parse_disp_buffers
14980b57cec5SDimitry Andric
__kmp_stg_print_disp_buffers(kmp_str_buf_t * buffer,char const * name,void * data)14990b57cec5SDimitry Andric static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
15000b57cec5SDimitry Andric char const *name, void *data) {
15010b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
15020b57cec5SDimitry Andric } // __kmp_stg_print_disp_buffers
15030b57cec5SDimitry Andric
15040b57cec5SDimitry Andric #if KMP_NESTED_HOT_TEAMS
15050b57cec5SDimitry Andric // -----------------------------------------------------------------------------
15060b57cec5SDimitry Andric // KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
15070b57cec5SDimitry Andric
__kmp_stg_parse_hot_teams_level(char const * name,char const * value,void * data)15080b57cec5SDimitry Andric static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
15090b57cec5SDimitry Andric void *data) {
15100b57cec5SDimitry Andric if (TCR_4(__kmp_init_parallel)) {
15110b57cec5SDimitry Andric KMP_WARNING(EnvParallelWarn, name);
15120b57cec5SDimitry Andric return;
15130b57cec5SDimitry Andric } // read value before first parallel only
15140b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
15150b57cec5SDimitry Andric &__kmp_hot_teams_max_level);
15160b57cec5SDimitry Andric } // __kmp_stg_parse_hot_teams_level
15170b57cec5SDimitry Andric
__kmp_stg_print_hot_teams_level(kmp_str_buf_t * buffer,char const * name,void * data)15180b57cec5SDimitry Andric static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
15190b57cec5SDimitry Andric char const *name, void *data) {
15200b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
15210b57cec5SDimitry Andric } // __kmp_stg_print_hot_teams_level
15220b57cec5SDimitry Andric
__kmp_stg_parse_hot_teams_mode(char const * name,char const * value,void * data)15230b57cec5SDimitry Andric static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
15240b57cec5SDimitry Andric void *data) {
15250b57cec5SDimitry Andric if (TCR_4(__kmp_init_parallel)) {
15260b57cec5SDimitry Andric KMP_WARNING(EnvParallelWarn, name);
15270b57cec5SDimitry Andric return;
15280b57cec5SDimitry Andric } // read value before first parallel only
15290b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
15300b57cec5SDimitry Andric &__kmp_hot_teams_mode);
15310b57cec5SDimitry Andric } // __kmp_stg_parse_hot_teams_mode
15320b57cec5SDimitry Andric
__kmp_stg_print_hot_teams_mode(kmp_str_buf_t * buffer,char const * name,void * data)15330b57cec5SDimitry Andric static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
15340b57cec5SDimitry Andric char const *name, void *data) {
15350b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
15360b57cec5SDimitry Andric } // __kmp_stg_print_hot_teams_mode
15370b57cec5SDimitry Andric
15380b57cec5SDimitry Andric #endif // KMP_NESTED_HOT_TEAMS
15390b57cec5SDimitry Andric
15400b57cec5SDimitry Andric // -----------------------------------------------------------------------------
15410b57cec5SDimitry Andric // KMP_HANDLE_SIGNALS
15420b57cec5SDimitry Andric
15430b57cec5SDimitry Andric #if KMP_HANDLE_SIGNALS
15440b57cec5SDimitry Andric
__kmp_stg_parse_handle_signals(char const * name,char const * value,void * data)15450b57cec5SDimitry Andric static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
15460b57cec5SDimitry Andric void *data) {
15470b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
15480b57cec5SDimitry Andric } // __kmp_stg_parse_handle_signals
15490b57cec5SDimitry Andric
__kmp_stg_print_handle_signals(kmp_str_buf_t * buffer,char const * name,void * data)15500b57cec5SDimitry Andric static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
15510b57cec5SDimitry Andric char const *name, void *data) {
15520b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
15530b57cec5SDimitry Andric } // __kmp_stg_print_handle_signals
15540b57cec5SDimitry Andric
15550b57cec5SDimitry Andric #endif // KMP_HANDLE_SIGNALS
15560b57cec5SDimitry Andric
15570b57cec5SDimitry Andric // -----------------------------------------------------------------------------
15580b57cec5SDimitry Andric // KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
15590b57cec5SDimitry Andric
15600b57cec5SDimitry Andric #ifdef KMP_DEBUG
15610b57cec5SDimitry Andric
15620b57cec5SDimitry Andric #define KMP_STG_X_DEBUG(x) \
15630b57cec5SDimitry Andric static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
15640b57cec5SDimitry Andric void *data) { \
15650b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
15660b57cec5SDimitry Andric } /* __kmp_stg_parse_x_debug */ \
15670b57cec5SDimitry Andric static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
15680b57cec5SDimitry Andric char const *name, void *data) { \
15690b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
15700b57cec5SDimitry Andric } /* __kmp_stg_print_x_debug */
15710b57cec5SDimitry Andric
15720b57cec5SDimitry Andric KMP_STG_X_DEBUG(a)
KMP_STG_X_DEBUG(b)15730b57cec5SDimitry Andric KMP_STG_X_DEBUG(b)
15740b57cec5SDimitry Andric KMP_STG_X_DEBUG(c)
15750b57cec5SDimitry Andric KMP_STG_X_DEBUG(d)
15760b57cec5SDimitry Andric KMP_STG_X_DEBUG(e)
15770b57cec5SDimitry Andric KMP_STG_X_DEBUG(f)
15780b57cec5SDimitry Andric
15790b57cec5SDimitry Andric #undef KMP_STG_X_DEBUG
15800b57cec5SDimitry Andric
15810b57cec5SDimitry Andric static void __kmp_stg_parse_debug(char const *name, char const *value,
15820b57cec5SDimitry Andric void *data) {
15830b57cec5SDimitry Andric int debug = 0;
15840b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
15850b57cec5SDimitry Andric if (kmp_a_debug < debug) {
15860b57cec5SDimitry Andric kmp_a_debug = debug;
15870b57cec5SDimitry Andric }
15880b57cec5SDimitry Andric if (kmp_b_debug < debug) {
15890b57cec5SDimitry Andric kmp_b_debug = debug;
15900b57cec5SDimitry Andric }
15910b57cec5SDimitry Andric if (kmp_c_debug < debug) {
15920b57cec5SDimitry Andric kmp_c_debug = debug;
15930b57cec5SDimitry Andric }
15940b57cec5SDimitry Andric if (kmp_d_debug < debug) {
15950b57cec5SDimitry Andric kmp_d_debug = debug;
15960b57cec5SDimitry Andric }
15970b57cec5SDimitry Andric if (kmp_e_debug < debug) {
15980b57cec5SDimitry Andric kmp_e_debug = debug;
15990b57cec5SDimitry Andric }
16000b57cec5SDimitry Andric if (kmp_f_debug < debug) {
16010b57cec5SDimitry Andric kmp_f_debug = debug;
16020b57cec5SDimitry Andric }
16030b57cec5SDimitry Andric } // __kmp_stg_parse_debug
16040b57cec5SDimitry Andric
__kmp_stg_parse_debug_buf(char const * name,char const * value,void * data)16050b57cec5SDimitry Andric static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
16060b57cec5SDimitry Andric void *data) {
16070b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
16085f757f3fSDimitry Andric // !!! TODO: Move buffer initialization of this file! It may works
16090b57cec5SDimitry Andric // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
16100b57cec5SDimitry Andric // KMP_DEBUG_BUF_CHARS.
16110b57cec5SDimitry Andric if (__kmp_debug_buf) {
16120b57cec5SDimitry Andric int i;
16130b57cec5SDimitry Andric int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
16140b57cec5SDimitry Andric
16150b57cec5SDimitry Andric /* allocate and initialize all entries in debug buffer to empty */
16160b57cec5SDimitry Andric __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
16170b57cec5SDimitry Andric for (i = 0; i < elements; i += __kmp_debug_buf_chars)
16180b57cec5SDimitry Andric __kmp_debug_buffer[i] = '\0';
16190b57cec5SDimitry Andric
16200b57cec5SDimitry Andric __kmp_debug_count = 0;
16210b57cec5SDimitry Andric }
16220b57cec5SDimitry Andric K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
16230b57cec5SDimitry Andric } // __kmp_stg_parse_debug_buf
16240b57cec5SDimitry Andric
__kmp_stg_print_debug_buf(kmp_str_buf_t * buffer,char const * name,void * data)16250b57cec5SDimitry Andric static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
16260b57cec5SDimitry Andric void *data) {
16270b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
16280b57cec5SDimitry Andric } // __kmp_stg_print_debug_buf
16290b57cec5SDimitry Andric
__kmp_stg_parse_debug_buf_atomic(char const * name,char const * value,void * data)16300b57cec5SDimitry Andric static void __kmp_stg_parse_debug_buf_atomic(char const *name,
16310b57cec5SDimitry Andric char const *value, void *data) {
16320b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
16330b57cec5SDimitry Andric } // __kmp_stg_parse_debug_buf_atomic
16340b57cec5SDimitry Andric
__kmp_stg_print_debug_buf_atomic(kmp_str_buf_t * buffer,char const * name,void * data)16350b57cec5SDimitry Andric static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
16360b57cec5SDimitry Andric char const *name, void *data) {
16370b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
16380b57cec5SDimitry Andric } // __kmp_stg_print_debug_buf_atomic
16390b57cec5SDimitry Andric
__kmp_stg_parse_debug_buf_chars(char const * name,char const * value,void * data)16400b57cec5SDimitry Andric static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
16410b57cec5SDimitry Andric void *data) {
16420b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
16430b57cec5SDimitry Andric &__kmp_debug_buf_chars);
16440b57cec5SDimitry Andric } // __kmp_stg_debug_parse_buf_chars
16450b57cec5SDimitry Andric
__kmp_stg_print_debug_buf_chars(kmp_str_buf_t * buffer,char const * name,void * data)16460b57cec5SDimitry Andric static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
16470b57cec5SDimitry Andric char const *name, void *data) {
16480b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
16490b57cec5SDimitry Andric } // __kmp_stg_print_debug_buf_chars
16500b57cec5SDimitry Andric
__kmp_stg_parse_debug_buf_lines(char const * name,char const * value,void * data)16510b57cec5SDimitry Andric static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
16520b57cec5SDimitry Andric void *data) {
16530b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
16540b57cec5SDimitry Andric &__kmp_debug_buf_lines);
16550b57cec5SDimitry Andric } // __kmp_stg_parse_debug_buf_lines
16560b57cec5SDimitry Andric
__kmp_stg_print_debug_buf_lines(kmp_str_buf_t * buffer,char const * name,void * data)16570b57cec5SDimitry Andric static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
16580b57cec5SDimitry Andric char const *name, void *data) {
16590b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
16600b57cec5SDimitry Andric } // __kmp_stg_print_debug_buf_lines
16610b57cec5SDimitry Andric
__kmp_stg_parse_diag(char const * name,char const * value,void * data)16620b57cec5SDimitry Andric static void __kmp_stg_parse_diag(char const *name, char const *value,
16630b57cec5SDimitry Andric void *data) {
16640b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
16650b57cec5SDimitry Andric } // __kmp_stg_parse_diag
16660b57cec5SDimitry Andric
__kmp_stg_print_diag(kmp_str_buf_t * buffer,char const * name,void * data)16670b57cec5SDimitry Andric static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
16680b57cec5SDimitry Andric void *data) {
16690b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, kmp_diag);
16700b57cec5SDimitry Andric } // __kmp_stg_print_diag
16710b57cec5SDimitry Andric
16720b57cec5SDimitry Andric #endif // KMP_DEBUG
16730b57cec5SDimitry Andric
16740b57cec5SDimitry Andric // -----------------------------------------------------------------------------
16750b57cec5SDimitry Andric // KMP_ALIGN_ALLOC
16760b57cec5SDimitry Andric
__kmp_stg_parse_align_alloc(char const * name,char const * value,void * data)16770b57cec5SDimitry Andric static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
16780b57cec5SDimitry Andric void *data) {
16790b57cec5SDimitry Andric __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
16800b57cec5SDimitry Andric &__kmp_align_alloc, 1);
16810b57cec5SDimitry Andric } // __kmp_stg_parse_align_alloc
16820b57cec5SDimitry Andric
__kmp_stg_print_align_alloc(kmp_str_buf_t * buffer,char const * name,void * data)16830b57cec5SDimitry Andric static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
16840b57cec5SDimitry Andric void *data) {
16850b57cec5SDimitry Andric __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
16860b57cec5SDimitry Andric } // __kmp_stg_print_align_alloc
16870b57cec5SDimitry Andric
16880b57cec5SDimitry Andric // -----------------------------------------------------------------------------
16890b57cec5SDimitry Andric // KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
16900b57cec5SDimitry Andric
16910b57cec5SDimitry Andric // TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
16920b57cec5SDimitry Andric // parse and print functions, pass required info through data argument.
16930b57cec5SDimitry Andric
__kmp_stg_parse_barrier_branch_bit(char const * name,char const * value,void * data)16940b57cec5SDimitry Andric static void __kmp_stg_parse_barrier_branch_bit(char const *name,
16950b57cec5SDimitry Andric char const *value, void *data) {
16960b57cec5SDimitry Andric const char *var;
16970b57cec5SDimitry Andric
16980b57cec5SDimitry Andric /* ---------- Barrier branch bit control ------------ */
16990b57cec5SDimitry Andric for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
17000b57cec5SDimitry Andric var = __kmp_barrier_branch_bit_env_name[i];
17010b57cec5SDimitry Andric if ((strcmp(var, name) == 0) && (value != 0)) {
17020b57cec5SDimitry Andric char *comma;
17030b57cec5SDimitry Andric
17040b57cec5SDimitry Andric comma = CCAST(char *, strchr(value, ','));
17050b57cec5SDimitry Andric __kmp_barrier_gather_branch_bits[i] =
17060b57cec5SDimitry Andric (kmp_uint32)__kmp_str_to_int(value, ',');
17070b57cec5SDimitry Andric /* is there a specified release parameter? */
17080b57cec5SDimitry Andric if (comma == NULL) {
17090b57cec5SDimitry Andric __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
17100b57cec5SDimitry Andric } else {
17110b57cec5SDimitry Andric __kmp_barrier_release_branch_bits[i] =
17120b57cec5SDimitry Andric (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
17130b57cec5SDimitry Andric
17140b57cec5SDimitry Andric if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
17150b57cec5SDimitry Andric __kmp_msg(kmp_ms_warning,
17160b57cec5SDimitry Andric KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
17170b57cec5SDimitry Andric __kmp_msg_null);
17180b57cec5SDimitry Andric __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
17190b57cec5SDimitry Andric }
17200b57cec5SDimitry Andric }
17210b57cec5SDimitry Andric if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
17220b57cec5SDimitry Andric KMP_WARNING(BarrGatherValueInvalid, name, value);
17230b57cec5SDimitry Andric KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
17240b57cec5SDimitry Andric __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
17250b57cec5SDimitry Andric }
17260b57cec5SDimitry Andric }
17270b57cec5SDimitry Andric K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
17280b57cec5SDimitry Andric __kmp_barrier_gather_branch_bits[i],
17290b57cec5SDimitry Andric __kmp_barrier_release_branch_bits[i]))
17300b57cec5SDimitry Andric }
17310b57cec5SDimitry Andric } // __kmp_stg_parse_barrier_branch_bit
17320b57cec5SDimitry Andric
__kmp_stg_print_barrier_branch_bit(kmp_str_buf_t * buffer,char const * name,void * data)17330b57cec5SDimitry Andric static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
17340b57cec5SDimitry Andric char const *name, void *data) {
17350b57cec5SDimitry Andric const char *var;
17360b57cec5SDimitry Andric for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
17370b57cec5SDimitry Andric var = __kmp_barrier_branch_bit_env_name[i];
17380b57cec5SDimitry Andric if (strcmp(var, name) == 0) {
17390b57cec5SDimitry Andric if (__kmp_env_format) {
17400b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
17410b57cec5SDimitry Andric } else {
17420b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s='",
17430b57cec5SDimitry Andric __kmp_barrier_branch_bit_env_name[i]);
17440b57cec5SDimitry Andric }
17450b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%d,%d'\n",
17460b57cec5SDimitry Andric __kmp_barrier_gather_branch_bits[i],
17470b57cec5SDimitry Andric __kmp_barrier_release_branch_bits[i]);
17480b57cec5SDimitry Andric }
17490b57cec5SDimitry Andric }
17500b57cec5SDimitry Andric } // __kmp_stg_print_barrier_branch_bit
17510b57cec5SDimitry Andric
17520b57cec5SDimitry Andric // ----------------------------------------------------------------------------
17530b57cec5SDimitry Andric // KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
17540b57cec5SDimitry Andric // KMP_REDUCTION_BARRIER_PATTERN
17550b57cec5SDimitry Andric
17560b57cec5SDimitry Andric // TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
17570b57cec5SDimitry Andric // print functions, pass required data to functions through data argument.
17580b57cec5SDimitry Andric
__kmp_stg_parse_barrier_pattern(char const * name,char const * value,void * data)17590b57cec5SDimitry Andric static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
17600b57cec5SDimitry Andric void *data) {
17610b57cec5SDimitry Andric const char *var;
17620b57cec5SDimitry Andric /* ---------- Barrier method control ------------ */
17630b57cec5SDimitry Andric
1764349cc55cSDimitry Andric static int dist_req = 0, non_dist_req = 0;
1765349cc55cSDimitry Andric static bool warn = 1;
17660b57cec5SDimitry Andric for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
17670b57cec5SDimitry Andric var = __kmp_barrier_pattern_env_name[i];
17680b57cec5SDimitry Andric
17690b57cec5SDimitry Andric if ((strcmp(var, name) == 0) && (value != 0)) {
17700b57cec5SDimitry Andric int j;
17710b57cec5SDimitry Andric char *comma = CCAST(char *, strchr(value, ','));
17720b57cec5SDimitry Andric
17730b57cec5SDimitry Andric /* handle first parameter: gather pattern */
17740b57cec5SDimitry Andric for (j = bp_linear_bar; j < bp_last_bar; j++) {
17750b57cec5SDimitry Andric if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
17760b57cec5SDimitry Andric ',')) {
1777349cc55cSDimitry Andric if (j == bp_dist_bar) {
1778349cc55cSDimitry Andric dist_req++;
1779349cc55cSDimitry Andric } else {
1780349cc55cSDimitry Andric non_dist_req++;
1781349cc55cSDimitry Andric }
17820b57cec5SDimitry Andric __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
17830b57cec5SDimitry Andric break;
17840b57cec5SDimitry Andric }
17850b57cec5SDimitry Andric }
17860b57cec5SDimitry Andric if (j == bp_last_bar) {
17870b57cec5SDimitry Andric KMP_WARNING(BarrGatherValueInvalid, name, value);
17880b57cec5SDimitry Andric KMP_INFORM(Using_str_Value, name,
17890b57cec5SDimitry Andric __kmp_barrier_pattern_name[bp_linear_bar]);
17900b57cec5SDimitry Andric }
17910b57cec5SDimitry Andric
17920b57cec5SDimitry Andric /* handle second parameter: release pattern */
17930b57cec5SDimitry Andric if (comma != NULL) {
17940b57cec5SDimitry Andric for (j = bp_linear_bar; j < bp_last_bar; j++) {
17950b57cec5SDimitry Andric if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1796349cc55cSDimitry Andric if (j == bp_dist_bar) {
1797349cc55cSDimitry Andric dist_req++;
1798349cc55cSDimitry Andric } else {
1799349cc55cSDimitry Andric non_dist_req++;
1800349cc55cSDimitry Andric }
18010b57cec5SDimitry Andric __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
18020b57cec5SDimitry Andric break;
18030b57cec5SDimitry Andric }
18040b57cec5SDimitry Andric }
18050b57cec5SDimitry Andric if (j == bp_last_bar) {
18060b57cec5SDimitry Andric __kmp_msg(kmp_ms_warning,
18070b57cec5SDimitry Andric KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
18080b57cec5SDimitry Andric __kmp_msg_null);
18090b57cec5SDimitry Andric KMP_INFORM(Using_str_Value, name,
18100b57cec5SDimitry Andric __kmp_barrier_pattern_name[bp_linear_bar]);
18110b57cec5SDimitry Andric }
18120b57cec5SDimitry Andric }
18130b57cec5SDimitry Andric }
18140b57cec5SDimitry Andric }
1815349cc55cSDimitry Andric if (dist_req != 0) {
1816349cc55cSDimitry Andric // set all barriers to dist
1817349cc55cSDimitry Andric if ((non_dist_req != 0) && warn) {
1818349cc55cSDimitry Andric KMP_INFORM(BarrierPatternOverride, name,
1819349cc55cSDimitry Andric __kmp_barrier_pattern_name[bp_dist_bar]);
1820349cc55cSDimitry Andric warn = 0;
1821349cc55cSDimitry Andric }
1822349cc55cSDimitry Andric for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1823349cc55cSDimitry Andric if (__kmp_barrier_release_pattern[i] != bp_dist_bar)
1824349cc55cSDimitry Andric __kmp_barrier_release_pattern[i] = bp_dist_bar;
1825349cc55cSDimitry Andric if (__kmp_barrier_gather_pattern[i] != bp_dist_bar)
1826349cc55cSDimitry Andric __kmp_barrier_gather_pattern[i] = bp_dist_bar;
1827349cc55cSDimitry Andric }
1828349cc55cSDimitry Andric }
18290b57cec5SDimitry Andric } // __kmp_stg_parse_barrier_pattern
18300b57cec5SDimitry Andric
__kmp_stg_print_barrier_pattern(kmp_str_buf_t * buffer,char const * name,void * data)18310b57cec5SDimitry Andric static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
18320b57cec5SDimitry Andric char const *name, void *data) {
18330b57cec5SDimitry Andric const char *var;
18340b57cec5SDimitry Andric for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
18350b57cec5SDimitry Andric var = __kmp_barrier_pattern_env_name[i];
18360b57cec5SDimitry Andric if (strcmp(var, name) == 0) {
18370b57cec5SDimitry Andric int j = __kmp_barrier_gather_pattern[i];
18380b57cec5SDimitry Andric int k = __kmp_barrier_release_pattern[i];
18390b57cec5SDimitry Andric if (__kmp_env_format) {
18400b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
18410b57cec5SDimitry Andric } else {
18420b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s='",
18430b57cec5SDimitry Andric __kmp_barrier_pattern_env_name[i]);
18440b57cec5SDimitry Andric }
1845349cc55cSDimitry Andric KMP_DEBUG_ASSERT(j < bp_last_bar && k < bp_last_bar);
18460b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
18470b57cec5SDimitry Andric __kmp_barrier_pattern_name[k]);
18480b57cec5SDimitry Andric }
18490b57cec5SDimitry Andric }
18500b57cec5SDimitry Andric } // __kmp_stg_print_barrier_pattern
18510b57cec5SDimitry Andric
18520b57cec5SDimitry Andric // -----------------------------------------------------------------------------
18530b57cec5SDimitry Andric // KMP_ABORT_DELAY
18540b57cec5SDimitry Andric
__kmp_stg_parse_abort_delay(char const * name,char const * value,void * data)18550b57cec5SDimitry Andric static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
18560b57cec5SDimitry Andric void *data) {
18570b57cec5SDimitry Andric // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
18580b57cec5SDimitry Andric // milliseconds.
18590b57cec5SDimitry Andric int delay = __kmp_abort_delay / 1000;
18600b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
18610b57cec5SDimitry Andric __kmp_abort_delay = delay * 1000;
18620b57cec5SDimitry Andric } // __kmp_stg_parse_abort_delay
18630b57cec5SDimitry Andric
__kmp_stg_print_abort_delay(kmp_str_buf_t * buffer,char const * name,void * data)18640b57cec5SDimitry Andric static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
18650b57cec5SDimitry Andric void *data) {
18660b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
18670b57cec5SDimitry Andric } // __kmp_stg_print_abort_delay
18680b57cec5SDimitry Andric
18690b57cec5SDimitry Andric // -----------------------------------------------------------------------------
18700b57cec5SDimitry Andric // KMP_CPUINFO_FILE
18710b57cec5SDimitry Andric
__kmp_stg_parse_cpuinfo_file(char const * name,char const * value,void * data)18720b57cec5SDimitry Andric static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
18730b57cec5SDimitry Andric void *data) {
18740b57cec5SDimitry Andric #if KMP_AFFINITY_SUPPORTED
18750b57cec5SDimitry Andric __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
18760b57cec5SDimitry Andric K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
18770b57cec5SDimitry Andric #endif
18780b57cec5SDimitry Andric } //__kmp_stg_parse_cpuinfo_file
18790b57cec5SDimitry Andric
__kmp_stg_print_cpuinfo_file(kmp_str_buf_t * buffer,char const * name,void * data)18800b57cec5SDimitry Andric static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
18810b57cec5SDimitry Andric char const *name, void *data) {
18820b57cec5SDimitry Andric #if KMP_AFFINITY_SUPPORTED
18830b57cec5SDimitry Andric if (__kmp_env_format) {
18840b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME;
18850b57cec5SDimitry Andric } else {
18860b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s", name);
18870b57cec5SDimitry Andric }
18880b57cec5SDimitry Andric if (__kmp_cpuinfo_file) {
18890b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
18900b57cec5SDimitry Andric } else {
18910b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
18920b57cec5SDimitry Andric }
18930b57cec5SDimitry Andric #endif
18940b57cec5SDimitry Andric } //__kmp_stg_print_cpuinfo_file
18950b57cec5SDimitry Andric
18960b57cec5SDimitry Andric // -----------------------------------------------------------------------------
18970b57cec5SDimitry Andric // KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
18980b57cec5SDimitry Andric
__kmp_stg_parse_force_reduction(char const * name,char const * value,void * data)18990b57cec5SDimitry Andric static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
19000b57cec5SDimitry Andric void *data) {
19010b57cec5SDimitry Andric kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
19020b57cec5SDimitry Andric int rc;
19030b57cec5SDimitry Andric
19040b57cec5SDimitry Andric rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
19050b57cec5SDimitry Andric if (rc) {
19060b57cec5SDimitry Andric return;
19070b57cec5SDimitry Andric }
19080b57cec5SDimitry Andric if (reduction->force) {
19090b57cec5SDimitry Andric if (value != 0) {
19100b57cec5SDimitry Andric if (__kmp_str_match("critical", 0, value))
19110b57cec5SDimitry Andric __kmp_force_reduction_method = critical_reduce_block;
19120b57cec5SDimitry Andric else if (__kmp_str_match("atomic", 0, value))
19130b57cec5SDimitry Andric __kmp_force_reduction_method = atomic_reduce_block;
19140b57cec5SDimitry Andric else if (__kmp_str_match("tree", 0, value))
19150b57cec5SDimitry Andric __kmp_force_reduction_method = tree_reduce_block;
19160b57cec5SDimitry Andric else {
19170b57cec5SDimitry Andric KMP_FATAL(UnknownForceReduction, name, value);
19180b57cec5SDimitry Andric }
19190b57cec5SDimitry Andric }
19200b57cec5SDimitry Andric } else {
19210b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
19220b57cec5SDimitry Andric if (__kmp_determ_red) {
19230b57cec5SDimitry Andric __kmp_force_reduction_method = tree_reduce_block;
19240b57cec5SDimitry Andric } else {
19250b57cec5SDimitry Andric __kmp_force_reduction_method = reduction_method_not_defined;
19260b57cec5SDimitry Andric }
19270b57cec5SDimitry Andric }
19280b57cec5SDimitry Andric K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
19290b57cec5SDimitry Andric __kmp_force_reduction_method));
19300b57cec5SDimitry Andric } // __kmp_stg_parse_force_reduction
19310b57cec5SDimitry Andric
__kmp_stg_print_force_reduction(kmp_str_buf_t * buffer,char const * name,void * data)19320b57cec5SDimitry Andric static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
19330b57cec5SDimitry Andric char const *name, void *data) {
19340b57cec5SDimitry Andric
19350b57cec5SDimitry Andric kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
19360b57cec5SDimitry Andric if (reduction->force) {
19370b57cec5SDimitry Andric if (__kmp_force_reduction_method == critical_reduce_block) {
19380b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "critical");
19390b57cec5SDimitry Andric } else if (__kmp_force_reduction_method == atomic_reduce_block) {
19400b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "atomic");
19410b57cec5SDimitry Andric } else if (__kmp_force_reduction_method == tree_reduce_block) {
19420b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "tree");
19430b57cec5SDimitry Andric } else {
19440b57cec5SDimitry Andric if (__kmp_env_format) {
19450b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME;
19460b57cec5SDimitry Andric } else {
19470b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s", name);
19480b57cec5SDimitry Andric }
19490b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
19500b57cec5SDimitry Andric }
19510b57cec5SDimitry Andric } else {
19520b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
19530b57cec5SDimitry Andric }
19540b57cec5SDimitry Andric
19550b57cec5SDimitry Andric } // __kmp_stg_print_force_reduction
19560b57cec5SDimitry Andric
19570b57cec5SDimitry Andric // -----------------------------------------------------------------------------
19580b57cec5SDimitry Andric // KMP_STORAGE_MAP
19590b57cec5SDimitry Andric
__kmp_stg_parse_storage_map(char const * name,char const * value,void * data)19600b57cec5SDimitry Andric static void __kmp_stg_parse_storage_map(char const *name, char const *value,
19610b57cec5SDimitry Andric void *data) {
19620b57cec5SDimitry Andric if (__kmp_str_match("verbose", 1, value)) {
19630b57cec5SDimitry Andric __kmp_storage_map = TRUE;
19640b57cec5SDimitry Andric __kmp_storage_map_verbose = TRUE;
19650b57cec5SDimitry Andric __kmp_storage_map_verbose_specified = TRUE;
19660b57cec5SDimitry Andric
19670b57cec5SDimitry Andric } else {
19680b57cec5SDimitry Andric __kmp_storage_map_verbose = FALSE;
19690b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
19700b57cec5SDimitry Andric }
19710b57cec5SDimitry Andric } // __kmp_stg_parse_storage_map
19720b57cec5SDimitry Andric
__kmp_stg_print_storage_map(kmp_str_buf_t * buffer,char const * name,void * data)19730b57cec5SDimitry Andric static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
19740b57cec5SDimitry Andric void *data) {
19750b57cec5SDimitry Andric if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
19760b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "verbose");
19770b57cec5SDimitry Andric } else {
19780b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
19790b57cec5SDimitry Andric }
19800b57cec5SDimitry Andric } // __kmp_stg_print_storage_map
19810b57cec5SDimitry Andric
19820b57cec5SDimitry Andric // -----------------------------------------------------------------------------
19830b57cec5SDimitry Andric // KMP_ALL_THREADPRIVATE
19840b57cec5SDimitry Andric
__kmp_stg_parse_all_threadprivate(char const * name,char const * value,void * data)19850b57cec5SDimitry Andric static void __kmp_stg_parse_all_threadprivate(char const *name,
19860b57cec5SDimitry Andric char const *value, void *data) {
19870b57cec5SDimitry Andric __kmp_stg_parse_int(name, value,
19880b57cec5SDimitry Andric __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
19890b57cec5SDimitry Andric __kmp_max_nth, &__kmp_tp_capacity);
19900b57cec5SDimitry Andric } // __kmp_stg_parse_all_threadprivate
19910b57cec5SDimitry Andric
__kmp_stg_print_all_threadprivate(kmp_str_buf_t * buffer,char const * name,void * data)19920b57cec5SDimitry Andric static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
19930b57cec5SDimitry Andric char const *name, void *data) {
19940b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
19950b57cec5SDimitry Andric }
19960b57cec5SDimitry Andric
19970b57cec5SDimitry Andric // -----------------------------------------------------------------------------
19980b57cec5SDimitry Andric // KMP_FOREIGN_THREADS_THREADPRIVATE
19990b57cec5SDimitry Andric
__kmp_stg_parse_foreign_threads_threadprivate(char const * name,char const * value,void * data)20000b57cec5SDimitry Andric static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
20010b57cec5SDimitry Andric char const *value,
20020b57cec5SDimitry Andric void *data) {
20030b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
20040b57cec5SDimitry Andric } // __kmp_stg_parse_foreign_threads_threadprivate
20050b57cec5SDimitry Andric
__kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t * buffer,char const * name,void * data)20060b57cec5SDimitry Andric static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
20070b57cec5SDimitry Andric char const *name,
20080b57cec5SDimitry Andric void *data) {
20090b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
20100b57cec5SDimitry Andric } // __kmp_stg_print_foreign_threads_threadprivate
20110b57cec5SDimitry Andric
20120b57cec5SDimitry Andric // -----------------------------------------------------------------------------
20130b57cec5SDimitry Andric // KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
20140b57cec5SDimitry Andric
20155f757f3fSDimitry Andric static inline const char *
__kmp_hw_get_core_type_keyword(kmp_hw_core_type_t type)20165f757f3fSDimitry Andric __kmp_hw_get_core_type_keyword(kmp_hw_core_type_t type) {
20175f757f3fSDimitry Andric switch (type) {
20185f757f3fSDimitry Andric case KMP_HW_CORE_TYPE_UNKNOWN:
20197a6dacacSDimitry Andric case KMP_HW_MAX_NUM_CORE_TYPES:
20205f757f3fSDimitry Andric return "unknown";
20215f757f3fSDimitry Andric #if KMP_ARCH_X86 || KMP_ARCH_X86_64
20225f757f3fSDimitry Andric case KMP_HW_CORE_TYPE_ATOM:
20235f757f3fSDimitry Andric return "intel_atom";
20245f757f3fSDimitry Andric case KMP_HW_CORE_TYPE_CORE:
20255f757f3fSDimitry Andric return "intel_core";
20265f757f3fSDimitry Andric #endif
20275f757f3fSDimitry Andric }
20287a6dacacSDimitry Andric KMP_ASSERT2(false, "Unhandled kmp_hw_core_type_t enumeration");
20297a6dacacSDimitry Andric KMP_BUILTIN_UNREACHABLE;
20305f757f3fSDimitry Andric }
20315f757f3fSDimitry Andric
20320b57cec5SDimitry Andric #if KMP_AFFINITY_SUPPORTED
20330b57cec5SDimitry Andric // Parse the proc id list. Return TRUE if successful, FALSE otherwise.
__kmp_parse_affinity_proc_id_list(const char * var,const char * env,const char ** nextEnv,char ** proclist)20340b57cec5SDimitry Andric static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
20350b57cec5SDimitry Andric const char **nextEnv,
20360b57cec5SDimitry Andric char **proclist) {
20370b57cec5SDimitry Andric const char *scan = env;
20380b57cec5SDimitry Andric const char *next = scan;
20390b57cec5SDimitry Andric int empty = TRUE;
20400b57cec5SDimitry Andric
20410b57cec5SDimitry Andric *proclist = NULL;
20420b57cec5SDimitry Andric
20430b57cec5SDimitry Andric for (;;) {
20440b57cec5SDimitry Andric int start, end, stride;
20450b57cec5SDimitry Andric
20460b57cec5SDimitry Andric SKIP_WS(scan);
20470b57cec5SDimitry Andric next = scan;
20480b57cec5SDimitry Andric if (*next == '\0') {
20490b57cec5SDimitry Andric break;
20500b57cec5SDimitry Andric }
20510b57cec5SDimitry Andric
20520b57cec5SDimitry Andric if (*next == '{') {
20530b57cec5SDimitry Andric int num;
20540b57cec5SDimitry Andric next++; // skip '{'
20550b57cec5SDimitry Andric SKIP_WS(next);
20560b57cec5SDimitry Andric scan = next;
20570b57cec5SDimitry Andric
20580b57cec5SDimitry Andric // Read the first integer in the set.
20590b57cec5SDimitry Andric if ((*next < '0') || (*next > '9')) {
20600b57cec5SDimitry Andric KMP_WARNING(AffSyntaxError, var);
20610b57cec5SDimitry Andric return FALSE;
20620b57cec5SDimitry Andric }
20630b57cec5SDimitry Andric SKIP_DIGITS(next);
20640b57cec5SDimitry Andric num = __kmp_str_to_int(scan, *next);
20650b57cec5SDimitry Andric KMP_ASSERT(num >= 0);
20660b57cec5SDimitry Andric
20670b57cec5SDimitry Andric for (;;) {
20680b57cec5SDimitry Andric // Check for end of set.
20690b57cec5SDimitry Andric SKIP_WS(next);
20700b57cec5SDimitry Andric if (*next == '}') {
20710b57cec5SDimitry Andric next++; // skip '}'
20720b57cec5SDimitry Andric break;
20730b57cec5SDimitry Andric }
20740b57cec5SDimitry Andric
20750b57cec5SDimitry Andric // Skip optional comma.
20760b57cec5SDimitry Andric if (*next == ',') {
20770b57cec5SDimitry Andric next++;
20780b57cec5SDimitry Andric }
20790b57cec5SDimitry Andric SKIP_WS(next);
20800b57cec5SDimitry Andric
20810b57cec5SDimitry Andric // Read the next integer in the set.
20820b57cec5SDimitry Andric scan = next;
20830b57cec5SDimitry Andric if ((*next < '0') || (*next > '9')) {
20840b57cec5SDimitry Andric KMP_WARNING(AffSyntaxError, var);
20850b57cec5SDimitry Andric return FALSE;
20860b57cec5SDimitry Andric }
20870b57cec5SDimitry Andric
20880b57cec5SDimitry Andric SKIP_DIGITS(next);
20890b57cec5SDimitry Andric num = __kmp_str_to_int(scan, *next);
20900b57cec5SDimitry Andric KMP_ASSERT(num >= 0);
20910b57cec5SDimitry Andric }
20920b57cec5SDimitry Andric empty = FALSE;
20930b57cec5SDimitry Andric
20940b57cec5SDimitry Andric SKIP_WS(next);
20950b57cec5SDimitry Andric if (*next == ',') {
20960b57cec5SDimitry Andric next++;
20970b57cec5SDimitry Andric }
20980b57cec5SDimitry Andric scan = next;
20990b57cec5SDimitry Andric continue;
21000b57cec5SDimitry Andric }
21010b57cec5SDimitry Andric
21020b57cec5SDimitry Andric // Next character is not an integer => end of list
21030b57cec5SDimitry Andric if ((*next < '0') || (*next > '9')) {
21040b57cec5SDimitry Andric if (empty) {
21050b57cec5SDimitry Andric KMP_WARNING(AffSyntaxError, var);
21060b57cec5SDimitry Andric return FALSE;
21070b57cec5SDimitry Andric }
21080b57cec5SDimitry Andric break;
21090b57cec5SDimitry Andric }
21100b57cec5SDimitry Andric
21110b57cec5SDimitry Andric // Read the first integer.
21120b57cec5SDimitry Andric SKIP_DIGITS(next);
21130b57cec5SDimitry Andric start = __kmp_str_to_int(scan, *next);
21140b57cec5SDimitry Andric KMP_ASSERT(start >= 0);
21150b57cec5SDimitry Andric SKIP_WS(next);
21160b57cec5SDimitry Andric
21170b57cec5SDimitry Andric // If this isn't a range, then go on.
21180b57cec5SDimitry Andric if (*next != '-') {
21190b57cec5SDimitry Andric empty = FALSE;
21200b57cec5SDimitry Andric
21210b57cec5SDimitry Andric // Skip optional comma.
21220b57cec5SDimitry Andric if (*next == ',') {
21230b57cec5SDimitry Andric next++;
21240b57cec5SDimitry Andric }
21250b57cec5SDimitry Andric scan = next;
21260b57cec5SDimitry Andric continue;
21270b57cec5SDimitry Andric }
21280b57cec5SDimitry Andric
21290b57cec5SDimitry Andric // This is a range. Skip over the '-' and read in the 2nd int.
21300b57cec5SDimitry Andric next++; // skip '-'
21310b57cec5SDimitry Andric SKIP_WS(next);
21320b57cec5SDimitry Andric scan = next;
21330b57cec5SDimitry Andric if ((*next < '0') || (*next > '9')) {
21340b57cec5SDimitry Andric KMP_WARNING(AffSyntaxError, var);
21350b57cec5SDimitry Andric return FALSE;
21360b57cec5SDimitry Andric }
21370b57cec5SDimitry Andric SKIP_DIGITS(next);
21380b57cec5SDimitry Andric end = __kmp_str_to_int(scan, *next);
21390b57cec5SDimitry Andric KMP_ASSERT(end >= 0);
21400b57cec5SDimitry Andric
21410b57cec5SDimitry Andric // Check for a stride parameter
21420b57cec5SDimitry Andric stride = 1;
21430b57cec5SDimitry Andric SKIP_WS(next);
21440b57cec5SDimitry Andric if (*next == ':') {
21450b57cec5SDimitry Andric // A stride is specified. Skip over the ':" and read the 3rd int.
21460b57cec5SDimitry Andric int sign = +1;
21470b57cec5SDimitry Andric next++; // skip ':'
21480b57cec5SDimitry Andric SKIP_WS(next);
21490b57cec5SDimitry Andric scan = next;
21500b57cec5SDimitry Andric if (*next == '-') {
21510b57cec5SDimitry Andric sign = -1;
21520b57cec5SDimitry Andric next++;
21530b57cec5SDimitry Andric SKIP_WS(next);
21540b57cec5SDimitry Andric scan = next;
21550b57cec5SDimitry Andric }
21560b57cec5SDimitry Andric if ((*next < '0') || (*next > '9')) {
21570b57cec5SDimitry Andric KMP_WARNING(AffSyntaxError, var);
21580b57cec5SDimitry Andric return FALSE;
21590b57cec5SDimitry Andric }
21600b57cec5SDimitry Andric SKIP_DIGITS(next);
21610b57cec5SDimitry Andric stride = __kmp_str_to_int(scan, *next);
21620b57cec5SDimitry Andric KMP_ASSERT(stride >= 0);
21630b57cec5SDimitry Andric stride *= sign;
21640b57cec5SDimitry Andric }
21650b57cec5SDimitry Andric
21660b57cec5SDimitry Andric // Do some range checks.
21670b57cec5SDimitry Andric if (stride == 0) {
21680b57cec5SDimitry Andric KMP_WARNING(AffZeroStride, var);
21690b57cec5SDimitry Andric return FALSE;
21700b57cec5SDimitry Andric }
21710b57cec5SDimitry Andric if (stride > 0) {
21720b57cec5SDimitry Andric if (start > end) {
21730b57cec5SDimitry Andric KMP_WARNING(AffStartGreaterEnd, var, start, end);
21740b57cec5SDimitry Andric return FALSE;
21750b57cec5SDimitry Andric }
21760b57cec5SDimitry Andric } else {
21770b57cec5SDimitry Andric if (start < end) {
21780b57cec5SDimitry Andric KMP_WARNING(AffStrideLessZero, var, start, end);
21790b57cec5SDimitry Andric return FALSE;
21800b57cec5SDimitry Andric }
21810b57cec5SDimitry Andric }
21820b57cec5SDimitry Andric if ((end - start) / stride > 65536) {
21830b57cec5SDimitry Andric KMP_WARNING(AffRangeTooBig, var, end, start, stride);
21840b57cec5SDimitry Andric return FALSE;
21850b57cec5SDimitry Andric }
21860b57cec5SDimitry Andric
21870b57cec5SDimitry Andric empty = FALSE;
21880b57cec5SDimitry Andric
21890b57cec5SDimitry Andric // Skip optional comma.
21900b57cec5SDimitry Andric SKIP_WS(next);
21910b57cec5SDimitry Andric if (*next == ',') {
21920b57cec5SDimitry Andric next++;
21930b57cec5SDimitry Andric }
21940b57cec5SDimitry Andric scan = next;
21950b57cec5SDimitry Andric }
21960b57cec5SDimitry Andric
21970b57cec5SDimitry Andric *nextEnv = next;
21980b57cec5SDimitry Andric
21990b57cec5SDimitry Andric {
2200e8d8bef9SDimitry Andric ptrdiff_t len = next - env;
22010b57cec5SDimitry Andric char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
22020b57cec5SDimitry Andric KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
22030b57cec5SDimitry Andric retlist[len] = '\0';
22040b57cec5SDimitry Andric *proclist = retlist;
22050b57cec5SDimitry Andric }
22060b57cec5SDimitry Andric return TRUE;
22070b57cec5SDimitry Andric }
22080b57cec5SDimitry Andric
22090b57cec5SDimitry Andric // If KMP_AFFINITY is specified without a type, then
22100b57cec5SDimitry Andric // __kmp_affinity_notype should point to its setting.
22110b57cec5SDimitry Andric static kmp_setting_t *__kmp_affinity_notype = NULL;
22120b57cec5SDimitry Andric
__kmp_parse_affinity_env(char const * name,char const * value,kmp_affinity_t * out_affinity)22130b57cec5SDimitry Andric static void __kmp_parse_affinity_env(char const *name, char const *value,
2214bdd1243dSDimitry Andric kmp_affinity_t *out_affinity) {
22150b57cec5SDimitry Andric char *buffer = NULL; // Copy of env var value.
22160b57cec5SDimitry Andric char *buf = NULL; // Buffer for strtok_r() function.
22170b57cec5SDimitry Andric char *next = NULL; // end of token / start of next.
22180b57cec5SDimitry Andric const char *start; // start of current token (for err msgs)
22190b57cec5SDimitry Andric int count = 0; // Counter of parsed integer numbers.
22200b57cec5SDimitry Andric int number[2]; // Parsed numbers.
22210b57cec5SDimitry Andric
22220b57cec5SDimitry Andric // Guards.
22230b57cec5SDimitry Andric int type = 0;
22240b57cec5SDimitry Andric int proclist = 0;
22250b57cec5SDimitry Andric int verbose = 0;
22260b57cec5SDimitry Andric int warnings = 0;
22270b57cec5SDimitry Andric int respect = 0;
22280b57cec5SDimitry Andric int gran = 0;
22290b57cec5SDimitry Andric int dups = 0;
2230fcaf7f86SDimitry Andric int reset = 0;
2231fe6060f1SDimitry Andric bool set = false;
22320b57cec5SDimitry Andric
22330b57cec5SDimitry Andric KMP_ASSERT(value != NULL);
22340b57cec5SDimitry Andric
22350b57cec5SDimitry Andric if (TCR_4(__kmp_init_middle)) {
22360b57cec5SDimitry Andric KMP_WARNING(EnvMiddleWarn, name);
22370b57cec5SDimitry Andric __kmp_env_toPrint(name, 0);
22380b57cec5SDimitry Andric return;
22390b57cec5SDimitry Andric }
22400b57cec5SDimitry Andric __kmp_env_toPrint(name, 1);
22410b57cec5SDimitry Andric
22420b57cec5SDimitry Andric buffer =
22430b57cec5SDimitry Andric __kmp_str_format("%s", value); // Copy env var to keep original intact.
22440b57cec5SDimitry Andric buf = buffer;
22450b57cec5SDimitry Andric SKIP_WS(buf);
22460b57cec5SDimitry Andric
22470b57cec5SDimitry Andric // Helper macros.
22480b57cec5SDimitry Andric
22490b57cec5SDimitry Andric // If we see a parse error, emit a warning and scan to the next ",".
22500b57cec5SDimitry Andric //
22510b57cec5SDimitry Andric // FIXME - there's got to be a better way to print an error
22525ffd83dbSDimitry Andric // message, hopefully without overwriting peices of buf.
22530b57cec5SDimitry Andric #define EMIT_WARN(skip, errlist) \
22540b57cec5SDimitry Andric { \
22550b57cec5SDimitry Andric char ch; \
22560b57cec5SDimitry Andric if (skip) { \
22570b57cec5SDimitry Andric SKIP_TO(next, ','); \
22580b57cec5SDimitry Andric } \
22590b57cec5SDimitry Andric ch = *next; \
22600b57cec5SDimitry Andric *next = '\0'; \
22610b57cec5SDimitry Andric KMP_WARNING errlist; \
22620b57cec5SDimitry Andric *next = ch; \
22630b57cec5SDimitry Andric if (skip) { \
22640b57cec5SDimitry Andric if (ch == ',') \
22650b57cec5SDimitry Andric next++; \
22660b57cec5SDimitry Andric } \
22670b57cec5SDimitry Andric buf = next; \
22680b57cec5SDimitry Andric }
22690b57cec5SDimitry Andric
22700b57cec5SDimitry Andric #define _set_param(_guard, _var, _val) \
22710b57cec5SDimitry Andric { \
22720b57cec5SDimitry Andric if (_guard == 0) { \
22730b57cec5SDimitry Andric _var = _val; \
22740b57cec5SDimitry Andric } else { \
22750b57cec5SDimitry Andric EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
22760b57cec5SDimitry Andric } \
22770b57cec5SDimitry Andric ++_guard; \
22780b57cec5SDimitry Andric }
22790b57cec5SDimitry Andric
2280bdd1243dSDimitry Andric #define set_type(val) _set_param(type, out_affinity->type, val)
2281bdd1243dSDimitry Andric #define set_verbose(val) _set_param(verbose, out_affinity->flags.verbose, val)
2282bdd1243dSDimitry Andric #define set_warnings(val) \
2283bdd1243dSDimitry Andric _set_param(warnings, out_affinity->flags.warnings, val)
2284bdd1243dSDimitry Andric #define set_respect(val) _set_param(respect, out_affinity->flags.respect, val)
2285bdd1243dSDimitry Andric #define set_dups(val) _set_param(dups, out_affinity->flags.dups, val)
2286bdd1243dSDimitry Andric #define set_proclist(val) _set_param(proclist, out_affinity->proclist, val)
2287bdd1243dSDimitry Andric #define set_reset(val) _set_param(reset, out_affinity->flags.reset, val)
22880b57cec5SDimitry Andric
22890b57cec5SDimitry Andric #define set_gran(val, levels) \
22900b57cec5SDimitry Andric { \
22910b57cec5SDimitry Andric if (gran == 0) { \
2292bdd1243dSDimitry Andric out_affinity->gran = val; \
2293bdd1243dSDimitry Andric out_affinity->gran_levels = levels; \
22940b57cec5SDimitry Andric } else { \
22950b57cec5SDimitry Andric EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
22960b57cec5SDimitry Andric } \
22970b57cec5SDimitry Andric ++gran; \
22980b57cec5SDimitry Andric }
22990b57cec5SDimitry Andric
23000b57cec5SDimitry Andric KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
23010b57cec5SDimitry Andric (__kmp_nested_proc_bind.used > 0));
23020b57cec5SDimitry Andric
23030b57cec5SDimitry Andric while (*buf != '\0') {
23040b57cec5SDimitry Andric start = next = buf;
23050b57cec5SDimitry Andric
23060b57cec5SDimitry Andric if (__kmp_match_str("none", buf, CCAST(const char **, &next))) {
23070b57cec5SDimitry Andric set_type(affinity_none);
23080b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
23090b57cec5SDimitry Andric buf = next;
23100b57cec5SDimitry Andric } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) {
23110b57cec5SDimitry Andric set_type(affinity_scatter);
23120b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
23130b57cec5SDimitry Andric buf = next;
23140b57cec5SDimitry Andric } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) {
23150b57cec5SDimitry Andric set_type(affinity_compact);
23160b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
23170b57cec5SDimitry Andric buf = next;
23180b57cec5SDimitry Andric } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) {
23190b57cec5SDimitry Andric set_type(affinity_logical);
23200b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
23210b57cec5SDimitry Andric buf = next;
23220b57cec5SDimitry Andric } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) {
23230b57cec5SDimitry Andric set_type(affinity_physical);
23240b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
23250b57cec5SDimitry Andric buf = next;
23260b57cec5SDimitry Andric } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) {
23270b57cec5SDimitry Andric set_type(affinity_explicit);
23280b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
23290b57cec5SDimitry Andric buf = next;
23300b57cec5SDimitry Andric } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) {
23310b57cec5SDimitry Andric set_type(affinity_balanced);
23320b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
23330b57cec5SDimitry Andric buf = next;
23340b57cec5SDimitry Andric } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) {
23350b57cec5SDimitry Andric set_type(affinity_disabled);
23360b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
23370b57cec5SDimitry Andric buf = next;
23380b57cec5SDimitry Andric } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) {
23390b57cec5SDimitry Andric set_verbose(TRUE);
23400b57cec5SDimitry Andric buf = next;
23410b57cec5SDimitry Andric } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) {
23420b57cec5SDimitry Andric set_verbose(FALSE);
23430b57cec5SDimitry Andric buf = next;
23440b57cec5SDimitry Andric } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) {
23450b57cec5SDimitry Andric set_warnings(TRUE);
23460b57cec5SDimitry Andric buf = next;
23470b57cec5SDimitry Andric } else if (__kmp_match_str("nowarnings", buf,
23480b57cec5SDimitry Andric CCAST(const char **, &next))) {
23490b57cec5SDimitry Andric set_warnings(FALSE);
23500b57cec5SDimitry Andric buf = next;
23510b57cec5SDimitry Andric } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) {
23520b57cec5SDimitry Andric set_respect(TRUE);
23530b57cec5SDimitry Andric buf = next;
23540b57cec5SDimitry Andric } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) {
23550b57cec5SDimitry Andric set_respect(FALSE);
23560b57cec5SDimitry Andric buf = next;
2357fcaf7f86SDimitry Andric } else if (__kmp_match_str("reset", buf, CCAST(const char **, &next))) {
2358fcaf7f86SDimitry Andric set_reset(TRUE);
2359fcaf7f86SDimitry Andric buf = next;
2360fcaf7f86SDimitry Andric } else if (__kmp_match_str("noreset", buf, CCAST(const char **, &next))) {
2361fcaf7f86SDimitry Andric set_reset(FALSE);
2362fcaf7f86SDimitry Andric buf = next;
23630b57cec5SDimitry Andric } else if (__kmp_match_str("duplicates", buf,
23640b57cec5SDimitry Andric CCAST(const char **, &next)) ||
23650b57cec5SDimitry Andric __kmp_match_str("dups", buf, CCAST(const char **, &next))) {
23660b57cec5SDimitry Andric set_dups(TRUE);
23670b57cec5SDimitry Andric buf = next;
23680b57cec5SDimitry Andric } else if (__kmp_match_str("noduplicates", buf,
23690b57cec5SDimitry Andric CCAST(const char **, &next)) ||
23700b57cec5SDimitry Andric __kmp_match_str("nodups", buf, CCAST(const char **, &next))) {
23710b57cec5SDimitry Andric set_dups(FALSE);
23720b57cec5SDimitry Andric buf = next;
23730b57cec5SDimitry Andric } else if (__kmp_match_str("granularity", buf,
23740b57cec5SDimitry Andric CCAST(const char **, &next)) ||
23750b57cec5SDimitry Andric __kmp_match_str("gran", buf, CCAST(const char **, &next))) {
23760b57cec5SDimitry Andric SKIP_WS(next);
23770b57cec5SDimitry Andric if (*next != '=') {
23780b57cec5SDimitry Andric EMIT_WARN(TRUE, (AffInvalidParam, name, start));
23790b57cec5SDimitry Andric continue;
23800b57cec5SDimitry Andric }
23810b57cec5SDimitry Andric next++; // skip '='
23820b57cec5SDimitry Andric SKIP_WS(next);
23830b57cec5SDimitry Andric
23840b57cec5SDimitry Andric buf = next;
2385fe6060f1SDimitry Andric
23865f757f3fSDimitry Andric // Have to try core_type and core_efficiency matches first since "core"
23875f757f3fSDimitry Andric // will register as core granularity with "extra chars"
23885f757f3fSDimitry Andric if (__kmp_match_str("core_type", buf, CCAST(const char **, &next))) {
23895f757f3fSDimitry Andric set_gran(KMP_HW_CORE, -1);
23905f757f3fSDimitry Andric out_affinity->flags.core_types_gran = 1;
23915f757f3fSDimitry Andric buf = next;
23925f757f3fSDimitry Andric set = true;
23935f757f3fSDimitry Andric } else if (__kmp_match_str("core_efficiency", buf,
23945f757f3fSDimitry Andric CCAST(const char **, &next)) ||
23955f757f3fSDimitry Andric __kmp_match_str("core_eff", buf,
23965f757f3fSDimitry Andric CCAST(const char **, &next))) {
23975f757f3fSDimitry Andric set_gran(KMP_HW_CORE, -1);
23985f757f3fSDimitry Andric out_affinity->flags.core_effs_gran = 1;
23995f757f3fSDimitry Andric buf = next;
24005f757f3fSDimitry Andric set = true;
24015f757f3fSDimitry Andric }
24025f757f3fSDimitry Andric if (!set) {
2403fe6060f1SDimitry Andric // Try any hardware topology type for granularity
2404fe6060f1SDimitry Andric KMP_FOREACH_HW_TYPE(type) {
2405fe6060f1SDimitry Andric const char *name = __kmp_hw_get_keyword(type);
2406fe6060f1SDimitry Andric if (__kmp_match_str(name, buf, CCAST(const char **, &next))) {
2407fe6060f1SDimitry Andric set_gran(type, -1);
2408fe6060f1SDimitry Andric buf = next;
2409fe6060f1SDimitry Andric set = true;
2410fe6060f1SDimitry Andric break;
2411fe6060f1SDimitry Andric }
2412fe6060f1SDimitry Andric }
24135f757f3fSDimitry Andric }
2414fe6060f1SDimitry Andric if (!set) {
2415fe6060f1SDimitry Andric // Support older names for different granularity layers
24160b57cec5SDimitry Andric if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) {
2417fe6060f1SDimitry Andric set_gran(KMP_HW_THREAD, -1);
24180b57cec5SDimitry Andric buf = next;
2419fe6060f1SDimitry Andric set = true;
2420fe6060f1SDimitry Andric } else if (__kmp_match_str("package", buf,
2421fe6060f1SDimitry Andric CCAST(const char **, &next))) {
2422fe6060f1SDimitry Andric set_gran(KMP_HW_SOCKET, -1);
24230b57cec5SDimitry Andric buf = next;
2424fe6060f1SDimitry Andric set = true;
24250b57cec5SDimitry Andric } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
2426fe6060f1SDimitry Andric set_gran(KMP_HW_NUMA, -1);
24270b57cec5SDimitry Andric buf = next;
2428fe6060f1SDimitry Andric set = true;
24290b57cec5SDimitry Andric #if KMP_GROUP_AFFINITY
24300b57cec5SDimitry Andric } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
2431fe6060f1SDimitry Andric set_gran(KMP_HW_PROC_GROUP, -1);
24320b57cec5SDimitry Andric buf = next;
2433fe6060f1SDimitry Andric set = true;
24340b57cec5SDimitry Andric #endif /* KMP_GROUP AFFINITY */
24350b57cec5SDimitry Andric } else if ((*buf >= '0') && (*buf <= '9')) {
24360b57cec5SDimitry Andric int n;
24370b57cec5SDimitry Andric next = buf;
24380b57cec5SDimitry Andric SKIP_DIGITS(next);
24390b57cec5SDimitry Andric n = __kmp_str_to_int(buf, *next);
24400b57cec5SDimitry Andric KMP_ASSERT(n >= 0);
24410b57cec5SDimitry Andric buf = next;
2442fe6060f1SDimitry Andric set_gran(KMP_HW_UNKNOWN, n);
2443fe6060f1SDimitry Andric set = true;
24440b57cec5SDimitry Andric } else {
24450b57cec5SDimitry Andric EMIT_WARN(TRUE, (AffInvalidParam, name, start));
24460b57cec5SDimitry Andric continue;
24470b57cec5SDimitry Andric }
2448fe6060f1SDimitry Andric }
24490b57cec5SDimitry Andric } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
24500b57cec5SDimitry Andric char *temp_proclist;
24510b57cec5SDimitry Andric
24520b57cec5SDimitry Andric SKIP_WS(next);
24530b57cec5SDimitry Andric if (*next != '=') {
24540b57cec5SDimitry Andric EMIT_WARN(TRUE, (AffInvalidParam, name, start));
24550b57cec5SDimitry Andric continue;
24560b57cec5SDimitry Andric }
24570b57cec5SDimitry Andric next++; // skip '='
24580b57cec5SDimitry Andric SKIP_WS(next);
24590b57cec5SDimitry Andric if (*next != '[') {
24600b57cec5SDimitry Andric EMIT_WARN(TRUE, (AffInvalidParam, name, start));
24610b57cec5SDimitry Andric continue;
24620b57cec5SDimitry Andric }
24630b57cec5SDimitry Andric next++; // skip '['
24640b57cec5SDimitry Andric buf = next;
24650b57cec5SDimitry Andric if (!__kmp_parse_affinity_proc_id_list(
24660b57cec5SDimitry Andric name, buf, CCAST(const char **, &next), &temp_proclist)) {
24670b57cec5SDimitry Andric // warning already emitted.
24680b57cec5SDimitry Andric SKIP_TO(next, ']');
24690b57cec5SDimitry Andric if (*next == ']')
24700b57cec5SDimitry Andric next++;
24710b57cec5SDimitry Andric SKIP_TO(next, ',');
24720b57cec5SDimitry Andric if (*next == ',')
24730b57cec5SDimitry Andric next++;
24740b57cec5SDimitry Andric buf = next;
24750b57cec5SDimitry Andric continue;
24760b57cec5SDimitry Andric }
24770b57cec5SDimitry Andric if (*next != ']') {
24780b57cec5SDimitry Andric EMIT_WARN(TRUE, (AffInvalidParam, name, start));
24790b57cec5SDimitry Andric continue;
24800b57cec5SDimitry Andric }
24810b57cec5SDimitry Andric next++; // skip ']'
24820b57cec5SDimitry Andric set_proclist(temp_proclist);
24830b57cec5SDimitry Andric } else if ((*buf >= '0') && (*buf <= '9')) {
24840b57cec5SDimitry Andric // Parse integer numbers -- permute and offset.
24850b57cec5SDimitry Andric int n;
24860b57cec5SDimitry Andric next = buf;
24870b57cec5SDimitry Andric SKIP_DIGITS(next);
24880b57cec5SDimitry Andric n = __kmp_str_to_int(buf, *next);
24890b57cec5SDimitry Andric KMP_ASSERT(n >= 0);
24900b57cec5SDimitry Andric buf = next;
24910b57cec5SDimitry Andric if (count < 2) {
24920b57cec5SDimitry Andric number[count] = n;
24930b57cec5SDimitry Andric } else {
24940b57cec5SDimitry Andric KMP_WARNING(AffManyParams, name, start);
24950b57cec5SDimitry Andric }
24960b57cec5SDimitry Andric ++count;
24970b57cec5SDimitry Andric } else {
24980b57cec5SDimitry Andric EMIT_WARN(TRUE, (AffInvalidParam, name, start));
24990b57cec5SDimitry Andric continue;
25000b57cec5SDimitry Andric }
25010b57cec5SDimitry Andric
25020b57cec5SDimitry Andric SKIP_WS(next);
25030b57cec5SDimitry Andric if (*next == ',') {
25040b57cec5SDimitry Andric next++;
25050b57cec5SDimitry Andric SKIP_WS(next);
25060b57cec5SDimitry Andric } else if (*next != '\0') {
25070b57cec5SDimitry Andric const char *temp = next;
25080b57cec5SDimitry Andric EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
25090b57cec5SDimitry Andric continue;
25100b57cec5SDimitry Andric }
25110b57cec5SDimitry Andric buf = next;
25120b57cec5SDimitry Andric } // while
25130b57cec5SDimitry Andric
25140b57cec5SDimitry Andric #undef EMIT_WARN
25150b57cec5SDimitry Andric #undef _set_param
25160b57cec5SDimitry Andric #undef set_type
25170b57cec5SDimitry Andric #undef set_verbose
25180b57cec5SDimitry Andric #undef set_warnings
25190b57cec5SDimitry Andric #undef set_respect
25200b57cec5SDimitry Andric #undef set_granularity
2521fcaf7f86SDimitry Andric #undef set_reset
25220b57cec5SDimitry Andric
25230b57cec5SDimitry Andric __kmp_str_free(&buffer);
25240b57cec5SDimitry Andric
25250b57cec5SDimitry Andric if (proclist) {
25260b57cec5SDimitry Andric if (!type) {
25270b57cec5SDimitry Andric KMP_WARNING(AffProcListNoType, name);
2528bdd1243dSDimitry Andric out_affinity->type = affinity_explicit;
25290b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2530bdd1243dSDimitry Andric } else if (out_affinity->type != affinity_explicit) {
25310b57cec5SDimitry Andric KMP_WARNING(AffProcListNotExplicit, name);
2532bdd1243dSDimitry Andric KMP_ASSERT(out_affinity->proclist != NULL);
2533bdd1243dSDimitry Andric KMP_INTERNAL_FREE(out_affinity->proclist);
2534bdd1243dSDimitry Andric out_affinity->proclist = NULL;
25350b57cec5SDimitry Andric }
25360b57cec5SDimitry Andric }
2537bdd1243dSDimitry Andric switch (out_affinity->type) {
25380b57cec5SDimitry Andric case affinity_logical:
25390b57cec5SDimitry Andric case affinity_physical: {
25400b57cec5SDimitry Andric if (count > 0) {
2541bdd1243dSDimitry Andric out_affinity->offset = number[0];
25420b57cec5SDimitry Andric }
25430b57cec5SDimitry Andric if (count > 1) {
25440b57cec5SDimitry Andric KMP_WARNING(AffManyParamsForLogic, name, number[1]);
25450b57cec5SDimitry Andric }
25460b57cec5SDimitry Andric } break;
25470b57cec5SDimitry Andric case affinity_balanced: {
25480b57cec5SDimitry Andric if (count > 0) {
2549bdd1243dSDimitry Andric out_affinity->compact = number[0];
25500b57cec5SDimitry Andric }
25510b57cec5SDimitry Andric if (count > 1) {
2552bdd1243dSDimitry Andric out_affinity->offset = number[1];
25530b57cec5SDimitry Andric }
25540b57cec5SDimitry Andric
2555bdd1243dSDimitry Andric if (__kmp_affinity.gran == KMP_HW_UNKNOWN) {
2556bdd1243dSDimitry Andric int verbose = out_affinity->flags.verbose;
2557bdd1243dSDimitry Andric int warnings = out_affinity->flags.warnings;
25580b57cec5SDimitry Andric #if KMP_MIC_SUPPORTED
25590b57cec5SDimitry Andric if (__kmp_mic_type != non_mic) {
2560bdd1243dSDimitry Andric if (verbose || warnings) {
2561bdd1243dSDimitry Andric KMP_WARNING(AffGranUsing, out_affinity->env_var, "fine");
25620b57cec5SDimitry Andric }
2563bdd1243dSDimitry Andric out_affinity->gran = KMP_HW_THREAD;
25640b57cec5SDimitry Andric } else
25650b57cec5SDimitry Andric #endif
25660b57cec5SDimitry Andric {
2567bdd1243dSDimitry Andric if (verbose || warnings) {
2568bdd1243dSDimitry Andric KMP_WARNING(AffGranUsing, out_affinity->env_var, "core");
25690b57cec5SDimitry Andric }
2570bdd1243dSDimitry Andric out_affinity->gran = KMP_HW_CORE;
25710b57cec5SDimitry Andric }
25720b57cec5SDimitry Andric }
25730b57cec5SDimitry Andric } break;
25740b57cec5SDimitry Andric case affinity_scatter:
25750b57cec5SDimitry Andric case affinity_compact: {
25760b57cec5SDimitry Andric if (count > 0) {
2577bdd1243dSDimitry Andric out_affinity->compact = number[0];
25780b57cec5SDimitry Andric }
25790b57cec5SDimitry Andric if (count > 1) {
2580bdd1243dSDimitry Andric out_affinity->offset = number[1];
25810b57cec5SDimitry Andric }
25820b57cec5SDimitry Andric } break;
25830b57cec5SDimitry Andric case affinity_explicit: {
2584bdd1243dSDimitry Andric if (out_affinity->proclist == NULL) {
25850b57cec5SDimitry Andric KMP_WARNING(AffNoProcList, name);
2586bdd1243dSDimitry Andric out_affinity->type = affinity_none;
25870b57cec5SDimitry Andric }
25880b57cec5SDimitry Andric if (count > 0) {
25890b57cec5SDimitry Andric KMP_WARNING(AffNoParam, name, "explicit");
25900b57cec5SDimitry Andric }
25910b57cec5SDimitry Andric } break;
25920b57cec5SDimitry Andric case affinity_none: {
25930b57cec5SDimitry Andric if (count > 0) {
25940b57cec5SDimitry Andric KMP_WARNING(AffNoParam, name, "none");
25950b57cec5SDimitry Andric }
25960b57cec5SDimitry Andric } break;
25970b57cec5SDimitry Andric case affinity_disabled: {
25980b57cec5SDimitry Andric if (count > 0) {
25990b57cec5SDimitry Andric KMP_WARNING(AffNoParam, name, "disabled");
26000b57cec5SDimitry Andric }
26010b57cec5SDimitry Andric } break;
26020b57cec5SDimitry Andric case affinity_default: {
26030b57cec5SDimitry Andric if (count > 0) {
26040b57cec5SDimitry Andric KMP_WARNING(AffNoParam, name, "default");
26050b57cec5SDimitry Andric }
26060b57cec5SDimitry Andric } break;
2607fe6060f1SDimitry Andric default: {
2608fe6060f1SDimitry Andric KMP_ASSERT(0);
2609fe6060f1SDimitry Andric }
26100b57cec5SDimitry Andric }
26110b57cec5SDimitry Andric } // __kmp_parse_affinity_env
26120b57cec5SDimitry Andric
__kmp_stg_parse_affinity(char const * name,char const * value,void * data)26130b57cec5SDimitry Andric static void __kmp_stg_parse_affinity(char const *name, char const *value,
26140b57cec5SDimitry Andric void *data) {
26150b57cec5SDimitry Andric kmp_setting_t **rivals = (kmp_setting_t **)data;
26160b57cec5SDimitry Andric int rc;
26170b57cec5SDimitry Andric
26180b57cec5SDimitry Andric rc = __kmp_stg_check_rivals(name, value, rivals);
26190b57cec5SDimitry Andric if (rc) {
26200b57cec5SDimitry Andric return;
26210b57cec5SDimitry Andric }
26220b57cec5SDimitry Andric
2623bdd1243dSDimitry Andric __kmp_parse_affinity_env(name, value, &__kmp_affinity);
26240b57cec5SDimitry Andric
26250b57cec5SDimitry Andric } // __kmp_stg_parse_affinity
__kmp_stg_parse_hh_affinity(char const * name,char const * value,void * data)2626bdd1243dSDimitry Andric static void __kmp_stg_parse_hh_affinity(char const *name, char const *value,
26270b57cec5SDimitry Andric void *data) {
2628bdd1243dSDimitry Andric __kmp_parse_affinity_env(name, value, &__kmp_hh_affinity);
2629bdd1243dSDimitry Andric // Warn about unused parts of hidden helper affinity settings if specified.
2630bdd1243dSDimitry Andric if (__kmp_hh_affinity.flags.reset) {
2631bdd1243dSDimitry Andric KMP_WARNING(AffInvalidParam, name, "reset");
2632bdd1243dSDimitry Andric }
2633bdd1243dSDimitry Andric if (__kmp_hh_affinity.flags.respect != affinity_respect_mask_default) {
2634bdd1243dSDimitry Andric KMP_WARNING(AffInvalidParam, name, "respect");
2635bdd1243dSDimitry Andric }
2636bdd1243dSDimitry Andric }
2637bdd1243dSDimitry Andric
__kmp_print_affinity_env(kmp_str_buf_t * buffer,char const * name,const kmp_affinity_t & affinity)2638bdd1243dSDimitry Andric static void __kmp_print_affinity_env(kmp_str_buf_t *buffer, char const *name,
2639bdd1243dSDimitry Andric const kmp_affinity_t &affinity) {
2640bdd1243dSDimitry Andric bool is_hh_affinity = (&affinity == &__kmp_hh_affinity);
26410b57cec5SDimitry Andric if (__kmp_env_format) {
26420b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(name);
26430b57cec5SDimitry Andric } else {
26440b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s='", name);
26450b57cec5SDimitry Andric }
2646bdd1243dSDimitry Andric if (affinity.flags.verbose) {
26470b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,", "verbose");
26480b57cec5SDimitry Andric } else {
26490b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,", "noverbose");
26500b57cec5SDimitry Andric }
2651bdd1243dSDimitry Andric if (affinity.flags.warnings) {
26520b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,", "warnings");
26530b57cec5SDimitry Andric } else {
26540b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,", "nowarnings");
26550b57cec5SDimitry Andric }
26560b57cec5SDimitry Andric if (KMP_AFFINITY_CAPABLE()) {
2657bdd1243dSDimitry Andric // Hidden helper affinity does not affect global reset
2658bdd1243dSDimitry Andric // or respect flags. That is still solely controlled by KMP_AFFINITY.
2659bdd1243dSDimitry Andric if (!is_hh_affinity) {
2660bdd1243dSDimitry Andric if (affinity.flags.respect) {
26610b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,", "respect");
26620b57cec5SDimitry Andric } else {
26630b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,", "norespect");
26640b57cec5SDimitry Andric }
2665bdd1243dSDimitry Andric if (affinity.flags.reset) {
2666fcaf7f86SDimitry Andric __kmp_str_buf_print(buffer, "%s,", "reset");
2667fcaf7f86SDimitry Andric } else {
2668fcaf7f86SDimitry Andric __kmp_str_buf_print(buffer, "%s,", "noreset");
2669fcaf7f86SDimitry Andric }
2670bdd1243dSDimitry Andric }
26715f757f3fSDimitry Andric __kmp_str_buf_print(buffer, "granularity=");
26725f757f3fSDimitry Andric if (affinity.flags.core_types_gran)
26735f757f3fSDimitry Andric __kmp_str_buf_print(buffer, "core_type,");
26745f757f3fSDimitry Andric else if (affinity.flags.core_effs_gran) {
26755f757f3fSDimitry Andric __kmp_str_buf_print(buffer, "core_eff,");
26765f757f3fSDimitry Andric } else {
26775f757f3fSDimitry Andric __kmp_str_buf_print(
26785f757f3fSDimitry Andric buffer, "%s,", __kmp_hw_get_keyword(affinity.gran, /*plural=*/false));
26795f757f3fSDimitry Andric }
26800b57cec5SDimitry Andric }
26810b57cec5SDimitry Andric if (!KMP_AFFINITY_CAPABLE()) {
26820b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s", "disabled");
2683bdd1243dSDimitry Andric } else {
2684bdd1243dSDimitry Andric int compact = affinity.compact;
2685bdd1243dSDimitry Andric int offset = affinity.offset;
2686bdd1243dSDimitry Andric switch (affinity.type) {
26870b57cec5SDimitry Andric case affinity_none:
26880b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s", "none");
26890b57cec5SDimitry Andric break;
26900b57cec5SDimitry Andric case affinity_physical:
2691bdd1243dSDimitry Andric __kmp_str_buf_print(buffer, "%s,%d", "physical", offset);
26920b57cec5SDimitry Andric break;
26930b57cec5SDimitry Andric case affinity_logical:
2694bdd1243dSDimitry Andric __kmp_str_buf_print(buffer, "%s,%d", "logical", offset);
26950b57cec5SDimitry Andric break;
26960b57cec5SDimitry Andric case affinity_compact:
2697bdd1243dSDimitry Andric __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", compact, offset);
26980b57cec5SDimitry Andric break;
26990b57cec5SDimitry Andric case affinity_scatter:
2700bdd1243dSDimitry Andric __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", compact, offset);
27010b57cec5SDimitry Andric break;
27020b57cec5SDimitry Andric case affinity_explicit:
2703bdd1243dSDimitry Andric __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist", affinity.proclist,
2704bdd1243dSDimitry Andric "explicit");
27050b57cec5SDimitry Andric break;
27060b57cec5SDimitry Andric case affinity_balanced:
2707bdd1243dSDimitry Andric __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced", compact, offset);
27080b57cec5SDimitry Andric break;
27090b57cec5SDimitry Andric case affinity_disabled:
27100b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s", "disabled");
27110b57cec5SDimitry Andric break;
27120b57cec5SDimitry Andric case affinity_default:
27130b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s", "default");
27140b57cec5SDimitry Andric break;
27150b57cec5SDimitry Andric default:
27160b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s", "<unknown>");
27170b57cec5SDimitry Andric break;
27180b57cec5SDimitry Andric }
2719bdd1243dSDimitry Andric }
27200b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "'\n");
27210b57cec5SDimitry Andric } //__kmp_stg_print_affinity
27220b57cec5SDimitry Andric
__kmp_stg_print_affinity(kmp_str_buf_t * buffer,char const * name,void * data)2723bdd1243dSDimitry Andric static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
2724bdd1243dSDimitry Andric void *data) {
2725bdd1243dSDimitry Andric __kmp_print_affinity_env(buffer, name, __kmp_affinity);
2726bdd1243dSDimitry Andric }
__kmp_stg_print_hh_affinity(kmp_str_buf_t * buffer,char const * name,void * data)2727bdd1243dSDimitry Andric static void __kmp_stg_print_hh_affinity(kmp_str_buf_t *buffer, char const *name,
2728bdd1243dSDimitry Andric void *data) {
2729bdd1243dSDimitry Andric __kmp_print_affinity_env(buffer, name, __kmp_hh_affinity);
2730bdd1243dSDimitry Andric }
2731bdd1243dSDimitry Andric
27320b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
27330b57cec5SDimitry Andric
__kmp_stg_parse_gomp_cpu_affinity(char const * name,char const * value,void * data)27340b57cec5SDimitry Andric static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
27350b57cec5SDimitry Andric char const *value, void *data) {
27360b57cec5SDimitry Andric const char *next = NULL;
27370b57cec5SDimitry Andric char *temp_proclist;
27380b57cec5SDimitry Andric kmp_setting_t **rivals = (kmp_setting_t **)data;
27390b57cec5SDimitry Andric int rc;
27400b57cec5SDimitry Andric
27410b57cec5SDimitry Andric rc = __kmp_stg_check_rivals(name, value, rivals);
27420b57cec5SDimitry Andric if (rc) {
27430b57cec5SDimitry Andric return;
27440b57cec5SDimitry Andric }
27450b57cec5SDimitry Andric
27460b57cec5SDimitry Andric if (TCR_4(__kmp_init_middle)) {
27470b57cec5SDimitry Andric KMP_WARNING(EnvMiddleWarn, name);
27480b57cec5SDimitry Andric __kmp_env_toPrint(name, 0);
27490b57cec5SDimitry Andric return;
27500b57cec5SDimitry Andric }
27510b57cec5SDimitry Andric
27520b57cec5SDimitry Andric __kmp_env_toPrint(name, 1);
27530b57cec5SDimitry Andric
27540b57cec5SDimitry Andric if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
27550b57cec5SDimitry Andric SKIP_WS(next);
27560b57cec5SDimitry Andric if (*next == '\0') {
27570b57cec5SDimitry Andric // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2758bdd1243dSDimitry Andric __kmp_affinity.proclist = temp_proclist;
2759bdd1243dSDimitry Andric __kmp_affinity.type = affinity_explicit;
2760bdd1243dSDimitry Andric __kmp_affinity.gran = KMP_HW_THREAD;
27610b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
27620b57cec5SDimitry Andric } else {
27630b57cec5SDimitry Andric KMP_WARNING(AffSyntaxError, name);
27640b57cec5SDimitry Andric if (temp_proclist != NULL) {
27650b57cec5SDimitry Andric KMP_INTERNAL_FREE((void *)temp_proclist);
27660b57cec5SDimitry Andric }
27670b57cec5SDimitry Andric }
27680b57cec5SDimitry Andric } else {
27690b57cec5SDimitry Andric // Warning already emitted
2770bdd1243dSDimitry Andric __kmp_affinity.type = affinity_none;
27710b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
27720b57cec5SDimitry Andric }
27730b57cec5SDimitry Andric } // __kmp_stg_parse_gomp_cpu_affinity
27740b57cec5SDimitry Andric
27750b57cec5SDimitry Andric #endif /* KMP_GOMP_COMPAT */
27760b57cec5SDimitry Andric
27770b57cec5SDimitry Andric /*-----------------------------------------------------------------------------
27780b57cec5SDimitry Andric The OMP_PLACES proc id list parser. Here is the grammar:
27790b57cec5SDimitry Andric
27800b57cec5SDimitry Andric place_list := place
27810b57cec5SDimitry Andric place_list := place , place_list
27820b57cec5SDimitry Andric place := num
27830b57cec5SDimitry Andric place := place : num
27840b57cec5SDimitry Andric place := place : num : signed
27850b57cec5SDimitry Andric place := { subplacelist }
27860b57cec5SDimitry Andric place := ! place // (lowest priority)
27870b57cec5SDimitry Andric subplace_list := subplace
27880b57cec5SDimitry Andric subplace_list := subplace , subplace_list
27890b57cec5SDimitry Andric subplace := num
27900b57cec5SDimitry Andric subplace := num : num
27910b57cec5SDimitry Andric subplace := num : num : signed
27920b57cec5SDimitry Andric signed := num
27930b57cec5SDimitry Andric signed := + signed
27940b57cec5SDimitry Andric signed := - signed
27950b57cec5SDimitry Andric -----------------------------------------------------------------------------*/
27960b57cec5SDimitry Andric
27975f757f3fSDimitry Andric // Return TRUE if successful parse, FALSE otherwise
__kmp_parse_subplace_list(const char * var,const char ** scan)27980b57cec5SDimitry Andric static int __kmp_parse_subplace_list(const char *var, const char **scan) {
27990b57cec5SDimitry Andric const char *next;
28000b57cec5SDimitry Andric
28010b57cec5SDimitry Andric for (;;) {
28020b57cec5SDimitry Andric int start, count, stride;
28030b57cec5SDimitry Andric
28040b57cec5SDimitry Andric //
28050b57cec5SDimitry Andric // Read in the starting proc id
28060b57cec5SDimitry Andric //
28070b57cec5SDimitry Andric SKIP_WS(*scan);
28080b57cec5SDimitry Andric if ((**scan < '0') || (**scan > '9')) {
28090b57cec5SDimitry Andric return FALSE;
28100b57cec5SDimitry Andric }
28110b57cec5SDimitry Andric next = *scan;
28120b57cec5SDimitry Andric SKIP_DIGITS(next);
28130b57cec5SDimitry Andric start = __kmp_str_to_int(*scan, *next);
28140b57cec5SDimitry Andric KMP_ASSERT(start >= 0);
28150b57cec5SDimitry Andric *scan = next;
28160b57cec5SDimitry Andric
28170b57cec5SDimitry Andric // valid follow sets are ',' ':' and '}'
28180b57cec5SDimitry Andric SKIP_WS(*scan);
28190b57cec5SDimitry Andric if (**scan == '}') {
28200b57cec5SDimitry Andric break;
28210b57cec5SDimitry Andric }
28220b57cec5SDimitry Andric if (**scan == ',') {
28230b57cec5SDimitry Andric (*scan)++; // skip ','
28240b57cec5SDimitry Andric continue;
28250b57cec5SDimitry Andric }
28260b57cec5SDimitry Andric if (**scan != ':') {
28270b57cec5SDimitry Andric return FALSE;
28280b57cec5SDimitry Andric }
28290b57cec5SDimitry Andric (*scan)++; // skip ':'
28300b57cec5SDimitry Andric
28310b57cec5SDimitry Andric // Read count parameter
28320b57cec5SDimitry Andric SKIP_WS(*scan);
28330b57cec5SDimitry Andric if ((**scan < '0') || (**scan > '9')) {
28340b57cec5SDimitry Andric return FALSE;
28350b57cec5SDimitry Andric }
28360b57cec5SDimitry Andric next = *scan;
28370b57cec5SDimitry Andric SKIP_DIGITS(next);
28380b57cec5SDimitry Andric count = __kmp_str_to_int(*scan, *next);
28390b57cec5SDimitry Andric KMP_ASSERT(count >= 0);
28400b57cec5SDimitry Andric *scan = next;
28410b57cec5SDimitry Andric
28420b57cec5SDimitry Andric // valid follow sets are ',' ':' and '}'
28430b57cec5SDimitry Andric SKIP_WS(*scan);
28440b57cec5SDimitry Andric if (**scan == '}') {
28450b57cec5SDimitry Andric break;
28460b57cec5SDimitry Andric }
28470b57cec5SDimitry Andric if (**scan == ',') {
28480b57cec5SDimitry Andric (*scan)++; // skip ','
28490b57cec5SDimitry Andric continue;
28500b57cec5SDimitry Andric }
28510b57cec5SDimitry Andric if (**scan != ':') {
28520b57cec5SDimitry Andric return FALSE;
28530b57cec5SDimitry Andric }
28540b57cec5SDimitry Andric (*scan)++; // skip ':'
28550b57cec5SDimitry Andric
28560b57cec5SDimitry Andric // Read stride parameter
28570b57cec5SDimitry Andric int sign = +1;
28580b57cec5SDimitry Andric for (;;) {
28590b57cec5SDimitry Andric SKIP_WS(*scan);
28600b57cec5SDimitry Andric if (**scan == '+') {
28610b57cec5SDimitry Andric (*scan)++; // skip '+'
28620b57cec5SDimitry Andric continue;
28630b57cec5SDimitry Andric }
28640b57cec5SDimitry Andric if (**scan == '-') {
28650b57cec5SDimitry Andric sign *= -1;
28660b57cec5SDimitry Andric (*scan)++; // skip '-'
28670b57cec5SDimitry Andric continue;
28680b57cec5SDimitry Andric }
28690b57cec5SDimitry Andric break;
28700b57cec5SDimitry Andric }
28710b57cec5SDimitry Andric SKIP_WS(*scan);
28720b57cec5SDimitry Andric if ((**scan < '0') || (**scan > '9')) {
28730b57cec5SDimitry Andric return FALSE;
28740b57cec5SDimitry Andric }
28750b57cec5SDimitry Andric next = *scan;
28760b57cec5SDimitry Andric SKIP_DIGITS(next);
28770b57cec5SDimitry Andric stride = __kmp_str_to_int(*scan, *next);
28780b57cec5SDimitry Andric KMP_ASSERT(stride >= 0);
28790b57cec5SDimitry Andric *scan = next;
28800b57cec5SDimitry Andric stride *= sign;
28810b57cec5SDimitry Andric
28820b57cec5SDimitry Andric // valid follow sets are ',' and '}'
28830b57cec5SDimitry Andric SKIP_WS(*scan);
28840b57cec5SDimitry Andric if (**scan == '}') {
28850b57cec5SDimitry Andric break;
28860b57cec5SDimitry Andric }
28870b57cec5SDimitry Andric if (**scan == ',') {
28880b57cec5SDimitry Andric (*scan)++; // skip ','
28890b57cec5SDimitry Andric continue;
28900b57cec5SDimitry Andric }
28910b57cec5SDimitry Andric return FALSE;
28920b57cec5SDimitry Andric }
28930b57cec5SDimitry Andric return TRUE;
28940b57cec5SDimitry Andric }
28950b57cec5SDimitry Andric
28965f757f3fSDimitry Andric // Return TRUE if successful parse, FALSE otherwise
__kmp_parse_place(const char * var,const char ** scan)28970b57cec5SDimitry Andric static int __kmp_parse_place(const char *var, const char **scan) {
28980b57cec5SDimitry Andric const char *next;
28990b57cec5SDimitry Andric
29000b57cec5SDimitry Andric // valid follow sets are '{' '!' and num
29010b57cec5SDimitry Andric SKIP_WS(*scan);
29020b57cec5SDimitry Andric if (**scan == '{') {
29030b57cec5SDimitry Andric (*scan)++; // skip '{'
29040b57cec5SDimitry Andric if (!__kmp_parse_subplace_list(var, scan)) {
29050b57cec5SDimitry Andric return FALSE;
29060b57cec5SDimitry Andric }
29070b57cec5SDimitry Andric if (**scan != '}') {
29080b57cec5SDimitry Andric return FALSE;
29090b57cec5SDimitry Andric }
29100b57cec5SDimitry Andric (*scan)++; // skip '}'
29110b57cec5SDimitry Andric } else if (**scan == '!') {
29120b57cec5SDimitry Andric (*scan)++; // skip '!'
29130b57cec5SDimitry Andric return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
29140b57cec5SDimitry Andric } else if ((**scan >= '0') && (**scan <= '9')) {
29150b57cec5SDimitry Andric next = *scan;
29160b57cec5SDimitry Andric SKIP_DIGITS(next);
29170b57cec5SDimitry Andric int proc = __kmp_str_to_int(*scan, *next);
29180b57cec5SDimitry Andric KMP_ASSERT(proc >= 0);
29190b57cec5SDimitry Andric *scan = next;
29200b57cec5SDimitry Andric } else {
29210b57cec5SDimitry Andric return FALSE;
29220b57cec5SDimitry Andric }
29230b57cec5SDimitry Andric return TRUE;
29240b57cec5SDimitry Andric }
29250b57cec5SDimitry Andric
29265f757f3fSDimitry Andric // Return TRUE if successful parse, FALSE otherwise
__kmp_parse_place_list(const char * var,const char * env,char ** place_list)29270b57cec5SDimitry Andric static int __kmp_parse_place_list(const char *var, const char *env,
29280b57cec5SDimitry Andric char **place_list) {
29290b57cec5SDimitry Andric const char *scan = env;
29300b57cec5SDimitry Andric const char *next = scan;
29310b57cec5SDimitry Andric
29320b57cec5SDimitry Andric for (;;) {
29330b57cec5SDimitry Andric int count, stride;
29340b57cec5SDimitry Andric
29350b57cec5SDimitry Andric if (!__kmp_parse_place(var, &scan)) {
29360b57cec5SDimitry Andric return FALSE;
29370b57cec5SDimitry Andric }
29380b57cec5SDimitry Andric
29390b57cec5SDimitry Andric // valid follow sets are ',' ':' and EOL
29400b57cec5SDimitry Andric SKIP_WS(scan);
29410b57cec5SDimitry Andric if (*scan == '\0') {
29420b57cec5SDimitry Andric break;
29430b57cec5SDimitry Andric }
29440b57cec5SDimitry Andric if (*scan == ',') {
29450b57cec5SDimitry Andric scan++; // skip ','
29460b57cec5SDimitry Andric continue;
29470b57cec5SDimitry Andric }
29480b57cec5SDimitry Andric if (*scan != ':') {
29490b57cec5SDimitry Andric return FALSE;
29500b57cec5SDimitry Andric }
29510b57cec5SDimitry Andric scan++; // skip ':'
29520b57cec5SDimitry Andric
29530b57cec5SDimitry Andric // Read count parameter
29540b57cec5SDimitry Andric SKIP_WS(scan);
29550b57cec5SDimitry Andric if ((*scan < '0') || (*scan > '9')) {
29560b57cec5SDimitry Andric return FALSE;
29570b57cec5SDimitry Andric }
29580b57cec5SDimitry Andric next = scan;
29590b57cec5SDimitry Andric SKIP_DIGITS(next);
29600b57cec5SDimitry Andric count = __kmp_str_to_int(scan, *next);
29610b57cec5SDimitry Andric KMP_ASSERT(count >= 0);
29620b57cec5SDimitry Andric scan = next;
29630b57cec5SDimitry Andric
29640b57cec5SDimitry Andric // valid follow sets are ',' ':' and EOL
29650b57cec5SDimitry Andric SKIP_WS(scan);
29660b57cec5SDimitry Andric if (*scan == '\0') {
29670b57cec5SDimitry Andric break;
29680b57cec5SDimitry Andric }
29690b57cec5SDimitry Andric if (*scan == ',') {
29700b57cec5SDimitry Andric scan++; // skip ','
29710b57cec5SDimitry Andric continue;
29720b57cec5SDimitry Andric }
29730b57cec5SDimitry Andric if (*scan != ':') {
29740b57cec5SDimitry Andric return FALSE;
29750b57cec5SDimitry Andric }
29760b57cec5SDimitry Andric scan++; // skip ':'
29770b57cec5SDimitry Andric
29780b57cec5SDimitry Andric // Read stride parameter
29790b57cec5SDimitry Andric int sign = +1;
29800b57cec5SDimitry Andric for (;;) {
29810b57cec5SDimitry Andric SKIP_WS(scan);
29820b57cec5SDimitry Andric if (*scan == '+') {
29830b57cec5SDimitry Andric scan++; // skip '+'
29840b57cec5SDimitry Andric continue;
29850b57cec5SDimitry Andric }
29860b57cec5SDimitry Andric if (*scan == '-') {
29870b57cec5SDimitry Andric sign *= -1;
29880b57cec5SDimitry Andric scan++; // skip '-'
29890b57cec5SDimitry Andric continue;
29900b57cec5SDimitry Andric }
29910b57cec5SDimitry Andric break;
29920b57cec5SDimitry Andric }
29930b57cec5SDimitry Andric SKIP_WS(scan);
29940b57cec5SDimitry Andric if ((*scan < '0') || (*scan > '9')) {
29950b57cec5SDimitry Andric return FALSE;
29960b57cec5SDimitry Andric }
29970b57cec5SDimitry Andric next = scan;
29980b57cec5SDimitry Andric SKIP_DIGITS(next);
29990b57cec5SDimitry Andric stride = __kmp_str_to_int(scan, *next);
30000b57cec5SDimitry Andric KMP_ASSERT(stride >= 0);
30010b57cec5SDimitry Andric scan = next;
30020b57cec5SDimitry Andric stride *= sign;
30030b57cec5SDimitry Andric
30040b57cec5SDimitry Andric // valid follow sets are ',' and EOL
30050b57cec5SDimitry Andric SKIP_WS(scan);
30060b57cec5SDimitry Andric if (*scan == '\0') {
30070b57cec5SDimitry Andric break;
30080b57cec5SDimitry Andric }
30090b57cec5SDimitry Andric if (*scan == ',') {
30100b57cec5SDimitry Andric scan++; // skip ','
30110b57cec5SDimitry Andric continue;
30120b57cec5SDimitry Andric }
30130b57cec5SDimitry Andric
30140b57cec5SDimitry Andric return FALSE;
30150b57cec5SDimitry Andric }
30160b57cec5SDimitry Andric
30170b57cec5SDimitry Andric {
3018e8d8bef9SDimitry Andric ptrdiff_t len = scan - env;
30190b57cec5SDimitry Andric char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
30200b57cec5SDimitry Andric KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
30210b57cec5SDimitry Andric retlist[len] = '\0';
30220b57cec5SDimitry Andric *place_list = retlist;
30230b57cec5SDimitry Andric }
30240b57cec5SDimitry Andric return TRUE;
30250b57cec5SDimitry Andric }
30260b57cec5SDimitry Andric
__kmp_places_set(enum affinity_type type,kmp_hw_t kind)30275f757f3fSDimitry Andric static inline void __kmp_places_set(enum affinity_type type, kmp_hw_t kind) {
30285f757f3fSDimitry Andric __kmp_affinity.type = type;
30295f757f3fSDimitry Andric __kmp_affinity.gran = kind;
30305f757f3fSDimitry Andric __kmp_affinity.flags.dups = FALSE;
30315f757f3fSDimitry Andric __kmp_affinity.flags.omp_places = TRUE;
30325f757f3fSDimitry Andric }
30335f757f3fSDimitry Andric
__kmp_places_syntax_error_fallback(char const * name,kmp_hw_t kind)30345f757f3fSDimitry Andric static void __kmp_places_syntax_error_fallback(char const *name,
30355f757f3fSDimitry Andric kmp_hw_t kind) {
30365f757f3fSDimitry Andric const char *str = __kmp_hw_get_catalog_string(kind, /*plural=*/true);
30375f757f3fSDimitry Andric KMP_WARNING(SyntaxErrorUsing, name, str);
30385f757f3fSDimitry Andric __kmp_places_set(affinity_compact, kind);
30395f757f3fSDimitry Andric if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default)
30405f757f3fSDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
30415f757f3fSDimitry Andric }
30425f757f3fSDimitry Andric
__kmp_stg_parse_places(char const * name,char const * value,void * data)30430b57cec5SDimitry Andric static void __kmp_stg_parse_places(char const *name, char const *value,
30440b57cec5SDimitry Andric void *data) {
3045fe6060f1SDimitry Andric struct kmp_place_t {
3046fe6060f1SDimitry Andric const char *name;
3047fe6060f1SDimitry Andric kmp_hw_t type;
3048fe6060f1SDimitry Andric };
30490b57cec5SDimitry Andric int count;
3050fe6060f1SDimitry Andric bool set = false;
30510b57cec5SDimitry Andric const char *scan = value;
30520b57cec5SDimitry Andric const char *next = scan;
3053fe6060f1SDimitry Andric kmp_place_t std_places[] = {{"threads", KMP_HW_THREAD},
3054fe6060f1SDimitry Andric {"cores", KMP_HW_CORE},
3055fe6060f1SDimitry Andric {"numa_domains", KMP_HW_NUMA},
3056fe6060f1SDimitry Andric {"ll_caches", KMP_HW_LLC},
3057fe6060f1SDimitry Andric {"sockets", KMP_HW_SOCKET}};
30580b57cec5SDimitry Andric kmp_setting_t **rivals = (kmp_setting_t **)data;
30590b57cec5SDimitry Andric int rc;
30600b57cec5SDimitry Andric
30610b57cec5SDimitry Andric rc = __kmp_stg_check_rivals(name, value, rivals);
30620b57cec5SDimitry Andric if (rc) {
30630b57cec5SDimitry Andric return;
30640b57cec5SDimitry Andric }
30650b57cec5SDimitry Andric
3066fe6060f1SDimitry Andric // Standard choices
3067fe6060f1SDimitry Andric for (size_t i = 0; i < sizeof(std_places) / sizeof(std_places[0]); ++i) {
3068fe6060f1SDimitry Andric const kmp_place_t &place = std_places[i];
3069fe6060f1SDimitry Andric if (__kmp_match_str(place.name, scan, &next)) {
3070fe6060f1SDimitry Andric scan = next;
30715f757f3fSDimitry Andric __kmp_places_set(affinity_compact, place.type);
3072fe6060f1SDimitry Andric set = true;
30735f757f3fSDimitry Andric // Parse core attribute if it exists
30745f757f3fSDimitry Andric if (KMP_HW_MAX_NUM_CORE_TYPES > 1) {
30755f757f3fSDimitry Andric SKIP_WS(scan);
30765f757f3fSDimitry Andric if (*scan == ':') {
30775f757f3fSDimitry Andric if (place.type != KMP_HW_CORE) {
30785f757f3fSDimitry Andric __kmp_places_syntax_error_fallback(name, place.type);
30795f757f3fSDimitry Andric return;
30805f757f3fSDimitry Andric }
30815f757f3fSDimitry Andric scan++; // skip ':'
30825f757f3fSDimitry Andric SKIP_WS(scan);
30835f757f3fSDimitry Andric #if KMP_ARCH_X86 || KMP_ARCH_X86_64
30845f757f3fSDimitry Andric if (__kmp_match_str("intel_core", scan, &next)) {
30855f757f3fSDimitry Andric __kmp_affinity.core_attr_gran.core_type = KMP_HW_CORE_TYPE_CORE;
30865f757f3fSDimitry Andric __kmp_affinity.core_attr_gran.valid = 1;
30875f757f3fSDimitry Andric scan = next;
30885f757f3fSDimitry Andric } else if (__kmp_match_str("intel_atom", scan, &next)) {
30895f757f3fSDimitry Andric __kmp_affinity.core_attr_gran.core_type = KMP_HW_CORE_TYPE_ATOM;
30905f757f3fSDimitry Andric __kmp_affinity.core_attr_gran.valid = 1;
30915f757f3fSDimitry Andric scan = next;
30925f757f3fSDimitry Andric } else
30935f757f3fSDimitry Andric #endif
30945f757f3fSDimitry Andric if (__kmp_match_str("eff", scan, &next)) {
30955f757f3fSDimitry Andric int eff;
30965f757f3fSDimitry Andric if (!isdigit(*next)) {
30975f757f3fSDimitry Andric __kmp_places_syntax_error_fallback(name, place.type);
30985f757f3fSDimitry Andric return;
30995f757f3fSDimitry Andric }
31005f757f3fSDimitry Andric scan = next;
31015f757f3fSDimitry Andric SKIP_DIGITS(next);
31025f757f3fSDimitry Andric eff = __kmp_str_to_int(scan, *next);
31035f757f3fSDimitry Andric if (eff < 0) {
31045f757f3fSDimitry Andric __kmp_places_syntax_error_fallback(name, place.type);
31055f757f3fSDimitry Andric return;
31065f757f3fSDimitry Andric }
31075f757f3fSDimitry Andric if (eff >= KMP_HW_MAX_NUM_CORE_EFFS)
31085f757f3fSDimitry Andric eff = KMP_HW_MAX_NUM_CORE_EFFS - 1;
31095f757f3fSDimitry Andric __kmp_affinity.core_attr_gran.core_eff = eff;
31105f757f3fSDimitry Andric __kmp_affinity.core_attr_gran.valid = 1;
31115f757f3fSDimitry Andric scan = next;
31125f757f3fSDimitry Andric }
31135f757f3fSDimitry Andric if (!__kmp_affinity.core_attr_gran.valid) {
31145f757f3fSDimitry Andric __kmp_places_syntax_error_fallback(name, place.type);
31155f757f3fSDimitry Andric return;
31165f757f3fSDimitry Andric }
31175f757f3fSDimitry Andric }
31185f757f3fSDimitry Andric }
3119fe6060f1SDimitry Andric break;
31200b57cec5SDimitry Andric }
3121fe6060f1SDimitry Andric }
3122fe6060f1SDimitry Andric // Implementation choices for OMP_PLACES based on internal types
3123fe6060f1SDimitry Andric if (!set) {
3124fe6060f1SDimitry Andric KMP_FOREACH_HW_TYPE(type) {
3125fe6060f1SDimitry Andric const char *name = __kmp_hw_get_keyword(type, true);
3126fe6060f1SDimitry Andric if (__kmp_match_str("unknowns", scan, &next))
3127fe6060f1SDimitry Andric continue;
3128fe6060f1SDimitry Andric if (__kmp_match_str(name, scan, &next)) {
31290b57cec5SDimitry Andric scan = next;
31305f757f3fSDimitry Andric __kmp_places_set(affinity_compact, type);
3131fe6060f1SDimitry Andric set = true;
3132fe6060f1SDimitry Andric break;
3133fe6060f1SDimitry Andric }
3134fe6060f1SDimitry Andric }
3135fe6060f1SDimitry Andric }
31365f757f3fSDimitry Andric // Implementation choices for OMP_PLACES based on core attributes
31375f757f3fSDimitry Andric if (!set) {
31385f757f3fSDimitry Andric if (__kmp_match_str("core_types", scan, &next)) {
31395f757f3fSDimitry Andric scan = next;
31405f757f3fSDimitry Andric if (*scan != '\0') {
31415f757f3fSDimitry Andric KMP_WARNING(ParseExtraCharsWarn, name, scan);
31425f757f3fSDimitry Andric }
31435f757f3fSDimitry Andric __kmp_places_set(affinity_compact, KMP_HW_CORE);
31445f757f3fSDimitry Andric __kmp_affinity.flags.core_types_gran = 1;
31455f757f3fSDimitry Andric set = true;
31465f757f3fSDimitry Andric } else if (__kmp_match_str("core_effs", scan, &next) ||
31475f757f3fSDimitry Andric __kmp_match_str("core_efficiencies", scan, &next)) {
31485f757f3fSDimitry Andric scan = next;
31495f757f3fSDimitry Andric if (*scan != '\0') {
31505f757f3fSDimitry Andric KMP_WARNING(ParseExtraCharsWarn, name, scan);
31515f757f3fSDimitry Andric }
31525f757f3fSDimitry Andric __kmp_places_set(affinity_compact, KMP_HW_CORE);
31535f757f3fSDimitry Andric __kmp_affinity.flags.core_effs_gran = 1;
31545f757f3fSDimitry Andric set = true;
31555f757f3fSDimitry Andric }
31565f757f3fSDimitry Andric }
31575f757f3fSDimitry Andric // Explicit place list
3158fe6060f1SDimitry Andric if (!set) {
3159bdd1243dSDimitry Andric if (__kmp_affinity.proclist != NULL) {
3160bdd1243dSDimitry Andric KMP_INTERNAL_FREE((void *)__kmp_affinity.proclist);
3161bdd1243dSDimitry Andric __kmp_affinity.proclist = NULL;
31620b57cec5SDimitry Andric }
3163bdd1243dSDimitry Andric if (__kmp_parse_place_list(name, value, &__kmp_affinity.proclist)) {
31645f757f3fSDimitry Andric __kmp_places_set(affinity_explicit, KMP_HW_THREAD);
3165fe6060f1SDimitry Andric } else {
3166fe6060f1SDimitry Andric // Syntax error fallback
31675f757f3fSDimitry Andric __kmp_places_syntax_error_fallback(name, KMP_HW_CORE);
3168fe6060f1SDimitry Andric }
31690b57cec5SDimitry Andric if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
31700b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
31710b57cec5SDimitry Andric }
31720b57cec5SDimitry Andric return;
31730b57cec5SDimitry Andric }
31745f757f3fSDimitry Andric
31755f757f3fSDimitry Andric kmp_hw_t gran = __kmp_affinity.gran;
3176bdd1243dSDimitry Andric if (__kmp_affinity.gran != KMP_HW_UNKNOWN) {
31775f757f3fSDimitry Andric gran = __kmp_affinity.gran;
31785f757f3fSDimitry Andric } else {
31795f757f3fSDimitry Andric gran = KMP_HW_CORE;
3180fe6060f1SDimitry Andric }
31810b57cec5SDimitry Andric
31820b57cec5SDimitry Andric if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
31830b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
31840b57cec5SDimitry Andric }
31850b57cec5SDimitry Andric
31860b57cec5SDimitry Andric SKIP_WS(scan);
31870b57cec5SDimitry Andric if (*scan == '\0') {
31880b57cec5SDimitry Andric return;
31890b57cec5SDimitry Andric }
31900b57cec5SDimitry Andric
31910b57cec5SDimitry Andric // Parse option count parameter in parentheses
31920b57cec5SDimitry Andric if (*scan != '(') {
31935f757f3fSDimitry Andric __kmp_places_syntax_error_fallback(name, gran);
31940b57cec5SDimitry Andric return;
31950b57cec5SDimitry Andric }
31960b57cec5SDimitry Andric scan++; // skip '('
31970b57cec5SDimitry Andric
31980b57cec5SDimitry Andric SKIP_WS(scan);
31990b57cec5SDimitry Andric next = scan;
32000b57cec5SDimitry Andric SKIP_DIGITS(next);
32010b57cec5SDimitry Andric count = __kmp_str_to_int(scan, *next);
32020b57cec5SDimitry Andric KMP_ASSERT(count >= 0);
32030b57cec5SDimitry Andric scan = next;
32040b57cec5SDimitry Andric
32050b57cec5SDimitry Andric SKIP_WS(scan);
32060b57cec5SDimitry Andric if (*scan != ')') {
32075f757f3fSDimitry Andric __kmp_places_syntax_error_fallback(name, gran);
32080b57cec5SDimitry Andric return;
32090b57cec5SDimitry Andric }
32100b57cec5SDimitry Andric scan++; // skip ')'
32110b57cec5SDimitry Andric
32120b57cec5SDimitry Andric SKIP_WS(scan);
32130b57cec5SDimitry Andric if (*scan != '\0') {
32140b57cec5SDimitry Andric KMP_WARNING(ParseExtraCharsWarn, name, scan);
32150b57cec5SDimitry Andric }
32160b57cec5SDimitry Andric __kmp_affinity_num_places = count;
32170b57cec5SDimitry Andric }
32180b57cec5SDimitry Andric
__kmp_stg_print_places(kmp_str_buf_t * buffer,char const * name,void * data)32190b57cec5SDimitry Andric static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
32200b57cec5SDimitry Andric void *data) {
3221bdd1243dSDimitry Andric enum affinity_type type = __kmp_affinity.type;
3222bdd1243dSDimitry Andric const char *proclist = __kmp_affinity.proclist;
3223bdd1243dSDimitry Andric kmp_hw_t gran = __kmp_affinity.gran;
3224bdd1243dSDimitry Andric
32250b57cec5SDimitry Andric if (__kmp_env_format) {
32260b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME;
32270b57cec5SDimitry Andric } else {
32280b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s", name);
32290b57cec5SDimitry Andric }
32300b57cec5SDimitry Andric if ((__kmp_nested_proc_bind.used == 0) ||
32310b57cec5SDimitry Andric (__kmp_nested_proc_bind.bind_types == NULL) ||
32320b57cec5SDimitry Andric (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
32330b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3234bdd1243dSDimitry Andric } else if (type == affinity_explicit) {
3235bdd1243dSDimitry Andric if (proclist != NULL) {
3236bdd1243dSDimitry Andric __kmp_str_buf_print(buffer, "='%s'\n", proclist);
32370b57cec5SDimitry Andric } else {
32380b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
32390b57cec5SDimitry Andric }
3240bdd1243dSDimitry Andric } else if (type == affinity_compact) {
32410b57cec5SDimitry Andric int num;
3242bdd1243dSDimitry Andric if (__kmp_affinity.num_masks > 0) {
3243bdd1243dSDimitry Andric num = __kmp_affinity.num_masks;
32440b57cec5SDimitry Andric } else if (__kmp_affinity_num_places > 0) {
32450b57cec5SDimitry Andric num = __kmp_affinity_num_places;
32460b57cec5SDimitry Andric } else {
32470b57cec5SDimitry Andric num = 0;
32480b57cec5SDimitry Andric }
3249bdd1243dSDimitry Andric if (gran != KMP_HW_UNKNOWN) {
32505f757f3fSDimitry Andric // If core_types or core_effs, just print and return
32515f757f3fSDimitry Andric if (__kmp_affinity.flags.core_types_gran) {
32525f757f3fSDimitry Andric __kmp_str_buf_print(buffer, "='%s'\n", "core_types");
32535f757f3fSDimitry Andric return;
32540b57cec5SDimitry Andric }
32555f757f3fSDimitry Andric if (__kmp_affinity.flags.core_effs_gran) {
32565f757f3fSDimitry Andric __kmp_str_buf_print(buffer, "='%s'\n", "core_effs");
32575f757f3fSDimitry Andric return;
32585f757f3fSDimitry Andric }
32595f757f3fSDimitry Andric
32605f757f3fSDimitry Andric // threads, cores, sockets, cores:<attribute>, etc.
32615f757f3fSDimitry Andric const char *name = __kmp_hw_get_keyword(gran, true);
32625f757f3fSDimitry Andric __kmp_str_buf_print(buffer, "='%s", name);
32635f757f3fSDimitry Andric
32645f757f3fSDimitry Andric // Add core attributes if it exists
32655f757f3fSDimitry Andric if (__kmp_affinity.core_attr_gran.valid) {
32665f757f3fSDimitry Andric kmp_hw_core_type_t ct =
32675f757f3fSDimitry Andric (kmp_hw_core_type_t)__kmp_affinity.core_attr_gran.core_type;
32685f757f3fSDimitry Andric int eff = __kmp_affinity.core_attr_gran.core_eff;
32695f757f3fSDimitry Andric if (ct != KMP_HW_CORE_TYPE_UNKNOWN) {
32705f757f3fSDimitry Andric const char *ct_name = __kmp_hw_get_core_type_keyword(ct);
32715f757f3fSDimitry Andric __kmp_str_buf_print(buffer, ":%s", name, ct_name);
32725f757f3fSDimitry Andric } else if (eff >= 0 && eff < KMP_HW_MAX_NUM_CORE_EFFS) {
32735f757f3fSDimitry Andric __kmp_str_buf_print(buffer, ":eff%d", name, eff);
32745f757f3fSDimitry Andric }
32755f757f3fSDimitry Andric }
32765f757f3fSDimitry Andric
32775f757f3fSDimitry Andric // Add the '(#)' part if it exists
32785f757f3fSDimitry Andric if (num > 0)
32795f757f3fSDimitry Andric __kmp_str_buf_print(buffer, "(%d)", num);
32805f757f3fSDimitry Andric __kmp_str_buf_print(buffer, "'\n");
32810b57cec5SDimitry Andric } else {
32820b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
32830b57cec5SDimitry Andric }
32840b57cec5SDimitry Andric } else {
32850b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
32860b57cec5SDimitry Andric }
32870b57cec5SDimitry Andric }
32880b57cec5SDimitry Andric
__kmp_stg_parse_topology_method(char const * name,char const * value,void * data)32890b57cec5SDimitry Andric static void __kmp_stg_parse_topology_method(char const *name, char const *value,
32900b57cec5SDimitry Andric void *data) {
32910b57cec5SDimitry Andric if (__kmp_str_match("all", 1, value)) {
32920b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_all;
32930b57cec5SDimitry Andric }
32940b57cec5SDimitry Andric #if KMP_USE_HWLOC
32950b57cec5SDimitry Andric else if (__kmp_str_match("hwloc", 1, value)) {
32960b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_hwloc;
32970b57cec5SDimitry Andric }
32980b57cec5SDimitry Andric #endif
32990b57cec5SDimitry Andric #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3300fe6060f1SDimitry Andric else if (__kmp_str_match("cpuid_leaf31", 12, value) ||
3301fe6060f1SDimitry Andric __kmp_str_match("cpuid 1f", 8, value) ||
3302fe6060f1SDimitry Andric __kmp_str_match("cpuid 31", 8, value) ||
3303fe6060f1SDimitry Andric __kmp_str_match("cpuid1f", 7, value) ||
3304fe6060f1SDimitry Andric __kmp_str_match("cpuid31", 7, value) ||
3305fe6060f1SDimitry Andric __kmp_str_match("leaf 1f", 7, value) ||
3306fe6060f1SDimitry Andric __kmp_str_match("leaf 31", 7, value) ||
3307fe6060f1SDimitry Andric __kmp_str_match("leaf1f", 6, value) ||
3308fe6060f1SDimitry Andric __kmp_str_match("leaf31", 6, value)) {
3309fe6060f1SDimitry Andric __kmp_affinity_top_method = affinity_top_method_x2apicid_1f;
3310fe6060f1SDimitry Andric } else if (__kmp_str_match("x2apic id", 9, value) ||
33110b57cec5SDimitry Andric __kmp_str_match("x2apic_id", 9, value) ||
33120b57cec5SDimitry Andric __kmp_str_match("x2apic-id", 9, value) ||
33130b57cec5SDimitry Andric __kmp_str_match("x2apicid", 8, value) ||
33140b57cec5SDimitry Andric __kmp_str_match("cpuid leaf 11", 13, value) ||
33150b57cec5SDimitry Andric __kmp_str_match("cpuid_leaf_11", 13, value) ||
33160b57cec5SDimitry Andric __kmp_str_match("cpuid-leaf-11", 13, value) ||
33170b57cec5SDimitry Andric __kmp_str_match("cpuid leaf11", 12, value) ||
33180b57cec5SDimitry Andric __kmp_str_match("cpuid_leaf11", 12, value) ||
33190b57cec5SDimitry Andric __kmp_str_match("cpuid-leaf11", 12, value) ||
33200b57cec5SDimitry Andric __kmp_str_match("cpuidleaf 11", 12, value) ||
33210b57cec5SDimitry Andric __kmp_str_match("cpuidleaf_11", 12, value) ||
33220b57cec5SDimitry Andric __kmp_str_match("cpuidleaf-11", 12, value) ||
33230b57cec5SDimitry Andric __kmp_str_match("cpuidleaf11", 11, value) ||
33240b57cec5SDimitry Andric __kmp_str_match("cpuid 11", 8, value) ||
33250b57cec5SDimitry Andric __kmp_str_match("cpuid_11", 8, value) ||
33260b57cec5SDimitry Andric __kmp_str_match("cpuid-11", 8, value) ||
33270b57cec5SDimitry Andric __kmp_str_match("cpuid11", 7, value) ||
33280b57cec5SDimitry Andric __kmp_str_match("leaf 11", 7, value) ||
33290b57cec5SDimitry Andric __kmp_str_match("leaf_11", 7, value) ||
33300b57cec5SDimitry Andric __kmp_str_match("leaf-11", 7, value) ||
33310b57cec5SDimitry Andric __kmp_str_match("leaf11", 6, value)) {
33320b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_x2apicid;
33330b57cec5SDimitry Andric } else if (__kmp_str_match("apic id", 7, value) ||
33340b57cec5SDimitry Andric __kmp_str_match("apic_id", 7, value) ||
33350b57cec5SDimitry Andric __kmp_str_match("apic-id", 7, value) ||
33360b57cec5SDimitry Andric __kmp_str_match("apicid", 6, value) ||
33370b57cec5SDimitry Andric __kmp_str_match("cpuid leaf 4", 12, value) ||
33380b57cec5SDimitry Andric __kmp_str_match("cpuid_leaf_4", 12, value) ||
33390b57cec5SDimitry Andric __kmp_str_match("cpuid-leaf-4", 12, value) ||
33400b57cec5SDimitry Andric __kmp_str_match("cpuid leaf4", 11, value) ||
33410b57cec5SDimitry Andric __kmp_str_match("cpuid_leaf4", 11, value) ||
33420b57cec5SDimitry Andric __kmp_str_match("cpuid-leaf4", 11, value) ||
33430b57cec5SDimitry Andric __kmp_str_match("cpuidleaf 4", 11, value) ||
33440b57cec5SDimitry Andric __kmp_str_match("cpuidleaf_4", 11, value) ||
33450b57cec5SDimitry Andric __kmp_str_match("cpuidleaf-4", 11, value) ||
33460b57cec5SDimitry Andric __kmp_str_match("cpuidleaf4", 10, value) ||
33470b57cec5SDimitry Andric __kmp_str_match("cpuid 4", 7, value) ||
33480b57cec5SDimitry Andric __kmp_str_match("cpuid_4", 7, value) ||
33490b57cec5SDimitry Andric __kmp_str_match("cpuid-4", 7, value) ||
33500b57cec5SDimitry Andric __kmp_str_match("cpuid4", 6, value) ||
33510b57cec5SDimitry Andric __kmp_str_match("leaf 4", 6, value) ||
33520b57cec5SDimitry Andric __kmp_str_match("leaf_4", 6, value) ||
33530b57cec5SDimitry Andric __kmp_str_match("leaf-4", 6, value) ||
33540b57cec5SDimitry Andric __kmp_str_match("leaf4", 5, value)) {
33550b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_apicid;
33560b57cec5SDimitry Andric }
33570b57cec5SDimitry Andric #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
33580b57cec5SDimitry Andric else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
33590b57cec5SDimitry Andric __kmp_str_match("cpuinfo", 5, value)) {
33600b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_cpuinfo;
33610b57cec5SDimitry Andric }
33620b57cec5SDimitry Andric #if KMP_GROUP_AFFINITY
33630b57cec5SDimitry Andric else if (__kmp_str_match("group", 1, value)) {
3364349cc55cSDimitry Andric KMP_WARNING(StgDeprecatedValue, name, value, "all");
33650b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_group;
33660b57cec5SDimitry Andric }
33670b57cec5SDimitry Andric #endif /* KMP_GROUP_AFFINITY */
33680b57cec5SDimitry Andric else if (__kmp_str_match("flat", 1, value)) {
33690b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_flat;
33700b57cec5SDimitry Andric } else {
33710b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
33720b57cec5SDimitry Andric }
33730b57cec5SDimitry Andric } // __kmp_stg_parse_topology_method
33740b57cec5SDimitry Andric
__kmp_stg_print_topology_method(kmp_str_buf_t * buffer,char const * name,void * data)33750b57cec5SDimitry Andric static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
33760b57cec5SDimitry Andric char const *name, void *data) {
33770b57cec5SDimitry Andric char const *value = NULL;
33780b57cec5SDimitry Andric
33790b57cec5SDimitry Andric switch (__kmp_affinity_top_method) {
33800b57cec5SDimitry Andric case affinity_top_method_default:
33810b57cec5SDimitry Andric value = "default";
33820b57cec5SDimitry Andric break;
33830b57cec5SDimitry Andric
33840b57cec5SDimitry Andric case affinity_top_method_all:
33850b57cec5SDimitry Andric value = "all";
33860b57cec5SDimitry Andric break;
33870b57cec5SDimitry Andric
33880b57cec5SDimitry Andric #if KMP_ARCH_X86 || KMP_ARCH_X86_64
3389fe6060f1SDimitry Andric case affinity_top_method_x2apicid_1f:
3390fe6060f1SDimitry Andric value = "x2APIC id leaf 0x1f";
3391fe6060f1SDimitry Andric break;
3392fe6060f1SDimitry Andric
33930b57cec5SDimitry Andric case affinity_top_method_x2apicid:
3394fe6060f1SDimitry Andric value = "x2APIC id leaf 0xb";
33950b57cec5SDimitry Andric break;
33960b57cec5SDimitry Andric
33970b57cec5SDimitry Andric case affinity_top_method_apicid:
33980b57cec5SDimitry Andric value = "APIC id";
33990b57cec5SDimitry Andric break;
34000b57cec5SDimitry Andric #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
34010b57cec5SDimitry Andric
34020b57cec5SDimitry Andric #if KMP_USE_HWLOC
34030b57cec5SDimitry Andric case affinity_top_method_hwloc:
34040b57cec5SDimitry Andric value = "hwloc";
34050b57cec5SDimitry Andric break;
34060b57cec5SDimitry Andric #endif
34070b57cec5SDimitry Andric
34080b57cec5SDimitry Andric case affinity_top_method_cpuinfo:
34090b57cec5SDimitry Andric value = "cpuinfo";
34100b57cec5SDimitry Andric break;
34110b57cec5SDimitry Andric
34120b57cec5SDimitry Andric #if KMP_GROUP_AFFINITY
34130b57cec5SDimitry Andric case affinity_top_method_group:
34140b57cec5SDimitry Andric value = "group";
34150b57cec5SDimitry Andric break;
34160b57cec5SDimitry Andric #endif /* KMP_GROUP_AFFINITY */
34170b57cec5SDimitry Andric
34180b57cec5SDimitry Andric case affinity_top_method_flat:
34190b57cec5SDimitry Andric value = "flat";
34200b57cec5SDimitry Andric break;
34210b57cec5SDimitry Andric }
34220b57cec5SDimitry Andric
34230b57cec5SDimitry Andric if (value != NULL) {
34240b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, value);
34250b57cec5SDimitry Andric }
34260b57cec5SDimitry Andric } // __kmp_stg_print_topology_method
34270b57cec5SDimitry Andric
3428349cc55cSDimitry Andric // KMP_TEAMS_PROC_BIND
3429349cc55cSDimitry Andric struct kmp_proc_bind_info_t {
3430349cc55cSDimitry Andric const char *name;
3431349cc55cSDimitry Andric kmp_proc_bind_t proc_bind;
3432349cc55cSDimitry Andric };
3433349cc55cSDimitry Andric static kmp_proc_bind_info_t proc_bind_table[] = {
3434349cc55cSDimitry Andric {"spread", proc_bind_spread},
3435349cc55cSDimitry Andric {"true", proc_bind_spread},
3436349cc55cSDimitry Andric {"close", proc_bind_close},
3437349cc55cSDimitry Andric // teams-bind = false means "replicate the primary thread's affinity"
3438349cc55cSDimitry Andric {"false", proc_bind_primary},
3439349cc55cSDimitry Andric {"primary", proc_bind_primary}};
__kmp_stg_parse_teams_proc_bind(char const * name,char const * value,void * data)3440349cc55cSDimitry Andric static void __kmp_stg_parse_teams_proc_bind(char const *name, char const *value,
3441349cc55cSDimitry Andric void *data) {
3442349cc55cSDimitry Andric int valid;
3443349cc55cSDimitry Andric const char *end;
3444349cc55cSDimitry Andric valid = 0;
3445349cc55cSDimitry Andric for (size_t i = 0; i < sizeof(proc_bind_table) / sizeof(proc_bind_table[0]);
3446349cc55cSDimitry Andric ++i) {
3447349cc55cSDimitry Andric if (__kmp_match_str(proc_bind_table[i].name, value, &end)) {
3448349cc55cSDimitry Andric __kmp_teams_proc_bind = proc_bind_table[i].proc_bind;
3449349cc55cSDimitry Andric valid = 1;
3450349cc55cSDimitry Andric break;
3451349cc55cSDimitry Andric }
3452349cc55cSDimitry Andric }
3453349cc55cSDimitry Andric if (!valid) {
3454349cc55cSDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
3455349cc55cSDimitry Andric }
3456349cc55cSDimitry Andric }
__kmp_stg_print_teams_proc_bind(kmp_str_buf_t * buffer,char const * name,void * data)3457349cc55cSDimitry Andric static void __kmp_stg_print_teams_proc_bind(kmp_str_buf_t *buffer,
3458349cc55cSDimitry Andric char const *name, void *data) {
3459349cc55cSDimitry Andric const char *value = KMP_I18N_STR(NotDefined);
3460349cc55cSDimitry Andric for (size_t i = 0; i < sizeof(proc_bind_table) / sizeof(proc_bind_table[0]);
3461349cc55cSDimitry Andric ++i) {
3462349cc55cSDimitry Andric if (__kmp_teams_proc_bind == proc_bind_table[i].proc_bind) {
3463349cc55cSDimitry Andric value = proc_bind_table[i].name;
3464349cc55cSDimitry Andric break;
3465349cc55cSDimitry Andric }
3466349cc55cSDimitry Andric }
3467349cc55cSDimitry Andric __kmp_stg_print_str(buffer, name, value);
3468349cc55cSDimitry Andric }
34690b57cec5SDimitry Andric #endif /* KMP_AFFINITY_SUPPORTED */
34700b57cec5SDimitry Andric
34710b57cec5SDimitry Andric // OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
34720b57cec5SDimitry Andric // OMP_PLACES / place-partition-var is not.
__kmp_stg_parse_proc_bind(char const * name,char const * value,void * data)34730b57cec5SDimitry Andric static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
34740b57cec5SDimitry Andric void *data) {
34750b57cec5SDimitry Andric kmp_setting_t **rivals = (kmp_setting_t **)data;
34760b57cec5SDimitry Andric int rc;
34770b57cec5SDimitry Andric
34780b57cec5SDimitry Andric rc = __kmp_stg_check_rivals(name, value, rivals);
34790b57cec5SDimitry Andric if (rc) {
34800b57cec5SDimitry Andric return;
34810b57cec5SDimitry Andric }
34820b57cec5SDimitry Andric
34830b57cec5SDimitry Andric // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
34840b57cec5SDimitry Andric KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
34850b57cec5SDimitry Andric (__kmp_nested_proc_bind.used > 0));
34860b57cec5SDimitry Andric
34870b57cec5SDimitry Andric const char *buf = value;
34880b57cec5SDimitry Andric const char *next;
34890b57cec5SDimitry Andric int num;
34900b57cec5SDimitry Andric SKIP_WS(buf);
34910b57cec5SDimitry Andric if ((*buf >= '0') && (*buf <= '9')) {
34920b57cec5SDimitry Andric next = buf;
34930b57cec5SDimitry Andric SKIP_DIGITS(next);
34940b57cec5SDimitry Andric num = __kmp_str_to_int(buf, *next);
34950b57cec5SDimitry Andric KMP_ASSERT(num >= 0);
34960b57cec5SDimitry Andric buf = next;
34970b57cec5SDimitry Andric SKIP_WS(buf);
34980b57cec5SDimitry Andric } else {
34990b57cec5SDimitry Andric num = -1;
35000b57cec5SDimitry Andric }
35010b57cec5SDimitry Andric
35020b57cec5SDimitry Andric next = buf;
35030b57cec5SDimitry Andric if (__kmp_match_str("disabled", buf, &next)) {
35040b57cec5SDimitry Andric buf = next;
35050b57cec5SDimitry Andric SKIP_WS(buf);
35060b57cec5SDimitry Andric #if KMP_AFFINITY_SUPPORTED
3507bdd1243dSDimitry Andric __kmp_affinity.type = affinity_disabled;
35080b57cec5SDimitry Andric #endif /* KMP_AFFINITY_SUPPORTED */
35090b57cec5SDimitry Andric __kmp_nested_proc_bind.used = 1;
35100b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
35110b57cec5SDimitry Andric } else if ((num == (int)proc_bind_false) ||
35120b57cec5SDimitry Andric __kmp_match_str("false", buf, &next)) {
35130b57cec5SDimitry Andric buf = next;
35140b57cec5SDimitry Andric SKIP_WS(buf);
35150b57cec5SDimitry Andric #if KMP_AFFINITY_SUPPORTED
3516bdd1243dSDimitry Andric __kmp_affinity.type = affinity_none;
35170b57cec5SDimitry Andric #endif /* KMP_AFFINITY_SUPPORTED */
35180b57cec5SDimitry Andric __kmp_nested_proc_bind.used = 1;
35190b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
35200b57cec5SDimitry Andric } else if ((num == (int)proc_bind_true) ||
35210b57cec5SDimitry Andric __kmp_match_str("true", buf, &next)) {
35220b57cec5SDimitry Andric buf = next;
35230b57cec5SDimitry Andric SKIP_WS(buf);
35240b57cec5SDimitry Andric __kmp_nested_proc_bind.used = 1;
35250b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
35260b57cec5SDimitry Andric } else {
35270b57cec5SDimitry Andric // Count the number of values in the env var string
35280b57cec5SDimitry Andric const char *scan;
35290b57cec5SDimitry Andric int nelem = 1;
35300b57cec5SDimitry Andric for (scan = buf; *scan != '\0'; scan++) {
35310b57cec5SDimitry Andric if (*scan == ',') {
35320b57cec5SDimitry Andric nelem++;
35330b57cec5SDimitry Andric }
35340b57cec5SDimitry Andric }
35350b57cec5SDimitry Andric
35360b57cec5SDimitry Andric // Create / expand the nested proc_bind array as needed
35370b57cec5SDimitry Andric if (__kmp_nested_proc_bind.size < nelem) {
35380b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types =
35390b57cec5SDimitry Andric (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
35400b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types,
35410b57cec5SDimitry Andric sizeof(kmp_proc_bind_t) * nelem);
35420b57cec5SDimitry Andric if (__kmp_nested_proc_bind.bind_types == NULL) {
35430b57cec5SDimitry Andric KMP_FATAL(MemoryAllocFailed);
35440b57cec5SDimitry Andric }
35450b57cec5SDimitry Andric __kmp_nested_proc_bind.size = nelem;
35460b57cec5SDimitry Andric }
35470b57cec5SDimitry Andric __kmp_nested_proc_bind.used = nelem;
35480b57cec5SDimitry Andric
35490b57cec5SDimitry Andric if (nelem > 1 && !__kmp_dflt_max_active_levels_set)
35500b57cec5SDimitry Andric __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
35510b57cec5SDimitry Andric
35520b57cec5SDimitry Andric // Save values in the nested proc_bind array
35530b57cec5SDimitry Andric int i = 0;
35540b57cec5SDimitry Andric for (;;) {
35550b57cec5SDimitry Andric enum kmp_proc_bind_t bind;
35560b57cec5SDimitry Andric
3557fe6060f1SDimitry Andric if ((num == (int)proc_bind_primary) ||
3558fe6060f1SDimitry Andric __kmp_match_str("master", buf, &next) ||
3559fe6060f1SDimitry Andric __kmp_match_str("primary", buf, &next)) {
35600b57cec5SDimitry Andric buf = next;
35610b57cec5SDimitry Andric SKIP_WS(buf);
3562fe6060f1SDimitry Andric bind = proc_bind_primary;
35630b57cec5SDimitry Andric } else if ((num == (int)proc_bind_close) ||
35640b57cec5SDimitry Andric __kmp_match_str("close", buf, &next)) {
35650b57cec5SDimitry Andric buf = next;
35660b57cec5SDimitry Andric SKIP_WS(buf);
35670b57cec5SDimitry Andric bind = proc_bind_close;
35680b57cec5SDimitry Andric } else if ((num == (int)proc_bind_spread) ||
35690b57cec5SDimitry Andric __kmp_match_str("spread", buf, &next)) {
35700b57cec5SDimitry Andric buf = next;
35710b57cec5SDimitry Andric SKIP_WS(buf);
35720b57cec5SDimitry Andric bind = proc_bind_spread;
35730b57cec5SDimitry Andric } else {
35740b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
35750b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
35760b57cec5SDimitry Andric __kmp_nested_proc_bind.used = 1;
35770b57cec5SDimitry Andric return;
35780b57cec5SDimitry Andric }
35790b57cec5SDimitry Andric
35800b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[i++] = bind;
35810b57cec5SDimitry Andric if (i >= nelem) {
35820b57cec5SDimitry Andric break;
35830b57cec5SDimitry Andric }
35840b57cec5SDimitry Andric KMP_DEBUG_ASSERT(*buf == ',');
35850b57cec5SDimitry Andric buf++;
35860b57cec5SDimitry Andric SKIP_WS(buf);
35870b57cec5SDimitry Andric
35880b57cec5SDimitry Andric // Read next value if it was specified as an integer
35890b57cec5SDimitry Andric if ((*buf >= '0') && (*buf <= '9')) {
35900b57cec5SDimitry Andric next = buf;
35910b57cec5SDimitry Andric SKIP_DIGITS(next);
35920b57cec5SDimitry Andric num = __kmp_str_to_int(buf, *next);
35930b57cec5SDimitry Andric KMP_ASSERT(num >= 0);
35940b57cec5SDimitry Andric buf = next;
35950b57cec5SDimitry Andric SKIP_WS(buf);
35960b57cec5SDimitry Andric } else {
35970b57cec5SDimitry Andric num = -1;
35980b57cec5SDimitry Andric }
35990b57cec5SDimitry Andric }
36000b57cec5SDimitry Andric SKIP_WS(buf);
36010b57cec5SDimitry Andric }
36020b57cec5SDimitry Andric if (*buf != '\0') {
36030b57cec5SDimitry Andric KMP_WARNING(ParseExtraCharsWarn, name, buf);
36040b57cec5SDimitry Andric }
36050b57cec5SDimitry Andric }
36060b57cec5SDimitry Andric
__kmp_stg_print_proc_bind(kmp_str_buf_t * buffer,char const * name,void * data)36070b57cec5SDimitry Andric static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
36080b57cec5SDimitry Andric void *data) {
36090b57cec5SDimitry Andric int nelem = __kmp_nested_proc_bind.used;
36100b57cec5SDimitry Andric if (__kmp_env_format) {
36110b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME;
36120b57cec5SDimitry Andric } else {
36130b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s", name);
36140b57cec5SDimitry Andric }
36150b57cec5SDimitry Andric if (nelem == 0) {
36160b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
36170b57cec5SDimitry Andric } else {
36180b57cec5SDimitry Andric int i;
36190b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "='", name);
36200b57cec5SDimitry Andric for (i = 0; i < nelem; i++) {
36210b57cec5SDimitry Andric switch (__kmp_nested_proc_bind.bind_types[i]) {
36220b57cec5SDimitry Andric case proc_bind_false:
36230b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "false");
36240b57cec5SDimitry Andric break;
36250b57cec5SDimitry Andric
36260b57cec5SDimitry Andric case proc_bind_true:
36270b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "true");
36280b57cec5SDimitry Andric break;
36290b57cec5SDimitry Andric
3630fe6060f1SDimitry Andric case proc_bind_primary:
3631fe6060f1SDimitry Andric __kmp_str_buf_print(buffer, "primary");
36320b57cec5SDimitry Andric break;
36330b57cec5SDimitry Andric
36340b57cec5SDimitry Andric case proc_bind_close:
36350b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "close");
36360b57cec5SDimitry Andric break;
36370b57cec5SDimitry Andric
36380b57cec5SDimitry Andric case proc_bind_spread:
36390b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "spread");
36400b57cec5SDimitry Andric break;
36410b57cec5SDimitry Andric
36420b57cec5SDimitry Andric case proc_bind_intel:
36430b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "intel");
36440b57cec5SDimitry Andric break;
36450b57cec5SDimitry Andric
36460b57cec5SDimitry Andric case proc_bind_default:
36470b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "default");
36480b57cec5SDimitry Andric break;
36490b57cec5SDimitry Andric }
36500b57cec5SDimitry Andric if (i < nelem - 1) {
36510b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ",");
36520b57cec5SDimitry Andric }
36530b57cec5SDimitry Andric }
36540b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "'\n");
36550b57cec5SDimitry Andric }
36560b57cec5SDimitry Andric }
36570b57cec5SDimitry Andric
__kmp_stg_parse_display_affinity(char const * name,char const * value,void * data)36580b57cec5SDimitry Andric static void __kmp_stg_parse_display_affinity(char const *name,
36590b57cec5SDimitry Andric char const *value, void *data) {
36600b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_display_affinity);
36610b57cec5SDimitry Andric }
__kmp_stg_print_display_affinity(kmp_str_buf_t * buffer,char const * name,void * data)36620b57cec5SDimitry Andric static void __kmp_stg_print_display_affinity(kmp_str_buf_t *buffer,
36630b57cec5SDimitry Andric char const *name, void *data) {
36640b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_display_affinity);
36650b57cec5SDimitry Andric }
__kmp_stg_parse_affinity_format(char const * name,char const * value,void * data)36660b57cec5SDimitry Andric static void __kmp_stg_parse_affinity_format(char const *name, char const *value,
36670b57cec5SDimitry Andric void *data) {
36680b57cec5SDimitry Andric size_t length = KMP_STRLEN(value);
36690b57cec5SDimitry Andric __kmp_strncpy_truncate(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, value,
36700b57cec5SDimitry Andric length);
36710b57cec5SDimitry Andric }
__kmp_stg_print_affinity_format(kmp_str_buf_t * buffer,char const * name,void * data)36720b57cec5SDimitry Andric static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer,
36730b57cec5SDimitry Andric char const *name, void *data) {
36740b57cec5SDimitry Andric if (__kmp_env_format) {
36750b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(name);
36760b57cec5SDimitry Andric } else {
36770b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s='", name);
36780b57cec5SDimitry Andric }
36790b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s'\n", __kmp_affinity_format);
36800b57cec5SDimitry Andric }
3681e8d8bef9SDimitry Andric
3682e8d8bef9SDimitry Andric /*-----------------------------------------------------------------------------
3683e8d8bef9SDimitry Andric OMP_ALLOCATOR sets default allocator. Here is the grammar:
3684e8d8bef9SDimitry Andric
3685e8d8bef9SDimitry Andric <allocator> |= <predef-allocator> | <predef-mem-space> |
3686e8d8bef9SDimitry Andric <predef-mem-space>:<traits>
3687e8d8bef9SDimitry Andric <traits> |= <trait>=<value> | <trait>=<value>,<traits>
3688e8d8bef9SDimitry Andric <predef-allocator> |= omp_default_mem_alloc | omp_large_cap_mem_alloc |
3689e8d8bef9SDimitry Andric omp_const_mem_alloc | omp_high_bw_mem_alloc |
3690e8d8bef9SDimitry Andric omp_low_lat_mem_alloc | omp_cgroup_mem_alloc |
3691e8d8bef9SDimitry Andric omp_pteam_mem_alloc | omp_thread_mem_alloc
3692e8d8bef9SDimitry Andric <predef-mem-space> |= omp_default_mem_space | omp_large_cap_mem_space |
3693e8d8bef9SDimitry Andric omp_const_mem_space | omp_high_bw_mem_space |
3694e8d8bef9SDimitry Andric omp_low_lat_mem_space
3695e8d8bef9SDimitry Andric <trait> |= sync_hint | alignment | access | pool_size | fallback |
3696e8d8bef9SDimitry Andric fb_data | pinned | partition
3697e8d8bef9SDimitry Andric <value> |= one of the allowed values of trait |
3698e8d8bef9SDimitry Andric non-negative integer | <predef-allocator>
3699e8d8bef9SDimitry Andric -----------------------------------------------------------------------------*/
3700e8d8bef9SDimitry Andric
__kmp_stg_parse_allocator(char const * name,char const * value,void * data)37010b57cec5SDimitry Andric static void __kmp_stg_parse_allocator(char const *name, char const *value,
37020b57cec5SDimitry Andric void *data) {
37030b57cec5SDimitry Andric const char *buf = value;
3704e8d8bef9SDimitry Andric const char *next, *scan, *start;
3705e8d8bef9SDimitry Andric char *key;
3706e8d8bef9SDimitry Andric omp_allocator_handle_t al;
3707e8d8bef9SDimitry Andric omp_memspace_handle_t ms = omp_default_mem_space;
3708e8d8bef9SDimitry Andric bool is_memspace = false;
3709e8d8bef9SDimitry Andric int ntraits = 0, count = 0;
3710e8d8bef9SDimitry Andric
37110b57cec5SDimitry Andric SKIP_WS(buf);
37120b57cec5SDimitry Andric next = buf;
3713e8d8bef9SDimitry Andric const char *delim = strchr(buf, ':');
3714e8d8bef9SDimitry Andric const char *predef_mem_space = strstr(buf, "mem_space");
3715e8d8bef9SDimitry Andric
3716e8d8bef9SDimitry Andric bool is_memalloc = (!predef_mem_space && !delim) ? true : false;
3717e8d8bef9SDimitry Andric
3718e8d8bef9SDimitry Andric // Count the number of traits in the env var string
3719e8d8bef9SDimitry Andric if (delim) {
3720e8d8bef9SDimitry Andric ntraits = 1;
3721e8d8bef9SDimitry Andric for (scan = buf; *scan != '\0'; scan++) {
3722e8d8bef9SDimitry Andric if (*scan == ',')
3723e8d8bef9SDimitry Andric ntraits++;
3724e8d8bef9SDimitry Andric }
3725e8d8bef9SDimitry Andric }
3726d409305fSDimitry Andric omp_alloctrait_t *traits =
3727d409305fSDimitry Andric (omp_alloctrait_t *)KMP_ALLOCA(ntraits * sizeof(omp_alloctrait_t));
3728e8d8bef9SDimitry Andric
3729e8d8bef9SDimitry Andric // Helper macros
3730e8d8bef9SDimitry Andric #define IS_POWER_OF_TWO(n) (((n) & ((n)-1)) == 0)
3731e8d8bef9SDimitry Andric
3732e8d8bef9SDimitry Andric #define GET_NEXT(sentinel) \
3733e8d8bef9SDimitry Andric { \
3734e8d8bef9SDimitry Andric SKIP_WS(next); \
3735e8d8bef9SDimitry Andric if (*next == sentinel) \
3736e8d8bef9SDimitry Andric next++; \
3737e8d8bef9SDimitry Andric SKIP_WS(next); \
3738e8d8bef9SDimitry Andric scan = next; \
3739e8d8bef9SDimitry Andric }
3740e8d8bef9SDimitry Andric
3741e8d8bef9SDimitry Andric #define SKIP_PAIR(key) \
3742e8d8bef9SDimitry Andric { \
3743e8d8bef9SDimitry Andric char const str_delimiter[] = {',', 0}; \
3744e8d8bef9SDimitry Andric char *value = __kmp_str_token(CCAST(char *, scan), str_delimiter, \
3745e8d8bef9SDimitry Andric CCAST(char **, &next)); \
3746e8d8bef9SDimitry Andric KMP_WARNING(StgInvalidValue, key, value); \
3747e8d8bef9SDimitry Andric ntraits--; \
3748e8d8bef9SDimitry Andric SKIP_WS(next); \
3749e8d8bef9SDimitry Andric scan = next; \
3750e8d8bef9SDimitry Andric }
3751e8d8bef9SDimitry Andric
3752e8d8bef9SDimitry Andric #define SET_KEY() \
3753e8d8bef9SDimitry Andric { \
3754e8d8bef9SDimitry Andric char const str_delimiter[] = {'=', 0}; \
3755e8d8bef9SDimitry Andric key = __kmp_str_token(CCAST(char *, start), str_delimiter, \
3756e8d8bef9SDimitry Andric CCAST(char **, &next)); \
3757e8d8bef9SDimitry Andric scan = next; \
3758e8d8bef9SDimitry Andric }
3759e8d8bef9SDimitry Andric
3760e8d8bef9SDimitry Andric scan = next;
3761e8d8bef9SDimitry Andric while (*next != '\0') {
3762e8d8bef9SDimitry Andric if (is_memalloc ||
3763e8d8bef9SDimitry Andric __kmp_match_str("fb_data", scan, &next)) { // allocator check
3764e8d8bef9SDimitry Andric start = scan;
3765e8d8bef9SDimitry Andric GET_NEXT('=');
3766e8d8bef9SDimitry Andric // check HBW and LCAP first as the only non-default supported
3767e8d8bef9SDimitry Andric if (__kmp_match_str("omp_high_bw_mem_alloc", scan, &next)) {
3768e8d8bef9SDimitry Andric SKIP_WS(next);
3769e8d8bef9SDimitry Andric if (is_memalloc) {
37700b57cec5SDimitry Andric if (__kmp_memkind_available) {
37710b57cec5SDimitry Andric __kmp_def_allocator = omp_high_bw_mem_alloc;
3772e8d8bef9SDimitry Andric return;
37730b57cec5SDimitry Andric } else {
3774e8d8bef9SDimitry Andric KMP_WARNING(OmpNoAllocator, "omp_high_bw_mem_alloc");
37750b57cec5SDimitry Andric }
3776e8d8bef9SDimitry Andric } else {
3777e8d8bef9SDimitry Andric traits[count].key = omp_atk_fb_data;
3778e8d8bef9SDimitry Andric traits[count].value = RCAST(omp_uintptr_t, omp_high_bw_mem_alloc);
3779e8d8bef9SDimitry Andric }
3780e8d8bef9SDimitry Andric } else if (__kmp_match_str("omp_large_cap_mem_alloc", scan, &next)) {
3781e8d8bef9SDimitry Andric SKIP_WS(next);
3782e8d8bef9SDimitry Andric if (is_memalloc) {
3783e8d8bef9SDimitry Andric if (__kmp_memkind_available) {
3784e8d8bef9SDimitry Andric __kmp_def_allocator = omp_large_cap_mem_alloc;
3785e8d8bef9SDimitry Andric return;
3786e8d8bef9SDimitry Andric } else {
3787e8d8bef9SDimitry Andric KMP_WARNING(OmpNoAllocator, "omp_large_cap_mem_alloc");
3788e8d8bef9SDimitry Andric }
3789e8d8bef9SDimitry Andric } else {
3790e8d8bef9SDimitry Andric traits[count].key = omp_atk_fb_data;
3791e8d8bef9SDimitry Andric traits[count].value = RCAST(omp_uintptr_t, omp_large_cap_mem_alloc);
3792e8d8bef9SDimitry Andric }
3793e8d8bef9SDimitry Andric } else if (__kmp_match_str("omp_default_mem_alloc", scan, &next)) {
3794e8d8bef9SDimitry Andric // default requested
3795e8d8bef9SDimitry Andric SKIP_WS(next);
3796e8d8bef9SDimitry Andric if (!is_memalloc) {
3797e8d8bef9SDimitry Andric traits[count].key = omp_atk_fb_data;
3798e8d8bef9SDimitry Andric traits[count].value = RCAST(omp_uintptr_t, omp_default_mem_alloc);
3799e8d8bef9SDimitry Andric }
3800e8d8bef9SDimitry Andric } else if (__kmp_match_str("omp_const_mem_alloc", scan, &next)) {
3801e8d8bef9SDimitry Andric SKIP_WS(next);
3802e8d8bef9SDimitry Andric if (is_memalloc) {
3803e8d8bef9SDimitry Andric KMP_WARNING(OmpNoAllocator, "omp_const_mem_alloc");
3804e8d8bef9SDimitry Andric } else {
3805e8d8bef9SDimitry Andric traits[count].key = omp_atk_fb_data;
3806e8d8bef9SDimitry Andric traits[count].value = RCAST(omp_uintptr_t, omp_const_mem_alloc);
3807e8d8bef9SDimitry Andric }
3808e8d8bef9SDimitry Andric } else if (__kmp_match_str("omp_low_lat_mem_alloc", scan, &next)) {
3809e8d8bef9SDimitry Andric SKIP_WS(next);
3810e8d8bef9SDimitry Andric if (is_memalloc) {
3811e8d8bef9SDimitry Andric KMP_WARNING(OmpNoAllocator, "omp_low_lat_mem_alloc");
3812e8d8bef9SDimitry Andric } else {
3813e8d8bef9SDimitry Andric traits[count].key = omp_atk_fb_data;
3814e8d8bef9SDimitry Andric traits[count].value = RCAST(omp_uintptr_t, omp_low_lat_mem_alloc);
3815e8d8bef9SDimitry Andric }
3816e8d8bef9SDimitry Andric } else if (__kmp_match_str("omp_cgroup_mem_alloc", scan, &next)) {
3817e8d8bef9SDimitry Andric SKIP_WS(next);
3818e8d8bef9SDimitry Andric if (is_memalloc) {
3819e8d8bef9SDimitry Andric KMP_WARNING(OmpNoAllocator, "omp_cgroup_mem_alloc");
3820e8d8bef9SDimitry Andric } else {
3821e8d8bef9SDimitry Andric traits[count].key = omp_atk_fb_data;
3822e8d8bef9SDimitry Andric traits[count].value = RCAST(omp_uintptr_t, omp_cgroup_mem_alloc);
3823e8d8bef9SDimitry Andric }
3824e8d8bef9SDimitry Andric } else if (__kmp_match_str("omp_pteam_mem_alloc", scan, &next)) {
3825e8d8bef9SDimitry Andric SKIP_WS(next);
3826e8d8bef9SDimitry Andric if (is_memalloc) {
3827e8d8bef9SDimitry Andric KMP_WARNING(OmpNoAllocator, "omp_pteam_mem_alloc");
3828e8d8bef9SDimitry Andric } else {
3829e8d8bef9SDimitry Andric traits[count].key = omp_atk_fb_data;
3830e8d8bef9SDimitry Andric traits[count].value = RCAST(omp_uintptr_t, omp_pteam_mem_alloc);
3831e8d8bef9SDimitry Andric }
3832e8d8bef9SDimitry Andric } else if (__kmp_match_str("omp_thread_mem_alloc", scan, &next)) {
3833e8d8bef9SDimitry Andric SKIP_WS(next);
3834e8d8bef9SDimitry Andric if (is_memalloc) {
3835e8d8bef9SDimitry Andric KMP_WARNING(OmpNoAllocator, "omp_thread_mem_alloc");
3836e8d8bef9SDimitry Andric } else {
3837e8d8bef9SDimitry Andric traits[count].key = omp_atk_fb_data;
3838e8d8bef9SDimitry Andric traits[count].value = RCAST(omp_uintptr_t, omp_thread_mem_alloc);
3839e8d8bef9SDimitry Andric }
3840e8d8bef9SDimitry Andric } else {
3841e8d8bef9SDimitry Andric if (!is_memalloc) {
3842e8d8bef9SDimitry Andric SET_KEY();
3843e8d8bef9SDimitry Andric SKIP_PAIR(key);
3844e8d8bef9SDimitry Andric continue;
3845e8d8bef9SDimitry Andric }
3846e8d8bef9SDimitry Andric }
3847e8d8bef9SDimitry Andric if (is_memalloc) {
38480b57cec5SDimitry Andric __kmp_def_allocator = omp_default_mem_alloc;
3849e8d8bef9SDimitry Andric if (next == buf || *next != '\0') {
3850e8d8bef9SDimitry Andric // either no match or extra symbols present after the matched token
3851e8d8bef9SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
3852e8d8bef9SDimitry Andric }
3853e8d8bef9SDimitry Andric return;
3854e8d8bef9SDimitry Andric } else {
3855e8d8bef9SDimitry Andric ++count;
3856e8d8bef9SDimitry Andric if (count == ntraits)
38570b57cec5SDimitry Andric break;
3858e8d8bef9SDimitry Andric GET_NEXT(',');
3859e8d8bef9SDimitry Andric }
3860e8d8bef9SDimitry Andric } else { // memspace
3861e8d8bef9SDimitry Andric if (!is_memspace) {
3862e8d8bef9SDimitry Andric if (__kmp_match_str("omp_default_mem_space", scan, &next)) {
3863e8d8bef9SDimitry Andric SKIP_WS(next);
3864e8d8bef9SDimitry Andric ms = omp_default_mem_space;
3865e8d8bef9SDimitry Andric } else if (__kmp_match_str("omp_large_cap_mem_space", scan, &next)) {
3866e8d8bef9SDimitry Andric SKIP_WS(next);
3867e8d8bef9SDimitry Andric ms = omp_large_cap_mem_space;
3868e8d8bef9SDimitry Andric } else if (__kmp_match_str("omp_const_mem_space", scan, &next)) {
3869e8d8bef9SDimitry Andric SKIP_WS(next);
3870e8d8bef9SDimitry Andric ms = omp_const_mem_space;
3871e8d8bef9SDimitry Andric } else if (__kmp_match_str("omp_high_bw_mem_space", scan, &next)) {
3872e8d8bef9SDimitry Andric SKIP_WS(next);
3873e8d8bef9SDimitry Andric ms = omp_high_bw_mem_space;
3874e8d8bef9SDimitry Andric } else if (__kmp_match_str("omp_low_lat_mem_space", scan, &next)) {
3875e8d8bef9SDimitry Andric SKIP_WS(next);
3876e8d8bef9SDimitry Andric ms = omp_low_lat_mem_space;
3877e8d8bef9SDimitry Andric } else {
38780b57cec5SDimitry Andric __kmp_def_allocator = omp_default_mem_alloc;
3879e8d8bef9SDimitry Andric if (next == buf || *next != '\0') {
3880e8d8bef9SDimitry Andric // either no match or extra symbols present after the matched token
3881e8d8bef9SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
38820b57cec5SDimitry Andric }
38830b57cec5SDimitry Andric return;
38840b57cec5SDimitry Andric }
3885e8d8bef9SDimitry Andric is_memspace = true;
3886e8d8bef9SDimitry Andric }
3887e8d8bef9SDimitry Andric if (delim) { // traits
3888e8d8bef9SDimitry Andric GET_NEXT(':');
3889e8d8bef9SDimitry Andric start = scan;
3890e8d8bef9SDimitry Andric if (__kmp_match_str("sync_hint", scan, &next)) {
3891e8d8bef9SDimitry Andric GET_NEXT('=');
3892e8d8bef9SDimitry Andric traits[count].key = omp_atk_sync_hint;
3893e8d8bef9SDimitry Andric if (__kmp_match_str("contended", scan, &next)) {
3894e8d8bef9SDimitry Andric traits[count].value = omp_atv_contended;
3895e8d8bef9SDimitry Andric } else if (__kmp_match_str("uncontended", scan, &next)) {
3896e8d8bef9SDimitry Andric traits[count].value = omp_atv_uncontended;
3897e8d8bef9SDimitry Andric } else if (__kmp_match_str("serialized", scan, &next)) {
3898e8d8bef9SDimitry Andric traits[count].value = omp_atv_serialized;
3899e8d8bef9SDimitry Andric } else if (__kmp_match_str("private", scan, &next)) {
3900e8d8bef9SDimitry Andric traits[count].value = omp_atv_private;
39010b57cec5SDimitry Andric } else {
3902e8d8bef9SDimitry Andric SET_KEY();
3903e8d8bef9SDimitry Andric SKIP_PAIR(key);
3904e8d8bef9SDimitry Andric continue;
39050b57cec5SDimitry Andric }
3906e8d8bef9SDimitry Andric } else if (__kmp_match_str("alignment", scan, &next)) {
3907e8d8bef9SDimitry Andric GET_NEXT('=');
3908e8d8bef9SDimitry Andric if (!isdigit(*next)) {
3909e8d8bef9SDimitry Andric SET_KEY();
3910e8d8bef9SDimitry Andric SKIP_PAIR(key);
3911e8d8bef9SDimitry Andric continue;
39120b57cec5SDimitry Andric }
3913e8d8bef9SDimitry Andric SKIP_DIGITS(next);
3914e8d8bef9SDimitry Andric int n = __kmp_str_to_int(scan, ',');
3915e8d8bef9SDimitry Andric if (n < 0 || !IS_POWER_OF_TWO(n)) {
3916e8d8bef9SDimitry Andric SET_KEY();
3917e8d8bef9SDimitry Andric SKIP_PAIR(key);
3918e8d8bef9SDimitry Andric continue;
39190b57cec5SDimitry Andric }
3920e8d8bef9SDimitry Andric traits[count].key = omp_atk_alignment;
3921e8d8bef9SDimitry Andric traits[count].value = n;
3922e8d8bef9SDimitry Andric } else if (__kmp_match_str("access", scan, &next)) {
3923e8d8bef9SDimitry Andric GET_NEXT('=');
3924e8d8bef9SDimitry Andric traits[count].key = omp_atk_access;
3925e8d8bef9SDimitry Andric if (__kmp_match_str("all", scan, &next)) {
3926e8d8bef9SDimitry Andric traits[count].value = omp_atv_all;
3927e8d8bef9SDimitry Andric } else if (__kmp_match_str("cgroup", scan, &next)) {
3928e8d8bef9SDimitry Andric traits[count].value = omp_atv_cgroup;
3929e8d8bef9SDimitry Andric } else if (__kmp_match_str("pteam", scan, &next)) {
3930e8d8bef9SDimitry Andric traits[count].value = omp_atv_pteam;
3931e8d8bef9SDimitry Andric } else if (__kmp_match_str("thread", scan, &next)) {
3932e8d8bef9SDimitry Andric traits[count].value = omp_atv_thread;
3933e8d8bef9SDimitry Andric } else {
3934e8d8bef9SDimitry Andric SET_KEY();
3935e8d8bef9SDimitry Andric SKIP_PAIR(key);
3936e8d8bef9SDimitry Andric continue;
3937e8d8bef9SDimitry Andric }
3938e8d8bef9SDimitry Andric } else if (__kmp_match_str("pool_size", scan, &next)) {
3939e8d8bef9SDimitry Andric GET_NEXT('=');
3940e8d8bef9SDimitry Andric if (!isdigit(*next)) {
3941e8d8bef9SDimitry Andric SET_KEY();
3942e8d8bef9SDimitry Andric SKIP_PAIR(key);
3943e8d8bef9SDimitry Andric continue;
3944e8d8bef9SDimitry Andric }
3945e8d8bef9SDimitry Andric SKIP_DIGITS(next);
3946e8d8bef9SDimitry Andric int n = __kmp_str_to_int(scan, ',');
3947e8d8bef9SDimitry Andric if (n < 0) {
3948e8d8bef9SDimitry Andric SET_KEY();
3949e8d8bef9SDimitry Andric SKIP_PAIR(key);
3950e8d8bef9SDimitry Andric continue;
3951e8d8bef9SDimitry Andric }
3952e8d8bef9SDimitry Andric traits[count].key = omp_atk_pool_size;
3953e8d8bef9SDimitry Andric traits[count].value = n;
3954e8d8bef9SDimitry Andric } else if (__kmp_match_str("fallback", scan, &next)) {
3955e8d8bef9SDimitry Andric GET_NEXT('=');
3956e8d8bef9SDimitry Andric traits[count].key = omp_atk_fallback;
3957e8d8bef9SDimitry Andric if (__kmp_match_str("default_mem_fb", scan, &next)) {
3958e8d8bef9SDimitry Andric traits[count].value = omp_atv_default_mem_fb;
3959e8d8bef9SDimitry Andric } else if (__kmp_match_str("null_fb", scan, &next)) {
3960e8d8bef9SDimitry Andric traits[count].value = omp_atv_null_fb;
3961e8d8bef9SDimitry Andric } else if (__kmp_match_str("abort_fb", scan, &next)) {
3962e8d8bef9SDimitry Andric traits[count].value = omp_atv_abort_fb;
3963e8d8bef9SDimitry Andric } else if (__kmp_match_str("allocator_fb", scan, &next)) {
3964e8d8bef9SDimitry Andric traits[count].value = omp_atv_allocator_fb;
3965e8d8bef9SDimitry Andric } else {
3966e8d8bef9SDimitry Andric SET_KEY();
3967e8d8bef9SDimitry Andric SKIP_PAIR(key);
3968e8d8bef9SDimitry Andric continue;
3969e8d8bef9SDimitry Andric }
3970e8d8bef9SDimitry Andric } else if (__kmp_match_str("pinned", scan, &next)) {
3971e8d8bef9SDimitry Andric GET_NEXT('=');
3972e8d8bef9SDimitry Andric traits[count].key = omp_atk_pinned;
3973e8d8bef9SDimitry Andric if (__kmp_str_match_true(next)) {
3974e8d8bef9SDimitry Andric traits[count].value = omp_atv_true;
3975e8d8bef9SDimitry Andric } else if (__kmp_str_match_false(next)) {
3976e8d8bef9SDimitry Andric traits[count].value = omp_atv_false;
3977e8d8bef9SDimitry Andric } else {
3978e8d8bef9SDimitry Andric SET_KEY();
3979e8d8bef9SDimitry Andric SKIP_PAIR(key);
3980e8d8bef9SDimitry Andric continue;
3981e8d8bef9SDimitry Andric }
3982e8d8bef9SDimitry Andric } else if (__kmp_match_str("partition", scan, &next)) {
3983e8d8bef9SDimitry Andric GET_NEXT('=');
3984e8d8bef9SDimitry Andric traits[count].key = omp_atk_partition;
3985e8d8bef9SDimitry Andric if (__kmp_match_str("environment", scan, &next)) {
3986e8d8bef9SDimitry Andric traits[count].value = omp_atv_environment;
3987e8d8bef9SDimitry Andric } else if (__kmp_match_str("nearest", scan, &next)) {
3988e8d8bef9SDimitry Andric traits[count].value = omp_atv_nearest;
3989e8d8bef9SDimitry Andric } else if (__kmp_match_str("blocked", scan, &next)) {
3990e8d8bef9SDimitry Andric traits[count].value = omp_atv_blocked;
3991e8d8bef9SDimitry Andric } else if (__kmp_match_str("interleaved", scan, &next)) {
3992e8d8bef9SDimitry Andric traits[count].value = omp_atv_interleaved;
3993e8d8bef9SDimitry Andric } else {
3994e8d8bef9SDimitry Andric SET_KEY();
3995e8d8bef9SDimitry Andric SKIP_PAIR(key);
3996e8d8bef9SDimitry Andric continue;
3997e8d8bef9SDimitry Andric }
3998e8d8bef9SDimitry Andric } else {
3999e8d8bef9SDimitry Andric SET_KEY();
4000e8d8bef9SDimitry Andric SKIP_PAIR(key);
4001e8d8bef9SDimitry Andric continue;
4002e8d8bef9SDimitry Andric }
4003e8d8bef9SDimitry Andric SKIP_WS(next);
4004e8d8bef9SDimitry Andric ++count;
4005e8d8bef9SDimitry Andric if (count == ntraits)
4006e8d8bef9SDimitry Andric break;
4007e8d8bef9SDimitry Andric GET_NEXT(',');
4008e8d8bef9SDimitry Andric } // traits
4009e8d8bef9SDimitry Andric } // memspace
4010e8d8bef9SDimitry Andric } // while
4011e8d8bef9SDimitry Andric al = __kmpc_init_allocator(__kmp_get_gtid(), ms, ntraits, traits);
4012e8d8bef9SDimitry Andric __kmp_def_allocator = (al == omp_null_allocator) ? omp_default_mem_alloc : al;
40130b57cec5SDimitry Andric }
40140b57cec5SDimitry Andric
__kmp_stg_print_allocator(kmp_str_buf_t * buffer,char const * name,void * data)40150b57cec5SDimitry Andric static void __kmp_stg_print_allocator(kmp_str_buf_t *buffer, char const *name,
40160b57cec5SDimitry Andric void *data) {
40170b57cec5SDimitry Andric if (__kmp_def_allocator == omp_default_mem_alloc) {
40180b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "omp_default_mem_alloc");
40190b57cec5SDimitry Andric } else if (__kmp_def_allocator == omp_high_bw_mem_alloc) {
40200b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "omp_high_bw_mem_alloc");
40210b57cec5SDimitry Andric } else if (__kmp_def_allocator == omp_large_cap_mem_alloc) {
40220b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "omp_large_cap_mem_alloc");
40230b57cec5SDimitry Andric } else if (__kmp_def_allocator == omp_const_mem_alloc) {
40240b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "omp_const_mem_alloc");
40250b57cec5SDimitry Andric } else if (__kmp_def_allocator == omp_low_lat_mem_alloc) {
40260b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "omp_low_lat_mem_alloc");
40270b57cec5SDimitry Andric } else if (__kmp_def_allocator == omp_cgroup_mem_alloc) {
40280b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "omp_cgroup_mem_alloc");
40290b57cec5SDimitry Andric } else if (__kmp_def_allocator == omp_pteam_mem_alloc) {
40300b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "omp_pteam_mem_alloc");
40310b57cec5SDimitry Andric } else if (__kmp_def_allocator == omp_thread_mem_alloc) {
40320b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "omp_thread_mem_alloc");
40330b57cec5SDimitry Andric }
40340b57cec5SDimitry Andric }
40350b57cec5SDimitry Andric
40360b57cec5SDimitry Andric // -----------------------------------------------------------------------------
40370b57cec5SDimitry Andric // OMP_DYNAMIC
40380b57cec5SDimitry Andric
__kmp_stg_parse_omp_dynamic(char const * name,char const * value,void * data)40390b57cec5SDimitry Andric static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
40400b57cec5SDimitry Andric void *data) {
40410b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
40420b57cec5SDimitry Andric } // __kmp_stg_parse_omp_dynamic
40430b57cec5SDimitry Andric
__kmp_stg_print_omp_dynamic(kmp_str_buf_t * buffer,char const * name,void * data)40440b57cec5SDimitry Andric static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
40450b57cec5SDimitry Andric void *data) {
40460b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
40470b57cec5SDimitry Andric } // __kmp_stg_print_omp_dynamic
40480b57cec5SDimitry Andric
__kmp_stg_parse_kmp_dynamic_mode(char const * name,char const * value,void * data)40490b57cec5SDimitry Andric static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
40500b57cec5SDimitry Andric char const *value, void *data) {
40510b57cec5SDimitry Andric if (TCR_4(__kmp_init_parallel)) {
40520b57cec5SDimitry Andric KMP_WARNING(EnvParallelWarn, name);
40530b57cec5SDimitry Andric __kmp_env_toPrint(name, 0);
40540b57cec5SDimitry Andric return;
40550b57cec5SDimitry Andric }
40560b57cec5SDimitry Andric #ifdef USE_LOAD_BALANCE
40570b57cec5SDimitry Andric else if (__kmp_str_match("load balance", 2, value) ||
40580b57cec5SDimitry Andric __kmp_str_match("load_balance", 2, value) ||
40590b57cec5SDimitry Andric __kmp_str_match("load-balance", 2, value) ||
40600b57cec5SDimitry Andric __kmp_str_match("loadbalance", 2, value) ||
40610b57cec5SDimitry Andric __kmp_str_match("balance", 1, value)) {
40620b57cec5SDimitry Andric __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
40630b57cec5SDimitry Andric }
40640b57cec5SDimitry Andric #endif /* USE_LOAD_BALANCE */
40650b57cec5SDimitry Andric else if (__kmp_str_match("thread limit", 1, value) ||
40660b57cec5SDimitry Andric __kmp_str_match("thread_limit", 1, value) ||
40670b57cec5SDimitry Andric __kmp_str_match("thread-limit", 1, value) ||
40680b57cec5SDimitry Andric __kmp_str_match("threadlimit", 1, value) ||
40690b57cec5SDimitry Andric __kmp_str_match("limit", 2, value)) {
40700b57cec5SDimitry Andric __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
40710b57cec5SDimitry Andric } else if (__kmp_str_match("random", 1, value)) {
40720b57cec5SDimitry Andric __kmp_global.g.g_dynamic_mode = dynamic_random;
40730b57cec5SDimitry Andric } else {
40740b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
40750b57cec5SDimitry Andric }
40760b57cec5SDimitry Andric } //__kmp_stg_parse_kmp_dynamic_mode
40770b57cec5SDimitry Andric
__kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t * buffer,char const * name,void * data)40780b57cec5SDimitry Andric static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
40790b57cec5SDimitry Andric char const *name, void *data) {
40800b57cec5SDimitry Andric #if KMP_DEBUG
40810b57cec5SDimitry Andric if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
40820b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
40830b57cec5SDimitry Andric }
40840b57cec5SDimitry Andric #ifdef USE_LOAD_BALANCE
40850b57cec5SDimitry Andric else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
40860b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "load balance");
40870b57cec5SDimitry Andric }
40880b57cec5SDimitry Andric #endif /* USE_LOAD_BALANCE */
40890b57cec5SDimitry Andric else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
40900b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "thread limit");
40910b57cec5SDimitry Andric } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
40920b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "random");
40930b57cec5SDimitry Andric } else {
40940b57cec5SDimitry Andric KMP_ASSERT(0);
40950b57cec5SDimitry Andric }
40960b57cec5SDimitry Andric #endif /* KMP_DEBUG */
40970b57cec5SDimitry Andric } // __kmp_stg_print_kmp_dynamic_mode
40980b57cec5SDimitry Andric
40990b57cec5SDimitry Andric #ifdef USE_LOAD_BALANCE
41000b57cec5SDimitry Andric
41010b57cec5SDimitry Andric // -----------------------------------------------------------------------------
41020b57cec5SDimitry Andric // KMP_LOAD_BALANCE_INTERVAL
41030b57cec5SDimitry Andric
__kmp_stg_parse_ld_balance_interval(char const * name,char const * value,void * data)41040b57cec5SDimitry Andric static void __kmp_stg_parse_ld_balance_interval(char const *name,
41050b57cec5SDimitry Andric char const *value, void *data) {
41060b57cec5SDimitry Andric double interval = __kmp_convert_to_double(value);
41070b57cec5SDimitry Andric if (interval >= 0) {
41080b57cec5SDimitry Andric __kmp_load_balance_interval = interval;
41090b57cec5SDimitry Andric } else {
41100b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
41110b57cec5SDimitry Andric }
41120b57cec5SDimitry Andric } // __kmp_stg_parse_load_balance_interval
41130b57cec5SDimitry Andric
__kmp_stg_print_ld_balance_interval(kmp_str_buf_t * buffer,char const * name,void * data)41140b57cec5SDimitry Andric static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
41150b57cec5SDimitry Andric char const *name, void *data) {
41160b57cec5SDimitry Andric #if KMP_DEBUG
41170b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
41180b57cec5SDimitry Andric __kmp_load_balance_interval);
41190b57cec5SDimitry Andric #endif /* KMP_DEBUG */
41200b57cec5SDimitry Andric } // __kmp_stg_print_load_balance_interval
41210b57cec5SDimitry Andric
41220b57cec5SDimitry Andric #endif /* USE_LOAD_BALANCE */
41230b57cec5SDimitry Andric
41240b57cec5SDimitry Andric // -----------------------------------------------------------------------------
41250b57cec5SDimitry Andric // KMP_INIT_AT_FORK
41260b57cec5SDimitry Andric
__kmp_stg_parse_init_at_fork(char const * name,char const * value,void * data)41270b57cec5SDimitry Andric static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
41280b57cec5SDimitry Andric void *data) {
41290b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
41300b57cec5SDimitry Andric if (__kmp_need_register_atfork) {
41310b57cec5SDimitry Andric __kmp_need_register_atfork_specified = TRUE;
41320b57cec5SDimitry Andric }
41330b57cec5SDimitry Andric } // __kmp_stg_parse_init_at_fork
41340b57cec5SDimitry Andric
__kmp_stg_print_init_at_fork(kmp_str_buf_t * buffer,char const * name,void * data)41350b57cec5SDimitry Andric static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
41360b57cec5SDimitry Andric char const *name, void *data) {
41370b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
41380b57cec5SDimitry Andric } // __kmp_stg_print_init_at_fork
41390b57cec5SDimitry Andric
41400b57cec5SDimitry Andric // -----------------------------------------------------------------------------
41410b57cec5SDimitry Andric // KMP_SCHEDULE
41420b57cec5SDimitry Andric
__kmp_stg_parse_schedule(char const * name,char const * value,void * data)41430b57cec5SDimitry Andric static void __kmp_stg_parse_schedule(char const *name, char const *value,
41440b57cec5SDimitry Andric void *data) {
41450b57cec5SDimitry Andric
41460b57cec5SDimitry Andric if (value != NULL) {
41470b57cec5SDimitry Andric size_t length = KMP_STRLEN(value);
41480b57cec5SDimitry Andric if (length > INT_MAX) {
41490b57cec5SDimitry Andric KMP_WARNING(LongValue, name);
41500b57cec5SDimitry Andric } else {
41510b57cec5SDimitry Andric const char *semicolon;
41520b57cec5SDimitry Andric if (value[length - 1] == '"' || value[length - 1] == '\'')
41530b57cec5SDimitry Andric KMP_WARNING(UnbalancedQuotes, name);
41540b57cec5SDimitry Andric do {
41550b57cec5SDimitry Andric char sentinel;
41560b57cec5SDimitry Andric
41570b57cec5SDimitry Andric semicolon = strchr(value, ';');
41580b57cec5SDimitry Andric if (*value && semicolon != value) {
41590b57cec5SDimitry Andric const char *comma = strchr(value, ',');
41600b57cec5SDimitry Andric
41610b57cec5SDimitry Andric if (comma) {
41620b57cec5SDimitry Andric ++comma;
41630b57cec5SDimitry Andric sentinel = ',';
41640b57cec5SDimitry Andric } else
41650b57cec5SDimitry Andric sentinel = ';';
41660b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
41670b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
41680b57cec5SDimitry Andric __kmp_static = kmp_sch_static_greedy;
41690b57cec5SDimitry Andric continue;
41700b57cec5SDimitry Andric } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
41710b57cec5SDimitry Andric ';')) {
41720b57cec5SDimitry Andric __kmp_static = kmp_sch_static_balanced;
41730b57cec5SDimitry Andric continue;
41740b57cec5SDimitry Andric }
41750b57cec5SDimitry Andric } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
41760b57cec5SDimitry Andric sentinel)) {
41770b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
41780b57cec5SDimitry Andric __kmp_guided = kmp_sch_guided_iterative_chunked;
41790b57cec5SDimitry Andric continue;
41800b57cec5SDimitry Andric } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
41810b57cec5SDimitry Andric ';')) {
41820b57cec5SDimitry Andric /* analytical not allowed for too many threads */
41830b57cec5SDimitry Andric __kmp_guided = kmp_sch_guided_analytical_chunked;
41840b57cec5SDimitry Andric continue;
41850b57cec5SDimitry Andric }
41860b57cec5SDimitry Andric }
41870b57cec5SDimitry Andric KMP_WARNING(InvalidClause, name, value);
41880b57cec5SDimitry Andric } else
41890b57cec5SDimitry Andric KMP_WARNING(EmptyClause, name);
41900b57cec5SDimitry Andric } while ((value = semicolon ? semicolon + 1 : NULL));
41910b57cec5SDimitry Andric }
41920b57cec5SDimitry Andric }
41930b57cec5SDimitry Andric
41940b57cec5SDimitry Andric } // __kmp_stg_parse__schedule
41950b57cec5SDimitry Andric
__kmp_stg_print_schedule(kmp_str_buf_t * buffer,char const * name,void * data)41960b57cec5SDimitry Andric static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
41970b57cec5SDimitry Andric void *data) {
41980b57cec5SDimitry Andric if (__kmp_env_format) {
41990b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(name);
42000b57cec5SDimitry Andric } else {
42010b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s='", name);
42020b57cec5SDimitry Andric }
42030b57cec5SDimitry Andric if (__kmp_static == kmp_sch_static_greedy) {
42040b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s", "static,greedy");
42050b57cec5SDimitry Andric } else if (__kmp_static == kmp_sch_static_balanced) {
42060b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s", "static,balanced");
42070b57cec5SDimitry Andric }
42080b57cec5SDimitry Andric if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
42090b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
42100b57cec5SDimitry Andric } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
42110b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
42120b57cec5SDimitry Andric }
42130b57cec5SDimitry Andric } // __kmp_stg_print_schedule
42140b57cec5SDimitry Andric
42150b57cec5SDimitry Andric // -----------------------------------------------------------------------------
42160b57cec5SDimitry Andric // OMP_SCHEDULE
42170b57cec5SDimitry Andric
__kmp_omp_schedule_restore()42180b57cec5SDimitry Andric static inline void __kmp_omp_schedule_restore() {
42190b57cec5SDimitry Andric #if KMP_USE_HIER_SCHED
42200b57cec5SDimitry Andric __kmp_hier_scheds.deallocate();
42210b57cec5SDimitry Andric #endif
42220b57cec5SDimitry Andric __kmp_chunk = 0;
42230b57cec5SDimitry Andric __kmp_sched = kmp_sch_default;
42240b57cec5SDimitry Andric }
42250b57cec5SDimitry Andric
42260b57cec5SDimitry Andric // if parse_hier = true:
42270b57cec5SDimitry Andric // Parse [HW,][modifier:]kind[,chunk]
42280b57cec5SDimitry Andric // else:
42290b57cec5SDimitry Andric // Parse [modifier:]kind[,chunk]
__kmp_parse_single_omp_schedule(const char * name,const char * value,bool parse_hier=false)42300b57cec5SDimitry Andric static const char *__kmp_parse_single_omp_schedule(const char *name,
42310b57cec5SDimitry Andric const char *value,
42320b57cec5SDimitry Andric bool parse_hier = false) {
42330b57cec5SDimitry Andric /* get the specified scheduling style */
42340b57cec5SDimitry Andric const char *ptr = value;
42350b57cec5SDimitry Andric const char *delim;
42360b57cec5SDimitry Andric int chunk = 0;
42370b57cec5SDimitry Andric enum sched_type sched = kmp_sch_default;
42380b57cec5SDimitry Andric if (*ptr == '\0')
42390b57cec5SDimitry Andric return NULL;
42400b57cec5SDimitry Andric delim = ptr;
42410b57cec5SDimitry Andric while (*delim != ',' && *delim != ':' && *delim != '\0')
42420b57cec5SDimitry Andric delim++;
42430b57cec5SDimitry Andric #if KMP_USE_HIER_SCHED
42440b57cec5SDimitry Andric kmp_hier_layer_e layer = kmp_hier_layer_e::LAYER_THREAD;
42450b57cec5SDimitry Andric if (parse_hier) {
42460b57cec5SDimitry Andric if (*delim == ',') {
42470b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("L1", ptr, ',')) {
42480b57cec5SDimitry Andric layer = kmp_hier_layer_e::LAYER_L1;
42490b57cec5SDimitry Andric } else if (!__kmp_strcasecmp_with_sentinel("L2", ptr, ',')) {
42500b57cec5SDimitry Andric layer = kmp_hier_layer_e::LAYER_L2;
42510b57cec5SDimitry Andric } else if (!__kmp_strcasecmp_with_sentinel("L3", ptr, ',')) {
42520b57cec5SDimitry Andric layer = kmp_hier_layer_e::LAYER_L3;
42530b57cec5SDimitry Andric } else if (!__kmp_strcasecmp_with_sentinel("NUMA", ptr, ',')) {
42540b57cec5SDimitry Andric layer = kmp_hier_layer_e::LAYER_NUMA;
42550b57cec5SDimitry Andric }
42560b57cec5SDimitry Andric }
42570b57cec5SDimitry Andric if (layer != kmp_hier_layer_e::LAYER_THREAD && *delim != ',') {
42580b57cec5SDimitry Andric // If there is no comma after the layer, then this schedule is invalid
42590b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
42600b57cec5SDimitry Andric __kmp_omp_schedule_restore();
42610b57cec5SDimitry Andric return NULL;
42620b57cec5SDimitry Andric } else if (layer != kmp_hier_layer_e::LAYER_THREAD) {
42630b57cec5SDimitry Andric ptr = ++delim;
42640b57cec5SDimitry Andric while (*delim != ',' && *delim != ':' && *delim != '\0')
42650b57cec5SDimitry Andric delim++;
42660b57cec5SDimitry Andric }
42670b57cec5SDimitry Andric }
42680b57cec5SDimitry Andric #endif // KMP_USE_HIER_SCHED
42690b57cec5SDimitry Andric // Read in schedule modifier if specified
42700b57cec5SDimitry Andric enum sched_type sched_modifier = (enum sched_type)0;
42710b57cec5SDimitry Andric if (*delim == ':') {
42720b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("monotonic", ptr, *delim)) {
42730b57cec5SDimitry Andric sched_modifier = sched_type::kmp_sch_modifier_monotonic;
42740b57cec5SDimitry Andric ptr = ++delim;
42750b57cec5SDimitry Andric while (*delim != ',' && *delim != ':' && *delim != '\0')
42760b57cec5SDimitry Andric delim++;
42770b57cec5SDimitry Andric } else if (!__kmp_strcasecmp_with_sentinel("nonmonotonic", ptr, *delim)) {
42780b57cec5SDimitry Andric sched_modifier = sched_type::kmp_sch_modifier_nonmonotonic;
42790b57cec5SDimitry Andric ptr = ++delim;
42800b57cec5SDimitry Andric while (*delim != ',' && *delim != ':' && *delim != '\0')
42810b57cec5SDimitry Andric delim++;
42820b57cec5SDimitry Andric } else if (!parse_hier) {
42830b57cec5SDimitry Andric // If there is no proper schedule modifier, then this schedule is invalid
42840b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
42850b57cec5SDimitry Andric __kmp_omp_schedule_restore();
42860b57cec5SDimitry Andric return NULL;
42870b57cec5SDimitry Andric }
42880b57cec5SDimitry Andric }
42890b57cec5SDimitry Andric // Read in schedule kind (required)
42900b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("dynamic", ptr, *delim))
42910b57cec5SDimitry Andric sched = kmp_sch_dynamic_chunked;
42920b57cec5SDimitry Andric else if (!__kmp_strcasecmp_with_sentinel("guided", ptr, *delim))
42930b57cec5SDimitry Andric sched = kmp_sch_guided_chunked;
42940b57cec5SDimitry Andric // AC: TODO: probably remove TRAPEZOIDAL (OMP 3.0 does not allow it)
42950b57cec5SDimitry Andric else if (!__kmp_strcasecmp_with_sentinel("auto", ptr, *delim))
42960b57cec5SDimitry Andric sched = kmp_sch_auto;
42970b57cec5SDimitry Andric else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", ptr, *delim))
42980b57cec5SDimitry Andric sched = kmp_sch_trapezoidal;
42990b57cec5SDimitry Andric else if (!__kmp_strcasecmp_with_sentinel("static", ptr, *delim))
43000b57cec5SDimitry Andric sched = kmp_sch_static;
43010b57cec5SDimitry Andric #if KMP_STATIC_STEAL_ENABLED
4302fe6060f1SDimitry Andric else if (!__kmp_strcasecmp_with_sentinel("static_steal", ptr, *delim)) {
4303fe6060f1SDimitry Andric // replace static_steal with dynamic to better cope with ordered loops
4304fe6060f1SDimitry Andric sched = kmp_sch_dynamic_chunked;
4305fe6060f1SDimitry Andric sched_modifier = sched_type::kmp_sch_modifier_nonmonotonic;
4306fe6060f1SDimitry Andric }
43070b57cec5SDimitry Andric #endif
43080b57cec5SDimitry Andric else {
43090b57cec5SDimitry Andric // If there is no proper schedule kind, then this schedule is invalid
43100b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
43110b57cec5SDimitry Andric __kmp_omp_schedule_restore();
43120b57cec5SDimitry Andric return NULL;
43130b57cec5SDimitry Andric }
43140b57cec5SDimitry Andric
43150b57cec5SDimitry Andric // Read in schedule chunk size if specified
43160b57cec5SDimitry Andric if (*delim == ',') {
43170b57cec5SDimitry Andric ptr = delim + 1;
43180b57cec5SDimitry Andric SKIP_WS(ptr);
43190b57cec5SDimitry Andric if (!isdigit(*ptr)) {
43200b57cec5SDimitry Andric // If there is no chunk after comma, then this schedule is invalid
43210b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
43220b57cec5SDimitry Andric __kmp_omp_schedule_restore();
43230b57cec5SDimitry Andric return NULL;
43240b57cec5SDimitry Andric }
43250b57cec5SDimitry Andric SKIP_DIGITS(ptr);
43260b57cec5SDimitry Andric // auto schedule should not specify chunk size
43270b57cec5SDimitry Andric if (sched == kmp_sch_auto) {
43280b57cec5SDimitry Andric __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, delim),
43290b57cec5SDimitry Andric __kmp_msg_null);
43300b57cec5SDimitry Andric } else {
43310b57cec5SDimitry Andric if (sched == kmp_sch_static)
43320b57cec5SDimitry Andric sched = kmp_sch_static_chunked;
43330b57cec5SDimitry Andric chunk = __kmp_str_to_int(delim + 1, *ptr);
43340b57cec5SDimitry Andric if (chunk < 1) {
43350b57cec5SDimitry Andric chunk = KMP_DEFAULT_CHUNK;
43360b57cec5SDimitry Andric __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, delim),
43370b57cec5SDimitry Andric __kmp_msg_null);
43380b57cec5SDimitry Andric KMP_INFORM(Using_int_Value, name, __kmp_chunk);
43390b57cec5SDimitry Andric // AC: next block commented out until KMP_DEFAULT_CHUNK != KMP_MIN_CHUNK
43400b57cec5SDimitry Andric // (to improve code coverage :)
43410b57cec5SDimitry Andric // The default chunk size is 1 according to standard, thus making
43420b57cec5SDimitry Andric // KMP_MIN_CHUNK not 1 we would introduce mess:
43430b57cec5SDimitry Andric // wrong chunk becomes 1, but it will be impossible to explicitly set
43440b57cec5SDimitry Andric // to 1 because it becomes KMP_MIN_CHUNK...
43450b57cec5SDimitry Andric // } else if ( chunk < KMP_MIN_CHUNK ) {
43460b57cec5SDimitry Andric // chunk = KMP_MIN_CHUNK;
43470b57cec5SDimitry Andric } else if (chunk > KMP_MAX_CHUNK) {
43480b57cec5SDimitry Andric chunk = KMP_MAX_CHUNK;
43490b57cec5SDimitry Andric __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, delim),
43500b57cec5SDimitry Andric __kmp_msg_null);
43510b57cec5SDimitry Andric KMP_INFORM(Using_int_Value, name, chunk);
43520b57cec5SDimitry Andric }
43530b57cec5SDimitry Andric }
43540b57cec5SDimitry Andric } else {
43550b57cec5SDimitry Andric ptr = delim;
43560b57cec5SDimitry Andric }
43570b57cec5SDimitry Andric
43580b57cec5SDimitry Andric SCHEDULE_SET_MODIFIERS(sched, sched_modifier);
43590b57cec5SDimitry Andric
43600b57cec5SDimitry Andric #if KMP_USE_HIER_SCHED
43610b57cec5SDimitry Andric if (layer != kmp_hier_layer_e::LAYER_THREAD) {
43620b57cec5SDimitry Andric __kmp_hier_scheds.append(sched, chunk, layer);
43630b57cec5SDimitry Andric } else
43640b57cec5SDimitry Andric #endif
43650b57cec5SDimitry Andric {
43660b57cec5SDimitry Andric __kmp_chunk = chunk;
43670b57cec5SDimitry Andric __kmp_sched = sched;
43680b57cec5SDimitry Andric }
43690b57cec5SDimitry Andric return ptr;
43700b57cec5SDimitry Andric }
43710b57cec5SDimitry Andric
__kmp_stg_parse_omp_schedule(char const * name,char const * value,void * data)43720b57cec5SDimitry Andric static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
43730b57cec5SDimitry Andric void *data) {
43740b57cec5SDimitry Andric size_t length;
43750b57cec5SDimitry Andric const char *ptr = value;
4376*0fca6ea1SDimitry Andric if (ptr) {
43770b57cec5SDimitry Andric SKIP_WS(ptr);
43780b57cec5SDimitry Andric length = KMP_STRLEN(value);
43790b57cec5SDimitry Andric if (length) {
43800b57cec5SDimitry Andric if (value[length - 1] == '"' || value[length - 1] == '\'')
43810b57cec5SDimitry Andric KMP_WARNING(UnbalancedQuotes, name);
43820b57cec5SDimitry Andric /* get the specified scheduling style */
43830b57cec5SDimitry Andric #if KMP_USE_HIER_SCHED
43840b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("EXPERIMENTAL", ptr, ' ')) {
43850b57cec5SDimitry Andric SKIP_TOKEN(ptr);
43860b57cec5SDimitry Andric SKIP_WS(ptr);
43870b57cec5SDimitry Andric while ((ptr = __kmp_parse_single_omp_schedule(name, ptr, true))) {
43880b57cec5SDimitry Andric while (*ptr == ' ' || *ptr == '\t' || *ptr == ':')
43890b57cec5SDimitry Andric ptr++;
43900b57cec5SDimitry Andric if (*ptr == '\0')
43910b57cec5SDimitry Andric break;
43920b57cec5SDimitry Andric }
43930b57cec5SDimitry Andric } else
43940b57cec5SDimitry Andric #endif
43950b57cec5SDimitry Andric __kmp_parse_single_omp_schedule(name, ptr);
43960b57cec5SDimitry Andric } else
43970b57cec5SDimitry Andric KMP_WARNING(EmptyString, name);
43980b57cec5SDimitry Andric }
43990b57cec5SDimitry Andric #if KMP_USE_HIER_SCHED
44000b57cec5SDimitry Andric __kmp_hier_scheds.sort();
44010b57cec5SDimitry Andric #endif
44020b57cec5SDimitry Andric K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
44030b57cec5SDimitry Andric K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
44040b57cec5SDimitry Andric K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
44050b57cec5SDimitry Andric K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
44060b57cec5SDimitry Andric } // __kmp_stg_parse_omp_schedule
44070b57cec5SDimitry Andric
__kmp_stg_print_omp_schedule(kmp_str_buf_t * buffer,char const * name,void * data)44080b57cec5SDimitry Andric static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
44090b57cec5SDimitry Andric char const *name, void *data) {
44100b57cec5SDimitry Andric if (__kmp_env_format) {
44110b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(name);
44120b57cec5SDimitry Andric } else {
44130b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s='", name);
44140b57cec5SDimitry Andric }
44150b57cec5SDimitry Andric enum sched_type sched = SCHEDULE_WITHOUT_MODIFIERS(__kmp_sched);
44160b57cec5SDimitry Andric if (SCHEDULE_HAS_MONOTONIC(__kmp_sched)) {
44170b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "monotonic:");
44180b57cec5SDimitry Andric } else if (SCHEDULE_HAS_NONMONOTONIC(__kmp_sched)) {
44190b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "nonmonotonic:");
44200b57cec5SDimitry Andric }
44210b57cec5SDimitry Andric if (__kmp_chunk) {
44220b57cec5SDimitry Andric switch (sched) {
44230b57cec5SDimitry Andric case kmp_sch_dynamic_chunked:
44240b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
44250b57cec5SDimitry Andric break;
44260b57cec5SDimitry Andric case kmp_sch_guided_iterative_chunked:
44270b57cec5SDimitry Andric case kmp_sch_guided_analytical_chunked:
44280b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
44290b57cec5SDimitry Andric break;
44300b57cec5SDimitry Andric case kmp_sch_trapezoidal:
44310b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
44320b57cec5SDimitry Andric break;
44330b57cec5SDimitry Andric case kmp_sch_static:
44340b57cec5SDimitry Andric case kmp_sch_static_chunked:
44350b57cec5SDimitry Andric case kmp_sch_static_balanced:
44360b57cec5SDimitry Andric case kmp_sch_static_greedy:
44370b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
44380b57cec5SDimitry Andric break;
44390b57cec5SDimitry Andric case kmp_sch_static_steal:
44400b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
44410b57cec5SDimitry Andric break;
44420b57cec5SDimitry Andric case kmp_sch_auto:
44430b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
44440b57cec5SDimitry Andric break;
44457a6dacacSDimitry Andric default:
44467a6dacacSDimitry Andric KMP_ASSERT2(false, "Unhandled sched_type enumeration");
44477a6dacacSDimitry Andric KMP_BUILTIN_UNREACHABLE;
44487a6dacacSDimitry Andric break;
44490b57cec5SDimitry Andric }
44500b57cec5SDimitry Andric } else {
44510b57cec5SDimitry Andric switch (sched) {
44520b57cec5SDimitry Andric case kmp_sch_dynamic_chunked:
44530b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
44540b57cec5SDimitry Andric break;
44550b57cec5SDimitry Andric case kmp_sch_guided_iterative_chunked:
44560b57cec5SDimitry Andric case kmp_sch_guided_analytical_chunked:
44570b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s'\n", "guided");
44580b57cec5SDimitry Andric break;
44590b57cec5SDimitry Andric case kmp_sch_trapezoidal:
44600b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
44610b57cec5SDimitry Andric break;
44620b57cec5SDimitry Andric case kmp_sch_static:
44630b57cec5SDimitry Andric case kmp_sch_static_chunked:
44640b57cec5SDimitry Andric case kmp_sch_static_balanced:
44650b57cec5SDimitry Andric case kmp_sch_static_greedy:
44660b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s'\n", "static");
44670b57cec5SDimitry Andric break;
44680b57cec5SDimitry Andric case kmp_sch_static_steal:
44690b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
44700b57cec5SDimitry Andric break;
44710b57cec5SDimitry Andric case kmp_sch_auto:
44720b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s'\n", "auto");
44730b57cec5SDimitry Andric break;
44747a6dacacSDimitry Andric default:
44757a6dacacSDimitry Andric KMP_ASSERT2(false, "Unhandled sched_type enumeration");
44767a6dacacSDimitry Andric KMP_BUILTIN_UNREACHABLE;
44777a6dacacSDimitry Andric break;
44780b57cec5SDimitry Andric }
44790b57cec5SDimitry Andric }
44800b57cec5SDimitry Andric } // __kmp_stg_print_omp_schedule
44810b57cec5SDimitry Andric
44820b57cec5SDimitry Andric #if KMP_USE_HIER_SCHED
44830b57cec5SDimitry Andric // -----------------------------------------------------------------------------
44840b57cec5SDimitry Andric // KMP_DISP_HAND_THREAD
__kmp_stg_parse_kmp_hand_thread(char const * name,char const * value,void * data)44850b57cec5SDimitry Andric static void __kmp_stg_parse_kmp_hand_thread(char const *name, char const *value,
44860b57cec5SDimitry Andric void *data) {
44870b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &(__kmp_dispatch_hand_threading));
44880b57cec5SDimitry Andric } // __kmp_stg_parse_kmp_hand_thread
44890b57cec5SDimitry Andric
__kmp_stg_print_kmp_hand_thread(kmp_str_buf_t * buffer,char const * name,void * data)44900b57cec5SDimitry Andric static void __kmp_stg_print_kmp_hand_thread(kmp_str_buf_t *buffer,
44910b57cec5SDimitry Andric char const *name, void *data) {
44920b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_dispatch_hand_threading);
44930b57cec5SDimitry Andric } // __kmp_stg_print_kmp_hand_thread
44940b57cec5SDimitry Andric #endif
44950b57cec5SDimitry Andric
44960b57cec5SDimitry Andric // -----------------------------------------------------------------------------
4497fe6060f1SDimitry Andric // KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE
__kmp_stg_parse_kmp_force_monotonic(char const * name,char const * value,void * data)4498fe6060f1SDimitry Andric static void __kmp_stg_parse_kmp_force_monotonic(char const *name,
4499fe6060f1SDimitry Andric char const *value, void *data) {
4500fe6060f1SDimitry Andric __kmp_stg_parse_bool(name, value, &(__kmp_force_monotonic));
4501fe6060f1SDimitry Andric } // __kmp_stg_parse_kmp_force_monotonic
4502fe6060f1SDimitry Andric
__kmp_stg_print_kmp_force_monotonic(kmp_str_buf_t * buffer,char const * name,void * data)4503fe6060f1SDimitry Andric static void __kmp_stg_print_kmp_force_monotonic(kmp_str_buf_t *buffer,
4504fe6060f1SDimitry Andric char const *name, void *data) {
4505fe6060f1SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_force_monotonic);
4506fe6060f1SDimitry Andric } // __kmp_stg_print_kmp_force_monotonic
4507fe6060f1SDimitry Andric
4508fe6060f1SDimitry Andric // -----------------------------------------------------------------------------
45090b57cec5SDimitry Andric // KMP_ATOMIC_MODE
45100b57cec5SDimitry Andric
__kmp_stg_parse_atomic_mode(char const * name,char const * value,void * data)45110b57cec5SDimitry Andric static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
45120b57cec5SDimitry Andric void *data) {
45130b57cec5SDimitry Andric // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
45140b57cec5SDimitry Andric // compatibility mode.
45150b57cec5SDimitry Andric int mode = 0;
45160b57cec5SDimitry Andric int max = 1;
45170b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
45180b57cec5SDimitry Andric max = 2;
45190b57cec5SDimitry Andric #endif /* KMP_GOMP_COMPAT */
45200b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, max, &mode);
45210b57cec5SDimitry Andric // TODO; parse_int is not very suitable for this case. In case of overflow it
45220b57cec5SDimitry Andric // is better to use
45230b57cec5SDimitry Andric // 0 rather that max value.
45240b57cec5SDimitry Andric if (mode > 0) {
45250b57cec5SDimitry Andric __kmp_atomic_mode = mode;
45260b57cec5SDimitry Andric }
45270b57cec5SDimitry Andric } // __kmp_stg_parse_atomic_mode
45280b57cec5SDimitry Andric
__kmp_stg_print_atomic_mode(kmp_str_buf_t * buffer,char const * name,void * data)45290b57cec5SDimitry Andric static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
45300b57cec5SDimitry Andric void *data) {
45310b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
45320b57cec5SDimitry Andric } // __kmp_stg_print_atomic_mode
45330b57cec5SDimitry Andric
45340b57cec5SDimitry Andric // -----------------------------------------------------------------------------
45350b57cec5SDimitry Andric // KMP_CONSISTENCY_CHECK
45360b57cec5SDimitry Andric
__kmp_stg_parse_consistency_check(char const * name,char const * value,void * data)45370b57cec5SDimitry Andric static void __kmp_stg_parse_consistency_check(char const *name,
45380b57cec5SDimitry Andric char const *value, void *data) {
45390b57cec5SDimitry Andric if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
45400b57cec5SDimitry Andric // Note, this will not work from kmp_set_defaults because th_cons stack was
45410b57cec5SDimitry Andric // not allocated
45420b57cec5SDimitry Andric // for existed thread(s) thus the first __kmp_push_<construct> will break
45430b57cec5SDimitry Andric // with assertion.
45440b57cec5SDimitry Andric // TODO: allocate th_cons if called from kmp_set_defaults.
45450b57cec5SDimitry Andric __kmp_env_consistency_check = TRUE;
45460b57cec5SDimitry Andric } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
45470b57cec5SDimitry Andric __kmp_env_consistency_check = FALSE;
45480b57cec5SDimitry Andric } else {
45490b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
45500b57cec5SDimitry Andric }
45510b57cec5SDimitry Andric } // __kmp_stg_parse_consistency_check
45520b57cec5SDimitry Andric
__kmp_stg_print_consistency_check(kmp_str_buf_t * buffer,char const * name,void * data)45530b57cec5SDimitry Andric static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
45540b57cec5SDimitry Andric char const *name, void *data) {
45550b57cec5SDimitry Andric #if KMP_DEBUG
45560b57cec5SDimitry Andric const char *value = NULL;
45570b57cec5SDimitry Andric
45580b57cec5SDimitry Andric if (__kmp_env_consistency_check) {
45590b57cec5SDimitry Andric value = "all";
45600b57cec5SDimitry Andric } else {
45610b57cec5SDimitry Andric value = "none";
45620b57cec5SDimitry Andric }
45630b57cec5SDimitry Andric
45640b57cec5SDimitry Andric if (value != NULL) {
45650b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, value);
45660b57cec5SDimitry Andric }
45670b57cec5SDimitry Andric #endif /* KMP_DEBUG */
45680b57cec5SDimitry Andric } // __kmp_stg_print_consistency_check
45690b57cec5SDimitry Andric
45700b57cec5SDimitry Andric #if USE_ITT_BUILD
45710b57cec5SDimitry Andric // -----------------------------------------------------------------------------
45720b57cec5SDimitry Andric // KMP_ITT_PREPARE_DELAY
45730b57cec5SDimitry Andric
45740b57cec5SDimitry Andric #if USE_ITT_NOTIFY
45750b57cec5SDimitry Andric
__kmp_stg_parse_itt_prepare_delay(char const * name,char const * value,void * data)45760b57cec5SDimitry Andric static void __kmp_stg_parse_itt_prepare_delay(char const *name,
45770b57cec5SDimitry Andric char const *value, void *data) {
45780b57cec5SDimitry Andric // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
45790b57cec5SDimitry Andric // iterations.
45800b57cec5SDimitry Andric int delay = 0;
45810b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
45820b57cec5SDimitry Andric __kmp_itt_prepare_delay = delay;
45830b57cec5SDimitry Andric } // __kmp_str_parse_itt_prepare_delay
45840b57cec5SDimitry Andric
__kmp_stg_print_itt_prepare_delay(kmp_str_buf_t * buffer,char const * name,void * data)45850b57cec5SDimitry Andric static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
45860b57cec5SDimitry Andric char const *name, void *data) {
45870b57cec5SDimitry Andric __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
45880b57cec5SDimitry Andric
45890b57cec5SDimitry Andric } // __kmp_str_print_itt_prepare_delay
45900b57cec5SDimitry Andric
45910b57cec5SDimitry Andric #endif // USE_ITT_NOTIFY
45920b57cec5SDimitry Andric #endif /* USE_ITT_BUILD */
45930b57cec5SDimitry Andric
45940b57cec5SDimitry Andric // -----------------------------------------------------------------------------
45950b57cec5SDimitry Andric // KMP_MALLOC_POOL_INCR
45960b57cec5SDimitry Andric
__kmp_stg_parse_malloc_pool_incr(char const * name,char const * value,void * data)45970b57cec5SDimitry Andric static void __kmp_stg_parse_malloc_pool_incr(char const *name,
45980b57cec5SDimitry Andric char const *value, void *data) {
45990b57cec5SDimitry Andric __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
46000b57cec5SDimitry Andric KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
46010b57cec5SDimitry Andric 1);
46020b57cec5SDimitry Andric } // __kmp_stg_parse_malloc_pool_incr
46030b57cec5SDimitry Andric
__kmp_stg_print_malloc_pool_incr(kmp_str_buf_t * buffer,char const * name,void * data)46040b57cec5SDimitry Andric static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
46050b57cec5SDimitry Andric char const *name, void *data) {
46060b57cec5SDimitry Andric __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
46070b57cec5SDimitry Andric
46080b57cec5SDimitry Andric } // _kmp_stg_print_malloc_pool_incr
46090b57cec5SDimitry Andric
46100b57cec5SDimitry Andric #ifdef KMP_DEBUG
46110b57cec5SDimitry Andric
46120b57cec5SDimitry Andric // -----------------------------------------------------------------------------
46130b57cec5SDimitry Andric // KMP_PAR_RANGE
46140b57cec5SDimitry Andric
__kmp_stg_parse_par_range_env(char const * name,char const * value,void * data)46150b57cec5SDimitry Andric static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
46160b57cec5SDimitry Andric void *data) {
46170b57cec5SDimitry Andric __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
46180b57cec5SDimitry Andric __kmp_par_range_routine, __kmp_par_range_filename,
46190b57cec5SDimitry Andric &__kmp_par_range_lb, &__kmp_par_range_ub);
46200b57cec5SDimitry Andric } // __kmp_stg_parse_par_range_env
46210b57cec5SDimitry Andric
__kmp_stg_print_par_range_env(kmp_str_buf_t * buffer,char const * name,void * data)46220b57cec5SDimitry Andric static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
46230b57cec5SDimitry Andric char const *name, void *data) {
46240b57cec5SDimitry Andric if (__kmp_par_range != 0) {
46250b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, par_range_to_print);
46260b57cec5SDimitry Andric }
46270b57cec5SDimitry Andric } // __kmp_stg_print_par_range_env
46280b57cec5SDimitry Andric
46290b57cec5SDimitry Andric #endif
46300b57cec5SDimitry Andric
46310b57cec5SDimitry Andric // -----------------------------------------------------------------------------
46320b57cec5SDimitry Andric // KMP_GTID_MODE
46330b57cec5SDimitry Andric
__kmp_stg_parse_gtid_mode(char const * name,char const * value,void * data)46340b57cec5SDimitry Andric static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
46350b57cec5SDimitry Andric void *data) {
46360b57cec5SDimitry Andric // Modes:
46370b57cec5SDimitry Andric // 0 -- do not change default
46380b57cec5SDimitry Andric // 1 -- sp search
46390b57cec5SDimitry Andric // 2 -- use "keyed" TLS var, i.e.
46400b57cec5SDimitry Andric // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
46410b57cec5SDimitry Andric // 3 -- __declspec(thread) TLS var in tdata section
46420b57cec5SDimitry Andric int mode = 0;
46430b57cec5SDimitry Andric int max = 2;
46440b57cec5SDimitry Andric #ifdef KMP_TDATA_GTID
46450b57cec5SDimitry Andric max = 3;
46460b57cec5SDimitry Andric #endif /* KMP_TDATA_GTID */
46470b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, max, &mode);
46480b57cec5SDimitry Andric // TODO; parse_int is not very suitable for this case. In case of overflow it
46490b57cec5SDimitry Andric // is better to use 0 rather that max value.
46500b57cec5SDimitry Andric if (mode == 0) {
46510b57cec5SDimitry Andric __kmp_adjust_gtid_mode = TRUE;
46520b57cec5SDimitry Andric } else {
46530b57cec5SDimitry Andric __kmp_gtid_mode = mode;
46540b57cec5SDimitry Andric __kmp_adjust_gtid_mode = FALSE;
46550b57cec5SDimitry Andric }
46560b57cec5SDimitry Andric } // __kmp_str_parse_gtid_mode
46570b57cec5SDimitry Andric
__kmp_stg_print_gtid_mode(kmp_str_buf_t * buffer,char const * name,void * data)46580b57cec5SDimitry Andric static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
46590b57cec5SDimitry Andric void *data) {
46600b57cec5SDimitry Andric if (__kmp_adjust_gtid_mode) {
46610b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, 0);
46620b57cec5SDimitry Andric } else {
46630b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
46640b57cec5SDimitry Andric }
46650b57cec5SDimitry Andric } // __kmp_stg_print_gtid_mode
46660b57cec5SDimitry Andric
46670b57cec5SDimitry Andric // -----------------------------------------------------------------------------
46680b57cec5SDimitry Andric // KMP_NUM_LOCKS_IN_BLOCK
46690b57cec5SDimitry Andric
__kmp_stg_parse_lock_block(char const * name,char const * value,void * data)46700b57cec5SDimitry Andric static void __kmp_stg_parse_lock_block(char const *name, char const *value,
46710b57cec5SDimitry Andric void *data) {
46720b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
46730b57cec5SDimitry Andric } // __kmp_str_parse_lock_block
46740b57cec5SDimitry Andric
__kmp_stg_print_lock_block(kmp_str_buf_t * buffer,char const * name,void * data)46750b57cec5SDimitry Andric static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
46760b57cec5SDimitry Andric void *data) {
46770b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
46780b57cec5SDimitry Andric } // __kmp_stg_print_lock_block
46790b57cec5SDimitry Andric
46800b57cec5SDimitry Andric // -----------------------------------------------------------------------------
46810b57cec5SDimitry Andric // KMP_LOCK_KIND
46820b57cec5SDimitry Andric
46830b57cec5SDimitry Andric #if KMP_USE_DYNAMIC_LOCK
46840b57cec5SDimitry Andric #define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
46850b57cec5SDimitry Andric #else
46860b57cec5SDimitry Andric #define KMP_STORE_LOCK_SEQ(a)
46870b57cec5SDimitry Andric #endif
46880b57cec5SDimitry Andric
__kmp_stg_parse_lock_kind(char const * name,char const * value,void * data)46890b57cec5SDimitry Andric static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
46900b57cec5SDimitry Andric void *data) {
46910b57cec5SDimitry Andric if (__kmp_init_user_locks) {
46920b57cec5SDimitry Andric KMP_WARNING(EnvLockWarn, name);
46930b57cec5SDimitry Andric return;
46940b57cec5SDimitry Andric }
46950b57cec5SDimitry Andric
46960b57cec5SDimitry Andric if (__kmp_str_match("tas", 2, value) ||
46970b57cec5SDimitry Andric __kmp_str_match("test and set", 2, value) ||
46980b57cec5SDimitry Andric __kmp_str_match("test_and_set", 2, value) ||
46990b57cec5SDimitry Andric __kmp_str_match("test-and-set", 2, value) ||
47000b57cec5SDimitry Andric __kmp_str_match("test andset", 2, value) ||
47010b57cec5SDimitry Andric __kmp_str_match("test_andset", 2, value) ||
47020b57cec5SDimitry Andric __kmp_str_match("test-andset", 2, value) ||
47030b57cec5SDimitry Andric __kmp_str_match("testand set", 2, value) ||
47040b57cec5SDimitry Andric __kmp_str_match("testand_set", 2, value) ||
47050b57cec5SDimitry Andric __kmp_str_match("testand-set", 2, value) ||
47060b57cec5SDimitry Andric __kmp_str_match("testandset", 2, value)) {
47070b57cec5SDimitry Andric __kmp_user_lock_kind = lk_tas;
47080b57cec5SDimitry Andric KMP_STORE_LOCK_SEQ(tas);
47090b57cec5SDimitry Andric }
47100b57cec5SDimitry Andric #if KMP_USE_FUTEX
47110b57cec5SDimitry Andric else if (__kmp_str_match("futex", 1, value)) {
47120b57cec5SDimitry Andric if (__kmp_futex_determine_capable()) {
47130b57cec5SDimitry Andric __kmp_user_lock_kind = lk_futex;
47140b57cec5SDimitry Andric KMP_STORE_LOCK_SEQ(futex);
47150b57cec5SDimitry Andric } else {
47160b57cec5SDimitry Andric KMP_WARNING(FutexNotSupported, name, value);
47170b57cec5SDimitry Andric }
47180b57cec5SDimitry Andric }
47190b57cec5SDimitry Andric #endif
47200b57cec5SDimitry Andric else if (__kmp_str_match("ticket", 2, value)) {
47210b57cec5SDimitry Andric __kmp_user_lock_kind = lk_ticket;
47220b57cec5SDimitry Andric KMP_STORE_LOCK_SEQ(ticket);
47230b57cec5SDimitry Andric } else if (__kmp_str_match("queuing", 1, value) ||
47240b57cec5SDimitry Andric __kmp_str_match("queue", 1, value)) {
47250b57cec5SDimitry Andric __kmp_user_lock_kind = lk_queuing;
47260b57cec5SDimitry Andric KMP_STORE_LOCK_SEQ(queuing);
47270b57cec5SDimitry Andric } else if (__kmp_str_match("drdpa ticket", 1, value) ||
47280b57cec5SDimitry Andric __kmp_str_match("drdpa_ticket", 1, value) ||
47290b57cec5SDimitry Andric __kmp_str_match("drdpa-ticket", 1, value) ||
47300b57cec5SDimitry Andric __kmp_str_match("drdpaticket", 1, value) ||
47310b57cec5SDimitry Andric __kmp_str_match("drdpa", 1, value)) {
47320b57cec5SDimitry Andric __kmp_user_lock_kind = lk_drdpa;
47330b57cec5SDimitry Andric KMP_STORE_LOCK_SEQ(drdpa);
47340b57cec5SDimitry Andric }
47350b57cec5SDimitry Andric #if KMP_USE_ADAPTIVE_LOCKS
47360b57cec5SDimitry Andric else if (__kmp_str_match("adaptive", 1, value)) {
4737349cc55cSDimitry Andric if (__kmp_cpuinfo.flags.rtm) { // ??? Is cpuinfo available here?
47380b57cec5SDimitry Andric __kmp_user_lock_kind = lk_adaptive;
47390b57cec5SDimitry Andric KMP_STORE_LOCK_SEQ(adaptive);
47400b57cec5SDimitry Andric } else {
47410b57cec5SDimitry Andric KMP_WARNING(AdaptiveNotSupported, name, value);
47420b57cec5SDimitry Andric __kmp_user_lock_kind = lk_queuing;
47430b57cec5SDimitry Andric KMP_STORE_LOCK_SEQ(queuing);
47440b57cec5SDimitry Andric }
47450b57cec5SDimitry Andric }
47460b57cec5SDimitry Andric #endif // KMP_USE_ADAPTIVE_LOCKS
47470b57cec5SDimitry Andric #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4748e8d8bef9SDimitry Andric else if (__kmp_str_match("rtm_queuing", 1, value)) {
4749349cc55cSDimitry Andric if (__kmp_cpuinfo.flags.rtm) {
4750e8d8bef9SDimitry Andric __kmp_user_lock_kind = lk_rtm_queuing;
4751e8d8bef9SDimitry Andric KMP_STORE_LOCK_SEQ(rtm_queuing);
47520b57cec5SDimitry Andric } else {
47530b57cec5SDimitry Andric KMP_WARNING(AdaptiveNotSupported, name, value);
47540b57cec5SDimitry Andric __kmp_user_lock_kind = lk_queuing;
47550b57cec5SDimitry Andric KMP_STORE_LOCK_SEQ(queuing);
47560b57cec5SDimitry Andric }
4757e8d8bef9SDimitry Andric } else if (__kmp_str_match("rtm_spin", 1, value)) {
4758349cc55cSDimitry Andric if (__kmp_cpuinfo.flags.rtm) {
4759e8d8bef9SDimitry Andric __kmp_user_lock_kind = lk_rtm_spin;
4760e8d8bef9SDimitry Andric KMP_STORE_LOCK_SEQ(rtm_spin);
4761e8d8bef9SDimitry Andric } else {
4762e8d8bef9SDimitry Andric KMP_WARNING(AdaptiveNotSupported, name, value);
4763e8d8bef9SDimitry Andric __kmp_user_lock_kind = lk_tas;
4764e8d8bef9SDimitry Andric KMP_STORE_LOCK_SEQ(queuing);
4765e8d8bef9SDimitry Andric }
47660b57cec5SDimitry Andric } else if (__kmp_str_match("hle", 1, value)) {
47670b57cec5SDimitry Andric __kmp_user_lock_kind = lk_hle;
47680b57cec5SDimitry Andric KMP_STORE_LOCK_SEQ(hle);
47690b57cec5SDimitry Andric }
47700b57cec5SDimitry Andric #endif
47710b57cec5SDimitry Andric else {
47720b57cec5SDimitry Andric KMP_WARNING(StgInvalidValue, name, value);
47730b57cec5SDimitry Andric }
47740b57cec5SDimitry Andric }
47750b57cec5SDimitry Andric
__kmp_stg_print_lock_kind(kmp_str_buf_t * buffer,char const * name,void * data)47760b57cec5SDimitry Andric static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
47770b57cec5SDimitry Andric void *data) {
47780b57cec5SDimitry Andric const char *value = NULL;
47790b57cec5SDimitry Andric
47800b57cec5SDimitry Andric switch (__kmp_user_lock_kind) {
47810b57cec5SDimitry Andric case lk_default:
47820b57cec5SDimitry Andric value = "default";
47830b57cec5SDimitry Andric break;
47840b57cec5SDimitry Andric
47850b57cec5SDimitry Andric case lk_tas:
47860b57cec5SDimitry Andric value = "tas";
47870b57cec5SDimitry Andric break;
47880b57cec5SDimitry Andric
47890b57cec5SDimitry Andric #if KMP_USE_FUTEX
47900b57cec5SDimitry Andric case lk_futex:
47910b57cec5SDimitry Andric value = "futex";
47920b57cec5SDimitry Andric break;
47930b57cec5SDimitry Andric #endif
47940b57cec5SDimitry Andric
47950b57cec5SDimitry Andric #if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4796e8d8bef9SDimitry Andric case lk_rtm_queuing:
4797e8d8bef9SDimitry Andric value = "rtm_queuing";
4798e8d8bef9SDimitry Andric break;
4799e8d8bef9SDimitry Andric
4800e8d8bef9SDimitry Andric case lk_rtm_spin:
4801e8d8bef9SDimitry Andric value = "rtm_spin";
48020b57cec5SDimitry Andric break;
48030b57cec5SDimitry Andric
48040b57cec5SDimitry Andric case lk_hle:
48050b57cec5SDimitry Andric value = "hle";
48060b57cec5SDimitry Andric break;
48070b57cec5SDimitry Andric #endif
48080b57cec5SDimitry Andric
48090b57cec5SDimitry Andric case lk_ticket:
48100b57cec5SDimitry Andric value = "ticket";
48110b57cec5SDimitry Andric break;
48120b57cec5SDimitry Andric
48130b57cec5SDimitry Andric case lk_queuing:
48140b57cec5SDimitry Andric value = "queuing";
48150b57cec5SDimitry Andric break;
48160b57cec5SDimitry Andric
48170b57cec5SDimitry Andric case lk_drdpa:
48180b57cec5SDimitry Andric value = "drdpa";
48190b57cec5SDimitry Andric break;
48200b57cec5SDimitry Andric #if KMP_USE_ADAPTIVE_LOCKS
48210b57cec5SDimitry Andric case lk_adaptive:
48220b57cec5SDimitry Andric value = "adaptive";
48230b57cec5SDimitry Andric break;
48240b57cec5SDimitry Andric #endif
48250b57cec5SDimitry Andric }
48260b57cec5SDimitry Andric
48270b57cec5SDimitry Andric if (value != NULL) {
48280b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, value);
48290b57cec5SDimitry Andric }
48300b57cec5SDimitry Andric }
48310b57cec5SDimitry Andric
48320b57cec5SDimitry Andric // -----------------------------------------------------------------------------
48330b57cec5SDimitry Andric // KMP_SPIN_BACKOFF_PARAMS
48340b57cec5SDimitry Andric
48350b57cec5SDimitry Andric // KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
48360b57cec5SDimitry Andric // for machine pause)
__kmp_stg_parse_spin_backoff_params(const char * name,const char * value,void * data)48370b57cec5SDimitry Andric static void __kmp_stg_parse_spin_backoff_params(const char *name,
48380b57cec5SDimitry Andric const char *value, void *data) {
48390b57cec5SDimitry Andric const char *next = value;
48400b57cec5SDimitry Andric
48410b57cec5SDimitry Andric int total = 0; // Count elements that were set. It'll be used as an array size
48420b57cec5SDimitry Andric int prev_comma = FALSE; // For correct processing sequential commas
48430b57cec5SDimitry Andric int i;
48440b57cec5SDimitry Andric
48450b57cec5SDimitry Andric kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
48460b57cec5SDimitry Andric kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
48470b57cec5SDimitry Andric
48480b57cec5SDimitry Andric // Run only 3 iterations because it is enough to read two values or find a
48490b57cec5SDimitry Andric // syntax error
48500b57cec5SDimitry Andric for (i = 0; i < 3; i++) {
48510b57cec5SDimitry Andric SKIP_WS(next);
48520b57cec5SDimitry Andric
48530b57cec5SDimitry Andric if (*next == '\0') {
48540b57cec5SDimitry Andric break;
48550b57cec5SDimitry Andric }
48560b57cec5SDimitry Andric // Next character is not an integer or not a comma OR number of values > 2
48570b57cec5SDimitry Andric // => end of list
48580b57cec5SDimitry Andric if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
48590b57cec5SDimitry Andric KMP_WARNING(EnvSyntaxError, name, value);
48600b57cec5SDimitry Andric return;
48610b57cec5SDimitry Andric }
48620b57cec5SDimitry Andric // The next character is ','
48630b57cec5SDimitry Andric if (*next == ',') {
4864480093f4SDimitry Andric // ',' is the first character
48650b57cec5SDimitry Andric if (total == 0 || prev_comma) {
48660b57cec5SDimitry Andric total++;
48670b57cec5SDimitry Andric }
48680b57cec5SDimitry Andric prev_comma = TRUE;
48690b57cec5SDimitry Andric next++; // skip ','
48700b57cec5SDimitry Andric SKIP_WS(next);
48710b57cec5SDimitry Andric }
48720b57cec5SDimitry Andric // Next character is a digit
48730b57cec5SDimitry Andric if (*next >= '0' && *next <= '9') {
48740b57cec5SDimitry Andric int num;
48750b57cec5SDimitry Andric const char *buf = next;
48760b57cec5SDimitry Andric char const *msg = NULL;
48770b57cec5SDimitry Andric prev_comma = FALSE;
48780b57cec5SDimitry Andric SKIP_DIGITS(next);
48790b57cec5SDimitry Andric total++;
48800b57cec5SDimitry Andric
48810b57cec5SDimitry Andric const char *tmp = next;
48820b57cec5SDimitry Andric SKIP_WS(tmp);
48830b57cec5SDimitry Andric if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
48840b57cec5SDimitry Andric KMP_WARNING(EnvSpacesNotAllowed, name, value);
48850b57cec5SDimitry Andric return;
48860b57cec5SDimitry Andric }
48870b57cec5SDimitry Andric
48880b57cec5SDimitry Andric num = __kmp_str_to_int(buf, *next);
48890b57cec5SDimitry Andric if (num <= 0) { // The number of retries should be > 0
48900b57cec5SDimitry Andric msg = KMP_I18N_STR(ValueTooSmall);
48910b57cec5SDimitry Andric num = 1;
48920b57cec5SDimitry Andric }
48930b57cec5SDimitry Andric if (msg != NULL) {
48940b57cec5SDimitry Andric // Message is not empty. Print warning.
48950b57cec5SDimitry Andric KMP_WARNING(ParseSizeIntWarn, name, value, msg);
48960b57cec5SDimitry Andric KMP_INFORM(Using_int_Value, name, num);
48970b57cec5SDimitry Andric }
48980b57cec5SDimitry Andric if (total == 1) {
48990b57cec5SDimitry Andric max_backoff = num;
49000b57cec5SDimitry Andric } else if (total == 2) {
49010b57cec5SDimitry Andric min_tick = num;
49020b57cec5SDimitry Andric }
49030b57cec5SDimitry Andric }
49040b57cec5SDimitry Andric }
49050b57cec5SDimitry Andric KMP_DEBUG_ASSERT(total > 0);
49060b57cec5SDimitry Andric if (total <= 0) {
49070b57cec5SDimitry Andric KMP_WARNING(EnvSyntaxError, name, value);
49080b57cec5SDimitry Andric return;
49090b57cec5SDimitry Andric }
49100b57cec5SDimitry Andric __kmp_spin_backoff_params.max_backoff = max_backoff;
49110b57cec5SDimitry Andric __kmp_spin_backoff_params.min_tick = min_tick;
49120b57cec5SDimitry Andric }
49130b57cec5SDimitry Andric
__kmp_stg_print_spin_backoff_params(kmp_str_buf_t * buffer,char const * name,void * data)49140b57cec5SDimitry Andric static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
49150b57cec5SDimitry Andric char const *name, void *data) {
49160b57cec5SDimitry Andric if (__kmp_env_format) {
49170b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(name);
49180b57cec5SDimitry Andric } else {
49190b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s='", name);
49200b57cec5SDimitry Andric }
49210b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
49220b57cec5SDimitry Andric __kmp_spin_backoff_params.min_tick);
49230b57cec5SDimitry Andric }
49240b57cec5SDimitry Andric
49250b57cec5SDimitry Andric #if KMP_USE_ADAPTIVE_LOCKS
49260b57cec5SDimitry Andric
49270b57cec5SDimitry Andric // -----------------------------------------------------------------------------
49280b57cec5SDimitry Andric // KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
49290b57cec5SDimitry Andric
49300b57cec5SDimitry Andric // Parse out values for the tunable parameters from a string of the form
49310b57cec5SDimitry Andric // KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
__kmp_stg_parse_adaptive_lock_props(const char * name,const char * value,void * data)49320b57cec5SDimitry Andric static void __kmp_stg_parse_adaptive_lock_props(const char *name,
49330b57cec5SDimitry Andric const char *value, void *data) {
49340b57cec5SDimitry Andric int max_retries = 0;
49350b57cec5SDimitry Andric int max_badness = 0;
49360b57cec5SDimitry Andric
49370b57cec5SDimitry Andric const char *next = value;
49380b57cec5SDimitry Andric
49390b57cec5SDimitry Andric int total = 0; // Count elements that were set. It'll be used as an array size
49400b57cec5SDimitry Andric int prev_comma = FALSE; // For correct processing sequential commas
49410b57cec5SDimitry Andric int i;
49420b57cec5SDimitry Andric
49430b57cec5SDimitry Andric // Save values in the structure __kmp_speculative_backoff_params
49440b57cec5SDimitry Andric // Run only 3 iterations because it is enough to read two values or find a
49450b57cec5SDimitry Andric // syntax error
49460b57cec5SDimitry Andric for (i = 0; i < 3; i++) {
49470b57cec5SDimitry Andric SKIP_WS(next);
49480b57cec5SDimitry Andric
49490b57cec5SDimitry Andric if (*next == '\0') {
49500b57cec5SDimitry Andric break;
49510b57cec5SDimitry Andric }
49520b57cec5SDimitry Andric // Next character is not an integer or not a comma OR number of values > 2
49530b57cec5SDimitry Andric // => end of list
49540b57cec5SDimitry Andric if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
49550b57cec5SDimitry Andric KMP_WARNING(EnvSyntaxError, name, value);
49560b57cec5SDimitry Andric return;
49570b57cec5SDimitry Andric }
49580b57cec5SDimitry Andric // The next character is ','
49590b57cec5SDimitry Andric if (*next == ',') {
4960480093f4SDimitry Andric // ',' is the first character
49610b57cec5SDimitry Andric if (total == 0 || prev_comma) {
49620b57cec5SDimitry Andric total++;
49630b57cec5SDimitry Andric }
49640b57cec5SDimitry Andric prev_comma = TRUE;
49650b57cec5SDimitry Andric next++; // skip ','
49660b57cec5SDimitry Andric SKIP_WS(next);
49670b57cec5SDimitry Andric }
49680b57cec5SDimitry Andric // Next character is a digit
49690b57cec5SDimitry Andric if (*next >= '0' && *next <= '9') {
49700b57cec5SDimitry Andric int num;
49710b57cec5SDimitry Andric const char *buf = next;
49720b57cec5SDimitry Andric char const *msg = NULL;
49730b57cec5SDimitry Andric prev_comma = FALSE;
49740b57cec5SDimitry Andric SKIP_DIGITS(next);
49750b57cec5SDimitry Andric total++;
49760b57cec5SDimitry Andric
49770b57cec5SDimitry Andric const char *tmp = next;
49780b57cec5SDimitry Andric SKIP_WS(tmp);
49790b57cec5SDimitry Andric if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
49800b57cec5SDimitry Andric KMP_WARNING(EnvSpacesNotAllowed, name, value);
49810b57cec5SDimitry Andric return;
49820b57cec5SDimitry Andric }
49830b57cec5SDimitry Andric
49840b57cec5SDimitry Andric num = __kmp_str_to_int(buf, *next);
49850b57cec5SDimitry Andric if (num < 0) { // The number of retries should be >= 0
49860b57cec5SDimitry Andric msg = KMP_I18N_STR(ValueTooSmall);
49870b57cec5SDimitry Andric num = 1;
49880b57cec5SDimitry Andric }
49890b57cec5SDimitry Andric if (msg != NULL) {
49900b57cec5SDimitry Andric // Message is not empty. Print warning.
49910b57cec5SDimitry Andric KMP_WARNING(ParseSizeIntWarn, name, value, msg);
49920b57cec5SDimitry Andric KMP_INFORM(Using_int_Value, name, num);
49930b57cec5SDimitry Andric }
49940b57cec5SDimitry Andric if (total == 1) {
49950b57cec5SDimitry Andric max_retries = num;
49960b57cec5SDimitry Andric } else if (total == 2) {
49970b57cec5SDimitry Andric max_badness = num;
49980b57cec5SDimitry Andric }
49990b57cec5SDimitry Andric }
50000b57cec5SDimitry Andric }
50010b57cec5SDimitry Andric KMP_DEBUG_ASSERT(total > 0);
50020b57cec5SDimitry Andric if (total <= 0) {
50030b57cec5SDimitry Andric KMP_WARNING(EnvSyntaxError, name, value);
50040b57cec5SDimitry Andric return;
50050b57cec5SDimitry Andric }
50060b57cec5SDimitry Andric __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
50070b57cec5SDimitry Andric __kmp_adaptive_backoff_params.max_badness = max_badness;
50080b57cec5SDimitry Andric }
50090b57cec5SDimitry Andric
__kmp_stg_print_adaptive_lock_props(kmp_str_buf_t * buffer,char const * name,void * data)50100b57cec5SDimitry Andric static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
50110b57cec5SDimitry Andric char const *name, void *data) {
50120b57cec5SDimitry Andric if (__kmp_env_format) {
50130b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(name);
50140b57cec5SDimitry Andric } else {
50150b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s='", name);
50160b57cec5SDimitry Andric }
50170b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%d,%d'\n",
50180b57cec5SDimitry Andric __kmp_adaptive_backoff_params.max_soft_retries,
50190b57cec5SDimitry Andric __kmp_adaptive_backoff_params.max_badness);
50200b57cec5SDimitry Andric } // __kmp_stg_print_adaptive_lock_props
50210b57cec5SDimitry Andric
50220b57cec5SDimitry Andric #if KMP_DEBUG_ADAPTIVE_LOCKS
50230b57cec5SDimitry Andric
__kmp_stg_parse_speculative_statsfile(char const * name,char const * value,void * data)50240b57cec5SDimitry Andric static void __kmp_stg_parse_speculative_statsfile(char const *name,
50250b57cec5SDimitry Andric char const *value,
50260b57cec5SDimitry Andric void *data) {
5027fe6060f1SDimitry Andric __kmp_stg_parse_file(name, value, "",
5028fe6060f1SDimitry Andric CCAST(char **, &__kmp_speculative_statsfile));
50290b57cec5SDimitry Andric } // __kmp_stg_parse_speculative_statsfile
50300b57cec5SDimitry Andric
__kmp_stg_print_speculative_statsfile(kmp_str_buf_t * buffer,char const * name,void * data)50310b57cec5SDimitry Andric static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
50320b57cec5SDimitry Andric char const *name,
50330b57cec5SDimitry Andric void *data) {
50340b57cec5SDimitry Andric if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
50350b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "stdout");
50360b57cec5SDimitry Andric } else {
50370b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
50380b57cec5SDimitry Andric }
50390b57cec5SDimitry Andric
50400b57cec5SDimitry Andric } // __kmp_stg_print_speculative_statsfile
50410b57cec5SDimitry Andric
50420b57cec5SDimitry Andric #endif // KMP_DEBUG_ADAPTIVE_LOCKS
50430b57cec5SDimitry Andric
50440b57cec5SDimitry Andric #endif // KMP_USE_ADAPTIVE_LOCKS
50450b57cec5SDimitry Andric
50460b57cec5SDimitry Andric // -----------------------------------------------------------------------------
50470b57cec5SDimitry Andric // KMP_HW_SUBSET (was KMP_PLACE_THREADS)
5048fe6060f1SDimitry Andric // 2s16c,2t => 2S16C,2T => 2S16C \0 2T
50490b57cec5SDimitry Andric
5050fe6060f1SDimitry Andric // Return KMP_HW_SUBSET preferred hardware type in case a token is ambiguously
5051fe6060f1SDimitry Andric // short. The original KMP_HW_SUBSET environment variable had single letters:
5052fe6060f1SDimitry Andric // s, c, t for sockets, cores, threads repsectively.
__kmp_hw_subset_break_tie(const kmp_hw_t * possible,size_t num_possible)5053fe6060f1SDimitry Andric static kmp_hw_t __kmp_hw_subset_break_tie(const kmp_hw_t *possible,
5054fe6060f1SDimitry Andric size_t num_possible) {
5055fe6060f1SDimitry Andric for (size_t i = 0; i < num_possible; ++i) {
5056fe6060f1SDimitry Andric if (possible[i] == KMP_HW_THREAD)
5057fe6060f1SDimitry Andric return KMP_HW_THREAD;
5058fe6060f1SDimitry Andric else if (possible[i] == KMP_HW_CORE)
5059fe6060f1SDimitry Andric return KMP_HW_CORE;
5060fe6060f1SDimitry Andric else if (possible[i] == KMP_HW_SOCKET)
5061fe6060f1SDimitry Andric return KMP_HW_SOCKET;
5062fe6060f1SDimitry Andric }
5063fe6060f1SDimitry Andric return KMP_HW_UNKNOWN;
5064fe6060f1SDimitry Andric }
5065fe6060f1SDimitry Andric
5066fe6060f1SDimitry Andric // Return hardware type from string or HW_UNKNOWN if string cannot be parsed
5067fe6060f1SDimitry Andric // This algorithm is very forgiving to the user in that, the instant it can
5068fe6060f1SDimitry Andric // reduce the search space to one, it assumes that is the topology level the
5069fe6060f1SDimitry Andric // user wanted, even if it is misspelled later in the token.
__kmp_stg_parse_hw_subset_name(char const * token)5070fe6060f1SDimitry Andric static kmp_hw_t __kmp_stg_parse_hw_subset_name(char const *token) {
5071fe6060f1SDimitry Andric size_t index, num_possible, token_length;
5072fe6060f1SDimitry Andric kmp_hw_t possible[KMP_HW_LAST];
5073fe6060f1SDimitry Andric const char *end;
5074fe6060f1SDimitry Andric
5075fe6060f1SDimitry Andric // Find the end of the hardware token string
5076fe6060f1SDimitry Andric end = token;
5077fe6060f1SDimitry Andric token_length = 0;
5078fe6060f1SDimitry Andric while (isalnum(*end) || *end == '_') {
5079fe6060f1SDimitry Andric token_length++;
5080fe6060f1SDimitry Andric end++;
5081fe6060f1SDimitry Andric }
5082fe6060f1SDimitry Andric
5083fe6060f1SDimitry Andric // Set the possibilities to all hardware types
5084fe6060f1SDimitry Andric num_possible = 0;
5085fe6060f1SDimitry Andric KMP_FOREACH_HW_TYPE(type) { possible[num_possible++] = type; }
5086fe6060f1SDimitry Andric
5087fe6060f1SDimitry Andric // Eliminate hardware types by comparing the front of the token
5088fe6060f1SDimitry Andric // with hardware names
5089fe6060f1SDimitry Andric // In most cases, the first letter in the token will indicate exactly
5090fe6060f1SDimitry Andric // which hardware type is parsed, e.g., 'C' = Core
5091fe6060f1SDimitry Andric index = 0;
5092fe6060f1SDimitry Andric while (num_possible > 1 && index < token_length) {
5093fe6060f1SDimitry Andric size_t n = num_possible;
5094fe6060f1SDimitry Andric char token_char = (char)toupper(token[index]);
5095fe6060f1SDimitry Andric for (size_t i = 0; i < n; ++i) {
5096fe6060f1SDimitry Andric const char *s;
5097fe6060f1SDimitry Andric kmp_hw_t type = possible[i];
5098fe6060f1SDimitry Andric s = __kmp_hw_get_keyword(type, false);
5099fe6060f1SDimitry Andric if (index < KMP_STRLEN(s)) {
5100fe6060f1SDimitry Andric char c = (char)toupper(s[index]);
5101fe6060f1SDimitry Andric // Mark hardware types for removal when the characters do not match
5102fe6060f1SDimitry Andric if (c != token_char) {
5103fe6060f1SDimitry Andric possible[i] = KMP_HW_UNKNOWN;
5104fe6060f1SDimitry Andric num_possible--;
5105fe6060f1SDimitry Andric }
5106fe6060f1SDimitry Andric }
5107fe6060f1SDimitry Andric }
5108fe6060f1SDimitry Andric // Remove hardware types that this token cannot be
5109fe6060f1SDimitry Andric size_t start = 0;
5110fe6060f1SDimitry Andric for (size_t i = 0; i < n; ++i) {
5111fe6060f1SDimitry Andric if (possible[i] != KMP_HW_UNKNOWN) {
5112fe6060f1SDimitry Andric kmp_hw_t temp = possible[i];
5113fe6060f1SDimitry Andric possible[i] = possible[start];
5114fe6060f1SDimitry Andric possible[start] = temp;
5115fe6060f1SDimitry Andric start++;
5116fe6060f1SDimitry Andric }
5117fe6060f1SDimitry Andric }
5118fe6060f1SDimitry Andric KMP_ASSERT(start == num_possible);
5119fe6060f1SDimitry Andric index++;
5120fe6060f1SDimitry Andric }
5121fe6060f1SDimitry Andric
5122fe6060f1SDimitry Andric // Attempt to break a tie if user has very short token
5123fe6060f1SDimitry Andric // (e.g., is 'T' tile or thread?)
5124fe6060f1SDimitry Andric if (num_possible > 1)
5125fe6060f1SDimitry Andric return __kmp_hw_subset_break_tie(possible, num_possible);
5126fe6060f1SDimitry Andric if (num_possible == 1)
5127fe6060f1SDimitry Andric return possible[0];
5128fe6060f1SDimitry Andric return KMP_HW_UNKNOWN;
5129fe6060f1SDimitry Andric }
5130fe6060f1SDimitry Andric
5131fe6060f1SDimitry Andric // The longest observable sequence of items can only be HW_LAST length
51320b57cec5SDimitry Andric // The input string is usually short enough, let's use 512 limit for now
5133fe6060f1SDimitry Andric #define MAX_T_LEVEL KMP_HW_LAST
51340b57cec5SDimitry Andric #define MAX_STR_LEN 512
__kmp_stg_parse_hw_subset(char const * name,char const * value,void * data)51350b57cec5SDimitry Andric static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
51360b57cec5SDimitry Andric void *data) {
51370b57cec5SDimitry Andric // Value example: 1s,5c@3,2T
51380b57cec5SDimitry Andric // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
51390b57cec5SDimitry Andric kmp_setting_t **rivals = (kmp_setting_t **)data;
51400b57cec5SDimitry Andric if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
51410b57cec5SDimitry Andric KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
51420b57cec5SDimitry Andric }
51430b57cec5SDimitry Andric if (__kmp_stg_check_rivals(name, value, rivals)) {
51440b57cec5SDimitry Andric return;
51450b57cec5SDimitry Andric }
51460b57cec5SDimitry Andric
51470b57cec5SDimitry Andric char *components[MAX_T_LEVEL];
51480b57cec5SDimitry Andric char const *digits = "0123456789";
51490b57cec5SDimitry Andric char input[MAX_STR_LEN];
51500b57cec5SDimitry Andric size_t len = 0, mlen = MAX_STR_LEN;
51510b57cec5SDimitry Andric int level = 0;
5152fe6060f1SDimitry Andric bool absolute = false;
5153fe6060f1SDimitry Andric // Canonicalize the string (remove spaces, unify delimiters, etc.)
51540b57cec5SDimitry Andric char *pos = CCAST(char *, value);
51550b57cec5SDimitry Andric while (*pos && mlen) {
51560b57cec5SDimitry Andric if (*pos != ' ') { // skip spaces
51570b57cec5SDimitry Andric if (len == 0 && *pos == ':') {
5158fe6060f1SDimitry Andric absolute = true;
51590b57cec5SDimitry Andric } else {
5160e8d8bef9SDimitry Andric input[len] = (char)(toupper(*pos));
51610b57cec5SDimitry Andric if (input[len] == 'X')
51620b57cec5SDimitry Andric input[len] = ','; // unify delimiters of levels
51630b57cec5SDimitry Andric if (input[len] == 'O' && strchr(digits, *(pos + 1)))
51640b57cec5SDimitry Andric input[len] = '@'; // unify delimiters of offset
51650b57cec5SDimitry Andric len++;
51660b57cec5SDimitry Andric }
51670b57cec5SDimitry Andric }
51680b57cec5SDimitry Andric mlen--;
51690b57cec5SDimitry Andric pos++;
51700b57cec5SDimitry Andric }
5171fe6060f1SDimitry Andric if (len == 0 || mlen == 0) {
51720b57cec5SDimitry Andric goto err; // contents is either empty or too long
5173fe6060f1SDimitry Andric }
51740b57cec5SDimitry Andric input[len] = '\0';
51750b57cec5SDimitry Andric // Split by delimiter
51760b57cec5SDimitry Andric pos = input;
51770b57cec5SDimitry Andric components[level++] = pos;
51780b57cec5SDimitry Andric while ((pos = strchr(pos, ','))) {
51790b57cec5SDimitry Andric if (level >= MAX_T_LEVEL)
51800b57cec5SDimitry Andric goto err; // too many components provided
51810b57cec5SDimitry Andric *pos = '\0'; // modify input and avoid more copying
51820b57cec5SDimitry Andric components[level++] = ++pos; // expect something after ","
51830b57cec5SDimitry Andric }
5184fe6060f1SDimitry Andric
5185fe6060f1SDimitry Andric __kmp_hw_subset = kmp_hw_subset_t::allocate();
5186fe6060f1SDimitry Andric if (absolute)
5187fe6060f1SDimitry Andric __kmp_hw_subset->set_absolute();
5188fe6060f1SDimitry Andric
51890b57cec5SDimitry Andric // Check each component
51900b57cec5SDimitry Andric for (int i = 0; i < level; ++i) {
51910eae32dcSDimitry Andric int core_level = 0;
51920eae32dcSDimitry Andric char *core_components[MAX_T_LEVEL];
51930eae32dcSDimitry Andric // Split possible core components by '&' delimiter
51940eae32dcSDimitry Andric pos = components[i];
51950eae32dcSDimitry Andric core_components[core_level++] = pos;
51960eae32dcSDimitry Andric while ((pos = strchr(pos, '&'))) {
51970eae32dcSDimitry Andric if (core_level >= MAX_T_LEVEL)
51980eae32dcSDimitry Andric goto err; // too many different core types
51990eae32dcSDimitry Andric *pos = '\0'; // modify input and avoid more copying
52000eae32dcSDimitry Andric core_components[core_level++] = ++pos; // expect something after '&'
52010eae32dcSDimitry Andric }
52020eae32dcSDimitry Andric
52030eae32dcSDimitry Andric for (int j = 0; j < core_level; ++j) {
52040eae32dcSDimitry Andric char *offset_ptr;
52050eae32dcSDimitry Andric char *attr_ptr;
52060b57cec5SDimitry Andric int offset = 0;
52070eae32dcSDimitry Andric kmp_hw_attr_t attr;
52080eae32dcSDimitry Andric int num;
52090eae32dcSDimitry Andric // components may begin with an optional count of the number of resources
52100eae32dcSDimitry Andric if (isdigit(*core_components[j])) {
52110eae32dcSDimitry Andric num = atoi(core_components[j]);
5212fe6060f1SDimitry Andric if (num <= 0) {
5213fe6060f1SDimitry Andric goto err; // only positive integers are valid for count
5214fe6060f1SDimitry Andric }
52150eae32dcSDimitry Andric pos = core_components[j] + strspn(core_components[j], digits);
52160eae32dcSDimitry Andric } else if (*core_components[j] == '*') {
52170eae32dcSDimitry Andric num = kmp_hw_subset_t::USE_ALL;
52180eae32dcSDimitry Andric pos = core_components[j] + 1;
52190eae32dcSDimitry Andric } else {
52200eae32dcSDimitry Andric num = kmp_hw_subset_t::USE_ALL;
52210eae32dcSDimitry Andric pos = core_components[j];
52220b57cec5SDimitry Andric }
52230eae32dcSDimitry Andric
52240eae32dcSDimitry Andric offset_ptr = strchr(core_components[j], '@');
52250eae32dcSDimitry Andric attr_ptr = strchr(core_components[j], ':');
52260eae32dcSDimitry Andric
52270eae32dcSDimitry Andric if (offset_ptr) {
52280eae32dcSDimitry Andric offset = atoi(offset_ptr + 1); // save offset
52290eae32dcSDimitry Andric *offset_ptr = '\0'; // cut the offset from the component
52300eae32dcSDimitry Andric }
52310eae32dcSDimitry Andric if (attr_ptr) {
52320eae32dcSDimitry Andric attr.clear();
52330eae32dcSDimitry Andric // save the attribute
52340eae32dcSDimitry Andric #if KMP_ARCH_X86 || KMP_ARCH_X86_64
52350eae32dcSDimitry Andric if (__kmp_str_match("intel_core", -1, attr_ptr + 1)) {
52360eae32dcSDimitry Andric attr.set_core_type(KMP_HW_CORE_TYPE_CORE);
52370eae32dcSDimitry Andric } else if (__kmp_str_match("intel_atom", -1, attr_ptr + 1)) {
52380eae32dcSDimitry Andric attr.set_core_type(KMP_HW_CORE_TYPE_ATOM);
523981ad6265SDimitry Andric } else
52400eae32dcSDimitry Andric #endif
52410eae32dcSDimitry Andric if (__kmp_str_match("eff", 3, attr_ptr + 1)) {
52420eae32dcSDimitry Andric const char *number = attr_ptr + 1;
52430eae32dcSDimitry Andric // skip the eff[iciency] token
52440eae32dcSDimitry Andric while (isalpha(*number))
52450eae32dcSDimitry Andric number++;
52460eae32dcSDimitry Andric if (!isdigit(*number)) {
52470b57cec5SDimitry Andric goto err;
5248fe6060f1SDimitry Andric }
52490eae32dcSDimitry Andric int efficiency = atoi(number);
52500eae32dcSDimitry Andric attr.set_core_eff(efficiency);
52510eae32dcSDimitry Andric } else {
52520eae32dcSDimitry Andric goto err;
52530eae32dcSDimitry Andric }
52540eae32dcSDimitry Andric *attr_ptr = '\0'; // cut the attribute from the component
52550eae32dcSDimitry Andric }
52560b57cec5SDimitry Andric // detect the component type
5257fe6060f1SDimitry Andric kmp_hw_t type = __kmp_stg_parse_hw_subset_name(pos);
5258fe6060f1SDimitry Andric if (type == KMP_HW_UNKNOWN) {
52590b57cec5SDimitry Andric goto err;
52600b57cec5SDimitry Andric }
52610eae32dcSDimitry Andric // Only the core type can have attributes
52620eae32dcSDimitry Andric if (attr && type != KMP_HW_CORE)
52630eae32dcSDimitry Andric goto err;
52640eae32dcSDimitry Andric // Must allow core be specified more than once
52650eae32dcSDimitry Andric if (type != KMP_HW_CORE && __kmp_hw_subset->specified(type)) {
52660b57cec5SDimitry Andric goto err;
52670b57cec5SDimitry Andric }
52680eae32dcSDimitry Andric __kmp_hw_subset->push_back(num, type, offset, attr);
52690eae32dcSDimitry Andric }
52700b57cec5SDimitry Andric }
52710b57cec5SDimitry Andric return;
52720b57cec5SDimitry Andric err:
52730b57cec5SDimitry Andric KMP_WARNING(AffHWSubsetInvalid, name, value);
5274fe6060f1SDimitry Andric if (__kmp_hw_subset) {
5275fe6060f1SDimitry Andric kmp_hw_subset_t::deallocate(__kmp_hw_subset);
5276fe6060f1SDimitry Andric __kmp_hw_subset = nullptr;
5277fe6060f1SDimitry Andric }
52780b57cec5SDimitry Andric return;
52790b57cec5SDimitry Andric }
52800b57cec5SDimitry Andric
__kmp_stg_print_hw_subset(kmp_str_buf_t * buffer,char const * name,void * data)52810b57cec5SDimitry Andric static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
52820b57cec5SDimitry Andric void *data) {
52830b57cec5SDimitry Andric kmp_str_buf_t buf;
5284fe6060f1SDimitry Andric int depth;
5285fe6060f1SDimitry Andric if (!__kmp_hw_subset)
5286fe6060f1SDimitry Andric return;
52870b57cec5SDimitry Andric __kmp_str_buf_init(&buf);
52880b57cec5SDimitry Andric if (__kmp_env_format)
52890b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME_EX(name);
52900b57cec5SDimitry Andric else
52910b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s='", name);
5292fe6060f1SDimitry Andric
5293fe6060f1SDimitry Andric depth = __kmp_hw_subset->get_depth();
5294fe6060f1SDimitry Andric for (int i = 0; i < depth; ++i) {
5295fe6060f1SDimitry Andric const auto &item = __kmp_hw_subset->at(i);
52960eae32dcSDimitry Andric if (i > 0)
52970eae32dcSDimitry Andric __kmp_str_buf_print(&buf, "%c", ',');
52980eae32dcSDimitry Andric for (int j = 0; j < item.num_attrs; ++j) {
52990eae32dcSDimitry Andric __kmp_str_buf_print(&buf, "%s%d%s", (j > 0 ? "&" : ""), item.num[j],
5300fe6060f1SDimitry Andric __kmp_hw_get_keyword(item.type));
53010eae32dcSDimitry Andric if (item.attr[j].is_core_type_valid())
53020eae32dcSDimitry Andric __kmp_str_buf_print(
53030eae32dcSDimitry Andric &buf, ":%s",
53040eae32dcSDimitry Andric __kmp_hw_get_core_type_keyword(item.attr[j].get_core_type()));
53050eae32dcSDimitry Andric if (item.attr[j].is_core_eff_valid())
53060eae32dcSDimitry Andric __kmp_str_buf_print(&buf, ":eff%d", item.attr[j].get_core_eff());
53070eae32dcSDimitry Andric if (item.offset[j])
53080eae32dcSDimitry Andric __kmp_str_buf_print(&buf, "@%d", item.offset[j]);
53090eae32dcSDimitry Andric }
53100b57cec5SDimitry Andric }
53110b57cec5SDimitry Andric __kmp_str_buf_print(buffer, "%s'\n", buf.str);
53120b57cec5SDimitry Andric __kmp_str_buf_free(&buf);
53130b57cec5SDimitry Andric }
53140b57cec5SDimitry Andric
53150b57cec5SDimitry Andric #if USE_ITT_BUILD
53160b57cec5SDimitry Andric // -----------------------------------------------------------------------------
53170b57cec5SDimitry Andric // KMP_FORKJOIN_FRAMES
53180b57cec5SDimitry Andric
__kmp_stg_parse_forkjoin_frames(char const * name,char const * value,void * data)53190b57cec5SDimitry Andric static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
53200b57cec5SDimitry Andric void *data) {
53210b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
53220b57cec5SDimitry Andric } // __kmp_stg_parse_forkjoin_frames
53230b57cec5SDimitry Andric
__kmp_stg_print_forkjoin_frames(kmp_str_buf_t * buffer,char const * name,void * data)53240b57cec5SDimitry Andric static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
53250b57cec5SDimitry Andric char const *name, void *data) {
53260b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
53270b57cec5SDimitry Andric } // __kmp_stg_print_forkjoin_frames
53280b57cec5SDimitry Andric
53290b57cec5SDimitry Andric // -----------------------------------------------------------------------------
53300b57cec5SDimitry Andric // KMP_FORKJOIN_FRAMES_MODE
53310b57cec5SDimitry Andric
__kmp_stg_parse_forkjoin_frames_mode(char const * name,char const * value,void * data)53320b57cec5SDimitry Andric static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
53330b57cec5SDimitry Andric char const *value,
53340b57cec5SDimitry Andric void *data) {
53350b57cec5SDimitry Andric __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
53360b57cec5SDimitry Andric } // __kmp_stg_parse_forkjoin_frames
53370b57cec5SDimitry Andric
__kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t * buffer,char const * name,void * data)53380b57cec5SDimitry Andric static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
53390b57cec5SDimitry Andric char const *name, void *data) {
53400b57cec5SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
53410b57cec5SDimitry Andric } // __kmp_stg_print_forkjoin_frames
53420b57cec5SDimitry Andric #endif /* USE_ITT_BUILD */
53430b57cec5SDimitry Andric
53440b57cec5SDimitry Andric // -----------------------------------------------------------------------------
53450b57cec5SDimitry Andric // KMP_ENABLE_TASK_THROTTLING
53460b57cec5SDimitry Andric
__kmp_stg_parse_task_throttling(char const * name,char const * value,void * data)5347fe6060f1SDimitry Andric static void __kmp_stg_parse_task_throttling(char const *name, char const *value,
5348fe6060f1SDimitry Andric void *data) {
53490b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_enable_task_throttling);
53500b57cec5SDimitry Andric } // __kmp_stg_parse_task_throttling
53510b57cec5SDimitry Andric
__kmp_stg_print_task_throttling(kmp_str_buf_t * buffer,char const * name,void * data)53520b57cec5SDimitry Andric static void __kmp_stg_print_task_throttling(kmp_str_buf_t *buffer,
53530b57cec5SDimitry Andric char const *name, void *data) {
53540b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_enable_task_throttling);
53550b57cec5SDimitry Andric } // __kmp_stg_print_task_throttling
53560b57cec5SDimitry Andric
5357e8d8bef9SDimitry Andric #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5358e8d8bef9SDimitry Andric // -----------------------------------------------------------------------------
5359e8d8bef9SDimitry Andric // KMP_USER_LEVEL_MWAIT
5360e8d8bef9SDimitry Andric
__kmp_stg_parse_user_level_mwait(char const * name,char const * value,void * data)5361e8d8bef9SDimitry Andric static void __kmp_stg_parse_user_level_mwait(char const *name,
5362e8d8bef9SDimitry Andric char const *value, void *data) {
5363e8d8bef9SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_user_level_mwait);
5364e8d8bef9SDimitry Andric } // __kmp_stg_parse_user_level_mwait
5365e8d8bef9SDimitry Andric
__kmp_stg_print_user_level_mwait(kmp_str_buf_t * buffer,char const * name,void * data)5366e8d8bef9SDimitry Andric static void __kmp_stg_print_user_level_mwait(kmp_str_buf_t *buffer,
5367e8d8bef9SDimitry Andric char const *name, void *data) {
5368e8d8bef9SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_user_level_mwait);
5369e8d8bef9SDimitry Andric } // __kmp_stg_print_user_level_mwait
5370e8d8bef9SDimitry Andric
5371e8d8bef9SDimitry Andric // -----------------------------------------------------------------------------
5372e8d8bef9SDimitry Andric // KMP_MWAIT_HINTS
5373e8d8bef9SDimitry Andric
__kmp_stg_parse_mwait_hints(char const * name,char const * value,void * data)5374e8d8bef9SDimitry Andric static void __kmp_stg_parse_mwait_hints(char const *name, char const *value,
5375e8d8bef9SDimitry Andric void *data) {
5376e8d8bef9SDimitry Andric __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_mwait_hints);
5377e8d8bef9SDimitry Andric } // __kmp_stg_parse_mwait_hints
5378e8d8bef9SDimitry Andric
__kmp_stg_print_mwait_hints(kmp_str_buf_t * buffer,char const * name,void * data)5379e8d8bef9SDimitry Andric static void __kmp_stg_print_mwait_hints(kmp_str_buf_t *buffer, char const *name,
5380e8d8bef9SDimitry Andric void *data) {
5381e8d8bef9SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_mwait_hints);
5382e8d8bef9SDimitry Andric } // __kmp_stg_print_mwait_hints
5383e8d8bef9SDimitry Andric
5384e8d8bef9SDimitry Andric #endif // KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5385e8d8bef9SDimitry Andric
538604eeddc0SDimitry Andric #if KMP_HAVE_UMWAIT
538704eeddc0SDimitry Andric // -----------------------------------------------------------------------------
538804eeddc0SDimitry Andric // KMP_TPAUSE
538904eeddc0SDimitry Andric // 0 = don't use TPAUSE, 1 = use C0.1 state, 2 = use C0.2 state
539004eeddc0SDimitry Andric
__kmp_stg_parse_tpause(char const * name,char const * value,void * data)539104eeddc0SDimitry Andric static void __kmp_stg_parse_tpause(char const *name, char const *value,
539204eeddc0SDimitry Andric void *data) {
539304eeddc0SDimitry Andric __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_tpause_state);
539404eeddc0SDimitry Andric if (__kmp_tpause_state != 0) {
539504eeddc0SDimitry Andric // The actual hint passed to tpause is: 0 for C0.2 and 1 for C0.1
539604eeddc0SDimitry Andric if (__kmp_tpause_state == 2) // use C0.2
539704eeddc0SDimitry Andric __kmp_tpause_hint = 0; // default was set to 1 for C0.1
539804eeddc0SDimitry Andric }
539904eeddc0SDimitry Andric } // __kmp_stg_parse_tpause
540004eeddc0SDimitry Andric
__kmp_stg_print_tpause(kmp_str_buf_t * buffer,char const * name,void * data)540104eeddc0SDimitry Andric static void __kmp_stg_print_tpause(kmp_str_buf_t *buffer, char const *name,
540204eeddc0SDimitry Andric void *data) {
540304eeddc0SDimitry Andric __kmp_stg_print_int(buffer, name, __kmp_tpause_state);
540404eeddc0SDimitry Andric } // __kmp_stg_print_tpause
540504eeddc0SDimitry Andric #endif // KMP_HAVE_UMWAIT
540604eeddc0SDimitry Andric
54070b57cec5SDimitry Andric // -----------------------------------------------------------------------------
54080b57cec5SDimitry Andric // OMP_DISPLAY_ENV
54090b57cec5SDimitry Andric
__kmp_stg_parse_omp_display_env(char const * name,char const * value,void * data)54100b57cec5SDimitry Andric static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
54110b57cec5SDimitry Andric void *data) {
54120b57cec5SDimitry Andric if (__kmp_str_match("VERBOSE", 1, value)) {
54130b57cec5SDimitry Andric __kmp_display_env_verbose = TRUE;
54140b57cec5SDimitry Andric } else {
54150b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_display_env);
54160b57cec5SDimitry Andric }
54170b57cec5SDimitry Andric } // __kmp_stg_parse_omp_display_env
54180b57cec5SDimitry Andric
__kmp_stg_print_omp_display_env(kmp_str_buf_t * buffer,char const * name,void * data)54190b57cec5SDimitry Andric static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
54200b57cec5SDimitry Andric char const *name, void *data) {
54210b57cec5SDimitry Andric if (__kmp_display_env_verbose) {
54220b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, "VERBOSE");
54230b57cec5SDimitry Andric } else {
54240b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_display_env);
54250b57cec5SDimitry Andric }
54260b57cec5SDimitry Andric } // __kmp_stg_print_omp_display_env
54270b57cec5SDimitry Andric
__kmp_stg_parse_omp_cancellation(char const * name,char const * value,void * data)54280b57cec5SDimitry Andric static void __kmp_stg_parse_omp_cancellation(char const *name,
54290b57cec5SDimitry Andric char const *value, void *data) {
54300b57cec5SDimitry Andric if (TCR_4(__kmp_init_parallel)) {
54310b57cec5SDimitry Andric KMP_WARNING(EnvParallelWarn, name);
54320b57cec5SDimitry Andric return;
54330b57cec5SDimitry Andric } // read value before first parallel only
54340b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
54350b57cec5SDimitry Andric } // __kmp_stg_parse_omp_cancellation
54360b57cec5SDimitry Andric
__kmp_stg_print_omp_cancellation(kmp_str_buf_t * buffer,char const * name,void * data)54370b57cec5SDimitry Andric static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
54380b57cec5SDimitry Andric char const *name, void *data) {
54390b57cec5SDimitry Andric __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
54400b57cec5SDimitry Andric } // __kmp_stg_print_omp_cancellation
54410b57cec5SDimitry Andric
54420b57cec5SDimitry Andric #if OMPT_SUPPORT
5443fe6060f1SDimitry Andric int __kmp_tool = 1;
54440b57cec5SDimitry Andric
__kmp_stg_parse_omp_tool(char const * name,char const * value,void * data)54450b57cec5SDimitry Andric static void __kmp_stg_parse_omp_tool(char const *name, char const *value,
54460b57cec5SDimitry Andric void *data) {
54470b57cec5SDimitry Andric __kmp_stg_parse_bool(name, value, &__kmp_tool);
54480b57cec5SDimitry Andric } // __kmp_stg_parse_omp_tool
54490b57cec5SDimitry Andric
__kmp_stg_print_omp_tool(kmp_str_buf_t * buffer,char const * name,void * data)54500b57cec5SDimitry Andric static void __kmp_stg_print_omp_tool(kmp_str_buf_t *buffer, char const *name,
54510b57cec5SDimitry Andric void *data) {
54520b57cec5SDimitry Andric if (__kmp_env_format) {
54530b57cec5SDimitry Andric KMP_STR_BUF_PRINT_BOOL_EX(name, __kmp_tool, "enabled", "disabled");
54540b57cec5SDimitry Andric } else {
54550b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s=%s\n", name,
54560b57cec5SDimitry Andric __kmp_tool ? "enabled" : "disabled");
54570b57cec5SDimitry Andric }
54580b57cec5SDimitry Andric } // __kmp_stg_print_omp_tool
54590b57cec5SDimitry Andric
5460fe6060f1SDimitry Andric char *__kmp_tool_libraries = NULL;
54610b57cec5SDimitry Andric
__kmp_stg_parse_omp_tool_libraries(char const * name,char const * value,void * data)54620b57cec5SDimitry Andric static void __kmp_stg_parse_omp_tool_libraries(char const *name,
54630b57cec5SDimitry Andric char const *value, void *data) {
54640b57cec5SDimitry Andric __kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
54650b57cec5SDimitry Andric } // __kmp_stg_parse_omp_tool_libraries
54660b57cec5SDimitry Andric
__kmp_stg_print_omp_tool_libraries(kmp_str_buf_t * buffer,char const * name,void * data)54670b57cec5SDimitry Andric static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer,
54680b57cec5SDimitry Andric char const *name, void *data) {
54690b57cec5SDimitry Andric if (__kmp_tool_libraries)
54700b57cec5SDimitry Andric __kmp_stg_print_str(buffer, name, __kmp_tool_libraries);
54710b57cec5SDimitry Andric else {
54720b57cec5SDimitry Andric if (__kmp_env_format) {
54730b57cec5SDimitry Andric KMP_STR_BUF_PRINT_NAME;
54740b57cec5SDimitry Andric } else {
54750b57cec5SDimitry Andric __kmp_str_buf_print(buffer, " %s", name);
54760b57cec5SDimitry Andric }
54770b57cec5SDimitry Andric __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
54780b57cec5SDimitry Andric }
54790b57cec5SDimitry Andric } // __kmp_stg_print_omp_tool_libraries
54800b57cec5SDimitry Andric
5481fe6060f1SDimitry Andric char *__kmp_tool_verbose_init = NULL;
5482e8d8bef9SDimitry Andric
__kmp_stg_parse_omp_tool_verbose_init(char const * name,char const * value,void * data)5483e8d8bef9SDimitry Andric static void __kmp_stg_parse_omp_tool_verbose_init(char const *name,
5484fe6060f1SDimitry Andric char const *value,
5485fe6060f1SDimitry Andric void *data) {
5486e8d8bef9SDimitry Andric __kmp_stg_parse_str(name, value, &__kmp_tool_verbose_init);
5487e8d8bef9SDimitry Andric } // __kmp_stg_parse_omp_tool_libraries
5488e8d8bef9SDimitry Andric
__kmp_stg_print_omp_tool_verbose_init(kmp_str_buf_t * buffer,char const * name,void * data)5489e8d8bef9SDimitry Andric static void __kmp_stg_print_omp_tool_verbose_init(kmp_str_buf_t *buffer,
5490fe6060f1SDimitry Andric char const *name,
5491fe6060f1SDimitry Andric void *data) {
5492e8d8bef9SDimitry Andric if (__kmp_tool_verbose_init)
5493fe6060f1SDimitry Andric __kmp_stg_print_str(buffer, name, __kmp_tool_verbose_init);
5494e8d8bef9SDimitry Andric else {
5495e8d8bef9SDimitry Andric if (__kmp_env_format) {
5496e8d8bef9SDimitry Andric KMP_STR_BUF_PRINT_NAME;
5497e8d8bef9SDimitry Andric } else {
5498e8d8bef9SDimitry Andric __kmp_str_buf_print(buffer, " %s", name);
5499e8d8bef9SDimitry Andric }
5500e8d8bef9SDimitry Andric __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
5501e8d8bef9SDimitry Andric }
5502e8d8bef9SDimitry Andric } // __kmp_stg_print_omp_tool_verbose_init
5503e8d8bef9SDimitry Andric
55040b57cec5SDimitry Andric #endif
55050b57cec5SDimitry Andric
55060b57cec5SDimitry Andric // Table.
55070b57cec5SDimitry Andric
55080b57cec5SDimitry Andric static kmp_setting_t __kmp_stg_table[] = {
55090b57cec5SDimitry Andric
55100b57cec5SDimitry Andric {"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
55110b57cec5SDimitry Andric {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
55120b57cec5SDimitry Andric NULL, 0, 0},
55130b57cec5SDimitry Andric {"KMP_USE_YIELD", __kmp_stg_parse_use_yield, __kmp_stg_print_use_yield,
55140b57cec5SDimitry Andric NULL, 0, 0},
55150b57cec5SDimitry Andric {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
55160b57cec5SDimitry Andric __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
55170b57cec5SDimitry Andric {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
55180b57cec5SDimitry Andric NULL, 0, 0},
55190b57cec5SDimitry Andric {"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
55200b57cec5SDimitry Andric __kmp_stg_print_device_thread_limit, NULL, 0, 0},
55210b57cec5SDimitry Andric #if KMP_USE_MONITOR
55220b57cec5SDimitry Andric {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
55230b57cec5SDimitry Andric __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
55240b57cec5SDimitry Andric #endif
55250b57cec5SDimitry Andric {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
55260b57cec5SDimitry Andric 0, 0},
55270b57cec5SDimitry Andric {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
55280b57cec5SDimitry Andric __kmp_stg_print_stackoffset, NULL, 0, 0},
55290b57cec5SDimitry Andric {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
55300b57cec5SDimitry Andric NULL, 0, 0},
55310b57cec5SDimitry Andric {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
55320b57cec5SDimitry Andric 0, 0},
55330b57cec5SDimitry Andric {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
55340b57cec5SDimitry Andric 0},
55350b57cec5SDimitry Andric {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
55360b57cec5SDimitry Andric 0, 0},
55370b57cec5SDimitry Andric
5538fe6060f1SDimitry Andric {"KMP_NESTING_MODE", __kmp_stg_parse_nesting_mode,
5539fe6060f1SDimitry Andric __kmp_stg_print_nesting_mode, NULL, 0, 0},
55400b57cec5SDimitry Andric {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
55410b57cec5SDimitry Andric {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
55420b57cec5SDimitry Andric __kmp_stg_print_num_threads, NULL, 0, 0},
55430b57cec5SDimitry Andric {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
55440b57cec5SDimitry Andric NULL, 0, 0},
55450b57cec5SDimitry Andric
55460b57cec5SDimitry Andric {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
55470b57cec5SDimitry Andric 0},
55480b57cec5SDimitry Andric {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
55490b57cec5SDimitry Andric __kmp_stg_print_task_stealing, NULL, 0, 0},
55500b57cec5SDimitry Andric {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
55510b57cec5SDimitry Andric __kmp_stg_print_max_active_levels, NULL, 0, 0},
55520b57cec5SDimitry Andric {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
55530b57cec5SDimitry Andric __kmp_stg_print_default_device, NULL, 0, 0},
55540b57cec5SDimitry Andric {"OMP_TARGET_OFFLOAD", __kmp_stg_parse_target_offload,
55550b57cec5SDimitry Andric __kmp_stg_print_target_offload, NULL, 0, 0},
55560b57cec5SDimitry Andric {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
55570b57cec5SDimitry Andric __kmp_stg_print_max_task_priority, NULL, 0, 0},
55580b57cec5SDimitry Andric {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
55590b57cec5SDimitry Andric __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
55600b57cec5SDimitry Andric {"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
55610b57cec5SDimitry Andric __kmp_stg_print_thread_limit, NULL, 0, 0},
55620b57cec5SDimitry Andric {"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
55630b57cec5SDimitry Andric __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
5564fe6060f1SDimitry Andric {"OMP_NUM_TEAMS", __kmp_stg_parse_nteams, __kmp_stg_print_nteams, NULL, 0,
5565fe6060f1SDimitry Andric 0},
5566fe6060f1SDimitry Andric {"OMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_th_limit,
5567fe6060f1SDimitry Andric __kmp_stg_print_teams_th_limit, NULL, 0, 0},
55680b57cec5SDimitry Andric {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
55690b57cec5SDimitry Andric __kmp_stg_print_wait_policy, NULL, 0, 0},
55700b57cec5SDimitry Andric {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
55710b57cec5SDimitry Andric __kmp_stg_print_disp_buffers, NULL, 0, 0},
55720b57cec5SDimitry Andric #if KMP_NESTED_HOT_TEAMS
55730b57cec5SDimitry Andric {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
55740b57cec5SDimitry Andric __kmp_stg_print_hot_teams_level, NULL, 0, 0},
55750b57cec5SDimitry Andric {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
55760b57cec5SDimitry Andric __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
55770b57cec5SDimitry Andric #endif // KMP_NESTED_HOT_TEAMS
55780b57cec5SDimitry Andric
55790b57cec5SDimitry Andric #if KMP_HANDLE_SIGNALS
55800b57cec5SDimitry Andric {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
55810b57cec5SDimitry Andric __kmp_stg_print_handle_signals, NULL, 0, 0},
55820b57cec5SDimitry Andric #endif
55830b57cec5SDimitry Andric
55840b57cec5SDimitry Andric #if KMP_ARCH_X86 || KMP_ARCH_X86_64
55850b57cec5SDimitry Andric {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
55860b57cec5SDimitry Andric __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
55870b57cec5SDimitry Andric #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
55880b57cec5SDimitry Andric
55890b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
55900b57cec5SDimitry Andric {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
55910b57cec5SDimitry Andric #endif
55920b57cec5SDimitry Andric
55930b57cec5SDimitry Andric #ifdef KMP_DEBUG
55940b57cec5SDimitry Andric {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
55950b57cec5SDimitry Andric 0},
55960b57cec5SDimitry Andric {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
55970b57cec5SDimitry Andric 0},
55980b57cec5SDimitry Andric {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
55990b57cec5SDimitry Andric 0},
56000b57cec5SDimitry Andric {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
56010b57cec5SDimitry Andric 0},
56020b57cec5SDimitry Andric {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
56030b57cec5SDimitry Andric 0},
56040b57cec5SDimitry Andric {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
56050b57cec5SDimitry Andric 0},
56060b57cec5SDimitry Andric {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
56070b57cec5SDimitry Andric {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
56080b57cec5SDimitry Andric NULL, 0, 0},
56090b57cec5SDimitry Andric {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
56100b57cec5SDimitry Andric __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
56110b57cec5SDimitry Andric {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
56120b57cec5SDimitry Andric __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
56130b57cec5SDimitry Andric {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
56140b57cec5SDimitry Andric __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
56150b57cec5SDimitry Andric {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
56160b57cec5SDimitry Andric
56170b57cec5SDimitry Andric {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
56180b57cec5SDimitry Andric __kmp_stg_print_par_range_env, NULL, 0, 0},
56190b57cec5SDimitry Andric #endif // KMP_DEBUG
56200b57cec5SDimitry Andric
56210b57cec5SDimitry Andric {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
56220b57cec5SDimitry Andric __kmp_stg_print_align_alloc, NULL, 0, 0},
56230b57cec5SDimitry Andric
56240b57cec5SDimitry Andric {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
56250b57cec5SDimitry Andric __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
56260b57cec5SDimitry Andric {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
56270b57cec5SDimitry Andric __kmp_stg_print_barrier_pattern, NULL, 0, 0},
56280b57cec5SDimitry Andric {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
56290b57cec5SDimitry Andric __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
56300b57cec5SDimitry Andric {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
56310b57cec5SDimitry Andric __kmp_stg_print_barrier_pattern, NULL, 0, 0},
56320b57cec5SDimitry Andric #if KMP_FAST_REDUCTION_BARRIER
56330b57cec5SDimitry Andric {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
56340b57cec5SDimitry Andric __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
56350b57cec5SDimitry Andric {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
56360b57cec5SDimitry Andric __kmp_stg_print_barrier_pattern, NULL, 0, 0},
56370b57cec5SDimitry Andric #endif
56380b57cec5SDimitry Andric
56390b57cec5SDimitry Andric {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
56400b57cec5SDimitry Andric __kmp_stg_print_abort_delay, NULL, 0, 0},
56410b57cec5SDimitry Andric {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
56420b57cec5SDimitry Andric __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
56430b57cec5SDimitry Andric {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
56440b57cec5SDimitry Andric __kmp_stg_print_force_reduction, NULL, 0, 0},
56450b57cec5SDimitry Andric {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
56460b57cec5SDimitry Andric __kmp_stg_print_force_reduction, NULL, 0, 0},
56470b57cec5SDimitry Andric {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
56480b57cec5SDimitry Andric __kmp_stg_print_storage_map, NULL, 0, 0},
56490b57cec5SDimitry Andric {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
56500b57cec5SDimitry Andric __kmp_stg_print_all_threadprivate, NULL, 0, 0},
56510b57cec5SDimitry Andric {"KMP_FOREIGN_THREADS_THREADPRIVATE",
56520b57cec5SDimitry Andric __kmp_stg_parse_foreign_threads_threadprivate,
56530b57cec5SDimitry Andric __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
56540b57cec5SDimitry Andric
56550b57cec5SDimitry Andric #if KMP_AFFINITY_SUPPORTED
56560b57cec5SDimitry Andric {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
56570b57cec5SDimitry Andric 0, 0},
5658bdd1243dSDimitry Andric {"KMP_HIDDEN_HELPER_AFFINITY", __kmp_stg_parse_hh_affinity,
5659bdd1243dSDimitry Andric __kmp_stg_print_hh_affinity, NULL, 0, 0},
56600b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
56610b57cec5SDimitry Andric {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
56620b57cec5SDimitry Andric /* no print */ NULL, 0, 0},
56630b57cec5SDimitry Andric #endif /* KMP_GOMP_COMPAT */
56640b57cec5SDimitry Andric {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
56650b57cec5SDimitry Andric NULL, 0, 0},
5666349cc55cSDimitry Andric {"KMP_TEAMS_PROC_BIND", __kmp_stg_parse_teams_proc_bind,
5667349cc55cSDimitry Andric __kmp_stg_print_teams_proc_bind, NULL, 0, 0},
56680b57cec5SDimitry Andric {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
56690b57cec5SDimitry Andric {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
56700b57cec5SDimitry Andric __kmp_stg_print_topology_method, NULL, 0, 0},
56710b57cec5SDimitry Andric
56720b57cec5SDimitry Andric #else
56730b57cec5SDimitry Andric
56740b57cec5SDimitry Andric // KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
56750b57cec5SDimitry Andric // OMP_PROC_BIND and proc-bind-var are supported, however.
56760b57cec5SDimitry Andric {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
56770b57cec5SDimitry Andric NULL, 0, 0},
56780b57cec5SDimitry Andric
56790b57cec5SDimitry Andric #endif // KMP_AFFINITY_SUPPORTED
56800b57cec5SDimitry Andric {"OMP_DISPLAY_AFFINITY", __kmp_stg_parse_display_affinity,
56810b57cec5SDimitry Andric __kmp_stg_print_display_affinity, NULL, 0, 0},
56820b57cec5SDimitry Andric {"OMP_AFFINITY_FORMAT", __kmp_stg_parse_affinity_format,
56830b57cec5SDimitry Andric __kmp_stg_print_affinity_format, NULL, 0, 0},
56840b57cec5SDimitry Andric {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
56850b57cec5SDimitry Andric __kmp_stg_print_init_at_fork, NULL, 0, 0},
56860b57cec5SDimitry Andric {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
56870b57cec5SDimitry Andric 0, 0},
56880b57cec5SDimitry Andric {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
56890b57cec5SDimitry Andric NULL, 0, 0},
56900b57cec5SDimitry Andric #if KMP_USE_HIER_SCHED
56910b57cec5SDimitry Andric {"KMP_DISP_HAND_THREAD", __kmp_stg_parse_kmp_hand_thread,
56920b57cec5SDimitry Andric __kmp_stg_print_kmp_hand_thread, NULL, 0, 0},
56930b57cec5SDimitry Andric #endif
5694fe6060f1SDimitry Andric {"KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE",
5695fe6060f1SDimitry Andric __kmp_stg_parse_kmp_force_monotonic, __kmp_stg_print_kmp_force_monotonic,
5696fe6060f1SDimitry Andric NULL, 0, 0},
56970b57cec5SDimitry Andric {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
56980b57cec5SDimitry Andric __kmp_stg_print_atomic_mode, NULL, 0, 0},
56990b57cec5SDimitry Andric {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
57000b57cec5SDimitry Andric __kmp_stg_print_consistency_check, NULL, 0, 0},
57010b57cec5SDimitry Andric
57020b57cec5SDimitry Andric #if USE_ITT_BUILD && USE_ITT_NOTIFY
57030b57cec5SDimitry Andric {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
57040b57cec5SDimitry Andric __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
57050b57cec5SDimitry Andric #endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
57060b57cec5SDimitry Andric {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
57070b57cec5SDimitry Andric __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
57080b57cec5SDimitry Andric {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
57090b57cec5SDimitry Andric NULL, 0, 0},
57100b57cec5SDimitry Andric {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
57110b57cec5SDimitry Andric NULL, 0, 0},
57120b57cec5SDimitry Andric {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
57130b57cec5SDimitry Andric __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
57140b57cec5SDimitry Andric
57150b57cec5SDimitry Andric #ifdef USE_LOAD_BALANCE
57160b57cec5SDimitry Andric {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
57170b57cec5SDimitry Andric __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
57180b57cec5SDimitry Andric #endif
57190b57cec5SDimitry Andric
57200b57cec5SDimitry Andric {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
57210b57cec5SDimitry Andric __kmp_stg_print_lock_block, NULL, 0, 0},
57220b57cec5SDimitry Andric {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
57230b57cec5SDimitry Andric NULL, 0, 0},
57240b57cec5SDimitry Andric {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
57250b57cec5SDimitry Andric __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
57260b57cec5SDimitry Andric #if KMP_USE_ADAPTIVE_LOCKS
57270b57cec5SDimitry Andric {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
57280b57cec5SDimitry Andric __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
57290b57cec5SDimitry Andric #if KMP_DEBUG_ADAPTIVE_LOCKS
57300b57cec5SDimitry Andric {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
57310b57cec5SDimitry Andric __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
57320b57cec5SDimitry Andric #endif
57330b57cec5SDimitry Andric #endif // KMP_USE_ADAPTIVE_LOCKS
57340b57cec5SDimitry Andric {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
57350b57cec5SDimitry Andric NULL, 0, 0},
57360b57cec5SDimitry Andric {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
57370b57cec5SDimitry Andric NULL, 0, 0},
57380b57cec5SDimitry Andric #if USE_ITT_BUILD
57390b57cec5SDimitry Andric {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
57400b57cec5SDimitry Andric __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
57410b57cec5SDimitry Andric {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
57420b57cec5SDimitry Andric __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
57430b57cec5SDimitry Andric #endif
57440b57cec5SDimitry Andric {"KMP_ENABLE_TASK_THROTTLING", __kmp_stg_parse_task_throttling,
57450b57cec5SDimitry Andric __kmp_stg_print_task_throttling, NULL, 0, 0},
57460b57cec5SDimitry Andric
57470b57cec5SDimitry Andric {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
57480b57cec5SDimitry Andric __kmp_stg_print_omp_display_env, NULL, 0, 0},
57490b57cec5SDimitry Andric {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
57500b57cec5SDimitry Andric __kmp_stg_print_omp_cancellation, NULL, 0, 0},
57510b57cec5SDimitry Andric {"OMP_ALLOCATOR", __kmp_stg_parse_allocator, __kmp_stg_print_allocator,
57520b57cec5SDimitry Andric NULL, 0, 0},
5753e8d8bef9SDimitry Andric {"LIBOMP_USE_HIDDEN_HELPER_TASK", __kmp_stg_parse_use_hidden_helper,
5754e8d8bef9SDimitry Andric __kmp_stg_print_use_hidden_helper, NULL, 0, 0},
5755e8d8bef9SDimitry Andric {"LIBOMP_NUM_HIDDEN_HELPER_THREADS",
5756e8d8bef9SDimitry Andric __kmp_stg_parse_num_hidden_helper_threads,
5757e8d8bef9SDimitry Andric __kmp_stg_print_num_hidden_helper_threads, NULL, 0, 0},
575806c3fb27SDimitry Andric #if OMPX_TASKGRAPH
575906c3fb27SDimitry Andric {"KMP_MAX_TDGS", __kmp_stg_parse_max_tdgs, __kmp_std_print_max_tdgs, NULL,
576006c3fb27SDimitry Andric 0, 0},
576106c3fb27SDimitry Andric {"KMP_TDG_DOT", __kmp_stg_parse_tdg_dot, __kmp_stg_print_tdg_dot, NULL, 0, 0},
576206c3fb27SDimitry Andric #endif
57630b57cec5SDimitry Andric
57640b57cec5SDimitry Andric #if OMPT_SUPPORT
57650b57cec5SDimitry Andric {"OMP_TOOL", __kmp_stg_parse_omp_tool, __kmp_stg_print_omp_tool, NULL, 0,
57660b57cec5SDimitry Andric 0},
57670b57cec5SDimitry Andric {"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries,
57680b57cec5SDimitry Andric __kmp_stg_print_omp_tool_libraries, NULL, 0, 0},
5769e8d8bef9SDimitry Andric {"OMP_TOOL_VERBOSE_INIT", __kmp_stg_parse_omp_tool_verbose_init,
5770e8d8bef9SDimitry Andric __kmp_stg_print_omp_tool_verbose_init, NULL, 0, 0},
57710b57cec5SDimitry Andric #endif
57720b57cec5SDimitry Andric
5773e8d8bef9SDimitry Andric #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5774e8d8bef9SDimitry Andric {"KMP_USER_LEVEL_MWAIT", __kmp_stg_parse_user_level_mwait,
5775e8d8bef9SDimitry Andric __kmp_stg_print_user_level_mwait, NULL, 0, 0},
5776e8d8bef9SDimitry Andric {"KMP_MWAIT_HINTS", __kmp_stg_parse_mwait_hints,
5777e8d8bef9SDimitry Andric __kmp_stg_print_mwait_hints, NULL, 0, 0},
5778e8d8bef9SDimitry Andric #endif
577904eeddc0SDimitry Andric
578004eeddc0SDimitry Andric #if KMP_HAVE_UMWAIT
578104eeddc0SDimitry Andric {"KMP_TPAUSE", __kmp_stg_parse_tpause, __kmp_stg_print_tpause, NULL, 0, 0},
578204eeddc0SDimitry Andric #endif
57830b57cec5SDimitry Andric {"", NULL, NULL, NULL, 0, 0}}; // settings
57840b57cec5SDimitry Andric
57850b57cec5SDimitry Andric static int const __kmp_stg_count =
57860b57cec5SDimitry Andric sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
57870b57cec5SDimitry Andric
__kmp_stg_find(char const * name)57880b57cec5SDimitry Andric static inline kmp_setting_t *__kmp_stg_find(char const *name) {
57890b57cec5SDimitry Andric
57900b57cec5SDimitry Andric int i;
57910b57cec5SDimitry Andric if (name != NULL) {
57920b57cec5SDimitry Andric for (i = 0; i < __kmp_stg_count; ++i) {
57930b57cec5SDimitry Andric if (strcmp(__kmp_stg_table[i].name, name) == 0) {
57940b57cec5SDimitry Andric return &__kmp_stg_table[i];
57950b57cec5SDimitry Andric }
57960b57cec5SDimitry Andric }
57970b57cec5SDimitry Andric }
57980b57cec5SDimitry Andric return NULL;
57990b57cec5SDimitry Andric
58000b57cec5SDimitry Andric } // __kmp_stg_find
58010b57cec5SDimitry Andric
__kmp_stg_cmp(void const * _a,void const * _b)58020b57cec5SDimitry Andric static int __kmp_stg_cmp(void const *_a, void const *_b) {
58030b57cec5SDimitry Andric const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
58040b57cec5SDimitry Andric const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);
58050b57cec5SDimitry Andric
58060b57cec5SDimitry Andric // Process KMP_AFFINITY last.
58070b57cec5SDimitry Andric // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
58080b57cec5SDimitry Andric if (strcmp(a->name, "KMP_AFFINITY") == 0) {
58090b57cec5SDimitry Andric if (strcmp(b->name, "KMP_AFFINITY") == 0) {
58100b57cec5SDimitry Andric return 0;
58110b57cec5SDimitry Andric }
58120b57cec5SDimitry Andric return 1;
58130b57cec5SDimitry Andric } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
58140b57cec5SDimitry Andric return -1;
58150b57cec5SDimitry Andric }
58160b57cec5SDimitry Andric return strcmp(a->name, b->name);
58170b57cec5SDimitry Andric } // __kmp_stg_cmp
58180b57cec5SDimitry Andric
__kmp_stg_init(void)58190b57cec5SDimitry Andric static void __kmp_stg_init(void) {
58200b57cec5SDimitry Andric
58210b57cec5SDimitry Andric static int initialized = 0;
58220b57cec5SDimitry Andric
58230b57cec5SDimitry Andric if (!initialized) {
58240b57cec5SDimitry Andric
58250b57cec5SDimitry Andric // Sort table.
58260b57cec5SDimitry Andric qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
58270b57cec5SDimitry Andric __kmp_stg_cmp);
58280b57cec5SDimitry Andric
58290b57cec5SDimitry Andric { // Initialize *_STACKSIZE data.
58300b57cec5SDimitry Andric kmp_setting_t *kmp_stacksize =
58310b57cec5SDimitry Andric __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
58320b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
58330b57cec5SDimitry Andric kmp_setting_t *gomp_stacksize =
58340b57cec5SDimitry Andric __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
58350b57cec5SDimitry Andric #endif
58360b57cec5SDimitry Andric kmp_setting_t *omp_stacksize =
58370b57cec5SDimitry Andric __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
58380b57cec5SDimitry Andric
58390b57cec5SDimitry Andric // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
58400b57cec5SDimitry Andric // !!! Compiler does not understand rivals is used and optimizes out
58410b57cec5SDimitry Andric // assignments
58420b57cec5SDimitry Andric // !!! rivals[ i ++ ] = ...;
58430b57cec5SDimitry Andric static kmp_setting_t *volatile rivals[4];
58440b57cec5SDimitry Andric static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
58450b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
58460b57cec5SDimitry Andric static kmp_stg_ss_data_t gomp_data = {1024,
58470b57cec5SDimitry Andric CCAST(kmp_setting_t **, rivals)};
58480b57cec5SDimitry Andric #endif
58490b57cec5SDimitry Andric static kmp_stg_ss_data_t omp_data = {1024,
58500b57cec5SDimitry Andric CCAST(kmp_setting_t **, rivals)};
58510b57cec5SDimitry Andric int i = 0;
58520b57cec5SDimitry Andric
58530b57cec5SDimitry Andric rivals[i++] = kmp_stacksize;
58540b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
58550b57cec5SDimitry Andric if (gomp_stacksize != NULL) {
58560b57cec5SDimitry Andric rivals[i++] = gomp_stacksize;
58570b57cec5SDimitry Andric }
58580b57cec5SDimitry Andric #endif
58590b57cec5SDimitry Andric rivals[i++] = omp_stacksize;
58600b57cec5SDimitry Andric rivals[i++] = NULL;
58610b57cec5SDimitry Andric
58620b57cec5SDimitry Andric kmp_stacksize->data = &kmp_data;
58630b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
58640b57cec5SDimitry Andric if (gomp_stacksize != NULL) {
58650b57cec5SDimitry Andric gomp_stacksize->data = &gomp_data;
58660b57cec5SDimitry Andric }
58670b57cec5SDimitry Andric #endif
58680b57cec5SDimitry Andric omp_stacksize->data = &omp_data;
58690b57cec5SDimitry Andric }
58700b57cec5SDimitry Andric
58710b57cec5SDimitry Andric { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
58720b57cec5SDimitry Andric kmp_setting_t *kmp_library =
58730b57cec5SDimitry Andric __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
58740b57cec5SDimitry Andric kmp_setting_t *omp_wait_policy =
58750b57cec5SDimitry Andric __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
58760b57cec5SDimitry Andric
58770b57cec5SDimitry Andric // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
58780b57cec5SDimitry Andric static kmp_setting_t *volatile rivals[3];
58790b57cec5SDimitry Andric static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
58800b57cec5SDimitry Andric static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
58810b57cec5SDimitry Andric int i = 0;
58820b57cec5SDimitry Andric
58830b57cec5SDimitry Andric rivals[i++] = kmp_library;
58840b57cec5SDimitry Andric if (omp_wait_policy != NULL) {
58850b57cec5SDimitry Andric rivals[i++] = omp_wait_policy;
58860b57cec5SDimitry Andric }
58870b57cec5SDimitry Andric rivals[i++] = NULL;
58880b57cec5SDimitry Andric
58890b57cec5SDimitry Andric kmp_library->data = &kmp_data;
58900b57cec5SDimitry Andric if (omp_wait_policy != NULL) {
58910b57cec5SDimitry Andric omp_wait_policy->data = &omp_data;
58920b57cec5SDimitry Andric }
58930b57cec5SDimitry Andric }
58940b57cec5SDimitry Andric
58950b57cec5SDimitry Andric { // Initialize KMP_DEVICE_THREAD_LIMIT and KMP_ALL_THREADS
58960b57cec5SDimitry Andric kmp_setting_t *kmp_device_thread_limit =
58970b57cec5SDimitry Andric __kmp_stg_find("KMP_DEVICE_THREAD_LIMIT"); // 1st priority.
58980b57cec5SDimitry Andric kmp_setting_t *kmp_all_threads =
58990b57cec5SDimitry Andric __kmp_stg_find("KMP_ALL_THREADS"); // 2nd priority.
59000b57cec5SDimitry Andric
59010b57cec5SDimitry Andric // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
59020b57cec5SDimitry Andric static kmp_setting_t *volatile rivals[3];
59030b57cec5SDimitry Andric int i = 0;
59040b57cec5SDimitry Andric
59050b57cec5SDimitry Andric rivals[i++] = kmp_device_thread_limit;
59060b57cec5SDimitry Andric rivals[i++] = kmp_all_threads;
59070b57cec5SDimitry Andric rivals[i++] = NULL;
59080b57cec5SDimitry Andric
59090b57cec5SDimitry Andric kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
59100b57cec5SDimitry Andric kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
59110b57cec5SDimitry Andric }
59120b57cec5SDimitry Andric
59130b57cec5SDimitry Andric { // Initialize KMP_HW_SUBSET and KMP_PLACE_THREADS
59140b57cec5SDimitry Andric // 1st priority
59150b57cec5SDimitry Andric kmp_setting_t *kmp_hw_subset = __kmp_stg_find("KMP_HW_SUBSET");
59160b57cec5SDimitry Andric // 2nd priority
59170b57cec5SDimitry Andric kmp_setting_t *kmp_place_threads = __kmp_stg_find("KMP_PLACE_THREADS");
59180b57cec5SDimitry Andric
59190b57cec5SDimitry Andric // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
59200b57cec5SDimitry Andric static kmp_setting_t *volatile rivals[3];
59210b57cec5SDimitry Andric int i = 0;
59220b57cec5SDimitry Andric
59230b57cec5SDimitry Andric rivals[i++] = kmp_hw_subset;
59240b57cec5SDimitry Andric rivals[i++] = kmp_place_threads;
59250b57cec5SDimitry Andric rivals[i++] = NULL;
59260b57cec5SDimitry Andric
59270b57cec5SDimitry Andric kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
59280b57cec5SDimitry Andric kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
59290b57cec5SDimitry Andric }
59300b57cec5SDimitry Andric
59310b57cec5SDimitry Andric #if KMP_AFFINITY_SUPPORTED
59320b57cec5SDimitry Andric { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
59330b57cec5SDimitry Andric kmp_setting_t *kmp_affinity =
59340b57cec5SDimitry Andric __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
59350b57cec5SDimitry Andric KMP_DEBUG_ASSERT(kmp_affinity != NULL);
59360b57cec5SDimitry Andric
59370b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
59380b57cec5SDimitry Andric kmp_setting_t *gomp_cpu_affinity =
59390b57cec5SDimitry Andric __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
59400b57cec5SDimitry Andric KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
59410b57cec5SDimitry Andric #endif
59420b57cec5SDimitry Andric
59430b57cec5SDimitry Andric kmp_setting_t *omp_proc_bind =
59440b57cec5SDimitry Andric __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
59450b57cec5SDimitry Andric KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
59460b57cec5SDimitry Andric
59470b57cec5SDimitry Andric // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
59480b57cec5SDimitry Andric static kmp_setting_t *volatile rivals[4];
59490b57cec5SDimitry Andric int i = 0;
59500b57cec5SDimitry Andric
59510b57cec5SDimitry Andric rivals[i++] = kmp_affinity;
59520b57cec5SDimitry Andric
59530b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
59540b57cec5SDimitry Andric rivals[i++] = gomp_cpu_affinity;
59550b57cec5SDimitry Andric gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
59560b57cec5SDimitry Andric #endif
59570b57cec5SDimitry Andric
59580b57cec5SDimitry Andric rivals[i++] = omp_proc_bind;
59590b57cec5SDimitry Andric omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
59600b57cec5SDimitry Andric rivals[i++] = NULL;
59610b57cec5SDimitry Andric
59620b57cec5SDimitry Andric static kmp_setting_t *volatile places_rivals[4];
59630b57cec5SDimitry Andric i = 0;
59640b57cec5SDimitry Andric
59650b57cec5SDimitry Andric kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
59660b57cec5SDimitry Andric KMP_DEBUG_ASSERT(omp_places != NULL);
59670b57cec5SDimitry Andric
59680b57cec5SDimitry Andric places_rivals[i++] = kmp_affinity;
59690b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
59700b57cec5SDimitry Andric places_rivals[i++] = gomp_cpu_affinity;
59710b57cec5SDimitry Andric #endif
59720b57cec5SDimitry Andric places_rivals[i++] = omp_places;
59730b57cec5SDimitry Andric omp_places->data = CCAST(kmp_setting_t **, places_rivals);
59740b57cec5SDimitry Andric places_rivals[i++] = NULL;
59750b57cec5SDimitry Andric }
59760b57cec5SDimitry Andric #else
59770b57cec5SDimitry Andric // KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
59780b57cec5SDimitry Andric // OMP_PLACES not supported yet.
59790b57cec5SDimitry Andric #endif // KMP_AFFINITY_SUPPORTED
59800b57cec5SDimitry Andric
59810b57cec5SDimitry Andric { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
59820b57cec5SDimitry Andric kmp_setting_t *kmp_force_red =
59830b57cec5SDimitry Andric __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
59840b57cec5SDimitry Andric kmp_setting_t *kmp_determ_red =
59850b57cec5SDimitry Andric __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
59860b57cec5SDimitry Andric
59870b57cec5SDimitry Andric // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
59880b57cec5SDimitry Andric static kmp_setting_t *volatile rivals[3];
59890b57cec5SDimitry Andric static kmp_stg_fr_data_t force_data = {1,
59900b57cec5SDimitry Andric CCAST(kmp_setting_t **, rivals)};
59910b57cec5SDimitry Andric static kmp_stg_fr_data_t determ_data = {0,
59920b57cec5SDimitry Andric CCAST(kmp_setting_t **, rivals)};
59930b57cec5SDimitry Andric int i = 0;
59940b57cec5SDimitry Andric
59950b57cec5SDimitry Andric rivals[i++] = kmp_force_red;
59960b57cec5SDimitry Andric if (kmp_determ_red != NULL) {
59970b57cec5SDimitry Andric rivals[i++] = kmp_determ_red;
59980b57cec5SDimitry Andric }
59990b57cec5SDimitry Andric rivals[i++] = NULL;
60000b57cec5SDimitry Andric
60010b57cec5SDimitry Andric kmp_force_red->data = &force_data;
60020b57cec5SDimitry Andric if (kmp_determ_red != NULL) {
60030b57cec5SDimitry Andric kmp_determ_red->data = &determ_data;
60040b57cec5SDimitry Andric }
60050b57cec5SDimitry Andric }
60060b57cec5SDimitry Andric
60070b57cec5SDimitry Andric initialized = 1;
60080b57cec5SDimitry Andric }
60090b57cec5SDimitry Andric
60100b57cec5SDimitry Andric // Reset flags.
60110b57cec5SDimitry Andric int i;
60120b57cec5SDimitry Andric for (i = 0; i < __kmp_stg_count; ++i) {
60130b57cec5SDimitry Andric __kmp_stg_table[i].set = 0;
60140b57cec5SDimitry Andric }
60150b57cec5SDimitry Andric
60160b57cec5SDimitry Andric } // __kmp_stg_init
60170b57cec5SDimitry Andric
__kmp_stg_parse(char const * name,char const * value)60180b57cec5SDimitry Andric static void __kmp_stg_parse(char const *name, char const *value) {
60190b57cec5SDimitry Andric // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
60200b57cec5SDimitry Andric // really nameless, they are presented in environment block as
60210b57cec5SDimitry Andric // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
60220b57cec5SDimitry Andric if (name[0] == 0) {
60230b57cec5SDimitry Andric return;
60240b57cec5SDimitry Andric }
60250b57cec5SDimitry Andric
60260b57cec5SDimitry Andric if (value != NULL) {
60270b57cec5SDimitry Andric kmp_setting_t *setting = __kmp_stg_find(name);
60280b57cec5SDimitry Andric if (setting != NULL) {
60290b57cec5SDimitry Andric setting->parse(name, value, setting->data);
60300b57cec5SDimitry Andric setting->defined = 1;
60310b57cec5SDimitry Andric }
60320b57cec5SDimitry Andric }
60330b57cec5SDimitry Andric
60340b57cec5SDimitry Andric } // __kmp_stg_parse
60350b57cec5SDimitry Andric
__kmp_stg_check_rivals(char const * name,char const * value,kmp_setting_t ** rivals)60360b57cec5SDimitry Andric static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
60370b57cec5SDimitry Andric char const *name, // Name of variable.
60380b57cec5SDimitry Andric char const *value, // Value of the variable.
60390b57cec5SDimitry Andric kmp_setting_t **rivals // List of rival settings (must include current one).
60400b57cec5SDimitry Andric ) {
60410b57cec5SDimitry Andric
60420b57cec5SDimitry Andric if (rivals == NULL) {
60430b57cec5SDimitry Andric return 0;
60440b57cec5SDimitry Andric }
60450b57cec5SDimitry Andric
60460b57cec5SDimitry Andric // Loop thru higher priority settings (listed before current).
60470b57cec5SDimitry Andric int i = 0;
60480b57cec5SDimitry Andric for (; strcmp(rivals[i]->name, name) != 0; i++) {
60490b57cec5SDimitry Andric KMP_DEBUG_ASSERT(rivals[i] != NULL);
60500b57cec5SDimitry Andric
60510b57cec5SDimitry Andric #if KMP_AFFINITY_SUPPORTED
60520b57cec5SDimitry Andric if (rivals[i] == __kmp_affinity_notype) {
60530b57cec5SDimitry Andric // If KMP_AFFINITY is specified without a type name,
60540b57cec5SDimitry Andric // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
60550b57cec5SDimitry Andric continue;
60560b57cec5SDimitry Andric }
60570b57cec5SDimitry Andric #endif
60580b57cec5SDimitry Andric
60590b57cec5SDimitry Andric if (rivals[i]->set) {
60600b57cec5SDimitry Andric KMP_WARNING(StgIgnored, name, rivals[i]->name);
60610b57cec5SDimitry Andric return 1;
60620b57cec5SDimitry Andric }
60630b57cec5SDimitry Andric }
60640b57cec5SDimitry Andric
60650b57cec5SDimitry Andric ++i; // Skip current setting.
60660b57cec5SDimitry Andric return 0;
60670b57cec5SDimitry Andric
60680b57cec5SDimitry Andric } // __kmp_stg_check_rivals
60690b57cec5SDimitry Andric
__kmp_env_toPrint(char const * name,int flag)60700b57cec5SDimitry Andric static int __kmp_env_toPrint(char const *name, int flag) {
60710b57cec5SDimitry Andric int rc = 0;
60720b57cec5SDimitry Andric kmp_setting_t *setting = __kmp_stg_find(name);
60730b57cec5SDimitry Andric if (setting != NULL) {
60740b57cec5SDimitry Andric rc = setting->defined;
60750b57cec5SDimitry Andric if (flag >= 0) {
60760b57cec5SDimitry Andric setting->defined = flag;
60770b57cec5SDimitry Andric }
60780b57cec5SDimitry Andric }
60790b57cec5SDimitry Andric return rc;
60800b57cec5SDimitry Andric }
60810b57cec5SDimitry Andric
6082bdd1243dSDimitry Andric #if defined(KMP_DEBUG) && KMP_AFFINITY_SUPPORTED
__kmp_print_affinity_settings(const kmp_affinity_t * affinity)6083bdd1243dSDimitry Andric static void __kmp_print_affinity_settings(const kmp_affinity_t *affinity) {
6084bdd1243dSDimitry Andric K_DIAG(1, ("%s:\n", affinity->env_var));
6085bdd1243dSDimitry Andric K_DIAG(1, (" type : %d\n", affinity->type));
6086bdd1243dSDimitry Andric K_DIAG(1, (" compact : %d\n", affinity->compact));
6087bdd1243dSDimitry Andric K_DIAG(1, (" offset : %d\n", affinity->offset));
6088bdd1243dSDimitry Andric K_DIAG(1, (" verbose : %u\n", affinity->flags.verbose));
6089bdd1243dSDimitry Andric K_DIAG(1, (" warnings : %u\n", affinity->flags.warnings));
6090bdd1243dSDimitry Andric K_DIAG(1, (" respect : %u\n", affinity->flags.respect));
6091bdd1243dSDimitry Andric K_DIAG(1, (" reset : %u\n", affinity->flags.reset));
6092bdd1243dSDimitry Andric K_DIAG(1, (" dups : %u\n", affinity->flags.dups));
6093bdd1243dSDimitry Andric K_DIAG(1, (" gran : %d\n", (int)affinity->gran));
6094bdd1243dSDimitry Andric KMP_DEBUG_ASSERT(affinity->type != affinity_default);
6095bdd1243dSDimitry Andric }
6096bdd1243dSDimitry Andric #endif
6097bdd1243dSDimitry Andric
__kmp_aux_env_initialize(kmp_env_blk_t * block)60980b57cec5SDimitry Andric static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
60990b57cec5SDimitry Andric
61000b57cec5SDimitry Andric char const *value;
61010b57cec5SDimitry Andric
61020b57cec5SDimitry Andric /* OMP_NUM_THREADS */
61030b57cec5SDimitry Andric value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
61040b57cec5SDimitry Andric if (value) {
61050b57cec5SDimitry Andric ompc_set_num_threads(__kmp_dflt_team_nth);
61060b57cec5SDimitry Andric }
61070b57cec5SDimitry Andric
61080b57cec5SDimitry Andric /* KMP_BLOCKTIME */
61090b57cec5SDimitry Andric value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
61100b57cec5SDimitry Andric if (value) {
61115f757f3fSDimitry Andric int gtid, tid;
61125f757f3fSDimitry Andric kmp_info_t *thread;
61135f757f3fSDimitry Andric
61145f757f3fSDimitry Andric gtid = __kmp_entry_gtid();
61155f757f3fSDimitry Andric tid = __kmp_tid_from_gtid(gtid);
61165f757f3fSDimitry Andric thread = __kmp_thread_from_gtid(gtid);
61175f757f3fSDimitry Andric __kmp_aux_set_blocktime(__kmp_dflt_blocktime, thread, tid);
61180b57cec5SDimitry Andric }
61190b57cec5SDimitry Andric
61200b57cec5SDimitry Andric /* OMP_NESTED */
61210b57cec5SDimitry Andric value = __kmp_env_blk_var(block, "OMP_NESTED");
61220b57cec5SDimitry Andric if (value) {
61230b57cec5SDimitry Andric ompc_set_nested(__kmp_dflt_max_active_levels > 1);
61240b57cec5SDimitry Andric }
61250b57cec5SDimitry Andric
61260b57cec5SDimitry Andric /* OMP_DYNAMIC */
61270b57cec5SDimitry Andric value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
61280b57cec5SDimitry Andric if (value) {
61290b57cec5SDimitry Andric ompc_set_dynamic(__kmp_global.g.g_dynamic);
61300b57cec5SDimitry Andric }
61310b57cec5SDimitry Andric }
61320b57cec5SDimitry Andric
__kmp_env_initialize(char const * string)61330b57cec5SDimitry Andric void __kmp_env_initialize(char const *string) {
61340b57cec5SDimitry Andric
61350b57cec5SDimitry Andric kmp_env_blk_t block;
61360b57cec5SDimitry Andric int i;
61370b57cec5SDimitry Andric
61380b57cec5SDimitry Andric __kmp_stg_init();
61390b57cec5SDimitry Andric
61400b57cec5SDimitry Andric // Hack!!!
61410b57cec5SDimitry Andric if (string == NULL) {
61420b57cec5SDimitry Andric // __kmp_max_nth = __kmp_sys_max_nth;
61430b57cec5SDimitry Andric __kmp_threads_capacity =
61440b57cec5SDimitry Andric __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
61450b57cec5SDimitry Andric }
61460b57cec5SDimitry Andric __kmp_env_blk_init(&block, string);
61470b57cec5SDimitry Andric
61480b57cec5SDimitry Andric // update the set flag on all entries that have an env var
61490b57cec5SDimitry Andric for (i = 0; i < block.count; ++i) {
61500b57cec5SDimitry Andric if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
61510b57cec5SDimitry Andric continue;
61520b57cec5SDimitry Andric }
61530b57cec5SDimitry Andric if (block.vars[i].value == NULL) {
61540b57cec5SDimitry Andric continue;
61550b57cec5SDimitry Andric }
61560b57cec5SDimitry Andric kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
61570b57cec5SDimitry Andric if (setting != NULL) {
61580b57cec5SDimitry Andric setting->set = 1;
61590b57cec5SDimitry Andric }
61600b57cec5SDimitry Andric }
61610b57cec5SDimitry Andric
61620b57cec5SDimitry Andric // We need to know if blocktime was set when processing OMP_WAIT_POLICY
61630b57cec5SDimitry Andric blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
61640b57cec5SDimitry Andric
61650b57cec5SDimitry Andric // Special case. If we parse environment, not a string, process KMP_WARNINGS
61660b57cec5SDimitry Andric // first.
61670b57cec5SDimitry Andric if (string == NULL) {
61680b57cec5SDimitry Andric char const *name = "KMP_WARNINGS";
61690b57cec5SDimitry Andric char const *value = __kmp_env_blk_var(&block, name);
61700b57cec5SDimitry Andric __kmp_stg_parse(name, value);
61710b57cec5SDimitry Andric }
61720b57cec5SDimitry Andric
61730b57cec5SDimitry Andric #if KMP_AFFINITY_SUPPORTED
61740b57cec5SDimitry Andric // Special case. KMP_AFFINITY is not a rival to other affinity env vars
61750b57cec5SDimitry Andric // if no affinity type is specified. We want to allow
61760b57cec5SDimitry Andric // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
61770b57cec5SDimitry Andric // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
61780b57cec5SDimitry Andric // affinity mechanism.
61790b57cec5SDimitry Andric __kmp_affinity_notype = NULL;
61800b57cec5SDimitry Andric char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
61810b57cec5SDimitry Andric if (aff_str != NULL) {
61820b57cec5SDimitry Andric // Check if the KMP_AFFINITY type is specified in the string.
61830b57cec5SDimitry Andric // We just search the string for "compact", "scatter", etc.
61840b57cec5SDimitry Andric // without really parsing the string. The syntax of the
61850b57cec5SDimitry Andric // KMP_AFFINITY env var is such that none of the affinity
61860b57cec5SDimitry Andric // type names can appear anywhere other that the type
61870b57cec5SDimitry Andric // specifier, even as substrings.
61880b57cec5SDimitry Andric //
61890b57cec5SDimitry Andric // I can't find a case-insensitive version of strstr on Windows* OS.
61901db9f3b2SDimitry Andric // Use the case-sensitive version for now. AIX does the same.
61910b57cec5SDimitry Andric
61921db9f3b2SDimitry Andric #if KMP_OS_WINDOWS || KMP_OS_AIX
61930b57cec5SDimitry Andric #define FIND strstr
61940b57cec5SDimitry Andric #else
61950b57cec5SDimitry Andric #define FIND strcasestr
61960b57cec5SDimitry Andric #endif
61970b57cec5SDimitry Andric
61980b57cec5SDimitry Andric if ((FIND(aff_str, "none") == NULL) &&
61990b57cec5SDimitry Andric (FIND(aff_str, "physical") == NULL) &&
62000b57cec5SDimitry Andric (FIND(aff_str, "logical") == NULL) &&
62010b57cec5SDimitry Andric (FIND(aff_str, "compact") == NULL) &&
62020b57cec5SDimitry Andric (FIND(aff_str, "scatter") == NULL) &&
62030b57cec5SDimitry Andric (FIND(aff_str, "explicit") == NULL) &&
62040b57cec5SDimitry Andric (FIND(aff_str, "balanced") == NULL) &&
62050b57cec5SDimitry Andric (FIND(aff_str, "disabled") == NULL)) {
62060b57cec5SDimitry Andric __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
62070b57cec5SDimitry Andric } else {
62080b57cec5SDimitry Andric // A new affinity type is specified.
62090b57cec5SDimitry Andric // Reset the affinity flags to their default values,
62100b57cec5SDimitry Andric // in case this is called from kmp_set_defaults().
6211bdd1243dSDimitry Andric __kmp_affinity.type = affinity_default;
6212bdd1243dSDimitry Andric __kmp_affinity.gran = KMP_HW_UNKNOWN;
62130b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_default;
6214bdd1243dSDimitry Andric __kmp_affinity.flags.respect = affinity_respect_mask_default;
62150b57cec5SDimitry Andric }
62160b57cec5SDimitry Andric #undef FIND
62170b57cec5SDimitry Andric
62180b57cec5SDimitry Andric // Also reset the affinity flags if OMP_PROC_BIND is specified.
62190b57cec5SDimitry Andric aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
62200b57cec5SDimitry Andric if (aff_str != NULL) {
6221bdd1243dSDimitry Andric __kmp_affinity.type = affinity_default;
6222bdd1243dSDimitry Andric __kmp_affinity.gran = KMP_HW_UNKNOWN;
62230b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_default;
6224bdd1243dSDimitry Andric __kmp_affinity.flags.respect = affinity_respect_mask_default;
62250b57cec5SDimitry Andric }
62260b57cec5SDimitry Andric }
62270b57cec5SDimitry Andric
62280b57cec5SDimitry Andric #endif /* KMP_AFFINITY_SUPPORTED */
62290b57cec5SDimitry Andric
62300b57cec5SDimitry Andric // Set up the nested proc bind type vector.
62310b57cec5SDimitry Andric if (__kmp_nested_proc_bind.bind_types == NULL) {
62320b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types =
62330b57cec5SDimitry Andric (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
62340b57cec5SDimitry Andric if (__kmp_nested_proc_bind.bind_types == NULL) {
62350b57cec5SDimitry Andric KMP_FATAL(MemoryAllocFailed);
62360b57cec5SDimitry Andric }
62370b57cec5SDimitry Andric __kmp_nested_proc_bind.size = 1;
62380b57cec5SDimitry Andric __kmp_nested_proc_bind.used = 1;
62390b57cec5SDimitry Andric #if KMP_AFFINITY_SUPPORTED
62400b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
62410b57cec5SDimitry Andric #else
62420b57cec5SDimitry Andric // default proc bind is false if affinity not supported
62430b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
62440b57cec5SDimitry Andric #endif
62450b57cec5SDimitry Andric }
62460b57cec5SDimitry Andric
62470b57cec5SDimitry Andric // Set up the affinity format ICV
62480b57cec5SDimitry Andric // Grab the default affinity format string from the message catalog
62490b57cec5SDimitry Andric kmp_msg_t m =
62500b57cec5SDimitry Andric __kmp_msg_format(kmp_i18n_msg_AffFormatDefault, "%P", "%i", "%n", "%A");
62510b57cec5SDimitry Andric KMP_DEBUG_ASSERT(KMP_STRLEN(m.str) < KMP_AFFINITY_FORMAT_SIZE);
62520b57cec5SDimitry Andric
62530b57cec5SDimitry Andric if (__kmp_affinity_format == NULL) {
62540b57cec5SDimitry Andric __kmp_affinity_format =
62550b57cec5SDimitry Andric (char *)KMP_INTERNAL_MALLOC(sizeof(char) * KMP_AFFINITY_FORMAT_SIZE);
62560b57cec5SDimitry Andric }
62570b57cec5SDimitry Andric KMP_STRCPY_S(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, m.str);
62580b57cec5SDimitry Andric __kmp_str_free(&m.str);
62590b57cec5SDimitry Andric
62600b57cec5SDimitry Andric // Now process all of the settings.
62610b57cec5SDimitry Andric for (i = 0; i < block.count; ++i) {
62620b57cec5SDimitry Andric __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
62630b57cec5SDimitry Andric }
62640b57cec5SDimitry Andric
62650b57cec5SDimitry Andric // If user locks have been allocated yet, don't reset the lock vptr table.
62660b57cec5SDimitry Andric if (!__kmp_init_user_locks) {
62670b57cec5SDimitry Andric if (__kmp_user_lock_kind == lk_default) {
62680b57cec5SDimitry Andric __kmp_user_lock_kind = lk_queuing;
62690b57cec5SDimitry Andric }
62700b57cec5SDimitry Andric #if KMP_USE_DYNAMIC_LOCK
62710b57cec5SDimitry Andric __kmp_init_dynamic_user_locks();
62720b57cec5SDimitry Andric #else
62730b57cec5SDimitry Andric __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
62740b57cec5SDimitry Andric #endif
62750b57cec5SDimitry Andric } else {
62760b57cec5SDimitry Andric KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
62770b57cec5SDimitry Andric KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
62780b57cec5SDimitry Andric // Binds lock functions again to follow the transition between different
62790b57cec5SDimitry Andric // KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
62800b57cec5SDimitry Andric // as we do not allow lock kind changes after making a call to any
62810b57cec5SDimitry Andric // user lock functions (true).
62820b57cec5SDimitry Andric #if KMP_USE_DYNAMIC_LOCK
62830b57cec5SDimitry Andric __kmp_init_dynamic_user_locks();
62840b57cec5SDimitry Andric #else
62850b57cec5SDimitry Andric __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
62860b57cec5SDimitry Andric #endif
62870b57cec5SDimitry Andric }
62880b57cec5SDimitry Andric
62890b57cec5SDimitry Andric #if KMP_AFFINITY_SUPPORTED
62900b57cec5SDimitry Andric
62910b57cec5SDimitry Andric if (!TCR_4(__kmp_init_middle)) {
62920b57cec5SDimitry Andric #if KMP_USE_HWLOC
62930b57cec5SDimitry Andric // Force using hwloc when either tiles or numa nodes requested within
6294fe6060f1SDimitry Andric // KMP_HW_SUBSET or granularity setting and no other topology method
6295fe6060f1SDimitry Andric // is requested
6296fe6060f1SDimitry Andric if (__kmp_hw_subset &&
6297fe6060f1SDimitry Andric __kmp_affinity_top_method == affinity_top_method_default)
6298fe6060f1SDimitry Andric if (__kmp_hw_subset->specified(KMP_HW_NUMA) ||
6299fe6060f1SDimitry Andric __kmp_hw_subset->specified(KMP_HW_TILE) ||
6300bdd1243dSDimitry Andric __kmp_affinity.gran == KMP_HW_TILE ||
6301bdd1243dSDimitry Andric __kmp_affinity.gran == KMP_HW_NUMA)
63020b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_hwloc;
6303fe6060f1SDimitry Andric // Force using hwloc when tiles or numa nodes requested for OMP_PLACES
6304bdd1243dSDimitry Andric if (__kmp_affinity.gran == KMP_HW_NUMA ||
6305bdd1243dSDimitry Andric __kmp_affinity.gran == KMP_HW_TILE)
6306fe6060f1SDimitry Andric __kmp_affinity_top_method = affinity_top_method_hwloc;
63070b57cec5SDimitry Andric #endif
63080b57cec5SDimitry Andric // Determine if the machine/OS is actually capable of supporting
63090b57cec5SDimitry Andric // affinity.
63100b57cec5SDimitry Andric const char *var = "KMP_AFFINITY";
63110b57cec5SDimitry Andric KMPAffinity::pick_api();
63120b57cec5SDimitry Andric #if KMP_USE_HWLOC
63130b57cec5SDimitry Andric // If Hwloc topology discovery was requested but affinity was also disabled,
63140b57cec5SDimitry Andric // then tell user that Hwloc request is being ignored and use default
63150b57cec5SDimitry Andric // topology discovery method.
63160b57cec5SDimitry Andric if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
63170b57cec5SDimitry Andric __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
63180b57cec5SDimitry Andric KMP_WARNING(AffIgnoringHwloc, var);
63190b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_all;
63200b57cec5SDimitry Andric }
63210b57cec5SDimitry Andric #endif
6322bdd1243dSDimitry Andric if (__kmp_affinity.type == affinity_disabled) {
63230b57cec5SDimitry Andric KMP_AFFINITY_DISABLE();
63240b57cec5SDimitry Andric } else if (!KMP_AFFINITY_CAPABLE()) {
63250b57cec5SDimitry Andric __kmp_affinity_dispatch->determine_capable(var);
63260b57cec5SDimitry Andric if (!KMP_AFFINITY_CAPABLE()) {
6327bdd1243dSDimitry Andric if (__kmp_affinity.flags.verbose ||
6328bdd1243dSDimitry Andric (__kmp_affinity.flags.warnings &&
6329bdd1243dSDimitry Andric (__kmp_affinity.type != affinity_default) &&
6330bdd1243dSDimitry Andric (__kmp_affinity.type != affinity_none) &&
6331bdd1243dSDimitry Andric (__kmp_affinity.type != affinity_disabled))) {
63320b57cec5SDimitry Andric KMP_WARNING(AffNotSupported, var);
63330b57cec5SDimitry Andric }
6334bdd1243dSDimitry Andric __kmp_affinity.type = affinity_disabled;
6335bdd1243dSDimitry Andric __kmp_affinity.flags.respect = FALSE;
6336bdd1243dSDimitry Andric __kmp_affinity.gran = KMP_HW_THREAD;
63370b57cec5SDimitry Andric }
63380b57cec5SDimitry Andric }
63390b57cec5SDimitry Andric
6340bdd1243dSDimitry Andric if (__kmp_affinity.type == affinity_disabled) {
63410b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
63420b57cec5SDimitry Andric } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
63430b57cec5SDimitry Andric // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
63440b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
63450b57cec5SDimitry Andric }
63460b57cec5SDimitry Andric
63470b57cec5SDimitry Andric if (KMP_AFFINITY_CAPABLE()) {
63480b57cec5SDimitry Andric
63490b57cec5SDimitry Andric #if KMP_GROUP_AFFINITY
63500b57cec5SDimitry Andric // This checks to see if the initial affinity mask is equal
63510b57cec5SDimitry Andric // to a single windows processor group. If it is, then we do
63520b57cec5SDimitry Andric // not respect the initial affinity mask and instead, use the
63530b57cec5SDimitry Andric // entire machine.
63540b57cec5SDimitry Andric bool exactly_one_group = false;
63550b57cec5SDimitry Andric if (__kmp_num_proc_groups > 1) {
63560b57cec5SDimitry Andric int group;
63570b57cec5SDimitry Andric bool within_one_group;
63580b57cec5SDimitry Andric // Get the initial affinity mask and determine if it is
63590b57cec5SDimitry Andric // contained within a single group.
63600b57cec5SDimitry Andric kmp_affin_mask_t *init_mask;
63610b57cec5SDimitry Andric KMP_CPU_ALLOC(init_mask);
63620b57cec5SDimitry Andric __kmp_get_system_affinity(init_mask, TRUE);
63630b57cec5SDimitry Andric group = __kmp_get_proc_group(init_mask);
63640b57cec5SDimitry Andric within_one_group = (group >= 0);
63650b57cec5SDimitry Andric // If the initial affinity is within a single group,
63660b57cec5SDimitry Andric // then determine if it is equal to that single group.
63670b57cec5SDimitry Andric if (within_one_group) {
63680b57cec5SDimitry Andric DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
63690b57cec5SDimitry Andric DWORD num_bits_in_mask = 0;
63700b57cec5SDimitry Andric for (int bit = init_mask->begin(); bit != init_mask->end();
63710b57cec5SDimitry Andric bit = init_mask->next(bit))
63720b57cec5SDimitry Andric num_bits_in_mask++;
63730b57cec5SDimitry Andric exactly_one_group = (num_bits_in_group == num_bits_in_mask);
63740b57cec5SDimitry Andric }
63750b57cec5SDimitry Andric KMP_CPU_FREE(init_mask);
63760b57cec5SDimitry Andric }
63770b57cec5SDimitry Andric
63780b57cec5SDimitry Andric // Handle the Win 64 group affinity stuff if there are multiple
63790b57cec5SDimitry Andric // processor groups, or if the user requested it, and OMP 4.0
63800b57cec5SDimitry Andric // affinity is not in effect.
6381349cc55cSDimitry Andric if (__kmp_num_proc_groups > 1 &&
6382bdd1243dSDimitry Andric __kmp_affinity.type == affinity_default &&
6383349cc55cSDimitry Andric __kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
6384349cc55cSDimitry Andric // Do not respect the initial processor affinity mask if it is assigned
6385349cc55cSDimitry Andric // exactly one Windows Processor Group since this is interpreted as the
6386349cc55cSDimitry Andric // default OS assignment. Not respecting the mask allows the runtime to
6387349cc55cSDimitry Andric // use all the logical processors in all groups.
6388bdd1243dSDimitry Andric if (__kmp_affinity.flags.respect == affinity_respect_mask_default &&
63890b57cec5SDimitry Andric exactly_one_group) {
6390bdd1243dSDimitry Andric __kmp_affinity.flags.respect = FALSE;
63910b57cec5SDimitry Andric }
6392349cc55cSDimitry Andric // Use compact affinity with anticipation of pinning to at least the
6393349cc55cSDimitry Andric // group granularity since threads can only be bound to one group.
6394bdd1243dSDimitry Andric if (__kmp_affinity.type == affinity_default) {
6395bdd1243dSDimitry Andric __kmp_affinity.type = affinity_compact;
63960b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
63970b57cec5SDimitry Andric }
6398bdd1243dSDimitry Andric if (__kmp_hh_affinity.type == affinity_default)
6399bdd1243dSDimitry Andric __kmp_hh_affinity.type = affinity_compact;
6400349cc55cSDimitry Andric if (__kmp_affinity_top_method == affinity_top_method_default)
64010b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_all;
6402bdd1243dSDimitry Andric if (__kmp_affinity.gran == KMP_HW_UNKNOWN)
6403bdd1243dSDimitry Andric __kmp_affinity.gran = KMP_HW_PROC_GROUP;
6404bdd1243dSDimitry Andric if (__kmp_hh_affinity.gran == KMP_HW_UNKNOWN)
6405bdd1243dSDimitry Andric __kmp_hh_affinity.gran = KMP_HW_PROC_GROUP;
64060b57cec5SDimitry Andric } else
64070b57cec5SDimitry Andric
64080b57cec5SDimitry Andric #endif /* KMP_GROUP_AFFINITY */
64090b57cec5SDimitry Andric
64100b57cec5SDimitry Andric {
6411bdd1243dSDimitry Andric if (__kmp_affinity.flags.respect == affinity_respect_mask_default) {
64120b57cec5SDimitry Andric #if KMP_GROUP_AFFINITY
64130b57cec5SDimitry Andric if (__kmp_num_proc_groups > 1 && exactly_one_group) {
6414bdd1243dSDimitry Andric __kmp_affinity.flags.respect = FALSE;
64150b57cec5SDimitry Andric } else
64160b57cec5SDimitry Andric #endif /* KMP_GROUP_AFFINITY */
64170b57cec5SDimitry Andric {
6418bdd1243dSDimitry Andric __kmp_affinity.flags.respect = TRUE;
64190b57cec5SDimitry Andric }
64200b57cec5SDimitry Andric }
64210b57cec5SDimitry Andric if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
64220b57cec5SDimitry Andric (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
642322b3e789SDimitry Andric if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)
642422b3e789SDimitry Andric __kmp_affinity.type = affinity_none;
6425bdd1243dSDimitry Andric if (__kmp_affinity.type == affinity_default) {
6426bdd1243dSDimitry Andric __kmp_affinity.type = affinity_compact;
6427bdd1243dSDimitry Andric __kmp_affinity.flags.dups = FALSE;
64280b57cec5SDimitry Andric }
6429bdd1243dSDimitry Andric } else if (__kmp_affinity.type == affinity_default) {
64300b57cec5SDimitry Andric #if KMP_MIC_SUPPORTED
64310b57cec5SDimitry Andric if (__kmp_mic_type != non_mic) {
64320b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
64330b57cec5SDimitry Andric } else
64340b57cec5SDimitry Andric #endif
64350b57cec5SDimitry Andric {
64360b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
64370b57cec5SDimitry Andric }
64380b57cec5SDimitry Andric #if KMP_MIC_SUPPORTED
64390b57cec5SDimitry Andric if (__kmp_mic_type != non_mic) {
6440bdd1243dSDimitry Andric __kmp_affinity.type = affinity_scatter;
64410b57cec5SDimitry Andric } else
64420b57cec5SDimitry Andric #endif
64430b57cec5SDimitry Andric {
6444bdd1243dSDimitry Andric __kmp_affinity.type = affinity_none;
64450b57cec5SDimitry Andric }
64460b57cec5SDimitry Andric }
6447bdd1243dSDimitry Andric if (__kmp_hh_affinity.type == affinity_default)
6448bdd1243dSDimitry Andric __kmp_hh_affinity.type = affinity_none;
6449bdd1243dSDimitry Andric if ((__kmp_affinity.gran == KMP_HW_UNKNOWN) &&
6450bdd1243dSDimitry Andric (__kmp_affinity.gran_levels < 0)) {
64510b57cec5SDimitry Andric #if KMP_MIC_SUPPORTED
64520b57cec5SDimitry Andric if (__kmp_mic_type != non_mic) {
6453bdd1243dSDimitry Andric __kmp_affinity.gran = KMP_HW_THREAD;
64540b57cec5SDimitry Andric } else
64550b57cec5SDimitry Andric #endif
64560b57cec5SDimitry Andric {
6457bdd1243dSDimitry Andric __kmp_affinity.gran = KMP_HW_CORE;
6458bdd1243dSDimitry Andric }
6459bdd1243dSDimitry Andric }
6460bdd1243dSDimitry Andric if ((__kmp_hh_affinity.gran == KMP_HW_UNKNOWN) &&
6461bdd1243dSDimitry Andric (__kmp_hh_affinity.gran_levels < 0)) {
6462bdd1243dSDimitry Andric #if KMP_MIC_SUPPORTED
6463bdd1243dSDimitry Andric if (__kmp_mic_type != non_mic) {
6464bdd1243dSDimitry Andric __kmp_hh_affinity.gran = KMP_HW_THREAD;
6465bdd1243dSDimitry Andric } else
6466bdd1243dSDimitry Andric #endif
6467bdd1243dSDimitry Andric {
6468bdd1243dSDimitry Andric __kmp_hh_affinity.gran = KMP_HW_CORE;
64690b57cec5SDimitry Andric }
64700b57cec5SDimitry Andric }
64710b57cec5SDimitry Andric if (__kmp_affinity_top_method == affinity_top_method_default) {
64720b57cec5SDimitry Andric __kmp_affinity_top_method = affinity_top_method_all;
64730b57cec5SDimitry Andric }
64740b57cec5SDimitry Andric }
6475bdd1243dSDimitry Andric } else {
6476bdd1243dSDimitry Andric // If affinity is disabled, then still need to assign topology method
6477bdd1243dSDimitry Andric // to attempt machine detection and affinity types
6478bdd1243dSDimitry Andric if (__kmp_affinity_top_method == affinity_top_method_default)
6479bdd1243dSDimitry Andric __kmp_affinity_top_method = affinity_top_method_all;
6480bdd1243dSDimitry Andric if (__kmp_affinity.type == affinity_default)
6481bdd1243dSDimitry Andric __kmp_affinity.type = affinity_disabled;
6482bdd1243dSDimitry Andric if (__kmp_hh_affinity.type == affinity_default)
6483bdd1243dSDimitry Andric __kmp_hh_affinity.type = affinity_disabled;
64840b57cec5SDimitry Andric }
64850b57cec5SDimitry Andric
6486bdd1243dSDimitry Andric #ifdef KMP_DEBUG
6487bdd1243dSDimitry Andric for (const kmp_affinity_t *affinity : __kmp_affinities)
6488bdd1243dSDimitry Andric __kmp_print_affinity_settings(affinity);
64890b57cec5SDimitry Andric KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
64900b57cec5SDimitry Andric K_DIAG(1, ("__kmp_nested_proc_bind.bind_types[0] == %d\n",
64910b57cec5SDimitry Andric __kmp_nested_proc_bind.bind_types[0]));
6492bdd1243dSDimitry Andric #endif
64930b57cec5SDimitry Andric }
64940b57cec5SDimitry Andric
64950b57cec5SDimitry Andric #endif /* KMP_AFFINITY_SUPPORTED */
64960b57cec5SDimitry Andric
64970b57cec5SDimitry Andric // Post-initialization step: some env. vars need their value's further
64980b57cec5SDimitry Andric // processing
64990b57cec5SDimitry Andric if (string != NULL) { // kmp_set_defaults() was called
65000b57cec5SDimitry Andric __kmp_aux_env_initialize(&block);
65010b57cec5SDimitry Andric }
65020b57cec5SDimitry Andric
65030b57cec5SDimitry Andric __kmp_env_blk_free(&block);
65040b57cec5SDimitry Andric
65050b57cec5SDimitry Andric KMP_MB();
65060b57cec5SDimitry Andric
65070b57cec5SDimitry Andric } // __kmp_env_initialize
65080b57cec5SDimitry Andric
__kmp_env_print()65090b57cec5SDimitry Andric void __kmp_env_print() {
65100b57cec5SDimitry Andric
65110b57cec5SDimitry Andric kmp_env_blk_t block;
65120b57cec5SDimitry Andric int i;
65130b57cec5SDimitry Andric kmp_str_buf_t buffer;
65140b57cec5SDimitry Andric
65150b57cec5SDimitry Andric __kmp_stg_init();
65160b57cec5SDimitry Andric __kmp_str_buf_init(&buffer);
65170b57cec5SDimitry Andric
65180b57cec5SDimitry Andric __kmp_env_blk_init(&block, NULL);
65190b57cec5SDimitry Andric __kmp_env_blk_sort(&block);
65200b57cec5SDimitry Andric
65210b57cec5SDimitry Andric // Print real environment values.
65220b57cec5SDimitry Andric __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
65230b57cec5SDimitry Andric for (i = 0; i < block.count; ++i) {
65240b57cec5SDimitry Andric char const *name = block.vars[i].name;
65250b57cec5SDimitry Andric char const *value = block.vars[i].value;
65260b57cec5SDimitry Andric if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
65270b57cec5SDimitry Andric strncmp(name, "OMP_", 4) == 0
65280b57cec5SDimitry Andric #ifdef KMP_GOMP_COMPAT
65290b57cec5SDimitry Andric || strncmp(name, "GOMP_", 5) == 0
65300b57cec5SDimitry Andric #endif // KMP_GOMP_COMPAT
65310b57cec5SDimitry Andric ) {
65320b57cec5SDimitry Andric __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
65330b57cec5SDimitry Andric }
65340b57cec5SDimitry Andric }
65350b57cec5SDimitry Andric __kmp_str_buf_print(&buffer, "\n");
65360b57cec5SDimitry Andric
65370b57cec5SDimitry Andric // Print internal (effective) settings.
65380b57cec5SDimitry Andric __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
65390b57cec5SDimitry Andric for (int i = 0; i < __kmp_stg_count; ++i) {
65400b57cec5SDimitry Andric if (__kmp_stg_table[i].print != NULL) {
65410b57cec5SDimitry Andric __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
65420b57cec5SDimitry Andric __kmp_stg_table[i].data);
65430b57cec5SDimitry Andric }
65440b57cec5SDimitry Andric }
65450b57cec5SDimitry Andric
65460b57cec5SDimitry Andric __kmp_printf("%s", buffer.str);
65470b57cec5SDimitry Andric
65480b57cec5SDimitry Andric __kmp_env_blk_free(&block);
65490b57cec5SDimitry Andric __kmp_str_buf_free(&buffer);
65500b57cec5SDimitry Andric
65510b57cec5SDimitry Andric __kmp_printf("\n");
65520b57cec5SDimitry Andric
65530b57cec5SDimitry Andric } // __kmp_env_print
65540b57cec5SDimitry Andric
__kmp_env_print_2()65550b57cec5SDimitry Andric void __kmp_env_print_2() {
65565ffd83dbSDimitry Andric __kmp_display_env_impl(__kmp_display_env, __kmp_display_env_verbose);
65575ffd83dbSDimitry Andric } // __kmp_env_print_2
65580b57cec5SDimitry Andric
__kmp_display_env_impl(int display_env,int display_env_verbose)65595ffd83dbSDimitry Andric void __kmp_display_env_impl(int display_env, int display_env_verbose) {
65600b57cec5SDimitry Andric kmp_env_blk_t block;
65610b57cec5SDimitry Andric kmp_str_buf_t buffer;
65620b57cec5SDimitry Andric
65630b57cec5SDimitry Andric __kmp_env_format = 1;
65640b57cec5SDimitry Andric
65650b57cec5SDimitry Andric __kmp_stg_init();
65660b57cec5SDimitry Andric __kmp_str_buf_init(&buffer);
65670b57cec5SDimitry Andric
65680b57cec5SDimitry Andric __kmp_env_blk_init(&block, NULL);
65690b57cec5SDimitry Andric __kmp_env_blk_sort(&block);
65700b57cec5SDimitry Andric
65710b57cec5SDimitry Andric __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
65720b57cec5SDimitry Andric __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
65730b57cec5SDimitry Andric
65740b57cec5SDimitry Andric for (int i = 0; i < __kmp_stg_count; ++i) {
65750b57cec5SDimitry Andric if (__kmp_stg_table[i].print != NULL &&
6576fe6060f1SDimitry Andric ((display_env && strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
65775ffd83dbSDimitry Andric display_env_verbose)) {
65780b57cec5SDimitry Andric __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
65790b57cec5SDimitry Andric __kmp_stg_table[i].data);
65800b57cec5SDimitry Andric }
65810b57cec5SDimitry Andric }
65820b57cec5SDimitry Andric
65830b57cec5SDimitry Andric __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
65840b57cec5SDimitry Andric __kmp_str_buf_print(&buffer, "\n");
65850b57cec5SDimitry Andric
65860b57cec5SDimitry Andric __kmp_printf("%s", buffer.str);
65870b57cec5SDimitry Andric
65880b57cec5SDimitry Andric __kmp_env_blk_free(&block);
65890b57cec5SDimitry Andric __kmp_str_buf_free(&buffer);
65900b57cec5SDimitry Andric
65910b57cec5SDimitry Andric __kmp_printf("\n");
65925ffd83dbSDimitry Andric }
65930b57cec5SDimitry Andric
6594fe6060f1SDimitry Andric #if OMPD_SUPPORT
6595fe6060f1SDimitry Andric // Dump environment variables for OMPD
__kmp_env_dump()6596fe6060f1SDimitry Andric void __kmp_env_dump() {
6597fe6060f1SDimitry Andric
6598fe6060f1SDimitry Andric kmp_env_blk_t block;
6599fe6060f1SDimitry Andric kmp_str_buf_t buffer, env, notdefined;
6600fe6060f1SDimitry Andric
6601fe6060f1SDimitry Andric __kmp_stg_init();
6602fe6060f1SDimitry Andric __kmp_str_buf_init(&buffer);
6603fe6060f1SDimitry Andric __kmp_str_buf_init(&env);
6604fe6060f1SDimitry Andric __kmp_str_buf_init(¬defined);
6605fe6060f1SDimitry Andric
6606fe6060f1SDimitry Andric __kmp_env_blk_init(&block, NULL);
6607fe6060f1SDimitry Andric __kmp_env_blk_sort(&block);
6608fe6060f1SDimitry Andric
6609fe6060f1SDimitry Andric __kmp_str_buf_print(¬defined, ": %s", KMP_I18N_STR(NotDefined));
6610fe6060f1SDimitry Andric
6611fe6060f1SDimitry Andric for (int i = 0; i < __kmp_stg_count; ++i) {
6612fe6060f1SDimitry Andric if (__kmp_stg_table[i].print == NULL)
6613fe6060f1SDimitry Andric continue;
6614fe6060f1SDimitry Andric __kmp_str_buf_clear(&env);
6615fe6060f1SDimitry Andric __kmp_stg_table[i].print(&env, __kmp_stg_table[i].name,
6616fe6060f1SDimitry Andric __kmp_stg_table[i].data);
6617fe6060f1SDimitry Andric if (env.used < 4) // valid definition must have indents (3) and a new line
6618fe6060f1SDimitry Andric continue;
6619fe6060f1SDimitry Andric if (strstr(env.str, notdefined.str))
6620fe6060f1SDimitry Andric // normalize the string
6621fe6060f1SDimitry Andric __kmp_str_buf_print(&buffer, "%s=undefined\n", __kmp_stg_table[i].name);
6622fe6060f1SDimitry Andric else
6623fe6060f1SDimitry Andric __kmp_str_buf_cat(&buffer, env.str + 3, env.used - 3);
6624fe6060f1SDimitry Andric }
6625fe6060f1SDimitry Andric
6626fe6060f1SDimitry Andric ompd_env_block = (char *)__kmp_allocate(buffer.used + 1);
6627fe6060f1SDimitry Andric KMP_MEMCPY(ompd_env_block, buffer.str, buffer.used + 1);
6628fe6060f1SDimitry Andric ompd_env_block_size = (ompd_size_t)KMP_STRLEN(ompd_env_block);
6629fe6060f1SDimitry Andric
6630fe6060f1SDimitry Andric __kmp_env_blk_free(&block);
6631fe6060f1SDimitry Andric __kmp_str_buf_free(&buffer);
6632fe6060f1SDimitry Andric __kmp_str_buf_free(&env);
6633fe6060f1SDimitry Andric __kmp_str_buf_free(¬defined);
6634fe6060f1SDimitry Andric }
6635fe6060f1SDimitry Andric #endif // OMPD_SUPPORT
6636fe6060f1SDimitry Andric
66370b57cec5SDimitry Andric // end of file
6638