blob: c4fb9f2d90d1f9c51b9b30413d0c3cae2336a8b4 [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.
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000140 }
141 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000142 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);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000285 }
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;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000300 }
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);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000315 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000316#endif
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000317 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000318 } 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;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000325 }
326 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000327 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);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000335 }
336 }
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;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000365 }
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;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000373 }
374 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000375 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);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000383 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000384 *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// -----------------------------------------------------------------------------
Jonathan Peytonf4392462017-07-27 20:58:41 +0000572// KMP_DEVICE_THREAD_LIMIT, KMP_ALL_THREADS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000573
Jonathan Peyton09244f32017-07-26 20:07:58 +0000574static void __kmp_stg_parse_device_thread_limit(char const *name,
575 char const *value, void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +0000576 kmp_setting_t **rivals = (kmp_setting_t **)data;
577 int rc;
Jonathan Peyton09244f32017-07-26 20:07:58 +0000578 if (strcmp(name, "KMP_ALL_THREADS") == 0) {
579 KMP_INFORM(EnvVarDeprecated, name, "KMP_DEVICE_THREAD_LIMIT");
580 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000581 rc = __kmp_stg_check_rivals(name, value, rivals);
582 if (rc) {
583 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000584 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000585 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
586 __kmp_max_nth = __kmp_xproc;
587 __kmp_allThreadsSpecified = 1;
588 } else {
589 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
590 __kmp_allThreadsSpecified = 0;
591 }
592 K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000593
Jonathan Peyton09244f32017-07-26 20:07:58 +0000594} // __kmp_stg_parse_device_thread_limit
Jim Cownie5e8470a2013-09-27 10:38:44 +0000595
Jonathan Peyton09244f32017-07-26 20:07:58 +0000596static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
597 char const *name, void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +0000598 __kmp_stg_print_int(buffer, name, __kmp_max_nth);
Jonathan Peyton09244f32017-07-26 20:07:58 +0000599} // __kmp_stg_print_device_thread_limit
Jim Cownie5e8470a2013-09-27 10:38:44 +0000600
Jonathan Peyton30419822017-05-12 18:01:32 +0000601// -----------------------------------------------------------------------------
Jonathan Peytonf4392462017-07-27 20:58:41 +0000602// OMP_THREAD_LIMIT
603static void __kmp_stg_parse_thread_limit(char const *name, char const *value,
604 void *data) {
605 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
606 K_DIAG(1, ("__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));
607
608} // __kmp_stg_parse_thread_limit
609
610static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
611 char const *name, void *data) {
612 __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
613} // __kmp_stg_print_thread_limit
614
615// -----------------------------------------------------------------------------
Jonathan Peyton4f90c822017-08-02 20:04:45 +0000616// KMP_TEAMS_THREAD_LIMIT
617static void __kmp_stg_parse_teams_thread_limit(char const *name,
618 char const *value, void *data) {
619 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
620} // __kmp_stg_teams_thread_limit
621
622static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
623 char const *name, void *data) {
624 __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
625} // __kmp_stg_print_teams_thread_limit
626
627// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000628// KMP_BLOCKTIME
Jim Cownie5e8470a2013-09-27 10:38:44 +0000629
Jonathan Peyton30419822017-05-12 18:01:32 +0000630static void __kmp_stg_parse_blocktime(char const *name, char const *value,
631 void *data) {
632 __kmp_dflt_blocktime = __kmp_convert_to_milliseconds(value);
633 if (__kmp_dflt_blocktime < 0) {
634 __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
635 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
636 __kmp_msg_null);
637 KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime);
638 __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
639 } else {
640 if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
641 __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
642 __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
643 __kmp_msg_null);
644 KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime);
645 } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
646 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
647 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
648 __kmp_msg_null);
649 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000650 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000651 __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000652 }
Jonathan Peytone1c7c132016-10-07 18:12:19 +0000653#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +0000654 // calculate number of monitor thread wakeup intervals corresponding to
655 // blocktime.
656 __kmp_monitor_wakeups =
657 KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
658 __kmp_bt_intervals =
659 KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
Jonathan Peytone1c7c132016-10-07 18:12:19 +0000660#endif
Jonathan Peyton30419822017-05-12 18:01:32 +0000661 K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
662 if (__kmp_env_blocktime) {
663 K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
664 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000665} // __kmp_stg_parse_blocktime
666
Jonathan Peyton30419822017-05-12 18:01:32 +0000667static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
668 void *data) {
669 __kmp_stg_print_int(buffer, name, __kmp_dflt_blocktime);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000670} // __kmp_stg_print_blocktime
671
Jonathan Peytond74d8902017-07-25 18:20:16 +0000672// Used for OMP_WAIT_POLICY
673static char const *blocktime_str = NULL;
674
Jonathan Peyton30419822017-05-12 18:01:32 +0000675// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000676// KMP_DUPLICATE_LIB_OK
Jim Cownie5e8470a2013-09-27 10:38:44 +0000677
Jonathan Peyton30419822017-05-12 18:01:32 +0000678static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
679 char const *value, void *data) {
680 /* actually this variable is not supported, put here for compatibility with
681 earlier builds and for static/dynamic combination */
682 __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000683} // __kmp_stg_parse_duplicate_lib_ok
684
Jonathan Peyton30419822017-05-12 18:01:32 +0000685static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
686 char const *name, void *data) {
687 __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000688} // __kmp_stg_print_duplicate_lib_ok
689
Jonathan Peyton30419822017-05-12 18:01:32 +0000690// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000691// KMP_INHERIT_FP_CONTROL
Jim Cownie5e8470a2013-09-27 10:38:44 +0000692
693#if KMP_ARCH_X86 || KMP_ARCH_X86_64
694
Jonathan Peyton30419822017-05-12 18:01:32 +0000695static void __kmp_stg_parse_inherit_fp_control(char const *name,
696 char const *value, void *data) {
697 __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000698} // __kmp_stg_parse_inherit_fp_control
699
Jonathan Peyton30419822017-05-12 18:01:32 +0000700static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
701 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000702#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000703 __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000704#endif /* KMP_DEBUG */
705} // __kmp_stg_print_inherit_fp_control
706
707#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
708
Jonathan Peyton30419822017-05-12 18:01:32 +0000709// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000710// KMP_LIBRARY, OMP_WAIT_POLICY
Jim Cownie5e8470a2013-09-27 10:38:44 +0000711
Jonathan Peyton30419822017-05-12 18:01:32 +0000712static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
713 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000714
Jonathan Peyton30419822017-05-12 18:01:32 +0000715 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
716 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000717
Jonathan Peyton30419822017-05-12 18:01:32 +0000718 rc = __kmp_stg_check_rivals(name, value, wait->rivals);
719 if (rc) {
720 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000721 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000722
Jonathan Peyton30419822017-05-12 18:01:32 +0000723 if (wait->omp) {
724 if (__kmp_str_match("ACTIVE", 1, value)) {
725 __kmp_library = library_turnaround;
726 if (blocktime_str == NULL) {
727 // KMP_BLOCKTIME not specified, so set default to "infinite".
728 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
729 }
730 } else if (__kmp_str_match("PASSIVE", 1, value)) {
731 __kmp_library = library_throughput;
732 if (blocktime_str == NULL) {
733 // KMP_BLOCKTIME not specified, so set default to 0.
734 __kmp_dflt_blocktime = 0;
735 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000736 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +0000737 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000738 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000739 } else {
740 if (__kmp_str_match("serial", 1, value)) { /* S */
741 __kmp_library = library_serial;
742 } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
743 __kmp_library = library_throughput;
744 } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
745 __kmp_library = library_turnaround;
746 } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
747 __kmp_library = library_turnaround;
748 } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
749 __kmp_library = library_throughput;
750 } else {
751 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000752 }
753 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000754 __kmp_aux_set_library(__kmp_library);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000755
756} // __kmp_stg_parse_wait_policy
757
Jonathan Peyton30419822017-05-12 18:01:32 +0000758static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
759 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000760
Jonathan Peyton30419822017-05-12 18:01:32 +0000761 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
762 char const *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000763
Jonathan Peyton30419822017-05-12 18:01:32 +0000764 if (wait->omp) {
765 switch (__kmp_library) {
766 case library_turnaround: {
767 value = "ACTIVE";
768 } break;
769 case library_throughput: {
770 value = "PASSIVE";
771 } break;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000772 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000773 } else {
774 switch (__kmp_library) {
775 case library_serial: {
776 value = "serial";
777 } break;
778 case library_turnaround: {
779 value = "turnaround";
780 } break;
781 case library_throughput: {
782 value = "throughput";
783 } break;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000784 }
785 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000786 if (value != NULL) {
787 __kmp_stg_print_str(buffer, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000788 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000789
790} // __kmp_stg_print_wait_policy
791
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000792#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +0000793// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000794// KMP_MONITOR_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000795
Jonathan Peyton30419822017-05-12 18:01:32 +0000796static void __kmp_stg_parse_monitor_stacksize(char const *name,
797 char const *value, void *data) {
798 __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
799 NULL, &__kmp_monitor_stksize, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000800} // __kmp_stg_parse_monitor_stacksize
801
Jonathan Peyton30419822017-05-12 18:01:32 +0000802static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
803 char const *name, void *data) {
804 if (__kmp_env_format) {
805 if (__kmp_monitor_stksize > 0)
806 KMP_STR_BUF_PRINT_NAME_EX(name);
807 else
808 KMP_STR_BUF_PRINT_NAME;
809 } else {
810 __kmp_str_buf_print(buffer, " %s", name);
811 }
812 if (__kmp_monitor_stksize > 0) {
813 __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
814 } else {
815 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
816 }
817 if (__kmp_env_format && __kmp_monitor_stksize) {
818 __kmp_str_buf_print(buffer, "'\n");
819 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000820} // __kmp_stg_print_monitor_stacksize
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000821#endif // KMP_USE_MONITOR
Jim Cownie5e8470a2013-09-27 10:38:44 +0000822
Jonathan Peyton30419822017-05-12 18:01:32 +0000823// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000824// KMP_SETTINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000825
Jonathan Peyton30419822017-05-12 18:01:32 +0000826static void __kmp_stg_parse_settings(char const *name, char const *value,
827 void *data) {
828 __kmp_stg_parse_bool(name, value, &__kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000829} // __kmp_stg_parse_settings
830
Jonathan Peyton30419822017-05-12 18:01:32 +0000831static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
832 void *data) {
833 __kmp_stg_print_bool(buffer, name, __kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000834} // __kmp_stg_print_settings
835
Jonathan Peyton30419822017-05-12 18:01:32 +0000836// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000837// KMP_STACKPAD
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000838
Jonathan Peyton30419822017-05-12 18:01:32 +0000839static void __kmp_stg_parse_stackpad(char const *name, char const *value,
840 void *data) {
841 __kmp_stg_parse_int(name, // Env var name
842 value, // Env var value
843 KMP_MIN_STKPADDING, // Min value
844 KMP_MAX_STKPADDING, // Max value
845 &__kmp_stkpadding // Var to initialize
846 );
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000847} // __kmp_stg_parse_stackpad
848
Jonathan Peyton30419822017-05-12 18:01:32 +0000849static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
850 void *data) {
851 __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000852} // __kmp_stg_print_stackpad
853
Jonathan Peyton30419822017-05-12 18:01:32 +0000854// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000855// KMP_STACKOFFSET
Jim Cownie5e8470a2013-09-27 10:38:44 +0000856
Jonathan Peyton30419822017-05-12 18:01:32 +0000857static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
858 void *data) {
859 __kmp_stg_parse_size(name, // Env var name
860 value, // Env var value
861 KMP_MIN_STKOFFSET, // Min value
862 KMP_MAX_STKOFFSET, // Max value
863 NULL, //
864 &__kmp_stkoffset, // Var to initialize
865 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000866} // __kmp_stg_parse_stackoffset
867
Jonathan Peyton30419822017-05-12 18:01:32 +0000868static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
869 void *data) {
870 __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000871} // __kmp_stg_print_stackoffset
872
Jonathan Peyton30419822017-05-12 18:01:32 +0000873// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000874// KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000875
Jonathan Peyton30419822017-05-12 18:01:32 +0000876static void __kmp_stg_parse_stacksize(char const *name, char const *value,
877 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000878
Jonathan Peyton30419822017-05-12 18:01:32 +0000879 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
880 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000881
Jonathan Peyton30419822017-05-12 18:01:32 +0000882 rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
883 if (rc) {
884 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000885 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000886 __kmp_stg_parse_size(name, // Env var name
887 value, // Env var value
888 __kmp_sys_min_stksize, // Min value
889 KMP_MAX_STKSIZE, // Max value
890 &__kmp_env_stksize, //
891 &__kmp_stksize, // Var to initialize
892 stacksize->factor);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000893
894} // __kmp_stg_parse_stacksize
895
Jonathan Peyton30419822017-05-12 18:01:32 +0000896// This function is called for printing both KMP_STACKSIZE (factor is 1) and
897// OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
898// OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
899// customer request in future.
900static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
901 void *data) {
902 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
903 if (__kmp_env_format) {
904 KMP_STR_BUF_PRINT_NAME_EX(name);
905 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
906 ? __kmp_stksize / stacksize->factor
907 : __kmp_stksize);
908 __kmp_str_buf_print(buffer, "'\n");
909 } else {
910 __kmp_str_buf_print(buffer, " %s=", name);
911 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
912 ? __kmp_stksize / stacksize->factor
913 : __kmp_stksize);
914 __kmp_str_buf_print(buffer, "\n");
915 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000916} // __kmp_stg_print_stacksize
917
Jonathan Peyton30419822017-05-12 18:01:32 +0000918// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000919// KMP_VERSION
Jim Cownie5e8470a2013-09-27 10:38:44 +0000920
Jonathan Peyton30419822017-05-12 18:01:32 +0000921static void __kmp_stg_parse_version(char const *name, char const *value,
922 void *data) {
923 __kmp_stg_parse_bool(name, value, &__kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000924} // __kmp_stg_parse_version
925
Jonathan Peyton30419822017-05-12 18:01:32 +0000926static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
927 void *data) {
928 __kmp_stg_print_bool(buffer, name, __kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000929} // __kmp_stg_print_version
930
Jonathan Peyton30419822017-05-12 18:01:32 +0000931// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000932// KMP_WARNINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000933
Jonathan Peyton30419822017-05-12 18:01:32 +0000934static void __kmp_stg_parse_warnings(char const *name, char const *value,
935 void *data) {
936 __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
937 if (__kmp_generate_warnings != kmp_warnings_off) {
938 // AC: only 0/1 values documented, so reset to explicit to distinguish from
939 // default setting
940 __kmp_generate_warnings = kmp_warnings_explicit;
941 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000942} // __kmp_stg_parse_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000943
Jonathan Peyton30419822017-05-12 18:01:32 +0000944static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
945 void *data) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000946 // AC: TODO: change to print_int? (needs documentation change)
947 __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
948} // __kmp_stg_print_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000949
Jonathan Peyton30419822017-05-12 18:01:32 +0000950// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000951// OMP_NESTED, OMP_NUM_THREADS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000952
Jonathan Peyton30419822017-05-12 18:01:32 +0000953static void __kmp_stg_parse_nested(char const *name, char const *value,
954 void *data) {
955 __kmp_stg_parse_bool(name, value, &__kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000956} // __kmp_stg_parse_nested
957
Jonathan Peyton30419822017-05-12 18:01:32 +0000958static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
959 void *data) {
960 __kmp_stg_print_bool(buffer, name, __kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000961} // __kmp_stg_print_nested
962
Jonathan Peyton30419822017-05-12 18:01:32 +0000963static void __kmp_parse_nested_num_threads(const char *var, const char *env,
964 kmp_nested_nthreads_t *nth_array) {
965 const char *next = env;
966 const char *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000967
Jonathan Peyton30419822017-05-12 18:01:32 +0000968 int total = 0; // Count elements that were set. It'll be used as an array size
969 int prev_comma = FALSE; // For correct processing sequential commas
Jim Cownie5e8470a2013-09-27 10:38:44 +0000970
Jonathan Peyton30419822017-05-12 18:01:32 +0000971 // Count the number of values in the env. var string
972 for (;;) {
973 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000974
Jonathan Peyton30419822017-05-12 18:01:32 +0000975 if (*next == '\0') {
976 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000977 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000978 // Next character is not an integer or not a comma => end of list
979 if (((*next < '0') || (*next > '9')) && (*next != ',')) {
980 KMP_WARNING(NthSyntaxError, var, env);
981 return;
982 }
983 // The next character is ','
984 if (*next == ',') {
985 // ',' is the fisrt character
986 if (total == 0 || prev_comma) {
987 total++;
988 }
989 prev_comma = TRUE;
990 next++; // skip ','
991 SKIP_WS(next);
992 }
993 // Next character is a digit
994 if (*next >= '0' && *next <= '9') {
995 prev_comma = FALSE;
996 SKIP_DIGITS(next);
997 total++;
998 const char *tmp = next;
999 SKIP_WS(tmp);
1000 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
1001 KMP_WARNING(NthSpacesNotAllowed, var, env);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001002 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00001003 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001004 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001005 }
1006 KMP_DEBUG_ASSERT(total > 0);
1007 if (total <= 0) {
1008 KMP_WARNING(NthSyntaxError, var, env);
1009 return;
1010 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001011
Jonathan Peyton30419822017-05-12 18:01:32 +00001012 // Check if the nested nthreads array exists
1013 if (!nth_array->nth) {
1014 // Allocate an array of double size
1015 nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
1016 if (nth_array->nth == NULL) {
1017 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001018 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001019 nth_array->size = total * 2;
1020 } else {
1021 if (nth_array->size < total) {
1022 // Increase the array size
1023 do {
1024 nth_array->size *= 2;
1025 } while (nth_array->size < total);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001026
Jonathan Peyton30419822017-05-12 18:01:32 +00001027 nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
1028 nth_array->nth, sizeof(int) * nth_array->size);
1029 if (nth_array->nth == NULL) {
1030 KMP_FATAL(MemoryAllocFailed);
1031 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001032 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001033 }
1034 nth_array->used = total;
1035 int i = 0;
1036
1037 prev_comma = FALSE;
1038 total = 0;
1039 // Save values in the array
1040 for (;;) {
1041 SKIP_WS(scan);
1042 if (*scan == '\0') {
1043 break;
1044 }
1045 // The next character is ','
1046 if (*scan == ',') {
1047 // ',' in the beginning of the list
1048 if (total == 0) {
1049 // The value is supposed to be equal to __kmp_avail_proc but it is
1050 // unknown at the moment.
1051 // So let's put a placeholder (#threads = 0) to correct it later.
1052 nth_array->nth[i++] = 0;
1053 total++;
1054 } else if (prev_comma) {
1055 // Num threads is inherited from the previous level
1056 nth_array->nth[i] = nth_array->nth[i - 1];
1057 i++;
1058 total++;
1059 }
1060 prev_comma = TRUE;
1061 scan++; // skip ','
1062 SKIP_WS(scan);
1063 }
1064 // Next character is a digit
1065 if (*scan >= '0' && *scan <= '9') {
1066 int num;
1067 const char *buf = scan;
1068 char const *msg = NULL;
1069 prev_comma = FALSE;
1070 SKIP_DIGITS(scan);
1071 total++;
1072
1073 num = __kmp_str_to_int(buf, *scan);
1074 if (num < KMP_MIN_NTH) {
1075 msg = KMP_I18N_STR(ValueTooSmall);
1076 num = KMP_MIN_NTH;
1077 } else if (num > __kmp_sys_max_nth) {
1078 msg = KMP_I18N_STR(ValueTooLarge);
1079 num = __kmp_sys_max_nth;
1080 }
1081 if (msg != NULL) {
1082 // Message is not empty. Print warning.
1083 KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1084 KMP_INFORM(Using_int_Value, var, num);
1085 }
1086 nth_array->nth[i++] = num;
1087 }
1088 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001089}
1090
Jonathan Peyton30419822017-05-12 18:01:32 +00001091static void __kmp_stg_parse_num_threads(char const *name, char const *value,
1092 void *data) {
1093 // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
1094 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
1095 // The array of 1 element
1096 __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
1097 __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1098 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1099 __kmp_xproc;
1100 } else {
1101 __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1102 if (__kmp_nested_nth.nth) {
1103 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1104 if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1105 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1106 }
1107 }
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001108 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001109 K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001110} // __kmp_stg_parse_num_threads
1111
Jonathan Peyton30419822017-05-12 18:01:32 +00001112static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
1113 void *data) {
1114 if (__kmp_env_format) {
1115 KMP_STR_BUF_PRINT_NAME;
1116 } else {
1117 __kmp_str_buf_print(buffer, " %s", name);
1118 }
1119 if (__kmp_nested_nth.used) {
1120 kmp_str_buf_t buf;
1121 __kmp_str_buf_init(&buf);
1122 for (int i = 0; i < __kmp_nested_nth.used; i++) {
1123 __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
1124 if (i < __kmp_nested_nth.used - 1) {
1125 __kmp_str_buf_print(&buf, ",");
1126 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001127 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001128 __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
1129 __kmp_str_buf_free(&buf);
1130 } else {
1131 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1132 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001133} // __kmp_stg_print_num_threads
1134
Jonathan Peyton30419822017-05-12 18:01:32 +00001135// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001136// OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001137
Jonathan Peyton30419822017-05-12 18:01:32 +00001138static void __kmp_stg_parse_tasking(char const *name, char const *value,
1139 void *data) {
1140 __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
1141 (int *)&__kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001142} // __kmp_stg_parse_tasking
1143
Jonathan Peyton30419822017-05-12 18:01:32 +00001144static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
1145 void *data) {
1146 __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001147} // __kmp_stg_print_tasking
1148
Jonathan Peyton30419822017-05-12 18:01:32 +00001149static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
1150 void *data) {
1151 __kmp_stg_parse_int(name, value, 0, 1,
1152 (int *)&__kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001153} // __kmp_stg_parse_task_stealing
1154
Jonathan Peyton30419822017-05-12 18:01:32 +00001155static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1156 char const *name, void *data) {
1157 __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001158} // __kmp_stg_print_task_stealing
1159
Jonathan Peyton30419822017-05-12 18:01:32 +00001160static void __kmp_stg_parse_max_active_levels(char const *name,
1161 char const *value, void *data) {
1162 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1163 &__kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001164} // __kmp_stg_parse_max_active_levels
1165
Jonathan Peyton30419822017-05-12 18:01:32 +00001166static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1167 char const *name, void *data) {
1168 __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001169} // __kmp_stg_print_max_active_levels
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001170
George Rokos28f31b42016-09-09 17:55:26 +00001171#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001172// -----------------------------------------------------------------------------
George Rokos28f31b42016-09-09 17:55:26 +00001173// OpenMP 4.0: OMP_DEFAULT_DEVICE
Jonathan Peyton30419822017-05-12 18:01:32 +00001174static void __kmp_stg_parse_default_device(char const *name, char const *value,
1175 void *data) {
1176 __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1177 &__kmp_default_device);
George Rokos28f31b42016-09-09 17:55:26 +00001178} // __kmp_stg_parse_default_device
1179
Jonathan Peyton30419822017-05-12 18:01:32 +00001180static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1181 char const *name, void *data) {
George Rokos28f31b42016-09-09 17:55:26 +00001182 __kmp_stg_print_int(buffer, name, __kmp_default_device);
1183} // __kmp_stg_print_default_device
1184#endif
1185
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001186#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001187// -----------------------------------------------------------------------------
Jonathan Peyton28510722016-02-25 18:04:09 +00001188// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
Jonathan Peyton30419822017-05-12 18:01:32 +00001189static void __kmp_stg_parse_max_task_priority(char const *name,
1190 char const *value, void *data) {
1191 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1192 &__kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001193} // __kmp_stg_parse_max_task_priority
1194
Jonathan Peyton30419822017-05-12 18:01:32 +00001195static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1196 char const *name, void *data) {
1197 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001198} // __kmp_stg_print_max_task_priority
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001199
1200// KMP_TASKLOOP_MIN_TASKS
1201// taskloop threashold to switch from recursive to linear tasks creation
1202static void __kmp_stg_parse_taskloop_min_tasks(char const *name,
Jonathan Peytond74d8902017-07-25 18:20:16 +00001203 char const *value, void *data) {
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001204 int tmp;
1205 __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1206 __kmp_taskloop_min_tasks = tmp;
1207} // __kmp_stg_parse_taskloop_min_tasks
1208
1209static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
Jonathan Peytond74d8902017-07-25 18:20:16 +00001210 char const *name, void *data) {
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001211 __kmp_stg_print_int(buffer, name, __kmp_taskloop_min_tasks);
1212} // __kmp_stg_print_taskloop_min_tasks
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001213#endif // OMP_45_ENABLED
Jonathan Peyton28510722016-02-25 18:04:09 +00001214
Jonathan Peyton30419822017-05-12 18:01:32 +00001215// -----------------------------------------------------------------------------
Jonathan Peyton067325f2016-05-31 19:01:15 +00001216// KMP_DISP_NUM_BUFFERS
Jonathan Peyton30419822017-05-12 18:01:32 +00001217static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
1218 void *data) {
1219 if (TCR_4(__kmp_init_serial)) {
1220 KMP_WARNING(EnvSerialWarn, name);
1221 return;
1222 } // read value before serial initialization only
1223 __kmp_stg_parse_int(name, value, 1, KMP_MAX_NTH, &__kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001224} // __kmp_stg_parse_disp_buffers
1225
Jonathan Peyton30419822017-05-12 18:01:32 +00001226static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1227 char const *name, void *data) {
1228 __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001229} // __kmp_stg_print_disp_buffers
1230
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001231#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00001232// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001233// KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001234
Jonathan Peyton30419822017-05-12 18:01:32 +00001235static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
1236 void *data) {
1237 if (TCR_4(__kmp_init_parallel)) {
1238 KMP_WARNING(EnvParallelWarn, name);
1239 return;
1240 } // read value before first parallel only
1241 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1242 &__kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001243} // __kmp_stg_parse_hot_teams_level
1244
Jonathan Peyton30419822017-05-12 18:01:32 +00001245static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1246 char const *name, void *data) {
1247 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001248} // __kmp_stg_print_hot_teams_level
1249
Jonathan Peyton30419822017-05-12 18:01:32 +00001250static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
1251 void *data) {
1252 if (TCR_4(__kmp_init_parallel)) {
1253 KMP_WARNING(EnvParallelWarn, name);
1254 return;
1255 } // read value before first parallel only
1256 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1257 &__kmp_hot_teams_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001258} // __kmp_stg_parse_hot_teams_mode
1259
Jonathan Peyton30419822017-05-12 18:01:32 +00001260static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1261 char const *name, void *data) {
1262 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001263} // __kmp_stg_print_hot_teams_mode
1264
1265#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001266
Jonathan Peyton30419822017-05-12 18:01:32 +00001267// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001268// KMP_HANDLE_SIGNALS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001269
1270#if KMP_HANDLE_SIGNALS
1271
Jonathan Peyton30419822017-05-12 18:01:32 +00001272static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
1273 void *data) {
1274 __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001275} // __kmp_stg_parse_handle_signals
1276
Jonathan Peyton30419822017-05-12 18:01:32 +00001277static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1278 char const *name, void *data) {
1279 __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001280} // __kmp_stg_print_handle_signals
1281
1282#endif // KMP_HANDLE_SIGNALS
1283
Jonathan Peyton30419822017-05-12 18:01:32 +00001284// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001285// KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
Jim Cownie5e8470a2013-09-27 10:38:44 +00001286
1287#ifdef KMP_DEBUG
1288
Jonathan Peyton30419822017-05-12 18:01:32 +00001289#define KMP_STG_X_DEBUG(x) \
1290 static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1291 void *data) { \
1292 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1293 } /* __kmp_stg_parse_x_debug */ \
1294 static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1295 char const *name, void *data) { \
1296 __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1297 } /* __kmp_stg_print_x_debug */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001298
Jonathan Peyton30419822017-05-12 18:01:32 +00001299KMP_STG_X_DEBUG(a)
1300KMP_STG_X_DEBUG(b)
1301KMP_STG_X_DEBUG(c)
1302KMP_STG_X_DEBUG(d)
1303KMP_STG_X_DEBUG(e)
1304KMP_STG_X_DEBUG(f)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001305
1306#undef KMP_STG_X_DEBUG
1307
Jonathan Peyton30419822017-05-12 18:01:32 +00001308static void __kmp_stg_parse_debug(char const *name, char const *value,
1309 void *data) {
1310 int debug = 0;
1311 __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1312 if (kmp_a_debug < debug) {
1313 kmp_a_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001314 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001315 if (kmp_b_debug < debug) {
1316 kmp_b_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001317 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001318 if (kmp_c_debug < debug) {
1319 kmp_c_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001320 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001321 if (kmp_d_debug < debug) {
1322 kmp_d_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001323 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001324 if (kmp_e_debug < debug) {
1325 kmp_e_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001326 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001327 if (kmp_f_debug < debug) {
1328 kmp_f_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001329 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001330} // __kmp_stg_parse_debug
1331
Jonathan Peyton30419822017-05-12 18:01:32 +00001332static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
1333 void *data) {
1334 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1335 // !!! TODO: Move buffer initialization of of this file! It may works
1336 // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
1337 // KMP_DEBUG_BUF_CHARS.
1338 if (__kmp_debug_buf) {
1339 int i;
1340 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001341
Jonathan Peyton30419822017-05-12 18:01:32 +00001342 /* allocate and initialize all entries in debug buffer to empty */
1343 __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
1344 for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1345 __kmp_debug_buffer[i] = '\0';
Jim Cownie5e8470a2013-09-27 10:38:44 +00001346
Jonathan Peyton30419822017-05-12 18:01:32 +00001347 __kmp_debug_count = 0;
1348 }
1349 K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001350} // __kmp_stg_parse_debug_buf
1351
Jonathan Peyton30419822017-05-12 18:01:32 +00001352static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
1353 void *data) {
1354 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001355} // __kmp_stg_print_debug_buf
1356
Jonathan Peyton30419822017-05-12 18:01:32 +00001357static void __kmp_stg_parse_debug_buf_atomic(char const *name,
1358 char const *value, void *data) {
1359 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001360} // __kmp_stg_parse_debug_buf_atomic
1361
Jonathan Peyton30419822017-05-12 18:01:32 +00001362static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1363 char const *name, void *data) {
1364 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001365} // __kmp_stg_print_debug_buf_atomic
1366
Jonathan Peyton30419822017-05-12 18:01:32 +00001367static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
1368 void *data) {
1369 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1370 &__kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001371} // __kmp_stg_debug_parse_buf_chars
1372
Jonathan Peyton30419822017-05-12 18:01:32 +00001373static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1374 char const *name, void *data) {
1375 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001376} // __kmp_stg_print_debug_buf_chars
1377
Jonathan Peyton30419822017-05-12 18:01:32 +00001378static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
1379 void *data) {
1380 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1381 &__kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001382} // __kmp_stg_parse_debug_buf_lines
1383
Jonathan Peyton30419822017-05-12 18:01:32 +00001384static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1385 char const *name, void *data) {
1386 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001387} // __kmp_stg_print_debug_buf_lines
1388
Jonathan Peyton30419822017-05-12 18:01:32 +00001389static void __kmp_stg_parse_diag(char const *name, char const *value,
1390 void *data) {
1391 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001392} // __kmp_stg_parse_diag
1393
Jonathan Peyton30419822017-05-12 18:01:32 +00001394static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
1395 void *data) {
1396 __kmp_stg_print_int(buffer, name, kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001397} // __kmp_stg_print_diag
1398
1399#endif // KMP_DEBUG
1400
Jonathan Peyton30419822017-05-12 18:01:32 +00001401// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001402// KMP_ALIGN_ALLOC
Jim Cownie5e8470a2013-09-27 10:38:44 +00001403
Jonathan Peyton30419822017-05-12 18:01:32 +00001404static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
1405 void *data) {
1406 __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1407 &__kmp_align_alloc, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001408} // __kmp_stg_parse_align_alloc
1409
Jonathan Peyton30419822017-05-12 18:01:32 +00001410static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
1411 void *data) {
1412 __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001413} // __kmp_stg_print_align_alloc
1414
Jonathan Peyton30419822017-05-12 18:01:32 +00001415// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001416// KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
Jim Cownie5e8470a2013-09-27 10:38:44 +00001417
Jonathan Peyton30419822017-05-12 18:01:32 +00001418// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
1419// parse and print functions, pass required info through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001420
Jonathan Peyton30419822017-05-12 18:01:32 +00001421static void __kmp_stg_parse_barrier_branch_bit(char const *name,
1422 char const *value, void *data) {
1423 const char *var;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001424
Jonathan Peyton30419822017-05-12 18:01:32 +00001425 /* ---------- Barrier branch bit control ------------ */
1426 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1427 var = __kmp_barrier_branch_bit_env_name[i];
1428 if ((strcmp(var, name) == 0) && (value != 0)) {
1429 char *comma;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001430
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001431 comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00001432 __kmp_barrier_gather_branch_bits[i] =
1433 (kmp_uint32)__kmp_str_to_int(value, ',');
1434 /* is there a specified release parameter? */
1435 if (comma == NULL) {
1436 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1437 } else {
1438 __kmp_barrier_release_branch_bits[i] =
1439 (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001440
Jonathan Peyton30419822017-05-12 18:01:32 +00001441 if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1442 __kmp_msg(kmp_ms_warning,
1443 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1444 __kmp_msg_null);
1445 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001446 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001447 }
1448 if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1449 KMP_WARNING(BarrGatherValueInvalid, name, value);
1450 KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1451 __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1452 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001453 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001454 K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1455 __kmp_barrier_gather_branch_bits[i],
1456 __kmp_barrier_release_branch_bits[i]))
1457 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001458} // __kmp_stg_parse_barrier_branch_bit
1459
Jonathan Peyton30419822017-05-12 18:01:32 +00001460static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1461 char const *name, void *data) {
1462 const char *var;
1463 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1464 var = __kmp_barrier_branch_bit_env_name[i];
1465 if (strcmp(var, name) == 0) {
1466 if (__kmp_env_format) {
1467 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1468 } else {
1469 __kmp_str_buf_print(buffer, " %s='",
1470 __kmp_barrier_branch_bit_env_name[i]);
1471 }
1472 __kmp_str_buf_print(buffer, "%d,%d'\n",
1473 __kmp_barrier_gather_branch_bits[i],
1474 __kmp_barrier_release_branch_bits[i]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001475 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001476 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001477} // __kmp_stg_print_barrier_branch_bit
1478
Jonathan Peyton30419822017-05-12 18:01:32 +00001479// ----------------------------------------------------------------------------
1480// KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
1481// KMP_REDUCTION_BARRIER_PATTERN
Jim Cownie5e8470a2013-09-27 10:38:44 +00001482
Jonathan Peyton30419822017-05-12 18:01:32 +00001483// TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
1484// print functions, pass required data to functions through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001485
Jonathan Peyton30419822017-05-12 18:01:32 +00001486static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
1487 void *data) {
1488 const char *var;
1489 /* ---------- Barrier method control ------------ */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001490
Jonathan Peyton30419822017-05-12 18:01:32 +00001491 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1492 var = __kmp_barrier_pattern_env_name[i];
Jim Cownie5e8470a2013-09-27 10:38:44 +00001493
Jonathan Peyton30419822017-05-12 18:01:32 +00001494 if ((strcmp(var, name) == 0) && (value != 0)) {
1495 int j;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001496 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001497
Jonathan Peyton30419822017-05-12 18:01:32 +00001498 /* handle first parameter: gather pattern */
1499 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1500 if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1501 ',')) {
1502 __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1503 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001504 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001505 }
1506 if (j == bp_last_bar) {
1507 KMP_WARNING(BarrGatherValueInvalid, name, value);
1508 KMP_INFORM(Using_str_Value, name,
1509 __kmp_barrier_pattern_name[bp_linear_bar]);
1510 }
1511
1512 /* handle second parameter: release pattern */
1513 if (comma != NULL) {
1514 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1515 if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1516 __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1517 break;
1518 }
1519 }
1520 if (j == bp_last_bar) {
1521 __kmp_msg(kmp_ms_warning,
1522 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1523 __kmp_msg_null);
1524 KMP_INFORM(Using_str_Value, name,
1525 __kmp_barrier_pattern_name[bp_linear_bar]);
1526 }
1527 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001528 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001529 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001530} // __kmp_stg_parse_barrier_pattern
1531
Jonathan Peyton30419822017-05-12 18:01:32 +00001532static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1533 char const *name, void *data) {
1534 const char *var;
1535 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1536 var = __kmp_barrier_pattern_env_name[i];
1537 if (strcmp(var, name) == 0) {
1538 int j = __kmp_barrier_gather_pattern[i];
1539 int k = __kmp_barrier_release_pattern[i];
1540 if (__kmp_env_format) {
1541 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1542 } else {
1543 __kmp_str_buf_print(buffer, " %s='",
1544 __kmp_barrier_pattern_env_name[i]);
1545 }
1546 __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
1547 __kmp_barrier_pattern_name[k]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001548 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001549 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001550} // __kmp_stg_print_barrier_pattern
1551
Jonathan Peyton30419822017-05-12 18:01:32 +00001552// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001553// KMP_ABORT_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00001554
Jonathan Peyton30419822017-05-12 18:01:32 +00001555static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
1556 void *data) {
1557 // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
1558 // milliseconds.
1559 int delay = __kmp_abort_delay / 1000;
1560 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1561 __kmp_abort_delay = delay * 1000;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001562} // __kmp_stg_parse_abort_delay
1563
Jonathan Peyton30419822017-05-12 18:01:32 +00001564static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
1565 void *data) {
1566 __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001567} // __kmp_stg_print_abort_delay
1568
Jonathan Peyton30419822017-05-12 18:01:32 +00001569// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001570// KMP_CPUINFO_FILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001571
Jonathan Peyton30419822017-05-12 18:01:32 +00001572static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
1573 void *data) {
1574#if KMP_AFFINITY_SUPPORTED
1575 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1576 K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1577#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001578} //__kmp_stg_parse_cpuinfo_file
1579
Jonathan Peyton30419822017-05-12 18:01:32 +00001580static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1581 char const *name, void *data) {
1582#if KMP_AFFINITY_SUPPORTED
1583 if (__kmp_env_format) {
1584 KMP_STR_BUF_PRINT_NAME;
1585 } else {
1586 __kmp_str_buf_print(buffer, " %s", name);
1587 }
1588 if (__kmp_cpuinfo_file) {
1589 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
1590 } else {
1591 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1592 }
1593#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001594} //__kmp_stg_print_cpuinfo_file
1595
Jonathan Peyton30419822017-05-12 18:01:32 +00001596// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001597// KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
Jim Cownie5e8470a2013-09-27 10:38:44 +00001598
Jonathan Peyton30419822017-05-12 18:01:32 +00001599static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
1600 void *data) {
1601 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1602 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001603
Jonathan Peyton30419822017-05-12 18:01:32 +00001604 rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1605 if (rc) {
1606 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001607 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001608 if (reduction->force) {
1609 if (value != 0) {
1610 if (__kmp_str_match("critical", 0, value))
1611 __kmp_force_reduction_method = critical_reduce_block;
1612 else if (__kmp_str_match("atomic", 0, value))
1613 __kmp_force_reduction_method = atomic_reduce_block;
1614 else if (__kmp_str_match("tree", 0, value))
1615 __kmp_force_reduction_method = tree_reduce_block;
1616 else {
1617 KMP_FATAL(UnknownForceReduction, name, value);
1618 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001619 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001620 } else {
1621 __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1622 if (__kmp_determ_red) {
1623 __kmp_force_reduction_method = tree_reduce_block;
1624 } else {
1625 __kmp_force_reduction_method = reduction_method_not_defined;
1626 }
1627 }
1628 K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
1629 __kmp_force_reduction_method));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001630} // __kmp_stg_parse_force_reduction
1631
Jonathan Peyton30419822017-05-12 18:01:32 +00001632static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1633 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00001634
Jonathan Peyton30419822017-05-12 18:01:32 +00001635 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1636 if (reduction->force) {
1637 if (__kmp_force_reduction_method == critical_reduce_block) {
1638 __kmp_stg_print_str(buffer, name, "critical");
1639 } else if (__kmp_force_reduction_method == atomic_reduce_block) {
1640 __kmp_stg_print_str(buffer, name, "atomic");
1641 } else if (__kmp_force_reduction_method == tree_reduce_block) {
1642 __kmp_stg_print_str(buffer, name, "tree");
Jim Cownie5e8470a2013-09-27 10:38:44 +00001643 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00001644 if (__kmp_env_format) {
1645 KMP_STR_BUF_PRINT_NAME;
1646 } else {
1647 __kmp_str_buf_print(buffer, " %s", name);
1648 }
1649 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001650 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001651 } else {
1652 __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1653 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001654
1655} // __kmp_stg_print_force_reduction
1656
Jonathan Peyton30419822017-05-12 18:01:32 +00001657// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001658// KMP_STORAGE_MAP
Jim Cownie5e8470a2013-09-27 10:38:44 +00001659
Jonathan Peyton30419822017-05-12 18:01:32 +00001660static void __kmp_stg_parse_storage_map(char const *name, char const *value,
1661 void *data) {
1662 if (__kmp_str_match("verbose", 1, value)) {
1663 __kmp_storage_map = TRUE;
1664 __kmp_storage_map_verbose = TRUE;
1665 __kmp_storage_map_verbose_specified = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001666
Jonathan Peyton30419822017-05-12 18:01:32 +00001667 } else {
1668 __kmp_storage_map_verbose = FALSE;
1669 __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001670 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001671} // __kmp_stg_parse_storage_map
1672
Jonathan Peyton30419822017-05-12 18:01:32 +00001673static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
1674 void *data) {
1675 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1676 __kmp_stg_print_str(buffer, name, "verbose");
1677 } else {
1678 __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1679 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001680} // __kmp_stg_print_storage_map
1681
Jonathan Peyton30419822017-05-12 18:01:32 +00001682// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001683// KMP_ALL_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001684
Jonathan Peyton30419822017-05-12 18:01:32 +00001685static void __kmp_stg_parse_all_threadprivate(char const *name,
1686 char const *value, void *data) {
1687 __kmp_stg_parse_int(name, value,
1688 __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1689 __kmp_max_nth, &__kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001690} // __kmp_stg_parse_all_threadprivate
1691
Jonathan Peyton30419822017-05-12 18:01:32 +00001692static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1693 char const *name, void *data) {
1694 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001695}
1696
Jonathan Peyton30419822017-05-12 18:01:32 +00001697// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001698// KMP_FOREIGN_THREADS_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001699
Jonathan Peyton30419822017-05-12 18:01:32 +00001700static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
1701 char const *value,
1702 void *data) {
1703 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001704} // __kmp_stg_parse_foreign_threads_threadprivate
1705
Jonathan Peyton30419822017-05-12 18:01:32 +00001706static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
1707 char const *name,
1708 void *data) {
1709 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001710} // __kmp_stg_print_foreign_threads_threadprivate
1711
Jonathan Peyton30419822017-05-12 18:01:32 +00001712// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001713// KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
Jim Cownie5e8470a2013-09-27 10:38:44 +00001714
Alp Toker98758b02014-03-02 04:12:06 +00001715#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00001716// Parse the proc id list. Return TRUE if successful, FALSE otherwise.
Jonathan Peyton30419822017-05-12 18:01:32 +00001717static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
1718 const char **nextEnv,
1719 char **proclist) {
1720 const char *scan = env;
1721 const char *next = scan;
1722 int empty = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001723
Jonathan Peyton30419822017-05-12 18:01:32 +00001724 *proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001725
Jonathan Peyton30419822017-05-12 18:01:32 +00001726 for (;;) {
1727 int start, end, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001728
Jonathan Peyton30419822017-05-12 18:01:32 +00001729 SKIP_WS(scan);
1730 next = scan;
1731 if (*next == '\0') {
1732 break;
1733 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001734
Jonathan Peyton30419822017-05-12 18:01:32 +00001735 if (*next == '{') {
1736 int num;
1737 next++; // skip '{'
1738 SKIP_WS(next);
1739 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001740
Jonathan Peyton30419822017-05-12 18:01:32 +00001741 // Read the first integer in the set.
1742 if ((*next < '0') || (*next > '9')) {
1743 KMP_WARNING(AffSyntaxError, var);
1744 return FALSE;
1745 }
1746 SKIP_DIGITS(next);
1747 num = __kmp_str_to_int(scan, *next);
1748 KMP_ASSERT(num >= 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001749
Jonathan Peyton30419822017-05-12 18:01:32 +00001750 for (;;) {
1751 // Check for end of set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001752 SKIP_WS(next);
Jonathan Peyton30419822017-05-12 18:01:32 +00001753 if (*next == '}') {
1754 next++; // skip '}'
1755 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001756 }
1757
Jim Cownie5e8470a2013-09-27 10:38:44 +00001758 // Skip optional comma.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001759 if (*next == ',') {
Jonathan Peyton30419822017-05-12 18:01:32 +00001760 next++;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001761 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001762 SKIP_WS(next);
1763
1764 // Read the next integer in the set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001765 scan = next;
Jonathan Peyton30419822017-05-12 18:01:32 +00001766 if ((*next < '0') || (*next > '9')) {
1767 KMP_WARNING(AffSyntaxError, var);
1768 return FALSE;
1769 }
1770
1771 SKIP_DIGITS(next);
1772 num = __kmp_str_to_int(scan, *next);
1773 KMP_ASSERT(num >= 0);
1774 }
1775 empty = FALSE;
1776
1777 SKIP_WS(next);
1778 if (*next == ',') {
1779 next++;
1780 }
1781 scan = next;
1782 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001783 }
1784
Jonathan Peyton30419822017-05-12 18:01:32 +00001785 // Next character is not an integer => end of list
1786 if ((*next < '0') || (*next > '9')) {
1787 if (empty) {
1788 KMP_WARNING(AffSyntaxError, var);
1789 return FALSE;
1790 }
1791 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001792 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001793
1794 // Read the first integer.
1795 SKIP_DIGITS(next);
1796 start = __kmp_str_to_int(scan, *next);
1797 KMP_ASSERT(start >= 0);
1798 SKIP_WS(next);
1799
1800 // If this isn't a range, then go on.
1801 if (*next != '-') {
1802 empty = FALSE;
1803
1804 // Skip optional comma.
1805 if (*next == ',') {
1806 next++;
1807 }
1808 scan = next;
1809 continue;
1810 }
1811
1812 // This is a range. Skip over the '-' and read in the 2nd int.
1813 next++; // skip '-'
1814 SKIP_WS(next);
1815 scan = next;
1816 if ((*next < '0') || (*next > '9')) {
1817 KMP_WARNING(AffSyntaxError, var);
1818 return FALSE;
1819 }
1820 SKIP_DIGITS(next);
1821 end = __kmp_str_to_int(scan, *next);
1822 KMP_ASSERT(end >= 0);
1823
1824 // Check for a stride parameter
1825 stride = 1;
1826 SKIP_WS(next);
1827 if (*next == ':') {
1828 // A stride is specified. Skip over the ':" and read the 3rd int.
1829 int sign = +1;
1830 next++; // skip ':'
1831 SKIP_WS(next);
1832 scan = next;
1833 if (*next == '-') {
1834 sign = -1;
1835 next++;
1836 SKIP_WS(next);
1837 scan = next;
1838 }
1839 if ((*next < '0') || (*next > '9')) {
1840 KMP_WARNING(AffSyntaxError, var);
1841 return FALSE;
1842 }
1843 SKIP_DIGITS(next);
1844 stride = __kmp_str_to_int(scan, *next);
1845 KMP_ASSERT(stride >= 0);
1846 stride *= sign;
1847 }
1848
1849 // Do some range checks.
1850 if (stride == 0) {
1851 KMP_WARNING(AffZeroStride, var);
1852 return FALSE;
1853 }
1854 if (stride > 0) {
1855 if (start > end) {
1856 KMP_WARNING(AffStartGreaterEnd, var, start, end);
1857 return FALSE;
1858 }
1859 } else {
1860 if (start < end) {
1861 KMP_WARNING(AffStrideLessZero, var, start, end);
1862 return FALSE;
1863 }
1864 }
1865 if ((end - start) / stride > 65536) {
1866 KMP_WARNING(AffRangeTooBig, var, end, start, stride);
1867 return FALSE;
1868 }
1869
1870 empty = FALSE;
1871
1872 // Skip optional comma.
1873 SKIP_WS(next);
1874 if (*next == ',') {
1875 next++;
1876 }
1877 scan = next;
1878 }
1879
1880 *nextEnv = next;
1881
1882 {
1883 int len = next - env;
1884 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
1885 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
1886 retlist[len] = '\0';
1887 *proclist = retlist;
1888 }
1889 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001890}
1891
Jim Cownie5e8470a2013-09-27 10:38:44 +00001892// If KMP_AFFINITY is specified without a type, then
1893// __kmp_affinity_notype should point to its setting.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001894static kmp_setting_t *__kmp_affinity_notype = NULL;
1895
Jonathan Peyton30419822017-05-12 18:01:32 +00001896static void __kmp_parse_affinity_env(char const *name, char const *value,
1897 enum affinity_type *out_type,
1898 char **out_proclist, int *out_verbose,
1899 int *out_warn, int *out_respect,
1900 enum affinity_gran *out_gran,
1901 int *out_gran_levels, int *out_dups,
1902 int *out_compact, int *out_offset) {
1903 char *buffer = NULL; // Copy of env var value.
1904 char *buf = NULL; // Buffer for strtok_r() function.
1905 char *next = NULL; // end of token / start of next.
1906 const char *start; // start of current token (for err msgs)
1907 int count = 0; // Counter of parsed integer numbers.
1908 int number[2]; // Parsed numbers.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001909
Jonathan Peyton30419822017-05-12 18:01:32 +00001910 // Guards.
1911 int type = 0;
1912 int proclist = 0;
1913 int max_proclist = 0;
1914 int verbose = 0;
1915 int warnings = 0;
1916 int respect = 0;
1917 int gran = 0;
1918 int dups = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001919
Jonathan Peyton30419822017-05-12 18:01:32 +00001920 KMP_ASSERT(value != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001921
Jonathan Peyton30419822017-05-12 18:01:32 +00001922 if (TCR_4(__kmp_init_middle)) {
1923 KMP_WARNING(EnvMiddleWarn, name);
1924 __kmp_env_toPrint(name, 0);
1925 return;
1926 }
1927 __kmp_env_toPrint(name, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001928
Jonathan Peyton30419822017-05-12 18:01:32 +00001929 buffer =
1930 __kmp_str_format("%s", value); // Copy env var to keep original intact.
1931 buf = buffer;
1932 SKIP_WS(buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001933
Jonathan Peyton30419822017-05-12 18:01:32 +00001934// Helper macros.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001935
Jonathan Peyton30419822017-05-12 18:01:32 +00001936// If we see a parse error, emit a warning and scan to the next ",".
1937//
1938// FIXME - there's got to be a better way to print an error
1939// message, hopefully without overwritting peices of buf.
1940#define EMIT_WARN(skip, errlist) \
1941 { \
1942 char ch; \
1943 if (skip) { \
1944 SKIP_TO(next, ','); \
1945 } \
1946 ch = *next; \
1947 *next = '\0'; \
1948 KMP_WARNING errlist; \
1949 *next = ch; \
1950 if (skip) { \
1951 if (ch == ',') \
1952 next++; \
1953 } \
1954 buf = next; \
1955 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001956
Jonathan Peyton30419822017-05-12 18:01:32 +00001957#define _set_param(_guard, _var, _val) \
1958 { \
1959 if (_guard == 0) { \
1960 _var = _val; \
1961 } else { \
1962 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001963 } \
Jonathan Peyton30419822017-05-12 18:01:32 +00001964 ++_guard; \
1965 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001966
Jonathan Peyton30419822017-05-12 18:01:32 +00001967#define set_type(val) _set_param(type, *out_type, val)
1968#define set_verbose(val) _set_param(verbose, *out_verbose, val)
1969#define set_warnings(val) _set_param(warnings, *out_warn, val)
1970#define set_respect(val) _set_param(respect, *out_respect, val)
1971#define set_dups(val) _set_param(dups, *out_dups, val)
1972#define set_proclist(val) _set_param(proclist, *out_proclist, val)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001973
Jonathan Peyton30419822017-05-12 18:01:32 +00001974#define set_gran(val, levels) \
1975 { \
1976 if (gran == 0) { \
1977 *out_gran = val; \
1978 *out_gran_levels = levels; \
1979 } else { \
1980 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001981 } \
Jonathan Peyton30419822017-05-12 18:01:32 +00001982 ++gran; \
1983 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001984
Jonathan Peyton30419822017-05-12 18:01:32 +00001985#if OMP_40_ENABLED
1986 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
1987 (__kmp_nested_proc_bind.used > 0));
Andrey Churbanov613edeb2015-02-20 18:14:43 +00001988#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00001989
1990 while (*buf != '\0') {
1991 start = next = buf;
1992
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001993 if (__kmp_match_str("none", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001994 set_type(affinity_none);
1995#if OMP_40_ENABLED
1996 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
1997#endif
1998 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001999 } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002000 set_type(affinity_scatter);
2001#if OMP_40_ENABLED
2002 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2003#endif
2004 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002005 } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002006 set_type(affinity_compact);
2007#if OMP_40_ENABLED
2008 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2009#endif
2010 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002011 } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002012 set_type(affinity_logical);
2013#if OMP_40_ENABLED
2014 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2015#endif
2016 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002017 } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002018 set_type(affinity_physical);
2019#if OMP_40_ENABLED
2020 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2021#endif
2022 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002023 } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002024 set_type(affinity_explicit);
2025#if OMP_40_ENABLED
2026 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2027#endif
2028 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002029 } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002030 set_type(affinity_balanced);
2031#if OMP_40_ENABLED
2032 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2033#endif
2034 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002035 } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002036 set_type(affinity_disabled);
2037#if OMP_40_ENABLED
2038 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2039#endif
2040 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002041 } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002042 set_verbose(TRUE);
2043 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002044 } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002045 set_verbose(FALSE);
2046 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002047 } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002048 set_warnings(TRUE);
2049 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002050 } else if (__kmp_match_str("nowarnings", buf,
2051 CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002052 set_warnings(FALSE);
2053 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002054 } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002055 set_respect(TRUE);
2056 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002057 } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002058 set_respect(FALSE);
2059 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002060 } else if (__kmp_match_str("duplicates", buf,
2061 CCAST(const char **, &next)) ||
2062 __kmp_match_str("dups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002063 set_dups(TRUE);
2064 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002065 } else if (__kmp_match_str("noduplicates", buf,
2066 CCAST(const char **, &next)) ||
2067 __kmp_match_str("nodups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002068 set_dups(FALSE);
2069 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002070 } else if (__kmp_match_str("granularity", buf,
2071 CCAST(const char **, &next)) ||
2072 __kmp_match_str("gran", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002073 SKIP_WS(next);
2074 if (*next != '=') {
2075 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2076 continue;
2077 }
2078 next++; // skip '='
2079 SKIP_WS(next);
2080
2081 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002082 if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002083 set_gran(affinity_gran_fine, -1);
2084 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002085 } else if (__kmp_match_str("thread", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002086 set_gran(affinity_gran_thread, -1);
2087 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002088 } else if (__kmp_match_str("core", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002089 set_gran(affinity_gran_core, -1);
2090 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002091 } else if (__kmp_match_str("package", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002092 set_gran(affinity_gran_package, -1);
2093 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002094 } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002095 set_gran(affinity_gran_node, -1);
2096 buf = next;
2097#if KMP_GROUP_AFFINITY
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002098 } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002099 set_gran(affinity_gran_group, -1);
2100 buf = next;
2101#endif /* KMP_GROUP AFFINITY */
2102 } else if ((*buf >= '0') && (*buf <= '9')) {
2103 int n;
2104 next = buf;
2105 SKIP_DIGITS(next);
2106 n = __kmp_str_to_int(buf, *next);
2107 KMP_ASSERT(n >= 0);
2108 buf = next;
2109 set_gran(affinity_gran_default, n);
2110 } else {
2111 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2112 continue;
2113 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002114 } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002115 char *temp_proclist;
2116
2117 SKIP_WS(next);
2118 if (*next != '=') {
2119 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2120 continue;
2121 }
2122 next++; // skip '='
2123 SKIP_WS(next);
2124 if (*next != '[') {
2125 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2126 continue;
2127 }
2128 next++; // skip '['
2129 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002130 if (!__kmp_parse_affinity_proc_id_list(
2131 name, buf, CCAST(const char **, &next), &temp_proclist)) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002132 // warning already emitted.
2133 SKIP_TO(next, ']');
2134 if (*next == ']')
2135 next++;
2136 SKIP_TO(next, ',');
2137 if (*next == ',')
2138 next++;
2139 buf = next;
2140 continue;
2141 }
2142 if (*next != ']') {
2143 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2144 continue;
2145 }
2146 next++; // skip ']'
2147 set_proclist(temp_proclist);
2148 } else if ((*buf >= '0') && (*buf <= '9')) {
2149 // Parse integer numbers -- permute and offset.
2150 int n;
2151 next = buf;
2152 SKIP_DIGITS(next);
2153 n = __kmp_str_to_int(buf, *next);
2154 KMP_ASSERT(n >= 0);
2155 buf = next;
2156 if (count < 2) {
2157 number[count] = n;
2158 } else {
2159 KMP_WARNING(AffManyParams, name, start);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002160 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002161 ++count;
2162 } else {
2163 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2164 continue;
2165 }
2166
2167 SKIP_WS(next);
2168 if (*next == ',') {
2169 next++;
2170 SKIP_WS(next);
2171 } else if (*next != '\0') {
2172 const char *temp = next;
2173 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2174 continue;
2175 }
2176 buf = next;
2177 } // while
2178
2179#undef EMIT_WARN
2180#undef _set_param
2181#undef set_type
2182#undef set_verbose
2183#undef set_warnings
2184#undef set_respect
2185#undef set_granularity
2186
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002187 __kmp_str_free(CCAST(const char **, &buffer));
Jonathan Peyton30419822017-05-12 18:01:32 +00002188
2189 if (proclist) {
2190 if (!type) {
2191 KMP_WARNING(AffProcListNoType, name);
2192 *out_type = affinity_explicit;
2193#if OMP_40_ENABLED
2194 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2195#endif
2196 } else if (*out_type != affinity_explicit) {
2197 KMP_WARNING(AffProcListNotExplicit, name);
2198 KMP_ASSERT(*out_proclist != NULL);
2199 KMP_INTERNAL_FREE(*out_proclist);
2200 *out_proclist = NULL;
2201 }
2202 }
2203 switch (*out_type) {
2204 case affinity_logical:
2205 case affinity_physical: {
2206 if (count > 0) {
2207 *out_offset = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002208 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002209 if (count > 1) {
2210 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002211 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002212 } break;
2213 case affinity_balanced: {
2214 if (count > 0) {
2215 *out_compact = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002216 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002217 if (count > 1) {
2218 *out_offset = number[1];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002219 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002220
2221 if (__kmp_affinity_gran == affinity_gran_default) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002222#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002223 if (__kmp_mic_type != non_mic) {
2224 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2225 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine");
2226 }
2227 __kmp_affinity_gran = affinity_gran_fine;
2228 } else
2229#endif
2230 {
2231 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2232 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core");
2233 }
2234 __kmp_affinity_gran = affinity_gran_core;
2235 }
2236 }
2237 } break;
2238 case affinity_scatter:
2239 case affinity_compact: {
2240 if (count > 0) {
2241 *out_compact = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002242 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002243 if (count > 1) {
2244 *out_offset = number[1];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002245 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002246 } break;
2247 case affinity_explicit: {
2248 if (*out_proclist == NULL) {
2249 KMP_WARNING(AffNoProcList, name);
2250 __kmp_affinity_type = affinity_none;
2251 }
2252 if (count > 0) {
2253 KMP_WARNING(AffNoParam, name, "explicit");
2254 }
2255 } break;
2256 case affinity_none: {
2257 if (count > 0) {
2258 KMP_WARNING(AffNoParam, name, "none");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002259 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002260 } break;
2261 case affinity_disabled: {
2262 if (count > 0) {
2263 KMP_WARNING(AffNoParam, name, "disabled");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002264 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002265 } break;
2266 case affinity_default: {
2267 if (count > 0) {
2268 KMP_WARNING(AffNoParam, name, "default");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002269 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002270 } break;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002271 default: { KMP_ASSERT(0); }
2272 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002273} // __kmp_parse_affinity_env
2274
Jonathan Peyton30419822017-05-12 18:01:32 +00002275static void __kmp_stg_parse_affinity(char const *name, char const *value,
2276 void *data) {
2277 kmp_setting_t **rivals = (kmp_setting_t **)data;
2278 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002279
Jonathan Peyton30419822017-05-12 18:01:32 +00002280 rc = __kmp_stg_check_rivals(name, value, rivals);
2281 if (rc) {
2282 return;
2283 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002284
Jonathan Peyton30419822017-05-12 18:01:32 +00002285 __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2286 &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2287 &__kmp_affinity_warnings,
2288 &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2289 &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2290 &__kmp_affinity_compact, &__kmp_affinity_offset);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002291
2292} // __kmp_stg_parse_affinity
2293
Jonathan Peyton30419822017-05-12 18:01:32 +00002294static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
2295 void *data) {
2296 if (__kmp_env_format) {
2297 KMP_STR_BUF_PRINT_NAME_EX(name);
2298 } else {
2299 __kmp_str_buf_print(buffer, " %s='", name);
2300 }
2301 if (__kmp_affinity_verbose) {
2302 __kmp_str_buf_print(buffer, "%s,", "verbose");
2303 } else {
2304 __kmp_str_buf_print(buffer, "%s,", "noverbose");
2305 }
2306 if (__kmp_affinity_warnings) {
2307 __kmp_str_buf_print(buffer, "%s,", "warnings");
2308 } else {
2309 __kmp_str_buf_print(buffer, "%s,", "nowarnings");
2310 }
2311 if (KMP_AFFINITY_CAPABLE()) {
2312 if (__kmp_affinity_respect_mask) {
2313 __kmp_str_buf_print(buffer, "%s,", "respect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002314 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002315 __kmp_str_buf_print(buffer, "%s,", "norespect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002316 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002317 switch (__kmp_affinity_gran) {
2318 case affinity_gran_default:
2319 __kmp_str_buf_print(buffer, "%s", "granularity=default,");
2320 break;
2321 case affinity_gran_fine:
2322 __kmp_str_buf_print(buffer, "%s", "granularity=fine,");
2323 break;
2324 case affinity_gran_thread:
2325 __kmp_str_buf_print(buffer, "%s", "granularity=thread,");
2326 break;
2327 case affinity_gran_core:
2328 __kmp_str_buf_print(buffer, "%s", "granularity=core,");
2329 break;
2330 case affinity_gran_package:
2331 __kmp_str_buf_print(buffer, "%s", "granularity=package,");
2332 break;
2333 case affinity_gran_node:
2334 __kmp_str_buf_print(buffer, "%s", "granularity=node,");
2335 break;
2336#if KMP_GROUP_AFFINITY
2337 case affinity_gran_group:
2338 __kmp_str_buf_print(buffer, "%s", "granularity=group,");
2339 break;
2340#endif /* KMP_GROUP_AFFINITY */
2341 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002342 }
2343 if (!KMP_AFFINITY_CAPABLE()) {
2344 __kmp_str_buf_print(buffer, "%s", "disabled");
2345 } else
2346 switch (__kmp_affinity_type) {
2347 case affinity_none:
2348 __kmp_str_buf_print(buffer, "%s", "none");
2349 break;
2350 case affinity_physical:
2351 __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset);
2352 break;
2353 case affinity_logical:
2354 __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset);
2355 break;
2356 case affinity_compact:
2357 __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact,
2358 __kmp_affinity_offset);
2359 break;
2360 case affinity_scatter:
2361 __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact,
2362 __kmp_affinity_offset);
2363 break;
2364 case affinity_explicit:
2365 __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist",
2366 __kmp_affinity_proclist, "explicit");
2367 break;
2368 case affinity_balanced:
2369 __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced",
2370 __kmp_affinity_compact, __kmp_affinity_offset);
2371 break;
2372 case affinity_disabled:
2373 __kmp_str_buf_print(buffer, "%s", "disabled");
2374 break;
2375 case affinity_default:
2376 __kmp_str_buf_print(buffer, "%s", "default");
2377 break;
2378 default:
2379 __kmp_str_buf_print(buffer, "%s", "<unknown>");
2380 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002381 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002382 __kmp_str_buf_print(buffer, "'\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002383} //__kmp_stg_print_affinity
2384
Jonathan Peyton30419822017-05-12 18:01:32 +00002385#ifdef KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00002386
Jonathan Peyton30419822017-05-12 18:01:32 +00002387static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
2388 char const *value, void *data) {
2389 const char *next = NULL;
2390 char *temp_proclist;
2391 kmp_setting_t **rivals = (kmp_setting_t **)data;
2392 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002393
Jonathan Peyton30419822017-05-12 18:01:32 +00002394 rc = __kmp_stg_check_rivals(name, value, rivals);
2395 if (rc) {
2396 return;
2397 }
2398
2399 if (TCR_4(__kmp_init_middle)) {
2400 KMP_WARNING(EnvMiddleWarn, name);
2401 __kmp_env_toPrint(name, 0);
2402 return;
2403 }
2404
2405 __kmp_env_toPrint(name, 1);
2406
2407 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2408 SKIP_WS(next);
2409 if (*next == '\0') {
2410 // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2411 __kmp_affinity_proclist = temp_proclist;
2412 __kmp_affinity_type = affinity_explicit;
2413 __kmp_affinity_gran = affinity_gran_fine;
2414#if OMP_40_ENABLED
2415 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2416#endif
2417 } else {
2418 KMP_WARNING(AffSyntaxError, name);
2419 if (temp_proclist != NULL) {
2420 KMP_INTERNAL_FREE((void *)temp_proclist);
2421 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002422 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002423 } else {
2424 // Warning already emitted
2425 __kmp_affinity_type = affinity_none;
2426#if OMP_40_ENABLED
2427 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2428#endif
2429 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002430} // __kmp_stg_parse_gomp_cpu_affinity
2431
Jonathan Peyton30419822017-05-12 18:01:32 +00002432#endif /* KMP_GOMP_COMPAT */
Jim Cownie5e8470a2013-09-27 10:38:44 +00002433
Jonathan Peyton30419822017-05-12 18:01:32 +00002434#if OMP_40_ENABLED
Jim Cownie5e8470a2013-09-27 10:38:44 +00002435
2436/*-----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00002437The OMP_PLACES proc id list parser. Here is the grammar:
2438
2439place_list := place
2440place_list := place , place_list
2441place := num
2442place := place : num
2443place := place : num : signed
2444place := { subplacelist }
2445place := ! place // (lowest priority)
2446subplace_list := subplace
2447subplace_list := subplace , subplace_list
2448subplace := num
2449subplace := num : num
2450subplace := num : num : signed
2451signed := num
2452signed := + signed
2453signed := - signed
Jim Cownie5e8470a2013-09-27 10:38:44 +00002454-----------------------------------------------------------------------------*/
2455
Jonathan Peyton30419822017-05-12 18:01:32 +00002456static int __kmp_parse_subplace_list(const char *var, const char **scan) {
2457 const char *next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002458
Jonathan Peyton30419822017-05-12 18:01:32 +00002459 for (;;) {
2460 int start, count, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002461
2462 //
Jonathan Peyton30419822017-05-12 18:01:32 +00002463 // Read in the starting proc id
Jim Cownie5e8470a2013-09-27 10:38:44 +00002464 //
2465 SKIP_WS(*scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002466 if ((**scan < '0') || (**scan > '9')) {
2467 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2468 return FALSE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002469 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002470 next = *scan;
2471 SKIP_DIGITS(next);
2472 start = __kmp_str_to_int(*scan, *next);
2473 KMP_ASSERT(start >= 0);
2474 *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002475
Jonathan Peyton30419822017-05-12 18:01:32 +00002476 // valid follow sets are ',' ':' and '}'
2477 SKIP_WS(*scan);
2478 if (**scan == '}') {
2479 break;
2480 }
2481 if (**scan == ',') {
2482 (*scan)++; // skip ','
2483 continue;
2484 }
2485 if (**scan != ':') {
2486 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2487 return FALSE;
2488 }
2489 (*scan)++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002490
Jonathan Peyton30419822017-05-12 18:01:32 +00002491 // Read count parameter
2492 SKIP_WS(*scan);
2493 if ((**scan < '0') || (**scan > '9')) {
2494 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2495 return FALSE;
2496 }
2497 next = *scan;
2498 SKIP_DIGITS(next);
2499 count = __kmp_str_to_int(*scan, *next);
2500 KMP_ASSERT(count >= 0);
2501 *scan = next;
2502
2503 // valid follow sets are ',' ':' and '}'
2504 SKIP_WS(*scan);
2505 if (**scan == '}') {
2506 break;
2507 }
2508 if (**scan == ',') {
2509 (*scan)++; // skip ','
2510 continue;
2511 }
2512 if (**scan != ':') {
2513 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2514 return FALSE;
2515 }
2516 (*scan)++; // skip ':'
2517
2518 // Read stride parameter
2519 int sign = +1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002520 for (;;) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002521 SKIP_WS(*scan);
2522 if (**scan == '+') {
2523 (*scan)++; // skip '+'
2524 continue;
2525 }
2526 if (**scan == '-') {
2527 sign *= -1;
2528 (*scan)++; // skip '-'
2529 continue;
2530 }
2531 break;
2532 }
2533 SKIP_WS(*scan);
2534 if ((**scan < '0') || (**scan > '9')) {
2535 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2536 return FALSE;
2537 }
2538 next = *scan;
2539 SKIP_DIGITS(next);
2540 stride = __kmp_str_to_int(*scan, *next);
2541 KMP_ASSERT(stride >= 0);
2542 *scan = next;
2543 stride *= sign;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002544
Jonathan Peyton30419822017-05-12 18:01:32 +00002545 // valid follow sets are ',' and '}'
2546 SKIP_WS(*scan);
2547 if (**scan == '}') {
2548 break;
2549 }
2550 if (**scan == ',') {
2551 (*scan)++; // skip ','
2552 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002553 }
2554
Jonathan Peyton30419822017-05-12 18:01:32 +00002555 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2556 return FALSE;
2557 }
2558 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002559}
2560
Jonathan Peyton30419822017-05-12 18:01:32 +00002561static int __kmp_parse_place(const char *var, const char **scan) {
2562 const char *next;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002563
Jonathan Peyton30419822017-05-12 18:01:32 +00002564 // valid follow sets are '{' '!' and num
2565 SKIP_WS(*scan);
2566 if (**scan == '{') {
2567 (*scan)++; // skip '{'
2568 if (!__kmp_parse_subplace_list(var, scan)) {
2569 return FALSE;
2570 }
2571 if (**scan != '}') {
2572 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2573 return FALSE;
2574 }
2575 (*scan)++; // skip '}'
2576 } else if (**scan == '!') {
2577 (*scan)++; // skip '!'
2578 return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2579 } else if ((**scan >= '0') && (**scan <= '9')) {
2580 next = *scan;
2581 SKIP_DIGITS(next);
2582 int proc = __kmp_str_to_int(*scan, *next);
2583 KMP_ASSERT(proc >= 0);
2584 *scan = next;
2585 } else {
2586 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2587 return FALSE;
2588 }
2589 return TRUE;
2590}
2591
2592static int __kmp_parse_place_list(const char *var, const char *env,
2593 char **place_list) {
2594 const char *scan = env;
2595 const char *next = scan;
2596
2597 for (;;) {
2598 int start, count, stride;
2599
2600 if (!__kmp_parse_place(var, &scan)) {
2601 return FALSE;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002602 }
2603
Jonathan Peyton30419822017-05-12 18:01:32 +00002604 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002605 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002606 if (*scan == '\0') {
2607 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002608 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002609 if (*scan == ',') {
2610 scan++; // skip ','
2611 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002612 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002613 if (*scan != ':') {
2614 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2615 return FALSE;
2616 }
2617 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002618
Jonathan Peyton30419822017-05-12 18:01:32 +00002619 // Read count parameter
Jim Cownie5e8470a2013-09-27 10:38:44 +00002620 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002621 if ((*scan < '0') || (*scan > '9')) {
2622 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2623 return FALSE;
2624 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002625 next = scan;
2626 SKIP_DIGITS(next);
2627 count = __kmp_str_to_int(scan, *next);
2628 KMP_ASSERT(count >= 0);
2629 scan = next;
2630
Jonathan Peyton30419822017-05-12 18:01:32 +00002631 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002632 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002633 if (*scan == '\0') {
2634 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002635 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002636 if (*scan == ',') {
2637 scan++; // skip ','
2638 continue;
2639 }
2640 if (*scan != ':') {
2641 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2642 return FALSE;
2643 }
2644 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002645
Jonathan Peyton30419822017-05-12 18:01:32 +00002646 // Read stride parameter
2647 int sign = +1;
2648 for (;;) {
2649 SKIP_WS(scan);
2650 if (*scan == '+') {
2651 scan++; // skip '+'
2652 continue;
2653 }
2654 if (*scan == '-') {
2655 sign *= -1;
2656 scan++; // skip '-'
2657 continue;
2658 }
2659 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002660 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002661 SKIP_WS(scan);
2662 if ((*scan < '0') || (*scan > '9')) {
2663 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2664 return FALSE;
2665 }
2666 next = scan;
2667 SKIP_DIGITS(next);
2668 stride = __kmp_str_to_int(scan, *next);
2669 KMP_ASSERT(stride >= 0);
2670 scan = next;
2671 stride *= sign;
2672
2673 // valid follow sets are ',' and EOL
2674 SKIP_WS(scan);
2675 if (*scan == '\0') {
2676 break;
2677 }
2678 if (*scan == ',') {
2679 scan++; // skip ','
2680 continue;
2681 }
2682
2683 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2684 return FALSE;
2685 }
2686
2687 {
2688 int len = scan - env;
2689 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
2690 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
2691 retlist[len] = '\0';
2692 *place_list = retlist;
2693 }
2694 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002695}
2696
Jonathan Peyton30419822017-05-12 18:01:32 +00002697static void __kmp_stg_parse_places(char const *name, char const *value,
2698 void *data) {
2699 int count;
2700 const char *scan = value;
2701 const char *next = scan;
2702 const char *kind = "\"threads\"";
2703 kmp_setting_t **rivals = (kmp_setting_t **)data;
2704 int rc;
2705
2706 rc = __kmp_stg_check_rivals(name, value, rivals);
2707 if (rc) {
2708 return;
2709 }
2710
2711 // If OMP_PROC_BIND is not specified but OMP_PLACES is,
2712 // then let OMP_PROC_BIND default to true.
2713 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2714 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2715 }
2716
2717 //__kmp_affinity_num_places = 0;
2718
2719 if (__kmp_match_str("threads", scan, &next)) {
2720 scan = next;
2721 __kmp_affinity_type = affinity_compact;
2722 __kmp_affinity_gran = affinity_gran_thread;
2723 __kmp_affinity_dups = FALSE;
2724 kind = "\"threads\"";
2725 } else if (__kmp_match_str("cores", scan, &next)) {
2726 scan = next;
2727 __kmp_affinity_type = affinity_compact;
2728 __kmp_affinity_gran = affinity_gran_core;
2729 __kmp_affinity_dups = FALSE;
2730 kind = "\"cores\"";
2731 } else if (__kmp_match_str("sockets", scan, &next)) {
2732 scan = next;
2733 __kmp_affinity_type = affinity_compact;
2734 __kmp_affinity_gran = affinity_gran_package;
2735 __kmp_affinity_dups = FALSE;
2736 kind = "\"sockets\"";
2737 } else {
2738 if (__kmp_affinity_proclist != NULL) {
2739 KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist);
2740 __kmp_affinity_proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002741 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002742 if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2743 __kmp_affinity_type = affinity_explicit;
2744 __kmp_affinity_gran = affinity_gran_fine;
2745 __kmp_affinity_dups = FALSE;
2746 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002747 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
Jonathan Peyton30419822017-05-12 18:01:32 +00002748 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002749 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002750 return;
2751 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002752
Jonathan Peyton30419822017-05-12 18:01:32 +00002753 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2754 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2755 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002756
Jonathan Peyton30419822017-05-12 18:01:32 +00002757 SKIP_WS(scan);
2758 if (*scan == '\0') {
2759 return;
2760 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002761
Jonathan Peyton30419822017-05-12 18:01:32 +00002762 // Parse option count parameter in parentheses
2763 if (*scan != '(') {
2764 KMP_WARNING(SyntaxErrorUsing, name, kind);
2765 return;
2766 }
2767 scan++; // skip '('
Jim Cownie5e8470a2013-09-27 10:38:44 +00002768
Jonathan Peyton30419822017-05-12 18:01:32 +00002769 SKIP_WS(scan);
2770 next = scan;
2771 SKIP_DIGITS(next);
2772 count = __kmp_str_to_int(scan, *next);
2773 KMP_ASSERT(count >= 0);
2774 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002775
Jonathan Peyton30419822017-05-12 18:01:32 +00002776 SKIP_WS(scan);
2777 if (*scan != ')') {
2778 KMP_WARNING(SyntaxErrorUsing, name, kind);
2779 return;
2780 }
2781 scan++; // skip ')'
2782
2783 SKIP_WS(scan);
2784 if (*scan != '\0') {
2785 KMP_WARNING(ParseExtraCharsWarn, name, scan);
2786 }
2787 __kmp_affinity_num_places = count;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002788}
2789
Jonathan Peyton30419822017-05-12 18:01:32 +00002790static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
2791 void *data) {
2792 if (__kmp_env_format) {
2793 KMP_STR_BUF_PRINT_NAME;
2794 } else {
2795 __kmp_str_buf_print(buffer, " %s", name);
2796 }
2797 if ((__kmp_nested_proc_bind.used == 0) ||
2798 (__kmp_nested_proc_bind.bind_types == NULL) ||
2799 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
2800 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2801 } else if (__kmp_affinity_type == affinity_explicit) {
2802 if (__kmp_affinity_proclist != NULL) {
2803 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002804 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002805 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002806 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002807 } else if (__kmp_affinity_type == affinity_compact) {
2808 int num;
2809 if (__kmp_affinity_num_masks > 0) {
2810 num = __kmp_affinity_num_masks;
2811 } else if (__kmp_affinity_num_places > 0) {
2812 num = __kmp_affinity_num_places;
2813 } else {
2814 num = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002815 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002816 if (__kmp_affinity_gran == affinity_gran_thread) {
2817 if (num > 0) {
2818 __kmp_str_buf_print(buffer, "='threads(%d)'\n", num);
2819 } else {
2820 __kmp_str_buf_print(buffer, "='threads'\n");
2821 }
2822 } else if (__kmp_affinity_gran == affinity_gran_core) {
2823 if (num > 0) {
2824 __kmp_str_buf_print(buffer, "='cores(%d)' \n", num);
2825 } else {
2826 __kmp_str_buf_print(buffer, "='cores'\n");
2827 }
2828 } else if (__kmp_affinity_gran == affinity_gran_package) {
2829 if (num > 0) {
2830 __kmp_str_buf_print(buffer, "='sockets(%d)'\n", num);
2831 } else {
2832 __kmp_str_buf_print(buffer, "='sockets'\n");
2833 }
2834 } else {
2835 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002836 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002837 } else {
2838 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2839 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002840}
2841
2842#endif /* OMP_40_ENABLED */
2843
Jonathan Peyton30419822017-05-12 18:01:32 +00002844#if (!OMP_40_ENABLED)
Jim Cownie5e8470a2013-09-27 10:38:44 +00002845
Jonathan Peyton30419822017-05-12 18:01:32 +00002846static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
2847 void *data) {
2848 int enabled;
2849 kmp_setting_t **rivals = (kmp_setting_t **)data;
2850 int rc;
2851
2852 rc = __kmp_stg_check_rivals(name, value, rivals);
2853 if (rc) {
2854 return;
2855 }
2856
2857 // In OMP 3.1, OMP_PROC_BIND is strictly a boolean
2858 __kmp_stg_parse_bool(name, value, &enabled);
2859 if (enabled) {
2860 // OMP_PROC_BIND => granularity=fine,scatter on MIC
2861 // OMP_PROC_BIND => granularity=core,scatter elsewhere
2862 __kmp_affinity_type = affinity_scatter;
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002863#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002864 if (__kmp_mic_type != non_mic)
2865 __kmp_affinity_gran = affinity_gran_fine;
2866 else
2867#endif
2868 __kmp_affinity_gran = affinity_gran_core;
2869 } else {
2870 __kmp_affinity_type = affinity_none;
2871 }
2872} // __kmp_parse_proc_bind
2873
2874#endif /* if (! OMP_40_ENABLED) */
2875
2876static void __kmp_stg_parse_topology_method(char const *name, char const *value,
2877 void *data) {
2878 if (__kmp_str_match("all", 1, value)) {
2879 __kmp_affinity_top_method = affinity_top_method_all;
2880 }
2881#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2882 else if (__kmp_str_match("x2apic id", 9, value) ||
2883 __kmp_str_match("x2apic_id", 9, value) ||
2884 __kmp_str_match("x2apic-id", 9, value) ||
2885 __kmp_str_match("x2apicid", 8, value) ||
2886 __kmp_str_match("cpuid leaf 11", 13, value) ||
2887 __kmp_str_match("cpuid_leaf_11", 13, value) ||
2888 __kmp_str_match("cpuid-leaf-11", 13, value) ||
2889 __kmp_str_match("cpuid leaf11", 12, value) ||
2890 __kmp_str_match("cpuid_leaf11", 12, value) ||
2891 __kmp_str_match("cpuid-leaf11", 12, value) ||
2892 __kmp_str_match("cpuidleaf 11", 12, value) ||
2893 __kmp_str_match("cpuidleaf_11", 12, value) ||
2894 __kmp_str_match("cpuidleaf-11", 12, value) ||
2895 __kmp_str_match("cpuidleaf11", 11, value) ||
2896 __kmp_str_match("cpuid 11", 8, value) ||
2897 __kmp_str_match("cpuid_11", 8, value) ||
2898 __kmp_str_match("cpuid-11", 8, value) ||
2899 __kmp_str_match("cpuid11", 7, value) ||
2900 __kmp_str_match("leaf 11", 7, value) ||
2901 __kmp_str_match("leaf_11", 7, value) ||
2902 __kmp_str_match("leaf-11", 7, value) ||
2903 __kmp_str_match("leaf11", 6, value)) {
2904 __kmp_affinity_top_method = affinity_top_method_x2apicid;
2905 } else if (__kmp_str_match("apic id", 7, value) ||
2906 __kmp_str_match("apic_id", 7, value) ||
2907 __kmp_str_match("apic-id", 7, value) ||
2908 __kmp_str_match("apicid", 6, value) ||
2909 __kmp_str_match("cpuid leaf 4", 12, value) ||
2910 __kmp_str_match("cpuid_leaf_4", 12, value) ||
2911 __kmp_str_match("cpuid-leaf-4", 12, value) ||
2912 __kmp_str_match("cpuid leaf4", 11, value) ||
2913 __kmp_str_match("cpuid_leaf4", 11, value) ||
2914 __kmp_str_match("cpuid-leaf4", 11, value) ||
2915 __kmp_str_match("cpuidleaf 4", 11, value) ||
2916 __kmp_str_match("cpuidleaf_4", 11, value) ||
2917 __kmp_str_match("cpuidleaf-4", 11, value) ||
2918 __kmp_str_match("cpuidleaf4", 10, value) ||
2919 __kmp_str_match("cpuid 4", 7, value) ||
2920 __kmp_str_match("cpuid_4", 7, value) ||
2921 __kmp_str_match("cpuid-4", 7, value) ||
2922 __kmp_str_match("cpuid4", 6, value) ||
2923 __kmp_str_match("leaf 4", 6, value) ||
2924 __kmp_str_match("leaf_4", 6, value) ||
2925 __kmp_str_match("leaf-4", 6, value) ||
2926 __kmp_str_match("leaf4", 5, value)) {
2927 __kmp_affinity_top_method = affinity_top_method_apicid;
2928 }
2929#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2930 else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
2931 __kmp_str_match("cpuinfo", 5, value)) {
2932 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
2933 }
2934#if KMP_GROUP_AFFINITY
2935 else if (__kmp_str_match("group", 1, value)) {
2936 __kmp_affinity_top_method = affinity_top_method_group;
2937 }
2938#endif /* KMP_GROUP_AFFINITY */
2939 else if (__kmp_str_match("flat", 1, value)) {
2940 __kmp_affinity_top_method = affinity_top_method_flat;
2941 }
2942#if KMP_USE_HWLOC
2943 else if (__kmp_str_match("hwloc", 1, value)) {
2944 __kmp_affinity_top_method = affinity_top_method_hwloc;
2945 }
2946#endif
2947 else {
2948 KMP_WARNING(StgInvalidValue, name, value);
2949 }
2950} // __kmp_stg_parse_topology_method
2951
2952static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
2953 char const *name, void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002954 char const *value = NULL;
2955
2956 switch (__kmp_affinity_top_method) {
2957 case affinity_top_method_default:
2958 value = "default";
2959 break;
2960
2961 case affinity_top_method_all:
2962 value = "all";
2963 break;
2964
2965#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2966 case affinity_top_method_x2apicid:
2967 value = "x2APIC id";
2968 break;
2969
2970 case affinity_top_method_apicid:
2971 value = "APIC id";
2972 break;
2973#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2974
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002975#if KMP_USE_HWLOC
Jonathan Peyton30419822017-05-12 18:01:32 +00002976 case affinity_top_method_hwloc:
2977 value = "hwloc";
2978 break;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002979#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00002980
2981 case affinity_top_method_cpuinfo:
2982 value = "cpuinfo";
2983 break;
2984
2985#if KMP_GROUP_AFFINITY
2986 case affinity_top_method_group:
2987 value = "group";
2988 break;
2989#endif /* KMP_GROUP_AFFINITY */
2990
2991 case affinity_top_method_flat:
2992 value = "flat";
2993 break;
2994 }
2995
2996 if (value != NULL) {
2997 __kmp_stg_print_str(buffer, name, value);
2998 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002999} // __kmp_stg_print_topology_method
3000
3001#endif /* KMP_AFFINITY_SUPPORTED */
3002
3003#if OMP_40_ENABLED
3004
3005// OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
3006// OMP_PLACES / place-partition-var is not.
3007static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
3008 void *data) {
3009 kmp_setting_t **rivals = (kmp_setting_t **)data;
3010 int rc;
3011
3012 rc = __kmp_stg_check_rivals(name, value, rivals);
3013 if (rc) {
3014 return;
3015 }
3016
3017 // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
3018 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
3019 (__kmp_nested_proc_bind.used > 0));
3020
3021 const char *buf = value;
3022 const char *next;
3023 int num;
3024 SKIP_WS(buf);
3025 if ((*buf >= '0') && (*buf <= '9')) {
3026 next = buf;
3027 SKIP_DIGITS(next);
3028 num = __kmp_str_to_int(buf, *next);
3029 KMP_ASSERT(num >= 0);
3030 buf = next;
3031 SKIP_WS(buf);
3032 } else {
3033 num = -1;
3034 }
3035
3036 next = buf;
3037 if (__kmp_match_str("disabled", buf, &next)) {
3038 buf = next;
3039 SKIP_WS(buf);
3040#if KMP_AFFINITY_SUPPORTED
3041 __kmp_affinity_type = affinity_disabled;
3042#endif /* KMP_AFFINITY_SUPPORTED */
3043 __kmp_nested_proc_bind.used = 1;
3044 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3045 } else if ((num == (int)proc_bind_false) ||
3046 __kmp_match_str("false", buf, &next)) {
3047 buf = next;
3048 SKIP_WS(buf);
3049#if KMP_AFFINITY_SUPPORTED
3050 __kmp_affinity_type = affinity_none;
3051#endif /* KMP_AFFINITY_SUPPORTED */
3052 __kmp_nested_proc_bind.used = 1;
3053 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3054 } else if ((num == (int)proc_bind_true) ||
3055 __kmp_match_str("true", buf, &next)) {
3056 buf = next;
3057 SKIP_WS(buf);
3058 __kmp_nested_proc_bind.used = 1;
3059 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3060 } else {
3061 // Count the number of values in the env var string
3062 const char *scan;
3063 int nelem = 1;
3064 for (scan = buf; *scan != '\0'; scan++) {
3065 if (*scan == ',') {
3066 nelem++;
3067 }
3068 }
3069
3070 // Create / expand the nested proc_bind array as needed
3071 if (__kmp_nested_proc_bind.size < nelem) {
3072 __kmp_nested_proc_bind.bind_types =
3073 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3074 __kmp_nested_proc_bind.bind_types,
3075 sizeof(kmp_proc_bind_t) * nelem);
3076 if (__kmp_nested_proc_bind.bind_types == NULL) {
3077 KMP_FATAL(MemoryAllocFailed);
3078 }
3079 __kmp_nested_proc_bind.size = nelem;
3080 }
3081 __kmp_nested_proc_bind.used = nelem;
3082
3083 // Save values in the nested proc_bind array
3084 int i = 0;
3085 for (;;) {
3086 enum kmp_proc_bind_t bind;
3087
3088 if ((num == (int)proc_bind_master) ||
3089 __kmp_match_str("master", buf, &next)) {
3090 buf = next;
3091 SKIP_WS(buf);
3092 bind = proc_bind_master;
3093 } else if ((num == (int)proc_bind_close) ||
3094 __kmp_match_str("close", buf, &next)) {
3095 buf = next;
3096 SKIP_WS(buf);
3097 bind = proc_bind_close;
3098 } else if ((num == (int)proc_bind_spread) ||
3099 __kmp_match_str("spread", buf, &next)) {
3100 buf = next;
3101 SKIP_WS(buf);
3102 bind = proc_bind_spread;
3103 } else {
3104 KMP_WARNING(StgInvalidValue, name, value);
3105 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3106 __kmp_nested_proc_bind.used = 1;
3107 return;
3108 }
3109
3110 __kmp_nested_proc_bind.bind_types[i++] = bind;
3111 if (i >= nelem) {
3112 break;
3113 }
3114 KMP_DEBUG_ASSERT(*buf == ',');
3115 buf++;
3116 SKIP_WS(buf);
3117
3118 // Read next value if it was specified as an integer
3119 if ((*buf >= '0') && (*buf <= '9')) {
3120 next = buf;
3121 SKIP_DIGITS(next);
3122 num = __kmp_str_to_int(buf, *next);
3123 KMP_ASSERT(num >= 0);
3124 buf = next;
3125 SKIP_WS(buf);
3126 } else {
3127 num = -1;
3128 }
3129 }
3130 SKIP_WS(buf);
3131 }
3132 if (*buf != '\0') {
3133 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3134 }
3135}
3136
3137static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
3138 void *data) {
3139 int nelem = __kmp_nested_proc_bind.used;
3140 if (__kmp_env_format) {
3141 KMP_STR_BUF_PRINT_NAME;
3142 } else {
3143 __kmp_str_buf_print(buffer, " %s", name);
3144 }
3145 if (nelem == 0) {
3146 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3147 } else {
3148 int i;
3149 __kmp_str_buf_print(buffer, "='", name);
3150 for (i = 0; i < nelem; i++) {
3151 switch (__kmp_nested_proc_bind.bind_types[i]) {
3152 case proc_bind_false:
3153 __kmp_str_buf_print(buffer, "false");
3154 break;
3155
3156 case proc_bind_true:
3157 __kmp_str_buf_print(buffer, "true");
3158 break;
3159
3160 case proc_bind_master:
3161 __kmp_str_buf_print(buffer, "master");
3162 break;
3163
3164 case proc_bind_close:
3165 __kmp_str_buf_print(buffer, "close");
3166 break;
3167
3168 case proc_bind_spread:
3169 __kmp_str_buf_print(buffer, "spread");
3170 break;
3171
3172 case proc_bind_intel:
3173 __kmp_str_buf_print(buffer, "intel");
3174 break;
3175
3176 case proc_bind_default:
3177 __kmp_str_buf_print(buffer, "default");
3178 break;
3179 }
3180 if (i < nelem - 1) {
3181 __kmp_str_buf_print(buffer, ",");
3182 }
3183 }
3184 __kmp_str_buf_print(buffer, "'\n");
3185 }
3186}
3187
3188#endif /* OMP_40_ENABLED */
3189
3190// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003191// OMP_DYNAMIC
Jim Cownie5e8470a2013-09-27 10:38:44 +00003192
Jonathan Peyton30419822017-05-12 18:01:32 +00003193static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
3194 void *data) {
3195 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003196} // __kmp_stg_parse_omp_dynamic
3197
Jonathan Peyton30419822017-05-12 18:01:32 +00003198static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
3199 void *data) {
3200 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003201} // __kmp_stg_print_omp_dynamic
3202
Jonathan Peyton30419822017-05-12 18:01:32 +00003203static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
3204 char const *value, void *data) {
3205 if (TCR_4(__kmp_init_parallel)) {
3206 KMP_WARNING(EnvParallelWarn, name);
3207 __kmp_env_toPrint(name, 0);
3208 return;
3209 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003210#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00003211 else if (__kmp_str_match("load balance", 2, value) ||
3212 __kmp_str_match("load_balance", 2, value) ||
3213 __kmp_str_match("load-balance", 2, value) ||
3214 __kmp_str_match("loadbalance", 2, value) ||
3215 __kmp_str_match("balance", 1, value)) {
3216 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3217 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003218#endif /* USE_LOAD_BALANCE */
Jonathan Peyton30419822017-05-12 18:01:32 +00003219 else if (__kmp_str_match("thread limit", 1, value) ||
3220 __kmp_str_match("thread_limit", 1, value) ||
3221 __kmp_str_match("thread-limit", 1, value) ||
3222 __kmp_str_match("threadlimit", 1, value) ||
3223 __kmp_str_match("limit", 2, value)) {
3224 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3225 } else if (__kmp_str_match("random", 1, value)) {
3226 __kmp_global.g.g_dynamic_mode = dynamic_random;
3227 } else {
3228 KMP_WARNING(StgInvalidValue, name, value);
3229 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003230} //__kmp_stg_parse_kmp_dynamic_mode
3231
Jonathan Peyton30419822017-05-12 18:01:32 +00003232static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
3233 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003234#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003235 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
3236 __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
3237 }
3238#ifdef USE_LOAD_BALANCE
3239 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
3240 __kmp_stg_print_str(buffer, name, "load balance");
3241 }
3242#endif /* USE_LOAD_BALANCE */
3243 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
3244 __kmp_stg_print_str(buffer, name, "thread limit");
3245 } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
3246 __kmp_stg_print_str(buffer, name, "random");
3247 } else {
3248 KMP_ASSERT(0);
3249 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003250#endif /* KMP_DEBUG */
3251} // __kmp_stg_print_kmp_dynamic_mode
3252
Jim Cownie5e8470a2013-09-27 10:38:44 +00003253#ifdef USE_LOAD_BALANCE
3254
Jonathan Peyton30419822017-05-12 18:01:32 +00003255// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003256// KMP_LOAD_BALANCE_INTERVAL
Jim Cownie5e8470a2013-09-27 10:38:44 +00003257
Jonathan Peyton30419822017-05-12 18:01:32 +00003258static void __kmp_stg_parse_ld_balance_interval(char const *name,
3259 char const *value, void *data) {
3260 double interval = __kmp_convert_to_double(value);
3261 if (interval >= 0) {
3262 __kmp_load_balance_interval = interval;
3263 } else {
3264 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003265 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003266} // __kmp_stg_parse_load_balance_interval
3267
Jonathan Peyton30419822017-05-12 18:01:32 +00003268static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
3269 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003270#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003271 __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
3272 __kmp_load_balance_interval);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003273#endif /* KMP_DEBUG */
3274} // __kmp_stg_print_load_balance_interval
3275
3276#endif /* USE_LOAD_BALANCE */
3277
Jonathan Peyton30419822017-05-12 18:01:32 +00003278// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003279// KMP_INIT_AT_FORK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003280
Jonathan Peyton30419822017-05-12 18:01:32 +00003281static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
3282 void *data) {
3283 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
3284 if (__kmp_need_register_atfork) {
3285 __kmp_need_register_atfork_specified = TRUE;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003286 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003287} // __kmp_stg_parse_init_at_fork
3288
Jonathan Peyton30419822017-05-12 18:01:32 +00003289static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
3290 char const *name, void *data) {
3291 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003292} // __kmp_stg_print_init_at_fork
3293
Jonathan Peyton30419822017-05-12 18:01:32 +00003294// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003295// KMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003296
Jonathan Peyton30419822017-05-12 18:01:32 +00003297static void __kmp_stg_parse_schedule(char const *name, char const *value,
3298 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003299
Jonathan Peyton30419822017-05-12 18:01:32 +00003300 if (value != NULL) {
3301 size_t length = KMP_STRLEN(value);
3302 if (length > INT_MAX) {
3303 KMP_WARNING(LongValue, name);
3304 } else {
3305 char *semicolon;
3306 if (value[length - 1] == '"' || value[length - 1] == '\'')
3307 KMP_WARNING(UnbalancedQuotes, name);
3308 do {
3309 char sentinel;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003310
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003311 semicolon = CCAST(char *, strchr(value, ';'));
Jonathan Peyton30419822017-05-12 18:01:32 +00003312 if (*value && semicolon != value) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003313 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003314
Jonathan Peyton30419822017-05-12 18:01:32 +00003315 if (comma) {
3316 ++comma;
3317 sentinel = ',';
3318 } else
3319 sentinel = ';';
3320 if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
3321 if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
3322 __kmp_static = kmp_sch_static_greedy;
3323 continue;
3324 } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
3325 ';')) {
3326 __kmp_static = kmp_sch_static_balanced;
3327 continue;
3328 }
3329 } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3330 sentinel)) {
3331 if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
3332 __kmp_guided = kmp_sch_guided_iterative_chunked;
3333 continue;
3334 } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
3335 ';')) {
3336 /* analytical not allowed for too many threads */
3337 __kmp_guided = kmp_sch_guided_analytical_chunked;
3338 continue;
3339 }
3340 }
3341 KMP_WARNING(InvalidClause, name, value);
3342 } else
3343 KMP_WARNING(EmptyClause, name);
3344 } while ((value = semicolon ? semicolon + 1 : NULL));
3345 }
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003346 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003347
3348} // __kmp_stg_parse__schedule
3349
Jonathan Peyton30419822017-05-12 18:01:32 +00003350static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
3351 void *data) {
3352 if (__kmp_env_format) {
3353 KMP_STR_BUF_PRINT_NAME_EX(name);
3354 } else {
3355 __kmp_str_buf_print(buffer, " %s='", name);
3356 }
3357 if (__kmp_static == kmp_sch_static_greedy) {
3358 __kmp_str_buf_print(buffer, "%s", "static,greedy");
3359 } else if (__kmp_static == kmp_sch_static_balanced) {
3360 __kmp_str_buf_print(buffer, "%s", "static,balanced");
3361 }
3362 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
3363 __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
3364 } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
3365 __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
3366 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003367} // __kmp_stg_print_schedule
3368
Jonathan Peyton30419822017-05-12 18:01:32 +00003369// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003370// OMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003371
Jonathan Peyton30419822017-05-12 18:01:32 +00003372static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
3373 void *data) {
3374 size_t length;
3375 if (value) {
3376 length = KMP_STRLEN(value);
3377 if (length) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003378 char *comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00003379 if (value[length - 1] == '"' || value[length - 1] == '\'')
3380 KMP_WARNING(UnbalancedQuotes, name);
3381 /* get the specified scheduling style */
3382 if (!__kmp_strcasecmp_with_sentinel("dynamic", value, ',')) /* DYNAMIC */
3383 __kmp_sched = kmp_sch_dynamic_chunked;
3384 else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3385 ',')) /* GUIDED */
3386 __kmp_sched = kmp_sch_guided_chunked;
3387 // AC: TODO: add AUTO schedule, and pprobably remove TRAPEZOIDAL (OMP 3.0
3388 // does not allow it)
3389 else if (!__kmp_strcasecmp_with_sentinel("auto", value, ',')) { /* AUTO */
3390 __kmp_sched = kmp_sch_auto;
3391 if (comma) {
3392 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, comma),
3393 __kmp_msg_null);
3394 comma = NULL;
3395 }
3396 } else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", value,
3397 ',')) /* TRAPEZOIDAL */
3398 __kmp_sched = kmp_sch_trapezoidal;
3399 else if (!__kmp_strcasecmp_with_sentinel("static", value,
3400 ',')) /* STATIC */
3401 __kmp_sched = kmp_sch_static;
Andrey Churbanov429dbc22016-07-11 10:44:57 +00003402#if KMP_STATIC_STEAL_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00003403 else if (!__kmp_strcasecmp_with_sentinel("static_steal", value, ','))
3404 __kmp_sched = kmp_sch_static_steal;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003405#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003406 else {
3407 KMP_WARNING(StgInvalidValue, name, value);
3408 value = NULL; /* skip processing of comma */
3409 }
3410 if (value && comma) {
Jonathan Peyton30419822017-05-12 18:01:32 +00003411 if (__kmp_sched == kmp_sch_static)
3412 __kmp_sched = kmp_sch_static_chunked;
3413 ++comma;
3414 __kmp_chunk = __kmp_str_to_int(comma, 0);
3415 if (__kmp_chunk < 1) {
3416 __kmp_chunk = KMP_DEFAULT_CHUNK;
3417 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, comma),
3418 __kmp_msg_null);
3419 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3420 // AC: next block commented out until KMP_DEFAULT_CHUNK !=
3421 // KMP_MIN_CHUNK (to improve code coverage :)
3422 // The default chunk size is 1 according to standard, thus making
3423 // KMP_MIN_CHUNK not 1 we would introduce mess:
3424 // wrong chunk becomes 1, but it will be impossible to explicitely
3425 // set 1, because it becomes KMP_MIN_CHUNK...
3426 // } else if ( __kmp_chunk < KMP_MIN_CHUNK ) {
3427 // __kmp_chunk = KMP_MIN_CHUNK;
3428 } else if (__kmp_chunk > KMP_MAX_CHUNK) {
3429 __kmp_chunk = KMP_MAX_CHUNK;
3430 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, comma),
3431 __kmp_msg_null);
3432 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3433 }
Jonathan Peytond74d8902017-07-25 18:20:16 +00003434 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003435 } else
3436 KMP_WARNING(EmptyString, name);
3437 }
3438 K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
3439 K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
3440 K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
3441 K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
Jim Cownie5e8470a2013-09-27 10:38:44 +00003442} // __kmp_stg_parse_omp_schedule
3443
Jonathan Peyton30419822017-05-12 18:01:32 +00003444static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
3445 char const *name, void *data) {
3446 if (__kmp_env_format) {
3447 KMP_STR_BUF_PRINT_NAME_EX(name);
3448 } else {
3449 __kmp_str_buf_print(buffer, " %s='", name);
3450 }
3451 if (__kmp_chunk) {
3452 switch (__kmp_sched) {
3453 case kmp_sch_dynamic_chunked:
3454 __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
3455 break;
3456 case kmp_sch_guided_iterative_chunked:
3457 case kmp_sch_guided_analytical_chunked:
3458 __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
3459 break;
3460 case kmp_sch_trapezoidal:
3461 __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
3462 break;
3463 case kmp_sch_static:
3464 case kmp_sch_static_chunked:
3465 case kmp_sch_static_balanced:
3466 case kmp_sch_static_greedy:
3467 __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
3468 break;
3469 case kmp_sch_static_steal:
3470 __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
3471 break;
3472 case kmp_sch_auto:
3473 __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
3474 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003475 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003476 } else {
3477 switch (__kmp_sched) {
3478 case kmp_sch_dynamic_chunked:
3479 __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
3480 break;
3481 case kmp_sch_guided_iterative_chunked:
3482 case kmp_sch_guided_analytical_chunked:
3483 __kmp_str_buf_print(buffer, "%s'\n", "guided");
3484 break;
3485 case kmp_sch_trapezoidal:
3486 __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
3487 break;
3488 case kmp_sch_static:
3489 case kmp_sch_static_chunked:
3490 case kmp_sch_static_balanced:
3491 case kmp_sch_static_greedy:
3492 __kmp_str_buf_print(buffer, "%s'\n", "static");
3493 break;
3494 case kmp_sch_static_steal:
3495 __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
3496 break;
3497 case kmp_sch_auto:
3498 __kmp_str_buf_print(buffer, "%s'\n", "auto");
3499 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003500 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003501 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003502} // __kmp_stg_print_omp_schedule
3503
Jonathan Peyton30419822017-05-12 18:01:32 +00003504// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003505// KMP_ATOMIC_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003506
Jonathan Peyton30419822017-05-12 18:01:32 +00003507static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
3508 void *data) {
3509 // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
3510 // compatibility mode.
3511 int mode = 0;
3512 int max = 1;
3513#ifdef KMP_GOMP_COMPAT
3514 max = 2;
3515#endif /* KMP_GOMP_COMPAT */
3516 __kmp_stg_parse_int(name, value, 0, max, &mode);
3517 // TODO; parse_int is not very suitable for this case. In case of overflow it
3518 // is better to use
3519 // 0 rather that max value.
3520 if (mode > 0) {
3521 __kmp_atomic_mode = mode;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003522 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003523} // __kmp_stg_parse_atomic_mode
3524
Jonathan Peyton30419822017-05-12 18:01:32 +00003525static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
3526 void *data) {
3527 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003528} // __kmp_stg_print_atomic_mode
3529
Jonathan Peyton30419822017-05-12 18:01:32 +00003530// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003531// KMP_CONSISTENCY_CHECK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003532
Jonathan Peyton30419822017-05-12 18:01:32 +00003533static void __kmp_stg_parse_consistency_check(char const *name,
3534 char const *value, void *data) {
3535 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
3536 // Note, this will not work from kmp_set_defaults because th_cons stack was
3537 // not allocated
3538 // for existed thread(s) thus the first __kmp_push_<construct> will break
3539 // with assertion.
3540 // TODO: allocate th_cons if called from kmp_set_defaults.
3541 __kmp_env_consistency_check = TRUE;
3542 } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
3543 __kmp_env_consistency_check = FALSE;
3544 } else {
3545 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003546 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003547} // __kmp_stg_parse_consistency_check
3548
Jonathan Peyton30419822017-05-12 18:01:32 +00003549static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
3550 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003551#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003552 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003553
Jonathan Peyton30419822017-05-12 18:01:32 +00003554 if (__kmp_env_consistency_check) {
3555 value = "all";
3556 } else {
3557 value = "none";
3558 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003559
Jonathan Peyton30419822017-05-12 18:01:32 +00003560 if (value != NULL) {
3561 __kmp_stg_print_str(buffer, name, value);
3562 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003563#endif /* KMP_DEBUG */
3564} // __kmp_stg_print_consistency_check
3565
Jim Cownie5e8470a2013-09-27 10:38:44 +00003566#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00003567// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003568// KMP_ITT_PREPARE_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00003569
3570#if USE_ITT_NOTIFY
3571
Jonathan Peyton30419822017-05-12 18:01:32 +00003572static void __kmp_stg_parse_itt_prepare_delay(char const *name,
3573 char const *value, void *data) {
3574 // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
3575 // iterations.
3576 int delay = 0;
3577 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
3578 __kmp_itt_prepare_delay = delay;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003579} // __kmp_str_parse_itt_prepare_delay
3580
Jonathan Peyton30419822017-05-12 18:01:32 +00003581static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
3582 char const *name, void *data) {
3583 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003584
3585} // __kmp_str_print_itt_prepare_delay
3586
3587#endif // USE_ITT_NOTIFY
3588#endif /* USE_ITT_BUILD */
3589
Jonathan Peyton30419822017-05-12 18:01:32 +00003590// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003591// KMP_MALLOC_POOL_INCR
Jim Cownie5e8470a2013-09-27 10:38:44 +00003592
Jonathan Peyton30419822017-05-12 18:01:32 +00003593static void __kmp_stg_parse_malloc_pool_incr(char const *name,
3594 char const *value, void *data) {
3595 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
3596 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
3597 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003598} // __kmp_stg_parse_malloc_pool_incr
3599
Jonathan Peyton30419822017-05-12 18:01:32 +00003600static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
3601 char const *name, void *data) {
3602 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003603
3604} // _kmp_stg_print_malloc_pool_incr
3605
Jim Cownie5e8470a2013-09-27 10:38:44 +00003606#ifdef KMP_DEBUG
3607
Jonathan Peyton30419822017-05-12 18:01:32 +00003608// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003609// KMP_PAR_RANGE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003610
Jonathan Peyton30419822017-05-12 18:01:32 +00003611static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
3612 void *data) {
3613 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
3614 __kmp_par_range_routine, __kmp_par_range_filename,
3615 &__kmp_par_range_lb, &__kmp_par_range_ub);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003616} // __kmp_stg_parse_par_range_env
3617
Jonathan Peyton30419822017-05-12 18:01:32 +00003618static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
3619 char const *name, void *data) {
3620 if (__kmp_par_range != 0) {
3621 __kmp_stg_print_str(buffer, name, par_range_to_print);
3622 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003623} // __kmp_stg_print_par_range_env
3624
Jonathan Peyton30419822017-05-12 18:01:32 +00003625// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003626// KMP_YIELD_CYCLE, KMP_YIELD_ON, KMP_YIELD_OFF
Jim Cownie5e8470a2013-09-27 10:38:44 +00003627
Jonathan Peyton30419822017-05-12 18:01:32 +00003628static void __kmp_stg_parse_yield_cycle(char const *name, char const *value,
3629 void *data) {
3630 int flag = __kmp_yield_cycle;
3631 __kmp_stg_parse_bool(name, value, &flag);
3632 __kmp_yield_cycle = flag;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003633} // __kmp_stg_parse_yield_cycle
3634
Jonathan Peyton30419822017-05-12 18:01:32 +00003635static void __kmp_stg_print_yield_cycle(kmp_str_buf_t *buffer, char const *name,
3636 void *data) {
3637 __kmp_stg_print_bool(buffer, name, __kmp_yield_cycle);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003638} // __kmp_stg_print_yield_cycle
3639
Jonathan Peyton30419822017-05-12 18:01:32 +00003640static void __kmp_stg_parse_yield_on(char const *name, char const *value,
3641 void *data) {
3642 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003643} // __kmp_stg_parse_yield_on
3644
Jonathan Peyton30419822017-05-12 18:01:32 +00003645static void __kmp_stg_print_yield_on(kmp_str_buf_t *buffer, char const *name,
3646 void *data) {
3647 __kmp_stg_print_int(buffer, name, __kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003648} // __kmp_stg_print_yield_on
3649
Jonathan Peyton30419822017-05-12 18:01:32 +00003650static void __kmp_stg_parse_yield_off(char const *name, char const *value,
3651 void *data) {
3652 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003653} // __kmp_stg_parse_yield_off
3654
Jonathan Peyton30419822017-05-12 18:01:32 +00003655static void __kmp_stg_print_yield_off(kmp_str_buf_t *buffer, char const *name,
3656 void *data) {
3657 __kmp_stg_print_int(buffer, name, __kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003658} // __kmp_stg_print_yield_off
3659
3660#endif
3661
Jonathan Peyton30419822017-05-12 18:01:32 +00003662// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003663// KMP_INIT_WAIT, KMP_NEXT_WAIT
Jim Cownie5e8470a2013-09-27 10:38:44 +00003664
Jonathan Peyton30419822017-05-12 18:01:32 +00003665static void __kmp_stg_parse_init_wait(char const *name, char const *value,
3666 void *data) {
3667 int wait;
3668 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3669 wait = __kmp_init_wait / 2;
3670 __kmp_stg_parse_int(name, value, KMP_MIN_INIT_WAIT, KMP_MAX_INIT_WAIT, &wait);
3671 __kmp_init_wait = wait * 2;
3672 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3673 __kmp_yield_init = __kmp_init_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003674} // __kmp_stg_parse_init_wait
3675
Jonathan Peyton30419822017-05-12 18:01:32 +00003676static void __kmp_stg_print_init_wait(kmp_str_buf_t *buffer, char const *name,
3677 void *data) {
3678 __kmp_stg_print_int(buffer, name, __kmp_init_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003679} // __kmp_stg_print_init_wait
3680
Jonathan Peyton30419822017-05-12 18:01:32 +00003681static void __kmp_stg_parse_next_wait(char const *name, char const *value,
3682 void *data) {
3683 int wait;
3684 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3685 wait = __kmp_next_wait / 2;
3686 __kmp_stg_parse_int(name, value, KMP_MIN_NEXT_WAIT, KMP_MAX_NEXT_WAIT, &wait);
3687 __kmp_next_wait = wait * 2;
3688 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3689 __kmp_yield_next = __kmp_next_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003690} // __kmp_stg_parse_next_wait
3691
Jonathan Peyton30419822017-05-12 18:01:32 +00003692static void __kmp_stg_print_next_wait(kmp_str_buf_t *buffer, char const *name,
3693 void *data) {
3694 __kmp_stg_print_int(buffer, name, __kmp_next_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003695} //__kmp_stg_print_next_wait
3696
Jonathan Peyton30419822017-05-12 18:01:32 +00003697// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003698// KMP_GTID_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003699
Jonathan Peyton30419822017-05-12 18:01:32 +00003700static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
3701 void *data) {
3702 // Modes:
3703 // 0 -- do not change default
3704 // 1 -- sp search
3705 // 2 -- use "keyed" TLS var, i.e.
3706 // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
3707 // 3 -- __declspec(thread) TLS var in tdata section
3708 int mode = 0;
3709 int max = 2;
3710#ifdef KMP_TDATA_GTID
3711 max = 3;
3712#endif /* KMP_TDATA_GTID */
3713 __kmp_stg_parse_int(name, value, 0, max, &mode);
3714 // TODO; parse_int is not very suitable for this case. In case of overflow it
3715 // is better to use 0 rather that max value.
3716 if (mode == 0) {
3717 __kmp_adjust_gtid_mode = TRUE;
3718 } else {
3719 __kmp_gtid_mode = mode;
3720 __kmp_adjust_gtid_mode = FALSE;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003721 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003722} // __kmp_str_parse_gtid_mode
3723
Jonathan Peyton30419822017-05-12 18:01:32 +00003724static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
3725 void *data) {
3726 if (__kmp_adjust_gtid_mode) {
3727 __kmp_stg_print_int(buffer, name, 0);
3728 } else {
3729 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
3730 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003731} // __kmp_stg_print_gtid_mode
3732
Jonathan Peyton30419822017-05-12 18:01:32 +00003733// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003734// KMP_NUM_LOCKS_IN_BLOCK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003735
Jonathan Peyton30419822017-05-12 18:01:32 +00003736static void __kmp_stg_parse_lock_block(char const *name, char const *value,
3737 void *data) {
3738 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003739} // __kmp_str_parse_lock_block
3740
Jonathan Peyton30419822017-05-12 18:01:32 +00003741static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
3742 void *data) {
3743 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003744} // __kmp_stg_print_lock_block
3745
Jonathan Peyton30419822017-05-12 18:01:32 +00003746// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003747// KMP_LOCK_KIND
Jim Cownie5e8470a2013-09-27 10:38:44 +00003748
Jonathan Peytondae13d82015-12-11 21:57:06 +00003749#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00003750#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003751#else
Jonathan Peyton30419822017-05-12 18:01:32 +00003752#define KMP_STORE_LOCK_SEQ(a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003753#endif
3754
Jonathan Peyton30419822017-05-12 18:01:32 +00003755static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
3756 void *data) {
3757 if (__kmp_init_user_locks) {
3758 KMP_WARNING(EnvLockWarn, name);
3759 return;
3760 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003761
Jonathan Peyton30419822017-05-12 18:01:32 +00003762 if (__kmp_str_match("tas", 2, value) ||
3763 __kmp_str_match("test and set", 2, value) ||
3764 __kmp_str_match("test_and_set", 2, value) ||
3765 __kmp_str_match("test-and-set", 2, value) ||
3766 __kmp_str_match("test andset", 2, value) ||
3767 __kmp_str_match("test_andset", 2, value) ||
3768 __kmp_str_match("test-andset", 2, value) ||
3769 __kmp_str_match("testand set", 2, value) ||
3770 __kmp_str_match("testand_set", 2, value) ||
3771 __kmp_str_match("testand-set", 2, value) ||
3772 __kmp_str_match("testandset", 2, value)) {
3773 __kmp_user_lock_kind = lk_tas;
3774 KMP_STORE_LOCK_SEQ(tas);
3775 }
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003776#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003777 else if (__kmp_str_match("futex", 1, value)) {
3778 if (__kmp_futex_determine_capable()) {
3779 __kmp_user_lock_kind = lk_futex;
3780 KMP_STORE_LOCK_SEQ(futex);
3781 } else {
3782 KMP_WARNING(FutexNotSupported, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003783 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003784 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003785#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003786 else if (__kmp_str_match("ticket", 2, value)) {
3787 __kmp_user_lock_kind = lk_ticket;
3788 KMP_STORE_LOCK_SEQ(ticket);
3789 } else if (__kmp_str_match("queuing", 1, value) ||
3790 __kmp_str_match("queue", 1, value)) {
3791 __kmp_user_lock_kind = lk_queuing;
3792 KMP_STORE_LOCK_SEQ(queuing);
3793 } else if (__kmp_str_match("drdpa ticket", 1, value) ||
3794 __kmp_str_match("drdpa_ticket", 1, value) ||
3795 __kmp_str_match("drdpa-ticket", 1, value) ||
3796 __kmp_str_match("drdpaticket", 1, value) ||
3797 __kmp_str_match("drdpa", 1, value)) {
3798 __kmp_user_lock_kind = lk_drdpa;
3799 KMP_STORE_LOCK_SEQ(drdpa);
3800 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003801#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003802 else if (__kmp_str_match("adaptive", 1, value)) {
3803 if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
3804 __kmp_user_lock_kind = lk_adaptive;
3805 KMP_STORE_LOCK_SEQ(adaptive);
3806 } else {
3807 KMP_WARNING(AdaptiveNotSupported, name, value);
3808 __kmp_user_lock_kind = lk_queuing;
3809 KMP_STORE_LOCK_SEQ(queuing);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003810 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003811 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003812#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peytondae13d82015-12-11 21:57:06 +00003813#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003814 else if (__kmp_str_match("rtm", 1, value)) {
3815 if (__kmp_cpuinfo.rtm) {
3816 __kmp_user_lock_kind = lk_rtm;
3817 KMP_STORE_LOCK_SEQ(rtm);
3818 } else {
3819 KMP_WARNING(AdaptiveNotSupported, name, value);
3820 __kmp_user_lock_kind = lk_queuing;
3821 KMP_STORE_LOCK_SEQ(queuing);
Jonathan Peytondae13d82015-12-11 21:57:06 +00003822 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003823 } else if (__kmp_str_match("hle", 1, value)) {
3824 __kmp_user_lock_kind = lk_hle;
3825 KMP_STORE_LOCK_SEQ(hle);
3826 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00003827#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003828 else {
3829 KMP_WARNING(StgInvalidValue, name, value);
3830 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003831}
3832
Jonathan Peyton30419822017-05-12 18:01:32 +00003833static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
3834 void *data) {
3835 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003836
Jonathan Peyton30419822017-05-12 18:01:32 +00003837 switch (__kmp_user_lock_kind) {
3838 case lk_default:
3839 value = "default";
3840 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003841
Jonathan Peyton30419822017-05-12 18:01:32 +00003842 case lk_tas:
3843 value = "tas";
3844 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003845
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003846#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003847 case lk_futex:
3848 value = "futex";
3849 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003850#endif
3851
Jonathan Peytondae13d82015-12-11 21:57:06 +00003852#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003853 case lk_rtm:
3854 value = "rtm";
3855 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003856
Jonathan Peyton30419822017-05-12 18:01:32 +00003857 case lk_hle:
3858 value = "hle";
3859 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003860#endif
3861
Jonathan Peyton30419822017-05-12 18:01:32 +00003862 case lk_ticket:
3863 value = "ticket";
3864 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003865
Jonathan Peyton30419822017-05-12 18:01:32 +00003866 case lk_queuing:
3867 value = "queuing";
3868 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003869
Jonathan Peyton30419822017-05-12 18:01:32 +00003870 case lk_drdpa:
3871 value = "drdpa";
3872 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003873#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003874 case lk_adaptive:
3875 value = "adaptive";
3876 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003877#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003878 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003879
Jonathan Peyton30419822017-05-12 18:01:32 +00003880 if (value != NULL) {
3881 __kmp_stg_print_str(buffer, name, value);
3882 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003883}
3884
Jonathan Peyton30419822017-05-12 18:01:32 +00003885// -----------------------------------------------------------------------------
Jonathan Peyton377aa402016-04-14 16:00:37 +00003886// KMP_SPIN_BACKOFF_PARAMS
Jonathan Peyton377aa402016-04-14 16:00:37 +00003887
Jonathan Peyton30419822017-05-12 18:01:32 +00003888// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
3889// for machine pause)
3890static void __kmp_stg_parse_spin_backoff_params(const char *name,
3891 const char *value, void *data) {
3892 const char *next = value;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003893
Jonathan Peyton30419822017-05-12 18:01:32 +00003894 int total = 0; // Count elements that were set. It'll be used as an array size
3895 int prev_comma = FALSE; // For correct processing sequential commas
3896 int i;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003897
Jonathan Peyton30419822017-05-12 18:01:32 +00003898 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
3899 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003900
Jonathan Peyton30419822017-05-12 18:01:32 +00003901 // Run only 3 iterations because it is enough to read two values or find a
3902 // syntax error
3903 for (i = 0; i < 3; i++) {
3904 SKIP_WS(next);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003905
Jonathan Peyton30419822017-05-12 18:01:32 +00003906 if (*next == '\0') {
3907 break;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003908 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003909 // Next character is not an integer or not a comma OR number of values > 2
3910 // => end of list
3911 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
3912 KMP_WARNING(EnvSyntaxError, name, value);
3913 return;
3914 }
3915 // The next character is ','
3916 if (*next == ',') {
3917 // ',' is the fisrt character
3918 if (total == 0 || prev_comma) {
3919 total++;
3920 }
3921 prev_comma = TRUE;
3922 next++; // skip ','
3923 SKIP_WS(next);
3924 }
3925 // Next character is a digit
3926 if (*next >= '0' && *next <= '9') {
3927 int num;
3928 const char *buf = next;
3929 char const *msg = NULL;
3930 prev_comma = FALSE;
3931 SKIP_DIGITS(next);
3932 total++;
3933
3934 const char *tmp = next;
3935 SKIP_WS(tmp);
3936 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
3937 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003938 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00003939 }
3940
3941 num = __kmp_str_to_int(buf, *next);
3942 if (num <= 0) { // The number of retries should be > 0
3943 msg = KMP_I18N_STR(ValueTooSmall);
3944 num = 1;
3945 } else if (num > KMP_INT_MAX) {
3946 msg = KMP_I18N_STR(ValueTooLarge);
3947 num = KMP_INT_MAX;
3948 }
3949 if (msg != NULL) {
3950 // Message is not empty. Print warning.
3951 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
3952 KMP_INFORM(Using_int_Value, name, num);
3953 }
3954 if (total == 1) {
3955 max_backoff = num;
3956 } else if (total == 2) {
3957 min_tick = num;
3958 }
Jonathan Peyton377aa402016-04-14 16:00:37 +00003959 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003960 }
3961 KMP_DEBUG_ASSERT(total > 0);
3962 if (total <= 0) {
3963 KMP_WARNING(EnvSyntaxError, name, value);
3964 return;
3965 }
3966 __kmp_spin_backoff_params.max_backoff = max_backoff;
3967 __kmp_spin_backoff_params.min_tick = min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003968}
3969
Jonathan Peyton30419822017-05-12 18:01:32 +00003970static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
3971 char const *name, void *data) {
3972 if (__kmp_env_format) {
3973 KMP_STR_BUF_PRINT_NAME_EX(name);
3974 } else {
3975 __kmp_str_buf_print(buffer, " %s='", name);
3976 }
3977 __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
3978 __kmp_spin_backoff_params.min_tick);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003979}
3980
Jim Cownie5e8470a2013-09-27 10:38:44 +00003981#if KMP_USE_ADAPTIVE_LOCKS
3982
Jonathan Peyton30419822017-05-12 18:01:32 +00003983// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003984// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003985
3986// Parse out values for the tunable parameters from a string of the form
3987// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
Jonathan Peyton30419822017-05-12 18:01:32 +00003988static void __kmp_stg_parse_adaptive_lock_props(const char *name,
3989 const char *value, void *data) {
3990 int max_retries = 0;
3991 int max_badness = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003992
Jonathan Peyton30419822017-05-12 18:01:32 +00003993 const char *next = value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003994
Jonathan Peyton30419822017-05-12 18:01:32 +00003995 int total = 0; // Count elements that were set. It'll be used as an array size
3996 int prev_comma = FALSE; // For correct processing sequential commas
3997 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003998
Jonathan Peyton30419822017-05-12 18:01:32 +00003999 // Save values in the structure __kmp_speculative_backoff_params
4000 // Run only 3 iterations because it is enough to read two values or find a
4001 // syntax error
4002 for (i = 0; i < 3; i++) {
4003 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004004
Jonathan Peyton30419822017-05-12 18:01:32 +00004005 if (*next == '\0') {
4006 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004007 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004008 // Next character is not an integer or not a comma OR number of values > 2
4009 // => end of list
4010 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
4011 KMP_WARNING(EnvSyntaxError, name, value);
4012 return;
4013 }
4014 // The next character is ','
4015 if (*next == ',') {
4016 // ',' is the fisrt character
4017 if (total == 0 || prev_comma) {
4018 total++;
4019 }
4020 prev_comma = TRUE;
4021 next++; // skip ','
4022 SKIP_WS(next);
4023 }
4024 // Next character is a digit
4025 if (*next >= '0' && *next <= '9') {
4026 int num;
4027 const char *buf = next;
4028 char const *msg = NULL;
4029 prev_comma = FALSE;
4030 SKIP_DIGITS(next);
4031 total++;
4032
4033 const char *tmp = next;
4034 SKIP_WS(tmp);
4035 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4036 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004037 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00004038 }
4039
4040 num = __kmp_str_to_int(buf, *next);
4041 if (num < 0) { // The number of retries should be >= 0
4042 msg = KMP_I18N_STR(ValueTooSmall);
4043 num = 1;
4044 } else if (num > KMP_INT_MAX) {
4045 msg = KMP_I18N_STR(ValueTooLarge);
4046 num = KMP_INT_MAX;
4047 }
4048 if (msg != NULL) {
4049 // Message is not empty. Print warning.
4050 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4051 KMP_INFORM(Using_int_Value, name, num);
4052 }
4053 if (total == 1) {
4054 max_retries = num;
4055 } else if (total == 2) {
4056 max_badness = num;
4057 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004058 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004059 }
4060 KMP_DEBUG_ASSERT(total > 0);
4061 if (total <= 0) {
4062 KMP_WARNING(EnvSyntaxError, name, value);
4063 return;
4064 }
4065 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4066 __kmp_adaptive_backoff_params.max_badness = max_badness;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004067}
4068
Jonathan Peyton30419822017-05-12 18:01:32 +00004069static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4070 char const *name, void *data) {
4071 if (__kmp_env_format) {
4072 KMP_STR_BUF_PRINT_NAME_EX(name);
4073 } else {
4074 __kmp_str_buf_print(buffer, " %s='", name);
4075 }
4076 __kmp_str_buf_print(buffer, "%d,%d'\n",
4077 __kmp_adaptive_backoff_params.max_soft_retries,
4078 __kmp_adaptive_backoff_params.max_badness);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004079} // __kmp_stg_print_adaptive_lock_props
4080
4081#if KMP_DEBUG_ADAPTIVE_LOCKS
4082
Jonathan Peyton30419822017-05-12 18:01:32 +00004083static void __kmp_stg_parse_speculative_statsfile(char const *name,
4084 char const *value,
4085 void *data) {
4086 __kmp_stg_parse_file(name, value, "", &__kmp_speculative_statsfile);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004087} // __kmp_stg_parse_speculative_statsfile
4088
Jonathan Peyton30419822017-05-12 18:01:32 +00004089static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
4090 char const *name,
4091 void *data) {
4092 if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
4093 __kmp_stg_print_str(buffer, name, "stdout");
4094 } else {
4095 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
4096 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004097
4098} // __kmp_stg_print_speculative_statsfile
4099
4100#endif // KMP_DEBUG_ADAPTIVE_LOCKS
4101
4102#endif // KMP_USE_ADAPTIVE_LOCKS
4103
Jonathan Peyton30419822017-05-12 18:01:32 +00004104// -----------------------------------------------------------------------------
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004105// KMP_HW_SUBSET (was KMP_PLACE_THREADS)
Jim Cownie5e8470a2013-09-27 10:38:44 +00004106
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004107// The longest observable sequense of items is
4108// Socket-Node-Tile-Core-Thread
4109// So, let's limit to 5 levels for now
4110// The input string is usually short enough, let's use 512 limit for now
4111#define MAX_T_LEVEL 5
4112#define MAX_STR_LEN 512
Jonathan Peyton30419822017-05-12 18:01:32 +00004113static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
4114 void *data) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004115 // Value example: 1s,5c@3,2T
4116 // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
4117 static int parsed = 0;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004118 if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
4119 KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
4120 if (parsed == 1) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004121 return; // already parsed KMP_HW_SUBSET
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004122 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004123 }
4124 parsed = 1;
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004125
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004126 char *components[MAX_T_LEVEL];
4127 char const *digits = "0123456789";
4128 char input[MAX_STR_LEN];
4129 size_t len = 0, mlen = MAX_STR_LEN;
4130 int level = 0;
4131 // Canonize the string (remove spaces, unify delimiters, etc.)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004132 char *pos = CCAST(char *, value);
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004133 while (*pos && mlen) {
4134 if (*pos != ' ') { // skip spaces
4135 if (len == 0 && *pos == ':') {
4136 __kmp_hws_abs_flag = 1; // if the first symbol is ":", skip it
4137 } else {
4138 input[len] = toupper(*pos);
4139 if (input[len] == 'X')
4140 input[len] = ','; // unify delimiters of levels
4141 if (input[len] == 'O' && strchr(digits, *(pos + 1)))
4142 input[len] = '@'; // unify delimiters of offset
4143 len++;
4144 }
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004145 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004146 mlen--;
4147 pos++;
4148 }
4149 if (len == 0 || mlen == 0)
4150 goto err; // contents is either empty or too long
4151 input[len] = '\0';
4152 __kmp_hws_requested = 1; // mark that subset requested
4153 // Split by delimiter
4154 pos = input;
4155 components[level++] = pos;
George Rokos4800fc42017-04-25 15:55:39 +00004156 while ((pos = strchr(pos, ','))) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004157 *pos = '\0'; // modify input and avoid more copying
4158 components[level++] = ++pos; // expect something after ","
4159 if (level > MAX_T_LEVEL)
4160 goto err; // too many components provided
4161 }
4162 // Check each component
4163 for (int i = 0; i < level; ++i) {
4164 int offset = 0;
4165 int num = atoi(components[i]); // each component should start with a number
4166 if ((pos = strchr(components[i], '@'))) {
4167 offset = atoi(pos + 1); // save offset
4168 *pos = '\0'; // cut the offset from the component
4169 }
4170 pos = components[i] + strspn(components[i], digits);
4171 if (pos == components[i])
4172 goto err;
4173 // detect the component type
4174 switch (*pos) {
4175 case 'S': // Socket
4176 if (__kmp_hws_socket.num > 0)
4177 goto err; // duplicate is not allowed
4178 __kmp_hws_socket.num = num;
4179 __kmp_hws_socket.offset = offset;
4180 break;
4181 case 'N': // NUMA Node
4182 if (__kmp_hws_node.num > 0)
4183 goto err; // duplicate is not allowed
4184 __kmp_hws_node.num = num;
4185 __kmp_hws_node.offset = offset;
4186 break;
4187 case 'L': // Cache
4188 if (*(pos + 1) == '2') { // L2 - Tile
4189 if (__kmp_hws_tile.num > 0)
4190 goto err; // duplicate is not allowed
4191 __kmp_hws_tile.num = num;
4192 __kmp_hws_tile.offset = offset;
4193 } else if (*(pos + 1) == '3') { // L3 - Socket
4194 if (__kmp_hws_socket.num > 0)
4195 goto err; // duplicate is not allowed
4196 __kmp_hws_socket.num = num;
4197 __kmp_hws_socket.offset = offset;
4198 } else if (*(pos + 1) == '1') { // L1 - Core
4199 if (__kmp_hws_core.num > 0)
4200 goto err; // duplicate is not allowed
4201 __kmp_hws_core.num = num;
4202 __kmp_hws_core.offset = offset;
4203 }
4204 break;
4205 case 'C': // Core (or Cache?)
4206 if (*(pos + 1) != 'A') {
4207 if (__kmp_hws_core.num > 0)
4208 goto err; // duplicate is not allowed
4209 __kmp_hws_core.num = num;
4210 __kmp_hws_core.offset = offset;
4211 } else { // Cache
4212 char *d = pos + strcspn(pos, digits); // find digit
4213 if (*d == '2') { // L2 - Tile
4214 if (__kmp_hws_tile.num > 0)
4215 goto err; // duplicate is not allowed
4216 __kmp_hws_tile.num = num;
4217 __kmp_hws_tile.offset = offset;
4218 } else if (*d == '3') { // L3 - Socket
4219 if (__kmp_hws_socket.num > 0)
4220 goto err; // duplicate is not allowed
4221 __kmp_hws_socket.num = num;
4222 __kmp_hws_socket.offset = offset;
4223 } else if (*d == '1') { // L1 - Core
4224 if (__kmp_hws_core.num > 0)
4225 goto err; // duplicate is not allowed
4226 __kmp_hws_core.num = num;
4227 __kmp_hws_core.offset = offset;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004228 } else {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004229 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004230 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004231 }
4232 break;
4233 case 'T': // Thread
4234 if (__kmp_hws_proc.num > 0)
4235 goto err; // duplicate is not allowed
4236 __kmp_hws_proc.num = num;
4237 __kmp_hws_proc.offset = offset;
4238 break;
4239 default:
4240 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004241 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004242 }
4243 return;
4244err:
4245 KMP_WARNING(AffHWSubsetInvalid, name, value);
4246 __kmp_hws_requested = 0; // mark that subset not requested
4247 return;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004248}
4249
Jonathan Peyton30419822017-05-12 18:01:32 +00004250static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004251 void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +00004252 if (__kmp_hws_requested) {
4253 int comma = 0;
4254 kmp_str_buf_t buf;
4255 __kmp_str_buf_init(&buf);
4256 if (__kmp_env_format)
4257 KMP_STR_BUF_PRINT_NAME_EX(name);
4258 else
4259 __kmp_str_buf_print(buffer, " %s='", name);
4260 if (__kmp_hws_socket.num) {
4261 __kmp_str_buf_print(&buf, "%ds", __kmp_hws_socket.num);
4262 if (__kmp_hws_socket.offset)
4263 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_socket.offset);
4264 comma = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004265 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004266 if (__kmp_hws_node.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004267 __kmp_str_buf_print(&buf, "%s%dn", comma ? "," : "", __kmp_hws_node.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004268 if (__kmp_hws_node.offset)
4269 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_node.offset);
4270 comma = 1;
4271 }
4272 if (__kmp_hws_tile.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004273 __kmp_str_buf_print(&buf, "%s%dL2", comma ? "," : "", __kmp_hws_tile.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004274 if (__kmp_hws_tile.offset)
4275 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_tile.offset);
4276 comma = 1;
4277 }
4278 if (__kmp_hws_core.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004279 __kmp_str_buf_print(&buf, "%s%dc", comma ? "," : "", __kmp_hws_core.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004280 if (__kmp_hws_core.offset)
4281 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_core.offset);
4282 comma = 1;
4283 }
4284 if (__kmp_hws_proc.num)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004285 __kmp_str_buf_print(&buf, "%s%dt", comma ? "," : "", __kmp_hws_proc.num);
4286 __kmp_str_buf_print(buffer, "%s'\n", buf.str);
Jonathan Peyton30419822017-05-12 18:01:32 +00004287 __kmp_str_buf_free(&buf);
4288 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004289}
Jim Cownie5e8470a2013-09-27 10:38:44 +00004290
4291#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004292// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004293// KMP_FORKJOIN_FRAMES
Jim Cownie5e8470a2013-09-27 10:38:44 +00004294
Jonathan Peyton30419822017-05-12 18:01:32 +00004295static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
4296 void *data) {
4297 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004298} // __kmp_stg_parse_forkjoin_frames
4299
Jonathan Peyton30419822017-05-12 18:01:32 +00004300static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
4301 char const *name, void *data) {
4302 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004303} // __kmp_stg_print_forkjoin_frames
4304
Jonathan Peyton30419822017-05-12 18:01:32 +00004305// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004306// KMP_FORKJOIN_FRAMES_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00004307
Jonathan Peyton30419822017-05-12 18:01:32 +00004308static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
4309 char const *value,
4310 void *data) {
4311 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004312} // __kmp_stg_parse_forkjoin_frames
4313
Jonathan Peyton30419822017-05-12 18:01:32 +00004314static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
4315 char const *name, void *data) {
4316 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004317} // __kmp_stg_print_forkjoin_frames
4318#endif /* USE_ITT_BUILD */
4319
Jonathan Peyton30419822017-05-12 18:01:32 +00004320// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004321// OMP_DISPLAY_ENV
Jim Cownie5e8470a2013-09-27 10:38:44 +00004322
4323#if OMP_40_ENABLED
4324
Jonathan Peyton30419822017-05-12 18:01:32 +00004325static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
4326 void *data) {
4327 if (__kmp_str_match("VERBOSE", 1, value)) {
4328 __kmp_display_env_verbose = TRUE;
4329 } else {
4330 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
4331 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004332
4333} // __kmp_stg_parse_omp_display_env
4334
Jonathan Peyton30419822017-05-12 18:01:32 +00004335static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
4336 char const *name, void *data) {
4337 if (__kmp_display_env_verbose) {
4338 __kmp_stg_print_str(buffer, name, "VERBOSE");
4339 } else {
4340 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
4341 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004342} // __kmp_stg_print_omp_display_env
4343
Jonathan Peyton30419822017-05-12 18:01:32 +00004344static void __kmp_stg_parse_omp_cancellation(char const *name,
4345 char const *value, void *data) {
4346 if (TCR_4(__kmp_init_parallel)) {
4347 KMP_WARNING(EnvParallelWarn, name);
4348 return;
4349 } // read value before first parallel only
4350 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004351} // __kmp_stg_parse_omp_cancellation
4352
Jonathan Peyton30419822017-05-12 18:01:32 +00004353static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
4354 char const *name, void *data) {
4355 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004356} // __kmp_stg_print_omp_cancellation
4357
Jim Cownie5e8470a2013-09-27 10:38:44 +00004358#endif
4359
Jonathan Peyton30419822017-05-12 18:01:32 +00004360// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004361// Table.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004362
4363static kmp_setting_t __kmp_stg_table[] = {
4364
Jonathan Peyton09244f32017-07-26 20:07:58 +00004365 {"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
Jonathan Peyton30419822017-05-12 18:01:32 +00004366 {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
4367 NULL, 0, 0},
4368 {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
4369 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
4370 {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
4371 NULL, 0, 0},
Jonathan Peyton09244f32017-07-26 20:07:58 +00004372 {"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
4373 __kmp_stg_print_device_thread_limit, NULL, 0, 0},
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004374#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +00004375 {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
4376 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004377#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004378 {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
4379 0, 0},
4380 {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
4381 __kmp_stg_print_stackoffset, NULL, 0, 0},
4382 {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4383 NULL, 0, 0},
4384 {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
4385 0, 0},
4386 {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
4387 0},
4388 {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
4389 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004390
Jonathan Peyton30419822017-05-12 18:01:32 +00004391 {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
4392 {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
4393 __kmp_stg_print_num_threads, NULL, 0, 0},
4394 {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4395 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004396
Jonathan Peyton30419822017-05-12 18:01:32 +00004397 {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
4398 0},
4399 {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
4400 __kmp_stg_print_task_stealing, NULL, 0, 0},
4401 {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
4402 __kmp_stg_print_max_active_levels, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004403#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004404 {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
4405 __kmp_stg_print_default_device, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004406#endif
Jonathan Peytondf6818b2016-06-14 17:57:47 +00004407#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004408 {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
4409 __kmp_stg_print_max_task_priority, NULL, 0, 0},
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00004410 {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
4411 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
Jonathan Peyton28510722016-02-25 18:04:09 +00004412#endif
Jonathan Peytonf4392462017-07-27 20:58:41 +00004413 {"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
4414 __kmp_stg_print_thread_limit, NULL, 0, 0},
Jonathan Peyton4f90c822017-08-02 20:04:45 +00004415 {"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
4416 __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
Jonathan Peyton30419822017-05-12 18:01:32 +00004417 {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
4418 __kmp_stg_print_wait_policy, NULL, 0, 0},
4419 {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
4420 __kmp_stg_print_disp_buffers, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004421#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00004422 {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
4423 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
4424 {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
4425 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004426#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00004427
4428#if KMP_HANDLE_SIGNALS
Jonathan Peyton30419822017-05-12 18:01:32 +00004429 {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
4430 __kmp_stg_print_handle_signals, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004431#endif
4432
4433#if KMP_ARCH_X86 || KMP_ARCH_X86_64
Jonathan Peyton30419822017-05-12 18:01:32 +00004434 {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
4435 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004436#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
4437
4438#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004439 {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004440#endif
4441
4442#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00004443 {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
4444 0},
4445 {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
4446 0},
4447 {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
4448 0},
4449 {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
4450 0},
4451 {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
4452 0},
4453 {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
4454 0},
4455 {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
4456 {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
4457 NULL, 0, 0},
4458 {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
4459 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
4460 {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
4461 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
4462 {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
4463 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
4464 {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004465
Jonathan Peyton30419822017-05-12 18:01:32 +00004466 {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
4467 __kmp_stg_print_par_range_env, NULL, 0, 0},
4468 {"KMP_YIELD_CYCLE", __kmp_stg_parse_yield_cycle,
4469 __kmp_stg_print_yield_cycle, NULL, 0, 0},
4470 {"KMP_YIELD_ON", __kmp_stg_parse_yield_on, __kmp_stg_print_yield_on, NULL,
4471 0, 0},
4472 {"KMP_YIELD_OFF", __kmp_stg_parse_yield_off, __kmp_stg_print_yield_off,
4473 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004474#endif // KMP_DEBUG
4475
Jonathan Peyton30419822017-05-12 18:01:32 +00004476 {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
4477 __kmp_stg_print_align_alloc, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004478
Jonathan Peyton30419822017-05-12 18:01:32 +00004479 {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4480 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4481 {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4482 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
4483 {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4484 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4485 {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4486 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004487#if KMP_FAST_REDUCTION_BARRIER
Jonathan Peyton30419822017-05-12 18:01:32 +00004488 {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4489 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4490 {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4491 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004492#endif
4493
Jonathan Peyton30419822017-05-12 18:01:32 +00004494 {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
4495 __kmp_stg_print_abort_delay, NULL, 0, 0},
4496 {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
4497 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
4498 {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
4499 __kmp_stg_print_force_reduction, NULL, 0, 0},
4500 {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
4501 __kmp_stg_print_force_reduction, NULL, 0, 0},
4502 {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
4503 __kmp_stg_print_storage_map, NULL, 0, 0},
4504 {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
4505 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
4506 {"KMP_FOREIGN_THREADS_THREADPRIVATE",
4507 __kmp_stg_parse_foreign_threads_threadprivate,
4508 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004509
Alp Toker98758b02014-03-02 04:12:06 +00004510#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004511 {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
4512 0, 0},
4513#ifdef KMP_GOMP_COMPAT
4514 {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
4515 /* no print */ NULL, 0, 0},
4516#endif /* KMP_GOMP_COMPAT */
4517#if OMP_40_ENABLED
4518 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4519 NULL, 0, 0},
4520 {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
4521#else
4522 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, NULL, /* no print */ NULL, 0,
4523 0},
4524#endif /* OMP_40_ENABLED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00004525
Jonathan Peyton30419822017-05-12 18:01:32 +00004526 {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
4527 __kmp_stg_print_topology_method, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004528
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004529#else
Jim Cownie5e8470a2013-09-27 10:38:44 +00004530
Jonathan Peyton30419822017-05-12 18:01:32 +00004531// KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
4532// OMP_PROC_BIND and proc-bind-var are supported, however.
4533#if OMP_40_ENABLED
4534 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4535 NULL, 0, 0},
4536#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004537
Alp Toker98758b02014-03-02 04:12:06 +00004538#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004539
Jonathan Peyton30419822017-05-12 18:01:32 +00004540 {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
4541 __kmp_stg_print_init_at_fork, NULL, 0, 0},
4542 {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
4543 0, 0},
4544 {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
4545 NULL, 0, 0},
4546 {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
4547 __kmp_stg_print_atomic_mode, NULL, 0, 0},
4548 {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
4549 __kmp_stg_print_consistency_check, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004550
4551#if USE_ITT_BUILD && USE_ITT_NOTIFY
Jonathan Peyton30419822017-05-12 18:01:32 +00004552 {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
4553 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004554#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
Jonathan Peyton30419822017-05-12 18:01:32 +00004555 {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
4556 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
4557 {"KMP_INIT_WAIT", __kmp_stg_parse_init_wait, __kmp_stg_print_init_wait,
4558 NULL, 0, 0},
4559 {"KMP_NEXT_WAIT", __kmp_stg_parse_next_wait, __kmp_stg_print_next_wait,
4560 NULL, 0, 0},
4561 {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
4562 NULL, 0, 0},
4563 {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
4564 NULL, 0, 0},
4565 {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
4566 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004567
4568#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00004569 {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
4570 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004571#endif
4572
Jonathan Peyton30419822017-05-12 18:01:32 +00004573 {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
4574 __kmp_stg_print_lock_block, NULL, 0, 0},
4575 {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
4576 NULL, 0, 0},
4577 {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
4578 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004579#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004580 {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
4581 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004582#if KMP_DEBUG_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004583 {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
4584 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004585#endif
4586#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004587 {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4588 NULL, 0, 0},
4589 {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4590 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004591#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004592 {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
4593 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
4594 {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
4595 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004596#endif
4597
Jonathan Peyton30419822017-05-12 18:01:32 +00004598#if OMP_40_ENABLED
4599 {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
4600 __kmp_stg_print_omp_display_env, NULL, 0, 0},
4601 {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
4602 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004603#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004604 {"", NULL, NULL, NULL, 0, 0}}; // settings
Jim Cownie5e8470a2013-09-27 10:38:44 +00004605
Jonathan Peyton30419822017-05-12 18:01:32 +00004606static int const __kmp_stg_count =
4607 sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004608
Jonathan Peyton30419822017-05-12 18:01:32 +00004609static inline kmp_setting_t *__kmp_stg_find(char const *name) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004610
Jonathan Peyton30419822017-05-12 18:01:32 +00004611 int i;
4612 if (name != NULL) {
4613 for (i = 0; i < __kmp_stg_count; ++i) {
4614 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
4615 return &__kmp_stg_table[i];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004616 }
4617 }
4618 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004619 return NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004620
4621} // __kmp_stg_find
4622
Jonathan Peyton30419822017-05-12 18:01:32 +00004623static int __kmp_stg_cmp(void const *_a, void const *_b) {
Andrey Churbanov5ba90c72017-07-17 09:03:14 +00004624 const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
4625 const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004626
Jonathan Peyton30419822017-05-12 18:01:32 +00004627 // Process KMP_AFFINITY last.
4628 // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
4629 if (strcmp(a->name, "KMP_AFFINITY") == 0) {
4630 if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4631 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004632 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004633 return 1;
4634 } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4635 return -1;
4636 }
4637 return strcmp(a->name, b->name);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004638} // __kmp_stg_cmp
4639
Jonathan Peyton30419822017-05-12 18:01:32 +00004640static void __kmp_stg_init(void) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004641
Jonathan Peyton30419822017-05-12 18:01:32 +00004642 static int initialized = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004643
Jonathan Peyton30419822017-05-12 18:01:32 +00004644 if (!initialized) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004645
Jonathan Peyton30419822017-05-12 18:01:32 +00004646 // Sort table.
4647 qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
4648 __kmp_stg_cmp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004649
Jonathan Peyton30419822017-05-12 18:01:32 +00004650 { // Initialize *_STACKSIZE data.
4651 kmp_setting_t *kmp_stacksize =
4652 __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004653#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004654 kmp_setting_t *gomp_stacksize =
4655 __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004656#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004657 kmp_setting_t *omp_stacksize =
4658 __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004659
Jonathan Peyton30419822017-05-12 18:01:32 +00004660 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4661 // !!! Compiler does not understand rivals is used and optimizes out
4662 // assignments
4663 // !!! rivals[ i ++ ] = ...;
4664 static kmp_setting_t *volatile rivals[4];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004665 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004666#ifdef KMP_GOMP_COMPAT
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004667 static kmp_stg_ss_data_t gomp_data = {1024,
4668 CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004669#endif
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004670 static kmp_stg_ss_data_t omp_data = {1024,
4671 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004672 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004673
Jonathan Peyton30419822017-05-12 18:01:32 +00004674 rivals[i++] = kmp_stacksize;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004675#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004676 if (gomp_stacksize != NULL) {
4677 rivals[i++] = gomp_stacksize;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004678 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004679#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004680 rivals[i++] = omp_stacksize;
4681 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004682
Jonathan Peyton30419822017-05-12 18:01:32 +00004683 kmp_stacksize->data = &kmp_data;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004684#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004685 if (gomp_stacksize != NULL) {
4686 gomp_stacksize->data = &gomp_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004687 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004688#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004689 omp_stacksize->data = &omp_data;
4690 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004691
Jonathan Peyton30419822017-05-12 18:01:32 +00004692 { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
4693 kmp_setting_t *kmp_library =
4694 __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
4695 kmp_setting_t *omp_wait_policy =
4696 __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004697
Jonathan Peyton30419822017-05-12 18:01:32 +00004698 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4699 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004700 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
4701 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004702 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004703
Jonathan Peyton30419822017-05-12 18:01:32 +00004704 rivals[i++] = kmp_library;
4705 if (omp_wait_policy != NULL) {
4706 rivals[i++] = omp_wait_policy;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004707 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004708 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004709
Jonathan Peyton30419822017-05-12 18:01:32 +00004710 kmp_library->data = &kmp_data;
4711 if (omp_wait_policy != NULL) {
4712 omp_wait_policy->data = &omp_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004713 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004714 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004715
Jonathan Peytonf4392462017-07-27 20:58:41 +00004716 { // Initialize KMP_DEVICE_THREAD_LIMIT and KMP_ALL_THREADS
Jonathan Peyton09244f32017-07-26 20:07:58 +00004717 kmp_setting_t *kmp_device_thread_limit =
4718 __kmp_stg_find("KMP_DEVICE_THREAD_LIMIT"); // 1st priority.
Jonathan Peyton30419822017-05-12 18:01:32 +00004719 kmp_setting_t *kmp_all_threads =
Jonathan Peyton09244f32017-07-26 20:07:58 +00004720 __kmp_stg_find("KMP_ALL_THREADS"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004721
Jonathan Peyton30419822017-05-12 18:01:32 +00004722 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
Jonathan Peytonf4392462017-07-27 20:58:41 +00004723 static kmp_setting_t *volatile rivals[3];
Jonathan Peyton30419822017-05-12 18:01:32 +00004724 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004725
Jonathan Peyton09244f32017-07-26 20:07:58 +00004726 rivals[i++] = kmp_device_thread_limit;
Jonathan Peyton30419822017-05-12 18:01:32 +00004727 rivals[i++] = kmp_all_threads;
Jonathan Peyton30419822017-05-12 18:01:32 +00004728 rivals[i++] = NULL;
Jonathan Peyton09244f32017-07-26 20:07:58 +00004729
4730 kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004731 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004732 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004733
Alp Toker98758b02014-03-02 04:12:06 +00004734#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004735 { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
4736 kmp_setting_t *kmp_affinity =
4737 __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
4738 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004739
Jonathan Peyton30419822017-05-12 18:01:32 +00004740#ifdef KMP_GOMP_COMPAT
4741 kmp_setting_t *gomp_cpu_affinity =
4742 __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
4743 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
4744#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004745
Jonathan Peyton30419822017-05-12 18:01:32 +00004746 kmp_setting_t *omp_proc_bind =
4747 __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
4748 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004749
Jonathan Peyton30419822017-05-12 18:01:32 +00004750 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4751 static kmp_setting_t *volatile rivals[4];
4752 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004753
Jonathan Peyton30419822017-05-12 18:01:32 +00004754 rivals[i++] = kmp_affinity;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004755
Jonathan Peyton30419822017-05-12 18:01:32 +00004756#ifdef KMP_GOMP_COMPAT
4757 rivals[i++] = gomp_cpu_affinity;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004758 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004759#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004760
Jonathan Peyton30419822017-05-12 18:01:32 +00004761 rivals[i++] = omp_proc_bind;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004762 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004763 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004764
Jonathan Peyton30419822017-05-12 18:01:32 +00004765#if OMP_40_ENABLED
4766 static kmp_setting_t *volatile places_rivals[4];
4767 i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004768
Jonathan Peyton30419822017-05-12 18:01:32 +00004769 kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
4770 KMP_DEBUG_ASSERT(omp_places != NULL);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004771
Jonathan Peyton30419822017-05-12 18:01:32 +00004772 places_rivals[i++] = kmp_affinity;
4773#ifdef KMP_GOMP_COMPAT
4774 places_rivals[i++] = gomp_cpu_affinity;
4775#endif
4776 places_rivals[i++] = omp_places;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004777 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004778 places_rivals[i++] = NULL;
4779#endif
4780 }
Alp Toker98758b02014-03-02 04:12:06 +00004781#else
Jonathan Peyton30419822017-05-12 18:01:32 +00004782// KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
4783// OMP_PLACES not supported yet.
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004784#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004785
Jonathan Peyton30419822017-05-12 18:01:32 +00004786 { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
4787 kmp_setting_t *kmp_force_red =
4788 __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
4789 kmp_setting_t *kmp_determ_red =
4790 __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004791
Jonathan Peyton30419822017-05-12 18:01:32 +00004792 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4793 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004794 static kmp_stg_fr_data_t force_data = {1,
4795 CCAST(kmp_setting_t **, rivals)};
4796 static kmp_stg_fr_data_t determ_data = {0,
4797 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004798 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004799
Jonathan Peyton30419822017-05-12 18:01:32 +00004800 rivals[i++] = kmp_force_red;
4801 if (kmp_determ_red != NULL) {
4802 rivals[i++] = kmp_determ_red;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004803 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004804 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004805
Jonathan Peyton30419822017-05-12 18:01:32 +00004806 kmp_force_red->data = &force_data;
4807 if (kmp_determ_red != NULL) {
4808 kmp_determ_red->data = &determ_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004809 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004810 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004811
Jonathan Peyton30419822017-05-12 18:01:32 +00004812 initialized = 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004813 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004814
Jonathan Peyton30419822017-05-12 18:01:32 +00004815 // Reset flags.
4816 int i;
4817 for (i = 0; i < __kmp_stg_count; ++i) {
4818 __kmp_stg_table[i].set = 0;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004819 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004820
4821} // __kmp_stg_init
4822
Jonathan Peyton30419822017-05-12 18:01:32 +00004823static void __kmp_stg_parse(char const *name, char const *value) {
4824 // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
4825 // really nameless, they are presented in environment block as
4826 // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
4827 if (name[0] == 0) {
4828 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004829 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004830
Jonathan Peyton30419822017-05-12 18:01:32 +00004831 if (value != NULL) {
4832 kmp_setting_t *setting = __kmp_stg_find(name);
4833 if (setting != NULL) {
4834 setting->parse(name, value, setting->data);
4835 setting->defined = 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004836 }
4837 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004838
4839} // __kmp_stg_parse
4840
Jonathan Peyton30419822017-05-12 18:01:32 +00004841static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
4842 char const *name, // Name of variable.
4843 char const *value, // Value of the variable.
4844 kmp_setting_t **rivals // List of rival settings (must include current one).
4845 ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004846
Jonathan Peyton30419822017-05-12 18:01:32 +00004847 if (rivals == NULL) {
4848 return 0;
4849 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004850
Jonathan Peyton30419822017-05-12 18:01:32 +00004851 // Loop thru higher priority settings (listed before current).
4852 int i = 0;
4853 for (; strcmp(rivals[i]->name, name) != 0; i++) {
4854 KMP_DEBUG_ASSERT(rivals[i] != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004855
Alp Toker763b9392014-02-28 09:42:41 +00004856#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004857 if (rivals[i] == __kmp_affinity_notype) {
4858 // If KMP_AFFINITY is specified without a type name,
4859 // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
4860 continue;
4861 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004862#endif
4863
Jonathan Peyton30419822017-05-12 18:01:32 +00004864 if (rivals[i]->set) {
4865 KMP_WARNING(StgIgnored, name, rivals[i]->name);
4866 return 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004867 }
4868 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004869
Jonathan Peyton30419822017-05-12 18:01:32 +00004870 ++i; // Skip current setting.
4871 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004872
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004873} // __kmp_stg_check_rivals
Jim Cownie5e8470a2013-09-27 10:38:44 +00004874
Jonathan Peyton30419822017-05-12 18:01:32 +00004875static int __kmp_env_toPrint(char const *name, int flag) {
4876 int rc = 0;
4877 kmp_setting_t *setting = __kmp_stg_find(name);
4878 if (setting != NULL) {
4879 rc = setting->defined;
4880 if (flag >= 0) {
4881 setting->defined = flag;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004882 }
4883 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004884 return rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004885}
4886
Jonathan Peyton30419822017-05-12 18:01:32 +00004887static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004888
Jonathan Peyton30419822017-05-12 18:01:32 +00004889 char const *value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004890
Jonathan Peyton30419822017-05-12 18:01:32 +00004891 /* OMP_NUM_THREADS */
4892 value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
4893 if (value) {
4894 ompc_set_num_threads(__kmp_dflt_team_nth);
4895 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004896
Jonathan Peyton30419822017-05-12 18:01:32 +00004897 /* KMP_BLOCKTIME */
4898 value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
4899 if (value) {
4900 kmpc_set_blocktime(__kmp_dflt_blocktime);
4901 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004902
Jonathan Peyton30419822017-05-12 18:01:32 +00004903 /* OMP_NESTED */
4904 value = __kmp_env_blk_var(block, "OMP_NESTED");
4905 if (value) {
4906 ompc_set_nested(__kmp_dflt_nested);
4907 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004908
Jonathan Peyton30419822017-05-12 18:01:32 +00004909 /* OMP_DYNAMIC */
4910 value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
4911 if (value) {
4912 ompc_set_dynamic(__kmp_global.g.g_dynamic);
4913 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004914
4915}
4916
Jonathan Peyton30419822017-05-12 18:01:32 +00004917void __kmp_env_initialize(char const *string) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004918
Jonathan Peyton30419822017-05-12 18:01:32 +00004919 kmp_env_blk_t block;
4920 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004921
Jonathan Peyton30419822017-05-12 18:01:32 +00004922 __kmp_stg_init();
Jim Cownie5e8470a2013-09-27 10:38:44 +00004923
Jonathan Peyton30419822017-05-12 18:01:32 +00004924 // Hack!!!
4925 if (string == NULL) {
4926 // __kmp_max_nth = __kmp_sys_max_nth;
4927 __kmp_threads_capacity =
4928 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004929 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004930 __kmp_env_blk_init(&block, string);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004931
Jonathan Peyton30419822017-05-12 18:01:32 +00004932 // update the set flag on all entries that have an env var
4933 for (i = 0; i < block.count; ++i) {
4934 if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
4935 continue;
4936 }
4937 if (block.vars[i].value == NULL) {
4938 continue;
4939 }
4940 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
4941 if (setting != NULL) {
4942 setting->set = 1;
4943 }
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004944 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004945
Jonathan Peytond74d8902017-07-25 18:20:16 +00004946// We need to know if blocktime was set when processing OMP_WAIT_POLICY
Jonathan Peyton30419822017-05-12 18:01:32 +00004947 blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
Jonathan Peyton50e8f182016-04-04 19:38:32 +00004948
Jonathan Peyton30419822017-05-12 18:01:32 +00004949 // Special case. If we parse environment, not a string, process KMP_WARNINGS
4950 // first.
4951 if (string == NULL) {
4952 char const *name = "KMP_WARNINGS";
4953 char const *value = __kmp_env_blk_var(&block, name);
4954 __kmp_stg_parse(name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004955 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004956
Alp Toker763b9392014-02-28 09:42:41 +00004957#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004958 // Special case. KMP_AFFINITY is not a rival to other affinity env vars
4959 // if no affinity type is specified. We want to allow
4960 // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
4961 // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
4962 // affinity mechanism.
4963 __kmp_affinity_notype = NULL;
4964 char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
4965 if (aff_str != NULL) {
4966// Check if the KMP_AFFINITY type is specified in the string.
4967// We just search the string for "compact", "scatter", etc.
4968// without really parsing the string. The syntax of the
4969// KMP_AFFINITY env var is such that none of the affinity
4970// type names can appear anywhere other that the type
4971// specifier, even as substrings.
4972//
4973// I can't find a case-insensitive version of strstr on Windows* OS.
4974// Use the case-sensitive version for now.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004975
Jonathan Peyton30419822017-05-12 18:01:32 +00004976#if KMP_OS_WINDOWS
4977#define FIND strstr
4978#else
4979#define FIND strcasestr
4980#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004981
Jonathan Peyton30419822017-05-12 18:01:32 +00004982 if ((FIND(aff_str, "none") == NULL) &&
4983 (FIND(aff_str, "physical") == NULL) &&
4984 (FIND(aff_str, "logical") == NULL) &&
4985 (FIND(aff_str, "compact") == NULL) &&
4986 (FIND(aff_str, "scatter") == NULL) &&
4987 (FIND(aff_str, "explicit") == NULL) &&
4988 (FIND(aff_str, "balanced") == NULL) &&
4989 (FIND(aff_str, "disabled") == NULL)) {
4990 __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
4991 } else {
4992 // A new affinity type is specified.
4993 // Reset the affinity flags to their default values,
4994 // in case this is called from kmp_set_defaults().
4995 __kmp_affinity_type = affinity_default;
4996 __kmp_affinity_gran = affinity_gran_default;
4997 __kmp_affinity_top_method = affinity_top_method_default;
4998 __kmp_affinity_respect_mask = affinity_respect_mask_default;
4999 }
5000#undef FIND
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005001
5002#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005003 // Also reset the affinity flags if OMP_PROC_BIND is specified.
5004 aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
5005 if (aff_str != NULL) {
5006 __kmp_affinity_type = affinity_default;
5007 __kmp_affinity_gran = affinity_gran_default;
5008 __kmp_affinity_top_method = affinity_top_method_default;
5009 __kmp_affinity_respect_mask = affinity_respect_mask_default;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005010 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005011#endif /* OMP_40_ENABLED */
5012 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005013
Alp Toker763b9392014-02-28 09:42:41 +00005014#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005015
5016#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005017 // Set up the nested proc bind type vector.
5018 if (__kmp_nested_proc_bind.bind_types == NULL) {
5019 __kmp_nested_proc_bind.bind_types =
5020 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
5021 if (__kmp_nested_proc_bind.bind_types == NULL) {
5022 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005023 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005024 __kmp_nested_proc_bind.size = 1;
5025 __kmp_nested_proc_bind.used = 1;
5026#if KMP_AFFINITY_SUPPORTED
5027 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
5028#else
5029 // default proc bind is false if affinity not supported
5030 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5031#endif
5032 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005033#endif /* OMP_40_ENABLED */
5034
Jonathan Peyton30419822017-05-12 18:01:32 +00005035 // Now process all of the settings.
5036 for (i = 0; i < block.count; ++i) {
5037 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005038 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005039
Jonathan Peyton30419822017-05-12 18:01:32 +00005040 // If user locks have been allocated yet, don't reset the lock vptr table.
5041 if (!__kmp_init_user_locks) {
5042 if (__kmp_user_lock_kind == lk_default) {
5043 __kmp_user_lock_kind = lk_queuing;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005044 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005045#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00005046 __kmp_init_dynamic_user_locks();
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005047#else
Jonathan Peyton30419822017-05-12 18:01:32 +00005048 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005049#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005050 } else {
5051 KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
5052 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
5053// Binds lock functions again to follow the transition between different
5054// KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
5055// as we do not allow lock kind changes after making a call to any
5056// user lock functions (true).
5057#if KMP_USE_DYNAMIC_LOCK
5058 __kmp_init_dynamic_user_locks();
5059#else
5060 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5061#endif
5062 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005063
Alp Toker763b9392014-02-28 09:42:41 +00005064#if KMP_AFFINITY_SUPPORTED
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005065
Jonathan Peyton30419822017-05-12 18:01:32 +00005066 if (!TCR_4(__kmp_init_middle)) {
5067 // Determine if the machine/OS is actually capable of supporting
5068 // affinity.
5069 const char *var = "KMP_AFFINITY";
5070 KMPAffinity::pick_api();
Jonathan Peytone3e2aaf2017-05-31 20:35:22 +00005071#if KMP_USE_HWLOC
5072 // If Hwloc topology discovery was requested but affinity was also disabled,
5073 // then tell user that Hwloc request is being ignored and use default
5074 // topology discovery method.
5075 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
5076 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
5077 KMP_WARNING(AffIgnoringHwloc, var);
5078 __kmp_affinity_top_method = affinity_top_method_all;
5079 }
5080#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005081 if (__kmp_affinity_type == affinity_disabled) {
5082 KMP_AFFINITY_DISABLE();
5083 } else if (!KMP_AFFINITY_CAPABLE()) {
5084 __kmp_affinity_dispatch->determine_capable(var);
5085 if (!KMP_AFFINITY_CAPABLE()) {
5086 if (__kmp_affinity_verbose ||
5087 (__kmp_affinity_warnings &&
5088 (__kmp_affinity_type != affinity_default) &&
5089 (__kmp_affinity_type != affinity_none) &&
5090 (__kmp_affinity_type != affinity_disabled))) {
5091 KMP_WARNING(AffNotSupported, var);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005092 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005093 __kmp_affinity_type = affinity_disabled;
5094 __kmp_affinity_respect_mask = 0;
5095 __kmp_affinity_gran = affinity_gran_fine;
5096 }
5097 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005098
Jonathan Peyton30419822017-05-12 18:01:32 +00005099#if OMP_40_ENABLED
5100 if (__kmp_affinity_type == affinity_disabled) {
5101 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5102 } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
5103 // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
5104 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
5105 }
5106#endif /* OMP_40_ENABLED */
5107
5108 if (KMP_AFFINITY_CAPABLE()) {
5109
5110#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005111 // This checks to see if the initial affinity mask is equal
5112 // to a single windows processor group. If it is, then we do
5113 // not respect the initial affinity mask and instead, use the
5114 // entire machine.
5115 bool exactly_one_group = false;
5116 if (__kmp_num_proc_groups > 1) {
5117 int group;
5118 bool within_one_group;
5119 // Get the initial affinity mask and determine if it is
5120 // contained within a single group.
5121 kmp_affin_mask_t *init_mask;
5122 KMP_CPU_ALLOC(init_mask);
5123 __kmp_get_system_affinity(init_mask, TRUE);
5124 group = __kmp_get_proc_group(init_mask);
5125 within_one_group = (group >= 0);
5126 // If the initial affinity is within a single group,
5127 // then determine if it is equal to that single group.
5128 if (within_one_group) {
5129 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
5130 int num_bits_in_mask = 0;
5131 for (int bit = init_mask->begin(); bit != init_mask->end();
5132 bit = init_mask->next(bit))
5133 num_bits_in_mask++;
5134 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
5135 }
5136 KMP_CPU_FREE(init_mask);
5137 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005138
5139 // Handle the Win 64 group affinity stuff if there are multiple
5140 // processor groups, or if the user requested it, and OMP 4.0
5141 // affinity is not in effect.
5142 if (((__kmp_num_proc_groups > 1) &&
5143 (__kmp_affinity_type == affinity_default)
5144#if OMP_40_ENABLED
5145 && (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default))
5146#endif
5147 || (__kmp_affinity_top_method == affinity_top_method_group)) {
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005148 if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
5149 exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005150 __kmp_affinity_respect_mask = FALSE;
5151 }
5152 if (__kmp_affinity_type == affinity_default) {
5153 __kmp_affinity_type = affinity_compact;
5154#if OMP_40_ENABLED
5155 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5156#endif
5157 }
5158 if (__kmp_affinity_top_method == affinity_top_method_default) {
5159 if (__kmp_affinity_gran == affinity_gran_default) {
5160 __kmp_affinity_top_method = affinity_top_method_group;
5161 __kmp_affinity_gran = affinity_gran_group;
5162 } else if (__kmp_affinity_gran == affinity_gran_group) {
5163 __kmp_affinity_top_method = affinity_top_method_group;
5164 } else {
5165 __kmp_affinity_top_method = affinity_top_method_all;
5166 }
5167 } else if (__kmp_affinity_top_method == affinity_top_method_group) {
5168 if (__kmp_affinity_gran == affinity_gran_default) {
5169 __kmp_affinity_gran = affinity_gran_group;
5170 } else if ((__kmp_affinity_gran != affinity_gran_group) &&
5171 (__kmp_affinity_gran != affinity_gran_fine) &&
5172 (__kmp_affinity_gran != affinity_gran_thread)) {
5173 const char *str = NULL;
5174 switch (__kmp_affinity_gran) {
5175 case affinity_gran_core:
5176 str = "core";
5177 break;
5178 case affinity_gran_package:
5179 str = "package";
5180 break;
5181 case affinity_gran_node:
5182 str = "node";
5183 break;
5184 default:
5185 KMP_DEBUG_ASSERT(0);
5186 }
5187 KMP_WARNING(AffGranTopGroup, var, str);
5188 __kmp_affinity_gran = affinity_gran_fine;
5189 }
5190 } else {
5191 if (__kmp_affinity_gran == affinity_gran_default) {
5192 __kmp_affinity_gran = affinity_gran_core;
5193 } else if (__kmp_affinity_gran == affinity_gran_group) {
5194 const char *str = NULL;
5195 switch (__kmp_affinity_type) {
5196 case affinity_physical:
5197 str = "physical";
5198 break;
5199 case affinity_logical:
5200 str = "logical";
5201 break;
5202 case affinity_compact:
5203 str = "compact";
5204 break;
5205 case affinity_scatter:
5206 str = "scatter";
5207 break;
5208 case affinity_explicit:
5209 str = "explicit";
5210 break;
5211 // No MIC on windows, so no affinity_balanced case
5212 default:
5213 KMP_DEBUG_ASSERT(0);
5214 }
5215 KMP_WARNING(AffGranGroupType, var, str);
5216 __kmp_affinity_gran = affinity_gran_core;
5217 }
5218 }
5219 } else
5220
5221#endif /* KMP_GROUP_AFFINITY */
5222
5223 {
5224 if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
5225#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005226 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005227 __kmp_affinity_respect_mask = FALSE;
5228 } else
5229#endif /* KMP_GROUP_AFFINITY */
5230 {
5231 __kmp_affinity_respect_mask = TRUE;
5232 }
5233 }
5234#if OMP_40_ENABLED
5235 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
5236 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
5237 if (__kmp_affinity_type == affinity_default) {
5238 __kmp_affinity_type = affinity_compact;
5239 __kmp_affinity_dups = FALSE;
5240 }
5241 } else
5242#endif /* OMP_40_ENABLED */
5243 if (__kmp_affinity_type == affinity_default) {
5244#if OMP_40_ENABLED
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005245#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005246 if (__kmp_mic_type != non_mic) {
5247 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5248 } else
5249#endif
5250 {
Andrey Churbanov94e569e2015-03-10 09:19:47 +00005251 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
Jonathan Peyton30419822017-05-12 18:01:32 +00005252 }
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005253#endif /* OMP_40_ENABLED */
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005254#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005255 if (__kmp_mic_type != non_mic) {
5256 __kmp_affinity_type = affinity_scatter;
5257 } else
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005258#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005259 {
5260 __kmp_affinity_type = affinity_none;
5261 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005262 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005263 if ((__kmp_affinity_gran == affinity_gran_default) &&
5264 (__kmp_affinity_gran_levels < 0)) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005265#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005266 if (__kmp_mic_type != non_mic) {
5267 __kmp_affinity_gran = affinity_gran_fine;
5268 } else
5269#endif
5270 {
5271 __kmp_affinity_gran = affinity_gran_core;
5272 }
5273 }
5274 if (__kmp_affinity_top_method == affinity_top_method_default) {
5275 __kmp_affinity_top_method = affinity_top_method_all;
5276 }
5277 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005278 }
5279
Jonathan Peyton30419822017-05-12 18:01:32 +00005280 K_DIAG(1, ("__kmp_affinity_type == %d\n", __kmp_affinity_type));
5281 K_DIAG(1, ("__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
5282 K_DIAG(1, ("__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
5283 K_DIAG(1, ("__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
5284 K_DIAG(1, ("__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
5285 K_DIAG(1, ("__kmp_affinity_respect_mask == %d\n",
5286 __kmp_affinity_respect_mask));
5287 K_DIAG(1, ("__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
5288
5289 KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
5290#if OMP_40_ENABLED
5291 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
5292#endif
5293 }
5294
Alp Toker763b9392014-02-28 09:42:41 +00005295#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005296
Jonathan Peyton30419822017-05-12 18:01:32 +00005297 if (__kmp_version) {
5298 __kmp_print_version_1();
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005299 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005300
Jonathan Peyton30419822017-05-12 18:01:32 +00005301 // Post-initialization step: some env. vars need their value's further
5302 // processing
5303 if (string != NULL) { // kmp_set_defaults() was called
5304 __kmp_aux_env_initialize(&block);
5305 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005306
Jonathan Peyton30419822017-05-12 18:01:32 +00005307 __kmp_env_blk_free(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005308
Jonathan Peyton30419822017-05-12 18:01:32 +00005309 KMP_MB();
Jim Cownie5e8470a2013-09-27 10:38:44 +00005310
5311} // __kmp_env_initialize
5312
Jonathan Peyton30419822017-05-12 18:01:32 +00005313void __kmp_env_print() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005314
Jonathan Peyton30419822017-05-12 18:01:32 +00005315 kmp_env_blk_t block;
5316 int i;
5317 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005318
Jonathan Peyton30419822017-05-12 18:01:32 +00005319 __kmp_stg_init();
5320 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005321
Jonathan Peyton30419822017-05-12 18:01:32 +00005322 __kmp_env_blk_init(&block, NULL);
5323 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005324
Jonathan Peyton30419822017-05-12 18:01:32 +00005325 // Print real environment values.
5326 __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
5327 for (i = 0; i < block.count; ++i) {
5328 char const *name = block.vars[i].name;
5329 char const *value = block.vars[i].value;
5330 if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
5331 strncmp(name, "OMP_", 4) == 0
5332#ifdef KMP_GOMP_COMPAT
5333 || strncmp(name, "GOMP_", 5) == 0
5334#endif // KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00005335 ) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005336 __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005337 }
5338 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005339 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005340
Jonathan Peyton30419822017-05-12 18:01:32 +00005341 // Print internal (effective) settings.
5342 __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
5343 for (int i = 0; i < __kmp_stg_count; ++i) {
5344 if (__kmp_stg_table[i].print != NULL) {
5345 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5346 __kmp_stg_table[i].data);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005347 }
5348 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005349
Jonathan Peyton30419822017-05-12 18:01:32 +00005350 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005351
Jonathan Peyton30419822017-05-12 18:01:32 +00005352 __kmp_env_blk_free(&block);
5353 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005354
Jonathan Peyton30419822017-05-12 18:01:32 +00005355 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005356
5357} // __kmp_env_print
5358
Jim Cownie5e8470a2013-09-27 10:38:44 +00005359#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005360void __kmp_env_print_2() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005361
Jonathan Peyton30419822017-05-12 18:01:32 +00005362 kmp_env_blk_t block;
5363 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005364
Jonathan Peyton30419822017-05-12 18:01:32 +00005365 __kmp_env_format = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005366
Jonathan Peyton30419822017-05-12 18:01:32 +00005367 __kmp_stg_init();
5368 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005369
Jonathan Peyton30419822017-05-12 18:01:32 +00005370 __kmp_env_blk_init(&block, NULL);
5371 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005372
Jonathan Peyton30419822017-05-12 18:01:32 +00005373 __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
5374 __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005375
Jonathan Peyton30419822017-05-12 18:01:32 +00005376 for (int i = 0; i < __kmp_stg_count; ++i) {
5377 if (__kmp_stg_table[i].print != NULL &&
5378 ((__kmp_display_env &&
5379 strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
5380 __kmp_display_env_verbose)) {
5381 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5382 __kmp_stg_table[i].data);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005383 }
5384 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005385
Jonathan Peyton30419822017-05-12 18:01:32 +00005386 __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
5387 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005388
Jonathan Peyton30419822017-05-12 18:01:32 +00005389 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005390
Jonathan Peyton30419822017-05-12 18:01:32 +00005391 __kmp_env_blk_free(&block);
5392 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005393
Jonathan Peyton30419822017-05-12 18:01:32 +00005394 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005395
5396} // __kmp_env_print_2
5397#endif // OMP_40_ENABLED
5398
Jim Cownie5e8470a2013-09-27 10:38:44 +00005399// end of file