blob: 7bef5a36d7a90a8b05b09df0f5862cbdd43e914e [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 Peytond74d8902017-07-25 18:20:16 +0000644// Used for OMP_WAIT_POLICY
645static char const *blocktime_str = NULL;
646
Jonathan Peyton30419822017-05-12 18:01:32 +0000647// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000648// KMP_DUPLICATE_LIB_OK
Jim Cownie5e8470a2013-09-27 10:38:44 +0000649
Jonathan Peyton30419822017-05-12 18:01:32 +0000650static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
651 char const *value, void *data) {
652 /* actually this variable is not supported, put here for compatibility with
653 earlier builds and for static/dynamic combination */
654 __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000655} // __kmp_stg_parse_duplicate_lib_ok
656
Jonathan Peyton30419822017-05-12 18:01:32 +0000657static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
658 char const *name, void *data) {
659 __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000660} // __kmp_stg_print_duplicate_lib_ok
661
Jonathan Peyton30419822017-05-12 18:01:32 +0000662// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000663// KMP_INHERIT_FP_CONTROL
Jim Cownie5e8470a2013-09-27 10:38:44 +0000664
665#if KMP_ARCH_X86 || KMP_ARCH_X86_64
666
Jonathan Peyton30419822017-05-12 18:01:32 +0000667static void __kmp_stg_parse_inherit_fp_control(char const *name,
668 char const *value, void *data) {
669 __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000670} // __kmp_stg_parse_inherit_fp_control
671
Jonathan Peyton30419822017-05-12 18:01:32 +0000672static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
673 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000674#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000675 __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000676#endif /* KMP_DEBUG */
677} // __kmp_stg_print_inherit_fp_control
678
679#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
680
Jonathan Peyton30419822017-05-12 18:01:32 +0000681// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000682// KMP_LIBRARY, OMP_WAIT_POLICY
Jim Cownie5e8470a2013-09-27 10:38:44 +0000683
Jonathan Peyton30419822017-05-12 18:01:32 +0000684static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
685 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000686
Jonathan Peyton30419822017-05-12 18:01:32 +0000687 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
688 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000689
Jonathan Peyton30419822017-05-12 18:01:32 +0000690 rc = __kmp_stg_check_rivals(name, value, wait->rivals);
691 if (rc) {
692 return;
693 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +0000694
Jonathan Peyton30419822017-05-12 18:01:32 +0000695 if (wait->omp) {
696 if (__kmp_str_match("ACTIVE", 1, value)) {
697 __kmp_library = library_turnaround;
698 if (blocktime_str == NULL) {
699 // KMP_BLOCKTIME not specified, so set default to "infinite".
700 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
701 }
702 } else if (__kmp_str_match("PASSIVE", 1, value)) {
703 __kmp_library = library_throughput;
704 if (blocktime_str == NULL) {
705 // KMP_BLOCKTIME not specified, so set default to 0.
706 __kmp_dflt_blocktime = 0;
707 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000708 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +0000709 KMP_WARNING(StgInvalidValue, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000710 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000711 } else {
712 if (__kmp_str_match("serial", 1, value)) { /* S */
713 __kmp_library = library_serial;
714 } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
715 __kmp_library = library_throughput;
716 } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
717 __kmp_library = library_turnaround;
718 } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
719 __kmp_library = library_turnaround;
720 } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
721 __kmp_library = library_throughput;
722 } else {
723 KMP_WARNING(StgInvalidValue, name, value);
724 }; // if
725 }; // if
726 __kmp_aux_set_library(__kmp_library);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000727
728} // __kmp_stg_parse_wait_policy
729
Jonathan Peyton30419822017-05-12 18:01:32 +0000730static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
731 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000732
Jonathan Peyton30419822017-05-12 18:01:32 +0000733 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
734 char const *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000735
Jonathan Peyton30419822017-05-12 18:01:32 +0000736 if (wait->omp) {
737 switch (__kmp_library) {
738 case library_turnaround: {
739 value = "ACTIVE";
740 } break;
741 case library_throughput: {
742 value = "PASSIVE";
743 } break;
744 }; // switch
745 } else {
746 switch (__kmp_library) {
747 case library_serial: {
748 value = "serial";
749 } break;
750 case library_turnaround: {
751 value = "turnaround";
752 } break;
753 case library_throughput: {
754 value = "throughput";
755 } break;
756 }; // switch
757 }; // if
758 if (value != NULL) {
759 __kmp_stg_print_str(buffer, name, value);
760 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +0000761
762} // __kmp_stg_print_wait_policy
763
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000764#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +0000765// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000766// KMP_MONITOR_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000767
Jonathan Peyton30419822017-05-12 18:01:32 +0000768static void __kmp_stg_parse_monitor_stacksize(char const *name,
769 char const *value, void *data) {
770 __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
771 NULL, &__kmp_monitor_stksize, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000772} // __kmp_stg_parse_monitor_stacksize
773
Jonathan Peyton30419822017-05-12 18:01:32 +0000774static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
775 char const *name, void *data) {
776 if (__kmp_env_format) {
777 if (__kmp_monitor_stksize > 0)
778 KMP_STR_BUF_PRINT_NAME_EX(name);
779 else
780 KMP_STR_BUF_PRINT_NAME;
781 } else {
782 __kmp_str_buf_print(buffer, " %s", name);
783 }
784 if (__kmp_monitor_stksize > 0) {
785 __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
786 } else {
787 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
788 }
789 if (__kmp_env_format && __kmp_monitor_stksize) {
790 __kmp_str_buf_print(buffer, "'\n");
791 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000792} // __kmp_stg_print_monitor_stacksize
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000793#endif // KMP_USE_MONITOR
Jim Cownie5e8470a2013-09-27 10:38:44 +0000794
Jonathan Peyton30419822017-05-12 18:01:32 +0000795// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000796// KMP_SETTINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000797
Jonathan Peyton30419822017-05-12 18:01:32 +0000798static void __kmp_stg_parse_settings(char const *name, char const *value,
799 void *data) {
800 __kmp_stg_parse_bool(name, value, &__kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000801} // __kmp_stg_parse_settings
802
Jonathan Peyton30419822017-05-12 18:01:32 +0000803static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
804 void *data) {
805 __kmp_stg_print_bool(buffer, name, __kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000806} // __kmp_stg_print_settings
807
Jonathan Peyton30419822017-05-12 18:01:32 +0000808// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000809// KMP_STACKPAD
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000810
Jonathan Peyton30419822017-05-12 18:01:32 +0000811static void __kmp_stg_parse_stackpad(char const *name, char const *value,
812 void *data) {
813 __kmp_stg_parse_int(name, // Env var name
814 value, // Env var value
815 KMP_MIN_STKPADDING, // Min value
816 KMP_MAX_STKPADDING, // Max value
817 &__kmp_stkpadding // Var to initialize
818 );
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000819} // __kmp_stg_parse_stackpad
820
Jonathan Peyton30419822017-05-12 18:01:32 +0000821static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
822 void *data) {
823 __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000824} // __kmp_stg_print_stackpad
825
Jonathan Peyton30419822017-05-12 18:01:32 +0000826// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000827// KMP_STACKOFFSET
Jim Cownie5e8470a2013-09-27 10:38:44 +0000828
Jonathan Peyton30419822017-05-12 18:01:32 +0000829static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
830 void *data) {
831 __kmp_stg_parse_size(name, // Env var name
832 value, // Env var value
833 KMP_MIN_STKOFFSET, // Min value
834 KMP_MAX_STKOFFSET, // Max value
835 NULL, //
836 &__kmp_stkoffset, // Var to initialize
837 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000838} // __kmp_stg_parse_stackoffset
839
Jonathan Peyton30419822017-05-12 18:01:32 +0000840static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
841 void *data) {
842 __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000843} // __kmp_stg_print_stackoffset
844
Jonathan Peyton30419822017-05-12 18:01:32 +0000845// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000846// KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000847
Jonathan Peyton30419822017-05-12 18:01:32 +0000848static void __kmp_stg_parse_stacksize(char const *name, char const *value,
849 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000850
Jonathan Peyton30419822017-05-12 18:01:32 +0000851 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
852 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000853
Jonathan Peyton30419822017-05-12 18:01:32 +0000854 rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
855 if (rc) {
856 return;
857 }; // if
858 __kmp_stg_parse_size(name, // Env var name
859 value, // Env var value
860 __kmp_sys_min_stksize, // Min value
861 KMP_MAX_STKSIZE, // Max value
862 &__kmp_env_stksize, //
863 &__kmp_stksize, // Var to initialize
864 stacksize->factor);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000865
866} // __kmp_stg_parse_stacksize
867
Jonathan Peyton30419822017-05-12 18:01:32 +0000868// This function is called for printing both KMP_STACKSIZE (factor is 1) and
869// OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
870// OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
871// customer request in future.
872static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
873 void *data) {
874 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
875 if (__kmp_env_format) {
876 KMP_STR_BUF_PRINT_NAME_EX(name);
877 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
878 ? __kmp_stksize / stacksize->factor
879 : __kmp_stksize);
880 __kmp_str_buf_print(buffer, "'\n");
881 } else {
882 __kmp_str_buf_print(buffer, " %s=", name);
883 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
884 ? __kmp_stksize / stacksize->factor
885 : __kmp_stksize);
886 __kmp_str_buf_print(buffer, "\n");
887 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000888} // __kmp_stg_print_stacksize
889
Jonathan Peyton30419822017-05-12 18:01:32 +0000890// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000891// KMP_VERSION
Jim Cownie5e8470a2013-09-27 10:38:44 +0000892
Jonathan Peyton30419822017-05-12 18:01:32 +0000893static void __kmp_stg_parse_version(char const *name, char const *value,
894 void *data) {
895 __kmp_stg_parse_bool(name, value, &__kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000896} // __kmp_stg_parse_version
897
Jonathan Peyton30419822017-05-12 18:01:32 +0000898static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
899 void *data) {
900 __kmp_stg_print_bool(buffer, name, __kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000901} // __kmp_stg_print_version
902
Jonathan Peyton30419822017-05-12 18:01:32 +0000903// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000904// KMP_WARNINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000905
Jonathan Peyton30419822017-05-12 18:01:32 +0000906static void __kmp_stg_parse_warnings(char const *name, char const *value,
907 void *data) {
908 __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
909 if (__kmp_generate_warnings != kmp_warnings_off) {
910 // AC: only 0/1 values documented, so reset to explicit to distinguish from
911 // default setting
912 __kmp_generate_warnings = kmp_warnings_explicit;
913 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000914} // __kmp_stg_parse_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000915
Jonathan Peyton30419822017-05-12 18:01:32 +0000916static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
917 void *data) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000918 // AC: TODO: change to print_int? (needs documentation change)
919 __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
920} // __kmp_stg_print_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000921
Jonathan Peyton30419822017-05-12 18:01:32 +0000922// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000923// OMP_NESTED, OMP_NUM_THREADS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000924
Jonathan Peyton30419822017-05-12 18:01:32 +0000925static void __kmp_stg_parse_nested(char const *name, char const *value,
926 void *data) {
927 __kmp_stg_parse_bool(name, value, &__kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000928} // __kmp_stg_parse_nested
929
Jonathan Peyton30419822017-05-12 18:01:32 +0000930static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
931 void *data) {
932 __kmp_stg_print_bool(buffer, name, __kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000933} // __kmp_stg_print_nested
934
Jonathan Peyton30419822017-05-12 18:01:32 +0000935static void __kmp_parse_nested_num_threads(const char *var, const char *env,
936 kmp_nested_nthreads_t *nth_array) {
937 const char *next = env;
938 const char *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000939
Jonathan Peyton30419822017-05-12 18:01:32 +0000940 int total = 0; // Count elements that were set. It'll be used as an array size
941 int prev_comma = FALSE; // For correct processing sequential commas
Jim Cownie5e8470a2013-09-27 10:38:44 +0000942
Jonathan Peyton30419822017-05-12 18:01:32 +0000943 // Count the number of values in the env. var string
944 for (;;) {
945 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000946
Jonathan Peyton30419822017-05-12 18:01:32 +0000947 if (*next == '\0') {
948 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000949 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000950 // Next character is not an integer or not a comma => end of list
951 if (((*next < '0') || (*next > '9')) && (*next != ',')) {
952 KMP_WARNING(NthSyntaxError, var, env);
953 return;
954 }
955 // The next character is ','
956 if (*next == ',') {
957 // ',' is the fisrt character
958 if (total == 0 || prev_comma) {
959 total++;
960 }
961 prev_comma = TRUE;
962 next++; // skip ','
963 SKIP_WS(next);
964 }
965 // Next character is a digit
966 if (*next >= '0' && *next <= '9') {
967 prev_comma = FALSE;
968 SKIP_DIGITS(next);
969 total++;
970 const char *tmp = next;
971 SKIP_WS(tmp);
972 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
973 KMP_WARNING(NthSpacesNotAllowed, var, env);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000974 return;
Jonathan Peyton30419822017-05-12 18:01:32 +0000975 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000976 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000977 }
978 KMP_DEBUG_ASSERT(total > 0);
979 if (total <= 0) {
980 KMP_WARNING(NthSyntaxError, var, env);
981 return;
982 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000983
Jonathan Peyton30419822017-05-12 18:01:32 +0000984 // Check if the nested nthreads array exists
985 if (!nth_array->nth) {
986 // Allocate an array of double size
987 nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
988 if (nth_array->nth == NULL) {
989 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000990 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000991 nth_array->size = total * 2;
992 } else {
993 if (nth_array->size < total) {
994 // Increase the array size
995 do {
996 nth_array->size *= 2;
997 } while (nth_array->size < total);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000998
Jonathan Peyton30419822017-05-12 18:01:32 +0000999 nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
1000 nth_array->nth, sizeof(int) * nth_array->size);
1001 if (nth_array->nth == NULL) {
1002 KMP_FATAL(MemoryAllocFailed);
1003 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001004 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001005 }
1006 nth_array->used = total;
1007 int i = 0;
1008
1009 prev_comma = FALSE;
1010 total = 0;
1011 // Save values in the array
1012 for (;;) {
1013 SKIP_WS(scan);
1014 if (*scan == '\0') {
1015 break;
1016 }
1017 // The next character is ','
1018 if (*scan == ',') {
1019 // ',' in the beginning of the list
1020 if (total == 0) {
1021 // The value is supposed to be equal to __kmp_avail_proc but it is
1022 // unknown at the moment.
1023 // So let's put a placeholder (#threads = 0) to correct it later.
1024 nth_array->nth[i++] = 0;
1025 total++;
1026 } else if (prev_comma) {
1027 // Num threads is inherited from the previous level
1028 nth_array->nth[i] = nth_array->nth[i - 1];
1029 i++;
1030 total++;
1031 }
1032 prev_comma = TRUE;
1033 scan++; // skip ','
1034 SKIP_WS(scan);
1035 }
1036 // Next character is a digit
1037 if (*scan >= '0' && *scan <= '9') {
1038 int num;
1039 const char *buf = scan;
1040 char const *msg = NULL;
1041 prev_comma = FALSE;
1042 SKIP_DIGITS(scan);
1043 total++;
1044
1045 num = __kmp_str_to_int(buf, *scan);
1046 if (num < KMP_MIN_NTH) {
1047 msg = KMP_I18N_STR(ValueTooSmall);
1048 num = KMP_MIN_NTH;
1049 } else if (num > __kmp_sys_max_nth) {
1050 msg = KMP_I18N_STR(ValueTooLarge);
1051 num = __kmp_sys_max_nth;
1052 }
1053 if (msg != NULL) {
1054 // Message is not empty. Print warning.
1055 KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1056 KMP_INFORM(Using_int_Value, var, num);
1057 }
1058 nth_array->nth[i++] = num;
1059 }
1060 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001061}
1062
Jonathan Peyton30419822017-05-12 18:01:32 +00001063static void __kmp_stg_parse_num_threads(char const *name, char const *value,
1064 void *data) {
1065 // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
1066 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
1067 // The array of 1 element
1068 __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
1069 __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1070 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1071 __kmp_xproc;
1072 } else {
1073 __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1074 if (__kmp_nested_nth.nth) {
1075 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1076 if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1077 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1078 }
1079 }
1080 }; // if
1081 K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001082} // __kmp_stg_parse_num_threads
1083
Jonathan Peyton30419822017-05-12 18:01:32 +00001084static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
1085 void *data) {
1086 if (__kmp_env_format) {
1087 KMP_STR_BUF_PRINT_NAME;
1088 } else {
1089 __kmp_str_buf_print(buffer, " %s", name);
1090 }
1091 if (__kmp_nested_nth.used) {
1092 kmp_str_buf_t buf;
1093 __kmp_str_buf_init(&buf);
1094 for (int i = 0; i < __kmp_nested_nth.used; i++) {
1095 __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
1096 if (i < __kmp_nested_nth.used - 1) {
1097 __kmp_str_buf_print(&buf, ",");
1098 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001099 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001100 __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
1101 __kmp_str_buf_free(&buf);
1102 } else {
1103 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1104 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001105} // __kmp_stg_print_num_threads
1106
Jonathan Peyton30419822017-05-12 18:01:32 +00001107// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001108// OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001109
Jonathan Peyton30419822017-05-12 18:01:32 +00001110static void __kmp_stg_parse_tasking(char const *name, char const *value,
1111 void *data) {
1112 __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
1113 (int *)&__kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001114} // __kmp_stg_parse_tasking
1115
Jonathan Peyton30419822017-05-12 18:01:32 +00001116static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
1117 void *data) {
1118 __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001119} // __kmp_stg_print_tasking
1120
Jonathan Peyton30419822017-05-12 18:01:32 +00001121static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
1122 void *data) {
1123 __kmp_stg_parse_int(name, value, 0, 1,
1124 (int *)&__kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001125} // __kmp_stg_parse_task_stealing
1126
Jonathan Peyton30419822017-05-12 18:01:32 +00001127static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1128 char const *name, void *data) {
1129 __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001130} // __kmp_stg_print_task_stealing
1131
Jonathan Peyton30419822017-05-12 18:01:32 +00001132static void __kmp_stg_parse_max_active_levels(char const *name,
1133 char const *value, void *data) {
1134 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1135 &__kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001136} // __kmp_stg_parse_max_active_levels
1137
Jonathan Peyton30419822017-05-12 18:01:32 +00001138static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1139 char const *name, void *data) {
1140 __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001141} // __kmp_stg_print_max_active_levels
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001142
George Rokos28f31b42016-09-09 17:55:26 +00001143#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001144// -----------------------------------------------------------------------------
George Rokos28f31b42016-09-09 17:55:26 +00001145// OpenMP 4.0: OMP_DEFAULT_DEVICE
Jonathan Peyton30419822017-05-12 18:01:32 +00001146static void __kmp_stg_parse_default_device(char const *name, char const *value,
1147 void *data) {
1148 __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1149 &__kmp_default_device);
George Rokos28f31b42016-09-09 17:55:26 +00001150} // __kmp_stg_parse_default_device
1151
Jonathan Peyton30419822017-05-12 18:01:32 +00001152static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1153 char const *name, void *data) {
George Rokos28f31b42016-09-09 17:55:26 +00001154 __kmp_stg_print_int(buffer, name, __kmp_default_device);
1155} // __kmp_stg_print_default_device
1156#endif
1157
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001158#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001159// -----------------------------------------------------------------------------
Jonathan Peyton28510722016-02-25 18:04:09 +00001160// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
Jonathan Peyton30419822017-05-12 18:01:32 +00001161static void __kmp_stg_parse_max_task_priority(char const *name,
1162 char const *value, void *data) {
1163 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1164 &__kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001165} // __kmp_stg_parse_max_task_priority
1166
Jonathan Peyton30419822017-05-12 18:01:32 +00001167static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1168 char const *name, void *data) {
1169 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001170} // __kmp_stg_print_max_task_priority
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001171
1172// KMP_TASKLOOP_MIN_TASKS
1173// taskloop threashold to switch from recursive to linear tasks creation
1174static void __kmp_stg_parse_taskloop_min_tasks(char const *name,
Jonathan Peytond74d8902017-07-25 18:20:16 +00001175 char const *value, void *data) {
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001176 int tmp;
1177 __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1178 __kmp_taskloop_min_tasks = tmp;
1179} // __kmp_stg_parse_taskloop_min_tasks
1180
1181static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
Jonathan Peytond74d8902017-07-25 18:20:16 +00001182 char const *name, void *data) {
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001183 __kmp_stg_print_int(buffer, name, __kmp_taskloop_min_tasks);
1184} // __kmp_stg_print_taskloop_min_tasks
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001185#endif // OMP_45_ENABLED
Jonathan Peyton28510722016-02-25 18:04:09 +00001186
Jonathan Peyton30419822017-05-12 18:01:32 +00001187// -----------------------------------------------------------------------------
Jonathan Peyton067325f2016-05-31 19:01:15 +00001188// KMP_DISP_NUM_BUFFERS
Jonathan Peyton30419822017-05-12 18:01:32 +00001189static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
1190 void *data) {
1191 if (TCR_4(__kmp_init_serial)) {
1192 KMP_WARNING(EnvSerialWarn, name);
1193 return;
1194 } // read value before serial initialization only
1195 __kmp_stg_parse_int(name, value, 1, KMP_MAX_NTH, &__kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001196} // __kmp_stg_parse_disp_buffers
1197
Jonathan Peyton30419822017-05-12 18:01:32 +00001198static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1199 char const *name, void *data) {
1200 __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001201} // __kmp_stg_print_disp_buffers
1202
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001203#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00001204// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001205// KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001206
Jonathan Peyton30419822017-05-12 18:01:32 +00001207static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
1208 void *data) {
1209 if (TCR_4(__kmp_init_parallel)) {
1210 KMP_WARNING(EnvParallelWarn, name);
1211 return;
1212 } // read value before first parallel only
1213 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1214 &__kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001215} // __kmp_stg_parse_hot_teams_level
1216
Jonathan Peyton30419822017-05-12 18:01:32 +00001217static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1218 char const *name, void *data) {
1219 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001220} // __kmp_stg_print_hot_teams_level
1221
Jonathan Peyton30419822017-05-12 18:01:32 +00001222static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
1223 void *data) {
1224 if (TCR_4(__kmp_init_parallel)) {
1225 KMP_WARNING(EnvParallelWarn, name);
1226 return;
1227 } // read value before first parallel only
1228 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1229 &__kmp_hot_teams_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001230} // __kmp_stg_parse_hot_teams_mode
1231
Jonathan Peyton30419822017-05-12 18:01:32 +00001232static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1233 char const *name, void *data) {
1234 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001235} // __kmp_stg_print_hot_teams_mode
1236
1237#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001238
Jonathan Peyton30419822017-05-12 18:01:32 +00001239// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001240// KMP_HANDLE_SIGNALS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001241
1242#if KMP_HANDLE_SIGNALS
1243
Jonathan Peyton30419822017-05-12 18:01:32 +00001244static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
1245 void *data) {
1246 __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001247} // __kmp_stg_parse_handle_signals
1248
Jonathan Peyton30419822017-05-12 18:01:32 +00001249static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1250 char const *name, void *data) {
1251 __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001252} // __kmp_stg_print_handle_signals
1253
1254#endif // KMP_HANDLE_SIGNALS
1255
Jonathan Peyton30419822017-05-12 18:01:32 +00001256// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001257// KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
Jim Cownie5e8470a2013-09-27 10:38:44 +00001258
1259#ifdef KMP_DEBUG
1260
Jonathan Peyton30419822017-05-12 18:01:32 +00001261#define KMP_STG_X_DEBUG(x) \
1262 static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1263 void *data) { \
1264 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1265 } /* __kmp_stg_parse_x_debug */ \
1266 static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1267 char const *name, void *data) { \
1268 __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1269 } /* __kmp_stg_print_x_debug */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001270
Jonathan Peyton30419822017-05-12 18:01:32 +00001271KMP_STG_X_DEBUG(a)
1272KMP_STG_X_DEBUG(b)
1273KMP_STG_X_DEBUG(c)
1274KMP_STG_X_DEBUG(d)
1275KMP_STG_X_DEBUG(e)
1276KMP_STG_X_DEBUG(f)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001277
1278#undef KMP_STG_X_DEBUG
1279
Jonathan Peyton30419822017-05-12 18:01:32 +00001280static void __kmp_stg_parse_debug(char const *name, char const *value,
1281 void *data) {
1282 int debug = 0;
1283 __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1284 if (kmp_a_debug < debug) {
1285 kmp_a_debug = debug;
1286 }; // if
1287 if (kmp_b_debug < debug) {
1288 kmp_b_debug = debug;
1289 }; // if
1290 if (kmp_c_debug < debug) {
1291 kmp_c_debug = debug;
1292 }; // if
1293 if (kmp_d_debug < debug) {
1294 kmp_d_debug = debug;
1295 }; // if
1296 if (kmp_e_debug < debug) {
1297 kmp_e_debug = debug;
1298 }; // if
1299 if (kmp_f_debug < debug) {
1300 kmp_f_debug = debug;
1301 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00001302} // __kmp_stg_parse_debug
1303
Jonathan Peyton30419822017-05-12 18:01:32 +00001304static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
1305 void *data) {
1306 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1307 // !!! TODO: Move buffer initialization of of this file! It may works
1308 // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
1309 // KMP_DEBUG_BUF_CHARS.
1310 if (__kmp_debug_buf) {
1311 int i;
1312 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001313
Jonathan Peyton30419822017-05-12 18:01:32 +00001314 /* allocate and initialize all entries in debug buffer to empty */
1315 __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
1316 for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1317 __kmp_debug_buffer[i] = '\0';
Jim Cownie5e8470a2013-09-27 10:38:44 +00001318
Jonathan Peyton30419822017-05-12 18:01:32 +00001319 __kmp_debug_count = 0;
1320 }
1321 K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001322} // __kmp_stg_parse_debug_buf
1323
Jonathan Peyton30419822017-05-12 18:01:32 +00001324static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
1325 void *data) {
1326 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001327} // __kmp_stg_print_debug_buf
1328
Jonathan Peyton30419822017-05-12 18:01:32 +00001329static void __kmp_stg_parse_debug_buf_atomic(char const *name,
1330 char const *value, void *data) {
1331 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001332} // __kmp_stg_parse_debug_buf_atomic
1333
Jonathan Peyton30419822017-05-12 18:01:32 +00001334static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1335 char const *name, void *data) {
1336 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001337} // __kmp_stg_print_debug_buf_atomic
1338
Jonathan Peyton30419822017-05-12 18:01:32 +00001339static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
1340 void *data) {
1341 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1342 &__kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001343} // __kmp_stg_debug_parse_buf_chars
1344
Jonathan Peyton30419822017-05-12 18:01:32 +00001345static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1346 char const *name, void *data) {
1347 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001348} // __kmp_stg_print_debug_buf_chars
1349
Jonathan Peyton30419822017-05-12 18:01:32 +00001350static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
1351 void *data) {
1352 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1353 &__kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001354} // __kmp_stg_parse_debug_buf_lines
1355
Jonathan Peyton30419822017-05-12 18:01:32 +00001356static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1357 char const *name, void *data) {
1358 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001359} // __kmp_stg_print_debug_buf_lines
1360
Jonathan Peyton30419822017-05-12 18:01:32 +00001361static void __kmp_stg_parse_diag(char const *name, char const *value,
1362 void *data) {
1363 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001364} // __kmp_stg_parse_diag
1365
Jonathan Peyton30419822017-05-12 18:01:32 +00001366static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
1367 void *data) {
1368 __kmp_stg_print_int(buffer, name, kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001369} // __kmp_stg_print_diag
1370
1371#endif // KMP_DEBUG
1372
Jonathan Peyton30419822017-05-12 18:01:32 +00001373// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001374// KMP_ALIGN_ALLOC
Jim Cownie5e8470a2013-09-27 10:38:44 +00001375
Jonathan Peyton30419822017-05-12 18:01:32 +00001376static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
1377 void *data) {
1378 __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1379 &__kmp_align_alloc, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001380} // __kmp_stg_parse_align_alloc
1381
Jonathan Peyton30419822017-05-12 18:01:32 +00001382static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
1383 void *data) {
1384 __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001385} // __kmp_stg_print_align_alloc
1386
Jonathan Peyton30419822017-05-12 18:01:32 +00001387// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001388// KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
Jim Cownie5e8470a2013-09-27 10:38:44 +00001389
Jonathan Peyton30419822017-05-12 18:01:32 +00001390// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
1391// parse and print functions, pass required info through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001392
Jonathan Peyton30419822017-05-12 18:01:32 +00001393static void __kmp_stg_parse_barrier_branch_bit(char const *name,
1394 char const *value, void *data) {
1395 const char *var;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001396
Jonathan Peyton30419822017-05-12 18:01:32 +00001397 /* ---------- Barrier branch bit control ------------ */
1398 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1399 var = __kmp_barrier_branch_bit_env_name[i];
1400 if ((strcmp(var, name) == 0) && (value != 0)) {
1401 char *comma;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001402
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001403 comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00001404 __kmp_barrier_gather_branch_bits[i] =
1405 (kmp_uint32)__kmp_str_to_int(value, ',');
1406 /* is there a specified release parameter? */
1407 if (comma == NULL) {
1408 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1409 } else {
1410 __kmp_barrier_release_branch_bits[i] =
1411 (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001412
Jonathan Peyton30419822017-05-12 18:01:32 +00001413 if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1414 __kmp_msg(kmp_ms_warning,
1415 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1416 __kmp_msg_null);
1417 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001418 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001419 }
1420 if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1421 KMP_WARNING(BarrGatherValueInvalid, name, value);
1422 KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1423 __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1424 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001425 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001426 K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1427 __kmp_barrier_gather_branch_bits[i],
1428 __kmp_barrier_release_branch_bits[i]))
1429 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001430} // __kmp_stg_parse_barrier_branch_bit
1431
Jonathan Peyton30419822017-05-12 18:01:32 +00001432static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1433 char const *name, void *data) {
1434 const char *var;
1435 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1436 var = __kmp_barrier_branch_bit_env_name[i];
1437 if (strcmp(var, name) == 0) {
1438 if (__kmp_env_format) {
1439 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1440 } else {
1441 __kmp_str_buf_print(buffer, " %s='",
1442 __kmp_barrier_branch_bit_env_name[i]);
1443 }
1444 __kmp_str_buf_print(buffer, "%d,%d'\n",
1445 __kmp_barrier_gather_branch_bits[i],
1446 __kmp_barrier_release_branch_bits[i]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001447 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001448 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001449} // __kmp_stg_print_barrier_branch_bit
1450
Jonathan Peyton30419822017-05-12 18:01:32 +00001451// ----------------------------------------------------------------------------
1452// KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
1453// KMP_REDUCTION_BARRIER_PATTERN
Jim Cownie5e8470a2013-09-27 10:38:44 +00001454
Jonathan Peyton30419822017-05-12 18:01:32 +00001455// TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
1456// print functions, pass required data to functions through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001457
Jonathan Peyton30419822017-05-12 18:01:32 +00001458static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
1459 void *data) {
1460 const char *var;
1461 /* ---------- Barrier method control ------------ */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001462
Jonathan Peyton30419822017-05-12 18:01:32 +00001463 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1464 var = __kmp_barrier_pattern_env_name[i];
Jim Cownie5e8470a2013-09-27 10:38:44 +00001465
Jonathan Peyton30419822017-05-12 18:01:32 +00001466 if ((strcmp(var, name) == 0) && (value != 0)) {
1467 int j;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001468 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001469
Jonathan Peyton30419822017-05-12 18:01:32 +00001470 /* handle first parameter: gather pattern */
1471 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1472 if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1473 ',')) {
1474 __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1475 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001476 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001477 }
1478 if (j == bp_last_bar) {
1479 KMP_WARNING(BarrGatherValueInvalid, name, value);
1480 KMP_INFORM(Using_str_Value, name,
1481 __kmp_barrier_pattern_name[bp_linear_bar]);
1482 }
1483
1484 /* handle second parameter: release pattern */
1485 if (comma != NULL) {
1486 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1487 if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1488 __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1489 break;
1490 }
1491 }
1492 if (j == bp_last_bar) {
1493 __kmp_msg(kmp_ms_warning,
1494 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1495 __kmp_msg_null);
1496 KMP_INFORM(Using_str_Value, name,
1497 __kmp_barrier_pattern_name[bp_linear_bar]);
1498 }
1499 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001500 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001501 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001502} // __kmp_stg_parse_barrier_pattern
1503
Jonathan Peyton30419822017-05-12 18:01:32 +00001504static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1505 char const *name, void *data) {
1506 const char *var;
1507 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1508 var = __kmp_barrier_pattern_env_name[i];
1509 if (strcmp(var, name) == 0) {
1510 int j = __kmp_barrier_gather_pattern[i];
1511 int k = __kmp_barrier_release_pattern[i];
1512 if (__kmp_env_format) {
1513 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1514 } else {
1515 __kmp_str_buf_print(buffer, " %s='",
1516 __kmp_barrier_pattern_env_name[i]);
1517 }
1518 __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
1519 __kmp_barrier_pattern_name[k]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001520 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001521 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001522} // __kmp_stg_print_barrier_pattern
1523
Jonathan Peyton30419822017-05-12 18:01:32 +00001524// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001525// KMP_ABORT_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00001526
Jonathan Peyton30419822017-05-12 18:01:32 +00001527static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
1528 void *data) {
1529 // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
1530 // milliseconds.
1531 int delay = __kmp_abort_delay / 1000;
1532 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1533 __kmp_abort_delay = delay * 1000;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001534} // __kmp_stg_parse_abort_delay
1535
Jonathan Peyton30419822017-05-12 18:01:32 +00001536static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
1537 void *data) {
1538 __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001539} // __kmp_stg_print_abort_delay
1540
Jonathan Peyton30419822017-05-12 18:01:32 +00001541// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001542// KMP_CPUINFO_FILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001543
Jonathan Peyton30419822017-05-12 18:01:32 +00001544static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
1545 void *data) {
1546#if KMP_AFFINITY_SUPPORTED
1547 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1548 K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1549#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001550} //__kmp_stg_parse_cpuinfo_file
1551
Jonathan Peyton30419822017-05-12 18:01:32 +00001552static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1553 char const *name, void *data) {
1554#if KMP_AFFINITY_SUPPORTED
1555 if (__kmp_env_format) {
1556 KMP_STR_BUF_PRINT_NAME;
1557 } else {
1558 __kmp_str_buf_print(buffer, " %s", name);
1559 }
1560 if (__kmp_cpuinfo_file) {
1561 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
1562 } else {
1563 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1564 }
1565#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001566} //__kmp_stg_print_cpuinfo_file
1567
Jonathan Peyton30419822017-05-12 18:01:32 +00001568// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001569// KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
Jim Cownie5e8470a2013-09-27 10:38:44 +00001570
Jonathan Peyton30419822017-05-12 18:01:32 +00001571static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
1572 void *data) {
1573 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1574 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001575
Jonathan Peyton30419822017-05-12 18:01:32 +00001576 rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1577 if (rc) {
1578 return;
1579 }; // if
1580 if (reduction->force) {
1581 if (value != 0) {
1582 if (__kmp_str_match("critical", 0, value))
1583 __kmp_force_reduction_method = critical_reduce_block;
1584 else if (__kmp_str_match("atomic", 0, value))
1585 __kmp_force_reduction_method = atomic_reduce_block;
1586 else if (__kmp_str_match("tree", 0, value))
1587 __kmp_force_reduction_method = tree_reduce_block;
1588 else {
1589 KMP_FATAL(UnknownForceReduction, name, value);
1590 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001591 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001592 } else {
1593 __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1594 if (__kmp_determ_red) {
1595 __kmp_force_reduction_method = tree_reduce_block;
1596 } else {
1597 __kmp_force_reduction_method = reduction_method_not_defined;
1598 }
1599 }
1600 K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
1601 __kmp_force_reduction_method));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001602} // __kmp_stg_parse_force_reduction
1603
Jonathan Peyton30419822017-05-12 18:01:32 +00001604static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1605 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00001606
Jonathan Peyton30419822017-05-12 18:01:32 +00001607 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1608 if (reduction->force) {
1609 if (__kmp_force_reduction_method == critical_reduce_block) {
1610 __kmp_stg_print_str(buffer, name, "critical");
1611 } else if (__kmp_force_reduction_method == atomic_reduce_block) {
1612 __kmp_stg_print_str(buffer, name, "atomic");
1613 } else if (__kmp_force_reduction_method == tree_reduce_block) {
1614 __kmp_stg_print_str(buffer, name, "tree");
Jim Cownie5e8470a2013-09-27 10:38:44 +00001615 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00001616 if (__kmp_env_format) {
1617 KMP_STR_BUF_PRINT_NAME;
1618 } else {
1619 __kmp_str_buf_print(buffer, " %s", name);
1620 }
1621 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001622 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001623 } else {
1624 __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1625 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001626
1627} // __kmp_stg_print_force_reduction
1628
Jonathan Peyton30419822017-05-12 18:01:32 +00001629// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001630// KMP_STORAGE_MAP
Jim Cownie5e8470a2013-09-27 10:38:44 +00001631
Jonathan Peyton30419822017-05-12 18:01:32 +00001632static void __kmp_stg_parse_storage_map(char const *name, char const *value,
1633 void *data) {
1634 if (__kmp_str_match("verbose", 1, value)) {
1635 __kmp_storage_map = TRUE;
1636 __kmp_storage_map_verbose = TRUE;
1637 __kmp_storage_map_verbose_specified = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001638
Jonathan Peyton30419822017-05-12 18:01:32 +00001639 } else {
1640 __kmp_storage_map_verbose = FALSE;
1641 __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
1642 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00001643} // __kmp_stg_parse_storage_map
1644
Jonathan Peyton30419822017-05-12 18:01:32 +00001645static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
1646 void *data) {
1647 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1648 __kmp_stg_print_str(buffer, name, "verbose");
1649 } else {
1650 __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1651 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001652} // __kmp_stg_print_storage_map
1653
Jonathan Peyton30419822017-05-12 18:01:32 +00001654// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001655// KMP_ALL_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001656
Jonathan Peyton30419822017-05-12 18:01:32 +00001657static void __kmp_stg_parse_all_threadprivate(char const *name,
1658 char const *value, void *data) {
1659 __kmp_stg_parse_int(name, value,
1660 __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1661 __kmp_max_nth, &__kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001662} // __kmp_stg_parse_all_threadprivate
1663
Jonathan Peyton30419822017-05-12 18:01:32 +00001664static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1665 char const *name, void *data) {
1666 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001667}
1668
Jonathan Peyton30419822017-05-12 18:01:32 +00001669// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001670// KMP_FOREIGN_THREADS_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001671
Jonathan Peyton30419822017-05-12 18:01:32 +00001672static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
1673 char const *value,
1674 void *data) {
1675 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001676} // __kmp_stg_parse_foreign_threads_threadprivate
1677
Jonathan Peyton30419822017-05-12 18:01:32 +00001678static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
1679 char const *name,
1680 void *data) {
1681 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001682} // __kmp_stg_print_foreign_threads_threadprivate
1683
Jonathan Peyton30419822017-05-12 18:01:32 +00001684// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001685// KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
Jim Cownie5e8470a2013-09-27 10:38:44 +00001686
Alp Toker98758b02014-03-02 04:12:06 +00001687#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00001688// Parse the proc id list. Return TRUE if successful, FALSE otherwise.
Jonathan Peyton30419822017-05-12 18:01:32 +00001689static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
1690 const char **nextEnv,
1691 char **proclist) {
1692 const char *scan = env;
1693 const char *next = scan;
1694 int empty = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001695
Jonathan Peyton30419822017-05-12 18:01:32 +00001696 *proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001697
Jonathan Peyton30419822017-05-12 18:01:32 +00001698 for (;;) {
1699 int start, end, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001700
Jonathan Peyton30419822017-05-12 18:01:32 +00001701 SKIP_WS(scan);
1702 next = scan;
1703 if (*next == '\0') {
1704 break;
1705 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001706
Jonathan Peyton30419822017-05-12 18:01:32 +00001707 if (*next == '{') {
1708 int num;
1709 next++; // skip '{'
1710 SKIP_WS(next);
1711 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001712
Jonathan Peyton30419822017-05-12 18:01:32 +00001713 // Read the first integer in the set.
1714 if ((*next < '0') || (*next > '9')) {
1715 KMP_WARNING(AffSyntaxError, var);
1716 return FALSE;
1717 }
1718 SKIP_DIGITS(next);
1719 num = __kmp_str_to_int(scan, *next);
1720 KMP_ASSERT(num >= 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001721
Jonathan Peyton30419822017-05-12 18:01:32 +00001722 for (;;) {
1723 // Check for end of set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001724 SKIP_WS(next);
Jonathan Peyton30419822017-05-12 18:01:32 +00001725 if (*next == '}') {
1726 next++; // skip '}'
1727 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001728 }
1729
Jim Cownie5e8470a2013-09-27 10:38:44 +00001730 // Skip optional comma.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001731 if (*next == ',') {
Jonathan Peyton30419822017-05-12 18:01:32 +00001732 next++;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001733 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001734 SKIP_WS(next);
1735
1736 // Read the next integer in the set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001737 scan = next;
Jonathan Peyton30419822017-05-12 18:01:32 +00001738 if ((*next < '0') || (*next > '9')) {
1739 KMP_WARNING(AffSyntaxError, var);
1740 return FALSE;
1741 }
1742
1743 SKIP_DIGITS(next);
1744 num = __kmp_str_to_int(scan, *next);
1745 KMP_ASSERT(num >= 0);
1746 }
1747 empty = FALSE;
1748
1749 SKIP_WS(next);
1750 if (*next == ',') {
1751 next++;
1752 }
1753 scan = next;
1754 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001755 }
1756
Jonathan Peyton30419822017-05-12 18:01:32 +00001757 // Next character is not an integer => end of list
1758 if ((*next < '0') || (*next > '9')) {
1759 if (empty) {
1760 KMP_WARNING(AffSyntaxError, var);
1761 return FALSE;
1762 }
1763 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001764 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001765
1766 // Read the first integer.
1767 SKIP_DIGITS(next);
1768 start = __kmp_str_to_int(scan, *next);
1769 KMP_ASSERT(start >= 0);
1770 SKIP_WS(next);
1771
1772 // If this isn't a range, then go on.
1773 if (*next != '-') {
1774 empty = FALSE;
1775
1776 // Skip optional comma.
1777 if (*next == ',') {
1778 next++;
1779 }
1780 scan = next;
1781 continue;
1782 }
1783
1784 // This is a range. Skip over the '-' and read in the 2nd int.
1785 next++; // skip '-'
1786 SKIP_WS(next);
1787 scan = next;
1788 if ((*next < '0') || (*next > '9')) {
1789 KMP_WARNING(AffSyntaxError, var);
1790 return FALSE;
1791 }
1792 SKIP_DIGITS(next);
1793 end = __kmp_str_to_int(scan, *next);
1794 KMP_ASSERT(end >= 0);
1795
1796 // Check for a stride parameter
1797 stride = 1;
1798 SKIP_WS(next);
1799 if (*next == ':') {
1800 // A stride is specified. Skip over the ':" and read the 3rd int.
1801 int sign = +1;
1802 next++; // skip ':'
1803 SKIP_WS(next);
1804 scan = next;
1805 if (*next == '-') {
1806 sign = -1;
1807 next++;
1808 SKIP_WS(next);
1809 scan = next;
1810 }
1811 if ((*next < '0') || (*next > '9')) {
1812 KMP_WARNING(AffSyntaxError, var);
1813 return FALSE;
1814 }
1815 SKIP_DIGITS(next);
1816 stride = __kmp_str_to_int(scan, *next);
1817 KMP_ASSERT(stride >= 0);
1818 stride *= sign;
1819 }
1820
1821 // Do some range checks.
1822 if (stride == 0) {
1823 KMP_WARNING(AffZeroStride, var);
1824 return FALSE;
1825 }
1826 if (stride > 0) {
1827 if (start > end) {
1828 KMP_WARNING(AffStartGreaterEnd, var, start, end);
1829 return FALSE;
1830 }
1831 } else {
1832 if (start < end) {
1833 KMP_WARNING(AffStrideLessZero, var, start, end);
1834 return FALSE;
1835 }
1836 }
1837 if ((end - start) / stride > 65536) {
1838 KMP_WARNING(AffRangeTooBig, var, end, start, stride);
1839 return FALSE;
1840 }
1841
1842 empty = FALSE;
1843
1844 // Skip optional comma.
1845 SKIP_WS(next);
1846 if (*next == ',') {
1847 next++;
1848 }
1849 scan = next;
1850 }
1851
1852 *nextEnv = next;
1853
1854 {
1855 int len = next - env;
1856 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
1857 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
1858 retlist[len] = '\0';
1859 *proclist = retlist;
1860 }
1861 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001862}
1863
Jim Cownie5e8470a2013-09-27 10:38:44 +00001864// If KMP_AFFINITY is specified without a type, then
1865// __kmp_affinity_notype should point to its setting.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001866static kmp_setting_t *__kmp_affinity_notype = NULL;
1867
Jonathan Peyton30419822017-05-12 18:01:32 +00001868static void __kmp_parse_affinity_env(char const *name, char const *value,
1869 enum affinity_type *out_type,
1870 char **out_proclist, int *out_verbose,
1871 int *out_warn, int *out_respect,
1872 enum affinity_gran *out_gran,
1873 int *out_gran_levels, int *out_dups,
1874 int *out_compact, int *out_offset) {
1875 char *buffer = NULL; // Copy of env var value.
1876 char *buf = NULL; // Buffer for strtok_r() function.
1877 char *next = NULL; // end of token / start of next.
1878 const char *start; // start of current token (for err msgs)
1879 int count = 0; // Counter of parsed integer numbers.
1880 int number[2]; // Parsed numbers.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001881
Jonathan Peyton30419822017-05-12 18:01:32 +00001882 // Guards.
1883 int type = 0;
1884 int proclist = 0;
1885 int max_proclist = 0;
1886 int verbose = 0;
1887 int warnings = 0;
1888 int respect = 0;
1889 int gran = 0;
1890 int dups = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001891
Jonathan Peyton30419822017-05-12 18:01:32 +00001892 KMP_ASSERT(value != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001893
Jonathan Peyton30419822017-05-12 18:01:32 +00001894 if (TCR_4(__kmp_init_middle)) {
1895 KMP_WARNING(EnvMiddleWarn, name);
1896 __kmp_env_toPrint(name, 0);
1897 return;
1898 }
1899 __kmp_env_toPrint(name, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001900
Jonathan Peyton30419822017-05-12 18:01:32 +00001901 buffer =
1902 __kmp_str_format("%s", value); // Copy env var to keep original intact.
1903 buf = buffer;
1904 SKIP_WS(buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001905
Jonathan Peyton30419822017-05-12 18:01:32 +00001906// Helper macros.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001907
Jonathan Peyton30419822017-05-12 18:01:32 +00001908// If we see a parse error, emit a warning and scan to the next ",".
1909//
1910// FIXME - there's got to be a better way to print an error
1911// message, hopefully without overwritting peices of buf.
1912#define EMIT_WARN(skip, errlist) \
1913 { \
1914 char ch; \
1915 if (skip) { \
1916 SKIP_TO(next, ','); \
1917 } \
1918 ch = *next; \
1919 *next = '\0'; \
1920 KMP_WARNING errlist; \
1921 *next = ch; \
1922 if (skip) { \
1923 if (ch == ',') \
1924 next++; \
1925 } \
1926 buf = next; \
1927 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001928
Jonathan Peyton30419822017-05-12 18:01:32 +00001929#define _set_param(_guard, _var, _val) \
1930 { \
1931 if (_guard == 0) { \
1932 _var = _val; \
1933 } else { \
1934 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
1935 }; \
1936 ++_guard; \
1937 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001938
Jonathan Peyton30419822017-05-12 18:01:32 +00001939#define set_type(val) _set_param(type, *out_type, val)
1940#define set_verbose(val) _set_param(verbose, *out_verbose, val)
1941#define set_warnings(val) _set_param(warnings, *out_warn, val)
1942#define set_respect(val) _set_param(respect, *out_respect, val)
1943#define set_dups(val) _set_param(dups, *out_dups, val)
1944#define set_proclist(val) _set_param(proclist, *out_proclist, val)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001945
Jonathan Peyton30419822017-05-12 18:01:32 +00001946#define set_gran(val, levels) \
1947 { \
1948 if (gran == 0) { \
1949 *out_gran = val; \
1950 *out_gran_levels = levels; \
1951 } else { \
1952 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
1953 }; \
1954 ++gran; \
1955 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001956
Jonathan Peyton30419822017-05-12 18:01:32 +00001957#if OMP_40_ENABLED
1958 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
1959 (__kmp_nested_proc_bind.used > 0));
Andrey Churbanov613edeb2015-02-20 18:14:43 +00001960#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00001961
1962 while (*buf != '\0') {
1963 start = next = buf;
1964
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001965 if (__kmp_match_str("none", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001966 set_type(affinity_none);
1967#if OMP_40_ENABLED
1968 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
1969#endif
1970 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001971 } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001972 set_type(affinity_scatter);
1973#if OMP_40_ENABLED
1974 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1975#endif
1976 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001977 } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001978 set_type(affinity_compact);
1979#if OMP_40_ENABLED
1980 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1981#endif
1982 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001983 } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001984 set_type(affinity_logical);
1985#if OMP_40_ENABLED
1986 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1987#endif
1988 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001989 } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001990 set_type(affinity_physical);
1991#if OMP_40_ENABLED
1992 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1993#endif
1994 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001995 } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001996 set_type(affinity_explicit);
1997#if OMP_40_ENABLED
1998 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1999#endif
2000 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002001 } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002002 set_type(affinity_balanced);
2003#if OMP_40_ENABLED
2004 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2005#endif
2006 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002007 } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002008 set_type(affinity_disabled);
2009#if OMP_40_ENABLED
2010 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2011#endif
2012 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002013 } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002014 set_verbose(TRUE);
2015 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002016 } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002017 set_verbose(FALSE);
2018 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002019 } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002020 set_warnings(TRUE);
2021 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002022 } else if (__kmp_match_str("nowarnings", buf,
2023 CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002024 set_warnings(FALSE);
2025 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002026 } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002027 set_respect(TRUE);
2028 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002029 } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002030 set_respect(FALSE);
2031 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002032 } else if (__kmp_match_str("duplicates", buf,
2033 CCAST(const char **, &next)) ||
2034 __kmp_match_str("dups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002035 set_dups(TRUE);
2036 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002037 } else if (__kmp_match_str("noduplicates", buf,
2038 CCAST(const char **, &next)) ||
2039 __kmp_match_str("nodups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002040 set_dups(FALSE);
2041 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002042 } else if (__kmp_match_str("granularity", buf,
2043 CCAST(const char **, &next)) ||
2044 __kmp_match_str("gran", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002045 SKIP_WS(next);
2046 if (*next != '=') {
2047 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2048 continue;
2049 }
2050 next++; // skip '='
2051 SKIP_WS(next);
2052
2053 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002054 if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002055 set_gran(affinity_gran_fine, -1);
2056 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002057 } else if (__kmp_match_str("thread", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002058 set_gran(affinity_gran_thread, -1);
2059 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002060 } else if (__kmp_match_str("core", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002061 set_gran(affinity_gran_core, -1);
2062 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002063 } else if (__kmp_match_str("package", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002064 set_gran(affinity_gran_package, -1);
2065 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002066 } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002067 set_gran(affinity_gran_node, -1);
2068 buf = next;
2069#if KMP_GROUP_AFFINITY
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002070 } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002071 set_gran(affinity_gran_group, -1);
2072 buf = next;
2073#endif /* KMP_GROUP AFFINITY */
2074 } else if ((*buf >= '0') && (*buf <= '9')) {
2075 int n;
2076 next = buf;
2077 SKIP_DIGITS(next);
2078 n = __kmp_str_to_int(buf, *next);
2079 KMP_ASSERT(n >= 0);
2080 buf = next;
2081 set_gran(affinity_gran_default, n);
2082 } else {
2083 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2084 continue;
2085 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002086 } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002087 char *temp_proclist;
2088
2089 SKIP_WS(next);
2090 if (*next != '=') {
2091 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2092 continue;
2093 }
2094 next++; // skip '='
2095 SKIP_WS(next);
2096 if (*next != '[') {
2097 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2098 continue;
2099 }
2100 next++; // skip '['
2101 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002102 if (!__kmp_parse_affinity_proc_id_list(
2103 name, buf, CCAST(const char **, &next), &temp_proclist)) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002104 // warning already emitted.
2105 SKIP_TO(next, ']');
2106 if (*next == ']')
2107 next++;
2108 SKIP_TO(next, ',');
2109 if (*next == ',')
2110 next++;
2111 buf = next;
2112 continue;
2113 }
2114 if (*next != ']') {
2115 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2116 continue;
2117 }
2118 next++; // skip ']'
2119 set_proclist(temp_proclist);
2120 } else if ((*buf >= '0') && (*buf <= '9')) {
2121 // Parse integer numbers -- permute and offset.
2122 int n;
2123 next = buf;
2124 SKIP_DIGITS(next);
2125 n = __kmp_str_to_int(buf, *next);
2126 KMP_ASSERT(n >= 0);
2127 buf = next;
2128 if (count < 2) {
2129 number[count] = n;
2130 } else {
2131 KMP_WARNING(AffManyParams, name, start);
2132 }; // if
2133 ++count;
2134 } else {
2135 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2136 continue;
2137 }
2138
2139 SKIP_WS(next);
2140 if (*next == ',') {
2141 next++;
2142 SKIP_WS(next);
2143 } else if (*next != '\0') {
2144 const char *temp = next;
2145 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2146 continue;
2147 }
2148 buf = next;
2149 } // while
2150
2151#undef EMIT_WARN
2152#undef _set_param
2153#undef set_type
2154#undef set_verbose
2155#undef set_warnings
2156#undef set_respect
2157#undef set_granularity
2158
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002159 __kmp_str_free(CCAST(const char **, &buffer));
Jonathan Peyton30419822017-05-12 18:01:32 +00002160
2161 if (proclist) {
2162 if (!type) {
2163 KMP_WARNING(AffProcListNoType, name);
2164 *out_type = affinity_explicit;
2165#if OMP_40_ENABLED
2166 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2167#endif
2168 } else if (*out_type != affinity_explicit) {
2169 KMP_WARNING(AffProcListNotExplicit, name);
2170 KMP_ASSERT(*out_proclist != NULL);
2171 KMP_INTERNAL_FREE(*out_proclist);
2172 *out_proclist = NULL;
2173 }
2174 }
2175 switch (*out_type) {
2176 case affinity_logical:
2177 case affinity_physical: {
2178 if (count > 0) {
2179 *out_offset = number[0];
2180 }; // if
2181 if (count > 1) {
2182 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
2183 }; // if
2184 } break;
2185 case affinity_balanced: {
2186 if (count > 0) {
2187 *out_compact = number[0];
2188 }; // if
2189 if (count > 1) {
2190 *out_offset = number[1];
2191 }; // if
2192
2193 if (__kmp_affinity_gran == affinity_gran_default) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002194#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002195 if (__kmp_mic_type != non_mic) {
2196 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2197 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine");
2198 }
2199 __kmp_affinity_gran = affinity_gran_fine;
2200 } else
2201#endif
2202 {
2203 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2204 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core");
2205 }
2206 __kmp_affinity_gran = affinity_gran_core;
2207 }
2208 }
2209 } break;
2210 case affinity_scatter:
2211 case affinity_compact: {
2212 if (count > 0) {
2213 *out_compact = number[0];
2214 }; // if
2215 if (count > 1) {
2216 *out_offset = number[1];
2217 }; // if
2218 } break;
2219 case affinity_explicit: {
2220 if (*out_proclist == NULL) {
2221 KMP_WARNING(AffNoProcList, name);
2222 __kmp_affinity_type = affinity_none;
2223 }
2224 if (count > 0) {
2225 KMP_WARNING(AffNoParam, name, "explicit");
2226 }
2227 } break;
2228 case affinity_none: {
2229 if (count > 0) {
2230 KMP_WARNING(AffNoParam, name, "none");
2231 }; // if
2232 } break;
2233 case affinity_disabled: {
2234 if (count > 0) {
2235 KMP_WARNING(AffNoParam, name, "disabled");
2236 }; // if
2237 } break;
2238 case affinity_default: {
2239 if (count > 0) {
2240 KMP_WARNING(AffNoParam, name, "default");
2241 }; // if
2242 } break;
2243 default: { KMP_ASSERT(0); };
2244 }; // switch
Jim Cownie5e8470a2013-09-27 10:38:44 +00002245} // __kmp_parse_affinity_env
2246
Jonathan Peyton30419822017-05-12 18:01:32 +00002247static void __kmp_stg_parse_affinity(char const *name, char const *value,
2248 void *data) {
2249 kmp_setting_t **rivals = (kmp_setting_t **)data;
2250 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002251
Jonathan Peyton30419822017-05-12 18:01:32 +00002252 rc = __kmp_stg_check_rivals(name, value, rivals);
2253 if (rc) {
2254 return;
2255 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002256
Jonathan Peyton30419822017-05-12 18:01:32 +00002257 __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2258 &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2259 &__kmp_affinity_warnings,
2260 &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2261 &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2262 &__kmp_affinity_compact, &__kmp_affinity_offset);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002263
2264} // __kmp_stg_parse_affinity
2265
Jonathan Peyton30419822017-05-12 18:01:32 +00002266static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
2267 void *data) {
2268 if (__kmp_env_format) {
2269 KMP_STR_BUF_PRINT_NAME_EX(name);
2270 } else {
2271 __kmp_str_buf_print(buffer, " %s='", name);
2272 }
2273 if (__kmp_affinity_verbose) {
2274 __kmp_str_buf_print(buffer, "%s,", "verbose");
2275 } else {
2276 __kmp_str_buf_print(buffer, "%s,", "noverbose");
2277 }
2278 if (__kmp_affinity_warnings) {
2279 __kmp_str_buf_print(buffer, "%s,", "warnings");
2280 } else {
2281 __kmp_str_buf_print(buffer, "%s,", "nowarnings");
2282 }
2283 if (KMP_AFFINITY_CAPABLE()) {
2284 if (__kmp_affinity_respect_mask) {
2285 __kmp_str_buf_print(buffer, "%s,", "respect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002286 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002287 __kmp_str_buf_print(buffer, "%s,", "norespect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002288 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002289 switch (__kmp_affinity_gran) {
2290 case affinity_gran_default:
2291 __kmp_str_buf_print(buffer, "%s", "granularity=default,");
2292 break;
2293 case affinity_gran_fine:
2294 __kmp_str_buf_print(buffer, "%s", "granularity=fine,");
2295 break;
2296 case affinity_gran_thread:
2297 __kmp_str_buf_print(buffer, "%s", "granularity=thread,");
2298 break;
2299 case affinity_gran_core:
2300 __kmp_str_buf_print(buffer, "%s", "granularity=core,");
2301 break;
2302 case affinity_gran_package:
2303 __kmp_str_buf_print(buffer, "%s", "granularity=package,");
2304 break;
2305 case affinity_gran_node:
2306 __kmp_str_buf_print(buffer, "%s", "granularity=node,");
2307 break;
2308#if KMP_GROUP_AFFINITY
2309 case affinity_gran_group:
2310 __kmp_str_buf_print(buffer, "%s", "granularity=group,");
2311 break;
2312#endif /* KMP_GROUP_AFFINITY */
2313 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002314 }
2315 if (!KMP_AFFINITY_CAPABLE()) {
2316 __kmp_str_buf_print(buffer, "%s", "disabled");
2317 } else
2318 switch (__kmp_affinity_type) {
2319 case affinity_none:
2320 __kmp_str_buf_print(buffer, "%s", "none");
2321 break;
2322 case affinity_physical:
2323 __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset);
2324 break;
2325 case affinity_logical:
2326 __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset);
2327 break;
2328 case affinity_compact:
2329 __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact,
2330 __kmp_affinity_offset);
2331 break;
2332 case affinity_scatter:
2333 __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact,
2334 __kmp_affinity_offset);
2335 break;
2336 case affinity_explicit:
2337 __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist",
2338 __kmp_affinity_proclist, "explicit");
2339 break;
2340 case affinity_balanced:
2341 __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced",
2342 __kmp_affinity_compact, __kmp_affinity_offset);
2343 break;
2344 case affinity_disabled:
2345 __kmp_str_buf_print(buffer, "%s", "disabled");
2346 break;
2347 case affinity_default:
2348 __kmp_str_buf_print(buffer, "%s", "default");
2349 break;
2350 default:
2351 __kmp_str_buf_print(buffer, "%s", "<unknown>");
2352 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002353 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002354 __kmp_str_buf_print(buffer, "'\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002355} //__kmp_stg_print_affinity
2356
Jonathan Peyton30419822017-05-12 18:01:32 +00002357#ifdef KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00002358
Jonathan Peyton30419822017-05-12 18:01:32 +00002359static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
2360 char const *value, void *data) {
2361 const char *next = NULL;
2362 char *temp_proclist;
2363 kmp_setting_t **rivals = (kmp_setting_t **)data;
2364 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002365
Jonathan Peyton30419822017-05-12 18:01:32 +00002366 rc = __kmp_stg_check_rivals(name, value, rivals);
2367 if (rc) {
2368 return;
2369 }
2370
2371 if (TCR_4(__kmp_init_middle)) {
2372 KMP_WARNING(EnvMiddleWarn, name);
2373 __kmp_env_toPrint(name, 0);
2374 return;
2375 }
2376
2377 __kmp_env_toPrint(name, 1);
2378
2379 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2380 SKIP_WS(next);
2381 if (*next == '\0') {
2382 // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2383 __kmp_affinity_proclist = temp_proclist;
2384 __kmp_affinity_type = affinity_explicit;
2385 __kmp_affinity_gran = affinity_gran_fine;
2386#if OMP_40_ENABLED
2387 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2388#endif
2389 } else {
2390 KMP_WARNING(AffSyntaxError, name);
2391 if (temp_proclist != NULL) {
2392 KMP_INTERNAL_FREE((void *)temp_proclist);
2393 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002394 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002395 } else {
2396 // Warning already emitted
2397 __kmp_affinity_type = affinity_none;
2398#if OMP_40_ENABLED
2399 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2400#endif
2401 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002402} // __kmp_stg_parse_gomp_cpu_affinity
2403
Jonathan Peyton30419822017-05-12 18:01:32 +00002404#endif /* KMP_GOMP_COMPAT */
Jim Cownie5e8470a2013-09-27 10:38:44 +00002405
Jonathan Peyton30419822017-05-12 18:01:32 +00002406#if OMP_40_ENABLED
Jim Cownie5e8470a2013-09-27 10:38:44 +00002407
2408/*-----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00002409The OMP_PLACES proc id list parser. Here is the grammar:
2410
2411place_list := place
2412place_list := place , place_list
2413place := num
2414place := place : num
2415place := place : num : signed
2416place := { subplacelist }
2417place := ! place // (lowest priority)
2418subplace_list := subplace
2419subplace_list := subplace , subplace_list
2420subplace := num
2421subplace := num : num
2422subplace := num : num : signed
2423signed := num
2424signed := + signed
2425signed := - signed
Jim Cownie5e8470a2013-09-27 10:38:44 +00002426-----------------------------------------------------------------------------*/
2427
Jonathan Peyton30419822017-05-12 18:01:32 +00002428static int __kmp_parse_subplace_list(const char *var, const char **scan) {
2429 const char *next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002430
Jonathan Peyton30419822017-05-12 18:01:32 +00002431 for (;;) {
2432 int start, count, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002433
2434 //
Jonathan Peyton30419822017-05-12 18:01:32 +00002435 // Read in the starting proc id
Jim Cownie5e8470a2013-09-27 10:38:44 +00002436 //
2437 SKIP_WS(*scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002438 if ((**scan < '0') || (**scan > '9')) {
2439 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2440 return FALSE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002441 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002442 next = *scan;
2443 SKIP_DIGITS(next);
2444 start = __kmp_str_to_int(*scan, *next);
2445 KMP_ASSERT(start >= 0);
2446 *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002447
Jonathan Peyton30419822017-05-12 18:01:32 +00002448 // valid follow sets are ',' ':' and '}'
2449 SKIP_WS(*scan);
2450 if (**scan == '}') {
2451 break;
2452 }
2453 if (**scan == ',') {
2454 (*scan)++; // skip ','
2455 continue;
2456 }
2457 if (**scan != ':') {
2458 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2459 return FALSE;
2460 }
2461 (*scan)++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002462
Jonathan Peyton30419822017-05-12 18:01:32 +00002463 // Read count parameter
2464 SKIP_WS(*scan);
2465 if ((**scan < '0') || (**scan > '9')) {
2466 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2467 return FALSE;
2468 }
2469 next = *scan;
2470 SKIP_DIGITS(next);
2471 count = __kmp_str_to_int(*scan, *next);
2472 KMP_ASSERT(count >= 0);
2473 *scan = next;
2474
2475 // valid follow sets are ',' ':' and '}'
2476 SKIP_WS(*scan);
2477 if (**scan == '}') {
2478 break;
2479 }
2480 if (**scan == ',') {
2481 (*scan)++; // skip ','
2482 continue;
2483 }
2484 if (**scan != ':') {
2485 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2486 return FALSE;
2487 }
2488 (*scan)++; // skip ':'
2489
2490 // Read stride parameter
2491 int sign = +1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002492 for (;;) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002493 SKIP_WS(*scan);
2494 if (**scan == '+') {
2495 (*scan)++; // skip '+'
2496 continue;
2497 }
2498 if (**scan == '-') {
2499 sign *= -1;
2500 (*scan)++; // skip '-'
2501 continue;
2502 }
2503 break;
2504 }
2505 SKIP_WS(*scan);
2506 if ((**scan < '0') || (**scan > '9')) {
2507 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2508 return FALSE;
2509 }
2510 next = *scan;
2511 SKIP_DIGITS(next);
2512 stride = __kmp_str_to_int(*scan, *next);
2513 KMP_ASSERT(stride >= 0);
2514 *scan = next;
2515 stride *= sign;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002516
Jonathan Peyton30419822017-05-12 18:01:32 +00002517 // valid follow sets are ',' and '}'
2518 SKIP_WS(*scan);
2519 if (**scan == '}') {
2520 break;
2521 }
2522 if (**scan == ',') {
2523 (*scan)++; // skip ','
2524 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002525 }
2526
Jonathan Peyton30419822017-05-12 18:01:32 +00002527 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2528 return FALSE;
2529 }
2530 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002531}
2532
Jonathan Peyton30419822017-05-12 18:01:32 +00002533static int __kmp_parse_place(const char *var, const char **scan) {
2534 const char *next;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002535
Jonathan Peyton30419822017-05-12 18:01:32 +00002536 // valid follow sets are '{' '!' and num
2537 SKIP_WS(*scan);
2538 if (**scan == '{') {
2539 (*scan)++; // skip '{'
2540 if (!__kmp_parse_subplace_list(var, scan)) {
2541 return FALSE;
2542 }
2543 if (**scan != '}') {
2544 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2545 return FALSE;
2546 }
2547 (*scan)++; // skip '}'
2548 } else if (**scan == '!') {
2549 (*scan)++; // skip '!'
2550 return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2551 } else if ((**scan >= '0') && (**scan <= '9')) {
2552 next = *scan;
2553 SKIP_DIGITS(next);
2554 int proc = __kmp_str_to_int(*scan, *next);
2555 KMP_ASSERT(proc >= 0);
2556 *scan = next;
2557 } else {
2558 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2559 return FALSE;
2560 }
2561 return TRUE;
2562}
2563
2564static int __kmp_parse_place_list(const char *var, const char *env,
2565 char **place_list) {
2566 const char *scan = env;
2567 const char *next = scan;
2568
2569 for (;;) {
2570 int start, count, stride;
2571
2572 if (!__kmp_parse_place(var, &scan)) {
2573 return FALSE;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002574 }
2575
Jonathan Peyton30419822017-05-12 18:01:32 +00002576 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002577 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002578 if (*scan == '\0') {
2579 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002580 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002581 if (*scan == ',') {
2582 scan++; // skip ','
2583 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002584 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002585 if (*scan != ':') {
2586 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2587 return FALSE;
2588 }
2589 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002590
Jonathan Peyton30419822017-05-12 18:01:32 +00002591 // Read count parameter
Jim Cownie5e8470a2013-09-27 10:38:44 +00002592 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002593 if ((*scan < '0') || (*scan > '9')) {
2594 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2595 return FALSE;
2596 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002597 next = scan;
2598 SKIP_DIGITS(next);
2599 count = __kmp_str_to_int(scan, *next);
2600 KMP_ASSERT(count >= 0);
2601 scan = next;
2602
Jonathan Peyton30419822017-05-12 18:01:32 +00002603 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002604 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002605 if (*scan == '\0') {
2606 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002607 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002608 if (*scan == ',') {
2609 scan++; // skip ','
2610 continue;
2611 }
2612 if (*scan != ':') {
2613 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2614 return FALSE;
2615 }
2616 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002617
Jonathan Peyton30419822017-05-12 18:01:32 +00002618 // Read stride parameter
2619 int sign = +1;
2620 for (;;) {
2621 SKIP_WS(scan);
2622 if (*scan == '+') {
2623 scan++; // skip '+'
2624 continue;
2625 }
2626 if (*scan == '-') {
2627 sign *= -1;
2628 scan++; // skip '-'
2629 continue;
2630 }
2631 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002632 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002633 SKIP_WS(scan);
2634 if ((*scan < '0') || (*scan > '9')) {
2635 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2636 return FALSE;
2637 }
2638 next = scan;
2639 SKIP_DIGITS(next);
2640 stride = __kmp_str_to_int(scan, *next);
2641 KMP_ASSERT(stride >= 0);
2642 scan = next;
2643 stride *= sign;
2644
2645 // valid follow sets are ',' and EOL
2646 SKIP_WS(scan);
2647 if (*scan == '\0') {
2648 break;
2649 }
2650 if (*scan == ',') {
2651 scan++; // skip ','
2652 continue;
2653 }
2654
2655 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2656 return FALSE;
2657 }
2658
2659 {
2660 int len = scan - env;
2661 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
2662 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
2663 retlist[len] = '\0';
2664 *place_list = retlist;
2665 }
2666 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002667}
2668
Jonathan Peyton30419822017-05-12 18:01:32 +00002669static void __kmp_stg_parse_places(char const *name, char const *value,
2670 void *data) {
2671 int count;
2672 const char *scan = value;
2673 const char *next = scan;
2674 const char *kind = "\"threads\"";
2675 kmp_setting_t **rivals = (kmp_setting_t **)data;
2676 int rc;
2677
2678 rc = __kmp_stg_check_rivals(name, value, rivals);
2679 if (rc) {
2680 return;
2681 }
2682
2683 // If OMP_PROC_BIND is not specified but OMP_PLACES is,
2684 // then let OMP_PROC_BIND default to true.
2685 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2686 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2687 }
2688
2689 //__kmp_affinity_num_places = 0;
2690
2691 if (__kmp_match_str("threads", scan, &next)) {
2692 scan = next;
2693 __kmp_affinity_type = affinity_compact;
2694 __kmp_affinity_gran = affinity_gran_thread;
2695 __kmp_affinity_dups = FALSE;
2696 kind = "\"threads\"";
2697 } else if (__kmp_match_str("cores", scan, &next)) {
2698 scan = next;
2699 __kmp_affinity_type = affinity_compact;
2700 __kmp_affinity_gran = affinity_gran_core;
2701 __kmp_affinity_dups = FALSE;
2702 kind = "\"cores\"";
2703 } else if (__kmp_match_str("sockets", scan, &next)) {
2704 scan = next;
2705 __kmp_affinity_type = affinity_compact;
2706 __kmp_affinity_gran = affinity_gran_package;
2707 __kmp_affinity_dups = FALSE;
2708 kind = "\"sockets\"";
2709 } else {
2710 if (__kmp_affinity_proclist != NULL) {
2711 KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist);
2712 __kmp_affinity_proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002713 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002714 if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2715 __kmp_affinity_type = affinity_explicit;
2716 __kmp_affinity_gran = affinity_gran_fine;
2717 __kmp_affinity_dups = FALSE;
2718 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002719 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
Jonathan Peyton30419822017-05-12 18:01:32 +00002720 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002721 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002722 return;
2723 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002724
Jonathan Peyton30419822017-05-12 18:01:32 +00002725 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2726 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2727 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002728
Jonathan Peyton30419822017-05-12 18:01:32 +00002729 SKIP_WS(scan);
2730 if (*scan == '\0') {
2731 return;
2732 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002733
Jonathan Peyton30419822017-05-12 18:01:32 +00002734 // Parse option count parameter in parentheses
2735 if (*scan != '(') {
2736 KMP_WARNING(SyntaxErrorUsing, name, kind);
2737 return;
2738 }
2739 scan++; // skip '('
Jim Cownie5e8470a2013-09-27 10:38:44 +00002740
Jonathan Peyton30419822017-05-12 18:01:32 +00002741 SKIP_WS(scan);
2742 next = scan;
2743 SKIP_DIGITS(next);
2744 count = __kmp_str_to_int(scan, *next);
2745 KMP_ASSERT(count >= 0);
2746 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002747
Jonathan Peyton30419822017-05-12 18:01:32 +00002748 SKIP_WS(scan);
2749 if (*scan != ')') {
2750 KMP_WARNING(SyntaxErrorUsing, name, kind);
2751 return;
2752 }
2753 scan++; // skip ')'
2754
2755 SKIP_WS(scan);
2756 if (*scan != '\0') {
2757 KMP_WARNING(ParseExtraCharsWarn, name, scan);
2758 }
2759 __kmp_affinity_num_places = count;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002760}
2761
Jonathan Peyton30419822017-05-12 18:01:32 +00002762static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
2763 void *data) {
2764 if (__kmp_env_format) {
2765 KMP_STR_BUF_PRINT_NAME;
2766 } else {
2767 __kmp_str_buf_print(buffer, " %s", name);
2768 }
2769 if ((__kmp_nested_proc_bind.used == 0) ||
2770 (__kmp_nested_proc_bind.bind_types == NULL) ||
2771 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
2772 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2773 } else if (__kmp_affinity_type == affinity_explicit) {
2774 if (__kmp_affinity_proclist != NULL) {
2775 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002776 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002777 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002778 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002779 } else if (__kmp_affinity_type == affinity_compact) {
2780 int num;
2781 if (__kmp_affinity_num_masks > 0) {
2782 num = __kmp_affinity_num_masks;
2783 } else if (__kmp_affinity_num_places > 0) {
2784 num = __kmp_affinity_num_places;
2785 } else {
2786 num = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002787 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002788 if (__kmp_affinity_gran == affinity_gran_thread) {
2789 if (num > 0) {
2790 __kmp_str_buf_print(buffer, "='threads(%d)'\n", num);
2791 } else {
2792 __kmp_str_buf_print(buffer, "='threads'\n");
2793 }
2794 } else if (__kmp_affinity_gran == affinity_gran_core) {
2795 if (num > 0) {
2796 __kmp_str_buf_print(buffer, "='cores(%d)' \n", num);
2797 } else {
2798 __kmp_str_buf_print(buffer, "='cores'\n");
2799 }
2800 } else if (__kmp_affinity_gran == affinity_gran_package) {
2801 if (num > 0) {
2802 __kmp_str_buf_print(buffer, "='sockets(%d)'\n", num);
2803 } else {
2804 __kmp_str_buf_print(buffer, "='sockets'\n");
2805 }
2806 } else {
2807 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002808 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002809 } else {
2810 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2811 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002812}
2813
2814#endif /* OMP_40_ENABLED */
2815
Jonathan Peyton30419822017-05-12 18:01:32 +00002816#if (!OMP_40_ENABLED)
Jim Cownie5e8470a2013-09-27 10:38:44 +00002817
Jonathan Peyton30419822017-05-12 18:01:32 +00002818static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
2819 void *data) {
2820 int enabled;
2821 kmp_setting_t **rivals = (kmp_setting_t **)data;
2822 int rc;
2823
2824 rc = __kmp_stg_check_rivals(name, value, rivals);
2825 if (rc) {
2826 return;
2827 }
2828
2829 // In OMP 3.1, OMP_PROC_BIND is strictly a boolean
2830 __kmp_stg_parse_bool(name, value, &enabled);
2831 if (enabled) {
2832 // OMP_PROC_BIND => granularity=fine,scatter on MIC
2833 // OMP_PROC_BIND => granularity=core,scatter elsewhere
2834 __kmp_affinity_type = affinity_scatter;
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002835#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002836 if (__kmp_mic_type != non_mic)
2837 __kmp_affinity_gran = affinity_gran_fine;
2838 else
2839#endif
2840 __kmp_affinity_gran = affinity_gran_core;
2841 } else {
2842 __kmp_affinity_type = affinity_none;
2843 }
2844} // __kmp_parse_proc_bind
2845
2846#endif /* if (! OMP_40_ENABLED) */
2847
2848static void __kmp_stg_parse_topology_method(char const *name, char const *value,
2849 void *data) {
2850 if (__kmp_str_match("all", 1, value)) {
2851 __kmp_affinity_top_method = affinity_top_method_all;
2852 }
2853#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2854 else if (__kmp_str_match("x2apic id", 9, value) ||
2855 __kmp_str_match("x2apic_id", 9, value) ||
2856 __kmp_str_match("x2apic-id", 9, value) ||
2857 __kmp_str_match("x2apicid", 8, value) ||
2858 __kmp_str_match("cpuid leaf 11", 13, value) ||
2859 __kmp_str_match("cpuid_leaf_11", 13, value) ||
2860 __kmp_str_match("cpuid-leaf-11", 13, value) ||
2861 __kmp_str_match("cpuid leaf11", 12, value) ||
2862 __kmp_str_match("cpuid_leaf11", 12, value) ||
2863 __kmp_str_match("cpuid-leaf11", 12, value) ||
2864 __kmp_str_match("cpuidleaf 11", 12, value) ||
2865 __kmp_str_match("cpuidleaf_11", 12, value) ||
2866 __kmp_str_match("cpuidleaf-11", 12, value) ||
2867 __kmp_str_match("cpuidleaf11", 11, value) ||
2868 __kmp_str_match("cpuid 11", 8, value) ||
2869 __kmp_str_match("cpuid_11", 8, value) ||
2870 __kmp_str_match("cpuid-11", 8, value) ||
2871 __kmp_str_match("cpuid11", 7, value) ||
2872 __kmp_str_match("leaf 11", 7, value) ||
2873 __kmp_str_match("leaf_11", 7, value) ||
2874 __kmp_str_match("leaf-11", 7, value) ||
2875 __kmp_str_match("leaf11", 6, value)) {
2876 __kmp_affinity_top_method = affinity_top_method_x2apicid;
2877 } else if (__kmp_str_match("apic id", 7, value) ||
2878 __kmp_str_match("apic_id", 7, value) ||
2879 __kmp_str_match("apic-id", 7, value) ||
2880 __kmp_str_match("apicid", 6, value) ||
2881 __kmp_str_match("cpuid leaf 4", 12, value) ||
2882 __kmp_str_match("cpuid_leaf_4", 12, value) ||
2883 __kmp_str_match("cpuid-leaf-4", 12, value) ||
2884 __kmp_str_match("cpuid leaf4", 11, value) ||
2885 __kmp_str_match("cpuid_leaf4", 11, value) ||
2886 __kmp_str_match("cpuid-leaf4", 11, value) ||
2887 __kmp_str_match("cpuidleaf 4", 11, value) ||
2888 __kmp_str_match("cpuidleaf_4", 11, value) ||
2889 __kmp_str_match("cpuidleaf-4", 11, value) ||
2890 __kmp_str_match("cpuidleaf4", 10, value) ||
2891 __kmp_str_match("cpuid 4", 7, value) ||
2892 __kmp_str_match("cpuid_4", 7, value) ||
2893 __kmp_str_match("cpuid-4", 7, value) ||
2894 __kmp_str_match("cpuid4", 6, value) ||
2895 __kmp_str_match("leaf 4", 6, value) ||
2896 __kmp_str_match("leaf_4", 6, value) ||
2897 __kmp_str_match("leaf-4", 6, value) ||
2898 __kmp_str_match("leaf4", 5, value)) {
2899 __kmp_affinity_top_method = affinity_top_method_apicid;
2900 }
2901#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2902 else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
2903 __kmp_str_match("cpuinfo", 5, value)) {
2904 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
2905 }
2906#if KMP_GROUP_AFFINITY
2907 else if (__kmp_str_match("group", 1, value)) {
2908 __kmp_affinity_top_method = affinity_top_method_group;
2909 }
2910#endif /* KMP_GROUP_AFFINITY */
2911 else if (__kmp_str_match("flat", 1, value)) {
2912 __kmp_affinity_top_method = affinity_top_method_flat;
2913 }
2914#if KMP_USE_HWLOC
2915 else if (__kmp_str_match("hwloc", 1, value)) {
2916 __kmp_affinity_top_method = affinity_top_method_hwloc;
2917 }
2918#endif
2919 else {
2920 KMP_WARNING(StgInvalidValue, name, value);
2921 }
2922} // __kmp_stg_parse_topology_method
2923
2924static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
2925 char const *name, void *data) {
2926#if KMP_DEBUG
2927 char const *value = NULL;
2928
2929 switch (__kmp_affinity_top_method) {
2930 case affinity_top_method_default:
2931 value = "default";
2932 break;
2933
2934 case affinity_top_method_all:
2935 value = "all";
2936 break;
2937
2938#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2939 case affinity_top_method_x2apicid:
2940 value = "x2APIC id";
2941 break;
2942
2943 case affinity_top_method_apicid:
2944 value = "APIC id";
2945 break;
2946#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2947
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002948#if KMP_USE_HWLOC
Jonathan Peyton30419822017-05-12 18:01:32 +00002949 case affinity_top_method_hwloc:
2950 value = "hwloc";
2951 break;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002952#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00002953
2954 case affinity_top_method_cpuinfo:
2955 value = "cpuinfo";
2956 break;
2957
2958#if KMP_GROUP_AFFINITY
2959 case affinity_top_method_group:
2960 value = "group";
2961 break;
2962#endif /* KMP_GROUP_AFFINITY */
2963
2964 case affinity_top_method_flat:
2965 value = "flat";
2966 break;
2967 }
2968
2969 if (value != NULL) {
2970 __kmp_stg_print_str(buffer, name, value);
2971 }
2972#endif /* KMP_DEBUG */
2973} // __kmp_stg_print_topology_method
2974
2975#endif /* KMP_AFFINITY_SUPPORTED */
2976
2977#if OMP_40_ENABLED
2978
2979// OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
2980// OMP_PLACES / place-partition-var is not.
2981static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
2982 void *data) {
2983 kmp_setting_t **rivals = (kmp_setting_t **)data;
2984 int rc;
2985
2986 rc = __kmp_stg_check_rivals(name, value, rivals);
2987 if (rc) {
2988 return;
2989 }
2990
2991 // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
2992 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
2993 (__kmp_nested_proc_bind.used > 0));
2994
2995 const char *buf = value;
2996 const char *next;
2997 int num;
2998 SKIP_WS(buf);
2999 if ((*buf >= '0') && (*buf <= '9')) {
3000 next = buf;
3001 SKIP_DIGITS(next);
3002 num = __kmp_str_to_int(buf, *next);
3003 KMP_ASSERT(num >= 0);
3004 buf = next;
3005 SKIP_WS(buf);
3006 } else {
3007 num = -1;
3008 }
3009
3010 next = buf;
3011 if (__kmp_match_str("disabled", buf, &next)) {
3012 buf = next;
3013 SKIP_WS(buf);
3014#if KMP_AFFINITY_SUPPORTED
3015 __kmp_affinity_type = affinity_disabled;
3016#endif /* KMP_AFFINITY_SUPPORTED */
3017 __kmp_nested_proc_bind.used = 1;
3018 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3019 } else if ((num == (int)proc_bind_false) ||
3020 __kmp_match_str("false", buf, &next)) {
3021 buf = next;
3022 SKIP_WS(buf);
3023#if KMP_AFFINITY_SUPPORTED
3024 __kmp_affinity_type = affinity_none;
3025#endif /* KMP_AFFINITY_SUPPORTED */
3026 __kmp_nested_proc_bind.used = 1;
3027 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3028 } else if ((num == (int)proc_bind_true) ||
3029 __kmp_match_str("true", buf, &next)) {
3030 buf = next;
3031 SKIP_WS(buf);
3032 __kmp_nested_proc_bind.used = 1;
3033 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3034 } else {
3035 // Count the number of values in the env var string
3036 const char *scan;
3037 int nelem = 1;
3038 for (scan = buf; *scan != '\0'; scan++) {
3039 if (*scan == ',') {
3040 nelem++;
3041 }
3042 }
3043
3044 // Create / expand the nested proc_bind array as needed
3045 if (__kmp_nested_proc_bind.size < nelem) {
3046 __kmp_nested_proc_bind.bind_types =
3047 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3048 __kmp_nested_proc_bind.bind_types,
3049 sizeof(kmp_proc_bind_t) * nelem);
3050 if (__kmp_nested_proc_bind.bind_types == NULL) {
3051 KMP_FATAL(MemoryAllocFailed);
3052 }
3053 __kmp_nested_proc_bind.size = nelem;
3054 }
3055 __kmp_nested_proc_bind.used = nelem;
3056
3057 // Save values in the nested proc_bind array
3058 int i = 0;
3059 for (;;) {
3060 enum kmp_proc_bind_t bind;
3061
3062 if ((num == (int)proc_bind_master) ||
3063 __kmp_match_str("master", buf, &next)) {
3064 buf = next;
3065 SKIP_WS(buf);
3066 bind = proc_bind_master;
3067 } else if ((num == (int)proc_bind_close) ||
3068 __kmp_match_str("close", buf, &next)) {
3069 buf = next;
3070 SKIP_WS(buf);
3071 bind = proc_bind_close;
3072 } else if ((num == (int)proc_bind_spread) ||
3073 __kmp_match_str("spread", buf, &next)) {
3074 buf = next;
3075 SKIP_WS(buf);
3076 bind = proc_bind_spread;
3077 } else {
3078 KMP_WARNING(StgInvalidValue, name, value);
3079 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3080 __kmp_nested_proc_bind.used = 1;
3081 return;
3082 }
3083
3084 __kmp_nested_proc_bind.bind_types[i++] = bind;
3085 if (i >= nelem) {
3086 break;
3087 }
3088 KMP_DEBUG_ASSERT(*buf == ',');
3089 buf++;
3090 SKIP_WS(buf);
3091
3092 // Read next value if it was specified as an integer
3093 if ((*buf >= '0') && (*buf <= '9')) {
3094 next = buf;
3095 SKIP_DIGITS(next);
3096 num = __kmp_str_to_int(buf, *next);
3097 KMP_ASSERT(num >= 0);
3098 buf = next;
3099 SKIP_WS(buf);
3100 } else {
3101 num = -1;
3102 }
3103 }
3104 SKIP_WS(buf);
3105 }
3106 if (*buf != '\0') {
3107 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3108 }
3109}
3110
3111static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
3112 void *data) {
3113 int nelem = __kmp_nested_proc_bind.used;
3114 if (__kmp_env_format) {
3115 KMP_STR_BUF_PRINT_NAME;
3116 } else {
3117 __kmp_str_buf_print(buffer, " %s", name);
3118 }
3119 if (nelem == 0) {
3120 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3121 } else {
3122 int i;
3123 __kmp_str_buf_print(buffer, "='", name);
3124 for (i = 0; i < nelem; i++) {
3125 switch (__kmp_nested_proc_bind.bind_types[i]) {
3126 case proc_bind_false:
3127 __kmp_str_buf_print(buffer, "false");
3128 break;
3129
3130 case proc_bind_true:
3131 __kmp_str_buf_print(buffer, "true");
3132 break;
3133
3134 case proc_bind_master:
3135 __kmp_str_buf_print(buffer, "master");
3136 break;
3137
3138 case proc_bind_close:
3139 __kmp_str_buf_print(buffer, "close");
3140 break;
3141
3142 case proc_bind_spread:
3143 __kmp_str_buf_print(buffer, "spread");
3144 break;
3145
3146 case proc_bind_intel:
3147 __kmp_str_buf_print(buffer, "intel");
3148 break;
3149
3150 case proc_bind_default:
3151 __kmp_str_buf_print(buffer, "default");
3152 break;
3153 }
3154 if (i < nelem - 1) {
3155 __kmp_str_buf_print(buffer, ",");
3156 }
3157 }
3158 __kmp_str_buf_print(buffer, "'\n");
3159 }
3160}
3161
3162#endif /* OMP_40_ENABLED */
3163
3164// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003165// OMP_DYNAMIC
Jim Cownie5e8470a2013-09-27 10:38:44 +00003166
Jonathan Peyton30419822017-05-12 18:01:32 +00003167static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
3168 void *data) {
3169 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003170} // __kmp_stg_parse_omp_dynamic
3171
Jonathan Peyton30419822017-05-12 18:01:32 +00003172static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
3173 void *data) {
3174 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003175} // __kmp_stg_print_omp_dynamic
3176
Jonathan Peyton30419822017-05-12 18:01:32 +00003177static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
3178 char const *value, void *data) {
3179 if (TCR_4(__kmp_init_parallel)) {
3180 KMP_WARNING(EnvParallelWarn, name);
3181 __kmp_env_toPrint(name, 0);
3182 return;
3183 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003184#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00003185 else if (__kmp_str_match("load balance", 2, value) ||
3186 __kmp_str_match("load_balance", 2, value) ||
3187 __kmp_str_match("load-balance", 2, value) ||
3188 __kmp_str_match("loadbalance", 2, value) ||
3189 __kmp_str_match("balance", 1, value)) {
3190 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3191 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003192#endif /* USE_LOAD_BALANCE */
Jonathan Peyton30419822017-05-12 18:01:32 +00003193 else if (__kmp_str_match("thread limit", 1, value) ||
3194 __kmp_str_match("thread_limit", 1, value) ||
3195 __kmp_str_match("thread-limit", 1, value) ||
3196 __kmp_str_match("threadlimit", 1, value) ||
3197 __kmp_str_match("limit", 2, value)) {
3198 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3199 } else if (__kmp_str_match("random", 1, value)) {
3200 __kmp_global.g.g_dynamic_mode = dynamic_random;
3201 } else {
3202 KMP_WARNING(StgInvalidValue, name, value);
3203 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003204} //__kmp_stg_parse_kmp_dynamic_mode
3205
Jonathan Peyton30419822017-05-12 18:01:32 +00003206static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
3207 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003208#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003209 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
3210 __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
3211 }
3212#ifdef USE_LOAD_BALANCE
3213 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
3214 __kmp_stg_print_str(buffer, name, "load balance");
3215 }
3216#endif /* USE_LOAD_BALANCE */
3217 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
3218 __kmp_stg_print_str(buffer, name, "thread limit");
3219 } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
3220 __kmp_stg_print_str(buffer, name, "random");
3221 } else {
3222 KMP_ASSERT(0);
3223 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003224#endif /* KMP_DEBUG */
3225} // __kmp_stg_print_kmp_dynamic_mode
3226
Jim Cownie5e8470a2013-09-27 10:38:44 +00003227#ifdef USE_LOAD_BALANCE
3228
Jonathan Peyton30419822017-05-12 18:01:32 +00003229// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003230// KMP_LOAD_BALANCE_INTERVAL
Jim Cownie5e8470a2013-09-27 10:38:44 +00003231
Jonathan Peyton30419822017-05-12 18:01:32 +00003232static void __kmp_stg_parse_ld_balance_interval(char const *name,
3233 char const *value, void *data) {
3234 double interval = __kmp_convert_to_double(value);
3235 if (interval >= 0) {
3236 __kmp_load_balance_interval = interval;
3237 } else {
3238 KMP_WARNING(StgInvalidValue, name, value);
3239 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003240} // __kmp_stg_parse_load_balance_interval
3241
Jonathan Peyton30419822017-05-12 18:01:32 +00003242static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
3243 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003244#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003245 __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
3246 __kmp_load_balance_interval);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003247#endif /* KMP_DEBUG */
3248} // __kmp_stg_print_load_balance_interval
3249
3250#endif /* USE_LOAD_BALANCE */
3251
Jonathan Peyton30419822017-05-12 18:01:32 +00003252// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003253// KMP_INIT_AT_FORK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003254
Jonathan Peyton30419822017-05-12 18:01:32 +00003255static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
3256 void *data) {
3257 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
3258 if (__kmp_need_register_atfork) {
3259 __kmp_need_register_atfork_specified = TRUE;
3260 };
Jim Cownie5e8470a2013-09-27 10:38:44 +00003261} // __kmp_stg_parse_init_at_fork
3262
Jonathan Peyton30419822017-05-12 18:01:32 +00003263static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
3264 char const *name, void *data) {
3265 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003266} // __kmp_stg_print_init_at_fork
3267
Jonathan Peyton30419822017-05-12 18:01:32 +00003268// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003269// KMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003270
Jonathan Peyton30419822017-05-12 18:01:32 +00003271static void __kmp_stg_parse_schedule(char const *name, char const *value,
3272 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003273
Jonathan Peyton30419822017-05-12 18:01:32 +00003274 if (value != NULL) {
3275 size_t length = KMP_STRLEN(value);
3276 if (length > INT_MAX) {
3277 KMP_WARNING(LongValue, name);
3278 } else {
3279 char *semicolon;
3280 if (value[length - 1] == '"' || value[length - 1] == '\'')
3281 KMP_WARNING(UnbalancedQuotes, name);
3282 do {
3283 char sentinel;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003284
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003285 semicolon = CCAST(char *, strchr(value, ';'));
Jonathan Peyton30419822017-05-12 18:01:32 +00003286 if (*value && semicolon != value) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003287 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003288
Jonathan Peyton30419822017-05-12 18:01:32 +00003289 if (comma) {
3290 ++comma;
3291 sentinel = ',';
3292 } else
3293 sentinel = ';';
3294 if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
3295 if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
3296 __kmp_static = kmp_sch_static_greedy;
3297 continue;
3298 } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
3299 ';')) {
3300 __kmp_static = kmp_sch_static_balanced;
3301 continue;
3302 }
3303 } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3304 sentinel)) {
3305 if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
3306 __kmp_guided = kmp_sch_guided_iterative_chunked;
3307 continue;
3308 } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
3309 ';')) {
3310 /* analytical not allowed for too many threads */
3311 __kmp_guided = kmp_sch_guided_analytical_chunked;
3312 continue;
3313 }
3314 }
3315 KMP_WARNING(InvalidClause, name, value);
3316 } else
3317 KMP_WARNING(EmptyClause, name);
3318 } while ((value = semicolon ? semicolon + 1 : NULL));
3319 }
3320 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003321
3322} // __kmp_stg_parse__schedule
3323
Jonathan Peyton30419822017-05-12 18:01:32 +00003324static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
3325 void *data) {
3326 if (__kmp_env_format) {
3327 KMP_STR_BUF_PRINT_NAME_EX(name);
3328 } else {
3329 __kmp_str_buf_print(buffer, " %s='", name);
3330 }
3331 if (__kmp_static == kmp_sch_static_greedy) {
3332 __kmp_str_buf_print(buffer, "%s", "static,greedy");
3333 } else if (__kmp_static == kmp_sch_static_balanced) {
3334 __kmp_str_buf_print(buffer, "%s", "static,balanced");
3335 }
3336 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
3337 __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
3338 } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
3339 __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
3340 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003341} // __kmp_stg_print_schedule
3342
Jonathan Peyton30419822017-05-12 18:01:32 +00003343// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003344// OMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003345
Jonathan Peyton30419822017-05-12 18:01:32 +00003346static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
3347 void *data) {
3348 size_t length;
3349 if (value) {
3350 length = KMP_STRLEN(value);
3351 if (length) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003352 char *comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00003353 if (value[length - 1] == '"' || value[length - 1] == '\'')
3354 KMP_WARNING(UnbalancedQuotes, name);
3355 /* get the specified scheduling style */
3356 if (!__kmp_strcasecmp_with_sentinel("dynamic", value, ',')) /* DYNAMIC */
3357 __kmp_sched = kmp_sch_dynamic_chunked;
3358 else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3359 ',')) /* GUIDED */
3360 __kmp_sched = kmp_sch_guided_chunked;
3361 // AC: TODO: add AUTO schedule, and pprobably remove TRAPEZOIDAL (OMP 3.0
3362 // does not allow it)
3363 else if (!__kmp_strcasecmp_with_sentinel("auto", value, ',')) { /* AUTO */
3364 __kmp_sched = kmp_sch_auto;
3365 if (comma) {
3366 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, comma),
3367 __kmp_msg_null);
3368 comma = NULL;
3369 }
3370 } else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", value,
3371 ',')) /* TRAPEZOIDAL */
3372 __kmp_sched = kmp_sch_trapezoidal;
3373 else if (!__kmp_strcasecmp_with_sentinel("static", value,
3374 ',')) /* STATIC */
3375 __kmp_sched = kmp_sch_static;
Andrey Churbanov429dbc22016-07-11 10:44:57 +00003376#if KMP_STATIC_STEAL_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00003377 else if (!__kmp_strcasecmp_with_sentinel("static_steal", value, ','))
3378 __kmp_sched = kmp_sch_static_steal;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003379#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003380 else {
3381 KMP_WARNING(StgInvalidValue, name, value);
3382 value = NULL; /* skip processing of comma */
3383 }
3384 if (value && comma) {
Jonathan Peyton30419822017-05-12 18:01:32 +00003385 if (__kmp_sched == kmp_sch_static)
3386 __kmp_sched = kmp_sch_static_chunked;
3387 ++comma;
3388 __kmp_chunk = __kmp_str_to_int(comma, 0);
3389 if (__kmp_chunk < 1) {
3390 __kmp_chunk = KMP_DEFAULT_CHUNK;
3391 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, comma),
3392 __kmp_msg_null);
3393 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3394 // AC: next block commented out until KMP_DEFAULT_CHUNK !=
3395 // KMP_MIN_CHUNK (to improve code coverage :)
3396 // The default chunk size is 1 according to standard, thus making
3397 // KMP_MIN_CHUNK not 1 we would introduce mess:
3398 // wrong chunk becomes 1, but it will be impossible to explicitely
3399 // set 1, because it becomes KMP_MIN_CHUNK...
3400 // } else if ( __kmp_chunk < KMP_MIN_CHUNK ) {
3401 // __kmp_chunk = KMP_MIN_CHUNK;
3402 } else if (__kmp_chunk > KMP_MAX_CHUNK) {
3403 __kmp_chunk = KMP_MAX_CHUNK;
3404 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, comma),
3405 __kmp_msg_null);
3406 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3407 }
Jonathan Peytond74d8902017-07-25 18:20:16 +00003408 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003409 } else
3410 KMP_WARNING(EmptyString, name);
3411 }
3412 K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
3413 K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
3414 K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
3415 K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
Jim Cownie5e8470a2013-09-27 10:38:44 +00003416} // __kmp_stg_parse_omp_schedule
3417
Jonathan Peyton30419822017-05-12 18:01:32 +00003418static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
3419 char const *name, void *data) {
3420 if (__kmp_env_format) {
3421 KMP_STR_BUF_PRINT_NAME_EX(name);
3422 } else {
3423 __kmp_str_buf_print(buffer, " %s='", name);
3424 }
3425 if (__kmp_chunk) {
3426 switch (__kmp_sched) {
3427 case kmp_sch_dynamic_chunked:
3428 __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
3429 break;
3430 case kmp_sch_guided_iterative_chunked:
3431 case kmp_sch_guided_analytical_chunked:
3432 __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
3433 break;
3434 case kmp_sch_trapezoidal:
3435 __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
3436 break;
3437 case kmp_sch_static:
3438 case kmp_sch_static_chunked:
3439 case kmp_sch_static_balanced:
3440 case kmp_sch_static_greedy:
3441 __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
3442 break;
3443 case kmp_sch_static_steal:
3444 __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
3445 break;
3446 case kmp_sch_auto:
3447 __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
3448 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003449 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003450 } else {
3451 switch (__kmp_sched) {
3452 case kmp_sch_dynamic_chunked:
3453 __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
3454 break;
3455 case kmp_sch_guided_iterative_chunked:
3456 case kmp_sch_guided_analytical_chunked:
3457 __kmp_str_buf_print(buffer, "%s'\n", "guided");
3458 break;
3459 case kmp_sch_trapezoidal:
3460 __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
3461 break;
3462 case kmp_sch_static:
3463 case kmp_sch_static_chunked:
3464 case kmp_sch_static_balanced:
3465 case kmp_sch_static_greedy:
3466 __kmp_str_buf_print(buffer, "%s'\n", "static");
3467 break;
3468 case kmp_sch_static_steal:
3469 __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
3470 break;
3471 case kmp_sch_auto:
3472 __kmp_str_buf_print(buffer, "%s'\n", "auto");
3473 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003474 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003475 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003476} // __kmp_stg_print_omp_schedule
3477
Jonathan Peyton30419822017-05-12 18:01:32 +00003478// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003479// KMP_ATOMIC_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003480
Jonathan Peyton30419822017-05-12 18:01:32 +00003481static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
3482 void *data) {
3483 // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
3484 // compatibility mode.
3485 int mode = 0;
3486 int max = 1;
3487#ifdef KMP_GOMP_COMPAT
3488 max = 2;
3489#endif /* KMP_GOMP_COMPAT */
3490 __kmp_stg_parse_int(name, value, 0, max, &mode);
3491 // TODO; parse_int is not very suitable for this case. In case of overflow it
3492 // is better to use
3493 // 0 rather that max value.
3494 if (mode > 0) {
3495 __kmp_atomic_mode = mode;
3496 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003497} // __kmp_stg_parse_atomic_mode
3498
Jonathan Peyton30419822017-05-12 18:01:32 +00003499static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
3500 void *data) {
3501 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003502} // __kmp_stg_print_atomic_mode
3503
Jonathan Peyton30419822017-05-12 18:01:32 +00003504// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003505// KMP_CONSISTENCY_CHECK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003506
Jonathan Peyton30419822017-05-12 18:01:32 +00003507static void __kmp_stg_parse_consistency_check(char const *name,
3508 char const *value, void *data) {
3509 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
3510 // Note, this will not work from kmp_set_defaults because th_cons stack was
3511 // not allocated
3512 // for existed thread(s) thus the first __kmp_push_<construct> will break
3513 // with assertion.
3514 // TODO: allocate th_cons if called from kmp_set_defaults.
3515 __kmp_env_consistency_check = TRUE;
3516 } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
3517 __kmp_env_consistency_check = FALSE;
3518 } else {
3519 KMP_WARNING(StgInvalidValue, name, value);
3520 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003521} // __kmp_stg_parse_consistency_check
3522
Jonathan Peyton30419822017-05-12 18:01:32 +00003523static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
3524 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003525#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003526 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003527
Jonathan Peyton30419822017-05-12 18:01:32 +00003528 if (__kmp_env_consistency_check) {
3529 value = "all";
3530 } else {
3531 value = "none";
3532 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003533
Jonathan Peyton30419822017-05-12 18:01:32 +00003534 if (value != NULL) {
3535 __kmp_stg_print_str(buffer, name, value);
3536 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003537#endif /* KMP_DEBUG */
3538} // __kmp_stg_print_consistency_check
3539
Jim Cownie5e8470a2013-09-27 10:38:44 +00003540#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00003541// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003542// KMP_ITT_PREPARE_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00003543
3544#if USE_ITT_NOTIFY
3545
Jonathan Peyton30419822017-05-12 18:01:32 +00003546static void __kmp_stg_parse_itt_prepare_delay(char const *name,
3547 char const *value, void *data) {
3548 // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
3549 // iterations.
3550 int delay = 0;
3551 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
3552 __kmp_itt_prepare_delay = delay;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003553} // __kmp_str_parse_itt_prepare_delay
3554
Jonathan Peyton30419822017-05-12 18:01:32 +00003555static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
3556 char const *name, void *data) {
3557 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003558
3559} // __kmp_str_print_itt_prepare_delay
3560
3561#endif // USE_ITT_NOTIFY
3562#endif /* USE_ITT_BUILD */
3563
Jonathan Peyton30419822017-05-12 18:01:32 +00003564// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003565// KMP_MALLOC_POOL_INCR
Jim Cownie5e8470a2013-09-27 10:38:44 +00003566
Jonathan Peyton30419822017-05-12 18:01:32 +00003567static void __kmp_stg_parse_malloc_pool_incr(char const *name,
3568 char const *value, void *data) {
3569 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
3570 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
3571 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003572} // __kmp_stg_parse_malloc_pool_incr
3573
Jonathan Peyton30419822017-05-12 18:01:32 +00003574static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
3575 char const *name, void *data) {
3576 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003577
3578} // _kmp_stg_print_malloc_pool_incr
3579
Jim Cownie5e8470a2013-09-27 10:38:44 +00003580#ifdef KMP_DEBUG
3581
Jonathan Peyton30419822017-05-12 18:01:32 +00003582// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003583// KMP_PAR_RANGE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003584
Jonathan Peyton30419822017-05-12 18:01:32 +00003585static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
3586 void *data) {
3587 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
3588 __kmp_par_range_routine, __kmp_par_range_filename,
3589 &__kmp_par_range_lb, &__kmp_par_range_ub);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003590} // __kmp_stg_parse_par_range_env
3591
Jonathan Peyton30419822017-05-12 18:01:32 +00003592static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
3593 char const *name, void *data) {
3594 if (__kmp_par_range != 0) {
3595 __kmp_stg_print_str(buffer, name, par_range_to_print);
3596 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003597} // __kmp_stg_print_par_range_env
3598
Jonathan Peyton30419822017-05-12 18:01:32 +00003599// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003600// KMP_YIELD_CYCLE, KMP_YIELD_ON, KMP_YIELD_OFF
Jim Cownie5e8470a2013-09-27 10:38:44 +00003601
Jonathan Peyton30419822017-05-12 18:01:32 +00003602static void __kmp_stg_parse_yield_cycle(char const *name, char const *value,
3603 void *data) {
3604 int flag = __kmp_yield_cycle;
3605 __kmp_stg_parse_bool(name, value, &flag);
3606 __kmp_yield_cycle = flag;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003607} // __kmp_stg_parse_yield_cycle
3608
Jonathan Peyton30419822017-05-12 18:01:32 +00003609static void __kmp_stg_print_yield_cycle(kmp_str_buf_t *buffer, char const *name,
3610 void *data) {
3611 __kmp_stg_print_bool(buffer, name, __kmp_yield_cycle);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003612} // __kmp_stg_print_yield_cycle
3613
Jonathan Peyton30419822017-05-12 18:01:32 +00003614static void __kmp_stg_parse_yield_on(char const *name, char const *value,
3615 void *data) {
3616 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003617} // __kmp_stg_parse_yield_on
3618
Jonathan Peyton30419822017-05-12 18:01:32 +00003619static void __kmp_stg_print_yield_on(kmp_str_buf_t *buffer, char const *name,
3620 void *data) {
3621 __kmp_stg_print_int(buffer, name, __kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003622} // __kmp_stg_print_yield_on
3623
Jonathan Peyton30419822017-05-12 18:01:32 +00003624static void __kmp_stg_parse_yield_off(char const *name, char const *value,
3625 void *data) {
3626 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003627} // __kmp_stg_parse_yield_off
3628
Jonathan Peyton30419822017-05-12 18:01:32 +00003629static void __kmp_stg_print_yield_off(kmp_str_buf_t *buffer, char const *name,
3630 void *data) {
3631 __kmp_stg_print_int(buffer, name, __kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003632} // __kmp_stg_print_yield_off
3633
3634#endif
3635
Jonathan Peyton30419822017-05-12 18:01:32 +00003636// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003637// KMP_INIT_WAIT, KMP_NEXT_WAIT
Jim Cownie5e8470a2013-09-27 10:38:44 +00003638
Jonathan Peyton30419822017-05-12 18:01:32 +00003639static void __kmp_stg_parse_init_wait(char const *name, char const *value,
3640 void *data) {
3641 int wait;
3642 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3643 wait = __kmp_init_wait / 2;
3644 __kmp_stg_parse_int(name, value, KMP_MIN_INIT_WAIT, KMP_MAX_INIT_WAIT, &wait);
3645 __kmp_init_wait = wait * 2;
3646 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3647 __kmp_yield_init = __kmp_init_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003648} // __kmp_stg_parse_init_wait
3649
Jonathan Peyton30419822017-05-12 18:01:32 +00003650static void __kmp_stg_print_init_wait(kmp_str_buf_t *buffer, char const *name,
3651 void *data) {
3652 __kmp_stg_print_int(buffer, name, __kmp_init_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003653} // __kmp_stg_print_init_wait
3654
Jonathan Peyton30419822017-05-12 18:01:32 +00003655static void __kmp_stg_parse_next_wait(char const *name, char const *value,
3656 void *data) {
3657 int wait;
3658 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3659 wait = __kmp_next_wait / 2;
3660 __kmp_stg_parse_int(name, value, KMP_MIN_NEXT_WAIT, KMP_MAX_NEXT_WAIT, &wait);
3661 __kmp_next_wait = wait * 2;
3662 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3663 __kmp_yield_next = __kmp_next_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003664} // __kmp_stg_parse_next_wait
3665
Jonathan Peyton30419822017-05-12 18:01:32 +00003666static void __kmp_stg_print_next_wait(kmp_str_buf_t *buffer, char const *name,
3667 void *data) {
3668 __kmp_stg_print_int(buffer, name, __kmp_next_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003669} //__kmp_stg_print_next_wait
3670
Jonathan Peyton30419822017-05-12 18:01:32 +00003671// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003672// KMP_GTID_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003673
Jonathan Peyton30419822017-05-12 18:01:32 +00003674static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
3675 void *data) {
3676 // Modes:
3677 // 0 -- do not change default
3678 // 1 -- sp search
3679 // 2 -- use "keyed" TLS var, i.e.
3680 // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
3681 // 3 -- __declspec(thread) TLS var in tdata section
3682 int mode = 0;
3683 int max = 2;
3684#ifdef KMP_TDATA_GTID
3685 max = 3;
3686#endif /* KMP_TDATA_GTID */
3687 __kmp_stg_parse_int(name, value, 0, max, &mode);
3688 // TODO; parse_int is not very suitable for this case. In case of overflow it
3689 // is better to use 0 rather that max value.
3690 if (mode == 0) {
3691 __kmp_adjust_gtid_mode = TRUE;
3692 } else {
3693 __kmp_gtid_mode = mode;
3694 __kmp_adjust_gtid_mode = FALSE;
3695 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003696} // __kmp_str_parse_gtid_mode
3697
Jonathan Peyton30419822017-05-12 18:01:32 +00003698static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
3699 void *data) {
3700 if (__kmp_adjust_gtid_mode) {
3701 __kmp_stg_print_int(buffer, name, 0);
3702 } else {
3703 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
3704 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003705} // __kmp_stg_print_gtid_mode
3706
Jonathan Peyton30419822017-05-12 18:01:32 +00003707// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003708// KMP_NUM_LOCKS_IN_BLOCK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003709
Jonathan Peyton30419822017-05-12 18:01:32 +00003710static void __kmp_stg_parse_lock_block(char const *name, char const *value,
3711 void *data) {
3712 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003713} // __kmp_str_parse_lock_block
3714
Jonathan Peyton30419822017-05-12 18:01:32 +00003715static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
3716 void *data) {
3717 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003718} // __kmp_stg_print_lock_block
3719
Jonathan Peyton30419822017-05-12 18:01:32 +00003720// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003721// KMP_LOCK_KIND
Jim Cownie5e8470a2013-09-27 10:38:44 +00003722
Jonathan Peytondae13d82015-12-11 21:57:06 +00003723#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00003724#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003725#else
Jonathan Peyton30419822017-05-12 18:01:32 +00003726#define KMP_STORE_LOCK_SEQ(a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003727#endif
3728
Jonathan Peyton30419822017-05-12 18:01:32 +00003729static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
3730 void *data) {
3731 if (__kmp_init_user_locks) {
3732 KMP_WARNING(EnvLockWarn, name);
3733 return;
3734 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003735
Jonathan Peyton30419822017-05-12 18:01:32 +00003736 if (__kmp_str_match("tas", 2, value) ||
3737 __kmp_str_match("test and set", 2, value) ||
3738 __kmp_str_match("test_and_set", 2, value) ||
3739 __kmp_str_match("test-and-set", 2, value) ||
3740 __kmp_str_match("test andset", 2, value) ||
3741 __kmp_str_match("test_andset", 2, value) ||
3742 __kmp_str_match("test-andset", 2, value) ||
3743 __kmp_str_match("testand set", 2, value) ||
3744 __kmp_str_match("testand_set", 2, value) ||
3745 __kmp_str_match("testand-set", 2, value) ||
3746 __kmp_str_match("testandset", 2, value)) {
3747 __kmp_user_lock_kind = lk_tas;
3748 KMP_STORE_LOCK_SEQ(tas);
3749 }
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003750#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003751 else if (__kmp_str_match("futex", 1, value)) {
3752 if (__kmp_futex_determine_capable()) {
3753 __kmp_user_lock_kind = lk_futex;
3754 KMP_STORE_LOCK_SEQ(futex);
3755 } else {
3756 KMP_WARNING(FutexNotSupported, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003757 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003758 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003759#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003760 else if (__kmp_str_match("ticket", 2, value)) {
3761 __kmp_user_lock_kind = lk_ticket;
3762 KMP_STORE_LOCK_SEQ(ticket);
3763 } else if (__kmp_str_match("queuing", 1, value) ||
3764 __kmp_str_match("queue", 1, value)) {
3765 __kmp_user_lock_kind = lk_queuing;
3766 KMP_STORE_LOCK_SEQ(queuing);
3767 } else if (__kmp_str_match("drdpa ticket", 1, value) ||
3768 __kmp_str_match("drdpa_ticket", 1, value) ||
3769 __kmp_str_match("drdpa-ticket", 1, value) ||
3770 __kmp_str_match("drdpaticket", 1, value) ||
3771 __kmp_str_match("drdpa", 1, value)) {
3772 __kmp_user_lock_kind = lk_drdpa;
3773 KMP_STORE_LOCK_SEQ(drdpa);
3774 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003775#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003776 else if (__kmp_str_match("adaptive", 1, value)) {
3777 if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
3778 __kmp_user_lock_kind = lk_adaptive;
3779 KMP_STORE_LOCK_SEQ(adaptive);
3780 } else {
3781 KMP_WARNING(AdaptiveNotSupported, name, value);
3782 __kmp_user_lock_kind = lk_queuing;
3783 KMP_STORE_LOCK_SEQ(queuing);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003784 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003785 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003786#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peytondae13d82015-12-11 21:57:06 +00003787#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003788 else if (__kmp_str_match("rtm", 1, value)) {
3789 if (__kmp_cpuinfo.rtm) {
3790 __kmp_user_lock_kind = lk_rtm;
3791 KMP_STORE_LOCK_SEQ(rtm);
3792 } else {
3793 KMP_WARNING(AdaptiveNotSupported, name, value);
3794 __kmp_user_lock_kind = lk_queuing;
3795 KMP_STORE_LOCK_SEQ(queuing);
Jonathan Peytondae13d82015-12-11 21:57:06 +00003796 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003797 } else if (__kmp_str_match("hle", 1, value)) {
3798 __kmp_user_lock_kind = lk_hle;
3799 KMP_STORE_LOCK_SEQ(hle);
3800 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00003801#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003802 else {
3803 KMP_WARNING(StgInvalidValue, name, value);
3804 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003805}
3806
Jonathan Peyton30419822017-05-12 18:01:32 +00003807static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
3808 void *data) {
3809 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003810
Jonathan Peyton30419822017-05-12 18:01:32 +00003811 switch (__kmp_user_lock_kind) {
3812 case lk_default:
3813 value = "default";
3814 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003815
Jonathan Peyton30419822017-05-12 18:01:32 +00003816 case lk_tas:
3817 value = "tas";
3818 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003819
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003820#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003821 case lk_futex:
3822 value = "futex";
3823 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003824#endif
3825
Jonathan Peytondae13d82015-12-11 21:57:06 +00003826#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003827 case lk_rtm:
3828 value = "rtm";
3829 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003830
Jonathan Peyton30419822017-05-12 18:01:32 +00003831 case lk_hle:
3832 value = "hle";
3833 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003834#endif
3835
Jonathan Peyton30419822017-05-12 18:01:32 +00003836 case lk_ticket:
3837 value = "ticket";
3838 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003839
Jonathan Peyton30419822017-05-12 18:01:32 +00003840 case lk_queuing:
3841 value = "queuing";
3842 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003843
Jonathan Peyton30419822017-05-12 18:01:32 +00003844 case lk_drdpa:
3845 value = "drdpa";
3846 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003847#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003848 case lk_adaptive:
3849 value = "adaptive";
3850 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003851#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003852 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003853
Jonathan Peyton30419822017-05-12 18:01:32 +00003854 if (value != NULL) {
3855 __kmp_stg_print_str(buffer, name, value);
3856 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003857}
3858
Jonathan Peyton30419822017-05-12 18:01:32 +00003859// -----------------------------------------------------------------------------
Jonathan Peyton377aa402016-04-14 16:00:37 +00003860// KMP_SPIN_BACKOFF_PARAMS
Jonathan Peyton377aa402016-04-14 16:00:37 +00003861
Jonathan Peyton30419822017-05-12 18:01:32 +00003862// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
3863// for machine pause)
3864static void __kmp_stg_parse_spin_backoff_params(const char *name,
3865 const char *value, void *data) {
3866 const char *next = value;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003867
Jonathan Peyton30419822017-05-12 18:01:32 +00003868 int total = 0; // Count elements that were set. It'll be used as an array size
3869 int prev_comma = FALSE; // For correct processing sequential commas
3870 int i;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003871
Jonathan Peyton30419822017-05-12 18:01:32 +00003872 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
3873 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003874
Jonathan Peyton30419822017-05-12 18:01:32 +00003875 // Run only 3 iterations because it is enough to read two values or find a
3876 // syntax error
3877 for (i = 0; i < 3; i++) {
3878 SKIP_WS(next);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003879
Jonathan Peyton30419822017-05-12 18:01:32 +00003880 if (*next == '\0') {
3881 break;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003882 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003883 // Next character is not an integer or not a comma OR number of values > 2
3884 // => end of list
3885 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
3886 KMP_WARNING(EnvSyntaxError, name, value);
3887 return;
3888 }
3889 // The next character is ','
3890 if (*next == ',') {
3891 // ',' is the fisrt character
3892 if (total == 0 || prev_comma) {
3893 total++;
3894 }
3895 prev_comma = TRUE;
3896 next++; // skip ','
3897 SKIP_WS(next);
3898 }
3899 // Next character is a digit
3900 if (*next >= '0' && *next <= '9') {
3901 int num;
3902 const char *buf = next;
3903 char const *msg = NULL;
3904 prev_comma = FALSE;
3905 SKIP_DIGITS(next);
3906 total++;
3907
3908 const char *tmp = next;
3909 SKIP_WS(tmp);
3910 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
3911 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003912 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00003913 }
3914
3915 num = __kmp_str_to_int(buf, *next);
3916 if (num <= 0) { // The number of retries should be > 0
3917 msg = KMP_I18N_STR(ValueTooSmall);
3918 num = 1;
3919 } else if (num > KMP_INT_MAX) {
3920 msg = KMP_I18N_STR(ValueTooLarge);
3921 num = KMP_INT_MAX;
3922 }
3923 if (msg != NULL) {
3924 // Message is not empty. Print warning.
3925 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
3926 KMP_INFORM(Using_int_Value, name, num);
3927 }
3928 if (total == 1) {
3929 max_backoff = num;
3930 } else if (total == 2) {
3931 min_tick = num;
3932 }
Jonathan Peyton377aa402016-04-14 16:00:37 +00003933 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003934 }
3935 KMP_DEBUG_ASSERT(total > 0);
3936 if (total <= 0) {
3937 KMP_WARNING(EnvSyntaxError, name, value);
3938 return;
3939 }
3940 __kmp_spin_backoff_params.max_backoff = max_backoff;
3941 __kmp_spin_backoff_params.min_tick = min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003942}
3943
Jonathan Peyton30419822017-05-12 18:01:32 +00003944static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
3945 char const *name, void *data) {
3946 if (__kmp_env_format) {
3947 KMP_STR_BUF_PRINT_NAME_EX(name);
3948 } else {
3949 __kmp_str_buf_print(buffer, " %s='", name);
3950 }
3951 __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
3952 __kmp_spin_backoff_params.min_tick);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003953}
3954
Jim Cownie5e8470a2013-09-27 10:38:44 +00003955#if KMP_USE_ADAPTIVE_LOCKS
3956
Jonathan Peyton30419822017-05-12 18:01:32 +00003957// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003958// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003959
3960// Parse out values for the tunable parameters from a string of the form
3961// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
Jonathan Peyton30419822017-05-12 18:01:32 +00003962static void __kmp_stg_parse_adaptive_lock_props(const char *name,
3963 const char *value, void *data) {
3964 int max_retries = 0;
3965 int max_badness = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003966
Jonathan Peyton30419822017-05-12 18:01:32 +00003967 const char *next = value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003968
Jonathan Peyton30419822017-05-12 18:01:32 +00003969 int total = 0; // Count elements that were set. It'll be used as an array size
3970 int prev_comma = FALSE; // For correct processing sequential commas
3971 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003972
Jonathan Peyton30419822017-05-12 18:01:32 +00003973 // Save values in the structure __kmp_speculative_backoff_params
3974 // Run only 3 iterations because it is enough to read two values or find a
3975 // syntax error
3976 for (i = 0; i < 3; i++) {
3977 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003978
Jonathan Peyton30419822017-05-12 18:01:32 +00003979 if (*next == '\0') {
3980 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003981 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003982 // Next character is not an integer or not a comma OR number of values > 2
3983 // => end of list
3984 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
3985 KMP_WARNING(EnvSyntaxError, name, value);
3986 return;
3987 }
3988 // The next character is ','
3989 if (*next == ',') {
3990 // ',' is the fisrt character
3991 if (total == 0 || prev_comma) {
3992 total++;
3993 }
3994 prev_comma = TRUE;
3995 next++; // skip ','
3996 SKIP_WS(next);
3997 }
3998 // Next character is a digit
3999 if (*next >= '0' && *next <= '9') {
4000 int num;
4001 const char *buf = next;
4002 char const *msg = NULL;
4003 prev_comma = FALSE;
4004 SKIP_DIGITS(next);
4005 total++;
4006
4007 const char *tmp = next;
4008 SKIP_WS(tmp);
4009 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4010 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004011 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00004012 }
4013
4014 num = __kmp_str_to_int(buf, *next);
4015 if (num < 0) { // The number of retries should be >= 0
4016 msg = KMP_I18N_STR(ValueTooSmall);
4017 num = 1;
4018 } else if (num > KMP_INT_MAX) {
4019 msg = KMP_I18N_STR(ValueTooLarge);
4020 num = KMP_INT_MAX;
4021 }
4022 if (msg != NULL) {
4023 // Message is not empty. Print warning.
4024 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4025 KMP_INFORM(Using_int_Value, name, num);
4026 }
4027 if (total == 1) {
4028 max_retries = num;
4029 } else if (total == 2) {
4030 max_badness = num;
4031 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004032 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004033 }
4034 KMP_DEBUG_ASSERT(total > 0);
4035 if (total <= 0) {
4036 KMP_WARNING(EnvSyntaxError, name, value);
4037 return;
4038 }
4039 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4040 __kmp_adaptive_backoff_params.max_badness = max_badness;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004041}
4042
Jonathan Peyton30419822017-05-12 18:01:32 +00004043static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4044 char const *name, void *data) {
4045 if (__kmp_env_format) {
4046 KMP_STR_BUF_PRINT_NAME_EX(name);
4047 } else {
4048 __kmp_str_buf_print(buffer, " %s='", name);
4049 }
4050 __kmp_str_buf_print(buffer, "%d,%d'\n",
4051 __kmp_adaptive_backoff_params.max_soft_retries,
4052 __kmp_adaptive_backoff_params.max_badness);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004053} // __kmp_stg_print_adaptive_lock_props
4054
4055#if KMP_DEBUG_ADAPTIVE_LOCKS
4056
Jonathan Peyton30419822017-05-12 18:01:32 +00004057static void __kmp_stg_parse_speculative_statsfile(char const *name,
4058 char const *value,
4059 void *data) {
4060 __kmp_stg_parse_file(name, value, "", &__kmp_speculative_statsfile);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004061} // __kmp_stg_parse_speculative_statsfile
4062
Jonathan Peyton30419822017-05-12 18:01:32 +00004063static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
4064 char const *name,
4065 void *data) {
4066 if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
4067 __kmp_stg_print_str(buffer, name, "stdout");
4068 } else {
4069 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
4070 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004071
4072} // __kmp_stg_print_speculative_statsfile
4073
4074#endif // KMP_DEBUG_ADAPTIVE_LOCKS
4075
4076#endif // KMP_USE_ADAPTIVE_LOCKS
4077
Jonathan Peyton30419822017-05-12 18:01:32 +00004078// -----------------------------------------------------------------------------
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004079// KMP_HW_SUBSET (was KMP_PLACE_THREADS)
Jim Cownie5e8470a2013-09-27 10:38:44 +00004080
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004081// The longest observable sequense of items is
4082// Socket-Node-Tile-Core-Thread
4083// So, let's limit to 5 levels for now
4084// The input string is usually short enough, let's use 512 limit for now
4085#define MAX_T_LEVEL 5
4086#define MAX_STR_LEN 512
Jonathan Peyton30419822017-05-12 18:01:32 +00004087static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
4088 void *data) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004089 // Value example: 1s,5c@3,2T
4090 // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
4091 static int parsed = 0;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004092 if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
4093 KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
4094 if (parsed == 1) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004095 return; // already parsed KMP_HW_SUBSET
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004096 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004097 }
4098 parsed = 1;
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004099
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004100 char *components[MAX_T_LEVEL];
4101 char const *digits = "0123456789";
4102 char input[MAX_STR_LEN];
4103 size_t len = 0, mlen = MAX_STR_LEN;
4104 int level = 0;
4105 // Canonize the string (remove spaces, unify delimiters, etc.)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004106 char *pos = CCAST(char *, value);
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004107 while (*pos && mlen) {
4108 if (*pos != ' ') { // skip spaces
4109 if (len == 0 && *pos == ':') {
4110 __kmp_hws_abs_flag = 1; // if the first symbol is ":", skip it
4111 } else {
4112 input[len] = toupper(*pos);
4113 if (input[len] == 'X')
4114 input[len] = ','; // unify delimiters of levels
4115 if (input[len] == 'O' && strchr(digits, *(pos + 1)))
4116 input[len] = '@'; // unify delimiters of offset
4117 len++;
4118 }
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004119 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004120 mlen--;
4121 pos++;
4122 }
4123 if (len == 0 || mlen == 0)
4124 goto err; // contents is either empty or too long
4125 input[len] = '\0';
4126 __kmp_hws_requested = 1; // mark that subset requested
4127 // Split by delimiter
4128 pos = input;
4129 components[level++] = pos;
George Rokos4800fc42017-04-25 15:55:39 +00004130 while ((pos = strchr(pos, ','))) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004131 *pos = '\0'; // modify input and avoid more copying
4132 components[level++] = ++pos; // expect something after ","
4133 if (level > MAX_T_LEVEL)
4134 goto err; // too many components provided
4135 }
4136 // Check each component
4137 for (int i = 0; i < level; ++i) {
4138 int offset = 0;
4139 int num = atoi(components[i]); // each component should start with a number
4140 if ((pos = strchr(components[i], '@'))) {
4141 offset = atoi(pos + 1); // save offset
4142 *pos = '\0'; // cut the offset from the component
4143 }
4144 pos = components[i] + strspn(components[i], digits);
4145 if (pos == components[i])
4146 goto err;
4147 // detect the component type
4148 switch (*pos) {
4149 case 'S': // Socket
4150 if (__kmp_hws_socket.num > 0)
4151 goto err; // duplicate is not allowed
4152 __kmp_hws_socket.num = num;
4153 __kmp_hws_socket.offset = offset;
4154 break;
4155 case 'N': // NUMA Node
4156 if (__kmp_hws_node.num > 0)
4157 goto err; // duplicate is not allowed
4158 __kmp_hws_node.num = num;
4159 __kmp_hws_node.offset = offset;
4160 break;
4161 case 'L': // Cache
4162 if (*(pos + 1) == '2') { // L2 - Tile
4163 if (__kmp_hws_tile.num > 0)
4164 goto err; // duplicate is not allowed
4165 __kmp_hws_tile.num = num;
4166 __kmp_hws_tile.offset = offset;
4167 } else if (*(pos + 1) == '3') { // L3 - Socket
4168 if (__kmp_hws_socket.num > 0)
4169 goto err; // duplicate is not allowed
4170 __kmp_hws_socket.num = num;
4171 __kmp_hws_socket.offset = offset;
4172 } else if (*(pos + 1) == '1') { // L1 - Core
4173 if (__kmp_hws_core.num > 0)
4174 goto err; // duplicate is not allowed
4175 __kmp_hws_core.num = num;
4176 __kmp_hws_core.offset = offset;
4177 }
4178 break;
4179 case 'C': // Core (or Cache?)
4180 if (*(pos + 1) != 'A') {
4181 if (__kmp_hws_core.num > 0)
4182 goto err; // duplicate is not allowed
4183 __kmp_hws_core.num = num;
4184 __kmp_hws_core.offset = offset;
4185 } else { // Cache
4186 char *d = pos + strcspn(pos, digits); // find digit
4187 if (*d == '2') { // L2 - Tile
4188 if (__kmp_hws_tile.num > 0)
4189 goto err; // duplicate is not allowed
4190 __kmp_hws_tile.num = num;
4191 __kmp_hws_tile.offset = offset;
4192 } else if (*d == '3') { // L3 - Socket
4193 if (__kmp_hws_socket.num > 0)
4194 goto err; // duplicate is not allowed
4195 __kmp_hws_socket.num = num;
4196 __kmp_hws_socket.offset = offset;
4197 } else if (*d == '1') { // L1 - Core
4198 if (__kmp_hws_core.num > 0)
4199 goto err; // duplicate is not allowed
4200 __kmp_hws_core.num = num;
4201 __kmp_hws_core.offset = offset;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004202 } else {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004203 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004204 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004205 }
4206 break;
4207 case 'T': // Thread
4208 if (__kmp_hws_proc.num > 0)
4209 goto err; // duplicate is not allowed
4210 __kmp_hws_proc.num = num;
4211 __kmp_hws_proc.offset = offset;
4212 break;
4213 default:
4214 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004215 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004216 }
4217 return;
4218err:
4219 KMP_WARNING(AffHWSubsetInvalid, name, value);
4220 __kmp_hws_requested = 0; // mark that subset not requested
4221 return;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004222}
4223
Jonathan Peyton30419822017-05-12 18:01:32 +00004224static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004225 void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +00004226 if (__kmp_hws_requested) {
4227 int comma = 0;
4228 kmp_str_buf_t buf;
4229 __kmp_str_buf_init(&buf);
4230 if (__kmp_env_format)
4231 KMP_STR_BUF_PRINT_NAME_EX(name);
4232 else
4233 __kmp_str_buf_print(buffer, " %s='", name);
4234 if (__kmp_hws_socket.num) {
4235 __kmp_str_buf_print(&buf, "%ds", __kmp_hws_socket.num);
4236 if (__kmp_hws_socket.offset)
4237 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_socket.offset);
4238 comma = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004239 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004240 if (__kmp_hws_node.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004241 __kmp_str_buf_print(&buf, "%s%dn", comma ? "," : "", __kmp_hws_node.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004242 if (__kmp_hws_node.offset)
4243 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_node.offset);
4244 comma = 1;
4245 }
4246 if (__kmp_hws_tile.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004247 __kmp_str_buf_print(&buf, "%s%dL2", comma ? "," : "", __kmp_hws_tile.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004248 if (__kmp_hws_tile.offset)
4249 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_tile.offset);
4250 comma = 1;
4251 }
4252 if (__kmp_hws_core.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004253 __kmp_str_buf_print(&buf, "%s%dc", comma ? "," : "", __kmp_hws_core.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004254 if (__kmp_hws_core.offset)
4255 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_core.offset);
4256 comma = 1;
4257 }
4258 if (__kmp_hws_proc.num)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004259 __kmp_str_buf_print(&buf, "%s%dt", comma ? "," : "", __kmp_hws_proc.num);
4260 __kmp_str_buf_print(buffer, "%s'\n", buf.str);
Jonathan Peyton30419822017-05-12 18:01:32 +00004261 __kmp_str_buf_free(&buf);
4262 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004263}
Jim Cownie5e8470a2013-09-27 10:38:44 +00004264
4265#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004266// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004267// KMP_FORKJOIN_FRAMES
Jim Cownie5e8470a2013-09-27 10:38:44 +00004268
Jonathan Peyton30419822017-05-12 18:01:32 +00004269static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
4270 void *data) {
4271 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004272} // __kmp_stg_parse_forkjoin_frames
4273
Jonathan Peyton30419822017-05-12 18:01:32 +00004274static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
4275 char const *name, void *data) {
4276 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004277} // __kmp_stg_print_forkjoin_frames
4278
Jonathan Peyton30419822017-05-12 18:01:32 +00004279// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004280// KMP_FORKJOIN_FRAMES_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00004281
Jonathan Peyton30419822017-05-12 18:01:32 +00004282static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
4283 char const *value,
4284 void *data) {
4285 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004286} // __kmp_stg_parse_forkjoin_frames
4287
Jonathan Peyton30419822017-05-12 18:01:32 +00004288static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
4289 char const *name, void *data) {
4290 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004291} // __kmp_stg_print_forkjoin_frames
4292#endif /* USE_ITT_BUILD */
4293
Jonathan Peyton30419822017-05-12 18:01:32 +00004294// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004295// OMP_DISPLAY_ENV
Jim Cownie5e8470a2013-09-27 10:38:44 +00004296
4297#if OMP_40_ENABLED
4298
Jonathan Peyton30419822017-05-12 18:01:32 +00004299static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
4300 void *data) {
4301 if (__kmp_str_match("VERBOSE", 1, value)) {
4302 __kmp_display_env_verbose = TRUE;
4303 } else {
4304 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
4305 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004306
4307} // __kmp_stg_parse_omp_display_env
4308
Jonathan Peyton30419822017-05-12 18:01:32 +00004309static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
4310 char const *name, void *data) {
4311 if (__kmp_display_env_verbose) {
4312 __kmp_stg_print_str(buffer, name, "VERBOSE");
4313 } else {
4314 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
4315 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004316} // __kmp_stg_print_omp_display_env
4317
Jonathan Peyton30419822017-05-12 18:01:32 +00004318static void __kmp_stg_parse_omp_cancellation(char const *name,
4319 char const *value, void *data) {
4320 if (TCR_4(__kmp_init_parallel)) {
4321 KMP_WARNING(EnvParallelWarn, name);
4322 return;
4323 } // read value before first parallel only
4324 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004325} // __kmp_stg_parse_omp_cancellation
4326
Jonathan Peyton30419822017-05-12 18:01:32 +00004327static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
4328 char const *name, void *data) {
4329 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004330} // __kmp_stg_print_omp_cancellation
4331
Jim Cownie5e8470a2013-09-27 10:38:44 +00004332#endif
4333
Jonathan Peyton30419822017-05-12 18:01:32 +00004334// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004335// Table.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004336
4337static kmp_setting_t __kmp_stg_table[] = {
4338
Jonathan Peyton30419822017-05-12 18:01:32 +00004339 {"KMP_ALL_THREADS", __kmp_stg_parse_all_threads,
4340 __kmp_stg_print_all_threads, NULL, 0, 0},
4341 {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
4342 NULL, 0, 0},
4343 {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
4344 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
4345 {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
4346 NULL, 0, 0},
4347 {"KMP_MAX_THREADS", __kmp_stg_parse_all_threads, NULL, NULL, 0,
4348 0}, // For backward compatibility
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004349#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +00004350 {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
4351 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004352#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004353 {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
4354 0, 0},
4355 {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
4356 __kmp_stg_print_stackoffset, NULL, 0, 0},
4357 {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4358 NULL, 0, 0},
4359 {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
4360 0, 0},
4361 {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
4362 0},
4363 {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
4364 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004365
Jonathan Peyton30419822017-05-12 18:01:32 +00004366 {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
4367 {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
4368 __kmp_stg_print_num_threads, NULL, 0, 0},
4369 {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4370 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004371
Jonathan Peyton30419822017-05-12 18:01:32 +00004372 {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
4373 0},
4374 {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
4375 __kmp_stg_print_task_stealing, NULL, 0, 0},
4376 {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
4377 __kmp_stg_print_max_active_levels, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004378#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004379 {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
4380 __kmp_stg_print_default_device, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004381#endif
Jonathan Peytondf6818b2016-06-14 17:57:47 +00004382#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004383 {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
4384 __kmp_stg_print_max_task_priority, NULL, 0, 0},
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00004385 {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
4386 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
Jonathan Peyton28510722016-02-25 18:04:09 +00004387#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004388 {"OMP_THREAD_LIMIT", __kmp_stg_parse_all_threads,
4389 __kmp_stg_print_all_threads, NULL, 0, 0},
4390 {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
4391 __kmp_stg_print_wait_policy, NULL, 0, 0},
4392 {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
4393 __kmp_stg_print_disp_buffers, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004394#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00004395 {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
4396 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
4397 {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
4398 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004399#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00004400
4401#if KMP_HANDLE_SIGNALS
Jonathan Peyton30419822017-05-12 18:01:32 +00004402 {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
4403 __kmp_stg_print_handle_signals, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004404#endif
4405
4406#if KMP_ARCH_X86 || KMP_ARCH_X86_64
Jonathan Peyton30419822017-05-12 18:01:32 +00004407 {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
4408 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004409#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
4410
4411#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004412 {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004413#endif
4414
4415#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00004416 {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
4417 0},
4418 {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
4419 0},
4420 {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
4421 0},
4422 {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
4423 0},
4424 {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
4425 0},
4426 {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
4427 0},
4428 {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
4429 {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
4430 NULL, 0, 0},
4431 {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
4432 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
4433 {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
4434 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
4435 {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
4436 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
4437 {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004438
Jonathan Peyton30419822017-05-12 18:01:32 +00004439 {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
4440 __kmp_stg_print_par_range_env, NULL, 0, 0},
4441 {"KMP_YIELD_CYCLE", __kmp_stg_parse_yield_cycle,
4442 __kmp_stg_print_yield_cycle, NULL, 0, 0},
4443 {"KMP_YIELD_ON", __kmp_stg_parse_yield_on, __kmp_stg_print_yield_on, NULL,
4444 0, 0},
4445 {"KMP_YIELD_OFF", __kmp_stg_parse_yield_off, __kmp_stg_print_yield_off,
4446 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004447#endif // KMP_DEBUG
4448
Jonathan Peyton30419822017-05-12 18:01:32 +00004449 {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
4450 __kmp_stg_print_align_alloc, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004451
Jonathan Peyton30419822017-05-12 18:01:32 +00004452 {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4453 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4454 {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4455 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
4456 {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4457 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4458 {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4459 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004460#if KMP_FAST_REDUCTION_BARRIER
Jonathan Peyton30419822017-05-12 18:01:32 +00004461 {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4462 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4463 {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4464 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004465#endif
4466
Jonathan Peyton30419822017-05-12 18:01:32 +00004467 {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
4468 __kmp_stg_print_abort_delay, NULL, 0, 0},
4469 {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
4470 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
4471 {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
4472 __kmp_stg_print_force_reduction, NULL, 0, 0},
4473 {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
4474 __kmp_stg_print_force_reduction, NULL, 0, 0},
4475 {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
4476 __kmp_stg_print_storage_map, NULL, 0, 0},
4477 {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
4478 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
4479 {"KMP_FOREIGN_THREADS_THREADPRIVATE",
4480 __kmp_stg_parse_foreign_threads_threadprivate,
4481 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004482
Alp Toker98758b02014-03-02 04:12:06 +00004483#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004484 {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
4485 0, 0},
4486#ifdef KMP_GOMP_COMPAT
4487 {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
4488 /* no print */ NULL, 0, 0},
4489#endif /* KMP_GOMP_COMPAT */
4490#if OMP_40_ENABLED
4491 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4492 NULL, 0, 0},
4493 {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
4494#else
4495 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, NULL, /* no print */ NULL, 0,
4496 0},
4497#endif /* OMP_40_ENABLED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00004498
Jonathan Peyton30419822017-05-12 18:01:32 +00004499 {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
4500 __kmp_stg_print_topology_method, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004501
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004502#else
Jim Cownie5e8470a2013-09-27 10:38:44 +00004503
Jonathan Peyton30419822017-05-12 18:01:32 +00004504// KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
4505// OMP_PROC_BIND and proc-bind-var are supported, however.
4506#if OMP_40_ENABLED
4507 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4508 NULL, 0, 0},
4509#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004510
Alp Toker98758b02014-03-02 04:12:06 +00004511#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004512
Jonathan Peyton30419822017-05-12 18:01:32 +00004513 {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
4514 __kmp_stg_print_init_at_fork, NULL, 0, 0},
4515 {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
4516 0, 0},
4517 {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
4518 NULL, 0, 0},
4519 {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
4520 __kmp_stg_print_atomic_mode, NULL, 0, 0},
4521 {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
4522 __kmp_stg_print_consistency_check, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004523
4524#if USE_ITT_BUILD && USE_ITT_NOTIFY
Jonathan Peyton30419822017-05-12 18:01:32 +00004525 {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
4526 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004527#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
Jonathan Peyton30419822017-05-12 18:01:32 +00004528 {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
4529 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
4530 {"KMP_INIT_WAIT", __kmp_stg_parse_init_wait, __kmp_stg_print_init_wait,
4531 NULL, 0, 0},
4532 {"KMP_NEXT_WAIT", __kmp_stg_parse_next_wait, __kmp_stg_print_next_wait,
4533 NULL, 0, 0},
4534 {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
4535 NULL, 0, 0},
4536 {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
4537 NULL, 0, 0},
4538 {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
4539 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004540
4541#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00004542 {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
4543 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004544#endif
4545
Jonathan Peyton30419822017-05-12 18:01:32 +00004546 {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
4547 __kmp_stg_print_lock_block, NULL, 0, 0},
4548 {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
4549 NULL, 0, 0},
4550 {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
4551 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004552#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004553 {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
4554 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004555#if KMP_DEBUG_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004556 {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
4557 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004558#endif
4559#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004560 {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4561 NULL, 0, 0},
4562 {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4563 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004564#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004565 {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
4566 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
4567 {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
4568 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004569#endif
4570
Jonathan Peyton30419822017-05-12 18:01:32 +00004571#if OMP_40_ENABLED
4572 {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
4573 __kmp_stg_print_omp_display_env, NULL, 0, 0},
4574 {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
4575 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004576#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004577 {"", NULL, NULL, NULL, 0, 0}}; // settings
Jim Cownie5e8470a2013-09-27 10:38:44 +00004578
Jonathan Peyton30419822017-05-12 18:01:32 +00004579static int const __kmp_stg_count =
4580 sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004581
Jonathan Peyton30419822017-05-12 18:01:32 +00004582static inline kmp_setting_t *__kmp_stg_find(char const *name) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004583
Jonathan Peyton30419822017-05-12 18:01:32 +00004584 int i;
4585 if (name != NULL) {
4586 for (i = 0; i < __kmp_stg_count; ++i) {
4587 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
4588 return &__kmp_stg_table[i];
4589 }; // if
4590 }; // for
4591 }; // if
4592 return NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004593
4594} // __kmp_stg_find
4595
Jonathan Peyton30419822017-05-12 18:01:32 +00004596static int __kmp_stg_cmp(void const *_a, void const *_b) {
Andrey Churbanov5ba90c72017-07-17 09:03:14 +00004597 const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
4598 const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004599
Jonathan Peyton30419822017-05-12 18:01:32 +00004600 // Process KMP_AFFINITY last.
4601 // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
4602 if (strcmp(a->name, "KMP_AFFINITY") == 0) {
4603 if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4604 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004605 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004606 return 1;
4607 } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4608 return -1;
4609 }
4610 return strcmp(a->name, b->name);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004611} // __kmp_stg_cmp
4612
Jonathan Peyton30419822017-05-12 18:01:32 +00004613static void __kmp_stg_init(void) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004614
Jonathan Peyton30419822017-05-12 18:01:32 +00004615 static int initialized = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004616
Jonathan Peyton30419822017-05-12 18:01:32 +00004617 if (!initialized) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004618
Jonathan Peyton30419822017-05-12 18:01:32 +00004619 // Sort table.
4620 qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
4621 __kmp_stg_cmp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004622
Jonathan Peyton30419822017-05-12 18:01:32 +00004623 { // Initialize *_STACKSIZE data.
4624 kmp_setting_t *kmp_stacksize =
4625 __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004626#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004627 kmp_setting_t *gomp_stacksize =
4628 __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004629#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004630 kmp_setting_t *omp_stacksize =
4631 __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004632
Jonathan Peyton30419822017-05-12 18:01:32 +00004633 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4634 // !!! Compiler does not understand rivals is used and optimizes out
4635 // assignments
4636 // !!! rivals[ i ++ ] = ...;
4637 static kmp_setting_t *volatile rivals[4];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004638 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004639#ifdef KMP_GOMP_COMPAT
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004640 static kmp_stg_ss_data_t gomp_data = {1024,
4641 CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004642#endif
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004643 static kmp_stg_ss_data_t omp_data = {1024,
4644 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004645 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004646
Jonathan Peyton30419822017-05-12 18:01:32 +00004647 rivals[i++] = kmp_stacksize;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004648#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004649 if (gomp_stacksize != NULL) {
4650 rivals[i++] = gomp_stacksize;
4651 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004652#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004653 rivals[i++] = omp_stacksize;
4654 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004655
Jonathan Peyton30419822017-05-12 18:01:32 +00004656 kmp_stacksize->data = &kmp_data;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004657#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004658 if (gomp_stacksize != NULL) {
4659 gomp_stacksize->data = &gomp_data;
4660 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004661#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004662 omp_stacksize->data = &omp_data;
4663 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004664
Jonathan Peyton30419822017-05-12 18:01:32 +00004665 { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
4666 kmp_setting_t *kmp_library =
4667 __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
4668 kmp_setting_t *omp_wait_policy =
4669 __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004670
Jonathan Peyton30419822017-05-12 18:01:32 +00004671 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4672 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004673 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
4674 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004675 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004676
Jonathan Peyton30419822017-05-12 18:01:32 +00004677 rivals[i++] = kmp_library;
4678 if (omp_wait_policy != NULL) {
4679 rivals[i++] = omp_wait_policy;
4680 }; // if
4681 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004682
Jonathan Peyton30419822017-05-12 18:01:32 +00004683 kmp_library->data = &kmp_data;
4684 if (omp_wait_policy != NULL) {
4685 omp_wait_policy->data = &omp_data;
4686 }; // if
4687 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004688
Jonathan Peyton30419822017-05-12 18:01:32 +00004689 { // Initialize KMP_ALL_THREADS, KMP_MAX_THREADS, and OMP_THREAD_LIMIT data.
4690 kmp_setting_t *kmp_all_threads =
4691 __kmp_stg_find("KMP_ALL_THREADS"); // 1st priority.
4692 kmp_setting_t *kmp_max_threads =
4693 __kmp_stg_find("KMP_MAX_THREADS"); // 2nd priority.
4694 kmp_setting_t *omp_thread_limit =
4695 __kmp_stg_find("OMP_THREAD_LIMIT"); // 3rd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004696
Jonathan Peyton30419822017-05-12 18:01:32 +00004697 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4698 static kmp_setting_t *volatile rivals[4];
4699 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004700
Jonathan Peyton30419822017-05-12 18:01:32 +00004701 rivals[i++] = kmp_all_threads;
4702 rivals[i++] = kmp_max_threads;
4703 if (omp_thread_limit != NULL) {
4704 rivals[i++] = omp_thread_limit;
4705 }; // if
4706 rivals[i++] = NULL;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004707 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
4708 kmp_max_threads->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004709 if (omp_thread_limit != NULL) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004710 omp_thread_limit->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004711 }; // if
4712 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004713
Alp Toker98758b02014-03-02 04:12:06 +00004714#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004715 { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
4716 kmp_setting_t *kmp_affinity =
4717 __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
4718 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004719
Jonathan Peyton30419822017-05-12 18:01:32 +00004720#ifdef KMP_GOMP_COMPAT
4721 kmp_setting_t *gomp_cpu_affinity =
4722 __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
4723 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
4724#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004725
Jonathan Peyton30419822017-05-12 18:01:32 +00004726 kmp_setting_t *omp_proc_bind =
4727 __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
4728 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004729
Jonathan Peyton30419822017-05-12 18:01:32 +00004730 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4731 static kmp_setting_t *volatile rivals[4];
4732 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004733
Jonathan Peyton30419822017-05-12 18:01:32 +00004734 rivals[i++] = kmp_affinity;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004735
Jonathan Peyton30419822017-05-12 18:01:32 +00004736#ifdef KMP_GOMP_COMPAT
4737 rivals[i++] = gomp_cpu_affinity;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004738 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004739#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004740
Jonathan Peyton30419822017-05-12 18:01:32 +00004741 rivals[i++] = omp_proc_bind;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004742 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004743 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004744
Jonathan Peyton30419822017-05-12 18:01:32 +00004745#if OMP_40_ENABLED
4746 static kmp_setting_t *volatile places_rivals[4];
4747 i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004748
Jonathan Peyton30419822017-05-12 18:01:32 +00004749 kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
4750 KMP_DEBUG_ASSERT(omp_places != NULL);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004751
Jonathan Peyton30419822017-05-12 18:01:32 +00004752 places_rivals[i++] = kmp_affinity;
4753#ifdef KMP_GOMP_COMPAT
4754 places_rivals[i++] = gomp_cpu_affinity;
4755#endif
4756 places_rivals[i++] = omp_places;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004757 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004758 places_rivals[i++] = NULL;
4759#endif
4760 }
Alp Toker98758b02014-03-02 04:12:06 +00004761#else
Jonathan Peyton30419822017-05-12 18:01:32 +00004762// KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
4763// OMP_PLACES not supported yet.
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004764#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004765
Jonathan Peyton30419822017-05-12 18:01:32 +00004766 { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
4767 kmp_setting_t *kmp_force_red =
4768 __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
4769 kmp_setting_t *kmp_determ_red =
4770 __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004771
Jonathan Peyton30419822017-05-12 18:01:32 +00004772 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4773 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004774 static kmp_stg_fr_data_t force_data = {1,
4775 CCAST(kmp_setting_t **, rivals)};
4776 static kmp_stg_fr_data_t determ_data = {0,
4777 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004778 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004779
Jonathan Peyton30419822017-05-12 18:01:32 +00004780 rivals[i++] = kmp_force_red;
4781 if (kmp_determ_red != NULL) {
4782 rivals[i++] = kmp_determ_red;
4783 }; // if
4784 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004785
Jonathan Peyton30419822017-05-12 18:01:32 +00004786 kmp_force_red->data = &force_data;
4787 if (kmp_determ_red != NULL) {
4788 kmp_determ_red->data = &determ_data;
4789 }; // if
4790 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004791
Jonathan Peyton30419822017-05-12 18:01:32 +00004792 initialized = 1;
4793 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004794
Jonathan Peyton30419822017-05-12 18:01:32 +00004795 // Reset flags.
4796 int i;
4797 for (i = 0; i < __kmp_stg_count; ++i) {
4798 __kmp_stg_table[i].set = 0;
4799 }; // for
Jim Cownie5e8470a2013-09-27 10:38:44 +00004800
4801} // __kmp_stg_init
4802
Jonathan Peyton30419822017-05-12 18:01:32 +00004803static void __kmp_stg_parse(char const *name, char const *value) {
4804 // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
4805 // really nameless, they are presented in environment block as
4806 // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
4807 if (name[0] == 0) {
4808 return;
4809 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004810
Jonathan Peyton30419822017-05-12 18:01:32 +00004811 if (value != NULL) {
4812 kmp_setting_t *setting = __kmp_stg_find(name);
4813 if (setting != NULL) {
4814 setting->parse(name, value, setting->data);
4815 setting->defined = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004816 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +00004817 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004818
4819} // __kmp_stg_parse
4820
Jonathan Peyton30419822017-05-12 18:01:32 +00004821static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
4822 char const *name, // Name of variable.
4823 char const *value, // Value of the variable.
4824 kmp_setting_t **rivals // List of rival settings (must include current one).
4825 ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004826
Jonathan Peyton30419822017-05-12 18:01:32 +00004827 if (rivals == NULL) {
4828 return 0;
4829 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004830
Jonathan Peyton30419822017-05-12 18:01:32 +00004831 // Loop thru higher priority settings (listed before current).
4832 int i = 0;
4833 for (; strcmp(rivals[i]->name, name) != 0; i++) {
4834 KMP_DEBUG_ASSERT(rivals[i] != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004835
Alp Toker763b9392014-02-28 09:42:41 +00004836#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004837 if (rivals[i] == __kmp_affinity_notype) {
4838 // If KMP_AFFINITY is specified without a type name,
4839 // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
4840 continue;
4841 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004842#endif
4843
Jonathan Peyton30419822017-05-12 18:01:32 +00004844 if (rivals[i]->set) {
4845 KMP_WARNING(StgIgnored, name, rivals[i]->name);
4846 return 1;
4847 }; // if
4848 }; // while
Jim Cownie5e8470a2013-09-27 10:38:44 +00004849
Jonathan Peyton30419822017-05-12 18:01:32 +00004850 ++i; // Skip current setting.
4851 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004852
4853}; // __kmp_stg_check_rivals
4854
Jonathan Peyton30419822017-05-12 18:01:32 +00004855static int __kmp_env_toPrint(char const *name, int flag) {
4856 int rc = 0;
4857 kmp_setting_t *setting = __kmp_stg_find(name);
4858 if (setting != NULL) {
4859 rc = setting->defined;
4860 if (flag >= 0) {
4861 setting->defined = flag;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004862 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +00004863 }; // if
4864 return rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004865}
4866
Jonathan Peyton30419822017-05-12 18:01:32 +00004867static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004868
Jonathan Peyton30419822017-05-12 18:01:32 +00004869 char const *value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004870
Jonathan Peyton30419822017-05-12 18:01:32 +00004871 /* OMP_NUM_THREADS */
4872 value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
4873 if (value) {
4874 ompc_set_num_threads(__kmp_dflt_team_nth);
4875 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004876
Jonathan Peyton30419822017-05-12 18:01:32 +00004877 /* KMP_BLOCKTIME */
4878 value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
4879 if (value) {
4880 kmpc_set_blocktime(__kmp_dflt_blocktime);
4881 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004882
Jonathan Peyton30419822017-05-12 18:01:32 +00004883 /* OMP_NESTED */
4884 value = __kmp_env_blk_var(block, "OMP_NESTED");
4885 if (value) {
4886 ompc_set_nested(__kmp_dflt_nested);
4887 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004888
Jonathan Peyton30419822017-05-12 18:01:32 +00004889 /* OMP_DYNAMIC */
4890 value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
4891 if (value) {
4892 ompc_set_dynamic(__kmp_global.g.g_dynamic);
4893 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004894
4895}
4896
Jonathan Peyton30419822017-05-12 18:01:32 +00004897void __kmp_env_initialize(char const *string) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004898
Jonathan Peyton30419822017-05-12 18:01:32 +00004899 kmp_env_blk_t block;
4900 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004901
Jonathan Peyton30419822017-05-12 18:01:32 +00004902 __kmp_stg_init();
Jim Cownie5e8470a2013-09-27 10:38:44 +00004903
Jonathan Peyton30419822017-05-12 18:01:32 +00004904 // Hack!!!
4905 if (string == NULL) {
4906 // __kmp_max_nth = __kmp_sys_max_nth;
4907 __kmp_threads_capacity =
4908 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
4909 }; // if
4910 __kmp_env_blk_init(&block, string);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004911
Jonathan Peyton30419822017-05-12 18:01:32 +00004912 // update the set flag on all entries that have an env var
4913 for (i = 0; i < block.count; ++i) {
4914 if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
4915 continue;
4916 }
4917 if (block.vars[i].value == NULL) {
4918 continue;
4919 }
4920 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
4921 if (setting != NULL) {
4922 setting->set = 1;
4923 }
4924 }; // for i
Jim Cownie5e8470a2013-09-27 10:38:44 +00004925
Jonathan Peytond74d8902017-07-25 18:20:16 +00004926// We need to know if blocktime was set when processing OMP_WAIT_POLICY
Jonathan Peyton30419822017-05-12 18:01:32 +00004927 blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
Jonathan Peyton50e8f182016-04-04 19:38:32 +00004928
Jonathan Peyton30419822017-05-12 18:01:32 +00004929 // Special case. If we parse environment, not a string, process KMP_WARNINGS
4930 // first.
4931 if (string == NULL) {
4932 char const *name = "KMP_WARNINGS";
4933 char const *value = __kmp_env_blk_var(&block, name);
4934 __kmp_stg_parse(name, value);
4935 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004936
Alp Toker763b9392014-02-28 09:42:41 +00004937#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004938 // Special case. KMP_AFFINITY is not a rival to other affinity env vars
4939 // if no affinity type is specified. We want to allow
4940 // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
4941 // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
4942 // affinity mechanism.
4943 __kmp_affinity_notype = NULL;
4944 char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
4945 if (aff_str != NULL) {
4946// Check if the KMP_AFFINITY type is specified in the string.
4947// We just search the string for "compact", "scatter", etc.
4948// without really parsing the string. The syntax of the
4949// KMP_AFFINITY env var is such that none of the affinity
4950// type names can appear anywhere other that the type
4951// specifier, even as substrings.
4952//
4953// I can't find a case-insensitive version of strstr on Windows* OS.
4954// Use the case-sensitive version for now.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004955
Jonathan Peyton30419822017-05-12 18:01:32 +00004956#if KMP_OS_WINDOWS
4957#define FIND strstr
4958#else
4959#define FIND strcasestr
4960#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004961
Jonathan Peyton30419822017-05-12 18:01:32 +00004962 if ((FIND(aff_str, "none") == NULL) &&
4963 (FIND(aff_str, "physical") == NULL) &&
4964 (FIND(aff_str, "logical") == NULL) &&
4965 (FIND(aff_str, "compact") == NULL) &&
4966 (FIND(aff_str, "scatter") == NULL) &&
4967 (FIND(aff_str, "explicit") == NULL) &&
4968 (FIND(aff_str, "balanced") == NULL) &&
4969 (FIND(aff_str, "disabled") == NULL)) {
4970 __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
4971 } else {
4972 // A new affinity type is specified.
4973 // Reset the affinity flags to their default values,
4974 // in case this is called from kmp_set_defaults().
4975 __kmp_affinity_type = affinity_default;
4976 __kmp_affinity_gran = affinity_gran_default;
4977 __kmp_affinity_top_method = affinity_top_method_default;
4978 __kmp_affinity_respect_mask = affinity_respect_mask_default;
4979 }
4980#undef FIND
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004981
4982#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004983 // Also reset the affinity flags if OMP_PROC_BIND is specified.
4984 aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
4985 if (aff_str != NULL) {
4986 __kmp_affinity_type = affinity_default;
4987 __kmp_affinity_gran = affinity_gran_default;
4988 __kmp_affinity_top_method = affinity_top_method_default;
4989 __kmp_affinity_respect_mask = affinity_respect_mask_default;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004990 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004991#endif /* OMP_40_ENABLED */
4992 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004993
Alp Toker763b9392014-02-28 09:42:41 +00004994#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00004995
4996#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004997 // Set up the nested proc bind type vector.
4998 if (__kmp_nested_proc_bind.bind_types == NULL) {
4999 __kmp_nested_proc_bind.bind_types =
5000 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
5001 if (__kmp_nested_proc_bind.bind_types == NULL) {
5002 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005003 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005004 __kmp_nested_proc_bind.size = 1;
5005 __kmp_nested_proc_bind.used = 1;
5006#if KMP_AFFINITY_SUPPORTED
5007 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
5008#else
5009 // default proc bind is false if affinity not supported
5010 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5011#endif
5012 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005013#endif /* OMP_40_ENABLED */
5014
Jonathan Peyton30419822017-05-12 18:01:32 +00005015 // Now process all of the settings.
5016 for (i = 0; i < block.count; ++i) {
5017 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
5018 }; // for i
Jim Cownie5e8470a2013-09-27 10:38:44 +00005019
Jonathan Peyton30419822017-05-12 18:01:32 +00005020 // If user locks have been allocated yet, don't reset the lock vptr table.
5021 if (!__kmp_init_user_locks) {
5022 if (__kmp_user_lock_kind == lk_default) {
5023 __kmp_user_lock_kind = lk_queuing;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005024 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005025#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00005026 __kmp_init_dynamic_user_locks();
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005027#else
Jonathan Peyton30419822017-05-12 18:01:32 +00005028 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005029#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005030 } else {
5031 KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
5032 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
5033// Binds lock functions again to follow the transition between different
5034// KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
5035// as we do not allow lock kind changes after making a call to any
5036// user lock functions (true).
5037#if KMP_USE_DYNAMIC_LOCK
5038 __kmp_init_dynamic_user_locks();
5039#else
5040 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5041#endif
5042 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005043
Alp Toker763b9392014-02-28 09:42:41 +00005044#if KMP_AFFINITY_SUPPORTED
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005045
Jonathan Peyton30419822017-05-12 18:01:32 +00005046 if (!TCR_4(__kmp_init_middle)) {
5047 // Determine if the machine/OS is actually capable of supporting
5048 // affinity.
5049 const char *var = "KMP_AFFINITY";
5050 KMPAffinity::pick_api();
Jonathan Peytone3e2aaf2017-05-31 20:35:22 +00005051#if KMP_USE_HWLOC
5052 // If Hwloc topology discovery was requested but affinity was also disabled,
5053 // then tell user that Hwloc request is being ignored and use default
5054 // topology discovery method.
5055 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
5056 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
5057 KMP_WARNING(AffIgnoringHwloc, var);
5058 __kmp_affinity_top_method = affinity_top_method_all;
5059 }
5060#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005061 if (__kmp_affinity_type == affinity_disabled) {
5062 KMP_AFFINITY_DISABLE();
5063 } else if (!KMP_AFFINITY_CAPABLE()) {
5064 __kmp_affinity_dispatch->determine_capable(var);
5065 if (!KMP_AFFINITY_CAPABLE()) {
5066 if (__kmp_affinity_verbose ||
5067 (__kmp_affinity_warnings &&
5068 (__kmp_affinity_type != affinity_default) &&
5069 (__kmp_affinity_type != affinity_none) &&
5070 (__kmp_affinity_type != affinity_disabled))) {
5071 KMP_WARNING(AffNotSupported, var);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005072 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005073 __kmp_affinity_type = affinity_disabled;
5074 __kmp_affinity_respect_mask = 0;
5075 __kmp_affinity_gran = affinity_gran_fine;
5076 }
5077 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005078
Jonathan Peyton30419822017-05-12 18:01:32 +00005079#if OMP_40_ENABLED
5080 if (__kmp_affinity_type == affinity_disabled) {
5081 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5082 } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
5083 // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
5084 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
5085 }
5086#endif /* OMP_40_ENABLED */
5087
5088 if (KMP_AFFINITY_CAPABLE()) {
5089
5090#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005091 // This checks to see if the initial affinity mask is equal
5092 // to a single windows processor group. If it is, then we do
5093 // not respect the initial affinity mask and instead, use the
5094 // entire machine.
5095 bool exactly_one_group = false;
5096 if (__kmp_num_proc_groups > 1) {
5097 int group;
5098 bool within_one_group;
5099 // Get the initial affinity mask and determine if it is
5100 // contained within a single group.
5101 kmp_affin_mask_t *init_mask;
5102 KMP_CPU_ALLOC(init_mask);
5103 __kmp_get_system_affinity(init_mask, TRUE);
5104 group = __kmp_get_proc_group(init_mask);
5105 within_one_group = (group >= 0);
5106 // If the initial affinity is within a single group,
5107 // then determine if it is equal to that single group.
5108 if (within_one_group) {
5109 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
5110 int num_bits_in_mask = 0;
5111 for (int bit = init_mask->begin(); bit != init_mask->end();
5112 bit = init_mask->next(bit))
5113 num_bits_in_mask++;
5114 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
5115 }
5116 KMP_CPU_FREE(init_mask);
5117 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005118
5119 // Handle the Win 64 group affinity stuff if there are multiple
5120 // processor groups, or if the user requested it, and OMP 4.0
5121 // affinity is not in effect.
5122 if (((__kmp_num_proc_groups > 1) &&
5123 (__kmp_affinity_type == affinity_default)
5124#if OMP_40_ENABLED
5125 && (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default))
5126#endif
5127 || (__kmp_affinity_top_method == affinity_top_method_group)) {
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005128 if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
5129 exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005130 __kmp_affinity_respect_mask = FALSE;
5131 }
5132 if (__kmp_affinity_type == affinity_default) {
5133 __kmp_affinity_type = affinity_compact;
5134#if OMP_40_ENABLED
5135 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5136#endif
5137 }
5138 if (__kmp_affinity_top_method == affinity_top_method_default) {
5139 if (__kmp_affinity_gran == affinity_gran_default) {
5140 __kmp_affinity_top_method = affinity_top_method_group;
5141 __kmp_affinity_gran = affinity_gran_group;
5142 } else if (__kmp_affinity_gran == affinity_gran_group) {
5143 __kmp_affinity_top_method = affinity_top_method_group;
5144 } else {
5145 __kmp_affinity_top_method = affinity_top_method_all;
5146 }
5147 } else if (__kmp_affinity_top_method == affinity_top_method_group) {
5148 if (__kmp_affinity_gran == affinity_gran_default) {
5149 __kmp_affinity_gran = affinity_gran_group;
5150 } else if ((__kmp_affinity_gran != affinity_gran_group) &&
5151 (__kmp_affinity_gran != affinity_gran_fine) &&
5152 (__kmp_affinity_gran != affinity_gran_thread)) {
5153 const char *str = NULL;
5154 switch (__kmp_affinity_gran) {
5155 case affinity_gran_core:
5156 str = "core";
5157 break;
5158 case affinity_gran_package:
5159 str = "package";
5160 break;
5161 case affinity_gran_node:
5162 str = "node";
5163 break;
5164 default:
5165 KMP_DEBUG_ASSERT(0);
5166 }
5167 KMP_WARNING(AffGranTopGroup, var, str);
5168 __kmp_affinity_gran = affinity_gran_fine;
5169 }
5170 } else {
5171 if (__kmp_affinity_gran == affinity_gran_default) {
5172 __kmp_affinity_gran = affinity_gran_core;
5173 } else if (__kmp_affinity_gran == affinity_gran_group) {
5174 const char *str = NULL;
5175 switch (__kmp_affinity_type) {
5176 case affinity_physical:
5177 str = "physical";
5178 break;
5179 case affinity_logical:
5180 str = "logical";
5181 break;
5182 case affinity_compact:
5183 str = "compact";
5184 break;
5185 case affinity_scatter:
5186 str = "scatter";
5187 break;
5188 case affinity_explicit:
5189 str = "explicit";
5190 break;
5191 // No MIC on windows, so no affinity_balanced case
5192 default:
5193 KMP_DEBUG_ASSERT(0);
5194 }
5195 KMP_WARNING(AffGranGroupType, var, str);
5196 __kmp_affinity_gran = affinity_gran_core;
5197 }
5198 }
5199 } else
5200
5201#endif /* KMP_GROUP_AFFINITY */
5202
5203 {
5204 if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
5205#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005206 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005207 __kmp_affinity_respect_mask = FALSE;
5208 } else
5209#endif /* KMP_GROUP_AFFINITY */
5210 {
5211 __kmp_affinity_respect_mask = TRUE;
5212 }
5213 }
5214#if OMP_40_ENABLED
5215 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
5216 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
5217 if (__kmp_affinity_type == affinity_default) {
5218 __kmp_affinity_type = affinity_compact;
5219 __kmp_affinity_dups = FALSE;
5220 }
5221 } else
5222#endif /* OMP_40_ENABLED */
5223 if (__kmp_affinity_type == affinity_default) {
5224#if OMP_40_ENABLED
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005225#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005226 if (__kmp_mic_type != non_mic) {
5227 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5228 } else
5229#endif
5230 {
Andrey Churbanov94e569e2015-03-10 09:19:47 +00005231 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
Jonathan Peyton30419822017-05-12 18:01:32 +00005232 }
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005233#endif /* OMP_40_ENABLED */
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005234#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005235 if (__kmp_mic_type != non_mic) {
5236 __kmp_affinity_type = affinity_scatter;
5237 } else
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005238#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005239 {
5240 __kmp_affinity_type = affinity_none;
5241 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005242 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005243 if ((__kmp_affinity_gran == affinity_gran_default) &&
5244 (__kmp_affinity_gran_levels < 0)) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005245#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005246 if (__kmp_mic_type != non_mic) {
5247 __kmp_affinity_gran = affinity_gran_fine;
5248 } else
5249#endif
5250 {
5251 __kmp_affinity_gran = affinity_gran_core;
5252 }
5253 }
5254 if (__kmp_affinity_top_method == affinity_top_method_default) {
5255 __kmp_affinity_top_method = affinity_top_method_all;
5256 }
5257 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005258 }
5259
Jonathan Peyton30419822017-05-12 18:01:32 +00005260 K_DIAG(1, ("__kmp_affinity_type == %d\n", __kmp_affinity_type));
5261 K_DIAG(1, ("__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
5262 K_DIAG(1, ("__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
5263 K_DIAG(1, ("__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
5264 K_DIAG(1, ("__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
5265 K_DIAG(1, ("__kmp_affinity_respect_mask == %d\n",
5266 __kmp_affinity_respect_mask));
5267 K_DIAG(1, ("__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
5268
5269 KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
5270#if OMP_40_ENABLED
5271 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
5272#endif
5273 }
5274
Alp Toker763b9392014-02-28 09:42:41 +00005275#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005276
Jonathan Peyton30419822017-05-12 18:01:32 +00005277 if (__kmp_version) {
5278 __kmp_print_version_1();
5279 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00005280
Jonathan Peyton30419822017-05-12 18:01:32 +00005281 // Post-initialization step: some env. vars need their value's further
5282 // processing
5283 if (string != NULL) { // kmp_set_defaults() was called
5284 __kmp_aux_env_initialize(&block);
5285 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005286
Jonathan Peyton30419822017-05-12 18:01:32 +00005287 __kmp_env_blk_free(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005288
Jonathan Peyton30419822017-05-12 18:01:32 +00005289 KMP_MB();
Jim Cownie5e8470a2013-09-27 10:38:44 +00005290
5291} // __kmp_env_initialize
5292
Jonathan Peyton30419822017-05-12 18:01:32 +00005293void __kmp_env_print() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005294
Jonathan Peyton30419822017-05-12 18:01:32 +00005295 kmp_env_blk_t block;
5296 int i;
5297 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005298
Jonathan Peyton30419822017-05-12 18:01:32 +00005299 __kmp_stg_init();
5300 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005301
Jonathan Peyton30419822017-05-12 18:01:32 +00005302 __kmp_env_blk_init(&block, NULL);
5303 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005304
Jonathan Peyton30419822017-05-12 18:01:32 +00005305 // Print real environment values.
5306 __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
5307 for (i = 0; i < block.count; ++i) {
5308 char const *name = block.vars[i].name;
5309 char const *value = block.vars[i].value;
5310 if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
5311 strncmp(name, "OMP_", 4) == 0
5312#ifdef KMP_GOMP_COMPAT
5313 || strncmp(name, "GOMP_", 5) == 0
5314#endif // KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00005315 ) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005316 __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
5317 }; // if
5318 }; // for
5319 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005320
Jonathan Peyton30419822017-05-12 18:01:32 +00005321 // Print internal (effective) settings.
5322 __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
5323 for (int i = 0; i < __kmp_stg_count; ++i) {
5324 if (__kmp_stg_table[i].print != NULL) {
5325 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5326 __kmp_stg_table[i].data);
5327 }; // if
5328 }; // for
Jim Cownie5e8470a2013-09-27 10:38:44 +00005329
Jonathan Peyton30419822017-05-12 18:01:32 +00005330 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005331
Jonathan Peyton30419822017-05-12 18:01:32 +00005332 __kmp_env_blk_free(&block);
5333 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005334
Jonathan Peyton30419822017-05-12 18:01:32 +00005335 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005336
5337} // __kmp_env_print
5338
Jim Cownie5e8470a2013-09-27 10:38:44 +00005339#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005340void __kmp_env_print_2() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005341
Jonathan Peyton30419822017-05-12 18:01:32 +00005342 kmp_env_blk_t block;
5343 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005344
Jonathan Peyton30419822017-05-12 18:01:32 +00005345 __kmp_env_format = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005346
Jonathan Peyton30419822017-05-12 18:01:32 +00005347 __kmp_stg_init();
5348 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005349
Jonathan Peyton30419822017-05-12 18:01:32 +00005350 __kmp_env_blk_init(&block, NULL);
5351 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005352
Jonathan Peyton30419822017-05-12 18:01:32 +00005353 __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
5354 __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005355
Jonathan Peyton30419822017-05-12 18:01:32 +00005356 for (int i = 0; i < __kmp_stg_count; ++i) {
5357 if (__kmp_stg_table[i].print != NULL &&
5358 ((__kmp_display_env &&
5359 strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
5360 __kmp_display_env_verbose)) {
5361 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5362 __kmp_stg_table[i].data);
5363 }; // if
5364 }; // for
Jim Cownie5e8470a2013-09-27 10:38:44 +00005365
Jonathan Peyton30419822017-05-12 18:01:32 +00005366 __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
5367 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005368
Jonathan Peyton30419822017-05-12 18:01:32 +00005369 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005370
Jonathan Peyton30419822017-05-12 18:01:32 +00005371 __kmp_env_blk_free(&block);
5372 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005373
Jonathan Peyton30419822017-05-12 18:01:32 +00005374 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005375
5376} // __kmp_env_print_2
5377#endif // OMP_40_ENABLED
5378
Jim Cownie5e8470a2013-09-27 10:38:44 +00005379// end of file