blob: 2360ed861862ad72b3416609bf59469ff54c1233 [file] [log] [blame]
Jim Cownie5e8470a2013-09-27 10:38:44 +00001/*
Jonathan Peytonde4749b2016-12-14 23:01:24 +00002 * kmp_settings.cpp -- Initialize environment variables
Jim Cownie5e8470a2013-09-27 10:38:44 +00003 */
4
5
6//===----------------------------------------------------------------------===//
7//
8// The LLVM Compiler Infrastructure
9//
10// This file is dual licensed under the MIT and the University of Illinois Open
11// Source Licenses. See LICENSE.txt for details.
12//
13//===----------------------------------------------------------------------===//
14
15
16#include "kmp.h"
Jonathan Peyton1cdd87a2016-11-14 21:08:35 +000017#include "kmp_affinity.h"
Jonathan Peyton30419822017-05-12 18:01:32 +000018#include "kmp_atomic.h"
19#include "kmp_environment.h"
20#include "kmp_i18n.h"
21#include "kmp_io.h"
22#include "kmp_itt.h"
23#include "kmp_lock.h"
24#include "kmp_settings.h"
25#include "kmp_str.h"
26#include "kmp_wrapper_getpid.h"
Andrey Churbanov4a9a8922017-04-13 17:15:07 +000027#include <ctype.h> // toupper()
Jim Cownie5e8470a2013-09-27 10:38:44 +000028
Jonathan Peyton30419822017-05-12 18:01:32 +000029static int __kmp_env_toPrint(char const *name, int flag);
Jim Cownie5e8470a2013-09-27 10:38:44 +000030
31bool __kmp_env_format = 0; // 0 - old format; 1 - new format
Jonathan Peyton30419822017-05-12 18:01:32 +000032
33// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +000034// Helper string functions. Subject to move to kmp_str.
Jim Cownie5e8470a2013-09-27 10:38:44 +000035
Jonathan Peyton30419822017-05-12 18:01:32 +000036static double __kmp_convert_to_double(char const *s) {
37 double result;
Jim Cownie5e8470a2013-09-27 10:38:44 +000038
Jonathan Peyton30419822017-05-12 18:01:32 +000039 if (KMP_SSCANF(s, "%lf", &result) < 1) {
40 result = 0.0;
41 }
Jim Cownie5e8470a2013-09-27 10:38:44 +000042
Jonathan Peyton30419822017-05-12 18:01:32 +000043 return result;
Jim Cownie5e8470a2013-09-27 10:38:44 +000044}
45
Jonathan Peyton2321d572015-06-08 19:25:25 +000046#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +000047static unsigned int __kmp_readstr_with_sentinel(char *dest, char const *src,
48 size_t len, char sentinel) {
49 unsigned int i;
50 for (i = 0; i < len; i++) {
51 if ((*src == '\0') || (*src == sentinel)) {
52 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +000053 }
Jonathan Peyton30419822017-05-12 18:01:32 +000054 *(dest++) = *(src++);
55 }
56 *dest = '\0';
57 return i;
Jim Cownie5e8470a2013-09-27 10:38:44 +000058}
Jonathan Peyton2321d572015-06-08 19:25:25 +000059#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +000060
Jonathan Peyton30419822017-05-12 18:01:32 +000061static int __kmp_match_with_sentinel(char const *a, char const *b, size_t len,
62 char sentinel) {
63 size_t l = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +000064
Jonathan Peyton30419822017-05-12 18:01:32 +000065 if (a == NULL)
66 a = "";
67 if (b == NULL)
68 b = "";
69 while (*a && *b && *b != sentinel) {
70 char ca = *a, cb = *b;
Jim Cownie5e8470a2013-09-27 10:38:44 +000071
Jonathan Peyton30419822017-05-12 18:01:32 +000072 if (ca >= 'a' && ca <= 'z')
73 ca -= 'a' - 'A';
74 if (cb >= 'a' && cb <= 'z')
75 cb -= 'a' - 'A';
76 if (ca != cb)
77 return FALSE;
78 ++l;
79 ++a;
80 ++b;
81 }
82 return l >= len;
Jim Cownie5e8470a2013-09-27 10:38:44 +000083}
84
Jim Cownie5e8470a2013-09-27 10:38:44 +000085// Expected usage:
86// token is the token to check for.
87// buf is the string being parsed.
88// *end returns the char after the end of the token.
89// it is not modified unless a match occurs.
90//
Jim Cownie5e8470a2013-09-27 10:38:44 +000091// Example 1:
92//
93// if (__kmp_match_str("token", buf, *end) {
94// <do something>
95// buf = end;
96// }
97//
98// Example 2:
99//
100// if (__kmp_match_str("token", buf, *end) {
101// char *save = **end;
102// **end = sentinel;
103// <use any of the __kmp*_with_sentinel() functions>
104// **end = save;
105// buf = end;
106// }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000107
Jonathan Peyton30419822017-05-12 18:01:32 +0000108static int __kmp_match_str(char const *token, char const *buf,
109 const char **end) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000110
Jonathan Peyton30419822017-05-12 18:01:32 +0000111 KMP_ASSERT(token != NULL);
112 KMP_ASSERT(buf != NULL);
113 KMP_ASSERT(end != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000114
Jonathan Peyton30419822017-05-12 18:01:32 +0000115 while (*token && *buf) {
116 char ct = *token, cb = *buf;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000117
Jonathan Peyton30419822017-05-12 18:01:32 +0000118 if (ct >= 'a' && ct <= 'z')
119 ct -= 'a' - 'A';
120 if (cb >= 'a' && cb <= 'z')
121 cb -= 'a' - 'A';
122 if (ct != cb)
123 return FALSE;
124 ++token;
125 ++buf;
126 }
127 if (*token) {
128 return FALSE;
129 }
130 *end = buf;
131 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000132}
133
Jonathan Peyton30419822017-05-12 18:01:32 +0000134static size_t __kmp_round4k(size_t size) {
135 size_t _4k = 4 * 1024;
136 if (size & (_4k - 1)) {
137 size &= ~(_4k - 1);
138 if (size <= KMP_SIZE_T_MAX - _4k) {
139 size += _4k; // Round up if there is no overflow.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000140 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000141 }; // if
142 return size;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000143} // __kmp_round4k
144
Jonathan Peyton30419822017-05-12 18:01:32 +0000145/* Here, multipliers are like __kmp_convert_to_seconds, but floating-point
146 values are allowed, and the return value is in milliseconds. The default
147 multiplier is milliseconds. Returns INT_MAX only if the value specified
148 matches "infinit*". Returns -1 if specified string is invalid. */
149int __kmp_convert_to_milliseconds(char const *data) {
150 int ret, nvalues, factor;
151 char mult, extra;
152 double value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000153
Jonathan Peyton30419822017-05-12 18:01:32 +0000154 if (data == NULL)
155 return (-1);
156 if (__kmp_str_match("infinit", -1, data))
157 return (INT_MAX);
158 value = (double)0.0;
159 mult = '\0';
160 nvalues = KMP_SSCANF(data, "%lf%c%c", &value, &mult, &extra);
161 if (nvalues < 1)
162 return (-1);
163 if (nvalues == 1)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000164 mult = '\0';
Jonathan Peyton30419822017-05-12 18:01:32 +0000165 if (nvalues == 3)
166 return (-1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000167
Jonathan Peyton30419822017-05-12 18:01:32 +0000168 if (value < 0)
169 return (-1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000170
Jonathan Peyton30419822017-05-12 18:01:32 +0000171 switch (mult) {
172 case '\0':
173 /* default is milliseconds */
174 factor = 1;
175 break;
176 case 's':
177 case 'S':
178 factor = 1000;
179 break;
180 case 'm':
181 case 'M':
182 factor = 1000 * 60;
183 break;
184 case 'h':
185 case 'H':
186 factor = 1000 * 60 * 60;
187 break;
188 case 'd':
189 case 'D':
190 factor = 1000 * 24 * 60 * 60;
191 break;
192 default:
193 return (-1);
194 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000195
Jonathan Peyton30419822017-05-12 18:01:32 +0000196 if (value >= ((INT_MAX - 1) / factor))
197 ret = INT_MAX - 1; /* Don't allow infinite value here */
198 else
199 ret = (int)(value * (double)factor); /* truncate to int */
Jim Cownie5e8470a2013-09-27 10:38:44 +0000200
Jonathan Peyton30419822017-05-12 18:01:32 +0000201 return ret;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000202}
203
Jonathan Peyton30419822017-05-12 18:01:32 +0000204static int __kmp_strcasecmp_with_sentinel(char const *a, char const *b,
205 char sentinel) {
206 if (a == NULL)
207 a = "";
208 if (b == NULL)
209 b = "";
210 while (*a && *b && *b != sentinel) {
211 char ca = *a, cb = *b;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000212
Jonathan Peyton30419822017-05-12 18:01:32 +0000213 if (ca >= 'a' && ca <= 'z')
214 ca -= 'a' - 'A';
215 if (cb >= 'a' && cb <= 'z')
216 cb -= 'a' - 'A';
217 if (ca != cb)
218 return (int)(unsigned char)*a - (int)(unsigned char)*b;
219 ++a;
220 ++b;
221 }
222 return *a
223 ? (*b && *b != sentinel)
224 ? (int)(unsigned char)*a - (int)(unsigned char)*b
225 : 1
226 : (*b && *b != sentinel) ? -1 : 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000227}
228
Jonathan Peyton30419822017-05-12 18:01:32 +0000229// =============================================================================
Jim Cownie5e8470a2013-09-27 10:38:44 +0000230// Table structures and helper functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000231
Jonathan Peyton30419822017-05-12 18:01:32 +0000232typedef struct __kmp_setting kmp_setting_t;
233typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
234typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
235typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000236
Jonathan Peyton30419822017-05-12 18:01:32 +0000237typedef void (*kmp_stg_parse_func_t)(char const *name, char const *value,
238 void *data);
239typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer, char const *name,
240 void *data);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000241
242struct __kmp_setting {
Jonathan Peyton30419822017-05-12 18:01:32 +0000243 char const *name; // Name of setting (environment variable).
244 kmp_stg_parse_func_t parse; // Parser function.
245 kmp_stg_print_func_t print; // Print function.
246 void *data; // Data passed to parser and printer.
247 int set; // Variable set during this "session"
248 // (__kmp_env_initialize() or kmp_set_defaults() call).
249 int defined; // Variable set in any "session".
Jim Cownie5e8470a2013-09-27 10:38:44 +0000250}; // struct __kmp_setting
251
252struct __kmp_stg_ss_data {
Jonathan Peyton30419822017-05-12 18:01:32 +0000253 size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
254 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
Jim Cownie5e8470a2013-09-27 10:38:44 +0000255}; // struct __kmp_stg_ss_data
256
257struct __kmp_stg_wp_data {
Jonathan Peyton30419822017-05-12 18:01:32 +0000258 int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
259 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
Jim Cownie5e8470a2013-09-27 10:38:44 +0000260}; // struct __kmp_stg_wp_data
261
262struct __kmp_stg_fr_data {
Jonathan Peyton30419822017-05-12 18:01:32 +0000263 int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
264 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
Jim Cownie5e8470a2013-09-27 10:38:44 +0000265}; // struct __kmp_stg_fr_data
266
Jonathan Peyton30419822017-05-12 18:01:32 +0000267static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
268 char const *name, // Name of variable.
269 char const *value, // Value of the variable.
270 kmp_setting_t **rivals // List of rival settings (must include current one).
271 );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000272
Jonathan Peyton30419822017-05-12 18:01:32 +0000273// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000274// Helper parse functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000275
Jonathan Peyton30419822017-05-12 18:01:32 +0000276static void __kmp_stg_parse_bool(char const *name, char const *value,
277 int *out) {
278 if (__kmp_str_match_true(value)) {
279 *out = TRUE;
280 } else if (__kmp_str_match_false(value)) {
281 *out = FALSE;
282 } else {
283 __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
284 KMP_HNT(ValidBoolValues), __kmp_msg_null);
285 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +0000286} // __kmp_stg_parse_bool
287
Jonathan Peyton30419822017-05-12 18:01:32 +0000288static void __kmp_stg_parse_size(char const *name, char const *value,
289 size_t size_min, size_t size_max,
290 int *is_specified, size_t *out,
291 size_t factor) {
292 char const *msg = NULL;
293#if KMP_OS_DARWIN
294 size_min = __kmp_round4k(size_min);
295 size_max = __kmp_round4k(size_max);
296#endif // KMP_OS_DARWIN
297 if (value) {
298 if (is_specified != NULL) {
299 *is_specified = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000300 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000301 __kmp_str_to_size(value, out, factor, &msg);
302 if (msg == NULL) {
303 if (*out > size_max) {
304 *out = size_max;
305 msg = KMP_I18N_STR(ValueTooLarge);
306 } else if (*out < size_min) {
307 *out = size_min;
308 msg = KMP_I18N_STR(ValueTooSmall);
309 } else {
310#if KMP_OS_DARWIN
311 size_t round4k = __kmp_round4k(*out);
312 if (*out != round4k) {
313 *out = round4k;
314 msg = KMP_I18N_STR(NotMultiple4K);
315 }; // if
316#endif
317 }; // if
318 } else {
319 // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to
320 // size_max silently.
321 if (*out < size_min) {
322 *out = size_max;
323 } else if (*out > size_max) {
324 *out = size_max;
325 }; // if
326 }; // if
327 if (msg != NULL) {
328 // Message is not empty. Print warning.
329 kmp_str_buf_t buf;
330 __kmp_str_buf_init(&buf);
331 __kmp_str_buf_print_size(&buf, *out);
332 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
333 KMP_INFORM(Using_str_Value, name, buf.str);
334 __kmp_str_buf_free(&buf);
335 }; // if
336 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +0000337} // __kmp_stg_parse_size
338
Jonathan Peyton2321d572015-06-08 19:25:25 +0000339#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +0000340static void __kmp_stg_parse_str(char const *name, char const *value,
341 char const **out) {
342 __kmp_str_free(out);
343 *out = __kmp_str_format("%s", value);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000344} // __kmp_stg_parse_str
Jonathan Peyton2321d572015-06-08 19:25:25 +0000345#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000346
Jonathan Peyton30419822017-05-12 18:01:32 +0000347static void __kmp_stg_parse_int(
348 char const
349 *name, // I: Name of environment variable (used in warning messages).
350 char const *value, // I: Value of environment variable to parse.
351 int min, // I: Miminal allowed value.
352 int max, // I: Maximum allowed value.
353 int *out // O: Output (parsed) value.
354 ) {
355 char const *msg = NULL;
356 kmp_uint64 uint = *out;
357 __kmp_str_to_uint(value, &uint, &msg);
358 if (msg == NULL) {
359 if (uint < (unsigned int)min) {
360 msg = KMP_I18N_STR(ValueTooSmall);
361 uint = min;
362 } else if (uint > (unsigned int)max) {
363 msg = KMP_I18N_STR(ValueTooLarge);
364 uint = max;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000365 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000366 } else {
367 // If overflow occurred msg contains error message and uint is very big. Cut
368 // tmp it to INT_MAX.
369 if (uint < (unsigned int)min) {
370 uint = min;
371 } else if (uint > (unsigned int)max) {
372 uint = max;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000373 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000374 }; // if
375 if (msg != NULL) {
376 // Message is not empty. Print warning.
377 kmp_str_buf_t buf;
378 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
379 __kmp_str_buf_init(&buf);
380 __kmp_str_buf_print(&buf, "%" KMP_UINT64_SPEC "", uint);
381 KMP_INFORM(Using_uint64_Value, name, buf.str);
382 __kmp_str_buf_free(&buf);
383 }; // if
384 *out = uint;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000385} // __kmp_stg_parse_int
386
Jonathan Peyton2321d572015-06-08 19:25:25 +0000387#if KMP_DEBUG_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +0000388static void __kmp_stg_parse_file(char const *name, char const *value,
389 char *suffix, char **out) {
390 char buffer[256];
391 char *t;
392 int hasSuffix;
393 __kmp_str_free(out);
394 t = (char *)strrchr(value, '.');
395 hasSuffix = t && __kmp_str_eqf(t, suffix);
396 t = __kmp_str_format("%s%s", value, hasSuffix ? "" : suffix);
397 __kmp_expand_file_name(buffer, sizeof(buffer), t);
398 __kmp_str_free(&t);
399 *out = __kmp_str_format("%s", buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000400} // __kmp_stg_parse_file
Jonathan Peyton2321d572015-06-08 19:25:25 +0000401#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000402
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000403#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000404static char *par_range_to_print = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000405
Jonathan Peyton30419822017-05-12 18:01:32 +0000406static void __kmp_stg_parse_par_range(char const *name, char const *value,
407 int *out_range, char *out_routine,
408 char *out_file, int *out_lb,
409 int *out_ub) {
410 size_t len = KMP_STRLEN(value + 1);
411 par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
412 KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
413 __kmp_par_range = +1;
414 __kmp_par_range_lb = 0;
415 __kmp_par_range_ub = INT_MAX;
416 for (;;) {
417 unsigned int len;
418 if ((value == NULL) || (*value == '\0')) {
419 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000420 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000421 if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
422 value = strchr(value, '=') + 1;
423 len = __kmp_readstr_with_sentinel(out_routine, value,
424 KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
425 if (len == 0) {
426 goto par_range_error;
427 }
428 value = strchr(value, ',');
429 if (value != NULL) {
430 value++;
431 }
432 continue;
433 }
434 if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
435 value = strchr(value, '=') + 1;
436 len = __kmp_readstr_with_sentinel(out_file, value,
437 KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
438 if (len == 0) {
439 goto par_range_error;
440 }
441 value = strchr(value, ',');
442 if (value != NULL) {
443 value++;
444 }
445 continue;
446 }
447 if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
448 (!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
449 value = strchr(value, '=') + 1;
450 if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
451 goto par_range_error;
452 }
453 *out_range = +1;
454 value = strchr(value, ',');
455 if (value != NULL) {
456 value++;
457 }
458 continue;
459 }
460 if (!__kmp_strcasecmp_with_sentinel("excl_range", value, '=')) {
461 value = strchr(value, '=') + 1;
462 if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
463 goto par_range_error;
464 }
465 *out_range = -1;
466 value = strchr(value, ',');
467 if (value != NULL) {
468 value++;
469 }
470 continue;
471 }
472 par_range_error:
473 KMP_WARNING(ParRangeSyntax, name);
474 __kmp_par_range = 0;
475 break;
476 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000477} // __kmp_stg_parse_par_range
Jim Cownie3051f972014-08-07 10:12:54 +0000478#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000479
Jonathan Peyton30419822017-05-12 18:01:32 +0000480int __kmp_initial_threads_capacity(int req_nproc) {
481 int nth = 32;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000482
Jonathan Peyton30419822017-05-12 18:01:32 +0000483 /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
484 * __kmp_max_nth) */
485 if (nth < (4 * req_nproc))
486 nth = (4 * req_nproc);
487 if (nth < (4 * __kmp_xproc))
488 nth = (4 * __kmp_xproc);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000489
Jonathan Peyton30419822017-05-12 18:01:32 +0000490 if (nth > __kmp_max_nth)
491 nth = __kmp_max_nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000492
Jonathan Peyton30419822017-05-12 18:01:32 +0000493 return nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000494}
495
Jonathan Peyton30419822017-05-12 18:01:32 +0000496int __kmp_default_tp_capacity(int req_nproc, int max_nth,
497 int all_threads_specified) {
498 int nth = 128;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000499
Jonathan Peyton30419822017-05-12 18:01:32 +0000500 if (all_threads_specified)
501 return max_nth;
502 /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
503 * __kmp_max_nth ) */
504 if (nth < (4 * req_nproc))
505 nth = (4 * req_nproc);
506 if (nth < (4 * __kmp_xproc))
507 nth = (4 * __kmp_xproc);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000508
Jonathan Peyton30419822017-05-12 18:01:32 +0000509 if (nth > __kmp_max_nth)
510 nth = __kmp_max_nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000511
Jonathan Peyton30419822017-05-12 18:01:32 +0000512 return nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000513}
514
Jonathan Peyton30419822017-05-12 18:01:32 +0000515// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000516// Helper print functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000517
Jonathan Peyton30419822017-05-12 18:01:32 +0000518static void __kmp_stg_print_bool(kmp_str_buf_t *buffer, char const *name,
519 int value) {
520 if (__kmp_env_format) {
521 KMP_STR_BUF_PRINT_BOOL;
522 } else {
523 __kmp_str_buf_print(buffer, " %s=%s\n", name, value ? "true" : "false");
524 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000525} // __kmp_stg_print_bool
526
Jonathan Peyton30419822017-05-12 18:01:32 +0000527static void __kmp_stg_print_int(kmp_str_buf_t *buffer, char const *name,
528 int value) {
529 if (__kmp_env_format) {
530 KMP_STR_BUF_PRINT_INT;
531 } else {
532 __kmp_str_buf_print(buffer, " %s=%d\n", name, value);
533 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000534} // __kmp_stg_print_int
535
Jonathan Peyton30419822017-05-12 18:01:32 +0000536static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer, char const *name,
537 kmp_uint64 value) {
538 if (__kmp_env_format) {
539 KMP_STR_BUF_PRINT_UINT64;
540 } else {
541 __kmp_str_buf_print(buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value);
542 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000543} // __kmp_stg_print_uint64
544
Jonathan Peyton30419822017-05-12 18:01:32 +0000545static void __kmp_stg_print_str(kmp_str_buf_t *buffer, char const *name,
546 char const *value) {
547 if (__kmp_env_format) {
548 KMP_STR_BUF_PRINT_STR;
549 } else {
550 __kmp_str_buf_print(buffer, " %s=%s\n", name, value);
551 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000552} // __kmp_stg_print_str
553
Jonathan Peyton30419822017-05-12 18:01:32 +0000554static void __kmp_stg_print_size(kmp_str_buf_t *buffer, char const *name,
555 size_t value) {
556 if (__kmp_env_format) {
557 KMP_STR_BUF_PRINT_NAME_EX(name);
558 __kmp_str_buf_print_size(buffer, value);
559 __kmp_str_buf_print(buffer, "'\n");
560 } else {
561 __kmp_str_buf_print(buffer, " %s=", name);
562 __kmp_str_buf_print_size(buffer, value);
563 __kmp_str_buf_print(buffer, "\n");
564 return;
565 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000566} // __kmp_stg_print_size
567
Jonathan Peyton30419822017-05-12 18:01:32 +0000568// =============================================================================
Jim Cownie5e8470a2013-09-27 10:38:44 +0000569// Parse and print functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000570
Jonathan Peyton30419822017-05-12 18:01:32 +0000571// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000572// KMP_ALL_THREADS, KMP_MAX_THREADS, OMP_THREAD_LIMIT
Jim Cownie5e8470a2013-09-27 10:38:44 +0000573
Jonathan Peyton30419822017-05-12 18:01:32 +0000574static void __kmp_stg_parse_all_threads(char const *name, char const *value,
575 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000576
Jonathan Peyton30419822017-05-12 18:01:32 +0000577 kmp_setting_t **rivals = (kmp_setting_t **)data;
578 int rc;
579 rc = __kmp_stg_check_rivals(name, value, rivals);
580 if (rc) {
581 return;
582 }; // if
583 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
584 __kmp_max_nth = __kmp_xproc;
585 __kmp_allThreadsSpecified = 1;
586 } else {
587 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
588 __kmp_allThreadsSpecified = 0;
589 }
590 K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000591
592} // __kmp_stg_parse_all_threads
593
Jonathan Peyton30419822017-05-12 18:01:32 +0000594static void __kmp_stg_print_all_threads(kmp_str_buf_t *buffer, char const *name,
595 void *data) {
596 __kmp_stg_print_int(buffer, name, __kmp_max_nth);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000597} // __kmp_stg_print_all_threads
598
Jonathan Peyton30419822017-05-12 18:01:32 +0000599// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000600// KMP_BLOCKTIME
Jim Cownie5e8470a2013-09-27 10:38:44 +0000601
Jonathan Peyton30419822017-05-12 18:01:32 +0000602static void __kmp_stg_parse_blocktime(char const *name, char const *value,
603 void *data) {
604 __kmp_dflt_blocktime = __kmp_convert_to_milliseconds(value);
605 if (__kmp_dflt_blocktime < 0) {
606 __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
607 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
608 __kmp_msg_null);
609 KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime);
610 __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
611 } else {
612 if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
613 __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
614 __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
615 __kmp_msg_null);
616 KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime);
617 } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
618 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
619 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
620 __kmp_msg_null);
621 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000622 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000623 __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
624 }; // if
Jonathan Peytone1c7c132016-10-07 18:12:19 +0000625#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +0000626 // calculate number of monitor thread wakeup intervals corresponding to
627 // blocktime.
628 __kmp_monitor_wakeups =
629 KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
630 __kmp_bt_intervals =
631 KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
Jonathan Peytone1c7c132016-10-07 18:12:19 +0000632#endif
Jonathan Peyton30419822017-05-12 18:01:32 +0000633 K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
634 if (__kmp_env_blocktime) {
635 K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
636 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000637} // __kmp_stg_parse_blocktime
638
Jonathan Peyton30419822017-05-12 18:01:32 +0000639static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
640 void *data) {
641 __kmp_stg_print_int(buffer, name, __kmp_dflt_blocktime);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000642} // __kmp_stg_print_blocktime
643
Jonathan Peyton30419822017-05-12 18:01:32 +0000644// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000645// KMP_DUPLICATE_LIB_OK
Jim Cownie5e8470a2013-09-27 10:38:44 +0000646
Jonathan Peyton30419822017-05-12 18:01:32 +0000647static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
648 char const *value, void *data) {
649 /* actually this variable is not supported, put here for compatibility with
650 earlier builds and for static/dynamic combination */
651 __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000652} // __kmp_stg_parse_duplicate_lib_ok
653
Jonathan Peyton30419822017-05-12 18:01:32 +0000654static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
655 char const *name, void *data) {
656 __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000657} // __kmp_stg_print_duplicate_lib_ok
658
Jonathan Peyton30419822017-05-12 18:01:32 +0000659// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000660// KMP_INHERIT_FP_CONTROL
Jim Cownie5e8470a2013-09-27 10:38:44 +0000661
662#if KMP_ARCH_X86 || KMP_ARCH_X86_64
663
Jonathan Peyton30419822017-05-12 18:01:32 +0000664static void __kmp_stg_parse_inherit_fp_control(char const *name,
665 char const *value, void *data) {
666 __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000667} // __kmp_stg_parse_inherit_fp_control
668
Jonathan Peyton30419822017-05-12 18:01:32 +0000669static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
670 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000671#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000672 __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000673#endif /* KMP_DEBUG */
674} // __kmp_stg_print_inherit_fp_control
675
676#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
677
Jonathan Peyton30419822017-05-12 18:01:32 +0000678// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000679// KMP_LIBRARY, OMP_WAIT_POLICY
Jim Cownie5e8470a2013-09-27 10:38:44 +0000680
Jonathan Peyton50e8f182016-04-04 19:38:32 +0000681static char const *blocktime_str = NULL;
682
Jonathan Peyton30419822017-05-12 18:01:32 +0000683static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
684 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000685
Jonathan Peyton30419822017-05-12 18:01:32 +0000686 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
687 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000688
Jonathan Peyton30419822017-05-12 18:01:32 +0000689 rc = __kmp_stg_check_rivals(name, value, wait->rivals);
690 if (rc) {
691 return;
692 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +0000693
Jonathan Peyton30419822017-05-12 18:01:32 +0000694 if (wait->omp) {
695 if (__kmp_str_match("ACTIVE", 1, value)) {
696 __kmp_library = library_turnaround;
697 if (blocktime_str == NULL) {
698 // KMP_BLOCKTIME not specified, so set default to "infinite".
699 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
700 }
701 } else if (__kmp_str_match("PASSIVE", 1, value)) {
702 __kmp_library = library_throughput;
703 if (blocktime_str == NULL) {
704 // KMP_BLOCKTIME not specified, so set default to 0.
705 __kmp_dflt_blocktime = 0;
706 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000707 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +0000708 KMP_WARNING(StgInvalidValue, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000709 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +0000710 } else {
711 if (__kmp_str_match("serial", 1, value)) { /* S */
712 __kmp_library = library_serial;
713 } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
714 __kmp_library = library_throughput;
715 } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
716 __kmp_library = library_turnaround;
717 } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
718 __kmp_library = library_turnaround;
719 } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
720 __kmp_library = library_throughput;
721 } else {
722 KMP_WARNING(StgInvalidValue, name, value);
723 }; // if
724 }; // if
725 __kmp_aux_set_library(__kmp_library);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000726
727} // __kmp_stg_parse_wait_policy
728
Jonathan Peyton30419822017-05-12 18:01:32 +0000729static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
730 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000731
Jonathan Peyton30419822017-05-12 18:01:32 +0000732 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
733 char const *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000734
Jonathan Peyton30419822017-05-12 18:01:32 +0000735 if (wait->omp) {
736 switch (__kmp_library) {
737 case library_turnaround: {
738 value = "ACTIVE";
739 } break;
740 case library_throughput: {
741 value = "PASSIVE";
742 } break;
743 }; // switch
744 } else {
745 switch (__kmp_library) {
746 case library_serial: {
747 value = "serial";
748 } break;
749 case library_turnaround: {
750 value = "turnaround";
751 } break;
752 case library_throughput: {
753 value = "throughput";
754 } break;
755 }; // switch
756 }; // if
757 if (value != NULL) {
758 __kmp_stg_print_str(buffer, name, value);
759 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +0000760
761} // __kmp_stg_print_wait_policy
762
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000763#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +0000764// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000765// KMP_MONITOR_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000766
Jonathan Peyton30419822017-05-12 18:01:32 +0000767static void __kmp_stg_parse_monitor_stacksize(char const *name,
768 char const *value, void *data) {
769 __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
770 NULL, &__kmp_monitor_stksize, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000771} // __kmp_stg_parse_monitor_stacksize
772
Jonathan Peyton30419822017-05-12 18:01:32 +0000773static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
774 char const *name, void *data) {
775 if (__kmp_env_format) {
776 if (__kmp_monitor_stksize > 0)
777 KMP_STR_BUF_PRINT_NAME_EX(name);
778 else
779 KMP_STR_BUF_PRINT_NAME;
780 } else {
781 __kmp_str_buf_print(buffer, " %s", name);
782 }
783 if (__kmp_monitor_stksize > 0) {
784 __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
785 } else {
786 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
787 }
788 if (__kmp_env_format && __kmp_monitor_stksize) {
789 __kmp_str_buf_print(buffer, "'\n");
790 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000791} // __kmp_stg_print_monitor_stacksize
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000792#endif // KMP_USE_MONITOR
Jim Cownie5e8470a2013-09-27 10:38:44 +0000793
Jonathan Peyton30419822017-05-12 18:01:32 +0000794// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000795// KMP_SETTINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000796
Jonathan Peyton30419822017-05-12 18:01:32 +0000797static void __kmp_stg_parse_settings(char const *name, char const *value,
798 void *data) {
799 __kmp_stg_parse_bool(name, value, &__kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000800} // __kmp_stg_parse_settings
801
Jonathan Peyton30419822017-05-12 18:01:32 +0000802static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
803 void *data) {
804 __kmp_stg_print_bool(buffer, name, __kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000805} // __kmp_stg_print_settings
806
Jonathan Peyton30419822017-05-12 18:01:32 +0000807// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000808// KMP_STACKPAD
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000809
Jonathan Peyton30419822017-05-12 18:01:32 +0000810static void __kmp_stg_parse_stackpad(char const *name, char const *value,
811 void *data) {
812 __kmp_stg_parse_int(name, // Env var name
813 value, // Env var value
814 KMP_MIN_STKPADDING, // Min value
815 KMP_MAX_STKPADDING, // Max value
816 &__kmp_stkpadding // Var to initialize
817 );
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000818} // __kmp_stg_parse_stackpad
819
Jonathan Peyton30419822017-05-12 18:01:32 +0000820static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
821 void *data) {
822 __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000823} // __kmp_stg_print_stackpad
824
Jonathan Peyton30419822017-05-12 18:01:32 +0000825// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000826// KMP_STACKOFFSET
Jim Cownie5e8470a2013-09-27 10:38:44 +0000827
Jonathan Peyton30419822017-05-12 18:01:32 +0000828static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
829 void *data) {
830 __kmp_stg_parse_size(name, // Env var name
831 value, // Env var value
832 KMP_MIN_STKOFFSET, // Min value
833 KMP_MAX_STKOFFSET, // Max value
834 NULL, //
835 &__kmp_stkoffset, // Var to initialize
836 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000837} // __kmp_stg_parse_stackoffset
838
Jonathan Peyton30419822017-05-12 18:01:32 +0000839static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
840 void *data) {
841 __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000842} // __kmp_stg_print_stackoffset
843
Jonathan Peyton30419822017-05-12 18:01:32 +0000844// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000845// KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000846
Jonathan Peyton30419822017-05-12 18:01:32 +0000847static void __kmp_stg_parse_stacksize(char const *name, char const *value,
848 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000849
Jonathan Peyton30419822017-05-12 18:01:32 +0000850 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
851 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000852
Jonathan Peyton30419822017-05-12 18:01:32 +0000853 rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
854 if (rc) {
855 return;
856 }; // if
857 __kmp_stg_parse_size(name, // Env var name
858 value, // Env var value
859 __kmp_sys_min_stksize, // Min value
860 KMP_MAX_STKSIZE, // Max value
861 &__kmp_env_stksize, //
862 &__kmp_stksize, // Var to initialize
863 stacksize->factor);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000864
865} // __kmp_stg_parse_stacksize
866
Jonathan Peyton30419822017-05-12 18:01:32 +0000867// This function is called for printing both KMP_STACKSIZE (factor is 1) and
868// OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
869// OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
870// customer request in future.
871static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
872 void *data) {
873 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
874 if (__kmp_env_format) {
875 KMP_STR_BUF_PRINT_NAME_EX(name);
876 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
877 ? __kmp_stksize / stacksize->factor
878 : __kmp_stksize);
879 __kmp_str_buf_print(buffer, "'\n");
880 } else {
881 __kmp_str_buf_print(buffer, " %s=", name);
882 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
883 ? __kmp_stksize / stacksize->factor
884 : __kmp_stksize);
885 __kmp_str_buf_print(buffer, "\n");
886 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000887} // __kmp_stg_print_stacksize
888
Jonathan Peyton30419822017-05-12 18:01:32 +0000889// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000890// KMP_VERSION
Jim Cownie5e8470a2013-09-27 10:38:44 +0000891
Jonathan Peyton30419822017-05-12 18:01:32 +0000892static void __kmp_stg_parse_version(char const *name, char const *value,
893 void *data) {
894 __kmp_stg_parse_bool(name, value, &__kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000895} // __kmp_stg_parse_version
896
Jonathan Peyton30419822017-05-12 18:01:32 +0000897static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
898 void *data) {
899 __kmp_stg_print_bool(buffer, name, __kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000900} // __kmp_stg_print_version
901
Jonathan Peyton30419822017-05-12 18:01:32 +0000902// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000903// KMP_WARNINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000904
Jonathan Peyton30419822017-05-12 18:01:32 +0000905static void __kmp_stg_parse_warnings(char const *name, char const *value,
906 void *data) {
907 __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
908 if (__kmp_generate_warnings != kmp_warnings_off) {
909 // AC: only 0/1 values documented, so reset to explicit to distinguish from
910 // default setting
911 __kmp_generate_warnings = kmp_warnings_explicit;
912 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000913} // __kmp_stg_parse_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000914
Jonathan Peyton30419822017-05-12 18:01:32 +0000915static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
916 void *data) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000917 // AC: TODO: change to print_int? (needs documentation change)
918 __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
919} // __kmp_stg_print_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000920
Jonathan Peyton30419822017-05-12 18:01:32 +0000921// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000922// OMP_NESTED, OMP_NUM_THREADS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000923
Jonathan Peyton30419822017-05-12 18:01:32 +0000924static void __kmp_stg_parse_nested(char const *name, char const *value,
925 void *data) {
926 __kmp_stg_parse_bool(name, value, &__kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000927} // __kmp_stg_parse_nested
928
Jonathan Peyton30419822017-05-12 18:01:32 +0000929static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
930 void *data) {
931 __kmp_stg_print_bool(buffer, name, __kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000932} // __kmp_stg_print_nested
933
Jonathan Peyton30419822017-05-12 18:01:32 +0000934static void __kmp_parse_nested_num_threads(const char *var, const char *env,
935 kmp_nested_nthreads_t *nth_array) {
936 const char *next = env;
937 const char *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000938
Jonathan Peyton30419822017-05-12 18:01:32 +0000939 int total = 0; // Count elements that were set. It'll be used as an array size
940 int prev_comma = FALSE; // For correct processing sequential commas
Jim Cownie5e8470a2013-09-27 10:38:44 +0000941
Jonathan Peyton30419822017-05-12 18:01:32 +0000942 // Count the number of values in the env. var string
943 for (;;) {
944 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000945
Jonathan Peyton30419822017-05-12 18:01:32 +0000946 if (*next == '\0') {
947 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000948 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000949 // Next character is not an integer or not a comma => end of list
950 if (((*next < '0') || (*next > '9')) && (*next != ',')) {
951 KMP_WARNING(NthSyntaxError, var, env);
952 return;
953 }
954 // The next character is ','
955 if (*next == ',') {
956 // ',' is the fisrt character
957 if (total == 0 || prev_comma) {
958 total++;
959 }
960 prev_comma = TRUE;
961 next++; // skip ','
962 SKIP_WS(next);
963 }
964 // Next character is a digit
965 if (*next >= '0' && *next <= '9') {
966 prev_comma = FALSE;
967 SKIP_DIGITS(next);
968 total++;
969 const char *tmp = next;
970 SKIP_WS(tmp);
971 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
972 KMP_WARNING(NthSpacesNotAllowed, var, env);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000973 return;
Jonathan Peyton30419822017-05-12 18:01:32 +0000974 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000975 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000976 }
977 KMP_DEBUG_ASSERT(total > 0);
978 if (total <= 0) {
979 KMP_WARNING(NthSyntaxError, var, env);
980 return;
981 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000982
Jonathan Peyton30419822017-05-12 18:01:32 +0000983 // Check if the nested nthreads array exists
984 if (!nth_array->nth) {
985 // Allocate an array of double size
986 nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
987 if (nth_array->nth == NULL) {
988 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000989 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000990 nth_array->size = total * 2;
991 } else {
992 if (nth_array->size < total) {
993 // Increase the array size
994 do {
995 nth_array->size *= 2;
996 } while (nth_array->size < total);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000997
Jonathan Peyton30419822017-05-12 18:01:32 +0000998 nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
999 nth_array->nth, sizeof(int) * nth_array->size);
1000 if (nth_array->nth == NULL) {
1001 KMP_FATAL(MemoryAllocFailed);
1002 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001003 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001004 }
1005 nth_array->used = total;
1006 int i = 0;
1007
1008 prev_comma = FALSE;
1009 total = 0;
1010 // Save values in the array
1011 for (;;) {
1012 SKIP_WS(scan);
1013 if (*scan == '\0') {
1014 break;
1015 }
1016 // The next character is ','
1017 if (*scan == ',') {
1018 // ',' in the beginning of the list
1019 if (total == 0) {
1020 // The value is supposed to be equal to __kmp_avail_proc but it is
1021 // unknown at the moment.
1022 // So let's put a placeholder (#threads = 0) to correct it later.
1023 nth_array->nth[i++] = 0;
1024 total++;
1025 } else if (prev_comma) {
1026 // Num threads is inherited from the previous level
1027 nth_array->nth[i] = nth_array->nth[i - 1];
1028 i++;
1029 total++;
1030 }
1031 prev_comma = TRUE;
1032 scan++; // skip ','
1033 SKIP_WS(scan);
1034 }
1035 // Next character is a digit
1036 if (*scan >= '0' && *scan <= '9') {
1037 int num;
1038 const char *buf = scan;
1039 char const *msg = NULL;
1040 prev_comma = FALSE;
1041 SKIP_DIGITS(scan);
1042 total++;
1043
1044 num = __kmp_str_to_int(buf, *scan);
1045 if (num < KMP_MIN_NTH) {
1046 msg = KMP_I18N_STR(ValueTooSmall);
1047 num = KMP_MIN_NTH;
1048 } else if (num > __kmp_sys_max_nth) {
1049 msg = KMP_I18N_STR(ValueTooLarge);
1050 num = __kmp_sys_max_nth;
1051 }
1052 if (msg != NULL) {
1053 // Message is not empty. Print warning.
1054 KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1055 KMP_INFORM(Using_int_Value, var, num);
1056 }
1057 nth_array->nth[i++] = num;
1058 }
1059 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001060}
1061
Jonathan Peyton30419822017-05-12 18:01:32 +00001062static void __kmp_stg_parse_num_threads(char const *name, char const *value,
1063 void *data) {
1064 // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
1065 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
1066 // The array of 1 element
1067 __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
1068 __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1069 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1070 __kmp_xproc;
1071 } else {
1072 __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1073 if (__kmp_nested_nth.nth) {
1074 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1075 if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1076 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1077 }
1078 }
1079 }; // if
1080 K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001081} // __kmp_stg_parse_num_threads
1082
Jonathan Peyton30419822017-05-12 18:01:32 +00001083static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
1084 void *data) {
1085 if (__kmp_env_format) {
1086 KMP_STR_BUF_PRINT_NAME;
1087 } else {
1088 __kmp_str_buf_print(buffer, " %s", name);
1089 }
1090 if (__kmp_nested_nth.used) {
1091 kmp_str_buf_t buf;
1092 __kmp_str_buf_init(&buf);
1093 for (int i = 0; i < __kmp_nested_nth.used; i++) {
1094 __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
1095 if (i < __kmp_nested_nth.used - 1) {
1096 __kmp_str_buf_print(&buf, ",");
1097 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001098 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001099 __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
1100 __kmp_str_buf_free(&buf);
1101 } else {
1102 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1103 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001104} // __kmp_stg_print_num_threads
1105
Jonathan Peyton30419822017-05-12 18:01:32 +00001106// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001107// OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001108
Jonathan Peyton30419822017-05-12 18:01:32 +00001109static void __kmp_stg_parse_tasking(char const *name, char const *value,
1110 void *data) {
1111 __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
1112 (int *)&__kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001113} // __kmp_stg_parse_tasking
1114
Jonathan Peyton30419822017-05-12 18:01:32 +00001115static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
1116 void *data) {
1117 __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001118} // __kmp_stg_print_tasking
1119
Jonathan Peyton30419822017-05-12 18:01:32 +00001120static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
1121 void *data) {
1122 __kmp_stg_parse_int(name, value, 0, 1,
1123 (int *)&__kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001124} // __kmp_stg_parse_task_stealing
1125
Jonathan Peyton30419822017-05-12 18:01:32 +00001126static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1127 char const *name, void *data) {
1128 __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001129} // __kmp_stg_print_task_stealing
1130
Jonathan Peyton30419822017-05-12 18:01:32 +00001131static void __kmp_stg_parse_max_active_levels(char const *name,
1132 char const *value, void *data) {
1133 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1134 &__kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001135} // __kmp_stg_parse_max_active_levels
1136
Jonathan Peyton30419822017-05-12 18:01:32 +00001137static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1138 char const *name, void *data) {
1139 __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001140} // __kmp_stg_print_max_active_levels
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001141
George Rokos28f31b42016-09-09 17:55:26 +00001142#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001143// -----------------------------------------------------------------------------
George Rokos28f31b42016-09-09 17:55:26 +00001144// OpenMP 4.0: OMP_DEFAULT_DEVICE
Jonathan Peyton30419822017-05-12 18:01:32 +00001145static void __kmp_stg_parse_default_device(char const *name, char const *value,
1146 void *data) {
1147 __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1148 &__kmp_default_device);
George Rokos28f31b42016-09-09 17:55:26 +00001149} // __kmp_stg_parse_default_device
1150
Jonathan Peyton30419822017-05-12 18:01:32 +00001151static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1152 char const *name, void *data) {
George Rokos28f31b42016-09-09 17:55:26 +00001153 __kmp_stg_print_int(buffer, name, __kmp_default_device);
1154} // __kmp_stg_print_default_device
1155#endif
1156
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001157#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001158// -----------------------------------------------------------------------------
Jonathan Peyton28510722016-02-25 18:04:09 +00001159// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
Jonathan Peyton30419822017-05-12 18:01:32 +00001160static void __kmp_stg_parse_max_task_priority(char const *name,
1161 char const *value, void *data) {
1162 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1163 &__kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001164} // __kmp_stg_parse_max_task_priority
1165
Jonathan Peyton30419822017-05-12 18:01:32 +00001166static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1167 char const *name, void *data) {
1168 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001169} // __kmp_stg_print_max_task_priority
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001170#endif // OMP_45_ENABLED
Jonathan Peyton28510722016-02-25 18:04:09 +00001171
Jonathan Peyton30419822017-05-12 18:01:32 +00001172// -----------------------------------------------------------------------------
Jonathan Peyton067325f2016-05-31 19:01:15 +00001173// KMP_DISP_NUM_BUFFERS
Jonathan Peyton30419822017-05-12 18:01:32 +00001174static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
1175 void *data) {
1176 if (TCR_4(__kmp_init_serial)) {
1177 KMP_WARNING(EnvSerialWarn, name);
1178 return;
1179 } // read value before serial initialization only
1180 __kmp_stg_parse_int(name, value, 1, KMP_MAX_NTH, &__kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001181} // __kmp_stg_parse_disp_buffers
1182
Jonathan Peyton30419822017-05-12 18:01:32 +00001183static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1184 char const *name, void *data) {
1185 __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001186} // __kmp_stg_print_disp_buffers
1187
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001188#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00001189// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001190// KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001191
Jonathan Peyton30419822017-05-12 18:01:32 +00001192static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
1193 void *data) {
1194 if (TCR_4(__kmp_init_parallel)) {
1195 KMP_WARNING(EnvParallelWarn, name);
1196 return;
1197 } // read value before first parallel only
1198 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1199 &__kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001200} // __kmp_stg_parse_hot_teams_level
1201
Jonathan Peyton30419822017-05-12 18:01:32 +00001202static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1203 char const *name, void *data) {
1204 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001205} // __kmp_stg_print_hot_teams_level
1206
Jonathan Peyton30419822017-05-12 18:01:32 +00001207static void __kmp_stg_parse_hot_teams_mode(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_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001215} // __kmp_stg_parse_hot_teams_mode
1216
Jonathan Peyton30419822017-05-12 18:01:32 +00001217static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1218 char const *name, void *data) {
1219 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001220} // __kmp_stg_print_hot_teams_mode
1221
1222#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001223
Jonathan Peyton30419822017-05-12 18:01:32 +00001224// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001225// KMP_HANDLE_SIGNALS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001226
1227#if KMP_HANDLE_SIGNALS
1228
Jonathan Peyton30419822017-05-12 18:01:32 +00001229static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
1230 void *data) {
1231 __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001232} // __kmp_stg_parse_handle_signals
1233
Jonathan Peyton30419822017-05-12 18:01:32 +00001234static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1235 char const *name, void *data) {
1236 __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001237} // __kmp_stg_print_handle_signals
1238
1239#endif // KMP_HANDLE_SIGNALS
1240
Jonathan Peyton30419822017-05-12 18:01:32 +00001241// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001242// KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
Jim Cownie5e8470a2013-09-27 10:38:44 +00001243
1244#ifdef KMP_DEBUG
1245
Jonathan Peyton30419822017-05-12 18:01:32 +00001246#define KMP_STG_X_DEBUG(x) \
1247 static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1248 void *data) { \
1249 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1250 } /* __kmp_stg_parse_x_debug */ \
1251 static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1252 char const *name, void *data) { \
1253 __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1254 } /* __kmp_stg_print_x_debug */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001255
Jonathan Peyton30419822017-05-12 18:01:32 +00001256KMP_STG_X_DEBUG(a)
1257KMP_STG_X_DEBUG(b)
1258KMP_STG_X_DEBUG(c)
1259KMP_STG_X_DEBUG(d)
1260KMP_STG_X_DEBUG(e)
1261KMP_STG_X_DEBUG(f)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001262
1263#undef KMP_STG_X_DEBUG
1264
Jonathan Peyton30419822017-05-12 18:01:32 +00001265static void __kmp_stg_parse_debug(char const *name, char const *value,
1266 void *data) {
1267 int debug = 0;
1268 __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1269 if (kmp_a_debug < debug) {
1270 kmp_a_debug = debug;
1271 }; // if
1272 if (kmp_b_debug < debug) {
1273 kmp_b_debug = debug;
1274 }; // if
1275 if (kmp_c_debug < debug) {
1276 kmp_c_debug = debug;
1277 }; // if
1278 if (kmp_d_debug < debug) {
1279 kmp_d_debug = debug;
1280 }; // if
1281 if (kmp_e_debug < debug) {
1282 kmp_e_debug = debug;
1283 }; // if
1284 if (kmp_f_debug < debug) {
1285 kmp_f_debug = debug;
1286 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00001287} // __kmp_stg_parse_debug
1288
Jonathan Peyton30419822017-05-12 18:01:32 +00001289static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
1290 void *data) {
1291 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1292 // !!! TODO: Move buffer initialization of of this file! It may works
1293 // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
1294 // KMP_DEBUG_BUF_CHARS.
1295 if (__kmp_debug_buf) {
1296 int i;
1297 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001298
Jonathan Peyton30419822017-05-12 18:01:32 +00001299 /* allocate and initialize all entries in debug buffer to empty */
1300 __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
1301 for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1302 __kmp_debug_buffer[i] = '\0';
Jim Cownie5e8470a2013-09-27 10:38:44 +00001303
Jonathan Peyton30419822017-05-12 18:01:32 +00001304 __kmp_debug_count = 0;
1305 }
1306 K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001307} // __kmp_stg_parse_debug_buf
1308
Jonathan Peyton30419822017-05-12 18:01:32 +00001309static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
1310 void *data) {
1311 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001312} // __kmp_stg_print_debug_buf
1313
Jonathan Peyton30419822017-05-12 18:01:32 +00001314static void __kmp_stg_parse_debug_buf_atomic(char const *name,
1315 char const *value, void *data) {
1316 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001317} // __kmp_stg_parse_debug_buf_atomic
1318
Jonathan Peyton30419822017-05-12 18:01:32 +00001319static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1320 char const *name, void *data) {
1321 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001322} // __kmp_stg_print_debug_buf_atomic
1323
Jonathan Peyton30419822017-05-12 18:01:32 +00001324static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
1325 void *data) {
1326 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1327 &__kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001328} // __kmp_stg_debug_parse_buf_chars
1329
Jonathan Peyton30419822017-05-12 18:01:32 +00001330static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1331 char const *name, void *data) {
1332 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001333} // __kmp_stg_print_debug_buf_chars
1334
Jonathan Peyton30419822017-05-12 18:01:32 +00001335static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
1336 void *data) {
1337 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1338 &__kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001339} // __kmp_stg_parse_debug_buf_lines
1340
Jonathan Peyton30419822017-05-12 18:01:32 +00001341static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1342 char const *name, void *data) {
1343 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001344} // __kmp_stg_print_debug_buf_lines
1345
Jonathan Peyton30419822017-05-12 18:01:32 +00001346static void __kmp_stg_parse_diag(char const *name, char const *value,
1347 void *data) {
1348 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001349} // __kmp_stg_parse_diag
1350
Jonathan Peyton30419822017-05-12 18:01:32 +00001351static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
1352 void *data) {
1353 __kmp_stg_print_int(buffer, name, kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001354} // __kmp_stg_print_diag
1355
1356#endif // KMP_DEBUG
1357
Jonathan Peyton30419822017-05-12 18:01:32 +00001358// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001359// KMP_ALIGN_ALLOC
Jim Cownie5e8470a2013-09-27 10:38:44 +00001360
Jonathan Peyton30419822017-05-12 18:01:32 +00001361static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
1362 void *data) {
1363 __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1364 &__kmp_align_alloc, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001365} // __kmp_stg_parse_align_alloc
1366
Jonathan Peyton30419822017-05-12 18:01:32 +00001367static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
1368 void *data) {
1369 __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001370} // __kmp_stg_print_align_alloc
1371
Jonathan Peyton30419822017-05-12 18:01:32 +00001372// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001373// KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
Jim Cownie5e8470a2013-09-27 10:38:44 +00001374
Jonathan Peyton30419822017-05-12 18:01:32 +00001375// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
1376// parse and print functions, pass required info through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001377
Jonathan Peyton30419822017-05-12 18:01:32 +00001378static void __kmp_stg_parse_barrier_branch_bit(char const *name,
1379 char const *value, void *data) {
1380 const char *var;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001381
Jonathan Peyton30419822017-05-12 18:01:32 +00001382 /* ---------- Barrier branch bit control ------------ */
1383 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1384 var = __kmp_barrier_branch_bit_env_name[i];
1385 if ((strcmp(var, name) == 0) && (value != 0)) {
1386 char *comma;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001387
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001388 comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00001389 __kmp_barrier_gather_branch_bits[i] =
1390 (kmp_uint32)__kmp_str_to_int(value, ',');
1391 /* is there a specified release parameter? */
1392 if (comma == NULL) {
1393 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1394 } else {
1395 __kmp_barrier_release_branch_bits[i] =
1396 (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001397
Jonathan Peyton30419822017-05-12 18:01:32 +00001398 if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1399 __kmp_msg(kmp_ms_warning,
1400 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1401 __kmp_msg_null);
1402 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001403 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001404 }
1405 if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1406 KMP_WARNING(BarrGatherValueInvalid, name, value);
1407 KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1408 __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1409 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001410 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001411 K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1412 __kmp_barrier_gather_branch_bits[i],
1413 __kmp_barrier_release_branch_bits[i]))
1414 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001415} // __kmp_stg_parse_barrier_branch_bit
1416
Jonathan Peyton30419822017-05-12 18:01:32 +00001417static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1418 char const *name, void *data) {
1419 const char *var;
1420 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1421 var = __kmp_barrier_branch_bit_env_name[i];
1422 if (strcmp(var, name) == 0) {
1423 if (__kmp_env_format) {
1424 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1425 } else {
1426 __kmp_str_buf_print(buffer, " %s='",
1427 __kmp_barrier_branch_bit_env_name[i]);
1428 }
1429 __kmp_str_buf_print(buffer, "%d,%d'\n",
1430 __kmp_barrier_gather_branch_bits[i],
1431 __kmp_barrier_release_branch_bits[i]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001432 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001433 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001434} // __kmp_stg_print_barrier_branch_bit
1435
Jonathan Peyton30419822017-05-12 18:01:32 +00001436// ----------------------------------------------------------------------------
1437// KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
1438// KMP_REDUCTION_BARRIER_PATTERN
Jim Cownie5e8470a2013-09-27 10:38:44 +00001439
Jonathan Peyton30419822017-05-12 18:01:32 +00001440// TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
1441// print functions, pass required data to functions through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001442
Jonathan Peyton30419822017-05-12 18:01:32 +00001443static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
1444 void *data) {
1445 const char *var;
1446 /* ---------- Barrier method control ------------ */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001447
Jonathan Peyton30419822017-05-12 18:01:32 +00001448 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1449 var = __kmp_barrier_pattern_env_name[i];
Jim Cownie5e8470a2013-09-27 10:38:44 +00001450
Jonathan Peyton30419822017-05-12 18:01:32 +00001451 if ((strcmp(var, name) == 0) && (value != 0)) {
1452 int j;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001453 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001454
Jonathan Peyton30419822017-05-12 18:01:32 +00001455 /* handle first parameter: gather pattern */
1456 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1457 if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1458 ',')) {
1459 __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1460 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001461 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001462 }
1463 if (j == bp_last_bar) {
1464 KMP_WARNING(BarrGatherValueInvalid, name, value);
1465 KMP_INFORM(Using_str_Value, name,
1466 __kmp_barrier_pattern_name[bp_linear_bar]);
1467 }
1468
1469 /* handle second parameter: release pattern */
1470 if (comma != NULL) {
1471 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1472 if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1473 __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1474 break;
1475 }
1476 }
1477 if (j == bp_last_bar) {
1478 __kmp_msg(kmp_ms_warning,
1479 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1480 __kmp_msg_null);
1481 KMP_INFORM(Using_str_Value, name,
1482 __kmp_barrier_pattern_name[bp_linear_bar]);
1483 }
1484 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001485 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001486 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001487} // __kmp_stg_parse_barrier_pattern
1488
Jonathan Peyton30419822017-05-12 18:01:32 +00001489static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1490 char const *name, void *data) {
1491 const char *var;
1492 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1493 var = __kmp_barrier_pattern_env_name[i];
1494 if (strcmp(var, name) == 0) {
1495 int j = __kmp_barrier_gather_pattern[i];
1496 int k = __kmp_barrier_release_pattern[i];
1497 if (__kmp_env_format) {
1498 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1499 } else {
1500 __kmp_str_buf_print(buffer, " %s='",
1501 __kmp_barrier_pattern_env_name[i]);
1502 }
1503 __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
1504 __kmp_barrier_pattern_name[k]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001505 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001506 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001507} // __kmp_stg_print_barrier_pattern
1508
Jonathan Peyton30419822017-05-12 18:01:32 +00001509// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001510// KMP_ABORT_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00001511
Jonathan Peyton30419822017-05-12 18:01:32 +00001512static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
1513 void *data) {
1514 // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
1515 // milliseconds.
1516 int delay = __kmp_abort_delay / 1000;
1517 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1518 __kmp_abort_delay = delay * 1000;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001519} // __kmp_stg_parse_abort_delay
1520
Jonathan Peyton30419822017-05-12 18:01:32 +00001521static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
1522 void *data) {
1523 __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001524} // __kmp_stg_print_abort_delay
1525
Jonathan Peyton30419822017-05-12 18:01:32 +00001526// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001527// KMP_CPUINFO_FILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001528
Jonathan Peyton30419822017-05-12 18:01:32 +00001529static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
1530 void *data) {
1531#if KMP_AFFINITY_SUPPORTED
1532 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1533 K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1534#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001535} //__kmp_stg_parse_cpuinfo_file
1536
Jonathan Peyton30419822017-05-12 18:01:32 +00001537static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1538 char const *name, void *data) {
1539#if KMP_AFFINITY_SUPPORTED
1540 if (__kmp_env_format) {
1541 KMP_STR_BUF_PRINT_NAME;
1542 } else {
1543 __kmp_str_buf_print(buffer, " %s", name);
1544 }
1545 if (__kmp_cpuinfo_file) {
1546 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
1547 } else {
1548 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1549 }
1550#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001551} //__kmp_stg_print_cpuinfo_file
1552
Jonathan Peyton30419822017-05-12 18:01:32 +00001553// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001554// KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
Jim Cownie5e8470a2013-09-27 10:38:44 +00001555
Jonathan Peyton30419822017-05-12 18:01:32 +00001556static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
1557 void *data) {
1558 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1559 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001560
Jonathan Peyton30419822017-05-12 18:01:32 +00001561 rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1562 if (rc) {
1563 return;
1564 }; // if
1565 if (reduction->force) {
1566 if (value != 0) {
1567 if (__kmp_str_match("critical", 0, value))
1568 __kmp_force_reduction_method = critical_reduce_block;
1569 else if (__kmp_str_match("atomic", 0, value))
1570 __kmp_force_reduction_method = atomic_reduce_block;
1571 else if (__kmp_str_match("tree", 0, value))
1572 __kmp_force_reduction_method = tree_reduce_block;
1573 else {
1574 KMP_FATAL(UnknownForceReduction, name, value);
1575 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001576 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001577 } else {
1578 __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1579 if (__kmp_determ_red) {
1580 __kmp_force_reduction_method = tree_reduce_block;
1581 } else {
1582 __kmp_force_reduction_method = reduction_method_not_defined;
1583 }
1584 }
1585 K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
1586 __kmp_force_reduction_method));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001587} // __kmp_stg_parse_force_reduction
1588
Jonathan Peyton30419822017-05-12 18:01:32 +00001589static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1590 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00001591
Jonathan Peyton30419822017-05-12 18:01:32 +00001592 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1593 if (reduction->force) {
1594 if (__kmp_force_reduction_method == critical_reduce_block) {
1595 __kmp_stg_print_str(buffer, name, "critical");
1596 } else if (__kmp_force_reduction_method == atomic_reduce_block) {
1597 __kmp_stg_print_str(buffer, name, "atomic");
1598 } else if (__kmp_force_reduction_method == tree_reduce_block) {
1599 __kmp_stg_print_str(buffer, name, "tree");
Jim Cownie5e8470a2013-09-27 10:38:44 +00001600 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00001601 if (__kmp_env_format) {
1602 KMP_STR_BUF_PRINT_NAME;
1603 } else {
1604 __kmp_str_buf_print(buffer, " %s", name);
1605 }
1606 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001607 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001608 } else {
1609 __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1610 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001611
1612} // __kmp_stg_print_force_reduction
1613
Jonathan Peyton30419822017-05-12 18:01:32 +00001614// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001615// KMP_STORAGE_MAP
Jim Cownie5e8470a2013-09-27 10:38:44 +00001616
Jonathan Peyton30419822017-05-12 18:01:32 +00001617static void __kmp_stg_parse_storage_map(char const *name, char const *value,
1618 void *data) {
1619 if (__kmp_str_match("verbose", 1, value)) {
1620 __kmp_storage_map = TRUE;
1621 __kmp_storage_map_verbose = TRUE;
1622 __kmp_storage_map_verbose_specified = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001623
Jonathan Peyton30419822017-05-12 18:01:32 +00001624 } else {
1625 __kmp_storage_map_verbose = FALSE;
1626 __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
1627 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00001628} // __kmp_stg_parse_storage_map
1629
Jonathan Peyton30419822017-05-12 18:01:32 +00001630static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
1631 void *data) {
1632 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1633 __kmp_stg_print_str(buffer, name, "verbose");
1634 } else {
1635 __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1636 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001637} // __kmp_stg_print_storage_map
1638
Jonathan Peyton30419822017-05-12 18:01:32 +00001639// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001640// KMP_ALL_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001641
Jonathan Peyton30419822017-05-12 18:01:32 +00001642static void __kmp_stg_parse_all_threadprivate(char const *name,
1643 char const *value, void *data) {
1644 __kmp_stg_parse_int(name, value,
1645 __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1646 __kmp_max_nth, &__kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001647} // __kmp_stg_parse_all_threadprivate
1648
Jonathan Peyton30419822017-05-12 18:01:32 +00001649static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1650 char const *name, void *data) {
1651 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001652}
1653
Jonathan Peyton30419822017-05-12 18:01:32 +00001654// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001655// KMP_FOREIGN_THREADS_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001656
Jonathan Peyton30419822017-05-12 18:01:32 +00001657static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
1658 char const *value,
1659 void *data) {
1660 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001661} // __kmp_stg_parse_foreign_threads_threadprivate
1662
Jonathan Peyton30419822017-05-12 18:01:32 +00001663static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
1664 char const *name,
1665 void *data) {
1666 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001667} // __kmp_stg_print_foreign_threads_threadprivate
1668
Jonathan Peyton30419822017-05-12 18:01:32 +00001669// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001670// KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
Jim Cownie5e8470a2013-09-27 10:38:44 +00001671
Alp Toker98758b02014-03-02 04:12:06 +00001672#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00001673// Parse the proc id list. Return TRUE if successful, FALSE otherwise.
Jonathan Peyton30419822017-05-12 18:01:32 +00001674static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
1675 const char **nextEnv,
1676 char **proclist) {
1677 const char *scan = env;
1678 const char *next = scan;
1679 int empty = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001680
Jonathan Peyton30419822017-05-12 18:01:32 +00001681 *proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001682
Jonathan Peyton30419822017-05-12 18:01:32 +00001683 for (;;) {
1684 int start, end, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001685
Jonathan Peyton30419822017-05-12 18:01:32 +00001686 SKIP_WS(scan);
1687 next = scan;
1688 if (*next == '\0') {
1689 break;
1690 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001691
Jonathan Peyton30419822017-05-12 18:01:32 +00001692 if (*next == '{') {
1693 int num;
1694 next++; // skip '{'
1695 SKIP_WS(next);
1696 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001697
Jonathan Peyton30419822017-05-12 18:01:32 +00001698 // Read the first integer in the set.
1699 if ((*next < '0') || (*next > '9')) {
1700 KMP_WARNING(AffSyntaxError, var);
1701 return FALSE;
1702 }
1703 SKIP_DIGITS(next);
1704 num = __kmp_str_to_int(scan, *next);
1705 KMP_ASSERT(num >= 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001706
Jonathan Peyton30419822017-05-12 18:01:32 +00001707 for (;;) {
1708 // Check for end of set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001709 SKIP_WS(next);
Jonathan Peyton30419822017-05-12 18:01:32 +00001710 if (*next == '}') {
1711 next++; // skip '}'
1712 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001713 }
1714
Jim Cownie5e8470a2013-09-27 10:38:44 +00001715 // Skip optional comma.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001716 if (*next == ',') {
Jonathan Peyton30419822017-05-12 18:01:32 +00001717 next++;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001718 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001719 SKIP_WS(next);
1720
1721 // Read the next integer in the set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001722 scan = next;
Jonathan Peyton30419822017-05-12 18:01:32 +00001723 if ((*next < '0') || (*next > '9')) {
1724 KMP_WARNING(AffSyntaxError, var);
1725 return FALSE;
1726 }
1727
1728 SKIP_DIGITS(next);
1729 num = __kmp_str_to_int(scan, *next);
1730 KMP_ASSERT(num >= 0);
1731 }
1732 empty = FALSE;
1733
1734 SKIP_WS(next);
1735 if (*next == ',') {
1736 next++;
1737 }
1738 scan = next;
1739 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001740 }
1741
Jonathan Peyton30419822017-05-12 18:01:32 +00001742 // Next character is not an integer => end of list
1743 if ((*next < '0') || (*next > '9')) {
1744 if (empty) {
1745 KMP_WARNING(AffSyntaxError, var);
1746 return FALSE;
1747 }
1748 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001749 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001750
1751 // Read the first integer.
1752 SKIP_DIGITS(next);
1753 start = __kmp_str_to_int(scan, *next);
1754 KMP_ASSERT(start >= 0);
1755 SKIP_WS(next);
1756
1757 // If this isn't a range, then go on.
1758 if (*next != '-') {
1759 empty = FALSE;
1760
1761 // Skip optional comma.
1762 if (*next == ',') {
1763 next++;
1764 }
1765 scan = next;
1766 continue;
1767 }
1768
1769 // This is a range. Skip over the '-' and read in the 2nd int.
1770 next++; // skip '-'
1771 SKIP_WS(next);
1772 scan = next;
1773 if ((*next < '0') || (*next > '9')) {
1774 KMP_WARNING(AffSyntaxError, var);
1775 return FALSE;
1776 }
1777 SKIP_DIGITS(next);
1778 end = __kmp_str_to_int(scan, *next);
1779 KMP_ASSERT(end >= 0);
1780
1781 // Check for a stride parameter
1782 stride = 1;
1783 SKIP_WS(next);
1784 if (*next == ':') {
1785 // A stride is specified. Skip over the ':" and read the 3rd int.
1786 int sign = +1;
1787 next++; // skip ':'
1788 SKIP_WS(next);
1789 scan = next;
1790 if (*next == '-') {
1791 sign = -1;
1792 next++;
1793 SKIP_WS(next);
1794 scan = next;
1795 }
1796 if ((*next < '0') || (*next > '9')) {
1797 KMP_WARNING(AffSyntaxError, var);
1798 return FALSE;
1799 }
1800 SKIP_DIGITS(next);
1801 stride = __kmp_str_to_int(scan, *next);
1802 KMP_ASSERT(stride >= 0);
1803 stride *= sign;
1804 }
1805
1806 // Do some range checks.
1807 if (stride == 0) {
1808 KMP_WARNING(AffZeroStride, var);
1809 return FALSE;
1810 }
1811 if (stride > 0) {
1812 if (start > end) {
1813 KMP_WARNING(AffStartGreaterEnd, var, start, end);
1814 return FALSE;
1815 }
1816 } else {
1817 if (start < end) {
1818 KMP_WARNING(AffStrideLessZero, var, start, end);
1819 return FALSE;
1820 }
1821 }
1822 if ((end - start) / stride > 65536) {
1823 KMP_WARNING(AffRangeTooBig, var, end, start, stride);
1824 return FALSE;
1825 }
1826
1827 empty = FALSE;
1828
1829 // Skip optional comma.
1830 SKIP_WS(next);
1831 if (*next == ',') {
1832 next++;
1833 }
1834 scan = next;
1835 }
1836
1837 *nextEnv = next;
1838
1839 {
1840 int len = next - env;
1841 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
1842 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
1843 retlist[len] = '\0';
1844 *proclist = retlist;
1845 }
1846 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001847}
1848
Jim Cownie5e8470a2013-09-27 10:38:44 +00001849// If KMP_AFFINITY is specified without a type, then
1850// __kmp_affinity_notype should point to its setting.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001851static kmp_setting_t *__kmp_affinity_notype = NULL;
1852
Jonathan Peyton30419822017-05-12 18:01:32 +00001853static void __kmp_parse_affinity_env(char const *name, char const *value,
1854 enum affinity_type *out_type,
1855 char **out_proclist, int *out_verbose,
1856 int *out_warn, int *out_respect,
1857 enum affinity_gran *out_gran,
1858 int *out_gran_levels, int *out_dups,
1859 int *out_compact, int *out_offset) {
1860 char *buffer = NULL; // Copy of env var value.
1861 char *buf = NULL; // Buffer for strtok_r() function.
1862 char *next = NULL; // end of token / start of next.
1863 const char *start; // start of current token (for err msgs)
1864 int count = 0; // Counter of parsed integer numbers.
1865 int number[2]; // Parsed numbers.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001866
Jonathan Peyton30419822017-05-12 18:01:32 +00001867 // Guards.
1868 int type = 0;
1869 int proclist = 0;
1870 int max_proclist = 0;
1871 int verbose = 0;
1872 int warnings = 0;
1873 int respect = 0;
1874 int gran = 0;
1875 int dups = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001876
Jonathan Peyton30419822017-05-12 18:01:32 +00001877 KMP_ASSERT(value != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001878
Jonathan Peyton30419822017-05-12 18:01:32 +00001879 if (TCR_4(__kmp_init_middle)) {
1880 KMP_WARNING(EnvMiddleWarn, name);
1881 __kmp_env_toPrint(name, 0);
1882 return;
1883 }
1884 __kmp_env_toPrint(name, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001885
Jonathan Peyton30419822017-05-12 18:01:32 +00001886 buffer =
1887 __kmp_str_format("%s", value); // Copy env var to keep original intact.
1888 buf = buffer;
1889 SKIP_WS(buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001890
Jonathan Peyton30419822017-05-12 18:01:32 +00001891// Helper macros.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001892
Jonathan Peyton30419822017-05-12 18:01:32 +00001893// If we see a parse error, emit a warning and scan to the next ",".
1894//
1895// FIXME - there's got to be a better way to print an error
1896// message, hopefully without overwritting peices of buf.
1897#define EMIT_WARN(skip, errlist) \
1898 { \
1899 char ch; \
1900 if (skip) { \
1901 SKIP_TO(next, ','); \
1902 } \
1903 ch = *next; \
1904 *next = '\0'; \
1905 KMP_WARNING errlist; \
1906 *next = ch; \
1907 if (skip) { \
1908 if (ch == ',') \
1909 next++; \
1910 } \
1911 buf = next; \
1912 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001913
Jonathan Peyton30419822017-05-12 18:01:32 +00001914#define _set_param(_guard, _var, _val) \
1915 { \
1916 if (_guard == 0) { \
1917 _var = _val; \
1918 } else { \
1919 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
1920 }; \
1921 ++_guard; \
1922 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001923
Jonathan Peyton30419822017-05-12 18:01:32 +00001924#define set_type(val) _set_param(type, *out_type, val)
1925#define set_verbose(val) _set_param(verbose, *out_verbose, val)
1926#define set_warnings(val) _set_param(warnings, *out_warn, val)
1927#define set_respect(val) _set_param(respect, *out_respect, val)
1928#define set_dups(val) _set_param(dups, *out_dups, val)
1929#define set_proclist(val) _set_param(proclist, *out_proclist, val)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001930
Jonathan Peyton30419822017-05-12 18:01:32 +00001931#define set_gran(val, levels) \
1932 { \
1933 if (gran == 0) { \
1934 *out_gran = val; \
1935 *out_gran_levels = levels; \
1936 } else { \
1937 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
1938 }; \
1939 ++gran; \
1940 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001941
Jonathan Peyton30419822017-05-12 18:01:32 +00001942#if OMP_40_ENABLED
1943 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
1944 (__kmp_nested_proc_bind.used > 0));
Andrey Churbanov613edeb2015-02-20 18:14:43 +00001945#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00001946
1947 while (*buf != '\0') {
1948 start = next = buf;
1949
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001950 if (__kmp_match_str("none", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001951 set_type(affinity_none);
1952#if OMP_40_ENABLED
1953 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
1954#endif
1955 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001956 } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001957 set_type(affinity_scatter);
1958#if OMP_40_ENABLED
1959 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1960#endif
1961 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001962 } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001963 set_type(affinity_compact);
1964#if OMP_40_ENABLED
1965 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1966#endif
1967 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001968 } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001969 set_type(affinity_logical);
1970#if OMP_40_ENABLED
1971 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1972#endif
1973 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001974 } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001975 set_type(affinity_physical);
1976#if OMP_40_ENABLED
1977 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1978#endif
1979 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001980 } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001981 set_type(affinity_explicit);
1982#if OMP_40_ENABLED
1983 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1984#endif
1985 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001986 } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001987 set_type(affinity_balanced);
1988#if OMP_40_ENABLED
1989 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1990#endif
1991 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001992 } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001993 set_type(affinity_disabled);
1994#if OMP_40_ENABLED
1995 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
1996#endif
1997 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001998 } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001999 set_verbose(TRUE);
2000 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002001 } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002002 set_verbose(FALSE);
2003 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002004 } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002005 set_warnings(TRUE);
2006 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002007 } else if (__kmp_match_str("nowarnings", buf,
2008 CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002009 set_warnings(FALSE);
2010 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002011 } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002012 set_respect(TRUE);
2013 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002014 } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002015 set_respect(FALSE);
2016 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002017 } else if (__kmp_match_str("duplicates", buf,
2018 CCAST(const char **, &next)) ||
2019 __kmp_match_str("dups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002020 set_dups(TRUE);
2021 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002022 } else if (__kmp_match_str("noduplicates", buf,
2023 CCAST(const char **, &next)) ||
2024 __kmp_match_str("nodups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002025 set_dups(FALSE);
2026 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002027 } else if (__kmp_match_str("granularity", buf,
2028 CCAST(const char **, &next)) ||
2029 __kmp_match_str("gran", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002030 SKIP_WS(next);
2031 if (*next != '=') {
2032 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2033 continue;
2034 }
2035 next++; // skip '='
2036 SKIP_WS(next);
2037
2038 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002039 if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002040 set_gran(affinity_gran_fine, -1);
2041 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002042 } else if (__kmp_match_str("thread", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002043 set_gran(affinity_gran_thread, -1);
2044 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002045 } else if (__kmp_match_str("core", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002046 set_gran(affinity_gran_core, -1);
2047 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002048 } else if (__kmp_match_str("package", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002049 set_gran(affinity_gran_package, -1);
2050 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002051 } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002052 set_gran(affinity_gran_node, -1);
2053 buf = next;
2054#if KMP_GROUP_AFFINITY
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002055 } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002056 set_gran(affinity_gran_group, -1);
2057 buf = next;
2058#endif /* KMP_GROUP AFFINITY */
2059 } else if ((*buf >= '0') && (*buf <= '9')) {
2060 int n;
2061 next = buf;
2062 SKIP_DIGITS(next);
2063 n = __kmp_str_to_int(buf, *next);
2064 KMP_ASSERT(n >= 0);
2065 buf = next;
2066 set_gran(affinity_gran_default, n);
2067 } else {
2068 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2069 continue;
2070 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002071 } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002072 char *temp_proclist;
2073
2074 SKIP_WS(next);
2075 if (*next != '=') {
2076 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2077 continue;
2078 }
2079 next++; // skip '='
2080 SKIP_WS(next);
2081 if (*next != '[') {
2082 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2083 continue;
2084 }
2085 next++; // skip '['
2086 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002087 if (!__kmp_parse_affinity_proc_id_list(
2088 name, buf, CCAST(const char **, &next), &temp_proclist)) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002089 // warning already emitted.
2090 SKIP_TO(next, ']');
2091 if (*next == ']')
2092 next++;
2093 SKIP_TO(next, ',');
2094 if (*next == ',')
2095 next++;
2096 buf = next;
2097 continue;
2098 }
2099 if (*next != ']') {
2100 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2101 continue;
2102 }
2103 next++; // skip ']'
2104 set_proclist(temp_proclist);
2105 } else if ((*buf >= '0') && (*buf <= '9')) {
2106 // Parse integer numbers -- permute and offset.
2107 int n;
2108 next = buf;
2109 SKIP_DIGITS(next);
2110 n = __kmp_str_to_int(buf, *next);
2111 KMP_ASSERT(n >= 0);
2112 buf = next;
2113 if (count < 2) {
2114 number[count] = n;
2115 } else {
2116 KMP_WARNING(AffManyParams, name, start);
2117 }; // if
2118 ++count;
2119 } else {
2120 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2121 continue;
2122 }
2123
2124 SKIP_WS(next);
2125 if (*next == ',') {
2126 next++;
2127 SKIP_WS(next);
2128 } else if (*next != '\0') {
2129 const char *temp = next;
2130 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2131 continue;
2132 }
2133 buf = next;
2134 } // while
2135
2136#undef EMIT_WARN
2137#undef _set_param
2138#undef set_type
2139#undef set_verbose
2140#undef set_warnings
2141#undef set_respect
2142#undef set_granularity
2143
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002144 __kmp_str_free(CCAST(const char **, &buffer));
Jonathan Peyton30419822017-05-12 18:01:32 +00002145
2146 if (proclist) {
2147 if (!type) {
2148 KMP_WARNING(AffProcListNoType, name);
2149 *out_type = affinity_explicit;
2150#if OMP_40_ENABLED
2151 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2152#endif
2153 } else if (*out_type != affinity_explicit) {
2154 KMP_WARNING(AffProcListNotExplicit, name);
2155 KMP_ASSERT(*out_proclist != NULL);
2156 KMP_INTERNAL_FREE(*out_proclist);
2157 *out_proclist = NULL;
2158 }
2159 }
2160 switch (*out_type) {
2161 case affinity_logical:
2162 case affinity_physical: {
2163 if (count > 0) {
2164 *out_offset = number[0];
2165 }; // if
2166 if (count > 1) {
2167 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
2168 }; // if
2169 } break;
2170 case affinity_balanced: {
2171 if (count > 0) {
2172 *out_compact = number[0];
2173 }; // if
2174 if (count > 1) {
2175 *out_offset = number[1];
2176 }; // if
2177
2178 if (__kmp_affinity_gran == affinity_gran_default) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002179#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002180 if (__kmp_mic_type != non_mic) {
2181 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2182 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine");
2183 }
2184 __kmp_affinity_gran = affinity_gran_fine;
2185 } else
2186#endif
2187 {
2188 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2189 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core");
2190 }
2191 __kmp_affinity_gran = affinity_gran_core;
2192 }
2193 }
2194 } break;
2195 case affinity_scatter:
2196 case affinity_compact: {
2197 if (count > 0) {
2198 *out_compact = number[0];
2199 }; // if
2200 if (count > 1) {
2201 *out_offset = number[1];
2202 }; // if
2203 } break;
2204 case affinity_explicit: {
2205 if (*out_proclist == NULL) {
2206 KMP_WARNING(AffNoProcList, name);
2207 __kmp_affinity_type = affinity_none;
2208 }
2209 if (count > 0) {
2210 KMP_WARNING(AffNoParam, name, "explicit");
2211 }
2212 } break;
2213 case affinity_none: {
2214 if (count > 0) {
2215 KMP_WARNING(AffNoParam, name, "none");
2216 }; // if
2217 } break;
2218 case affinity_disabled: {
2219 if (count > 0) {
2220 KMP_WARNING(AffNoParam, name, "disabled");
2221 }; // if
2222 } break;
2223 case affinity_default: {
2224 if (count > 0) {
2225 KMP_WARNING(AffNoParam, name, "default");
2226 }; // if
2227 } break;
2228 default: { KMP_ASSERT(0); };
2229 }; // switch
Jim Cownie5e8470a2013-09-27 10:38:44 +00002230} // __kmp_parse_affinity_env
2231
Jonathan Peyton30419822017-05-12 18:01:32 +00002232static void __kmp_stg_parse_affinity(char const *name, char const *value,
2233 void *data) {
2234 kmp_setting_t **rivals = (kmp_setting_t **)data;
2235 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002236
Jonathan Peyton30419822017-05-12 18:01:32 +00002237 rc = __kmp_stg_check_rivals(name, value, rivals);
2238 if (rc) {
2239 return;
2240 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002241
Jonathan Peyton30419822017-05-12 18:01:32 +00002242 __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2243 &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2244 &__kmp_affinity_warnings,
2245 &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2246 &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2247 &__kmp_affinity_compact, &__kmp_affinity_offset);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002248
2249} // __kmp_stg_parse_affinity
2250
Jonathan Peyton30419822017-05-12 18:01:32 +00002251static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
2252 void *data) {
2253 if (__kmp_env_format) {
2254 KMP_STR_BUF_PRINT_NAME_EX(name);
2255 } else {
2256 __kmp_str_buf_print(buffer, " %s='", name);
2257 }
2258 if (__kmp_affinity_verbose) {
2259 __kmp_str_buf_print(buffer, "%s,", "verbose");
2260 } else {
2261 __kmp_str_buf_print(buffer, "%s,", "noverbose");
2262 }
2263 if (__kmp_affinity_warnings) {
2264 __kmp_str_buf_print(buffer, "%s,", "warnings");
2265 } else {
2266 __kmp_str_buf_print(buffer, "%s,", "nowarnings");
2267 }
2268 if (KMP_AFFINITY_CAPABLE()) {
2269 if (__kmp_affinity_respect_mask) {
2270 __kmp_str_buf_print(buffer, "%s,", "respect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002271 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002272 __kmp_str_buf_print(buffer, "%s,", "norespect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002273 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002274 switch (__kmp_affinity_gran) {
2275 case affinity_gran_default:
2276 __kmp_str_buf_print(buffer, "%s", "granularity=default,");
2277 break;
2278 case affinity_gran_fine:
2279 __kmp_str_buf_print(buffer, "%s", "granularity=fine,");
2280 break;
2281 case affinity_gran_thread:
2282 __kmp_str_buf_print(buffer, "%s", "granularity=thread,");
2283 break;
2284 case affinity_gran_core:
2285 __kmp_str_buf_print(buffer, "%s", "granularity=core,");
2286 break;
2287 case affinity_gran_package:
2288 __kmp_str_buf_print(buffer, "%s", "granularity=package,");
2289 break;
2290 case affinity_gran_node:
2291 __kmp_str_buf_print(buffer, "%s", "granularity=node,");
2292 break;
2293#if KMP_GROUP_AFFINITY
2294 case affinity_gran_group:
2295 __kmp_str_buf_print(buffer, "%s", "granularity=group,");
2296 break;
2297#endif /* KMP_GROUP_AFFINITY */
2298 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002299 }
2300 if (!KMP_AFFINITY_CAPABLE()) {
2301 __kmp_str_buf_print(buffer, "%s", "disabled");
2302 } else
2303 switch (__kmp_affinity_type) {
2304 case affinity_none:
2305 __kmp_str_buf_print(buffer, "%s", "none");
2306 break;
2307 case affinity_physical:
2308 __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset);
2309 break;
2310 case affinity_logical:
2311 __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset);
2312 break;
2313 case affinity_compact:
2314 __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact,
2315 __kmp_affinity_offset);
2316 break;
2317 case affinity_scatter:
2318 __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact,
2319 __kmp_affinity_offset);
2320 break;
2321 case affinity_explicit:
2322 __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist",
2323 __kmp_affinity_proclist, "explicit");
2324 break;
2325 case affinity_balanced:
2326 __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced",
2327 __kmp_affinity_compact, __kmp_affinity_offset);
2328 break;
2329 case affinity_disabled:
2330 __kmp_str_buf_print(buffer, "%s", "disabled");
2331 break;
2332 case affinity_default:
2333 __kmp_str_buf_print(buffer, "%s", "default");
2334 break;
2335 default:
2336 __kmp_str_buf_print(buffer, "%s", "<unknown>");
2337 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002338 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002339 __kmp_str_buf_print(buffer, "'\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002340} //__kmp_stg_print_affinity
2341
Jonathan Peyton30419822017-05-12 18:01:32 +00002342#ifdef KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00002343
Jonathan Peyton30419822017-05-12 18:01:32 +00002344static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
2345 char const *value, void *data) {
2346 const char *next = NULL;
2347 char *temp_proclist;
2348 kmp_setting_t **rivals = (kmp_setting_t **)data;
2349 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002350
Jonathan Peyton30419822017-05-12 18:01:32 +00002351 rc = __kmp_stg_check_rivals(name, value, rivals);
2352 if (rc) {
2353 return;
2354 }
2355
2356 if (TCR_4(__kmp_init_middle)) {
2357 KMP_WARNING(EnvMiddleWarn, name);
2358 __kmp_env_toPrint(name, 0);
2359 return;
2360 }
2361
2362 __kmp_env_toPrint(name, 1);
2363
2364 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2365 SKIP_WS(next);
2366 if (*next == '\0') {
2367 // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2368 __kmp_affinity_proclist = temp_proclist;
2369 __kmp_affinity_type = affinity_explicit;
2370 __kmp_affinity_gran = affinity_gran_fine;
2371#if OMP_40_ENABLED
2372 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2373#endif
2374 } else {
2375 KMP_WARNING(AffSyntaxError, name);
2376 if (temp_proclist != NULL) {
2377 KMP_INTERNAL_FREE((void *)temp_proclist);
2378 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002379 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002380 } else {
2381 // Warning already emitted
2382 __kmp_affinity_type = affinity_none;
2383#if OMP_40_ENABLED
2384 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2385#endif
2386 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002387} // __kmp_stg_parse_gomp_cpu_affinity
2388
Jonathan Peyton30419822017-05-12 18:01:32 +00002389#endif /* KMP_GOMP_COMPAT */
Jim Cownie5e8470a2013-09-27 10:38:44 +00002390
Jonathan Peyton30419822017-05-12 18:01:32 +00002391#if OMP_40_ENABLED
Jim Cownie5e8470a2013-09-27 10:38:44 +00002392
2393/*-----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00002394The OMP_PLACES proc id list parser. Here is the grammar:
2395
2396place_list := place
2397place_list := place , place_list
2398place := num
2399place := place : num
2400place := place : num : signed
2401place := { subplacelist }
2402place := ! place // (lowest priority)
2403subplace_list := subplace
2404subplace_list := subplace , subplace_list
2405subplace := num
2406subplace := num : num
2407subplace := num : num : signed
2408signed := num
2409signed := + signed
2410signed := - signed
Jim Cownie5e8470a2013-09-27 10:38:44 +00002411-----------------------------------------------------------------------------*/
2412
Jonathan Peyton30419822017-05-12 18:01:32 +00002413static int __kmp_parse_subplace_list(const char *var, const char **scan) {
2414 const char *next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002415
Jonathan Peyton30419822017-05-12 18:01:32 +00002416 for (;;) {
2417 int start, count, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002418
2419 //
Jonathan Peyton30419822017-05-12 18:01:32 +00002420 // Read in the starting proc id
Jim Cownie5e8470a2013-09-27 10:38:44 +00002421 //
2422 SKIP_WS(*scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002423 if ((**scan < '0') || (**scan > '9')) {
2424 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2425 return FALSE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002426 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002427 next = *scan;
2428 SKIP_DIGITS(next);
2429 start = __kmp_str_to_int(*scan, *next);
2430 KMP_ASSERT(start >= 0);
2431 *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002432
Jonathan Peyton30419822017-05-12 18:01:32 +00002433 // valid follow sets are ',' ':' and '}'
2434 SKIP_WS(*scan);
2435 if (**scan == '}') {
2436 break;
2437 }
2438 if (**scan == ',') {
2439 (*scan)++; // skip ','
2440 continue;
2441 }
2442 if (**scan != ':') {
2443 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2444 return FALSE;
2445 }
2446 (*scan)++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002447
Jonathan Peyton30419822017-05-12 18:01:32 +00002448 // Read count parameter
2449 SKIP_WS(*scan);
2450 if ((**scan < '0') || (**scan > '9')) {
2451 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2452 return FALSE;
2453 }
2454 next = *scan;
2455 SKIP_DIGITS(next);
2456 count = __kmp_str_to_int(*scan, *next);
2457 KMP_ASSERT(count >= 0);
2458 *scan = next;
2459
2460 // valid follow sets are ',' ':' and '}'
2461 SKIP_WS(*scan);
2462 if (**scan == '}') {
2463 break;
2464 }
2465 if (**scan == ',') {
2466 (*scan)++; // skip ','
2467 continue;
2468 }
2469 if (**scan != ':') {
2470 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2471 return FALSE;
2472 }
2473 (*scan)++; // skip ':'
2474
2475 // Read stride parameter
2476 int sign = +1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002477 for (;;) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002478 SKIP_WS(*scan);
2479 if (**scan == '+') {
2480 (*scan)++; // skip '+'
2481 continue;
2482 }
2483 if (**scan == '-') {
2484 sign *= -1;
2485 (*scan)++; // skip '-'
2486 continue;
2487 }
2488 break;
2489 }
2490 SKIP_WS(*scan);
2491 if ((**scan < '0') || (**scan > '9')) {
2492 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2493 return FALSE;
2494 }
2495 next = *scan;
2496 SKIP_DIGITS(next);
2497 stride = __kmp_str_to_int(*scan, *next);
2498 KMP_ASSERT(stride >= 0);
2499 *scan = next;
2500 stride *= sign;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002501
Jonathan Peyton30419822017-05-12 18:01:32 +00002502 // valid follow sets are ',' and '}'
2503 SKIP_WS(*scan);
2504 if (**scan == '}') {
2505 break;
2506 }
2507 if (**scan == ',') {
2508 (*scan)++; // skip ','
2509 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002510 }
2511
Jonathan Peyton30419822017-05-12 18:01:32 +00002512 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2513 return FALSE;
2514 }
2515 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002516}
2517
Jonathan Peyton30419822017-05-12 18:01:32 +00002518static int __kmp_parse_place(const char *var, const char **scan) {
2519 const char *next;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002520
Jonathan Peyton30419822017-05-12 18:01:32 +00002521 // valid follow sets are '{' '!' and num
2522 SKIP_WS(*scan);
2523 if (**scan == '{') {
2524 (*scan)++; // skip '{'
2525 if (!__kmp_parse_subplace_list(var, scan)) {
2526 return FALSE;
2527 }
2528 if (**scan != '}') {
2529 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2530 return FALSE;
2531 }
2532 (*scan)++; // skip '}'
2533 } else if (**scan == '!') {
2534 (*scan)++; // skip '!'
2535 return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2536 } else if ((**scan >= '0') && (**scan <= '9')) {
2537 next = *scan;
2538 SKIP_DIGITS(next);
2539 int proc = __kmp_str_to_int(*scan, *next);
2540 KMP_ASSERT(proc >= 0);
2541 *scan = next;
2542 } else {
2543 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2544 return FALSE;
2545 }
2546 return TRUE;
2547}
2548
2549static int __kmp_parse_place_list(const char *var, const char *env,
2550 char **place_list) {
2551 const char *scan = env;
2552 const char *next = scan;
2553
2554 for (;;) {
2555 int start, count, stride;
2556
2557 if (!__kmp_parse_place(var, &scan)) {
2558 return FALSE;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002559 }
2560
Jonathan Peyton30419822017-05-12 18:01:32 +00002561 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002562 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002563 if (*scan == '\0') {
2564 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002565 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002566 if (*scan == ',') {
2567 scan++; // skip ','
2568 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002569 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002570 if (*scan != ':') {
2571 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2572 return FALSE;
2573 }
2574 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002575
Jonathan Peyton30419822017-05-12 18:01:32 +00002576 // Read count parameter
Jim Cownie5e8470a2013-09-27 10:38:44 +00002577 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002578 if ((*scan < '0') || (*scan > '9')) {
2579 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2580 return FALSE;
2581 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002582 next = scan;
2583 SKIP_DIGITS(next);
2584 count = __kmp_str_to_int(scan, *next);
2585 KMP_ASSERT(count >= 0);
2586 scan = next;
2587
Jonathan Peyton30419822017-05-12 18:01:32 +00002588 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002589 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002590 if (*scan == '\0') {
2591 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002592 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002593 if (*scan == ',') {
2594 scan++; // skip ','
2595 continue;
2596 }
2597 if (*scan != ':') {
2598 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2599 return FALSE;
2600 }
2601 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002602
Jonathan Peyton30419822017-05-12 18:01:32 +00002603 // Read stride parameter
2604 int sign = +1;
2605 for (;;) {
2606 SKIP_WS(scan);
2607 if (*scan == '+') {
2608 scan++; // skip '+'
2609 continue;
2610 }
2611 if (*scan == '-') {
2612 sign *= -1;
2613 scan++; // skip '-'
2614 continue;
2615 }
2616 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002617 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002618 SKIP_WS(scan);
2619 if ((*scan < '0') || (*scan > '9')) {
2620 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2621 return FALSE;
2622 }
2623 next = scan;
2624 SKIP_DIGITS(next);
2625 stride = __kmp_str_to_int(scan, *next);
2626 KMP_ASSERT(stride >= 0);
2627 scan = next;
2628 stride *= sign;
2629
2630 // valid follow sets are ',' and EOL
2631 SKIP_WS(scan);
2632 if (*scan == '\0') {
2633 break;
2634 }
2635 if (*scan == ',') {
2636 scan++; // skip ','
2637 continue;
2638 }
2639
2640 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2641 return FALSE;
2642 }
2643
2644 {
2645 int len = scan - env;
2646 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
2647 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
2648 retlist[len] = '\0';
2649 *place_list = retlist;
2650 }
2651 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002652}
2653
Jonathan Peyton30419822017-05-12 18:01:32 +00002654static void __kmp_stg_parse_places(char const *name, char const *value,
2655 void *data) {
2656 int count;
2657 const char *scan = value;
2658 const char *next = scan;
2659 const char *kind = "\"threads\"";
2660 kmp_setting_t **rivals = (kmp_setting_t **)data;
2661 int rc;
2662
2663 rc = __kmp_stg_check_rivals(name, value, rivals);
2664 if (rc) {
2665 return;
2666 }
2667
2668 // If OMP_PROC_BIND is not specified but OMP_PLACES is,
2669 // then let OMP_PROC_BIND default to true.
2670 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2671 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2672 }
2673
2674 //__kmp_affinity_num_places = 0;
2675
2676 if (__kmp_match_str("threads", scan, &next)) {
2677 scan = next;
2678 __kmp_affinity_type = affinity_compact;
2679 __kmp_affinity_gran = affinity_gran_thread;
2680 __kmp_affinity_dups = FALSE;
2681 kind = "\"threads\"";
2682 } else if (__kmp_match_str("cores", scan, &next)) {
2683 scan = next;
2684 __kmp_affinity_type = affinity_compact;
2685 __kmp_affinity_gran = affinity_gran_core;
2686 __kmp_affinity_dups = FALSE;
2687 kind = "\"cores\"";
2688 } else if (__kmp_match_str("sockets", scan, &next)) {
2689 scan = next;
2690 __kmp_affinity_type = affinity_compact;
2691 __kmp_affinity_gran = affinity_gran_package;
2692 __kmp_affinity_dups = FALSE;
2693 kind = "\"sockets\"";
2694 } else {
2695 if (__kmp_affinity_proclist != NULL) {
2696 KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist);
2697 __kmp_affinity_proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002698 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002699 if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2700 __kmp_affinity_type = affinity_explicit;
2701 __kmp_affinity_gran = affinity_gran_fine;
2702 __kmp_affinity_dups = FALSE;
2703 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002704 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
Jonathan Peyton30419822017-05-12 18:01:32 +00002705 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002706 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002707 return;
2708 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002709
Jonathan Peyton30419822017-05-12 18:01:32 +00002710 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2711 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2712 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002713
Jonathan Peyton30419822017-05-12 18:01:32 +00002714 SKIP_WS(scan);
2715 if (*scan == '\0') {
2716 return;
2717 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002718
Jonathan Peyton30419822017-05-12 18:01:32 +00002719 // Parse option count parameter in parentheses
2720 if (*scan != '(') {
2721 KMP_WARNING(SyntaxErrorUsing, name, kind);
2722 return;
2723 }
2724 scan++; // skip '('
Jim Cownie5e8470a2013-09-27 10:38:44 +00002725
Jonathan Peyton30419822017-05-12 18:01:32 +00002726 SKIP_WS(scan);
2727 next = scan;
2728 SKIP_DIGITS(next);
2729 count = __kmp_str_to_int(scan, *next);
2730 KMP_ASSERT(count >= 0);
2731 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002732
Jonathan Peyton30419822017-05-12 18:01:32 +00002733 SKIP_WS(scan);
2734 if (*scan != ')') {
2735 KMP_WARNING(SyntaxErrorUsing, name, kind);
2736 return;
2737 }
2738 scan++; // skip ')'
2739
2740 SKIP_WS(scan);
2741 if (*scan != '\0') {
2742 KMP_WARNING(ParseExtraCharsWarn, name, scan);
2743 }
2744 __kmp_affinity_num_places = count;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002745}
2746
Jonathan Peyton30419822017-05-12 18:01:32 +00002747static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
2748 void *data) {
2749 if (__kmp_env_format) {
2750 KMP_STR_BUF_PRINT_NAME;
2751 } else {
2752 __kmp_str_buf_print(buffer, " %s", name);
2753 }
2754 if ((__kmp_nested_proc_bind.used == 0) ||
2755 (__kmp_nested_proc_bind.bind_types == NULL) ||
2756 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
2757 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2758 } else if (__kmp_affinity_type == affinity_explicit) {
2759 if (__kmp_affinity_proclist != NULL) {
2760 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002761 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002762 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002763 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002764 } else if (__kmp_affinity_type == affinity_compact) {
2765 int num;
2766 if (__kmp_affinity_num_masks > 0) {
2767 num = __kmp_affinity_num_masks;
2768 } else if (__kmp_affinity_num_places > 0) {
2769 num = __kmp_affinity_num_places;
2770 } else {
2771 num = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002772 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002773 if (__kmp_affinity_gran == affinity_gran_thread) {
2774 if (num > 0) {
2775 __kmp_str_buf_print(buffer, "='threads(%d)'\n", num);
2776 } else {
2777 __kmp_str_buf_print(buffer, "='threads'\n");
2778 }
2779 } else if (__kmp_affinity_gran == affinity_gran_core) {
2780 if (num > 0) {
2781 __kmp_str_buf_print(buffer, "='cores(%d)' \n", num);
2782 } else {
2783 __kmp_str_buf_print(buffer, "='cores'\n");
2784 }
2785 } else if (__kmp_affinity_gran == affinity_gran_package) {
2786 if (num > 0) {
2787 __kmp_str_buf_print(buffer, "='sockets(%d)'\n", num);
2788 } else {
2789 __kmp_str_buf_print(buffer, "='sockets'\n");
2790 }
2791 } else {
2792 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002793 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002794 } else {
2795 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2796 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002797}
2798
2799#endif /* OMP_40_ENABLED */
2800
Jonathan Peyton30419822017-05-12 18:01:32 +00002801#if (!OMP_40_ENABLED)
Jim Cownie5e8470a2013-09-27 10:38:44 +00002802
Jonathan Peyton30419822017-05-12 18:01:32 +00002803static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
2804 void *data) {
2805 int enabled;
2806 kmp_setting_t **rivals = (kmp_setting_t **)data;
2807 int rc;
2808
2809 rc = __kmp_stg_check_rivals(name, value, rivals);
2810 if (rc) {
2811 return;
2812 }
2813
2814 // In OMP 3.1, OMP_PROC_BIND is strictly a boolean
2815 __kmp_stg_parse_bool(name, value, &enabled);
2816 if (enabled) {
2817 // OMP_PROC_BIND => granularity=fine,scatter on MIC
2818 // OMP_PROC_BIND => granularity=core,scatter elsewhere
2819 __kmp_affinity_type = affinity_scatter;
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002820#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002821 if (__kmp_mic_type != non_mic)
2822 __kmp_affinity_gran = affinity_gran_fine;
2823 else
2824#endif
2825 __kmp_affinity_gran = affinity_gran_core;
2826 } else {
2827 __kmp_affinity_type = affinity_none;
2828 }
2829} // __kmp_parse_proc_bind
2830
2831#endif /* if (! OMP_40_ENABLED) */
2832
2833static void __kmp_stg_parse_topology_method(char const *name, char const *value,
2834 void *data) {
2835 if (__kmp_str_match("all", 1, value)) {
2836 __kmp_affinity_top_method = affinity_top_method_all;
2837 }
2838#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2839 else if (__kmp_str_match("x2apic id", 9, value) ||
2840 __kmp_str_match("x2apic_id", 9, value) ||
2841 __kmp_str_match("x2apic-id", 9, value) ||
2842 __kmp_str_match("x2apicid", 8, value) ||
2843 __kmp_str_match("cpuid leaf 11", 13, value) ||
2844 __kmp_str_match("cpuid_leaf_11", 13, value) ||
2845 __kmp_str_match("cpuid-leaf-11", 13, value) ||
2846 __kmp_str_match("cpuid leaf11", 12, value) ||
2847 __kmp_str_match("cpuid_leaf11", 12, value) ||
2848 __kmp_str_match("cpuid-leaf11", 12, value) ||
2849 __kmp_str_match("cpuidleaf 11", 12, value) ||
2850 __kmp_str_match("cpuidleaf_11", 12, value) ||
2851 __kmp_str_match("cpuidleaf-11", 12, value) ||
2852 __kmp_str_match("cpuidleaf11", 11, value) ||
2853 __kmp_str_match("cpuid 11", 8, value) ||
2854 __kmp_str_match("cpuid_11", 8, value) ||
2855 __kmp_str_match("cpuid-11", 8, value) ||
2856 __kmp_str_match("cpuid11", 7, value) ||
2857 __kmp_str_match("leaf 11", 7, value) ||
2858 __kmp_str_match("leaf_11", 7, value) ||
2859 __kmp_str_match("leaf-11", 7, value) ||
2860 __kmp_str_match("leaf11", 6, value)) {
2861 __kmp_affinity_top_method = affinity_top_method_x2apicid;
2862 } else if (__kmp_str_match("apic id", 7, value) ||
2863 __kmp_str_match("apic_id", 7, value) ||
2864 __kmp_str_match("apic-id", 7, value) ||
2865 __kmp_str_match("apicid", 6, value) ||
2866 __kmp_str_match("cpuid leaf 4", 12, value) ||
2867 __kmp_str_match("cpuid_leaf_4", 12, value) ||
2868 __kmp_str_match("cpuid-leaf-4", 12, value) ||
2869 __kmp_str_match("cpuid leaf4", 11, value) ||
2870 __kmp_str_match("cpuid_leaf4", 11, value) ||
2871 __kmp_str_match("cpuid-leaf4", 11, value) ||
2872 __kmp_str_match("cpuidleaf 4", 11, value) ||
2873 __kmp_str_match("cpuidleaf_4", 11, value) ||
2874 __kmp_str_match("cpuidleaf-4", 11, value) ||
2875 __kmp_str_match("cpuidleaf4", 10, value) ||
2876 __kmp_str_match("cpuid 4", 7, value) ||
2877 __kmp_str_match("cpuid_4", 7, value) ||
2878 __kmp_str_match("cpuid-4", 7, value) ||
2879 __kmp_str_match("cpuid4", 6, value) ||
2880 __kmp_str_match("leaf 4", 6, value) ||
2881 __kmp_str_match("leaf_4", 6, value) ||
2882 __kmp_str_match("leaf-4", 6, value) ||
2883 __kmp_str_match("leaf4", 5, value)) {
2884 __kmp_affinity_top_method = affinity_top_method_apicid;
2885 }
2886#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2887 else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
2888 __kmp_str_match("cpuinfo", 5, value)) {
2889 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
2890 }
2891#if KMP_GROUP_AFFINITY
2892 else if (__kmp_str_match("group", 1, value)) {
2893 __kmp_affinity_top_method = affinity_top_method_group;
2894 }
2895#endif /* KMP_GROUP_AFFINITY */
2896 else if (__kmp_str_match("flat", 1, value)) {
2897 __kmp_affinity_top_method = affinity_top_method_flat;
2898 }
2899#if KMP_USE_HWLOC
2900 else if (__kmp_str_match("hwloc", 1, value)) {
2901 __kmp_affinity_top_method = affinity_top_method_hwloc;
2902 }
2903#endif
2904 else {
2905 KMP_WARNING(StgInvalidValue, name, value);
2906 }
2907} // __kmp_stg_parse_topology_method
2908
2909static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
2910 char const *name, void *data) {
2911#if KMP_DEBUG
2912 char const *value = NULL;
2913
2914 switch (__kmp_affinity_top_method) {
2915 case affinity_top_method_default:
2916 value = "default";
2917 break;
2918
2919 case affinity_top_method_all:
2920 value = "all";
2921 break;
2922
2923#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2924 case affinity_top_method_x2apicid:
2925 value = "x2APIC id";
2926 break;
2927
2928 case affinity_top_method_apicid:
2929 value = "APIC id";
2930 break;
2931#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2932
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002933#if KMP_USE_HWLOC
Jonathan Peyton30419822017-05-12 18:01:32 +00002934 case affinity_top_method_hwloc:
2935 value = "hwloc";
2936 break;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002937#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00002938
2939 case affinity_top_method_cpuinfo:
2940 value = "cpuinfo";
2941 break;
2942
2943#if KMP_GROUP_AFFINITY
2944 case affinity_top_method_group:
2945 value = "group";
2946 break;
2947#endif /* KMP_GROUP_AFFINITY */
2948
2949 case affinity_top_method_flat:
2950 value = "flat";
2951 break;
2952 }
2953
2954 if (value != NULL) {
2955 __kmp_stg_print_str(buffer, name, value);
2956 }
2957#endif /* KMP_DEBUG */
2958} // __kmp_stg_print_topology_method
2959
2960#endif /* KMP_AFFINITY_SUPPORTED */
2961
2962#if OMP_40_ENABLED
2963
2964// OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
2965// OMP_PLACES / place-partition-var is not.
2966static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
2967 void *data) {
2968 kmp_setting_t **rivals = (kmp_setting_t **)data;
2969 int rc;
2970
2971 rc = __kmp_stg_check_rivals(name, value, rivals);
2972 if (rc) {
2973 return;
2974 }
2975
2976 // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
2977 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
2978 (__kmp_nested_proc_bind.used > 0));
2979
2980 const char *buf = value;
2981 const char *next;
2982 int num;
2983 SKIP_WS(buf);
2984 if ((*buf >= '0') && (*buf <= '9')) {
2985 next = buf;
2986 SKIP_DIGITS(next);
2987 num = __kmp_str_to_int(buf, *next);
2988 KMP_ASSERT(num >= 0);
2989 buf = next;
2990 SKIP_WS(buf);
2991 } else {
2992 num = -1;
2993 }
2994
2995 next = buf;
2996 if (__kmp_match_str("disabled", buf, &next)) {
2997 buf = next;
2998 SKIP_WS(buf);
2999#if KMP_AFFINITY_SUPPORTED
3000 __kmp_affinity_type = affinity_disabled;
3001#endif /* KMP_AFFINITY_SUPPORTED */
3002 __kmp_nested_proc_bind.used = 1;
3003 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3004 } else if ((num == (int)proc_bind_false) ||
3005 __kmp_match_str("false", buf, &next)) {
3006 buf = next;
3007 SKIP_WS(buf);
3008#if KMP_AFFINITY_SUPPORTED
3009 __kmp_affinity_type = affinity_none;
3010#endif /* KMP_AFFINITY_SUPPORTED */
3011 __kmp_nested_proc_bind.used = 1;
3012 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3013 } else if ((num == (int)proc_bind_true) ||
3014 __kmp_match_str("true", buf, &next)) {
3015 buf = next;
3016 SKIP_WS(buf);
3017 __kmp_nested_proc_bind.used = 1;
3018 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3019 } else {
3020 // Count the number of values in the env var string
3021 const char *scan;
3022 int nelem = 1;
3023 for (scan = buf; *scan != '\0'; scan++) {
3024 if (*scan == ',') {
3025 nelem++;
3026 }
3027 }
3028
3029 // Create / expand the nested proc_bind array as needed
3030 if (__kmp_nested_proc_bind.size < nelem) {
3031 __kmp_nested_proc_bind.bind_types =
3032 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3033 __kmp_nested_proc_bind.bind_types,
3034 sizeof(kmp_proc_bind_t) * nelem);
3035 if (__kmp_nested_proc_bind.bind_types == NULL) {
3036 KMP_FATAL(MemoryAllocFailed);
3037 }
3038 __kmp_nested_proc_bind.size = nelem;
3039 }
3040 __kmp_nested_proc_bind.used = nelem;
3041
3042 // Save values in the nested proc_bind array
3043 int i = 0;
3044 for (;;) {
3045 enum kmp_proc_bind_t bind;
3046
3047 if ((num == (int)proc_bind_master) ||
3048 __kmp_match_str("master", buf, &next)) {
3049 buf = next;
3050 SKIP_WS(buf);
3051 bind = proc_bind_master;
3052 } else if ((num == (int)proc_bind_close) ||
3053 __kmp_match_str("close", buf, &next)) {
3054 buf = next;
3055 SKIP_WS(buf);
3056 bind = proc_bind_close;
3057 } else if ((num == (int)proc_bind_spread) ||
3058 __kmp_match_str("spread", buf, &next)) {
3059 buf = next;
3060 SKIP_WS(buf);
3061 bind = proc_bind_spread;
3062 } else {
3063 KMP_WARNING(StgInvalidValue, name, value);
3064 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3065 __kmp_nested_proc_bind.used = 1;
3066 return;
3067 }
3068
3069 __kmp_nested_proc_bind.bind_types[i++] = bind;
3070 if (i >= nelem) {
3071 break;
3072 }
3073 KMP_DEBUG_ASSERT(*buf == ',');
3074 buf++;
3075 SKIP_WS(buf);
3076
3077 // Read next value if it was specified as an integer
3078 if ((*buf >= '0') && (*buf <= '9')) {
3079 next = buf;
3080 SKIP_DIGITS(next);
3081 num = __kmp_str_to_int(buf, *next);
3082 KMP_ASSERT(num >= 0);
3083 buf = next;
3084 SKIP_WS(buf);
3085 } else {
3086 num = -1;
3087 }
3088 }
3089 SKIP_WS(buf);
3090 }
3091 if (*buf != '\0') {
3092 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3093 }
3094}
3095
3096static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
3097 void *data) {
3098 int nelem = __kmp_nested_proc_bind.used;
3099 if (__kmp_env_format) {
3100 KMP_STR_BUF_PRINT_NAME;
3101 } else {
3102 __kmp_str_buf_print(buffer, " %s", name);
3103 }
3104 if (nelem == 0) {
3105 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3106 } else {
3107 int i;
3108 __kmp_str_buf_print(buffer, "='", name);
3109 for (i = 0; i < nelem; i++) {
3110 switch (__kmp_nested_proc_bind.bind_types[i]) {
3111 case proc_bind_false:
3112 __kmp_str_buf_print(buffer, "false");
3113 break;
3114
3115 case proc_bind_true:
3116 __kmp_str_buf_print(buffer, "true");
3117 break;
3118
3119 case proc_bind_master:
3120 __kmp_str_buf_print(buffer, "master");
3121 break;
3122
3123 case proc_bind_close:
3124 __kmp_str_buf_print(buffer, "close");
3125 break;
3126
3127 case proc_bind_spread:
3128 __kmp_str_buf_print(buffer, "spread");
3129 break;
3130
3131 case proc_bind_intel:
3132 __kmp_str_buf_print(buffer, "intel");
3133 break;
3134
3135 case proc_bind_default:
3136 __kmp_str_buf_print(buffer, "default");
3137 break;
3138 }
3139 if (i < nelem - 1) {
3140 __kmp_str_buf_print(buffer, ",");
3141 }
3142 }
3143 __kmp_str_buf_print(buffer, "'\n");
3144 }
3145}
3146
3147#endif /* OMP_40_ENABLED */
3148
3149// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003150// OMP_DYNAMIC
Jim Cownie5e8470a2013-09-27 10:38:44 +00003151
Jonathan Peyton30419822017-05-12 18:01:32 +00003152static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
3153 void *data) {
3154 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003155} // __kmp_stg_parse_omp_dynamic
3156
Jonathan Peyton30419822017-05-12 18:01:32 +00003157static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
3158 void *data) {
3159 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003160} // __kmp_stg_print_omp_dynamic
3161
Jonathan Peyton30419822017-05-12 18:01:32 +00003162static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
3163 char const *value, void *data) {
3164 if (TCR_4(__kmp_init_parallel)) {
3165 KMP_WARNING(EnvParallelWarn, name);
3166 __kmp_env_toPrint(name, 0);
3167 return;
3168 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003169#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00003170 else if (__kmp_str_match("load balance", 2, value) ||
3171 __kmp_str_match("load_balance", 2, value) ||
3172 __kmp_str_match("load-balance", 2, value) ||
3173 __kmp_str_match("loadbalance", 2, value) ||
3174 __kmp_str_match("balance", 1, value)) {
3175 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3176 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003177#endif /* USE_LOAD_BALANCE */
Jonathan Peyton30419822017-05-12 18:01:32 +00003178 else if (__kmp_str_match("thread limit", 1, value) ||
3179 __kmp_str_match("thread_limit", 1, value) ||
3180 __kmp_str_match("thread-limit", 1, value) ||
3181 __kmp_str_match("threadlimit", 1, value) ||
3182 __kmp_str_match("limit", 2, value)) {
3183 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3184 } else if (__kmp_str_match("random", 1, value)) {
3185 __kmp_global.g.g_dynamic_mode = dynamic_random;
3186 } else {
3187 KMP_WARNING(StgInvalidValue, name, value);
3188 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003189} //__kmp_stg_parse_kmp_dynamic_mode
3190
Jonathan Peyton30419822017-05-12 18:01:32 +00003191static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
3192 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003193#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003194 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
3195 __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
3196 }
3197#ifdef USE_LOAD_BALANCE
3198 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
3199 __kmp_stg_print_str(buffer, name, "load balance");
3200 }
3201#endif /* USE_LOAD_BALANCE */
3202 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
3203 __kmp_stg_print_str(buffer, name, "thread limit");
3204 } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
3205 __kmp_stg_print_str(buffer, name, "random");
3206 } else {
3207 KMP_ASSERT(0);
3208 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003209#endif /* KMP_DEBUG */
3210} // __kmp_stg_print_kmp_dynamic_mode
3211
Jim Cownie5e8470a2013-09-27 10:38:44 +00003212#ifdef USE_LOAD_BALANCE
3213
Jonathan Peyton30419822017-05-12 18:01:32 +00003214// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003215// KMP_LOAD_BALANCE_INTERVAL
Jim Cownie5e8470a2013-09-27 10:38:44 +00003216
Jonathan Peyton30419822017-05-12 18:01:32 +00003217static void __kmp_stg_parse_ld_balance_interval(char const *name,
3218 char const *value, void *data) {
3219 double interval = __kmp_convert_to_double(value);
3220 if (interval >= 0) {
3221 __kmp_load_balance_interval = interval;
3222 } else {
3223 KMP_WARNING(StgInvalidValue, name, value);
3224 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003225} // __kmp_stg_parse_load_balance_interval
3226
Jonathan Peyton30419822017-05-12 18:01:32 +00003227static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
3228 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003229#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003230 __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
3231 __kmp_load_balance_interval);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003232#endif /* KMP_DEBUG */
3233} // __kmp_stg_print_load_balance_interval
3234
3235#endif /* USE_LOAD_BALANCE */
3236
Jonathan Peyton30419822017-05-12 18:01:32 +00003237// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003238// KMP_INIT_AT_FORK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003239
Jonathan Peyton30419822017-05-12 18:01:32 +00003240static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
3241 void *data) {
3242 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
3243 if (__kmp_need_register_atfork) {
3244 __kmp_need_register_atfork_specified = TRUE;
3245 };
Jim Cownie5e8470a2013-09-27 10:38:44 +00003246} // __kmp_stg_parse_init_at_fork
3247
Jonathan Peyton30419822017-05-12 18:01:32 +00003248static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
3249 char const *name, void *data) {
3250 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003251} // __kmp_stg_print_init_at_fork
3252
Jonathan Peyton30419822017-05-12 18:01:32 +00003253// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003254// KMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003255
Jonathan Peyton30419822017-05-12 18:01:32 +00003256static void __kmp_stg_parse_schedule(char const *name, char const *value,
3257 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003258
Jonathan Peyton30419822017-05-12 18:01:32 +00003259 if (value != NULL) {
3260 size_t length = KMP_STRLEN(value);
3261 if (length > INT_MAX) {
3262 KMP_WARNING(LongValue, name);
3263 } else {
3264 char *semicolon;
3265 if (value[length - 1] == '"' || value[length - 1] == '\'')
3266 KMP_WARNING(UnbalancedQuotes, name);
3267 do {
3268 char sentinel;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003269
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003270 semicolon = CCAST(char *, strchr(value, ';'));
Jonathan Peyton30419822017-05-12 18:01:32 +00003271 if (*value && semicolon != value) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003272 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003273
Jonathan Peyton30419822017-05-12 18:01:32 +00003274 if (comma) {
3275 ++comma;
3276 sentinel = ',';
3277 } else
3278 sentinel = ';';
3279 if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
3280 if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
3281 __kmp_static = kmp_sch_static_greedy;
3282 continue;
3283 } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
3284 ';')) {
3285 __kmp_static = kmp_sch_static_balanced;
3286 continue;
3287 }
3288 } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3289 sentinel)) {
3290 if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
3291 __kmp_guided = kmp_sch_guided_iterative_chunked;
3292 continue;
3293 } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
3294 ';')) {
3295 /* analytical not allowed for too many threads */
3296 __kmp_guided = kmp_sch_guided_analytical_chunked;
3297 continue;
3298 }
3299 }
3300 KMP_WARNING(InvalidClause, name, value);
3301 } else
3302 KMP_WARNING(EmptyClause, name);
3303 } while ((value = semicolon ? semicolon + 1 : NULL));
3304 }
3305 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003306
3307} // __kmp_stg_parse__schedule
3308
Jonathan Peyton30419822017-05-12 18:01:32 +00003309static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
3310 void *data) {
3311 if (__kmp_env_format) {
3312 KMP_STR_BUF_PRINT_NAME_EX(name);
3313 } else {
3314 __kmp_str_buf_print(buffer, " %s='", name);
3315 }
3316 if (__kmp_static == kmp_sch_static_greedy) {
3317 __kmp_str_buf_print(buffer, "%s", "static,greedy");
3318 } else if (__kmp_static == kmp_sch_static_balanced) {
3319 __kmp_str_buf_print(buffer, "%s", "static,balanced");
3320 }
3321 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
3322 __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
3323 } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
3324 __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
3325 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003326} // __kmp_stg_print_schedule
3327
Jonathan Peyton30419822017-05-12 18:01:32 +00003328// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003329// OMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003330
Jonathan Peyton30419822017-05-12 18:01:32 +00003331static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
3332 void *data) {
3333 size_t length;
3334 if (value) {
3335 length = KMP_STRLEN(value);
3336 if (length) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003337 char *comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00003338 if (value[length - 1] == '"' || value[length - 1] == '\'')
3339 KMP_WARNING(UnbalancedQuotes, name);
3340 /* get the specified scheduling style */
3341 if (!__kmp_strcasecmp_with_sentinel("dynamic", value, ',')) /* DYNAMIC */
3342 __kmp_sched = kmp_sch_dynamic_chunked;
3343 else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3344 ',')) /* GUIDED */
3345 __kmp_sched = kmp_sch_guided_chunked;
3346 // AC: TODO: add AUTO schedule, and pprobably remove TRAPEZOIDAL (OMP 3.0
3347 // does not allow it)
3348 else if (!__kmp_strcasecmp_with_sentinel("auto", value, ',')) { /* AUTO */
3349 __kmp_sched = kmp_sch_auto;
3350 if (comma) {
3351 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, comma),
3352 __kmp_msg_null);
3353 comma = NULL;
3354 }
3355 } else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", value,
3356 ',')) /* TRAPEZOIDAL */
3357 __kmp_sched = kmp_sch_trapezoidal;
3358 else if (!__kmp_strcasecmp_with_sentinel("static", value,
3359 ',')) /* STATIC */
3360 __kmp_sched = kmp_sch_static;
Andrey Churbanov429dbc22016-07-11 10:44:57 +00003361#if KMP_STATIC_STEAL_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00003362 else if (!__kmp_strcasecmp_with_sentinel("static_steal", value, ','))
3363 __kmp_sched = kmp_sch_static_steal;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003364#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003365 else {
3366 KMP_WARNING(StgInvalidValue, name, value);
3367 value = NULL; /* skip processing of comma */
3368 }
3369 if (value && comma) {
3370 __kmp_env_chunk = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003371
Jonathan Peyton30419822017-05-12 18:01:32 +00003372 if (__kmp_sched == kmp_sch_static)
3373 __kmp_sched = kmp_sch_static_chunked;
3374 ++comma;
3375 __kmp_chunk = __kmp_str_to_int(comma, 0);
3376 if (__kmp_chunk < 1) {
3377 __kmp_chunk = KMP_DEFAULT_CHUNK;
3378 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, comma),
3379 __kmp_msg_null);
3380 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3381 // AC: next block commented out until KMP_DEFAULT_CHUNK !=
3382 // KMP_MIN_CHUNK (to improve code coverage :)
3383 // The default chunk size is 1 according to standard, thus making
3384 // KMP_MIN_CHUNK not 1 we would introduce mess:
3385 // wrong chunk becomes 1, but it will be impossible to explicitely
3386 // set 1, because it becomes KMP_MIN_CHUNK...
3387 // } else if ( __kmp_chunk < KMP_MIN_CHUNK ) {
3388 // __kmp_chunk = KMP_MIN_CHUNK;
3389 } else if (__kmp_chunk > KMP_MAX_CHUNK) {
3390 __kmp_chunk = KMP_MAX_CHUNK;
3391 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, comma),
3392 __kmp_msg_null);
3393 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3394 }
3395 } else
3396 __kmp_env_chunk = FALSE;
3397 } else
3398 KMP_WARNING(EmptyString, name);
3399 }
3400 K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
3401 K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
3402 K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
3403 K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
Jim Cownie5e8470a2013-09-27 10:38:44 +00003404} // __kmp_stg_parse_omp_schedule
3405
Jonathan Peyton30419822017-05-12 18:01:32 +00003406static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
3407 char const *name, void *data) {
3408 if (__kmp_env_format) {
3409 KMP_STR_BUF_PRINT_NAME_EX(name);
3410 } else {
3411 __kmp_str_buf_print(buffer, " %s='", name);
3412 }
3413 if (__kmp_chunk) {
3414 switch (__kmp_sched) {
3415 case kmp_sch_dynamic_chunked:
3416 __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
3417 break;
3418 case kmp_sch_guided_iterative_chunked:
3419 case kmp_sch_guided_analytical_chunked:
3420 __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
3421 break;
3422 case kmp_sch_trapezoidal:
3423 __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
3424 break;
3425 case kmp_sch_static:
3426 case kmp_sch_static_chunked:
3427 case kmp_sch_static_balanced:
3428 case kmp_sch_static_greedy:
3429 __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
3430 break;
3431 case kmp_sch_static_steal:
3432 __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
3433 break;
3434 case kmp_sch_auto:
3435 __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
3436 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003437 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003438 } else {
3439 switch (__kmp_sched) {
3440 case kmp_sch_dynamic_chunked:
3441 __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
3442 break;
3443 case kmp_sch_guided_iterative_chunked:
3444 case kmp_sch_guided_analytical_chunked:
3445 __kmp_str_buf_print(buffer, "%s'\n", "guided");
3446 break;
3447 case kmp_sch_trapezoidal:
3448 __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
3449 break;
3450 case kmp_sch_static:
3451 case kmp_sch_static_chunked:
3452 case kmp_sch_static_balanced:
3453 case kmp_sch_static_greedy:
3454 __kmp_str_buf_print(buffer, "%s'\n", "static");
3455 break;
3456 case kmp_sch_static_steal:
3457 __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
3458 break;
3459 case kmp_sch_auto:
3460 __kmp_str_buf_print(buffer, "%s'\n", "auto");
3461 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003462 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003463 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003464} // __kmp_stg_print_omp_schedule
3465
Jonathan Peyton30419822017-05-12 18:01:32 +00003466// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003467// KMP_ATOMIC_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003468
Jonathan Peyton30419822017-05-12 18:01:32 +00003469static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
3470 void *data) {
3471 // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
3472 // compatibility mode.
3473 int mode = 0;
3474 int max = 1;
3475#ifdef KMP_GOMP_COMPAT
3476 max = 2;
3477#endif /* KMP_GOMP_COMPAT */
3478 __kmp_stg_parse_int(name, value, 0, max, &mode);
3479 // TODO; parse_int is not very suitable for this case. In case of overflow it
3480 // is better to use
3481 // 0 rather that max value.
3482 if (mode > 0) {
3483 __kmp_atomic_mode = mode;
3484 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003485} // __kmp_stg_parse_atomic_mode
3486
Jonathan Peyton30419822017-05-12 18:01:32 +00003487static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
3488 void *data) {
3489 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003490} // __kmp_stg_print_atomic_mode
3491
Jonathan Peyton30419822017-05-12 18:01:32 +00003492// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003493// KMP_CONSISTENCY_CHECK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003494
Jonathan Peyton30419822017-05-12 18:01:32 +00003495static void __kmp_stg_parse_consistency_check(char const *name,
3496 char const *value, void *data) {
3497 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
3498 // Note, this will not work from kmp_set_defaults because th_cons stack was
3499 // not allocated
3500 // for existed thread(s) thus the first __kmp_push_<construct> will break
3501 // with assertion.
3502 // TODO: allocate th_cons if called from kmp_set_defaults.
3503 __kmp_env_consistency_check = TRUE;
3504 } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
3505 __kmp_env_consistency_check = FALSE;
3506 } else {
3507 KMP_WARNING(StgInvalidValue, name, value);
3508 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003509} // __kmp_stg_parse_consistency_check
3510
Jonathan Peyton30419822017-05-12 18:01:32 +00003511static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
3512 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003513#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003514 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003515
Jonathan Peyton30419822017-05-12 18:01:32 +00003516 if (__kmp_env_consistency_check) {
3517 value = "all";
3518 } else {
3519 value = "none";
3520 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003521
Jonathan Peyton30419822017-05-12 18:01:32 +00003522 if (value != NULL) {
3523 __kmp_stg_print_str(buffer, name, value);
3524 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003525#endif /* KMP_DEBUG */
3526} // __kmp_stg_print_consistency_check
3527
Jim Cownie5e8470a2013-09-27 10:38:44 +00003528#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00003529// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003530// KMP_ITT_PREPARE_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00003531
3532#if USE_ITT_NOTIFY
3533
Jonathan Peyton30419822017-05-12 18:01:32 +00003534static void __kmp_stg_parse_itt_prepare_delay(char const *name,
3535 char const *value, void *data) {
3536 // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
3537 // iterations.
3538 int delay = 0;
3539 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
3540 __kmp_itt_prepare_delay = delay;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003541} // __kmp_str_parse_itt_prepare_delay
3542
Jonathan Peyton30419822017-05-12 18:01:32 +00003543static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
3544 char const *name, void *data) {
3545 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003546
3547} // __kmp_str_print_itt_prepare_delay
3548
3549#endif // USE_ITT_NOTIFY
3550#endif /* USE_ITT_BUILD */
3551
Jonathan Peyton30419822017-05-12 18:01:32 +00003552// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003553// KMP_MALLOC_POOL_INCR
Jim Cownie5e8470a2013-09-27 10:38:44 +00003554
Jonathan Peyton30419822017-05-12 18:01:32 +00003555static void __kmp_stg_parse_malloc_pool_incr(char const *name,
3556 char const *value, void *data) {
3557 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
3558 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
3559 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003560} // __kmp_stg_parse_malloc_pool_incr
3561
Jonathan Peyton30419822017-05-12 18:01:32 +00003562static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
3563 char const *name, void *data) {
3564 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003565
3566} // _kmp_stg_print_malloc_pool_incr
3567
Jim Cownie5e8470a2013-09-27 10:38:44 +00003568#ifdef KMP_DEBUG
3569
Jonathan Peyton30419822017-05-12 18:01:32 +00003570// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003571// KMP_PAR_RANGE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003572
Jonathan Peyton30419822017-05-12 18:01:32 +00003573static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
3574 void *data) {
3575 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
3576 __kmp_par_range_routine, __kmp_par_range_filename,
3577 &__kmp_par_range_lb, &__kmp_par_range_ub);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003578} // __kmp_stg_parse_par_range_env
3579
Jonathan Peyton30419822017-05-12 18:01:32 +00003580static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
3581 char const *name, void *data) {
3582 if (__kmp_par_range != 0) {
3583 __kmp_stg_print_str(buffer, name, par_range_to_print);
3584 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003585} // __kmp_stg_print_par_range_env
3586
Jonathan Peyton30419822017-05-12 18:01:32 +00003587// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003588// KMP_YIELD_CYCLE, KMP_YIELD_ON, KMP_YIELD_OFF
Jim Cownie5e8470a2013-09-27 10:38:44 +00003589
Jonathan Peyton30419822017-05-12 18:01:32 +00003590static void __kmp_stg_parse_yield_cycle(char const *name, char const *value,
3591 void *data) {
3592 int flag = __kmp_yield_cycle;
3593 __kmp_stg_parse_bool(name, value, &flag);
3594 __kmp_yield_cycle = flag;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003595} // __kmp_stg_parse_yield_cycle
3596
Jonathan Peyton30419822017-05-12 18:01:32 +00003597static void __kmp_stg_print_yield_cycle(kmp_str_buf_t *buffer, char const *name,
3598 void *data) {
3599 __kmp_stg_print_bool(buffer, name, __kmp_yield_cycle);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003600} // __kmp_stg_print_yield_cycle
3601
Jonathan Peyton30419822017-05-12 18:01:32 +00003602static void __kmp_stg_parse_yield_on(char const *name, char const *value,
3603 void *data) {
3604 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003605} // __kmp_stg_parse_yield_on
3606
Jonathan Peyton30419822017-05-12 18:01:32 +00003607static void __kmp_stg_print_yield_on(kmp_str_buf_t *buffer, char const *name,
3608 void *data) {
3609 __kmp_stg_print_int(buffer, name, __kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003610} // __kmp_stg_print_yield_on
3611
Jonathan Peyton30419822017-05-12 18:01:32 +00003612static void __kmp_stg_parse_yield_off(char const *name, char const *value,
3613 void *data) {
3614 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003615} // __kmp_stg_parse_yield_off
3616
Jonathan Peyton30419822017-05-12 18:01:32 +00003617static void __kmp_stg_print_yield_off(kmp_str_buf_t *buffer, char const *name,
3618 void *data) {
3619 __kmp_stg_print_int(buffer, name, __kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003620} // __kmp_stg_print_yield_off
3621
3622#endif
3623
Jonathan Peyton30419822017-05-12 18:01:32 +00003624// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003625// KMP_INIT_WAIT, KMP_NEXT_WAIT
Jim Cownie5e8470a2013-09-27 10:38:44 +00003626
Jonathan Peyton30419822017-05-12 18:01:32 +00003627static void __kmp_stg_parse_init_wait(char const *name, char const *value,
3628 void *data) {
3629 int wait;
3630 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3631 wait = __kmp_init_wait / 2;
3632 __kmp_stg_parse_int(name, value, KMP_MIN_INIT_WAIT, KMP_MAX_INIT_WAIT, &wait);
3633 __kmp_init_wait = wait * 2;
3634 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3635 __kmp_yield_init = __kmp_init_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003636} // __kmp_stg_parse_init_wait
3637
Jonathan Peyton30419822017-05-12 18:01:32 +00003638static void __kmp_stg_print_init_wait(kmp_str_buf_t *buffer, char const *name,
3639 void *data) {
3640 __kmp_stg_print_int(buffer, name, __kmp_init_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003641} // __kmp_stg_print_init_wait
3642
Jonathan Peyton30419822017-05-12 18:01:32 +00003643static void __kmp_stg_parse_next_wait(char const *name, char const *value,
3644 void *data) {
3645 int wait;
3646 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3647 wait = __kmp_next_wait / 2;
3648 __kmp_stg_parse_int(name, value, KMP_MIN_NEXT_WAIT, KMP_MAX_NEXT_WAIT, &wait);
3649 __kmp_next_wait = wait * 2;
3650 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3651 __kmp_yield_next = __kmp_next_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003652} // __kmp_stg_parse_next_wait
3653
Jonathan Peyton30419822017-05-12 18:01:32 +00003654static void __kmp_stg_print_next_wait(kmp_str_buf_t *buffer, char const *name,
3655 void *data) {
3656 __kmp_stg_print_int(buffer, name, __kmp_next_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003657} //__kmp_stg_print_next_wait
3658
Jonathan Peyton30419822017-05-12 18:01:32 +00003659// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003660// KMP_GTID_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003661
Jonathan Peyton30419822017-05-12 18:01:32 +00003662static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
3663 void *data) {
3664 // Modes:
3665 // 0 -- do not change default
3666 // 1 -- sp search
3667 // 2 -- use "keyed" TLS var, i.e.
3668 // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
3669 // 3 -- __declspec(thread) TLS var in tdata section
3670 int mode = 0;
3671 int max = 2;
3672#ifdef KMP_TDATA_GTID
3673 max = 3;
3674#endif /* KMP_TDATA_GTID */
3675 __kmp_stg_parse_int(name, value, 0, max, &mode);
3676 // TODO; parse_int is not very suitable for this case. In case of overflow it
3677 // is better to use 0 rather that max value.
3678 if (mode == 0) {
3679 __kmp_adjust_gtid_mode = TRUE;
3680 } else {
3681 __kmp_gtid_mode = mode;
3682 __kmp_adjust_gtid_mode = FALSE;
3683 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00003684} // __kmp_str_parse_gtid_mode
3685
Jonathan Peyton30419822017-05-12 18:01:32 +00003686static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
3687 void *data) {
3688 if (__kmp_adjust_gtid_mode) {
3689 __kmp_stg_print_int(buffer, name, 0);
3690 } else {
3691 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
3692 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003693} // __kmp_stg_print_gtid_mode
3694
Jonathan Peyton30419822017-05-12 18:01:32 +00003695// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003696// KMP_NUM_LOCKS_IN_BLOCK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003697
Jonathan Peyton30419822017-05-12 18:01:32 +00003698static void __kmp_stg_parse_lock_block(char const *name, char const *value,
3699 void *data) {
3700 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003701} // __kmp_str_parse_lock_block
3702
Jonathan Peyton30419822017-05-12 18:01:32 +00003703static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
3704 void *data) {
3705 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003706} // __kmp_stg_print_lock_block
3707
Jonathan Peyton30419822017-05-12 18:01:32 +00003708// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003709// KMP_LOCK_KIND
Jim Cownie5e8470a2013-09-27 10:38:44 +00003710
Jonathan Peytondae13d82015-12-11 21:57:06 +00003711#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00003712#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003713#else
Jonathan Peyton30419822017-05-12 18:01:32 +00003714#define KMP_STORE_LOCK_SEQ(a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003715#endif
3716
Jonathan Peyton30419822017-05-12 18:01:32 +00003717static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
3718 void *data) {
3719 if (__kmp_init_user_locks) {
3720 KMP_WARNING(EnvLockWarn, name);
3721 return;
3722 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003723
Jonathan Peyton30419822017-05-12 18:01:32 +00003724 if (__kmp_str_match("tas", 2, value) ||
3725 __kmp_str_match("test and set", 2, value) ||
3726 __kmp_str_match("test_and_set", 2, value) ||
3727 __kmp_str_match("test-and-set", 2, value) ||
3728 __kmp_str_match("test andset", 2, value) ||
3729 __kmp_str_match("test_andset", 2, value) ||
3730 __kmp_str_match("test-andset", 2, value) ||
3731 __kmp_str_match("testand set", 2, value) ||
3732 __kmp_str_match("testand_set", 2, value) ||
3733 __kmp_str_match("testand-set", 2, value) ||
3734 __kmp_str_match("testandset", 2, value)) {
3735 __kmp_user_lock_kind = lk_tas;
3736 KMP_STORE_LOCK_SEQ(tas);
3737 }
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003738#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003739 else if (__kmp_str_match("futex", 1, value)) {
3740 if (__kmp_futex_determine_capable()) {
3741 __kmp_user_lock_kind = lk_futex;
3742 KMP_STORE_LOCK_SEQ(futex);
3743 } else {
3744 KMP_WARNING(FutexNotSupported, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003745 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003746 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003747#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003748 else if (__kmp_str_match("ticket", 2, value)) {
3749 __kmp_user_lock_kind = lk_ticket;
3750 KMP_STORE_LOCK_SEQ(ticket);
3751 } else if (__kmp_str_match("queuing", 1, value) ||
3752 __kmp_str_match("queue", 1, value)) {
3753 __kmp_user_lock_kind = lk_queuing;
3754 KMP_STORE_LOCK_SEQ(queuing);
3755 } else if (__kmp_str_match("drdpa ticket", 1, value) ||
3756 __kmp_str_match("drdpa_ticket", 1, value) ||
3757 __kmp_str_match("drdpa-ticket", 1, value) ||
3758 __kmp_str_match("drdpaticket", 1, value) ||
3759 __kmp_str_match("drdpa", 1, value)) {
3760 __kmp_user_lock_kind = lk_drdpa;
3761 KMP_STORE_LOCK_SEQ(drdpa);
3762 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003763#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003764 else if (__kmp_str_match("adaptive", 1, value)) {
3765 if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
3766 __kmp_user_lock_kind = lk_adaptive;
3767 KMP_STORE_LOCK_SEQ(adaptive);
3768 } else {
3769 KMP_WARNING(AdaptiveNotSupported, name, value);
3770 __kmp_user_lock_kind = lk_queuing;
3771 KMP_STORE_LOCK_SEQ(queuing);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003772 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003773 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003774#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peytondae13d82015-12-11 21:57:06 +00003775#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003776 else if (__kmp_str_match("rtm", 1, value)) {
3777 if (__kmp_cpuinfo.rtm) {
3778 __kmp_user_lock_kind = lk_rtm;
3779 KMP_STORE_LOCK_SEQ(rtm);
3780 } else {
3781 KMP_WARNING(AdaptiveNotSupported, name, value);
3782 __kmp_user_lock_kind = lk_queuing;
3783 KMP_STORE_LOCK_SEQ(queuing);
Jonathan Peytondae13d82015-12-11 21:57:06 +00003784 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003785 } else if (__kmp_str_match("hle", 1, value)) {
3786 __kmp_user_lock_kind = lk_hle;
3787 KMP_STORE_LOCK_SEQ(hle);
3788 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00003789#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003790 else {
3791 KMP_WARNING(StgInvalidValue, name, value);
3792 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003793}
3794
Jonathan Peyton30419822017-05-12 18:01:32 +00003795static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
3796 void *data) {
3797 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003798
Jonathan Peyton30419822017-05-12 18:01:32 +00003799 switch (__kmp_user_lock_kind) {
3800 case lk_default:
3801 value = "default";
3802 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003803
Jonathan Peyton30419822017-05-12 18:01:32 +00003804 case lk_tas:
3805 value = "tas";
3806 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003807
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003808#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003809 case lk_futex:
3810 value = "futex";
3811 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003812#endif
3813
Jonathan Peytondae13d82015-12-11 21:57:06 +00003814#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003815 case lk_rtm:
3816 value = "rtm";
3817 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003818
Jonathan Peyton30419822017-05-12 18:01:32 +00003819 case lk_hle:
3820 value = "hle";
3821 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003822#endif
3823
Jonathan Peyton30419822017-05-12 18:01:32 +00003824 case lk_ticket:
3825 value = "ticket";
3826 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003827
Jonathan Peyton30419822017-05-12 18:01:32 +00003828 case lk_queuing:
3829 value = "queuing";
3830 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003831
Jonathan Peyton30419822017-05-12 18:01:32 +00003832 case lk_drdpa:
3833 value = "drdpa";
3834 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003835#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003836 case lk_adaptive:
3837 value = "adaptive";
3838 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003839#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003840 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003841
Jonathan Peyton30419822017-05-12 18:01:32 +00003842 if (value != NULL) {
3843 __kmp_stg_print_str(buffer, name, value);
3844 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003845}
3846
Jonathan Peyton30419822017-05-12 18:01:32 +00003847// -----------------------------------------------------------------------------
Jonathan Peyton377aa402016-04-14 16:00:37 +00003848// KMP_SPIN_BACKOFF_PARAMS
Jonathan Peyton377aa402016-04-14 16:00:37 +00003849
Jonathan Peyton30419822017-05-12 18:01:32 +00003850// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
3851// for machine pause)
3852static void __kmp_stg_parse_spin_backoff_params(const char *name,
3853 const char *value, void *data) {
3854 const char *next = value;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003855
Jonathan Peyton30419822017-05-12 18:01:32 +00003856 int total = 0; // Count elements that were set. It'll be used as an array size
3857 int prev_comma = FALSE; // For correct processing sequential commas
3858 int i;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003859
Jonathan Peyton30419822017-05-12 18:01:32 +00003860 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
3861 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003862
Jonathan Peyton30419822017-05-12 18:01:32 +00003863 // Run only 3 iterations because it is enough to read two values or find a
3864 // syntax error
3865 for (i = 0; i < 3; i++) {
3866 SKIP_WS(next);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003867
Jonathan Peyton30419822017-05-12 18:01:32 +00003868 if (*next == '\0') {
3869 break;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003870 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003871 // Next character is not an integer or not a comma OR number of values > 2
3872 // => end of list
3873 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
3874 KMP_WARNING(EnvSyntaxError, name, value);
3875 return;
3876 }
3877 // The next character is ','
3878 if (*next == ',') {
3879 // ',' is the fisrt character
3880 if (total == 0 || prev_comma) {
3881 total++;
3882 }
3883 prev_comma = TRUE;
3884 next++; // skip ','
3885 SKIP_WS(next);
3886 }
3887 // Next character is a digit
3888 if (*next >= '0' && *next <= '9') {
3889 int num;
3890 const char *buf = next;
3891 char const *msg = NULL;
3892 prev_comma = FALSE;
3893 SKIP_DIGITS(next);
3894 total++;
3895
3896 const char *tmp = next;
3897 SKIP_WS(tmp);
3898 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
3899 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003900 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00003901 }
3902
3903 num = __kmp_str_to_int(buf, *next);
3904 if (num <= 0) { // The number of retries should be > 0
3905 msg = KMP_I18N_STR(ValueTooSmall);
3906 num = 1;
3907 } else if (num > KMP_INT_MAX) {
3908 msg = KMP_I18N_STR(ValueTooLarge);
3909 num = KMP_INT_MAX;
3910 }
3911 if (msg != NULL) {
3912 // Message is not empty. Print warning.
3913 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
3914 KMP_INFORM(Using_int_Value, name, num);
3915 }
3916 if (total == 1) {
3917 max_backoff = num;
3918 } else if (total == 2) {
3919 min_tick = num;
3920 }
Jonathan Peyton377aa402016-04-14 16:00:37 +00003921 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003922 }
3923 KMP_DEBUG_ASSERT(total > 0);
3924 if (total <= 0) {
3925 KMP_WARNING(EnvSyntaxError, name, value);
3926 return;
3927 }
3928 __kmp_spin_backoff_params.max_backoff = max_backoff;
3929 __kmp_spin_backoff_params.min_tick = min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003930}
3931
Jonathan Peyton30419822017-05-12 18:01:32 +00003932static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
3933 char const *name, void *data) {
3934 if (__kmp_env_format) {
3935 KMP_STR_BUF_PRINT_NAME_EX(name);
3936 } else {
3937 __kmp_str_buf_print(buffer, " %s='", name);
3938 }
3939 __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
3940 __kmp_spin_backoff_params.min_tick);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003941}
3942
Jim Cownie5e8470a2013-09-27 10:38:44 +00003943#if KMP_USE_ADAPTIVE_LOCKS
3944
Jonathan Peyton30419822017-05-12 18:01:32 +00003945// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003946// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003947
3948// Parse out values for the tunable parameters from a string of the form
3949// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
Jonathan Peyton30419822017-05-12 18:01:32 +00003950static void __kmp_stg_parse_adaptive_lock_props(const char *name,
3951 const char *value, void *data) {
3952 int max_retries = 0;
3953 int max_badness = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003954
Jonathan Peyton30419822017-05-12 18:01:32 +00003955 const char *next = value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003956
Jonathan Peyton30419822017-05-12 18:01:32 +00003957 int total = 0; // Count elements that were set. It'll be used as an array size
3958 int prev_comma = FALSE; // For correct processing sequential commas
3959 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003960
Jonathan Peyton30419822017-05-12 18:01:32 +00003961 // Save values in the structure __kmp_speculative_backoff_params
3962 // Run only 3 iterations because it is enough to read two values or find a
3963 // syntax error
3964 for (i = 0; i < 3; i++) {
3965 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003966
Jonathan Peyton30419822017-05-12 18:01:32 +00003967 if (*next == '\0') {
3968 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003969 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003970 // Next character is not an integer or not a comma OR number of values > 2
3971 // => end of list
3972 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
3973 KMP_WARNING(EnvSyntaxError, name, value);
3974 return;
3975 }
3976 // The next character is ','
3977 if (*next == ',') {
3978 // ',' is the fisrt character
3979 if (total == 0 || prev_comma) {
3980 total++;
3981 }
3982 prev_comma = TRUE;
3983 next++; // skip ','
3984 SKIP_WS(next);
3985 }
3986 // Next character is a digit
3987 if (*next >= '0' && *next <= '9') {
3988 int num;
3989 const char *buf = next;
3990 char const *msg = NULL;
3991 prev_comma = FALSE;
3992 SKIP_DIGITS(next);
3993 total++;
3994
3995 const char *tmp = next;
3996 SKIP_WS(tmp);
3997 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
3998 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003999 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00004000 }
4001
4002 num = __kmp_str_to_int(buf, *next);
4003 if (num < 0) { // The number of retries should be >= 0
4004 msg = KMP_I18N_STR(ValueTooSmall);
4005 num = 1;
4006 } else if (num > KMP_INT_MAX) {
4007 msg = KMP_I18N_STR(ValueTooLarge);
4008 num = KMP_INT_MAX;
4009 }
4010 if (msg != NULL) {
4011 // Message is not empty. Print warning.
4012 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4013 KMP_INFORM(Using_int_Value, name, num);
4014 }
4015 if (total == 1) {
4016 max_retries = num;
4017 } else if (total == 2) {
4018 max_badness = num;
4019 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004020 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004021 }
4022 KMP_DEBUG_ASSERT(total > 0);
4023 if (total <= 0) {
4024 KMP_WARNING(EnvSyntaxError, name, value);
4025 return;
4026 }
4027 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4028 __kmp_adaptive_backoff_params.max_badness = max_badness;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004029}
4030
Jonathan Peyton30419822017-05-12 18:01:32 +00004031static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4032 char const *name, void *data) {
4033 if (__kmp_env_format) {
4034 KMP_STR_BUF_PRINT_NAME_EX(name);
4035 } else {
4036 __kmp_str_buf_print(buffer, " %s='", name);
4037 }
4038 __kmp_str_buf_print(buffer, "%d,%d'\n",
4039 __kmp_adaptive_backoff_params.max_soft_retries,
4040 __kmp_adaptive_backoff_params.max_badness);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004041} // __kmp_stg_print_adaptive_lock_props
4042
4043#if KMP_DEBUG_ADAPTIVE_LOCKS
4044
Jonathan Peyton30419822017-05-12 18:01:32 +00004045static void __kmp_stg_parse_speculative_statsfile(char const *name,
4046 char const *value,
4047 void *data) {
4048 __kmp_stg_parse_file(name, value, "", &__kmp_speculative_statsfile);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004049} // __kmp_stg_parse_speculative_statsfile
4050
Jonathan Peyton30419822017-05-12 18:01:32 +00004051static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
4052 char const *name,
4053 void *data) {
4054 if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
4055 __kmp_stg_print_str(buffer, name, "stdout");
4056 } else {
4057 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
4058 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004059
4060} // __kmp_stg_print_speculative_statsfile
4061
4062#endif // KMP_DEBUG_ADAPTIVE_LOCKS
4063
4064#endif // KMP_USE_ADAPTIVE_LOCKS
4065
Jonathan Peyton30419822017-05-12 18:01:32 +00004066// -----------------------------------------------------------------------------
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004067// KMP_HW_SUBSET (was KMP_PLACE_THREADS)
Jim Cownie5e8470a2013-09-27 10:38:44 +00004068
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004069// The longest observable sequense of items is
4070// Socket-Node-Tile-Core-Thread
4071// So, let's limit to 5 levels for now
4072// The input string is usually short enough, let's use 512 limit for now
4073#define MAX_T_LEVEL 5
4074#define MAX_STR_LEN 512
Jonathan Peyton30419822017-05-12 18:01:32 +00004075static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
4076 void *data) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004077 // Value example: 1s,5c@3,2T
4078 // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
4079 static int parsed = 0;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004080 if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
4081 KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
4082 if (parsed == 1) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004083 return; // already parsed KMP_HW_SUBSET
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004084 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004085 }
4086 parsed = 1;
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004087
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004088 char *components[MAX_T_LEVEL];
4089 char const *digits = "0123456789";
4090 char input[MAX_STR_LEN];
4091 size_t len = 0, mlen = MAX_STR_LEN;
4092 int level = 0;
4093 // Canonize the string (remove spaces, unify delimiters, etc.)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004094 char *pos = CCAST(char *, value);
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004095 while (*pos && mlen) {
4096 if (*pos != ' ') { // skip spaces
4097 if (len == 0 && *pos == ':') {
4098 __kmp_hws_abs_flag = 1; // if the first symbol is ":", skip it
4099 } else {
4100 input[len] = toupper(*pos);
4101 if (input[len] == 'X')
4102 input[len] = ','; // unify delimiters of levels
4103 if (input[len] == 'O' && strchr(digits, *(pos + 1)))
4104 input[len] = '@'; // unify delimiters of offset
4105 len++;
4106 }
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004107 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004108 mlen--;
4109 pos++;
4110 }
4111 if (len == 0 || mlen == 0)
4112 goto err; // contents is either empty or too long
4113 input[len] = '\0';
4114 __kmp_hws_requested = 1; // mark that subset requested
4115 // Split by delimiter
4116 pos = input;
4117 components[level++] = pos;
George Rokos4800fc42017-04-25 15:55:39 +00004118 while ((pos = strchr(pos, ','))) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004119 *pos = '\0'; // modify input and avoid more copying
4120 components[level++] = ++pos; // expect something after ","
4121 if (level > MAX_T_LEVEL)
4122 goto err; // too many components provided
4123 }
4124 // Check each component
4125 for (int i = 0; i < level; ++i) {
4126 int offset = 0;
4127 int num = atoi(components[i]); // each component should start with a number
4128 if ((pos = strchr(components[i], '@'))) {
4129 offset = atoi(pos + 1); // save offset
4130 *pos = '\0'; // cut the offset from the component
4131 }
4132 pos = components[i] + strspn(components[i], digits);
4133 if (pos == components[i])
4134 goto err;
4135 // detect the component type
4136 switch (*pos) {
4137 case 'S': // Socket
4138 if (__kmp_hws_socket.num > 0)
4139 goto err; // duplicate is not allowed
4140 __kmp_hws_socket.num = num;
4141 __kmp_hws_socket.offset = offset;
4142 break;
4143 case 'N': // NUMA Node
4144 if (__kmp_hws_node.num > 0)
4145 goto err; // duplicate is not allowed
4146 __kmp_hws_node.num = num;
4147 __kmp_hws_node.offset = offset;
4148 break;
4149 case 'L': // Cache
4150 if (*(pos + 1) == '2') { // L2 - Tile
4151 if (__kmp_hws_tile.num > 0)
4152 goto err; // duplicate is not allowed
4153 __kmp_hws_tile.num = num;
4154 __kmp_hws_tile.offset = offset;
4155 } else if (*(pos + 1) == '3') { // L3 - Socket
4156 if (__kmp_hws_socket.num > 0)
4157 goto err; // duplicate is not allowed
4158 __kmp_hws_socket.num = num;
4159 __kmp_hws_socket.offset = offset;
4160 } else if (*(pos + 1) == '1') { // L1 - Core
4161 if (__kmp_hws_core.num > 0)
4162 goto err; // duplicate is not allowed
4163 __kmp_hws_core.num = num;
4164 __kmp_hws_core.offset = offset;
4165 }
4166 break;
4167 case 'C': // Core (or Cache?)
4168 if (*(pos + 1) != 'A') {
4169 if (__kmp_hws_core.num > 0)
4170 goto err; // duplicate is not allowed
4171 __kmp_hws_core.num = num;
4172 __kmp_hws_core.offset = offset;
4173 } else { // Cache
4174 char *d = pos + strcspn(pos, digits); // find digit
4175 if (*d == '2') { // L2 - Tile
4176 if (__kmp_hws_tile.num > 0)
4177 goto err; // duplicate is not allowed
4178 __kmp_hws_tile.num = num;
4179 __kmp_hws_tile.offset = offset;
4180 } else if (*d == '3') { // L3 - Socket
4181 if (__kmp_hws_socket.num > 0)
4182 goto err; // duplicate is not allowed
4183 __kmp_hws_socket.num = num;
4184 __kmp_hws_socket.offset = offset;
4185 } else if (*d == '1') { // L1 - Core
4186 if (__kmp_hws_core.num > 0)
4187 goto err; // duplicate is not allowed
4188 __kmp_hws_core.num = num;
4189 __kmp_hws_core.offset = offset;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004190 } else {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004191 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004192 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004193 }
4194 break;
4195 case 'T': // Thread
4196 if (__kmp_hws_proc.num > 0)
4197 goto err; // duplicate is not allowed
4198 __kmp_hws_proc.num = num;
4199 __kmp_hws_proc.offset = offset;
4200 break;
4201 default:
4202 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004203 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004204 }
4205 return;
4206err:
4207 KMP_WARNING(AffHWSubsetInvalid, name, value);
4208 __kmp_hws_requested = 0; // mark that subset not requested
4209 return;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004210}
4211
Jonathan Peyton30419822017-05-12 18:01:32 +00004212static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004213 void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +00004214 if (__kmp_hws_requested) {
4215 int comma = 0;
4216 kmp_str_buf_t buf;
4217 __kmp_str_buf_init(&buf);
4218 if (__kmp_env_format)
4219 KMP_STR_BUF_PRINT_NAME_EX(name);
4220 else
4221 __kmp_str_buf_print(buffer, " %s='", name);
4222 if (__kmp_hws_socket.num) {
4223 __kmp_str_buf_print(&buf, "%ds", __kmp_hws_socket.num);
4224 if (__kmp_hws_socket.offset)
4225 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_socket.offset);
4226 comma = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004227 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004228 if (__kmp_hws_node.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004229 __kmp_str_buf_print(&buf, "%s%dn", comma ? "," : "", __kmp_hws_node.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004230 if (__kmp_hws_node.offset)
4231 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_node.offset);
4232 comma = 1;
4233 }
4234 if (__kmp_hws_tile.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004235 __kmp_str_buf_print(&buf, "%s%dL2", comma ? "," : "", __kmp_hws_tile.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004236 if (__kmp_hws_tile.offset)
4237 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_tile.offset);
4238 comma = 1;
4239 }
4240 if (__kmp_hws_core.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004241 __kmp_str_buf_print(&buf, "%s%dc", comma ? "," : "", __kmp_hws_core.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004242 if (__kmp_hws_core.offset)
4243 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_core.offset);
4244 comma = 1;
4245 }
4246 if (__kmp_hws_proc.num)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004247 __kmp_str_buf_print(&buf, "%s%dt", comma ? "," : "", __kmp_hws_proc.num);
4248 __kmp_str_buf_print(buffer, "%s'\n", buf.str);
Jonathan Peyton30419822017-05-12 18:01:32 +00004249 __kmp_str_buf_free(&buf);
4250 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004251}
Jim Cownie5e8470a2013-09-27 10:38:44 +00004252
4253#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004254// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004255// KMP_FORKJOIN_FRAMES
Jim Cownie5e8470a2013-09-27 10:38:44 +00004256
Jonathan Peyton30419822017-05-12 18:01:32 +00004257static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
4258 void *data) {
4259 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004260} // __kmp_stg_parse_forkjoin_frames
4261
Jonathan Peyton30419822017-05-12 18:01:32 +00004262static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
4263 char const *name, void *data) {
4264 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004265} // __kmp_stg_print_forkjoin_frames
4266
Jonathan Peyton30419822017-05-12 18:01:32 +00004267// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004268// KMP_FORKJOIN_FRAMES_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00004269
Jonathan Peyton30419822017-05-12 18:01:32 +00004270static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
4271 char const *value,
4272 void *data) {
4273 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004274} // __kmp_stg_parse_forkjoin_frames
4275
Jonathan Peyton30419822017-05-12 18:01:32 +00004276static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
4277 char const *name, void *data) {
4278 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004279} // __kmp_stg_print_forkjoin_frames
4280#endif /* USE_ITT_BUILD */
4281
Jonathan Peyton30419822017-05-12 18:01:32 +00004282// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004283// OMP_DISPLAY_ENV
Jim Cownie5e8470a2013-09-27 10:38:44 +00004284
4285#if OMP_40_ENABLED
4286
Jonathan Peyton30419822017-05-12 18:01:32 +00004287static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
4288 void *data) {
4289 if (__kmp_str_match("VERBOSE", 1, value)) {
4290 __kmp_display_env_verbose = TRUE;
4291 } else {
4292 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
4293 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004294
4295} // __kmp_stg_parse_omp_display_env
4296
Jonathan Peyton30419822017-05-12 18:01:32 +00004297static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
4298 char const *name, void *data) {
4299 if (__kmp_display_env_verbose) {
4300 __kmp_stg_print_str(buffer, name, "VERBOSE");
4301 } else {
4302 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
4303 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004304} // __kmp_stg_print_omp_display_env
4305
Jonathan Peyton30419822017-05-12 18:01:32 +00004306static void __kmp_stg_parse_omp_cancellation(char const *name,
4307 char const *value, void *data) {
4308 if (TCR_4(__kmp_init_parallel)) {
4309 KMP_WARNING(EnvParallelWarn, name);
4310 return;
4311 } // read value before first parallel only
4312 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004313} // __kmp_stg_parse_omp_cancellation
4314
Jonathan Peyton30419822017-05-12 18:01:32 +00004315static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
4316 char const *name, void *data) {
4317 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004318} // __kmp_stg_print_omp_cancellation
4319
Jim Cownie5e8470a2013-09-27 10:38:44 +00004320#endif
4321
Jonathan Peyton30419822017-05-12 18:01:32 +00004322// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004323// Table.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004324
4325static kmp_setting_t __kmp_stg_table[] = {
4326
Jonathan Peyton30419822017-05-12 18:01:32 +00004327 {"KMP_ALL_THREADS", __kmp_stg_parse_all_threads,
4328 __kmp_stg_print_all_threads, NULL, 0, 0},
4329 {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
4330 NULL, 0, 0},
4331 {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
4332 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
4333 {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
4334 NULL, 0, 0},
4335 {"KMP_MAX_THREADS", __kmp_stg_parse_all_threads, NULL, NULL, 0,
4336 0}, // For backward compatibility
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004337#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +00004338 {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
4339 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004340#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004341 {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
4342 0, 0},
4343 {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
4344 __kmp_stg_print_stackoffset, NULL, 0, 0},
4345 {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4346 NULL, 0, 0},
4347 {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
4348 0, 0},
4349 {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
4350 0},
4351 {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
4352 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004353
Jonathan Peyton30419822017-05-12 18:01:32 +00004354 {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
4355 {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
4356 __kmp_stg_print_num_threads, NULL, 0, 0},
4357 {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4358 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004359
Jonathan Peyton30419822017-05-12 18:01:32 +00004360 {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
4361 0},
4362 {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
4363 __kmp_stg_print_task_stealing, NULL, 0, 0},
4364 {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
4365 __kmp_stg_print_max_active_levels, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004366#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004367 {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
4368 __kmp_stg_print_default_device, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004369#endif
Jonathan Peytondf6818b2016-06-14 17:57:47 +00004370#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004371 {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
4372 __kmp_stg_print_max_task_priority, NULL, 0, 0},
Jonathan Peyton28510722016-02-25 18:04:09 +00004373#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004374 {"OMP_THREAD_LIMIT", __kmp_stg_parse_all_threads,
4375 __kmp_stg_print_all_threads, NULL, 0, 0},
4376 {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
4377 __kmp_stg_print_wait_policy, NULL, 0, 0},
4378 {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
4379 __kmp_stg_print_disp_buffers, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004380#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00004381 {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
4382 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
4383 {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
4384 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004385#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00004386
4387#if KMP_HANDLE_SIGNALS
Jonathan Peyton30419822017-05-12 18:01:32 +00004388 {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
4389 __kmp_stg_print_handle_signals, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004390#endif
4391
4392#if KMP_ARCH_X86 || KMP_ARCH_X86_64
Jonathan Peyton30419822017-05-12 18:01:32 +00004393 {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
4394 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004395#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
4396
4397#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004398 {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004399#endif
4400
4401#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00004402 {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
4403 0},
4404 {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
4405 0},
4406 {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
4407 0},
4408 {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
4409 0},
4410 {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
4411 0},
4412 {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
4413 0},
4414 {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
4415 {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
4416 NULL, 0, 0},
4417 {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
4418 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
4419 {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
4420 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
4421 {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
4422 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
4423 {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004424
Jonathan Peyton30419822017-05-12 18:01:32 +00004425 {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
4426 __kmp_stg_print_par_range_env, NULL, 0, 0},
4427 {"KMP_YIELD_CYCLE", __kmp_stg_parse_yield_cycle,
4428 __kmp_stg_print_yield_cycle, NULL, 0, 0},
4429 {"KMP_YIELD_ON", __kmp_stg_parse_yield_on, __kmp_stg_print_yield_on, NULL,
4430 0, 0},
4431 {"KMP_YIELD_OFF", __kmp_stg_parse_yield_off, __kmp_stg_print_yield_off,
4432 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004433#endif // KMP_DEBUG
4434
Jonathan Peyton30419822017-05-12 18:01:32 +00004435 {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
4436 __kmp_stg_print_align_alloc, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004437
Jonathan Peyton30419822017-05-12 18:01:32 +00004438 {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4439 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4440 {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4441 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
4442 {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4443 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4444 {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4445 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004446#if KMP_FAST_REDUCTION_BARRIER
Jonathan Peyton30419822017-05-12 18:01:32 +00004447 {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4448 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4449 {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4450 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004451#endif
4452
Jonathan Peyton30419822017-05-12 18:01:32 +00004453 {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
4454 __kmp_stg_print_abort_delay, NULL, 0, 0},
4455 {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
4456 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
4457 {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
4458 __kmp_stg_print_force_reduction, NULL, 0, 0},
4459 {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
4460 __kmp_stg_print_force_reduction, NULL, 0, 0},
4461 {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
4462 __kmp_stg_print_storage_map, NULL, 0, 0},
4463 {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
4464 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
4465 {"KMP_FOREIGN_THREADS_THREADPRIVATE",
4466 __kmp_stg_parse_foreign_threads_threadprivate,
4467 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004468
Alp Toker98758b02014-03-02 04:12:06 +00004469#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004470 {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
4471 0, 0},
4472#ifdef KMP_GOMP_COMPAT
4473 {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
4474 /* no print */ NULL, 0, 0},
4475#endif /* KMP_GOMP_COMPAT */
4476#if OMP_40_ENABLED
4477 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4478 NULL, 0, 0},
4479 {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
4480#else
4481 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, NULL, /* no print */ NULL, 0,
4482 0},
4483#endif /* OMP_40_ENABLED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00004484
Jonathan Peyton30419822017-05-12 18:01:32 +00004485 {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
4486 __kmp_stg_print_topology_method, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004487
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004488#else
Jim Cownie5e8470a2013-09-27 10:38:44 +00004489
Jonathan Peyton30419822017-05-12 18:01:32 +00004490// KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
4491// OMP_PROC_BIND and proc-bind-var are supported, however.
4492#if OMP_40_ENABLED
4493 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4494 NULL, 0, 0},
4495#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004496
Alp Toker98758b02014-03-02 04:12:06 +00004497#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004498
Jonathan Peyton30419822017-05-12 18:01:32 +00004499 {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
4500 __kmp_stg_print_init_at_fork, NULL, 0, 0},
4501 {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
4502 0, 0},
4503 {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
4504 NULL, 0, 0},
4505 {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
4506 __kmp_stg_print_atomic_mode, NULL, 0, 0},
4507 {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
4508 __kmp_stg_print_consistency_check, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004509
4510#if USE_ITT_BUILD && USE_ITT_NOTIFY
Jonathan Peyton30419822017-05-12 18:01:32 +00004511 {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
4512 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004513#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
Jonathan Peyton30419822017-05-12 18:01:32 +00004514 {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
4515 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
4516 {"KMP_INIT_WAIT", __kmp_stg_parse_init_wait, __kmp_stg_print_init_wait,
4517 NULL, 0, 0},
4518 {"KMP_NEXT_WAIT", __kmp_stg_parse_next_wait, __kmp_stg_print_next_wait,
4519 NULL, 0, 0},
4520 {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
4521 NULL, 0, 0},
4522 {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
4523 NULL, 0, 0},
4524 {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
4525 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004526
4527#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00004528 {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
4529 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004530#endif
4531
Jonathan Peyton30419822017-05-12 18:01:32 +00004532 {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
4533 __kmp_stg_print_lock_block, NULL, 0, 0},
4534 {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
4535 NULL, 0, 0},
4536 {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
4537 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004538#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004539 {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
4540 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004541#if KMP_DEBUG_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004542 {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
4543 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004544#endif
4545#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004546 {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4547 NULL, 0, 0},
4548 {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4549 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004550#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004551 {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
4552 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
4553 {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
4554 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004555#endif
4556
Jonathan Peyton30419822017-05-12 18:01:32 +00004557#if OMP_40_ENABLED
4558 {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
4559 __kmp_stg_print_omp_display_env, NULL, 0, 0},
4560 {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
4561 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004562#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004563 {"", NULL, NULL, NULL, 0, 0}}; // settings
Jim Cownie5e8470a2013-09-27 10:38:44 +00004564
Jonathan Peyton30419822017-05-12 18:01:32 +00004565static int const __kmp_stg_count =
4566 sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004567
Jonathan Peyton30419822017-05-12 18:01:32 +00004568static inline kmp_setting_t *__kmp_stg_find(char const *name) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004569
Jonathan Peyton30419822017-05-12 18:01:32 +00004570 int i;
4571 if (name != NULL) {
4572 for (i = 0; i < __kmp_stg_count; ++i) {
4573 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
4574 return &__kmp_stg_table[i];
4575 }; // if
4576 }; // for
4577 }; // if
4578 return NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004579
4580} // __kmp_stg_find
4581
Jonathan Peyton30419822017-05-12 18:01:32 +00004582static int __kmp_stg_cmp(void const *_a, void const *_b) {
Andrey Churbanov5ba90c72017-07-17 09:03:14 +00004583 const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
4584 const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004585
Jonathan Peyton30419822017-05-12 18:01:32 +00004586 // Process KMP_AFFINITY last.
4587 // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
4588 if (strcmp(a->name, "KMP_AFFINITY") == 0) {
4589 if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4590 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004591 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004592 return 1;
4593 } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4594 return -1;
4595 }
4596 return strcmp(a->name, b->name);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004597} // __kmp_stg_cmp
4598
Jonathan Peyton30419822017-05-12 18:01:32 +00004599static void __kmp_stg_init(void) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004600
Jonathan Peyton30419822017-05-12 18:01:32 +00004601 static int initialized = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004602
Jonathan Peyton30419822017-05-12 18:01:32 +00004603 if (!initialized) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004604
Jonathan Peyton30419822017-05-12 18:01:32 +00004605 // Sort table.
4606 qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
4607 __kmp_stg_cmp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004608
Jonathan Peyton30419822017-05-12 18:01:32 +00004609 { // Initialize *_STACKSIZE data.
4610 kmp_setting_t *kmp_stacksize =
4611 __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004612#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004613 kmp_setting_t *gomp_stacksize =
4614 __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004615#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004616 kmp_setting_t *omp_stacksize =
4617 __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004618
Jonathan Peyton30419822017-05-12 18:01:32 +00004619 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4620 // !!! Compiler does not understand rivals is used and optimizes out
4621 // assignments
4622 // !!! rivals[ i ++ ] = ...;
4623 static kmp_setting_t *volatile rivals[4];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004624 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004625#ifdef KMP_GOMP_COMPAT
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004626 static kmp_stg_ss_data_t gomp_data = {1024,
4627 CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004628#endif
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004629 static kmp_stg_ss_data_t omp_data = {1024,
4630 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004631 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004632
Jonathan Peyton30419822017-05-12 18:01:32 +00004633 rivals[i++] = kmp_stacksize;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004634#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004635 if (gomp_stacksize != NULL) {
4636 rivals[i++] = gomp_stacksize;
4637 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004638#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004639 rivals[i++] = omp_stacksize;
4640 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004641
Jonathan Peyton30419822017-05-12 18:01:32 +00004642 kmp_stacksize->data = &kmp_data;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004643#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004644 if (gomp_stacksize != NULL) {
4645 gomp_stacksize->data = &gomp_data;
4646 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004647#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004648 omp_stacksize->data = &omp_data;
4649 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004650
Jonathan Peyton30419822017-05-12 18:01:32 +00004651 { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
4652 kmp_setting_t *kmp_library =
4653 __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
4654 kmp_setting_t *omp_wait_policy =
4655 __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004656
Jonathan Peyton30419822017-05-12 18:01:32 +00004657 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4658 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004659 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
4660 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004661 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004662
Jonathan Peyton30419822017-05-12 18:01:32 +00004663 rivals[i++] = kmp_library;
4664 if (omp_wait_policy != NULL) {
4665 rivals[i++] = omp_wait_policy;
4666 }; // if
4667 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004668
Jonathan Peyton30419822017-05-12 18:01:32 +00004669 kmp_library->data = &kmp_data;
4670 if (omp_wait_policy != NULL) {
4671 omp_wait_policy->data = &omp_data;
4672 }; // if
4673 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004674
Jonathan Peyton30419822017-05-12 18:01:32 +00004675 { // Initialize KMP_ALL_THREADS, KMP_MAX_THREADS, and OMP_THREAD_LIMIT data.
4676 kmp_setting_t *kmp_all_threads =
4677 __kmp_stg_find("KMP_ALL_THREADS"); // 1st priority.
4678 kmp_setting_t *kmp_max_threads =
4679 __kmp_stg_find("KMP_MAX_THREADS"); // 2nd priority.
4680 kmp_setting_t *omp_thread_limit =
4681 __kmp_stg_find("OMP_THREAD_LIMIT"); // 3rd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004682
Jonathan Peyton30419822017-05-12 18:01:32 +00004683 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4684 static kmp_setting_t *volatile rivals[4];
4685 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004686
Jonathan Peyton30419822017-05-12 18:01:32 +00004687 rivals[i++] = kmp_all_threads;
4688 rivals[i++] = kmp_max_threads;
4689 if (omp_thread_limit != NULL) {
4690 rivals[i++] = omp_thread_limit;
4691 }; // if
4692 rivals[i++] = NULL;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004693 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
4694 kmp_max_threads->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004695 if (omp_thread_limit != NULL) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004696 omp_thread_limit->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004697 }; // if
4698 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004699
Alp Toker98758b02014-03-02 04:12:06 +00004700#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004701 { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
4702 kmp_setting_t *kmp_affinity =
4703 __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
4704 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004705
Jonathan Peyton30419822017-05-12 18:01:32 +00004706#ifdef KMP_GOMP_COMPAT
4707 kmp_setting_t *gomp_cpu_affinity =
4708 __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
4709 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
4710#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004711
Jonathan Peyton30419822017-05-12 18:01:32 +00004712 kmp_setting_t *omp_proc_bind =
4713 __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
4714 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004715
Jonathan Peyton30419822017-05-12 18:01:32 +00004716 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4717 static kmp_setting_t *volatile rivals[4];
4718 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004719
Jonathan Peyton30419822017-05-12 18:01:32 +00004720 rivals[i++] = kmp_affinity;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004721
Jonathan Peyton30419822017-05-12 18:01:32 +00004722#ifdef KMP_GOMP_COMPAT
4723 rivals[i++] = gomp_cpu_affinity;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004724 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004725#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004726
Jonathan Peyton30419822017-05-12 18:01:32 +00004727 rivals[i++] = omp_proc_bind;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004728 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004729 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004730
Jonathan Peyton30419822017-05-12 18:01:32 +00004731#if OMP_40_ENABLED
4732 static kmp_setting_t *volatile places_rivals[4];
4733 i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004734
Jonathan Peyton30419822017-05-12 18:01:32 +00004735 kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
4736 KMP_DEBUG_ASSERT(omp_places != NULL);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004737
Jonathan Peyton30419822017-05-12 18:01:32 +00004738 places_rivals[i++] = kmp_affinity;
4739#ifdef KMP_GOMP_COMPAT
4740 places_rivals[i++] = gomp_cpu_affinity;
4741#endif
4742 places_rivals[i++] = omp_places;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004743 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004744 places_rivals[i++] = NULL;
4745#endif
4746 }
Alp Toker98758b02014-03-02 04:12:06 +00004747#else
Jonathan Peyton30419822017-05-12 18:01:32 +00004748// KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
4749// OMP_PLACES not supported yet.
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004750#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004751
Jonathan Peyton30419822017-05-12 18:01:32 +00004752 { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
4753 kmp_setting_t *kmp_force_red =
4754 __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
4755 kmp_setting_t *kmp_determ_red =
4756 __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004757
Jonathan Peyton30419822017-05-12 18:01:32 +00004758 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4759 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004760 static kmp_stg_fr_data_t force_data = {1,
4761 CCAST(kmp_setting_t **, rivals)};
4762 static kmp_stg_fr_data_t determ_data = {0,
4763 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004764 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004765
Jonathan Peyton30419822017-05-12 18:01:32 +00004766 rivals[i++] = kmp_force_red;
4767 if (kmp_determ_red != NULL) {
4768 rivals[i++] = kmp_determ_red;
4769 }; // if
4770 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004771
Jonathan Peyton30419822017-05-12 18:01:32 +00004772 kmp_force_red->data = &force_data;
4773 if (kmp_determ_red != NULL) {
4774 kmp_determ_red->data = &determ_data;
4775 }; // if
4776 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004777
Jonathan Peyton30419822017-05-12 18:01:32 +00004778 initialized = 1;
4779 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004780
Jonathan Peyton30419822017-05-12 18:01:32 +00004781 // Reset flags.
4782 int i;
4783 for (i = 0; i < __kmp_stg_count; ++i) {
4784 __kmp_stg_table[i].set = 0;
4785 }; // for
Jim Cownie5e8470a2013-09-27 10:38:44 +00004786
4787} // __kmp_stg_init
4788
Jonathan Peyton30419822017-05-12 18:01:32 +00004789static void __kmp_stg_parse(char const *name, char const *value) {
4790 // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
4791 // really nameless, they are presented in environment block as
4792 // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
4793 if (name[0] == 0) {
4794 return;
4795 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004796
Jonathan Peyton30419822017-05-12 18:01:32 +00004797 if (value != NULL) {
4798 kmp_setting_t *setting = __kmp_stg_find(name);
4799 if (setting != NULL) {
4800 setting->parse(name, value, setting->data);
4801 setting->defined = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004802 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +00004803 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004804
4805} // __kmp_stg_parse
4806
Jonathan Peyton30419822017-05-12 18:01:32 +00004807static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
4808 char const *name, // Name of variable.
4809 char const *value, // Value of the variable.
4810 kmp_setting_t **rivals // List of rival settings (must include current one).
4811 ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004812
Jonathan Peyton30419822017-05-12 18:01:32 +00004813 if (rivals == NULL) {
4814 return 0;
4815 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004816
Jonathan Peyton30419822017-05-12 18:01:32 +00004817 // Loop thru higher priority settings (listed before current).
4818 int i = 0;
4819 for (; strcmp(rivals[i]->name, name) != 0; i++) {
4820 KMP_DEBUG_ASSERT(rivals[i] != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004821
Alp Toker763b9392014-02-28 09:42:41 +00004822#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004823 if (rivals[i] == __kmp_affinity_notype) {
4824 // If KMP_AFFINITY is specified without a type name,
4825 // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
4826 continue;
4827 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004828#endif
4829
Jonathan Peyton30419822017-05-12 18:01:32 +00004830 if (rivals[i]->set) {
4831 KMP_WARNING(StgIgnored, name, rivals[i]->name);
4832 return 1;
4833 }; // if
4834 }; // while
Jim Cownie5e8470a2013-09-27 10:38:44 +00004835
Jonathan Peyton30419822017-05-12 18:01:32 +00004836 ++i; // Skip current setting.
4837 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004838
4839}; // __kmp_stg_check_rivals
4840
Jonathan Peyton30419822017-05-12 18:01:32 +00004841static int __kmp_env_toPrint(char const *name, int flag) {
4842 int rc = 0;
4843 kmp_setting_t *setting = __kmp_stg_find(name);
4844 if (setting != NULL) {
4845 rc = setting->defined;
4846 if (flag >= 0) {
4847 setting->defined = flag;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004848 }; // if
Jonathan Peyton30419822017-05-12 18:01:32 +00004849 }; // if
4850 return rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004851}
4852
Jonathan Peyton30419822017-05-12 18:01:32 +00004853static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004854
Jonathan Peyton30419822017-05-12 18:01:32 +00004855 char const *value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004856
Jonathan Peyton30419822017-05-12 18:01:32 +00004857 /* OMP_NUM_THREADS */
4858 value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
4859 if (value) {
4860 ompc_set_num_threads(__kmp_dflt_team_nth);
4861 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004862
Jonathan Peyton30419822017-05-12 18:01:32 +00004863 /* KMP_BLOCKTIME */
4864 value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
4865 if (value) {
4866 kmpc_set_blocktime(__kmp_dflt_blocktime);
4867 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004868
Jonathan Peyton30419822017-05-12 18:01:32 +00004869 /* OMP_NESTED */
4870 value = __kmp_env_blk_var(block, "OMP_NESTED");
4871 if (value) {
4872 ompc_set_nested(__kmp_dflt_nested);
4873 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004874
Jonathan Peyton30419822017-05-12 18:01:32 +00004875 /* OMP_DYNAMIC */
4876 value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
4877 if (value) {
4878 ompc_set_dynamic(__kmp_global.g.g_dynamic);
4879 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004880
4881}
4882
Jonathan Peyton30419822017-05-12 18:01:32 +00004883void __kmp_env_initialize(char const *string) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004884
Jonathan Peyton30419822017-05-12 18:01:32 +00004885 kmp_env_blk_t block;
4886 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004887
Jonathan Peyton30419822017-05-12 18:01:32 +00004888 __kmp_stg_init();
Jim Cownie5e8470a2013-09-27 10:38:44 +00004889
Jonathan Peyton30419822017-05-12 18:01:32 +00004890 // Hack!!!
4891 if (string == NULL) {
4892 // __kmp_max_nth = __kmp_sys_max_nth;
4893 __kmp_threads_capacity =
4894 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
4895 }; // if
4896 __kmp_env_blk_init(&block, string);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004897
Jonathan Peyton30419822017-05-12 18:01:32 +00004898 // update the set flag on all entries that have an env var
4899 for (i = 0; i < block.count; ++i) {
4900 if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
4901 continue;
4902 }
4903 if (block.vars[i].value == NULL) {
4904 continue;
4905 }
4906 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
4907 if (setting != NULL) {
4908 setting->set = 1;
4909 }
4910 }; // for i
Jim Cownie5e8470a2013-09-27 10:38:44 +00004911
Jonathan Peyton30419822017-05-12 18:01:32 +00004912 // We need to know if blocktime was set when processing OMP_WAIT_POLICY
4913 blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
Jonathan Peyton50e8f182016-04-04 19:38:32 +00004914
Jonathan Peyton30419822017-05-12 18:01:32 +00004915 // Special case. If we parse environment, not a string, process KMP_WARNINGS
4916 // first.
4917 if (string == NULL) {
4918 char const *name = "KMP_WARNINGS";
4919 char const *value = __kmp_env_blk_var(&block, name);
4920 __kmp_stg_parse(name, value);
4921 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00004922
Alp Toker763b9392014-02-28 09:42:41 +00004923#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004924 // Special case. KMP_AFFINITY is not a rival to other affinity env vars
4925 // if no affinity type is specified. We want to allow
4926 // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
4927 // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
4928 // affinity mechanism.
4929 __kmp_affinity_notype = NULL;
4930 char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
4931 if (aff_str != NULL) {
4932// Check if the KMP_AFFINITY type is specified in the string.
4933// We just search the string for "compact", "scatter", etc.
4934// without really parsing the string. The syntax of the
4935// KMP_AFFINITY env var is such that none of the affinity
4936// type names can appear anywhere other that the type
4937// specifier, even as substrings.
4938//
4939// I can't find a case-insensitive version of strstr on Windows* OS.
4940// Use the case-sensitive version for now.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004941
Jonathan Peyton30419822017-05-12 18:01:32 +00004942#if KMP_OS_WINDOWS
4943#define FIND strstr
4944#else
4945#define FIND strcasestr
4946#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004947
Jonathan Peyton30419822017-05-12 18:01:32 +00004948 if ((FIND(aff_str, "none") == NULL) &&
4949 (FIND(aff_str, "physical") == NULL) &&
4950 (FIND(aff_str, "logical") == NULL) &&
4951 (FIND(aff_str, "compact") == NULL) &&
4952 (FIND(aff_str, "scatter") == NULL) &&
4953 (FIND(aff_str, "explicit") == NULL) &&
4954 (FIND(aff_str, "balanced") == NULL) &&
4955 (FIND(aff_str, "disabled") == NULL)) {
4956 __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
4957 } else {
4958 // A new affinity type is specified.
4959 // Reset the affinity flags to their default values,
4960 // in case this is called from kmp_set_defaults().
4961 __kmp_affinity_type = affinity_default;
4962 __kmp_affinity_gran = affinity_gran_default;
4963 __kmp_affinity_top_method = affinity_top_method_default;
4964 __kmp_affinity_respect_mask = affinity_respect_mask_default;
4965 }
4966#undef FIND
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004967
4968#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004969 // Also reset the affinity flags if OMP_PROC_BIND is specified.
4970 aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
4971 if (aff_str != NULL) {
4972 __kmp_affinity_type = affinity_default;
4973 __kmp_affinity_gran = affinity_gran_default;
4974 __kmp_affinity_top_method = affinity_top_method_default;
4975 __kmp_affinity_respect_mask = affinity_respect_mask_default;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004976 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004977#endif /* OMP_40_ENABLED */
4978 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004979
Alp Toker763b9392014-02-28 09:42:41 +00004980#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00004981
4982#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004983 // Set up the nested proc bind type vector.
4984 if (__kmp_nested_proc_bind.bind_types == NULL) {
4985 __kmp_nested_proc_bind.bind_types =
4986 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
4987 if (__kmp_nested_proc_bind.bind_types == NULL) {
4988 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004989 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004990 __kmp_nested_proc_bind.size = 1;
4991 __kmp_nested_proc_bind.used = 1;
4992#if KMP_AFFINITY_SUPPORTED
4993 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
4994#else
4995 // default proc bind is false if affinity not supported
4996 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
4997#endif
4998 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004999#endif /* OMP_40_ENABLED */
5000
Jonathan Peyton30419822017-05-12 18:01:32 +00005001 // Now process all of the settings.
5002 for (i = 0; i < block.count; ++i) {
5003 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
5004 }; // for i
Jim Cownie5e8470a2013-09-27 10:38:44 +00005005
Jonathan Peyton30419822017-05-12 18:01:32 +00005006 // If user locks have been allocated yet, don't reset the lock vptr table.
5007 if (!__kmp_init_user_locks) {
5008 if (__kmp_user_lock_kind == lk_default) {
5009 __kmp_user_lock_kind = lk_queuing;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005010 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005011#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00005012 __kmp_init_dynamic_user_locks();
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005013#else
Jonathan Peyton30419822017-05-12 18:01:32 +00005014 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005015#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005016 } else {
5017 KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
5018 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
5019// Binds lock functions again to follow the transition between different
5020// KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
5021// as we do not allow lock kind changes after making a call to any
5022// user lock functions (true).
5023#if KMP_USE_DYNAMIC_LOCK
5024 __kmp_init_dynamic_user_locks();
5025#else
5026 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5027#endif
5028 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005029
Alp Toker763b9392014-02-28 09:42:41 +00005030#if KMP_AFFINITY_SUPPORTED
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005031
Jonathan Peyton30419822017-05-12 18:01:32 +00005032 if (!TCR_4(__kmp_init_middle)) {
5033 // Determine if the machine/OS is actually capable of supporting
5034 // affinity.
5035 const char *var = "KMP_AFFINITY";
5036 KMPAffinity::pick_api();
Jonathan Peytone3e2aaf2017-05-31 20:35:22 +00005037#if KMP_USE_HWLOC
5038 // If Hwloc topology discovery was requested but affinity was also disabled,
5039 // then tell user that Hwloc request is being ignored and use default
5040 // topology discovery method.
5041 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
5042 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
5043 KMP_WARNING(AffIgnoringHwloc, var);
5044 __kmp_affinity_top_method = affinity_top_method_all;
5045 }
5046#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005047 if (__kmp_affinity_type == affinity_disabled) {
5048 KMP_AFFINITY_DISABLE();
5049 } else if (!KMP_AFFINITY_CAPABLE()) {
5050 __kmp_affinity_dispatch->determine_capable(var);
5051 if (!KMP_AFFINITY_CAPABLE()) {
5052 if (__kmp_affinity_verbose ||
5053 (__kmp_affinity_warnings &&
5054 (__kmp_affinity_type != affinity_default) &&
5055 (__kmp_affinity_type != affinity_none) &&
5056 (__kmp_affinity_type != affinity_disabled))) {
5057 KMP_WARNING(AffNotSupported, var);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005058 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005059 __kmp_affinity_type = affinity_disabled;
5060 __kmp_affinity_respect_mask = 0;
5061 __kmp_affinity_gran = affinity_gran_fine;
5062 }
5063 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005064
Jonathan Peyton30419822017-05-12 18:01:32 +00005065#if OMP_40_ENABLED
5066 if (__kmp_affinity_type == affinity_disabled) {
5067 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5068 } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
5069 // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
5070 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
5071 }
5072#endif /* OMP_40_ENABLED */
5073
5074 if (KMP_AFFINITY_CAPABLE()) {
5075
5076#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005077 // This checks to see if the initial affinity mask is equal
5078 // to a single windows processor group. If it is, then we do
5079 // not respect the initial affinity mask and instead, use the
5080 // entire machine.
5081 bool exactly_one_group = false;
5082 if (__kmp_num_proc_groups > 1) {
5083 int group;
5084 bool within_one_group;
5085 // Get the initial affinity mask and determine if it is
5086 // contained within a single group.
5087 kmp_affin_mask_t *init_mask;
5088 KMP_CPU_ALLOC(init_mask);
5089 __kmp_get_system_affinity(init_mask, TRUE);
5090 group = __kmp_get_proc_group(init_mask);
5091 within_one_group = (group >= 0);
5092 // If the initial affinity is within a single group,
5093 // then determine if it is equal to that single group.
5094 if (within_one_group) {
5095 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
5096 int num_bits_in_mask = 0;
5097 for (int bit = init_mask->begin(); bit != init_mask->end();
5098 bit = init_mask->next(bit))
5099 num_bits_in_mask++;
5100 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
5101 }
5102 KMP_CPU_FREE(init_mask);
5103 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005104
5105 // Handle the Win 64 group affinity stuff if there are multiple
5106 // processor groups, or if the user requested it, and OMP 4.0
5107 // affinity is not in effect.
5108 if (((__kmp_num_proc_groups > 1) &&
5109 (__kmp_affinity_type == affinity_default)
5110#if OMP_40_ENABLED
5111 && (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default))
5112#endif
5113 || (__kmp_affinity_top_method == affinity_top_method_group)) {
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005114 if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
5115 exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005116 __kmp_affinity_respect_mask = FALSE;
5117 }
5118 if (__kmp_affinity_type == affinity_default) {
5119 __kmp_affinity_type = affinity_compact;
5120#if OMP_40_ENABLED
5121 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5122#endif
5123 }
5124 if (__kmp_affinity_top_method == affinity_top_method_default) {
5125 if (__kmp_affinity_gran == affinity_gran_default) {
5126 __kmp_affinity_top_method = affinity_top_method_group;
5127 __kmp_affinity_gran = affinity_gran_group;
5128 } else if (__kmp_affinity_gran == affinity_gran_group) {
5129 __kmp_affinity_top_method = affinity_top_method_group;
5130 } else {
5131 __kmp_affinity_top_method = affinity_top_method_all;
5132 }
5133 } else if (__kmp_affinity_top_method == affinity_top_method_group) {
5134 if (__kmp_affinity_gran == affinity_gran_default) {
5135 __kmp_affinity_gran = affinity_gran_group;
5136 } else if ((__kmp_affinity_gran != affinity_gran_group) &&
5137 (__kmp_affinity_gran != affinity_gran_fine) &&
5138 (__kmp_affinity_gran != affinity_gran_thread)) {
5139 const char *str = NULL;
5140 switch (__kmp_affinity_gran) {
5141 case affinity_gran_core:
5142 str = "core";
5143 break;
5144 case affinity_gran_package:
5145 str = "package";
5146 break;
5147 case affinity_gran_node:
5148 str = "node";
5149 break;
5150 default:
5151 KMP_DEBUG_ASSERT(0);
5152 }
5153 KMP_WARNING(AffGranTopGroup, var, str);
5154 __kmp_affinity_gran = affinity_gran_fine;
5155 }
5156 } else {
5157 if (__kmp_affinity_gran == affinity_gran_default) {
5158 __kmp_affinity_gran = affinity_gran_core;
5159 } else if (__kmp_affinity_gran == affinity_gran_group) {
5160 const char *str = NULL;
5161 switch (__kmp_affinity_type) {
5162 case affinity_physical:
5163 str = "physical";
5164 break;
5165 case affinity_logical:
5166 str = "logical";
5167 break;
5168 case affinity_compact:
5169 str = "compact";
5170 break;
5171 case affinity_scatter:
5172 str = "scatter";
5173 break;
5174 case affinity_explicit:
5175 str = "explicit";
5176 break;
5177 // No MIC on windows, so no affinity_balanced case
5178 default:
5179 KMP_DEBUG_ASSERT(0);
5180 }
5181 KMP_WARNING(AffGranGroupType, var, str);
5182 __kmp_affinity_gran = affinity_gran_core;
5183 }
5184 }
5185 } else
5186
5187#endif /* KMP_GROUP_AFFINITY */
5188
5189 {
5190 if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
5191#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005192 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005193 __kmp_affinity_respect_mask = FALSE;
5194 } else
5195#endif /* KMP_GROUP_AFFINITY */
5196 {
5197 __kmp_affinity_respect_mask = TRUE;
5198 }
5199 }
5200#if OMP_40_ENABLED
5201 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
5202 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
5203 if (__kmp_affinity_type == affinity_default) {
5204 __kmp_affinity_type = affinity_compact;
5205 __kmp_affinity_dups = FALSE;
5206 }
5207 } else
5208#endif /* OMP_40_ENABLED */
5209 if (__kmp_affinity_type == affinity_default) {
5210#if OMP_40_ENABLED
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005211#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005212 if (__kmp_mic_type != non_mic) {
5213 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5214 } else
5215#endif
5216 {
Andrey Churbanov94e569e2015-03-10 09:19:47 +00005217 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
Jonathan Peyton30419822017-05-12 18:01:32 +00005218 }
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005219#endif /* OMP_40_ENABLED */
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005220#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005221 if (__kmp_mic_type != non_mic) {
5222 __kmp_affinity_type = affinity_scatter;
5223 } else
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005224#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005225 {
5226 __kmp_affinity_type = affinity_none;
5227 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005228 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005229 if ((__kmp_affinity_gran == affinity_gran_default) &&
5230 (__kmp_affinity_gran_levels < 0)) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005231#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005232 if (__kmp_mic_type != non_mic) {
5233 __kmp_affinity_gran = affinity_gran_fine;
5234 } else
5235#endif
5236 {
5237 __kmp_affinity_gran = affinity_gran_core;
5238 }
5239 }
5240 if (__kmp_affinity_top_method == affinity_top_method_default) {
5241 __kmp_affinity_top_method = affinity_top_method_all;
5242 }
5243 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005244 }
5245
Jonathan Peyton30419822017-05-12 18:01:32 +00005246 K_DIAG(1, ("__kmp_affinity_type == %d\n", __kmp_affinity_type));
5247 K_DIAG(1, ("__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
5248 K_DIAG(1, ("__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
5249 K_DIAG(1, ("__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
5250 K_DIAG(1, ("__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
5251 K_DIAG(1, ("__kmp_affinity_respect_mask == %d\n",
5252 __kmp_affinity_respect_mask));
5253 K_DIAG(1, ("__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
5254
5255 KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
5256#if OMP_40_ENABLED
5257 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
5258#endif
5259 }
5260
Alp Toker763b9392014-02-28 09:42:41 +00005261#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005262
Jonathan Peyton30419822017-05-12 18:01:32 +00005263 if (__kmp_version) {
5264 __kmp_print_version_1();
5265 }; // if
Jim Cownie5e8470a2013-09-27 10:38:44 +00005266
Jonathan Peyton30419822017-05-12 18:01:32 +00005267 // Post-initialization step: some env. vars need their value's further
5268 // processing
5269 if (string != NULL) { // kmp_set_defaults() was called
5270 __kmp_aux_env_initialize(&block);
5271 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005272
Jonathan Peyton30419822017-05-12 18:01:32 +00005273 __kmp_env_blk_free(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005274
Jonathan Peyton30419822017-05-12 18:01:32 +00005275 KMP_MB();
Jim Cownie5e8470a2013-09-27 10:38:44 +00005276
5277} // __kmp_env_initialize
5278
Jonathan Peyton30419822017-05-12 18:01:32 +00005279void __kmp_env_print() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005280
Jonathan Peyton30419822017-05-12 18:01:32 +00005281 kmp_env_blk_t block;
5282 int i;
5283 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005284
Jonathan Peyton30419822017-05-12 18:01:32 +00005285 __kmp_stg_init();
5286 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005287
Jonathan Peyton30419822017-05-12 18:01:32 +00005288 __kmp_env_blk_init(&block, NULL);
5289 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005290
Jonathan Peyton30419822017-05-12 18:01:32 +00005291 // Print real environment values.
5292 __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
5293 for (i = 0; i < block.count; ++i) {
5294 char const *name = block.vars[i].name;
5295 char const *value = block.vars[i].value;
5296 if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
5297 strncmp(name, "OMP_", 4) == 0
5298#ifdef KMP_GOMP_COMPAT
5299 || strncmp(name, "GOMP_", 5) == 0
5300#endif // KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00005301 ) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005302 __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
5303 }; // if
5304 }; // for
5305 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005306
Jonathan Peyton30419822017-05-12 18:01:32 +00005307 // Print internal (effective) settings.
5308 __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
5309 for (int i = 0; i < __kmp_stg_count; ++i) {
5310 if (__kmp_stg_table[i].print != NULL) {
5311 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5312 __kmp_stg_table[i].data);
5313 }; // if
5314 }; // for
Jim Cownie5e8470a2013-09-27 10:38:44 +00005315
Jonathan Peyton30419822017-05-12 18:01:32 +00005316 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005317
Jonathan Peyton30419822017-05-12 18:01:32 +00005318 __kmp_env_blk_free(&block);
5319 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005320
Jonathan Peyton30419822017-05-12 18:01:32 +00005321 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005322
5323} // __kmp_env_print
5324
Jim Cownie5e8470a2013-09-27 10:38:44 +00005325#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005326void __kmp_env_print_2() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005327
Jonathan Peyton30419822017-05-12 18:01:32 +00005328 kmp_env_blk_t block;
5329 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005330
Jonathan Peyton30419822017-05-12 18:01:32 +00005331 __kmp_env_format = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005332
Jonathan Peyton30419822017-05-12 18:01:32 +00005333 __kmp_stg_init();
5334 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005335
Jonathan Peyton30419822017-05-12 18:01:32 +00005336 __kmp_env_blk_init(&block, NULL);
5337 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005338
Jonathan Peyton30419822017-05-12 18:01:32 +00005339 __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
5340 __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005341
Jonathan Peyton30419822017-05-12 18:01:32 +00005342 for (int i = 0; i < __kmp_stg_count; ++i) {
5343 if (__kmp_stg_table[i].print != NULL &&
5344 ((__kmp_display_env &&
5345 strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
5346 __kmp_display_env_verbose)) {
5347 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5348 __kmp_stg_table[i].data);
5349 }; // if
5350 }; // for
Jim Cownie5e8470a2013-09-27 10:38:44 +00005351
Jonathan Peyton30419822017-05-12 18:01:32 +00005352 __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
5353 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005354
Jonathan Peyton30419822017-05-12 18:01:32 +00005355 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005356
Jonathan Peyton30419822017-05-12 18:01:32 +00005357 __kmp_env_blk_free(&block);
5358 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005359
Jonathan Peyton30419822017-05-12 18:01:32 +00005360 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005361
5362} // __kmp_env_print_2
5363#endif // OMP_40_ENABLED
5364
Jim Cownie5e8470a2013-09-27 10:38:44 +00005365// end of file