blob: 0a05e7c6b75b858e1da21e7ac6b87e8c2a52715e [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,
Jonas Hahnfeldaeb40ad2017-11-09 15:52:25 +0000338 char **out) {
Jonathan Peyton30419822017-05-12 18:01:32 +0000339 __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 Churbanova5868212017-11-30 11:51:47 +00002087#if KMP_USE_HWLOC
2088 } else if (__kmp_match_str("tile", buf, CCAST(const char **, &next))) {
2089 set_gran(affinity_gran_tile, -1);
2090 buf = next;
2091#endif
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002092 } else if (__kmp_match_str("package", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002093 set_gran(affinity_gran_package, -1);
2094 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002095 } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002096 set_gran(affinity_gran_node, -1);
2097 buf = next;
2098#if KMP_GROUP_AFFINITY
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002099 } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002100 set_gran(affinity_gran_group, -1);
2101 buf = next;
2102#endif /* KMP_GROUP AFFINITY */
2103 } else if ((*buf >= '0') && (*buf <= '9')) {
2104 int n;
2105 next = buf;
2106 SKIP_DIGITS(next);
2107 n = __kmp_str_to_int(buf, *next);
2108 KMP_ASSERT(n >= 0);
2109 buf = next;
2110 set_gran(affinity_gran_default, n);
2111 } else {
2112 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2113 continue;
2114 }
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002115 } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002116 char *temp_proclist;
2117
2118 SKIP_WS(next);
2119 if (*next != '=') {
2120 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2121 continue;
2122 }
2123 next++; // skip '='
2124 SKIP_WS(next);
2125 if (*next != '[') {
2126 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2127 continue;
2128 }
2129 next++; // skip '['
2130 buf = next;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002131 if (!__kmp_parse_affinity_proc_id_list(
2132 name, buf, CCAST(const char **, &next), &temp_proclist)) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002133 // warning already emitted.
2134 SKIP_TO(next, ']');
2135 if (*next == ']')
2136 next++;
2137 SKIP_TO(next, ',');
2138 if (*next == ',')
2139 next++;
2140 buf = next;
2141 continue;
2142 }
2143 if (*next != ']') {
2144 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2145 continue;
2146 }
2147 next++; // skip ']'
2148 set_proclist(temp_proclist);
2149 } else if ((*buf >= '0') && (*buf <= '9')) {
2150 // Parse integer numbers -- permute and offset.
2151 int n;
2152 next = buf;
2153 SKIP_DIGITS(next);
2154 n = __kmp_str_to_int(buf, *next);
2155 KMP_ASSERT(n >= 0);
2156 buf = next;
2157 if (count < 2) {
2158 number[count] = n;
2159 } else {
2160 KMP_WARNING(AffManyParams, name, start);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002161 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002162 ++count;
2163 } else {
2164 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2165 continue;
2166 }
2167
2168 SKIP_WS(next);
2169 if (*next == ',') {
2170 next++;
2171 SKIP_WS(next);
2172 } else if (*next != '\0') {
2173 const char *temp = next;
2174 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2175 continue;
2176 }
2177 buf = next;
2178 } // while
2179
2180#undef EMIT_WARN
2181#undef _set_param
2182#undef set_type
2183#undef set_verbose
2184#undef set_warnings
2185#undef set_respect
2186#undef set_granularity
2187
Jonas Hahnfeldaeb40ad2017-11-09 15:52:25 +00002188 __kmp_str_free(&buffer);
Jonathan Peyton30419822017-05-12 18:01:32 +00002189
2190 if (proclist) {
2191 if (!type) {
2192 KMP_WARNING(AffProcListNoType, name);
2193 *out_type = affinity_explicit;
2194#if OMP_40_ENABLED
2195 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2196#endif
2197 } else if (*out_type != affinity_explicit) {
2198 KMP_WARNING(AffProcListNotExplicit, name);
2199 KMP_ASSERT(*out_proclist != NULL);
2200 KMP_INTERNAL_FREE(*out_proclist);
2201 *out_proclist = NULL;
2202 }
2203 }
2204 switch (*out_type) {
2205 case affinity_logical:
2206 case affinity_physical: {
2207 if (count > 0) {
2208 *out_offset = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002209 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002210 if (count > 1) {
2211 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002212 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002213 } break;
2214 case affinity_balanced: {
2215 if (count > 0) {
2216 *out_compact = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002217 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002218 if (count > 1) {
2219 *out_offset = number[1];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002220 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002221
2222 if (__kmp_affinity_gran == affinity_gran_default) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002223#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002224 if (__kmp_mic_type != non_mic) {
2225 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2226 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine");
2227 }
2228 __kmp_affinity_gran = affinity_gran_fine;
2229 } else
2230#endif
2231 {
2232 if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
2233 KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core");
2234 }
2235 __kmp_affinity_gran = affinity_gran_core;
2236 }
2237 }
2238 } break;
2239 case affinity_scatter:
2240 case affinity_compact: {
2241 if (count > 0) {
2242 *out_compact = number[0];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002243 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002244 if (count > 1) {
2245 *out_offset = number[1];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002246 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002247 } break;
2248 case affinity_explicit: {
2249 if (*out_proclist == NULL) {
2250 KMP_WARNING(AffNoProcList, name);
2251 __kmp_affinity_type = affinity_none;
2252 }
2253 if (count > 0) {
2254 KMP_WARNING(AffNoParam, name, "explicit");
2255 }
2256 } break;
2257 case affinity_none: {
2258 if (count > 0) {
2259 KMP_WARNING(AffNoParam, name, "none");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002260 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002261 } break;
2262 case affinity_disabled: {
2263 if (count > 0) {
2264 KMP_WARNING(AffNoParam, name, "disabled");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002265 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002266 } break;
2267 case affinity_default: {
2268 if (count > 0) {
2269 KMP_WARNING(AffNoParam, name, "default");
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002270 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002271 } break;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00002272 default: { KMP_ASSERT(0); }
2273 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002274} // __kmp_parse_affinity_env
2275
Jonathan Peyton30419822017-05-12 18:01:32 +00002276static void __kmp_stg_parse_affinity(char const *name, char const *value,
2277 void *data) {
2278 kmp_setting_t **rivals = (kmp_setting_t **)data;
2279 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002280
Jonathan Peyton30419822017-05-12 18:01:32 +00002281 rc = __kmp_stg_check_rivals(name, value, rivals);
2282 if (rc) {
2283 return;
2284 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002285
Jonathan Peyton30419822017-05-12 18:01:32 +00002286 __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
2287 &__kmp_affinity_proclist, &__kmp_affinity_verbose,
2288 &__kmp_affinity_warnings,
2289 &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
2290 &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
2291 &__kmp_affinity_compact, &__kmp_affinity_offset);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002292
2293} // __kmp_stg_parse_affinity
2294
Jonathan Peyton30419822017-05-12 18:01:32 +00002295static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
2296 void *data) {
2297 if (__kmp_env_format) {
2298 KMP_STR_BUF_PRINT_NAME_EX(name);
2299 } else {
2300 __kmp_str_buf_print(buffer, " %s='", name);
2301 }
2302 if (__kmp_affinity_verbose) {
2303 __kmp_str_buf_print(buffer, "%s,", "verbose");
2304 } else {
2305 __kmp_str_buf_print(buffer, "%s,", "noverbose");
2306 }
2307 if (__kmp_affinity_warnings) {
2308 __kmp_str_buf_print(buffer, "%s,", "warnings");
2309 } else {
2310 __kmp_str_buf_print(buffer, "%s,", "nowarnings");
2311 }
2312 if (KMP_AFFINITY_CAPABLE()) {
2313 if (__kmp_affinity_respect_mask) {
2314 __kmp_str_buf_print(buffer, "%s,", "respect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002315 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002316 __kmp_str_buf_print(buffer, "%s,", "norespect");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002317 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002318 switch (__kmp_affinity_gran) {
2319 case affinity_gran_default:
2320 __kmp_str_buf_print(buffer, "%s", "granularity=default,");
2321 break;
2322 case affinity_gran_fine:
2323 __kmp_str_buf_print(buffer, "%s", "granularity=fine,");
2324 break;
2325 case affinity_gran_thread:
2326 __kmp_str_buf_print(buffer, "%s", "granularity=thread,");
2327 break;
2328 case affinity_gran_core:
2329 __kmp_str_buf_print(buffer, "%s", "granularity=core,");
2330 break;
2331 case affinity_gran_package:
2332 __kmp_str_buf_print(buffer, "%s", "granularity=package,");
2333 break;
2334 case affinity_gran_node:
2335 __kmp_str_buf_print(buffer, "%s", "granularity=node,");
2336 break;
2337#if KMP_GROUP_AFFINITY
2338 case affinity_gran_group:
2339 __kmp_str_buf_print(buffer, "%s", "granularity=group,");
2340 break;
2341#endif /* KMP_GROUP_AFFINITY */
2342 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002343 }
2344 if (!KMP_AFFINITY_CAPABLE()) {
2345 __kmp_str_buf_print(buffer, "%s", "disabled");
2346 } else
2347 switch (__kmp_affinity_type) {
2348 case affinity_none:
2349 __kmp_str_buf_print(buffer, "%s", "none");
2350 break;
2351 case affinity_physical:
2352 __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset);
2353 break;
2354 case affinity_logical:
2355 __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset);
2356 break;
2357 case affinity_compact:
2358 __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact,
2359 __kmp_affinity_offset);
2360 break;
2361 case affinity_scatter:
2362 __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact,
2363 __kmp_affinity_offset);
2364 break;
2365 case affinity_explicit:
2366 __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist",
2367 __kmp_affinity_proclist, "explicit");
2368 break;
2369 case affinity_balanced:
2370 __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced",
2371 __kmp_affinity_compact, __kmp_affinity_offset);
2372 break;
2373 case affinity_disabled:
2374 __kmp_str_buf_print(buffer, "%s", "disabled");
2375 break;
2376 case affinity_default:
2377 __kmp_str_buf_print(buffer, "%s", "default");
2378 break;
2379 default:
2380 __kmp_str_buf_print(buffer, "%s", "<unknown>");
2381 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002382 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002383 __kmp_str_buf_print(buffer, "'\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00002384} //__kmp_stg_print_affinity
2385
Jonathan Peyton30419822017-05-12 18:01:32 +00002386#ifdef KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00002387
Jonathan Peyton30419822017-05-12 18:01:32 +00002388static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
2389 char const *value, void *data) {
2390 const char *next = NULL;
2391 char *temp_proclist;
2392 kmp_setting_t **rivals = (kmp_setting_t **)data;
2393 int rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002394
Jonathan Peyton30419822017-05-12 18:01:32 +00002395 rc = __kmp_stg_check_rivals(name, value, rivals);
2396 if (rc) {
2397 return;
2398 }
2399
2400 if (TCR_4(__kmp_init_middle)) {
2401 KMP_WARNING(EnvMiddleWarn, name);
2402 __kmp_env_toPrint(name, 0);
2403 return;
2404 }
2405
2406 __kmp_env_toPrint(name, 1);
2407
2408 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2409 SKIP_WS(next);
2410 if (*next == '\0') {
2411 // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2412 __kmp_affinity_proclist = temp_proclist;
2413 __kmp_affinity_type = affinity_explicit;
2414 __kmp_affinity_gran = affinity_gran_fine;
2415#if OMP_40_ENABLED
2416 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2417#endif
2418 } else {
2419 KMP_WARNING(AffSyntaxError, name);
2420 if (temp_proclist != NULL) {
2421 KMP_INTERNAL_FREE((void *)temp_proclist);
2422 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002423 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002424 } else {
2425 // Warning already emitted
2426 __kmp_affinity_type = affinity_none;
2427#if OMP_40_ENABLED
2428 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2429#endif
2430 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002431} // __kmp_stg_parse_gomp_cpu_affinity
2432
Jonathan Peyton30419822017-05-12 18:01:32 +00002433#endif /* KMP_GOMP_COMPAT */
Jim Cownie5e8470a2013-09-27 10:38:44 +00002434
Jonathan Peyton30419822017-05-12 18:01:32 +00002435#if OMP_40_ENABLED
Jim Cownie5e8470a2013-09-27 10:38:44 +00002436
2437/*-----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00002438The OMP_PLACES proc id list parser. Here is the grammar:
2439
2440place_list := place
2441place_list := place , place_list
2442place := num
2443place := place : num
2444place := place : num : signed
2445place := { subplacelist }
2446place := ! place // (lowest priority)
2447subplace_list := subplace
2448subplace_list := subplace , subplace_list
2449subplace := num
2450subplace := num : num
2451subplace := num : num : signed
2452signed := num
2453signed := + signed
2454signed := - signed
Jim Cownie5e8470a2013-09-27 10:38:44 +00002455-----------------------------------------------------------------------------*/
2456
Jonathan Peyton30419822017-05-12 18:01:32 +00002457static int __kmp_parse_subplace_list(const char *var, const char **scan) {
2458 const char *next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002459
Jonathan Peyton30419822017-05-12 18:01:32 +00002460 for (;;) {
2461 int start, count, stride;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002462
2463 //
Jonathan Peyton30419822017-05-12 18:01:32 +00002464 // Read in the starting proc id
Jim Cownie5e8470a2013-09-27 10:38:44 +00002465 //
2466 SKIP_WS(*scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002467 if ((**scan < '0') || (**scan > '9')) {
2468 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2469 return FALSE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002470 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002471 next = *scan;
2472 SKIP_DIGITS(next);
2473 start = __kmp_str_to_int(*scan, *next);
2474 KMP_ASSERT(start >= 0);
2475 *scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002476
Jonathan Peyton30419822017-05-12 18:01:32 +00002477 // valid follow sets are ',' ':' and '}'
2478 SKIP_WS(*scan);
2479 if (**scan == '}') {
2480 break;
2481 }
2482 if (**scan == ',') {
2483 (*scan)++; // skip ','
2484 continue;
2485 }
2486 if (**scan != ':') {
2487 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2488 return FALSE;
2489 }
2490 (*scan)++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002491
Jonathan Peyton30419822017-05-12 18:01:32 +00002492 // Read count parameter
2493 SKIP_WS(*scan);
2494 if ((**scan < '0') || (**scan > '9')) {
2495 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2496 return FALSE;
2497 }
2498 next = *scan;
2499 SKIP_DIGITS(next);
2500 count = __kmp_str_to_int(*scan, *next);
2501 KMP_ASSERT(count >= 0);
2502 *scan = next;
2503
2504 // valid follow sets are ',' ':' and '}'
2505 SKIP_WS(*scan);
2506 if (**scan == '}') {
2507 break;
2508 }
2509 if (**scan == ',') {
2510 (*scan)++; // skip ','
2511 continue;
2512 }
2513 if (**scan != ':') {
2514 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2515 return FALSE;
2516 }
2517 (*scan)++; // skip ':'
2518
2519 // Read stride parameter
2520 int sign = +1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002521 for (;;) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002522 SKIP_WS(*scan);
2523 if (**scan == '+') {
2524 (*scan)++; // skip '+'
2525 continue;
2526 }
2527 if (**scan == '-') {
2528 sign *= -1;
2529 (*scan)++; // skip '-'
2530 continue;
2531 }
2532 break;
2533 }
2534 SKIP_WS(*scan);
2535 if ((**scan < '0') || (**scan > '9')) {
2536 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2537 return FALSE;
2538 }
2539 next = *scan;
2540 SKIP_DIGITS(next);
2541 stride = __kmp_str_to_int(*scan, *next);
2542 KMP_ASSERT(stride >= 0);
2543 *scan = next;
2544 stride *= sign;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002545
Jonathan Peyton30419822017-05-12 18:01:32 +00002546 // valid follow sets are ',' and '}'
2547 SKIP_WS(*scan);
2548 if (**scan == '}') {
2549 break;
2550 }
2551 if (**scan == ',') {
2552 (*scan)++; // skip ','
2553 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002554 }
2555
Jonathan Peyton30419822017-05-12 18:01:32 +00002556 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2557 return FALSE;
2558 }
2559 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002560}
2561
Jonathan Peyton30419822017-05-12 18:01:32 +00002562static int __kmp_parse_place(const char *var, const char **scan) {
2563 const char *next;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002564
Jonathan Peyton30419822017-05-12 18:01:32 +00002565 // valid follow sets are '{' '!' and num
2566 SKIP_WS(*scan);
2567 if (**scan == '{') {
2568 (*scan)++; // skip '{'
2569 if (!__kmp_parse_subplace_list(var, scan)) {
2570 return FALSE;
2571 }
2572 if (**scan != '}') {
2573 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2574 return FALSE;
2575 }
2576 (*scan)++; // skip '}'
2577 } else if (**scan == '!') {
2578 (*scan)++; // skip '!'
2579 return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2580 } else if ((**scan >= '0') && (**scan <= '9')) {
2581 next = *scan;
2582 SKIP_DIGITS(next);
2583 int proc = __kmp_str_to_int(*scan, *next);
2584 KMP_ASSERT(proc >= 0);
2585 *scan = next;
2586 } else {
2587 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2588 return FALSE;
2589 }
2590 return TRUE;
2591}
2592
2593static int __kmp_parse_place_list(const char *var, const char *env,
2594 char **place_list) {
2595 const char *scan = env;
2596 const char *next = scan;
2597
2598 for (;;) {
2599 int start, count, stride;
2600
2601 if (!__kmp_parse_place(var, &scan)) {
2602 return FALSE;
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002603 }
2604
Jonathan Peyton30419822017-05-12 18:01:32 +00002605 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002606 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002607 if (*scan == '\0') {
2608 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002609 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002610 if (*scan == ',') {
2611 scan++; // skip ','
2612 continue;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002613 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002614 if (*scan != ':') {
2615 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2616 return FALSE;
2617 }
2618 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002619
Jonathan Peyton30419822017-05-12 18:01:32 +00002620 // Read count parameter
Jim Cownie5e8470a2013-09-27 10:38:44 +00002621 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002622 if ((*scan < '0') || (*scan > '9')) {
2623 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2624 return FALSE;
2625 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002626 next = scan;
2627 SKIP_DIGITS(next);
2628 count = __kmp_str_to_int(scan, *next);
2629 KMP_ASSERT(count >= 0);
2630 scan = next;
2631
Jonathan Peyton30419822017-05-12 18:01:32 +00002632 // valid follow sets are ',' ':' and EOL
Jim Cownie5e8470a2013-09-27 10:38:44 +00002633 SKIP_WS(scan);
Jonathan Peyton30419822017-05-12 18:01:32 +00002634 if (*scan == '\0') {
2635 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002636 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002637 if (*scan == ',') {
2638 scan++; // skip ','
2639 continue;
2640 }
2641 if (*scan != ':') {
2642 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2643 return FALSE;
2644 }
2645 scan++; // skip ':'
Jim Cownie5e8470a2013-09-27 10:38:44 +00002646
Jonathan Peyton30419822017-05-12 18:01:32 +00002647 // Read stride parameter
2648 int sign = +1;
2649 for (;;) {
2650 SKIP_WS(scan);
2651 if (*scan == '+') {
2652 scan++; // skip '+'
2653 continue;
2654 }
2655 if (*scan == '-') {
2656 sign *= -1;
2657 scan++; // skip '-'
2658 continue;
2659 }
2660 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002661 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002662 SKIP_WS(scan);
2663 if ((*scan < '0') || (*scan > '9')) {
2664 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2665 return FALSE;
2666 }
2667 next = scan;
2668 SKIP_DIGITS(next);
2669 stride = __kmp_str_to_int(scan, *next);
2670 KMP_ASSERT(stride >= 0);
2671 scan = next;
2672 stride *= sign;
2673
2674 // valid follow sets are ',' and EOL
2675 SKIP_WS(scan);
2676 if (*scan == '\0') {
2677 break;
2678 }
2679 if (*scan == ',') {
2680 scan++; // skip ','
2681 continue;
2682 }
2683
2684 KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
2685 return FALSE;
2686 }
2687
2688 {
2689 int len = scan - env;
2690 char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
2691 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
2692 retlist[len] = '\0';
2693 *place_list = retlist;
2694 }
2695 return TRUE;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002696}
2697
Jonathan Peyton30419822017-05-12 18:01:32 +00002698static void __kmp_stg_parse_places(char const *name, char const *value,
2699 void *data) {
2700 int count;
2701 const char *scan = value;
2702 const char *next = scan;
2703 const char *kind = "\"threads\"";
2704 kmp_setting_t **rivals = (kmp_setting_t **)data;
2705 int rc;
2706
2707 rc = __kmp_stg_check_rivals(name, value, rivals);
2708 if (rc) {
2709 return;
2710 }
2711
2712 // If OMP_PROC_BIND is not specified but OMP_PLACES is,
2713 // then let OMP_PROC_BIND default to true.
2714 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2715 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2716 }
2717
2718 //__kmp_affinity_num_places = 0;
2719
2720 if (__kmp_match_str("threads", scan, &next)) {
2721 scan = next;
2722 __kmp_affinity_type = affinity_compact;
2723 __kmp_affinity_gran = affinity_gran_thread;
2724 __kmp_affinity_dups = FALSE;
2725 kind = "\"threads\"";
2726 } else if (__kmp_match_str("cores", scan, &next)) {
2727 scan = next;
2728 __kmp_affinity_type = affinity_compact;
2729 __kmp_affinity_gran = affinity_gran_core;
2730 __kmp_affinity_dups = FALSE;
2731 kind = "\"cores\"";
Andrey Churbanova5868212017-11-30 11:51:47 +00002732#if KMP_USE_HWLOC
2733 } else if (__kmp_match_str("tiles", scan, &next)) {
2734 scan = next;
2735 __kmp_affinity_type = affinity_compact;
2736 __kmp_affinity_gran = affinity_gran_tile;
2737 __kmp_affinity_dups = FALSE;
2738 kind = "\"tiles\"";
2739#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00002740 } else if (__kmp_match_str("sockets", scan, &next)) {
2741 scan = next;
2742 __kmp_affinity_type = affinity_compact;
2743 __kmp_affinity_gran = affinity_gran_package;
2744 __kmp_affinity_dups = FALSE;
2745 kind = "\"sockets\"";
2746 } else {
2747 if (__kmp_affinity_proclist != NULL) {
2748 KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist);
2749 __kmp_affinity_proclist = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002750 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002751 if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
2752 __kmp_affinity_type = affinity_explicit;
2753 __kmp_affinity_gran = affinity_gran_fine;
2754 __kmp_affinity_dups = FALSE;
2755 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +00002756 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
Jonathan Peyton30419822017-05-12 18:01:32 +00002757 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002758 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002759 return;
2760 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002761
Jonathan Peyton30419822017-05-12 18:01:32 +00002762 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
2763 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
2764 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002765
Jonathan Peyton30419822017-05-12 18:01:32 +00002766 SKIP_WS(scan);
2767 if (*scan == '\0') {
2768 return;
2769 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002770
Jonathan Peyton30419822017-05-12 18:01:32 +00002771 // Parse option count parameter in parentheses
2772 if (*scan != '(') {
2773 KMP_WARNING(SyntaxErrorUsing, name, kind);
2774 return;
2775 }
2776 scan++; // skip '('
Jim Cownie5e8470a2013-09-27 10:38:44 +00002777
Jonathan Peyton30419822017-05-12 18:01:32 +00002778 SKIP_WS(scan);
2779 next = scan;
2780 SKIP_DIGITS(next);
2781 count = __kmp_str_to_int(scan, *next);
2782 KMP_ASSERT(count >= 0);
2783 scan = next;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002784
Jonathan Peyton30419822017-05-12 18:01:32 +00002785 SKIP_WS(scan);
2786 if (*scan != ')') {
2787 KMP_WARNING(SyntaxErrorUsing, name, kind);
2788 return;
2789 }
2790 scan++; // skip ')'
2791
2792 SKIP_WS(scan);
2793 if (*scan != '\0') {
2794 KMP_WARNING(ParseExtraCharsWarn, name, scan);
2795 }
2796 __kmp_affinity_num_places = count;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002797}
2798
Jonathan Peyton30419822017-05-12 18:01:32 +00002799static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
2800 void *data) {
2801 if (__kmp_env_format) {
2802 KMP_STR_BUF_PRINT_NAME;
2803 } else {
2804 __kmp_str_buf_print(buffer, " %s", name);
2805 }
2806 if ((__kmp_nested_proc_bind.used == 0) ||
2807 (__kmp_nested_proc_bind.bind_types == NULL) ||
2808 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
2809 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2810 } else if (__kmp_affinity_type == affinity_explicit) {
2811 if (__kmp_affinity_proclist != NULL) {
2812 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist);
Jim Cownie5e8470a2013-09-27 10:38:44 +00002813 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002814 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002815 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002816 } else if (__kmp_affinity_type == affinity_compact) {
2817 int num;
2818 if (__kmp_affinity_num_masks > 0) {
2819 num = __kmp_affinity_num_masks;
2820 } else if (__kmp_affinity_num_places > 0) {
2821 num = __kmp_affinity_num_places;
2822 } else {
2823 num = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00002824 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002825 if (__kmp_affinity_gran == affinity_gran_thread) {
2826 if (num > 0) {
2827 __kmp_str_buf_print(buffer, "='threads(%d)'\n", num);
2828 } else {
2829 __kmp_str_buf_print(buffer, "='threads'\n");
2830 }
2831 } else if (__kmp_affinity_gran == affinity_gran_core) {
2832 if (num > 0) {
2833 __kmp_str_buf_print(buffer, "='cores(%d)' \n", num);
2834 } else {
2835 __kmp_str_buf_print(buffer, "='cores'\n");
2836 }
Andrey Churbanova5868212017-11-30 11:51:47 +00002837#if KMP_USE_HWLOC
2838 } else if (__kmp_affinity_gran == affinity_gran_tile) {
2839 if (num > 0) {
2840 __kmp_str_buf_print(buffer, "='tiles(%d)' \n", num);
2841 } else {
2842 __kmp_str_buf_print(buffer, "='tiles'\n");
2843 }
2844#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00002845 } else if (__kmp_affinity_gran == affinity_gran_package) {
2846 if (num > 0) {
2847 __kmp_str_buf_print(buffer, "='sockets(%d)'\n", num);
2848 } else {
2849 __kmp_str_buf_print(buffer, "='sockets'\n");
2850 }
2851 } else {
2852 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
Jim Cownie5e8470a2013-09-27 10:38:44 +00002853 }
Jonathan Peyton30419822017-05-12 18:01:32 +00002854 } else {
2855 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
2856 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00002857}
2858
2859#endif /* OMP_40_ENABLED */
2860
Jonathan Peyton30419822017-05-12 18:01:32 +00002861#if (!OMP_40_ENABLED)
Jim Cownie5e8470a2013-09-27 10:38:44 +00002862
Jonathan Peyton30419822017-05-12 18:01:32 +00002863static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
2864 void *data) {
2865 int enabled;
2866 kmp_setting_t **rivals = (kmp_setting_t **)data;
2867 int rc;
2868
2869 rc = __kmp_stg_check_rivals(name, value, rivals);
2870 if (rc) {
2871 return;
2872 }
2873
2874 // In OMP 3.1, OMP_PROC_BIND is strictly a boolean
2875 __kmp_stg_parse_bool(name, value, &enabled);
2876 if (enabled) {
2877 // OMP_PROC_BIND => granularity=fine,scatter on MIC
2878 // OMP_PROC_BIND => granularity=core,scatter elsewhere
2879 __kmp_affinity_type = affinity_scatter;
Jonathan Peyton492e0a32017-06-13 17:17:26 +00002880#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00002881 if (__kmp_mic_type != non_mic)
2882 __kmp_affinity_gran = affinity_gran_fine;
2883 else
2884#endif
2885 __kmp_affinity_gran = affinity_gran_core;
2886 } else {
2887 __kmp_affinity_type = affinity_none;
2888 }
2889} // __kmp_parse_proc_bind
2890
2891#endif /* if (! OMP_40_ENABLED) */
2892
2893static void __kmp_stg_parse_topology_method(char const *name, char const *value,
2894 void *data) {
2895 if (__kmp_str_match("all", 1, value)) {
2896 __kmp_affinity_top_method = affinity_top_method_all;
2897 }
Andrey Churbanova5868212017-11-30 11:51:47 +00002898#if KMP_USE_HWLOC
2899 else if (__kmp_str_match("hwloc", 1, value)) {
2900 __kmp_affinity_top_method = affinity_top_method_hwloc;
2901 }
2902#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00002903#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2904 else if (__kmp_str_match("x2apic id", 9, value) ||
2905 __kmp_str_match("x2apic_id", 9, value) ||
2906 __kmp_str_match("x2apic-id", 9, value) ||
2907 __kmp_str_match("x2apicid", 8, value) ||
2908 __kmp_str_match("cpuid leaf 11", 13, value) ||
2909 __kmp_str_match("cpuid_leaf_11", 13, value) ||
2910 __kmp_str_match("cpuid-leaf-11", 13, value) ||
2911 __kmp_str_match("cpuid leaf11", 12, value) ||
2912 __kmp_str_match("cpuid_leaf11", 12, value) ||
2913 __kmp_str_match("cpuid-leaf11", 12, value) ||
2914 __kmp_str_match("cpuidleaf 11", 12, value) ||
2915 __kmp_str_match("cpuidleaf_11", 12, value) ||
2916 __kmp_str_match("cpuidleaf-11", 12, value) ||
2917 __kmp_str_match("cpuidleaf11", 11, value) ||
2918 __kmp_str_match("cpuid 11", 8, value) ||
2919 __kmp_str_match("cpuid_11", 8, value) ||
2920 __kmp_str_match("cpuid-11", 8, value) ||
2921 __kmp_str_match("cpuid11", 7, value) ||
2922 __kmp_str_match("leaf 11", 7, value) ||
2923 __kmp_str_match("leaf_11", 7, value) ||
2924 __kmp_str_match("leaf-11", 7, value) ||
2925 __kmp_str_match("leaf11", 6, value)) {
2926 __kmp_affinity_top_method = affinity_top_method_x2apicid;
2927 } else if (__kmp_str_match("apic id", 7, value) ||
2928 __kmp_str_match("apic_id", 7, value) ||
2929 __kmp_str_match("apic-id", 7, value) ||
2930 __kmp_str_match("apicid", 6, value) ||
2931 __kmp_str_match("cpuid leaf 4", 12, value) ||
2932 __kmp_str_match("cpuid_leaf_4", 12, value) ||
2933 __kmp_str_match("cpuid-leaf-4", 12, value) ||
2934 __kmp_str_match("cpuid leaf4", 11, value) ||
2935 __kmp_str_match("cpuid_leaf4", 11, value) ||
2936 __kmp_str_match("cpuid-leaf4", 11, value) ||
2937 __kmp_str_match("cpuidleaf 4", 11, value) ||
2938 __kmp_str_match("cpuidleaf_4", 11, value) ||
2939 __kmp_str_match("cpuidleaf-4", 11, value) ||
2940 __kmp_str_match("cpuidleaf4", 10, value) ||
2941 __kmp_str_match("cpuid 4", 7, value) ||
2942 __kmp_str_match("cpuid_4", 7, value) ||
2943 __kmp_str_match("cpuid-4", 7, value) ||
2944 __kmp_str_match("cpuid4", 6, value) ||
2945 __kmp_str_match("leaf 4", 6, value) ||
2946 __kmp_str_match("leaf_4", 6, value) ||
2947 __kmp_str_match("leaf-4", 6, value) ||
2948 __kmp_str_match("leaf4", 5, value)) {
2949 __kmp_affinity_top_method = affinity_top_method_apicid;
2950 }
2951#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2952 else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
2953 __kmp_str_match("cpuinfo", 5, value)) {
2954 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
2955 }
2956#if KMP_GROUP_AFFINITY
2957 else if (__kmp_str_match("group", 1, value)) {
2958 __kmp_affinity_top_method = affinity_top_method_group;
2959 }
2960#endif /* KMP_GROUP_AFFINITY */
2961 else if (__kmp_str_match("flat", 1, value)) {
2962 __kmp_affinity_top_method = affinity_top_method_flat;
Andrey Churbanova5868212017-11-30 11:51:47 +00002963 } else {
Jonathan Peyton30419822017-05-12 18:01:32 +00002964 KMP_WARNING(StgInvalidValue, name, value);
2965 }
2966} // __kmp_stg_parse_topology_method
2967
2968static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
2969 char const *name, void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +00002970 char const *value = NULL;
2971
2972 switch (__kmp_affinity_top_method) {
2973 case affinity_top_method_default:
2974 value = "default";
2975 break;
2976
2977 case affinity_top_method_all:
2978 value = "all";
2979 break;
2980
2981#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2982 case affinity_top_method_x2apicid:
2983 value = "x2APIC id";
2984 break;
2985
2986 case affinity_top_method_apicid:
2987 value = "APIC id";
2988 break;
2989#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2990
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002991#if KMP_USE_HWLOC
Jonathan Peyton30419822017-05-12 18:01:32 +00002992 case affinity_top_method_hwloc:
2993 value = "hwloc";
2994 break;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00002995#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00002996
2997 case affinity_top_method_cpuinfo:
2998 value = "cpuinfo";
2999 break;
3000
3001#if KMP_GROUP_AFFINITY
3002 case affinity_top_method_group:
3003 value = "group";
3004 break;
3005#endif /* KMP_GROUP_AFFINITY */
3006
3007 case affinity_top_method_flat:
3008 value = "flat";
3009 break;
3010 }
3011
3012 if (value != NULL) {
3013 __kmp_stg_print_str(buffer, name, value);
3014 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003015} // __kmp_stg_print_topology_method
3016
3017#endif /* KMP_AFFINITY_SUPPORTED */
3018
3019#if OMP_40_ENABLED
3020
3021// OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
3022// OMP_PLACES / place-partition-var is not.
3023static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
3024 void *data) {
3025 kmp_setting_t **rivals = (kmp_setting_t **)data;
3026 int rc;
3027
3028 rc = __kmp_stg_check_rivals(name, value, rivals);
3029 if (rc) {
3030 return;
3031 }
3032
3033 // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
3034 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
3035 (__kmp_nested_proc_bind.used > 0));
3036
3037 const char *buf = value;
3038 const char *next;
3039 int num;
3040 SKIP_WS(buf);
3041 if ((*buf >= '0') && (*buf <= '9')) {
3042 next = buf;
3043 SKIP_DIGITS(next);
3044 num = __kmp_str_to_int(buf, *next);
3045 KMP_ASSERT(num >= 0);
3046 buf = next;
3047 SKIP_WS(buf);
3048 } else {
3049 num = -1;
3050 }
3051
3052 next = buf;
3053 if (__kmp_match_str("disabled", buf, &next)) {
3054 buf = next;
3055 SKIP_WS(buf);
3056#if KMP_AFFINITY_SUPPORTED
3057 __kmp_affinity_type = affinity_disabled;
3058#endif /* KMP_AFFINITY_SUPPORTED */
3059 __kmp_nested_proc_bind.used = 1;
3060 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3061 } else if ((num == (int)proc_bind_false) ||
3062 __kmp_match_str("false", buf, &next)) {
3063 buf = next;
3064 SKIP_WS(buf);
3065#if KMP_AFFINITY_SUPPORTED
3066 __kmp_affinity_type = affinity_none;
3067#endif /* KMP_AFFINITY_SUPPORTED */
3068 __kmp_nested_proc_bind.used = 1;
3069 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3070 } else if ((num == (int)proc_bind_true) ||
3071 __kmp_match_str("true", buf, &next)) {
3072 buf = next;
3073 SKIP_WS(buf);
3074 __kmp_nested_proc_bind.used = 1;
3075 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3076 } else {
3077 // Count the number of values in the env var string
3078 const char *scan;
3079 int nelem = 1;
3080 for (scan = buf; *scan != '\0'; scan++) {
3081 if (*scan == ',') {
3082 nelem++;
3083 }
3084 }
3085
3086 // Create / expand the nested proc_bind array as needed
3087 if (__kmp_nested_proc_bind.size < nelem) {
3088 __kmp_nested_proc_bind.bind_types =
3089 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3090 __kmp_nested_proc_bind.bind_types,
3091 sizeof(kmp_proc_bind_t) * nelem);
3092 if (__kmp_nested_proc_bind.bind_types == NULL) {
3093 KMP_FATAL(MemoryAllocFailed);
3094 }
3095 __kmp_nested_proc_bind.size = nelem;
3096 }
3097 __kmp_nested_proc_bind.used = nelem;
3098
3099 // Save values in the nested proc_bind array
3100 int i = 0;
3101 for (;;) {
3102 enum kmp_proc_bind_t bind;
3103
3104 if ((num == (int)proc_bind_master) ||
3105 __kmp_match_str("master", buf, &next)) {
3106 buf = next;
3107 SKIP_WS(buf);
3108 bind = proc_bind_master;
3109 } else if ((num == (int)proc_bind_close) ||
3110 __kmp_match_str("close", buf, &next)) {
3111 buf = next;
3112 SKIP_WS(buf);
3113 bind = proc_bind_close;
3114 } else if ((num == (int)proc_bind_spread) ||
3115 __kmp_match_str("spread", buf, &next)) {
3116 buf = next;
3117 SKIP_WS(buf);
3118 bind = proc_bind_spread;
3119 } else {
3120 KMP_WARNING(StgInvalidValue, name, value);
3121 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3122 __kmp_nested_proc_bind.used = 1;
3123 return;
3124 }
3125
3126 __kmp_nested_proc_bind.bind_types[i++] = bind;
3127 if (i >= nelem) {
3128 break;
3129 }
3130 KMP_DEBUG_ASSERT(*buf == ',');
3131 buf++;
3132 SKIP_WS(buf);
3133
3134 // Read next value if it was specified as an integer
3135 if ((*buf >= '0') && (*buf <= '9')) {
3136 next = buf;
3137 SKIP_DIGITS(next);
3138 num = __kmp_str_to_int(buf, *next);
3139 KMP_ASSERT(num >= 0);
3140 buf = next;
3141 SKIP_WS(buf);
3142 } else {
3143 num = -1;
3144 }
3145 }
3146 SKIP_WS(buf);
3147 }
3148 if (*buf != '\0') {
3149 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3150 }
3151}
3152
3153static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
3154 void *data) {
3155 int nelem = __kmp_nested_proc_bind.used;
3156 if (__kmp_env_format) {
3157 KMP_STR_BUF_PRINT_NAME;
3158 } else {
3159 __kmp_str_buf_print(buffer, " %s", name);
3160 }
3161 if (nelem == 0) {
3162 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3163 } else {
3164 int i;
3165 __kmp_str_buf_print(buffer, "='", name);
3166 for (i = 0; i < nelem; i++) {
3167 switch (__kmp_nested_proc_bind.bind_types[i]) {
3168 case proc_bind_false:
3169 __kmp_str_buf_print(buffer, "false");
3170 break;
3171
3172 case proc_bind_true:
3173 __kmp_str_buf_print(buffer, "true");
3174 break;
3175
3176 case proc_bind_master:
3177 __kmp_str_buf_print(buffer, "master");
3178 break;
3179
3180 case proc_bind_close:
3181 __kmp_str_buf_print(buffer, "close");
3182 break;
3183
3184 case proc_bind_spread:
3185 __kmp_str_buf_print(buffer, "spread");
3186 break;
3187
3188 case proc_bind_intel:
3189 __kmp_str_buf_print(buffer, "intel");
3190 break;
3191
3192 case proc_bind_default:
3193 __kmp_str_buf_print(buffer, "default");
3194 break;
3195 }
3196 if (i < nelem - 1) {
3197 __kmp_str_buf_print(buffer, ",");
3198 }
3199 }
3200 __kmp_str_buf_print(buffer, "'\n");
3201 }
3202}
3203
3204#endif /* OMP_40_ENABLED */
3205
3206// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003207// OMP_DYNAMIC
Jim Cownie5e8470a2013-09-27 10:38:44 +00003208
Jonathan Peyton30419822017-05-12 18:01:32 +00003209static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
3210 void *data) {
3211 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
Jim Cownie5e8470a2013-09-27 10:38:44 +00003212} // __kmp_stg_parse_omp_dynamic
3213
Jonathan Peyton30419822017-05-12 18:01:32 +00003214static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
3215 void *data) {
3216 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003217} // __kmp_stg_print_omp_dynamic
3218
Jonathan Peyton30419822017-05-12 18:01:32 +00003219static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
3220 char const *value, void *data) {
3221 if (TCR_4(__kmp_init_parallel)) {
3222 KMP_WARNING(EnvParallelWarn, name);
3223 __kmp_env_toPrint(name, 0);
3224 return;
3225 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003226#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00003227 else if (__kmp_str_match("load balance", 2, value) ||
3228 __kmp_str_match("load_balance", 2, value) ||
3229 __kmp_str_match("load-balance", 2, value) ||
3230 __kmp_str_match("loadbalance", 2, value) ||
3231 __kmp_str_match("balance", 1, value)) {
3232 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
3233 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003234#endif /* USE_LOAD_BALANCE */
Jonathan Peyton30419822017-05-12 18:01:32 +00003235 else if (__kmp_str_match("thread limit", 1, value) ||
3236 __kmp_str_match("thread_limit", 1, value) ||
3237 __kmp_str_match("thread-limit", 1, value) ||
3238 __kmp_str_match("threadlimit", 1, value) ||
3239 __kmp_str_match("limit", 2, value)) {
3240 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
3241 } else if (__kmp_str_match("random", 1, value)) {
3242 __kmp_global.g.g_dynamic_mode = dynamic_random;
3243 } else {
3244 KMP_WARNING(StgInvalidValue, name, value);
3245 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003246} //__kmp_stg_parse_kmp_dynamic_mode
3247
Jonathan Peyton30419822017-05-12 18:01:32 +00003248static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
3249 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003250#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003251 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
3252 __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
3253 }
3254#ifdef USE_LOAD_BALANCE
3255 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
3256 __kmp_stg_print_str(buffer, name, "load balance");
3257 }
3258#endif /* USE_LOAD_BALANCE */
3259 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
3260 __kmp_stg_print_str(buffer, name, "thread limit");
3261 } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
3262 __kmp_stg_print_str(buffer, name, "random");
3263 } else {
3264 KMP_ASSERT(0);
3265 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003266#endif /* KMP_DEBUG */
3267} // __kmp_stg_print_kmp_dynamic_mode
3268
Jim Cownie5e8470a2013-09-27 10:38:44 +00003269#ifdef USE_LOAD_BALANCE
3270
Jonathan Peyton30419822017-05-12 18:01:32 +00003271// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003272// KMP_LOAD_BALANCE_INTERVAL
Jim Cownie5e8470a2013-09-27 10:38:44 +00003273
Jonathan Peyton30419822017-05-12 18:01:32 +00003274static void __kmp_stg_parse_ld_balance_interval(char const *name,
3275 char const *value, void *data) {
3276 double interval = __kmp_convert_to_double(value);
3277 if (interval >= 0) {
3278 __kmp_load_balance_interval = interval;
3279 } else {
3280 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003281 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003282} // __kmp_stg_parse_load_balance_interval
3283
Jonathan Peyton30419822017-05-12 18:01:32 +00003284static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
3285 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003286#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003287 __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
3288 __kmp_load_balance_interval);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003289#endif /* KMP_DEBUG */
3290} // __kmp_stg_print_load_balance_interval
3291
3292#endif /* USE_LOAD_BALANCE */
3293
Jonathan Peyton30419822017-05-12 18:01:32 +00003294// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003295// KMP_INIT_AT_FORK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003296
Jonathan Peyton30419822017-05-12 18:01:32 +00003297static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
3298 void *data) {
3299 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
3300 if (__kmp_need_register_atfork) {
3301 __kmp_need_register_atfork_specified = TRUE;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003302 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003303} // __kmp_stg_parse_init_at_fork
3304
Jonathan Peyton30419822017-05-12 18:01:32 +00003305static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
3306 char const *name, void *data) {
3307 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003308} // __kmp_stg_print_init_at_fork
3309
Jonathan Peyton30419822017-05-12 18:01:32 +00003310// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003311// KMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003312
Jonathan Peyton30419822017-05-12 18:01:32 +00003313static void __kmp_stg_parse_schedule(char const *name, char const *value,
3314 void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003315
Jonathan Peyton30419822017-05-12 18:01:32 +00003316 if (value != NULL) {
3317 size_t length = KMP_STRLEN(value);
3318 if (length > INT_MAX) {
3319 KMP_WARNING(LongValue, name);
3320 } else {
Jonas Hahnfelde9b7c0a2017-11-09 15:52:29 +00003321 const char *semicolon;
Jonathan Peyton30419822017-05-12 18:01:32 +00003322 if (value[length - 1] == '"' || value[length - 1] == '\'')
3323 KMP_WARNING(UnbalancedQuotes, name);
3324 do {
3325 char sentinel;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003326
Jonas Hahnfelde9b7c0a2017-11-09 15:52:29 +00003327 semicolon = strchr(value, ';');
Jonathan Peyton30419822017-05-12 18:01:32 +00003328 if (*value && semicolon != value) {
Jonas Hahnfelde9b7c0a2017-11-09 15:52:29 +00003329 const char *comma = strchr(value, ',');
Jim Cownie5e8470a2013-09-27 10:38:44 +00003330
Jonathan Peyton30419822017-05-12 18:01:32 +00003331 if (comma) {
3332 ++comma;
3333 sentinel = ',';
3334 } else
3335 sentinel = ';';
3336 if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
3337 if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
3338 __kmp_static = kmp_sch_static_greedy;
3339 continue;
3340 } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
3341 ';')) {
3342 __kmp_static = kmp_sch_static_balanced;
3343 continue;
3344 }
3345 } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3346 sentinel)) {
3347 if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
3348 __kmp_guided = kmp_sch_guided_iterative_chunked;
3349 continue;
3350 } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
3351 ';')) {
3352 /* analytical not allowed for too many threads */
3353 __kmp_guided = kmp_sch_guided_analytical_chunked;
3354 continue;
3355 }
3356 }
3357 KMP_WARNING(InvalidClause, name, value);
3358 } else
3359 KMP_WARNING(EmptyClause, name);
3360 } while ((value = semicolon ? semicolon + 1 : NULL));
3361 }
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003362 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003363
3364} // __kmp_stg_parse__schedule
3365
Jonathan Peyton30419822017-05-12 18:01:32 +00003366static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
3367 void *data) {
3368 if (__kmp_env_format) {
3369 KMP_STR_BUF_PRINT_NAME_EX(name);
3370 } else {
3371 __kmp_str_buf_print(buffer, " %s='", name);
3372 }
3373 if (__kmp_static == kmp_sch_static_greedy) {
3374 __kmp_str_buf_print(buffer, "%s", "static,greedy");
3375 } else if (__kmp_static == kmp_sch_static_balanced) {
3376 __kmp_str_buf_print(buffer, "%s", "static,balanced");
3377 }
3378 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
3379 __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
3380 } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
3381 __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
3382 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003383} // __kmp_stg_print_schedule
3384
Jonathan Peyton30419822017-05-12 18:01:32 +00003385// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003386// OMP_SCHEDULE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003387
Jonathan Peyton30419822017-05-12 18:01:32 +00003388static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
3389 void *data) {
3390 size_t length;
3391 if (value) {
3392 length = KMP_STRLEN(value);
3393 if (length) {
Jonas Hahnfelde9b7c0a2017-11-09 15:52:29 +00003394 const char *comma = strchr(value, ',');
Jonathan Peyton30419822017-05-12 18:01:32 +00003395 if (value[length - 1] == '"' || value[length - 1] == '\'')
3396 KMP_WARNING(UnbalancedQuotes, name);
3397 /* get the specified scheduling style */
3398 if (!__kmp_strcasecmp_with_sentinel("dynamic", value, ',')) /* DYNAMIC */
3399 __kmp_sched = kmp_sch_dynamic_chunked;
3400 else if (!__kmp_strcasecmp_with_sentinel("guided", value,
3401 ',')) /* GUIDED */
3402 __kmp_sched = kmp_sch_guided_chunked;
3403 // AC: TODO: add AUTO schedule, and pprobably remove TRAPEZOIDAL (OMP 3.0
3404 // does not allow it)
3405 else if (!__kmp_strcasecmp_with_sentinel("auto", value, ',')) { /* AUTO */
3406 __kmp_sched = kmp_sch_auto;
3407 if (comma) {
3408 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, comma),
3409 __kmp_msg_null);
3410 comma = NULL;
3411 }
3412 } else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", value,
3413 ',')) /* TRAPEZOIDAL */
3414 __kmp_sched = kmp_sch_trapezoidal;
3415 else if (!__kmp_strcasecmp_with_sentinel("static", value,
3416 ',')) /* STATIC */
3417 __kmp_sched = kmp_sch_static;
Andrey Churbanov429dbc22016-07-11 10:44:57 +00003418#if KMP_STATIC_STEAL_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00003419 else if (!__kmp_strcasecmp_with_sentinel("static_steal", value, ','))
3420 __kmp_sched = kmp_sch_static_steal;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003421#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003422 else {
3423 KMP_WARNING(StgInvalidValue, name, value);
3424 value = NULL; /* skip processing of comma */
3425 }
3426 if (value && comma) {
Jonathan Peyton30419822017-05-12 18:01:32 +00003427 if (__kmp_sched == kmp_sch_static)
3428 __kmp_sched = kmp_sch_static_chunked;
3429 ++comma;
3430 __kmp_chunk = __kmp_str_to_int(comma, 0);
3431 if (__kmp_chunk < 1) {
3432 __kmp_chunk = KMP_DEFAULT_CHUNK;
3433 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, comma),
3434 __kmp_msg_null);
3435 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3436 // AC: next block commented out until KMP_DEFAULT_CHUNK !=
3437 // KMP_MIN_CHUNK (to improve code coverage :)
3438 // The default chunk size is 1 according to standard, thus making
3439 // KMP_MIN_CHUNK not 1 we would introduce mess:
3440 // wrong chunk becomes 1, but it will be impossible to explicitely
3441 // set 1, because it becomes KMP_MIN_CHUNK...
3442 // } else if ( __kmp_chunk < KMP_MIN_CHUNK ) {
3443 // __kmp_chunk = KMP_MIN_CHUNK;
3444 } else if (__kmp_chunk > KMP_MAX_CHUNK) {
3445 __kmp_chunk = KMP_MAX_CHUNK;
3446 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, comma),
3447 __kmp_msg_null);
3448 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
3449 }
Jonathan Peytond74d8902017-07-25 18:20:16 +00003450 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003451 } else
3452 KMP_WARNING(EmptyString, name);
3453 }
3454 K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
3455 K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
3456 K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
3457 K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
Jim Cownie5e8470a2013-09-27 10:38:44 +00003458} // __kmp_stg_parse_omp_schedule
3459
Jonathan Peyton30419822017-05-12 18:01:32 +00003460static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
3461 char const *name, void *data) {
3462 if (__kmp_env_format) {
3463 KMP_STR_BUF_PRINT_NAME_EX(name);
3464 } else {
3465 __kmp_str_buf_print(buffer, " %s='", name);
3466 }
3467 if (__kmp_chunk) {
3468 switch (__kmp_sched) {
3469 case kmp_sch_dynamic_chunked:
3470 __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
3471 break;
3472 case kmp_sch_guided_iterative_chunked:
3473 case kmp_sch_guided_analytical_chunked:
3474 __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
3475 break;
3476 case kmp_sch_trapezoidal:
3477 __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
3478 break;
3479 case kmp_sch_static:
3480 case kmp_sch_static_chunked:
3481 case kmp_sch_static_balanced:
3482 case kmp_sch_static_greedy:
3483 __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
3484 break;
3485 case kmp_sch_static_steal:
3486 __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
3487 break;
3488 case kmp_sch_auto:
3489 __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
3490 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003491 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003492 } else {
3493 switch (__kmp_sched) {
3494 case kmp_sch_dynamic_chunked:
3495 __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
3496 break;
3497 case kmp_sch_guided_iterative_chunked:
3498 case kmp_sch_guided_analytical_chunked:
3499 __kmp_str_buf_print(buffer, "%s'\n", "guided");
3500 break;
3501 case kmp_sch_trapezoidal:
3502 __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
3503 break;
3504 case kmp_sch_static:
3505 case kmp_sch_static_chunked:
3506 case kmp_sch_static_balanced:
3507 case kmp_sch_static_greedy:
3508 __kmp_str_buf_print(buffer, "%s'\n", "static");
3509 break;
3510 case kmp_sch_static_steal:
3511 __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
3512 break;
3513 case kmp_sch_auto:
3514 __kmp_str_buf_print(buffer, "%s'\n", "auto");
3515 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003516 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003517 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003518} // __kmp_stg_print_omp_schedule
3519
Jonathan Peyton30419822017-05-12 18:01:32 +00003520// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003521// KMP_ATOMIC_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003522
Jonathan Peyton30419822017-05-12 18:01:32 +00003523static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
3524 void *data) {
3525 // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
3526 // compatibility mode.
3527 int mode = 0;
3528 int max = 1;
3529#ifdef KMP_GOMP_COMPAT
3530 max = 2;
3531#endif /* KMP_GOMP_COMPAT */
3532 __kmp_stg_parse_int(name, value, 0, max, &mode);
3533 // TODO; parse_int is not very suitable for this case. In case of overflow it
3534 // is better to use
3535 // 0 rather that max value.
3536 if (mode > 0) {
3537 __kmp_atomic_mode = mode;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003538 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003539} // __kmp_stg_parse_atomic_mode
3540
Jonathan Peyton30419822017-05-12 18:01:32 +00003541static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
3542 void *data) {
3543 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003544} // __kmp_stg_print_atomic_mode
3545
Jonathan Peyton30419822017-05-12 18:01:32 +00003546// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003547// KMP_CONSISTENCY_CHECK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003548
Jonathan Peyton30419822017-05-12 18:01:32 +00003549static void __kmp_stg_parse_consistency_check(char const *name,
3550 char const *value, void *data) {
3551 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
3552 // Note, this will not work from kmp_set_defaults because th_cons stack was
3553 // not allocated
3554 // for existed thread(s) thus the first __kmp_push_<construct> will break
3555 // with assertion.
3556 // TODO: allocate th_cons if called from kmp_set_defaults.
3557 __kmp_env_consistency_check = TRUE;
3558 } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
3559 __kmp_env_consistency_check = FALSE;
3560 } else {
3561 KMP_WARNING(StgInvalidValue, name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003562 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003563} // __kmp_stg_parse_consistency_check
3564
Jonathan Peyton30419822017-05-12 18:01:32 +00003565static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
3566 char const *name, void *data) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00003567#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00003568 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003569
Jonathan Peyton30419822017-05-12 18:01:32 +00003570 if (__kmp_env_consistency_check) {
3571 value = "all";
3572 } else {
3573 value = "none";
3574 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003575
Jonathan Peyton30419822017-05-12 18:01:32 +00003576 if (value != NULL) {
3577 __kmp_stg_print_str(buffer, name, value);
3578 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003579#endif /* KMP_DEBUG */
3580} // __kmp_stg_print_consistency_check
3581
Jim Cownie5e8470a2013-09-27 10:38:44 +00003582#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00003583// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003584// KMP_ITT_PREPARE_DELAY
Jim Cownie5e8470a2013-09-27 10:38:44 +00003585
3586#if USE_ITT_NOTIFY
3587
Jonathan Peyton30419822017-05-12 18:01:32 +00003588static void __kmp_stg_parse_itt_prepare_delay(char const *name,
3589 char const *value, void *data) {
3590 // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
3591 // iterations.
3592 int delay = 0;
3593 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
3594 __kmp_itt_prepare_delay = delay;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003595} // __kmp_str_parse_itt_prepare_delay
3596
Jonathan Peyton30419822017-05-12 18:01:32 +00003597static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
3598 char const *name, void *data) {
3599 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003600
3601} // __kmp_str_print_itt_prepare_delay
3602
3603#endif // USE_ITT_NOTIFY
3604#endif /* USE_ITT_BUILD */
3605
Jonathan Peyton30419822017-05-12 18:01:32 +00003606// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003607// KMP_MALLOC_POOL_INCR
Jim Cownie5e8470a2013-09-27 10:38:44 +00003608
Jonathan Peyton30419822017-05-12 18:01:32 +00003609static void __kmp_stg_parse_malloc_pool_incr(char const *name,
3610 char const *value, void *data) {
3611 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
3612 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
3613 1);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003614} // __kmp_stg_parse_malloc_pool_incr
3615
Jonathan Peyton30419822017-05-12 18:01:32 +00003616static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
3617 char const *name, void *data) {
3618 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003619
3620} // _kmp_stg_print_malloc_pool_incr
3621
Jim Cownie5e8470a2013-09-27 10:38:44 +00003622#ifdef KMP_DEBUG
3623
Jonathan Peyton30419822017-05-12 18:01:32 +00003624// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003625// KMP_PAR_RANGE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003626
Jonathan Peyton30419822017-05-12 18:01:32 +00003627static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
3628 void *data) {
3629 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
3630 __kmp_par_range_routine, __kmp_par_range_filename,
3631 &__kmp_par_range_lb, &__kmp_par_range_ub);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003632} // __kmp_stg_parse_par_range_env
3633
Jonathan Peyton30419822017-05-12 18:01:32 +00003634static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
3635 char const *name, void *data) {
3636 if (__kmp_par_range != 0) {
3637 __kmp_stg_print_str(buffer, name, par_range_to_print);
3638 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003639} // __kmp_stg_print_par_range_env
3640
Jonathan Peyton30419822017-05-12 18:01:32 +00003641// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003642// KMP_YIELD_CYCLE, KMP_YIELD_ON, KMP_YIELD_OFF
Jim Cownie5e8470a2013-09-27 10:38:44 +00003643
Jonathan Peyton30419822017-05-12 18:01:32 +00003644static void __kmp_stg_parse_yield_cycle(char const *name, char const *value,
3645 void *data) {
3646 int flag = __kmp_yield_cycle;
3647 __kmp_stg_parse_bool(name, value, &flag);
3648 __kmp_yield_cycle = flag;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003649} // __kmp_stg_parse_yield_cycle
3650
Jonathan Peyton30419822017-05-12 18:01:32 +00003651static void __kmp_stg_print_yield_cycle(kmp_str_buf_t *buffer, char const *name,
3652 void *data) {
3653 __kmp_stg_print_bool(buffer, name, __kmp_yield_cycle);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003654} // __kmp_stg_print_yield_cycle
3655
Jonathan Peyton30419822017-05-12 18:01:32 +00003656static void __kmp_stg_parse_yield_on(char const *name, char const *value,
3657 void *data) {
3658 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003659} // __kmp_stg_parse_yield_on
3660
Jonathan Peyton30419822017-05-12 18:01:32 +00003661static void __kmp_stg_print_yield_on(kmp_str_buf_t *buffer, char const *name,
3662 void *data) {
3663 __kmp_stg_print_int(buffer, name, __kmp_yield_on_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003664} // __kmp_stg_print_yield_on
3665
Jonathan Peyton30419822017-05-12 18:01:32 +00003666static void __kmp_stg_parse_yield_off(char const *name, char const *value,
3667 void *data) {
3668 __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003669} // __kmp_stg_parse_yield_off
3670
Jonathan Peyton30419822017-05-12 18:01:32 +00003671static void __kmp_stg_print_yield_off(kmp_str_buf_t *buffer, char const *name,
3672 void *data) {
3673 __kmp_stg_print_int(buffer, name, __kmp_yield_off_count);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003674} // __kmp_stg_print_yield_off
3675
3676#endif
3677
Jonathan Peyton30419822017-05-12 18:01:32 +00003678// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003679// KMP_INIT_WAIT, KMP_NEXT_WAIT
Jim Cownie5e8470a2013-09-27 10:38:44 +00003680
Jonathan Peyton30419822017-05-12 18:01:32 +00003681static void __kmp_stg_parse_init_wait(char const *name, char const *value,
3682 void *data) {
3683 int wait;
3684 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3685 wait = __kmp_init_wait / 2;
3686 __kmp_stg_parse_int(name, value, KMP_MIN_INIT_WAIT, KMP_MAX_INIT_WAIT, &wait);
3687 __kmp_init_wait = wait * 2;
3688 KMP_ASSERT((__kmp_init_wait & 1) == 0);
3689 __kmp_yield_init = __kmp_init_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003690} // __kmp_stg_parse_init_wait
3691
Jonathan Peyton30419822017-05-12 18:01:32 +00003692static void __kmp_stg_print_init_wait(kmp_str_buf_t *buffer, char const *name,
3693 void *data) {
3694 __kmp_stg_print_int(buffer, name, __kmp_init_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003695} // __kmp_stg_print_init_wait
3696
Jonathan Peyton30419822017-05-12 18:01:32 +00003697static void __kmp_stg_parse_next_wait(char const *name, char const *value,
3698 void *data) {
3699 int wait;
3700 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3701 wait = __kmp_next_wait / 2;
3702 __kmp_stg_parse_int(name, value, KMP_MIN_NEXT_WAIT, KMP_MAX_NEXT_WAIT, &wait);
3703 __kmp_next_wait = wait * 2;
3704 KMP_ASSERT((__kmp_next_wait & 1) == 0);
3705 __kmp_yield_next = __kmp_next_wait;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003706} // __kmp_stg_parse_next_wait
3707
Jonathan Peyton30419822017-05-12 18:01:32 +00003708static void __kmp_stg_print_next_wait(kmp_str_buf_t *buffer, char const *name,
3709 void *data) {
3710 __kmp_stg_print_int(buffer, name, __kmp_next_wait);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003711} //__kmp_stg_print_next_wait
3712
Jonathan Peyton30419822017-05-12 18:01:32 +00003713// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003714// KMP_GTID_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00003715
Jonathan Peyton30419822017-05-12 18:01:32 +00003716static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
3717 void *data) {
3718 // Modes:
3719 // 0 -- do not change default
3720 // 1 -- sp search
3721 // 2 -- use "keyed" TLS var, i.e.
3722 // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
3723 // 3 -- __declspec(thread) TLS var in tdata section
3724 int mode = 0;
3725 int max = 2;
3726#ifdef KMP_TDATA_GTID
3727 max = 3;
3728#endif /* KMP_TDATA_GTID */
3729 __kmp_stg_parse_int(name, value, 0, max, &mode);
3730 // TODO; parse_int is not very suitable for this case. In case of overflow it
3731 // is better to use 0 rather that max value.
3732 if (mode == 0) {
3733 __kmp_adjust_gtid_mode = TRUE;
3734 } else {
3735 __kmp_gtid_mode = mode;
3736 __kmp_adjust_gtid_mode = FALSE;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00003737 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003738} // __kmp_str_parse_gtid_mode
3739
Jonathan Peyton30419822017-05-12 18:01:32 +00003740static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
3741 void *data) {
3742 if (__kmp_adjust_gtid_mode) {
3743 __kmp_stg_print_int(buffer, name, 0);
3744 } else {
3745 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
3746 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003747} // __kmp_stg_print_gtid_mode
3748
Jonathan Peyton30419822017-05-12 18:01:32 +00003749// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003750// KMP_NUM_LOCKS_IN_BLOCK
Jim Cownie5e8470a2013-09-27 10:38:44 +00003751
Jonathan Peyton30419822017-05-12 18:01:32 +00003752static void __kmp_stg_parse_lock_block(char const *name, char const *value,
3753 void *data) {
3754 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003755} // __kmp_str_parse_lock_block
3756
Jonathan Peyton30419822017-05-12 18:01:32 +00003757static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
3758 void *data) {
3759 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003760} // __kmp_stg_print_lock_block
3761
Jonathan Peyton30419822017-05-12 18:01:32 +00003762// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00003763// KMP_LOCK_KIND
Jim Cownie5e8470a2013-09-27 10:38:44 +00003764
Jonathan Peytondae13d82015-12-11 21:57:06 +00003765#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00003766#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003767#else
Jonathan Peyton30419822017-05-12 18:01:32 +00003768#define KMP_STORE_LOCK_SEQ(a)
Jonathan Peytondae13d82015-12-11 21:57:06 +00003769#endif
3770
Jonathan Peyton30419822017-05-12 18:01:32 +00003771static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
3772 void *data) {
3773 if (__kmp_init_user_locks) {
3774 KMP_WARNING(EnvLockWarn, name);
3775 return;
3776 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003777
Jonathan Peyton30419822017-05-12 18:01:32 +00003778 if (__kmp_str_match("tas", 2, value) ||
3779 __kmp_str_match("test and set", 2, value) ||
3780 __kmp_str_match("test_and_set", 2, value) ||
3781 __kmp_str_match("test-and-set", 2, value) ||
3782 __kmp_str_match("test andset", 2, value) ||
3783 __kmp_str_match("test_andset", 2, value) ||
3784 __kmp_str_match("test-andset", 2, value) ||
3785 __kmp_str_match("testand set", 2, value) ||
3786 __kmp_str_match("testand_set", 2, value) ||
3787 __kmp_str_match("testand-set", 2, value) ||
3788 __kmp_str_match("testandset", 2, value)) {
3789 __kmp_user_lock_kind = lk_tas;
3790 KMP_STORE_LOCK_SEQ(tas);
3791 }
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003792#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003793 else if (__kmp_str_match("futex", 1, value)) {
3794 if (__kmp_futex_determine_capable()) {
3795 __kmp_user_lock_kind = lk_futex;
3796 KMP_STORE_LOCK_SEQ(futex);
3797 } else {
3798 KMP_WARNING(FutexNotSupported, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003799 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003800 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003801#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003802 else if (__kmp_str_match("ticket", 2, value)) {
3803 __kmp_user_lock_kind = lk_ticket;
3804 KMP_STORE_LOCK_SEQ(ticket);
3805 } else if (__kmp_str_match("queuing", 1, value) ||
3806 __kmp_str_match("queue", 1, value)) {
3807 __kmp_user_lock_kind = lk_queuing;
3808 KMP_STORE_LOCK_SEQ(queuing);
3809 } else if (__kmp_str_match("drdpa ticket", 1, value) ||
3810 __kmp_str_match("drdpa_ticket", 1, value) ||
3811 __kmp_str_match("drdpa-ticket", 1, value) ||
3812 __kmp_str_match("drdpaticket", 1, value) ||
3813 __kmp_str_match("drdpa", 1, value)) {
3814 __kmp_user_lock_kind = lk_drdpa;
3815 KMP_STORE_LOCK_SEQ(drdpa);
3816 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003817#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003818 else if (__kmp_str_match("adaptive", 1, value)) {
3819 if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
3820 __kmp_user_lock_kind = lk_adaptive;
3821 KMP_STORE_LOCK_SEQ(adaptive);
3822 } else {
3823 KMP_WARNING(AdaptiveNotSupported, name, value);
3824 __kmp_user_lock_kind = lk_queuing;
3825 KMP_STORE_LOCK_SEQ(queuing);
Jim Cownie5e8470a2013-09-27 10:38:44 +00003826 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003827 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003828#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peytondae13d82015-12-11 21:57:06 +00003829#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003830 else if (__kmp_str_match("rtm", 1, value)) {
3831 if (__kmp_cpuinfo.rtm) {
3832 __kmp_user_lock_kind = lk_rtm;
3833 KMP_STORE_LOCK_SEQ(rtm);
3834 } else {
3835 KMP_WARNING(AdaptiveNotSupported, name, value);
3836 __kmp_user_lock_kind = lk_queuing;
3837 KMP_STORE_LOCK_SEQ(queuing);
Jonathan Peytondae13d82015-12-11 21:57:06 +00003838 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003839 } else if (__kmp_str_match("hle", 1, value)) {
3840 __kmp_user_lock_kind = lk_hle;
3841 KMP_STORE_LOCK_SEQ(hle);
3842 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00003843#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003844 else {
3845 KMP_WARNING(StgInvalidValue, name, value);
3846 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003847}
3848
Jonathan Peyton30419822017-05-12 18:01:32 +00003849static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
3850 void *data) {
3851 const char *value = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003852
Jonathan Peyton30419822017-05-12 18:01:32 +00003853 switch (__kmp_user_lock_kind) {
3854 case lk_default:
3855 value = "default";
3856 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003857
Jonathan Peyton30419822017-05-12 18:01:32 +00003858 case lk_tas:
3859 value = "tas";
3860 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003861
Paul Osmialowskifb043fd2016-05-16 09:44:11 +00003862#if KMP_USE_FUTEX
Jonathan Peyton30419822017-05-12 18:01:32 +00003863 case lk_futex:
3864 value = "futex";
3865 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003866#endif
3867
Jonathan Peytondae13d82015-12-11 21:57:06 +00003868#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
Jonathan Peyton30419822017-05-12 18:01:32 +00003869 case lk_rtm:
3870 value = "rtm";
3871 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003872
Jonathan Peyton30419822017-05-12 18:01:32 +00003873 case lk_hle:
3874 value = "hle";
3875 break;
Jonathan Peytondae13d82015-12-11 21:57:06 +00003876#endif
3877
Jonathan Peyton30419822017-05-12 18:01:32 +00003878 case lk_ticket:
3879 value = "ticket";
3880 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003881
Jonathan Peyton30419822017-05-12 18:01:32 +00003882 case lk_queuing:
3883 value = "queuing";
3884 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003885
Jonathan Peyton30419822017-05-12 18:01:32 +00003886 case lk_drdpa:
3887 value = "drdpa";
3888 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003889#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00003890 case lk_adaptive:
3891 value = "adaptive";
3892 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00003893#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00003894 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003895
Jonathan Peyton30419822017-05-12 18:01:32 +00003896 if (value != NULL) {
3897 __kmp_stg_print_str(buffer, name, value);
3898 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00003899}
3900
Jonathan Peyton30419822017-05-12 18:01:32 +00003901// -----------------------------------------------------------------------------
Jonathan Peyton377aa402016-04-14 16:00:37 +00003902// KMP_SPIN_BACKOFF_PARAMS
Jonathan Peyton377aa402016-04-14 16:00:37 +00003903
Jonathan Peyton30419822017-05-12 18:01:32 +00003904// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
3905// for machine pause)
3906static void __kmp_stg_parse_spin_backoff_params(const char *name,
3907 const char *value, void *data) {
3908 const char *next = value;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003909
Jonathan Peyton30419822017-05-12 18:01:32 +00003910 int total = 0; // Count elements that were set. It'll be used as an array size
3911 int prev_comma = FALSE; // For correct processing sequential commas
3912 int i;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003913
Jonathan Peyton30419822017-05-12 18:01:32 +00003914 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
3915 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003916
Jonathan Peyton30419822017-05-12 18:01:32 +00003917 // Run only 3 iterations because it is enough to read two values or find a
3918 // syntax error
3919 for (i = 0; i < 3; i++) {
3920 SKIP_WS(next);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003921
Jonathan Peyton30419822017-05-12 18:01:32 +00003922 if (*next == '\0') {
3923 break;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003924 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003925 // Next character is not an integer or not a comma OR number of values > 2
3926 // => end of list
3927 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
3928 KMP_WARNING(EnvSyntaxError, name, value);
3929 return;
3930 }
3931 // The next character is ','
3932 if (*next == ',') {
3933 // ',' is the fisrt character
3934 if (total == 0 || prev_comma) {
3935 total++;
3936 }
3937 prev_comma = TRUE;
3938 next++; // skip ','
3939 SKIP_WS(next);
3940 }
3941 // Next character is a digit
3942 if (*next >= '0' && *next <= '9') {
3943 int num;
3944 const char *buf = next;
3945 char const *msg = NULL;
3946 prev_comma = FALSE;
3947 SKIP_DIGITS(next);
3948 total++;
3949
3950 const char *tmp = next;
3951 SKIP_WS(tmp);
3952 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
3953 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003954 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00003955 }
3956
3957 num = __kmp_str_to_int(buf, *next);
3958 if (num <= 0) { // The number of retries should be > 0
3959 msg = KMP_I18N_STR(ValueTooSmall);
3960 num = 1;
3961 } else if (num > KMP_INT_MAX) {
3962 msg = KMP_I18N_STR(ValueTooLarge);
3963 num = KMP_INT_MAX;
3964 }
3965 if (msg != NULL) {
3966 // Message is not empty. Print warning.
3967 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
3968 KMP_INFORM(Using_int_Value, name, num);
3969 }
3970 if (total == 1) {
3971 max_backoff = num;
3972 } else if (total == 2) {
3973 min_tick = num;
3974 }
Jonathan Peyton377aa402016-04-14 16:00:37 +00003975 }
Jonathan Peyton30419822017-05-12 18:01:32 +00003976 }
3977 KMP_DEBUG_ASSERT(total > 0);
3978 if (total <= 0) {
3979 KMP_WARNING(EnvSyntaxError, name, value);
3980 return;
3981 }
3982 __kmp_spin_backoff_params.max_backoff = max_backoff;
3983 __kmp_spin_backoff_params.min_tick = min_tick;
Jonathan Peyton377aa402016-04-14 16:00:37 +00003984}
3985
Jonathan Peyton30419822017-05-12 18:01:32 +00003986static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
3987 char const *name, void *data) {
3988 if (__kmp_env_format) {
3989 KMP_STR_BUF_PRINT_NAME_EX(name);
3990 } else {
3991 __kmp_str_buf_print(buffer, " %s='", name);
3992 }
3993 __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
3994 __kmp_spin_backoff_params.min_tick);
Jonathan Peyton377aa402016-04-14 16:00:37 +00003995}
3996
Jim Cownie5e8470a2013-09-27 10:38:44 +00003997#if KMP_USE_ADAPTIVE_LOCKS
3998
Jonathan Peyton30419822017-05-12 18:01:32 +00003999// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004000// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
Jim Cownie5e8470a2013-09-27 10:38:44 +00004001
4002// Parse out values for the tunable parameters from a string of the form
4003// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
Jonathan Peyton30419822017-05-12 18:01:32 +00004004static void __kmp_stg_parse_adaptive_lock_props(const char *name,
4005 const char *value, void *data) {
4006 int max_retries = 0;
4007 int max_badness = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004008
Jonathan Peyton30419822017-05-12 18:01:32 +00004009 const char *next = value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004010
Jonathan Peyton30419822017-05-12 18:01:32 +00004011 int total = 0; // Count elements that were set. It'll be used as an array size
4012 int prev_comma = FALSE; // For correct processing sequential commas
4013 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004014
Jonathan Peyton30419822017-05-12 18:01:32 +00004015 // Save values in the structure __kmp_speculative_backoff_params
4016 // Run only 3 iterations because it is enough to read two values or find a
4017 // syntax error
4018 for (i = 0; i < 3; i++) {
4019 SKIP_WS(next);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004020
Jonathan Peyton30419822017-05-12 18:01:32 +00004021 if (*next == '\0') {
4022 break;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004023 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004024 // Next character is not an integer or not a comma OR number of values > 2
4025 // => end of list
4026 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
4027 KMP_WARNING(EnvSyntaxError, name, value);
4028 return;
4029 }
4030 // The next character is ','
4031 if (*next == ',') {
4032 // ',' is the fisrt character
4033 if (total == 0 || prev_comma) {
4034 total++;
4035 }
4036 prev_comma = TRUE;
4037 next++; // skip ','
4038 SKIP_WS(next);
4039 }
4040 // Next character is a digit
4041 if (*next >= '0' && *next <= '9') {
4042 int num;
4043 const char *buf = next;
4044 char const *msg = NULL;
4045 prev_comma = FALSE;
4046 SKIP_DIGITS(next);
4047 total++;
4048
4049 const char *tmp = next;
4050 SKIP_WS(tmp);
4051 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4052 KMP_WARNING(EnvSpacesNotAllowed, name, value);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004053 return;
Jonathan Peyton30419822017-05-12 18:01:32 +00004054 }
4055
4056 num = __kmp_str_to_int(buf, *next);
4057 if (num < 0) { // The number of retries should be >= 0
4058 msg = KMP_I18N_STR(ValueTooSmall);
4059 num = 1;
4060 } else if (num > KMP_INT_MAX) {
4061 msg = KMP_I18N_STR(ValueTooLarge);
4062 num = KMP_INT_MAX;
4063 }
4064 if (msg != NULL) {
4065 // Message is not empty. Print warning.
4066 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4067 KMP_INFORM(Using_int_Value, name, num);
4068 }
4069 if (total == 1) {
4070 max_retries = num;
4071 } else if (total == 2) {
4072 max_badness = num;
4073 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004074 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004075 }
4076 KMP_DEBUG_ASSERT(total > 0);
4077 if (total <= 0) {
4078 KMP_WARNING(EnvSyntaxError, name, value);
4079 return;
4080 }
4081 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4082 __kmp_adaptive_backoff_params.max_badness = max_badness;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004083}
4084
Jonathan Peyton30419822017-05-12 18:01:32 +00004085static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4086 char const *name, void *data) {
4087 if (__kmp_env_format) {
4088 KMP_STR_BUF_PRINT_NAME_EX(name);
4089 } else {
4090 __kmp_str_buf_print(buffer, " %s='", name);
4091 }
4092 __kmp_str_buf_print(buffer, "%d,%d'\n",
4093 __kmp_adaptive_backoff_params.max_soft_retries,
4094 __kmp_adaptive_backoff_params.max_badness);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004095} // __kmp_stg_print_adaptive_lock_props
4096
4097#if KMP_DEBUG_ADAPTIVE_LOCKS
4098
Jonathan Peyton30419822017-05-12 18:01:32 +00004099static void __kmp_stg_parse_speculative_statsfile(char const *name,
4100 char const *value,
4101 void *data) {
4102 __kmp_stg_parse_file(name, value, "", &__kmp_speculative_statsfile);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004103} // __kmp_stg_parse_speculative_statsfile
4104
Jonathan Peyton30419822017-05-12 18:01:32 +00004105static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
4106 char const *name,
4107 void *data) {
4108 if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
4109 __kmp_stg_print_str(buffer, name, "stdout");
4110 } else {
4111 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
4112 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004113
4114} // __kmp_stg_print_speculative_statsfile
4115
4116#endif // KMP_DEBUG_ADAPTIVE_LOCKS
4117
4118#endif // KMP_USE_ADAPTIVE_LOCKS
4119
Jonathan Peyton30419822017-05-12 18:01:32 +00004120// -----------------------------------------------------------------------------
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004121// KMP_HW_SUBSET (was KMP_PLACE_THREADS)
Jim Cownie5e8470a2013-09-27 10:38:44 +00004122
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004123// The longest observable sequense of items is
4124// Socket-Node-Tile-Core-Thread
4125// So, let's limit to 5 levels for now
4126// The input string is usually short enough, let's use 512 limit for now
4127#define MAX_T_LEVEL 5
4128#define MAX_STR_LEN 512
Jonathan Peyton30419822017-05-12 18:01:32 +00004129static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
4130 void *data) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004131 // Value example: 1s,5c@3,2T
4132 // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
Jonathan Peyton3f850bf2017-10-06 19:23:19 +00004133 kmp_setting_t **rivals = (kmp_setting_t **)data;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004134 if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
4135 KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004136 }
Jonathan Peyton3f850bf2017-10-06 19:23:19 +00004137 if (__kmp_stg_check_rivals(name, value, rivals)) {
4138 return;
4139 }
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004140
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004141 char *components[MAX_T_LEVEL];
4142 char const *digits = "0123456789";
4143 char input[MAX_STR_LEN];
4144 size_t len = 0, mlen = MAX_STR_LEN;
4145 int level = 0;
4146 // Canonize the string (remove spaces, unify delimiters, etc.)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004147 char *pos = CCAST(char *, value);
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004148 while (*pos && mlen) {
4149 if (*pos != ' ') { // skip spaces
4150 if (len == 0 && *pos == ':') {
4151 __kmp_hws_abs_flag = 1; // if the first symbol is ":", skip it
4152 } else {
4153 input[len] = toupper(*pos);
4154 if (input[len] == 'X')
4155 input[len] = ','; // unify delimiters of levels
4156 if (input[len] == 'O' && strchr(digits, *(pos + 1)))
4157 input[len] = '@'; // unify delimiters of offset
4158 len++;
4159 }
Jonathan Peytonb9d28fb2016-06-16 18:53:48 +00004160 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004161 mlen--;
4162 pos++;
4163 }
4164 if (len == 0 || mlen == 0)
4165 goto err; // contents is either empty or too long
4166 input[len] = '\0';
4167 __kmp_hws_requested = 1; // mark that subset requested
4168 // Split by delimiter
4169 pos = input;
4170 components[level++] = pos;
George Rokos4800fc42017-04-25 15:55:39 +00004171 while ((pos = strchr(pos, ','))) {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004172 *pos = '\0'; // modify input and avoid more copying
4173 components[level++] = ++pos; // expect something after ","
4174 if (level > MAX_T_LEVEL)
4175 goto err; // too many components provided
4176 }
4177 // Check each component
4178 for (int i = 0; i < level; ++i) {
4179 int offset = 0;
4180 int num = atoi(components[i]); // each component should start with a number
4181 if ((pos = strchr(components[i], '@'))) {
4182 offset = atoi(pos + 1); // save offset
4183 *pos = '\0'; // cut the offset from the component
4184 }
4185 pos = components[i] + strspn(components[i], digits);
4186 if (pos == components[i])
4187 goto err;
4188 // detect the component type
4189 switch (*pos) {
4190 case 'S': // Socket
4191 if (__kmp_hws_socket.num > 0)
4192 goto err; // duplicate is not allowed
4193 __kmp_hws_socket.num = num;
4194 __kmp_hws_socket.offset = offset;
4195 break;
4196 case 'N': // NUMA Node
4197 if (__kmp_hws_node.num > 0)
4198 goto err; // duplicate is not allowed
4199 __kmp_hws_node.num = num;
4200 __kmp_hws_node.offset = offset;
4201 break;
4202 case 'L': // Cache
4203 if (*(pos + 1) == '2') { // L2 - Tile
4204 if (__kmp_hws_tile.num > 0)
4205 goto err; // duplicate is not allowed
4206 __kmp_hws_tile.num = num;
4207 __kmp_hws_tile.offset = offset;
4208 } else if (*(pos + 1) == '3') { // L3 - Socket
4209 if (__kmp_hws_socket.num > 0)
4210 goto err; // duplicate is not allowed
4211 __kmp_hws_socket.num = num;
4212 __kmp_hws_socket.offset = offset;
4213 } else if (*(pos + 1) == '1') { // L1 - Core
4214 if (__kmp_hws_core.num > 0)
4215 goto err; // duplicate is not allowed
4216 __kmp_hws_core.num = num;
4217 __kmp_hws_core.offset = offset;
4218 }
4219 break;
4220 case 'C': // Core (or Cache?)
4221 if (*(pos + 1) != 'A') {
4222 if (__kmp_hws_core.num > 0)
4223 goto err; // duplicate is not allowed
4224 __kmp_hws_core.num = num;
4225 __kmp_hws_core.offset = offset;
4226 } else { // Cache
4227 char *d = pos + strcspn(pos, digits); // find digit
4228 if (*d == '2') { // L2 - Tile
4229 if (__kmp_hws_tile.num > 0)
4230 goto err; // duplicate is not allowed
4231 __kmp_hws_tile.num = num;
4232 __kmp_hws_tile.offset = offset;
4233 } else if (*d == '3') { // L3 - Socket
4234 if (__kmp_hws_socket.num > 0)
4235 goto err; // duplicate is not allowed
4236 __kmp_hws_socket.num = num;
4237 __kmp_hws_socket.offset = offset;
4238 } else if (*d == '1') { // L1 - Core
4239 if (__kmp_hws_core.num > 0)
4240 goto err; // duplicate is not allowed
4241 __kmp_hws_core.num = num;
4242 __kmp_hws_core.offset = offset;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004243 } else {
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004244 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004245 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004246 }
4247 break;
4248 case 'T': // Thread
4249 if (__kmp_hws_proc.num > 0)
4250 goto err; // duplicate is not allowed
4251 __kmp_hws_proc.num = num;
4252 __kmp_hws_proc.offset = offset;
4253 break;
4254 default:
4255 goto err;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004256 }
Andrey Churbanov4a9a8922017-04-13 17:15:07 +00004257 }
4258 return;
4259err:
4260 KMP_WARNING(AffHWSubsetInvalid, name, value);
4261 __kmp_hws_requested = 0; // mark that subset not requested
4262 return;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004263}
4264
Jonathan Peyton30419822017-05-12 18:01:32 +00004265static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004266 void *data) {
Jonathan Peyton30419822017-05-12 18:01:32 +00004267 if (__kmp_hws_requested) {
4268 int comma = 0;
4269 kmp_str_buf_t buf;
4270 __kmp_str_buf_init(&buf);
4271 if (__kmp_env_format)
4272 KMP_STR_BUF_PRINT_NAME_EX(name);
4273 else
4274 __kmp_str_buf_print(buffer, " %s='", name);
4275 if (__kmp_hws_socket.num) {
4276 __kmp_str_buf_print(&buf, "%ds", __kmp_hws_socket.num);
4277 if (__kmp_hws_socket.offset)
4278 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_socket.offset);
4279 comma = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004280 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004281 if (__kmp_hws_node.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004282 __kmp_str_buf_print(&buf, "%s%dn", comma ? "," : "", __kmp_hws_node.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004283 if (__kmp_hws_node.offset)
4284 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_node.offset);
4285 comma = 1;
4286 }
4287 if (__kmp_hws_tile.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004288 __kmp_str_buf_print(&buf, "%s%dL2", comma ? "," : "", __kmp_hws_tile.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004289 if (__kmp_hws_tile.offset)
4290 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_tile.offset);
4291 comma = 1;
4292 }
4293 if (__kmp_hws_core.num) {
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004294 __kmp_str_buf_print(&buf, "%s%dc", comma ? "," : "", __kmp_hws_core.num);
Jonathan Peyton30419822017-05-12 18:01:32 +00004295 if (__kmp_hws_core.offset)
4296 __kmp_str_buf_print(&buf, "@%d", __kmp_hws_core.offset);
4297 comma = 1;
4298 }
4299 if (__kmp_hws_proc.num)
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004300 __kmp_str_buf_print(&buf, "%s%dt", comma ? "," : "", __kmp_hws_proc.num);
4301 __kmp_str_buf_print(buffer, "%s'\n", buf.str);
Jonathan Peyton30419822017-05-12 18:01:32 +00004302 __kmp_str_buf_free(&buf);
4303 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004304}
Jim Cownie5e8470a2013-09-27 10:38:44 +00004305
4306#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004307// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004308// KMP_FORKJOIN_FRAMES
Jim Cownie5e8470a2013-09-27 10:38:44 +00004309
Jonathan Peyton30419822017-05-12 18:01:32 +00004310static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
4311 void *data) {
4312 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004313} // __kmp_stg_parse_forkjoin_frames
4314
Jonathan Peyton30419822017-05-12 18:01:32 +00004315static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
4316 char const *name, void *data) {
4317 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004318} // __kmp_stg_print_forkjoin_frames
4319
Jonathan Peyton30419822017-05-12 18:01:32 +00004320// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004321// KMP_FORKJOIN_FRAMES_MODE
Jim Cownie5e8470a2013-09-27 10:38:44 +00004322
Jonathan Peyton30419822017-05-12 18:01:32 +00004323static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
4324 char const *value,
4325 void *data) {
4326 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004327} // __kmp_stg_parse_forkjoin_frames
4328
Jonathan Peyton30419822017-05-12 18:01:32 +00004329static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
4330 char const *name, void *data) {
4331 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004332} // __kmp_stg_print_forkjoin_frames
4333#endif /* USE_ITT_BUILD */
4334
Jonathan Peyton30419822017-05-12 18:01:32 +00004335// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +00004336// OMP_DISPLAY_ENV
Jim Cownie5e8470a2013-09-27 10:38:44 +00004337
4338#if OMP_40_ENABLED
4339
Jonathan Peyton30419822017-05-12 18:01:32 +00004340static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
4341 void *data) {
4342 if (__kmp_str_match("VERBOSE", 1, value)) {
4343 __kmp_display_env_verbose = TRUE;
4344 } else {
4345 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
4346 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004347
4348} // __kmp_stg_parse_omp_display_env
4349
Jonathan Peyton30419822017-05-12 18:01:32 +00004350static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
4351 char const *name, void *data) {
4352 if (__kmp_display_env_verbose) {
4353 __kmp_stg_print_str(buffer, name, "VERBOSE");
4354 } else {
4355 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
4356 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004357} // __kmp_stg_print_omp_display_env
4358
Jonathan Peyton30419822017-05-12 18:01:32 +00004359static void __kmp_stg_parse_omp_cancellation(char const *name,
4360 char const *value, void *data) {
4361 if (TCR_4(__kmp_init_parallel)) {
4362 KMP_WARNING(EnvParallelWarn, name);
4363 return;
4364 } // read value before first parallel only
4365 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004366} // __kmp_stg_parse_omp_cancellation
4367
Jonathan Peyton30419822017-05-12 18:01:32 +00004368static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
4369 char const *name, void *data) {
4370 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
Jim Cownie181b4bb2013-12-23 17:28:57 +00004371} // __kmp_stg_print_omp_cancellation
4372
Jim Cownie5e8470a2013-09-27 10:38:44 +00004373#endif
4374
Joachim Protze82e94a52017-11-01 10:08:30 +00004375#if OMP_50_ENABLED && OMPT_SUPPORT
4376
Jonas Hahnfeldaeb40ad2017-11-09 15:52:25 +00004377static char *__kmp_tool_libraries = NULL;
4378
Joachim Protze82e94a52017-11-01 10:08:30 +00004379static void __kmp_stg_parse_omp_tool_libraries(char const *name,
4380 char const *value, void *data) {
4381 __kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
4382} // __kmp_stg_parse_omp_tool_libraries
4383
4384static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer,
4385 char const *name, void *data) {
4386 if (__kmp_tool_libraries)
4387 __kmp_stg_print_str(buffer, name, __kmp_tool_libraries);
4388 else {
4389 if (__kmp_env_format) {
4390 KMP_STR_BUF_PRINT_NAME;
4391 } else {
4392 __kmp_str_buf_print(buffer, " %s", name);
4393 }
4394 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
4395 }
4396} // __kmp_stg_print_omp_tool_libraries
4397
4398#endif
4399
Jim Cownie5e8470a2013-09-27 10:38:44 +00004400// Table.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004401
4402static kmp_setting_t __kmp_stg_table[] = {
4403
Jonathan Peyton09244f32017-07-26 20:07:58 +00004404 {"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
Jonathan Peyton30419822017-05-12 18:01:32 +00004405 {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
4406 NULL, 0, 0},
4407 {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
4408 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
4409 {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
4410 NULL, 0, 0},
Jonathan Peyton09244f32017-07-26 20:07:58 +00004411 {"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
4412 __kmp_stg_print_device_thread_limit, NULL, 0, 0},
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004413#if KMP_USE_MONITOR
Jonathan Peyton30419822017-05-12 18:01:32 +00004414 {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
4415 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
Jonathan Peytonb66d1aa2016-09-27 17:11:17 +00004416#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004417 {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
4418 0, 0},
4419 {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
4420 __kmp_stg_print_stackoffset, NULL, 0, 0},
4421 {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4422 NULL, 0, 0},
4423 {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
4424 0, 0},
4425 {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
4426 0},
4427 {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
4428 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004429
Jonathan Peyton30419822017-05-12 18:01:32 +00004430 {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
4431 {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
4432 __kmp_stg_print_num_threads, NULL, 0, 0},
4433 {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
4434 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004435
Jonathan Peyton30419822017-05-12 18:01:32 +00004436 {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
4437 0},
4438 {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
4439 __kmp_stg_print_task_stealing, NULL, 0, 0},
4440 {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
4441 __kmp_stg_print_max_active_levels, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004442#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004443 {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
4444 __kmp_stg_print_default_device, NULL, 0, 0},
George Rokos28f31b42016-09-09 17:55:26 +00004445#endif
Jonathan Peytondf6818b2016-06-14 17:57:47 +00004446#if OMP_45_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00004447 {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
4448 __kmp_stg_print_max_task_priority, NULL, 0, 0},
Jonathan Peyton93e17cf2017-07-18 18:50:13 +00004449 {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
4450 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
Jonathan Peyton28510722016-02-25 18:04:09 +00004451#endif
Jonathan Peytonf4392462017-07-27 20:58:41 +00004452 {"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
4453 __kmp_stg_print_thread_limit, NULL, 0, 0},
Jonathan Peyton4f90c822017-08-02 20:04:45 +00004454 {"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
4455 __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
Jonathan Peyton30419822017-05-12 18:01:32 +00004456 {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
4457 __kmp_stg_print_wait_policy, NULL, 0, 0},
4458 {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
4459 __kmp_stg_print_disp_buffers, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004460#if KMP_NESTED_HOT_TEAMS
Jonathan Peyton30419822017-05-12 18:01:32 +00004461 {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
4462 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
4463 {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
4464 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004465#endif // KMP_NESTED_HOT_TEAMS
Jim Cownie5e8470a2013-09-27 10:38:44 +00004466
4467#if KMP_HANDLE_SIGNALS
Jonathan Peyton30419822017-05-12 18:01:32 +00004468 {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
4469 __kmp_stg_print_handle_signals, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004470#endif
4471
4472#if KMP_ARCH_X86 || KMP_ARCH_X86_64
Jonathan Peyton30419822017-05-12 18:01:32 +00004473 {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
4474 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004475#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
4476
4477#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004478 {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004479#endif
4480
4481#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +00004482 {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
4483 0},
4484 {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
4485 0},
4486 {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
4487 0},
4488 {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
4489 0},
4490 {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
4491 0},
4492 {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
4493 0},
4494 {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
4495 {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
4496 NULL, 0, 0},
4497 {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
4498 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
4499 {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
4500 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
4501 {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
4502 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
4503 {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004504
Jonathan Peyton30419822017-05-12 18:01:32 +00004505 {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
4506 __kmp_stg_print_par_range_env, NULL, 0, 0},
4507 {"KMP_YIELD_CYCLE", __kmp_stg_parse_yield_cycle,
4508 __kmp_stg_print_yield_cycle, NULL, 0, 0},
4509 {"KMP_YIELD_ON", __kmp_stg_parse_yield_on, __kmp_stg_print_yield_on, NULL,
4510 0, 0},
4511 {"KMP_YIELD_OFF", __kmp_stg_parse_yield_off, __kmp_stg_print_yield_off,
4512 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004513#endif // KMP_DEBUG
4514
Jonathan Peyton30419822017-05-12 18:01:32 +00004515 {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
4516 __kmp_stg_print_align_alloc, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004517
Jonathan Peyton30419822017-05-12 18:01:32 +00004518 {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4519 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4520 {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4521 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
4522 {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4523 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4524 {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4525 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004526#if KMP_FAST_REDUCTION_BARRIER
Jonathan Peyton30419822017-05-12 18:01:32 +00004527 {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
4528 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
4529 {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
4530 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004531#endif
4532
Jonathan Peyton30419822017-05-12 18:01:32 +00004533 {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
4534 __kmp_stg_print_abort_delay, NULL, 0, 0},
4535 {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
4536 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
4537 {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
4538 __kmp_stg_print_force_reduction, NULL, 0, 0},
4539 {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
4540 __kmp_stg_print_force_reduction, NULL, 0, 0},
4541 {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
4542 __kmp_stg_print_storage_map, NULL, 0, 0},
4543 {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
4544 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
4545 {"KMP_FOREIGN_THREADS_THREADPRIVATE",
4546 __kmp_stg_parse_foreign_threads_threadprivate,
4547 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004548
Alp Toker98758b02014-03-02 04:12:06 +00004549#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004550 {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
4551 0, 0},
4552#ifdef KMP_GOMP_COMPAT
4553 {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
4554 /* no print */ NULL, 0, 0},
4555#endif /* KMP_GOMP_COMPAT */
4556#if OMP_40_ENABLED
4557 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4558 NULL, 0, 0},
4559 {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
4560#else
4561 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, NULL, /* no print */ NULL, 0,
4562 0},
4563#endif /* OMP_40_ENABLED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00004564
Jonathan Peyton30419822017-05-12 18:01:32 +00004565 {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
4566 __kmp_stg_print_topology_method, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004567
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004568#else
Jim Cownie5e8470a2013-09-27 10:38:44 +00004569
Jonathan Peyton30419822017-05-12 18:01:32 +00004570// KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
4571// OMP_PROC_BIND and proc-bind-var are supported, however.
4572#if OMP_40_ENABLED
4573 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
4574 NULL, 0, 0},
4575#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004576
Alp Toker98758b02014-03-02 04:12:06 +00004577#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004578
Jonathan Peyton30419822017-05-12 18:01:32 +00004579 {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
4580 __kmp_stg_print_init_at_fork, NULL, 0, 0},
4581 {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
4582 0, 0},
4583 {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
4584 NULL, 0, 0},
4585 {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
4586 __kmp_stg_print_atomic_mode, NULL, 0, 0},
4587 {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
4588 __kmp_stg_print_consistency_check, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004589
4590#if USE_ITT_BUILD && USE_ITT_NOTIFY
Jonathan Peyton30419822017-05-12 18:01:32 +00004591 {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
4592 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004593#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
Jonathan Peyton30419822017-05-12 18:01:32 +00004594 {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
4595 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
4596 {"KMP_INIT_WAIT", __kmp_stg_parse_init_wait, __kmp_stg_print_init_wait,
4597 NULL, 0, 0},
4598 {"KMP_NEXT_WAIT", __kmp_stg_parse_next_wait, __kmp_stg_print_next_wait,
4599 NULL, 0, 0},
4600 {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
4601 NULL, 0, 0},
4602 {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
4603 NULL, 0, 0},
4604 {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
4605 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004606
4607#ifdef USE_LOAD_BALANCE
Jonathan Peyton30419822017-05-12 18:01:32 +00004608 {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
4609 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004610#endif
4611
Jonathan Peyton30419822017-05-12 18:01:32 +00004612 {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
4613 __kmp_stg_print_lock_block, NULL, 0, 0},
4614 {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
4615 NULL, 0, 0},
4616 {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
4617 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004618#if KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004619 {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
4620 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004621#if KMP_DEBUG_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004622 {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
4623 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004624#endif
4625#endif // KMP_USE_ADAPTIVE_LOCKS
Jonathan Peyton30419822017-05-12 18:01:32 +00004626 {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4627 NULL, 0, 0},
4628 {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
4629 NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004630#if USE_ITT_BUILD
Jonathan Peyton30419822017-05-12 18:01:32 +00004631 {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
4632 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
4633 {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
4634 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004635#endif
4636
Jonathan Peyton30419822017-05-12 18:01:32 +00004637#if OMP_40_ENABLED
4638 {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
4639 __kmp_stg_print_omp_display_env, NULL, 0, 0},
4640 {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
4641 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
Jim Cownie5e8470a2013-09-27 10:38:44 +00004642#endif
Joachim Protze82e94a52017-11-01 10:08:30 +00004643
4644#if OMP_50_ENABLED && OMPT_SUPPORT
4645 {"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries,
4646 __kmp_stg_print_omp_tool_libraries, NULL, 0, 0},
4647#endif
4648
Jonathan Peyton30419822017-05-12 18:01:32 +00004649 {"", NULL, NULL, NULL, 0, 0}}; // settings
Jim Cownie5e8470a2013-09-27 10:38:44 +00004650
Jonathan Peyton30419822017-05-12 18:01:32 +00004651static int const __kmp_stg_count =
4652 sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004653
Jonathan Peyton30419822017-05-12 18:01:32 +00004654static inline kmp_setting_t *__kmp_stg_find(char const *name) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004655
Jonathan Peyton30419822017-05-12 18:01:32 +00004656 int i;
4657 if (name != NULL) {
4658 for (i = 0; i < __kmp_stg_count; ++i) {
4659 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
4660 return &__kmp_stg_table[i];
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004661 }
4662 }
4663 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004664 return NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004665
4666} // __kmp_stg_find
4667
Jonathan Peyton30419822017-05-12 18:01:32 +00004668static int __kmp_stg_cmp(void const *_a, void const *_b) {
Andrey Churbanov5ba90c72017-07-17 09:03:14 +00004669 const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
4670 const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004671
Jonathan Peyton30419822017-05-12 18:01:32 +00004672 // Process KMP_AFFINITY last.
4673 // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
4674 if (strcmp(a->name, "KMP_AFFINITY") == 0) {
4675 if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4676 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004677 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004678 return 1;
4679 } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
4680 return -1;
4681 }
4682 return strcmp(a->name, b->name);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004683} // __kmp_stg_cmp
4684
Jonathan Peyton30419822017-05-12 18:01:32 +00004685static void __kmp_stg_init(void) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004686
Jonathan Peyton30419822017-05-12 18:01:32 +00004687 static int initialized = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004688
Jonathan Peyton30419822017-05-12 18:01:32 +00004689 if (!initialized) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004690
Jonathan Peyton30419822017-05-12 18:01:32 +00004691 // Sort table.
4692 qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
4693 __kmp_stg_cmp);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004694
Jonathan Peyton30419822017-05-12 18:01:32 +00004695 { // Initialize *_STACKSIZE data.
4696 kmp_setting_t *kmp_stacksize =
4697 __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004698#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004699 kmp_setting_t *gomp_stacksize =
4700 __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004701#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004702 kmp_setting_t *omp_stacksize =
4703 __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004704
Jonathan Peyton8c432f22018-01-04 22:56:47 +00004705 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
Jonathan Peyton30419822017-05-12 18:01:32 +00004706 // !!! Compiler does not understand rivals is used and optimizes out
4707 // assignments
4708 // !!! rivals[ i ++ ] = ...;
4709 static kmp_setting_t *volatile rivals[4];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004710 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004711#ifdef KMP_GOMP_COMPAT
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004712 static kmp_stg_ss_data_t gomp_data = {1024,
4713 CCAST(kmp_setting_t **, rivals)};
Jim Cownie5e8470a2013-09-27 10:38:44 +00004714#endif
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004715 static kmp_stg_ss_data_t omp_data = {1024,
4716 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004717 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004718
Jonathan Peyton30419822017-05-12 18:01:32 +00004719 rivals[i++] = kmp_stacksize;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004720#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004721 if (gomp_stacksize != NULL) {
4722 rivals[i++] = gomp_stacksize;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004723 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004724#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004725 rivals[i++] = omp_stacksize;
4726 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004727
Jonathan Peyton30419822017-05-12 18:01:32 +00004728 kmp_stacksize->data = &kmp_data;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004729#ifdef KMP_GOMP_COMPAT
Jonathan Peyton30419822017-05-12 18:01:32 +00004730 if (gomp_stacksize != NULL) {
4731 gomp_stacksize->data = &gomp_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004732 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004733#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00004734 omp_stacksize->data = &omp_data;
4735 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004736
Jonathan Peyton30419822017-05-12 18:01:32 +00004737 { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
4738 kmp_setting_t *kmp_library =
4739 __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
4740 kmp_setting_t *omp_wait_policy =
4741 __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004742
Jonathan Peyton8c432f22018-01-04 22:56:47 +00004743 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
Jonathan Peyton30419822017-05-12 18:01:32 +00004744 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004745 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
4746 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004747 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004748
Jonathan Peyton30419822017-05-12 18:01:32 +00004749 rivals[i++] = kmp_library;
4750 if (omp_wait_policy != NULL) {
4751 rivals[i++] = omp_wait_policy;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004752 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004753 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004754
Jonathan Peyton30419822017-05-12 18:01:32 +00004755 kmp_library->data = &kmp_data;
4756 if (omp_wait_policy != NULL) {
4757 omp_wait_policy->data = &omp_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004758 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004759 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004760
Jonathan Peytonf4392462017-07-27 20:58:41 +00004761 { // Initialize KMP_DEVICE_THREAD_LIMIT and KMP_ALL_THREADS
Jonathan Peyton09244f32017-07-26 20:07:58 +00004762 kmp_setting_t *kmp_device_thread_limit =
4763 __kmp_stg_find("KMP_DEVICE_THREAD_LIMIT"); // 1st priority.
Jonathan Peyton30419822017-05-12 18:01:32 +00004764 kmp_setting_t *kmp_all_threads =
Jonathan Peyton09244f32017-07-26 20:07:58 +00004765 __kmp_stg_find("KMP_ALL_THREADS"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004766
Jonathan Peyton8c432f22018-01-04 22:56:47 +00004767 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
Jonathan Peytonf4392462017-07-27 20:58:41 +00004768 static kmp_setting_t *volatile rivals[3];
Jonathan Peyton30419822017-05-12 18:01:32 +00004769 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004770
Jonathan Peyton09244f32017-07-26 20:07:58 +00004771 rivals[i++] = kmp_device_thread_limit;
Jonathan Peyton30419822017-05-12 18:01:32 +00004772 rivals[i++] = kmp_all_threads;
Jonathan Peyton30419822017-05-12 18:01:32 +00004773 rivals[i++] = NULL;
Jonathan Peyton09244f32017-07-26 20:07:58 +00004774
4775 kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004776 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004777 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004778
Jonathan Peyton3f850bf2017-10-06 19:23:19 +00004779 { // Initialize KMP_HW_SUBSET and KMP_PLACE_THREADS
4780 // 1st priority
4781 kmp_setting_t *kmp_hw_subset = __kmp_stg_find("KMP_HW_SUBSET");
4782 // 2nd priority
4783 kmp_setting_t *kmp_place_threads = __kmp_stg_find("KMP_PLACE_THREADS");
4784
Jonathan Peyton8c432f22018-01-04 22:56:47 +00004785 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
Jonathan Peyton3f850bf2017-10-06 19:23:19 +00004786 static kmp_setting_t *volatile rivals[3];
4787 int i = 0;
4788
4789 rivals[i++] = kmp_hw_subset;
4790 rivals[i++] = kmp_place_threads;
4791 rivals[i++] = NULL;
4792
4793 kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
4794 kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
4795 }
4796
Alp Toker98758b02014-03-02 04:12:06 +00004797#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004798 { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
4799 kmp_setting_t *kmp_affinity =
4800 __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
4801 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004802
Jonathan Peyton30419822017-05-12 18:01:32 +00004803#ifdef KMP_GOMP_COMPAT
4804 kmp_setting_t *gomp_cpu_affinity =
4805 __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
4806 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
4807#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004808
Jonathan Peyton30419822017-05-12 18:01:32 +00004809 kmp_setting_t *omp_proc_bind =
4810 __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
4811 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004812
Jonathan Peyton8c432f22018-01-04 22:56:47 +00004813 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
Jonathan Peyton30419822017-05-12 18:01:32 +00004814 static kmp_setting_t *volatile rivals[4];
4815 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004816
Jonathan Peyton30419822017-05-12 18:01:32 +00004817 rivals[i++] = kmp_affinity;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004818
Jonathan Peyton30419822017-05-12 18:01:32 +00004819#ifdef KMP_GOMP_COMPAT
4820 rivals[i++] = gomp_cpu_affinity;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004821 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004822#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00004823
Jonathan Peyton30419822017-05-12 18:01:32 +00004824 rivals[i++] = omp_proc_bind;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004825 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004826 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004827
Jonathan Peyton30419822017-05-12 18:01:32 +00004828#if OMP_40_ENABLED
4829 static kmp_setting_t *volatile places_rivals[4];
4830 i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004831
Jonathan Peyton30419822017-05-12 18:01:32 +00004832 kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
4833 KMP_DEBUG_ASSERT(omp_places != NULL);
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004834
Jonathan Peyton30419822017-05-12 18:01:32 +00004835 places_rivals[i++] = kmp_affinity;
4836#ifdef KMP_GOMP_COMPAT
4837 places_rivals[i++] = gomp_cpu_affinity;
4838#endif
4839 places_rivals[i++] = omp_places;
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004840 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
Jonathan Peyton30419822017-05-12 18:01:32 +00004841 places_rivals[i++] = NULL;
4842#endif
4843 }
Alp Toker98758b02014-03-02 04:12:06 +00004844#else
Jonathan Peyton30419822017-05-12 18:01:32 +00004845// KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
4846// OMP_PLACES not supported yet.
Jim Cownie4cc4bb42014-10-07 16:25:50 +00004847#endif // KMP_AFFINITY_SUPPORTED
Jim Cownie5e8470a2013-09-27 10:38:44 +00004848
Jonathan Peyton30419822017-05-12 18:01:32 +00004849 { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
4850 kmp_setting_t *kmp_force_red =
4851 __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
4852 kmp_setting_t *kmp_determ_red =
4853 __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
Jim Cownie5e8470a2013-09-27 10:38:44 +00004854
Jonathan Peyton8c432f22018-01-04 22:56:47 +00004855 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
Jonathan Peyton30419822017-05-12 18:01:32 +00004856 static kmp_setting_t *volatile rivals[3];
Andrey Churbanovc47afcd2017-07-03 11:24:08 +00004857 static kmp_stg_fr_data_t force_data = {1,
4858 CCAST(kmp_setting_t **, rivals)};
4859 static kmp_stg_fr_data_t determ_data = {0,
4860 CCAST(kmp_setting_t **, rivals)};
Jonathan Peyton30419822017-05-12 18:01:32 +00004861 int i = 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004862
Jonathan Peyton30419822017-05-12 18:01:32 +00004863 rivals[i++] = kmp_force_red;
4864 if (kmp_determ_red != NULL) {
4865 rivals[i++] = kmp_determ_red;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004866 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004867 rivals[i++] = NULL;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004868
Jonathan Peyton30419822017-05-12 18:01:32 +00004869 kmp_force_red->data = &force_data;
4870 if (kmp_determ_red != NULL) {
4871 kmp_determ_red->data = &determ_data;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004872 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004873 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004874
Jonathan Peyton30419822017-05-12 18:01:32 +00004875 initialized = 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004876 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004877
Jonathan Peyton30419822017-05-12 18:01:32 +00004878 // Reset flags.
4879 int i;
4880 for (i = 0; i < __kmp_stg_count; ++i) {
4881 __kmp_stg_table[i].set = 0;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004882 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004883
4884} // __kmp_stg_init
4885
Jonathan Peyton30419822017-05-12 18:01:32 +00004886static void __kmp_stg_parse(char const *name, char const *value) {
4887 // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
4888 // really nameless, they are presented in environment block as
4889 // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
4890 if (name[0] == 0) {
4891 return;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004892 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004893
Jonathan Peyton30419822017-05-12 18:01:32 +00004894 if (value != NULL) {
4895 kmp_setting_t *setting = __kmp_stg_find(name);
4896 if (setting != NULL) {
4897 setting->parse(name, value, setting->data);
4898 setting->defined = 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004899 }
4900 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004901
4902} // __kmp_stg_parse
4903
Jonathan Peyton30419822017-05-12 18:01:32 +00004904static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
4905 char const *name, // Name of variable.
4906 char const *value, // Value of the variable.
4907 kmp_setting_t **rivals // List of rival settings (must include current one).
4908 ) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004909
Jonathan Peyton30419822017-05-12 18:01:32 +00004910 if (rivals == NULL) {
4911 return 0;
4912 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004913
Jonathan Peyton30419822017-05-12 18:01:32 +00004914 // Loop thru higher priority settings (listed before current).
4915 int i = 0;
4916 for (; strcmp(rivals[i]->name, name) != 0; i++) {
4917 KMP_DEBUG_ASSERT(rivals[i] != NULL);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004918
Alp Toker763b9392014-02-28 09:42:41 +00004919#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00004920 if (rivals[i] == __kmp_affinity_notype) {
4921 // If KMP_AFFINITY is specified without a type name,
4922 // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
4923 continue;
4924 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004925#endif
4926
Jonathan Peyton30419822017-05-12 18:01:32 +00004927 if (rivals[i]->set) {
4928 KMP_WARNING(StgIgnored, name, rivals[i]->name);
4929 return 1;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004930 }
4931 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004932
Jonathan Peyton30419822017-05-12 18:01:32 +00004933 ++i; // Skip current setting.
4934 return 0;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004935
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004936} // __kmp_stg_check_rivals
Jim Cownie5e8470a2013-09-27 10:38:44 +00004937
Jonathan Peyton30419822017-05-12 18:01:32 +00004938static int __kmp_env_toPrint(char const *name, int flag) {
4939 int rc = 0;
4940 kmp_setting_t *setting = __kmp_stg_find(name);
4941 if (setting != NULL) {
4942 rc = setting->defined;
4943 if (flag >= 0) {
4944 setting->defined = flag;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004945 }
4946 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004947 return rc;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004948}
4949
Jonathan Peyton30419822017-05-12 18:01:32 +00004950static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004951
Jonathan Peyton30419822017-05-12 18:01:32 +00004952 char const *value;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004953
Jonathan Peyton30419822017-05-12 18:01:32 +00004954 /* OMP_NUM_THREADS */
4955 value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
4956 if (value) {
4957 ompc_set_num_threads(__kmp_dflt_team_nth);
4958 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004959
Jonathan Peyton30419822017-05-12 18:01:32 +00004960 /* KMP_BLOCKTIME */
4961 value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
4962 if (value) {
4963 kmpc_set_blocktime(__kmp_dflt_blocktime);
4964 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004965
Jonathan Peyton30419822017-05-12 18:01:32 +00004966 /* OMP_NESTED */
4967 value = __kmp_env_blk_var(block, "OMP_NESTED");
4968 if (value) {
4969 ompc_set_nested(__kmp_dflt_nested);
4970 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004971
Jonathan Peyton30419822017-05-12 18:01:32 +00004972 /* OMP_DYNAMIC */
4973 value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
4974 if (value) {
4975 ompc_set_dynamic(__kmp_global.g.g_dynamic);
4976 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00004977}
4978
Jonathan Peyton30419822017-05-12 18:01:32 +00004979void __kmp_env_initialize(char const *string) {
Jim Cownie5e8470a2013-09-27 10:38:44 +00004980
Jonathan Peyton30419822017-05-12 18:01:32 +00004981 kmp_env_blk_t block;
4982 int i;
Jim Cownie5e8470a2013-09-27 10:38:44 +00004983
Jonathan Peyton30419822017-05-12 18:01:32 +00004984 __kmp_stg_init();
Jim Cownie5e8470a2013-09-27 10:38:44 +00004985
Jonathan Peyton30419822017-05-12 18:01:32 +00004986 // Hack!!!
4987 if (string == NULL) {
4988 // __kmp_max_nth = __kmp_sys_max_nth;
4989 __kmp_threads_capacity =
4990 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00004991 }
Jonathan Peyton30419822017-05-12 18:01:32 +00004992 __kmp_env_blk_init(&block, string);
Jim Cownie5e8470a2013-09-27 10:38:44 +00004993
Jonathan Peyton30419822017-05-12 18:01:32 +00004994 // update the set flag on all entries that have an env var
4995 for (i = 0; i < block.count; ++i) {
4996 if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
4997 continue;
4998 }
4999 if (block.vars[i].value == NULL) {
5000 continue;
5001 }
5002 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
5003 if (setting != NULL) {
5004 setting->set = 1;
5005 }
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005006 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005007
Jonathan Peyton94a114f2017-10-20 19:30:57 +00005008 // We need to know if blocktime was set when processing OMP_WAIT_POLICY
Jonathan Peyton30419822017-05-12 18:01:32 +00005009 blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
Jonathan Peyton50e8f182016-04-04 19:38:32 +00005010
Jonathan Peyton30419822017-05-12 18:01:32 +00005011 // Special case. If we parse environment, not a string, process KMP_WARNINGS
5012 // first.
5013 if (string == NULL) {
5014 char const *name = "KMP_WARNINGS";
5015 char const *value = __kmp_env_blk_var(&block, name);
5016 __kmp_stg_parse(name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005017 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005018
Alp Toker763b9392014-02-28 09:42:41 +00005019#if KMP_AFFINITY_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005020 // Special case. KMP_AFFINITY is not a rival to other affinity env vars
5021 // if no affinity type is specified. We want to allow
5022 // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
5023 // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
5024 // affinity mechanism.
5025 __kmp_affinity_notype = NULL;
5026 char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
5027 if (aff_str != NULL) {
5028// Check if the KMP_AFFINITY type is specified in the string.
5029// We just search the string for "compact", "scatter", etc.
5030// without really parsing the string. The syntax of the
5031// KMP_AFFINITY env var is such that none of the affinity
5032// type names can appear anywhere other that the type
5033// specifier, even as substrings.
5034//
5035// I can't find a case-insensitive version of strstr on Windows* OS.
5036// Use the case-sensitive version for now.
Jim Cownie5e8470a2013-09-27 10:38:44 +00005037
Jonathan Peyton30419822017-05-12 18:01:32 +00005038#if KMP_OS_WINDOWS
5039#define FIND strstr
5040#else
5041#define FIND strcasestr
5042#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +00005043
Jonathan Peyton30419822017-05-12 18:01:32 +00005044 if ((FIND(aff_str, "none") == NULL) &&
5045 (FIND(aff_str, "physical") == NULL) &&
5046 (FIND(aff_str, "logical") == NULL) &&
5047 (FIND(aff_str, "compact") == NULL) &&
5048 (FIND(aff_str, "scatter") == NULL) &&
5049 (FIND(aff_str, "explicit") == NULL) &&
5050 (FIND(aff_str, "balanced") == NULL) &&
5051 (FIND(aff_str, "disabled") == NULL)) {
5052 __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
5053 } else {
5054 // A new affinity type is specified.
5055 // Reset the affinity flags to their default values,
5056 // in case this is called from kmp_set_defaults().
5057 __kmp_affinity_type = affinity_default;
5058 __kmp_affinity_gran = affinity_gran_default;
5059 __kmp_affinity_top_method = affinity_top_method_default;
5060 __kmp_affinity_respect_mask = affinity_respect_mask_default;
5061 }
5062#undef FIND
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005063
5064#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005065 // Also reset the affinity flags if OMP_PROC_BIND is specified.
5066 aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
5067 if (aff_str != NULL) {
5068 __kmp_affinity_type = affinity_default;
5069 __kmp_affinity_gran = affinity_gran_default;
5070 __kmp_affinity_top_method = affinity_top_method_default;
5071 __kmp_affinity_respect_mask = affinity_respect_mask_default;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005072 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005073#endif /* OMP_40_ENABLED */
5074 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005075
Alp Toker763b9392014-02-28 09:42:41 +00005076#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005077
5078#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005079 // Set up the nested proc bind type vector.
5080 if (__kmp_nested_proc_bind.bind_types == NULL) {
5081 __kmp_nested_proc_bind.bind_types =
5082 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
5083 if (__kmp_nested_proc_bind.bind_types == NULL) {
5084 KMP_FATAL(MemoryAllocFailed);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005085 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005086 __kmp_nested_proc_bind.size = 1;
5087 __kmp_nested_proc_bind.used = 1;
5088#if KMP_AFFINITY_SUPPORTED
5089 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
5090#else
5091 // default proc bind is false if affinity not supported
5092 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5093#endif
5094 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005095#endif /* OMP_40_ENABLED */
5096
Jonathan Peyton30419822017-05-12 18:01:32 +00005097 // Now process all of the settings.
5098 for (i = 0; i < block.count; ++i) {
5099 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005100 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005101
Jonathan Peyton30419822017-05-12 18:01:32 +00005102 // If user locks have been allocated yet, don't reset the lock vptr table.
5103 if (!__kmp_init_user_locks) {
5104 if (__kmp_user_lock_kind == lk_default) {
5105 __kmp_user_lock_kind = lk_queuing;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005106 }
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005107#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +00005108 __kmp_init_dynamic_user_locks();
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005109#else
Jonathan Peyton30419822017-05-12 18:01:32 +00005110 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
Andrey Churbanov5c56fb52015-02-20 18:05:17 +00005111#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005112 } else {
5113 KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
5114 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
5115// Binds lock functions again to follow the transition between different
5116// KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
5117// as we do not allow lock kind changes after making a call to any
5118// user lock functions (true).
5119#if KMP_USE_DYNAMIC_LOCK
5120 __kmp_init_dynamic_user_locks();
5121#else
5122 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
5123#endif
5124 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005125
Alp Toker763b9392014-02-28 09:42:41 +00005126#if KMP_AFFINITY_SUPPORTED
Jim Cownie4cc4bb42014-10-07 16:25:50 +00005127
Jonathan Peyton30419822017-05-12 18:01:32 +00005128 if (!TCR_4(__kmp_init_middle)) {
Jonathan Peyton79390ad2018-01-10 18:31:49 +00005129#if KMP_USE_HWLOC
5130 // Force using hwloc when either tiles or numa nodes requested within
5131 // KMP_HW_SUBSET and no other topology method is requested
5132 if ((__kmp_hws_node.num > 0 || __kmp_hws_tile.num > 0 ||
5133 __kmp_affinity_gran == affinity_gran_tile) &&
5134 (__kmp_affinity_top_method == affinity_top_method_default)) {
5135 __kmp_affinity_top_method = affinity_top_method_hwloc;
5136 }
5137#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005138 // Determine if the machine/OS is actually capable of supporting
5139 // affinity.
5140 const char *var = "KMP_AFFINITY";
5141 KMPAffinity::pick_api();
Jonathan Peytone3e2aaf2017-05-31 20:35:22 +00005142#if KMP_USE_HWLOC
5143 // If Hwloc topology discovery was requested but affinity was also disabled,
5144 // then tell user that Hwloc request is being ignored and use default
5145 // topology discovery method.
5146 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
5147 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
5148 KMP_WARNING(AffIgnoringHwloc, var);
5149 __kmp_affinity_top_method = affinity_top_method_all;
5150 }
5151#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005152 if (__kmp_affinity_type == affinity_disabled) {
5153 KMP_AFFINITY_DISABLE();
5154 } else if (!KMP_AFFINITY_CAPABLE()) {
5155 __kmp_affinity_dispatch->determine_capable(var);
5156 if (!KMP_AFFINITY_CAPABLE()) {
5157 if (__kmp_affinity_verbose ||
5158 (__kmp_affinity_warnings &&
5159 (__kmp_affinity_type != affinity_default) &&
5160 (__kmp_affinity_type != affinity_none) &&
5161 (__kmp_affinity_type != affinity_disabled))) {
5162 KMP_WARNING(AffNotSupported, var);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005163 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005164 __kmp_affinity_type = affinity_disabled;
5165 __kmp_affinity_respect_mask = 0;
5166 __kmp_affinity_gran = affinity_gran_fine;
5167 }
5168 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005169
Jonathan Peyton30419822017-05-12 18:01:32 +00005170#if OMP_40_ENABLED
5171 if (__kmp_affinity_type == affinity_disabled) {
5172 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
5173 } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
5174 // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
5175 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
5176 }
5177#endif /* OMP_40_ENABLED */
5178
5179 if (KMP_AFFINITY_CAPABLE()) {
5180
5181#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005182 // This checks to see if the initial affinity mask is equal
5183 // to a single windows processor group. If it is, then we do
5184 // not respect the initial affinity mask and instead, use the
5185 // entire machine.
5186 bool exactly_one_group = false;
5187 if (__kmp_num_proc_groups > 1) {
5188 int group;
5189 bool within_one_group;
5190 // Get the initial affinity mask and determine if it is
5191 // contained within a single group.
5192 kmp_affin_mask_t *init_mask;
5193 KMP_CPU_ALLOC(init_mask);
5194 __kmp_get_system_affinity(init_mask, TRUE);
5195 group = __kmp_get_proc_group(init_mask);
5196 within_one_group = (group >= 0);
5197 // If the initial affinity is within a single group,
5198 // then determine if it is equal to that single group.
5199 if (within_one_group) {
5200 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
5201 int num_bits_in_mask = 0;
5202 for (int bit = init_mask->begin(); bit != init_mask->end();
5203 bit = init_mask->next(bit))
5204 num_bits_in_mask++;
5205 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
5206 }
5207 KMP_CPU_FREE(init_mask);
5208 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005209
5210 // Handle the Win 64 group affinity stuff if there are multiple
5211 // processor groups, or if the user requested it, and OMP 4.0
5212 // affinity is not in effect.
5213 if (((__kmp_num_proc_groups > 1) &&
5214 (__kmp_affinity_type == affinity_default)
5215#if OMP_40_ENABLED
5216 && (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default))
5217#endif
5218 || (__kmp_affinity_top_method == affinity_top_method_group)) {
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005219 if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
5220 exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005221 __kmp_affinity_respect_mask = FALSE;
5222 }
5223 if (__kmp_affinity_type == affinity_default) {
5224 __kmp_affinity_type = affinity_compact;
5225#if OMP_40_ENABLED
5226 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5227#endif
5228 }
5229 if (__kmp_affinity_top_method == affinity_top_method_default) {
5230 if (__kmp_affinity_gran == affinity_gran_default) {
5231 __kmp_affinity_top_method = affinity_top_method_group;
5232 __kmp_affinity_gran = affinity_gran_group;
5233 } else if (__kmp_affinity_gran == affinity_gran_group) {
5234 __kmp_affinity_top_method = affinity_top_method_group;
5235 } else {
5236 __kmp_affinity_top_method = affinity_top_method_all;
5237 }
5238 } else if (__kmp_affinity_top_method == affinity_top_method_group) {
5239 if (__kmp_affinity_gran == affinity_gran_default) {
5240 __kmp_affinity_gran = affinity_gran_group;
5241 } else if ((__kmp_affinity_gran != affinity_gran_group) &&
5242 (__kmp_affinity_gran != affinity_gran_fine) &&
5243 (__kmp_affinity_gran != affinity_gran_thread)) {
5244 const char *str = NULL;
5245 switch (__kmp_affinity_gran) {
5246 case affinity_gran_core:
5247 str = "core";
5248 break;
5249 case affinity_gran_package:
5250 str = "package";
5251 break;
5252 case affinity_gran_node:
5253 str = "node";
5254 break;
Andrey Churbanova5868212017-11-30 11:51:47 +00005255 case affinity_gran_tile:
5256 str = "tile";
5257 break;
Jonathan Peyton30419822017-05-12 18:01:32 +00005258 default:
5259 KMP_DEBUG_ASSERT(0);
5260 }
5261 KMP_WARNING(AffGranTopGroup, var, str);
5262 __kmp_affinity_gran = affinity_gran_fine;
5263 }
5264 } else {
5265 if (__kmp_affinity_gran == affinity_gran_default) {
5266 __kmp_affinity_gran = affinity_gran_core;
5267 } else if (__kmp_affinity_gran == affinity_gran_group) {
5268 const char *str = NULL;
5269 switch (__kmp_affinity_type) {
5270 case affinity_physical:
5271 str = "physical";
5272 break;
5273 case affinity_logical:
5274 str = "logical";
5275 break;
5276 case affinity_compact:
5277 str = "compact";
5278 break;
5279 case affinity_scatter:
5280 str = "scatter";
5281 break;
5282 case affinity_explicit:
5283 str = "explicit";
5284 break;
5285 // No MIC on windows, so no affinity_balanced case
5286 default:
5287 KMP_DEBUG_ASSERT(0);
5288 }
5289 KMP_WARNING(AffGranGroupType, var, str);
5290 __kmp_affinity_gran = affinity_gran_core;
5291 }
5292 }
5293 } else
5294
5295#endif /* KMP_GROUP_AFFINITY */
5296
5297 {
5298 if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
5299#if KMP_GROUP_AFFINITY
Jonathan Peyton9f5df8b2017-05-31 20:33:56 +00005300 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005301 __kmp_affinity_respect_mask = FALSE;
5302 } else
5303#endif /* KMP_GROUP_AFFINITY */
5304 {
5305 __kmp_affinity_respect_mask = TRUE;
5306 }
5307 }
5308#if OMP_40_ENABLED
5309 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
5310 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
5311 if (__kmp_affinity_type == affinity_default) {
5312 __kmp_affinity_type = affinity_compact;
5313 __kmp_affinity_dups = FALSE;
5314 }
5315 } else
5316#endif /* OMP_40_ENABLED */
5317 if (__kmp_affinity_type == affinity_default) {
5318#if OMP_40_ENABLED
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005319#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005320 if (__kmp_mic_type != non_mic) {
5321 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
5322 } else
5323#endif
5324 {
Andrey Churbanov94e569e2015-03-10 09:19:47 +00005325 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
Jonathan Peyton30419822017-05-12 18:01:32 +00005326 }
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005327#endif /* OMP_40_ENABLED */
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005328#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005329 if (__kmp_mic_type != non_mic) {
5330 __kmp_affinity_type = affinity_scatter;
5331 } else
Andrey Churbanov613edeb2015-02-20 18:14:43 +00005332#endif
Jonathan Peyton30419822017-05-12 18:01:32 +00005333 {
5334 __kmp_affinity_type = affinity_none;
5335 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005336 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005337 if ((__kmp_affinity_gran == affinity_gran_default) &&
5338 (__kmp_affinity_gran_levels < 0)) {
Jonathan Peyton492e0a32017-06-13 17:17:26 +00005339#if KMP_MIC_SUPPORTED
Jonathan Peyton30419822017-05-12 18:01:32 +00005340 if (__kmp_mic_type != non_mic) {
5341 __kmp_affinity_gran = affinity_gran_fine;
5342 } else
5343#endif
5344 {
5345 __kmp_affinity_gran = affinity_gran_core;
5346 }
5347 }
5348 if (__kmp_affinity_top_method == affinity_top_method_default) {
5349 __kmp_affinity_top_method = affinity_top_method_all;
5350 }
5351 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005352 }
5353
Jonathan Peyton30419822017-05-12 18:01:32 +00005354 K_DIAG(1, ("__kmp_affinity_type == %d\n", __kmp_affinity_type));
5355 K_DIAG(1, ("__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
5356 K_DIAG(1, ("__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
5357 K_DIAG(1, ("__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
5358 K_DIAG(1, ("__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
5359 K_DIAG(1, ("__kmp_affinity_respect_mask == %d\n",
5360 __kmp_affinity_respect_mask));
5361 K_DIAG(1, ("__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
5362
5363 KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
5364#if OMP_40_ENABLED
5365 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
5366#endif
5367 }
5368
Alp Toker763b9392014-02-28 09:42:41 +00005369#endif /* KMP_AFFINITY_SUPPORTED */
Jim Cownie5e8470a2013-09-27 10:38:44 +00005370
Jonathan Peyton30419822017-05-12 18:01:32 +00005371 if (__kmp_version) {
5372 __kmp_print_version_1();
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005373 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005374
Jonathan Peyton30419822017-05-12 18:01:32 +00005375 // Post-initialization step: some env. vars need their value's further
5376 // processing
5377 if (string != NULL) { // kmp_set_defaults() was called
5378 __kmp_aux_env_initialize(&block);
5379 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005380
Jonathan Peyton30419822017-05-12 18:01:32 +00005381 __kmp_env_blk_free(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005382
Jonathan Peyton30419822017-05-12 18:01:32 +00005383 KMP_MB();
Jim Cownie5e8470a2013-09-27 10:38:44 +00005384
5385} // __kmp_env_initialize
5386
Jonathan Peyton30419822017-05-12 18:01:32 +00005387void __kmp_env_print() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005388
Jonathan Peyton30419822017-05-12 18:01:32 +00005389 kmp_env_blk_t block;
5390 int i;
5391 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005392
Jonathan Peyton30419822017-05-12 18:01:32 +00005393 __kmp_stg_init();
5394 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005395
Jonathan Peyton30419822017-05-12 18:01:32 +00005396 __kmp_env_blk_init(&block, NULL);
5397 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005398
Jonathan Peyton30419822017-05-12 18:01:32 +00005399 // Print real environment values.
5400 __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
5401 for (i = 0; i < block.count; ++i) {
5402 char const *name = block.vars[i].name;
5403 char const *value = block.vars[i].value;
5404 if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
5405 strncmp(name, "OMP_", 4) == 0
5406#ifdef KMP_GOMP_COMPAT
5407 || strncmp(name, "GOMP_", 5) == 0
5408#endif // KMP_GOMP_COMPAT
Jim Cownie5e8470a2013-09-27 10:38:44 +00005409 ) {
Jonathan Peyton30419822017-05-12 18:01:32 +00005410 __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005411 }
5412 }
Jonathan Peyton30419822017-05-12 18:01:32 +00005413 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005414
Jonathan Peyton30419822017-05-12 18:01:32 +00005415 // Print internal (effective) settings.
5416 __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
5417 for (int i = 0; i < __kmp_stg_count; ++i) {
5418 if (__kmp_stg_table[i].print != NULL) {
5419 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5420 __kmp_stg_table[i].data);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005421 }
5422 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005423
Jonathan Peyton30419822017-05-12 18:01:32 +00005424 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005425
Jonathan Peyton30419822017-05-12 18:01:32 +00005426 __kmp_env_blk_free(&block);
5427 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005428
Jonathan Peyton30419822017-05-12 18:01:32 +00005429 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005430
5431} // __kmp_env_print
5432
Jim Cownie5e8470a2013-09-27 10:38:44 +00005433#if OMP_40_ENABLED
Jonathan Peyton30419822017-05-12 18:01:32 +00005434void __kmp_env_print_2() {
Jim Cownie5e8470a2013-09-27 10:38:44 +00005435
Jonathan Peyton30419822017-05-12 18:01:32 +00005436 kmp_env_blk_t block;
5437 kmp_str_buf_t buffer;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005438
Jonathan Peyton30419822017-05-12 18:01:32 +00005439 __kmp_env_format = 1;
Jim Cownie5e8470a2013-09-27 10:38:44 +00005440
Jonathan Peyton30419822017-05-12 18:01:32 +00005441 __kmp_stg_init();
5442 __kmp_str_buf_init(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005443
Jonathan Peyton30419822017-05-12 18:01:32 +00005444 __kmp_env_blk_init(&block, NULL);
5445 __kmp_env_blk_sort(&block);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005446
Jonathan Peyton30419822017-05-12 18:01:32 +00005447 __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
5448 __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005449
Jonathan Peyton30419822017-05-12 18:01:32 +00005450 for (int i = 0; i < __kmp_stg_count; ++i) {
5451 if (__kmp_stg_table[i].print != NULL &&
5452 ((__kmp_display_env &&
5453 strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
5454 __kmp_display_env_verbose)) {
5455 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
5456 __kmp_stg_table[i].data);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +00005457 }
5458 }
Jim Cownie5e8470a2013-09-27 10:38:44 +00005459
Jonathan Peyton30419822017-05-12 18:01:32 +00005460 __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
5461 __kmp_str_buf_print(&buffer, "\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005462
Jonathan Peyton30419822017-05-12 18:01:32 +00005463 __kmp_printf("%s", buffer.str);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005464
Jonathan Peyton30419822017-05-12 18:01:32 +00005465 __kmp_env_blk_free(&block);
5466 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +00005467
Jonathan Peyton30419822017-05-12 18:01:32 +00005468 __kmp_printf("\n");
Jim Cownie5e8470a2013-09-27 10:38:44 +00005469
5470} // __kmp_env_print_2
5471#endif // OMP_40_ENABLED
5472
Jim Cownie5e8470a2013-09-27 10:38:44 +00005473// end of file