blob: b4328e706525bb72aee218b06e8d733e706d0759 [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
Jim Cownie5e8470a2013-09-27 10:38:44 +00005//===----------------------------------------------------------------------===//
6//
7// The LLVM Compiler Infrastructure
8//
9// This file is dual licensed under the MIT and the University of Illinois Open
10// Source Licenses. See LICENSE.txt for details.
11//
12//===----------------------------------------------------------------------===//
13
Jim Cownie5e8470a2013-09-27 10:38:44 +000014#include "kmp.h"
Jonathan Peyton1cdd87a2016-11-14 21:08:35 +000015#include "kmp_affinity.h"
Jonathan Peyton30419822017-05-12 18:01:32 +000016#include "kmp_atomic.h"
17#include "kmp_environment.h"
18#include "kmp_i18n.h"
19#include "kmp_io.h"
20#include "kmp_itt.h"
21#include "kmp_lock.h"
22#include "kmp_settings.h"
23#include "kmp_str.h"
24#include "kmp_wrapper_getpid.h"
Jonathan Peyton94a114f2017-10-20 19:30:57 +000025#include <ctype.h> // toupper()
Jim Cownie5e8470a2013-09-27 10:38:44 +000026
Jonathan Peyton30419822017-05-12 18:01:32 +000027static int __kmp_env_toPrint(char const *name, int flag);
Jim Cownie5e8470a2013-09-27 10:38:44 +000028
29bool __kmp_env_format = 0; // 0 - old format; 1 - new format
Jonathan Peyton30419822017-05-12 18:01:32 +000030
31// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +000032// Helper string functions. Subject to move to kmp_str.
Jim Cownie5e8470a2013-09-27 10:38:44 +000033
Jonathan Peyton30419822017-05-12 18:01:32 +000034static double __kmp_convert_to_double(char const *s) {
35 double result;
Jim Cownie5e8470a2013-09-27 10:38:44 +000036
Jonathan Peyton30419822017-05-12 18:01:32 +000037 if (KMP_SSCANF(s, "%lf", &result) < 1) {
38 result = 0.0;
39 }
Jim Cownie5e8470a2013-09-27 10:38:44 +000040
Jonathan Peyton30419822017-05-12 18:01:32 +000041 return result;
Jim Cownie5e8470a2013-09-27 10:38:44 +000042}
43
Jonathan Peyton2321d572015-06-08 19:25:25 +000044#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +000045static unsigned int __kmp_readstr_with_sentinel(char *dest, char const *src,
46 size_t len, char sentinel) {
47 unsigned int i;
48 for (i = 0; i < len; i++) {
49 if ((*src == '\0') || (*src == sentinel)) {
50 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +000051 }
Jonathan Peyton30419822017-05-12 18:01:32 +000052 *(dest++) = *(src++);
53 }
54 *dest = '\0';
55 return i;
Jim Cownie5e8470a2013-09-27 10:38:44 +000056}
Jonathan Peyton2321d572015-06-08 19:25:25 +000057#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +000058
Jonathan Peyton30419822017-05-12 18:01:32 +000059static int __kmp_match_with_sentinel(char const *a, char const *b, size_t len,
60 char sentinel) {
61 size_t l = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +000062
Jonathan Peyton30419822017-05-12 18:01:32 +000063 if (a == NULL)
64 a = "";
65 if (b == NULL)
66 b = "";
67 while (*a && *b && *b != sentinel) {
68 char ca = *a, cb = *b;
Jim Cownie5e8470a2013-09-27 10:38:44 +000069
Jonathan Peyton30419822017-05-12 18:01:32 +000070 if (ca >= 'a' && ca <= 'z')
71 ca -= 'a' - 'A';
72 if (cb >= 'a' && cb <= 'z')
73 cb -= 'a' - 'A';
74 if (ca != cb)
75 return FALSE;
76 ++l;
77 ++a;
78 ++b;
79 }
80 return l >= len;
Jim Cownie5e8470a2013-09-27 10:38:44 +000081}
82
Jim Cownie5e8470a2013-09-27 10:38:44 +000083// Expected usage:
84// token is the token to check for.
85// buf is the string being parsed.
86// *end returns the char after the end of the token.
87// it is not modified unless a match occurs.
88//
Jim Cownie5e8470a2013-09-27 10:38:44 +000089// Example 1:
90//
91// if (__kmp_match_str("token", buf, *end) {
92// <do something>
93// buf = end;
94// }
95//
96// Example 2:
97//
98// if (__kmp_match_str("token", buf, *end) {
99// char *save = **end;
100// **end = sentinel;
101// <use any of the __kmp*_with_sentinel() functions>
102// **end = save;
103// buf = end;
104// }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000105
Jonathan Peyton30419822017-05-12 18:01:32 +0000106static int __kmp_match_str(char const *token, char const *buf,
107 const char **end) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000108
Jonathan Peyton30419822017-05-12 18:01:32 +0000109 KMP_ASSERT(token != NULL);
110 KMP_ASSERT(buf != NULL);
111 KMP_ASSERT(end != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000112
Jonathan Peyton30419822017-05-12 18:01:32 +0000113 while (*token && *buf) {
114 char ct = *token, cb = *buf;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000115
Jonathan Peyton30419822017-05-12 18:01:32 +0000116 if (ct >= 'a' && ct <= 'z')
117 ct -= 'a' - 'A';
118 if (cb >= 'a' && cb <= 'z')
119 cb -= 'a' - 'A';
120 if (ct != cb)
121 return FALSE;
122 ++token;
123 ++buf;
124 }
125 if (*token) {
126 return FALSE;
127 }
128 *end = buf;
129 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000130}
131
Jonathan Peyton30419822017-05-12 18:01:32 +0000132static size_t __kmp_round4k(size_t size) {
133 size_t _4k = 4 * 1024;
134 if (size & (_4k - 1)) {
135 size &= ~(_4k - 1);
136 if (size <= KMP_SIZE_T_MAX - _4k) {
137 size += _4k; // Round up if there is no overflow.
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000138 }
139 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000140 return size;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000141} // __kmp_round4k
142
Jonathan Peyton30419822017-05-12 18:01:32 +0000143/* Here, multipliers are like __kmp_convert_to_seconds, but floating-point
144 values are allowed, and the return value is in milliseconds. The default
145 multiplier is milliseconds. Returns INT_MAX only if the value specified
146 matches "infinit*". Returns -1 if specified string is invalid. */
147int __kmp_convert_to_milliseconds(char const *data) {
148 int ret, nvalues, factor;
149 char mult, extra;
150 double value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000151
Jonathan Peyton30419822017-05-12 18:01:32 +0000152 if (data == NULL)
153 return (-1);
154 if (__kmp_str_match("infinit", -1, data))
155 return (INT_MAX);
156 value = (double)0.0;
157 mult = '\0';
158 nvalues = KMP_SSCANF(data, "%lf%c%c", &value, &mult, &extra);
159 if (nvalues < 1)
160 return (-1);
161 if (nvalues == 1)
Jim Cownie5e8470a2013-09-27 10:38:44 +0000162 mult = '\0';
Jonathan Peyton30419822017-05-12 18:01:32 +0000163 if (nvalues == 3)
164 return (-1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000165
Jonathan Peyton30419822017-05-12 18:01:32 +0000166 if (value < 0)
167 return (-1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000168
Jonathan Peyton30419822017-05-12 18:01:32 +0000169 switch (mult) {
170 case '\0':
171 /* default is milliseconds */
172 factor = 1;
173 break;
174 case 's':
175 case 'S':
176 factor = 1000;
177 break;
178 case 'm':
179 case 'M':
180 factor = 1000 * 60;
181 break;
182 case 'h':
183 case 'H':
184 factor = 1000 * 60 * 60;
185 break;
186 case 'd':
187 case 'D':
188 factor = 1000 * 24 * 60 * 60;
189 break;
190 default:
191 return (-1);
192 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000193
Jonathan Peyton30419822017-05-12 18:01:32 +0000194 if (value >= ((INT_MAX - 1) / factor))
195 ret = INT_MAX - 1; /* Don't allow infinite value here */
196 else
197 ret = (int)(value * (double)factor); /* truncate to int */
Jim Cownie5e8470a2013-09-27 10:38:44 +0000198
Jonathan Peyton30419822017-05-12 18:01:32 +0000199 return ret;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000200}
201
Jonathan Peyton30419822017-05-12 18:01:32 +0000202static int __kmp_strcasecmp_with_sentinel(char const *a, char const *b,
203 char sentinel) {
204 if (a == NULL)
205 a = "";
206 if (b == NULL)
207 b = "";
208 while (*a && *b && *b != sentinel) {
209 char ca = *a, cb = *b;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000210
Jonathan Peyton30419822017-05-12 18:01:32 +0000211 if (ca >= 'a' && ca <= 'z')
212 ca -= 'a' - 'A';
213 if (cb >= 'a' && cb <= 'z')
214 cb -= 'a' - 'A';
215 if (ca != cb)
216 return (int)(unsigned char)*a - (int)(unsigned char)*b;
217 ++a;
218 ++b;
219 }
220 return *a
221 ? (*b && *b != sentinel)
222 ? (int)(unsigned char)*a - (int)(unsigned char)*b
223 : 1
224 : (*b && *b != sentinel) ? -1 : 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000225}
226
Jonathan Peyton30419822017-05-12 18:01:32 +0000227// =============================================================================
Jim Cownie5e8470a2013-09-27 10:38:44 +0000228// Table structures and helper functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000229
Jonathan Peyton30419822017-05-12 18:01:32 +0000230typedef struct __kmp_setting kmp_setting_t;
231typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
232typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
233typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000234
Jonathan Peyton30419822017-05-12 18:01:32 +0000235typedef void (*kmp_stg_parse_func_t)(char const *name, char const *value,
236 void *data);
237typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer, char const *name,
238 void *data);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000239
240struct __kmp_setting {
Jonathan Peyton30419822017-05-12 18:01:32 +0000241 char const *name; // Name of setting (environment variable).
242 kmp_stg_parse_func_t parse; // Parser function.
243 kmp_stg_print_func_t print; // Print function.
244 void *data; // Data passed to parser and printer.
245 int set; // Variable set during this "session"
246 // (__kmp_env_initialize() or kmp_set_defaults() call).
247 int defined; // Variable set in any "session".
Jim Cownie5e8470a2013-09-27 10:38:44 +0000248}; // struct __kmp_setting
249
250struct __kmp_stg_ss_data {
Jonathan Peyton30419822017-05-12 18:01:32 +0000251 size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
252 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
Jim Cownie5e8470a2013-09-27 10:38:44 +0000253}; // struct __kmp_stg_ss_data
254
255struct __kmp_stg_wp_data {
Jonathan Peyton30419822017-05-12 18:01:32 +0000256 int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
257 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
Jim Cownie5e8470a2013-09-27 10:38:44 +0000258}; // struct __kmp_stg_wp_data
259
260struct __kmp_stg_fr_data {
Jonathan Peyton30419822017-05-12 18:01:32 +0000261 int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
262 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
Jim Cownie5e8470a2013-09-27 10:38:44 +0000263}; // struct __kmp_stg_fr_data
264
Jonathan Peyton30419822017-05-12 18:01:32 +0000265static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
266 char const *name, // Name of variable.
267 char const *value, // Value of the variable.
268 kmp_setting_t **rivals // List of rival settings (must include current one).
269 );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000270
Jonathan Peyton30419822017-05-12 18:01:32 +0000271// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000272// Helper parse functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000273
Jonathan Peyton30419822017-05-12 18:01:32 +0000274static void __kmp_stg_parse_bool(char const *name, char const *value,
275 int *out) {
276 if (__kmp_str_match_true(value)) {
277 *out = TRUE;
278 } else if (__kmp_str_match_false(value)) {
279 *out = FALSE;
280 } else {
281 __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
282 KMP_HNT(ValidBoolValues), __kmp_msg_null);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000283 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000284} // __kmp_stg_parse_bool
285
Jonathan Peyton30419822017-05-12 18:01:32 +0000286static void __kmp_stg_parse_size(char const *name, char const *value,
287 size_t size_min, size_t size_max,
288 int *is_specified, size_t *out,
289 size_t factor) {
290 char const *msg = NULL;
291#if KMP_OS_DARWIN
292 size_min = __kmp_round4k(size_min);
293 size_max = __kmp_round4k(size_max);
294#endif // KMP_OS_DARWIN
295 if (value) {
296 if (is_specified != NULL) {
297 *is_specified = 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000298 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000299 __kmp_str_to_size(value, out, factor, &msg);
300 if (msg == NULL) {
301 if (*out > size_max) {
302 *out = size_max;
303 msg = KMP_I18N_STR(ValueTooLarge);
304 } else if (*out < size_min) {
305 *out = size_min;
306 msg = KMP_I18N_STR(ValueTooSmall);
307 } else {
308#if KMP_OS_DARWIN
309 size_t round4k = __kmp_round4k(*out);
310 if (*out != round4k) {
311 *out = round4k;
312 msg = KMP_I18N_STR(NotMultiple4K);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000313 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000314#endif
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000315 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000316 } else {
317 // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to
318 // size_max silently.
319 if (*out < size_min) {
320 *out = size_max;
321 } else if (*out > size_max) {
322 *out = size_max;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000323 }
324 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000325 if (msg != NULL) {
326 // Message is not empty. Print warning.
327 kmp_str_buf_t buf;
328 __kmp_str_buf_init(&buf);
329 __kmp_str_buf_print_size(&buf, *out);
330 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
331 KMP_INFORM(Using_str_Value, name, buf.str);
332 __kmp_str_buf_free(&buf);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000333 }
334 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000335} // __kmp_stg_parse_size
336
Jonathan Peyton2321d572015-06-08 19:25:25 +0000337#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +0000338static void __kmp_stg_parse_str(char const *name, char const *value,
339 char const **out) {
340 __kmp_str_free(out);
341 *out = __kmp_str_format("%s", value);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000342} // __kmp_stg_parse_str
Jonathan Peyton2321d572015-06-08 19:25:25 +0000343#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000344
Jonathan Peyton30419822017-05-12 18:01:32 +0000345static void __kmp_stg_parse_int(
346 char const
347 *name, // I: Name of environment variable (used in warning messages).
348 char const *value, // I: Value of environment variable to parse.
349 int min, // I: Miminal allowed value.
350 int max, // I: Maximum allowed value.
351 int *out // O: Output (parsed) value.
352 ) {
353 char const *msg = NULL;
354 kmp_uint64 uint = *out;
355 __kmp_str_to_uint(value, &uint, &msg);
356 if (msg == NULL) {
357 if (uint < (unsigned int)min) {
358 msg = KMP_I18N_STR(ValueTooSmall);
359 uint = min;
360 } else if (uint > (unsigned int)max) {
361 msg = KMP_I18N_STR(ValueTooLarge);
362 uint = max;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000363 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000364 } else {
365 // If overflow occurred msg contains error message and uint is very big. Cut
366 // tmp it to INT_MAX.
367 if (uint < (unsigned int)min) {
368 uint = min;
369 } else if (uint > (unsigned int)max) {
370 uint = max;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000371 }
372 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000373 if (msg != NULL) {
374 // Message is not empty. Print warning.
375 kmp_str_buf_t buf;
376 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
377 __kmp_str_buf_init(&buf);
378 __kmp_str_buf_print(&buf, "%" KMP_UINT64_SPEC "", uint);
379 KMP_INFORM(Using_uint64_Value, name, buf.str);
380 __kmp_str_buf_free(&buf);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000381 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000382 *out = uint;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000383} // __kmp_stg_parse_int
384
Jonathan Peyton2321d572015-06-08 19:25:25 +0000385#if KMP_DEBUG_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +0000386static void __kmp_stg_parse_file(char const *name, char const *value,
387 char *suffix, char **out) {
388 char buffer[256];
389 char *t;
390 int hasSuffix;
391 __kmp_str_free(out);
392 t = (char *)strrchr(value, '.');
393 hasSuffix = t && __kmp_str_eqf(t, suffix);
394 t = __kmp_str_format("%s%s", value, hasSuffix ? "" : suffix);
395 __kmp_expand_file_name(buffer, sizeof(buffer), t);
396 __kmp_str_free(&t);
397 *out = __kmp_str_format("%s", buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000398} // __kmp_stg_parse_file
Jonathan Peyton2321d572015-06-08 19:25:25 +0000399#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000400
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000401#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000402static char *par_range_to_print = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000403
Jonathan Peyton30419822017-05-12 18:01:32 +0000404static void __kmp_stg_parse_par_range(char const *name, char const *value,
405 int *out_range, char *out_routine,
406 char *out_file, int *out_lb,
407 int *out_ub) {
408 size_t len = KMP_STRLEN(value + 1);
409 par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
410 KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
411 __kmp_par_range = +1;
412 __kmp_par_range_lb = 0;
413 __kmp_par_range_ub = INT_MAX;
414 for (;;) {
415 unsigned int len;
416 if ((value == NULL) || (*value == '\0')) {
417 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000418 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000419 if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
420 value = strchr(value, '=') + 1;
421 len = __kmp_readstr_with_sentinel(out_routine, value,
422 KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
423 if (len == 0) {
424 goto par_range_error;
425 }
426 value = strchr(value, ',');
427 if (value != NULL) {
428 value++;
429 }
430 continue;
431 }
432 if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
433 value = strchr(value, '=') + 1;
434 len = __kmp_readstr_with_sentinel(out_file, value,
435 KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
436 if (len == 0) {
437 goto par_range_error;
438 }
439 value = strchr(value, ',');
440 if (value != NULL) {
441 value++;
442 }
443 continue;
444 }
445 if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
446 (!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
447 value = strchr(value, '=') + 1;
448 if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
449 goto par_range_error;
450 }
451 *out_range = +1;
452 value = strchr(value, ',');
453 if (value != NULL) {
454 value++;
455 }
456 continue;
457 }
458 if (!__kmp_strcasecmp_with_sentinel("excl_range", value, '=')) {
459 value = strchr(value, '=') + 1;
460 if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
461 goto par_range_error;
462 }
463 *out_range = -1;
464 value = strchr(value, ',');
465 if (value != NULL) {
466 value++;
467 }
468 continue;
469 }
470 par_range_error:
471 KMP_WARNING(ParRangeSyntax, name);
472 __kmp_par_range = 0;
473 break;
474 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000475} // __kmp_stg_parse_par_range
Jim Cownie3051f972014-08-07 10:12:54 +0000476#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000477
Jonathan Peyton30419822017-05-12 18:01:32 +0000478int __kmp_initial_threads_capacity(int req_nproc) {
479 int nth = 32;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000480
Jonathan Peyton30419822017-05-12 18:01:32 +0000481 /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
482 * __kmp_max_nth) */
483 if (nth < (4 * req_nproc))
484 nth = (4 * req_nproc);
485 if (nth < (4 * __kmp_xproc))
486 nth = (4 * __kmp_xproc);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000487
Jonathan Peyton30419822017-05-12 18:01:32 +0000488 if (nth > __kmp_max_nth)
489 nth = __kmp_max_nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000490
Jonathan Peyton30419822017-05-12 18:01:32 +0000491 return nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000492}
493
Jonathan Peyton30419822017-05-12 18:01:32 +0000494int __kmp_default_tp_capacity(int req_nproc, int max_nth,
495 int all_threads_specified) {
496 int nth = 128;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000497
Jonathan Peyton30419822017-05-12 18:01:32 +0000498 if (all_threads_specified)
499 return max_nth;
500 /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
501 * __kmp_max_nth ) */
502 if (nth < (4 * req_nproc))
503 nth = (4 * req_nproc);
504 if (nth < (4 * __kmp_xproc))
505 nth = (4 * __kmp_xproc);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000506
Jonathan Peyton30419822017-05-12 18:01:32 +0000507 if (nth > __kmp_max_nth)
508 nth = __kmp_max_nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000509
Jonathan Peyton30419822017-05-12 18:01:32 +0000510 return nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000511}
512
Jonathan Peyton30419822017-05-12 18:01:32 +0000513// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000514// Helper print functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000515
Jonathan Peyton30419822017-05-12 18:01:32 +0000516static void __kmp_stg_print_bool(kmp_str_buf_t *buffer, char const *name,
517 int value) {
518 if (__kmp_env_format) {
519 KMP_STR_BUF_PRINT_BOOL;
520 } else {
521 __kmp_str_buf_print(buffer, " %s=%s\n", name, value ? "true" : "false");
522 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000523} // __kmp_stg_print_bool
524
Jonathan Peyton30419822017-05-12 18:01:32 +0000525static void __kmp_stg_print_int(kmp_str_buf_t *buffer, char const *name,
526 int value) {
527 if (__kmp_env_format) {
528 KMP_STR_BUF_PRINT_INT;
529 } else {
530 __kmp_str_buf_print(buffer, " %s=%d\n", name, value);
531 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000532} // __kmp_stg_print_int
533
Jonathan Peyton30419822017-05-12 18:01:32 +0000534static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer, char const *name,
535 kmp_uint64 value) {
536 if (__kmp_env_format) {
537 KMP_STR_BUF_PRINT_UINT64;
538 } else {
539 __kmp_str_buf_print(buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value);
540 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000541} // __kmp_stg_print_uint64
542
Jonathan Peyton30419822017-05-12 18:01:32 +0000543static void __kmp_stg_print_str(kmp_str_buf_t *buffer, char const *name,
544 char const *value) {
545 if (__kmp_env_format) {
546 KMP_STR_BUF_PRINT_STR;
547 } else {
548 __kmp_str_buf_print(buffer, " %s=%s\n", name, value);
549 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000550} // __kmp_stg_print_str
551
Jonathan Peyton30419822017-05-12 18:01:32 +0000552static void __kmp_stg_print_size(kmp_str_buf_t *buffer, char const *name,
553 size_t value) {
554 if (__kmp_env_format) {
555 KMP_STR_BUF_PRINT_NAME_EX(name);
556 __kmp_str_buf_print_size(buffer, value);
557 __kmp_str_buf_print(buffer, "'\n");
558 } else {
559 __kmp_str_buf_print(buffer, " %s=", name);
560 __kmp_str_buf_print_size(buffer, value);
561 __kmp_str_buf_print(buffer, "\n");
562 return;
563 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000564} // __kmp_stg_print_size
565
Jonathan Peyton30419822017-05-12 18:01:32 +0000566// =============================================================================
Jim Cownie5e8470a2013-09-27 10:38:44 +0000567// Parse and print functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000568
Jonathan Peyton30419822017-05-12 18:01:32 +0000569// -----------------------------------------------------------------------------
Jonathan Peytonf4392462017-07-27 20:58:41 +0000570// KMP_DEVICE_THREAD_LIMIT, KMP_ALL_THREADS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000571
Jonathan Peyton09244f32017-07-26 20:07:58 +0000572static void __kmp_stg_parse_device_thread_limit(char const *name,
573 char const *value, void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +0000574 kmp_setting_t **rivals = (kmp_setting_t **)data;
575 int rc;
Jonathan Peyton09244f32017-07-26 20:07:58 +0000576 if (strcmp(name, "KMP_ALL_THREADS") == 0) {
577 KMP_INFORM(EnvVarDeprecated, name, "KMP_DEVICE_THREAD_LIMIT");
578 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000579 rc = __kmp_stg_check_rivals(name, value, rivals);
580 if (rc) {
581 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000582 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000583 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
584 __kmp_max_nth = __kmp_xproc;
585 __kmp_allThreadsSpecified = 1;
586 } else {
587 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
588 __kmp_allThreadsSpecified = 0;
589 }
590 K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000591
Jonathan Peyton09244f32017-07-26 20:07:58 +0000592} // __kmp_stg_parse_device_thread_limit
Jim Cownie5e8470a2013-09-27 10:38:44 +0000593
Jonathan Peyton09244f32017-07-26 20:07:58 +0000594static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
595 char const *name, void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +0000596 __kmp_stg_print_int(buffer, name, __kmp_max_nth);
Jonathan Peyton09244f32017-07-26 20:07:58 +0000597} // __kmp_stg_print_device_thread_limit
Jim Cownie5e8470a2013-09-27 10:38:44 +0000598
Jonathan Peyton30419822017-05-12 18:01:32 +0000599// -----------------------------------------------------------------------------
Jonathan Peytonf4392462017-07-27 20:58:41 +0000600// OMP_THREAD_LIMIT
601static void __kmp_stg_parse_thread_limit(char const *name, char const *value,
602 void *data) {
603 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
604 K_DIAG(1, ("__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));
605
606} // __kmp_stg_parse_thread_limit
607
608static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
609 char const *name, void *data) {
610 __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
611} // __kmp_stg_print_thread_limit
612
613// -----------------------------------------------------------------------------
Jonathan Peyton4f90c822017-08-02 20:04:45 +0000614// KMP_TEAMS_THREAD_LIMIT
615static void __kmp_stg_parse_teams_thread_limit(char const *name,
616 char const *value, void *data) {
617 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
618} // __kmp_stg_teams_thread_limit
619
620static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
621 char const *name, void *data) {
622 __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
623} // __kmp_stg_print_teams_thread_limit
624
625// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000626// KMP_BLOCKTIME
Jim Cownie5e8470a2013-09-27 10:38:44 +0000627
Jonathan Peyton30419822017-05-12 18:01:32 +0000628static void __kmp_stg_parse_blocktime(char const *name, char const *value,
629 void *data) {
630 __kmp_dflt_blocktime = __kmp_convert_to_milliseconds(value);
631 if (__kmp_dflt_blocktime < 0) {
632 __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
633 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
634 __kmp_msg_null);
635 KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime);
636 __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
637 } else {
638 if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
639 __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
640 __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
641 __kmp_msg_null);
642 KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime);
643 } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
644 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
645 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
646 __kmp_msg_null);
647 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000648 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000649 __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000650 }
Jonathan Peytone1c7c132016-10-07 18:12:19 +0000651#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +0000652 // calculate number of monitor thread wakeup intervals corresponding to
653 // blocktime.
654 __kmp_monitor_wakeups =
655 KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
656 __kmp_bt_intervals =
657 KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
Jonathan Peytone1c7c132016-10-07 18:12:19 +0000658#endif
Jonathan Peyton30419822017-05-12 18:01:32 +0000659 K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
660 if (__kmp_env_blocktime) {
661 K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
662 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000663} // __kmp_stg_parse_blocktime
664
Jonathan Peyton30419822017-05-12 18:01:32 +0000665static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
666 void *data) {
667 __kmp_stg_print_int(buffer, name, __kmp_dflt_blocktime);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000668} // __kmp_stg_print_blocktime
669
Jonathan Peytond74d8902017-07-25 18:20:16 +0000670// Used for OMP_WAIT_POLICY
671static char const *blocktime_str = NULL;
672
Jonathan Peyton30419822017-05-12 18:01:32 +0000673// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000674// KMP_DUPLICATE_LIB_OK
Jim Cownie5e8470a2013-09-27 10:38:44 +0000675
Jonathan Peyton30419822017-05-12 18:01:32 +0000676static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
677 char const *value, void *data) {
678 /* actually this variable is not supported, put here for compatibility with
679 earlier builds and for static/dynamic combination */
680 __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000681} // __kmp_stg_parse_duplicate_lib_ok
682
Jonathan Peyton30419822017-05-12 18:01:32 +0000683static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
684 char const *name, void *data) {
685 __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000686} // __kmp_stg_print_duplicate_lib_ok
687
Jonathan Peyton30419822017-05-12 18:01:32 +0000688// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000689// KMP_INHERIT_FP_CONTROL
Jim Cownie5e8470a2013-09-27 10:38:44 +0000690
691#if KMP_ARCH_X86 || KMP_ARCH_X86_64
692
Jonathan Peyton30419822017-05-12 18:01:32 +0000693static void __kmp_stg_parse_inherit_fp_control(char const *name,
694 char const *value, void *data) {
695 __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000696} // __kmp_stg_parse_inherit_fp_control
697
Jonathan Peyton30419822017-05-12 18:01:32 +0000698static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
699 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000700#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000701 __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000702#endif /* KMP_DEBUG */
703} // __kmp_stg_print_inherit_fp_control
704
705#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
706
Jonathan Peyton30419822017-05-12 18:01:32 +0000707// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000708// KMP_LIBRARY, OMP_WAIT_POLICY
Jim Cownie5e8470a2013-09-27 10:38:44 +0000709
Jonathan Peyton30419822017-05-12 18:01:32 +0000710static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
711 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000712
Jonathan Peyton30419822017-05-12 18:01:32 +0000713 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
714 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000715
Jonathan Peyton30419822017-05-12 18:01:32 +0000716 rc = __kmp_stg_check_rivals(name, value, wait->rivals);
717 if (rc) {
718 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000719 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000720
Jonathan Peyton30419822017-05-12 18:01:32 +0000721 if (wait->omp) {
722 if (__kmp_str_match("ACTIVE", 1, value)) {
723 __kmp_library = library_turnaround;
724 if (blocktime_str == NULL) {
725 // KMP_BLOCKTIME not specified, so set default to "infinite".
726 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
727 }
728 } else if (__kmp_str_match("PASSIVE", 1, value)) {
729 __kmp_library = library_throughput;
730 if (blocktime_str == NULL) {
731 // KMP_BLOCKTIME not specified, so set default to 0.
732 __kmp_dflt_blocktime = 0;
733 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000734 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +0000735 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000736 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000737 } else {
738 if (__kmp_str_match("serial", 1, value)) { /* S */
739 __kmp_library = library_serial;
740 } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
741 __kmp_library = library_throughput;
742 } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
743 __kmp_library = library_turnaround;
744 } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
745 __kmp_library = library_turnaround;
746 } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
747 __kmp_library = library_throughput;
748 } else {
749 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000750 }
751 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000752 __kmp_aux_set_library(__kmp_library);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000753
754} // __kmp_stg_parse_wait_policy
755
Jonathan Peyton30419822017-05-12 18:01:32 +0000756static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
757 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000758
Jonathan Peyton30419822017-05-12 18:01:32 +0000759 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
760 char const *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000761
Jonathan Peyton30419822017-05-12 18:01:32 +0000762 if (wait->omp) {
763 switch (__kmp_library) {
764 case library_turnaround: {
765 value = "ACTIVE";
766 } break;
767 case library_throughput: {
768 value = "PASSIVE";
769 } break;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000770 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000771 } else {
772 switch (__kmp_library) {
773 case library_serial: {
774 value = "serial";
775 } break;
776 case library_turnaround: {
777 value = "turnaround";
778 } break;
779 case library_throughput: {
780 value = "throughput";
781 } break;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000782 }
783 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000784 if (value != NULL) {
785 __kmp_stg_print_str(buffer, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000786 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000787
788} // __kmp_stg_print_wait_policy
789
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000790#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +0000791// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000792// KMP_MONITOR_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000793
Jonathan Peyton30419822017-05-12 18:01:32 +0000794static void __kmp_stg_parse_monitor_stacksize(char const *name,
795 char const *value, void *data) {
796 __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
797 NULL, &__kmp_monitor_stksize, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000798} // __kmp_stg_parse_monitor_stacksize
799
Jonathan Peyton30419822017-05-12 18:01:32 +0000800static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
801 char const *name, void *data) {
802 if (__kmp_env_format) {
803 if (__kmp_monitor_stksize > 0)
804 KMP_STR_BUF_PRINT_NAME_EX(name);
805 else
806 KMP_STR_BUF_PRINT_NAME;
807 } else {
808 __kmp_str_buf_print(buffer, " %s", name);
809 }
810 if (__kmp_monitor_stksize > 0) {
811 __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
812 } else {
813 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
814 }
815 if (__kmp_env_format && __kmp_monitor_stksize) {
816 __kmp_str_buf_print(buffer, "'\n");
817 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000818} // __kmp_stg_print_monitor_stacksize
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000819#endif // KMP_USE_MONITOR
Jim Cownie5e8470a2013-09-27 10:38:44 +0000820
Jonathan Peyton30419822017-05-12 18:01:32 +0000821// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000822// KMP_SETTINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000823
Jonathan Peyton30419822017-05-12 18:01:32 +0000824static void __kmp_stg_parse_settings(char const *name, char const *value,
825 void *data) {
826 __kmp_stg_parse_bool(name, value, &__kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000827} // __kmp_stg_parse_settings
828
Jonathan Peyton30419822017-05-12 18:01:32 +0000829static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
830 void *data) {
831 __kmp_stg_print_bool(buffer, name, __kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000832} // __kmp_stg_print_settings
833
Jonathan Peyton30419822017-05-12 18:01:32 +0000834// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000835// KMP_STACKPAD
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000836
Jonathan Peyton30419822017-05-12 18:01:32 +0000837static void __kmp_stg_parse_stackpad(char const *name, char const *value,
838 void *data) {
839 __kmp_stg_parse_int(name, // Env var name
840 value, // Env var value
841 KMP_MIN_STKPADDING, // Min value
842 KMP_MAX_STKPADDING, // Max value
843 &__kmp_stkpadding // Var to initialize
844 );
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000845} // __kmp_stg_parse_stackpad
846
Jonathan Peyton30419822017-05-12 18:01:32 +0000847static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
848 void *data) {
849 __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000850} // __kmp_stg_print_stackpad
851
Jonathan Peyton30419822017-05-12 18:01:32 +0000852// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000853// KMP_STACKOFFSET
Jim Cownie5e8470a2013-09-27 10:38:44 +0000854
Jonathan Peyton30419822017-05-12 18:01:32 +0000855static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
856 void *data) {
857 __kmp_stg_parse_size(name, // Env var name
858 value, // Env var value
859 KMP_MIN_STKOFFSET, // Min value
860 KMP_MAX_STKOFFSET, // Max value
861 NULL, //
862 &__kmp_stkoffset, // Var to initialize
863 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000864} // __kmp_stg_parse_stackoffset
865
Jonathan Peyton30419822017-05-12 18:01:32 +0000866static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
867 void *data) {
868 __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000869} // __kmp_stg_print_stackoffset
870
Jonathan Peyton30419822017-05-12 18:01:32 +0000871// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000872// KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000873
Jonathan Peyton30419822017-05-12 18:01:32 +0000874static void __kmp_stg_parse_stacksize(char const *name, char const *value,
875 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000876
Jonathan Peyton30419822017-05-12 18:01:32 +0000877 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
878 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000879
Jonathan Peyton30419822017-05-12 18:01:32 +0000880 rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
881 if (rc) {
882 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000883 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000884 __kmp_stg_parse_size(name, // Env var name
885 value, // Env var value
886 __kmp_sys_min_stksize, // Min value
887 KMP_MAX_STKSIZE, // Max value
888 &__kmp_env_stksize, //
889 &__kmp_stksize, // Var to initialize
890 stacksize->factor);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000891
892} // __kmp_stg_parse_stacksize
893
Jonathan Peyton30419822017-05-12 18:01:32 +0000894// This function is called for printing both KMP_STACKSIZE (factor is 1) and
895// OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
896// OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
897// customer request in future.
898static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
899 void *data) {
900 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
901 if (__kmp_env_format) {
902 KMP_STR_BUF_PRINT_NAME_EX(name);
903 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
904 ? __kmp_stksize / stacksize->factor
905 : __kmp_stksize);
906 __kmp_str_buf_print(buffer, "'\n");
907 } else {
908 __kmp_str_buf_print(buffer, " %s=", name);
909 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
910 ? __kmp_stksize / stacksize->factor
911 : __kmp_stksize);
912 __kmp_str_buf_print(buffer, "\n");
913 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000914} // __kmp_stg_print_stacksize
915
Jonathan Peyton30419822017-05-12 18:01:32 +0000916// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000917// KMP_VERSION
Jim Cownie5e8470a2013-09-27 10:38:44 +0000918
Jonathan Peyton30419822017-05-12 18:01:32 +0000919static void __kmp_stg_parse_version(char const *name, char const *value,
920 void *data) {
921 __kmp_stg_parse_bool(name, value, &__kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000922} // __kmp_stg_parse_version
923
Jonathan Peyton30419822017-05-12 18:01:32 +0000924static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
925 void *data) {
926 __kmp_stg_print_bool(buffer, name, __kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000927} // __kmp_stg_print_version
928
Jonathan Peyton30419822017-05-12 18:01:32 +0000929// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000930// KMP_WARNINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000931
Jonathan Peyton30419822017-05-12 18:01:32 +0000932static void __kmp_stg_parse_warnings(char const *name, char const *value,
933 void *data) {
934 __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
935 if (__kmp_generate_warnings != kmp_warnings_off) {
936 // AC: only 0/1 values documented, so reset to explicit to distinguish from
937 // default setting
938 __kmp_generate_warnings = kmp_warnings_explicit;
939 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000940} // __kmp_stg_parse_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000941
Jonathan Peyton30419822017-05-12 18:01:32 +0000942static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
943 void *data) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000944 // AC: TODO: change to print_int? (needs documentation change)
945 __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
946} // __kmp_stg_print_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000947
Jonathan Peyton30419822017-05-12 18:01:32 +0000948// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000949// OMP_NESTED, OMP_NUM_THREADS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000950
Jonathan Peyton30419822017-05-12 18:01:32 +0000951static void __kmp_stg_parse_nested(char const *name, char const *value,
952 void *data) {
953 __kmp_stg_parse_bool(name, value, &__kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000954} // __kmp_stg_parse_nested
955
Jonathan Peyton30419822017-05-12 18:01:32 +0000956static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
957 void *data) {
958 __kmp_stg_print_bool(buffer, name, __kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000959} // __kmp_stg_print_nested
960
Jonathan Peyton30419822017-05-12 18:01:32 +0000961static void __kmp_parse_nested_num_threads(const char *var, const char *env,
962 kmp_nested_nthreads_t *nth_array) {
963 const char *next = env;
964 const char *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000965
Jonathan Peyton30419822017-05-12 18:01:32 +0000966 int total = 0; // Count elements that were set. It'll be used as an array size
967 int prev_comma = FALSE; // For correct processing sequential commas
Jim Cownie5e8470a2013-09-27 10:38:44 +0000968
Jonathan Peyton30419822017-05-12 18:01:32 +0000969 // Count the number of values in the env. var string
970 for (;;) {
971 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000972
Jonathan Peyton30419822017-05-12 18:01:32 +0000973 if (*next == '\0') {
974 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000975 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000976 // Next character is not an integer or not a comma => end of list
977 if (((*next < '0') || (*next > '9')) && (*next != ',')) {
978 KMP_WARNING(NthSyntaxError, var, env);
979 return;
980 }
981 // The next character is ','
982 if (*next == ',') {
983 // ',' is the fisrt character
984 if (total == 0 || prev_comma) {
985 total++;
986 }
987 prev_comma = TRUE;
988 next++; // skip ','
989 SKIP_WS(next);
990 }
991 // Next character is a digit
992 if (*next >= '0' && *next <= '9') {
993 prev_comma = FALSE;
994 SKIP_DIGITS(next);
995 total++;
996 const char *tmp = next;
997 SKIP_WS(tmp);
998 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
999 KMP_WARNING(NthSpacesNotAllowed, var, env);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001000 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00001001 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001002 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001003 }
1004 KMP_DEBUG_ASSERT(total > 0);
1005 if (total <= 0) {
1006 KMP_WARNING(NthSyntaxError, var, env);
1007 return;
1008 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001009
Jonathan Peyton30419822017-05-12 18:01:32 +00001010 // Check if the nested nthreads array exists
1011 if (!nth_array->nth) {
1012 // Allocate an array of double size
1013 nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
1014 if (nth_array->nth == NULL) {
1015 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001016 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001017 nth_array->size = total * 2;
1018 } else {
1019 if (nth_array->size < total) {
1020 // Increase the array size
1021 do {
1022 nth_array->size *= 2;
1023 } while (nth_array->size < total);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001024
Jonathan Peyton30419822017-05-12 18:01:32 +00001025 nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
1026 nth_array->nth, sizeof(int) * nth_array->size);
1027 if (nth_array->nth == NULL) {
1028 KMP_FATAL(MemoryAllocFailed);
1029 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001030 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001031 }
1032 nth_array->used = total;
1033 int i = 0;
1034
1035 prev_comma = FALSE;
1036 total = 0;
1037 // Save values in the array
1038 for (;;) {
1039 SKIP_WS(scan);
1040 if (*scan == '\0') {
1041 break;
1042 }
1043 // The next character is ','
1044 if (*scan == ',') {
1045 // ',' in the beginning of the list
1046 if (total == 0) {
1047 // The value is supposed to be equal to __kmp_avail_proc but it is
1048 // unknown at the moment.
1049 // So let's put a placeholder (#threads = 0) to correct it later.
1050 nth_array->nth[i++] = 0;
1051 total++;
1052 } else if (prev_comma) {
1053 // Num threads is inherited from the previous level
1054 nth_array->nth[i] = nth_array->nth[i - 1];
1055 i++;
1056 total++;
1057 }
1058 prev_comma = TRUE;
1059 scan++; // skip ','
1060 SKIP_WS(scan);
1061 }
1062 // Next character is a digit
1063 if (*scan >= '0' && *scan <= '9') {
1064 int num;
1065 const char *buf = scan;
1066 char const *msg = NULL;
1067 prev_comma = FALSE;
1068 SKIP_DIGITS(scan);
1069 total++;
1070
1071 num = __kmp_str_to_int(buf, *scan);
1072 if (num < KMP_MIN_NTH) {
1073 msg = KMP_I18N_STR(ValueTooSmall);
1074 num = KMP_MIN_NTH;
1075 } else if (num > __kmp_sys_max_nth) {
1076 msg = KMP_I18N_STR(ValueTooLarge);
1077 num = __kmp_sys_max_nth;
1078 }
1079 if (msg != NULL) {
1080 // Message is not empty. Print warning.
1081 KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1082 KMP_INFORM(Using_int_Value, var, num);
1083 }
1084 nth_array->nth[i++] = num;
1085 }
1086 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001087}
1088
Jonathan Peyton30419822017-05-12 18:01:32 +00001089static void __kmp_stg_parse_num_threads(char const *name, char const *value,
1090 void *data) {
1091 // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
1092 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
1093 // The array of 1 element
1094 __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
1095 __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1096 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1097 __kmp_xproc;
1098 } else {
1099 __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1100 if (__kmp_nested_nth.nth) {
1101 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1102 if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1103 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1104 }
1105 }
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001106 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001107 K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001108} // __kmp_stg_parse_num_threads
1109
Jonathan Peyton30419822017-05-12 18:01:32 +00001110static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
1111 void *data) {
1112 if (__kmp_env_format) {
1113 KMP_STR_BUF_PRINT_NAME;
1114 } else {
1115 __kmp_str_buf_print(buffer, " %s", name);
1116 }
1117 if (__kmp_nested_nth.used) {
1118 kmp_str_buf_t buf;
1119 __kmp_str_buf_init(&buf);
1120 for (int i = 0; i < __kmp_nested_nth.used; i++) {
1121 __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
1122 if (i < __kmp_nested_nth.used - 1) {
1123 __kmp_str_buf_print(&buf, ",");
1124 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001125 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001126 __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
1127 __kmp_str_buf_free(&buf);
1128 } else {
1129 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1130 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001131} // __kmp_stg_print_num_threads
1132
Jonathan Peyton30419822017-05-12 18:01:32 +00001133// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001134// OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001135
Jonathan Peyton30419822017-05-12 18:01:32 +00001136static void __kmp_stg_parse_tasking(char const *name, char const *value,
1137 void *data) {
1138 __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
1139 (int *)&__kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001140} // __kmp_stg_parse_tasking
1141
Jonathan Peyton30419822017-05-12 18:01:32 +00001142static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
1143 void *data) {
1144 __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001145} // __kmp_stg_print_tasking
1146
Jonathan Peyton30419822017-05-12 18:01:32 +00001147static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
1148 void *data) {
1149 __kmp_stg_parse_int(name, value, 0, 1,
1150 (int *)&__kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001151} // __kmp_stg_parse_task_stealing
1152
Jonathan Peyton30419822017-05-12 18:01:32 +00001153static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1154 char const *name, void *data) {
1155 __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001156} // __kmp_stg_print_task_stealing
1157
Jonathan Peyton30419822017-05-12 18:01:32 +00001158static void __kmp_stg_parse_max_active_levels(char const *name,
1159 char const *value, void *data) {
1160 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1161 &__kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001162} // __kmp_stg_parse_max_active_levels
1163
Jonathan Peyton30419822017-05-12 18:01:32 +00001164static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1165 char const *name, void *data) {
1166 __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001167} // __kmp_stg_print_max_active_levels
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001168
George Rokos28f31b42016-09-09 17:55:26 +00001169#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001170// -----------------------------------------------------------------------------
George Rokos28f31b42016-09-09 17:55:26 +00001171// OpenMP 4.0: OMP_DEFAULT_DEVICE
Jonathan Peyton30419822017-05-12 18:01:32 +00001172static void __kmp_stg_parse_default_device(char const *name, char const *value,
1173 void *data) {
1174 __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1175 &__kmp_default_device);
George Rokos28f31b42016-09-09 17:55:26 +00001176} // __kmp_stg_parse_default_device
1177
Jonathan Peyton30419822017-05-12 18:01:32 +00001178static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1179 char const *name, void *data) {
George Rokos28f31b42016-09-09 17:55:26 +00001180 __kmp_stg_print_int(buffer, name, __kmp_default_device);
1181} // __kmp_stg_print_default_device
1182#endif
1183
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001184#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001185// -----------------------------------------------------------------------------
Jonathan Peyton28510722016-02-25 18:04:09 +00001186// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
Jonathan Peyton30419822017-05-12 18:01:32 +00001187static void __kmp_stg_parse_max_task_priority(char const *name,
1188 char const *value, void *data) {
1189 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1190 &__kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001191} // __kmp_stg_parse_max_task_priority
1192
Jonathan Peyton30419822017-05-12 18:01:32 +00001193static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1194 char const *name, void *data) {
1195 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001196} // __kmp_stg_print_max_task_priority
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001197
1198// KMP_TASKLOOP_MIN_TASKS
1199// taskloop threashold to switch from recursive to linear tasks creation
1200static void __kmp_stg_parse_taskloop_min_tasks(char const *name,
Jonathan Peytond74d8902017-07-25 18:20:16 +00001201 char const *value, void *data) {
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001202 int tmp;
1203 __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1204 __kmp_taskloop_min_tasks = tmp;
1205} // __kmp_stg_parse_taskloop_min_tasks
1206
1207static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
Jonathan Peytond74d8902017-07-25 18:20:16 +00001208 char const *name, void *data) {
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001209 __kmp_stg_print_int(buffer, name, __kmp_taskloop_min_tasks);
1210} // __kmp_stg_print_taskloop_min_tasks
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001211#endif // OMP_45_ENABLED
Jonathan Peyton28510722016-02-25 18:04:09 +00001212
Jonathan Peyton30419822017-05-12 18:01:32 +00001213// -----------------------------------------------------------------------------
Jonathan Peyton067325f2016-05-31 19:01:15 +00001214// KMP_DISP_NUM_BUFFERS
Jonathan Peyton30419822017-05-12 18:01:32 +00001215static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
1216 void *data) {
1217 if (TCR_4(__kmp_init_serial)) {
1218 KMP_WARNING(EnvSerialWarn, name);
1219 return;
1220 } // read value before serial initialization only
1221 __kmp_stg_parse_int(name, value, 1, KMP_MAX_NTH, &__kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001222} // __kmp_stg_parse_disp_buffers
1223
Jonathan Peyton30419822017-05-12 18:01:32 +00001224static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1225 char const *name, void *data) {
1226 __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001227} // __kmp_stg_print_disp_buffers
1228
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001229#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00001230// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001231// KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001232
Jonathan Peyton30419822017-05-12 18:01:32 +00001233static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
1234 void *data) {
1235 if (TCR_4(__kmp_init_parallel)) {
1236 KMP_WARNING(EnvParallelWarn, name);
1237 return;
1238 } // read value before first parallel only
1239 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1240 &__kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001241} // __kmp_stg_parse_hot_teams_level
1242
Jonathan Peyton30419822017-05-12 18:01:32 +00001243static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1244 char const *name, void *data) {
1245 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001246} // __kmp_stg_print_hot_teams_level
1247
Jonathan Peyton30419822017-05-12 18:01:32 +00001248static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
1249 void *data) {
1250 if (TCR_4(__kmp_init_parallel)) {
1251 KMP_WARNING(EnvParallelWarn, name);
1252 return;
1253 } // read value before first parallel only
1254 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1255 &__kmp_hot_teams_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001256} // __kmp_stg_parse_hot_teams_mode
1257
Jonathan Peyton30419822017-05-12 18:01:32 +00001258static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1259 char const *name, void *data) {
1260 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001261} // __kmp_stg_print_hot_teams_mode
1262
1263#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001264
Jonathan Peyton30419822017-05-12 18:01:32 +00001265// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001266// KMP_HANDLE_SIGNALS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001267
1268#if KMP_HANDLE_SIGNALS
1269
Jonathan Peyton30419822017-05-12 18:01:32 +00001270static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
1271 void *data) {
1272 __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001273} // __kmp_stg_parse_handle_signals
1274
Jonathan Peyton30419822017-05-12 18:01:32 +00001275static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1276 char const *name, void *data) {
1277 __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001278} // __kmp_stg_print_handle_signals
1279
1280#endif // KMP_HANDLE_SIGNALS
1281
Jonathan Peyton30419822017-05-12 18:01:32 +00001282// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001283// KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
Jim Cownie5e8470a2013-09-27 10:38:44 +00001284
1285#ifdef KMP_DEBUG
1286
Jonathan Peyton30419822017-05-12 18:01:32 +00001287#define KMP_STG_X_DEBUG(x) \
1288 static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1289 void *data) { \
1290 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1291 } /* __kmp_stg_parse_x_debug */ \
1292 static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1293 char const *name, void *data) { \
1294 __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1295 } /* __kmp_stg_print_x_debug */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001296
Jonathan Peyton30419822017-05-12 18:01:32 +00001297KMP_STG_X_DEBUG(a)
1298KMP_STG_X_DEBUG(b)
1299KMP_STG_X_DEBUG(c)
1300KMP_STG_X_DEBUG(d)
1301KMP_STG_X_DEBUG(e)
1302KMP_STG_X_DEBUG(f)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001303
1304#undef KMP_STG_X_DEBUG
1305
Jonathan Peyton30419822017-05-12 18:01:32 +00001306static void __kmp_stg_parse_debug(char const *name, char const *value,
1307 void *data) {
1308 int debug = 0;
1309 __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1310 if (kmp_a_debug < debug) {
1311 kmp_a_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001312 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001313 if (kmp_b_debug < debug) {
1314 kmp_b_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001315 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001316 if (kmp_c_debug < debug) {
1317 kmp_c_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001318 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001319 if (kmp_d_debug < debug) {
1320 kmp_d_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001321 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001322 if (kmp_e_debug < debug) {
1323 kmp_e_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001324 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001325 if (kmp_f_debug < debug) {
1326 kmp_f_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001327 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001328} // __kmp_stg_parse_debug
1329
Jonathan Peyton30419822017-05-12 18:01:32 +00001330static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
1331 void *data) {
1332 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1333 // !!! TODO: Move buffer initialization of of this file! It may works
1334 // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
1335 // KMP_DEBUG_BUF_CHARS.
1336 if (__kmp_debug_buf) {
1337 int i;
1338 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001339
Jonathan Peyton30419822017-05-12 18:01:32 +00001340 /* allocate and initialize all entries in debug buffer to empty */
1341 __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
1342 for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1343 __kmp_debug_buffer[i] = '\0';
Jim Cownie5e8470a2013-09-27 10:38:44 +00001344
Jonathan Peyton30419822017-05-12 18:01:32 +00001345 __kmp_debug_count = 0;
1346 }
1347 K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001348} // __kmp_stg_parse_debug_buf
1349
Jonathan Peyton30419822017-05-12 18:01:32 +00001350static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
1351 void *data) {
1352 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001353} // __kmp_stg_print_debug_buf
1354
Jonathan Peyton30419822017-05-12 18:01:32 +00001355static void __kmp_stg_parse_debug_buf_atomic(char const *name,
1356 char const *value, void *data) {
1357 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001358} // __kmp_stg_parse_debug_buf_atomic
1359
Jonathan Peyton30419822017-05-12 18:01:32 +00001360static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1361 char const *name, void *data) {
1362 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001363} // __kmp_stg_print_debug_buf_atomic
1364
Jonathan Peyton30419822017-05-12 18:01:32 +00001365static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
1366 void *data) {
1367 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1368 &__kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001369} // __kmp_stg_debug_parse_buf_chars
1370
Jonathan Peyton30419822017-05-12 18:01:32 +00001371static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1372 char const *name, void *data) {
1373 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001374} // __kmp_stg_print_debug_buf_chars
1375
Jonathan Peyton30419822017-05-12 18:01:32 +00001376static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
1377 void *data) {
1378 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1379 &__kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001380} // __kmp_stg_parse_debug_buf_lines
1381
Jonathan Peyton30419822017-05-12 18:01:32 +00001382static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1383 char const *name, void *data) {
1384 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001385} // __kmp_stg_print_debug_buf_lines
1386
Jonathan Peyton30419822017-05-12 18:01:32 +00001387static void __kmp_stg_parse_diag(char const *name, char const *value,
1388 void *data) {
1389 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001390} // __kmp_stg_parse_diag
1391
Jonathan Peyton30419822017-05-12 18:01:32 +00001392static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
1393 void *data) {
1394 __kmp_stg_print_int(buffer, name, kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001395} // __kmp_stg_print_diag
1396
1397#endif // KMP_DEBUG
1398
Jonathan Peyton30419822017-05-12 18:01:32 +00001399// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001400// KMP_ALIGN_ALLOC
Jim Cownie5e8470a2013-09-27 10:38:44 +00001401
Jonathan Peyton30419822017-05-12 18:01:32 +00001402static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
1403 void *data) {
1404 __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1405 &__kmp_align_alloc, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001406} // __kmp_stg_parse_align_alloc
1407
Jonathan Peyton30419822017-05-12 18:01:32 +00001408static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
1409 void *data) {
1410 __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001411} // __kmp_stg_print_align_alloc
1412
Jonathan Peyton30419822017-05-12 18:01:32 +00001413// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001414// KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
Jim Cownie5e8470a2013-09-27 10:38:44 +00001415
Jonathan Peyton30419822017-05-12 18:01:32 +00001416// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
1417// parse and print functions, pass required info through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001418
Jonathan Peyton30419822017-05-12 18:01:32 +00001419static void __kmp_stg_parse_barrier_branch_bit(char const *name,
1420 char const *value, void *data) {
1421 const char *var;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001422
Jonathan Peyton30419822017-05-12 18:01:32 +00001423 /* ---------- Barrier branch bit control ------------ */
1424 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1425 var = __kmp_barrier_branch_bit_env_name[i];
1426 if ((strcmp(var, name) == 0) && (value != 0)) {
1427 char *comma;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001428
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001429 comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00001430 __kmp_barrier_gather_branch_bits[i] =
1431 (kmp_uint32)__kmp_str_to_int(value, ',');
1432 /* is there a specified release parameter? */
1433 if (comma == NULL) {
1434 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1435 } else {
1436 __kmp_barrier_release_branch_bits[i] =
1437 (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001438
Jonathan Peyton30419822017-05-12 18:01:32 +00001439 if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1440 __kmp_msg(kmp_ms_warning,
1441 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1442 __kmp_msg_null);
1443 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001444 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001445 }
1446 if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1447 KMP_WARNING(BarrGatherValueInvalid, name, value);
1448 KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1449 __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1450 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001451 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001452 K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1453 __kmp_barrier_gather_branch_bits[i],
1454 __kmp_barrier_release_branch_bits[i]))
1455 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001456} // __kmp_stg_parse_barrier_branch_bit
1457
Jonathan Peyton30419822017-05-12 18:01:32 +00001458static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1459 char const *name, void *data) {
1460 const char *var;
1461 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1462 var = __kmp_barrier_branch_bit_env_name[i];
1463 if (strcmp(var, name) == 0) {
1464 if (__kmp_env_format) {
1465 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1466 } else {
1467 __kmp_str_buf_print(buffer, " %s='",
1468 __kmp_barrier_branch_bit_env_name[i]);
1469 }
1470 __kmp_str_buf_print(buffer, "%d,%d'\n",
1471 __kmp_barrier_gather_branch_bits[i],
1472 __kmp_barrier_release_branch_bits[i]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001473 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001474 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001475} // __kmp_stg_print_barrier_branch_bit
1476
Jonathan Peyton30419822017-05-12 18:01:32 +00001477// ----------------------------------------------------------------------------
1478// KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
1479// KMP_REDUCTION_BARRIER_PATTERN
Jim Cownie5e8470a2013-09-27 10:38:44 +00001480
Jonathan Peyton30419822017-05-12 18:01:32 +00001481// TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
1482// print functions, pass required data to functions through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001483
Jonathan Peyton30419822017-05-12 18:01:32 +00001484static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
1485 void *data) {
1486 const char *var;
1487 /* ---------- Barrier method control ------------ */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001488
Jonathan Peyton30419822017-05-12 18:01:32 +00001489 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1490 var = __kmp_barrier_pattern_env_name[i];
Jim Cownie5e8470a2013-09-27 10:38:44 +00001491
Jonathan Peyton30419822017-05-12 18:01:32 +00001492 if ((strcmp(var, name) == 0) && (value != 0)) {
1493 int j;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001494 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001495
Jonathan Peyton30419822017-05-12 18:01:32 +00001496 /* handle first parameter: gather pattern */
1497 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1498 if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1499 ',')) {
1500 __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1501 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001502 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001503 }
1504 if (j == bp_last_bar) {
1505 KMP_WARNING(BarrGatherValueInvalid, name, value);
1506 KMP_INFORM(Using_str_Value, name,
1507 __kmp_barrier_pattern_name[bp_linear_bar]);
1508 }
1509
1510 /* handle second parameter: release pattern */
1511 if (comma != NULL) {
1512 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1513 if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1514 __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1515 break;
1516 }
1517 }
1518 if (j == bp_last_bar) {
1519 __kmp_msg(kmp_ms_warning,
1520 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1521 __kmp_msg_null);
1522 KMP_INFORM(Using_str_Value, name,
1523 __kmp_barrier_pattern_name[bp_linear_bar]);
1524 }
1525 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001526 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001527 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001528} // __kmp_stg_parse_barrier_pattern
1529
Jonathan Peyton30419822017-05-12 18:01:32 +00001530static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1531 char const *name, void *data) {
1532 const char *var;
1533 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1534 var = __kmp_barrier_pattern_env_name[i];
1535 if (strcmp(var, name) == 0) {
1536 int j = __kmp_barrier_gather_pattern[i];
1537 int k = __kmp_barrier_release_pattern[i];
1538 if (__kmp_env_format) {
1539 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1540 } else {
1541 __kmp_str_buf_print(buffer, " %s='",
1542 __kmp_barrier_pattern_env_name[i]);
1543 }
1544 __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
1545 __kmp_barrier_pattern_name[k]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001546 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001547 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001548} // __kmp_stg_print_barrier_pattern
1549
Jonathan Peyton30419822017-05-12 18:01:32 +00001550// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001551// KMP_ABORT_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00001552
Jonathan Peyton30419822017-05-12 18:01:32 +00001553static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
1554 void *data) {
1555 // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
1556 // milliseconds.
1557 int delay = __kmp_abort_delay / 1000;
1558 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1559 __kmp_abort_delay = delay * 1000;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001560} // __kmp_stg_parse_abort_delay
1561
Jonathan Peyton30419822017-05-12 18:01:32 +00001562static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
1563 void *data) {
1564 __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001565} // __kmp_stg_print_abort_delay
1566
Jonathan Peyton30419822017-05-12 18:01:32 +00001567// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001568// KMP_CPUINFO_FILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001569
Jonathan Peyton30419822017-05-12 18:01:32 +00001570static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
1571 void *data) {
1572#if KMP_AFFINITY_SUPPORTED
1573 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1574 K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1575#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001576} //__kmp_stg_parse_cpuinfo_file
1577
Jonathan Peyton30419822017-05-12 18:01:32 +00001578static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1579 char const *name, void *data) {
1580#if KMP_AFFINITY_SUPPORTED
1581 if (__kmp_env_format) {
1582 KMP_STR_BUF_PRINT_NAME;
1583 } else {
1584 __kmp_str_buf_print(buffer, " %s", name);
1585 }
1586 if (__kmp_cpuinfo_file) {
1587 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
1588 } else {
1589 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1590 }
1591#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001592} //__kmp_stg_print_cpuinfo_file
1593
Jonathan Peyton30419822017-05-12 18:01:32 +00001594// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001595// KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
Jim Cownie5e8470a2013-09-27 10:38:44 +00001596
Jonathan Peyton30419822017-05-12 18:01:32 +00001597static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
1598 void *data) {
1599 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1600 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001601
Jonathan Peyton30419822017-05-12 18:01:32 +00001602 rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1603 if (rc) {
1604 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001605 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001606 if (reduction->force) {
1607 if (value != 0) {
1608 if (__kmp_str_match("critical", 0, value))
1609 __kmp_force_reduction_method = critical_reduce_block;
1610 else if (__kmp_str_match("atomic", 0, value))
1611 __kmp_force_reduction_method = atomic_reduce_block;
1612 else if (__kmp_str_match("tree", 0, value))
1613 __kmp_force_reduction_method = tree_reduce_block;
1614 else {
1615 KMP_FATAL(UnknownForceReduction, name, value);
1616 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001617 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001618 } else {
1619 __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1620 if (__kmp_determ_red) {
1621 __kmp_force_reduction_method = tree_reduce_block;
1622 } else {
1623 __kmp_force_reduction_method = reduction_method_not_defined;
1624 }
1625 }
1626 K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
1627 __kmp_force_reduction_method));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001628} // __kmp_stg_parse_force_reduction
1629
Jonathan Peyton30419822017-05-12 18:01:32 +00001630static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1631 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00001632
Jonathan Peyton30419822017-05-12 18:01:32 +00001633 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1634 if (reduction->force) {
1635 if (__kmp_force_reduction_method == critical_reduce_block) {
1636 __kmp_stg_print_str(buffer, name, "critical");
1637 } else if (__kmp_force_reduction_method == atomic_reduce_block) {
1638 __kmp_stg_print_str(buffer, name, "atomic");
1639 } else if (__kmp_force_reduction_method == tree_reduce_block) {
1640 __kmp_stg_print_str(buffer, name, "tree");
Jim Cownie5e8470a2013-09-27 10:38:44 +00001641 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00001642 if (__kmp_env_format) {
1643 KMP_STR_BUF_PRINT_NAME;
1644 } else {
1645 __kmp_str_buf_print(buffer, " %s", name);
1646 }
1647 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001648 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001649 } else {
1650 __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1651 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001652
1653} // __kmp_stg_print_force_reduction
1654
Jonathan Peyton30419822017-05-12 18:01:32 +00001655// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001656// KMP_STORAGE_MAP
Jim Cownie5e8470a2013-09-27 10:38:44 +00001657
Jonathan Peyton30419822017-05-12 18:01:32 +00001658static void __kmp_stg_parse_storage_map(char const *name, char const *value,
1659 void *data) {
1660 if (__kmp_str_match("verbose", 1, value)) {
1661 __kmp_storage_map = TRUE;
1662 __kmp_storage_map_verbose = TRUE;
1663 __kmp_storage_map_verbose_specified = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001664
Jonathan Peyton30419822017-05-12 18:01:32 +00001665 } else {
1666 __kmp_storage_map_verbose = FALSE;
1667 __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001668 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001669} // __kmp_stg_parse_storage_map
1670
Jonathan Peyton30419822017-05-12 18:01:32 +00001671static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
1672 void *data) {
1673 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1674 __kmp_stg_print_str(buffer, name, "verbose");
1675 } else {
1676 __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1677 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001678} // __kmp_stg_print_storage_map
1679
Jonathan Peyton30419822017-05-12 18:01:32 +00001680// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001681// KMP_ALL_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001682
Jonathan Peyton30419822017-05-12 18:01:32 +00001683static void __kmp_stg_parse_all_threadprivate(char const *name,
1684 char const *value, void *data) {
1685 __kmp_stg_parse_int(name, value,
1686 __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1687 __kmp_max_nth, &__kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001688} // __kmp_stg_parse_all_threadprivate
1689
Jonathan Peyton30419822017-05-12 18:01:32 +00001690static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1691 char const *name, void *data) {
1692 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001693}
1694
Jonathan Peyton30419822017-05-12 18:01:32 +00001695// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001696// KMP_FOREIGN_THREADS_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001697
Jonathan Peyton30419822017-05-12 18:01:32 +00001698static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
1699 char const *value,
1700 void *data) {
1701 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001702} // __kmp_stg_parse_foreign_threads_threadprivate
1703
Jonathan Peyton30419822017-05-12 18:01:32 +00001704static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
1705 char const *name,
1706 void *data) {
1707 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001708} // __kmp_stg_print_foreign_threads_threadprivate
1709
Jonathan Peyton30419822017-05-12 18:01:32 +00001710// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001711// KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
Jim Cownie5e8470a2013-09-27 10:38:44 +00001712
Alp Toker98758b02014-03-02 04:12:06 +00001713#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00001714// Parse the proc id list. Return TRUE if successful, FALSE otherwise.
Jonathan Peyton30419822017-05-12 18:01:32 +00001715static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
1716 const char **nextEnv,
1717 char **proclist) {
1718 const char *scan = env;
1719 const char *next = scan;
1720 int empty = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001721
Jonathan Peyton30419822017-05-12 18:01:32 +00001722 *proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001723
Jonathan Peyton30419822017-05-12 18:01:32 +00001724 for (;;) {
1725 int start, end, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001726
Jonathan Peyton30419822017-05-12 18:01:32 +00001727 SKIP_WS(scan);
1728 next = scan;
1729 if (*next == '\0') {
1730 break;
1731 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001732
Jonathan Peyton30419822017-05-12 18:01:32 +00001733 if (*next == '{') {
1734 int num;
1735 next++; // skip '{'
1736 SKIP_WS(next);
1737 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001738
Jonathan Peyton30419822017-05-12 18:01:32 +00001739 // Read the first integer in the set.
1740 if ((*next < '0') || (*next > '9')) {
1741 KMP_WARNING(AffSyntaxError, var);
1742 return FALSE;
1743 }
1744 SKIP_DIGITS(next);
1745 num = __kmp_str_to_int(scan, *next);
1746 KMP_ASSERT(num >= 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001747
Jonathan Peyton30419822017-05-12 18:01:32 +00001748 for (;;) {
1749 // Check for end of set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001750 SKIP_WS(next);
Jonathan Peyton30419822017-05-12 18:01:32 +00001751 if (*next == '}') {
1752 next++; // skip '}'
1753 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001754 }
1755
Jim Cownie5e8470a2013-09-27 10:38:44 +00001756 // Skip optional comma.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001757 if (*next == ',') {
Jonathan Peyton30419822017-05-12 18:01:32 +00001758 next++;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001759 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001760 SKIP_WS(next);
1761
1762 // Read the next integer in the set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001763 scan = next;
Jonathan Peyton30419822017-05-12 18:01:32 +00001764 if ((*next < '0') || (*next > '9')) {
1765 KMP_WARNING(AffSyntaxError, var);
1766 return FALSE;
1767 }
1768
1769 SKIP_DIGITS(next);
1770 num = __kmp_str_to_int(scan, *next);
1771 KMP_ASSERT(num >= 0);
1772 }
1773 empty = FALSE;
1774
1775 SKIP_WS(next);
1776 if (*next == ',') {
1777 next++;
1778 }
1779 scan = next;
1780 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001781 }
1782
Jonathan Peyton30419822017-05-12 18:01:32 +00001783 // Next character is not an integer => end of list
1784 if ((*next < '0') || (*next > '9')) {
1785 if (empty) {
1786 KMP_WARNING(AffSyntaxError, var);
1787 return FALSE;
1788 }
1789 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001790 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001791
1792 // Read the first integer.
1793 SKIP_DIGITS(next);
1794 start = __kmp_str_to_int(scan, *next);
1795 KMP_ASSERT(start >= 0);
1796 SKIP_WS(next);
1797
1798 // If this isn't a range, then go on.
1799 if (*next != '-') {
1800 empty = FALSE;
1801
1802 // Skip optional comma.
1803 if (*next == ',') {
1804 next++;
1805 }
1806 scan = next;
1807 continue;
1808 }
1809
1810 // This is a range. Skip over the '-' and read in the 2nd int.
1811 next++; // skip '-'
1812 SKIP_WS(next);
1813 scan = next;
1814 if ((*next < '0') || (*next > '9')) {
1815 KMP_WARNING(AffSyntaxError, var);
1816 return FALSE;
1817 }
1818 SKIP_DIGITS(next);
1819 end = __kmp_str_to_int(scan, *next);
1820 KMP_ASSERT(end >= 0);
1821
1822 // Check for a stride parameter
1823 stride = 1;
1824 SKIP_WS(next);
1825 if (*next == ':') {
1826 // A stride is specified. Skip over the ':" and read the 3rd int.
1827 int sign = +1;
1828 next++; // skip ':'
1829 SKIP_WS(next);
1830 scan = next;
1831 if (*next == '-') {
1832 sign = -1;
1833 next++;
1834 SKIP_WS(next);
1835 scan = next;
1836 }
1837 if ((*next < '0') || (*next > '9')) {
1838 KMP_WARNING(AffSyntaxError, var);
1839 return FALSE;
1840 }
1841 SKIP_DIGITS(next);
1842 stride = __kmp_str_to_int(scan, *next);
1843 KMP_ASSERT(stride >= 0);
1844 stride *= sign;
1845 }
1846
1847 // Do some range checks.
1848 if (stride == 0) {
1849 KMP_WARNING(AffZeroStride, var);
1850 return FALSE;
1851 }
1852 if (stride > 0) {
1853 if (start > end) {
1854 KMP_WARNING(AffStartGreaterEnd, var, start, end);
1855 return FALSE;
1856 }
1857 } else {
1858 if (start < end) {
1859 KMP_WARNING(AffStrideLessZero, var, start, end);
1860 return FALSE;
1861 }
1862 }
1863 if ((end - start) / stride > 65536) {
1864 KMP_WARNING(AffRangeTooBig, var, end, start, stride);
1865 return FALSE;
1866 }
1867
1868 empty = FALSE;
1869
1870 // Skip optional comma.
1871 SKIP_WS(next);
1872 if (*next == ',') {
1873 next++;
1874 }
1875 scan = next;
1876 }
1877
1878 *nextEnv = next;
1879
1880 {
1881 int len = next - env;
1882 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
1883 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
1884 retlist[len] = '\0';
1885 *proclist = retlist;
1886 }
1887 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001888}
1889
Jim Cownie5e8470a2013-09-27 10:38:44 +00001890// If KMP_AFFINITY is specified without a type, then
1891// __kmp_affinity_notype should point to its setting.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001892static kmp_setting_t *__kmp_affinity_notype = NULL;
1893
Jonathan Peyton30419822017-05-12 18:01:32 +00001894static void __kmp_parse_affinity_env(char const *name, char const *value,
1895 enum affinity_type *out_type,
1896 char **out_proclist, int *out_verbose,
1897 int *out_warn, int *out_respect,
1898 enum affinity_gran *out_gran,
1899 int *out_gran_levels, int *out_dups,
1900 int *out_compact, int *out_offset) {
1901 char *buffer = NULL; // Copy of env var value.
1902 char *buf = NULL; // Buffer for strtok_r() function.
1903 char *next = NULL; // end of token / start of next.
1904 const char *start; // start of current token (for err msgs)
1905 int count = 0; // Counter of parsed integer numbers.
1906 int number[2]; // Parsed numbers.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001907
Jonathan Peyton30419822017-05-12 18:01:32 +00001908 // Guards.
1909 int type = 0;
1910 int proclist = 0;
1911 int max_proclist = 0;
1912 int verbose = 0;
1913 int warnings = 0;
1914 int respect = 0;
1915 int gran = 0;
1916 int dups = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001917
Jonathan Peyton30419822017-05-12 18:01:32 +00001918 KMP_ASSERT(value != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001919
Jonathan Peyton30419822017-05-12 18:01:32 +00001920 if (TCR_4(__kmp_init_middle)) {
1921 KMP_WARNING(EnvMiddleWarn, name);
1922 __kmp_env_toPrint(name, 0);
1923 return;
1924 }
1925 __kmp_env_toPrint(name, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001926
Jonathan Peyton30419822017-05-12 18:01:32 +00001927 buffer =
1928 __kmp_str_format("%s", value); // Copy env var to keep original intact.
1929 buf = buffer;
1930 SKIP_WS(buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001931
Jonathan Peyton30419822017-05-12 18:01:32 +00001932// Helper macros.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001933
Jonathan Peyton30419822017-05-12 18:01:32 +00001934// If we see a parse error, emit a warning and scan to the next ",".
1935//
1936// FIXME - there's got to be a better way to print an error
1937// message, hopefully without overwritting peices of buf.
1938#define EMIT_WARN(skip, errlist) \
1939 { \
1940 char ch; \
1941 if (skip) { \
1942 SKIP_TO(next, ','); \
1943 } \
1944 ch = *next; \
1945 *next = '\0'; \
1946 KMP_WARNING errlist; \
1947 *next = ch; \
1948 if (skip) { \
1949 if (ch == ',') \
1950 next++; \
1951 } \
1952 buf = next; \
1953 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001954
Jonathan Peyton30419822017-05-12 18:01:32 +00001955#define _set_param(_guard, _var, _val) \
1956 { \
1957 if (_guard == 0) { \
1958 _var = _val; \
1959 } else { \
1960 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001961 } \
Jonathan Peyton30419822017-05-12 18:01:32 +00001962 ++_guard; \
1963 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001964
Jonathan Peyton30419822017-05-12 18:01:32 +00001965#define set_type(val) _set_param(type, *out_type, val)
1966#define set_verbose(val) _set_param(verbose, *out_verbose, val)
1967#define set_warnings(val) _set_param(warnings, *out_warn, val)
1968#define set_respect(val) _set_param(respect, *out_respect, val)
1969#define set_dups(val) _set_param(dups, *out_dups, val)
1970#define set_proclist(val) _set_param(proclist, *out_proclist, val)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001971
Jonathan Peyton30419822017-05-12 18:01:32 +00001972#define set_gran(val, levels) \
1973 { \
1974 if (gran == 0) { \
1975 *out_gran = val; \
1976 *out_gran_levels = levels; \
1977 } else { \
1978 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001979 } \
Jonathan Peyton30419822017-05-12 18:01:32 +00001980 ++gran; \
1981 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001982
Jonathan Peyton30419822017-05-12 18:01:32 +00001983#if OMP_40_ENABLED
1984 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
1985 (__kmp_nested_proc_bind.used > 0));
Andrey Churbanov613edeb2015-02-20 18:14:43 +00001986#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00001987
1988 while (*buf != '\0') {
1989 start = next = buf;
1990
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001991 if (__kmp_match_str("none", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001992 set_type(affinity_none);
1993#if OMP_40_ENABLED
1994 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
1995#endif
1996 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001997 } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001998 set_type(affinity_scatter);
1999#if OMP_40_ENABLED
2000 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2001#endif
2002 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002003 } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002004 set_type(affinity_compact);
2005#if OMP_40_ENABLED
2006 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2007#endif
2008 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002009 } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002010 set_type(affinity_logical);
2011#if OMP_40_ENABLED
2012 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2013#endif
2014 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002015 } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002016 set_type(affinity_physical);
2017#if OMP_40_ENABLED
2018 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2019#endif
2020 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002021 } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002022 set_type(affinity_explicit);
2023#if OMP_40_ENABLED
2024 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2025#endif
2026 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002027 } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002028 set_type(affinity_balanced);
2029#if OMP_40_ENABLED
2030 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2031#endif
2032 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002033 } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002034 set_type(affinity_disabled);
2035#if OMP_40_ENABLED
2036 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2037#endif
2038 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002039 } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002040 set_verbose(TRUE);
2041 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002042 } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002043 set_verbose(FALSE);
2044 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002045 } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002046 set_warnings(TRUE);
2047 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002048 } else if (__kmp_match_str("nowarnings", buf,
2049 CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002050 set_warnings(FALSE);
2051 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002052 } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002053 set_respect(TRUE);
2054 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002055 } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002056 set_respect(FALSE);
2057 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002058 } else if (__kmp_match_str("duplicates", buf,
2059 CCAST(const char **, &next)) ||
2060 __kmp_match_str("dups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002061 set_dups(TRUE);
2062 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002063 } else if (__kmp_match_str("noduplicates", buf,
2064 CCAST(const char **, &next)) ||
2065 __kmp_match_str("nodups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002066 set_dups(FALSE);
2067 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002068 } else if (__kmp_match_str("granularity", buf,
2069 CCAST(const char **, &next)) ||
2070 __kmp_match_str("gran", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002071 SKIP_WS(next);
2072 if (*next != '=') {
2073 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2074 continue;
2075 }
2076 next++; // skip '='
2077 SKIP_WS(next);
2078
2079 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002080 if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002081 set_gran(affinity_gran_fine, -1);
2082 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002083 } else if (__kmp_match_str("thread", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002084 set_gran(affinity_gran_thread, -1);
2085 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002086 } else if (__kmp_match_str("core", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002087 set_gran(affinity_gran_core, -1);
2088 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002089 } else if (__kmp_match_str("package", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002090 set_gran(affinity_gran_package, -1);
2091 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002092 } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002093 set_gran(affinity_gran_node, -1);
2094 buf = next;
2095#if KMP_GROUP_AFFINITY
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002096 } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002097 set_gran(affinity_gran_group, -1);
2098 buf = next;
2099#endif /* KMP_GROUP AFFINITY */
2100 } else if ((*buf >= '0') && (*buf <= '9')) {
2101 int n;
2102 next = buf;
2103 SKIP_DIGITS(next);
2104 n = __kmp_str_to_int(buf, *next);
2105 KMP_ASSERT(n >= 0);
2106 buf = next;
2107 set_gran(affinity_gran_default, n);
2108 } else {
2109 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2110 continue;
2111 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002112 } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002113 char *temp_proclist;
2114
2115 SKIP_WS(next);
2116 if (*next != '=') {
2117 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2118 continue;
2119 }
2120 next++; // skip '='
2121 SKIP_WS(next);
2122 if (*next != '[') {
2123 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2124 continue;
2125 }
2126 next++; // skip '['
2127 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002128 if (!__kmp_parse_affinity_proc_id_list(
2129 name, buf, CCAST(const char **, &next), &temp_proclist)) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002130 // warning already emitted.
2131 SKIP_TO(next, ']');
2132 if (*next == ']')
2133 next++;
2134 SKIP_TO(next, ',');
2135 if (*next == ',')
2136 next++;
2137 buf = next;
2138 continue;
2139 }
2140 if (*next != ']') {
2141 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2142 continue;
2143 }
2144 next++; // skip ']'
2145 set_proclist(temp_proclist);
2146 } else if ((*buf >= '0') && (*buf <= '9')) {
2147 // Parse integer numbers -- permute and offset.
2148 int n;
2149 next = buf;
2150 SKIP_DIGITS(next);
2151 n = __kmp_str_to_int(buf, *next);
2152 KMP_ASSERT(n >= 0);
2153 buf = next;
2154 if (count < 2) {
2155 number[count] = n;
2156 } else {
2157 KMP_WARNING(AffManyParams, name, start);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002158 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002159 ++count;
2160 } else {
2161 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2162 continue;
2163 }
2164
2165 SKIP_WS(next);
2166 if (*next == ',') {
2167 next++;
2168 SKIP_WS(next);
2169 } else if (*next != '\0') {
2170 const char *temp = next;
2171 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2172 continue;
2173 }
2174 buf = next;
2175 } // while
2176
2177#undef EMIT_WARN
2178#undef _set_param
2179#undef set_type
2180#undef set_verbose
2181#undef set_warnings
2182#undef set_respect
2183#undef set_granularity
2184
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002185 __kmp_str_free(CCAST(const char **, &buffer));
Jonathan Peyton30419822017-05-12 18:01:32 +00002186
2187 if (proclist) {
2188 if (!type) {
2189 KMP_WARNING(AffProcListNoType, name);
2190 *out_type = affinity_explicit;
2191#if OMP_40_ENABLED
2192 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2193#endif
2194 } else if (*out_type != affinity_explicit) {
2195 KMP_WARNING(AffProcListNotExplicit, name);
2196 KMP_ASSERT(*out_proclist != NULL);
2197 KMP_INTERNAL_FREE(*out_proclist);
2198 *out_proclist = NULL;
2199 }
2200 }
2201 switch (*out_type) {
2202 case affinity_logical:
2203 case affinity_physical: {
2204 if (count > 0) {
2205 *out_offset = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002206 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002207 if (count > 1) {
2208 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002209 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002210 } break;
2211 case affinity_balanced: {
2212 if (count > 0) {
2213 *out_compact = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002214 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002215 if (count > 1) {
2216 *out_offset = number[1];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002217 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002218
2219 if (__kmp_affinity_gran == affinity_gran_default) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002220#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002221 if (__kmp_mic_type != non_mic) {
2222 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2223 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine");
2224 }
2225 __kmp_affinity_gran = affinity_gran_fine;
2226 } else
2227#endif
2228 {
2229 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2230 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core");
2231 }
2232 __kmp_affinity_gran = affinity_gran_core;
2233 }
2234 }
2235 } break;
2236 case affinity_scatter:
2237 case affinity_compact: {
2238 if (count > 0) {
2239 *out_compact = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002240 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002241 if (count > 1) {
2242 *out_offset = number[1];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002243 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002244 } break;
2245 case affinity_explicit: {
2246 if (*out_proclist == NULL) {
2247 KMP_WARNING(AffNoProcList, name);
2248 __kmp_affinity_type = affinity_none;
2249 }
2250 if (count > 0) {
2251 KMP_WARNING(AffNoParam, name, "explicit");
2252 }
2253 } break;
2254 case affinity_none: {
2255 if (count > 0) {
2256 KMP_WARNING(AffNoParam, name, "none");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002257 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002258 } break;
2259 case affinity_disabled: {
2260 if (count > 0) {
2261 KMP_WARNING(AffNoParam, name, "disabled");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002262 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002263 } break;
2264 case affinity_default: {
2265 if (count > 0) {
2266 KMP_WARNING(AffNoParam, name, "default");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002267 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002268 } break;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002269 default: { KMP_ASSERT(0); }
2270 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002271} // __kmp_parse_affinity_env
2272
Jonathan Peyton30419822017-05-12 18:01:32 +00002273static void __kmp_stg_parse_affinity(char const *name, char const *value,
2274 void *data) {
2275 kmp_setting_t **rivals = (kmp_setting_t **)data;
2276 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002277
Jonathan Peyton30419822017-05-12 18:01:32 +00002278 rc = __kmp_stg_check_rivals(name, value, rivals);
2279 if (rc) {
2280 return;
2281 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002282
Jonathan Peyton30419822017-05-12 18:01:32 +00002283 __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2284 &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2285 &__kmp_affinity_warnings,
2286 &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2287 &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2288 &__kmp_affinity_compact, &__kmp_affinity_offset);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002289
2290} // __kmp_stg_parse_affinity
2291
Jonathan Peyton30419822017-05-12 18:01:32 +00002292static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
2293 void *data) {
2294 if (__kmp_env_format) {
2295 KMP_STR_BUF_PRINT_NAME_EX(name);
2296 } else {
2297 __kmp_str_buf_print(buffer, " %s='", name);
2298 }
2299 if (__kmp_affinity_verbose) {
2300 __kmp_str_buf_print(buffer, "%s,", "verbose");
2301 } else {
2302 __kmp_str_buf_print(buffer, "%s,", "noverbose");
2303 }
2304 if (__kmp_affinity_warnings) {
2305 __kmp_str_buf_print(buffer, "%s,", "warnings");
2306 } else {
2307 __kmp_str_buf_print(buffer, "%s,", "nowarnings");
2308 }
2309 if (KMP_AFFINITY_CAPABLE()) {
2310 if (__kmp_affinity_respect_mask) {
2311 __kmp_str_buf_print(buffer, "%s,", "respect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002312 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002313 __kmp_str_buf_print(buffer, "%s,", "norespect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002314 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002315 switch (__kmp_affinity_gran) {
2316 case affinity_gran_default:
2317 __kmp_str_buf_print(buffer, "%s", "granularity=default,");
2318 break;
2319 case affinity_gran_fine:
2320 __kmp_str_buf_print(buffer, "%s", "granularity=fine,");
2321 break;
2322 case affinity_gran_thread:
2323 __kmp_str_buf_print(buffer, "%s", "granularity=thread,");
2324 break;
2325 case affinity_gran_core:
2326 __kmp_str_buf_print(buffer, "%s", "granularity=core,");
2327 break;
2328 case affinity_gran_package:
2329 __kmp_str_buf_print(buffer, "%s", "granularity=package,");
2330 break;
2331 case affinity_gran_node:
2332 __kmp_str_buf_print(buffer, "%s", "granularity=node,");
2333 break;
2334#if KMP_GROUP_AFFINITY
2335 case affinity_gran_group:
2336 __kmp_str_buf_print(buffer, "%s", "granularity=group,");
2337 break;
2338#endif /* KMP_GROUP_AFFINITY */
2339 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002340 }
2341 if (!KMP_AFFINITY_CAPABLE()) {
2342 __kmp_str_buf_print(buffer, "%s", "disabled");
2343 } else
2344 switch (__kmp_affinity_type) {
2345 case affinity_none:
2346 __kmp_str_buf_print(buffer, "%s", "none");
2347 break;
2348 case affinity_physical:
2349 __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset);
2350 break;
2351 case affinity_logical:
2352 __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset);
2353 break;
2354 case affinity_compact:
2355 __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact,
2356 __kmp_affinity_offset);
2357 break;
2358 case affinity_scatter:
2359 __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact,
2360 __kmp_affinity_offset);
2361 break;
2362 case affinity_explicit:
2363 __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist",
2364 __kmp_affinity_proclist, "explicit");
2365 break;
2366 case affinity_balanced:
2367 __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced",
2368 __kmp_affinity_compact, __kmp_affinity_offset);
2369 break;
2370 case affinity_disabled:
2371 __kmp_str_buf_print(buffer, "%s", "disabled");
2372 break;
2373 case affinity_default:
2374 __kmp_str_buf_print(buffer, "%s", "default");
2375 break;
2376 default:
2377 __kmp_str_buf_print(buffer, "%s", "<unknown>");
2378 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002379 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002380 __kmp_str_buf_print(buffer, "'\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002381} //__kmp_stg_print_affinity
2382
Jonathan Peyton30419822017-05-12 18:01:32 +00002383#ifdef KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00002384
Jonathan Peyton30419822017-05-12 18:01:32 +00002385static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
2386 char const *value, void *data) {
2387 const char *next = NULL;
2388 char *temp_proclist;
2389 kmp_setting_t **rivals = (kmp_setting_t **)data;
2390 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002391
Jonathan Peyton30419822017-05-12 18:01:32 +00002392 rc = __kmp_stg_check_rivals(name, value, rivals);
2393 if (rc) {
2394 return;
2395 }
2396
2397 if (TCR_4(__kmp_init_middle)) {
2398 KMP_WARNING(EnvMiddleWarn, name);
2399 __kmp_env_toPrint(name, 0);
2400 return;
2401 }
2402
2403 __kmp_env_toPrint(name, 1);
2404
2405 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2406 SKIP_WS(next);
2407 if (*next == '\0') {
2408 // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2409 __kmp_affinity_proclist = temp_proclist;
2410 __kmp_affinity_type = affinity_explicit;
2411 __kmp_affinity_gran = affinity_gran_fine;
2412#if OMP_40_ENABLED
2413 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2414#endif
2415 } else {
2416 KMP_WARNING(AffSyntaxError, name);
2417 if (temp_proclist != NULL) {
2418 KMP_INTERNAL_FREE((void *)temp_proclist);
2419 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002420 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002421 } else {
2422 // Warning already emitted
2423 __kmp_affinity_type = affinity_none;
2424#if OMP_40_ENABLED
2425 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2426#endif
2427 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002428} // __kmp_stg_parse_gomp_cpu_affinity
2429
Jonathan Peyton30419822017-05-12 18:01:32 +00002430#endif /* KMP_GOMP_COMPAT */
Jim Cownie5e8470a2013-09-27 10:38:44 +00002431
Jonathan Peyton30419822017-05-12 18:01:32 +00002432#if OMP_40_ENABLED
Jim Cownie5e8470a2013-09-27 10:38:44 +00002433
2434/*-----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00002435The OMP_PLACES proc id list parser. Here is the grammar:
2436
2437place_list := place
2438place_list := place , place_list
2439place := num
2440place := place : num
2441place := place : num : signed
2442place := { subplacelist }
2443place := ! place // (lowest priority)
2444subplace_list := subplace
2445subplace_list := subplace , subplace_list
2446subplace := num
2447subplace := num : num
2448subplace := num : num : signed
2449signed := num
2450signed := + signed
2451signed := - signed
Jim Cownie5e8470a2013-09-27 10:38:44 +00002452-----------------------------------------------------------------------------*/
2453
Jonathan Peyton30419822017-05-12 18:01:32 +00002454static int __kmp_parse_subplace_list(const char *var, const char **scan) {
2455 const char *next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002456
Jonathan Peyton30419822017-05-12 18:01:32 +00002457 for (;;) {
2458 int start, count, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002459
2460 //
Jonathan Peyton30419822017-05-12 18:01:32 +00002461 // Read in the starting proc id
Jim Cownie5e8470a2013-09-27 10:38:44 +00002462 //
2463 SKIP_WS(*scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002464 if ((**scan < '0') || (**scan > '9')) {
2465 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2466 return FALSE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002467 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002468 next = *scan;
2469 SKIP_DIGITS(next);
2470 start = __kmp_str_to_int(*scan, *next);
2471 KMP_ASSERT(start >= 0);
2472 *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002473
Jonathan Peyton30419822017-05-12 18:01:32 +00002474 // valid follow sets are ',' ':' and '}'
2475 SKIP_WS(*scan);
2476 if (**scan == '}') {
2477 break;
2478 }
2479 if (**scan == ',') {
2480 (*scan)++; // skip ','
2481 continue;
2482 }
2483 if (**scan != ':') {
2484 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2485 return FALSE;
2486 }
2487 (*scan)++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002488
Jonathan Peyton30419822017-05-12 18:01:32 +00002489 // Read count parameter
2490 SKIP_WS(*scan);
2491 if ((**scan < '0') || (**scan > '9')) {
2492 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2493 return FALSE;
2494 }
2495 next = *scan;
2496 SKIP_DIGITS(next);
2497 count = __kmp_str_to_int(*scan, *next);
2498 KMP_ASSERT(count >= 0);
2499 *scan = next;
2500
2501 // valid follow sets are ',' ':' and '}'
2502 SKIP_WS(*scan);
2503 if (**scan == '}') {
2504 break;
2505 }
2506 if (**scan == ',') {
2507 (*scan)++; // skip ','
2508 continue;
2509 }
2510 if (**scan != ':') {
2511 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2512 return FALSE;
2513 }
2514 (*scan)++; // skip ':'
2515
2516 // Read stride parameter
2517 int sign = +1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002518 for (;;) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002519 SKIP_WS(*scan);
2520 if (**scan == '+') {
2521 (*scan)++; // skip '+'
2522 continue;
2523 }
2524 if (**scan == '-') {
2525 sign *= -1;
2526 (*scan)++; // skip '-'
2527 continue;
2528 }
2529 break;
2530 }
2531 SKIP_WS(*scan);
2532 if ((**scan < '0') || (**scan > '9')) {
2533 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2534 return FALSE;
2535 }
2536 next = *scan;
2537 SKIP_DIGITS(next);
2538 stride = __kmp_str_to_int(*scan, *next);
2539 KMP_ASSERT(stride >= 0);
2540 *scan = next;
2541 stride *= sign;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002542
Jonathan Peyton30419822017-05-12 18:01:32 +00002543 // valid follow sets are ',' and '}'
2544 SKIP_WS(*scan);
2545 if (**scan == '}') {
2546 break;
2547 }
2548 if (**scan == ',') {
2549 (*scan)++; // skip ','
2550 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002551 }
2552
Jonathan Peyton30419822017-05-12 18:01:32 +00002553 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2554 return FALSE;
2555 }
2556 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002557}
2558
Jonathan Peyton30419822017-05-12 18:01:32 +00002559static int __kmp_parse_place(const char *var, const char **scan) {
2560 const char *next;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002561
Jonathan Peyton30419822017-05-12 18:01:32 +00002562 // valid follow sets are '{' '!' and num
2563 SKIP_WS(*scan);
2564 if (**scan == '{') {
2565 (*scan)++; // skip '{'
2566 if (!__kmp_parse_subplace_list(var, scan)) {
2567 return FALSE;
2568 }
2569 if (**scan != '}') {
2570 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2571 return FALSE;
2572 }
2573 (*scan)++; // skip '}'
2574 } else if (**scan == '!') {
2575 (*scan)++; // skip '!'
2576 return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2577 } else if ((**scan >= '0') && (**scan <= '9')) {
2578 next = *scan;
2579 SKIP_DIGITS(next);
2580 int proc = __kmp_str_to_int(*scan, *next);
2581 KMP_ASSERT(proc >= 0);
2582 *scan = next;
2583 } else {
2584 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2585 return FALSE;
2586 }
2587 return TRUE;
2588}
2589
2590static int __kmp_parse_place_list(const char *var, const char *env,
2591 char **place_list) {
2592 const char *scan = env;
2593 const char *next = scan;
2594
2595 for (;;) {
2596 int start, count, stride;
2597
2598 if (!__kmp_parse_place(var, &scan)) {
2599 return FALSE;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002600 }
2601
Jonathan Peyton30419822017-05-12 18:01:32 +00002602 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002603 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002604 if (*scan == '\0') {
2605 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002606 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002607 if (*scan == ',') {
2608 scan++; // skip ','
2609 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002610 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002611 if (*scan != ':') {
2612 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2613 return FALSE;
2614 }
2615 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002616
Jonathan Peyton30419822017-05-12 18:01:32 +00002617 // Read count parameter
Jim Cownie5e8470a2013-09-27 10:38:44 +00002618 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002619 if ((*scan < '0') || (*scan > '9')) {
2620 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2621 return FALSE;
2622 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002623 next = scan;
2624 SKIP_DIGITS(next);
2625 count = __kmp_str_to_int(scan, *next);
2626 KMP_ASSERT(count >= 0);
2627 scan = next;
2628
Jonathan Peyton30419822017-05-12 18:01:32 +00002629 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002630 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002631 if (*scan == '\0') {
2632 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002633 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002634 if (*scan == ',') {
2635 scan++; // skip ','
2636 continue;
2637 }
2638 if (*scan != ':') {
2639 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2640 return FALSE;
2641 }
2642 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002643
Jonathan Peyton30419822017-05-12 18:01:32 +00002644 // Read stride parameter
2645 int sign = +1;
2646 for (;;) {
2647 SKIP_WS(scan);
2648 if (*scan == '+') {
2649 scan++; // skip '+'
2650 continue;
2651 }
2652 if (*scan == '-') {
2653 sign *= -1;
2654 scan++; // skip '-'
2655 continue;
2656 }
2657 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002658 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002659 SKIP_WS(scan);
2660 if ((*scan < '0') || (*scan > '9')) {
2661 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2662 return FALSE;
2663 }
2664 next = scan;
2665 SKIP_DIGITS(next);
2666 stride = __kmp_str_to_int(scan, *next);
2667 KMP_ASSERT(stride >= 0);
2668 scan = next;
2669 stride *= sign;
2670
2671 // valid follow sets are ',' and EOL
2672 SKIP_WS(scan);
2673 if (*scan == '\0') {
2674 break;
2675 }
2676 if (*scan == ',') {
2677 scan++; // skip ','
2678 continue;
2679 }
2680
2681 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2682 return FALSE;
2683 }
2684
2685 {
2686 int len = scan - env;
2687 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
2688 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
2689 retlist[len] = '\0';
2690 *place_list = retlist;
2691 }
2692 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002693}
2694
Jonathan Peyton30419822017-05-12 18:01:32 +00002695static void __kmp_stg_parse_places(char const *name, char const *value,
2696 void *data) {
2697 int count;
2698 const char *scan = value;
2699 const char *next = scan;
2700 const char *kind = "\"threads\"";
2701 kmp_setting_t **rivals = (kmp_setting_t **)data;
2702 int rc;
2703
2704 rc = __kmp_stg_check_rivals(name, value, rivals);
2705 if (rc) {
2706 return;
2707 }
2708
2709 // If OMP_PROC_BIND is not specified but OMP_PLACES is,
2710 // then let OMP_PROC_BIND default to true.
2711 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2712 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2713 }
2714
2715 //__kmp_affinity_num_places = 0;
2716
2717 if (__kmp_match_str("threads", scan, &next)) {
2718 scan = next;
2719 __kmp_affinity_type = affinity_compact;
2720 __kmp_affinity_gran = affinity_gran_thread;
2721 __kmp_affinity_dups = FALSE;
2722 kind = "\"threads\"";
2723 } else if (__kmp_match_str("cores", scan, &next)) {
2724 scan = next;
2725 __kmp_affinity_type = affinity_compact;
2726 __kmp_affinity_gran = affinity_gran_core;
2727 __kmp_affinity_dups = FALSE;
2728 kind = "\"cores\"";
2729 } else if (__kmp_match_str("sockets", scan, &next)) {
2730 scan = next;
2731 __kmp_affinity_type = affinity_compact;
2732 __kmp_affinity_gran = affinity_gran_package;
2733 __kmp_affinity_dups = FALSE;
2734 kind = "\"sockets\"";
2735 } else {
2736 if (__kmp_affinity_proclist != NULL) {
2737 KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist);
2738 __kmp_affinity_proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002739 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002740 if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2741 __kmp_affinity_type = affinity_explicit;
2742 __kmp_affinity_gran = affinity_gran_fine;
2743 __kmp_affinity_dups = FALSE;
2744 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002745 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
Jonathan Peyton30419822017-05-12 18:01:32 +00002746 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002747 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002748 return;
2749 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002750
Jonathan Peyton30419822017-05-12 18:01:32 +00002751 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2752 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2753 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002754
Jonathan Peyton30419822017-05-12 18:01:32 +00002755 SKIP_WS(scan);
2756 if (*scan == '\0') {
2757 return;
2758 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002759
Jonathan Peyton30419822017-05-12 18:01:32 +00002760 // Parse option count parameter in parentheses
2761 if (*scan != '(') {
2762 KMP_WARNING(SyntaxErrorUsing, name, kind);
2763 return;
2764 }
2765 scan++; // skip '('
Jim Cownie5e8470a2013-09-27 10:38:44 +00002766
Jonathan Peyton30419822017-05-12 18:01:32 +00002767 SKIP_WS(scan);
2768 next = scan;
2769 SKIP_DIGITS(next);
2770 count = __kmp_str_to_int(scan, *next);
2771 KMP_ASSERT(count >= 0);
2772 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002773
Jonathan Peyton30419822017-05-12 18:01:32 +00002774 SKIP_WS(scan);
2775 if (*scan != ')') {
2776 KMP_WARNING(SyntaxErrorUsing, name, kind);
2777 return;
2778 }
2779 scan++; // skip ')'
2780
2781 SKIP_WS(scan);
2782 if (*scan != '\0') {
2783 KMP_WARNING(ParseExtraCharsWarn, name, scan);
2784 }
2785 __kmp_affinity_num_places = count;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002786}
2787
Jonathan Peyton30419822017-05-12 18:01:32 +00002788static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
2789 void *data) {
2790 if (__kmp_env_format) {
2791 KMP_STR_BUF_PRINT_NAME;
2792 } else {
2793 __kmp_str_buf_print(buffer, " %s", name);
2794 }
2795 if ((__kmp_nested_proc_bind.used == 0) ||
2796 (__kmp_nested_proc_bind.bind_types == NULL) ||
2797 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
2798 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2799 } else if (__kmp_affinity_type == affinity_explicit) {
2800 if (__kmp_affinity_proclist != NULL) {
2801 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002802 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002803 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002804 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002805 } else if (__kmp_affinity_type == affinity_compact) {
2806 int num;
2807 if (__kmp_affinity_num_masks > 0) {
2808 num = __kmp_affinity_num_masks;
2809 } else if (__kmp_affinity_num_places > 0) {
2810 num = __kmp_affinity_num_places;
2811 } else {
2812 num = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002813 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002814 if (__kmp_affinity_gran == affinity_gran_thread) {
2815 if (num > 0) {
2816 __kmp_str_buf_print(buffer, "='threads(%d)'\n", num);
2817 } else {
2818 __kmp_str_buf_print(buffer, "='threads'\n");
2819 }
2820 } else if (__kmp_affinity_gran == affinity_gran_core) {
2821 if (num > 0) {
2822 __kmp_str_buf_print(buffer, "='cores(%d)' \n", num);
2823 } else {
2824 __kmp_str_buf_print(buffer, "='cores'\n");
2825 }
2826 } else if (__kmp_affinity_gran == affinity_gran_package) {
2827 if (num > 0) {
2828 __kmp_str_buf_print(buffer, "='sockets(%d)'\n", num);
2829 } else {
2830 __kmp_str_buf_print(buffer, "='sockets'\n");
2831 }
2832 } else {
2833 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002834 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002835 } else {
2836 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2837 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002838}
2839
2840#endif /* OMP_40_ENABLED */
2841
Jonathan Peyton30419822017-05-12 18:01:32 +00002842#if (!OMP_40_ENABLED)
Jim Cownie5e8470a2013-09-27 10:38:44 +00002843
Jonathan Peyton30419822017-05-12 18:01:32 +00002844static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
2845 void *data) {
2846 int enabled;
2847 kmp_setting_t **rivals = (kmp_setting_t **)data;
2848 int rc;
2849
2850 rc = __kmp_stg_check_rivals(name, value, rivals);
2851 if (rc) {
2852 return;
2853 }
2854
2855 // In OMP 3.1, OMP_PROC_BIND is strictly a boolean
2856 __kmp_stg_parse_bool(name, value, &enabled);
2857 if (enabled) {
2858 // OMP_PROC_BIND => granularity=fine,scatter on MIC
2859 // OMP_PROC_BIND => granularity=core,scatter elsewhere
2860 __kmp_affinity_type = affinity_scatter;
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002861#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002862 if (__kmp_mic_type != non_mic)
2863 __kmp_affinity_gran = affinity_gran_fine;
2864 else
2865#endif
2866 __kmp_affinity_gran = affinity_gran_core;
2867 } else {
2868 __kmp_affinity_type = affinity_none;
2869 }
2870} // __kmp_parse_proc_bind
2871
2872#endif /* if (! OMP_40_ENABLED) */
2873
2874static void __kmp_stg_parse_topology_method(char const *name, char const *value,
2875 void *data) {
2876 if (__kmp_str_match("all", 1, value)) {
2877 __kmp_affinity_top_method = affinity_top_method_all;
2878 }
2879#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2880 else if (__kmp_str_match("x2apic id", 9, value) ||
2881 __kmp_str_match("x2apic_id", 9, value) ||
2882 __kmp_str_match("x2apic-id", 9, value) ||
2883 __kmp_str_match("x2apicid", 8, value) ||
2884 __kmp_str_match("cpuid leaf 11", 13, value) ||
2885 __kmp_str_match("cpuid_leaf_11", 13, value) ||
2886 __kmp_str_match("cpuid-leaf-11", 13, value) ||
2887 __kmp_str_match("cpuid leaf11", 12, value) ||
2888 __kmp_str_match("cpuid_leaf11", 12, value) ||
2889 __kmp_str_match("cpuid-leaf11", 12, value) ||
2890 __kmp_str_match("cpuidleaf 11", 12, value) ||
2891 __kmp_str_match("cpuidleaf_11", 12, value) ||
2892 __kmp_str_match("cpuidleaf-11", 12, value) ||
2893 __kmp_str_match("cpuidleaf11", 11, value) ||
2894 __kmp_str_match("cpuid 11", 8, value) ||
2895 __kmp_str_match("cpuid_11", 8, value) ||
2896 __kmp_str_match("cpuid-11", 8, value) ||
2897 __kmp_str_match("cpuid11", 7, value) ||
2898 __kmp_str_match("leaf 11", 7, value) ||
2899 __kmp_str_match("leaf_11", 7, value) ||
2900 __kmp_str_match("leaf-11", 7, value) ||
2901 __kmp_str_match("leaf11", 6, value)) {
2902 __kmp_affinity_top_method = affinity_top_method_x2apicid;
2903 } else if (__kmp_str_match("apic id", 7, value) ||
2904 __kmp_str_match("apic_id", 7, value) ||
2905 __kmp_str_match("apic-id", 7, value) ||
2906 __kmp_str_match("apicid", 6, value) ||
2907 __kmp_str_match("cpuid leaf 4", 12, value) ||
2908 __kmp_str_match("cpuid_leaf_4", 12, value) ||
2909 __kmp_str_match("cpuid-leaf-4", 12, value) ||
2910 __kmp_str_match("cpuid leaf4", 11, value) ||
2911 __kmp_str_match("cpuid_leaf4", 11, value) ||
2912 __kmp_str_match("cpuid-leaf4", 11, value) ||
2913 __kmp_str_match("cpuidleaf 4", 11, value) ||
2914 __kmp_str_match("cpuidleaf_4", 11, value) ||
2915 __kmp_str_match("cpuidleaf-4", 11, value) ||
2916 __kmp_str_match("cpuidleaf4", 10, value) ||
2917 __kmp_str_match("cpuid 4", 7, value) ||
2918 __kmp_str_match("cpuid_4", 7, value) ||
2919 __kmp_str_match("cpuid-4", 7, value) ||
2920 __kmp_str_match("cpuid4", 6, value) ||
2921 __kmp_str_match("leaf 4", 6, value) ||
2922 __kmp_str_match("leaf_4", 6, value) ||
2923 __kmp_str_match("leaf-4", 6, value) ||
2924 __kmp_str_match("leaf4", 5, value)) {
2925 __kmp_affinity_top_method = affinity_top_method_apicid;
2926 }
2927#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2928 else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
2929 __kmp_str_match("cpuinfo", 5, value)) {
2930 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
2931 }
2932#if KMP_GROUP_AFFINITY
2933 else if (__kmp_str_match("group", 1, value)) {
2934 __kmp_affinity_top_method = affinity_top_method_group;
2935 }
2936#endif /* KMP_GROUP_AFFINITY */
2937 else if (__kmp_str_match("flat", 1, value)) {
2938 __kmp_affinity_top_method = affinity_top_method_flat;
2939 }
2940#if KMP_USE_HWLOC
2941 else if (__kmp_str_match("hwloc", 1, value)) {
2942 __kmp_affinity_top_method = affinity_top_method_hwloc;
2943 }
2944#endif
2945 else {
2946 KMP_WARNING(StgInvalidValue, name, value);
2947 }
2948} // __kmp_stg_parse_topology_method
2949
2950static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
2951 char const *name, void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002952 char const *value = NULL;
2953
2954 switch (__kmp_affinity_top_method) {
2955 case affinity_top_method_default:
2956 value = "default";
2957 break;
2958
2959 case affinity_top_method_all:
2960 value = "all";
2961 break;
2962
2963#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2964 case affinity_top_method_x2apicid:
2965 value = "x2APIC id";
2966 break;
2967
2968 case affinity_top_method_apicid:
2969 value = "APIC id";
2970 break;
2971#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2972
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002973#if KMP_USE_HWLOC
Jonathan Peyton30419822017-05-12 18:01:32 +00002974 case affinity_top_method_hwloc:
2975 value = "hwloc";
2976 break;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002977#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00002978
2979 case affinity_top_method_cpuinfo:
2980 value = "cpuinfo";
2981 break;
2982
2983#if KMP_GROUP_AFFINITY
2984 case affinity_top_method_group:
2985 value = "group";
2986 break;
2987#endif /* KMP_GROUP_AFFINITY */
2988
2989 case affinity_top_method_flat:
2990 value = "flat";
2991 break;
2992 }
2993
2994 if (value != NULL) {
2995 __kmp_stg_print_str(buffer, name, value);
2996 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002997} // __kmp_stg_print_topology_method
2998
2999#endif /* KMP_AFFINITY_SUPPORTED */
3000
3001#if OMP_40_ENABLED
3002
3003// OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
3004// OMP_PLACES / place-partition-var is not.
3005static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
3006 void *data) {
3007 kmp_setting_t **rivals = (kmp_setting_t **)data;
3008 int rc;
3009
3010 rc = __kmp_stg_check_rivals(name, value, rivals);
3011 if (rc) {
3012 return;
3013 }
3014
3015 // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
3016 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
3017 (__kmp_nested_proc_bind.used > 0));
3018
3019 const char *buf = value;
3020 const char *next;
3021 int num;
3022 SKIP_WS(buf);
3023 if ((*buf >= '0') && (*buf <= '9')) {
3024 next = buf;
3025 SKIP_DIGITS(next);
3026 num = __kmp_str_to_int(buf, *next);
3027 KMP_ASSERT(num >= 0);
3028 buf = next;
3029 SKIP_WS(buf);
3030 } else {
3031 num = -1;
3032 }
3033
3034 next = buf;
3035 if (__kmp_match_str("disabled", buf, &next)) {
3036 buf = next;
3037 SKIP_WS(buf);
3038#if KMP_AFFINITY_SUPPORTED
3039 __kmp_affinity_type = affinity_disabled;
3040#endif /* KMP_AFFINITY_SUPPORTED */
3041 __kmp_nested_proc_bind.used = 1;
3042 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3043 } else if ((num == (int)proc_bind_false) ||
3044 __kmp_match_str("false", buf, &next)) {
3045 buf = next;
3046 SKIP_WS(buf);
3047#if KMP_AFFINITY_SUPPORTED
3048 __kmp_affinity_type = affinity_none;
3049#endif /* KMP_AFFINITY_SUPPORTED */
3050 __kmp_nested_proc_bind.used = 1;
3051 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3052 } else if ((num == (int)proc_bind_true) ||
3053 __kmp_match_str("true", buf, &next)) {
3054 buf = next;
3055 SKIP_WS(buf);
3056 __kmp_nested_proc_bind.used = 1;
3057 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3058 } else {
3059 // Count the number of values in the env var string
3060 const char *scan;
3061 int nelem = 1;
3062 for (scan = buf; *scan != '\0'; scan++) {
3063 if (*scan == ',') {
3064 nelem++;
3065 }
3066 }
3067
3068 // Create / expand the nested proc_bind array as needed
3069 if (__kmp_nested_proc_bind.size < nelem) {
3070 __kmp_nested_proc_bind.bind_types =
3071 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3072 __kmp_nested_proc_bind.bind_types,
3073 sizeof(kmp_proc_bind_t) * nelem);
3074 if (__kmp_nested_proc_bind.bind_types == NULL) {
3075 KMP_FATAL(MemoryAllocFailed);
3076 }
3077 __kmp_nested_proc_bind.size = nelem;
3078 }
3079 __kmp_nested_proc_bind.used = nelem;
3080
3081 // Save values in the nested proc_bind array
3082 int i = 0;
3083 for (;;) {
3084 enum kmp_proc_bind_t bind;
3085
3086 if ((num == (int)proc_bind_master) ||
3087 __kmp_match_str("master", buf, &next)) {
3088 buf = next;
3089 SKIP_WS(buf);
3090 bind = proc_bind_master;
3091 } else if ((num == (int)proc_bind_close) ||
3092 __kmp_match_str("close", buf, &next)) {
3093 buf = next;
3094 SKIP_WS(buf);
3095 bind = proc_bind_close;
3096 } else if ((num == (int)proc_bind_spread) ||
3097 __kmp_match_str("spread", buf, &next)) {
3098 buf = next;
3099 SKIP_WS(buf);
3100 bind = proc_bind_spread;
3101 } else {
3102 KMP_WARNING(StgInvalidValue, name, value);
3103 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3104 __kmp_nested_proc_bind.used = 1;
3105 return;
3106 }
3107
3108 __kmp_nested_proc_bind.bind_types[i++] = bind;
3109 if (i >= nelem) {
3110 break;
3111 }
3112 KMP_DEBUG_ASSERT(*buf == ',');
3113 buf++;
3114 SKIP_WS(buf);
3115
3116 // Read next value if it was specified as an integer
3117 if ((*buf >= '0') && (*buf <= '9')) {
3118 next = buf;
3119 SKIP_DIGITS(next);
3120 num = __kmp_str_to_int(buf, *next);
3121 KMP_ASSERT(num >= 0);
3122 buf = next;
3123 SKIP_WS(buf);
3124 } else {
3125 num = -1;
3126 }
3127 }
3128 SKIP_WS(buf);
3129 }
3130 if (*buf != '\0') {
3131 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3132 }
3133}
3134
3135static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
3136 void *data) {
3137 int nelem = __kmp_nested_proc_bind.used;
3138 if (__kmp_env_format) {
3139 KMP_STR_BUF_PRINT_NAME;
3140 } else {
3141 __kmp_str_buf_print(buffer, " %s", name);
3142 }
3143 if (nelem == 0) {
3144 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3145 } else {
3146 int i;
3147 __kmp_str_buf_print(buffer, "='", name);
3148 for (i = 0; i < nelem; i++) {
3149 switch (__kmp_nested_proc_bind.bind_types[i]) {
3150 case proc_bind_false:
3151 __kmp_str_buf_print(buffer, "false");
3152 break;
3153
3154 case proc_bind_true:
3155 __kmp_str_buf_print(buffer, "true");
3156 break;
3157
3158 case proc_bind_master:
3159 __kmp_str_buf_print(buffer, "master");
3160 break;
3161
3162 case proc_bind_close:
3163 __kmp_str_buf_print(buffer, "close");
3164 break;
3165
3166 case proc_bind_spread:
3167 __kmp_str_buf_print(buffer, "spread");
3168 break;
3169
3170 case proc_bind_intel:
3171 __kmp_str_buf_print(buffer, "intel");
3172 break;
3173
3174 case proc_bind_default:
3175 __kmp_str_buf_print(buffer, "default");
3176 break;
3177 }
3178 if (i < nelem - 1) {
3179 __kmp_str_buf_print(buffer, ",");
3180 }
3181 }
3182 __kmp_str_buf_print(buffer, "'\n");
3183 }
3184}
3185
3186#endif /* OMP_40_ENABLED */
3187
3188// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003189// OMP_DYNAMIC
Jim Cownie5e8470a2013-09-27 10:38:44 +00003190
Jonathan Peyton30419822017-05-12 18:01:32 +00003191static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
3192 void *data) {
3193 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003194} // __kmp_stg_parse_omp_dynamic
3195
Jonathan Peyton30419822017-05-12 18:01:32 +00003196static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
3197 void *data) {
3198 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003199} // __kmp_stg_print_omp_dynamic
3200
Jonathan Peyton30419822017-05-12 18:01:32 +00003201static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
3202 char const *value, void *data) {
3203 if (TCR_4(__kmp_init_parallel)) {
3204 KMP_WARNING(EnvParallelWarn, name);
3205 __kmp_env_toPrint(name, 0);
3206 return;
3207 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003208#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00003209 else if (__kmp_str_match("load balance", 2, value) ||
3210 __kmp_str_match("load_balance", 2, value) ||
3211 __kmp_str_match("load-balance", 2, value) ||
3212 __kmp_str_match("loadbalance", 2, value) ||
3213 __kmp_str_match("balance", 1, value)) {
3214 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3215 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003216#endif /* USE_LOAD_BALANCE */
Jonathan Peyton30419822017-05-12 18:01:32 +00003217 else if (__kmp_str_match("thread limit", 1, value) ||
3218 __kmp_str_match("thread_limit", 1, value) ||
3219 __kmp_str_match("thread-limit", 1, value) ||
3220 __kmp_str_match("threadlimit", 1, value) ||
3221 __kmp_str_match("limit", 2, value)) {
3222 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3223 } else if (__kmp_str_match("random", 1, value)) {
3224 __kmp_global.g.g_dynamic_mode = dynamic_random;
3225 } else {
3226 KMP_WARNING(StgInvalidValue, name, value);
3227 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003228} //__kmp_stg_parse_kmp_dynamic_mode
3229
Jonathan Peyton30419822017-05-12 18:01:32 +00003230static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
3231 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003232#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003233 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
3234 __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
3235 }
3236#ifdef USE_LOAD_BALANCE
3237 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
3238 __kmp_stg_print_str(buffer, name, "load balance");
3239 }
3240#endif /* USE_LOAD_BALANCE */
3241 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
3242 __kmp_stg_print_str(buffer, name, "thread limit");
3243 } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
3244 __kmp_stg_print_str(buffer, name, "random");
3245 } else {
3246 KMP_ASSERT(0);
3247 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003248#endif /* KMP_DEBUG */
3249} // __kmp_stg_print_kmp_dynamic_mode
3250
Jim Cownie5e8470a2013-09-27 10:38:44 +00003251#ifdef USE_LOAD_BALANCE
3252
Jonathan Peyton30419822017-05-12 18:01:32 +00003253// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003254// KMP_LOAD_BALANCE_INTERVAL
Jim Cownie5e8470a2013-09-27 10:38:44 +00003255
Jonathan Peyton30419822017-05-12 18:01:32 +00003256static void __kmp_stg_parse_ld_balance_interval(char const *name,
3257 char const *value, void *data) {
3258 double interval = __kmp_convert_to_double(value);
3259 if (interval >= 0) {
3260 __kmp_load_balance_interval = interval;
3261 } else {
3262 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003263 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003264} // __kmp_stg_parse_load_balance_interval
3265
Jonathan Peyton30419822017-05-12 18:01:32 +00003266static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
3267 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003268#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003269 __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
3270 __kmp_load_balance_interval);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003271#endif /* KMP_DEBUG */
3272} // __kmp_stg_print_load_balance_interval
3273
3274#endif /* USE_LOAD_BALANCE */
3275
Jonathan Peyton30419822017-05-12 18:01:32 +00003276// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003277// KMP_INIT_AT_FORK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003278
Jonathan Peyton30419822017-05-12 18:01:32 +00003279static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
3280 void *data) {
3281 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
3282 if (__kmp_need_register_atfork) {
3283 __kmp_need_register_atfork_specified = TRUE;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003284 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003285} // __kmp_stg_parse_init_at_fork
3286
Jonathan Peyton30419822017-05-12 18:01:32 +00003287static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
3288 char const *name, void *data) {
3289 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003290} // __kmp_stg_print_init_at_fork
3291
Jonathan Peyton30419822017-05-12 18:01:32 +00003292// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003293// KMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003294
Jonathan Peyton30419822017-05-12 18:01:32 +00003295static void __kmp_stg_parse_schedule(char const *name, char const *value,
3296 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003297
Jonathan Peyton30419822017-05-12 18:01:32 +00003298 if (value != NULL) {
3299 size_t length = KMP_STRLEN(value);
3300 if (length > INT_MAX) {
3301 KMP_WARNING(LongValue, name);
3302 } else {
3303 char *semicolon;
3304 if (value[length - 1] == '"' || value[length - 1] == '\'')
3305 KMP_WARNING(UnbalancedQuotes, name);
3306 do {
3307 char sentinel;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003308
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003309 semicolon = CCAST(char *, strchr(value, ';'));
Jonathan Peyton30419822017-05-12 18:01:32 +00003310 if (*value && semicolon != value) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003311 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003312
Jonathan Peyton30419822017-05-12 18:01:32 +00003313 if (comma) {
3314 ++comma;
3315 sentinel = ',';
3316 } else
3317 sentinel = ';';
3318 if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
3319 if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
3320 __kmp_static = kmp_sch_static_greedy;
3321 continue;
3322 } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
3323 ';')) {
3324 __kmp_static = kmp_sch_static_balanced;
3325 continue;
3326 }
3327 } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3328 sentinel)) {
3329 if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
3330 __kmp_guided = kmp_sch_guided_iterative_chunked;
3331 continue;
3332 } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
3333 ';')) {
3334 /* analytical not allowed for too many threads */
3335 __kmp_guided = kmp_sch_guided_analytical_chunked;
3336 continue;
3337 }
3338 }
3339 KMP_WARNING(InvalidClause, name, value);
3340 } else
3341 KMP_WARNING(EmptyClause, name);
3342 } while ((value = semicolon ? semicolon + 1 : NULL));
3343 }
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003344 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003345
3346} // __kmp_stg_parse__schedule
3347
Jonathan Peyton30419822017-05-12 18:01:32 +00003348static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
3349 void *data) {
3350 if (__kmp_env_format) {
3351 KMP_STR_BUF_PRINT_NAME_EX(name);
3352 } else {
3353 __kmp_str_buf_print(buffer, " %s='", name);
3354 }
3355 if (__kmp_static == kmp_sch_static_greedy) {
3356 __kmp_str_buf_print(buffer, "%s", "static,greedy");
3357 } else if (__kmp_static == kmp_sch_static_balanced) {
3358 __kmp_str_buf_print(buffer, "%s", "static,balanced");
3359 }
3360 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
3361 __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
3362 } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
3363 __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
3364 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003365} // __kmp_stg_print_schedule
3366
Jonathan Peyton30419822017-05-12 18:01:32 +00003367// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003368// OMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003369
Jonathan Peyton30419822017-05-12 18:01:32 +00003370static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
3371 void *data) {
3372 size_t length;
3373 if (value) {
3374 length = KMP_STRLEN(value);
3375 if (length) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003376 char *comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00003377 if (value[length - 1] == '"' || value[length - 1] == '\'')
3378 KMP_WARNING(UnbalancedQuotes, name);
3379 /* get the specified scheduling style */
3380 if (!__kmp_strcasecmp_with_sentinel("dynamic", value, ',')) /* DYNAMIC */
3381 __kmp_sched = kmp_sch_dynamic_chunked;
3382 else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3383 ',')) /* GUIDED */
3384 __kmp_sched = kmp_sch_guided_chunked;
3385 // AC: TODO: add AUTO schedule, and pprobably remove TRAPEZOIDAL (OMP 3.0
3386 // does not allow it)
3387 else if (!__kmp_strcasecmp_with_sentinel("auto", value, ',')) { /* AUTO */
3388 __kmp_sched = kmp_sch_auto;
3389 if (comma) {
3390 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, comma),
3391 __kmp_msg_null);
3392 comma = NULL;
3393 }
3394 } else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", value,
3395 ',')) /* TRAPEZOIDAL */
3396 __kmp_sched = kmp_sch_trapezoidal;
3397 else if (!__kmp_strcasecmp_with_sentinel("static", value,
3398 ',')) /* STATIC */
3399 __kmp_sched = kmp_sch_static;
Andrey Churbanov429dbc22016-07-11 10:44:57 +00003400#if KMP_STATIC_STEAL_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00003401 else if (!__kmp_strcasecmp_with_sentinel("static_steal", value, ','))
3402 __kmp_sched = kmp_sch_static_steal;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003403#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003404 else {
3405 KMP_WARNING(StgInvalidValue, name, value);
3406 value = NULL; /* skip processing of comma */
3407 }
3408 if (value && comma) {
Jonathan Peyton30419822017-05-12 18:01:32 +00003409 if (__kmp_sched == kmp_sch_static)
3410 __kmp_sched = kmp_sch_static_chunked;
3411 ++comma;
3412 __kmp_chunk = __kmp_str_to_int(comma, 0);
3413 if (__kmp_chunk < 1) {
3414 __kmp_chunk = KMP_DEFAULT_CHUNK;
3415 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, comma),
3416 __kmp_msg_null);
3417 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3418 // AC: next block commented out until KMP_DEFAULT_CHUNK !=
3419 // KMP_MIN_CHUNK (to improve code coverage :)
3420 // The default chunk size is 1 according to standard, thus making
3421 // KMP_MIN_CHUNK not 1 we would introduce mess:
3422 // wrong chunk becomes 1, but it will be impossible to explicitely
3423 // set 1, because it becomes KMP_MIN_CHUNK...
3424 // } else if ( __kmp_chunk < KMP_MIN_CHUNK ) {
3425 // __kmp_chunk = KMP_MIN_CHUNK;
3426 } else if (__kmp_chunk > KMP_MAX_CHUNK) {
3427 __kmp_chunk = KMP_MAX_CHUNK;
3428 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, comma),
3429 __kmp_msg_null);
3430 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3431 }
Jonathan Peytond74d8902017-07-25 18:20:16 +00003432 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003433 } else
3434 KMP_WARNING(EmptyString, name);
3435 }
3436 K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
3437 K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
3438 K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
3439 K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
Jim Cownie5e8470a2013-09-27 10:38:44 +00003440} // __kmp_stg_parse_omp_schedule
3441
Jonathan Peyton30419822017-05-12 18:01:32 +00003442static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
3443 char const *name, void *data) {
3444 if (__kmp_env_format) {
3445 KMP_STR_BUF_PRINT_NAME_EX(name);
3446 } else {
3447 __kmp_str_buf_print(buffer, " %s='", name);
3448 }
3449 if (__kmp_chunk) {
3450 switch (__kmp_sched) {
3451 case kmp_sch_dynamic_chunked:
3452 __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
3453 break;
3454 case kmp_sch_guided_iterative_chunked:
3455 case kmp_sch_guided_analytical_chunked:
3456 __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
3457 break;
3458 case kmp_sch_trapezoidal:
3459 __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
3460 break;
3461 case kmp_sch_static:
3462 case kmp_sch_static_chunked:
3463 case kmp_sch_static_balanced:
3464 case kmp_sch_static_greedy:
3465 __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
3466 break;
3467 case kmp_sch_static_steal:
3468 __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
3469 break;
3470 case kmp_sch_auto:
3471 __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
3472 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003473 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003474 } else {
3475 switch (__kmp_sched) {
3476 case kmp_sch_dynamic_chunked:
3477 __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
3478 break;
3479 case kmp_sch_guided_iterative_chunked:
3480 case kmp_sch_guided_analytical_chunked:
3481 __kmp_str_buf_print(buffer, "%s'\n", "guided");
3482 break;
3483 case kmp_sch_trapezoidal:
3484 __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
3485 break;
3486 case kmp_sch_static:
3487 case kmp_sch_static_chunked:
3488 case kmp_sch_static_balanced:
3489 case kmp_sch_static_greedy:
3490 __kmp_str_buf_print(buffer, "%s'\n", "static");
3491 break;
3492 case kmp_sch_static_steal:
3493 __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
3494 break;
3495 case kmp_sch_auto:
3496 __kmp_str_buf_print(buffer, "%s'\n", "auto");
3497 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003498 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003499 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003500} // __kmp_stg_print_omp_schedule
3501
Jonathan Peyton30419822017-05-12 18:01:32 +00003502// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003503// KMP_ATOMIC_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003504
Jonathan Peyton30419822017-05-12 18:01:32 +00003505static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
3506 void *data) {
3507 // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
3508 // compatibility mode.
3509 int mode = 0;
3510 int max = 1;
3511#ifdef KMP_GOMP_COMPAT
3512 max = 2;
3513#endif /* KMP_GOMP_COMPAT */
3514 __kmp_stg_parse_int(name, value, 0, max, &mode);
3515 // TODO; parse_int is not very suitable for this case. In case of overflow it
3516 // is better to use
3517 // 0 rather that max value.
3518 if (mode > 0) {
3519 __kmp_atomic_mode = mode;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003520 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003521} // __kmp_stg_parse_atomic_mode
3522
Jonathan Peyton30419822017-05-12 18:01:32 +00003523static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
3524 void *data) {
3525 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003526} // __kmp_stg_print_atomic_mode
3527
Jonathan Peyton30419822017-05-12 18:01:32 +00003528// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003529// KMP_CONSISTENCY_CHECK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003530
Jonathan Peyton30419822017-05-12 18:01:32 +00003531static void __kmp_stg_parse_consistency_check(char const *name,
3532 char const *value, void *data) {
3533 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
3534 // Note, this will not work from kmp_set_defaults because th_cons stack was
3535 // not allocated
3536 // for existed thread(s) thus the first __kmp_push_<construct> will break
3537 // with assertion.
3538 // TODO: allocate th_cons if called from kmp_set_defaults.
3539 __kmp_env_consistency_check = TRUE;
3540 } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
3541 __kmp_env_consistency_check = FALSE;
3542 } else {
3543 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003544 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003545} // __kmp_stg_parse_consistency_check
3546
Jonathan Peyton30419822017-05-12 18:01:32 +00003547static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
3548 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003549#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003550 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003551
Jonathan Peyton30419822017-05-12 18:01:32 +00003552 if (__kmp_env_consistency_check) {
3553 value = "all";
3554 } else {
3555 value = "none";
3556 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003557
Jonathan Peyton30419822017-05-12 18:01:32 +00003558 if (value != NULL) {
3559 __kmp_stg_print_str(buffer, name, value);
3560 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003561#endif /* KMP_DEBUG */
3562} // __kmp_stg_print_consistency_check
3563
Jim Cownie5e8470a2013-09-27 10:38:44 +00003564#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00003565// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003566// KMP_ITT_PREPARE_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00003567
3568#if USE_ITT_NOTIFY
3569
Jonathan Peyton30419822017-05-12 18:01:32 +00003570static void __kmp_stg_parse_itt_prepare_delay(char const *name,
3571 char const *value, void *data) {
3572 // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
3573 // iterations.
3574 int delay = 0;
3575 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
3576 __kmp_itt_prepare_delay = delay;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003577} // __kmp_str_parse_itt_prepare_delay
3578
Jonathan Peyton30419822017-05-12 18:01:32 +00003579static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
3580 char const *name, void *data) {
3581 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003582
3583} // __kmp_str_print_itt_prepare_delay
3584
3585#endif // USE_ITT_NOTIFY
3586#endif /* USE_ITT_BUILD */
3587
Jonathan Peyton30419822017-05-12 18:01:32 +00003588// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003589// KMP_MALLOC_POOL_INCR
Jim Cownie5e8470a2013-09-27 10:38:44 +00003590
Jonathan Peyton30419822017-05-12 18:01:32 +00003591static void __kmp_stg_parse_malloc_pool_incr(char const *name,
3592 char const *value, void *data) {
3593 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
3594 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
3595 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003596} // __kmp_stg_parse_malloc_pool_incr
3597
Jonathan Peyton30419822017-05-12 18:01:32 +00003598static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
3599 char const *name, void *data) {
3600 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003601
3602} // _kmp_stg_print_malloc_pool_incr
3603
Jim Cownie5e8470a2013-09-27 10:38:44 +00003604#ifdef KMP_DEBUG
3605
Jonathan Peyton30419822017-05-12 18:01:32 +00003606// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003607// KMP_PAR_RANGE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003608
Jonathan Peyton30419822017-05-12 18:01:32 +00003609static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
3610 void *data) {
3611 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
3612 __kmp_par_range_routine, __kmp_par_range_filename,
3613 &__kmp_par_range_lb, &__kmp_par_range_ub);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003614} // __kmp_stg_parse_par_range_env
3615
Jonathan Peyton30419822017-05-12 18:01:32 +00003616static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
3617 char const *name, void *data) {
3618 if (__kmp_par_range != 0) {
3619 __kmp_stg_print_str(buffer, name, par_range_to_print);
3620 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003621} // __kmp_stg_print_par_range_env
3622
Jonathan Peyton30419822017-05-12 18:01:32 +00003623// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003624// KMP_YIELD_CYCLE, KMP_YIELD_ON, KMP_YIELD_OFF
Jim Cownie5e8470a2013-09-27 10:38:44 +00003625
Jonathan Peyton30419822017-05-12 18:01:32 +00003626static void __kmp_stg_parse_yield_cycle(char const *name, char const *value,
3627 void *data) {
3628 int flag = __kmp_yield_cycle;
3629 __kmp_stg_parse_bool(name, value, &flag);
3630 __kmp_yield_cycle = flag;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003631} // __kmp_stg_parse_yield_cycle
3632
Jonathan Peyton30419822017-05-12 18:01:32 +00003633static void __kmp_stg_print_yield_cycle(kmp_str_buf_t *buffer, char const *name,
3634 void *data) {
3635 __kmp_stg_print_bool(buffer, name, __kmp_yield_cycle);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003636} // __kmp_stg_print_yield_cycle
3637
Jonathan Peyton30419822017-05-12 18:01:32 +00003638static void __kmp_stg_parse_yield_on(char const *name, char const *value,
3639 void *data) {
3640 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003641} // __kmp_stg_parse_yield_on
3642
Jonathan Peyton30419822017-05-12 18:01:32 +00003643static void __kmp_stg_print_yield_on(kmp_str_buf_t *buffer, char const *name,
3644 void *data) {
3645 __kmp_stg_print_int(buffer, name, __kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003646} // __kmp_stg_print_yield_on
3647
Jonathan Peyton30419822017-05-12 18:01:32 +00003648static void __kmp_stg_parse_yield_off(char const *name, char const *value,
3649 void *data) {
3650 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003651} // __kmp_stg_parse_yield_off
3652
Jonathan Peyton30419822017-05-12 18:01:32 +00003653static void __kmp_stg_print_yield_off(kmp_str_buf_t *buffer, char const *name,
3654 void *data) {
3655 __kmp_stg_print_int(buffer, name, __kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003656} // __kmp_stg_print_yield_off
3657
3658#endif
3659
Jonathan Peyton30419822017-05-12 18:01:32 +00003660// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003661// KMP_INIT_WAIT, KMP_NEXT_WAIT
Jim Cownie5e8470a2013-09-27 10:38:44 +00003662
Jonathan Peyton30419822017-05-12 18:01:32 +00003663static void __kmp_stg_parse_init_wait(char const *name, char const *value,
3664 void *data) {
3665 int wait;
3666 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3667 wait = __kmp_init_wait / 2;
3668 __kmp_stg_parse_int(name, value, KMP_MIN_INIT_WAIT, KMP_MAX_INIT_WAIT, &wait);
3669 __kmp_init_wait = wait * 2;
3670 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3671 __kmp_yield_init = __kmp_init_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003672} // __kmp_stg_parse_init_wait
3673
Jonathan Peyton30419822017-05-12 18:01:32 +00003674static void __kmp_stg_print_init_wait(kmp_str_buf_t *buffer, char const *name,
3675 void *data) {
3676 __kmp_stg_print_int(buffer, name, __kmp_init_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003677} // __kmp_stg_print_init_wait
3678
Jonathan Peyton30419822017-05-12 18:01:32 +00003679static void __kmp_stg_parse_next_wait(char const *name, char const *value,
3680 void *data) {
3681 int wait;
3682 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3683 wait = __kmp_next_wait / 2;
3684 __kmp_stg_parse_int(name, value, KMP_MIN_NEXT_WAIT, KMP_MAX_NEXT_WAIT, &wait);
3685 __kmp_next_wait = wait * 2;
3686 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3687 __kmp_yield_next = __kmp_next_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003688} // __kmp_stg_parse_next_wait
3689
Jonathan Peyton30419822017-05-12 18:01:32 +00003690static void __kmp_stg_print_next_wait(kmp_str_buf_t *buffer, char const *name,
3691 void *data) {
3692 __kmp_stg_print_int(buffer, name, __kmp_next_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003693} //__kmp_stg_print_next_wait
3694
Jonathan Peyton30419822017-05-12 18:01:32 +00003695// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003696// KMP_GTID_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003697
Jonathan Peyton30419822017-05-12 18:01:32 +00003698static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
3699 void *data) {
3700 // Modes:
3701 // 0 -- do not change default
3702 // 1 -- sp search
3703 // 2 -- use "keyed" TLS var, i.e.
3704 // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
3705 // 3 -- __declspec(thread) TLS var in tdata section
3706 int mode = 0;
3707 int max = 2;
3708#ifdef KMP_TDATA_GTID
3709 max = 3;
3710#endif /* KMP_TDATA_GTID */
3711 __kmp_stg_parse_int(name, value, 0, max, &mode);
3712 // TODO; parse_int is not very suitable for this case. In case of overflow it
3713 // is better to use 0 rather that max value.
3714 if (mode == 0) {
3715 __kmp_adjust_gtid_mode = TRUE;
3716 } else {
3717 __kmp_gtid_mode = mode;
3718 __kmp_adjust_gtid_mode = FALSE;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003719 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003720} // __kmp_str_parse_gtid_mode
3721
Jonathan Peyton30419822017-05-12 18:01:32 +00003722static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
3723 void *data) {
3724 if (__kmp_adjust_gtid_mode) {
3725 __kmp_stg_print_int(buffer, name, 0);
3726 } else {
3727 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
3728 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003729} // __kmp_stg_print_gtid_mode
3730
Jonathan Peyton30419822017-05-12 18:01:32 +00003731// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003732// KMP_NUM_LOCKS_IN_BLOCK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003733
Jonathan Peyton30419822017-05-12 18:01:32 +00003734static void __kmp_stg_parse_lock_block(char const *name, char const *value,
3735 void *data) {
3736 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003737} // __kmp_str_parse_lock_block
3738
Jonathan Peyton30419822017-05-12 18:01:32 +00003739static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
3740 void *data) {
3741 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003742} // __kmp_stg_print_lock_block
3743
Jonathan Peyton30419822017-05-12 18:01:32 +00003744// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003745// KMP_LOCK_KIND
Jim Cownie5e8470a2013-09-27 10:38:44 +00003746
Jonathan Peytondae13d82015-12-11 21:57:06 +00003747#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00003748#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003749#else
Jonathan Peyton30419822017-05-12 18:01:32 +00003750#define KMP_STORE_LOCK_SEQ(a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003751#endif
3752
Jonathan Peyton30419822017-05-12 18:01:32 +00003753static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
3754 void *data) {
3755 if (__kmp_init_user_locks) {
3756 KMP_WARNING(EnvLockWarn, name);
3757 return;
3758 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003759
Jonathan Peyton30419822017-05-12 18:01:32 +00003760 if (__kmp_str_match("tas", 2, value) ||
3761 __kmp_str_match("test and set", 2, value) ||
3762 __kmp_str_match("test_and_set", 2, value) ||
3763 __kmp_str_match("test-and-set", 2, value) ||
3764 __kmp_str_match("test andset", 2, value) ||
3765 __kmp_str_match("test_andset", 2, value) ||
3766 __kmp_str_match("test-andset", 2, value) ||
3767 __kmp_str_match("testand set", 2, value) ||
3768 __kmp_str_match("testand_set", 2, value) ||
3769 __kmp_str_match("testand-set", 2, value) ||
3770 __kmp_str_match("testandset", 2, value)) {
3771 __kmp_user_lock_kind = lk_tas;
3772 KMP_STORE_LOCK_SEQ(tas);
3773 }
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003774#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003775 else if (__kmp_str_match("futex", 1, value)) {
3776 if (__kmp_futex_determine_capable()) {
3777 __kmp_user_lock_kind = lk_futex;
3778 KMP_STORE_LOCK_SEQ(futex);
3779 } else {
3780 KMP_WARNING(FutexNotSupported, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003781 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003782 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003783#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003784 else if (__kmp_str_match("ticket", 2, value)) {
3785 __kmp_user_lock_kind = lk_ticket;
3786 KMP_STORE_LOCK_SEQ(ticket);
3787 } else if (__kmp_str_match("queuing", 1, value) ||
3788 __kmp_str_match("queue", 1, value)) {
3789 __kmp_user_lock_kind = lk_queuing;
3790 KMP_STORE_LOCK_SEQ(queuing);
3791 } else if (__kmp_str_match("drdpa ticket", 1, value) ||
3792 __kmp_str_match("drdpa_ticket", 1, value) ||
3793 __kmp_str_match("drdpa-ticket", 1, value) ||
3794 __kmp_str_match("drdpaticket", 1, value) ||
3795 __kmp_str_match("drdpa", 1, value)) {
3796 __kmp_user_lock_kind = lk_drdpa;
3797 KMP_STORE_LOCK_SEQ(drdpa);
3798 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003799#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003800 else if (__kmp_str_match("adaptive", 1, value)) {
3801 if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
3802 __kmp_user_lock_kind = lk_adaptive;
3803 KMP_STORE_LOCK_SEQ(adaptive);
3804 } else {
3805 KMP_WARNING(AdaptiveNotSupported, name, value);
3806 __kmp_user_lock_kind = lk_queuing;
3807 KMP_STORE_LOCK_SEQ(queuing);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003808 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003809 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003810#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peytondae13d82015-12-11 21:57:06 +00003811#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003812 else if (__kmp_str_match("rtm", 1, value)) {
3813 if (__kmp_cpuinfo.rtm) {
3814 __kmp_user_lock_kind = lk_rtm;
3815 KMP_STORE_LOCK_SEQ(rtm);
3816 } else {
3817 KMP_WARNING(AdaptiveNotSupported, name, value);
3818 __kmp_user_lock_kind = lk_queuing;
3819 KMP_STORE_LOCK_SEQ(queuing);
Jonathan Peytondae13d82015-12-11 21:57:06 +00003820 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003821 } else if (__kmp_str_match("hle", 1, value)) {
3822 __kmp_user_lock_kind = lk_hle;
3823 KMP_STORE_LOCK_SEQ(hle);
3824 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00003825#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003826 else {
3827 KMP_WARNING(StgInvalidValue, name, value);
3828 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003829}
3830
Jonathan Peyton30419822017-05-12 18:01:32 +00003831static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
3832 void *data) {
3833 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003834
Jonathan Peyton30419822017-05-12 18:01:32 +00003835 switch (__kmp_user_lock_kind) {
3836 case lk_default:
3837 value = "default";
3838 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003839
Jonathan Peyton30419822017-05-12 18:01:32 +00003840 case lk_tas:
3841 value = "tas";
3842 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003843
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003844#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003845 case lk_futex:
3846 value = "futex";
3847 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003848#endif
3849
Jonathan Peytondae13d82015-12-11 21:57:06 +00003850#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003851 case lk_rtm:
3852 value = "rtm";
3853 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003854
Jonathan Peyton30419822017-05-12 18:01:32 +00003855 case lk_hle:
3856 value = "hle";
3857 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003858#endif
3859
Jonathan Peyton30419822017-05-12 18:01:32 +00003860 case lk_ticket:
3861 value = "ticket";
3862 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003863
Jonathan Peyton30419822017-05-12 18:01:32 +00003864 case lk_queuing:
3865 value = "queuing";
3866 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003867
Jonathan Peyton30419822017-05-12 18:01:32 +00003868 case lk_drdpa:
3869 value = "drdpa";
3870 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003871#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003872 case lk_adaptive:
3873 value = "adaptive";
3874 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003875#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003876 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003877
Jonathan Peyton30419822017-05-12 18:01:32 +00003878 if (value != NULL) {
3879 __kmp_stg_print_str(buffer, name, value);
3880 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003881}
3882
Jonathan Peyton30419822017-05-12 18:01:32 +00003883// -----------------------------------------------------------------------------
Jonathan Peyton377aa402016-04-14 16:00:37 +00003884// KMP_SPIN_BACKOFF_PARAMS
Jonathan Peyton377aa402016-04-14 16:00:37 +00003885
Jonathan Peyton30419822017-05-12 18:01:32 +00003886// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
3887// for machine pause)
3888static void __kmp_stg_parse_spin_backoff_params(const char *name,
3889 const char *value, void *data) {
3890 const char *next = value;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003891
Jonathan Peyton30419822017-05-12 18:01:32 +00003892 int total = 0; // Count elements that were set. It'll be used as an array size
3893 int prev_comma = FALSE; // For correct processing sequential commas
3894 int i;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003895
Jonathan Peyton30419822017-05-12 18:01:32 +00003896 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
3897 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003898
Jonathan Peyton30419822017-05-12 18:01:32 +00003899 // Run only 3 iterations because it is enough to read two values or find a
3900 // syntax error
3901 for (i = 0; i < 3; i++) {
3902 SKIP_WS(next);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003903
Jonathan Peyton30419822017-05-12 18:01:32 +00003904 if (*next == '\0') {
3905 break;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003906 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003907 // Next character is not an integer or not a comma OR number of values > 2
3908 // => end of list
3909 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
3910 KMP_WARNING(EnvSyntaxError, name, value);
3911 return;
3912 }
3913 // The next character is ','
3914 if (*next == ',') {
3915 // ',' is the fisrt character
3916 if (total == 0 || prev_comma) {
3917 total++;
3918 }
3919 prev_comma = TRUE;
3920 next++; // skip ','
3921 SKIP_WS(next);
3922 }
3923 // Next character is a digit
3924 if (*next >= '0' && *next <= '9') {
3925 int num;
3926 const char *buf = next;
3927 char const *msg = NULL;
3928 prev_comma = FALSE;
3929 SKIP_DIGITS(next);
3930 total++;
3931
3932 const char *tmp = next;
3933 SKIP_WS(tmp);
3934 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
3935 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003936 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00003937 }
3938
3939 num = __kmp_str_to_int(buf, *next);
3940 if (num <= 0) { // The number of retries should be > 0
3941 msg = KMP_I18N_STR(ValueTooSmall);
3942 num = 1;
3943 } else if (num > KMP_INT_MAX) {
3944 msg = KMP_I18N_STR(ValueTooLarge);
3945 num = KMP_INT_MAX;
3946 }
3947 if (msg != NULL) {
3948 // Message is not empty. Print warning.
3949 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
3950 KMP_INFORM(Using_int_Value, name, num);
3951 }
3952 if (total == 1) {
3953 max_backoff = num;
3954 } else if (total == 2) {
3955 min_tick = num;
3956 }
Jonathan Peyton377aa402016-04-14 16:00:37 +00003957 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003958 }
3959 KMP_DEBUG_ASSERT(total > 0);
3960 if (total <= 0) {
3961 KMP_WARNING(EnvSyntaxError, name, value);
3962 return;
3963 }
3964 __kmp_spin_backoff_params.max_backoff = max_backoff;
3965 __kmp_spin_backoff_params.min_tick = min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003966}
3967
Jonathan Peyton30419822017-05-12 18:01:32 +00003968static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
3969 char const *name, void *data) {
3970 if (__kmp_env_format) {
3971 KMP_STR_BUF_PRINT_NAME_EX(name);
3972 } else {
3973 __kmp_str_buf_print(buffer, " %s='", name);
3974 }
3975 __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
3976 __kmp_spin_backoff_params.min_tick);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003977}
3978
Jim Cownie5e8470a2013-09-27 10:38:44 +00003979#if KMP_USE_ADAPTIVE_LOCKS
3980
Jonathan Peyton30419822017-05-12 18:01:32 +00003981// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003982// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003983
3984// Parse out values for the tunable parameters from a string of the form
3985// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
Jonathan Peyton30419822017-05-12 18:01:32 +00003986static void __kmp_stg_parse_adaptive_lock_props(const char *name,
3987 const char *value, void *data) {
3988 int max_retries = 0;
3989 int max_badness = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003990
Jonathan Peyton30419822017-05-12 18:01:32 +00003991 const char *next = value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003992
Jonathan Peyton30419822017-05-12 18:01:32 +00003993 int total = 0; // Count elements that were set. It'll be used as an array size
3994 int prev_comma = FALSE; // For correct processing sequential commas
3995 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003996
Jonathan Peyton30419822017-05-12 18:01:32 +00003997 // Save values in the structure __kmp_speculative_backoff_params
3998 // Run only 3 iterations because it is enough to read two values or find a
3999 // syntax error
4000 for (i = 0; i < 3; i++) {
4001 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004002
Jonathan Peyton30419822017-05-12 18:01:32 +00004003 if (*next == '\0') {
4004 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004005 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004006 // Next character is not an integer or not a comma OR number of values > 2
4007 // => end of list
4008 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
4009 KMP_WARNING(EnvSyntaxError, name, value);
4010 return;
4011 }
4012 // The next character is ','
4013 if (*next == ',') {
4014 // ',' is the fisrt character
4015 if (total == 0 || prev_comma) {
4016 total++;
4017 }
4018 prev_comma = TRUE;
4019 next++; // skip ','
4020 SKIP_WS(next);
4021 }
4022 // Next character is a digit
4023 if (*next >= '0' && *next <= '9') {
4024 int num;
4025 const char *buf = next;
4026 char const *msg = NULL;
4027 prev_comma = FALSE;
4028 SKIP_DIGITS(next);
4029 total++;
4030
4031 const char *tmp = next;
4032 SKIP_WS(tmp);
4033 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4034 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004035 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00004036 }
4037
4038 num = __kmp_str_to_int(buf, *next);
4039 if (num < 0) { // The number of retries should be >= 0
4040 msg = KMP_I18N_STR(ValueTooSmall);
4041 num = 1;
4042 } else if (num > KMP_INT_MAX) {
4043 msg = KMP_I18N_STR(ValueTooLarge);
4044 num = KMP_INT_MAX;
4045 }
4046 if (msg != NULL) {
4047 // Message is not empty. Print warning.
4048 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4049 KMP_INFORM(Using_int_Value, name, num);
4050 }
4051 if (total == 1) {
4052 max_retries = num;
4053 } else if (total == 2) {
4054 max_badness = num;
4055 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004056 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004057 }
4058 KMP_DEBUG_ASSERT(total > 0);
4059 if (total <= 0) {
4060 KMP_WARNING(EnvSyntaxError, name, value);
4061 return;
4062 }
4063 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4064 __kmp_adaptive_backoff_params.max_badness = max_badness;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004065}
4066
Jonathan Peyton30419822017-05-12 18:01:32 +00004067static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4068 char const *name, void *data) {
4069 if (__kmp_env_format) {
4070 KMP_STR_BUF_PRINT_NAME_EX(name);
4071 } else {
4072 __kmp_str_buf_print(buffer, " %s='", name);
4073 }
4074 __kmp_str_buf_print(buffer, "%d,%d'\n",
4075 __kmp_adaptive_backoff_params.max_soft_retries,
4076 __kmp_adaptive_backoff_params.max_badness);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004077} // __kmp_stg_print_adaptive_lock_props
4078
4079#if KMP_DEBUG_ADAPTIVE_LOCKS
4080
Jonathan Peyton30419822017-05-12 18:01:32 +00004081static void __kmp_stg_parse_speculative_statsfile(char const *name,
4082 char const *value,
4083 void *data) {
4084 __kmp_stg_parse_file(name, value, "", &__kmp_speculative_statsfile);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004085} // __kmp_stg_parse_speculative_statsfile
4086
Jonathan Peyton30419822017-05-12 18:01:32 +00004087static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
4088 char const *name,
4089 void *data) {
4090 if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
4091 __kmp_stg_print_str(buffer, name, "stdout");
4092 } else {
4093 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
4094 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004095
4096} // __kmp_stg_print_speculative_statsfile
4097
4098#endif // KMP_DEBUG_ADAPTIVE_LOCKS
4099
4100#endif // KMP_USE_ADAPTIVE_LOCKS
4101
Jonathan Peyton30419822017-05-12 18:01:32 +00004102// -----------------------------------------------------------------------------
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004103// KMP_HW_SUBSET (was KMP_PLACE_THREADS)
Jim Cownie5e8470a2013-09-27 10:38:44 +00004104
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004105// The longest observable sequense of items is
4106// Socket-Node-Tile-Core-Thread
4107// So, let's limit to 5 levels for now
4108// The input string is usually short enough, let's use 512 limit for now
4109#define MAX_T_LEVEL 5
4110#define MAX_STR_LEN 512
Jonathan Peyton30419822017-05-12 18:01:32 +00004111static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
4112 void *data) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004113 // Value example: 1s,5c@3,2T
4114 // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
Jonathan Peyton3f850bf2017-10-06 19:23:19 +00004115 kmp_setting_t **rivals = (kmp_setting_t **)data;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004116 if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
4117 KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004118 }
Jonathan Peyton3f850bf2017-10-06 19:23:19 +00004119 if (__kmp_stg_check_rivals(name, value, rivals)) {
4120 return;
4121 }
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004122
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004123 char *components[MAX_T_LEVEL];
4124 char const *digits = "0123456789";
4125 char input[MAX_STR_LEN];
4126 size_t len = 0, mlen = MAX_STR_LEN;
4127 int level = 0;
4128 // Canonize the string (remove spaces, unify delimiters, etc.)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004129 char *pos = CCAST(char *, value);
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004130 while (*pos && mlen) {
4131 if (*pos != ' ') { // skip spaces
4132 if (len == 0 && *pos == ':') {
4133 __kmp_hws_abs_flag = 1; // if the first symbol is ":", skip it
4134 } else {
4135 input[len] = toupper(*pos);
4136 if (input[len] == 'X')
4137 input[len] = ','; // unify delimiters of levels
4138 if (input[len] == 'O' && strchr(digits, *(pos + 1)))
4139 input[len] = '@'; // unify delimiters of offset
4140 len++;
4141 }
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004142 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004143 mlen--;
4144 pos++;
4145 }
4146 if (len == 0 || mlen == 0)
4147 goto err; // contents is either empty or too long
4148 input[len] = '\0';
4149 __kmp_hws_requested = 1; // mark that subset requested
4150 // Split by delimiter
4151 pos = input;
4152 components[level++] = pos;
George Rokos4800fc42017-04-25 15:55:39 +00004153 while ((pos = strchr(pos, ','))) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004154 *pos = '\0'; // modify input and avoid more copying
4155 components[level++] = ++pos; // expect something after ","
4156 if (level > MAX_T_LEVEL)
4157 goto err; // too many components provided
4158 }
4159 // Check each component
4160 for (int i = 0; i < level; ++i) {
4161 int offset = 0;
4162 int num = atoi(components[i]); // each component should start with a number
4163 if ((pos = strchr(components[i], '@'))) {
4164 offset = atoi(pos + 1); // save offset
4165 *pos = '\0'; // cut the offset from the component
4166 }
4167 pos = components[i] + strspn(components[i], digits);
4168 if (pos == components[i])
4169 goto err;
4170 // detect the component type
4171 switch (*pos) {
4172 case 'S': // Socket
4173 if (__kmp_hws_socket.num > 0)
4174 goto err; // duplicate is not allowed
4175 __kmp_hws_socket.num = num;
4176 __kmp_hws_socket.offset = offset;
4177 break;
4178 case 'N': // NUMA Node
4179 if (__kmp_hws_node.num > 0)
4180 goto err; // duplicate is not allowed
4181 __kmp_hws_node.num = num;
4182 __kmp_hws_node.offset = offset;
4183 break;
4184 case 'L': // Cache
4185 if (*(pos + 1) == '2') { // L2 - Tile
4186 if (__kmp_hws_tile.num > 0)
4187 goto err; // duplicate is not allowed
4188 __kmp_hws_tile.num = num;
4189 __kmp_hws_tile.offset = offset;
4190 } else if (*(pos + 1) == '3') { // L3 - Socket
4191 if (__kmp_hws_socket.num > 0)
4192 goto err; // duplicate is not allowed
4193 __kmp_hws_socket.num = num;
4194 __kmp_hws_socket.offset = offset;
4195 } else if (*(pos + 1) == '1') { // L1 - Core
4196 if (__kmp_hws_core.num > 0)
4197 goto err; // duplicate is not allowed
4198 __kmp_hws_core.num = num;
4199 __kmp_hws_core.offset = offset;
4200 }
4201 break;
4202 case 'C': // Core (or Cache?)
4203 if (*(pos + 1) != 'A') {
4204 if (__kmp_hws_core.num > 0)
4205 goto err; // duplicate is not allowed
4206 __kmp_hws_core.num = num;
4207 __kmp_hws_core.offset = offset;
4208 } else { // Cache
4209 char *d = pos + strcspn(pos, digits); // find digit
4210 if (*d == '2') { // L2 - Tile
4211 if (__kmp_hws_tile.num > 0)
4212 goto err; // duplicate is not allowed
4213 __kmp_hws_tile.num = num;
4214 __kmp_hws_tile.offset = offset;
4215 } else if (*d == '3') { // L3 - Socket
4216 if (__kmp_hws_socket.num > 0)
4217 goto err; // duplicate is not allowed
4218 __kmp_hws_socket.num = num;
4219 __kmp_hws_socket.offset = offset;
4220 } else if (*d == '1') { // L1 - Core
4221 if (__kmp_hws_core.num > 0)
4222 goto err; // duplicate is not allowed
4223 __kmp_hws_core.num = num;
4224 __kmp_hws_core.offset = offset;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004225 } else {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004226 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004227 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004228 }
4229 break;
4230 case 'T': // Thread
4231 if (__kmp_hws_proc.num > 0)
4232 goto err; // duplicate is not allowed
4233 __kmp_hws_proc.num = num;
4234 __kmp_hws_proc.offset = offset;
4235 break;
4236 default:
4237 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004238 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004239 }
4240 return;
4241err:
4242 KMP_WARNING(AffHWSubsetInvalid, name, value);
4243 __kmp_hws_requested = 0; // mark that subset not requested
4244 return;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004245}
4246
Jonathan Peyton30419822017-05-12 18:01:32 +00004247static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004248 void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +00004249 if (__kmp_hws_requested) {
4250 int comma = 0;
4251 kmp_str_buf_t buf;
4252 __kmp_str_buf_init(&buf);
4253 if (__kmp_env_format)
4254 KMP_STR_BUF_PRINT_NAME_EX(name);
4255 else
4256 __kmp_str_buf_print(buffer, " %s='", name);
4257 if (__kmp_hws_socket.num) {
4258 __kmp_str_buf_print(&buf, "%ds", __kmp_hws_socket.num);
4259 if (__kmp_hws_socket.offset)
4260 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_socket.offset);
4261 comma = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004262 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004263 if (__kmp_hws_node.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004264 __kmp_str_buf_print(&buf, "%s%dn", comma ? "," : "", __kmp_hws_node.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004265 if (__kmp_hws_node.offset)
4266 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_node.offset);
4267 comma = 1;
4268 }
4269 if (__kmp_hws_tile.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004270 __kmp_str_buf_print(&buf, "%s%dL2", comma ? "," : "", __kmp_hws_tile.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004271 if (__kmp_hws_tile.offset)
4272 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_tile.offset);
4273 comma = 1;
4274 }
4275 if (__kmp_hws_core.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004276 __kmp_str_buf_print(&buf, "%s%dc", comma ? "," : "", __kmp_hws_core.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004277 if (__kmp_hws_core.offset)
4278 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_core.offset);
4279 comma = 1;
4280 }
4281 if (__kmp_hws_proc.num)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004282 __kmp_str_buf_print(&buf, "%s%dt", comma ? "," : "", __kmp_hws_proc.num);
4283 __kmp_str_buf_print(buffer, "%s'\n", buf.str);
Jonathan Peyton30419822017-05-12 18:01:32 +00004284 __kmp_str_buf_free(&buf);
4285 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004286}
Jim Cownie5e8470a2013-09-27 10:38:44 +00004287
4288#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004289// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004290// KMP_FORKJOIN_FRAMES
Jim Cownie5e8470a2013-09-27 10:38:44 +00004291
Jonathan Peyton30419822017-05-12 18:01:32 +00004292static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
4293 void *data) {
4294 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004295} // __kmp_stg_parse_forkjoin_frames
4296
Jonathan Peyton30419822017-05-12 18:01:32 +00004297static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
4298 char const *name, void *data) {
4299 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004300} // __kmp_stg_print_forkjoin_frames
4301
Jonathan Peyton30419822017-05-12 18:01:32 +00004302// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004303// KMP_FORKJOIN_FRAMES_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00004304
Jonathan Peyton30419822017-05-12 18:01:32 +00004305static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
4306 char const *value,
4307 void *data) {
4308 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004309} // __kmp_stg_parse_forkjoin_frames
4310
Jonathan Peyton30419822017-05-12 18:01:32 +00004311static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
4312 char const *name, void *data) {
4313 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004314} // __kmp_stg_print_forkjoin_frames
4315#endif /* USE_ITT_BUILD */
4316
Jonathan Peyton30419822017-05-12 18:01:32 +00004317// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004318// OMP_DISPLAY_ENV
Jim Cownie5e8470a2013-09-27 10:38:44 +00004319
4320#if OMP_40_ENABLED
4321
Jonathan Peyton30419822017-05-12 18:01:32 +00004322static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
4323 void *data) {
4324 if (__kmp_str_match("VERBOSE", 1, value)) {
4325 __kmp_display_env_verbose = TRUE;
4326 } else {
4327 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
4328 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004329
4330} // __kmp_stg_parse_omp_display_env
4331
Jonathan Peyton30419822017-05-12 18:01:32 +00004332static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
4333 char const *name, void *data) {
4334 if (__kmp_display_env_verbose) {
4335 __kmp_stg_print_str(buffer, name, "VERBOSE");
4336 } else {
4337 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
4338 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004339} // __kmp_stg_print_omp_display_env
4340
Jonathan Peyton30419822017-05-12 18:01:32 +00004341static void __kmp_stg_parse_omp_cancellation(char const *name,
4342 char const *value, void *data) {
4343 if (TCR_4(__kmp_init_parallel)) {
4344 KMP_WARNING(EnvParallelWarn, name);
4345 return;
4346 } // read value before first parallel only
4347 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004348} // __kmp_stg_parse_omp_cancellation
4349
Jonathan Peyton30419822017-05-12 18:01:32 +00004350static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
4351 char const *name, void *data) {
4352 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004353} // __kmp_stg_print_omp_cancellation
4354
Jim Cownie5e8470a2013-09-27 10:38:44 +00004355#endif
4356
Jonathan Peyton30419822017-05-12 18:01:32 +00004357// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004358// Table.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004359
4360static kmp_setting_t __kmp_stg_table[] = {
4361
Jonathan Peyton09244f32017-07-26 20:07:58 +00004362 {"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
Jonathan Peyton30419822017-05-12 18:01:32 +00004363 {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
4364 NULL, 0, 0},
4365 {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
4366 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
4367 {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
4368 NULL, 0, 0},
Jonathan Peyton09244f32017-07-26 20:07:58 +00004369 {"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
4370 __kmp_stg_print_device_thread_limit, NULL, 0, 0},
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004371#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +00004372 {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
4373 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004374#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004375 {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
4376 0, 0},
4377 {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
4378 __kmp_stg_print_stackoffset, NULL, 0, 0},
4379 {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4380 NULL, 0, 0},
4381 {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
4382 0, 0},
4383 {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
4384 0},
4385 {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
4386 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004387
Jonathan Peyton30419822017-05-12 18:01:32 +00004388 {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
4389 {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
4390 __kmp_stg_print_num_threads, NULL, 0, 0},
4391 {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4392 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004393
Jonathan Peyton30419822017-05-12 18:01:32 +00004394 {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
4395 0},
4396 {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
4397 __kmp_stg_print_task_stealing, NULL, 0, 0},
4398 {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
4399 __kmp_stg_print_max_active_levels, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004400#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004401 {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
4402 __kmp_stg_print_default_device, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004403#endif
Jonathan Peytondf6818b2016-06-14 17:57:47 +00004404#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004405 {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
4406 __kmp_stg_print_max_task_priority, NULL, 0, 0},
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00004407 {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
4408 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
Jonathan Peyton28510722016-02-25 18:04:09 +00004409#endif
Jonathan Peytonf4392462017-07-27 20:58:41 +00004410 {"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
4411 __kmp_stg_print_thread_limit, NULL, 0, 0},
Jonathan Peyton4f90c822017-08-02 20:04:45 +00004412 {"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
4413 __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
Jonathan Peyton30419822017-05-12 18:01:32 +00004414 {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
4415 __kmp_stg_print_wait_policy, NULL, 0, 0},
4416 {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
4417 __kmp_stg_print_disp_buffers, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004418#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00004419 {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
4420 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
4421 {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
4422 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004423#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00004424
4425#if KMP_HANDLE_SIGNALS
Jonathan Peyton30419822017-05-12 18:01:32 +00004426 {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
4427 __kmp_stg_print_handle_signals, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004428#endif
4429
4430#if KMP_ARCH_X86 || KMP_ARCH_X86_64
Jonathan Peyton30419822017-05-12 18:01:32 +00004431 {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
4432 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004433#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
4434
4435#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004436 {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004437#endif
4438
4439#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00004440 {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
4441 0},
4442 {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
4443 0},
4444 {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
4445 0},
4446 {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
4447 0},
4448 {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
4449 0},
4450 {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
4451 0},
4452 {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
4453 {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
4454 NULL, 0, 0},
4455 {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
4456 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
4457 {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
4458 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
4459 {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
4460 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
4461 {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004462
Jonathan Peyton30419822017-05-12 18:01:32 +00004463 {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
4464 __kmp_stg_print_par_range_env, NULL, 0, 0},
4465 {"KMP_YIELD_CYCLE", __kmp_stg_parse_yield_cycle,
4466 __kmp_stg_print_yield_cycle, NULL, 0, 0},
4467 {"KMP_YIELD_ON", __kmp_stg_parse_yield_on, __kmp_stg_print_yield_on, NULL,
4468 0, 0},
4469 {"KMP_YIELD_OFF", __kmp_stg_parse_yield_off, __kmp_stg_print_yield_off,
4470 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004471#endif // KMP_DEBUG
4472
Jonathan Peyton30419822017-05-12 18:01:32 +00004473 {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
4474 __kmp_stg_print_align_alloc, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004475
Jonathan Peyton30419822017-05-12 18:01:32 +00004476 {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4477 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4478 {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4479 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
4480 {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4481 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4482 {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4483 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004484#if KMP_FAST_REDUCTION_BARRIER
Jonathan Peyton30419822017-05-12 18:01:32 +00004485 {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4486 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4487 {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4488 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004489#endif
4490
Jonathan Peyton30419822017-05-12 18:01:32 +00004491 {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
4492 __kmp_stg_print_abort_delay, NULL, 0, 0},
4493 {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
4494 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
4495 {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
4496 __kmp_stg_print_force_reduction, NULL, 0, 0},
4497 {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
4498 __kmp_stg_print_force_reduction, NULL, 0, 0},
4499 {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
4500 __kmp_stg_print_storage_map, NULL, 0, 0},
4501 {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
4502 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
4503 {"KMP_FOREIGN_THREADS_THREADPRIVATE",
4504 __kmp_stg_parse_foreign_threads_threadprivate,
4505 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004506
Alp Toker98758b02014-03-02 04:12:06 +00004507#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004508 {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
4509 0, 0},
4510#ifdef KMP_GOMP_COMPAT
4511 {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
4512 /* no print */ NULL, 0, 0},
4513#endif /* KMP_GOMP_COMPAT */
4514#if OMP_40_ENABLED
4515 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4516 NULL, 0, 0},
4517 {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
4518#else
4519 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, NULL, /* no print */ NULL, 0,
4520 0},
4521#endif /* OMP_40_ENABLED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00004522
Jonathan Peyton30419822017-05-12 18:01:32 +00004523 {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
4524 __kmp_stg_print_topology_method, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004525
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004526#else
Jim Cownie5e8470a2013-09-27 10:38:44 +00004527
Jonathan Peyton30419822017-05-12 18:01:32 +00004528// KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
4529// OMP_PROC_BIND and proc-bind-var are supported, however.
4530#if OMP_40_ENABLED
4531 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4532 NULL, 0, 0},
4533#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004534
Alp Toker98758b02014-03-02 04:12:06 +00004535#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004536
Jonathan Peyton30419822017-05-12 18:01:32 +00004537 {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
4538 __kmp_stg_print_init_at_fork, NULL, 0, 0},
4539 {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
4540 0, 0},
4541 {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
4542 NULL, 0, 0},
4543 {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
4544 __kmp_stg_print_atomic_mode, NULL, 0, 0},
4545 {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
4546 __kmp_stg_print_consistency_check, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004547
4548#if USE_ITT_BUILD && USE_ITT_NOTIFY
Jonathan Peyton30419822017-05-12 18:01:32 +00004549 {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
4550 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004551#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
Jonathan Peyton30419822017-05-12 18:01:32 +00004552 {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
4553 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
4554 {"KMP_INIT_WAIT", __kmp_stg_parse_init_wait, __kmp_stg_print_init_wait,
4555 NULL, 0, 0},
4556 {"KMP_NEXT_WAIT", __kmp_stg_parse_next_wait, __kmp_stg_print_next_wait,
4557 NULL, 0, 0},
4558 {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
4559 NULL, 0, 0},
4560 {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
4561 NULL, 0, 0},
4562 {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
4563 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004564
4565#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00004566 {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
4567 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004568#endif
4569
Jonathan Peyton30419822017-05-12 18:01:32 +00004570 {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
4571 __kmp_stg_print_lock_block, NULL, 0, 0},
4572 {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
4573 NULL, 0, 0},
4574 {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
4575 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004576#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004577 {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
4578 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004579#if KMP_DEBUG_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004580 {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
4581 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004582#endif
4583#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004584 {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4585 NULL, 0, 0},
4586 {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4587 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004588#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004589 {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
4590 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
4591 {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
4592 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004593#endif
4594
Jonathan Peyton30419822017-05-12 18:01:32 +00004595#if OMP_40_ENABLED
4596 {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
4597 __kmp_stg_print_omp_display_env, NULL, 0, 0},
4598 {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
4599 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004600#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004601 {"", NULL, NULL, NULL, 0, 0}}; // settings
Jim Cownie5e8470a2013-09-27 10:38:44 +00004602
Jonathan Peyton30419822017-05-12 18:01:32 +00004603static int const __kmp_stg_count =
4604 sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004605
Jonathan Peyton30419822017-05-12 18:01:32 +00004606static inline kmp_setting_t *__kmp_stg_find(char const *name) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004607
Jonathan Peyton30419822017-05-12 18:01:32 +00004608 int i;
4609 if (name != NULL) {
4610 for (i = 0; i < __kmp_stg_count; ++i) {
4611 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
4612 return &__kmp_stg_table[i];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004613 }
4614 }
4615 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004616 return NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004617
4618} // __kmp_stg_find
4619
Jonathan Peyton30419822017-05-12 18:01:32 +00004620static int __kmp_stg_cmp(void const *_a, void const *_b) {
Andrey Churbanov5ba90c72017-07-17 09:03:14 +00004621 const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
4622 const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004623
Jonathan Peyton30419822017-05-12 18:01:32 +00004624 // Process KMP_AFFINITY last.
4625 // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
4626 if (strcmp(a->name, "KMP_AFFINITY") == 0) {
4627 if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4628 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004629 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004630 return 1;
4631 } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4632 return -1;
4633 }
4634 return strcmp(a->name, b->name);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004635} // __kmp_stg_cmp
4636
Jonathan Peyton30419822017-05-12 18:01:32 +00004637static void __kmp_stg_init(void) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004638
Jonathan Peyton30419822017-05-12 18:01:32 +00004639 static int initialized = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004640
Jonathan Peyton30419822017-05-12 18:01:32 +00004641 if (!initialized) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004642
Jonathan Peyton30419822017-05-12 18:01:32 +00004643 // Sort table.
4644 qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
4645 __kmp_stg_cmp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004646
Jonathan Peyton30419822017-05-12 18:01:32 +00004647 { // Initialize *_STACKSIZE data.
4648 kmp_setting_t *kmp_stacksize =
4649 __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004650#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004651 kmp_setting_t *gomp_stacksize =
4652 __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004653#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004654 kmp_setting_t *omp_stacksize =
4655 __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004656
Jonathan Peyton30419822017-05-12 18:01:32 +00004657 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4658 // !!! Compiler does not understand rivals is used and optimizes out
4659 // assignments
4660 // !!! rivals[ i ++ ] = ...;
4661 static kmp_setting_t *volatile rivals[4];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004662 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004663#ifdef KMP_GOMP_COMPAT
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004664 static kmp_stg_ss_data_t gomp_data = {1024,
4665 CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004666#endif
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004667 static kmp_stg_ss_data_t omp_data = {1024,
4668 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004669 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004670
Jonathan Peyton30419822017-05-12 18:01:32 +00004671 rivals[i++] = kmp_stacksize;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004672#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004673 if (gomp_stacksize != NULL) {
4674 rivals[i++] = gomp_stacksize;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004675 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004676#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004677 rivals[i++] = omp_stacksize;
4678 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004679
Jonathan Peyton30419822017-05-12 18:01:32 +00004680 kmp_stacksize->data = &kmp_data;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004681#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004682 if (gomp_stacksize != NULL) {
4683 gomp_stacksize->data = &gomp_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004684 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004685#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004686 omp_stacksize->data = &omp_data;
4687 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004688
Jonathan Peyton30419822017-05-12 18:01:32 +00004689 { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
4690 kmp_setting_t *kmp_library =
4691 __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
4692 kmp_setting_t *omp_wait_policy =
4693 __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004694
Jonathan Peyton30419822017-05-12 18:01:32 +00004695 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4696 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004697 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
4698 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004699 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004700
Jonathan Peyton30419822017-05-12 18:01:32 +00004701 rivals[i++] = kmp_library;
4702 if (omp_wait_policy != NULL) {
4703 rivals[i++] = omp_wait_policy;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004704 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004705 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004706
Jonathan Peyton30419822017-05-12 18:01:32 +00004707 kmp_library->data = &kmp_data;
4708 if (omp_wait_policy != NULL) {
4709 omp_wait_policy->data = &omp_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004710 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004711 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004712
Jonathan Peytonf4392462017-07-27 20:58:41 +00004713 { // Initialize KMP_DEVICE_THREAD_LIMIT and KMP_ALL_THREADS
Jonathan Peyton09244f32017-07-26 20:07:58 +00004714 kmp_setting_t *kmp_device_thread_limit =
4715 __kmp_stg_find("KMP_DEVICE_THREAD_LIMIT"); // 1st priority.
Jonathan Peyton30419822017-05-12 18:01:32 +00004716 kmp_setting_t *kmp_all_threads =
Jonathan Peyton09244f32017-07-26 20:07:58 +00004717 __kmp_stg_find("KMP_ALL_THREADS"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004718
Jonathan Peyton30419822017-05-12 18:01:32 +00004719 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
Jonathan Peytonf4392462017-07-27 20:58:41 +00004720 static kmp_setting_t *volatile rivals[3];
Jonathan Peyton30419822017-05-12 18:01:32 +00004721 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004722
Jonathan Peyton09244f32017-07-26 20:07:58 +00004723 rivals[i++] = kmp_device_thread_limit;
Jonathan Peyton30419822017-05-12 18:01:32 +00004724 rivals[i++] = kmp_all_threads;
Jonathan Peyton30419822017-05-12 18:01:32 +00004725 rivals[i++] = NULL;
Jonathan Peyton09244f32017-07-26 20:07:58 +00004726
4727 kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004728 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004729 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004730
Jonathan Peyton3f850bf2017-10-06 19:23:19 +00004731 { // Initialize KMP_HW_SUBSET and KMP_PLACE_THREADS
4732 // 1st priority
4733 kmp_setting_t *kmp_hw_subset = __kmp_stg_find("KMP_HW_SUBSET");
4734 // 2nd priority
4735 kmp_setting_t *kmp_place_threads = __kmp_stg_find("KMP_PLACE_THREADS");
4736
4737 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4738 static kmp_setting_t *volatile rivals[3];
4739 int i = 0;
4740
4741 rivals[i++] = kmp_hw_subset;
4742 rivals[i++] = kmp_place_threads;
4743 rivals[i++] = NULL;
4744
4745 kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
4746 kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
4747 }
4748
Alp Toker98758b02014-03-02 04:12:06 +00004749#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004750 { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
4751 kmp_setting_t *kmp_affinity =
4752 __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
4753 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004754
Jonathan Peyton30419822017-05-12 18:01:32 +00004755#ifdef KMP_GOMP_COMPAT
4756 kmp_setting_t *gomp_cpu_affinity =
4757 __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
4758 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
4759#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004760
Jonathan Peyton30419822017-05-12 18:01:32 +00004761 kmp_setting_t *omp_proc_bind =
4762 __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
4763 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004764
Jonathan Peyton30419822017-05-12 18:01:32 +00004765 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4766 static kmp_setting_t *volatile rivals[4];
4767 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004768
Jonathan Peyton30419822017-05-12 18:01:32 +00004769 rivals[i++] = kmp_affinity;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004770
Jonathan Peyton30419822017-05-12 18:01:32 +00004771#ifdef KMP_GOMP_COMPAT
4772 rivals[i++] = gomp_cpu_affinity;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004773 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004774#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004775
Jonathan Peyton30419822017-05-12 18:01:32 +00004776 rivals[i++] = omp_proc_bind;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004777 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004778 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004779
Jonathan Peyton30419822017-05-12 18:01:32 +00004780#if OMP_40_ENABLED
4781 static kmp_setting_t *volatile places_rivals[4];
4782 i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004783
Jonathan Peyton30419822017-05-12 18:01:32 +00004784 kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
4785 KMP_DEBUG_ASSERT(omp_places != NULL);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004786
Jonathan Peyton30419822017-05-12 18:01:32 +00004787 places_rivals[i++] = kmp_affinity;
4788#ifdef KMP_GOMP_COMPAT
4789 places_rivals[i++] = gomp_cpu_affinity;
4790#endif
4791 places_rivals[i++] = omp_places;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004792 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004793 places_rivals[i++] = NULL;
4794#endif
4795 }
Alp Toker98758b02014-03-02 04:12:06 +00004796#else
Jonathan Peyton30419822017-05-12 18:01:32 +00004797// KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
4798// OMP_PLACES not supported yet.
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004799#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004800
Jonathan Peyton30419822017-05-12 18:01:32 +00004801 { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
4802 kmp_setting_t *kmp_force_red =
4803 __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
4804 kmp_setting_t *kmp_determ_red =
4805 __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004806
Jonathan Peyton30419822017-05-12 18:01:32 +00004807 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4808 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004809 static kmp_stg_fr_data_t force_data = {1,
4810 CCAST(kmp_setting_t **, rivals)};
4811 static kmp_stg_fr_data_t determ_data = {0,
4812 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004813 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004814
Jonathan Peyton30419822017-05-12 18:01:32 +00004815 rivals[i++] = kmp_force_red;
4816 if (kmp_determ_red != NULL) {
4817 rivals[i++] = kmp_determ_red;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004818 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004819 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004820
Jonathan Peyton30419822017-05-12 18:01:32 +00004821 kmp_force_red->data = &force_data;
4822 if (kmp_determ_red != NULL) {
4823 kmp_determ_red->data = &determ_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004824 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004825 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004826
Jonathan Peyton30419822017-05-12 18:01:32 +00004827 initialized = 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004828 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004829
Jonathan Peyton30419822017-05-12 18:01:32 +00004830 // Reset flags.
4831 int i;
4832 for (i = 0; i < __kmp_stg_count; ++i) {
4833 __kmp_stg_table[i].set = 0;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004834 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004835
4836} // __kmp_stg_init
4837
Jonathan Peyton30419822017-05-12 18:01:32 +00004838static void __kmp_stg_parse(char const *name, char const *value) {
4839 // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
4840 // really nameless, they are presented in environment block as
4841 // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
4842 if (name[0] == 0) {
4843 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004844 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004845
Jonathan Peyton30419822017-05-12 18:01:32 +00004846 if (value != NULL) {
4847 kmp_setting_t *setting = __kmp_stg_find(name);
4848 if (setting != NULL) {
4849 setting->parse(name, value, setting->data);
4850 setting->defined = 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004851 }
4852 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004853
4854} // __kmp_stg_parse
4855
Jonathan Peyton30419822017-05-12 18:01:32 +00004856static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
4857 char const *name, // Name of variable.
4858 char const *value, // Value of the variable.
4859 kmp_setting_t **rivals // List of rival settings (must include current one).
4860 ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004861
Jonathan Peyton30419822017-05-12 18:01:32 +00004862 if (rivals == NULL) {
4863 return 0;
4864 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004865
Jonathan Peyton30419822017-05-12 18:01:32 +00004866 // Loop thru higher priority settings (listed before current).
4867 int i = 0;
4868 for (; strcmp(rivals[i]->name, name) != 0; i++) {
4869 KMP_DEBUG_ASSERT(rivals[i] != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004870
Alp Toker763b9392014-02-28 09:42:41 +00004871#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004872 if (rivals[i] == __kmp_affinity_notype) {
4873 // If KMP_AFFINITY is specified without a type name,
4874 // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
4875 continue;
4876 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004877#endif
4878
Jonathan Peyton30419822017-05-12 18:01:32 +00004879 if (rivals[i]->set) {
4880 KMP_WARNING(StgIgnored, name, rivals[i]->name);
4881 return 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004882 }
4883 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004884
Jonathan Peyton30419822017-05-12 18:01:32 +00004885 ++i; // Skip current setting.
4886 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004887
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004888} // __kmp_stg_check_rivals
Jim Cownie5e8470a2013-09-27 10:38:44 +00004889
Jonathan Peyton30419822017-05-12 18:01:32 +00004890static int __kmp_env_toPrint(char const *name, int flag) {
4891 int rc = 0;
4892 kmp_setting_t *setting = __kmp_stg_find(name);
4893 if (setting != NULL) {
4894 rc = setting->defined;
4895 if (flag >= 0) {
4896 setting->defined = flag;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004897 }
4898 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004899 return rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004900}
4901
Jonathan Peyton30419822017-05-12 18:01:32 +00004902static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004903
Jonathan Peyton30419822017-05-12 18:01:32 +00004904 char const *value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004905
Jonathan Peyton30419822017-05-12 18:01:32 +00004906 /* OMP_NUM_THREADS */
4907 value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
4908 if (value) {
4909 ompc_set_num_threads(__kmp_dflt_team_nth);
4910 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004911
Jonathan Peyton30419822017-05-12 18:01:32 +00004912 /* KMP_BLOCKTIME */
4913 value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
4914 if (value) {
4915 kmpc_set_blocktime(__kmp_dflt_blocktime);
4916 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004917
Jonathan Peyton30419822017-05-12 18:01:32 +00004918 /* OMP_NESTED */
4919 value = __kmp_env_blk_var(block, "OMP_NESTED");
4920 if (value) {
4921 ompc_set_nested(__kmp_dflt_nested);
4922 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004923
Jonathan Peyton30419822017-05-12 18:01:32 +00004924 /* OMP_DYNAMIC */
4925 value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
4926 if (value) {
4927 ompc_set_dynamic(__kmp_global.g.g_dynamic);
4928 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004929}
4930
Jonathan Peyton30419822017-05-12 18:01:32 +00004931void __kmp_env_initialize(char const *string) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004932
Jonathan Peyton30419822017-05-12 18:01:32 +00004933 kmp_env_blk_t block;
4934 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004935
Jonathan Peyton30419822017-05-12 18:01:32 +00004936 __kmp_stg_init();
Jim Cownie5e8470a2013-09-27 10:38:44 +00004937
Jonathan Peyton30419822017-05-12 18:01:32 +00004938 // Hack!!!
4939 if (string == NULL) {
4940 // __kmp_max_nth = __kmp_sys_max_nth;
4941 __kmp_threads_capacity =
4942 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004943 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004944 __kmp_env_blk_init(&block, string);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004945
Jonathan Peyton30419822017-05-12 18:01:32 +00004946 // update the set flag on all entries that have an env var
4947 for (i = 0; i < block.count; ++i) {
4948 if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
4949 continue;
4950 }
4951 if (block.vars[i].value == NULL) {
4952 continue;
4953 }
4954 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
4955 if (setting != NULL) {
4956 setting->set = 1;
4957 }
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004958 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004959
Jonathan Peyton94a114f2017-10-20 19:30:57 +00004960 // We need to know if blocktime was set when processing OMP_WAIT_POLICY
Jonathan Peyton30419822017-05-12 18:01:32 +00004961 blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
Jonathan Peyton50e8f182016-04-04 19:38:32 +00004962
Jonathan Peyton30419822017-05-12 18:01:32 +00004963 // Special case. If we parse environment, not a string, process KMP_WARNINGS
4964 // first.
4965 if (string == NULL) {
4966 char const *name = "KMP_WARNINGS";
4967 char const *value = __kmp_env_blk_var(&block, name);
4968 __kmp_stg_parse(name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004969 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004970
Alp Toker763b9392014-02-28 09:42:41 +00004971#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004972 // Special case. KMP_AFFINITY is not a rival to other affinity env vars
4973 // if no affinity type is specified. We want to allow
4974 // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
4975 // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
4976 // affinity mechanism.
4977 __kmp_affinity_notype = NULL;
4978 char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
4979 if (aff_str != NULL) {
4980// Check if the KMP_AFFINITY type is specified in the string.
4981// We just search the string for "compact", "scatter", etc.
4982// without really parsing the string. The syntax of the
4983// KMP_AFFINITY env var is such that none of the affinity
4984// type names can appear anywhere other that the type
4985// specifier, even as substrings.
4986//
4987// I can't find a case-insensitive version of strstr on Windows* OS.
4988// Use the case-sensitive version for now.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004989
Jonathan Peyton30419822017-05-12 18:01:32 +00004990#if KMP_OS_WINDOWS
4991#define FIND strstr
4992#else
4993#define FIND strcasestr
4994#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004995
Jonathan Peyton30419822017-05-12 18:01:32 +00004996 if ((FIND(aff_str, "none") == NULL) &&
4997 (FIND(aff_str, "physical") == NULL) &&
4998 (FIND(aff_str, "logical") == NULL) &&
4999 (FIND(aff_str, "compact") == NULL) &&
5000 (FIND(aff_str, "scatter") == NULL) &&
5001 (FIND(aff_str, "explicit") == NULL) &&
5002 (FIND(aff_str, "balanced") == NULL) &&
5003 (FIND(aff_str, "disabled") == NULL)) {
5004 __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
5005 } else {
5006 // A new affinity type is specified.
5007 // Reset the affinity flags to their default values,
5008 // in case this is called from kmp_set_defaults().
5009 __kmp_affinity_type = affinity_default;
5010 __kmp_affinity_gran = affinity_gran_default;
5011 __kmp_affinity_top_method = affinity_top_method_default;
5012 __kmp_affinity_respect_mask = affinity_respect_mask_default;
5013 }
5014#undef FIND
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005015
5016#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005017 // Also reset the affinity flags if OMP_PROC_BIND is specified.
5018 aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
5019 if (aff_str != NULL) {
5020 __kmp_affinity_type = affinity_default;
5021 __kmp_affinity_gran = affinity_gran_default;
5022 __kmp_affinity_top_method = affinity_top_method_default;
5023 __kmp_affinity_respect_mask = affinity_respect_mask_default;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005024 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005025#endif /* OMP_40_ENABLED */
5026 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005027
Alp Toker763b9392014-02-28 09:42:41 +00005028#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005029
5030#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005031 // Set up the nested proc bind type vector.
5032 if (__kmp_nested_proc_bind.bind_types == NULL) {
5033 __kmp_nested_proc_bind.bind_types =
5034 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
5035 if (__kmp_nested_proc_bind.bind_types == NULL) {
5036 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005037 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005038 __kmp_nested_proc_bind.size = 1;
5039 __kmp_nested_proc_bind.used = 1;
5040#if KMP_AFFINITY_SUPPORTED
5041 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
5042#else
5043 // default proc bind is false if affinity not supported
5044 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5045#endif
5046 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005047#endif /* OMP_40_ENABLED */
5048
Jonathan Peyton30419822017-05-12 18:01:32 +00005049 // Now process all of the settings.
5050 for (i = 0; i < block.count; ++i) {
5051 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005052 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005053
Jonathan Peyton30419822017-05-12 18:01:32 +00005054 // If user locks have been allocated yet, don't reset the lock vptr table.
5055 if (!__kmp_init_user_locks) {
5056 if (__kmp_user_lock_kind == lk_default) {
5057 __kmp_user_lock_kind = lk_queuing;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005058 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005059#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00005060 __kmp_init_dynamic_user_locks();
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005061#else
Jonathan Peyton30419822017-05-12 18:01:32 +00005062 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005063#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005064 } else {
5065 KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
5066 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
5067// Binds lock functions again to follow the transition between different
5068// KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
5069// as we do not allow lock kind changes after making a call to any
5070// user lock functions (true).
5071#if KMP_USE_DYNAMIC_LOCK
5072 __kmp_init_dynamic_user_locks();
5073#else
5074 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5075#endif
5076 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005077
Alp Toker763b9392014-02-28 09:42:41 +00005078#if KMP_AFFINITY_SUPPORTED
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005079
Jonathan Peyton30419822017-05-12 18:01:32 +00005080 if (!TCR_4(__kmp_init_middle)) {
5081 // Determine if the machine/OS is actually capable of supporting
5082 // affinity.
5083 const char *var = "KMP_AFFINITY";
5084 KMPAffinity::pick_api();
Jonathan Peytone3e2aaf2017-05-31 20:35:22 +00005085#if KMP_USE_HWLOC
5086 // If Hwloc topology discovery was requested but affinity was also disabled,
5087 // then tell user that Hwloc request is being ignored and use default
5088 // topology discovery method.
5089 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
5090 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
5091 KMP_WARNING(AffIgnoringHwloc, var);
5092 __kmp_affinity_top_method = affinity_top_method_all;
5093 }
5094#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005095 if (__kmp_affinity_type == affinity_disabled) {
5096 KMP_AFFINITY_DISABLE();
5097 } else if (!KMP_AFFINITY_CAPABLE()) {
5098 __kmp_affinity_dispatch->determine_capable(var);
5099 if (!KMP_AFFINITY_CAPABLE()) {
5100 if (__kmp_affinity_verbose ||
5101 (__kmp_affinity_warnings &&
5102 (__kmp_affinity_type != affinity_default) &&
5103 (__kmp_affinity_type != affinity_none) &&
5104 (__kmp_affinity_type != affinity_disabled))) {
5105 KMP_WARNING(AffNotSupported, var);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005106 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005107 __kmp_affinity_type = affinity_disabled;
5108 __kmp_affinity_respect_mask = 0;
5109 __kmp_affinity_gran = affinity_gran_fine;
5110 }
5111 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005112
Jonathan Peyton30419822017-05-12 18:01:32 +00005113#if OMP_40_ENABLED
5114 if (__kmp_affinity_type == affinity_disabled) {
5115 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5116 } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
5117 // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
5118 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
5119 }
5120#endif /* OMP_40_ENABLED */
5121
5122 if (KMP_AFFINITY_CAPABLE()) {
5123
5124#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005125 // This checks to see if the initial affinity mask is equal
5126 // to a single windows processor group. If it is, then we do
5127 // not respect the initial affinity mask and instead, use the
5128 // entire machine.
5129 bool exactly_one_group = false;
5130 if (__kmp_num_proc_groups > 1) {
5131 int group;
5132 bool within_one_group;
5133 // Get the initial affinity mask and determine if it is
5134 // contained within a single group.
5135 kmp_affin_mask_t *init_mask;
5136 KMP_CPU_ALLOC(init_mask);
5137 __kmp_get_system_affinity(init_mask, TRUE);
5138 group = __kmp_get_proc_group(init_mask);
5139 within_one_group = (group >= 0);
5140 // If the initial affinity is within a single group,
5141 // then determine if it is equal to that single group.
5142 if (within_one_group) {
5143 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
5144 int num_bits_in_mask = 0;
5145 for (int bit = init_mask->begin(); bit != init_mask->end();
5146 bit = init_mask->next(bit))
5147 num_bits_in_mask++;
5148 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
5149 }
5150 KMP_CPU_FREE(init_mask);
5151 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005152
5153 // Handle the Win 64 group affinity stuff if there are multiple
5154 // processor groups, or if the user requested it, and OMP 4.0
5155 // affinity is not in effect.
5156 if (((__kmp_num_proc_groups > 1) &&
5157 (__kmp_affinity_type == affinity_default)
5158#if OMP_40_ENABLED
5159 && (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default))
5160#endif
5161 || (__kmp_affinity_top_method == affinity_top_method_group)) {
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005162 if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
5163 exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005164 __kmp_affinity_respect_mask = FALSE;
5165 }
5166 if (__kmp_affinity_type == affinity_default) {
5167 __kmp_affinity_type = affinity_compact;
5168#if OMP_40_ENABLED
5169 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5170#endif
5171 }
5172 if (__kmp_affinity_top_method == affinity_top_method_default) {
5173 if (__kmp_affinity_gran == affinity_gran_default) {
5174 __kmp_affinity_top_method = affinity_top_method_group;
5175 __kmp_affinity_gran = affinity_gran_group;
5176 } else if (__kmp_affinity_gran == affinity_gran_group) {
5177 __kmp_affinity_top_method = affinity_top_method_group;
5178 } else {
5179 __kmp_affinity_top_method = affinity_top_method_all;
5180 }
5181 } else if (__kmp_affinity_top_method == affinity_top_method_group) {
5182 if (__kmp_affinity_gran == affinity_gran_default) {
5183 __kmp_affinity_gran = affinity_gran_group;
5184 } else if ((__kmp_affinity_gran != affinity_gran_group) &&
5185 (__kmp_affinity_gran != affinity_gran_fine) &&
5186 (__kmp_affinity_gran != affinity_gran_thread)) {
5187 const char *str = NULL;
5188 switch (__kmp_affinity_gran) {
5189 case affinity_gran_core:
5190 str = "core";
5191 break;
5192 case affinity_gran_package:
5193 str = "package";
5194 break;
5195 case affinity_gran_node:
5196 str = "node";
5197 break;
5198 default:
5199 KMP_DEBUG_ASSERT(0);
5200 }
5201 KMP_WARNING(AffGranTopGroup, var, str);
5202 __kmp_affinity_gran = affinity_gran_fine;
5203 }
5204 } else {
5205 if (__kmp_affinity_gran == affinity_gran_default) {
5206 __kmp_affinity_gran = affinity_gran_core;
5207 } else if (__kmp_affinity_gran == affinity_gran_group) {
5208 const char *str = NULL;
5209 switch (__kmp_affinity_type) {
5210 case affinity_physical:
5211 str = "physical";
5212 break;
5213 case affinity_logical:
5214 str = "logical";
5215 break;
5216 case affinity_compact:
5217 str = "compact";
5218 break;
5219 case affinity_scatter:
5220 str = "scatter";
5221 break;
5222 case affinity_explicit:
5223 str = "explicit";
5224 break;
5225 // No MIC on windows, so no affinity_balanced case
5226 default:
5227 KMP_DEBUG_ASSERT(0);
5228 }
5229 KMP_WARNING(AffGranGroupType, var, str);
5230 __kmp_affinity_gran = affinity_gran_core;
5231 }
5232 }
5233 } else
5234
5235#endif /* KMP_GROUP_AFFINITY */
5236
5237 {
5238 if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
5239#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005240 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005241 __kmp_affinity_respect_mask = FALSE;
5242 } else
5243#endif /* KMP_GROUP_AFFINITY */
5244 {
5245 __kmp_affinity_respect_mask = TRUE;
5246 }
5247 }
5248#if OMP_40_ENABLED
5249 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
5250 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
5251 if (__kmp_affinity_type == affinity_default) {
5252 __kmp_affinity_type = affinity_compact;
5253 __kmp_affinity_dups = FALSE;
5254 }
5255 } else
5256#endif /* OMP_40_ENABLED */
5257 if (__kmp_affinity_type == affinity_default) {
5258#if OMP_40_ENABLED
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005259#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005260 if (__kmp_mic_type != non_mic) {
5261 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5262 } else
5263#endif
5264 {
Andrey Churbanov94e569e2015-03-10 09:19:47 +00005265 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
Jonathan Peyton30419822017-05-12 18:01:32 +00005266 }
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005267#endif /* OMP_40_ENABLED */
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005268#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005269 if (__kmp_mic_type != non_mic) {
5270 __kmp_affinity_type = affinity_scatter;
5271 } else
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005272#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005273 {
5274 __kmp_affinity_type = affinity_none;
5275 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005276 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005277 if ((__kmp_affinity_gran == affinity_gran_default) &&
5278 (__kmp_affinity_gran_levels < 0)) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005279#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005280 if (__kmp_mic_type != non_mic) {
5281 __kmp_affinity_gran = affinity_gran_fine;
5282 } else
5283#endif
5284 {
5285 __kmp_affinity_gran = affinity_gran_core;
5286 }
5287 }
5288 if (__kmp_affinity_top_method == affinity_top_method_default) {
5289 __kmp_affinity_top_method = affinity_top_method_all;
5290 }
5291 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005292 }
5293
Jonathan Peyton30419822017-05-12 18:01:32 +00005294 K_DIAG(1, ("__kmp_affinity_type == %d\n", __kmp_affinity_type));
5295 K_DIAG(1, ("__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
5296 K_DIAG(1, ("__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
5297 K_DIAG(1, ("__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
5298 K_DIAG(1, ("__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
5299 K_DIAG(1, ("__kmp_affinity_respect_mask == %d\n",
5300 __kmp_affinity_respect_mask));
5301 K_DIAG(1, ("__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
5302
5303 KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
5304#if OMP_40_ENABLED
5305 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
5306#endif
5307 }
5308
Alp Toker763b9392014-02-28 09:42:41 +00005309#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005310
Jonathan Peyton30419822017-05-12 18:01:32 +00005311 if (__kmp_version) {
5312 __kmp_print_version_1();
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005313 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005314
Jonathan Peyton30419822017-05-12 18:01:32 +00005315 // Post-initialization step: some env. vars need their value's further
5316 // processing
5317 if (string != NULL) { // kmp_set_defaults() was called
5318 __kmp_aux_env_initialize(&block);
5319 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005320
Jonathan Peyton30419822017-05-12 18:01:32 +00005321 __kmp_env_blk_free(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005322
Jonathan Peyton30419822017-05-12 18:01:32 +00005323 KMP_MB();
Jim Cownie5e8470a2013-09-27 10:38:44 +00005324
5325} // __kmp_env_initialize
5326
Jonathan Peyton30419822017-05-12 18:01:32 +00005327void __kmp_env_print() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005328
Jonathan Peyton30419822017-05-12 18:01:32 +00005329 kmp_env_blk_t block;
5330 int i;
5331 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005332
Jonathan Peyton30419822017-05-12 18:01:32 +00005333 __kmp_stg_init();
5334 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005335
Jonathan Peyton30419822017-05-12 18:01:32 +00005336 __kmp_env_blk_init(&block, NULL);
5337 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005338
Jonathan Peyton30419822017-05-12 18:01:32 +00005339 // Print real environment values.
5340 __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
5341 for (i = 0; i < block.count; ++i) {
5342 char const *name = block.vars[i].name;
5343 char const *value = block.vars[i].value;
5344 if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
5345 strncmp(name, "OMP_", 4) == 0
5346#ifdef KMP_GOMP_COMPAT
5347 || strncmp(name, "GOMP_", 5) == 0
5348#endif // KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00005349 ) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005350 __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005351 }
5352 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005353 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005354
Jonathan Peyton30419822017-05-12 18:01:32 +00005355 // Print internal (effective) settings.
5356 __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
5357 for (int i = 0; i < __kmp_stg_count; ++i) {
5358 if (__kmp_stg_table[i].print != NULL) {
5359 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5360 __kmp_stg_table[i].data);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005361 }
5362 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005363
Jonathan Peyton30419822017-05-12 18:01:32 +00005364 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005365
Jonathan Peyton30419822017-05-12 18:01:32 +00005366 __kmp_env_blk_free(&block);
5367 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005368
Jonathan Peyton30419822017-05-12 18:01:32 +00005369 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005370
5371} // __kmp_env_print
5372
Jim Cownie5e8470a2013-09-27 10:38:44 +00005373#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005374void __kmp_env_print_2() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005375
Jonathan Peyton30419822017-05-12 18:01:32 +00005376 kmp_env_blk_t block;
5377 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005378
Jonathan Peyton30419822017-05-12 18:01:32 +00005379 __kmp_env_format = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005380
Jonathan Peyton30419822017-05-12 18:01:32 +00005381 __kmp_stg_init();
5382 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005383
Jonathan Peyton30419822017-05-12 18:01:32 +00005384 __kmp_env_blk_init(&block, NULL);
5385 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005386
Jonathan Peyton30419822017-05-12 18:01:32 +00005387 __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
5388 __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005389
Jonathan Peyton30419822017-05-12 18:01:32 +00005390 for (int i = 0; i < __kmp_stg_count; ++i) {
5391 if (__kmp_stg_table[i].print != NULL &&
5392 ((__kmp_display_env &&
5393 strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
5394 __kmp_display_env_verbose)) {
5395 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5396 __kmp_stg_table[i].data);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005397 }
5398 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005399
Jonathan Peyton30419822017-05-12 18:01:32 +00005400 __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
5401 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005402
Jonathan Peyton30419822017-05-12 18:01:32 +00005403 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005404
Jonathan Peyton30419822017-05-12 18:01:32 +00005405 __kmp_env_blk_free(&block);
5406 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005407
Jonathan Peyton30419822017-05-12 18:01:32 +00005408 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005409
5410} // __kmp_env_print_2
5411#endif // OMP_40_ENABLED
5412
Jim Cownie5e8470a2013-09-27 10:38:44 +00005413// end of file