blob: 00d9ba51eb4127a2a5cb629bbf343e35c800e183 [file] [log] [blame]
Jim Cownie5e8470a2013-09-27 10:38:44 +00001/*
Jonathan Peytonde4749b2016-12-14 23:01:24 +00002 * kmp_settings.cpp -- Initialize environment variables
Jim Cownie5e8470a2013-09-27 10:38:44 +00003 */
4
5
6//===----------------------------------------------------------------------===//
7//
8// The LLVM Compiler Infrastructure
9//
10// This file is dual licensed under the MIT and the University of Illinois Open
11// Source Licenses. See LICENSE.txt for details.
12//
13//===----------------------------------------------------------------------===//
14
15
16#include "kmp.h"
Jonathan Peyton1cdd87a2016-11-14 21:08:35 +000017#include "kmp_affinity.h"
Jonathan Peyton30419822017-05-12 18:01:32 +000018#include "kmp_atomic.h"
19#include "kmp_environment.h"
20#include "kmp_i18n.h"
21#include "kmp_io.h"
22#include "kmp_itt.h"
23#include "kmp_lock.h"
24#include "kmp_settings.h"
25#include "kmp_str.h"
26#include "kmp_wrapper_getpid.h"
Andrey Churbanov4a9a8922017-04-13 17:15:07 +000027#include <ctype.h> // toupper()
Jim Cownie5e8470a2013-09-27 10:38:44 +000028
Jonathan Peyton30419822017-05-12 18:01:32 +000029static int __kmp_env_toPrint(char const *name, int flag);
Jim Cownie5e8470a2013-09-27 10:38:44 +000030
31bool __kmp_env_format = 0; // 0 - old format; 1 - new format
Jonathan Peyton30419822017-05-12 18:01:32 +000032
33// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +000034// Helper string functions. Subject to move to kmp_str.
Jim Cownie5e8470a2013-09-27 10:38:44 +000035
Jonathan Peyton30419822017-05-12 18:01:32 +000036static double __kmp_convert_to_double(char const *s) {
37 double result;
Jim Cownie5e8470a2013-09-27 10:38:44 +000038
Jonathan Peyton30419822017-05-12 18:01:32 +000039 if (KMP_SSCANF(s, "%lf", &result) < 1) {
40 result = 0.0;
41 }
Jim Cownie5e8470a2013-09-27 10:38:44 +000042
Jonathan Peyton30419822017-05-12 18:01:32 +000043 return result;
Jim Cownie5e8470a2013-09-27 10:38:44 +000044}
45
Jonathan Peyton2321d572015-06-08 19:25:25 +000046#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +000047static unsigned int __kmp_readstr_with_sentinel(char *dest, char const *src,
48 size_t len, char sentinel) {
49 unsigned int i;
50 for (i = 0; i < len; i++) {
51 if ((*src == '\0') || (*src == sentinel)) {
52 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +000053 }
Jonathan Peyton30419822017-05-12 18:01:32 +000054 *(dest++) = *(src++);
55 }
56 *dest = '\0';
57 return i;
Jim Cownie5e8470a2013-09-27 10:38:44 +000058}
Jonathan Peyton2321d572015-06-08 19:25:25 +000059#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +000060
Jonathan Peyton30419822017-05-12 18:01:32 +000061static int __kmp_match_with_sentinel(char const *a, char const *b, size_t len,
62 char sentinel) {
63 size_t l = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +000064
Jonathan Peyton30419822017-05-12 18:01:32 +000065 if (a == NULL)
66 a = "";
67 if (b == NULL)
68 b = "";
69 while (*a && *b && *b != sentinel) {
70 char ca = *a, cb = *b;
Jim Cownie5e8470a2013-09-27 10:38:44 +000071
Jonathan Peyton30419822017-05-12 18:01:32 +000072 if (ca >= 'a' && ca <= 'z')
73 ca -= 'a' - 'A';
74 if (cb >= 'a' && cb <= 'z')
75 cb -= 'a' - 'A';
76 if (ca != cb)
77 return FALSE;
78 ++l;
79 ++a;
80 ++b;
81 }
82 return l >= len;
Jim Cownie5e8470a2013-09-27 10:38:44 +000083}
84
Jim Cownie5e8470a2013-09-27 10:38:44 +000085// Expected usage:
86// token is the token to check for.
87// buf is the string being parsed.
88// *end returns the char after the end of the token.
89// it is not modified unless a match occurs.
90//
Jim Cownie5e8470a2013-09-27 10:38:44 +000091// Example 1:
92//
93// if (__kmp_match_str("token", buf, *end) {
94// <do something>
95// buf = end;
96// }
97//
98// Example 2:
99//
100// if (__kmp_match_str("token", buf, *end) {
101// char *save = **end;
102// **end = sentinel;
103// <use any of the __kmp*_with_sentinel() functions>
104// **end = save;
105// buf = end;
106// }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000107
Jonathan Peyton30419822017-05-12 18:01:32 +0000108static int __kmp_match_str(char const *token, char const *buf,
109 const char **end) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000110
Jonathan Peyton30419822017-05-12 18:01:32 +0000111 KMP_ASSERT(token != NULL);
112 KMP_ASSERT(buf != NULL);
113 KMP_ASSERT(end != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000114
Jonathan Peyton30419822017-05-12 18:01:32 +0000115 while (*token && *buf) {
116 char ct = *token, cb = *buf;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000117
Jonathan Peyton30419822017-05-12 18:01:32 +0000118 if (ct >= 'a' && ct <= 'z')
119 ct -= 'a' - 'A';
120 if (cb >= 'a' && cb <= 'z')
121 cb -= 'a' - 'A';
122 if (ct != cb)
123 return FALSE;
124 ++token;
125 ++buf;
126 }
127 if (*token) {
128 return FALSE;
129 }
130 *end = buf;
131 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000132}
133
Jonathan Peyton30419822017-05-12 18:01:32 +0000134static size_t __kmp_round4k(size_t size) {
135 size_t _4k = 4 * 1024;
136 if (size & (_4k - 1)) {
137 size &= ~(_4k - 1);
138 if (size <= KMP_SIZE_T_MAX - _4k) {
139 size += _4k; // Round up if there is no overflow.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000140 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000141 }; // if
142 return size;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000143} // __kmp_round4k
144
Jonathan Peyton30419822017-05-12 18:01:32 +0000145/* Here, multipliers are like __kmp_convert_to_seconds, but floating-point
146 values are allowed, and the return value is in milliseconds. The default
147 multiplier is milliseconds. Returns INT_MAX only if the value specified
148 matches "infinit*". Returns -1 if specified string is invalid. */
149int __kmp_convert_to_milliseconds(char const *data) {
150 int ret, nvalues, factor;
151 char mult, extra;
152 double value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000153
Jonathan Peyton30419822017-05-12 18:01:32 +0000154 if (data == NULL)
155 return (-1);
156 if (__kmp_str_match("infinit", -1, data))
157 return (INT_MAX);
158 value = (double)0.0;
159 mult = '\0';
160 nvalues = KMP_SSCANF(data, "%lf%c%c", &value, &mult, &extra);
161 if (nvalues < 1)
162 return (-1);
163 if (nvalues == 1)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000164 mult = '\0';
Jonathan Peyton30419822017-05-12 18:01:32 +0000165 if (nvalues == 3)
166 return (-1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000167
Jonathan Peyton30419822017-05-12 18:01:32 +0000168 if (value < 0)
169 return (-1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000170
Jonathan Peyton30419822017-05-12 18:01:32 +0000171 switch (mult) {
172 case '\0':
173 /* default is milliseconds */
174 factor = 1;
175 break;
176 case 's':
177 case 'S':
178 factor = 1000;
179 break;
180 case 'm':
181 case 'M':
182 factor = 1000 * 60;
183 break;
184 case 'h':
185 case 'H':
186 factor = 1000 * 60 * 60;
187 break;
188 case 'd':
189 case 'D':
190 factor = 1000 * 24 * 60 * 60;
191 break;
192 default:
193 return (-1);
194 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000195
Jonathan Peyton30419822017-05-12 18:01:32 +0000196 if (value >= ((INT_MAX - 1) / factor))
197 ret = INT_MAX - 1; /* Don't allow infinite value here */
198 else
199 ret = (int)(value * (double)factor); /* truncate to int */
Jim Cownie5e8470a2013-09-27 10:38:44 +0000200
Jonathan Peyton30419822017-05-12 18:01:32 +0000201 return ret;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000202}
203
Jonathan Peyton30419822017-05-12 18:01:32 +0000204static int __kmp_strcasecmp_with_sentinel(char const *a, char const *b,
205 char sentinel) {
206 if (a == NULL)
207 a = "";
208 if (b == NULL)
209 b = "";
210 while (*a && *b && *b != sentinel) {
211 char ca = *a, cb = *b;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000212
Jonathan Peyton30419822017-05-12 18:01:32 +0000213 if (ca >= 'a' && ca <= 'z')
214 ca -= 'a' - 'A';
215 if (cb >= 'a' && cb <= 'z')
216 cb -= 'a' - 'A';
217 if (ca != cb)
218 return (int)(unsigned char)*a - (int)(unsigned char)*b;
219 ++a;
220 ++b;
221 }
222 return *a
223 ? (*b && *b != sentinel)
224 ? (int)(unsigned char)*a - (int)(unsigned char)*b
225 : 1
226 : (*b && *b != sentinel) ? -1 : 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000227}
228
Jonathan Peyton30419822017-05-12 18:01:32 +0000229// =============================================================================
Jim Cownie5e8470a2013-09-27 10:38:44 +0000230// Table structures and helper functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000231
Jonathan Peyton30419822017-05-12 18:01:32 +0000232typedef struct __kmp_setting kmp_setting_t;
233typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
234typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
235typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000236
Jonathan Peyton30419822017-05-12 18:01:32 +0000237typedef void (*kmp_stg_parse_func_t)(char const *name, char const *value,
238 void *data);
239typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer, char const *name,
240 void *data);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000241
242struct __kmp_setting {
Jonathan Peyton30419822017-05-12 18:01:32 +0000243 char const *name; // Name of setting (environment variable).
244 kmp_stg_parse_func_t parse; // Parser function.
245 kmp_stg_print_func_t print; // Print function.
246 void *data; // Data passed to parser and printer.
247 int set; // Variable set during this "session"
248 // (__kmp_env_initialize() or kmp_set_defaults() call).
249 int defined; // Variable set in any "session".
Jim Cownie5e8470a2013-09-27 10:38:44 +0000250}; // struct __kmp_setting
251
252struct __kmp_stg_ss_data {
Jonathan Peyton30419822017-05-12 18:01:32 +0000253 size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
254 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
Jim Cownie5e8470a2013-09-27 10:38:44 +0000255}; // struct __kmp_stg_ss_data
256
257struct __kmp_stg_wp_data {
Jonathan Peyton30419822017-05-12 18:01:32 +0000258 int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
259 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
Jim Cownie5e8470a2013-09-27 10:38:44 +0000260}; // struct __kmp_stg_wp_data
261
262struct __kmp_stg_fr_data {
Jonathan Peyton30419822017-05-12 18:01:32 +0000263 int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
264 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
Jim Cownie5e8470a2013-09-27 10:38:44 +0000265}; // struct __kmp_stg_fr_data
266
Jonathan Peyton30419822017-05-12 18:01:32 +0000267static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
268 char const *name, // Name of variable.
269 char const *value, // Value of the variable.
270 kmp_setting_t **rivals // List of rival settings (must include current one).
271 );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000272
Jonathan Peyton30419822017-05-12 18:01:32 +0000273// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000274// Helper parse functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000275
Jonathan Peyton30419822017-05-12 18:01:32 +0000276static void __kmp_stg_parse_bool(char const *name, char const *value,
277 int *out) {
278 if (__kmp_str_match_true(value)) {
279 *out = TRUE;
280 } else if (__kmp_str_match_false(value)) {
281 *out = FALSE;
282 } else {
283 __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
284 KMP_HNT(ValidBoolValues), __kmp_msg_null);
285 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +0000286} // __kmp_stg_parse_bool
287
Jonathan Peyton30419822017-05-12 18:01:32 +0000288static void __kmp_stg_parse_size(char const *name, char const *value,
289 size_t size_min, size_t size_max,
290 int *is_specified, size_t *out,
291 size_t factor) {
292 char const *msg = NULL;
293#if KMP_OS_DARWIN
294 size_min = __kmp_round4k(size_min);
295 size_max = __kmp_round4k(size_max);
296#endif // KMP_OS_DARWIN
297 if (value) {
298 if (is_specified != NULL) {
299 *is_specified = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000300 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000301 __kmp_str_to_size(value, out, factor, &msg);
302 if (msg == NULL) {
303 if (*out > size_max) {
304 *out = size_max;
305 msg = KMP_I18N_STR(ValueTooLarge);
306 } else if (*out < size_min) {
307 *out = size_min;
308 msg = KMP_I18N_STR(ValueTooSmall);
309 } else {
310#if KMP_OS_DARWIN
311 size_t round4k = __kmp_round4k(*out);
312 if (*out != round4k) {
313 *out = round4k;
314 msg = KMP_I18N_STR(NotMultiple4K);
315 }; // if
316#endif
317 }; // if
318 } else {
319 // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to
320 // size_max silently.
321 if (*out < size_min) {
322 *out = size_max;
323 } else if (*out > size_max) {
324 *out = size_max;
325 }; // if
326 }; // if
327 if (msg != NULL) {
328 // Message is not empty. Print warning.
329 kmp_str_buf_t buf;
330 __kmp_str_buf_init(&buf);
331 __kmp_str_buf_print_size(&buf, *out);
332 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
333 KMP_INFORM(Using_str_Value, name, buf.str);
334 __kmp_str_buf_free(&buf);
335 }; // if
336 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +0000337} // __kmp_stg_parse_size
338
Jonathan Peyton2321d572015-06-08 19:25:25 +0000339#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +0000340static void __kmp_stg_parse_str(char const *name, char const *value,
341 char const **out) {
342 __kmp_str_free(out);
343 *out = __kmp_str_format("%s", value);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000344} // __kmp_stg_parse_str
Jonathan Peyton2321d572015-06-08 19:25:25 +0000345#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000346
Jonathan Peyton30419822017-05-12 18:01:32 +0000347static void __kmp_stg_parse_int(
348 char const
349 *name, // I: Name of environment variable (used in warning messages).
350 char const *value, // I: Value of environment variable to parse.
351 int min, // I: Miminal allowed value.
352 int max, // I: Maximum allowed value.
353 int *out // O: Output (parsed) value.
354 ) {
355 char const *msg = NULL;
356 kmp_uint64 uint = *out;
357 __kmp_str_to_uint(value, &uint, &msg);
358 if (msg == NULL) {
359 if (uint < (unsigned int)min) {
360 msg = KMP_I18N_STR(ValueTooSmall);
361 uint = min;
362 } else if (uint > (unsigned int)max) {
363 msg = KMP_I18N_STR(ValueTooLarge);
364 uint = max;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000365 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000366 } else {
367 // If overflow occurred msg contains error message and uint is very big. Cut
368 // tmp it to INT_MAX.
369 if (uint < (unsigned int)min) {
370 uint = min;
371 } else if (uint > (unsigned int)max) {
372 uint = max;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000373 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000374 }; // if
375 if (msg != NULL) {
376 // Message is not empty. Print warning.
377 kmp_str_buf_t buf;
378 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
379 __kmp_str_buf_init(&buf);
380 __kmp_str_buf_print(&buf, "%" KMP_UINT64_SPEC "", uint);
381 KMP_INFORM(Using_uint64_Value, name, buf.str);
382 __kmp_str_buf_free(&buf);
383 }; // if
384 *out = uint;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000385} // __kmp_stg_parse_int
386
Jonathan Peyton2321d572015-06-08 19:25:25 +0000387#if KMP_DEBUG_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +0000388static void __kmp_stg_parse_file(char const *name, char const *value,
389 char *suffix, char **out) {
390 char buffer[256];
391 char *t;
392 int hasSuffix;
393 __kmp_str_free(out);
394 t = (char *)strrchr(value, '.');
395 hasSuffix = t && __kmp_str_eqf(t, suffix);
396 t = __kmp_str_format("%s%s", value, hasSuffix ? "" : suffix);
397 __kmp_expand_file_name(buffer, sizeof(buffer), t);
398 __kmp_str_free(&t);
399 *out = __kmp_str_format("%s", buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000400} // __kmp_stg_parse_file
Jonathan Peyton2321d572015-06-08 19:25:25 +0000401#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000402
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000403#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000404static char *par_range_to_print = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000405
Jonathan Peyton30419822017-05-12 18:01:32 +0000406static void __kmp_stg_parse_par_range(char const *name, char const *value,
407 int *out_range, char *out_routine,
408 char *out_file, int *out_lb,
409 int *out_ub) {
410 size_t len = KMP_STRLEN(value + 1);
411 par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
412 KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
413 __kmp_par_range = +1;
414 __kmp_par_range_lb = 0;
415 __kmp_par_range_ub = INT_MAX;
416 for (;;) {
417 unsigned int len;
418 if ((value == NULL) || (*value == '\0')) {
419 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000420 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000421 if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
422 value = strchr(value, '=') + 1;
423 len = __kmp_readstr_with_sentinel(out_routine, value,
424 KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
425 if (len == 0) {
426 goto par_range_error;
427 }
428 value = strchr(value, ',');
429 if (value != NULL) {
430 value++;
431 }
432 continue;
433 }
434 if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
435 value = strchr(value, '=') + 1;
436 len = __kmp_readstr_with_sentinel(out_file, value,
437 KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
438 if (len == 0) {
439 goto par_range_error;
440 }
441 value = strchr(value, ',');
442 if (value != NULL) {
443 value++;
444 }
445 continue;
446 }
447 if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
448 (!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
449 value = strchr(value, '=') + 1;
450 if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
451 goto par_range_error;
452 }
453 *out_range = +1;
454 value = strchr(value, ',');
455 if (value != NULL) {
456 value++;
457 }
458 continue;
459 }
460 if (!__kmp_strcasecmp_with_sentinel("excl_range", value, '=')) {
461 value = strchr(value, '=') + 1;
462 if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
463 goto par_range_error;
464 }
465 *out_range = -1;
466 value = strchr(value, ',');
467 if (value != NULL) {
468 value++;
469 }
470 continue;
471 }
472 par_range_error:
473 KMP_WARNING(ParRangeSyntax, name);
474 __kmp_par_range = 0;
475 break;
476 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000477} // __kmp_stg_parse_par_range
Jim Cownie3051f972014-08-07 10:12:54 +0000478#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000479
Jonathan Peyton30419822017-05-12 18:01:32 +0000480int __kmp_initial_threads_capacity(int req_nproc) {
481 int nth = 32;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000482
Jonathan Peyton30419822017-05-12 18:01:32 +0000483 /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
484 * __kmp_max_nth) */
485 if (nth < (4 * req_nproc))
486 nth = (4 * req_nproc);
487 if (nth < (4 * __kmp_xproc))
488 nth = (4 * __kmp_xproc);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000489
Jonathan Peyton30419822017-05-12 18:01:32 +0000490 if (nth > __kmp_max_nth)
491 nth = __kmp_max_nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000492
Jonathan Peyton30419822017-05-12 18:01:32 +0000493 return nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000494}
495
Jonathan Peyton30419822017-05-12 18:01:32 +0000496int __kmp_default_tp_capacity(int req_nproc, int max_nth,
497 int all_threads_specified) {
498 int nth = 128;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000499
Jonathan Peyton30419822017-05-12 18:01:32 +0000500 if (all_threads_specified)
501 return max_nth;
502 /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
503 * __kmp_max_nth ) */
504 if (nth < (4 * req_nproc))
505 nth = (4 * req_nproc);
506 if (nth < (4 * __kmp_xproc))
507 nth = (4 * __kmp_xproc);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000508
Jonathan Peyton30419822017-05-12 18:01:32 +0000509 if (nth > __kmp_max_nth)
510 nth = __kmp_max_nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000511
Jonathan Peyton30419822017-05-12 18:01:32 +0000512 return nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000513}
514
Jonathan Peyton30419822017-05-12 18:01:32 +0000515// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000516// Helper print functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000517
Jonathan Peyton30419822017-05-12 18:01:32 +0000518static void __kmp_stg_print_bool(kmp_str_buf_t *buffer, char const *name,
519 int value) {
520 if (__kmp_env_format) {
521 KMP_STR_BUF_PRINT_BOOL;
522 } else {
523 __kmp_str_buf_print(buffer, " %s=%s\n", name, value ? "true" : "false");
524 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000525} // __kmp_stg_print_bool
526
Jonathan Peyton30419822017-05-12 18:01:32 +0000527static void __kmp_stg_print_int(kmp_str_buf_t *buffer, char const *name,
528 int value) {
529 if (__kmp_env_format) {
530 KMP_STR_BUF_PRINT_INT;
531 } else {
532 __kmp_str_buf_print(buffer, " %s=%d\n", name, value);
533 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000534} // __kmp_stg_print_int
535
Jonathan Peyton30419822017-05-12 18:01:32 +0000536static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer, char const *name,
537 kmp_uint64 value) {
538 if (__kmp_env_format) {
539 KMP_STR_BUF_PRINT_UINT64;
540 } else {
541 __kmp_str_buf_print(buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value);
542 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000543} // __kmp_stg_print_uint64
544
Jonathan Peyton30419822017-05-12 18:01:32 +0000545static void __kmp_stg_print_str(kmp_str_buf_t *buffer, char const *name,
546 char const *value) {
547 if (__kmp_env_format) {
548 KMP_STR_BUF_PRINT_STR;
549 } else {
550 __kmp_str_buf_print(buffer, " %s=%s\n", name, value);
551 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000552} // __kmp_stg_print_str
553
Jonathan Peyton30419822017-05-12 18:01:32 +0000554static void __kmp_stg_print_size(kmp_str_buf_t *buffer, char const *name,
555 size_t value) {
556 if (__kmp_env_format) {
557 KMP_STR_BUF_PRINT_NAME_EX(name);
558 __kmp_str_buf_print_size(buffer, value);
559 __kmp_str_buf_print(buffer, "'\n");
560 } else {
561 __kmp_str_buf_print(buffer, " %s=", name);
562 __kmp_str_buf_print_size(buffer, value);
563 __kmp_str_buf_print(buffer, "\n");
564 return;
565 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000566} // __kmp_stg_print_size
567
Jonathan Peyton30419822017-05-12 18:01:32 +0000568// =============================================================================
Jim Cownie5e8470a2013-09-27 10:38:44 +0000569// Parse and print functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000570
Jonathan Peyton30419822017-05-12 18:01:32 +0000571// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000572// KMP_ALL_THREADS, KMP_MAX_THREADS, OMP_THREAD_LIMIT
Jim Cownie5e8470a2013-09-27 10:38:44 +0000573
Jonathan Peyton30419822017-05-12 18:01:32 +0000574static void __kmp_stg_parse_all_threads(char const *name, char const *value,
575 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000576
Jonathan Peyton30419822017-05-12 18:01:32 +0000577 kmp_setting_t **rivals = (kmp_setting_t **)data;
578 int rc;
579 rc = __kmp_stg_check_rivals(name, value, rivals);
580 if (rc) {
581 return;
582 }; // if
583 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
584 __kmp_max_nth = __kmp_xproc;
585 __kmp_allThreadsSpecified = 1;
586 } else {
587 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
588 __kmp_allThreadsSpecified = 0;
589 }
590 K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000591
592} // __kmp_stg_parse_all_threads
593
Jonathan Peyton30419822017-05-12 18:01:32 +0000594static void __kmp_stg_print_all_threads(kmp_str_buf_t *buffer, char const *name,
595 void *data) {
596 __kmp_stg_print_int(buffer, name, __kmp_max_nth);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000597} // __kmp_stg_print_all_threads
598
Jonathan Peyton30419822017-05-12 18:01:32 +0000599// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000600// KMP_BLOCKTIME
Jim Cownie5e8470a2013-09-27 10:38:44 +0000601
Jonathan Peyton30419822017-05-12 18:01:32 +0000602static void __kmp_stg_parse_blocktime(char const *name, char const *value,
603 void *data) {
604 __kmp_dflt_blocktime = __kmp_convert_to_milliseconds(value);
605 if (__kmp_dflt_blocktime < 0) {
606 __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
607 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
608 __kmp_msg_null);
609 KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime);
610 __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
611 } else {
612 if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
613 __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
614 __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
615 __kmp_msg_null);
616 KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime);
617 } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
618 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
619 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
620 __kmp_msg_null);
621 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000622 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000623 __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
624 }; // if
Jonathan Peytone1c7c132016-10-07 18:12:19 +0000625#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +0000626 // calculate number of monitor thread wakeup intervals corresponding to
627 // blocktime.
628 __kmp_monitor_wakeups =
629 KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
630 __kmp_bt_intervals =
631 KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
Jonathan Peytone1c7c132016-10-07 18:12:19 +0000632#endif
Jonathan Peyton30419822017-05-12 18:01:32 +0000633 K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
634 if (__kmp_env_blocktime) {
635 K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
636 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000637} // __kmp_stg_parse_blocktime
638
Jonathan Peyton30419822017-05-12 18:01:32 +0000639static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
640 void *data) {
641 __kmp_stg_print_int(buffer, name, __kmp_dflt_blocktime);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000642} // __kmp_stg_print_blocktime
643
Jonathan Peyton30419822017-05-12 18:01:32 +0000644// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000645// KMP_DUPLICATE_LIB_OK
Jim Cownie5e8470a2013-09-27 10:38:44 +0000646
Jonathan Peyton30419822017-05-12 18:01:32 +0000647static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
648 char const *value, void *data) {
649 /* actually this variable is not supported, put here for compatibility with
650 earlier builds and for static/dynamic combination */
651 __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000652} // __kmp_stg_parse_duplicate_lib_ok
653
Jonathan Peyton30419822017-05-12 18:01:32 +0000654static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
655 char const *name, void *data) {
656 __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000657} // __kmp_stg_print_duplicate_lib_ok
658
Jonathan Peyton30419822017-05-12 18:01:32 +0000659// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000660// KMP_INHERIT_FP_CONTROL
Jim Cownie5e8470a2013-09-27 10:38:44 +0000661
662#if KMP_ARCH_X86 || KMP_ARCH_X86_64
663
Jonathan Peyton30419822017-05-12 18:01:32 +0000664static void __kmp_stg_parse_inherit_fp_control(char const *name,
665 char const *value, void *data) {
666 __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000667} // __kmp_stg_parse_inherit_fp_control
668
Jonathan Peyton30419822017-05-12 18:01:32 +0000669static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
670 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000671#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000672 __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000673#endif /* KMP_DEBUG */
674} // __kmp_stg_print_inherit_fp_control
675
676#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
677
Jonathan Peyton30419822017-05-12 18:01:32 +0000678// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000679// KMP_LIBRARY, OMP_WAIT_POLICY
Jim Cownie5e8470a2013-09-27 10:38:44 +0000680
Jonathan Peyton50e8f182016-04-04 19:38:32 +0000681static char const *blocktime_str = NULL;
682
Jonathan Peyton30419822017-05-12 18:01:32 +0000683static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
684 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000685
Jonathan Peyton30419822017-05-12 18:01:32 +0000686 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
687 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000688
Jonathan Peyton30419822017-05-12 18:01:32 +0000689 rc = __kmp_stg_check_rivals(name, value, wait->rivals);
690 if (rc) {
691 return;
692 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +0000693
Jonathan Peyton30419822017-05-12 18:01:32 +0000694 if (wait->omp) {
695 if (__kmp_str_match("ACTIVE", 1, value)) {
696 __kmp_library = library_turnaround;
697 if (blocktime_str == NULL) {
698 // KMP_BLOCKTIME not specified, so set default to "infinite".
699 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
700 }
701 } else if (__kmp_str_match("PASSIVE", 1, value)) {
702 __kmp_library = library_throughput;
703 if (blocktime_str == NULL) {
704 // KMP_BLOCKTIME not specified, so set default to 0.
705 __kmp_dflt_blocktime = 0;
706 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000707 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +0000708 KMP_WARNING(StgInvalidValue, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000709 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000710 } else {
711 if (__kmp_str_match("serial", 1, value)) { /* S */
712 __kmp_library = library_serial;
713 } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
714 __kmp_library = library_throughput;
715 } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
716 __kmp_library = library_turnaround;
717 } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
718 __kmp_library = library_turnaround;
719 } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
720 __kmp_library = library_throughput;
721 } else {
722 KMP_WARNING(StgInvalidValue, name, value);
723 }; // if
724 }; // if
725 __kmp_aux_set_library(__kmp_library);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000726
727} // __kmp_stg_parse_wait_policy
728
Jonathan Peyton30419822017-05-12 18:01:32 +0000729static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
730 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000731
Jonathan Peyton30419822017-05-12 18:01:32 +0000732 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
733 char const *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000734
Jonathan Peyton30419822017-05-12 18:01:32 +0000735 if (wait->omp) {
736 switch (__kmp_library) {
737 case library_turnaround: {
738 value = "ACTIVE";
739 } break;
740 case library_throughput: {
741 value = "PASSIVE";
742 } break;
743 }; // switch
744 } else {
745 switch (__kmp_library) {
746 case library_serial: {
747 value = "serial";
748 } break;
749 case library_turnaround: {
750 value = "turnaround";
751 } break;
752 case library_throughput: {
753 value = "throughput";
754 } break;
755 }; // switch
756 }; // if
757 if (value != NULL) {
758 __kmp_stg_print_str(buffer, name, value);
759 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +0000760
761} // __kmp_stg_print_wait_policy
762
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000763#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +0000764// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000765// KMP_MONITOR_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000766
Jonathan Peyton30419822017-05-12 18:01:32 +0000767static void __kmp_stg_parse_monitor_stacksize(char const *name,
768 char const *value, void *data) {
769 __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
770 NULL, &__kmp_monitor_stksize, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000771} // __kmp_stg_parse_monitor_stacksize
772
Jonathan Peyton30419822017-05-12 18:01:32 +0000773static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
774 char const *name, void *data) {
775 if (__kmp_env_format) {
776 if (__kmp_monitor_stksize > 0)
777 KMP_STR_BUF_PRINT_NAME_EX(name);
778 else
779 KMP_STR_BUF_PRINT_NAME;
780 } else {
781 __kmp_str_buf_print(buffer, " %s", name);
782 }
783 if (__kmp_monitor_stksize > 0) {
784 __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
785 } else {
786 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
787 }
788 if (__kmp_env_format && __kmp_monitor_stksize) {
789 __kmp_str_buf_print(buffer, "'\n");
790 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000791} // __kmp_stg_print_monitor_stacksize
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000792#endif // KMP_USE_MONITOR
Jim Cownie5e8470a2013-09-27 10:38:44 +0000793
Jonathan Peyton30419822017-05-12 18:01:32 +0000794// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000795// KMP_SETTINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000796
Jonathan Peyton30419822017-05-12 18:01:32 +0000797static void __kmp_stg_parse_settings(char const *name, char const *value,
798 void *data) {
799 __kmp_stg_parse_bool(name, value, &__kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000800} // __kmp_stg_parse_settings
801
Jonathan Peyton30419822017-05-12 18:01:32 +0000802static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
803 void *data) {
804 __kmp_stg_print_bool(buffer, name, __kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000805} // __kmp_stg_print_settings
806
Jonathan Peyton30419822017-05-12 18:01:32 +0000807// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000808// KMP_STACKPAD
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000809
Jonathan Peyton30419822017-05-12 18:01:32 +0000810static void __kmp_stg_parse_stackpad(char const *name, char const *value,
811 void *data) {
812 __kmp_stg_parse_int(name, // Env var name
813 value, // Env var value
814 KMP_MIN_STKPADDING, // Min value
815 KMP_MAX_STKPADDING, // Max value
816 &__kmp_stkpadding // Var to initialize
817 );
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000818} // __kmp_stg_parse_stackpad
819
Jonathan Peyton30419822017-05-12 18:01:32 +0000820static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
821 void *data) {
822 __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000823} // __kmp_stg_print_stackpad
824
Jonathan Peyton30419822017-05-12 18:01:32 +0000825// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000826// KMP_STACKOFFSET
Jim Cownie5e8470a2013-09-27 10:38:44 +0000827
Jonathan Peyton30419822017-05-12 18:01:32 +0000828static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
829 void *data) {
830 __kmp_stg_parse_size(name, // Env var name
831 value, // Env var value
832 KMP_MIN_STKOFFSET, // Min value
833 KMP_MAX_STKOFFSET, // Max value
834 NULL, //
835 &__kmp_stkoffset, // Var to initialize
836 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000837} // __kmp_stg_parse_stackoffset
838
Jonathan Peyton30419822017-05-12 18:01:32 +0000839static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
840 void *data) {
841 __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000842} // __kmp_stg_print_stackoffset
843
Jonathan Peyton30419822017-05-12 18:01:32 +0000844// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000845// KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000846
Jonathan Peyton30419822017-05-12 18:01:32 +0000847static void __kmp_stg_parse_stacksize(char const *name, char const *value,
848 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000849
Jonathan Peyton30419822017-05-12 18:01:32 +0000850 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
851 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000852
Jonathan Peyton30419822017-05-12 18:01:32 +0000853 rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
854 if (rc) {
855 return;
856 }; // if
857 __kmp_stg_parse_size(name, // Env var name
858 value, // Env var value
859 __kmp_sys_min_stksize, // Min value
860 KMP_MAX_STKSIZE, // Max value
861 &__kmp_env_stksize, //
862 &__kmp_stksize, // Var to initialize
863 stacksize->factor);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000864
865} // __kmp_stg_parse_stacksize
866
Jonathan Peyton30419822017-05-12 18:01:32 +0000867// This function is called for printing both KMP_STACKSIZE (factor is 1) and
868// OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
869// OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
870// customer request in future.
871static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
872 void *data) {
873 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
874 if (__kmp_env_format) {
875 KMP_STR_BUF_PRINT_NAME_EX(name);
876 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
877 ? __kmp_stksize / stacksize->factor
878 : __kmp_stksize);
879 __kmp_str_buf_print(buffer, "'\n");
880 } else {
881 __kmp_str_buf_print(buffer, " %s=", name);
882 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
883 ? __kmp_stksize / stacksize->factor
884 : __kmp_stksize);
885 __kmp_str_buf_print(buffer, "\n");
886 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000887} // __kmp_stg_print_stacksize
888
Jonathan Peyton30419822017-05-12 18:01:32 +0000889// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000890// KMP_VERSION
Jim Cownie5e8470a2013-09-27 10:38:44 +0000891
Jonathan Peyton30419822017-05-12 18:01:32 +0000892static void __kmp_stg_parse_version(char const *name, char const *value,
893 void *data) {
894 __kmp_stg_parse_bool(name, value, &__kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000895} // __kmp_stg_parse_version
896
Jonathan Peyton30419822017-05-12 18:01:32 +0000897static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
898 void *data) {
899 __kmp_stg_print_bool(buffer, name, __kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000900} // __kmp_stg_print_version
901
Jonathan Peyton30419822017-05-12 18:01:32 +0000902// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000903// KMP_WARNINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000904
Jonathan Peyton30419822017-05-12 18:01:32 +0000905static void __kmp_stg_parse_warnings(char const *name, char const *value,
906 void *data) {
907 __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
908 if (__kmp_generate_warnings != kmp_warnings_off) {
909 // AC: only 0/1 values documented, so reset to explicit to distinguish from
910 // default setting
911 __kmp_generate_warnings = kmp_warnings_explicit;
912 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000913} // __kmp_stg_parse_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000914
Jonathan Peyton30419822017-05-12 18:01:32 +0000915static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
916 void *data) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000917 // AC: TODO: change to print_int? (needs documentation change)
918 __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
919} // __kmp_stg_print_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000920
Jonathan Peyton30419822017-05-12 18:01:32 +0000921// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000922// OMP_NESTED, OMP_NUM_THREADS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000923
Jonathan Peyton30419822017-05-12 18:01:32 +0000924static void __kmp_stg_parse_nested(char const *name, char const *value,
925 void *data) {
926 __kmp_stg_parse_bool(name, value, &__kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000927} // __kmp_stg_parse_nested
928
Jonathan Peyton30419822017-05-12 18:01:32 +0000929static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
930 void *data) {
931 __kmp_stg_print_bool(buffer, name, __kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000932} // __kmp_stg_print_nested
933
Jonathan Peyton30419822017-05-12 18:01:32 +0000934static void __kmp_parse_nested_num_threads(const char *var, const char *env,
935 kmp_nested_nthreads_t *nth_array) {
936 const char *next = env;
937 const char *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000938
Jonathan Peyton30419822017-05-12 18:01:32 +0000939 int total = 0; // Count elements that were set. It'll be used as an array size
940 int prev_comma = FALSE; // For correct processing sequential commas
Jim Cownie5e8470a2013-09-27 10:38:44 +0000941
Jonathan Peyton30419822017-05-12 18:01:32 +0000942 // Count the number of values in the env. var string
943 for (;;) {
944 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000945
Jonathan Peyton30419822017-05-12 18:01:32 +0000946 if (*next == '\0') {
947 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000948 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000949 // Next character is not an integer or not a comma => end of list
950 if (((*next < '0') || (*next > '9')) && (*next != ',')) {
951 KMP_WARNING(NthSyntaxError, var, env);
952 return;
953 }
954 // The next character is ','
955 if (*next == ',') {
956 // ',' is the fisrt character
957 if (total == 0 || prev_comma) {
958 total++;
959 }
960 prev_comma = TRUE;
961 next++; // skip ','
962 SKIP_WS(next);
963 }
964 // Next character is a digit
965 if (*next >= '0' && *next <= '9') {
966 prev_comma = FALSE;
967 SKIP_DIGITS(next);
968 total++;
969 const char *tmp = next;
970 SKIP_WS(tmp);
971 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
972 KMP_WARNING(NthSpacesNotAllowed, var, env);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000973 return;
Jonathan Peyton30419822017-05-12 18:01:32 +0000974 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000975 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000976 }
977 KMP_DEBUG_ASSERT(total > 0);
978 if (total <= 0) {
979 KMP_WARNING(NthSyntaxError, var, env);
980 return;
981 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000982
Jonathan Peyton30419822017-05-12 18:01:32 +0000983 // Check if the nested nthreads array exists
984 if (!nth_array->nth) {
985 // Allocate an array of double size
986 nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
987 if (nth_array->nth == NULL) {
988 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000989 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000990 nth_array->size = total * 2;
991 } else {
992 if (nth_array->size < total) {
993 // Increase the array size
994 do {
995 nth_array->size *= 2;
996 } while (nth_array->size < total);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000997
Jonathan Peyton30419822017-05-12 18:01:32 +0000998 nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
999 nth_array->nth, sizeof(int) * nth_array->size);
1000 if (nth_array->nth == NULL) {
1001 KMP_FATAL(MemoryAllocFailed);
1002 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001003 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001004 }
1005 nth_array->used = total;
1006 int i = 0;
1007
1008 prev_comma = FALSE;
1009 total = 0;
1010 // Save values in the array
1011 for (;;) {
1012 SKIP_WS(scan);
1013 if (*scan == '\0') {
1014 break;
1015 }
1016 // The next character is ','
1017 if (*scan == ',') {
1018 // ',' in the beginning of the list
1019 if (total == 0) {
1020 // The value is supposed to be equal to __kmp_avail_proc but it is
1021 // unknown at the moment.
1022 // So let's put a placeholder (#threads = 0) to correct it later.
1023 nth_array->nth[i++] = 0;
1024 total++;
1025 } else if (prev_comma) {
1026 // Num threads is inherited from the previous level
1027 nth_array->nth[i] = nth_array->nth[i - 1];
1028 i++;
1029 total++;
1030 }
1031 prev_comma = TRUE;
1032 scan++; // skip ','
1033 SKIP_WS(scan);
1034 }
1035 // Next character is a digit
1036 if (*scan >= '0' && *scan <= '9') {
1037 int num;
1038 const char *buf = scan;
1039 char const *msg = NULL;
1040 prev_comma = FALSE;
1041 SKIP_DIGITS(scan);
1042 total++;
1043
1044 num = __kmp_str_to_int(buf, *scan);
1045 if (num < KMP_MIN_NTH) {
1046 msg = KMP_I18N_STR(ValueTooSmall);
1047 num = KMP_MIN_NTH;
1048 } else if (num > __kmp_sys_max_nth) {
1049 msg = KMP_I18N_STR(ValueTooLarge);
1050 num = __kmp_sys_max_nth;
1051 }
1052 if (msg != NULL) {
1053 // Message is not empty. Print warning.
1054 KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1055 KMP_INFORM(Using_int_Value, var, num);
1056 }
1057 nth_array->nth[i++] = num;
1058 }
1059 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001060}
1061
Jonathan Peyton30419822017-05-12 18:01:32 +00001062static void __kmp_stg_parse_num_threads(char const *name, char const *value,
1063 void *data) {
1064 // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
1065 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
1066 // The array of 1 element
1067 __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
1068 __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1069 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1070 __kmp_xproc;
1071 } else {
1072 __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1073 if (__kmp_nested_nth.nth) {
1074 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1075 if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1076 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1077 }
1078 }
1079 }; // if
1080 K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001081} // __kmp_stg_parse_num_threads
1082
Jonathan Peyton30419822017-05-12 18:01:32 +00001083static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
1084 void *data) {
1085 if (__kmp_env_format) {
1086 KMP_STR_BUF_PRINT_NAME;
1087 } else {
1088 __kmp_str_buf_print(buffer, " %s", name);
1089 }
1090 if (__kmp_nested_nth.used) {
1091 kmp_str_buf_t buf;
1092 __kmp_str_buf_init(&buf);
1093 for (int i = 0; i < __kmp_nested_nth.used; i++) {
1094 __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
1095 if (i < __kmp_nested_nth.used - 1) {
1096 __kmp_str_buf_print(&buf, ",");
1097 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001098 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001099 __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
1100 __kmp_str_buf_free(&buf);
1101 } else {
1102 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1103 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001104} // __kmp_stg_print_num_threads
1105
Jonathan Peyton30419822017-05-12 18:01:32 +00001106// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001107// OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001108
Jonathan Peyton30419822017-05-12 18:01:32 +00001109static void __kmp_stg_parse_tasking(char const *name, char const *value,
1110 void *data) {
1111 __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
1112 (int *)&__kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001113} // __kmp_stg_parse_tasking
1114
Jonathan Peyton30419822017-05-12 18:01:32 +00001115static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
1116 void *data) {
1117 __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001118} // __kmp_stg_print_tasking
1119
Jonathan Peyton30419822017-05-12 18:01:32 +00001120static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
1121 void *data) {
1122 __kmp_stg_parse_int(name, value, 0, 1,
1123 (int *)&__kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001124} // __kmp_stg_parse_task_stealing
1125
Jonathan Peyton30419822017-05-12 18:01:32 +00001126static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1127 char const *name, void *data) {
1128 __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001129} // __kmp_stg_print_task_stealing
1130
Jonathan Peyton30419822017-05-12 18:01:32 +00001131static void __kmp_stg_parse_max_active_levels(char const *name,
1132 char const *value, void *data) {
1133 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1134 &__kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001135} // __kmp_stg_parse_max_active_levels
1136
Jonathan Peyton30419822017-05-12 18:01:32 +00001137static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1138 char const *name, void *data) {
1139 __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001140} // __kmp_stg_print_max_active_levels
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001141
George Rokos28f31b42016-09-09 17:55:26 +00001142#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001143// -----------------------------------------------------------------------------
George Rokos28f31b42016-09-09 17:55:26 +00001144// OpenMP 4.0: OMP_DEFAULT_DEVICE
Jonathan Peyton30419822017-05-12 18:01:32 +00001145static void __kmp_stg_parse_default_device(char const *name, char const *value,
1146 void *data) {
1147 __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1148 &__kmp_default_device);
George Rokos28f31b42016-09-09 17:55:26 +00001149} // __kmp_stg_parse_default_device
1150
Jonathan Peyton30419822017-05-12 18:01:32 +00001151static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1152 char const *name, void *data) {
George Rokos28f31b42016-09-09 17:55:26 +00001153 __kmp_stg_print_int(buffer, name, __kmp_default_device);
1154} // __kmp_stg_print_default_device
1155#endif
1156
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001157#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001158// -----------------------------------------------------------------------------
Jonathan Peyton28510722016-02-25 18:04:09 +00001159// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
Jonathan Peyton30419822017-05-12 18:01:32 +00001160static void __kmp_stg_parse_max_task_priority(char const *name,
1161 char const *value, void *data) {
1162 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1163 &__kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001164} // __kmp_stg_parse_max_task_priority
1165
Jonathan Peyton30419822017-05-12 18:01:32 +00001166static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1167 char const *name, void *data) {
1168 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001169} // __kmp_stg_print_max_task_priority
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001170
1171// KMP_TASKLOOP_MIN_TASKS
1172// taskloop threashold to switch from recursive to linear tasks creation
1173static void __kmp_stg_parse_taskloop_min_tasks(char const *name,
1174 char const *value, void *data) {
1175 int tmp;
1176 __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1177 __kmp_taskloop_min_tasks = tmp;
1178} // __kmp_stg_parse_taskloop_min_tasks
1179
1180static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
1181 char const *name, void *data) {
1182 __kmp_stg_print_int(buffer, name, __kmp_taskloop_min_tasks);
1183} // __kmp_stg_print_taskloop_min_tasks
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001184#endif // OMP_45_ENABLED
Jonathan Peyton28510722016-02-25 18:04:09 +00001185
Jonathan Peyton30419822017-05-12 18:01:32 +00001186// -----------------------------------------------------------------------------
Jonathan Peyton067325f2016-05-31 19:01:15 +00001187// KMP_DISP_NUM_BUFFERS
Jonathan Peyton30419822017-05-12 18:01:32 +00001188static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
1189 void *data) {
1190 if (TCR_4(__kmp_init_serial)) {
1191 KMP_WARNING(EnvSerialWarn, name);
1192 return;
1193 } // read value before serial initialization only
1194 __kmp_stg_parse_int(name, value, 1, KMP_MAX_NTH, &__kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001195} // __kmp_stg_parse_disp_buffers
1196
Jonathan Peyton30419822017-05-12 18:01:32 +00001197static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1198 char const *name, void *data) {
1199 __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001200} // __kmp_stg_print_disp_buffers
1201
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001202#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00001203// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001204// KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001205
Jonathan Peyton30419822017-05-12 18:01:32 +00001206static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
1207 void *data) {
1208 if (TCR_4(__kmp_init_parallel)) {
1209 KMP_WARNING(EnvParallelWarn, name);
1210 return;
1211 } // read value before first parallel only
1212 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1213 &__kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001214} // __kmp_stg_parse_hot_teams_level
1215
Jonathan Peyton30419822017-05-12 18:01:32 +00001216static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1217 char const *name, void *data) {
1218 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001219} // __kmp_stg_print_hot_teams_level
1220
Jonathan Peyton30419822017-05-12 18:01:32 +00001221static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
1222 void *data) {
1223 if (TCR_4(__kmp_init_parallel)) {
1224 KMP_WARNING(EnvParallelWarn, name);
1225 return;
1226 } // read value before first parallel only
1227 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1228 &__kmp_hot_teams_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001229} // __kmp_stg_parse_hot_teams_mode
1230
Jonathan Peyton30419822017-05-12 18:01:32 +00001231static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1232 char const *name, void *data) {
1233 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001234} // __kmp_stg_print_hot_teams_mode
1235
1236#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001237
Jonathan Peyton30419822017-05-12 18:01:32 +00001238// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001239// KMP_HANDLE_SIGNALS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001240
1241#if KMP_HANDLE_SIGNALS
1242
Jonathan Peyton30419822017-05-12 18:01:32 +00001243static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
1244 void *data) {
1245 __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001246} // __kmp_stg_parse_handle_signals
1247
Jonathan Peyton30419822017-05-12 18:01:32 +00001248static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1249 char const *name, void *data) {
1250 __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001251} // __kmp_stg_print_handle_signals
1252
1253#endif // KMP_HANDLE_SIGNALS
1254
Jonathan Peyton30419822017-05-12 18:01:32 +00001255// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001256// KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
Jim Cownie5e8470a2013-09-27 10:38:44 +00001257
1258#ifdef KMP_DEBUG
1259
Jonathan Peyton30419822017-05-12 18:01:32 +00001260#define KMP_STG_X_DEBUG(x) \
1261 static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1262 void *data) { \
1263 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1264 } /* __kmp_stg_parse_x_debug */ \
1265 static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1266 char const *name, void *data) { \
1267 __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1268 } /* __kmp_stg_print_x_debug */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001269
Jonathan Peyton30419822017-05-12 18:01:32 +00001270KMP_STG_X_DEBUG(a)
1271KMP_STG_X_DEBUG(b)
1272KMP_STG_X_DEBUG(c)
1273KMP_STG_X_DEBUG(d)
1274KMP_STG_X_DEBUG(e)
1275KMP_STG_X_DEBUG(f)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001276
1277#undef KMP_STG_X_DEBUG
1278
Jonathan Peyton30419822017-05-12 18:01:32 +00001279static void __kmp_stg_parse_debug(char const *name, char const *value,
1280 void *data) {
1281 int debug = 0;
1282 __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1283 if (kmp_a_debug < debug) {
1284 kmp_a_debug = debug;
1285 }; // if
1286 if (kmp_b_debug < debug) {
1287 kmp_b_debug = debug;
1288 }; // if
1289 if (kmp_c_debug < debug) {
1290 kmp_c_debug = debug;
1291 }; // if
1292 if (kmp_d_debug < debug) {
1293 kmp_d_debug = debug;
1294 }; // if
1295 if (kmp_e_debug < debug) {
1296 kmp_e_debug = debug;
1297 }; // if
1298 if (kmp_f_debug < debug) {
1299 kmp_f_debug = debug;
1300 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00001301} // __kmp_stg_parse_debug
1302
Jonathan Peyton30419822017-05-12 18:01:32 +00001303static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
1304 void *data) {
1305 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1306 // !!! TODO: Move buffer initialization of of this file! It may works
1307 // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
1308 // KMP_DEBUG_BUF_CHARS.
1309 if (__kmp_debug_buf) {
1310 int i;
1311 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001312
Jonathan Peyton30419822017-05-12 18:01:32 +00001313 /* allocate and initialize all entries in debug buffer to empty */
1314 __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
1315 for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1316 __kmp_debug_buffer[i] = '\0';
Jim Cownie5e8470a2013-09-27 10:38:44 +00001317
Jonathan Peyton30419822017-05-12 18:01:32 +00001318 __kmp_debug_count = 0;
1319 }
1320 K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001321} // __kmp_stg_parse_debug_buf
1322
Jonathan Peyton30419822017-05-12 18:01:32 +00001323static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
1324 void *data) {
1325 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001326} // __kmp_stg_print_debug_buf
1327
Jonathan Peyton30419822017-05-12 18:01:32 +00001328static void __kmp_stg_parse_debug_buf_atomic(char const *name,
1329 char const *value, void *data) {
1330 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001331} // __kmp_stg_parse_debug_buf_atomic
1332
Jonathan Peyton30419822017-05-12 18:01:32 +00001333static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1334 char const *name, void *data) {
1335 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001336} // __kmp_stg_print_debug_buf_atomic
1337
Jonathan Peyton30419822017-05-12 18:01:32 +00001338static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
1339 void *data) {
1340 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1341 &__kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001342} // __kmp_stg_debug_parse_buf_chars
1343
Jonathan Peyton30419822017-05-12 18:01:32 +00001344static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1345 char const *name, void *data) {
1346 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001347} // __kmp_stg_print_debug_buf_chars
1348
Jonathan Peyton30419822017-05-12 18:01:32 +00001349static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
1350 void *data) {
1351 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1352 &__kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001353} // __kmp_stg_parse_debug_buf_lines
1354
Jonathan Peyton30419822017-05-12 18:01:32 +00001355static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1356 char const *name, void *data) {
1357 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001358} // __kmp_stg_print_debug_buf_lines
1359
Jonathan Peyton30419822017-05-12 18:01:32 +00001360static void __kmp_stg_parse_diag(char const *name, char const *value,
1361 void *data) {
1362 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001363} // __kmp_stg_parse_diag
1364
Jonathan Peyton30419822017-05-12 18:01:32 +00001365static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
1366 void *data) {
1367 __kmp_stg_print_int(buffer, name, kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001368} // __kmp_stg_print_diag
1369
1370#endif // KMP_DEBUG
1371
Jonathan Peyton30419822017-05-12 18:01:32 +00001372// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001373// KMP_ALIGN_ALLOC
Jim Cownie5e8470a2013-09-27 10:38:44 +00001374
Jonathan Peyton30419822017-05-12 18:01:32 +00001375static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
1376 void *data) {
1377 __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1378 &__kmp_align_alloc, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001379} // __kmp_stg_parse_align_alloc
1380
Jonathan Peyton30419822017-05-12 18:01:32 +00001381static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
1382 void *data) {
1383 __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001384} // __kmp_stg_print_align_alloc
1385
Jonathan Peyton30419822017-05-12 18:01:32 +00001386// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001387// KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
Jim Cownie5e8470a2013-09-27 10:38:44 +00001388
Jonathan Peyton30419822017-05-12 18:01:32 +00001389// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
1390// parse and print functions, pass required info through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001391
Jonathan Peyton30419822017-05-12 18:01:32 +00001392static void __kmp_stg_parse_barrier_branch_bit(char const *name,
1393 char const *value, void *data) {
1394 const char *var;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001395
Jonathan Peyton30419822017-05-12 18:01:32 +00001396 /* ---------- Barrier branch bit control ------------ */
1397 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1398 var = __kmp_barrier_branch_bit_env_name[i];
1399 if ((strcmp(var, name) == 0) && (value != 0)) {
1400 char *comma;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001401
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001402 comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00001403 __kmp_barrier_gather_branch_bits[i] =
1404 (kmp_uint32)__kmp_str_to_int(value, ',');
1405 /* is there a specified release parameter? */
1406 if (comma == NULL) {
1407 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1408 } else {
1409 __kmp_barrier_release_branch_bits[i] =
1410 (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001411
Jonathan Peyton30419822017-05-12 18:01:32 +00001412 if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1413 __kmp_msg(kmp_ms_warning,
1414 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1415 __kmp_msg_null);
1416 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001417 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001418 }
1419 if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1420 KMP_WARNING(BarrGatherValueInvalid, name, value);
1421 KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1422 __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1423 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001424 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001425 K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1426 __kmp_barrier_gather_branch_bits[i],
1427 __kmp_barrier_release_branch_bits[i]))
1428 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001429} // __kmp_stg_parse_barrier_branch_bit
1430
Jonathan Peyton30419822017-05-12 18:01:32 +00001431static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1432 char const *name, void *data) {
1433 const char *var;
1434 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1435 var = __kmp_barrier_branch_bit_env_name[i];
1436 if (strcmp(var, name) == 0) {
1437 if (__kmp_env_format) {
1438 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1439 } else {
1440 __kmp_str_buf_print(buffer, " %s='",
1441 __kmp_barrier_branch_bit_env_name[i]);
1442 }
1443 __kmp_str_buf_print(buffer, "%d,%d'\n",
1444 __kmp_barrier_gather_branch_bits[i],
1445 __kmp_barrier_release_branch_bits[i]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001446 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001447 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001448} // __kmp_stg_print_barrier_branch_bit
1449
Jonathan Peyton30419822017-05-12 18:01:32 +00001450// ----------------------------------------------------------------------------
1451// KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
1452// KMP_REDUCTION_BARRIER_PATTERN
Jim Cownie5e8470a2013-09-27 10:38:44 +00001453
Jonathan Peyton30419822017-05-12 18:01:32 +00001454// TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
1455// print functions, pass required data to functions through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001456
Jonathan Peyton30419822017-05-12 18:01:32 +00001457static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
1458 void *data) {
1459 const char *var;
1460 /* ---------- Barrier method control ------------ */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001461
Jonathan Peyton30419822017-05-12 18:01:32 +00001462 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1463 var = __kmp_barrier_pattern_env_name[i];
Jim Cownie5e8470a2013-09-27 10:38:44 +00001464
Jonathan Peyton30419822017-05-12 18:01:32 +00001465 if ((strcmp(var, name) == 0) && (value != 0)) {
1466 int j;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001467 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001468
Jonathan Peyton30419822017-05-12 18:01:32 +00001469 /* handle first parameter: gather pattern */
1470 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1471 if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1472 ',')) {
1473 __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1474 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001475 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001476 }
1477 if (j == bp_last_bar) {
1478 KMP_WARNING(BarrGatherValueInvalid, name, value);
1479 KMP_INFORM(Using_str_Value, name,
1480 __kmp_barrier_pattern_name[bp_linear_bar]);
1481 }
1482
1483 /* handle second parameter: release pattern */
1484 if (comma != NULL) {
1485 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1486 if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1487 __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1488 break;
1489 }
1490 }
1491 if (j == bp_last_bar) {
1492 __kmp_msg(kmp_ms_warning,
1493 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1494 __kmp_msg_null);
1495 KMP_INFORM(Using_str_Value, name,
1496 __kmp_barrier_pattern_name[bp_linear_bar]);
1497 }
1498 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001499 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001500 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001501} // __kmp_stg_parse_barrier_pattern
1502
Jonathan Peyton30419822017-05-12 18:01:32 +00001503static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1504 char const *name, void *data) {
1505 const char *var;
1506 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1507 var = __kmp_barrier_pattern_env_name[i];
1508 if (strcmp(var, name) == 0) {
1509 int j = __kmp_barrier_gather_pattern[i];
1510 int k = __kmp_barrier_release_pattern[i];
1511 if (__kmp_env_format) {
1512 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1513 } else {
1514 __kmp_str_buf_print(buffer, " %s='",
1515 __kmp_barrier_pattern_env_name[i]);
1516 }
1517 __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
1518 __kmp_barrier_pattern_name[k]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001519 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001520 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001521} // __kmp_stg_print_barrier_pattern
1522
Jonathan Peyton30419822017-05-12 18:01:32 +00001523// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001524// KMP_ABORT_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00001525
Jonathan Peyton30419822017-05-12 18:01:32 +00001526static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
1527 void *data) {
1528 // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
1529 // milliseconds.
1530 int delay = __kmp_abort_delay / 1000;
1531 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1532 __kmp_abort_delay = delay * 1000;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001533} // __kmp_stg_parse_abort_delay
1534
Jonathan Peyton30419822017-05-12 18:01:32 +00001535static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
1536 void *data) {
1537 __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001538} // __kmp_stg_print_abort_delay
1539
Jonathan Peyton30419822017-05-12 18:01:32 +00001540// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001541// KMP_CPUINFO_FILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001542
Jonathan Peyton30419822017-05-12 18:01:32 +00001543static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
1544 void *data) {
1545#if KMP_AFFINITY_SUPPORTED
1546 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1547 K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1548#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001549} //__kmp_stg_parse_cpuinfo_file
1550
Jonathan Peyton30419822017-05-12 18:01:32 +00001551static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1552 char const *name, void *data) {
1553#if KMP_AFFINITY_SUPPORTED
1554 if (__kmp_env_format) {
1555 KMP_STR_BUF_PRINT_NAME;
1556 } else {
1557 __kmp_str_buf_print(buffer, " %s", name);
1558 }
1559 if (__kmp_cpuinfo_file) {
1560 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
1561 } else {
1562 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1563 }
1564#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001565} //__kmp_stg_print_cpuinfo_file
1566
Jonathan Peyton30419822017-05-12 18:01:32 +00001567// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001568// KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
Jim Cownie5e8470a2013-09-27 10:38:44 +00001569
Jonathan Peyton30419822017-05-12 18:01:32 +00001570static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
1571 void *data) {
1572 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1573 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001574
Jonathan Peyton30419822017-05-12 18:01:32 +00001575 rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1576 if (rc) {
1577 return;
1578 }; // if
1579 if (reduction->force) {
1580 if (value != 0) {
1581 if (__kmp_str_match("critical", 0, value))
1582 __kmp_force_reduction_method = critical_reduce_block;
1583 else if (__kmp_str_match("atomic", 0, value))
1584 __kmp_force_reduction_method = atomic_reduce_block;
1585 else if (__kmp_str_match("tree", 0, value))
1586 __kmp_force_reduction_method = tree_reduce_block;
1587 else {
1588 KMP_FATAL(UnknownForceReduction, name, value);
1589 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001590 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001591 } else {
1592 __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1593 if (__kmp_determ_red) {
1594 __kmp_force_reduction_method = tree_reduce_block;
1595 } else {
1596 __kmp_force_reduction_method = reduction_method_not_defined;
1597 }
1598 }
1599 K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
1600 __kmp_force_reduction_method));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001601} // __kmp_stg_parse_force_reduction
1602
Jonathan Peyton30419822017-05-12 18:01:32 +00001603static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1604 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00001605
Jonathan Peyton30419822017-05-12 18:01:32 +00001606 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1607 if (reduction->force) {
1608 if (__kmp_force_reduction_method == critical_reduce_block) {
1609 __kmp_stg_print_str(buffer, name, "critical");
1610 } else if (__kmp_force_reduction_method == atomic_reduce_block) {
1611 __kmp_stg_print_str(buffer, name, "atomic");
1612 } else if (__kmp_force_reduction_method == tree_reduce_block) {
1613 __kmp_stg_print_str(buffer, name, "tree");
Jim Cownie5e8470a2013-09-27 10:38:44 +00001614 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00001615 if (__kmp_env_format) {
1616 KMP_STR_BUF_PRINT_NAME;
1617 } else {
1618 __kmp_str_buf_print(buffer, " %s", name);
1619 }
1620 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001621 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001622 } else {
1623 __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1624 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001625
1626} // __kmp_stg_print_force_reduction
1627
Jonathan Peyton30419822017-05-12 18:01:32 +00001628// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001629// KMP_STORAGE_MAP
Jim Cownie5e8470a2013-09-27 10:38:44 +00001630
Jonathan Peyton30419822017-05-12 18:01:32 +00001631static void __kmp_stg_parse_storage_map(char const *name, char const *value,
1632 void *data) {
1633 if (__kmp_str_match("verbose", 1, value)) {
1634 __kmp_storage_map = TRUE;
1635 __kmp_storage_map_verbose = TRUE;
1636 __kmp_storage_map_verbose_specified = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001637
Jonathan Peyton30419822017-05-12 18:01:32 +00001638 } else {
1639 __kmp_storage_map_verbose = FALSE;
1640 __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
1641 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00001642} // __kmp_stg_parse_storage_map
1643
Jonathan Peyton30419822017-05-12 18:01:32 +00001644static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
1645 void *data) {
1646 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1647 __kmp_stg_print_str(buffer, name, "verbose");
1648 } else {
1649 __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1650 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001651} // __kmp_stg_print_storage_map
1652
Jonathan Peyton30419822017-05-12 18:01:32 +00001653// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001654// KMP_ALL_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001655
Jonathan Peyton30419822017-05-12 18:01:32 +00001656static void __kmp_stg_parse_all_threadprivate(char const *name,
1657 char const *value, void *data) {
1658 __kmp_stg_parse_int(name, value,
1659 __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1660 __kmp_max_nth, &__kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001661} // __kmp_stg_parse_all_threadprivate
1662
Jonathan Peyton30419822017-05-12 18:01:32 +00001663static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1664 char const *name, void *data) {
1665 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001666}
1667
Jonathan Peyton30419822017-05-12 18:01:32 +00001668// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001669// KMP_FOREIGN_THREADS_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001670
Jonathan Peyton30419822017-05-12 18:01:32 +00001671static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
1672 char const *value,
1673 void *data) {
1674 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001675} // __kmp_stg_parse_foreign_threads_threadprivate
1676
Jonathan Peyton30419822017-05-12 18:01:32 +00001677static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
1678 char const *name,
1679 void *data) {
1680 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001681} // __kmp_stg_print_foreign_threads_threadprivate
1682
Jonathan Peyton30419822017-05-12 18:01:32 +00001683// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001684// KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
Jim Cownie5e8470a2013-09-27 10:38:44 +00001685
Alp Toker98758b02014-03-02 04:12:06 +00001686#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00001687// Parse the proc id list. Return TRUE if successful, FALSE otherwise.
Jonathan Peyton30419822017-05-12 18:01:32 +00001688static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
1689 const char **nextEnv,
1690 char **proclist) {
1691 const char *scan = env;
1692 const char *next = scan;
1693 int empty = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001694
Jonathan Peyton30419822017-05-12 18:01:32 +00001695 *proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001696
Jonathan Peyton30419822017-05-12 18:01:32 +00001697 for (;;) {
1698 int start, end, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001699
Jonathan Peyton30419822017-05-12 18:01:32 +00001700 SKIP_WS(scan);
1701 next = scan;
1702 if (*next == '\0') {
1703 break;
1704 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001705
Jonathan Peyton30419822017-05-12 18:01:32 +00001706 if (*next == '{') {
1707 int num;
1708 next++; // skip '{'
1709 SKIP_WS(next);
1710 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001711
Jonathan Peyton30419822017-05-12 18:01:32 +00001712 // Read the first integer in the set.
1713 if ((*next < '0') || (*next > '9')) {
1714 KMP_WARNING(AffSyntaxError, var);
1715 return FALSE;
1716 }
1717 SKIP_DIGITS(next);
1718 num = __kmp_str_to_int(scan, *next);
1719 KMP_ASSERT(num >= 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001720
Jonathan Peyton30419822017-05-12 18:01:32 +00001721 for (;;) {
1722 // Check for end of set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001723 SKIP_WS(next);
Jonathan Peyton30419822017-05-12 18:01:32 +00001724 if (*next == '}') {
1725 next++; // skip '}'
1726 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001727 }
1728
Jim Cownie5e8470a2013-09-27 10:38:44 +00001729 // Skip optional comma.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001730 if (*next == ',') {
Jonathan Peyton30419822017-05-12 18:01:32 +00001731 next++;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001732 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001733 SKIP_WS(next);
1734
1735 // Read the next integer in the set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001736 scan = next;
Jonathan Peyton30419822017-05-12 18:01:32 +00001737 if ((*next < '0') || (*next > '9')) {
1738 KMP_WARNING(AffSyntaxError, var);
1739 return FALSE;
1740 }
1741
1742 SKIP_DIGITS(next);
1743 num = __kmp_str_to_int(scan, *next);
1744 KMP_ASSERT(num >= 0);
1745 }
1746 empty = FALSE;
1747
1748 SKIP_WS(next);
1749 if (*next == ',') {
1750 next++;
1751 }
1752 scan = next;
1753 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001754 }
1755
Jonathan Peyton30419822017-05-12 18:01:32 +00001756 // Next character is not an integer => end of list
1757 if ((*next < '0') || (*next > '9')) {
1758 if (empty) {
1759 KMP_WARNING(AffSyntaxError, var);
1760 return FALSE;
1761 }
1762 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001763 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001764
1765 // Read the first integer.
1766 SKIP_DIGITS(next);
1767 start = __kmp_str_to_int(scan, *next);
1768 KMP_ASSERT(start >= 0);
1769 SKIP_WS(next);
1770
1771 // If this isn't a range, then go on.
1772 if (*next != '-') {
1773 empty = FALSE;
1774
1775 // Skip optional comma.
1776 if (*next == ',') {
1777 next++;
1778 }
1779 scan = next;
1780 continue;
1781 }
1782
1783 // This is a range. Skip over the '-' and read in the 2nd int.
1784 next++; // skip '-'
1785 SKIP_WS(next);
1786 scan = next;
1787 if ((*next < '0') || (*next > '9')) {
1788 KMP_WARNING(AffSyntaxError, var);
1789 return FALSE;
1790 }
1791 SKIP_DIGITS(next);
1792 end = __kmp_str_to_int(scan, *next);
1793 KMP_ASSERT(end >= 0);
1794
1795 // Check for a stride parameter
1796 stride = 1;
1797 SKIP_WS(next);
1798 if (*next == ':') {
1799 // A stride is specified. Skip over the ':" and read the 3rd int.
1800 int sign = +1;
1801 next++; // skip ':'
1802 SKIP_WS(next);
1803 scan = next;
1804 if (*next == '-') {
1805 sign = -1;
1806 next++;
1807 SKIP_WS(next);
1808 scan = next;
1809 }
1810 if ((*next < '0') || (*next > '9')) {
1811 KMP_WARNING(AffSyntaxError, var);
1812 return FALSE;
1813 }
1814 SKIP_DIGITS(next);
1815 stride = __kmp_str_to_int(scan, *next);
1816 KMP_ASSERT(stride >= 0);
1817 stride *= sign;
1818 }
1819
1820 // Do some range checks.
1821 if (stride == 0) {
1822 KMP_WARNING(AffZeroStride, var);
1823 return FALSE;
1824 }
1825 if (stride > 0) {
1826 if (start > end) {
1827 KMP_WARNING(AffStartGreaterEnd, var, start, end);
1828 return FALSE;
1829 }
1830 } else {
1831 if (start < end) {
1832 KMP_WARNING(AffStrideLessZero, var, start, end);
1833 return FALSE;
1834 }
1835 }
1836 if ((end - start) / stride > 65536) {
1837 KMP_WARNING(AffRangeTooBig, var, end, start, stride);
1838 return FALSE;
1839 }
1840
1841 empty = FALSE;
1842
1843 // Skip optional comma.
1844 SKIP_WS(next);
1845 if (*next == ',') {
1846 next++;
1847 }
1848 scan = next;
1849 }
1850
1851 *nextEnv = next;
1852
1853 {
1854 int len = next - env;
1855 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
1856 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
1857 retlist[len] = '\0';
1858 *proclist = retlist;
1859 }
1860 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001861}
1862
Jim Cownie5e8470a2013-09-27 10:38:44 +00001863// If KMP_AFFINITY is specified without a type, then
1864// __kmp_affinity_notype should point to its setting.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001865static kmp_setting_t *__kmp_affinity_notype = NULL;
1866
Jonathan Peyton30419822017-05-12 18:01:32 +00001867static void __kmp_parse_affinity_env(char const *name, char const *value,
1868 enum affinity_type *out_type,
1869 char **out_proclist, int *out_verbose,
1870 int *out_warn, int *out_respect,
1871 enum affinity_gran *out_gran,
1872 int *out_gran_levels, int *out_dups,
1873 int *out_compact, int *out_offset) {
1874 char *buffer = NULL; // Copy of env var value.
1875 char *buf = NULL; // Buffer for strtok_r() function.
1876 char *next = NULL; // end of token / start of next.
1877 const char *start; // start of current token (for err msgs)
1878 int count = 0; // Counter of parsed integer numbers.
1879 int number[2]; // Parsed numbers.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001880
Jonathan Peyton30419822017-05-12 18:01:32 +00001881 // Guards.
1882 int type = 0;
1883 int proclist = 0;
1884 int max_proclist = 0;
1885 int verbose = 0;
1886 int warnings = 0;
1887 int respect = 0;
1888 int gran = 0;
1889 int dups = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001890
Jonathan Peyton30419822017-05-12 18:01:32 +00001891 KMP_ASSERT(value != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001892
Jonathan Peyton30419822017-05-12 18:01:32 +00001893 if (TCR_4(__kmp_init_middle)) {
1894 KMP_WARNING(EnvMiddleWarn, name);
1895 __kmp_env_toPrint(name, 0);
1896 return;
1897 }
1898 __kmp_env_toPrint(name, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001899
Jonathan Peyton30419822017-05-12 18:01:32 +00001900 buffer =
1901 __kmp_str_format("%s", value); // Copy env var to keep original intact.
1902 buf = buffer;
1903 SKIP_WS(buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001904
Jonathan Peyton30419822017-05-12 18:01:32 +00001905// Helper macros.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001906
Jonathan Peyton30419822017-05-12 18:01:32 +00001907// If we see a parse error, emit a warning and scan to the next ",".
1908//
1909// FIXME - there's got to be a better way to print an error
1910// message, hopefully without overwritting peices of buf.
1911#define EMIT_WARN(skip, errlist) \
1912 { \
1913 char ch; \
1914 if (skip) { \
1915 SKIP_TO(next, ','); \
1916 } \
1917 ch = *next; \
1918 *next = '\0'; \
1919 KMP_WARNING errlist; \
1920 *next = ch; \
1921 if (skip) { \
1922 if (ch == ',') \
1923 next++; \
1924 } \
1925 buf = next; \
1926 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001927
Jonathan Peyton30419822017-05-12 18:01:32 +00001928#define _set_param(_guard, _var, _val) \
1929 { \
1930 if (_guard == 0) { \
1931 _var = _val; \
1932 } else { \
1933 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
1934 }; \
1935 ++_guard; \
1936 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001937
Jonathan Peyton30419822017-05-12 18:01:32 +00001938#define set_type(val) _set_param(type, *out_type, val)
1939#define set_verbose(val) _set_param(verbose, *out_verbose, val)
1940#define set_warnings(val) _set_param(warnings, *out_warn, val)
1941#define set_respect(val) _set_param(respect, *out_respect, val)
1942#define set_dups(val) _set_param(dups, *out_dups, val)
1943#define set_proclist(val) _set_param(proclist, *out_proclist, val)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001944
Jonathan Peyton30419822017-05-12 18:01:32 +00001945#define set_gran(val, levels) \
1946 { \
1947 if (gran == 0) { \
1948 *out_gran = val; \
1949 *out_gran_levels = levels; \
1950 } else { \
1951 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
1952 }; \
1953 ++gran; \
1954 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001955
Jonathan Peyton30419822017-05-12 18:01:32 +00001956#if OMP_40_ENABLED
1957 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
1958 (__kmp_nested_proc_bind.used > 0));
Andrey Churbanov613edeb2015-02-20 18:14:43 +00001959#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00001960
1961 while (*buf != '\0') {
1962 start = next = buf;
1963
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001964 if (__kmp_match_str("none", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001965 set_type(affinity_none);
1966#if OMP_40_ENABLED
1967 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
1968#endif
1969 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001970 } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001971 set_type(affinity_scatter);
1972#if OMP_40_ENABLED
1973 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1974#endif
1975 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001976 } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001977 set_type(affinity_compact);
1978#if OMP_40_ENABLED
1979 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1980#endif
1981 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001982 } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001983 set_type(affinity_logical);
1984#if OMP_40_ENABLED
1985 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1986#endif
1987 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001988 } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001989 set_type(affinity_physical);
1990#if OMP_40_ENABLED
1991 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1992#endif
1993 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001994 } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001995 set_type(affinity_explicit);
1996#if OMP_40_ENABLED
1997 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1998#endif
1999 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002000 } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002001 set_type(affinity_balanced);
2002#if OMP_40_ENABLED
2003 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2004#endif
2005 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002006 } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002007 set_type(affinity_disabled);
2008#if OMP_40_ENABLED
2009 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2010#endif
2011 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002012 } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002013 set_verbose(TRUE);
2014 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002015 } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002016 set_verbose(FALSE);
2017 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002018 } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002019 set_warnings(TRUE);
2020 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002021 } else if (__kmp_match_str("nowarnings", buf,
2022 CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002023 set_warnings(FALSE);
2024 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002025 } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002026 set_respect(TRUE);
2027 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002028 } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002029 set_respect(FALSE);
2030 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002031 } else if (__kmp_match_str("duplicates", buf,
2032 CCAST(const char **, &next)) ||
2033 __kmp_match_str("dups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002034 set_dups(TRUE);
2035 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002036 } else if (__kmp_match_str("noduplicates", buf,
2037 CCAST(const char **, &next)) ||
2038 __kmp_match_str("nodups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002039 set_dups(FALSE);
2040 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002041 } else if (__kmp_match_str("granularity", buf,
2042 CCAST(const char **, &next)) ||
2043 __kmp_match_str("gran", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002044 SKIP_WS(next);
2045 if (*next != '=') {
2046 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2047 continue;
2048 }
2049 next++; // skip '='
2050 SKIP_WS(next);
2051
2052 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002053 if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002054 set_gran(affinity_gran_fine, -1);
2055 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002056 } else if (__kmp_match_str("thread", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002057 set_gran(affinity_gran_thread, -1);
2058 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002059 } else if (__kmp_match_str("core", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002060 set_gran(affinity_gran_core, -1);
2061 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002062 } else if (__kmp_match_str("package", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002063 set_gran(affinity_gran_package, -1);
2064 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002065 } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002066 set_gran(affinity_gran_node, -1);
2067 buf = next;
2068#if KMP_GROUP_AFFINITY
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002069 } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002070 set_gran(affinity_gran_group, -1);
2071 buf = next;
2072#endif /* KMP_GROUP AFFINITY */
2073 } else if ((*buf >= '0') && (*buf <= '9')) {
2074 int n;
2075 next = buf;
2076 SKIP_DIGITS(next);
2077 n = __kmp_str_to_int(buf, *next);
2078 KMP_ASSERT(n >= 0);
2079 buf = next;
2080 set_gran(affinity_gran_default, n);
2081 } else {
2082 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2083 continue;
2084 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002085 } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002086 char *temp_proclist;
2087
2088 SKIP_WS(next);
2089 if (*next != '=') {
2090 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2091 continue;
2092 }
2093 next++; // skip '='
2094 SKIP_WS(next);
2095 if (*next != '[') {
2096 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2097 continue;
2098 }
2099 next++; // skip '['
2100 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002101 if (!__kmp_parse_affinity_proc_id_list(
2102 name, buf, CCAST(const char **, &next), &temp_proclist)) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002103 // warning already emitted.
2104 SKIP_TO(next, ']');
2105 if (*next == ']')
2106 next++;
2107 SKIP_TO(next, ',');
2108 if (*next == ',')
2109 next++;
2110 buf = next;
2111 continue;
2112 }
2113 if (*next != ']') {
2114 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2115 continue;
2116 }
2117 next++; // skip ']'
2118 set_proclist(temp_proclist);
2119 } else if ((*buf >= '0') && (*buf <= '9')) {
2120 // Parse integer numbers -- permute and offset.
2121 int n;
2122 next = buf;
2123 SKIP_DIGITS(next);
2124 n = __kmp_str_to_int(buf, *next);
2125 KMP_ASSERT(n >= 0);
2126 buf = next;
2127 if (count < 2) {
2128 number[count] = n;
2129 } else {
2130 KMP_WARNING(AffManyParams, name, start);
2131 }; // if
2132 ++count;
2133 } else {
2134 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2135 continue;
2136 }
2137
2138 SKIP_WS(next);
2139 if (*next == ',') {
2140 next++;
2141 SKIP_WS(next);
2142 } else if (*next != '\0') {
2143 const char *temp = next;
2144 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2145 continue;
2146 }
2147 buf = next;
2148 } // while
2149
2150#undef EMIT_WARN
2151#undef _set_param
2152#undef set_type
2153#undef set_verbose
2154#undef set_warnings
2155#undef set_respect
2156#undef set_granularity
2157
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002158 __kmp_str_free(CCAST(const char **, &buffer));
Jonathan Peyton30419822017-05-12 18:01:32 +00002159
2160 if (proclist) {
2161 if (!type) {
2162 KMP_WARNING(AffProcListNoType, name);
2163 *out_type = affinity_explicit;
2164#if OMP_40_ENABLED
2165 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2166#endif
2167 } else if (*out_type != affinity_explicit) {
2168 KMP_WARNING(AffProcListNotExplicit, name);
2169 KMP_ASSERT(*out_proclist != NULL);
2170 KMP_INTERNAL_FREE(*out_proclist);
2171 *out_proclist = NULL;
2172 }
2173 }
2174 switch (*out_type) {
2175 case affinity_logical:
2176 case affinity_physical: {
2177 if (count > 0) {
2178 *out_offset = number[0];
2179 }; // if
2180 if (count > 1) {
2181 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
2182 }; // if
2183 } break;
2184 case affinity_balanced: {
2185 if (count > 0) {
2186 *out_compact = number[0];
2187 }; // if
2188 if (count > 1) {
2189 *out_offset = number[1];
2190 }; // if
2191
2192 if (__kmp_affinity_gran == affinity_gran_default) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002193#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002194 if (__kmp_mic_type != non_mic) {
2195 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2196 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine");
2197 }
2198 __kmp_affinity_gran = affinity_gran_fine;
2199 } else
2200#endif
2201 {
2202 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2203 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core");
2204 }
2205 __kmp_affinity_gran = affinity_gran_core;
2206 }
2207 }
2208 } break;
2209 case affinity_scatter:
2210 case affinity_compact: {
2211 if (count > 0) {
2212 *out_compact = number[0];
2213 }; // if
2214 if (count > 1) {
2215 *out_offset = number[1];
2216 }; // if
2217 } break;
2218 case affinity_explicit: {
2219 if (*out_proclist == NULL) {
2220 KMP_WARNING(AffNoProcList, name);
2221 __kmp_affinity_type = affinity_none;
2222 }
2223 if (count > 0) {
2224 KMP_WARNING(AffNoParam, name, "explicit");
2225 }
2226 } break;
2227 case affinity_none: {
2228 if (count > 0) {
2229 KMP_WARNING(AffNoParam, name, "none");
2230 }; // if
2231 } break;
2232 case affinity_disabled: {
2233 if (count > 0) {
2234 KMP_WARNING(AffNoParam, name, "disabled");
2235 }; // if
2236 } break;
2237 case affinity_default: {
2238 if (count > 0) {
2239 KMP_WARNING(AffNoParam, name, "default");
2240 }; // if
2241 } break;
2242 default: { KMP_ASSERT(0); };
2243 }; // switch
Jim Cownie5e8470a2013-09-27 10:38:44 +00002244} // __kmp_parse_affinity_env
2245
Jonathan Peyton30419822017-05-12 18:01:32 +00002246static void __kmp_stg_parse_affinity(char const *name, char const *value,
2247 void *data) {
2248 kmp_setting_t **rivals = (kmp_setting_t **)data;
2249 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002250
Jonathan Peyton30419822017-05-12 18:01:32 +00002251 rc = __kmp_stg_check_rivals(name, value, rivals);
2252 if (rc) {
2253 return;
2254 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002255
Jonathan Peyton30419822017-05-12 18:01:32 +00002256 __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2257 &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2258 &__kmp_affinity_warnings,
2259 &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2260 &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2261 &__kmp_affinity_compact, &__kmp_affinity_offset);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002262
2263} // __kmp_stg_parse_affinity
2264
Jonathan Peyton30419822017-05-12 18:01:32 +00002265static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
2266 void *data) {
2267 if (__kmp_env_format) {
2268 KMP_STR_BUF_PRINT_NAME_EX(name);
2269 } else {
2270 __kmp_str_buf_print(buffer, " %s='", name);
2271 }
2272 if (__kmp_affinity_verbose) {
2273 __kmp_str_buf_print(buffer, "%s,", "verbose");
2274 } else {
2275 __kmp_str_buf_print(buffer, "%s,", "noverbose");
2276 }
2277 if (__kmp_affinity_warnings) {
2278 __kmp_str_buf_print(buffer, "%s,", "warnings");
2279 } else {
2280 __kmp_str_buf_print(buffer, "%s,", "nowarnings");
2281 }
2282 if (KMP_AFFINITY_CAPABLE()) {
2283 if (__kmp_affinity_respect_mask) {
2284 __kmp_str_buf_print(buffer, "%s,", "respect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002285 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002286 __kmp_str_buf_print(buffer, "%s,", "norespect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002287 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002288 switch (__kmp_affinity_gran) {
2289 case affinity_gran_default:
2290 __kmp_str_buf_print(buffer, "%s", "granularity=default,");
2291 break;
2292 case affinity_gran_fine:
2293 __kmp_str_buf_print(buffer, "%s", "granularity=fine,");
2294 break;
2295 case affinity_gran_thread:
2296 __kmp_str_buf_print(buffer, "%s", "granularity=thread,");
2297 break;
2298 case affinity_gran_core:
2299 __kmp_str_buf_print(buffer, "%s", "granularity=core,");
2300 break;
2301 case affinity_gran_package:
2302 __kmp_str_buf_print(buffer, "%s", "granularity=package,");
2303 break;
2304 case affinity_gran_node:
2305 __kmp_str_buf_print(buffer, "%s", "granularity=node,");
2306 break;
2307#if KMP_GROUP_AFFINITY
2308 case affinity_gran_group:
2309 __kmp_str_buf_print(buffer, "%s", "granularity=group,");
2310 break;
2311#endif /* KMP_GROUP_AFFINITY */
2312 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002313 }
2314 if (!KMP_AFFINITY_CAPABLE()) {
2315 __kmp_str_buf_print(buffer, "%s", "disabled");
2316 } else
2317 switch (__kmp_affinity_type) {
2318 case affinity_none:
2319 __kmp_str_buf_print(buffer, "%s", "none");
2320 break;
2321 case affinity_physical:
2322 __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset);
2323 break;
2324 case affinity_logical:
2325 __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset);
2326 break;
2327 case affinity_compact:
2328 __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact,
2329 __kmp_affinity_offset);
2330 break;
2331 case affinity_scatter:
2332 __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact,
2333 __kmp_affinity_offset);
2334 break;
2335 case affinity_explicit:
2336 __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist",
2337 __kmp_affinity_proclist, "explicit");
2338 break;
2339 case affinity_balanced:
2340 __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced",
2341 __kmp_affinity_compact, __kmp_affinity_offset);
2342 break;
2343 case affinity_disabled:
2344 __kmp_str_buf_print(buffer, "%s", "disabled");
2345 break;
2346 case affinity_default:
2347 __kmp_str_buf_print(buffer, "%s", "default");
2348 break;
2349 default:
2350 __kmp_str_buf_print(buffer, "%s", "<unknown>");
2351 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002352 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002353 __kmp_str_buf_print(buffer, "'\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002354} //__kmp_stg_print_affinity
2355
Jonathan Peyton30419822017-05-12 18:01:32 +00002356#ifdef KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00002357
Jonathan Peyton30419822017-05-12 18:01:32 +00002358static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
2359 char const *value, void *data) {
2360 const char *next = NULL;
2361 char *temp_proclist;
2362 kmp_setting_t **rivals = (kmp_setting_t **)data;
2363 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002364
Jonathan Peyton30419822017-05-12 18:01:32 +00002365 rc = __kmp_stg_check_rivals(name, value, rivals);
2366 if (rc) {
2367 return;
2368 }
2369
2370 if (TCR_4(__kmp_init_middle)) {
2371 KMP_WARNING(EnvMiddleWarn, name);
2372 __kmp_env_toPrint(name, 0);
2373 return;
2374 }
2375
2376 __kmp_env_toPrint(name, 1);
2377
2378 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2379 SKIP_WS(next);
2380 if (*next == '\0') {
2381 // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2382 __kmp_affinity_proclist = temp_proclist;
2383 __kmp_affinity_type = affinity_explicit;
2384 __kmp_affinity_gran = affinity_gran_fine;
2385#if OMP_40_ENABLED
2386 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2387#endif
2388 } else {
2389 KMP_WARNING(AffSyntaxError, name);
2390 if (temp_proclist != NULL) {
2391 KMP_INTERNAL_FREE((void *)temp_proclist);
2392 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002393 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002394 } else {
2395 // Warning already emitted
2396 __kmp_affinity_type = affinity_none;
2397#if OMP_40_ENABLED
2398 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2399#endif
2400 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002401} // __kmp_stg_parse_gomp_cpu_affinity
2402
Jonathan Peyton30419822017-05-12 18:01:32 +00002403#endif /* KMP_GOMP_COMPAT */
Jim Cownie5e8470a2013-09-27 10:38:44 +00002404
Jonathan Peyton30419822017-05-12 18:01:32 +00002405#if OMP_40_ENABLED
Jim Cownie5e8470a2013-09-27 10:38:44 +00002406
2407/*-----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00002408The OMP_PLACES proc id list parser. Here is the grammar:
2409
2410place_list := place
2411place_list := place , place_list
2412place := num
2413place := place : num
2414place := place : num : signed
2415place := { subplacelist }
2416place := ! place // (lowest priority)
2417subplace_list := subplace
2418subplace_list := subplace , subplace_list
2419subplace := num
2420subplace := num : num
2421subplace := num : num : signed
2422signed := num
2423signed := + signed
2424signed := - signed
Jim Cownie5e8470a2013-09-27 10:38:44 +00002425-----------------------------------------------------------------------------*/
2426
Jonathan Peyton30419822017-05-12 18:01:32 +00002427static int __kmp_parse_subplace_list(const char *var, const char **scan) {
2428 const char *next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002429
Jonathan Peyton30419822017-05-12 18:01:32 +00002430 for (;;) {
2431 int start, count, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002432
2433 //
Jonathan Peyton30419822017-05-12 18:01:32 +00002434 // Read in the starting proc id
Jim Cownie5e8470a2013-09-27 10:38:44 +00002435 //
2436 SKIP_WS(*scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002437 if ((**scan < '0') || (**scan > '9')) {
2438 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2439 return FALSE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002440 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002441 next = *scan;
2442 SKIP_DIGITS(next);
2443 start = __kmp_str_to_int(*scan, *next);
2444 KMP_ASSERT(start >= 0);
2445 *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002446
Jonathan Peyton30419822017-05-12 18:01:32 +00002447 // valid follow sets are ',' ':' and '}'
2448 SKIP_WS(*scan);
2449 if (**scan == '}') {
2450 break;
2451 }
2452 if (**scan == ',') {
2453 (*scan)++; // skip ','
2454 continue;
2455 }
2456 if (**scan != ':') {
2457 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2458 return FALSE;
2459 }
2460 (*scan)++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002461
Jonathan Peyton30419822017-05-12 18:01:32 +00002462 // Read count parameter
2463 SKIP_WS(*scan);
2464 if ((**scan < '0') || (**scan > '9')) {
2465 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2466 return FALSE;
2467 }
2468 next = *scan;
2469 SKIP_DIGITS(next);
2470 count = __kmp_str_to_int(*scan, *next);
2471 KMP_ASSERT(count >= 0);
2472 *scan = next;
2473
2474 // valid follow sets are ',' ':' and '}'
2475 SKIP_WS(*scan);
2476 if (**scan == '}') {
2477 break;
2478 }
2479 if (**scan == ',') {
2480 (*scan)++; // skip ','
2481 continue;
2482 }
2483 if (**scan != ':') {
2484 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2485 return FALSE;
2486 }
2487 (*scan)++; // skip ':'
2488
2489 // Read stride parameter
2490 int sign = +1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002491 for (;;) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002492 SKIP_WS(*scan);
2493 if (**scan == '+') {
2494 (*scan)++; // skip '+'
2495 continue;
2496 }
2497 if (**scan == '-') {
2498 sign *= -1;
2499 (*scan)++; // skip '-'
2500 continue;
2501 }
2502 break;
2503 }
2504 SKIP_WS(*scan);
2505 if ((**scan < '0') || (**scan > '9')) {
2506 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2507 return FALSE;
2508 }
2509 next = *scan;
2510 SKIP_DIGITS(next);
2511 stride = __kmp_str_to_int(*scan, *next);
2512 KMP_ASSERT(stride >= 0);
2513 *scan = next;
2514 stride *= sign;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002515
Jonathan Peyton30419822017-05-12 18:01:32 +00002516 // valid follow sets are ',' and '}'
2517 SKIP_WS(*scan);
2518 if (**scan == '}') {
2519 break;
2520 }
2521 if (**scan == ',') {
2522 (*scan)++; // skip ','
2523 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002524 }
2525
Jonathan Peyton30419822017-05-12 18:01:32 +00002526 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2527 return FALSE;
2528 }
2529 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002530}
2531
Jonathan Peyton30419822017-05-12 18:01:32 +00002532static int __kmp_parse_place(const char *var, const char **scan) {
2533 const char *next;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002534
Jonathan Peyton30419822017-05-12 18:01:32 +00002535 // valid follow sets are '{' '!' and num
2536 SKIP_WS(*scan);
2537 if (**scan == '{') {
2538 (*scan)++; // skip '{'
2539 if (!__kmp_parse_subplace_list(var, scan)) {
2540 return FALSE;
2541 }
2542 if (**scan != '}') {
2543 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2544 return FALSE;
2545 }
2546 (*scan)++; // skip '}'
2547 } else if (**scan == '!') {
2548 (*scan)++; // skip '!'
2549 return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2550 } else if ((**scan >= '0') && (**scan <= '9')) {
2551 next = *scan;
2552 SKIP_DIGITS(next);
2553 int proc = __kmp_str_to_int(*scan, *next);
2554 KMP_ASSERT(proc >= 0);
2555 *scan = next;
2556 } else {
2557 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2558 return FALSE;
2559 }
2560 return TRUE;
2561}
2562
2563static int __kmp_parse_place_list(const char *var, const char *env,
2564 char **place_list) {
2565 const char *scan = env;
2566 const char *next = scan;
2567
2568 for (;;) {
2569 int start, count, stride;
2570
2571 if (!__kmp_parse_place(var, &scan)) {
2572 return FALSE;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002573 }
2574
Jonathan Peyton30419822017-05-12 18:01:32 +00002575 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002576 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002577 if (*scan == '\0') {
2578 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002579 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002580 if (*scan == ',') {
2581 scan++; // skip ','
2582 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002583 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002584 if (*scan != ':') {
2585 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2586 return FALSE;
2587 }
2588 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002589
Jonathan Peyton30419822017-05-12 18:01:32 +00002590 // Read count parameter
Jim Cownie5e8470a2013-09-27 10:38:44 +00002591 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002592 if ((*scan < '0') || (*scan > '9')) {
2593 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2594 return FALSE;
2595 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002596 next = scan;
2597 SKIP_DIGITS(next);
2598 count = __kmp_str_to_int(scan, *next);
2599 KMP_ASSERT(count >= 0);
2600 scan = next;
2601
Jonathan Peyton30419822017-05-12 18:01:32 +00002602 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002603 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002604 if (*scan == '\0') {
2605 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002606 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002607 if (*scan == ',') {
2608 scan++; // skip ','
2609 continue;
2610 }
2611 if (*scan != ':') {
2612 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2613 return FALSE;
2614 }
2615 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002616
Jonathan Peyton30419822017-05-12 18:01:32 +00002617 // Read stride parameter
2618 int sign = +1;
2619 for (;;) {
2620 SKIP_WS(scan);
2621 if (*scan == '+') {
2622 scan++; // skip '+'
2623 continue;
2624 }
2625 if (*scan == '-') {
2626 sign *= -1;
2627 scan++; // skip '-'
2628 continue;
2629 }
2630 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002631 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002632 SKIP_WS(scan);
2633 if ((*scan < '0') || (*scan > '9')) {
2634 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2635 return FALSE;
2636 }
2637 next = scan;
2638 SKIP_DIGITS(next);
2639 stride = __kmp_str_to_int(scan, *next);
2640 KMP_ASSERT(stride >= 0);
2641 scan = next;
2642 stride *= sign;
2643
2644 // valid follow sets are ',' and EOL
2645 SKIP_WS(scan);
2646 if (*scan == '\0') {
2647 break;
2648 }
2649 if (*scan == ',') {
2650 scan++; // skip ','
2651 continue;
2652 }
2653
2654 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2655 return FALSE;
2656 }
2657
2658 {
2659 int len = scan - env;
2660 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
2661 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
2662 retlist[len] = '\0';
2663 *place_list = retlist;
2664 }
2665 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002666}
2667
Jonathan Peyton30419822017-05-12 18:01:32 +00002668static void __kmp_stg_parse_places(char const *name, char const *value,
2669 void *data) {
2670 int count;
2671 const char *scan = value;
2672 const char *next = scan;
2673 const char *kind = "\"threads\"";
2674 kmp_setting_t **rivals = (kmp_setting_t **)data;
2675 int rc;
2676
2677 rc = __kmp_stg_check_rivals(name, value, rivals);
2678 if (rc) {
2679 return;
2680 }
2681
2682 // If OMP_PROC_BIND is not specified but OMP_PLACES is,
2683 // then let OMP_PROC_BIND default to true.
2684 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2685 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2686 }
2687
2688 //__kmp_affinity_num_places = 0;
2689
2690 if (__kmp_match_str("threads", scan, &next)) {
2691 scan = next;
2692 __kmp_affinity_type = affinity_compact;
2693 __kmp_affinity_gran = affinity_gran_thread;
2694 __kmp_affinity_dups = FALSE;
2695 kind = "\"threads\"";
2696 } else if (__kmp_match_str("cores", scan, &next)) {
2697 scan = next;
2698 __kmp_affinity_type = affinity_compact;
2699 __kmp_affinity_gran = affinity_gran_core;
2700 __kmp_affinity_dups = FALSE;
2701 kind = "\"cores\"";
2702 } else if (__kmp_match_str("sockets", scan, &next)) {
2703 scan = next;
2704 __kmp_affinity_type = affinity_compact;
2705 __kmp_affinity_gran = affinity_gran_package;
2706 __kmp_affinity_dups = FALSE;
2707 kind = "\"sockets\"";
2708 } else {
2709 if (__kmp_affinity_proclist != NULL) {
2710 KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist);
2711 __kmp_affinity_proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002712 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002713 if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2714 __kmp_affinity_type = affinity_explicit;
2715 __kmp_affinity_gran = affinity_gran_fine;
2716 __kmp_affinity_dups = FALSE;
2717 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002718 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
Jonathan Peyton30419822017-05-12 18:01:32 +00002719 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002720 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002721 return;
2722 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002723
Jonathan Peyton30419822017-05-12 18:01:32 +00002724 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2725 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2726 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002727
Jonathan Peyton30419822017-05-12 18:01:32 +00002728 SKIP_WS(scan);
2729 if (*scan == '\0') {
2730 return;
2731 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002732
Jonathan Peyton30419822017-05-12 18:01:32 +00002733 // Parse option count parameter in parentheses
2734 if (*scan != '(') {
2735 KMP_WARNING(SyntaxErrorUsing, name, kind);
2736 return;
2737 }
2738 scan++; // skip '('
Jim Cownie5e8470a2013-09-27 10:38:44 +00002739
Jonathan Peyton30419822017-05-12 18:01:32 +00002740 SKIP_WS(scan);
2741 next = scan;
2742 SKIP_DIGITS(next);
2743 count = __kmp_str_to_int(scan, *next);
2744 KMP_ASSERT(count >= 0);
2745 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002746
Jonathan Peyton30419822017-05-12 18:01:32 +00002747 SKIP_WS(scan);
2748 if (*scan != ')') {
2749 KMP_WARNING(SyntaxErrorUsing, name, kind);
2750 return;
2751 }
2752 scan++; // skip ')'
2753
2754 SKIP_WS(scan);
2755 if (*scan != '\0') {
2756 KMP_WARNING(ParseExtraCharsWarn, name, scan);
2757 }
2758 __kmp_affinity_num_places = count;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002759}
2760
Jonathan Peyton30419822017-05-12 18:01:32 +00002761static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
2762 void *data) {
2763 if (__kmp_env_format) {
2764 KMP_STR_BUF_PRINT_NAME;
2765 } else {
2766 __kmp_str_buf_print(buffer, " %s", name);
2767 }
2768 if ((__kmp_nested_proc_bind.used == 0) ||
2769 (__kmp_nested_proc_bind.bind_types == NULL) ||
2770 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
2771 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2772 } else if (__kmp_affinity_type == affinity_explicit) {
2773 if (__kmp_affinity_proclist != NULL) {
2774 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002775 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002776 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002777 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002778 } else if (__kmp_affinity_type == affinity_compact) {
2779 int num;
2780 if (__kmp_affinity_num_masks > 0) {
2781 num = __kmp_affinity_num_masks;
2782 } else if (__kmp_affinity_num_places > 0) {
2783 num = __kmp_affinity_num_places;
2784 } else {
2785 num = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002786 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002787 if (__kmp_affinity_gran == affinity_gran_thread) {
2788 if (num > 0) {
2789 __kmp_str_buf_print(buffer, "='threads(%d)'\n", num);
2790 } else {
2791 __kmp_str_buf_print(buffer, "='threads'\n");
2792 }
2793 } else if (__kmp_affinity_gran == affinity_gran_core) {
2794 if (num > 0) {
2795 __kmp_str_buf_print(buffer, "='cores(%d)' \n", num);
2796 } else {
2797 __kmp_str_buf_print(buffer, "='cores'\n");
2798 }
2799 } else if (__kmp_affinity_gran == affinity_gran_package) {
2800 if (num > 0) {
2801 __kmp_str_buf_print(buffer, "='sockets(%d)'\n", num);
2802 } else {
2803 __kmp_str_buf_print(buffer, "='sockets'\n");
2804 }
2805 } else {
2806 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002807 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002808 } else {
2809 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2810 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002811}
2812
2813#endif /* OMP_40_ENABLED */
2814
Jonathan Peyton30419822017-05-12 18:01:32 +00002815#if (!OMP_40_ENABLED)
Jim Cownie5e8470a2013-09-27 10:38:44 +00002816
Jonathan Peyton30419822017-05-12 18:01:32 +00002817static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
2818 void *data) {
2819 int enabled;
2820 kmp_setting_t **rivals = (kmp_setting_t **)data;
2821 int rc;
2822
2823 rc = __kmp_stg_check_rivals(name, value, rivals);
2824 if (rc) {
2825 return;
2826 }
2827
2828 // In OMP 3.1, OMP_PROC_BIND is strictly a boolean
2829 __kmp_stg_parse_bool(name, value, &enabled);
2830 if (enabled) {
2831 // OMP_PROC_BIND => granularity=fine,scatter on MIC
2832 // OMP_PROC_BIND => granularity=core,scatter elsewhere
2833 __kmp_affinity_type = affinity_scatter;
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002834#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002835 if (__kmp_mic_type != non_mic)
2836 __kmp_affinity_gran = affinity_gran_fine;
2837 else
2838#endif
2839 __kmp_affinity_gran = affinity_gran_core;
2840 } else {
2841 __kmp_affinity_type = affinity_none;
2842 }
2843} // __kmp_parse_proc_bind
2844
2845#endif /* if (! OMP_40_ENABLED) */
2846
2847static void __kmp_stg_parse_topology_method(char const *name, char const *value,
2848 void *data) {
2849 if (__kmp_str_match("all", 1, value)) {
2850 __kmp_affinity_top_method = affinity_top_method_all;
2851 }
2852#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2853 else if (__kmp_str_match("x2apic id", 9, value) ||
2854 __kmp_str_match("x2apic_id", 9, value) ||
2855 __kmp_str_match("x2apic-id", 9, value) ||
2856 __kmp_str_match("x2apicid", 8, value) ||
2857 __kmp_str_match("cpuid leaf 11", 13, value) ||
2858 __kmp_str_match("cpuid_leaf_11", 13, value) ||
2859 __kmp_str_match("cpuid-leaf-11", 13, value) ||
2860 __kmp_str_match("cpuid leaf11", 12, value) ||
2861 __kmp_str_match("cpuid_leaf11", 12, value) ||
2862 __kmp_str_match("cpuid-leaf11", 12, value) ||
2863 __kmp_str_match("cpuidleaf 11", 12, value) ||
2864 __kmp_str_match("cpuidleaf_11", 12, value) ||
2865 __kmp_str_match("cpuidleaf-11", 12, value) ||
2866 __kmp_str_match("cpuidleaf11", 11, value) ||
2867 __kmp_str_match("cpuid 11", 8, value) ||
2868 __kmp_str_match("cpuid_11", 8, value) ||
2869 __kmp_str_match("cpuid-11", 8, value) ||
2870 __kmp_str_match("cpuid11", 7, value) ||
2871 __kmp_str_match("leaf 11", 7, value) ||
2872 __kmp_str_match("leaf_11", 7, value) ||
2873 __kmp_str_match("leaf-11", 7, value) ||
2874 __kmp_str_match("leaf11", 6, value)) {
2875 __kmp_affinity_top_method = affinity_top_method_x2apicid;
2876 } else if (__kmp_str_match("apic id", 7, value) ||
2877 __kmp_str_match("apic_id", 7, value) ||
2878 __kmp_str_match("apic-id", 7, value) ||
2879 __kmp_str_match("apicid", 6, value) ||
2880 __kmp_str_match("cpuid leaf 4", 12, value) ||
2881 __kmp_str_match("cpuid_leaf_4", 12, value) ||
2882 __kmp_str_match("cpuid-leaf-4", 12, value) ||
2883 __kmp_str_match("cpuid leaf4", 11, value) ||
2884 __kmp_str_match("cpuid_leaf4", 11, value) ||
2885 __kmp_str_match("cpuid-leaf4", 11, value) ||
2886 __kmp_str_match("cpuidleaf 4", 11, value) ||
2887 __kmp_str_match("cpuidleaf_4", 11, value) ||
2888 __kmp_str_match("cpuidleaf-4", 11, value) ||
2889 __kmp_str_match("cpuidleaf4", 10, value) ||
2890 __kmp_str_match("cpuid 4", 7, value) ||
2891 __kmp_str_match("cpuid_4", 7, value) ||
2892 __kmp_str_match("cpuid-4", 7, value) ||
2893 __kmp_str_match("cpuid4", 6, value) ||
2894 __kmp_str_match("leaf 4", 6, value) ||
2895 __kmp_str_match("leaf_4", 6, value) ||
2896 __kmp_str_match("leaf-4", 6, value) ||
2897 __kmp_str_match("leaf4", 5, value)) {
2898 __kmp_affinity_top_method = affinity_top_method_apicid;
2899 }
2900#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2901 else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
2902 __kmp_str_match("cpuinfo", 5, value)) {
2903 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
2904 }
2905#if KMP_GROUP_AFFINITY
2906 else if (__kmp_str_match("group", 1, value)) {
2907 __kmp_affinity_top_method = affinity_top_method_group;
2908 }
2909#endif /* KMP_GROUP_AFFINITY */
2910 else if (__kmp_str_match("flat", 1, value)) {
2911 __kmp_affinity_top_method = affinity_top_method_flat;
2912 }
2913#if KMP_USE_HWLOC
2914 else if (__kmp_str_match("hwloc", 1, value)) {
2915 __kmp_affinity_top_method = affinity_top_method_hwloc;
2916 }
2917#endif
2918 else {
2919 KMP_WARNING(StgInvalidValue, name, value);
2920 }
2921} // __kmp_stg_parse_topology_method
2922
2923static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
2924 char const *name, void *data) {
2925#if KMP_DEBUG
2926 char const *value = NULL;
2927
2928 switch (__kmp_affinity_top_method) {
2929 case affinity_top_method_default:
2930 value = "default";
2931 break;
2932
2933 case affinity_top_method_all:
2934 value = "all";
2935 break;
2936
2937#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2938 case affinity_top_method_x2apicid:
2939 value = "x2APIC id";
2940 break;
2941
2942 case affinity_top_method_apicid:
2943 value = "APIC id";
2944 break;
2945#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2946
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002947#if KMP_USE_HWLOC
Jonathan Peyton30419822017-05-12 18:01:32 +00002948 case affinity_top_method_hwloc:
2949 value = "hwloc";
2950 break;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002951#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00002952
2953 case affinity_top_method_cpuinfo:
2954 value = "cpuinfo";
2955 break;
2956
2957#if KMP_GROUP_AFFINITY
2958 case affinity_top_method_group:
2959 value = "group";
2960 break;
2961#endif /* KMP_GROUP_AFFINITY */
2962
2963 case affinity_top_method_flat:
2964 value = "flat";
2965 break;
2966 }
2967
2968 if (value != NULL) {
2969 __kmp_stg_print_str(buffer, name, value);
2970 }
2971#endif /* KMP_DEBUG */
2972} // __kmp_stg_print_topology_method
2973
2974#endif /* KMP_AFFINITY_SUPPORTED */
2975
2976#if OMP_40_ENABLED
2977
2978// OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
2979// OMP_PLACES / place-partition-var is not.
2980static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
2981 void *data) {
2982 kmp_setting_t **rivals = (kmp_setting_t **)data;
2983 int rc;
2984
2985 rc = __kmp_stg_check_rivals(name, value, rivals);
2986 if (rc) {
2987 return;
2988 }
2989
2990 // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
2991 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
2992 (__kmp_nested_proc_bind.used > 0));
2993
2994 const char *buf = value;
2995 const char *next;
2996 int num;
2997 SKIP_WS(buf);
2998 if ((*buf >= '0') && (*buf <= '9')) {
2999 next = buf;
3000 SKIP_DIGITS(next);
3001 num = __kmp_str_to_int(buf, *next);
3002 KMP_ASSERT(num >= 0);
3003 buf = next;
3004 SKIP_WS(buf);
3005 } else {
3006 num = -1;
3007 }
3008
3009 next = buf;
3010 if (__kmp_match_str("disabled", buf, &next)) {
3011 buf = next;
3012 SKIP_WS(buf);
3013#if KMP_AFFINITY_SUPPORTED
3014 __kmp_affinity_type = affinity_disabled;
3015#endif /* KMP_AFFINITY_SUPPORTED */
3016 __kmp_nested_proc_bind.used = 1;
3017 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3018 } else if ((num == (int)proc_bind_false) ||
3019 __kmp_match_str("false", buf, &next)) {
3020 buf = next;
3021 SKIP_WS(buf);
3022#if KMP_AFFINITY_SUPPORTED
3023 __kmp_affinity_type = affinity_none;
3024#endif /* KMP_AFFINITY_SUPPORTED */
3025 __kmp_nested_proc_bind.used = 1;
3026 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3027 } else if ((num == (int)proc_bind_true) ||
3028 __kmp_match_str("true", buf, &next)) {
3029 buf = next;
3030 SKIP_WS(buf);
3031 __kmp_nested_proc_bind.used = 1;
3032 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3033 } else {
3034 // Count the number of values in the env var string
3035 const char *scan;
3036 int nelem = 1;
3037 for (scan = buf; *scan != '\0'; scan++) {
3038 if (*scan == ',') {
3039 nelem++;
3040 }
3041 }
3042
3043 // Create / expand the nested proc_bind array as needed
3044 if (__kmp_nested_proc_bind.size < nelem) {
3045 __kmp_nested_proc_bind.bind_types =
3046 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3047 __kmp_nested_proc_bind.bind_types,
3048 sizeof(kmp_proc_bind_t) * nelem);
3049 if (__kmp_nested_proc_bind.bind_types == NULL) {
3050 KMP_FATAL(MemoryAllocFailed);
3051 }
3052 __kmp_nested_proc_bind.size = nelem;
3053 }
3054 __kmp_nested_proc_bind.used = nelem;
3055
3056 // Save values in the nested proc_bind array
3057 int i = 0;
3058 for (;;) {
3059 enum kmp_proc_bind_t bind;
3060
3061 if ((num == (int)proc_bind_master) ||
3062 __kmp_match_str("master", buf, &next)) {
3063 buf = next;
3064 SKIP_WS(buf);
3065 bind = proc_bind_master;
3066 } else if ((num == (int)proc_bind_close) ||
3067 __kmp_match_str("close", buf, &next)) {
3068 buf = next;
3069 SKIP_WS(buf);
3070 bind = proc_bind_close;
3071 } else if ((num == (int)proc_bind_spread) ||
3072 __kmp_match_str("spread", buf, &next)) {
3073 buf = next;
3074 SKIP_WS(buf);
3075 bind = proc_bind_spread;
3076 } else {
3077 KMP_WARNING(StgInvalidValue, name, value);
3078 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3079 __kmp_nested_proc_bind.used = 1;
3080 return;
3081 }
3082
3083 __kmp_nested_proc_bind.bind_types[i++] = bind;
3084 if (i >= nelem) {
3085 break;
3086 }
3087 KMP_DEBUG_ASSERT(*buf == ',');
3088 buf++;
3089 SKIP_WS(buf);
3090
3091 // Read next value if it was specified as an integer
3092 if ((*buf >= '0') && (*buf <= '9')) {
3093 next = buf;
3094 SKIP_DIGITS(next);
3095 num = __kmp_str_to_int(buf, *next);
3096 KMP_ASSERT(num >= 0);
3097 buf = next;
3098 SKIP_WS(buf);
3099 } else {
3100 num = -1;
3101 }
3102 }
3103 SKIP_WS(buf);
3104 }
3105 if (*buf != '\0') {
3106 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3107 }
3108}
3109
3110static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
3111 void *data) {
3112 int nelem = __kmp_nested_proc_bind.used;
3113 if (__kmp_env_format) {
3114 KMP_STR_BUF_PRINT_NAME;
3115 } else {
3116 __kmp_str_buf_print(buffer, " %s", name);
3117 }
3118 if (nelem == 0) {
3119 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3120 } else {
3121 int i;
3122 __kmp_str_buf_print(buffer, "='", name);
3123 for (i = 0; i < nelem; i++) {
3124 switch (__kmp_nested_proc_bind.bind_types[i]) {
3125 case proc_bind_false:
3126 __kmp_str_buf_print(buffer, "false");
3127 break;
3128
3129 case proc_bind_true:
3130 __kmp_str_buf_print(buffer, "true");
3131 break;
3132
3133 case proc_bind_master:
3134 __kmp_str_buf_print(buffer, "master");
3135 break;
3136
3137 case proc_bind_close:
3138 __kmp_str_buf_print(buffer, "close");
3139 break;
3140
3141 case proc_bind_spread:
3142 __kmp_str_buf_print(buffer, "spread");
3143 break;
3144
3145 case proc_bind_intel:
3146 __kmp_str_buf_print(buffer, "intel");
3147 break;
3148
3149 case proc_bind_default:
3150 __kmp_str_buf_print(buffer, "default");
3151 break;
3152 }
3153 if (i < nelem - 1) {
3154 __kmp_str_buf_print(buffer, ",");
3155 }
3156 }
3157 __kmp_str_buf_print(buffer, "'\n");
3158 }
3159}
3160
3161#endif /* OMP_40_ENABLED */
3162
3163// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003164// OMP_DYNAMIC
Jim Cownie5e8470a2013-09-27 10:38:44 +00003165
Jonathan Peyton30419822017-05-12 18:01:32 +00003166static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
3167 void *data) {
3168 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003169} // __kmp_stg_parse_omp_dynamic
3170
Jonathan Peyton30419822017-05-12 18:01:32 +00003171static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
3172 void *data) {
3173 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003174} // __kmp_stg_print_omp_dynamic
3175
Jonathan Peyton30419822017-05-12 18:01:32 +00003176static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
3177 char const *value, void *data) {
3178 if (TCR_4(__kmp_init_parallel)) {
3179 KMP_WARNING(EnvParallelWarn, name);
3180 __kmp_env_toPrint(name, 0);
3181 return;
3182 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003183#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00003184 else if (__kmp_str_match("load balance", 2, value) ||
3185 __kmp_str_match("load_balance", 2, value) ||
3186 __kmp_str_match("load-balance", 2, value) ||
3187 __kmp_str_match("loadbalance", 2, value) ||
3188 __kmp_str_match("balance", 1, value)) {
3189 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3190 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003191#endif /* USE_LOAD_BALANCE */
Jonathan Peyton30419822017-05-12 18:01:32 +00003192 else if (__kmp_str_match("thread limit", 1, value) ||
3193 __kmp_str_match("thread_limit", 1, value) ||
3194 __kmp_str_match("thread-limit", 1, value) ||
3195 __kmp_str_match("threadlimit", 1, value) ||
3196 __kmp_str_match("limit", 2, value)) {
3197 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3198 } else if (__kmp_str_match("random", 1, value)) {
3199 __kmp_global.g.g_dynamic_mode = dynamic_random;
3200 } else {
3201 KMP_WARNING(StgInvalidValue, name, value);
3202 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003203} //__kmp_stg_parse_kmp_dynamic_mode
3204
Jonathan Peyton30419822017-05-12 18:01:32 +00003205static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
3206 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003207#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003208 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
3209 __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
3210 }
3211#ifdef USE_LOAD_BALANCE
3212 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
3213 __kmp_stg_print_str(buffer, name, "load balance");
3214 }
3215#endif /* USE_LOAD_BALANCE */
3216 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
3217 __kmp_stg_print_str(buffer, name, "thread limit");
3218 } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
3219 __kmp_stg_print_str(buffer, name, "random");
3220 } else {
3221 KMP_ASSERT(0);
3222 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003223#endif /* KMP_DEBUG */
3224} // __kmp_stg_print_kmp_dynamic_mode
3225
Jim Cownie5e8470a2013-09-27 10:38:44 +00003226#ifdef USE_LOAD_BALANCE
3227
Jonathan Peyton30419822017-05-12 18:01:32 +00003228// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003229// KMP_LOAD_BALANCE_INTERVAL
Jim Cownie5e8470a2013-09-27 10:38:44 +00003230
Jonathan Peyton30419822017-05-12 18:01:32 +00003231static void __kmp_stg_parse_ld_balance_interval(char const *name,
3232 char const *value, void *data) {
3233 double interval = __kmp_convert_to_double(value);
3234 if (interval >= 0) {
3235 __kmp_load_balance_interval = interval;
3236 } else {
3237 KMP_WARNING(StgInvalidValue, name, value);
3238 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003239} // __kmp_stg_parse_load_balance_interval
3240
Jonathan Peyton30419822017-05-12 18:01:32 +00003241static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
3242 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003243#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003244 __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
3245 __kmp_load_balance_interval);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003246#endif /* KMP_DEBUG */
3247} // __kmp_stg_print_load_balance_interval
3248
3249#endif /* USE_LOAD_BALANCE */
3250
Jonathan Peyton30419822017-05-12 18:01:32 +00003251// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003252// KMP_INIT_AT_FORK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003253
Jonathan Peyton30419822017-05-12 18:01:32 +00003254static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
3255 void *data) {
3256 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
3257 if (__kmp_need_register_atfork) {
3258 __kmp_need_register_atfork_specified = TRUE;
3259 };
Jim Cownie5e8470a2013-09-27 10:38:44 +00003260} // __kmp_stg_parse_init_at_fork
3261
Jonathan Peyton30419822017-05-12 18:01:32 +00003262static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
3263 char const *name, void *data) {
3264 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003265} // __kmp_stg_print_init_at_fork
3266
Jonathan Peyton30419822017-05-12 18:01:32 +00003267// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003268// KMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003269
Jonathan Peyton30419822017-05-12 18:01:32 +00003270static void __kmp_stg_parse_schedule(char const *name, char const *value,
3271 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003272
Jonathan Peyton30419822017-05-12 18:01:32 +00003273 if (value != NULL) {
3274 size_t length = KMP_STRLEN(value);
3275 if (length > INT_MAX) {
3276 KMP_WARNING(LongValue, name);
3277 } else {
3278 char *semicolon;
3279 if (value[length - 1] == '"' || value[length - 1] == '\'')
3280 KMP_WARNING(UnbalancedQuotes, name);
3281 do {
3282 char sentinel;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003283
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003284 semicolon = CCAST(char *, strchr(value, ';'));
Jonathan Peyton30419822017-05-12 18:01:32 +00003285 if (*value && semicolon != value) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003286 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003287
Jonathan Peyton30419822017-05-12 18:01:32 +00003288 if (comma) {
3289 ++comma;
3290 sentinel = ',';
3291 } else
3292 sentinel = ';';
3293 if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
3294 if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
3295 __kmp_static = kmp_sch_static_greedy;
3296 continue;
3297 } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
3298 ';')) {
3299 __kmp_static = kmp_sch_static_balanced;
3300 continue;
3301 }
3302 } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3303 sentinel)) {
3304 if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
3305 __kmp_guided = kmp_sch_guided_iterative_chunked;
3306 continue;
3307 } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
3308 ';')) {
3309 /* analytical not allowed for too many threads */
3310 __kmp_guided = kmp_sch_guided_analytical_chunked;
3311 continue;
3312 }
3313 }
3314 KMP_WARNING(InvalidClause, name, value);
3315 } else
3316 KMP_WARNING(EmptyClause, name);
3317 } while ((value = semicolon ? semicolon + 1 : NULL));
3318 }
3319 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003320
3321} // __kmp_stg_parse__schedule
3322
Jonathan Peyton30419822017-05-12 18:01:32 +00003323static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
3324 void *data) {
3325 if (__kmp_env_format) {
3326 KMP_STR_BUF_PRINT_NAME_EX(name);
3327 } else {
3328 __kmp_str_buf_print(buffer, " %s='", name);
3329 }
3330 if (__kmp_static == kmp_sch_static_greedy) {
3331 __kmp_str_buf_print(buffer, "%s", "static,greedy");
3332 } else if (__kmp_static == kmp_sch_static_balanced) {
3333 __kmp_str_buf_print(buffer, "%s", "static,balanced");
3334 }
3335 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
3336 __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
3337 } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
3338 __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
3339 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003340} // __kmp_stg_print_schedule
3341
Jonathan Peyton30419822017-05-12 18:01:32 +00003342// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003343// OMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003344
Jonathan Peyton30419822017-05-12 18:01:32 +00003345static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
3346 void *data) {
3347 size_t length;
3348 if (value) {
3349 length = KMP_STRLEN(value);
3350 if (length) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003351 char *comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00003352 if (value[length - 1] == '"' || value[length - 1] == '\'')
3353 KMP_WARNING(UnbalancedQuotes, name);
3354 /* get the specified scheduling style */
3355 if (!__kmp_strcasecmp_with_sentinel("dynamic", value, ',')) /* DYNAMIC */
3356 __kmp_sched = kmp_sch_dynamic_chunked;
3357 else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3358 ',')) /* GUIDED */
3359 __kmp_sched = kmp_sch_guided_chunked;
3360 // AC: TODO: add AUTO schedule, and pprobably remove TRAPEZOIDAL (OMP 3.0
3361 // does not allow it)
3362 else if (!__kmp_strcasecmp_with_sentinel("auto", value, ',')) { /* AUTO */
3363 __kmp_sched = kmp_sch_auto;
3364 if (comma) {
3365 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, comma),
3366 __kmp_msg_null);
3367 comma = NULL;
3368 }
3369 } else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", value,
3370 ',')) /* TRAPEZOIDAL */
3371 __kmp_sched = kmp_sch_trapezoidal;
3372 else if (!__kmp_strcasecmp_with_sentinel("static", value,
3373 ',')) /* STATIC */
3374 __kmp_sched = kmp_sch_static;
Andrey Churbanov429dbc22016-07-11 10:44:57 +00003375#if KMP_STATIC_STEAL_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00003376 else if (!__kmp_strcasecmp_with_sentinel("static_steal", value, ','))
3377 __kmp_sched = kmp_sch_static_steal;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003378#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003379 else {
3380 KMP_WARNING(StgInvalidValue, name, value);
3381 value = NULL; /* skip processing of comma */
3382 }
3383 if (value && comma) {
3384 __kmp_env_chunk = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003385
Jonathan Peyton30419822017-05-12 18:01:32 +00003386 if (__kmp_sched == kmp_sch_static)
3387 __kmp_sched = kmp_sch_static_chunked;
3388 ++comma;
3389 __kmp_chunk = __kmp_str_to_int(comma, 0);
3390 if (__kmp_chunk < 1) {
3391 __kmp_chunk = KMP_DEFAULT_CHUNK;
3392 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, comma),
3393 __kmp_msg_null);
3394 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3395 // AC: next block commented out until KMP_DEFAULT_CHUNK !=
3396 // KMP_MIN_CHUNK (to improve code coverage :)
3397 // The default chunk size is 1 according to standard, thus making
3398 // KMP_MIN_CHUNK not 1 we would introduce mess:
3399 // wrong chunk becomes 1, but it will be impossible to explicitely
3400 // set 1, because it becomes KMP_MIN_CHUNK...
3401 // } else if ( __kmp_chunk < KMP_MIN_CHUNK ) {
3402 // __kmp_chunk = KMP_MIN_CHUNK;
3403 } else if (__kmp_chunk > KMP_MAX_CHUNK) {
3404 __kmp_chunk = KMP_MAX_CHUNK;
3405 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, comma),
3406 __kmp_msg_null);
3407 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3408 }
3409 } else
3410 __kmp_env_chunk = FALSE;
3411 } else
3412 KMP_WARNING(EmptyString, name);
3413 }
3414 K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
3415 K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
3416 K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
3417 K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
Jim Cownie5e8470a2013-09-27 10:38:44 +00003418} // __kmp_stg_parse_omp_schedule
3419
Jonathan Peyton30419822017-05-12 18:01:32 +00003420static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
3421 char const *name, void *data) {
3422 if (__kmp_env_format) {
3423 KMP_STR_BUF_PRINT_NAME_EX(name);
3424 } else {
3425 __kmp_str_buf_print(buffer, " %s='", name);
3426 }
3427 if (__kmp_chunk) {
3428 switch (__kmp_sched) {
3429 case kmp_sch_dynamic_chunked:
3430 __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
3431 break;
3432 case kmp_sch_guided_iterative_chunked:
3433 case kmp_sch_guided_analytical_chunked:
3434 __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
3435 break;
3436 case kmp_sch_trapezoidal:
3437 __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
3438 break;
3439 case kmp_sch_static:
3440 case kmp_sch_static_chunked:
3441 case kmp_sch_static_balanced:
3442 case kmp_sch_static_greedy:
3443 __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
3444 break;
3445 case kmp_sch_static_steal:
3446 __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
3447 break;
3448 case kmp_sch_auto:
3449 __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
3450 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003451 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003452 } else {
3453 switch (__kmp_sched) {
3454 case kmp_sch_dynamic_chunked:
3455 __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
3456 break;
3457 case kmp_sch_guided_iterative_chunked:
3458 case kmp_sch_guided_analytical_chunked:
3459 __kmp_str_buf_print(buffer, "%s'\n", "guided");
3460 break;
3461 case kmp_sch_trapezoidal:
3462 __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
3463 break;
3464 case kmp_sch_static:
3465 case kmp_sch_static_chunked:
3466 case kmp_sch_static_balanced:
3467 case kmp_sch_static_greedy:
3468 __kmp_str_buf_print(buffer, "%s'\n", "static");
3469 break;
3470 case kmp_sch_static_steal:
3471 __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
3472 break;
3473 case kmp_sch_auto:
3474 __kmp_str_buf_print(buffer, "%s'\n", "auto");
3475 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003476 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003477 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003478} // __kmp_stg_print_omp_schedule
3479
Jonathan Peyton30419822017-05-12 18:01:32 +00003480// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003481// KMP_ATOMIC_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003482
Jonathan Peyton30419822017-05-12 18:01:32 +00003483static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
3484 void *data) {
3485 // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
3486 // compatibility mode.
3487 int mode = 0;
3488 int max = 1;
3489#ifdef KMP_GOMP_COMPAT
3490 max = 2;
3491#endif /* KMP_GOMP_COMPAT */
3492 __kmp_stg_parse_int(name, value, 0, max, &mode);
3493 // TODO; parse_int is not very suitable for this case. In case of overflow it
3494 // is better to use
3495 // 0 rather that max value.
3496 if (mode > 0) {
3497 __kmp_atomic_mode = mode;
3498 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003499} // __kmp_stg_parse_atomic_mode
3500
Jonathan Peyton30419822017-05-12 18:01:32 +00003501static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
3502 void *data) {
3503 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003504} // __kmp_stg_print_atomic_mode
3505
Jonathan Peyton30419822017-05-12 18:01:32 +00003506// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003507// KMP_CONSISTENCY_CHECK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003508
Jonathan Peyton30419822017-05-12 18:01:32 +00003509static void __kmp_stg_parse_consistency_check(char const *name,
3510 char const *value, void *data) {
3511 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
3512 // Note, this will not work from kmp_set_defaults because th_cons stack was
3513 // not allocated
3514 // for existed thread(s) thus the first __kmp_push_<construct> will break
3515 // with assertion.
3516 // TODO: allocate th_cons if called from kmp_set_defaults.
3517 __kmp_env_consistency_check = TRUE;
3518 } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
3519 __kmp_env_consistency_check = FALSE;
3520 } else {
3521 KMP_WARNING(StgInvalidValue, name, value);
3522 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003523} // __kmp_stg_parse_consistency_check
3524
Jonathan Peyton30419822017-05-12 18:01:32 +00003525static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
3526 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003527#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003528 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003529
Jonathan Peyton30419822017-05-12 18:01:32 +00003530 if (__kmp_env_consistency_check) {
3531 value = "all";
3532 } else {
3533 value = "none";
3534 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003535
Jonathan Peyton30419822017-05-12 18:01:32 +00003536 if (value != NULL) {
3537 __kmp_stg_print_str(buffer, name, value);
3538 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003539#endif /* KMP_DEBUG */
3540} // __kmp_stg_print_consistency_check
3541
Jim Cownie5e8470a2013-09-27 10:38:44 +00003542#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00003543// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003544// KMP_ITT_PREPARE_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00003545
3546#if USE_ITT_NOTIFY
3547
Jonathan Peyton30419822017-05-12 18:01:32 +00003548static void __kmp_stg_parse_itt_prepare_delay(char const *name,
3549 char const *value, void *data) {
3550 // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
3551 // iterations.
3552 int delay = 0;
3553 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
3554 __kmp_itt_prepare_delay = delay;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003555} // __kmp_str_parse_itt_prepare_delay
3556
Jonathan Peyton30419822017-05-12 18:01:32 +00003557static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
3558 char const *name, void *data) {
3559 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003560
3561} // __kmp_str_print_itt_prepare_delay
3562
3563#endif // USE_ITT_NOTIFY
3564#endif /* USE_ITT_BUILD */
3565
Jonathan Peyton30419822017-05-12 18:01:32 +00003566// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003567// KMP_MALLOC_POOL_INCR
Jim Cownie5e8470a2013-09-27 10:38:44 +00003568
Jonathan Peyton30419822017-05-12 18:01:32 +00003569static void __kmp_stg_parse_malloc_pool_incr(char const *name,
3570 char const *value, void *data) {
3571 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
3572 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
3573 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003574} // __kmp_stg_parse_malloc_pool_incr
3575
Jonathan Peyton30419822017-05-12 18:01:32 +00003576static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
3577 char const *name, void *data) {
3578 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003579
3580} // _kmp_stg_print_malloc_pool_incr
3581
Jim Cownie5e8470a2013-09-27 10:38:44 +00003582#ifdef KMP_DEBUG
3583
Jonathan Peyton30419822017-05-12 18:01:32 +00003584// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003585// KMP_PAR_RANGE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003586
Jonathan Peyton30419822017-05-12 18:01:32 +00003587static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
3588 void *data) {
3589 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
3590 __kmp_par_range_routine, __kmp_par_range_filename,
3591 &__kmp_par_range_lb, &__kmp_par_range_ub);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003592} // __kmp_stg_parse_par_range_env
3593
Jonathan Peyton30419822017-05-12 18:01:32 +00003594static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
3595 char const *name, void *data) {
3596 if (__kmp_par_range != 0) {
3597 __kmp_stg_print_str(buffer, name, par_range_to_print);
3598 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003599} // __kmp_stg_print_par_range_env
3600
Jonathan Peyton30419822017-05-12 18:01:32 +00003601// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003602// KMP_YIELD_CYCLE, KMP_YIELD_ON, KMP_YIELD_OFF
Jim Cownie5e8470a2013-09-27 10:38:44 +00003603
Jonathan Peyton30419822017-05-12 18:01:32 +00003604static void __kmp_stg_parse_yield_cycle(char const *name, char const *value,
3605 void *data) {
3606 int flag = __kmp_yield_cycle;
3607 __kmp_stg_parse_bool(name, value, &flag);
3608 __kmp_yield_cycle = flag;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003609} // __kmp_stg_parse_yield_cycle
3610
Jonathan Peyton30419822017-05-12 18:01:32 +00003611static void __kmp_stg_print_yield_cycle(kmp_str_buf_t *buffer, char const *name,
3612 void *data) {
3613 __kmp_stg_print_bool(buffer, name, __kmp_yield_cycle);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003614} // __kmp_stg_print_yield_cycle
3615
Jonathan Peyton30419822017-05-12 18:01:32 +00003616static void __kmp_stg_parse_yield_on(char const *name, char const *value,
3617 void *data) {
3618 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003619} // __kmp_stg_parse_yield_on
3620
Jonathan Peyton30419822017-05-12 18:01:32 +00003621static void __kmp_stg_print_yield_on(kmp_str_buf_t *buffer, char const *name,
3622 void *data) {
3623 __kmp_stg_print_int(buffer, name, __kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003624} // __kmp_stg_print_yield_on
3625
Jonathan Peyton30419822017-05-12 18:01:32 +00003626static void __kmp_stg_parse_yield_off(char const *name, char const *value,
3627 void *data) {
3628 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003629} // __kmp_stg_parse_yield_off
3630
Jonathan Peyton30419822017-05-12 18:01:32 +00003631static void __kmp_stg_print_yield_off(kmp_str_buf_t *buffer, char const *name,
3632 void *data) {
3633 __kmp_stg_print_int(buffer, name, __kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003634} // __kmp_stg_print_yield_off
3635
3636#endif
3637
Jonathan Peyton30419822017-05-12 18:01:32 +00003638// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003639// KMP_INIT_WAIT, KMP_NEXT_WAIT
Jim Cownie5e8470a2013-09-27 10:38:44 +00003640
Jonathan Peyton30419822017-05-12 18:01:32 +00003641static void __kmp_stg_parse_init_wait(char const *name, char const *value,
3642 void *data) {
3643 int wait;
3644 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3645 wait = __kmp_init_wait / 2;
3646 __kmp_stg_parse_int(name, value, KMP_MIN_INIT_WAIT, KMP_MAX_INIT_WAIT, &wait);
3647 __kmp_init_wait = wait * 2;
3648 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3649 __kmp_yield_init = __kmp_init_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003650} // __kmp_stg_parse_init_wait
3651
Jonathan Peyton30419822017-05-12 18:01:32 +00003652static void __kmp_stg_print_init_wait(kmp_str_buf_t *buffer, char const *name,
3653 void *data) {
3654 __kmp_stg_print_int(buffer, name, __kmp_init_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003655} // __kmp_stg_print_init_wait
3656
Jonathan Peyton30419822017-05-12 18:01:32 +00003657static void __kmp_stg_parse_next_wait(char const *name, char const *value,
3658 void *data) {
3659 int wait;
3660 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3661 wait = __kmp_next_wait / 2;
3662 __kmp_stg_parse_int(name, value, KMP_MIN_NEXT_WAIT, KMP_MAX_NEXT_WAIT, &wait);
3663 __kmp_next_wait = wait * 2;
3664 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3665 __kmp_yield_next = __kmp_next_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003666} // __kmp_stg_parse_next_wait
3667
Jonathan Peyton30419822017-05-12 18:01:32 +00003668static void __kmp_stg_print_next_wait(kmp_str_buf_t *buffer, char const *name,
3669 void *data) {
3670 __kmp_stg_print_int(buffer, name, __kmp_next_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003671} //__kmp_stg_print_next_wait
3672
Jonathan Peyton30419822017-05-12 18:01:32 +00003673// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003674// KMP_GTID_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003675
Jonathan Peyton30419822017-05-12 18:01:32 +00003676static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
3677 void *data) {
3678 // Modes:
3679 // 0 -- do not change default
3680 // 1 -- sp search
3681 // 2 -- use "keyed" TLS var, i.e.
3682 // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
3683 // 3 -- __declspec(thread) TLS var in tdata section
3684 int mode = 0;
3685 int max = 2;
3686#ifdef KMP_TDATA_GTID
3687 max = 3;
3688#endif /* KMP_TDATA_GTID */
3689 __kmp_stg_parse_int(name, value, 0, max, &mode);
3690 // TODO; parse_int is not very suitable for this case. In case of overflow it
3691 // is better to use 0 rather that max value.
3692 if (mode == 0) {
3693 __kmp_adjust_gtid_mode = TRUE;
3694 } else {
3695 __kmp_gtid_mode = mode;
3696 __kmp_adjust_gtid_mode = FALSE;
3697 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003698} // __kmp_str_parse_gtid_mode
3699
Jonathan Peyton30419822017-05-12 18:01:32 +00003700static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
3701 void *data) {
3702 if (__kmp_adjust_gtid_mode) {
3703 __kmp_stg_print_int(buffer, name, 0);
3704 } else {
3705 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
3706 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003707} // __kmp_stg_print_gtid_mode
3708
Jonathan Peyton30419822017-05-12 18:01:32 +00003709// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003710// KMP_NUM_LOCKS_IN_BLOCK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003711
Jonathan Peyton30419822017-05-12 18:01:32 +00003712static void __kmp_stg_parse_lock_block(char const *name, char const *value,
3713 void *data) {
3714 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003715} // __kmp_str_parse_lock_block
3716
Jonathan Peyton30419822017-05-12 18:01:32 +00003717static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
3718 void *data) {
3719 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003720} // __kmp_stg_print_lock_block
3721
Jonathan Peyton30419822017-05-12 18:01:32 +00003722// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003723// KMP_LOCK_KIND
Jim Cownie5e8470a2013-09-27 10:38:44 +00003724
Jonathan Peytondae13d82015-12-11 21:57:06 +00003725#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00003726#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003727#else
Jonathan Peyton30419822017-05-12 18:01:32 +00003728#define KMP_STORE_LOCK_SEQ(a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003729#endif
3730
Jonathan Peyton30419822017-05-12 18:01:32 +00003731static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
3732 void *data) {
3733 if (__kmp_init_user_locks) {
3734 KMP_WARNING(EnvLockWarn, name);
3735 return;
3736 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003737
Jonathan Peyton30419822017-05-12 18:01:32 +00003738 if (__kmp_str_match("tas", 2, value) ||
3739 __kmp_str_match("test and set", 2, value) ||
3740 __kmp_str_match("test_and_set", 2, value) ||
3741 __kmp_str_match("test-and-set", 2, value) ||
3742 __kmp_str_match("test andset", 2, value) ||
3743 __kmp_str_match("test_andset", 2, value) ||
3744 __kmp_str_match("test-andset", 2, value) ||
3745 __kmp_str_match("testand set", 2, value) ||
3746 __kmp_str_match("testand_set", 2, value) ||
3747 __kmp_str_match("testand-set", 2, value) ||
3748 __kmp_str_match("testandset", 2, value)) {
3749 __kmp_user_lock_kind = lk_tas;
3750 KMP_STORE_LOCK_SEQ(tas);
3751 }
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003752#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003753 else if (__kmp_str_match("futex", 1, value)) {
3754 if (__kmp_futex_determine_capable()) {
3755 __kmp_user_lock_kind = lk_futex;
3756 KMP_STORE_LOCK_SEQ(futex);
3757 } else {
3758 KMP_WARNING(FutexNotSupported, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003759 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003760 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003761#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003762 else if (__kmp_str_match("ticket", 2, value)) {
3763 __kmp_user_lock_kind = lk_ticket;
3764 KMP_STORE_LOCK_SEQ(ticket);
3765 } else if (__kmp_str_match("queuing", 1, value) ||
3766 __kmp_str_match("queue", 1, value)) {
3767 __kmp_user_lock_kind = lk_queuing;
3768 KMP_STORE_LOCK_SEQ(queuing);
3769 } else if (__kmp_str_match("drdpa ticket", 1, value) ||
3770 __kmp_str_match("drdpa_ticket", 1, value) ||
3771 __kmp_str_match("drdpa-ticket", 1, value) ||
3772 __kmp_str_match("drdpaticket", 1, value) ||
3773 __kmp_str_match("drdpa", 1, value)) {
3774 __kmp_user_lock_kind = lk_drdpa;
3775 KMP_STORE_LOCK_SEQ(drdpa);
3776 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003777#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003778 else if (__kmp_str_match("adaptive", 1, value)) {
3779 if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
3780 __kmp_user_lock_kind = lk_adaptive;
3781 KMP_STORE_LOCK_SEQ(adaptive);
3782 } else {
3783 KMP_WARNING(AdaptiveNotSupported, name, value);
3784 __kmp_user_lock_kind = lk_queuing;
3785 KMP_STORE_LOCK_SEQ(queuing);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003786 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003787 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003788#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peytondae13d82015-12-11 21:57:06 +00003789#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003790 else if (__kmp_str_match("rtm", 1, value)) {
3791 if (__kmp_cpuinfo.rtm) {
3792 __kmp_user_lock_kind = lk_rtm;
3793 KMP_STORE_LOCK_SEQ(rtm);
3794 } else {
3795 KMP_WARNING(AdaptiveNotSupported, name, value);
3796 __kmp_user_lock_kind = lk_queuing;
3797 KMP_STORE_LOCK_SEQ(queuing);
Jonathan Peytondae13d82015-12-11 21:57:06 +00003798 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003799 } else if (__kmp_str_match("hle", 1, value)) {
3800 __kmp_user_lock_kind = lk_hle;
3801 KMP_STORE_LOCK_SEQ(hle);
3802 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00003803#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003804 else {
3805 KMP_WARNING(StgInvalidValue, name, value);
3806 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003807}
3808
Jonathan Peyton30419822017-05-12 18:01:32 +00003809static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
3810 void *data) {
3811 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003812
Jonathan Peyton30419822017-05-12 18:01:32 +00003813 switch (__kmp_user_lock_kind) {
3814 case lk_default:
3815 value = "default";
3816 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003817
Jonathan Peyton30419822017-05-12 18:01:32 +00003818 case lk_tas:
3819 value = "tas";
3820 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003821
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003822#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003823 case lk_futex:
3824 value = "futex";
3825 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003826#endif
3827
Jonathan Peytondae13d82015-12-11 21:57:06 +00003828#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003829 case lk_rtm:
3830 value = "rtm";
3831 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003832
Jonathan Peyton30419822017-05-12 18:01:32 +00003833 case lk_hle:
3834 value = "hle";
3835 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003836#endif
3837
Jonathan Peyton30419822017-05-12 18:01:32 +00003838 case lk_ticket:
3839 value = "ticket";
3840 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003841
Jonathan Peyton30419822017-05-12 18:01:32 +00003842 case lk_queuing:
3843 value = "queuing";
3844 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003845
Jonathan Peyton30419822017-05-12 18:01:32 +00003846 case lk_drdpa:
3847 value = "drdpa";
3848 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003849#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003850 case lk_adaptive:
3851 value = "adaptive";
3852 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003853#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003854 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003855
Jonathan Peyton30419822017-05-12 18:01:32 +00003856 if (value != NULL) {
3857 __kmp_stg_print_str(buffer, name, value);
3858 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003859}
3860
Jonathan Peyton30419822017-05-12 18:01:32 +00003861// -----------------------------------------------------------------------------
Jonathan Peyton377aa402016-04-14 16:00:37 +00003862// KMP_SPIN_BACKOFF_PARAMS
Jonathan Peyton377aa402016-04-14 16:00:37 +00003863
Jonathan Peyton30419822017-05-12 18:01:32 +00003864// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
3865// for machine pause)
3866static void __kmp_stg_parse_spin_backoff_params(const char *name,
3867 const char *value, void *data) {
3868 const char *next = value;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003869
Jonathan Peyton30419822017-05-12 18:01:32 +00003870 int total = 0; // Count elements that were set. It'll be used as an array size
3871 int prev_comma = FALSE; // For correct processing sequential commas
3872 int i;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003873
Jonathan Peyton30419822017-05-12 18:01:32 +00003874 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
3875 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003876
Jonathan Peyton30419822017-05-12 18:01:32 +00003877 // Run only 3 iterations because it is enough to read two values or find a
3878 // syntax error
3879 for (i = 0; i < 3; i++) {
3880 SKIP_WS(next);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003881
Jonathan Peyton30419822017-05-12 18:01:32 +00003882 if (*next == '\0') {
3883 break;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003884 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003885 // Next character is not an integer or not a comma OR number of values > 2
3886 // => end of list
3887 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
3888 KMP_WARNING(EnvSyntaxError, name, value);
3889 return;
3890 }
3891 // The next character is ','
3892 if (*next == ',') {
3893 // ',' is the fisrt character
3894 if (total == 0 || prev_comma) {
3895 total++;
3896 }
3897 prev_comma = TRUE;
3898 next++; // skip ','
3899 SKIP_WS(next);
3900 }
3901 // Next character is a digit
3902 if (*next >= '0' && *next <= '9') {
3903 int num;
3904 const char *buf = next;
3905 char const *msg = NULL;
3906 prev_comma = FALSE;
3907 SKIP_DIGITS(next);
3908 total++;
3909
3910 const char *tmp = next;
3911 SKIP_WS(tmp);
3912 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
3913 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003914 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00003915 }
3916
3917 num = __kmp_str_to_int(buf, *next);
3918 if (num <= 0) { // The number of retries should be > 0
3919 msg = KMP_I18N_STR(ValueTooSmall);
3920 num = 1;
3921 } else if (num > KMP_INT_MAX) {
3922 msg = KMP_I18N_STR(ValueTooLarge);
3923 num = KMP_INT_MAX;
3924 }
3925 if (msg != NULL) {
3926 // Message is not empty. Print warning.
3927 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
3928 KMP_INFORM(Using_int_Value, name, num);
3929 }
3930 if (total == 1) {
3931 max_backoff = num;
3932 } else if (total == 2) {
3933 min_tick = num;
3934 }
Jonathan Peyton377aa402016-04-14 16:00:37 +00003935 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003936 }
3937 KMP_DEBUG_ASSERT(total > 0);
3938 if (total <= 0) {
3939 KMP_WARNING(EnvSyntaxError, name, value);
3940 return;
3941 }
3942 __kmp_spin_backoff_params.max_backoff = max_backoff;
3943 __kmp_spin_backoff_params.min_tick = min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003944}
3945
Jonathan Peyton30419822017-05-12 18:01:32 +00003946static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
3947 char const *name, void *data) {
3948 if (__kmp_env_format) {
3949 KMP_STR_BUF_PRINT_NAME_EX(name);
3950 } else {
3951 __kmp_str_buf_print(buffer, " %s='", name);
3952 }
3953 __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
3954 __kmp_spin_backoff_params.min_tick);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003955}
3956
Jim Cownie5e8470a2013-09-27 10:38:44 +00003957#if KMP_USE_ADAPTIVE_LOCKS
3958
Jonathan Peyton30419822017-05-12 18:01:32 +00003959// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003960// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003961
3962// Parse out values for the tunable parameters from a string of the form
3963// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
Jonathan Peyton30419822017-05-12 18:01:32 +00003964static void __kmp_stg_parse_adaptive_lock_props(const char *name,
3965 const char *value, void *data) {
3966 int max_retries = 0;
3967 int max_badness = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003968
Jonathan Peyton30419822017-05-12 18:01:32 +00003969 const char *next = value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003970
Jonathan Peyton30419822017-05-12 18:01:32 +00003971 int total = 0; // Count elements that were set. It'll be used as an array size
3972 int prev_comma = FALSE; // For correct processing sequential commas
3973 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003974
Jonathan Peyton30419822017-05-12 18:01:32 +00003975 // Save values in the structure __kmp_speculative_backoff_params
3976 // Run only 3 iterations because it is enough to read two values or find a
3977 // syntax error
3978 for (i = 0; i < 3; i++) {
3979 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003980
Jonathan Peyton30419822017-05-12 18:01:32 +00003981 if (*next == '\0') {
3982 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003983 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003984 // Next character is not an integer or not a comma OR number of values > 2
3985 // => end of list
3986 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
3987 KMP_WARNING(EnvSyntaxError, name, value);
3988 return;
3989 }
3990 // The next character is ','
3991 if (*next == ',') {
3992 // ',' is the fisrt character
3993 if (total == 0 || prev_comma) {
3994 total++;
3995 }
3996 prev_comma = TRUE;
3997 next++; // skip ','
3998 SKIP_WS(next);
3999 }
4000 // Next character is a digit
4001 if (*next >= '0' && *next <= '9') {
4002 int num;
4003 const char *buf = next;
4004 char const *msg = NULL;
4005 prev_comma = FALSE;
4006 SKIP_DIGITS(next);
4007 total++;
4008
4009 const char *tmp = next;
4010 SKIP_WS(tmp);
4011 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4012 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004013 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00004014 }
4015
4016 num = __kmp_str_to_int(buf, *next);
4017 if (num < 0) { // The number of retries should be >= 0
4018 msg = KMP_I18N_STR(ValueTooSmall);
4019 num = 1;
4020 } else if (num > KMP_INT_MAX) {
4021 msg = KMP_I18N_STR(ValueTooLarge);
4022 num = KMP_INT_MAX;
4023 }
4024 if (msg != NULL) {
4025 // Message is not empty. Print warning.
4026 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4027 KMP_INFORM(Using_int_Value, name, num);
4028 }
4029 if (total == 1) {
4030 max_retries = num;
4031 } else if (total == 2) {
4032 max_badness = num;
4033 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004034 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004035 }
4036 KMP_DEBUG_ASSERT(total > 0);
4037 if (total <= 0) {
4038 KMP_WARNING(EnvSyntaxError, name, value);
4039 return;
4040 }
4041 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4042 __kmp_adaptive_backoff_params.max_badness = max_badness;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004043}
4044
Jonathan Peyton30419822017-05-12 18:01:32 +00004045static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4046 char const *name, void *data) {
4047 if (__kmp_env_format) {
4048 KMP_STR_BUF_PRINT_NAME_EX(name);
4049 } else {
4050 __kmp_str_buf_print(buffer, " %s='", name);
4051 }
4052 __kmp_str_buf_print(buffer, "%d,%d'\n",
4053 __kmp_adaptive_backoff_params.max_soft_retries,
4054 __kmp_adaptive_backoff_params.max_badness);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004055} // __kmp_stg_print_adaptive_lock_props
4056
4057#if KMP_DEBUG_ADAPTIVE_LOCKS
4058
Jonathan Peyton30419822017-05-12 18:01:32 +00004059static void __kmp_stg_parse_speculative_statsfile(char const *name,
4060 char const *value,
4061 void *data) {
4062 __kmp_stg_parse_file(name, value, "", &__kmp_speculative_statsfile);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004063} // __kmp_stg_parse_speculative_statsfile
4064
Jonathan Peyton30419822017-05-12 18:01:32 +00004065static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
4066 char const *name,
4067 void *data) {
4068 if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
4069 __kmp_stg_print_str(buffer, name, "stdout");
4070 } else {
4071 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
4072 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004073
4074} // __kmp_stg_print_speculative_statsfile
4075
4076#endif // KMP_DEBUG_ADAPTIVE_LOCKS
4077
4078#endif // KMP_USE_ADAPTIVE_LOCKS
4079
Jonathan Peyton30419822017-05-12 18:01:32 +00004080// -----------------------------------------------------------------------------
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004081// KMP_HW_SUBSET (was KMP_PLACE_THREADS)
Jim Cownie5e8470a2013-09-27 10:38:44 +00004082
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004083// The longest observable sequense of items is
4084// Socket-Node-Tile-Core-Thread
4085// So, let's limit to 5 levels for now
4086// The input string is usually short enough, let's use 512 limit for now
4087#define MAX_T_LEVEL 5
4088#define MAX_STR_LEN 512
Jonathan Peyton30419822017-05-12 18:01:32 +00004089static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
4090 void *data) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004091 // Value example: 1s,5c@3,2T
4092 // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
4093 static int parsed = 0;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004094 if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
4095 KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
4096 if (parsed == 1) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004097 return; // already parsed KMP_HW_SUBSET
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004098 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004099 }
4100 parsed = 1;
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004101
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004102 char *components[MAX_T_LEVEL];
4103 char const *digits = "0123456789";
4104 char input[MAX_STR_LEN];
4105 size_t len = 0, mlen = MAX_STR_LEN;
4106 int level = 0;
4107 // Canonize the string (remove spaces, unify delimiters, etc.)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004108 char *pos = CCAST(char *, value);
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004109 while (*pos && mlen) {
4110 if (*pos != ' ') { // skip spaces
4111 if (len == 0 && *pos == ':') {
4112 __kmp_hws_abs_flag = 1; // if the first symbol is ":", skip it
4113 } else {
4114 input[len] = toupper(*pos);
4115 if (input[len] == 'X')
4116 input[len] = ','; // unify delimiters of levels
4117 if (input[len] == 'O' && strchr(digits, *(pos + 1)))
4118 input[len] = '@'; // unify delimiters of offset
4119 len++;
4120 }
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004121 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004122 mlen--;
4123 pos++;
4124 }
4125 if (len == 0 || mlen == 0)
4126 goto err; // contents is either empty or too long
4127 input[len] = '\0';
4128 __kmp_hws_requested = 1; // mark that subset requested
4129 // Split by delimiter
4130 pos = input;
4131 components[level++] = pos;
George Rokos4800fc42017-04-25 15:55:39 +00004132 while ((pos = strchr(pos, ','))) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004133 *pos = '\0'; // modify input and avoid more copying
4134 components[level++] = ++pos; // expect something after ","
4135 if (level > MAX_T_LEVEL)
4136 goto err; // too many components provided
4137 }
4138 // Check each component
4139 for (int i = 0; i < level; ++i) {
4140 int offset = 0;
4141 int num = atoi(components[i]); // each component should start with a number
4142 if ((pos = strchr(components[i], '@'))) {
4143 offset = atoi(pos + 1); // save offset
4144 *pos = '\0'; // cut the offset from the component
4145 }
4146 pos = components[i] + strspn(components[i], digits);
4147 if (pos == components[i])
4148 goto err;
4149 // detect the component type
4150 switch (*pos) {
4151 case 'S': // Socket
4152 if (__kmp_hws_socket.num > 0)
4153 goto err; // duplicate is not allowed
4154 __kmp_hws_socket.num = num;
4155 __kmp_hws_socket.offset = offset;
4156 break;
4157 case 'N': // NUMA Node
4158 if (__kmp_hws_node.num > 0)
4159 goto err; // duplicate is not allowed
4160 __kmp_hws_node.num = num;
4161 __kmp_hws_node.offset = offset;
4162 break;
4163 case 'L': // Cache
4164 if (*(pos + 1) == '2') { // L2 - Tile
4165 if (__kmp_hws_tile.num > 0)
4166 goto err; // duplicate is not allowed
4167 __kmp_hws_tile.num = num;
4168 __kmp_hws_tile.offset = offset;
4169 } else if (*(pos + 1) == '3') { // L3 - Socket
4170 if (__kmp_hws_socket.num > 0)
4171 goto err; // duplicate is not allowed
4172 __kmp_hws_socket.num = num;
4173 __kmp_hws_socket.offset = offset;
4174 } else if (*(pos + 1) == '1') { // L1 - Core
4175 if (__kmp_hws_core.num > 0)
4176 goto err; // duplicate is not allowed
4177 __kmp_hws_core.num = num;
4178 __kmp_hws_core.offset = offset;
4179 }
4180 break;
4181 case 'C': // Core (or Cache?)
4182 if (*(pos + 1) != 'A') {
4183 if (__kmp_hws_core.num > 0)
4184 goto err; // duplicate is not allowed
4185 __kmp_hws_core.num = num;
4186 __kmp_hws_core.offset = offset;
4187 } else { // Cache
4188 char *d = pos + strcspn(pos, digits); // find digit
4189 if (*d == '2') { // L2 - Tile
4190 if (__kmp_hws_tile.num > 0)
4191 goto err; // duplicate is not allowed
4192 __kmp_hws_tile.num = num;
4193 __kmp_hws_tile.offset = offset;
4194 } else if (*d == '3') { // L3 - Socket
4195 if (__kmp_hws_socket.num > 0)
4196 goto err; // duplicate is not allowed
4197 __kmp_hws_socket.num = num;
4198 __kmp_hws_socket.offset = offset;
4199 } else if (*d == '1') { // L1 - Core
4200 if (__kmp_hws_core.num > 0)
4201 goto err; // duplicate is not allowed
4202 __kmp_hws_core.num = num;
4203 __kmp_hws_core.offset = offset;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004204 } else {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004205 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004206 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004207 }
4208 break;
4209 case 'T': // Thread
4210 if (__kmp_hws_proc.num > 0)
4211 goto err; // duplicate is not allowed
4212 __kmp_hws_proc.num = num;
4213 __kmp_hws_proc.offset = offset;
4214 break;
4215 default:
4216 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004217 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004218 }
4219 return;
4220err:
4221 KMP_WARNING(AffHWSubsetInvalid, name, value);
4222 __kmp_hws_requested = 0; // mark that subset not requested
4223 return;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004224}
4225
Jonathan Peyton30419822017-05-12 18:01:32 +00004226static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004227 void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +00004228 if (__kmp_hws_requested) {
4229 int comma = 0;
4230 kmp_str_buf_t buf;
4231 __kmp_str_buf_init(&buf);
4232 if (__kmp_env_format)
4233 KMP_STR_BUF_PRINT_NAME_EX(name);
4234 else
4235 __kmp_str_buf_print(buffer, " %s='", name);
4236 if (__kmp_hws_socket.num) {
4237 __kmp_str_buf_print(&buf, "%ds", __kmp_hws_socket.num);
4238 if (__kmp_hws_socket.offset)
4239 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_socket.offset);
4240 comma = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004241 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004242 if (__kmp_hws_node.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004243 __kmp_str_buf_print(&buf, "%s%dn", comma ? "," : "", __kmp_hws_node.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004244 if (__kmp_hws_node.offset)
4245 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_node.offset);
4246 comma = 1;
4247 }
4248 if (__kmp_hws_tile.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004249 __kmp_str_buf_print(&buf, "%s%dL2", comma ? "," : "", __kmp_hws_tile.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004250 if (__kmp_hws_tile.offset)
4251 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_tile.offset);
4252 comma = 1;
4253 }
4254 if (__kmp_hws_core.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004255 __kmp_str_buf_print(&buf, "%s%dc", comma ? "," : "", __kmp_hws_core.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004256 if (__kmp_hws_core.offset)
4257 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_core.offset);
4258 comma = 1;
4259 }
4260 if (__kmp_hws_proc.num)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004261 __kmp_str_buf_print(&buf, "%s%dt", comma ? "," : "", __kmp_hws_proc.num);
4262 __kmp_str_buf_print(buffer, "%s'\n", buf.str);
Jonathan Peyton30419822017-05-12 18:01:32 +00004263 __kmp_str_buf_free(&buf);
4264 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004265}
Jim Cownie5e8470a2013-09-27 10:38:44 +00004266
4267#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004268// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004269// KMP_FORKJOIN_FRAMES
Jim Cownie5e8470a2013-09-27 10:38:44 +00004270
Jonathan Peyton30419822017-05-12 18:01:32 +00004271static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
4272 void *data) {
4273 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004274} // __kmp_stg_parse_forkjoin_frames
4275
Jonathan Peyton30419822017-05-12 18:01:32 +00004276static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
4277 char const *name, void *data) {
4278 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004279} // __kmp_stg_print_forkjoin_frames
4280
Jonathan Peyton30419822017-05-12 18:01:32 +00004281// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004282// KMP_FORKJOIN_FRAMES_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00004283
Jonathan Peyton30419822017-05-12 18:01:32 +00004284static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
4285 char const *value,
4286 void *data) {
4287 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004288} // __kmp_stg_parse_forkjoin_frames
4289
Jonathan Peyton30419822017-05-12 18:01:32 +00004290static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
4291 char const *name, void *data) {
4292 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004293} // __kmp_stg_print_forkjoin_frames
4294#endif /* USE_ITT_BUILD */
4295
Jonathan Peyton30419822017-05-12 18:01:32 +00004296// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004297// OMP_DISPLAY_ENV
Jim Cownie5e8470a2013-09-27 10:38:44 +00004298
4299#if OMP_40_ENABLED
4300
Jonathan Peyton30419822017-05-12 18:01:32 +00004301static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
4302 void *data) {
4303 if (__kmp_str_match("VERBOSE", 1, value)) {
4304 __kmp_display_env_verbose = TRUE;
4305 } else {
4306 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
4307 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004308
4309} // __kmp_stg_parse_omp_display_env
4310
Jonathan Peyton30419822017-05-12 18:01:32 +00004311static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
4312 char const *name, void *data) {
4313 if (__kmp_display_env_verbose) {
4314 __kmp_stg_print_str(buffer, name, "VERBOSE");
4315 } else {
4316 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
4317 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004318} // __kmp_stg_print_omp_display_env
4319
Jonathan Peyton30419822017-05-12 18:01:32 +00004320static void __kmp_stg_parse_omp_cancellation(char const *name,
4321 char const *value, void *data) {
4322 if (TCR_4(__kmp_init_parallel)) {
4323 KMP_WARNING(EnvParallelWarn, name);
4324 return;
4325 } // read value before first parallel only
4326 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004327} // __kmp_stg_parse_omp_cancellation
4328
Jonathan Peyton30419822017-05-12 18:01:32 +00004329static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
4330 char const *name, void *data) {
4331 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004332} // __kmp_stg_print_omp_cancellation
4333
Jim Cownie5e8470a2013-09-27 10:38:44 +00004334#endif
4335
Jonathan Peyton30419822017-05-12 18:01:32 +00004336// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004337// Table.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004338
4339static kmp_setting_t __kmp_stg_table[] = {
4340
Jonathan Peyton30419822017-05-12 18:01:32 +00004341 {"KMP_ALL_THREADS", __kmp_stg_parse_all_threads,
4342 __kmp_stg_print_all_threads, NULL, 0, 0},
4343 {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
4344 NULL, 0, 0},
4345 {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
4346 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
4347 {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
4348 NULL, 0, 0},
4349 {"KMP_MAX_THREADS", __kmp_stg_parse_all_threads, NULL, NULL, 0,
4350 0}, // For backward compatibility
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004351#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +00004352 {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
4353 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004354#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004355 {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
4356 0, 0},
4357 {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
4358 __kmp_stg_print_stackoffset, NULL, 0, 0},
4359 {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4360 NULL, 0, 0},
4361 {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
4362 0, 0},
4363 {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
4364 0},
4365 {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
4366 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004367
Jonathan Peyton30419822017-05-12 18:01:32 +00004368 {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
4369 {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
4370 __kmp_stg_print_num_threads, NULL, 0, 0},
4371 {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4372 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004373
Jonathan Peyton30419822017-05-12 18:01:32 +00004374 {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
4375 0},
4376 {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
4377 __kmp_stg_print_task_stealing, NULL, 0, 0},
4378 {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
4379 __kmp_stg_print_max_active_levels, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004380#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004381 {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
4382 __kmp_stg_print_default_device, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004383#endif
Jonathan Peytondf6818b2016-06-14 17:57:47 +00004384#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004385 {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
4386 __kmp_stg_print_max_task_priority, NULL, 0, 0},
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00004387 {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
4388 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
Jonathan Peyton28510722016-02-25 18:04:09 +00004389#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004390 {"OMP_THREAD_LIMIT", __kmp_stg_parse_all_threads,
4391 __kmp_stg_print_all_threads, NULL, 0, 0},
4392 {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
4393 __kmp_stg_print_wait_policy, NULL, 0, 0},
4394 {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
4395 __kmp_stg_print_disp_buffers, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004396#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00004397 {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
4398 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
4399 {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
4400 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004401#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00004402
4403#if KMP_HANDLE_SIGNALS
Jonathan Peyton30419822017-05-12 18:01:32 +00004404 {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
4405 __kmp_stg_print_handle_signals, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004406#endif
4407
4408#if KMP_ARCH_X86 || KMP_ARCH_X86_64
Jonathan Peyton30419822017-05-12 18:01:32 +00004409 {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
4410 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004411#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
4412
4413#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004414 {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004415#endif
4416
4417#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00004418 {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
4419 0},
4420 {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
4421 0},
4422 {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
4423 0},
4424 {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
4425 0},
4426 {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
4427 0},
4428 {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
4429 0},
4430 {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
4431 {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
4432 NULL, 0, 0},
4433 {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
4434 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
4435 {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
4436 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
4437 {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
4438 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
4439 {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004440
Jonathan Peyton30419822017-05-12 18:01:32 +00004441 {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
4442 __kmp_stg_print_par_range_env, NULL, 0, 0},
4443 {"KMP_YIELD_CYCLE", __kmp_stg_parse_yield_cycle,
4444 __kmp_stg_print_yield_cycle, NULL, 0, 0},
4445 {"KMP_YIELD_ON", __kmp_stg_parse_yield_on, __kmp_stg_print_yield_on, NULL,
4446 0, 0},
4447 {"KMP_YIELD_OFF", __kmp_stg_parse_yield_off, __kmp_stg_print_yield_off,
4448 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004449#endif // KMP_DEBUG
4450
Jonathan Peyton30419822017-05-12 18:01:32 +00004451 {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
4452 __kmp_stg_print_align_alloc, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004453
Jonathan Peyton30419822017-05-12 18:01:32 +00004454 {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4455 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4456 {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4457 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
4458 {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4459 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4460 {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4461 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004462#if KMP_FAST_REDUCTION_BARRIER
Jonathan Peyton30419822017-05-12 18:01:32 +00004463 {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4464 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4465 {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4466 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004467#endif
4468
Jonathan Peyton30419822017-05-12 18:01:32 +00004469 {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
4470 __kmp_stg_print_abort_delay, NULL, 0, 0},
4471 {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
4472 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
4473 {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
4474 __kmp_stg_print_force_reduction, NULL, 0, 0},
4475 {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
4476 __kmp_stg_print_force_reduction, NULL, 0, 0},
4477 {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
4478 __kmp_stg_print_storage_map, NULL, 0, 0},
4479 {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
4480 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
4481 {"KMP_FOREIGN_THREADS_THREADPRIVATE",
4482 __kmp_stg_parse_foreign_threads_threadprivate,
4483 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004484
Alp Toker98758b02014-03-02 04:12:06 +00004485#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004486 {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
4487 0, 0},
4488#ifdef KMP_GOMP_COMPAT
4489 {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
4490 /* no print */ NULL, 0, 0},
4491#endif /* KMP_GOMP_COMPAT */
4492#if OMP_40_ENABLED
4493 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4494 NULL, 0, 0},
4495 {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
4496#else
4497 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, NULL, /* no print */ NULL, 0,
4498 0},
4499#endif /* OMP_40_ENABLED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00004500
Jonathan Peyton30419822017-05-12 18:01:32 +00004501 {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
4502 __kmp_stg_print_topology_method, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004503
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004504#else
Jim Cownie5e8470a2013-09-27 10:38:44 +00004505
Jonathan Peyton30419822017-05-12 18:01:32 +00004506// KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
4507// OMP_PROC_BIND and proc-bind-var are supported, however.
4508#if OMP_40_ENABLED
4509 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4510 NULL, 0, 0},
4511#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004512
Alp Toker98758b02014-03-02 04:12:06 +00004513#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004514
Jonathan Peyton30419822017-05-12 18:01:32 +00004515 {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
4516 __kmp_stg_print_init_at_fork, NULL, 0, 0},
4517 {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
4518 0, 0},
4519 {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
4520 NULL, 0, 0},
4521 {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
4522 __kmp_stg_print_atomic_mode, NULL, 0, 0},
4523 {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
4524 __kmp_stg_print_consistency_check, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004525
4526#if USE_ITT_BUILD && USE_ITT_NOTIFY
Jonathan Peyton30419822017-05-12 18:01:32 +00004527 {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
4528 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004529#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
Jonathan Peyton30419822017-05-12 18:01:32 +00004530 {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
4531 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
4532 {"KMP_INIT_WAIT", __kmp_stg_parse_init_wait, __kmp_stg_print_init_wait,
4533 NULL, 0, 0},
4534 {"KMP_NEXT_WAIT", __kmp_stg_parse_next_wait, __kmp_stg_print_next_wait,
4535 NULL, 0, 0},
4536 {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
4537 NULL, 0, 0},
4538 {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
4539 NULL, 0, 0},
4540 {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
4541 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004542
4543#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00004544 {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
4545 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004546#endif
4547
Jonathan Peyton30419822017-05-12 18:01:32 +00004548 {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
4549 __kmp_stg_print_lock_block, NULL, 0, 0},
4550 {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
4551 NULL, 0, 0},
4552 {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
4553 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004554#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004555 {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
4556 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004557#if KMP_DEBUG_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004558 {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
4559 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004560#endif
4561#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004562 {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4563 NULL, 0, 0},
4564 {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4565 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004566#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004567 {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
4568 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
4569 {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
4570 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004571#endif
4572
Jonathan Peyton30419822017-05-12 18:01:32 +00004573#if OMP_40_ENABLED
4574 {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
4575 __kmp_stg_print_omp_display_env, NULL, 0, 0},
4576 {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
4577 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004578#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004579 {"", NULL, NULL, NULL, 0, 0}}; // settings
Jim Cownie5e8470a2013-09-27 10:38:44 +00004580
Jonathan Peyton30419822017-05-12 18:01:32 +00004581static int const __kmp_stg_count =
4582 sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004583
Jonathan Peyton30419822017-05-12 18:01:32 +00004584static inline kmp_setting_t *__kmp_stg_find(char const *name) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004585
Jonathan Peyton30419822017-05-12 18:01:32 +00004586 int i;
4587 if (name != NULL) {
4588 for (i = 0; i < __kmp_stg_count; ++i) {
4589 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
4590 return &__kmp_stg_table[i];
4591 }; // if
4592 }; // for
4593 }; // if
4594 return NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004595
4596} // __kmp_stg_find
4597
Jonathan Peyton30419822017-05-12 18:01:32 +00004598static int __kmp_stg_cmp(void const *_a, void const *_b) {
Andrey Churbanov5ba90c72017-07-17 09:03:14 +00004599 const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
4600 const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004601
Jonathan Peyton30419822017-05-12 18:01:32 +00004602 // Process KMP_AFFINITY last.
4603 // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
4604 if (strcmp(a->name, "KMP_AFFINITY") == 0) {
4605 if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4606 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004607 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004608 return 1;
4609 } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4610 return -1;
4611 }
4612 return strcmp(a->name, b->name);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004613} // __kmp_stg_cmp
4614
Jonathan Peyton30419822017-05-12 18:01:32 +00004615static void __kmp_stg_init(void) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004616
Jonathan Peyton30419822017-05-12 18:01:32 +00004617 static int initialized = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004618
Jonathan Peyton30419822017-05-12 18:01:32 +00004619 if (!initialized) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004620
Jonathan Peyton30419822017-05-12 18:01:32 +00004621 // Sort table.
4622 qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
4623 __kmp_stg_cmp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004624
Jonathan Peyton30419822017-05-12 18:01:32 +00004625 { // Initialize *_STACKSIZE data.
4626 kmp_setting_t *kmp_stacksize =
4627 __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004628#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004629 kmp_setting_t *gomp_stacksize =
4630 __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004631#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004632 kmp_setting_t *omp_stacksize =
4633 __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004634
Jonathan Peyton30419822017-05-12 18:01:32 +00004635 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4636 // !!! Compiler does not understand rivals is used and optimizes out
4637 // assignments
4638 // !!! rivals[ i ++ ] = ...;
4639 static kmp_setting_t *volatile rivals[4];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004640 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004641#ifdef KMP_GOMP_COMPAT
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004642 static kmp_stg_ss_data_t gomp_data = {1024,
4643 CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004644#endif
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004645 static kmp_stg_ss_data_t omp_data = {1024,
4646 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004647 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004648
Jonathan Peyton30419822017-05-12 18:01:32 +00004649 rivals[i++] = kmp_stacksize;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004650#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004651 if (gomp_stacksize != NULL) {
4652 rivals[i++] = gomp_stacksize;
4653 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004654#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004655 rivals[i++] = omp_stacksize;
4656 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004657
Jonathan Peyton30419822017-05-12 18:01:32 +00004658 kmp_stacksize->data = &kmp_data;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004659#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004660 if (gomp_stacksize != NULL) {
4661 gomp_stacksize->data = &gomp_data;
4662 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004663#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004664 omp_stacksize->data = &omp_data;
4665 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004666
Jonathan Peyton30419822017-05-12 18:01:32 +00004667 { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
4668 kmp_setting_t *kmp_library =
4669 __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
4670 kmp_setting_t *omp_wait_policy =
4671 __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004672
Jonathan Peyton30419822017-05-12 18:01:32 +00004673 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4674 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004675 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
4676 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004677 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004678
Jonathan Peyton30419822017-05-12 18:01:32 +00004679 rivals[i++] = kmp_library;
4680 if (omp_wait_policy != NULL) {
4681 rivals[i++] = omp_wait_policy;
4682 }; // if
4683 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004684
Jonathan Peyton30419822017-05-12 18:01:32 +00004685 kmp_library->data = &kmp_data;
4686 if (omp_wait_policy != NULL) {
4687 omp_wait_policy->data = &omp_data;
4688 }; // if
4689 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004690
Jonathan Peyton30419822017-05-12 18:01:32 +00004691 { // Initialize KMP_ALL_THREADS, KMP_MAX_THREADS, and OMP_THREAD_LIMIT data.
4692 kmp_setting_t *kmp_all_threads =
4693 __kmp_stg_find("KMP_ALL_THREADS"); // 1st priority.
4694 kmp_setting_t *kmp_max_threads =
4695 __kmp_stg_find("KMP_MAX_THREADS"); // 2nd priority.
4696 kmp_setting_t *omp_thread_limit =
4697 __kmp_stg_find("OMP_THREAD_LIMIT"); // 3rd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004698
Jonathan Peyton30419822017-05-12 18:01:32 +00004699 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4700 static kmp_setting_t *volatile rivals[4];
4701 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004702
Jonathan Peyton30419822017-05-12 18:01:32 +00004703 rivals[i++] = kmp_all_threads;
4704 rivals[i++] = kmp_max_threads;
4705 if (omp_thread_limit != NULL) {
4706 rivals[i++] = omp_thread_limit;
4707 }; // if
4708 rivals[i++] = NULL;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004709 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
4710 kmp_max_threads->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004711 if (omp_thread_limit != NULL) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004712 omp_thread_limit->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004713 }; // if
4714 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004715
Alp Toker98758b02014-03-02 04:12:06 +00004716#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004717 { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
4718 kmp_setting_t *kmp_affinity =
4719 __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
4720 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004721
Jonathan Peyton30419822017-05-12 18:01:32 +00004722#ifdef KMP_GOMP_COMPAT
4723 kmp_setting_t *gomp_cpu_affinity =
4724 __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
4725 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
4726#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004727
Jonathan Peyton30419822017-05-12 18:01:32 +00004728 kmp_setting_t *omp_proc_bind =
4729 __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
4730 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004731
Jonathan Peyton30419822017-05-12 18:01:32 +00004732 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4733 static kmp_setting_t *volatile rivals[4];
4734 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004735
Jonathan Peyton30419822017-05-12 18:01:32 +00004736 rivals[i++] = kmp_affinity;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004737
Jonathan Peyton30419822017-05-12 18:01:32 +00004738#ifdef KMP_GOMP_COMPAT
4739 rivals[i++] = gomp_cpu_affinity;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004740 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004741#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004742
Jonathan Peyton30419822017-05-12 18:01:32 +00004743 rivals[i++] = omp_proc_bind;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004744 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004745 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004746
Jonathan Peyton30419822017-05-12 18:01:32 +00004747#if OMP_40_ENABLED
4748 static kmp_setting_t *volatile places_rivals[4];
4749 i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004750
Jonathan Peyton30419822017-05-12 18:01:32 +00004751 kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
4752 KMP_DEBUG_ASSERT(omp_places != NULL);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004753
Jonathan Peyton30419822017-05-12 18:01:32 +00004754 places_rivals[i++] = kmp_affinity;
4755#ifdef KMP_GOMP_COMPAT
4756 places_rivals[i++] = gomp_cpu_affinity;
4757#endif
4758 places_rivals[i++] = omp_places;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004759 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004760 places_rivals[i++] = NULL;
4761#endif
4762 }
Alp Toker98758b02014-03-02 04:12:06 +00004763#else
Jonathan Peyton30419822017-05-12 18:01:32 +00004764// KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
4765// OMP_PLACES not supported yet.
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004766#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004767
Jonathan Peyton30419822017-05-12 18:01:32 +00004768 { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
4769 kmp_setting_t *kmp_force_red =
4770 __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
4771 kmp_setting_t *kmp_determ_red =
4772 __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004773
Jonathan Peyton30419822017-05-12 18:01:32 +00004774 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4775 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004776 static kmp_stg_fr_data_t force_data = {1,
4777 CCAST(kmp_setting_t **, rivals)};
4778 static kmp_stg_fr_data_t determ_data = {0,
4779 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004780 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004781
Jonathan Peyton30419822017-05-12 18:01:32 +00004782 rivals[i++] = kmp_force_red;
4783 if (kmp_determ_red != NULL) {
4784 rivals[i++] = kmp_determ_red;
4785 }; // if
4786 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004787
Jonathan Peyton30419822017-05-12 18:01:32 +00004788 kmp_force_red->data = &force_data;
4789 if (kmp_determ_red != NULL) {
4790 kmp_determ_red->data = &determ_data;
4791 }; // if
4792 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004793
Jonathan Peyton30419822017-05-12 18:01:32 +00004794 initialized = 1;
4795 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004796
Jonathan Peyton30419822017-05-12 18:01:32 +00004797 // Reset flags.
4798 int i;
4799 for (i = 0; i < __kmp_stg_count; ++i) {
4800 __kmp_stg_table[i].set = 0;
4801 }; // for
Jim Cownie5e8470a2013-09-27 10:38:44 +00004802
4803} // __kmp_stg_init
4804
Jonathan Peyton30419822017-05-12 18:01:32 +00004805static void __kmp_stg_parse(char const *name, char const *value) {
4806 // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
4807 // really nameless, they are presented in environment block as
4808 // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
4809 if (name[0] == 0) {
4810 return;
4811 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004812
Jonathan Peyton30419822017-05-12 18:01:32 +00004813 if (value != NULL) {
4814 kmp_setting_t *setting = __kmp_stg_find(name);
4815 if (setting != NULL) {
4816 setting->parse(name, value, setting->data);
4817 setting->defined = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004818 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +00004819 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004820
4821} // __kmp_stg_parse
4822
Jonathan Peyton30419822017-05-12 18:01:32 +00004823static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
4824 char const *name, // Name of variable.
4825 char const *value, // Value of the variable.
4826 kmp_setting_t **rivals // List of rival settings (must include current one).
4827 ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004828
Jonathan Peyton30419822017-05-12 18:01:32 +00004829 if (rivals == NULL) {
4830 return 0;
4831 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004832
Jonathan Peyton30419822017-05-12 18:01:32 +00004833 // Loop thru higher priority settings (listed before current).
4834 int i = 0;
4835 for (; strcmp(rivals[i]->name, name) != 0; i++) {
4836 KMP_DEBUG_ASSERT(rivals[i] != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004837
Alp Toker763b9392014-02-28 09:42:41 +00004838#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004839 if (rivals[i] == __kmp_affinity_notype) {
4840 // If KMP_AFFINITY is specified without a type name,
4841 // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
4842 continue;
4843 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004844#endif
4845
Jonathan Peyton30419822017-05-12 18:01:32 +00004846 if (rivals[i]->set) {
4847 KMP_WARNING(StgIgnored, name, rivals[i]->name);
4848 return 1;
4849 }; // if
4850 }; // while
Jim Cownie5e8470a2013-09-27 10:38:44 +00004851
Jonathan Peyton30419822017-05-12 18:01:32 +00004852 ++i; // Skip current setting.
4853 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004854
4855}; // __kmp_stg_check_rivals
4856
Jonathan Peyton30419822017-05-12 18:01:32 +00004857static int __kmp_env_toPrint(char const *name, int flag) {
4858 int rc = 0;
4859 kmp_setting_t *setting = __kmp_stg_find(name);
4860 if (setting != NULL) {
4861 rc = setting->defined;
4862 if (flag >= 0) {
4863 setting->defined = flag;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004864 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +00004865 }; // if
4866 return rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004867}
4868
Jonathan Peyton30419822017-05-12 18:01:32 +00004869static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004870
Jonathan Peyton30419822017-05-12 18:01:32 +00004871 char const *value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004872
Jonathan Peyton30419822017-05-12 18:01:32 +00004873 /* OMP_NUM_THREADS */
4874 value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
4875 if (value) {
4876 ompc_set_num_threads(__kmp_dflt_team_nth);
4877 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004878
Jonathan Peyton30419822017-05-12 18:01:32 +00004879 /* KMP_BLOCKTIME */
4880 value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
4881 if (value) {
4882 kmpc_set_blocktime(__kmp_dflt_blocktime);
4883 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004884
Jonathan Peyton30419822017-05-12 18:01:32 +00004885 /* OMP_NESTED */
4886 value = __kmp_env_blk_var(block, "OMP_NESTED");
4887 if (value) {
4888 ompc_set_nested(__kmp_dflt_nested);
4889 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004890
Jonathan Peyton30419822017-05-12 18:01:32 +00004891 /* OMP_DYNAMIC */
4892 value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
4893 if (value) {
4894 ompc_set_dynamic(__kmp_global.g.g_dynamic);
4895 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004896
4897}
4898
Jonathan Peyton30419822017-05-12 18:01:32 +00004899void __kmp_env_initialize(char const *string) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004900
Jonathan Peyton30419822017-05-12 18:01:32 +00004901 kmp_env_blk_t block;
4902 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004903
Jonathan Peyton30419822017-05-12 18:01:32 +00004904 __kmp_stg_init();
Jim Cownie5e8470a2013-09-27 10:38:44 +00004905
Jonathan Peyton30419822017-05-12 18:01:32 +00004906 // Hack!!!
4907 if (string == NULL) {
4908 // __kmp_max_nth = __kmp_sys_max_nth;
4909 __kmp_threads_capacity =
4910 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
4911 }; // if
4912 __kmp_env_blk_init(&block, string);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004913
Jonathan Peyton30419822017-05-12 18:01:32 +00004914 // update the set flag on all entries that have an env var
4915 for (i = 0; i < block.count; ++i) {
4916 if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
4917 continue;
4918 }
4919 if (block.vars[i].value == NULL) {
4920 continue;
4921 }
4922 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
4923 if (setting != NULL) {
4924 setting->set = 1;
4925 }
4926 }; // for i
Jim Cownie5e8470a2013-09-27 10:38:44 +00004927
Jonathan Peyton30419822017-05-12 18:01:32 +00004928 // We need to know if blocktime was set when processing OMP_WAIT_POLICY
4929 blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
Jonathan Peyton50e8f182016-04-04 19:38:32 +00004930
Jonathan Peyton30419822017-05-12 18:01:32 +00004931 // Special case. If we parse environment, not a string, process KMP_WARNINGS
4932 // first.
4933 if (string == NULL) {
4934 char const *name = "KMP_WARNINGS";
4935 char const *value = __kmp_env_blk_var(&block, name);
4936 __kmp_stg_parse(name, value);
4937 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004938
Alp Toker763b9392014-02-28 09:42:41 +00004939#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004940 // Special case. KMP_AFFINITY is not a rival to other affinity env vars
4941 // if no affinity type is specified. We want to allow
4942 // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
4943 // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
4944 // affinity mechanism.
4945 __kmp_affinity_notype = NULL;
4946 char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
4947 if (aff_str != NULL) {
4948// Check if the KMP_AFFINITY type is specified in the string.
4949// We just search the string for "compact", "scatter", etc.
4950// without really parsing the string. The syntax of the
4951// KMP_AFFINITY env var is such that none of the affinity
4952// type names can appear anywhere other that the type
4953// specifier, even as substrings.
4954//
4955// I can't find a case-insensitive version of strstr on Windows* OS.
4956// Use the case-sensitive version for now.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004957
Jonathan Peyton30419822017-05-12 18:01:32 +00004958#if KMP_OS_WINDOWS
4959#define FIND strstr
4960#else
4961#define FIND strcasestr
4962#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004963
Jonathan Peyton30419822017-05-12 18:01:32 +00004964 if ((FIND(aff_str, "none") == NULL) &&
4965 (FIND(aff_str, "physical") == NULL) &&
4966 (FIND(aff_str, "logical") == NULL) &&
4967 (FIND(aff_str, "compact") == NULL) &&
4968 (FIND(aff_str, "scatter") == NULL) &&
4969 (FIND(aff_str, "explicit") == NULL) &&
4970 (FIND(aff_str, "balanced") == NULL) &&
4971 (FIND(aff_str, "disabled") == NULL)) {
4972 __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
4973 } else {
4974 // A new affinity type is specified.
4975 // Reset the affinity flags to their default values,
4976 // in case this is called from kmp_set_defaults().
4977 __kmp_affinity_type = affinity_default;
4978 __kmp_affinity_gran = affinity_gran_default;
4979 __kmp_affinity_top_method = affinity_top_method_default;
4980 __kmp_affinity_respect_mask = affinity_respect_mask_default;
4981 }
4982#undef FIND
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004983
4984#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004985 // Also reset the affinity flags if OMP_PROC_BIND is specified.
4986 aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
4987 if (aff_str != NULL) {
4988 __kmp_affinity_type = affinity_default;
4989 __kmp_affinity_gran = affinity_gran_default;
4990 __kmp_affinity_top_method = affinity_top_method_default;
4991 __kmp_affinity_respect_mask = affinity_respect_mask_default;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004992 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004993#endif /* OMP_40_ENABLED */
4994 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004995
Alp Toker763b9392014-02-28 09:42:41 +00004996#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00004997
4998#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004999 // Set up the nested proc bind type vector.
5000 if (__kmp_nested_proc_bind.bind_types == NULL) {
5001 __kmp_nested_proc_bind.bind_types =
5002 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
5003 if (__kmp_nested_proc_bind.bind_types == NULL) {
5004 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005005 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005006 __kmp_nested_proc_bind.size = 1;
5007 __kmp_nested_proc_bind.used = 1;
5008#if KMP_AFFINITY_SUPPORTED
5009 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
5010#else
5011 // default proc bind is false if affinity not supported
5012 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5013#endif
5014 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005015#endif /* OMP_40_ENABLED */
5016
Jonathan Peyton30419822017-05-12 18:01:32 +00005017 // Now process all of the settings.
5018 for (i = 0; i < block.count; ++i) {
5019 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
5020 }; // for i
Jim Cownie5e8470a2013-09-27 10:38:44 +00005021
Jonathan Peyton30419822017-05-12 18:01:32 +00005022 // If user locks have been allocated yet, don't reset the lock vptr table.
5023 if (!__kmp_init_user_locks) {
5024 if (__kmp_user_lock_kind == lk_default) {
5025 __kmp_user_lock_kind = lk_queuing;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005026 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005027#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00005028 __kmp_init_dynamic_user_locks();
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005029#else
Jonathan Peyton30419822017-05-12 18:01:32 +00005030 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005031#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005032 } else {
5033 KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
5034 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
5035// Binds lock functions again to follow the transition between different
5036// KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
5037// as we do not allow lock kind changes after making a call to any
5038// user lock functions (true).
5039#if KMP_USE_DYNAMIC_LOCK
5040 __kmp_init_dynamic_user_locks();
5041#else
5042 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5043#endif
5044 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005045
Alp Toker763b9392014-02-28 09:42:41 +00005046#if KMP_AFFINITY_SUPPORTED
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005047
Jonathan Peyton30419822017-05-12 18:01:32 +00005048 if (!TCR_4(__kmp_init_middle)) {
5049 // Determine if the machine/OS is actually capable of supporting
5050 // affinity.
5051 const char *var = "KMP_AFFINITY";
5052 KMPAffinity::pick_api();
Jonathan Peytone3e2aaf2017-05-31 20:35:22 +00005053#if KMP_USE_HWLOC
5054 // If Hwloc topology discovery was requested but affinity was also disabled,
5055 // then tell user that Hwloc request is being ignored and use default
5056 // topology discovery method.
5057 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
5058 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
5059 KMP_WARNING(AffIgnoringHwloc, var);
5060 __kmp_affinity_top_method = affinity_top_method_all;
5061 }
5062#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005063 if (__kmp_affinity_type == affinity_disabled) {
5064 KMP_AFFINITY_DISABLE();
5065 } else if (!KMP_AFFINITY_CAPABLE()) {
5066 __kmp_affinity_dispatch->determine_capable(var);
5067 if (!KMP_AFFINITY_CAPABLE()) {
5068 if (__kmp_affinity_verbose ||
5069 (__kmp_affinity_warnings &&
5070 (__kmp_affinity_type != affinity_default) &&
5071 (__kmp_affinity_type != affinity_none) &&
5072 (__kmp_affinity_type != affinity_disabled))) {
5073 KMP_WARNING(AffNotSupported, var);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005074 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005075 __kmp_affinity_type = affinity_disabled;
5076 __kmp_affinity_respect_mask = 0;
5077 __kmp_affinity_gran = affinity_gran_fine;
5078 }
5079 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005080
Jonathan Peyton30419822017-05-12 18:01:32 +00005081#if OMP_40_ENABLED
5082 if (__kmp_affinity_type == affinity_disabled) {
5083 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5084 } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
5085 // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
5086 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
5087 }
5088#endif /* OMP_40_ENABLED */
5089
5090 if (KMP_AFFINITY_CAPABLE()) {
5091
5092#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005093 // This checks to see if the initial affinity mask is equal
5094 // to a single windows processor group. If it is, then we do
5095 // not respect the initial affinity mask and instead, use the
5096 // entire machine.
5097 bool exactly_one_group = false;
5098 if (__kmp_num_proc_groups > 1) {
5099 int group;
5100 bool within_one_group;
5101 // Get the initial affinity mask and determine if it is
5102 // contained within a single group.
5103 kmp_affin_mask_t *init_mask;
5104 KMP_CPU_ALLOC(init_mask);
5105 __kmp_get_system_affinity(init_mask, TRUE);
5106 group = __kmp_get_proc_group(init_mask);
5107 within_one_group = (group >= 0);
5108 // If the initial affinity is within a single group,
5109 // then determine if it is equal to that single group.
5110 if (within_one_group) {
5111 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
5112 int num_bits_in_mask = 0;
5113 for (int bit = init_mask->begin(); bit != init_mask->end();
5114 bit = init_mask->next(bit))
5115 num_bits_in_mask++;
5116 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
5117 }
5118 KMP_CPU_FREE(init_mask);
5119 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005120
5121 // Handle the Win 64 group affinity stuff if there are multiple
5122 // processor groups, or if the user requested it, and OMP 4.0
5123 // affinity is not in effect.
5124 if (((__kmp_num_proc_groups > 1) &&
5125 (__kmp_affinity_type == affinity_default)
5126#if OMP_40_ENABLED
5127 && (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default))
5128#endif
5129 || (__kmp_affinity_top_method == affinity_top_method_group)) {
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005130 if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
5131 exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005132 __kmp_affinity_respect_mask = FALSE;
5133 }
5134 if (__kmp_affinity_type == affinity_default) {
5135 __kmp_affinity_type = affinity_compact;
5136#if OMP_40_ENABLED
5137 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5138#endif
5139 }
5140 if (__kmp_affinity_top_method == affinity_top_method_default) {
5141 if (__kmp_affinity_gran == affinity_gran_default) {
5142 __kmp_affinity_top_method = affinity_top_method_group;
5143 __kmp_affinity_gran = affinity_gran_group;
5144 } else if (__kmp_affinity_gran == affinity_gran_group) {
5145 __kmp_affinity_top_method = affinity_top_method_group;
5146 } else {
5147 __kmp_affinity_top_method = affinity_top_method_all;
5148 }
5149 } else if (__kmp_affinity_top_method == affinity_top_method_group) {
5150 if (__kmp_affinity_gran == affinity_gran_default) {
5151 __kmp_affinity_gran = affinity_gran_group;
5152 } else if ((__kmp_affinity_gran != affinity_gran_group) &&
5153 (__kmp_affinity_gran != affinity_gran_fine) &&
5154 (__kmp_affinity_gran != affinity_gran_thread)) {
5155 const char *str = NULL;
5156 switch (__kmp_affinity_gran) {
5157 case affinity_gran_core:
5158 str = "core";
5159 break;
5160 case affinity_gran_package:
5161 str = "package";
5162 break;
5163 case affinity_gran_node:
5164 str = "node";
5165 break;
5166 default:
5167 KMP_DEBUG_ASSERT(0);
5168 }
5169 KMP_WARNING(AffGranTopGroup, var, str);
5170 __kmp_affinity_gran = affinity_gran_fine;
5171 }
5172 } else {
5173 if (__kmp_affinity_gran == affinity_gran_default) {
5174 __kmp_affinity_gran = affinity_gran_core;
5175 } else if (__kmp_affinity_gran == affinity_gran_group) {
5176 const char *str = NULL;
5177 switch (__kmp_affinity_type) {
5178 case affinity_physical:
5179 str = "physical";
5180 break;
5181 case affinity_logical:
5182 str = "logical";
5183 break;
5184 case affinity_compact:
5185 str = "compact";
5186 break;
5187 case affinity_scatter:
5188 str = "scatter";
5189 break;
5190 case affinity_explicit:
5191 str = "explicit";
5192 break;
5193 // No MIC on windows, so no affinity_balanced case
5194 default:
5195 KMP_DEBUG_ASSERT(0);
5196 }
5197 KMP_WARNING(AffGranGroupType, var, str);
5198 __kmp_affinity_gran = affinity_gran_core;
5199 }
5200 }
5201 } else
5202
5203#endif /* KMP_GROUP_AFFINITY */
5204
5205 {
5206 if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
5207#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005208 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005209 __kmp_affinity_respect_mask = FALSE;
5210 } else
5211#endif /* KMP_GROUP_AFFINITY */
5212 {
5213 __kmp_affinity_respect_mask = TRUE;
5214 }
5215 }
5216#if OMP_40_ENABLED
5217 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
5218 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
5219 if (__kmp_affinity_type == affinity_default) {
5220 __kmp_affinity_type = affinity_compact;
5221 __kmp_affinity_dups = FALSE;
5222 }
5223 } else
5224#endif /* OMP_40_ENABLED */
5225 if (__kmp_affinity_type == affinity_default) {
5226#if OMP_40_ENABLED
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005227#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005228 if (__kmp_mic_type != non_mic) {
5229 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5230 } else
5231#endif
5232 {
Andrey Churbanov94e569e2015-03-10 09:19:47 +00005233 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
Jonathan Peyton30419822017-05-12 18:01:32 +00005234 }
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005235#endif /* OMP_40_ENABLED */
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005236#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005237 if (__kmp_mic_type != non_mic) {
5238 __kmp_affinity_type = affinity_scatter;
5239 } else
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005240#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005241 {
5242 __kmp_affinity_type = affinity_none;
5243 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005244 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005245 if ((__kmp_affinity_gran == affinity_gran_default) &&
5246 (__kmp_affinity_gran_levels < 0)) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005247#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005248 if (__kmp_mic_type != non_mic) {
5249 __kmp_affinity_gran = affinity_gran_fine;
5250 } else
5251#endif
5252 {
5253 __kmp_affinity_gran = affinity_gran_core;
5254 }
5255 }
5256 if (__kmp_affinity_top_method == affinity_top_method_default) {
5257 __kmp_affinity_top_method = affinity_top_method_all;
5258 }
5259 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005260 }
5261
Jonathan Peyton30419822017-05-12 18:01:32 +00005262 K_DIAG(1, ("__kmp_affinity_type == %d\n", __kmp_affinity_type));
5263 K_DIAG(1, ("__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
5264 K_DIAG(1, ("__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
5265 K_DIAG(1, ("__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
5266 K_DIAG(1, ("__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
5267 K_DIAG(1, ("__kmp_affinity_respect_mask == %d\n",
5268 __kmp_affinity_respect_mask));
5269 K_DIAG(1, ("__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
5270
5271 KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
5272#if OMP_40_ENABLED
5273 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
5274#endif
5275 }
5276
Alp Toker763b9392014-02-28 09:42:41 +00005277#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005278
Jonathan Peyton30419822017-05-12 18:01:32 +00005279 if (__kmp_version) {
5280 __kmp_print_version_1();
5281 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00005282
Jonathan Peyton30419822017-05-12 18:01:32 +00005283 // Post-initialization step: some env. vars need their value's further
5284 // processing
5285 if (string != NULL) { // kmp_set_defaults() was called
5286 __kmp_aux_env_initialize(&block);
5287 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005288
Jonathan Peyton30419822017-05-12 18:01:32 +00005289 __kmp_env_blk_free(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005290
Jonathan Peyton30419822017-05-12 18:01:32 +00005291 KMP_MB();
Jim Cownie5e8470a2013-09-27 10:38:44 +00005292
5293} // __kmp_env_initialize
5294
Jonathan Peyton30419822017-05-12 18:01:32 +00005295void __kmp_env_print() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005296
Jonathan Peyton30419822017-05-12 18:01:32 +00005297 kmp_env_blk_t block;
5298 int i;
5299 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005300
Jonathan Peyton30419822017-05-12 18:01:32 +00005301 __kmp_stg_init();
5302 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005303
Jonathan Peyton30419822017-05-12 18:01:32 +00005304 __kmp_env_blk_init(&block, NULL);
5305 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005306
Jonathan Peyton30419822017-05-12 18:01:32 +00005307 // Print real environment values.
5308 __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
5309 for (i = 0; i < block.count; ++i) {
5310 char const *name = block.vars[i].name;
5311 char const *value = block.vars[i].value;
5312 if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
5313 strncmp(name, "OMP_", 4) == 0
5314#ifdef KMP_GOMP_COMPAT
5315 || strncmp(name, "GOMP_", 5) == 0
5316#endif // KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00005317 ) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005318 __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
5319 }; // if
5320 }; // for
5321 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005322
Jonathan Peyton30419822017-05-12 18:01:32 +00005323 // Print internal (effective) settings.
5324 __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
5325 for (int i = 0; i < __kmp_stg_count; ++i) {
5326 if (__kmp_stg_table[i].print != NULL) {
5327 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5328 __kmp_stg_table[i].data);
5329 }; // if
5330 }; // for
Jim Cownie5e8470a2013-09-27 10:38:44 +00005331
Jonathan Peyton30419822017-05-12 18:01:32 +00005332 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005333
Jonathan Peyton30419822017-05-12 18:01:32 +00005334 __kmp_env_blk_free(&block);
5335 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005336
Jonathan Peyton30419822017-05-12 18:01:32 +00005337 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005338
5339} // __kmp_env_print
5340
Jim Cownie5e8470a2013-09-27 10:38:44 +00005341#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005342void __kmp_env_print_2() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005343
Jonathan Peyton30419822017-05-12 18:01:32 +00005344 kmp_env_blk_t block;
5345 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005346
Jonathan Peyton30419822017-05-12 18:01:32 +00005347 __kmp_env_format = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005348
Jonathan Peyton30419822017-05-12 18:01:32 +00005349 __kmp_stg_init();
5350 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005351
Jonathan Peyton30419822017-05-12 18:01:32 +00005352 __kmp_env_blk_init(&block, NULL);
5353 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005354
Jonathan Peyton30419822017-05-12 18:01:32 +00005355 __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
5356 __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005357
Jonathan Peyton30419822017-05-12 18:01:32 +00005358 for (int i = 0; i < __kmp_stg_count; ++i) {
5359 if (__kmp_stg_table[i].print != NULL &&
5360 ((__kmp_display_env &&
5361 strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
5362 __kmp_display_env_verbose)) {
5363 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5364 __kmp_stg_table[i].data);
5365 }; // if
5366 }; // for
Jim Cownie5e8470a2013-09-27 10:38:44 +00005367
Jonathan Peyton30419822017-05-12 18:01:32 +00005368 __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
5369 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005370
Jonathan Peyton30419822017-05-12 18:01:32 +00005371 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005372
Jonathan Peyton30419822017-05-12 18:01:32 +00005373 __kmp_env_blk_free(&block);
5374 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005375
Jonathan Peyton30419822017-05-12 18:01:32 +00005376 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005377
5378} // __kmp_env_print_2
5379#endif // OMP_40_ENABLED
5380
Jim Cownie5e8470a2013-09-27 10:38:44 +00005381// end of file