blob: ee3076318f4f969288a45426e658deeb1ff10a88 [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 Peyton30419822017-05-12 18:01:32 +0000337static void __kmp_stg_parse_str(char const *name, char const *value,
338 char const **out) {
339 __kmp_str_free(out);
340 *out = __kmp_str_format("%s", value);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000341} // __kmp_stg_parse_str
Jim Cownie5e8470a2013-09-27 10:38:44 +0000342
Jonathan Peyton30419822017-05-12 18:01:32 +0000343static void __kmp_stg_parse_int(
344 char const
345 *name, // I: Name of environment variable (used in warning messages).
346 char const *value, // I: Value of environment variable to parse.
347 int min, // I: Miminal allowed value.
348 int max, // I: Maximum allowed value.
349 int *out // O: Output (parsed) value.
350 ) {
351 char const *msg = NULL;
352 kmp_uint64 uint = *out;
353 __kmp_str_to_uint(value, &uint, &msg);
354 if (msg == NULL) {
355 if (uint < (unsigned int)min) {
356 msg = KMP_I18N_STR(ValueTooSmall);
357 uint = min;
358 } else if (uint > (unsigned int)max) {
359 msg = KMP_I18N_STR(ValueTooLarge);
360 uint = max;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000361 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000362 } else {
363 // If overflow occurred msg contains error message and uint is very big. Cut
364 // tmp it to INT_MAX.
365 if (uint < (unsigned int)min) {
366 uint = min;
367 } else if (uint > (unsigned int)max) {
368 uint = max;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000369 }
370 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000371 if (msg != NULL) {
372 // Message is not empty. Print warning.
373 kmp_str_buf_t buf;
374 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
375 __kmp_str_buf_init(&buf);
376 __kmp_str_buf_print(&buf, "%" KMP_UINT64_SPEC "", uint);
377 KMP_INFORM(Using_uint64_Value, name, buf.str);
378 __kmp_str_buf_free(&buf);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000379 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000380 *out = uint;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000381} // __kmp_stg_parse_int
382
Jonathan Peyton2321d572015-06-08 19:25:25 +0000383#if KMP_DEBUG_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +0000384static void __kmp_stg_parse_file(char const *name, char const *value,
385 char *suffix, char **out) {
386 char buffer[256];
387 char *t;
388 int hasSuffix;
389 __kmp_str_free(out);
390 t = (char *)strrchr(value, '.');
391 hasSuffix = t && __kmp_str_eqf(t, suffix);
392 t = __kmp_str_format("%s%s", value, hasSuffix ? "" : suffix);
393 __kmp_expand_file_name(buffer, sizeof(buffer), t);
394 __kmp_str_free(&t);
395 *out = __kmp_str_format("%s", buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000396} // __kmp_stg_parse_file
Jonathan Peyton2321d572015-06-08 19:25:25 +0000397#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000398
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000399#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000400static char *par_range_to_print = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000401
Jonathan Peyton30419822017-05-12 18:01:32 +0000402static void __kmp_stg_parse_par_range(char const *name, char const *value,
403 int *out_range, char *out_routine,
404 char *out_file, int *out_lb,
405 int *out_ub) {
406 size_t len = KMP_STRLEN(value + 1);
407 par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
408 KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
409 __kmp_par_range = +1;
410 __kmp_par_range_lb = 0;
411 __kmp_par_range_ub = INT_MAX;
412 for (;;) {
413 unsigned int len;
414 if ((value == NULL) || (*value == '\0')) {
415 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000416 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000417 if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
418 value = strchr(value, '=') + 1;
419 len = __kmp_readstr_with_sentinel(out_routine, value,
420 KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
421 if (len == 0) {
422 goto par_range_error;
423 }
424 value = strchr(value, ',');
425 if (value != NULL) {
426 value++;
427 }
428 continue;
429 }
430 if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
431 value = strchr(value, '=') + 1;
432 len = __kmp_readstr_with_sentinel(out_file, value,
433 KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
434 if (len == 0) {
435 goto par_range_error;
436 }
437 value = strchr(value, ',');
438 if (value != NULL) {
439 value++;
440 }
441 continue;
442 }
443 if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
444 (!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
445 value = strchr(value, '=') + 1;
446 if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
447 goto par_range_error;
448 }
449 *out_range = +1;
450 value = strchr(value, ',');
451 if (value != NULL) {
452 value++;
453 }
454 continue;
455 }
456 if (!__kmp_strcasecmp_with_sentinel("excl_range", value, '=')) {
457 value = strchr(value, '=') + 1;
458 if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
459 goto par_range_error;
460 }
461 *out_range = -1;
462 value = strchr(value, ',');
463 if (value != NULL) {
464 value++;
465 }
466 continue;
467 }
468 par_range_error:
469 KMP_WARNING(ParRangeSyntax, name);
470 __kmp_par_range = 0;
471 break;
472 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000473} // __kmp_stg_parse_par_range
Jim Cownie3051f972014-08-07 10:12:54 +0000474#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000475
Jonathan Peyton30419822017-05-12 18:01:32 +0000476int __kmp_initial_threads_capacity(int req_nproc) {
477 int nth = 32;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000478
Jonathan Peyton30419822017-05-12 18:01:32 +0000479 /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
480 * __kmp_max_nth) */
481 if (nth < (4 * req_nproc))
482 nth = (4 * req_nproc);
483 if (nth < (4 * __kmp_xproc))
484 nth = (4 * __kmp_xproc);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000485
Jonathan Peyton30419822017-05-12 18:01:32 +0000486 if (nth > __kmp_max_nth)
487 nth = __kmp_max_nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000488
Jonathan Peyton30419822017-05-12 18:01:32 +0000489 return nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000490}
491
Jonathan Peyton30419822017-05-12 18:01:32 +0000492int __kmp_default_tp_capacity(int req_nproc, int max_nth,
493 int all_threads_specified) {
494 int nth = 128;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000495
Jonathan Peyton30419822017-05-12 18:01:32 +0000496 if (all_threads_specified)
497 return max_nth;
498 /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
499 * __kmp_max_nth ) */
500 if (nth < (4 * req_nproc))
501 nth = (4 * req_nproc);
502 if (nth < (4 * __kmp_xproc))
503 nth = (4 * __kmp_xproc);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000504
Jonathan Peyton30419822017-05-12 18:01:32 +0000505 if (nth > __kmp_max_nth)
506 nth = __kmp_max_nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000507
Jonathan Peyton30419822017-05-12 18:01:32 +0000508 return nth;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000509}
510
Jonathan Peyton30419822017-05-12 18:01:32 +0000511// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000512// Helper print functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000513
Jonathan Peyton30419822017-05-12 18:01:32 +0000514static void __kmp_stg_print_bool(kmp_str_buf_t *buffer, char const *name,
515 int value) {
516 if (__kmp_env_format) {
517 KMP_STR_BUF_PRINT_BOOL;
518 } else {
519 __kmp_str_buf_print(buffer, " %s=%s\n", name, value ? "true" : "false");
520 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000521} // __kmp_stg_print_bool
522
Jonathan Peyton30419822017-05-12 18:01:32 +0000523static void __kmp_stg_print_int(kmp_str_buf_t *buffer, char const *name,
524 int value) {
525 if (__kmp_env_format) {
526 KMP_STR_BUF_PRINT_INT;
527 } else {
528 __kmp_str_buf_print(buffer, " %s=%d\n", name, value);
529 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000530} // __kmp_stg_print_int
531
Jonathan Peyton30419822017-05-12 18:01:32 +0000532static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer, char const *name,
533 kmp_uint64 value) {
534 if (__kmp_env_format) {
535 KMP_STR_BUF_PRINT_UINT64;
536 } else {
537 __kmp_str_buf_print(buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value);
538 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000539} // __kmp_stg_print_uint64
540
Jonathan Peyton30419822017-05-12 18:01:32 +0000541static void __kmp_stg_print_str(kmp_str_buf_t *buffer, char const *name,
542 char const *value) {
543 if (__kmp_env_format) {
544 KMP_STR_BUF_PRINT_STR;
545 } else {
546 __kmp_str_buf_print(buffer, " %s=%s\n", name, value);
547 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000548} // __kmp_stg_print_str
549
Jonathan Peyton30419822017-05-12 18:01:32 +0000550static void __kmp_stg_print_size(kmp_str_buf_t *buffer, char const *name,
551 size_t value) {
552 if (__kmp_env_format) {
553 KMP_STR_BUF_PRINT_NAME_EX(name);
554 __kmp_str_buf_print_size(buffer, value);
555 __kmp_str_buf_print(buffer, "'\n");
556 } else {
557 __kmp_str_buf_print(buffer, " %s=", name);
558 __kmp_str_buf_print_size(buffer, value);
559 __kmp_str_buf_print(buffer, "\n");
560 return;
561 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000562} // __kmp_stg_print_size
563
Jonathan Peyton30419822017-05-12 18:01:32 +0000564// =============================================================================
Jim Cownie5e8470a2013-09-27 10:38:44 +0000565// Parse and print functions.
Jim Cownie5e8470a2013-09-27 10:38:44 +0000566
Jonathan Peyton30419822017-05-12 18:01:32 +0000567// -----------------------------------------------------------------------------
Jonathan Peytonf4392462017-07-27 20:58:41 +0000568// KMP_DEVICE_THREAD_LIMIT, KMP_ALL_THREADS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000569
Jonathan Peyton09244f32017-07-26 20:07:58 +0000570static void __kmp_stg_parse_device_thread_limit(char const *name,
571 char const *value, void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +0000572 kmp_setting_t **rivals = (kmp_setting_t **)data;
573 int rc;
Jonathan Peyton09244f32017-07-26 20:07:58 +0000574 if (strcmp(name, "KMP_ALL_THREADS") == 0) {
575 KMP_INFORM(EnvVarDeprecated, name, "KMP_DEVICE_THREAD_LIMIT");
576 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000577 rc = __kmp_stg_check_rivals(name, value, rivals);
578 if (rc) {
579 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000580 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000581 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
582 __kmp_max_nth = __kmp_xproc;
583 __kmp_allThreadsSpecified = 1;
584 } else {
585 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
586 __kmp_allThreadsSpecified = 0;
587 }
588 K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000589
Jonathan Peyton09244f32017-07-26 20:07:58 +0000590} // __kmp_stg_parse_device_thread_limit
Jim Cownie5e8470a2013-09-27 10:38:44 +0000591
Jonathan Peyton09244f32017-07-26 20:07:58 +0000592static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
593 char const *name, void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +0000594 __kmp_stg_print_int(buffer, name, __kmp_max_nth);
Jonathan Peyton09244f32017-07-26 20:07:58 +0000595} // __kmp_stg_print_device_thread_limit
Jim Cownie5e8470a2013-09-27 10:38:44 +0000596
Jonathan Peyton30419822017-05-12 18:01:32 +0000597// -----------------------------------------------------------------------------
Jonathan Peytonf4392462017-07-27 20:58:41 +0000598// OMP_THREAD_LIMIT
599static void __kmp_stg_parse_thread_limit(char const *name, char const *value,
600 void *data) {
601 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
602 K_DIAG(1, ("__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));
603
604} // __kmp_stg_parse_thread_limit
605
606static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
607 char const *name, void *data) {
608 __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
609} // __kmp_stg_print_thread_limit
610
611// -----------------------------------------------------------------------------
Jonathan Peyton4f90c822017-08-02 20:04:45 +0000612// KMP_TEAMS_THREAD_LIMIT
613static void __kmp_stg_parse_teams_thread_limit(char const *name,
614 char const *value, void *data) {
615 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
616} // __kmp_stg_teams_thread_limit
617
618static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
619 char const *name, void *data) {
620 __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
621} // __kmp_stg_print_teams_thread_limit
622
623// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000624// KMP_BLOCKTIME
Jim Cownie5e8470a2013-09-27 10:38:44 +0000625
Jonathan Peyton30419822017-05-12 18:01:32 +0000626static void __kmp_stg_parse_blocktime(char const *name, char const *value,
627 void *data) {
628 __kmp_dflt_blocktime = __kmp_convert_to_milliseconds(value);
629 if (__kmp_dflt_blocktime < 0) {
630 __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
631 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
632 __kmp_msg_null);
633 KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime);
634 __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
635 } else {
636 if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
637 __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
638 __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
639 __kmp_msg_null);
640 KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime);
641 } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
642 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
643 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
644 __kmp_msg_null);
645 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000646 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000647 __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000648 }
Jonathan Peytone1c7c132016-10-07 18:12:19 +0000649#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +0000650 // calculate number of monitor thread wakeup intervals corresponding to
651 // blocktime.
652 __kmp_monitor_wakeups =
653 KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
654 __kmp_bt_intervals =
655 KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
Jonathan Peytone1c7c132016-10-07 18:12:19 +0000656#endif
Jonathan Peyton30419822017-05-12 18:01:32 +0000657 K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
658 if (__kmp_env_blocktime) {
659 K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
660 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000661} // __kmp_stg_parse_blocktime
662
Jonathan Peyton30419822017-05-12 18:01:32 +0000663static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
664 void *data) {
665 __kmp_stg_print_int(buffer, name, __kmp_dflt_blocktime);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000666} // __kmp_stg_print_blocktime
667
Jonathan Peytond74d8902017-07-25 18:20:16 +0000668// Used for OMP_WAIT_POLICY
669static char const *blocktime_str = NULL;
670
Jonathan Peyton30419822017-05-12 18:01:32 +0000671// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000672// KMP_DUPLICATE_LIB_OK
Jim Cownie5e8470a2013-09-27 10:38:44 +0000673
Jonathan Peyton30419822017-05-12 18:01:32 +0000674static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
675 char const *value, void *data) {
676 /* actually this variable is not supported, put here for compatibility with
677 earlier builds and for static/dynamic combination */
678 __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000679} // __kmp_stg_parse_duplicate_lib_ok
680
Jonathan Peyton30419822017-05-12 18:01:32 +0000681static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
682 char const *name, void *data) {
683 __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000684} // __kmp_stg_print_duplicate_lib_ok
685
Jonathan Peyton30419822017-05-12 18:01:32 +0000686// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000687// KMP_INHERIT_FP_CONTROL
Jim Cownie5e8470a2013-09-27 10:38:44 +0000688
689#if KMP_ARCH_X86 || KMP_ARCH_X86_64
690
Jonathan Peyton30419822017-05-12 18:01:32 +0000691static void __kmp_stg_parse_inherit_fp_control(char const *name,
692 char const *value, void *data) {
693 __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000694} // __kmp_stg_parse_inherit_fp_control
695
Jonathan Peyton30419822017-05-12 18:01:32 +0000696static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
697 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000698#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000699 __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000700#endif /* KMP_DEBUG */
701} // __kmp_stg_print_inherit_fp_control
702
703#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
704
Jonathan Peyton30419822017-05-12 18:01:32 +0000705// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000706// KMP_LIBRARY, OMP_WAIT_POLICY
Jim Cownie5e8470a2013-09-27 10:38:44 +0000707
Jonathan Peyton30419822017-05-12 18:01:32 +0000708static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
709 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000710
Jonathan Peyton30419822017-05-12 18:01:32 +0000711 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
712 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000713
Jonathan Peyton30419822017-05-12 18:01:32 +0000714 rc = __kmp_stg_check_rivals(name, value, wait->rivals);
715 if (rc) {
716 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000717 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000718
Jonathan Peyton30419822017-05-12 18:01:32 +0000719 if (wait->omp) {
720 if (__kmp_str_match("ACTIVE", 1, value)) {
721 __kmp_library = library_turnaround;
722 if (blocktime_str == NULL) {
723 // KMP_BLOCKTIME not specified, so set default to "infinite".
724 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
725 }
726 } else if (__kmp_str_match("PASSIVE", 1, value)) {
727 __kmp_library = library_throughput;
728 if (blocktime_str == NULL) {
729 // KMP_BLOCKTIME not specified, so set default to 0.
730 __kmp_dflt_blocktime = 0;
731 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000732 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +0000733 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000734 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000735 } else {
736 if (__kmp_str_match("serial", 1, value)) { /* S */
737 __kmp_library = library_serial;
738 } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
739 __kmp_library = library_throughput;
740 } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
741 __kmp_library = library_turnaround;
742 } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
743 __kmp_library = library_turnaround;
744 } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
745 __kmp_library = library_throughput;
746 } else {
747 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000748 }
749 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000750 __kmp_aux_set_library(__kmp_library);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000751
752} // __kmp_stg_parse_wait_policy
753
Jonathan Peyton30419822017-05-12 18:01:32 +0000754static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
755 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000756
Jonathan Peyton30419822017-05-12 18:01:32 +0000757 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
758 char const *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000759
Jonathan Peyton30419822017-05-12 18:01:32 +0000760 if (wait->omp) {
761 switch (__kmp_library) {
762 case library_turnaround: {
763 value = "ACTIVE";
764 } break;
765 case library_throughput: {
766 value = "PASSIVE";
767 } break;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000768 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000769 } else {
770 switch (__kmp_library) {
771 case library_serial: {
772 value = "serial";
773 } break;
774 case library_turnaround: {
775 value = "turnaround";
776 } break;
777 case library_throughput: {
778 value = "throughput";
779 } break;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000780 }
781 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000782 if (value != NULL) {
783 __kmp_stg_print_str(buffer, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000784 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000785
786} // __kmp_stg_print_wait_policy
787
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000788#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +0000789// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000790// KMP_MONITOR_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000791
Jonathan Peyton30419822017-05-12 18:01:32 +0000792static void __kmp_stg_parse_monitor_stacksize(char const *name,
793 char const *value, void *data) {
794 __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
795 NULL, &__kmp_monitor_stksize, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000796} // __kmp_stg_parse_monitor_stacksize
797
Jonathan Peyton30419822017-05-12 18:01:32 +0000798static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
799 char const *name, void *data) {
800 if (__kmp_env_format) {
801 if (__kmp_monitor_stksize > 0)
802 KMP_STR_BUF_PRINT_NAME_EX(name);
803 else
804 KMP_STR_BUF_PRINT_NAME;
805 } else {
806 __kmp_str_buf_print(buffer, " %s", name);
807 }
808 if (__kmp_monitor_stksize > 0) {
809 __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
810 } else {
811 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
812 }
813 if (__kmp_env_format && __kmp_monitor_stksize) {
814 __kmp_str_buf_print(buffer, "'\n");
815 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000816} // __kmp_stg_print_monitor_stacksize
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +0000817#endif // KMP_USE_MONITOR
Jim Cownie5e8470a2013-09-27 10:38:44 +0000818
Jonathan Peyton30419822017-05-12 18:01:32 +0000819// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000820// KMP_SETTINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000821
Jonathan Peyton30419822017-05-12 18:01:32 +0000822static void __kmp_stg_parse_settings(char const *name, char const *value,
823 void *data) {
824 __kmp_stg_parse_bool(name, value, &__kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000825} // __kmp_stg_parse_settings
826
Jonathan Peyton30419822017-05-12 18:01:32 +0000827static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
828 void *data) {
829 __kmp_stg_print_bool(buffer, name, __kmp_settings);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000830} // __kmp_stg_print_settings
831
Jonathan Peyton30419822017-05-12 18:01:32 +0000832// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000833// KMP_STACKPAD
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000834
Jonathan Peyton30419822017-05-12 18:01:32 +0000835static void __kmp_stg_parse_stackpad(char const *name, char const *value,
836 void *data) {
837 __kmp_stg_parse_int(name, // Env var name
838 value, // Env var value
839 KMP_MIN_STKPADDING, // Min value
840 KMP_MAX_STKPADDING, // Max value
841 &__kmp_stkpadding // Var to initialize
842 );
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000843} // __kmp_stg_parse_stackpad
844
Jonathan Peyton30419822017-05-12 18:01:32 +0000845static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
846 void *data) {
847 __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000848} // __kmp_stg_print_stackpad
849
Jonathan Peyton30419822017-05-12 18:01:32 +0000850// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000851// KMP_STACKOFFSET
Jim Cownie5e8470a2013-09-27 10:38:44 +0000852
Jonathan Peyton30419822017-05-12 18:01:32 +0000853static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
854 void *data) {
855 __kmp_stg_parse_size(name, // Env var name
856 value, // Env var value
857 KMP_MIN_STKOFFSET, // Min value
858 KMP_MAX_STKOFFSET, // Max value
859 NULL, //
860 &__kmp_stkoffset, // Var to initialize
861 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000862} // __kmp_stg_parse_stackoffset
863
Jonathan Peyton30419822017-05-12 18:01:32 +0000864static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
865 void *data) {
866 __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000867} // __kmp_stg_print_stackoffset
868
Jonathan Peyton30419822017-05-12 18:01:32 +0000869// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000870// KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
Jim Cownie5e8470a2013-09-27 10:38:44 +0000871
Jonathan Peyton30419822017-05-12 18:01:32 +0000872static void __kmp_stg_parse_stacksize(char const *name, char const *value,
873 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000874
Jonathan Peyton30419822017-05-12 18:01:32 +0000875 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
876 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000877
Jonathan Peyton30419822017-05-12 18:01:32 +0000878 rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
879 if (rc) {
880 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000881 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000882 __kmp_stg_parse_size(name, // Env var name
883 value, // Env var value
884 __kmp_sys_min_stksize, // Min value
885 KMP_MAX_STKSIZE, // Max value
886 &__kmp_env_stksize, //
887 &__kmp_stksize, // Var to initialize
888 stacksize->factor);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000889
890} // __kmp_stg_parse_stacksize
891
Jonathan Peyton30419822017-05-12 18:01:32 +0000892// This function is called for printing both KMP_STACKSIZE (factor is 1) and
893// OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
894// OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
895// customer request in future.
896static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
897 void *data) {
898 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
899 if (__kmp_env_format) {
900 KMP_STR_BUF_PRINT_NAME_EX(name);
901 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
902 ? __kmp_stksize / stacksize->factor
903 : __kmp_stksize);
904 __kmp_str_buf_print(buffer, "'\n");
905 } else {
906 __kmp_str_buf_print(buffer, " %s=", name);
907 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
908 ? __kmp_stksize / stacksize->factor
909 : __kmp_stksize);
910 __kmp_str_buf_print(buffer, "\n");
911 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000912} // __kmp_stg_print_stacksize
913
Jonathan Peyton30419822017-05-12 18:01:32 +0000914// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000915// KMP_VERSION
Jim Cownie5e8470a2013-09-27 10:38:44 +0000916
Jonathan Peyton30419822017-05-12 18:01:32 +0000917static void __kmp_stg_parse_version(char const *name, char const *value,
918 void *data) {
919 __kmp_stg_parse_bool(name, value, &__kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000920} // __kmp_stg_parse_version
921
Jonathan Peyton30419822017-05-12 18:01:32 +0000922static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
923 void *data) {
924 __kmp_stg_print_bool(buffer, name, __kmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000925} // __kmp_stg_print_version
926
Jonathan Peyton30419822017-05-12 18:01:32 +0000927// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000928// KMP_WARNINGS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000929
Jonathan Peyton30419822017-05-12 18:01:32 +0000930static void __kmp_stg_parse_warnings(char const *name, char const *value,
931 void *data) {
932 __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
933 if (__kmp_generate_warnings != kmp_warnings_off) {
934 // AC: only 0/1 values documented, so reset to explicit to distinguish from
935 // default setting
936 __kmp_generate_warnings = kmp_warnings_explicit;
937 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000938} // __kmp_stg_parse_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000939
Jonathan Peyton30419822017-05-12 18:01:32 +0000940static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
941 void *data) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +0000942 // AC: TODO: change to print_int? (needs documentation change)
943 __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
944} // __kmp_stg_print_warnings
Jim Cownie5e8470a2013-09-27 10:38:44 +0000945
Jonathan Peyton30419822017-05-12 18:01:32 +0000946// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +0000947// OMP_NESTED, OMP_NUM_THREADS
Jim Cownie5e8470a2013-09-27 10:38:44 +0000948
Jonathan Peyton30419822017-05-12 18:01:32 +0000949static void __kmp_stg_parse_nested(char const *name, char const *value,
950 void *data) {
951 __kmp_stg_parse_bool(name, value, &__kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000952} // __kmp_stg_parse_nested
953
Jonathan Peyton30419822017-05-12 18:01:32 +0000954static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
955 void *data) {
956 __kmp_stg_print_bool(buffer, name, __kmp_dflt_nested);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000957} // __kmp_stg_print_nested
958
Jonathan Peyton30419822017-05-12 18:01:32 +0000959static void __kmp_parse_nested_num_threads(const char *var, const char *env,
960 kmp_nested_nthreads_t *nth_array) {
961 const char *next = env;
962 const char *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000963
Jonathan Peyton30419822017-05-12 18:01:32 +0000964 int total = 0; // Count elements that were set. It'll be used as an array size
965 int prev_comma = FALSE; // For correct processing sequential commas
Jim Cownie5e8470a2013-09-27 10:38:44 +0000966
Jonathan Peyton30419822017-05-12 18:01:32 +0000967 // Count the number of values in the env. var string
968 for (;;) {
969 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000970
Jonathan Peyton30419822017-05-12 18:01:32 +0000971 if (*next == '\0') {
972 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000973 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000974 // Next character is not an integer or not a comma => end of list
975 if (((*next < '0') || (*next > '9')) && (*next != ',')) {
976 KMP_WARNING(NthSyntaxError, var, env);
977 return;
978 }
979 // The next character is ','
980 if (*next == ',') {
981 // ',' is the fisrt character
982 if (total == 0 || prev_comma) {
983 total++;
984 }
985 prev_comma = TRUE;
986 next++; // skip ','
987 SKIP_WS(next);
988 }
989 // Next character is a digit
990 if (*next >= '0' && *next <= '9') {
991 prev_comma = FALSE;
992 SKIP_DIGITS(next);
993 total++;
994 const char *tmp = next;
995 SKIP_WS(tmp);
996 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
997 KMP_WARNING(NthSpacesNotAllowed, var, env);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000998 return;
Jonathan Peyton30419822017-05-12 18:01:32 +0000999 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001000 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001001 }
1002 KMP_DEBUG_ASSERT(total > 0);
1003 if (total <= 0) {
1004 KMP_WARNING(NthSyntaxError, var, env);
1005 return;
1006 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001007
Jonathan Peyton30419822017-05-12 18:01:32 +00001008 // Check if the nested nthreads array exists
1009 if (!nth_array->nth) {
1010 // Allocate an array of double size
1011 nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
1012 if (nth_array->nth == NULL) {
1013 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001014 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001015 nth_array->size = total * 2;
1016 } else {
1017 if (nth_array->size < total) {
1018 // Increase the array size
1019 do {
1020 nth_array->size *= 2;
1021 } while (nth_array->size < total);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001022
Jonathan Peyton30419822017-05-12 18:01:32 +00001023 nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
1024 nth_array->nth, sizeof(int) * nth_array->size);
1025 if (nth_array->nth == NULL) {
1026 KMP_FATAL(MemoryAllocFailed);
1027 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001028 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001029 }
1030 nth_array->used = total;
1031 int i = 0;
1032
1033 prev_comma = FALSE;
1034 total = 0;
1035 // Save values in the array
1036 for (;;) {
1037 SKIP_WS(scan);
1038 if (*scan == '\0') {
1039 break;
1040 }
1041 // The next character is ','
1042 if (*scan == ',') {
1043 // ',' in the beginning of the list
1044 if (total == 0) {
1045 // The value is supposed to be equal to __kmp_avail_proc but it is
1046 // unknown at the moment.
1047 // So let's put a placeholder (#threads = 0) to correct it later.
1048 nth_array->nth[i++] = 0;
1049 total++;
1050 } else if (prev_comma) {
1051 // Num threads is inherited from the previous level
1052 nth_array->nth[i] = nth_array->nth[i - 1];
1053 i++;
1054 total++;
1055 }
1056 prev_comma = TRUE;
1057 scan++; // skip ','
1058 SKIP_WS(scan);
1059 }
1060 // Next character is a digit
1061 if (*scan >= '0' && *scan <= '9') {
1062 int num;
1063 const char *buf = scan;
1064 char const *msg = NULL;
1065 prev_comma = FALSE;
1066 SKIP_DIGITS(scan);
1067 total++;
1068
1069 num = __kmp_str_to_int(buf, *scan);
1070 if (num < KMP_MIN_NTH) {
1071 msg = KMP_I18N_STR(ValueTooSmall);
1072 num = KMP_MIN_NTH;
1073 } else if (num > __kmp_sys_max_nth) {
1074 msg = KMP_I18N_STR(ValueTooLarge);
1075 num = __kmp_sys_max_nth;
1076 }
1077 if (msg != NULL) {
1078 // Message is not empty. Print warning.
1079 KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1080 KMP_INFORM(Using_int_Value, var, num);
1081 }
1082 nth_array->nth[i++] = num;
1083 }
1084 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001085}
1086
Jonathan Peyton30419822017-05-12 18:01:32 +00001087static void __kmp_stg_parse_num_threads(char const *name, char const *value,
1088 void *data) {
1089 // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
1090 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
1091 // The array of 1 element
1092 __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
1093 __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1094 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1095 __kmp_xproc;
1096 } else {
1097 __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1098 if (__kmp_nested_nth.nth) {
1099 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1100 if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1101 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1102 }
1103 }
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001104 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001105 K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001106} // __kmp_stg_parse_num_threads
1107
Jonathan Peyton30419822017-05-12 18:01:32 +00001108static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
1109 void *data) {
1110 if (__kmp_env_format) {
1111 KMP_STR_BUF_PRINT_NAME;
1112 } else {
1113 __kmp_str_buf_print(buffer, " %s", name);
1114 }
1115 if (__kmp_nested_nth.used) {
1116 kmp_str_buf_t buf;
1117 __kmp_str_buf_init(&buf);
1118 for (int i = 0; i < __kmp_nested_nth.used; i++) {
1119 __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
1120 if (i < __kmp_nested_nth.used - 1) {
1121 __kmp_str_buf_print(&buf, ",");
1122 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001123 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001124 __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
1125 __kmp_str_buf_free(&buf);
1126 } else {
1127 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1128 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001129} // __kmp_stg_print_num_threads
1130
Jonathan Peyton30419822017-05-12 18:01:32 +00001131// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001132// OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
Jim Cownie5e8470a2013-09-27 10:38:44 +00001133
Jonathan Peyton30419822017-05-12 18:01:32 +00001134static void __kmp_stg_parse_tasking(char const *name, char const *value,
1135 void *data) {
1136 __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
1137 (int *)&__kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001138} // __kmp_stg_parse_tasking
1139
Jonathan Peyton30419822017-05-12 18:01:32 +00001140static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
1141 void *data) {
1142 __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001143} // __kmp_stg_print_tasking
1144
Jonathan Peyton30419822017-05-12 18:01:32 +00001145static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
1146 void *data) {
1147 __kmp_stg_parse_int(name, value, 0, 1,
1148 (int *)&__kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001149} // __kmp_stg_parse_task_stealing
1150
Jonathan Peyton30419822017-05-12 18:01:32 +00001151static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1152 char const *name, void *data) {
1153 __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001154} // __kmp_stg_print_task_stealing
1155
Jonathan Peyton30419822017-05-12 18:01:32 +00001156static void __kmp_stg_parse_max_active_levels(char const *name,
1157 char const *value, void *data) {
1158 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1159 &__kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001160} // __kmp_stg_parse_max_active_levels
1161
Jonathan Peyton30419822017-05-12 18:01:32 +00001162static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1163 char const *name, void *data) {
1164 __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001165} // __kmp_stg_print_max_active_levels
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001166
George Rokos28f31b42016-09-09 17:55:26 +00001167#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001168// -----------------------------------------------------------------------------
George Rokos28f31b42016-09-09 17:55:26 +00001169// OpenMP 4.0: OMP_DEFAULT_DEVICE
Jonathan Peyton30419822017-05-12 18:01:32 +00001170static void __kmp_stg_parse_default_device(char const *name, char const *value,
1171 void *data) {
1172 __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1173 &__kmp_default_device);
George Rokos28f31b42016-09-09 17:55:26 +00001174} // __kmp_stg_parse_default_device
1175
Jonathan Peyton30419822017-05-12 18:01:32 +00001176static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1177 char const *name, void *data) {
George Rokos28f31b42016-09-09 17:55:26 +00001178 __kmp_stg_print_int(buffer, name, __kmp_default_device);
1179} // __kmp_stg_print_default_device
1180#endif
1181
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001182#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00001183// -----------------------------------------------------------------------------
Jonathan Peyton28510722016-02-25 18:04:09 +00001184// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
Jonathan Peyton30419822017-05-12 18:01:32 +00001185static void __kmp_stg_parse_max_task_priority(char const *name,
1186 char const *value, void *data) {
1187 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1188 &__kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001189} // __kmp_stg_parse_max_task_priority
1190
Jonathan Peyton30419822017-05-12 18:01:32 +00001191static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1192 char const *name, void *data) {
1193 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
Jonathan Peyton28510722016-02-25 18:04:09 +00001194} // __kmp_stg_print_max_task_priority
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001195
1196// KMP_TASKLOOP_MIN_TASKS
1197// taskloop threashold to switch from recursive to linear tasks creation
1198static void __kmp_stg_parse_taskloop_min_tasks(char const *name,
Jonathan Peytond74d8902017-07-25 18:20:16 +00001199 char const *value, void *data) {
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001200 int tmp;
1201 __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1202 __kmp_taskloop_min_tasks = tmp;
1203} // __kmp_stg_parse_taskloop_min_tasks
1204
1205static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
Jonathan Peytond74d8902017-07-25 18:20:16 +00001206 char const *name, void *data) {
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00001207 __kmp_stg_print_int(buffer, name, __kmp_taskloop_min_tasks);
1208} // __kmp_stg_print_taskloop_min_tasks
Jonathan Peytondf6818b2016-06-14 17:57:47 +00001209#endif // OMP_45_ENABLED
Jonathan Peyton28510722016-02-25 18:04:09 +00001210
Jonathan Peyton30419822017-05-12 18:01:32 +00001211// -----------------------------------------------------------------------------
Jonathan Peyton067325f2016-05-31 19:01:15 +00001212// KMP_DISP_NUM_BUFFERS
Jonathan Peyton30419822017-05-12 18:01:32 +00001213static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
1214 void *data) {
1215 if (TCR_4(__kmp_init_serial)) {
1216 KMP_WARNING(EnvSerialWarn, name);
1217 return;
1218 } // read value before serial initialization only
1219 __kmp_stg_parse_int(name, value, 1, KMP_MAX_NTH, &__kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001220} // __kmp_stg_parse_disp_buffers
1221
Jonathan Peyton30419822017-05-12 18:01:32 +00001222static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1223 char const *name, void *data) {
1224 __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
Jonathan Peyton067325f2016-05-31 19:01:15 +00001225} // __kmp_stg_print_disp_buffers
1226
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001227#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00001228// -----------------------------------------------------------------------------
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001229// KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001230
Jonathan Peyton30419822017-05-12 18:01:32 +00001231static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
1232 void *data) {
1233 if (TCR_4(__kmp_init_parallel)) {
1234 KMP_WARNING(EnvParallelWarn, name);
1235 return;
1236 } // read value before first parallel only
1237 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1238 &__kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001239} // __kmp_stg_parse_hot_teams_level
1240
Jonathan Peyton30419822017-05-12 18:01:32 +00001241static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1242 char const *name, void *data) {
1243 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001244} // __kmp_stg_print_hot_teams_level
1245
Jonathan Peyton30419822017-05-12 18:01:32 +00001246static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
1247 void *data) {
1248 if (TCR_4(__kmp_init_parallel)) {
1249 KMP_WARNING(EnvParallelWarn, name);
1250 return;
1251 } // read value before first parallel only
1252 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1253 &__kmp_hot_teams_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001254} // __kmp_stg_parse_hot_teams_mode
1255
Jonathan Peyton30419822017-05-12 18:01:32 +00001256static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1257 char const *name, void *data) {
1258 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00001259} // __kmp_stg_print_hot_teams_mode
1260
1261#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001262
Jonathan Peyton30419822017-05-12 18:01:32 +00001263// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001264// KMP_HANDLE_SIGNALS
Jim Cownie5e8470a2013-09-27 10:38:44 +00001265
1266#if KMP_HANDLE_SIGNALS
1267
Jonathan Peyton30419822017-05-12 18:01:32 +00001268static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
1269 void *data) {
1270 __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001271} // __kmp_stg_parse_handle_signals
1272
Jonathan Peyton30419822017-05-12 18:01:32 +00001273static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1274 char const *name, void *data) {
1275 __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001276} // __kmp_stg_print_handle_signals
1277
1278#endif // KMP_HANDLE_SIGNALS
1279
Jonathan Peyton30419822017-05-12 18:01:32 +00001280// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001281// KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
Jim Cownie5e8470a2013-09-27 10:38:44 +00001282
1283#ifdef KMP_DEBUG
1284
Jonathan Peyton30419822017-05-12 18:01:32 +00001285#define KMP_STG_X_DEBUG(x) \
1286 static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1287 void *data) { \
1288 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1289 } /* __kmp_stg_parse_x_debug */ \
1290 static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1291 char const *name, void *data) { \
1292 __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1293 } /* __kmp_stg_print_x_debug */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001294
Jonathan Peyton30419822017-05-12 18:01:32 +00001295KMP_STG_X_DEBUG(a)
1296KMP_STG_X_DEBUG(b)
1297KMP_STG_X_DEBUG(c)
1298KMP_STG_X_DEBUG(d)
1299KMP_STG_X_DEBUG(e)
1300KMP_STG_X_DEBUG(f)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001301
1302#undef KMP_STG_X_DEBUG
1303
Jonathan Peyton30419822017-05-12 18:01:32 +00001304static void __kmp_stg_parse_debug(char const *name, char const *value,
1305 void *data) {
1306 int debug = 0;
1307 __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1308 if (kmp_a_debug < debug) {
1309 kmp_a_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001310 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001311 if (kmp_b_debug < debug) {
1312 kmp_b_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001313 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001314 if (kmp_c_debug < debug) {
1315 kmp_c_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001316 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001317 if (kmp_d_debug < debug) {
1318 kmp_d_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001319 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001320 if (kmp_e_debug < debug) {
1321 kmp_e_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001322 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001323 if (kmp_f_debug < debug) {
1324 kmp_f_debug = debug;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001325 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001326} // __kmp_stg_parse_debug
1327
Jonathan Peyton30419822017-05-12 18:01:32 +00001328static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
1329 void *data) {
1330 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1331 // !!! TODO: Move buffer initialization of of this file! It may works
1332 // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
1333 // KMP_DEBUG_BUF_CHARS.
1334 if (__kmp_debug_buf) {
1335 int i;
1336 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001337
Jonathan Peyton30419822017-05-12 18:01:32 +00001338 /* allocate and initialize all entries in debug buffer to empty */
1339 __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
1340 for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1341 __kmp_debug_buffer[i] = '\0';
Jim Cownie5e8470a2013-09-27 10:38:44 +00001342
Jonathan Peyton30419822017-05-12 18:01:32 +00001343 __kmp_debug_count = 0;
1344 }
1345 K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001346} // __kmp_stg_parse_debug_buf
1347
Jonathan Peyton30419822017-05-12 18:01:32 +00001348static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
1349 void *data) {
1350 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001351} // __kmp_stg_print_debug_buf
1352
Jonathan Peyton30419822017-05-12 18:01:32 +00001353static void __kmp_stg_parse_debug_buf_atomic(char const *name,
1354 char const *value, void *data) {
1355 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001356} // __kmp_stg_parse_debug_buf_atomic
1357
Jonathan Peyton30419822017-05-12 18:01:32 +00001358static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1359 char const *name, void *data) {
1360 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001361} // __kmp_stg_print_debug_buf_atomic
1362
Jonathan Peyton30419822017-05-12 18:01:32 +00001363static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
1364 void *data) {
1365 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1366 &__kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001367} // __kmp_stg_debug_parse_buf_chars
1368
Jonathan Peyton30419822017-05-12 18:01:32 +00001369static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1370 char const *name, void *data) {
1371 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001372} // __kmp_stg_print_debug_buf_chars
1373
Jonathan Peyton30419822017-05-12 18:01:32 +00001374static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
1375 void *data) {
1376 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1377 &__kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001378} // __kmp_stg_parse_debug_buf_lines
1379
Jonathan Peyton30419822017-05-12 18:01:32 +00001380static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1381 char const *name, void *data) {
1382 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001383} // __kmp_stg_print_debug_buf_lines
1384
Jonathan Peyton30419822017-05-12 18:01:32 +00001385static void __kmp_stg_parse_diag(char const *name, char const *value,
1386 void *data) {
1387 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001388} // __kmp_stg_parse_diag
1389
Jonathan Peyton30419822017-05-12 18:01:32 +00001390static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
1391 void *data) {
1392 __kmp_stg_print_int(buffer, name, kmp_diag);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001393} // __kmp_stg_print_diag
1394
1395#endif // KMP_DEBUG
1396
Jonathan Peyton30419822017-05-12 18:01:32 +00001397// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001398// KMP_ALIGN_ALLOC
Jim Cownie5e8470a2013-09-27 10:38:44 +00001399
Jonathan Peyton30419822017-05-12 18:01:32 +00001400static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
1401 void *data) {
1402 __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1403 &__kmp_align_alloc, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001404} // __kmp_stg_parse_align_alloc
1405
Jonathan Peyton30419822017-05-12 18:01:32 +00001406static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
1407 void *data) {
1408 __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001409} // __kmp_stg_print_align_alloc
1410
Jonathan Peyton30419822017-05-12 18:01:32 +00001411// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001412// KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
Jim Cownie5e8470a2013-09-27 10:38:44 +00001413
Jonathan Peyton30419822017-05-12 18:01:32 +00001414// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
1415// parse and print functions, pass required info through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001416
Jonathan Peyton30419822017-05-12 18:01:32 +00001417static void __kmp_stg_parse_barrier_branch_bit(char const *name,
1418 char const *value, void *data) {
1419 const char *var;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001420
Jonathan Peyton30419822017-05-12 18:01:32 +00001421 /* ---------- Barrier branch bit control ------------ */
1422 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1423 var = __kmp_barrier_branch_bit_env_name[i];
1424 if ((strcmp(var, name) == 0) && (value != 0)) {
1425 char *comma;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001426
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001427 comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00001428 __kmp_barrier_gather_branch_bits[i] =
1429 (kmp_uint32)__kmp_str_to_int(value, ',');
1430 /* is there a specified release parameter? */
1431 if (comma == NULL) {
1432 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1433 } else {
1434 __kmp_barrier_release_branch_bits[i] =
1435 (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001436
Jonathan Peyton30419822017-05-12 18:01:32 +00001437 if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1438 __kmp_msg(kmp_ms_warning,
1439 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1440 __kmp_msg_null);
1441 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001442 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001443 }
1444 if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1445 KMP_WARNING(BarrGatherValueInvalid, name, value);
1446 KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1447 __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1448 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001449 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001450 K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1451 __kmp_barrier_gather_branch_bits[i],
1452 __kmp_barrier_release_branch_bits[i]))
1453 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001454} // __kmp_stg_parse_barrier_branch_bit
1455
Jonathan Peyton30419822017-05-12 18:01:32 +00001456static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1457 char const *name, void *data) {
1458 const char *var;
1459 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1460 var = __kmp_barrier_branch_bit_env_name[i];
1461 if (strcmp(var, name) == 0) {
1462 if (__kmp_env_format) {
1463 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1464 } else {
1465 __kmp_str_buf_print(buffer, " %s='",
1466 __kmp_barrier_branch_bit_env_name[i]);
1467 }
1468 __kmp_str_buf_print(buffer, "%d,%d'\n",
1469 __kmp_barrier_gather_branch_bits[i],
1470 __kmp_barrier_release_branch_bits[i]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001471 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001472 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001473} // __kmp_stg_print_barrier_branch_bit
1474
Jonathan Peyton30419822017-05-12 18:01:32 +00001475// ----------------------------------------------------------------------------
1476// KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
1477// KMP_REDUCTION_BARRIER_PATTERN
Jim Cownie5e8470a2013-09-27 10:38:44 +00001478
Jonathan Peyton30419822017-05-12 18:01:32 +00001479// TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
1480// print functions, pass required data to functions through data argument.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001481
Jonathan Peyton30419822017-05-12 18:01:32 +00001482static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
1483 void *data) {
1484 const char *var;
1485 /* ---------- Barrier method control ------------ */
Jim Cownie5e8470a2013-09-27 10:38:44 +00001486
Jonathan Peyton30419822017-05-12 18:01:32 +00001487 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1488 var = __kmp_barrier_pattern_env_name[i];
Jim Cownie5e8470a2013-09-27 10:38:44 +00001489
Jonathan Peyton30419822017-05-12 18:01:32 +00001490 if ((strcmp(var, name) == 0) && (value != 0)) {
1491 int j;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001492 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001493
Jonathan Peyton30419822017-05-12 18:01:32 +00001494 /* handle first parameter: gather pattern */
1495 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1496 if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1497 ',')) {
1498 __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1499 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001500 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001501 }
1502 if (j == bp_last_bar) {
1503 KMP_WARNING(BarrGatherValueInvalid, name, value);
1504 KMP_INFORM(Using_str_Value, name,
1505 __kmp_barrier_pattern_name[bp_linear_bar]);
1506 }
1507
1508 /* handle second parameter: release pattern */
1509 if (comma != NULL) {
1510 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1511 if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1512 __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1513 break;
1514 }
1515 }
1516 if (j == bp_last_bar) {
1517 __kmp_msg(kmp_ms_warning,
1518 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1519 __kmp_msg_null);
1520 KMP_INFORM(Using_str_Value, name,
1521 __kmp_barrier_pattern_name[bp_linear_bar]);
1522 }
1523 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001524 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001525 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001526} // __kmp_stg_parse_barrier_pattern
1527
Jonathan Peyton30419822017-05-12 18:01:32 +00001528static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1529 char const *name, void *data) {
1530 const char *var;
1531 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1532 var = __kmp_barrier_pattern_env_name[i];
1533 if (strcmp(var, name) == 0) {
1534 int j = __kmp_barrier_gather_pattern[i];
1535 int k = __kmp_barrier_release_pattern[i];
1536 if (__kmp_env_format) {
1537 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1538 } else {
1539 __kmp_str_buf_print(buffer, " %s='",
1540 __kmp_barrier_pattern_env_name[i]);
1541 }
1542 __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
1543 __kmp_barrier_pattern_name[k]);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001544 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001545 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001546} // __kmp_stg_print_barrier_pattern
1547
Jonathan Peyton30419822017-05-12 18:01:32 +00001548// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001549// KMP_ABORT_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00001550
Jonathan Peyton30419822017-05-12 18:01:32 +00001551static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
1552 void *data) {
1553 // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
1554 // milliseconds.
1555 int delay = __kmp_abort_delay / 1000;
1556 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1557 __kmp_abort_delay = delay * 1000;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001558} // __kmp_stg_parse_abort_delay
1559
Jonathan Peyton30419822017-05-12 18:01:32 +00001560static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
1561 void *data) {
1562 __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001563} // __kmp_stg_print_abort_delay
1564
Jonathan Peyton30419822017-05-12 18:01:32 +00001565// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001566// KMP_CPUINFO_FILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001567
Jonathan Peyton30419822017-05-12 18:01:32 +00001568static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
1569 void *data) {
1570#if KMP_AFFINITY_SUPPORTED
1571 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1572 K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1573#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001574} //__kmp_stg_parse_cpuinfo_file
1575
Jonathan Peyton30419822017-05-12 18:01:32 +00001576static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1577 char const *name, void *data) {
1578#if KMP_AFFINITY_SUPPORTED
1579 if (__kmp_env_format) {
1580 KMP_STR_BUF_PRINT_NAME;
1581 } else {
1582 __kmp_str_buf_print(buffer, " %s", name);
1583 }
1584 if (__kmp_cpuinfo_file) {
1585 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
1586 } else {
1587 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1588 }
1589#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00001590} //__kmp_stg_print_cpuinfo_file
1591
Jonathan Peyton30419822017-05-12 18:01:32 +00001592// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001593// KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
Jim Cownie5e8470a2013-09-27 10:38:44 +00001594
Jonathan Peyton30419822017-05-12 18:01:32 +00001595static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
1596 void *data) {
1597 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1598 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001599
Jonathan Peyton30419822017-05-12 18:01:32 +00001600 rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1601 if (rc) {
1602 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001603 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001604 if (reduction->force) {
1605 if (value != 0) {
1606 if (__kmp_str_match("critical", 0, value))
1607 __kmp_force_reduction_method = critical_reduce_block;
1608 else if (__kmp_str_match("atomic", 0, value))
1609 __kmp_force_reduction_method = atomic_reduce_block;
1610 else if (__kmp_str_match("tree", 0, value))
1611 __kmp_force_reduction_method = tree_reduce_block;
1612 else {
1613 KMP_FATAL(UnknownForceReduction, name, value);
1614 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001615 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001616 } else {
1617 __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1618 if (__kmp_determ_red) {
1619 __kmp_force_reduction_method = tree_reduce_block;
1620 } else {
1621 __kmp_force_reduction_method = reduction_method_not_defined;
1622 }
1623 }
1624 K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
1625 __kmp_force_reduction_method));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001626} // __kmp_stg_parse_force_reduction
1627
Jonathan Peyton30419822017-05-12 18:01:32 +00001628static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1629 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00001630
Jonathan Peyton30419822017-05-12 18:01:32 +00001631 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1632 if (reduction->force) {
1633 if (__kmp_force_reduction_method == critical_reduce_block) {
1634 __kmp_stg_print_str(buffer, name, "critical");
1635 } else if (__kmp_force_reduction_method == atomic_reduce_block) {
1636 __kmp_stg_print_str(buffer, name, "atomic");
1637 } else if (__kmp_force_reduction_method == tree_reduce_block) {
1638 __kmp_stg_print_str(buffer, name, "tree");
Jim Cownie5e8470a2013-09-27 10:38:44 +00001639 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00001640 if (__kmp_env_format) {
1641 KMP_STR_BUF_PRINT_NAME;
1642 } else {
1643 __kmp_str_buf_print(buffer, " %s", name);
1644 }
1645 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00001646 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001647 } else {
1648 __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1649 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001650
1651} // __kmp_stg_print_force_reduction
1652
Jonathan Peyton30419822017-05-12 18:01:32 +00001653// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001654// KMP_STORAGE_MAP
Jim Cownie5e8470a2013-09-27 10:38:44 +00001655
Jonathan Peyton30419822017-05-12 18:01:32 +00001656static void __kmp_stg_parse_storage_map(char const *name, char const *value,
1657 void *data) {
1658 if (__kmp_str_match("verbose", 1, value)) {
1659 __kmp_storage_map = TRUE;
1660 __kmp_storage_map_verbose = TRUE;
1661 __kmp_storage_map_verbose_specified = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001662
Jonathan Peyton30419822017-05-12 18:01:32 +00001663 } else {
1664 __kmp_storage_map_verbose = FALSE;
1665 __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001666 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001667} // __kmp_stg_parse_storage_map
1668
Jonathan Peyton30419822017-05-12 18:01:32 +00001669static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
1670 void *data) {
1671 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1672 __kmp_stg_print_str(buffer, name, "verbose");
1673 } else {
1674 __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1675 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001676} // __kmp_stg_print_storage_map
1677
Jonathan Peyton30419822017-05-12 18:01:32 +00001678// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001679// KMP_ALL_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001680
Jonathan Peyton30419822017-05-12 18:01:32 +00001681static void __kmp_stg_parse_all_threadprivate(char const *name,
1682 char const *value, void *data) {
1683 __kmp_stg_parse_int(name, value,
1684 __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1685 __kmp_max_nth, &__kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001686} // __kmp_stg_parse_all_threadprivate
1687
Jonathan Peyton30419822017-05-12 18:01:32 +00001688static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1689 char const *name, void *data) {
1690 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001691}
1692
Jonathan Peyton30419822017-05-12 18:01:32 +00001693// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001694// KMP_FOREIGN_THREADS_THREADPRIVATE
Jim Cownie5e8470a2013-09-27 10:38:44 +00001695
Jonathan Peyton30419822017-05-12 18:01:32 +00001696static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
1697 char const *value,
1698 void *data) {
1699 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001700} // __kmp_stg_parse_foreign_threads_threadprivate
1701
Jonathan Peyton30419822017-05-12 18:01:32 +00001702static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
1703 char const *name,
1704 void *data) {
1705 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001706} // __kmp_stg_print_foreign_threads_threadprivate
1707
Jonathan Peyton30419822017-05-12 18:01:32 +00001708// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00001709// KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
Jim Cownie5e8470a2013-09-27 10:38:44 +00001710
Alp Toker98758b02014-03-02 04:12:06 +00001711#if KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00001712// Parse the proc id list. Return TRUE if successful, FALSE otherwise.
Jonathan Peyton30419822017-05-12 18:01:32 +00001713static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
1714 const char **nextEnv,
1715 char **proclist) {
1716 const char *scan = env;
1717 const char *next = scan;
1718 int empty = TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001719
Jonathan Peyton30419822017-05-12 18:01:32 +00001720 *proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001721
Jonathan Peyton30419822017-05-12 18:01:32 +00001722 for (;;) {
1723 int start, end, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001724
Jonathan Peyton30419822017-05-12 18:01:32 +00001725 SKIP_WS(scan);
1726 next = scan;
1727 if (*next == '\0') {
1728 break;
1729 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001730
Jonathan Peyton30419822017-05-12 18:01:32 +00001731 if (*next == '{') {
1732 int num;
1733 next++; // skip '{'
1734 SKIP_WS(next);
1735 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001736
Jonathan Peyton30419822017-05-12 18:01:32 +00001737 // Read the first integer in the set.
1738 if ((*next < '0') || (*next > '9')) {
1739 KMP_WARNING(AffSyntaxError, var);
1740 return FALSE;
1741 }
1742 SKIP_DIGITS(next);
1743 num = __kmp_str_to_int(scan, *next);
1744 KMP_ASSERT(num >= 0);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001745
Jonathan Peyton30419822017-05-12 18:01:32 +00001746 for (;;) {
1747 // Check for end of set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001748 SKIP_WS(next);
Jonathan Peyton30419822017-05-12 18:01:32 +00001749 if (*next == '}') {
1750 next++; // skip '}'
1751 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001752 }
1753
Jim Cownie5e8470a2013-09-27 10:38:44 +00001754 // Skip optional comma.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001755 if (*next == ',') {
Jonathan Peyton30419822017-05-12 18:01:32 +00001756 next++;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001757 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001758 SKIP_WS(next);
1759
1760 // Read the next integer in the set.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001761 scan = next;
Jonathan Peyton30419822017-05-12 18:01:32 +00001762 if ((*next < '0') || (*next > '9')) {
1763 KMP_WARNING(AffSyntaxError, var);
1764 return FALSE;
1765 }
1766
1767 SKIP_DIGITS(next);
1768 num = __kmp_str_to_int(scan, *next);
1769 KMP_ASSERT(num >= 0);
1770 }
1771 empty = FALSE;
1772
1773 SKIP_WS(next);
1774 if (*next == ',') {
1775 next++;
1776 }
1777 scan = next;
1778 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001779 }
1780
Jonathan Peyton30419822017-05-12 18:01:32 +00001781 // Next character is not an integer => end of list
1782 if ((*next < '0') || (*next > '9')) {
1783 if (empty) {
1784 KMP_WARNING(AffSyntaxError, var);
1785 return FALSE;
1786 }
1787 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001788 }
Jonathan Peyton30419822017-05-12 18:01:32 +00001789
1790 // Read the first integer.
1791 SKIP_DIGITS(next);
1792 start = __kmp_str_to_int(scan, *next);
1793 KMP_ASSERT(start >= 0);
1794 SKIP_WS(next);
1795
1796 // If this isn't a range, then go on.
1797 if (*next != '-') {
1798 empty = FALSE;
1799
1800 // Skip optional comma.
1801 if (*next == ',') {
1802 next++;
1803 }
1804 scan = next;
1805 continue;
1806 }
1807
1808 // This is a range. Skip over the '-' and read in the 2nd int.
1809 next++; // skip '-'
1810 SKIP_WS(next);
1811 scan = next;
1812 if ((*next < '0') || (*next > '9')) {
1813 KMP_WARNING(AffSyntaxError, var);
1814 return FALSE;
1815 }
1816 SKIP_DIGITS(next);
1817 end = __kmp_str_to_int(scan, *next);
1818 KMP_ASSERT(end >= 0);
1819
1820 // Check for a stride parameter
1821 stride = 1;
1822 SKIP_WS(next);
1823 if (*next == ':') {
1824 // A stride is specified. Skip over the ':" and read the 3rd int.
1825 int sign = +1;
1826 next++; // skip ':'
1827 SKIP_WS(next);
1828 scan = next;
1829 if (*next == '-') {
1830 sign = -1;
1831 next++;
1832 SKIP_WS(next);
1833 scan = next;
1834 }
1835 if ((*next < '0') || (*next > '9')) {
1836 KMP_WARNING(AffSyntaxError, var);
1837 return FALSE;
1838 }
1839 SKIP_DIGITS(next);
1840 stride = __kmp_str_to_int(scan, *next);
1841 KMP_ASSERT(stride >= 0);
1842 stride *= sign;
1843 }
1844
1845 // Do some range checks.
1846 if (stride == 0) {
1847 KMP_WARNING(AffZeroStride, var);
1848 return FALSE;
1849 }
1850 if (stride > 0) {
1851 if (start > end) {
1852 KMP_WARNING(AffStartGreaterEnd, var, start, end);
1853 return FALSE;
1854 }
1855 } else {
1856 if (start < end) {
1857 KMP_WARNING(AffStrideLessZero, var, start, end);
1858 return FALSE;
1859 }
1860 }
1861 if ((end - start) / stride > 65536) {
1862 KMP_WARNING(AffRangeTooBig, var, end, start, stride);
1863 return FALSE;
1864 }
1865
1866 empty = FALSE;
1867
1868 // Skip optional comma.
1869 SKIP_WS(next);
1870 if (*next == ',') {
1871 next++;
1872 }
1873 scan = next;
1874 }
1875
1876 *nextEnv = next;
1877
1878 {
1879 int len = next - env;
1880 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
1881 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
1882 retlist[len] = '\0';
1883 *proclist = retlist;
1884 }
1885 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001886}
1887
Jim Cownie5e8470a2013-09-27 10:38:44 +00001888// If KMP_AFFINITY is specified without a type, then
1889// __kmp_affinity_notype should point to its setting.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001890static kmp_setting_t *__kmp_affinity_notype = NULL;
1891
Jonathan Peyton30419822017-05-12 18:01:32 +00001892static void __kmp_parse_affinity_env(char const *name, char const *value,
1893 enum affinity_type *out_type,
1894 char **out_proclist, int *out_verbose,
1895 int *out_warn, int *out_respect,
1896 enum affinity_gran *out_gran,
1897 int *out_gran_levels, int *out_dups,
1898 int *out_compact, int *out_offset) {
1899 char *buffer = NULL; // Copy of env var value.
1900 char *buf = NULL; // Buffer for strtok_r() function.
1901 char *next = NULL; // end of token / start of next.
1902 const char *start; // start of current token (for err msgs)
1903 int count = 0; // Counter of parsed integer numbers.
1904 int number[2]; // Parsed numbers.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001905
Jonathan Peyton30419822017-05-12 18:01:32 +00001906 // Guards.
1907 int type = 0;
1908 int proclist = 0;
1909 int max_proclist = 0;
1910 int verbose = 0;
1911 int warnings = 0;
1912 int respect = 0;
1913 int gran = 0;
1914 int dups = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00001915
Jonathan Peyton30419822017-05-12 18:01:32 +00001916 KMP_ASSERT(value != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001917
Jonathan Peyton30419822017-05-12 18:01:32 +00001918 if (TCR_4(__kmp_init_middle)) {
1919 KMP_WARNING(EnvMiddleWarn, name);
1920 __kmp_env_toPrint(name, 0);
1921 return;
1922 }
1923 __kmp_env_toPrint(name, 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001924
Jonathan Peyton30419822017-05-12 18:01:32 +00001925 buffer =
1926 __kmp_str_format("%s", value); // Copy env var to keep original intact.
1927 buf = buffer;
1928 SKIP_WS(buf);
Jim Cownie5e8470a2013-09-27 10:38:44 +00001929
Jonathan Peyton30419822017-05-12 18:01:32 +00001930// Helper macros.
Jim Cownie5e8470a2013-09-27 10:38:44 +00001931
Jonathan Peyton30419822017-05-12 18:01:32 +00001932// If we see a parse error, emit a warning and scan to the next ",".
1933//
1934// FIXME - there's got to be a better way to print an error
1935// message, hopefully without overwritting peices of buf.
1936#define EMIT_WARN(skip, errlist) \
1937 { \
1938 char ch; \
1939 if (skip) { \
1940 SKIP_TO(next, ','); \
1941 } \
1942 ch = *next; \
1943 *next = '\0'; \
1944 KMP_WARNING errlist; \
1945 *next = ch; \
1946 if (skip) { \
1947 if (ch == ',') \
1948 next++; \
1949 } \
1950 buf = next; \
1951 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001952
Jonathan Peyton30419822017-05-12 18:01:32 +00001953#define _set_param(_guard, _var, _val) \
1954 { \
1955 if (_guard == 0) { \
1956 _var = _val; \
1957 } else { \
1958 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001959 } \
Jonathan Peyton30419822017-05-12 18:01:32 +00001960 ++_guard; \
1961 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001962
Jonathan Peyton30419822017-05-12 18:01:32 +00001963#define set_type(val) _set_param(type, *out_type, val)
1964#define set_verbose(val) _set_param(verbose, *out_verbose, val)
1965#define set_warnings(val) _set_param(warnings, *out_warn, val)
1966#define set_respect(val) _set_param(respect, *out_respect, val)
1967#define set_dups(val) _set_param(dups, *out_dups, val)
1968#define set_proclist(val) _set_param(proclist, *out_proclist, val)
Jim Cownie5e8470a2013-09-27 10:38:44 +00001969
Jonathan Peyton30419822017-05-12 18:01:32 +00001970#define set_gran(val, levels) \
1971 { \
1972 if (gran == 0) { \
1973 *out_gran = val; \
1974 *out_gran_levels = levels; \
1975 } else { \
1976 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00001977 } \
Jonathan Peyton30419822017-05-12 18:01:32 +00001978 ++gran; \
1979 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00001980
Jonathan Peyton30419822017-05-12 18:01:32 +00001981#if OMP_40_ENABLED
1982 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
1983 (__kmp_nested_proc_bind.used > 0));
Andrey Churbanov613edeb2015-02-20 18:14:43 +00001984#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00001985
1986 while (*buf != '\0') {
1987 start = next = buf;
1988
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001989 if (__kmp_match_str("none", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001990 set_type(affinity_none);
1991#if OMP_40_ENABLED
1992 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
1993#endif
1994 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00001995 } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00001996 set_type(affinity_scatter);
1997#if OMP_40_ENABLED
1998 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
1999#endif
2000 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002001 } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002002 set_type(affinity_compact);
2003#if OMP_40_ENABLED
2004 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2005#endif
2006 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002007 } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002008 set_type(affinity_logical);
2009#if OMP_40_ENABLED
2010 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2011#endif
2012 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002013 } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002014 set_type(affinity_physical);
2015#if OMP_40_ENABLED
2016 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2017#endif
2018 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002019 } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002020 set_type(affinity_explicit);
2021#if OMP_40_ENABLED
2022 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2023#endif
2024 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002025 } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002026 set_type(affinity_balanced);
2027#if OMP_40_ENABLED
2028 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2029#endif
2030 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002031 } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002032 set_type(affinity_disabled);
2033#if OMP_40_ENABLED
2034 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2035#endif
2036 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002037 } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002038 set_verbose(TRUE);
2039 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002040 } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002041 set_verbose(FALSE);
2042 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002043 } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002044 set_warnings(TRUE);
2045 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002046 } else if (__kmp_match_str("nowarnings", buf,
2047 CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002048 set_warnings(FALSE);
2049 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002050 } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002051 set_respect(TRUE);
2052 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002053 } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002054 set_respect(FALSE);
2055 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002056 } else if (__kmp_match_str("duplicates", buf,
2057 CCAST(const char **, &next)) ||
2058 __kmp_match_str("dups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002059 set_dups(TRUE);
2060 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002061 } else if (__kmp_match_str("noduplicates", buf,
2062 CCAST(const char **, &next)) ||
2063 __kmp_match_str("nodups", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002064 set_dups(FALSE);
2065 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002066 } else if (__kmp_match_str("granularity", buf,
2067 CCAST(const char **, &next)) ||
2068 __kmp_match_str("gran", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002069 SKIP_WS(next);
2070 if (*next != '=') {
2071 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2072 continue;
2073 }
2074 next++; // skip '='
2075 SKIP_WS(next);
2076
2077 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002078 if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002079 set_gran(affinity_gran_fine, -1);
2080 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002081 } else if (__kmp_match_str("thread", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002082 set_gran(affinity_gran_thread, -1);
2083 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002084 } else if (__kmp_match_str("core", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002085 set_gran(affinity_gran_core, -1);
2086 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002087 } else if (__kmp_match_str("package", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002088 set_gran(affinity_gran_package, -1);
2089 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002090 } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002091 set_gran(affinity_gran_node, -1);
2092 buf = next;
2093#if KMP_GROUP_AFFINITY
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002094 } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002095 set_gran(affinity_gran_group, -1);
2096 buf = next;
2097#endif /* KMP_GROUP AFFINITY */
2098 } else if ((*buf >= '0') && (*buf <= '9')) {
2099 int n;
2100 next = buf;
2101 SKIP_DIGITS(next);
2102 n = __kmp_str_to_int(buf, *next);
2103 KMP_ASSERT(n >= 0);
2104 buf = next;
2105 set_gran(affinity_gran_default, n);
2106 } else {
2107 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2108 continue;
2109 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002110 } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002111 char *temp_proclist;
2112
2113 SKIP_WS(next);
2114 if (*next != '=') {
2115 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2116 continue;
2117 }
2118 next++; // skip '='
2119 SKIP_WS(next);
2120 if (*next != '[') {
2121 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2122 continue;
2123 }
2124 next++; // skip '['
2125 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002126 if (!__kmp_parse_affinity_proc_id_list(
2127 name, buf, CCAST(const char **, &next), &temp_proclist)) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002128 // warning already emitted.
2129 SKIP_TO(next, ']');
2130 if (*next == ']')
2131 next++;
2132 SKIP_TO(next, ',');
2133 if (*next == ',')
2134 next++;
2135 buf = next;
2136 continue;
2137 }
2138 if (*next != ']') {
2139 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2140 continue;
2141 }
2142 next++; // skip ']'
2143 set_proclist(temp_proclist);
2144 } else if ((*buf >= '0') && (*buf <= '9')) {
2145 // Parse integer numbers -- permute and offset.
2146 int n;
2147 next = buf;
2148 SKIP_DIGITS(next);
2149 n = __kmp_str_to_int(buf, *next);
2150 KMP_ASSERT(n >= 0);
2151 buf = next;
2152 if (count < 2) {
2153 number[count] = n;
2154 } else {
2155 KMP_WARNING(AffManyParams, name, start);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002156 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002157 ++count;
2158 } else {
2159 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2160 continue;
2161 }
2162
2163 SKIP_WS(next);
2164 if (*next == ',') {
2165 next++;
2166 SKIP_WS(next);
2167 } else if (*next != '\0') {
2168 const char *temp = next;
2169 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2170 continue;
2171 }
2172 buf = next;
2173 } // while
2174
2175#undef EMIT_WARN
2176#undef _set_param
2177#undef set_type
2178#undef set_verbose
2179#undef set_warnings
2180#undef set_respect
2181#undef set_granularity
2182
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002183 __kmp_str_free(CCAST(const char **, &buffer));
Jonathan Peyton30419822017-05-12 18:01:32 +00002184
2185 if (proclist) {
2186 if (!type) {
2187 KMP_WARNING(AffProcListNoType, name);
2188 *out_type = affinity_explicit;
2189#if OMP_40_ENABLED
2190 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2191#endif
2192 } else if (*out_type != affinity_explicit) {
2193 KMP_WARNING(AffProcListNotExplicit, name);
2194 KMP_ASSERT(*out_proclist != NULL);
2195 KMP_INTERNAL_FREE(*out_proclist);
2196 *out_proclist = NULL;
2197 }
2198 }
2199 switch (*out_type) {
2200 case affinity_logical:
2201 case affinity_physical: {
2202 if (count > 0) {
2203 *out_offset = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002204 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002205 if (count > 1) {
2206 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002207 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002208 } break;
2209 case affinity_balanced: {
2210 if (count > 0) {
2211 *out_compact = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002212 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002213 if (count > 1) {
2214 *out_offset = number[1];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002215 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002216
2217 if (__kmp_affinity_gran == affinity_gran_default) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002218#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002219 if (__kmp_mic_type != non_mic) {
2220 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2221 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine");
2222 }
2223 __kmp_affinity_gran = affinity_gran_fine;
2224 } else
2225#endif
2226 {
2227 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2228 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core");
2229 }
2230 __kmp_affinity_gran = affinity_gran_core;
2231 }
2232 }
2233 } break;
2234 case affinity_scatter:
2235 case affinity_compact: {
2236 if (count > 0) {
2237 *out_compact = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002238 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002239 if (count > 1) {
2240 *out_offset = number[1];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002241 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002242 } break;
2243 case affinity_explicit: {
2244 if (*out_proclist == NULL) {
2245 KMP_WARNING(AffNoProcList, name);
2246 __kmp_affinity_type = affinity_none;
2247 }
2248 if (count > 0) {
2249 KMP_WARNING(AffNoParam, name, "explicit");
2250 }
2251 } break;
2252 case affinity_none: {
2253 if (count > 0) {
2254 KMP_WARNING(AffNoParam, name, "none");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002255 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002256 } break;
2257 case affinity_disabled: {
2258 if (count > 0) {
2259 KMP_WARNING(AffNoParam, name, "disabled");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002260 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002261 } break;
2262 case affinity_default: {
2263 if (count > 0) {
2264 KMP_WARNING(AffNoParam, name, "default");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002265 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002266 } break;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002267 default: { KMP_ASSERT(0); }
2268 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002269} // __kmp_parse_affinity_env
2270
Jonathan Peyton30419822017-05-12 18:01:32 +00002271static void __kmp_stg_parse_affinity(char const *name, char const *value,
2272 void *data) {
2273 kmp_setting_t **rivals = (kmp_setting_t **)data;
2274 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002275
Jonathan Peyton30419822017-05-12 18:01:32 +00002276 rc = __kmp_stg_check_rivals(name, value, rivals);
2277 if (rc) {
2278 return;
2279 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002280
Jonathan Peyton30419822017-05-12 18:01:32 +00002281 __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2282 &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2283 &__kmp_affinity_warnings,
2284 &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2285 &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2286 &__kmp_affinity_compact, &__kmp_affinity_offset);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002287
2288} // __kmp_stg_parse_affinity
2289
Jonathan Peyton30419822017-05-12 18:01:32 +00002290static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
2291 void *data) {
2292 if (__kmp_env_format) {
2293 KMP_STR_BUF_PRINT_NAME_EX(name);
2294 } else {
2295 __kmp_str_buf_print(buffer, " %s='", name);
2296 }
2297 if (__kmp_affinity_verbose) {
2298 __kmp_str_buf_print(buffer, "%s,", "verbose");
2299 } else {
2300 __kmp_str_buf_print(buffer, "%s,", "noverbose");
2301 }
2302 if (__kmp_affinity_warnings) {
2303 __kmp_str_buf_print(buffer, "%s,", "warnings");
2304 } else {
2305 __kmp_str_buf_print(buffer, "%s,", "nowarnings");
2306 }
2307 if (KMP_AFFINITY_CAPABLE()) {
2308 if (__kmp_affinity_respect_mask) {
2309 __kmp_str_buf_print(buffer, "%s,", "respect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002310 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002311 __kmp_str_buf_print(buffer, "%s,", "norespect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002312 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002313 switch (__kmp_affinity_gran) {
2314 case affinity_gran_default:
2315 __kmp_str_buf_print(buffer, "%s", "granularity=default,");
2316 break;
2317 case affinity_gran_fine:
2318 __kmp_str_buf_print(buffer, "%s", "granularity=fine,");
2319 break;
2320 case affinity_gran_thread:
2321 __kmp_str_buf_print(buffer, "%s", "granularity=thread,");
2322 break;
2323 case affinity_gran_core:
2324 __kmp_str_buf_print(buffer, "%s", "granularity=core,");
2325 break;
2326 case affinity_gran_package:
2327 __kmp_str_buf_print(buffer, "%s", "granularity=package,");
2328 break;
2329 case affinity_gran_node:
2330 __kmp_str_buf_print(buffer, "%s", "granularity=node,");
2331 break;
2332#if KMP_GROUP_AFFINITY
2333 case affinity_gran_group:
2334 __kmp_str_buf_print(buffer, "%s", "granularity=group,");
2335 break;
2336#endif /* KMP_GROUP_AFFINITY */
2337 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002338 }
2339 if (!KMP_AFFINITY_CAPABLE()) {
2340 __kmp_str_buf_print(buffer, "%s", "disabled");
2341 } else
2342 switch (__kmp_affinity_type) {
2343 case affinity_none:
2344 __kmp_str_buf_print(buffer, "%s", "none");
2345 break;
2346 case affinity_physical:
2347 __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset);
2348 break;
2349 case affinity_logical:
2350 __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset);
2351 break;
2352 case affinity_compact:
2353 __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact,
2354 __kmp_affinity_offset);
2355 break;
2356 case affinity_scatter:
2357 __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact,
2358 __kmp_affinity_offset);
2359 break;
2360 case affinity_explicit:
2361 __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist",
2362 __kmp_affinity_proclist, "explicit");
2363 break;
2364 case affinity_balanced:
2365 __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced",
2366 __kmp_affinity_compact, __kmp_affinity_offset);
2367 break;
2368 case affinity_disabled:
2369 __kmp_str_buf_print(buffer, "%s", "disabled");
2370 break;
2371 case affinity_default:
2372 __kmp_str_buf_print(buffer, "%s", "default");
2373 break;
2374 default:
2375 __kmp_str_buf_print(buffer, "%s", "<unknown>");
2376 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002377 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002378 __kmp_str_buf_print(buffer, "'\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002379} //__kmp_stg_print_affinity
2380
Jonathan Peyton30419822017-05-12 18:01:32 +00002381#ifdef KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00002382
Jonathan Peyton30419822017-05-12 18:01:32 +00002383static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
2384 char const *value, void *data) {
2385 const char *next = NULL;
2386 char *temp_proclist;
2387 kmp_setting_t **rivals = (kmp_setting_t **)data;
2388 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002389
Jonathan Peyton30419822017-05-12 18:01:32 +00002390 rc = __kmp_stg_check_rivals(name, value, rivals);
2391 if (rc) {
2392 return;
2393 }
2394
2395 if (TCR_4(__kmp_init_middle)) {
2396 KMP_WARNING(EnvMiddleWarn, name);
2397 __kmp_env_toPrint(name, 0);
2398 return;
2399 }
2400
2401 __kmp_env_toPrint(name, 1);
2402
2403 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2404 SKIP_WS(next);
2405 if (*next == '\0') {
2406 // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2407 __kmp_affinity_proclist = temp_proclist;
2408 __kmp_affinity_type = affinity_explicit;
2409 __kmp_affinity_gran = affinity_gran_fine;
2410#if OMP_40_ENABLED
2411 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2412#endif
2413 } else {
2414 KMP_WARNING(AffSyntaxError, name);
2415 if (temp_proclist != NULL) {
2416 KMP_INTERNAL_FREE((void *)temp_proclist);
2417 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002418 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002419 } else {
2420 // Warning already emitted
2421 __kmp_affinity_type = affinity_none;
2422#if OMP_40_ENABLED
2423 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2424#endif
2425 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002426} // __kmp_stg_parse_gomp_cpu_affinity
2427
Jonathan Peyton30419822017-05-12 18:01:32 +00002428#endif /* KMP_GOMP_COMPAT */
Jim Cownie5e8470a2013-09-27 10:38:44 +00002429
Jonathan Peyton30419822017-05-12 18:01:32 +00002430#if OMP_40_ENABLED
Jim Cownie5e8470a2013-09-27 10:38:44 +00002431
2432/*-----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00002433The OMP_PLACES proc id list parser. Here is the grammar:
2434
2435place_list := place
2436place_list := place , place_list
2437place := num
2438place := place : num
2439place := place : num : signed
2440place := { subplacelist }
2441place := ! place // (lowest priority)
2442subplace_list := subplace
2443subplace_list := subplace , subplace_list
2444subplace := num
2445subplace := num : num
2446subplace := num : num : signed
2447signed := num
2448signed := + signed
2449signed := - signed
Jim Cownie5e8470a2013-09-27 10:38:44 +00002450-----------------------------------------------------------------------------*/
2451
Jonathan Peyton30419822017-05-12 18:01:32 +00002452static int __kmp_parse_subplace_list(const char *var, const char **scan) {
2453 const char *next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002454
Jonathan Peyton30419822017-05-12 18:01:32 +00002455 for (;;) {
2456 int start, count, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002457
2458 //
Jonathan Peyton30419822017-05-12 18:01:32 +00002459 // Read in the starting proc id
Jim Cownie5e8470a2013-09-27 10:38:44 +00002460 //
2461 SKIP_WS(*scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002462 if ((**scan < '0') || (**scan > '9')) {
2463 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2464 return FALSE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002465 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002466 next = *scan;
2467 SKIP_DIGITS(next);
2468 start = __kmp_str_to_int(*scan, *next);
2469 KMP_ASSERT(start >= 0);
2470 *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002471
Jonathan Peyton30419822017-05-12 18:01:32 +00002472 // valid follow sets are ',' ':' and '}'
2473 SKIP_WS(*scan);
2474 if (**scan == '}') {
2475 break;
2476 }
2477 if (**scan == ',') {
2478 (*scan)++; // skip ','
2479 continue;
2480 }
2481 if (**scan != ':') {
2482 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2483 return FALSE;
2484 }
2485 (*scan)++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002486
Jonathan Peyton30419822017-05-12 18:01:32 +00002487 // Read count parameter
2488 SKIP_WS(*scan);
2489 if ((**scan < '0') || (**scan > '9')) {
2490 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2491 return FALSE;
2492 }
2493 next = *scan;
2494 SKIP_DIGITS(next);
2495 count = __kmp_str_to_int(*scan, *next);
2496 KMP_ASSERT(count >= 0);
2497 *scan = next;
2498
2499 // valid follow sets are ',' ':' and '}'
2500 SKIP_WS(*scan);
2501 if (**scan == '}') {
2502 break;
2503 }
2504 if (**scan == ',') {
2505 (*scan)++; // skip ','
2506 continue;
2507 }
2508 if (**scan != ':') {
2509 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2510 return FALSE;
2511 }
2512 (*scan)++; // skip ':'
2513
2514 // Read stride parameter
2515 int sign = +1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002516 for (;;) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002517 SKIP_WS(*scan);
2518 if (**scan == '+') {
2519 (*scan)++; // skip '+'
2520 continue;
2521 }
2522 if (**scan == '-') {
2523 sign *= -1;
2524 (*scan)++; // skip '-'
2525 continue;
2526 }
2527 break;
2528 }
2529 SKIP_WS(*scan);
2530 if ((**scan < '0') || (**scan > '9')) {
2531 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2532 return FALSE;
2533 }
2534 next = *scan;
2535 SKIP_DIGITS(next);
2536 stride = __kmp_str_to_int(*scan, *next);
2537 KMP_ASSERT(stride >= 0);
2538 *scan = next;
2539 stride *= sign;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002540
Jonathan Peyton30419822017-05-12 18:01:32 +00002541 // valid follow sets are ',' and '}'
2542 SKIP_WS(*scan);
2543 if (**scan == '}') {
2544 break;
2545 }
2546 if (**scan == ',') {
2547 (*scan)++; // skip ','
2548 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002549 }
2550
Jonathan Peyton30419822017-05-12 18:01:32 +00002551 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2552 return FALSE;
2553 }
2554 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002555}
2556
Jonathan Peyton30419822017-05-12 18:01:32 +00002557static int __kmp_parse_place(const char *var, const char **scan) {
2558 const char *next;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002559
Jonathan Peyton30419822017-05-12 18:01:32 +00002560 // valid follow sets are '{' '!' and num
2561 SKIP_WS(*scan);
2562 if (**scan == '{') {
2563 (*scan)++; // skip '{'
2564 if (!__kmp_parse_subplace_list(var, scan)) {
2565 return FALSE;
2566 }
2567 if (**scan != '}') {
2568 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2569 return FALSE;
2570 }
2571 (*scan)++; // skip '}'
2572 } else if (**scan == '!') {
2573 (*scan)++; // skip '!'
2574 return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2575 } else if ((**scan >= '0') && (**scan <= '9')) {
2576 next = *scan;
2577 SKIP_DIGITS(next);
2578 int proc = __kmp_str_to_int(*scan, *next);
2579 KMP_ASSERT(proc >= 0);
2580 *scan = next;
2581 } else {
2582 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2583 return FALSE;
2584 }
2585 return TRUE;
2586}
2587
2588static int __kmp_parse_place_list(const char *var, const char *env,
2589 char **place_list) {
2590 const char *scan = env;
2591 const char *next = scan;
2592
2593 for (;;) {
2594 int start, count, stride;
2595
2596 if (!__kmp_parse_place(var, &scan)) {
2597 return FALSE;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002598 }
2599
Jonathan Peyton30419822017-05-12 18:01:32 +00002600 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002601 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002602 if (*scan == '\0') {
2603 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002604 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002605 if (*scan == ',') {
2606 scan++; // skip ','
2607 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002608 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002609 if (*scan != ':') {
2610 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2611 return FALSE;
2612 }
2613 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002614
Jonathan Peyton30419822017-05-12 18:01:32 +00002615 // Read count parameter
Jim Cownie5e8470a2013-09-27 10:38:44 +00002616 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002617 if ((*scan < '0') || (*scan > '9')) {
2618 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2619 return FALSE;
2620 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002621 next = scan;
2622 SKIP_DIGITS(next);
2623 count = __kmp_str_to_int(scan, *next);
2624 KMP_ASSERT(count >= 0);
2625 scan = next;
2626
Jonathan Peyton30419822017-05-12 18:01:32 +00002627 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002628 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002629 if (*scan == '\0') {
2630 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002631 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002632 if (*scan == ',') {
2633 scan++; // skip ','
2634 continue;
2635 }
2636 if (*scan != ':') {
2637 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2638 return FALSE;
2639 }
2640 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002641
Jonathan Peyton30419822017-05-12 18:01:32 +00002642 // Read stride parameter
2643 int sign = +1;
2644 for (;;) {
2645 SKIP_WS(scan);
2646 if (*scan == '+') {
2647 scan++; // skip '+'
2648 continue;
2649 }
2650 if (*scan == '-') {
2651 sign *= -1;
2652 scan++; // skip '-'
2653 continue;
2654 }
2655 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002656 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002657 SKIP_WS(scan);
2658 if ((*scan < '0') || (*scan > '9')) {
2659 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2660 return FALSE;
2661 }
2662 next = scan;
2663 SKIP_DIGITS(next);
2664 stride = __kmp_str_to_int(scan, *next);
2665 KMP_ASSERT(stride >= 0);
2666 scan = next;
2667 stride *= sign;
2668
2669 // valid follow sets are ',' and EOL
2670 SKIP_WS(scan);
2671 if (*scan == '\0') {
2672 break;
2673 }
2674 if (*scan == ',') {
2675 scan++; // skip ','
2676 continue;
2677 }
2678
2679 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2680 return FALSE;
2681 }
2682
2683 {
2684 int len = scan - env;
2685 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
2686 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
2687 retlist[len] = '\0';
2688 *place_list = retlist;
2689 }
2690 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002691}
2692
Jonathan Peyton30419822017-05-12 18:01:32 +00002693static void __kmp_stg_parse_places(char const *name, char const *value,
2694 void *data) {
2695 int count;
2696 const char *scan = value;
2697 const char *next = scan;
2698 const char *kind = "\"threads\"";
2699 kmp_setting_t **rivals = (kmp_setting_t **)data;
2700 int rc;
2701
2702 rc = __kmp_stg_check_rivals(name, value, rivals);
2703 if (rc) {
2704 return;
2705 }
2706
2707 // If OMP_PROC_BIND is not specified but OMP_PLACES is,
2708 // then let OMP_PROC_BIND default to true.
2709 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2710 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2711 }
2712
2713 //__kmp_affinity_num_places = 0;
2714
2715 if (__kmp_match_str("threads", scan, &next)) {
2716 scan = next;
2717 __kmp_affinity_type = affinity_compact;
2718 __kmp_affinity_gran = affinity_gran_thread;
2719 __kmp_affinity_dups = FALSE;
2720 kind = "\"threads\"";
2721 } else if (__kmp_match_str("cores", scan, &next)) {
2722 scan = next;
2723 __kmp_affinity_type = affinity_compact;
2724 __kmp_affinity_gran = affinity_gran_core;
2725 __kmp_affinity_dups = FALSE;
2726 kind = "\"cores\"";
2727 } else if (__kmp_match_str("sockets", scan, &next)) {
2728 scan = next;
2729 __kmp_affinity_type = affinity_compact;
2730 __kmp_affinity_gran = affinity_gran_package;
2731 __kmp_affinity_dups = FALSE;
2732 kind = "\"sockets\"";
2733 } else {
2734 if (__kmp_affinity_proclist != NULL) {
2735 KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist);
2736 __kmp_affinity_proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002737 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002738 if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2739 __kmp_affinity_type = affinity_explicit;
2740 __kmp_affinity_gran = affinity_gran_fine;
2741 __kmp_affinity_dups = FALSE;
2742 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002743 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
Jonathan Peyton30419822017-05-12 18:01:32 +00002744 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002745 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002746 return;
2747 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002748
Jonathan Peyton30419822017-05-12 18:01:32 +00002749 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2750 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2751 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002752
Jonathan Peyton30419822017-05-12 18:01:32 +00002753 SKIP_WS(scan);
2754 if (*scan == '\0') {
2755 return;
2756 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002757
Jonathan Peyton30419822017-05-12 18:01:32 +00002758 // Parse option count parameter in parentheses
2759 if (*scan != '(') {
2760 KMP_WARNING(SyntaxErrorUsing, name, kind);
2761 return;
2762 }
2763 scan++; // skip '('
Jim Cownie5e8470a2013-09-27 10:38:44 +00002764
Jonathan Peyton30419822017-05-12 18:01:32 +00002765 SKIP_WS(scan);
2766 next = scan;
2767 SKIP_DIGITS(next);
2768 count = __kmp_str_to_int(scan, *next);
2769 KMP_ASSERT(count >= 0);
2770 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002771
Jonathan Peyton30419822017-05-12 18:01:32 +00002772 SKIP_WS(scan);
2773 if (*scan != ')') {
2774 KMP_WARNING(SyntaxErrorUsing, name, kind);
2775 return;
2776 }
2777 scan++; // skip ')'
2778
2779 SKIP_WS(scan);
2780 if (*scan != '\0') {
2781 KMP_WARNING(ParseExtraCharsWarn, name, scan);
2782 }
2783 __kmp_affinity_num_places = count;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002784}
2785
Jonathan Peyton30419822017-05-12 18:01:32 +00002786static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
2787 void *data) {
2788 if (__kmp_env_format) {
2789 KMP_STR_BUF_PRINT_NAME;
2790 } else {
2791 __kmp_str_buf_print(buffer, " %s", name);
2792 }
2793 if ((__kmp_nested_proc_bind.used == 0) ||
2794 (__kmp_nested_proc_bind.bind_types == NULL) ||
2795 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
2796 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2797 } else if (__kmp_affinity_type == affinity_explicit) {
2798 if (__kmp_affinity_proclist != NULL) {
2799 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002800 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002801 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002802 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002803 } else if (__kmp_affinity_type == affinity_compact) {
2804 int num;
2805 if (__kmp_affinity_num_masks > 0) {
2806 num = __kmp_affinity_num_masks;
2807 } else if (__kmp_affinity_num_places > 0) {
2808 num = __kmp_affinity_num_places;
2809 } else {
2810 num = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002811 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002812 if (__kmp_affinity_gran == affinity_gran_thread) {
2813 if (num > 0) {
2814 __kmp_str_buf_print(buffer, "='threads(%d)'\n", num);
2815 } else {
2816 __kmp_str_buf_print(buffer, "='threads'\n");
2817 }
2818 } else if (__kmp_affinity_gran == affinity_gran_core) {
2819 if (num > 0) {
2820 __kmp_str_buf_print(buffer, "='cores(%d)' \n", num);
2821 } else {
2822 __kmp_str_buf_print(buffer, "='cores'\n");
2823 }
2824 } else if (__kmp_affinity_gran == affinity_gran_package) {
2825 if (num > 0) {
2826 __kmp_str_buf_print(buffer, "='sockets(%d)'\n", num);
2827 } else {
2828 __kmp_str_buf_print(buffer, "='sockets'\n");
2829 }
2830 } else {
2831 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002832 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002833 } else {
2834 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2835 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002836}
2837
2838#endif /* OMP_40_ENABLED */
2839
Jonathan Peyton30419822017-05-12 18:01:32 +00002840#if (!OMP_40_ENABLED)
Jim Cownie5e8470a2013-09-27 10:38:44 +00002841
Jonathan Peyton30419822017-05-12 18:01:32 +00002842static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
2843 void *data) {
2844 int enabled;
2845 kmp_setting_t **rivals = (kmp_setting_t **)data;
2846 int rc;
2847
2848 rc = __kmp_stg_check_rivals(name, value, rivals);
2849 if (rc) {
2850 return;
2851 }
2852
2853 // In OMP 3.1, OMP_PROC_BIND is strictly a boolean
2854 __kmp_stg_parse_bool(name, value, &enabled);
2855 if (enabled) {
2856 // OMP_PROC_BIND => granularity=fine,scatter on MIC
2857 // OMP_PROC_BIND => granularity=core,scatter elsewhere
2858 __kmp_affinity_type = affinity_scatter;
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002859#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002860 if (__kmp_mic_type != non_mic)
2861 __kmp_affinity_gran = affinity_gran_fine;
2862 else
2863#endif
2864 __kmp_affinity_gran = affinity_gran_core;
2865 } else {
2866 __kmp_affinity_type = affinity_none;
2867 }
2868} // __kmp_parse_proc_bind
2869
2870#endif /* if (! OMP_40_ENABLED) */
2871
2872static void __kmp_stg_parse_topology_method(char const *name, char const *value,
2873 void *data) {
2874 if (__kmp_str_match("all", 1, value)) {
2875 __kmp_affinity_top_method = affinity_top_method_all;
2876 }
2877#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2878 else if (__kmp_str_match("x2apic id", 9, value) ||
2879 __kmp_str_match("x2apic_id", 9, value) ||
2880 __kmp_str_match("x2apic-id", 9, value) ||
2881 __kmp_str_match("x2apicid", 8, value) ||
2882 __kmp_str_match("cpuid leaf 11", 13, value) ||
2883 __kmp_str_match("cpuid_leaf_11", 13, value) ||
2884 __kmp_str_match("cpuid-leaf-11", 13, value) ||
2885 __kmp_str_match("cpuid leaf11", 12, value) ||
2886 __kmp_str_match("cpuid_leaf11", 12, value) ||
2887 __kmp_str_match("cpuid-leaf11", 12, value) ||
2888 __kmp_str_match("cpuidleaf 11", 12, value) ||
2889 __kmp_str_match("cpuidleaf_11", 12, value) ||
2890 __kmp_str_match("cpuidleaf-11", 12, value) ||
2891 __kmp_str_match("cpuidleaf11", 11, value) ||
2892 __kmp_str_match("cpuid 11", 8, value) ||
2893 __kmp_str_match("cpuid_11", 8, value) ||
2894 __kmp_str_match("cpuid-11", 8, value) ||
2895 __kmp_str_match("cpuid11", 7, value) ||
2896 __kmp_str_match("leaf 11", 7, value) ||
2897 __kmp_str_match("leaf_11", 7, value) ||
2898 __kmp_str_match("leaf-11", 7, value) ||
2899 __kmp_str_match("leaf11", 6, value)) {
2900 __kmp_affinity_top_method = affinity_top_method_x2apicid;
2901 } else if (__kmp_str_match("apic id", 7, value) ||
2902 __kmp_str_match("apic_id", 7, value) ||
2903 __kmp_str_match("apic-id", 7, value) ||
2904 __kmp_str_match("apicid", 6, value) ||
2905 __kmp_str_match("cpuid leaf 4", 12, value) ||
2906 __kmp_str_match("cpuid_leaf_4", 12, value) ||
2907 __kmp_str_match("cpuid-leaf-4", 12, value) ||
2908 __kmp_str_match("cpuid leaf4", 11, value) ||
2909 __kmp_str_match("cpuid_leaf4", 11, value) ||
2910 __kmp_str_match("cpuid-leaf4", 11, value) ||
2911 __kmp_str_match("cpuidleaf 4", 11, value) ||
2912 __kmp_str_match("cpuidleaf_4", 11, value) ||
2913 __kmp_str_match("cpuidleaf-4", 11, value) ||
2914 __kmp_str_match("cpuidleaf4", 10, value) ||
2915 __kmp_str_match("cpuid 4", 7, value) ||
2916 __kmp_str_match("cpuid_4", 7, value) ||
2917 __kmp_str_match("cpuid-4", 7, value) ||
2918 __kmp_str_match("cpuid4", 6, value) ||
2919 __kmp_str_match("leaf 4", 6, value) ||
2920 __kmp_str_match("leaf_4", 6, value) ||
2921 __kmp_str_match("leaf-4", 6, value) ||
2922 __kmp_str_match("leaf4", 5, value)) {
2923 __kmp_affinity_top_method = affinity_top_method_apicid;
2924 }
2925#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2926 else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
2927 __kmp_str_match("cpuinfo", 5, value)) {
2928 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
2929 }
2930#if KMP_GROUP_AFFINITY
2931 else if (__kmp_str_match("group", 1, value)) {
2932 __kmp_affinity_top_method = affinity_top_method_group;
2933 }
2934#endif /* KMP_GROUP_AFFINITY */
2935 else if (__kmp_str_match("flat", 1, value)) {
2936 __kmp_affinity_top_method = affinity_top_method_flat;
2937 }
2938#if KMP_USE_HWLOC
2939 else if (__kmp_str_match("hwloc", 1, value)) {
2940 __kmp_affinity_top_method = affinity_top_method_hwloc;
2941 }
2942#endif
2943 else {
2944 KMP_WARNING(StgInvalidValue, name, value);
2945 }
2946} // __kmp_stg_parse_topology_method
2947
2948static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
2949 char const *name, void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002950 char const *value = NULL;
2951
2952 switch (__kmp_affinity_top_method) {
2953 case affinity_top_method_default:
2954 value = "default";
2955 break;
2956
2957 case affinity_top_method_all:
2958 value = "all";
2959 break;
2960
2961#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2962 case affinity_top_method_x2apicid:
2963 value = "x2APIC id";
2964 break;
2965
2966 case affinity_top_method_apicid:
2967 value = "APIC id";
2968 break;
2969#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2970
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002971#if KMP_USE_HWLOC
Jonathan Peyton30419822017-05-12 18:01:32 +00002972 case affinity_top_method_hwloc:
2973 value = "hwloc";
2974 break;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002975#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00002976
2977 case affinity_top_method_cpuinfo:
2978 value = "cpuinfo";
2979 break;
2980
2981#if KMP_GROUP_AFFINITY
2982 case affinity_top_method_group:
2983 value = "group";
2984 break;
2985#endif /* KMP_GROUP_AFFINITY */
2986
2987 case affinity_top_method_flat:
2988 value = "flat";
2989 break;
2990 }
2991
2992 if (value != NULL) {
2993 __kmp_stg_print_str(buffer, name, value);
2994 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002995} // __kmp_stg_print_topology_method
2996
2997#endif /* KMP_AFFINITY_SUPPORTED */
2998
2999#if OMP_40_ENABLED
3000
3001// OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
3002// OMP_PLACES / place-partition-var is not.
3003static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
3004 void *data) {
3005 kmp_setting_t **rivals = (kmp_setting_t **)data;
3006 int rc;
3007
3008 rc = __kmp_stg_check_rivals(name, value, rivals);
3009 if (rc) {
3010 return;
3011 }
3012
3013 // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
3014 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
3015 (__kmp_nested_proc_bind.used > 0));
3016
3017 const char *buf = value;
3018 const char *next;
3019 int num;
3020 SKIP_WS(buf);
3021 if ((*buf >= '0') && (*buf <= '9')) {
3022 next = buf;
3023 SKIP_DIGITS(next);
3024 num = __kmp_str_to_int(buf, *next);
3025 KMP_ASSERT(num >= 0);
3026 buf = next;
3027 SKIP_WS(buf);
3028 } else {
3029 num = -1;
3030 }
3031
3032 next = buf;
3033 if (__kmp_match_str("disabled", buf, &next)) {
3034 buf = next;
3035 SKIP_WS(buf);
3036#if KMP_AFFINITY_SUPPORTED
3037 __kmp_affinity_type = affinity_disabled;
3038#endif /* KMP_AFFINITY_SUPPORTED */
3039 __kmp_nested_proc_bind.used = 1;
3040 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3041 } else if ((num == (int)proc_bind_false) ||
3042 __kmp_match_str("false", buf, &next)) {
3043 buf = next;
3044 SKIP_WS(buf);
3045#if KMP_AFFINITY_SUPPORTED
3046 __kmp_affinity_type = affinity_none;
3047#endif /* KMP_AFFINITY_SUPPORTED */
3048 __kmp_nested_proc_bind.used = 1;
3049 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3050 } else if ((num == (int)proc_bind_true) ||
3051 __kmp_match_str("true", buf, &next)) {
3052 buf = next;
3053 SKIP_WS(buf);
3054 __kmp_nested_proc_bind.used = 1;
3055 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3056 } else {
3057 // Count the number of values in the env var string
3058 const char *scan;
3059 int nelem = 1;
3060 for (scan = buf; *scan != '\0'; scan++) {
3061 if (*scan == ',') {
3062 nelem++;
3063 }
3064 }
3065
3066 // Create / expand the nested proc_bind array as needed
3067 if (__kmp_nested_proc_bind.size < nelem) {
3068 __kmp_nested_proc_bind.bind_types =
3069 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3070 __kmp_nested_proc_bind.bind_types,
3071 sizeof(kmp_proc_bind_t) * nelem);
3072 if (__kmp_nested_proc_bind.bind_types == NULL) {
3073 KMP_FATAL(MemoryAllocFailed);
3074 }
3075 __kmp_nested_proc_bind.size = nelem;
3076 }
3077 __kmp_nested_proc_bind.used = nelem;
3078
3079 // Save values in the nested proc_bind array
3080 int i = 0;
3081 for (;;) {
3082 enum kmp_proc_bind_t bind;
3083
3084 if ((num == (int)proc_bind_master) ||
3085 __kmp_match_str("master", buf, &next)) {
3086 buf = next;
3087 SKIP_WS(buf);
3088 bind = proc_bind_master;
3089 } else if ((num == (int)proc_bind_close) ||
3090 __kmp_match_str("close", buf, &next)) {
3091 buf = next;
3092 SKIP_WS(buf);
3093 bind = proc_bind_close;
3094 } else if ((num == (int)proc_bind_spread) ||
3095 __kmp_match_str("spread", buf, &next)) {
3096 buf = next;
3097 SKIP_WS(buf);
3098 bind = proc_bind_spread;
3099 } else {
3100 KMP_WARNING(StgInvalidValue, name, value);
3101 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3102 __kmp_nested_proc_bind.used = 1;
3103 return;
3104 }
3105
3106 __kmp_nested_proc_bind.bind_types[i++] = bind;
3107 if (i >= nelem) {
3108 break;
3109 }
3110 KMP_DEBUG_ASSERT(*buf == ',');
3111 buf++;
3112 SKIP_WS(buf);
3113
3114 // Read next value if it was specified as an integer
3115 if ((*buf >= '0') && (*buf <= '9')) {
3116 next = buf;
3117 SKIP_DIGITS(next);
3118 num = __kmp_str_to_int(buf, *next);
3119 KMP_ASSERT(num >= 0);
3120 buf = next;
3121 SKIP_WS(buf);
3122 } else {
3123 num = -1;
3124 }
3125 }
3126 SKIP_WS(buf);
3127 }
3128 if (*buf != '\0') {
3129 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3130 }
3131}
3132
3133static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
3134 void *data) {
3135 int nelem = __kmp_nested_proc_bind.used;
3136 if (__kmp_env_format) {
3137 KMP_STR_BUF_PRINT_NAME;
3138 } else {
3139 __kmp_str_buf_print(buffer, " %s", name);
3140 }
3141 if (nelem == 0) {
3142 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3143 } else {
3144 int i;
3145 __kmp_str_buf_print(buffer, "='", name);
3146 for (i = 0; i < nelem; i++) {
3147 switch (__kmp_nested_proc_bind.bind_types[i]) {
3148 case proc_bind_false:
3149 __kmp_str_buf_print(buffer, "false");
3150 break;
3151
3152 case proc_bind_true:
3153 __kmp_str_buf_print(buffer, "true");
3154 break;
3155
3156 case proc_bind_master:
3157 __kmp_str_buf_print(buffer, "master");
3158 break;
3159
3160 case proc_bind_close:
3161 __kmp_str_buf_print(buffer, "close");
3162 break;
3163
3164 case proc_bind_spread:
3165 __kmp_str_buf_print(buffer, "spread");
3166 break;
3167
3168 case proc_bind_intel:
3169 __kmp_str_buf_print(buffer, "intel");
3170 break;
3171
3172 case proc_bind_default:
3173 __kmp_str_buf_print(buffer, "default");
3174 break;
3175 }
3176 if (i < nelem - 1) {
3177 __kmp_str_buf_print(buffer, ",");
3178 }
3179 }
3180 __kmp_str_buf_print(buffer, "'\n");
3181 }
3182}
3183
3184#endif /* OMP_40_ENABLED */
3185
3186// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003187// OMP_DYNAMIC
Jim Cownie5e8470a2013-09-27 10:38:44 +00003188
Jonathan Peyton30419822017-05-12 18:01:32 +00003189static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
3190 void *data) {
3191 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003192} // __kmp_stg_parse_omp_dynamic
3193
Jonathan Peyton30419822017-05-12 18:01:32 +00003194static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
3195 void *data) {
3196 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003197} // __kmp_stg_print_omp_dynamic
3198
Jonathan Peyton30419822017-05-12 18:01:32 +00003199static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
3200 char const *value, void *data) {
3201 if (TCR_4(__kmp_init_parallel)) {
3202 KMP_WARNING(EnvParallelWarn, name);
3203 __kmp_env_toPrint(name, 0);
3204 return;
3205 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003206#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00003207 else if (__kmp_str_match("load balance", 2, value) ||
3208 __kmp_str_match("load_balance", 2, value) ||
3209 __kmp_str_match("load-balance", 2, value) ||
3210 __kmp_str_match("loadbalance", 2, value) ||
3211 __kmp_str_match("balance", 1, value)) {
3212 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3213 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003214#endif /* USE_LOAD_BALANCE */
Jonathan Peyton30419822017-05-12 18:01:32 +00003215 else if (__kmp_str_match("thread limit", 1, value) ||
3216 __kmp_str_match("thread_limit", 1, value) ||
3217 __kmp_str_match("thread-limit", 1, value) ||
3218 __kmp_str_match("threadlimit", 1, value) ||
3219 __kmp_str_match("limit", 2, value)) {
3220 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3221 } else if (__kmp_str_match("random", 1, value)) {
3222 __kmp_global.g.g_dynamic_mode = dynamic_random;
3223 } else {
3224 KMP_WARNING(StgInvalidValue, name, value);
3225 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003226} //__kmp_stg_parse_kmp_dynamic_mode
3227
Jonathan Peyton30419822017-05-12 18:01:32 +00003228static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
3229 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003230#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003231 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
3232 __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
3233 }
3234#ifdef USE_LOAD_BALANCE
3235 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
3236 __kmp_stg_print_str(buffer, name, "load balance");
3237 }
3238#endif /* USE_LOAD_BALANCE */
3239 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
3240 __kmp_stg_print_str(buffer, name, "thread limit");
3241 } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
3242 __kmp_stg_print_str(buffer, name, "random");
3243 } else {
3244 KMP_ASSERT(0);
3245 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003246#endif /* KMP_DEBUG */
3247} // __kmp_stg_print_kmp_dynamic_mode
3248
Jim Cownie5e8470a2013-09-27 10:38:44 +00003249#ifdef USE_LOAD_BALANCE
3250
Jonathan Peyton30419822017-05-12 18:01:32 +00003251// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003252// KMP_LOAD_BALANCE_INTERVAL
Jim Cownie5e8470a2013-09-27 10:38:44 +00003253
Jonathan Peyton30419822017-05-12 18:01:32 +00003254static void __kmp_stg_parse_ld_balance_interval(char const *name,
3255 char const *value, void *data) {
3256 double interval = __kmp_convert_to_double(value);
3257 if (interval >= 0) {
3258 __kmp_load_balance_interval = interval;
3259 } else {
3260 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003261 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003262} // __kmp_stg_parse_load_balance_interval
3263
Jonathan Peyton30419822017-05-12 18:01:32 +00003264static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
3265 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003266#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003267 __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
3268 __kmp_load_balance_interval);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003269#endif /* KMP_DEBUG */
3270} // __kmp_stg_print_load_balance_interval
3271
3272#endif /* USE_LOAD_BALANCE */
3273
Jonathan Peyton30419822017-05-12 18:01:32 +00003274// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003275// KMP_INIT_AT_FORK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003276
Jonathan Peyton30419822017-05-12 18:01:32 +00003277static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
3278 void *data) {
3279 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
3280 if (__kmp_need_register_atfork) {
3281 __kmp_need_register_atfork_specified = TRUE;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003282 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003283} // __kmp_stg_parse_init_at_fork
3284
Jonathan Peyton30419822017-05-12 18:01:32 +00003285static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
3286 char const *name, void *data) {
3287 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003288} // __kmp_stg_print_init_at_fork
3289
Jonathan Peyton30419822017-05-12 18:01:32 +00003290// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003291// KMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003292
Jonathan Peyton30419822017-05-12 18:01:32 +00003293static void __kmp_stg_parse_schedule(char const *name, char const *value,
3294 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003295
Jonathan Peyton30419822017-05-12 18:01:32 +00003296 if (value != NULL) {
3297 size_t length = KMP_STRLEN(value);
3298 if (length > INT_MAX) {
3299 KMP_WARNING(LongValue, name);
3300 } else {
3301 char *semicolon;
3302 if (value[length - 1] == '"' || value[length - 1] == '\'')
3303 KMP_WARNING(UnbalancedQuotes, name);
3304 do {
3305 char sentinel;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003306
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003307 semicolon = CCAST(char *, strchr(value, ';'));
Jonathan Peyton30419822017-05-12 18:01:32 +00003308 if (*value && semicolon != value) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003309 char *comma = CCAST(char *, strchr(value, ','));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003310
Jonathan Peyton30419822017-05-12 18:01:32 +00003311 if (comma) {
3312 ++comma;
3313 sentinel = ',';
3314 } else
3315 sentinel = ';';
3316 if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
3317 if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
3318 __kmp_static = kmp_sch_static_greedy;
3319 continue;
3320 } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
3321 ';')) {
3322 __kmp_static = kmp_sch_static_balanced;
3323 continue;
3324 }
3325 } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3326 sentinel)) {
3327 if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
3328 __kmp_guided = kmp_sch_guided_iterative_chunked;
3329 continue;
3330 } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
3331 ';')) {
3332 /* analytical not allowed for too many threads */
3333 __kmp_guided = kmp_sch_guided_analytical_chunked;
3334 continue;
3335 }
3336 }
3337 KMP_WARNING(InvalidClause, name, value);
3338 } else
3339 KMP_WARNING(EmptyClause, name);
3340 } while ((value = semicolon ? semicolon + 1 : NULL));
3341 }
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003342 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003343
3344} // __kmp_stg_parse__schedule
3345
Jonathan Peyton30419822017-05-12 18:01:32 +00003346static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
3347 void *data) {
3348 if (__kmp_env_format) {
3349 KMP_STR_BUF_PRINT_NAME_EX(name);
3350 } else {
3351 __kmp_str_buf_print(buffer, " %s='", name);
3352 }
3353 if (__kmp_static == kmp_sch_static_greedy) {
3354 __kmp_str_buf_print(buffer, "%s", "static,greedy");
3355 } else if (__kmp_static == kmp_sch_static_balanced) {
3356 __kmp_str_buf_print(buffer, "%s", "static,balanced");
3357 }
3358 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
3359 __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
3360 } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
3361 __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
3362 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003363} // __kmp_stg_print_schedule
3364
Jonathan Peyton30419822017-05-12 18:01:32 +00003365// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003366// OMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003367
Jonathan Peyton30419822017-05-12 18:01:32 +00003368static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
3369 void *data) {
3370 size_t length;
3371 if (value) {
3372 length = KMP_STRLEN(value);
3373 if (length) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00003374 char *comma = CCAST(char *, strchr(value, ','));
Jonathan Peyton30419822017-05-12 18:01:32 +00003375 if (value[length - 1] == '"' || value[length - 1] == '\'')
3376 KMP_WARNING(UnbalancedQuotes, name);
3377 /* get the specified scheduling style */
3378 if (!__kmp_strcasecmp_with_sentinel("dynamic", value, ',')) /* DYNAMIC */
3379 __kmp_sched = kmp_sch_dynamic_chunked;
3380 else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3381 ',')) /* GUIDED */
3382 __kmp_sched = kmp_sch_guided_chunked;
3383 // AC: TODO: add AUTO schedule, and pprobably remove TRAPEZOIDAL (OMP 3.0
3384 // does not allow it)
3385 else if (!__kmp_strcasecmp_with_sentinel("auto", value, ',')) { /* AUTO */
3386 __kmp_sched = kmp_sch_auto;
3387 if (comma) {
3388 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, comma),
3389 __kmp_msg_null);
3390 comma = NULL;
3391 }
3392 } else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", value,
3393 ',')) /* TRAPEZOIDAL */
3394 __kmp_sched = kmp_sch_trapezoidal;
3395 else if (!__kmp_strcasecmp_with_sentinel("static", value,
3396 ',')) /* STATIC */
3397 __kmp_sched = kmp_sch_static;
Andrey Churbanov429dbc22016-07-11 10:44:57 +00003398#if KMP_STATIC_STEAL_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00003399 else if (!__kmp_strcasecmp_with_sentinel("static_steal", value, ','))
3400 __kmp_sched = kmp_sch_static_steal;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003401#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003402 else {
3403 KMP_WARNING(StgInvalidValue, name, value);
3404 value = NULL; /* skip processing of comma */
3405 }
3406 if (value && comma) {
Jonathan Peyton30419822017-05-12 18:01:32 +00003407 if (__kmp_sched == kmp_sch_static)
3408 __kmp_sched = kmp_sch_static_chunked;
3409 ++comma;
3410 __kmp_chunk = __kmp_str_to_int(comma, 0);
3411 if (__kmp_chunk < 1) {
3412 __kmp_chunk = KMP_DEFAULT_CHUNK;
3413 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, comma),
3414 __kmp_msg_null);
3415 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3416 // AC: next block commented out until KMP_DEFAULT_CHUNK !=
3417 // KMP_MIN_CHUNK (to improve code coverage :)
3418 // The default chunk size is 1 according to standard, thus making
3419 // KMP_MIN_CHUNK not 1 we would introduce mess:
3420 // wrong chunk becomes 1, but it will be impossible to explicitely
3421 // set 1, because it becomes KMP_MIN_CHUNK...
3422 // } else if ( __kmp_chunk < KMP_MIN_CHUNK ) {
3423 // __kmp_chunk = KMP_MIN_CHUNK;
3424 } else if (__kmp_chunk > KMP_MAX_CHUNK) {
3425 __kmp_chunk = KMP_MAX_CHUNK;
3426 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, comma),
3427 __kmp_msg_null);
3428 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3429 }
Jonathan Peytond74d8902017-07-25 18:20:16 +00003430 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003431 } else
3432 KMP_WARNING(EmptyString, name);
3433 }
3434 K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
3435 K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
3436 K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
3437 K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
Jim Cownie5e8470a2013-09-27 10:38:44 +00003438} // __kmp_stg_parse_omp_schedule
3439
Jonathan Peyton30419822017-05-12 18:01:32 +00003440static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
3441 char const *name, void *data) {
3442 if (__kmp_env_format) {
3443 KMP_STR_BUF_PRINT_NAME_EX(name);
3444 } else {
3445 __kmp_str_buf_print(buffer, " %s='", name);
3446 }
3447 if (__kmp_chunk) {
3448 switch (__kmp_sched) {
3449 case kmp_sch_dynamic_chunked:
3450 __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
3451 break;
3452 case kmp_sch_guided_iterative_chunked:
3453 case kmp_sch_guided_analytical_chunked:
3454 __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
3455 break;
3456 case kmp_sch_trapezoidal:
3457 __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
3458 break;
3459 case kmp_sch_static:
3460 case kmp_sch_static_chunked:
3461 case kmp_sch_static_balanced:
3462 case kmp_sch_static_greedy:
3463 __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
3464 break;
3465 case kmp_sch_static_steal:
3466 __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
3467 break;
3468 case kmp_sch_auto:
3469 __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
3470 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003471 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003472 } else {
3473 switch (__kmp_sched) {
3474 case kmp_sch_dynamic_chunked:
3475 __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
3476 break;
3477 case kmp_sch_guided_iterative_chunked:
3478 case kmp_sch_guided_analytical_chunked:
3479 __kmp_str_buf_print(buffer, "%s'\n", "guided");
3480 break;
3481 case kmp_sch_trapezoidal:
3482 __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
3483 break;
3484 case kmp_sch_static:
3485 case kmp_sch_static_chunked:
3486 case kmp_sch_static_balanced:
3487 case kmp_sch_static_greedy:
3488 __kmp_str_buf_print(buffer, "%s'\n", "static");
3489 break;
3490 case kmp_sch_static_steal:
3491 __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
3492 break;
3493 case kmp_sch_auto:
3494 __kmp_str_buf_print(buffer, "%s'\n", "auto");
3495 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003496 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003497 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003498} // __kmp_stg_print_omp_schedule
3499
Jonathan Peyton30419822017-05-12 18:01:32 +00003500// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003501// KMP_ATOMIC_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003502
Jonathan Peyton30419822017-05-12 18:01:32 +00003503static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
3504 void *data) {
3505 // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
3506 // compatibility mode.
3507 int mode = 0;
3508 int max = 1;
3509#ifdef KMP_GOMP_COMPAT
3510 max = 2;
3511#endif /* KMP_GOMP_COMPAT */
3512 __kmp_stg_parse_int(name, value, 0, max, &mode);
3513 // TODO; parse_int is not very suitable for this case. In case of overflow it
3514 // is better to use
3515 // 0 rather that max value.
3516 if (mode > 0) {
3517 __kmp_atomic_mode = mode;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003518 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003519} // __kmp_stg_parse_atomic_mode
3520
Jonathan Peyton30419822017-05-12 18:01:32 +00003521static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
3522 void *data) {
3523 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003524} // __kmp_stg_print_atomic_mode
3525
Jonathan Peyton30419822017-05-12 18:01:32 +00003526// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003527// KMP_CONSISTENCY_CHECK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003528
Jonathan Peyton30419822017-05-12 18:01:32 +00003529static void __kmp_stg_parse_consistency_check(char const *name,
3530 char const *value, void *data) {
3531 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
3532 // Note, this will not work from kmp_set_defaults because th_cons stack was
3533 // not allocated
3534 // for existed thread(s) thus the first __kmp_push_<construct> will break
3535 // with assertion.
3536 // TODO: allocate th_cons if called from kmp_set_defaults.
3537 __kmp_env_consistency_check = TRUE;
3538 } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
3539 __kmp_env_consistency_check = FALSE;
3540 } else {
3541 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003542 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003543} // __kmp_stg_parse_consistency_check
3544
Jonathan Peyton30419822017-05-12 18:01:32 +00003545static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
3546 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003547#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003548 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003549
Jonathan Peyton30419822017-05-12 18:01:32 +00003550 if (__kmp_env_consistency_check) {
3551 value = "all";
3552 } else {
3553 value = "none";
3554 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003555
Jonathan Peyton30419822017-05-12 18:01:32 +00003556 if (value != NULL) {
3557 __kmp_stg_print_str(buffer, name, value);
3558 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003559#endif /* KMP_DEBUG */
3560} // __kmp_stg_print_consistency_check
3561
Jim Cownie5e8470a2013-09-27 10:38:44 +00003562#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00003563// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003564// KMP_ITT_PREPARE_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00003565
3566#if USE_ITT_NOTIFY
3567
Jonathan Peyton30419822017-05-12 18:01:32 +00003568static void __kmp_stg_parse_itt_prepare_delay(char const *name,
3569 char const *value, void *data) {
3570 // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
3571 // iterations.
3572 int delay = 0;
3573 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
3574 __kmp_itt_prepare_delay = delay;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003575} // __kmp_str_parse_itt_prepare_delay
3576
Jonathan Peyton30419822017-05-12 18:01:32 +00003577static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
3578 char const *name, void *data) {
3579 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003580
3581} // __kmp_str_print_itt_prepare_delay
3582
3583#endif // USE_ITT_NOTIFY
3584#endif /* USE_ITT_BUILD */
3585
Jonathan Peyton30419822017-05-12 18:01:32 +00003586// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003587// KMP_MALLOC_POOL_INCR
Jim Cownie5e8470a2013-09-27 10:38:44 +00003588
Jonathan Peyton30419822017-05-12 18:01:32 +00003589static void __kmp_stg_parse_malloc_pool_incr(char const *name,
3590 char const *value, void *data) {
3591 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
3592 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
3593 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003594} // __kmp_stg_parse_malloc_pool_incr
3595
Jonathan Peyton30419822017-05-12 18:01:32 +00003596static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
3597 char const *name, void *data) {
3598 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003599
3600} // _kmp_stg_print_malloc_pool_incr
3601
Jim Cownie5e8470a2013-09-27 10:38:44 +00003602#ifdef KMP_DEBUG
3603
Jonathan Peyton30419822017-05-12 18:01:32 +00003604// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003605// KMP_PAR_RANGE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003606
Jonathan Peyton30419822017-05-12 18:01:32 +00003607static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
3608 void *data) {
3609 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
3610 __kmp_par_range_routine, __kmp_par_range_filename,
3611 &__kmp_par_range_lb, &__kmp_par_range_ub);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003612} // __kmp_stg_parse_par_range_env
3613
Jonathan Peyton30419822017-05-12 18:01:32 +00003614static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
3615 char const *name, void *data) {
3616 if (__kmp_par_range != 0) {
3617 __kmp_stg_print_str(buffer, name, par_range_to_print);
3618 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003619} // __kmp_stg_print_par_range_env
3620
Jonathan Peyton30419822017-05-12 18:01:32 +00003621// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003622// KMP_YIELD_CYCLE, KMP_YIELD_ON, KMP_YIELD_OFF
Jim Cownie5e8470a2013-09-27 10:38:44 +00003623
Jonathan Peyton30419822017-05-12 18:01:32 +00003624static void __kmp_stg_parse_yield_cycle(char const *name, char const *value,
3625 void *data) {
3626 int flag = __kmp_yield_cycle;
3627 __kmp_stg_parse_bool(name, value, &flag);
3628 __kmp_yield_cycle = flag;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003629} // __kmp_stg_parse_yield_cycle
3630
Jonathan Peyton30419822017-05-12 18:01:32 +00003631static void __kmp_stg_print_yield_cycle(kmp_str_buf_t *buffer, char const *name,
3632 void *data) {
3633 __kmp_stg_print_bool(buffer, name, __kmp_yield_cycle);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003634} // __kmp_stg_print_yield_cycle
3635
Jonathan Peyton30419822017-05-12 18:01:32 +00003636static void __kmp_stg_parse_yield_on(char const *name, char const *value,
3637 void *data) {
3638 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003639} // __kmp_stg_parse_yield_on
3640
Jonathan Peyton30419822017-05-12 18:01:32 +00003641static void __kmp_stg_print_yield_on(kmp_str_buf_t *buffer, char const *name,
3642 void *data) {
3643 __kmp_stg_print_int(buffer, name, __kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003644} // __kmp_stg_print_yield_on
3645
Jonathan Peyton30419822017-05-12 18:01:32 +00003646static void __kmp_stg_parse_yield_off(char const *name, char const *value,
3647 void *data) {
3648 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003649} // __kmp_stg_parse_yield_off
3650
Jonathan Peyton30419822017-05-12 18:01:32 +00003651static void __kmp_stg_print_yield_off(kmp_str_buf_t *buffer, char const *name,
3652 void *data) {
3653 __kmp_stg_print_int(buffer, name, __kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003654} // __kmp_stg_print_yield_off
3655
3656#endif
3657
Jonathan Peyton30419822017-05-12 18:01:32 +00003658// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003659// KMP_INIT_WAIT, KMP_NEXT_WAIT
Jim Cownie5e8470a2013-09-27 10:38:44 +00003660
Jonathan Peyton30419822017-05-12 18:01:32 +00003661static void __kmp_stg_parse_init_wait(char const *name, char const *value,
3662 void *data) {
3663 int wait;
3664 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3665 wait = __kmp_init_wait / 2;
3666 __kmp_stg_parse_int(name, value, KMP_MIN_INIT_WAIT, KMP_MAX_INIT_WAIT, &wait);
3667 __kmp_init_wait = wait * 2;
3668 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3669 __kmp_yield_init = __kmp_init_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003670} // __kmp_stg_parse_init_wait
3671
Jonathan Peyton30419822017-05-12 18:01:32 +00003672static void __kmp_stg_print_init_wait(kmp_str_buf_t *buffer, char const *name,
3673 void *data) {
3674 __kmp_stg_print_int(buffer, name, __kmp_init_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003675} // __kmp_stg_print_init_wait
3676
Jonathan Peyton30419822017-05-12 18:01:32 +00003677static void __kmp_stg_parse_next_wait(char const *name, char const *value,
3678 void *data) {
3679 int wait;
3680 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3681 wait = __kmp_next_wait / 2;
3682 __kmp_stg_parse_int(name, value, KMP_MIN_NEXT_WAIT, KMP_MAX_NEXT_WAIT, &wait);
3683 __kmp_next_wait = wait * 2;
3684 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3685 __kmp_yield_next = __kmp_next_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003686} // __kmp_stg_parse_next_wait
3687
Jonathan Peyton30419822017-05-12 18:01:32 +00003688static void __kmp_stg_print_next_wait(kmp_str_buf_t *buffer, char const *name,
3689 void *data) {
3690 __kmp_stg_print_int(buffer, name, __kmp_next_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003691} //__kmp_stg_print_next_wait
3692
Jonathan Peyton30419822017-05-12 18:01:32 +00003693// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003694// KMP_GTID_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003695
Jonathan Peyton30419822017-05-12 18:01:32 +00003696static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
3697 void *data) {
3698 // Modes:
3699 // 0 -- do not change default
3700 // 1 -- sp search
3701 // 2 -- use "keyed" TLS var, i.e.
3702 // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
3703 // 3 -- __declspec(thread) TLS var in tdata section
3704 int mode = 0;
3705 int max = 2;
3706#ifdef KMP_TDATA_GTID
3707 max = 3;
3708#endif /* KMP_TDATA_GTID */
3709 __kmp_stg_parse_int(name, value, 0, max, &mode);
3710 // TODO; parse_int is not very suitable for this case. In case of overflow it
3711 // is better to use 0 rather that max value.
3712 if (mode == 0) {
3713 __kmp_adjust_gtid_mode = TRUE;
3714 } else {
3715 __kmp_gtid_mode = mode;
3716 __kmp_adjust_gtid_mode = FALSE;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003717 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003718} // __kmp_str_parse_gtid_mode
3719
Jonathan Peyton30419822017-05-12 18:01:32 +00003720static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
3721 void *data) {
3722 if (__kmp_adjust_gtid_mode) {
3723 __kmp_stg_print_int(buffer, name, 0);
3724 } else {
3725 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
3726 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003727} // __kmp_stg_print_gtid_mode
3728
Jonathan Peyton30419822017-05-12 18:01:32 +00003729// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003730// KMP_NUM_LOCKS_IN_BLOCK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003731
Jonathan Peyton30419822017-05-12 18:01:32 +00003732static void __kmp_stg_parse_lock_block(char const *name, char const *value,
3733 void *data) {
3734 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003735} // __kmp_str_parse_lock_block
3736
Jonathan Peyton30419822017-05-12 18:01:32 +00003737static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
3738 void *data) {
3739 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003740} // __kmp_stg_print_lock_block
3741
Jonathan Peyton30419822017-05-12 18:01:32 +00003742// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003743// KMP_LOCK_KIND
Jim Cownie5e8470a2013-09-27 10:38:44 +00003744
Jonathan Peytondae13d82015-12-11 21:57:06 +00003745#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00003746#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003747#else
Jonathan Peyton30419822017-05-12 18:01:32 +00003748#define KMP_STORE_LOCK_SEQ(a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003749#endif
3750
Jonathan Peyton30419822017-05-12 18:01:32 +00003751static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
3752 void *data) {
3753 if (__kmp_init_user_locks) {
3754 KMP_WARNING(EnvLockWarn, name);
3755 return;
3756 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003757
Jonathan Peyton30419822017-05-12 18:01:32 +00003758 if (__kmp_str_match("tas", 2, value) ||
3759 __kmp_str_match("test and set", 2, value) ||
3760 __kmp_str_match("test_and_set", 2, value) ||
3761 __kmp_str_match("test-and-set", 2, value) ||
3762 __kmp_str_match("test andset", 2, value) ||
3763 __kmp_str_match("test_andset", 2, value) ||
3764 __kmp_str_match("test-andset", 2, value) ||
3765 __kmp_str_match("testand set", 2, value) ||
3766 __kmp_str_match("testand_set", 2, value) ||
3767 __kmp_str_match("testand-set", 2, value) ||
3768 __kmp_str_match("testandset", 2, value)) {
3769 __kmp_user_lock_kind = lk_tas;
3770 KMP_STORE_LOCK_SEQ(tas);
3771 }
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003772#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003773 else if (__kmp_str_match("futex", 1, value)) {
3774 if (__kmp_futex_determine_capable()) {
3775 __kmp_user_lock_kind = lk_futex;
3776 KMP_STORE_LOCK_SEQ(futex);
3777 } else {
3778 KMP_WARNING(FutexNotSupported, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003779 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003780 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003781#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003782 else if (__kmp_str_match("ticket", 2, value)) {
3783 __kmp_user_lock_kind = lk_ticket;
3784 KMP_STORE_LOCK_SEQ(ticket);
3785 } else if (__kmp_str_match("queuing", 1, value) ||
3786 __kmp_str_match("queue", 1, value)) {
3787 __kmp_user_lock_kind = lk_queuing;
3788 KMP_STORE_LOCK_SEQ(queuing);
3789 } else if (__kmp_str_match("drdpa ticket", 1, value) ||
3790 __kmp_str_match("drdpa_ticket", 1, value) ||
3791 __kmp_str_match("drdpa-ticket", 1, value) ||
3792 __kmp_str_match("drdpaticket", 1, value) ||
3793 __kmp_str_match("drdpa", 1, value)) {
3794 __kmp_user_lock_kind = lk_drdpa;
3795 KMP_STORE_LOCK_SEQ(drdpa);
3796 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003797#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003798 else if (__kmp_str_match("adaptive", 1, value)) {
3799 if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
3800 __kmp_user_lock_kind = lk_adaptive;
3801 KMP_STORE_LOCK_SEQ(adaptive);
3802 } else {
3803 KMP_WARNING(AdaptiveNotSupported, name, value);
3804 __kmp_user_lock_kind = lk_queuing;
3805 KMP_STORE_LOCK_SEQ(queuing);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003806 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003807 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003808#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peytondae13d82015-12-11 21:57:06 +00003809#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003810 else if (__kmp_str_match("rtm", 1, value)) {
3811 if (__kmp_cpuinfo.rtm) {
3812 __kmp_user_lock_kind = lk_rtm;
3813 KMP_STORE_LOCK_SEQ(rtm);
3814 } else {
3815 KMP_WARNING(AdaptiveNotSupported, name, value);
3816 __kmp_user_lock_kind = lk_queuing;
3817 KMP_STORE_LOCK_SEQ(queuing);
Jonathan Peytondae13d82015-12-11 21:57:06 +00003818 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003819 } else if (__kmp_str_match("hle", 1, value)) {
3820 __kmp_user_lock_kind = lk_hle;
3821 KMP_STORE_LOCK_SEQ(hle);
3822 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00003823#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003824 else {
3825 KMP_WARNING(StgInvalidValue, name, value);
3826 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003827}
3828
Jonathan Peyton30419822017-05-12 18:01:32 +00003829static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
3830 void *data) {
3831 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003832
Jonathan Peyton30419822017-05-12 18:01:32 +00003833 switch (__kmp_user_lock_kind) {
3834 case lk_default:
3835 value = "default";
3836 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003837
Jonathan Peyton30419822017-05-12 18:01:32 +00003838 case lk_tas:
3839 value = "tas";
3840 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003841
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003842#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003843 case lk_futex:
3844 value = "futex";
3845 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003846#endif
3847
Jonathan Peytondae13d82015-12-11 21:57:06 +00003848#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003849 case lk_rtm:
3850 value = "rtm";
3851 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003852
Jonathan Peyton30419822017-05-12 18:01:32 +00003853 case lk_hle:
3854 value = "hle";
3855 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003856#endif
3857
Jonathan Peyton30419822017-05-12 18:01:32 +00003858 case lk_ticket:
3859 value = "ticket";
3860 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003861
Jonathan Peyton30419822017-05-12 18:01:32 +00003862 case lk_queuing:
3863 value = "queuing";
3864 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003865
Jonathan Peyton30419822017-05-12 18:01:32 +00003866 case lk_drdpa:
3867 value = "drdpa";
3868 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003869#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003870 case lk_adaptive:
3871 value = "adaptive";
3872 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003873#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003874 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003875
Jonathan Peyton30419822017-05-12 18:01:32 +00003876 if (value != NULL) {
3877 __kmp_stg_print_str(buffer, name, value);
3878 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003879}
3880
Jonathan Peyton30419822017-05-12 18:01:32 +00003881// -----------------------------------------------------------------------------
Jonathan Peyton377aa402016-04-14 16:00:37 +00003882// KMP_SPIN_BACKOFF_PARAMS
Jonathan Peyton377aa402016-04-14 16:00:37 +00003883
Jonathan Peyton30419822017-05-12 18:01:32 +00003884// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
3885// for machine pause)
3886static void __kmp_stg_parse_spin_backoff_params(const char *name,
3887 const char *value, void *data) {
3888 const char *next = value;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003889
Jonathan Peyton30419822017-05-12 18:01:32 +00003890 int total = 0; // Count elements that were set. It'll be used as an array size
3891 int prev_comma = FALSE; // For correct processing sequential commas
3892 int i;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003893
Jonathan Peyton30419822017-05-12 18:01:32 +00003894 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
3895 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003896
Jonathan Peyton30419822017-05-12 18:01:32 +00003897 // Run only 3 iterations because it is enough to read two values or find a
3898 // syntax error
3899 for (i = 0; i < 3; i++) {
3900 SKIP_WS(next);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003901
Jonathan Peyton30419822017-05-12 18:01:32 +00003902 if (*next == '\0') {
3903 break;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003904 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003905 // Next character is not an integer or not a comma OR number of values > 2
3906 // => end of list
3907 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
3908 KMP_WARNING(EnvSyntaxError, name, value);
3909 return;
3910 }
3911 // The next character is ','
3912 if (*next == ',') {
3913 // ',' is the fisrt character
3914 if (total == 0 || prev_comma) {
3915 total++;
3916 }
3917 prev_comma = TRUE;
3918 next++; // skip ','
3919 SKIP_WS(next);
3920 }
3921 // Next character is a digit
3922 if (*next >= '0' && *next <= '9') {
3923 int num;
3924 const char *buf = next;
3925 char const *msg = NULL;
3926 prev_comma = FALSE;
3927 SKIP_DIGITS(next);
3928 total++;
3929
3930 const char *tmp = next;
3931 SKIP_WS(tmp);
3932 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
3933 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003934 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00003935 }
3936
3937 num = __kmp_str_to_int(buf, *next);
3938 if (num <= 0) { // The number of retries should be > 0
3939 msg = KMP_I18N_STR(ValueTooSmall);
3940 num = 1;
3941 } else if (num > KMP_INT_MAX) {
3942 msg = KMP_I18N_STR(ValueTooLarge);
3943 num = KMP_INT_MAX;
3944 }
3945 if (msg != NULL) {
3946 // Message is not empty. Print warning.
3947 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
3948 KMP_INFORM(Using_int_Value, name, num);
3949 }
3950 if (total == 1) {
3951 max_backoff = num;
3952 } else if (total == 2) {
3953 min_tick = num;
3954 }
Jonathan Peyton377aa402016-04-14 16:00:37 +00003955 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003956 }
3957 KMP_DEBUG_ASSERT(total > 0);
3958 if (total <= 0) {
3959 KMP_WARNING(EnvSyntaxError, name, value);
3960 return;
3961 }
3962 __kmp_spin_backoff_params.max_backoff = max_backoff;
3963 __kmp_spin_backoff_params.min_tick = min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003964}
3965
Jonathan Peyton30419822017-05-12 18:01:32 +00003966static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
3967 char const *name, void *data) {
3968 if (__kmp_env_format) {
3969 KMP_STR_BUF_PRINT_NAME_EX(name);
3970 } else {
3971 __kmp_str_buf_print(buffer, " %s='", name);
3972 }
3973 __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
3974 __kmp_spin_backoff_params.min_tick);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003975}
3976
Jim Cownie5e8470a2013-09-27 10:38:44 +00003977#if KMP_USE_ADAPTIVE_LOCKS
3978
Jonathan Peyton30419822017-05-12 18:01:32 +00003979// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003980// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003981
3982// Parse out values for the tunable parameters from a string of the form
3983// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
Jonathan Peyton30419822017-05-12 18:01:32 +00003984static void __kmp_stg_parse_adaptive_lock_props(const char *name,
3985 const char *value, void *data) {
3986 int max_retries = 0;
3987 int max_badness = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003988
Jonathan Peyton30419822017-05-12 18:01:32 +00003989 const char *next = value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003990
Jonathan Peyton30419822017-05-12 18:01:32 +00003991 int total = 0; // Count elements that were set. It'll be used as an array size
3992 int prev_comma = FALSE; // For correct processing sequential commas
3993 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003994
Jonathan Peyton30419822017-05-12 18:01:32 +00003995 // Save values in the structure __kmp_speculative_backoff_params
3996 // Run only 3 iterations because it is enough to read two values or find a
3997 // syntax error
3998 for (i = 0; i < 3; i++) {
3999 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004000
Jonathan Peyton30419822017-05-12 18:01:32 +00004001 if (*next == '\0') {
4002 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004003 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004004 // Next character is not an integer or not a comma OR number of values > 2
4005 // => end of list
4006 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
4007 KMP_WARNING(EnvSyntaxError, name, value);
4008 return;
4009 }
4010 // The next character is ','
4011 if (*next == ',') {
4012 // ',' is the fisrt character
4013 if (total == 0 || prev_comma) {
4014 total++;
4015 }
4016 prev_comma = TRUE;
4017 next++; // skip ','
4018 SKIP_WS(next);
4019 }
4020 // Next character is a digit
4021 if (*next >= '0' && *next <= '9') {
4022 int num;
4023 const char *buf = next;
4024 char const *msg = NULL;
4025 prev_comma = FALSE;
4026 SKIP_DIGITS(next);
4027 total++;
4028
4029 const char *tmp = next;
4030 SKIP_WS(tmp);
4031 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4032 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004033 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00004034 }
4035
4036 num = __kmp_str_to_int(buf, *next);
4037 if (num < 0) { // The number of retries should be >= 0
4038 msg = KMP_I18N_STR(ValueTooSmall);
4039 num = 1;
4040 } else if (num > KMP_INT_MAX) {
4041 msg = KMP_I18N_STR(ValueTooLarge);
4042 num = KMP_INT_MAX;
4043 }
4044 if (msg != NULL) {
4045 // Message is not empty. Print warning.
4046 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4047 KMP_INFORM(Using_int_Value, name, num);
4048 }
4049 if (total == 1) {
4050 max_retries = num;
4051 } else if (total == 2) {
4052 max_badness = num;
4053 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004054 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004055 }
4056 KMP_DEBUG_ASSERT(total > 0);
4057 if (total <= 0) {
4058 KMP_WARNING(EnvSyntaxError, name, value);
4059 return;
4060 }
4061 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4062 __kmp_adaptive_backoff_params.max_badness = max_badness;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004063}
4064
Jonathan Peyton30419822017-05-12 18:01:32 +00004065static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4066 char const *name, void *data) {
4067 if (__kmp_env_format) {
4068 KMP_STR_BUF_PRINT_NAME_EX(name);
4069 } else {
4070 __kmp_str_buf_print(buffer, " %s='", name);
4071 }
4072 __kmp_str_buf_print(buffer, "%d,%d'\n",
4073 __kmp_adaptive_backoff_params.max_soft_retries,
4074 __kmp_adaptive_backoff_params.max_badness);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004075} // __kmp_stg_print_adaptive_lock_props
4076
4077#if KMP_DEBUG_ADAPTIVE_LOCKS
4078
Jonathan Peyton30419822017-05-12 18:01:32 +00004079static void __kmp_stg_parse_speculative_statsfile(char const *name,
4080 char const *value,
4081 void *data) {
4082 __kmp_stg_parse_file(name, value, "", &__kmp_speculative_statsfile);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004083} // __kmp_stg_parse_speculative_statsfile
4084
Jonathan Peyton30419822017-05-12 18:01:32 +00004085static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
4086 char const *name,
4087 void *data) {
4088 if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
4089 __kmp_stg_print_str(buffer, name, "stdout");
4090 } else {
4091 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
4092 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004093
4094} // __kmp_stg_print_speculative_statsfile
4095
4096#endif // KMP_DEBUG_ADAPTIVE_LOCKS
4097
4098#endif // KMP_USE_ADAPTIVE_LOCKS
4099
Jonathan Peyton30419822017-05-12 18:01:32 +00004100// -----------------------------------------------------------------------------
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004101// KMP_HW_SUBSET (was KMP_PLACE_THREADS)
Jim Cownie5e8470a2013-09-27 10:38:44 +00004102
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004103// The longest observable sequense of items is
4104// Socket-Node-Tile-Core-Thread
4105// So, let's limit to 5 levels for now
4106// The input string is usually short enough, let's use 512 limit for now
4107#define MAX_T_LEVEL 5
4108#define MAX_STR_LEN 512
Jonathan Peyton30419822017-05-12 18:01:32 +00004109static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
4110 void *data) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004111 // Value example: 1s,5c@3,2T
4112 // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
Jonathan Peyton3f850bf2017-10-06 19:23:19 +00004113 kmp_setting_t **rivals = (kmp_setting_t **)data;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004114 if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
4115 KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004116 }
Jonathan Peyton3f850bf2017-10-06 19:23:19 +00004117 if (__kmp_stg_check_rivals(name, value, rivals)) {
4118 return;
4119 }
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004120
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004121 char *components[MAX_T_LEVEL];
4122 char const *digits = "0123456789";
4123 char input[MAX_STR_LEN];
4124 size_t len = 0, mlen = MAX_STR_LEN;
4125 int level = 0;
4126 // Canonize the string (remove spaces, unify delimiters, etc.)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004127 char *pos = CCAST(char *, value);
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004128 while (*pos && mlen) {
4129 if (*pos != ' ') { // skip spaces
4130 if (len == 0 && *pos == ':') {
4131 __kmp_hws_abs_flag = 1; // if the first symbol is ":", skip it
4132 } else {
4133 input[len] = toupper(*pos);
4134 if (input[len] == 'X')
4135 input[len] = ','; // unify delimiters of levels
4136 if (input[len] == 'O' && strchr(digits, *(pos + 1)))
4137 input[len] = '@'; // unify delimiters of offset
4138 len++;
4139 }
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004140 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004141 mlen--;
4142 pos++;
4143 }
4144 if (len == 0 || mlen == 0)
4145 goto err; // contents is either empty or too long
4146 input[len] = '\0';
4147 __kmp_hws_requested = 1; // mark that subset requested
4148 // Split by delimiter
4149 pos = input;
4150 components[level++] = pos;
George Rokos4800fc42017-04-25 15:55:39 +00004151 while ((pos = strchr(pos, ','))) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004152 *pos = '\0'; // modify input and avoid more copying
4153 components[level++] = ++pos; // expect something after ","
4154 if (level > MAX_T_LEVEL)
4155 goto err; // too many components provided
4156 }
4157 // Check each component
4158 for (int i = 0; i < level; ++i) {
4159 int offset = 0;
4160 int num = atoi(components[i]); // each component should start with a number
4161 if ((pos = strchr(components[i], '@'))) {
4162 offset = atoi(pos + 1); // save offset
4163 *pos = '\0'; // cut the offset from the component
4164 }
4165 pos = components[i] + strspn(components[i], digits);
4166 if (pos == components[i])
4167 goto err;
4168 // detect the component type
4169 switch (*pos) {
4170 case 'S': // Socket
4171 if (__kmp_hws_socket.num > 0)
4172 goto err; // duplicate is not allowed
4173 __kmp_hws_socket.num = num;
4174 __kmp_hws_socket.offset = offset;
4175 break;
4176 case 'N': // NUMA Node
4177 if (__kmp_hws_node.num > 0)
4178 goto err; // duplicate is not allowed
4179 __kmp_hws_node.num = num;
4180 __kmp_hws_node.offset = offset;
4181 break;
4182 case 'L': // Cache
4183 if (*(pos + 1) == '2') { // L2 - Tile
4184 if (__kmp_hws_tile.num > 0)
4185 goto err; // duplicate is not allowed
4186 __kmp_hws_tile.num = num;
4187 __kmp_hws_tile.offset = offset;
4188 } else if (*(pos + 1) == '3') { // L3 - Socket
4189 if (__kmp_hws_socket.num > 0)
4190 goto err; // duplicate is not allowed
4191 __kmp_hws_socket.num = num;
4192 __kmp_hws_socket.offset = offset;
4193 } else if (*(pos + 1) == '1') { // L1 - Core
4194 if (__kmp_hws_core.num > 0)
4195 goto err; // duplicate is not allowed
4196 __kmp_hws_core.num = num;
4197 __kmp_hws_core.offset = offset;
4198 }
4199 break;
4200 case 'C': // Core (or Cache?)
4201 if (*(pos + 1) != 'A') {
4202 if (__kmp_hws_core.num > 0)
4203 goto err; // duplicate is not allowed
4204 __kmp_hws_core.num = num;
4205 __kmp_hws_core.offset = offset;
4206 } else { // Cache
4207 char *d = pos + strcspn(pos, digits); // find digit
4208 if (*d == '2') { // L2 - Tile
4209 if (__kmp_hws_tile.num > 0)
4210 goto err; // duplicate is not allowed
4211 __kmp_hws_tile.num = num;
4212 __kmp_hws_tile.offset = offset;
4213 } else if (*d == '3') { // L3 - Socket
4214 if (__kmp_hws_socket.num > 0)
4215 goto err; // duplicate is not allowed
4216 __kmp_hws_socket.num = num;
4217 __kmp_hws_socket.offset = offset;
4218 } else if (*d == '1') { // L1 - Core
4219 if (__kmp_hws_core.num > 0)
4220 goto err; // duplicate is not allowed
4221 __kmp_hws_core.num = num;
4222 __kmp_hws_core.offset = offset;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004223 } else {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004224 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004225 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004226 }
4227 break;
4228 case 'T': // Thread
4229 if (__kmp_hws_proc.num > 0)
4230 goto err; // duplicate is not allowed
4231 __kmp_hws_proc.num = num;
4232 __kmp_hws_proc.offset = offset;
4233 break;
4234 default:
4235 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004236 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004237 }
4238 return;
4239err:
4240 KMP_WARNING(AffHWSubsetInvalid, name, value);
4241 __kmp_hws_requested = 0; // mark that subset not requested
4242 return;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004243}
4244
Jonathan Peyton30419822017-05-12 18:01:32 +00004245static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004246 void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +00004247 if (__kmp_hws_requested) {
4248 int comma = 0;
4249 kmp_str_buf_t buf;
4250 __kmp_str_buf_init(&buf);
4251 if (__kmp_env_format)
4252 KMP_STR_BUF_PRINT_NAME_EX(name);
4253 else
4254 __kmp_str_buf_print(buffer, " %s='", name);
4255 if (__kmp_hws_socket.num) {
4256 __kmp_str_buf_print(&buf, "%ds", __kmp_hws_socket.num);
4257 if (__kmp_hws_socket.offset)
4258 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_socket.offset);
4259 comma = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004260 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004261 if (__kmp_hws_node.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004262 __kmp_str_buf_print(&buf, "%s%dn", comma ? "," : "", __kmp_hws_node.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004263 if (__kmp_hws_node.offset)
4264 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_node.offset);
4265 comma = 1;
4266 }
4267 if (__kmp_hws_tile.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004268 __kmp_str_buf_print(&buf, "%s%dL2", comma ? "," : "", __kmp_hws_tile.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004269 if (__kmp_hws_tile.offset)
4270 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_tile.offset);
4271 comma = 1;
4272 }
4273 if (__kmp_hws_core.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004274 __kmp_str_buf_print(&buf, "%s%dc", comma ? "," : "", __kmp_hws_core.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004275 if (__kmp_hws_core.offset)
4276 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_core.offset);
4277 comma = 1;
4278 }
4279 if (__kmp_hws_proc.num)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004280 __kmp_str_buf_print(&buf, "%s%dt", comma ? "," : "", __kmp_hws_proc.num);
4281 __kmp_str_buf_print(buffer, "%s'\n", buf.str);
Jonathan Peyton30419822017-05-12 18:01:32 +00004282 __kmp_str_buf_free(&buf);
4283 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004284}
Jim Cownie5e8470a2013-09-27 10:38:44 +00004285
4286#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004287// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004288// KMP_FORKJOIN_FRAMES
Jim Cownie5e8470a2013-09-27 10:38:44 +00004289
Jonathan Peyton30419822017-05-12 18:01:32 +00004290static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
4291 void *data) {
4292 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004293} // __kmp_stg_parse_forkjoin_frames
4294
Jonathan Peyton30419822017-05-12 18:01:32 +00004295static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
4296 char const *name, void *data) {
4297 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004298} // __kmp_stg_print_forkjoin_frames
4299
Jonathan Peyton30419822017-05-12 18:01:32 +00004300// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004301// KMP_FORKJOIN_FRAMES_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00004302
Jonathan Peyton30419822017-05-12 18:01:32 +00004303static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
4304 char const *value,
4305 void *data) {
4306 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004307} // __kmp_stg_parse_forkjoin_frames
4308
Jonathan Peyton30419822017-05-12 18:01:32 +00004309static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
4310 char const *name, void *data) {
4311 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004312} // __kmp_stg_print_forkjoin_frames
4313#endif /* USE_ITT_BUILD */
4314
Jonathan Peyton30419822017-05-12 18:01:32 +00004315// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004316// OMP_DISPLAY_ENV
Jim Cownie5e8470a2013-09-27 10:38:44 +00004317
4318#if OMP_40_ENABLED
4319
Jonathan Peyton30419822017-05-12 18:01:32 +00004320static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
4321 void *data) {
4322 if (__kmp_str_match("VERBOSE", 1, value)) {
4323 __kmp_display_env_verbose = TRUE;
4324 } else {
4325 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
4326 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004327
4328} // __kmp_stg_parse_omp_display_env
4329
Jonathan Peyton30419822017-05-12 18:01:32 +00004330static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
4331 char const *name, void *data) {
4332 if (__kmp_display_env_verbose) {
4333 __kmp_stg_print_str(buffer, name, "VERBOSE");
4334 } else {
4335 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
4336 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004337} // __kmp_stg_print_omp_display_env
4338
Jonathan Peyton30419822017-05-12 18:01:32 +00004339static void __kmp_stg_parse_omp_cancellation(char const *name,
4340 char const *value, void *data) {
4341 if (TCR_4(__kmp_init_parallel)) {
4342 KMP_WARNING(EnvParallelWarn, name);
4343 return;
4344 } // read value before first parallel only
4345 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004346} // __kmp_stg_parse_omp_cancellation
4347
Jonathan Peyton30419822017-05-12 18:01:32 +00004348static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
4349 char const *name, void *data) {
4350 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004351} // __kmp_stg_print_omp_cancellation
4352
Jim Cownie5e8470a2013-09-27 10:38:44 +00004353#endif
4354
Joachim Protze82e94a52017-11-01 10:08:30 +00004355#if OMP_50_ENABLED && OMPT_SUPPORT
4356
4357static void __kmp_stg_parse_omp_tool_libraries(char const *name,
4358 char const *value, void *data) {
4359 __kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
4360} // __kmp_stg_parse_omp_tool_libraries
4361
4362static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer,
4363 char const *name, void *data) {
4364 if (__kmp_tool_libraries)
4365 __kmp_stg_print_str(buffer, name, __kmp_tool_libraries);
4366 else {
4367 if (__kmp_env_format) {
4368 KMP_STR_BUF_PRINT_NAME;
4369 } else {
4370 __kmp_str_buf_print(buffer, " %s", name);
4371 }
4372 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
4373 }
4374} // __kmp_stg_print_omp_tool_libraries
4375
4376#endif
4377
Jim Cownie5e8470a2013-09-27 10:38:44 +00004378// Table.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004379
4380static kmp_setting_t __kmp_stg_table[] = {
4381
Jonathan Peyton09244f32017-07-26 20:07:58 +00004382 {"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
Jonathan Peyton30419822017-05-12 18:01:32 +00004383 {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
4384 NULL, 0, 0},
4385 {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
4386 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
4387 {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
4388 NULL, 0, 0},
Jonathan Peyton09244f32017-07-26 20:07:58 +00004389 {"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
4390 __kmp_stg_print_device_thread_limit, NULL, 0, 0},
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004391#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +00004392 {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
4393 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004394#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004395 {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
4396 0, 0},
4397 {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
4398 __kmp_stg_print_stackoffset, NULL, 0, 0},
4399 {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4400 NULL, 0, 0},
4401 {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
4402 0, 0},
4403 {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
4404 0},
4405 {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
4406 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004407
Jonathan Peyton30419822017-05-12 18:01:32 +00004408 {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
4409 {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
4410 __kmp_stg_print_num_threads, NULL, 0, 0},
4411 {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4412 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004413
Jonathan Peyton30419822017-05-12 18:01:32 +00004414 {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
4415 0},
4416 {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
4417 __kmp_stg_print_task_stealing, NULL, 0, 0},
4418 {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
4419 __kmp_stg_print_max_active_levels, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004420#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004421 {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
4422 __kmp_stg_print_default_device, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004423#endif
Jonathan Peytondf6818b2016-06-14 17:57:47 +00004424#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004425 {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
4426 __kmp_stg_print_max_task_priority, NULL, 0, 0},
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00004427 {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
4428 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
Jonathan Peyton28510722016-02-25 18:04:09 +00004429#endif
Jonathan Peytonf4392462017-07-27 20:58:41 +00004430 {"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
4431 __kmp_stg_print_thread_limit, NULL, 0, 0},
Jonathan Peyton4f90c822017-08-02 20:04:45 +00004432 {"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
4433 __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
Jonathan Peyton30419822017-05-12 18:01:32 +00004434 {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
4435 __kmp_stg_print_wait_policy, NULL, 0, 0},
4436 {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
4437 __kmp_stg_print_disp_buffers, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004438#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00004439 {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
4440 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
4441 {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
4442 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004443#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00004444
4445#if KMP_HANDLE_SIGNALS
Jonathan Peyton30419822017-05-12 18:01:32 +00004446 {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
4447 __kmp_stg_print_handle_signals, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004448#endif
4449
4450#if KMP_ARCH_X86 || KMP_ARCH_X86_64
Jonathan Peyton30419822017-05-12 18:01:32 +00004451 {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
4452 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004453#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
4454
4455#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004456 {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004457#endif
4458
4459#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00004460 {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
4461 0},
4462 {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
4463 0},
4464 {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
4465 0},
4466 {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
4467 0},
4468 {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
4469 0},
4470 {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
4471 0},
4472 {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
4473 {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
4474 NULL, 0, 0},
4475 {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
4476 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
4477 {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
4478 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
4479 {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
4480 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
4481 {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004482
Jonathan Peyton30419822017-05-12 18:01:32 +00004483 {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
4484 __kmp_stg_print_par_range_env, NULL, 0, 0},
4485 {"KMP_YIELD_CYCLE", __kmp_stg_parse_yield_cycle,
4486 __kmp_stg_print_yield_cycle, NULL, 0, 0},
4487 {"KMP_YIELD_ON", __kmp_stg_parse_yield_on, __kmp_stg_print_yield_on, NULL,
4488 0, 0},
4489 {"KMP_YIELD_OFF", __kmp_stg_parse_yield_off, __kmp_stg_print_yield_off,
4490 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004491#endif // KMP_DEBUG
4492
Jonathan Peyton30419822017-05-12 18:01:32 +00004493 {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
4494 __kmp_stg_print_align_alloc, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004495
Jonathan Peyton30419822017-05-12 18:01:32 +00004496 {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4497 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4498 {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4499 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
4500 {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4501 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4502 {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4503 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004504#if KMP_FAST_REDUCTION_BARRIER
Jonathan Peyton30419822017-05-12 18:01:32 +00004505 {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4506 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4507 {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4508 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004509#endif
4510
Jonathan Peyton30419822017-05-12 18:01:32 +00004511 {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
4512 __kmp_stg_print_abort_delay, NULL, 0, 0},
4513 {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
4514 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
4515 {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
4516 __kmp_stg_print_force_reduction, NULL, 0, 0},
4517 {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
4518 __kmp_stg_print_force_reduction, NULL, 0, 0},
4519 {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
4520 __kmp_stg_print_storage_map, NULL, 0, 0},
4521 {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
4522 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
4523 {"KMP_FOREIGN_THREADS_THREADPRIVATE",
4524 __kmp_stg_parse_foreign_threads_threadprivate,
4525 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004526
Alp Toker98758b02014-03-02 04:12:06 +00004527#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004528 {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
4529 0, 0},
4530#ifdef KMP_GOMP_COMPAT
4531 {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
4532 /* no print */ NULL, 0, 0},
4533#endif /* KMP_GOMP_COMPAT */
4534#if OMP_40_ENABLED
4535 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4536 NULL, 0, 0},
4537 {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
4538#else
4539 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, NULL, /* no print */ NULL, 0,
4540 0},
4541#endif /* OMP_40_ENABLED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00004542
Jonathan Peyton30419822017-05-12 18:01:32 +00004543 {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
4544 __kmp_stg_print_topology_method, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004545
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004546#else
Jim Cownie5e8470a2013-09-27 10:38:44 +00004547
Jonathan Peyton30419822017-05-12 18:01:32 +00004548// KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
4549// OMP_PROC_BIND and proc-bind-var are supported, however.
4550#if OMP_40_ENABLED
4551 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4552 NULL, 0, 0},
4553#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004554
Alp Toker98758b02014-03-02 04:12:06 +00004555#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004556
Jonathan Peyton30419822017-05-12 18:01:32 +00004557 {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
4558 __kmp_stg_print_init_at_fork, NULL, 0, 0},
4559 {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
4560 0, 0},
4561 {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
4562 NULL, 0, 0},
4563 {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
4564 __kmp_stg_print_atomic_mode, NULL, 0, 0},
4565 {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
4566 __kmp_stg_print_consistency_check, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004567
4568#if USE_ITT_BUILD && USE_ITT_NOTIFY
Jonathan Peyton30419822017-05-12 18:01:32 +00004569 {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
4570 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004571#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
Jonathan Peyton30419822017-05-12 18:01:32 +00004572 {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
4573 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
4574 {"KMP_INIT_WAIT", __kmp_stg_parse_init_wait, __kmp_stg_print_init_wait,
4575 NULL, 0, 0},
4576 {"KMP_NEXT_WAIT", __kmp_stg_parse_next_wait, __kmp_stg_print_next_wait,
4577 NULL, 0, 0},
4578 {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
4579 NULL, 0, 0},
4580 {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
4581 NULL, 0, 0},
4582 {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
4583 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004584
4585#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00004586 {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
4587 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004588#endif
4589
Jonathan Peyton30419822017-05-12 18:01:32 +00004590 {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
4591 __kmp_stg_print_lock_block, NULL, 0, 0},
4592 {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
4593 NULL, 0, 0},
4594 {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
4595 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004596#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004597 {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
4598 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004599#if KMP_DEBUG_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004600 {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
4601 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004602#endif
4603#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004604 {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4605 NULL, 0, 0},
4606 {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4607 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004608#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004609 {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
4610 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
4611 {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
4612 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004613#endif
4614
Jonathan Peyton30419822017-05-12 18:01:32 +00004615#if OMP_40_ENABLED
4616 {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
4617 __kmp_stg_print_omp_display_env, NULL, 0, 0},
4618 {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
4619 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004620#endif
Joachim Protze82e94a52017-11-01 10:08:30 +00004621
4622#if OMP_50_ENABLED && OMPT_SUPPORT
4623 {"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries,
4624 __kmp_stg_print_omp_tool_libraries, NULL, 0, 0},
4625#endif
4626
Jonathan Peyton30419822017-05-12 18:01:32 +00004627 {"", NULL, NULL, NULL, 0, 0}}; // settings
Jim Cownie5e8470a2013-09-27 10:38:44 +00004628
Jonathan Peyton30419822017-05-12 18:01:32 +00004629static int const __kmp_stg_count =
4630 sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004631
Jonathan Peyton30419822017-05-12 18:01:32 +00004632static inline kmp_setting_t *__kmp_stg_find(char const *name) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004633
Jonathan Peyton30419822017-05-12 18:01:32 +00004634 int i;
4635 if (name != NULL) {
4636 for (i = 0; i < __kmp_stg_count; ++i) {
4637 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
4638 return &__kmp_stg_table[i];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004639 }
4640 }
4641 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004642 return NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004643
4644} // __kmp_stg_find
4645
Jonathan Peyton30419822017-05-12 18:01:32 +00004646static int __kmp_stg_cmp(void const *_a, void const *_b) {
Andrey Churbanov5ba90c72017-07-17 09:03:14 +00004647 const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
4648 const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004649
Jonathan Peyton30419822017-05-12 18:01:32 +00004650 // Process KMP_AFFINITY last.
4651 // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
4652 if (strcmp(a->name, "KMP_AFFINITY") == 0) {
4653 if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4654 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004655 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004656 return 1;
4657 } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4658 return -1;
4659 }
4660 return strcmp(a->name, b->name);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004661} // __kmp_stg_cmp
4662
Jonathan Peyton30419822017-05-12 18:01:32 +00004663static void __kmp_stg_init(void) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004664
Jonathan Peyton30419822017-05-12 18:01:32 +00004665 static int initialized = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004666
Jonathan Peyton30419822017-05-12 18:01:32 +00004667 if (!initialized) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004668
Jonathan Peyton30419822017-05-12 18:01:32 +00004669 // Sort table.
4670 qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
4671 __kmp_stg_cmp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004672
Jonathan Peyton30419822017-05-12 18:01:32 +00004673 { // Initialize *_STACKSIZE data.
4674 kmp_setting_t *kmp_stacksize =
4675 __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004676#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004677 kmp_setting_t *gomp_stacksize =
4678 __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004679#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004680 kmp_setting_t *omp_stacksize =
4681 __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004682
Jonathan Peyton30419822017-05-12 18:01:32 +00004683 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4684 // !!! Compiler does not understand rivals is used and optimizes out
4685 // assignments
4686 // !!! rivals[ i ++ ] = ...;
4687 static kmp_setting_t *volatile rivals[4];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004688 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004689#ifdef KMP_GOMP_COMPAT
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004690 static kmp_stg_ss_data_t gomp_data = {1024,
4691 CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004692#endif
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004693 static kmp_stg_ss_data_t omp_data = {1024,
4694 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004695 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004696
Jonathan Peyton30419822017-05-12 18:01:32 +00004697 rivals[i++] = kmp_stacksize;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004698#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004699 if (gomp_stacksize != NULL) {
4700 rivals[i++] = gomp_stacksize;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004701 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004702#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004703 rivals[i++] = omp_stacksize;
4704 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004705
Jonathan Peyton30419822017-05-12 18:01:32 +00004706 kmp_stacksize->data = &kmp_data;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004707#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004708 if (gomp_stacksize != NULL) {
4709 gomp_stacksize->data = &gomp_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004710 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004711#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004712 omp_stacksize->data = &omp_data;
4713 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004714
Jonathan Peyton30419822017-05-12 18:01:32 +00004715 { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
4716 kmp_setting_t *kmp_library =
4717 __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
4718 kmp_setting_t *omp_wait_policy =
4719 __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004720
Jonathan Peyton30419822017-05-12 18:01:32 +00004721 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4722 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004723 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
4724 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004725 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004726
Jonathan Peyton30419822017-05-12 18:01:32 +00004727 rivals[i++] = kmp_library;
4728 if (omp_wait_policy != NULL) {
4729 rivals[i++] = omp_wait_policy;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004730 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004731 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004732
Jonathan Peyton30419822017-05-12 18:01:32 +00004733 kmp_library->data = &kmp_data;
4734 if (omp_wait_policy != NULL) {
4735 omp_wait_policy->data = &omp_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004736 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004737 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004738
Jonathan Peytonf4392462017-07-27 20:58:41 +00004739 { // Initialize KMP_DEVICE_THREAD_LIMIT and KMP_ALL_THREADS
Jonathan Peyton09244f32017-07-26 20:07:58 +00004740 kmp_setting_t *kmp_device_thread_limit =
4741 __kmp_stg_find("KMP_DEVICE_THREAD_LIMIT"); // 1st priority.
Jonathan Peyton30419822017-05-12 18:01:32 +00004742 kmp_setting_t *kmp_all_threads =
Jonathan Peyton09244f32017-07-26 20:07:58 +00004743 __kmp_stg_find("KMP_ALL_THREADS"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004744
Jonathan Peyton30419822017-05-12 18:01:32 +00004745 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
Jonathan Peytonf4392462017-07-27 20:58:41 +00004746 static kmp_setting_t *volatile rivals[3];
Jonathan Peyton30419822017-05-12 18:01:32 +00004747 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004748
Jonathan Peyton09244f32017-07-26 20:07:58 +00004749 rivals[i++] = kmp_device_thread_limit;
Jonathan Peyton30419822017-05-12 18:01:32 +00004750 rivals[i++] = kmp_all_threads;
Jonathan Peyton30419822017-05-12 18:01:32 +00004751 rivals[i++] = NULL;
Jonathan Peyton09244f32017-07-26 20:07:58 +00004752
4753 kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004754 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004755 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004756
Jonathan Peyton3f850bf2017-10-06 19:23:19 +00004757 { // Initialize KMP_HW_SUBSET and KMP_PLACE_THREADS
4758 // 1st priority
4759 kmp_setting_t *kmp_hw_subset = __kmp_stg_find("KMP_HW_SUBSET");
4760 // 2nd priority
4761 kmp_setting_t *kmp_place_threads = __kmp_stg_find("KMP_PLACE_THREADS");
4762
4763 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4764 static kmp_setting_t *volatile rivals[3];
4765 int i = 0;
4766
4767 rivals[i++] = kmp_hw_subset;
4768 rivals[i++] = kmp_place_threads;
4769 rivals[i++] = NULL;
4770
4771 kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
4772 kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
4773 }
4774
Alp Toker98758b02014-03-02 04:12:06 +00004775#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004776 { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
4777 kmp_setting_t *kmp_affinity =
4778 __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
4779 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004780
Jonathan Peyton30419822017-05-12 18:01:32 +00004781#ifdef KMP_GOMP_COMPAT
4782 kmp_setting_t *gomp_cpu_affinity =
4783 __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
4784 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
4785#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004786
Jonathan Peyton30419822017-05-12 18:01:32 +00004787 kmp_setting_t *omp_proc_bind =
4788 __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
4789 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004790
Jonathan Peyton30419822017-05-12 18:01:32 +00004791 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4792 static kmp_setting_t *volatile rivals[4];
4793 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004794
Jonathan Peyton30419822017-05-12 18:01:32 +00004795 rivals[i++] = kmp_affinity;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004796
Jonathan Peyton30419822017-05-12 18:01:32 +00004797#ifdef KMP_GOMP_COMPAT
4798 rivals[i++] = gomp_cpu_affinity;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004799 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004800#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004801
Jonathan Peyton30419822017-05-12 18:01:32 +00004802 rivals[i++] = omp_proc_bind;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004803 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004804 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004805
Jonathan Peyton30419822017-05-12 18:01:32 +00004806#if OMP_40_ENABLED
4807 static kmp_setting_t *volatile places_rivals[4];
4808 i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004809
Jonathan Peyton30419822017-05-12 18:01:32 +00004810 kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
4811 KMP_DEBUG_ASSERT(omp_places != NULL);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004812
Jonathan Peyton30419822017-05-12 18:01:32 +00004813 places_rivals[i++] = kmp_affinity;
4814#ifdef KMP_GOMP_COMPAT
4815 places_rivals[i++] = gomp_cpu_affinity;
4816#endif
4817 places_rivals[i++] = omp_places;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004818 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004819 places_rivals[i++] = NULL;
4820#endif
4821 }
Alp Toker98758b02014-03-02 04:12:06 +00004822#else
Jonathan Peyton30419822017-05-12 18:01:32 +00004823// KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
4824// OMP_PLACES not supported yet.
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004825#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004826
Jonathan Peyton30419822017-05-12 18:01:32 +00004827 { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
4828 kmp_setting_t *kmp_force_red =
4829 __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
4830 kmp_setting_t *kmp_determ_red =
4831 __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004832
Jonathan Peyton30419822017-05-12 18:01:32 +00004833 // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
4834 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004835 static kmp_stg_fr_data_t force_data = {1,
4836 CCAST(kmp_setting_t **, rivals)};
4837 static kmp_stg_fr_data_t determ_data = {0,
4838 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004839 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004840
Jonathan Peyton30419822017-05-12 18:01:32 +00004841 rivals[i++] = kmp_force_red;
4842 if (kmp_determ_red != NULL) {
4843 rivals[i++] = kmp_determ_red;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004844 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004845 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004846
Jonathan Peyton30419822017-05-12 18:01:32 +00004847 kmp_force_red->data = &force_data;
4848 if (kmp_determ_red != NULL) {
4849 kmp_determ_red->data = &determ_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004850 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004851 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004852
Jonathan Peyton30419822017-05-12 18:01:32 +00004853 initialized = 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004854 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004855
Jonathan Peyton30419822017-05-12 18:01:32 +00004856 // Reset flags.
4857 int i;
4858 for (i = 0; i < __kmp_stg_count; ++i) {
4859 __kmp_stg_table[i].set = 0;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004860 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004861
4862} // __kmp_stg_init
4863
Jonathan Peyton30419822017-05-12 18:01:32 +00004864static void __kmp_stg_parse(char const *name, char const *value) {
4865 // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
4866 // really nameless, they are presented in environment block as
4867 // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
4868 if (name[0] == 0) {
4869 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004870 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004871
Jonathan Peyton30419822017-05-12 18:01:32 +00004872 if (value != NULL) {
4873 kmp_setting_t *setting = __kmp_stg_find(name);
4874 if (setting != NULL) {
4875 setting->parse(name, value, setting->data);
4876 setting->defined = 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004877 }
4878 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004879
4880} // __kmp_stg_parse
4881
Jonathan Peyton30419822017-05-12 18:01:32 +00004882static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
4883 char const *name, // Name of variable.
4884 char const *value, // Value of the variable.
4885 kmp_setting_t **rivals // List of rival settings (must include current one).
4886 ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004887
Jonathan Peyton30419822017-05-12 18:01:32 +00004888 if (rivals == NULL) {
4889 return 0;
4890 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004891
Jonathan Peyton30419822017-05-12 18:01:32 +00004892 // Loop thru higher priority settings (listed before current).
4893 int i = 0;
4894 for (; strcmp(rivals[i]->name, name) != 0; i++) {
4895 KMP_DEBUG_ASSERT(rivals[i] != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004896
Alp Toker763b9392014-02-28 09:42:41 +00004897#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004898 if (rivals[i] == __kmp_affinity_notype) {
4899 // If KMP_AFFINITY is specified without a type name,
4900 // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
4901 continue;
4902 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004903#endif
4904
Jonathan Peyton30419822017-05-12 18:01:32 +00004905 if (rivals[i]->set) {
4906 KMP_WARNING(StgIgnored, name, rivals[i]->name);
4907 return 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004908 }
4909 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004910
Jonathan Peyton30419822017-05-12 18:01:32 +00004911 ++i; // Skip current setting.
4912 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004913
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004914} // __kmp_stg_check_rivals
Jim Cownie5e8470a2013-09-27 10:38:44 +00004915
Jonathan Peyton30419822017-05-12 18:01:32 +00004916static int __kmp_env_toPrint(char const *name, int flag) {
4917 int rc = 0;
4918 kmp_setting_t *setting = __kmp_stg_find(name);
4919 if (setting != NULL) {
4920 rc = setting->defined;
4921 if (flag >= 0) {
4922 setting->defined = flag;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004923 }
4924 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004925 return rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004926}
4927
Jonathan Peyton30419822017-05-12 18:01:32 +00004928static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004929
Jonathan Peyton30419822017-05-12 18:01:32 +00004930 char const *value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004931
Jonathan Peyton30419822017-05-12 18:01:32 +00004932 /* OMP_NUM_THREADS */
4933 value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
4934 if (value) {
4935 ompc_set_num_threads(__kmp_dflt_team_nth);
4936 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004937
Jonathan Peyton30419822017-05-12 18:01:32 +00004938 /* KMP_BLOCKTIME */
4939 value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
4940 if (value) {
4941 kmpc_set_blocktime(__kmp_dflt_blocktime);
4942 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004943
Jonathan Peyton30419822017-05-12 18:01:32 +00004944 /* OMP_NESTED */
4945 value = __kmp_env_blk_var(block, "OMP_NESTED");
4946 if (value) {
4947 ompc_set_nested(__kmp_dflt_nested);
4948 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004949
Jonathan Peyton30419822017-05-12 18:01:32 +00004950 /* OMP_DYNAMIC */
4951 value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
4952 if (value) {
4953 ompc_set_dynamic(__kmp_global.g.g_dynamic);
4954 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004955}
4956
Jonathan Peyton30419822017-05-12 18:01:32 +00004957void __kmp_env_initialize(char const *string) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004958
Jonathan Peyton30419822017-05-12 18:01:32 +00004959 kmp_env_blk_t block;
4960 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004961
Jonathan Peyton30419822017-05-12 18:01:32 +00004962 __kmp_stg_init();
Jim Cownie5e8470a2013-09-27 10:38:44 +00004963
Jonathan Peyton30419822017-05-12 18:01:32 +00004964 // Hack!!!
4965 if (string == NULL) {
4966 // __kmp_max_nth = __kmp_sys_max_nth;
4967 __kmp_threads_capacity =
4968 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004969 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004970 __kmp_env_blk_init(&block, string);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004971
Jonathan Peyton30419822017-05-12 18:01:32 +00004972 // update the set flag on all entries that have an env var
4973 for (i = 0; i < block.count; ++i) {
4974 if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
4975 continue;
4976 }
4977 if (block.vars[i].value == NULL) {
4978 continue;
4979 }
4980 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
4981 if (setting != NULL) {
4982 setting->set = 1;
4983 }
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004984 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004985
Jonathan Peyton94a114f2017-10-20 19:30:57 +00004986 // We need to know if blocktime was set when processing OMP_WAIT_POLICY
Jonathan Peyton30419822017-05-12 18:01:32 +00004987 blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
Jonathan Peyton50e8f182016-04-04 19:38:32 +00004988
Jonathan Peyton30419822017-05-12 18:01:32 +00004989 // Special case. If we parse environment, not a string, process KMP_WARNINGS
4990 // first.
4991 if (string == NULL) {
4992 char const *name = "KMP_WARNINGS";
4993 char const *value = __kmp_env_blk_var(&block, name);
4994 __kmp_stg_parse(name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004995 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004996
Alp Toker763b9392014-02-28 09:42:41 +00004997#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004998 // Special case. KMP_AFFINITY is not a rival to other affinity env vars
4999 // if no affinity type is specified. We want to allow
5000 // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
5001 // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
5002 // affinity mechanism.
5003 __kmp_affinity_notype = NULL;
5004 char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
5005 if (aff_str != NULL) {
5006// Check if the KMP_AFFINITY type is specified in the string.
5007// We just search the string for "compact", "scatter", etc.
5008// without really parsing the string. The syntax of the
5009// KMP_AFFINITY env var is such that none of the affinity
5010// type names can appear anywhere other that the type
5011// specifier, even as substrings.
5012//
5013// I can't find a case-insensitive version of strstr on Windows* OS.
5014// Use the case-sensitive version for now.
Jim Cownie5e8470a2013-09-27 10:38:44 +00005015
Jonathan Peyton30419822017-05-12 18:01:32 +00005016#if KMP_OS_WINDOWS
5017#define FIND strstr
5018#else
5019#define FIND strcasestr
5020#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00005021
Jonathan Peyton30419822017-05-12 18:01:32 +00005022 if ((FIND(aff_str, "none") == NULL) &&
5023 (FIND(aff_str, "physical") == NULL) &&
5024 (FIND(aff_str, "logical") == NULL) &&
5025 (FIND(aff_str, "compact") == NULL) &&
5026 (FIND(aff_str, "scatter") == NULL) &&
5027 (FIND(aff_str, "explicit") == NULL) &&
5028 (FIND(aff_str, "balanced") == NULL) &&
5029 (FIND(aff_str, "disabled") == NULL)) {
5030 __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
5031 } else {
5032 // A new affinity type is specified.
5033 // Reset the affinity flags to their default values,
5034 // in case this is called from kmp_set_defaults().
5035 __kmp_affinity_type = affinity_default;
5036 __kmp_affinity_gran = affinity_gran_default;
5037 __kmp_affinity_top_method = affinity_top_method_default;
5038 __kmp_affinity_respect_mask = affinity_respect_mask_default;
5039 }
5040#undef FIND
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005041
5042#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005043 // Also reset the affinity flags if OMP_PROC_BIND is specified.
5044 aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
5045 if (aff_str != NULL) {
5046 __kmp_affinity_type = affinity_default;
5047 __kmp_affinity_gran = affinity_gran_default;
5048 __kmp_affinity_top_method = affinity_top_method_default;
5049 __kmp_affinity_respect_mask = affinity_respect_mask_default;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005050 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005051#endif /* OMP_40_ENABLED */
5052 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005053
Alp Toker763b9392014-02-28 09:42:41 +00005054#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005055
5056#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005057 // Set up the nested proc bind type vector.
5058 if (__kmp_nested_proc_bind.bind_types == NULL) {
5059 __kmp_nested_proc_bind.bind_types =
5060 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
5061 if (__kmp_nested_proc_bind.bind_types == NULL) {
5062 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005063 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005064 __kmp_nested_proc_bind.size = 1;
5065 __kmp_nested_proc_bind.used = 1;
5066#if KMP_AFFINITY_SUPPORTED
5067 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
5068#else
5069 // default proc bind is false if affinity not supported
5070 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5071#endif
5072 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005073#endif /* OMP_40_ENABLED */
5074
Jonathan Peyton30419822017-05-12 18:01:32 +00005075 // Now process all of the settings.
5076 for (i = 0; i < block.count; ++i) {
5077 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005078 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005079
Jonathan Peyton30419822017-05-12 18:01:32 +00005080 // If user locks have been allocated yet, don't reset the lock vptr table.
5081 if (!__kmp_init_user_locks) {
5082 if (__kmp_user_lock_kind == lk_default) {
5083 __kmp_user_lock_kind = lk_queuing;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005084 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005085#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00005086 __kmp_init_dynamic_user_locks();
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005087#else
Jonathan Peyton30419822017-05-12 18:01:32 +00005088 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005089#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005090 } else {
5091 KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
5092 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
5093// Binds lock functions again to follow the transition between different
5094// KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
5095// as we do not allow lock kind changes after making a call to any
5096// user lock functions (true).
5097#if KMP_USE_DYNAMIC_LOCK
5098 __kmp_init_dynamic_user_locks();
5099#else
5100 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5101#endif
5102 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005103
Alp Toker763b9392014-02-28 09:42:41 +00005104#if KMP_AFFINITY_SUPPORTED
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005105
Jonathan Peyton30419822017-05-12 18:01:32 +00005106 if (!TCR_4(__kmp_init_middle)) {
5107 // Determine if the machine/OS is actually capable of supporting
5108 // affinity.
5109 const char *var = "KMP_AFFINITY";
5110 KMPAffinity::pick_api();
Jonathan Peytone3e2aaf2017-05-31 20:35:22 +00005111#if KMP_USE_HWLOC
5112 // If Hwloc topology discovery was requested but affinity was also disabled,
5113 // then tell user that Hwloc request is being ignored and use default
5114 // topology discovery method.
5115 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
5116 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
5117 KMP_WARNING(AffIgnoringHwloc, var);
5118 __kmp_affinity_top_method = affinity_top_method_all;
5119 }
5120#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005121 if (__kmp_affinity_type == affinity_disabled) {
5122 KMP_AFFINITY_DISABLE();
5123 } else if (!KMP_AFFINITY_CAPABLE()) {
5124 __kmp_affinity_dispatch->determine_capable(var);
5125 if (!KMP_AFFINITY_CAPABLE()) {
5126 if (__kmp_affinity_verbose ||
5127 (__kmp_affinity_warnings &&
5128 (__kmp_affinity_type != affinity_default) &&
5129 (__kmp_affinity_type != affinity_none) &&
5130 (__kmp_affinity_type != affinity_disabled))) {
5131 KMP_WARNING(AffNotSupported, var);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005132 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005133 __kmp_affinity_type = affinity_disabled;
5134 __kmp_affinity_respect_mask = 0;
5135 __kmp_affinity_gran = affinity_gran_fine;
5136 }
5137 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005138
Jonathan Peyton30419822017-05-12 18:01:32 +00005139#if OMP_40_ENABLED
5140 if (__kmp_affinity_type == affinity_disabled) {
5141 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5142 } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
5143 // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
5144 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
5145 }
5146#endif /* OMP_40_ENABLED */
5147
5148 if (KMP_AFFINITY_CAPABLE()) {
5149
5150#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005151 // This checks to see if the initial affinity mask is equal
5152 // to a single windows processor group. If it is, then we do
5153 // not respect the initial affinity mask and instead, use the
5154 // entire machine.
5155 bool exactly_one_group = false;
5156 if (__kmp_num_proc_groups > 1) {
5157 int group;
5158 bool within_one_group;
5159 // Get the initial affinity mask and determine if it is
5160 // contained within a single group.
5161 kmp_affin_mask_t *init_mask;
5162 KMP_CPU_ALLOC(init_mask);
5163 __kmp_get_system_affinity(init_mask, TRUE);
5164 group = __kmp_get_proc_group(init_mask);
5165 within_one_group = (group >= 0);
5166 // If the initial affinity is within a single group,
5167 // then determine if it is equal to that single group.
5168 if (within_one_group) {
5169 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
5170 int num_bits_in_mask = 0;
5171 for (int bit = init_mask->begin(); bit != init_mask->end();
5172 bit = init_mask->next(bit))
5173 num_bits_in_mask++;
5174 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
5175 }
5176 KMP_CPU_FREE(init_mask);
5177 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005178
5179 // Handle the Win 64 group affinity stuff if there are multiple
5180 // processor groups, or if the user requested it, and OMP 4.0
5181 // affinity is not in effect.
5182 if (((__kmp_num_proc_groups > 1) &&
5183 (__kmp_affinity_type == affinity_default)
5184#if OMP_40_ENABLED
5185 && (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default))
5186#endif
5187 || (__kmp_affinity_top_method == affinity_top_method_group)) {
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005188 if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
5189 exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005190 __kmp_affinity_respect_mask = FALSE;
5191 }
5192 if (__kmp_affinity_type == affinity_default) {
5193 __kmp_affinity_type = affinity_compact;
5194#if OMP_40_ENABLED
5195 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5196#endif
5197 }
5198 if (__kmp_affinity_top_method == affinity_top_method_default) {
5199 if (__kmp_affinity_gran == affinity_gran_default) {
5200 __kmp_affinity_top_method = affinity_top_method_group;
5201 __kmp_affinity_gran = affinity_gran_group;
5202 } else if (__kmp_affinity_gran == affinity_gran_group) {
5203 __kmp_affinity_top_method = affinity_top_method_group;
5204 } else {
5205 __kmp_affinity_top_method = affinity_top_method_all;
5206 }
5207 } else if (__kmp_affinity_top_method == affinity_top_method_group) {
5208 if (__kmp_affinity_gran == affinity_gran_default) {
5209 __kmp_affinity_gran = affinity_gran_group;
5210 } else if ((__kmp_affinity_gran != affinity_gran_group) &&
5211 (__kmp_affinity_gran != affinity_gran_fine) &&
5212 (__kmp_affinity_gran != affinity_gran_thread)) {
5213 const char *str = NULL;
5214 switch (__kmp_affinity_gran) {
5215 case affinity_gran_core:
5216 str = "core";
5217 break;
5218 case affinity_gran_package:
5219 str = "package";
5220 break;
5221 case affinity_gran_node:
5222 str = "node";
5223 break;
5224 default:
5225 KMP_DEBUG_ASSERT(0);
5226 }
5227 KMP_WARNING(AffGranTopGroup, var, str);
5228 __kmp_affinity_gran = affinity_gran_fine;
5229 }
5230 } else {
5231 if (__kmp_affinity_gran == affinity_gran_default) {
5232 __kmp_affinity_gran = affinity_gran_core;
5233 } else if (__kmp_affinity_gran == affinity_gran_group) {
5234 const char *str = NULL;
5235 switch (__kmp_affinity_type) {
5236 case affinity_physical:
5237 str = "physical";
5238 break;
5239 case affinity_logical:
5240 str = "logical";
5241 break;
5242 case affinity_compact:
5243 str = "compact";
5244 break;
5245 case affinity_scatter:
5246 str = "scatter";
5247 break;
5248 case affinity_explicit:
5249 str = "explicit";
5250 break;
5251 // No MIC on windows, so no affinity_balanced case
5252 default:
5253 KMP_DEBUG_ASSERT(0);
5254 }
5255 KMP_WARNING(AffGranGroupType, var, str);
5256 __kmp_affinity_gran = affinity_gran_core;
5257 }
5258 }
5259 } else
5260
5261#endif /* KMP_GROUP_AFFINITY */
5262
5263 {
5264 if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
5265#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005266 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005267 __kmp_affinity_respect_mask = FALSE;
5268 } else
5269#endif /* KMP_GROUP_AFFINITY */
5270 {
5271 __kmp_affinity_respect_mask = TRUE;
5272 }
5273 }
5274#if OMP_40_ENABLED
5275 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
5276 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
5277 if (__kmp_affinity_type == affinity_default) {
5278 __kmp_affinity_type = affinity_compact;
5279 __kmp_affinity_dups = FALSE;
5280 }
5281 } else
5282#endif /* OMP_40_ENABLED */
5283 if (__kmp_affinity_type == affinity_default) {
5284#if OMP_40_ENABLED
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005285#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005286 if (__kmp_mic_type != non_mic) {
5287 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5288 } else
5289#endif
5290 {
Andrey Churbanov94e569e2015-03-10 09:19:47 +00005291 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
Jonathan Peyton30419822017-05-12 18:01:32 +00005292 }
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005293#endif /* OMP_40_ENABLED */
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005294#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005295 if (__kmp_mic_type != non_mic) {
5296 __kmp_affinity_type = affinity_scatter;
5297 } else
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005298#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005299 {
5300 __kmp_affinity_type = affinity_none;
5301 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005302 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005303 if ((__kmp_affinity_gran == affinity_gran_default) &&
5304 (__kmp_affinity_gran_levels < 0)) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005305#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005306 if (__kmp_mic_type != non_mic) {
5307 __kmp_affinity_gran = affinity_gran_fine;
5308 } else
5309#endif
5310 {
5311 __kmp_affinity_gran = affinity_gran_core;
5312 }
5313 }
5314 if (__kmp_affinity_top_method == affinity_top_method_default) {
5315 __kmp_affinity_top_method = affinity_top_method_all;
5316 }
5317 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005318 }
5319
Jonathan Peyton30419822017-05-12 18:01:32 +00005320 K_DIAG(1, ("__kmp_affinity_type == %d\n", __kmp_affinity_type));
5321 K_DIAG(1, ("__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
5322 K_DIAG(1, ("__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
5323 K_DIAG(1, ("__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
5324 K_DIAG(1, ("__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
5325 K_DIAG(1, ("__kmp_affinity_respect_mask == %d\n",
5326 __kmp_affinity_respect_mask));
5327 K_DIAG(1, ("__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
5328
5329 KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
5330#if OMP_40_ENABLED
5331 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
5332#endif
5333 }
5334
Alp Toker763b9392014-02-28 09:42:41 +00005335#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005336
Jonathan Peyton30419822017-05-12 18:01:32 +00005337 if (__kmp_version) {
5338 __kmp_print_version_1();
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005339 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005340
Jonathan Peyton30419822017-05-12 18:01:32 +00005341 // Post-initialization step: some env. vars need their value's further
5342 // processing
5343 if (string != NULL) { // kmp_set_defaults() was called
5344 __kmp_aux_env_initialize(&block);
5345 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005346
Jonathan Peyton30419822017-05-12 18:01:32 +00005347 __kmp_env_blk_free(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005348
Jonathan Peyton30419822017-05-12 18:01:32 +00005349 KMP_MB();
Jim Cownie5e8470a2013-09-27 10:38:44 +00005350
5351} // __kmp_env_initialize
5352
Jonathan Peyton30419822017-05-12 18:01:32 +00005353void __kmp_env_print() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005354
Jonathan Peyton30419822017-05-12 18:01:32 +00005355 kmp_env_blk_t block;
5356 int i;
5357 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005358
Jonathan Peyton30419822017-05-12 18:01:32 +00005359 __kmp_stg_init();
5360 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005361
Jonathan Peyton30419822017-05-12 18:01:32 +00005362 __kmp_env_blk_init(&block, NULL);
5363 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005364
Jonathan Peyton30419822017-05-12 18:01:32 +00005365 // Print real environment values.
5366 __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
5367 for (i = 0; i < block.count; ++i) {
5368 char const *name = block.vars[i].name;
5369 char const *value = block.vars[i].value;
5370 if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
5371 strncmp(name, "OMP_", 4) == 0
5372#ifdef KMP_GOMP_COMPAT
5373 || strncmp(name, "GOMP_", 5) == 0
5374#endif // KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00005375 ) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005376 __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005377 }
5378 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005379 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005380
Jonathan Peyton30419822017-05-12 18:01:32 +00005381 // Print internal (effective) settings.
5382 __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
5383 for (int i = 0; i < __kmp_stg_count; ++i) {
5384 if (__kmp_stg_table[i].print != NULL) {
5385 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5386 __kmp_stg_table[i].data);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005387 }
5388 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005389
Jonathan Peyton30419822017-05-12 18:01:32 +00005390 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005391
Jonathan Peyton30419822017-05-12 18:01:32 +00005392 __kmp_env_blk_free(&block);
5393 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005394
Jonathan Peyton30419822017-05-12 18:01:32 +00005395 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005396
5397} // __kmp_env_print
5398
Jim Cownie5e8470a2013-09-27 10:38:44 +00005399#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005400void __kmp_env_print_2() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005401
Jonathan Peyton30419822017-05-12 18:01:32 +00005402 kmp_env_blk_t block;
5403 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005404
Jonathan Peyton30419822017-05-12 18:01:32 +00005405 __kmp_env_format = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005406
Jonathan Peyton30419822017-05-12 18:01:32 +00005407 __kmp_stg_init();
5408 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005409
Jonathan Peyton30419822017-05-12 18:01:32 +00005410 __kmp_env_blk_init(&block, NULL);
5411 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005412
Jonathan Peyton30419822017-05-12 18:01:32 +00005413 __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
5414 __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005415
Jonathan Peyton30419822017-05-12 18:01:32 +00005416 for (int i = 0; i < __kmp_stg_count; ++i) {
5417 if (__kmp_stg_table[i].print != NULL &&
5418 ((__kmp_display_env &&
5419 strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
5420 __kmp_display_env_verbose)) {
5421 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5422 __kmp_stg_table[i].data);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005423 }
5424 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005425
Jonathan Peyton30419822017-05-12 18:01:32 +00005426 __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
5427 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005428
Jonathan Peyton30419822017-05-12 18:01:32 +00005429 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005430
Jonathan Peyton30419822017-05-12 18:01:32 +00005431 __kmp_env_blk_free(&block);
5432 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005433
Jonathan Peyton30419822017-05-12 18:01:32 +00005434 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005435
5436} // __kmp_env_print_2
5437#endif // OMP_40_ENABLED
5438
Jim Cownie5e8470a2013-09-27 10:38:44 +00005439// end of file