LLVM OpenMP* Runtime Library
kmp_settings.cpp
1/*
2 * kmp_settings.cpp -- Initialize environment variables
3 */
4
5//===----------------------------------------------------------------------===//
6//
7// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8// See https://llvm.org/LICENSE.txt for license information.
9// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10//
11//===----------------------------------------------------------------------===//
12
13#include "kmp.h"
14#include "kmp_affinity.h"
15#include "kmp_atomic.h"
16#if KMP_USE_HIER_SCHED
17#include "kmp_dispatch_hier.h"
18#endif
19#include "kmp_device_env.h"
20#include "kmp_environment.h"
21#include "kmp_i18n.h"
22#include "kmp_io.h"
23#include "kmp_itt.h"
24#include "kmp_lock.h"
25#include "kmp_settings.h"
26#include "kmp_str.h"
27#include "kmp_traits.h"
28#include "kmp_wrapper_getpid.h"
29#include <ctype.h> // toupper()
30#if OMPD_SUPPORT
31#include "ompd-specific.h"
32#endif
33
34static int __kmp_env_toPrint(char const *name, int flag);
35
36bool __kmp_env_format = 0; // 0 - old format; 1 - new format
37
38// -----------------------------------------------------------------------------
39// Helper string functions. Subject to move to kmp_str.
40
41#ifdef USE_LOAD_BALANCE
42static double __kmp_convert_to_double(char const *s) {
43 double result;
44
45 if (KMP_SSCANF(s, "%lf", &result) < 1) {
46 result = 0.0;
47 }
48
49 return result;
50}
51#endif
52
53#ifdef KMP_DEBUG
54static unsigned int __kmp_readstr_with_sentinel(char *dest, char const *src,
55 size_t len, char sentinel) {
56 unsigned int i;
57 for (i = 0; i < len; i++) {
58 if ((*src == '\0') || (*src == sentinel)) {
59 break;
60 }
61 *(dest++) = *(src++);
62 }
63 *dest = '\0';
64 return i;
65}
66#endif
67
68static int __kmp_match_with_sentinel(char const *a, char const *b, size_t len,
69 char sentinel) {
70 size_t l = 0;
71
72 if (a == NULL)
73 a = "";
74 if (b == NULL)
75 b = "";
76 while (*a && *b && *b != sentinel) {
77 char ca = *a, cb = *b;
78
79 if (ca >= 'a' && ca <= 'z')
80 ca -= 'a' - 'A';
81 if (cb >= 'a' && cb <= 'z')
82 cb -= 'a' - 'A';
83 if (ca != cb)
84 return FALSE;
85 ++l;
86 ++a;
87 ++b;
88 }
89 return l >= len;
90}
91
92// Expected usage:
93// token is the token to check for.
94// buf is the string being parsed.
95// *end returns the char after the end of the token.
96// it is not modified unless a match occurs.
97//
98// Example 1:
99//
100// if (__kmp_match_str("token", buf, *end) {
101// <do something>
102// buf = end;
103// }
104//
105// Example 2:
106//
107// if (__kmp_match_str("token", buf, *end) {
108// char *save = **end;
109// **end = sentinel;
110// <use any of the __kmp*_with_sentinel() functions>
111// **end = save;
112// buf = end;
113// }
114
115static int __kmp_match_str(char const *token, char const *buf,
116 const char **end) {
117
118 KMP_ASSERT(token != NULL);
119 KMP_ASSERT(buf != NULL);
120 KMP_ASSERT(end != NULL);
121
122 while (*token && *buf) {
123 char ct = *token, cb = *buf;
124
125 if (ct >= 'a' && ct <= 'z')
126 ct -= 'a' - 'A';
127 if (cb >= 'a' && cb <= 'z')
128 cb -= 'a' - 'A';
129 if (ct != cb)
130 return FALSE;
131 ++token;
132 ++buf;
133 }
134 if (*token) {
135 return FALSE;
136 }
137 *end = buf;
138 return TRUE;
139}
140
141#if KMP_OS_DARWIN
142static size_t __kmp_round4k(size_t size) {
143 size_t _4k = 4 * 1024;
144 if (size & (_4k - 1)) {
145 size &= ~(_4k - 1);
146 if (size <= KMP_SIZE_T_MAX - _4k) {
147 size += _4k; // Round up if there is no overflow.
148 }
149 }
150 return size;
151} // __kmp_round4k
152#endif
153
154static int __kmp_strcasecmp_with_sentinel(char const *a, char const *b,
155 char sentinel) {
156 if (a == NULL)
157 a = "";
158 if (b == NULL)
159 b = "";
160 while (*a && *b && *b != sentinel) {
161 char ca = *a, cb = *b;
162
163 if (ca >= 'a' && ca <= 'z')
164 ca -= 'a' - 'A';
165 if (cb >= 'a' && cb <= 'z')
166 cb -= 'a' - 'A';
167 if (ca != cb)
168 return (int)(unsigned char)*a - (int)(unsigned char)*b;
169 ++a;
170 ++b;
171 }
172 return *a ? (*b && *b != sentinel)
173 ? (int)(unsigned char)*a - (int)(unsigned char)*b
174 : 1
175 : (*b && *b != sentinel) ? -1
176 : 0;
177}
178
179// =============================================================================
180// Table structures and helper functions.
181
182typedef struct __kmp_setting kmp_setting_t;
183typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
184typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
185typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
186
187typedef void (*kmp_stg_parse_func_t)(char const *name, char const *value,
188 void *data);
189typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer, char const *name,
190 void *data);
191
192struct __kmp_setting {
193 char const *name; // Name of setting (environment variable).
194 kmp_stg_parse_func_t parse; // Parser function.
195 kmp_stg_print_func_t print; // Print function.
196 void *data; // Data passed to parser and printer.
197 int set; // Variable set during this "session"
198 // (__kmp_env_initialize() or kmp_set_defaults() call).
199 int defined; // Variable set in any "session".
200}; // struct __kmp_setting
201
202struct __kmp_stg_ss_data {
203 size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
204 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
205}; // struct __kmp_stg_ss_data
206
207struct __kmp_stg_wp_data {
208 int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
209 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
210}; // struct __kmp_stg_wp_data
211
212struct __kmp_stg_fr_data {
213 int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
214 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
215}; // struct __kmp_stg_fr_data
216
217static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
218 char const *name, // Name of variable.
219 char const *value, // Value of the variable.
220 kmp_setting_t **rivals // List of rival settings (must include current one).
221);
222
223// Helper struct that trims heading/trailing white spaces
224struct kmp_trimmed_str_t {
225 kmp_str_buf_t buf;
226 kmp_trimmed_str_t(const char *str) {
227 __kmp_str_buf_init(&buf);
228 size_t len = KMP_STRLEN(str);
229 if (len == 0)
230 return;
231 const char *begin = str;
232 const char *end = str + KMP_STRLEN(str) - 1;
233 SKIP_WS(begin);
234 while (begin < end && *end == ' ')
235 end--;
236 __kmp_str_buf_cat(&buf, begin, end - begin + 1);
237 }
238 ~kmp_trimmed_str_t() { __kmp_str_buf_free(&buf); }
239 const char *get() { return buf.str; }
240};
241
242// -----------------------------------------------------------------------------
243// Helper parse functions.
244
245static void __kmp_stg_parse_bool(char const *name, char const *value,
246 int *out) {
247 if (__kmp_str_match_true(value)) {
248 *out = TRUE;
249 } else if (__kmp_str_match_false(value)) {
250 *out = FALSE;
251 } else {
252 __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
253 KMP_HNT(ValidBoolValues), __kmp_msg_null);
254 }
255} // __kmp_stg_parse_bool
256
257// placed here in order to use __kmp_round4k static function
258void __kmp_check_stksize(size_t *val) {
259 // if system stack size is too big then limit the size for worker threads
260#if KMP_OS_AIX
261 if (*val > KMP_DEFAULT_STKSIZE * 2) // Use 2 times, 16 is too large for AIX.
262 *val = KMP_DEFAULT_STKSIZE * 2;
263#else
264 if (*val > KMP_DEFAULT_STKSIZE * 16) // just a heuristics...
265 *val = KMP_DEFAULT_STKSIZE * 16;
266#endif
267 if (*val < __kmp_sys_min_stksize)
268 *val = __kmp_sys_min_stksize;
269 if (*val > KMP_MAX_STKSIZE)
270 *val = KMP_MAX_STKSIZE; // dead code currently, but may work in future
271#if KMP_OS_DARWIN
272 *val = __kmp_round4k(*val);
273#endif // KMP_OS_DARWIN
274}
275
276static void __kmp_stg_parse_size(char const *name, char const *value,
277 size_t size_min, size_t size_max,
278 int *is_specified, size_t *out,
279 size_t factor) {
280 char const *msg = NULL;
281#if KMP_OS_DARWIN
282 size_min = __kmp_round4k(size_min);
283 size_max = __kmp_round4k(size_max);
284#endif // KMP_OS_DARWIN
285 if (value) {
286 if (is_specified != NULL) {
287 *is_specified = 1;
288 }
289 __kmp_str_to_size(value, out, factor, &msg);
290 if (msg == NULL) {
291 if (*out > size_max) {
292 *out = size_max;
293 msg = KMP_I18N_STR(ValueTooLarge);
294 } else if (*out < size_min) {
295 *out = size_min;
296 msg = KMP_I18N_STR(ValueTooSmall);
297 } else {
298#if KMP_OS_DARWIN
299 size_t round4k = __kmp_round4k(*out);
300 if (*out != round4k) {
301 *out = round4k;
302 msg = KMP_I18N_STR(NotMultiple4K);
303 }
304#endif
305 }
306 } else {
307 // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to
308 // size_max silently.
309 if (*out < size_min) {
310 *out = size_max;
311 } else if (*out > size_max) {
312 *out = size_max;
313 }
314 }
315 if (msg != NULL) {
316 // Message is not empty. Print warning.
317 kmp_str_buf_t buf;
318 __kmp_str_buf_init(&buf);
319 __kmp_str_buf_print_size(&buf, *out);
320 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
321 KMP_INFORM(Using_str_Value, name, buf.str);
322 __kmp_str_buf_free(&buf);
323 }
324 }
325} // __kmp_stg_parse_size
326
327static void __kmp_stg_parse_str(char const *name, char const *value,
328 char **out) {
329 __kmp_str_free(out);
330 *out = __kmp_str_format("%s", value);
331} // __kmp_stg_parse_str
332
333static void __kmp_stg_parse_int(
334 char const
335 *name, // I: Name of environment variable (used in warning messages).
336 char const *value, // I: Value of environment variable to parse.
337 int min, // I: Minimum allowed value.
338 int max, // I: Maximum allowed value.
339 int *out // O: Output (parsed) value.
340) {
341 char const *msg = NULL;
342 kmp_uint64 uint = *out;
343 __kmp_str_to_uint(value, &uint, &msg);
344 if (msg == NULL) {
345 if (uint < (unsigned int)min) {
346 msg = KMP_I18N_STR(ValueTooSmall);
347 uint = min;
348 } else if (uint > (unsigned int)max) {
349 msg = KMP_I18N_STR(ValueTooLarge);
350 uint = max;
351 }
352 } else {
353 // If overflow occurred msg contains error message and uint is very big. Cut
354 // tmp it to INT_MAX.
355 if (uint < (unsigned int)min) {
356 uint = min;
357 } else if (uint > (unsigned int)max) {
358 uint = max;
359 }
360 }
361 if (msg != NULL) {
362 // Message is not empty. Print warning.
363 kmp_str_buf_t buf;
364 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
365 __kmp_str_buf_init(&buf);
366 __kmp_str_buf_print(&buf, "%" KMP_UINT64_SPEC "", uint);
367 KMP_INFORM(Using_uint64_Value, name, buf.str);
368 __kmp_str_buf_free(&buf);
369 }
370 __kmp_type_convert(uint, out);
371} // __kmp_stg_parse_int
372
373#if KMP_DEBUG_ADAPTIVE_LOCKS
374static void __kmp_stg_parse_file(char const *name, char const *value,
375 const char *suffix, char **out) {
376 char buffer[256];
377 char *t;
378 int hasSuffix;
379 __kmp_str_free(out);
380 t = (char *)strrchr(value, '.');
381 hasSuffix = t && __kmp_str_eqf(t, suffix);
382 t = __kmp_str_format("%s%s", value, hasSuffix ? "" : suffix);
383 __kmp_expand_file_name(buffer, sizeof(buffer), t);
384 __kmp_str_free(&t);
385 *out = __kmp_str_format("%s", buffer);
386} // __kmp_stg_parse_file
387#endif
388
389#ifdef KMP_DEBUG
390static char *par_range_to_print = NULL;
391
392static void __kmp_stg_parse_par_range(char const *name, char const *value,
393 int *out_range, char *out_routine,
394 char *out_file, int *out_lb,
395 int *out_ub) {
396 const char *par_range_value;
397 size_t len = KMP_STRLEN(value) + 1;
398 par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
399 KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
400 __kmp_par_range = +1;
401 __kmp_par_range_lb = 0;
402 __kmp_par_range_ub = INT_MAX;
403 for (;;) {
404 unsigned int len;
405 if (!value || *value == '\0') {
406 break;
407 }
408 if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
409 par_range_value = strchr(value, '=') + 1;
410 if (!par_range_value)
411 goto par_range_error;
412 value = par_range_value;
413 len = __kmp_readstr_with_sentinel(out_routine, value,
414 KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
415 if (len == 0) {
416 goto par_range_error;
417 }
418 value = strchr(value, ',');
419 if (value != NULL) {
420 value++;
421 }
422 continue;
423 }
424 if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
425 par_range_value = strchr(value, '=') + 1;
426 if (!par_range_value)
427 goto par_range_error;
428 value = par_range_value;
429 len = __kmp_readstr_with_sentinel(out_file, value,
430 KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
431 if (len == 0) {
432 goto par_range_error;
433 }
434 value = strchr(value, ',');
435 if (value != NULL) {
436 value++;
437 }
438 continue;
439 }
440 if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
441 (!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
442 par_range_value = strchr(value, '=') + 1;
443 if (!par_range_value)
444 goto par_range_error;
445 value = par_range_value;
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 par_range_value = strchr(value, '=') + 1;
458 if (!par_range_value)
459 goto par_range_error;
460 value = par_range_value;
461 if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
462 goto par_range_error;
463 }
464 *out_range = -1;
465 value = strchr(value, ',');
466 if (value != NULL) {
467 value++;
468 }
469 continue;
470 }
471 par_range_error:
472 KMP_WARNING(ParRangeSyntax, name);
473 __kmp_par_range = 0;
474 break;
475 }
476} // __kmp_stg_parse_par_range
477#endif
478
479int __kmp_initial_threads_capacity(int req_nproc) {
480 int nth = 32;
481
482 /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
483 * __kmp_max_nth) */
484 if (nth < (4 * req_nproc))
485 nth = (4 * req_nproc);
486 if (nth < (4 * __kmp_xproc))
487 nth = (4 * __kmp_xproc);
488
489 // If hidden helper task is enabled, we initialize the thread capacity with
490 // extra __kmp_hidden_helper_threads_num.
491 if (__kmp_enable_hidden_helper) {
492 nth += __kmp_hidden_helper_threads_num;
493 }
494
495 if (nth > __kmp_max_nth)
496 nth = __kmp_max_nth;
497
498 return nth;
499}
500
501int __kmp_default_tp_capacity(int req_nproc, int max_nth,
502 int all_threads_specified) {
503 int nth = 128;
504
505 if (all_threads_specified)
506 return max_nth;
507 /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
508 * __kmp_max_nth ) */
509 if (nth < (4 * req_nproc))
510 nth = (4 * req_nproc);
511 if (nth < (4 * __kmp_xproc))
512 nth = (4 * __kmp_xproc);
513
514 if (nth > __kmp_max_nth)
515 nth = __kmp_max_nth;
516
517 return nth;
518}
519
520// -----------------------------------------------------------------------------
521// Helper print functions.
522
523static void __kmp_stg_print_bool(kmp_str_buf_t *buffer, char const *name,
524 int value) {
525 if (__kmp_env_format) {
526 KMP_STR_BUF_PRINT_BOOL;
527 } else {
528 __kmp_str_buf_print(buffer, " %s=%s\n", name, value ? "true" : "false");
529 }
530} // __kmp_stg_print_bool
531
532static void __kmp_stg_print_int(kmp_str_buf_t *buffer, char const *name,
533 int value) {
534 if (__kmp_env_format) {
535 KMP_STR_BUF_PRINT_INT;
536 } else {
537 __kmp_str_buf_print(buffer, " %s=%d\n", name, value);
538 }
539} // __kmp_stg_print_int
540
541static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer, char const *name,
542 kmp_uint64 value) {
543 if (__kmp_env_format) {
544 KMP_STR_BUF_PRINT_UINT64;
545 } else {
546 __kmp_str_buf_print(buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value);
547 }
548} // __kmp_stg_print_uint64
549
550static void __kmp_stg_print_str(kmp_str_buf_t *buffer, char const *name,
551 char const *value) {
552 if (__kmp_env_format) {
553 KMP_STR_BUF_PRINT_STR;
554 } else {
555 __kmp_str_buf_print(buffer, " %s=%s\n", name, value);
556 }
557} // __kmp_stg_print_str
558
559static void __kmp_stg_print_size(kmp_str_buf_t *buffer, char const *name,
560 size_t value) {
561 if (__kmp_env_format) {
562 KMP_STR_BUF_PRINT_NAME_EX(name);
563 __kmp_str_buf_print_size(buffer, value);
564 __kmp_str_buf_print(buffer, "'\n");
565 } else {
566 __kmp_str_buf_print(buffer, " %s=", name);
567 __kmp_str_buf_print_size(buffer, value);
568 __kmp_str_buf_print(buffer, "\n");
569 return;
570 }
571} // __kmp_stg_print_size
572
573// =============================================================================
574// Parse and print functions.
575
576// -----------------------------------------------------------------------------
577// KMP_DEVICE_THREAD_LIMIT, KMP_ALL_THREADS
578
579static void __kmp_stg_parse_device_thread_limit(char const *name,
580 char const *value, void *data) {
581 kmp_setting_t **rivals = (kmp_setting_t **)data;
582 int rc;
583 if (strcmp(name, "KMP_ALL_THREADS") == 0) {
584 KMP_INFORM(EnvVarDeprecated, name, "KMP_DEVICE_THREAD_LIMIT");
585 }
586 rc = __kmp_stg_check_rivals(name, value, rivals);
587 if (rc) {
588 return;
589 }
590 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
591 __kmp_max_nth = __kmp_xproc;
592 __kmp_allThreadsSpecified = 1;
593 } else {
594 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
595 __kmp_allThreadsSpecified = 0;
596 }
597 K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));
598
599} // __kmp_stg_parse_device_thread_limit
600
601static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
602 char const *name, void *data) {
603 __kmp_stg_print_int(buffer, name, __kmp_max_nth);
604} // __kmp_stg_print_device_thread_limit
605
606// -----------------------------------------------------------------------------
607// OMP_THREAD_LIMIT
608static void __kmp_stg_parse_thread_limit(char const *name, char const *value,
609 void *data) {
610 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
611 K_DIAG(1, ("__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));
612
613} // __kmp_stg_parse_thread_limit
614
615static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
616 char const *name, void *data) {
617 __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
618} // __kmp_stg_print_thread_limit
619
620// -----------------------------------------------------------------------------
621// OMP_NUM_TEAMS
622static void __kmp_stg_parse_nteams(char const *name, char const *value,
623 void *data) {
624 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_nteams);
625 K_DIAG(1, ("__kmp_nteams == %d\n", __kmp_nteams));
626} // __kmp_stg_parse_nteams
627
628static void __kmp_stg_print_nteams(kmp_str_buf_t *buffer, char const *name,
629 void *data) {
630 __kmp_stg_print_int(buffer, name, __kmp_nteams);
631} // __kmp_stg_print_nteams
632
633// -----------------------------------------------------------------------------
634// OMP_TEAMS_THREAD_LIMIT
635static void __kmp_stg_parse_teams_th_limit(char const *name, char const *value,
636 void *data) {
637 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth,
638 &__kmp_teams_thread_limit);
639 K_DIAG(1, ("__kmp_teams_thread_limit == %d\n", __kmp_teams_thread_limit));
640} // __kmp_stg_parse_teams_th_limit
641
642static void __kmp_stg_print_teams_th_limit(kmp_str_buf_t *buffer,
643 char const *name, void *data) {
644 __kmp_stg_print_int(buffer, name, __kmp_teams_thread_limit);
645} // __kmp_stg_print_teams_th_limit
646
647// -----------------------------------------------------------------------------
648// KMP_TEAMS_THREAD_LIMIT
649static void __kmp_stg_parse_teams_thread_limit(char const *name,
650 char const *value, void *data) {
651 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
652} // __kmp_stg_teams_thread_limit
653
654static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
655 char const *name, void *data) {
656 __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
657} // __kmp_stg_print_teams_thread_limit
658
659// -----------------------------------------------------------------------------
660// KMP_USE_YIELD
661static void __kmp_stg_parse_use_yield(char const *name, char const *value,
662 void *data) {
663 __kmp_stg_parse_int(name, value, 0, 2, &__kmp_use_yield);
664 __kmp_use_yield_exp_set = 1;
665} // __kmp_stg_parse_use_yield
666
667static void __kmp_stg_print_use_yield(kmp_str_buf_t *buffer, char const *name,
668 void *data) {
669 __kmp_stg_print_int(buffer, name, __kmp_use_yield);
670} // __kmp_stg_print_use_yield
671
672// -----------------------------------------------------------------------------
673// KMP_BLOCKTIME
674
675static void __kmp_stg_parse_blocktime(char const *name, char const *value,
676 void *data) {
677 const char *buf = value;
678 const char *next;
679 const int ms_mult = 1000;
680 int multiplier = 1;
681 int num;
682
683 // Read integer blocktime value
684 SKIP_WS(buf);
685 if ((*buf >= '0') && (*buf <= '9')) {
686 next = buf;
687 SKIP_DIGITS(next);
688 num = __kmp_basic_str_to_int(buf);
689 KMP_ASSERT(num >= 0);
690 buf = next;
691 SKIP_WS(buf);
692 } else {
693 num = -1;
694 }
695
696 // Read units: note that __kmp_dflt_blocktime units is now us
697 next = buf;
698 if (*buf == '\0' || __kmp_match_str("ms", buf, &next)) {
699 // units are in ms; convert
700 __kmp_dflt_blocktime = ms_mult * num;
701 __kmp_blocktime_units = 'm';
702 multiplier = ms_mult;
703 } else if (__kmp_match_str("us", buf, &next)) {
704 // units are in us
705 __kmp_dflt_blocktime = num;
706 __kmp_blocktime_units = 'u';
707 } else if (__kmp_match_str("infinite", buf, &next) ||
708 __kmp_match_str("infinity", buf, &next)) {
709 // units are in ms
710 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
711 __kmp_blocktime_units = 'm';
712 multiplier = ms_mult;
713 } else {
714 KMP_WARNING(StgInvalidValue, name, value);
715 // default units are in ms
716 __kmp_dflt_blocktime = ms_mult * num;
717 __kmp_blocktime_units = 'm';
718 multiplier = ms_mult;
719 }
720
721 if (num < 0 && __kmp_dflt_blocktime < 0) { // num out of range
722 __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME; // now in us
723 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
724 __kmp_msg_null);
725 // Inform in appropriate units
726 KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime / multiplier);
727 __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
728 } else if (num > 0 && __kmp_dflt_blocktime < 0) { // overflow
729 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
730 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value), __kmp_msg_null);
731 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime / multiplier);
732 __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
733 } else {
734 if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
735 __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
736 __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
737 __kmp_msg_null);
738 KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime / multiplier);
739 } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
740 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
741 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
742 __kmp_msg_null);
743 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime / multiplier);
744 }
745 __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
746 }
747#if KMP_USE_MONITOR
748 // calculate number of monitor thread wakeup intervals corresponding to
749 // blocktime.
750 __kmp_monitor_wakeups =
751 KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
752 __kmp_bt_intervals =
753 KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
754#endif
755 K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
756 if (__kmp_env_blocktime) {
757 K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
758 }
759} // __kmp_stg_parse_blocktime
760
761static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
762 void *data) {
763 int num = __kmp_dflt_blocktime;
764 if (__kmp_blocktime_units == 'm') {
765 num = num / 1000;
766 }
767 if (__kmp_env_format) {
768 KMP_STR_BUF_PRINT_NAME_EX(name);
769 } else {
770 __kmp_str_buf_print(buffer, " %s=", name);
771 }
772 __kmp_str_buf_print(buffer, "%d", num);
773 __kmp_str_buf_print(buffer, "%cs\n", __kmp_blocktime_units);
774} // __kmp_stg_print_blocktime
775
776// -----------------------------------------------------------------------------
777// KMP_DUPLICATE_LIB_OK
778
779static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
780 char const *value, void *data) {
781 /* actually this variable is not supported, put here for compatibility with
782 earlier builds and for static/dynamic combination */
783 __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
784} // __kmp_stg_parse_duplicate_lib_ok
785
786static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
787 char const *name, void *data) {
788 __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
789} // __kmp_stg_print_duplicate_lib_ok
790
791// -----------------------------------------------------------------------------
792// KMP_INHERIT_FP_CONTROL
793
794#if KMP_ARCH_X86 || KMP_ARCH_X86_64
795
796static void __kmp_stg_parse_inherit_fp_control(char const *name,
797 char const *value, void *data) {
798 __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
799} // __kmp_stg_parse_inherit_fp_control
800
801static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
802 char const *name, void *data) {
803#if KMP_DEBUG
804 __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
805#endif /* KMP_DEBUG */
806} // __kmp_stg_print_inherit_fp_control
807
808#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
809
810// Used for OMP_WAIT_POLICY
811static char const *blocktime_str = NULL;
812static char const *use_yield_str = NULL;
813
814// -----------------------------------------------------------------------------
815// KMP_LIBRARY, OMP_WAIT_POLICY
816
817static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
818 void *data) {
819
820 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
821 int rc;
822
823 rc = __kmp_stg_check_rivals(name, value, wait->rivals);
824 if (rc) {
825 return;
826 }
827
828 if (wait->omp) {
829 if (__kmp_str_match("ACTIVE", 1, value)) {
830 __kmp_library = library_turnaround;
831 if (blocktime_str == NULL) {
832 // KMP_BLOCKTIME not specified, so set default to "infinite".
833 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
834 }
835 if (use_yield_str == NULL) {
836 // KMP_USE_YIELD not specified, so set default to 2.
837 __kmp_use_yield = 2;
838 }
839 } else if (__kmp_str_match("PASSIVE", 1, value)) {
840 __kmp_library = library_throughput;
841 __kmp_wpolicy_passive = true; /* allow sleep while active tasking */
842 if (blocktime_str == NULL) {
843 // KMP_BLOCKTIME not specified, so set default to 0.
844 __kmp_dflt_blocktime = 0;
845 }
846 } else {
847 KMP_WARNING(StgInvalidValue, name, value);
848 }
849 } else {
850 if (__kmp_str_match("serial", 1, value)) { /* S */
851 __kmp_library = library_serial;
852 } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
853 __kmp_library = library_throughput;
854 if (blocktime_str == NULL) {
855 // KMP_BLOCKTIME not specified, so set default to 0.
856 __kmp_dflt_blocktime = 0;
857 }
858 } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
859 __kmp_library = library_turnaround;
860 } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
861 __kmp_library = library_turnaround;
862 } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
863 __kmp_library = library_throughput;
864 if (blocktime_str == NULL) {
865 // KMP_BLOCKTIME not specified, so set default to 0.
866 __kmp_dflt_blocktime = 0;
867 }
868 } else {
869 KMP_WARNING(StgInvalidValue, name, value);
870 }
871 }
872} // __kmp_stg_parse_wait_policy
873
874static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
875 void *data) {
876
877 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
878 char const *value = NULL;
879
880 if (wait->omp) {
881 switch (__kmp_library) {
882 case library_turnaround: {
883 value = "ACTIVE";
884 } break;
885 case library_throughput: {
886 value = "PASSIVE";
887 } break;
888 case library_none:
889 case library_serial: {
890 value = NULL;
891 } break;
892 }
893 } else {
894 switch (__kmp_library) {
895 case library_serial: {
896 value = "serial";
897 } break;
898 case library_turnaround: {
899 value = "turnaround";
900 } break;
901 case library_throughput: {
902 value = "throughput";
903 } break;
904 case library_none: {
905 value = NULL;
906 } break;
907 }
908 }
909 if (value != NULL) {
910 __kmp_stg_print_str(buffer, name, value);
911 }
912
913} // __kmp_stg_print_wait_policy
914
915#if KMP_USE_MONITOR
916// -----------------------------------------------------------------------------
917// KMP_MONITOR_STACKSIZE
918
919static void __kmp_stg_parse_monitor_stacksize(char const *name,
920 char const *value, void *data) {
921 __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
922 NULL, &__kmp_monitor_stksize, 1);
923} // __kmp_stg_parse_monitor_stacksize
924
925static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
926 char const *name, void *data) {
927 if (__kmp_env_format) {
928 if (__kmp_monitor_stksize > 0)
929 KMP_STR_BUF_PRINT_NAME_EX(name);
930 else
931 KMP_STR_BUF_PRINT_NAME;
932 } else {
933 __kmp_str_buf_print(buffer, " %s", name);
934 }
935 if (__kmp_monitor_stksize > 0) {
936 __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
937 } else {
938 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
939 }
940 if (__kmp_env_format && __kmp_monitor_stksize) {
941 __kmp_str_buf_print(buffer, "'\n");
942 }
943} // __kmp_stg_print_monitor_stacksize
944#endif // KMP_USE_MONITOR
945
946// -----------------------------------------------------------------------------
947// KMP_SETTINGS
948
949static void __kmp_stg_parse_settings(char const *name, char const *value,
950 void *data) {
951 __kmp_stg_parse_bool(name, value, &__kmp_settings);
952} // __kmp_stg_parse_settings
953
954static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
955 void *data) {
956 __kmp_stg_print_bool(buffer, name, __kmp_settings);
957} // __kmp_stg_print_settings
958
959// -----------------------------------------------------------------------------
960// KMP_STACKPAD
961
962static void __kmp_stg_parse_stackpad(char const *name, char const *value,
963 void *data) {
964 __kmp_stg_parse_int(name, // Env var name
965 value, // Env var value
966 KMP_MIN_STKPADDING, // Min value
967 KMP_MAX_STKPADDING, // Max value
968 &__kmp_stkpadding // Var to initialize
969 );
970} // __kmp_stg_parse_stackpad
971
972static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
973 void *data) {
974 __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
975} // __kmp_stg_print_stackpad
976
977// -----------------------------------------------------------------------------
978// KMP_STACKOFFSET
979
980static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
981 void *data) {
982 __kmp_stg_parse_size(name, // Env var name
983 value, // Env var value
984 KMP_MIN_STKOFFSET, // Min value
985 KMP_MAX_STKOFFSET, // Max value
986 NULL, //
987 &__kmp_stkoffset, // Var to initialize
988 1);
989} // __kmp_stg_parse_stackoffset
990
991static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
992 void *data) {
993 __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
994} // __kmp_stg_print_stackoffset
995
996// -----------------------------------------------------------------------------
997// KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
998
999static void __kmp_stg_parse_stacksize(char const *name, char const *value,
1000 void *data) {
1001
1002 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
1003 int rc;
1004
1005 rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
1006 if (rc) {
1007 return;
1008 }
1009 __kmp_stg_parse_size(name, // Env var name
1010 value, // Env var value
1011 __kmp_sys_min_stksize, // Min value
1012 KMP_MAX_STKSIZE, // Max value
1013 &__kmp_env_stksize, //
1014 &__kmp_stksize, // Var to initialize
1015 stacksize->factor);
1016
1017} // __kmp_stg_parse_stacksize
1018
1019// This function is called for printing both KMP_STACKSIZE (factor is 1) and
1020// OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
1021// OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
1022// customer request in future.
1023static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
1024 void *data) {
1025 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
1026 if (__kmp_env_format) {
1027 KMP_STR_BUF_PRINT_NAME_EX(name);
1028 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
1029 ? __kmp_stksize / stacksize->factor
1030 : __kmp_stksize);
1031 __kmp_str_buf_print(buffer, "'\n");
1032 } else {
1033 __kmp_str_buf_print(buffer, " %s=", name);
1034 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
1035 ? __kmp_stksize / stacksize->factor
1036 : __kmp_stksize);
1037 __kmp_str_buf_print(buffer, "\n");
1038 }
1039} // __kmp_stg_print_stacksize
1040
1041// -----------------------------------------------------------------------------
1042// KMP_VERSION
1043
1044static void __kmp_stg_parse_version(char const *name, char const *value,
1045 void *data) {
1046 __kmp_stg_parse_bool(name, value, &__kmp_version);
1047} // __kmp_stg_parse_version
1048
1049static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
1050 void *data) {
1051 __kmp_stg_print_bool(buffer, name, __kmp_version);
1052} // __kmp_stg_print_version
1053
1054// -----------------------------------------------------------------------------
1055// KMP_WARNINGS
1056
1057static void __kmp_stg_parse_warnings(char const *name, char const *value,
1058 void *data) {
1059 __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
1060 if (__kmp_generate_warnings != kmp_warnings_off) {
1061 // AC: only 0/1 values documented, so reset to explicit to distinguish from
1062 // default setting
1063 __kmp_generate_warnings = kmp_warnings_explicit;
1064 }
1065} // __kmp_stg_parse_warnings
1066
1067static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
1068 void *data) {
1069 // AC: TODO: change to print_int? (needs documentation change)
1070 __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
1071} // __kmp_stg_print_warnings
1072
1073// -----------------------------------------------------------------------------
1074// KMP_NESTING_MODE
1075
1076static void __kmp_stg_parse_nesting_mode(char const *name, char const *value,
1077 void *data) {
1078 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_nesting_mode);
1079#if KMP_HWLOC_ENABLED
1080 if (__kmp_nesting_mode > 0)
1081 __kmp_affinity_top_method = affinity_top_method_hwloc;
1082#endif // KMP_HWLOC_ENABLED
1083} // __kmp_stg_parse_nesting_mode
1084
1085static void __kmp_stg_print_nesting_mode(kmp_str_buf_t *buffer,
1086 char const *name, void *data) {
1087 if (__kmp_env_format) {
1088 KMP_STR_BUF_PRINT_NAME;
1089 } else {
1090 __kmp_str_buf_print(buffer, " %s", name);
1091 }
1092 __kmp_str_buf_print(buffer, "=%d\n", __kmp_nesting_mode);
1093} // __kmp_stg_print_nesting_mode
1094
1095// -----------------------------------------------------------------------------
1096// OMP_NESTED, OMP_NUM_THREADS
1097
1098static void __kmp_stg_parse_nested(char const *name, char const *value,
1099 void *data) {
1100 int nested;
1101 KMP_INFORM(EnvVarDeprecated, name, "OMP_MAX_ACTIVE_LEVELS");
1102 __kmp_stg_parse_bool(name, value, &nested);
1103 if (nested) {
1104 if (!__kmp_dflt_max_active_levels_set)
1105 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1106 } else { // nesting explicitly turned off
1107 __kmp_dflt_max_active_levels = 1;
1108 __kmp_dflt_max_active_levels_set = true;
1109 }
1110} // __kmp_stg_parse_nested
1111
1112static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
1113 void *data) {
1114 if (__kmp_env_format) {
1115 KMP_STR_BUF_PRINT_NAME;
1116 } else {
1117 __kmp_str_buf_print(buffer, " %s", name);
1118 }
1119 __kmp_str_buf_print(buffer, ": deprecated; max-active-levels-var=%d\n",
1120 __kmp_dflt_max_active_levels);
1121} // __kmp_stg_print_nested
1122
1123static void __kmp_parse_nested_num_threads(const char *var, const char *env,
1124 kmp_nested_nthreads_t *nth_array) {
1125 const char *next = env;
1126 const char *scan = next;
1127
1128 int total = 0; // Count elements that were set. It'll be used as an array size
1129 int prev_comma = FALSE; // For correct processing sequential commas
1130
1131 // Count the number of values in the env. var string
1132 for (;;) {
1133 SKIP_WS(next);
1134
1135 if (*next == '\0') {
1136 break;
1137 }
1138 // Next character is not an integer or not a comma => end of list
1139 if (((*next < '0') || (*next > '9')) && (*next != ',')) {
1140 KMP_WARNING(NthSyntaxError, var, env);
1141 return;
1142 }
1143 // The next character is ','
1144 if (*next == ',') {
1145 // ',' is the first character
1146 if (total == 0 || prev_comma) {
1147 total++;
1148 }
1149 prev_comma = TRUE;
1150 next++; // skip ','
1151 SKIP_WS(next);
1152 }
1153 // Next character is a digit
1154 if (*next >= '0' && *next <= '9') {
1155 prev_comma = FALSE;
1156 SKIP_DIGITS(next);
1157 total++;
1158 const char *tmp = next;
1159 SKIP_WS(tmp);
1160 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
1161 KMP_WARNING(NthSpacesNotAllowed, var, env);
1162 return;
1163 }
1164 }
1165 }
1166 if (!__kmp_dflt_max_active_levels_set && total > 1)
1167 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1168 if (total <= 0) {
1169 KMP_WARNING(NthSyntaxError, var, env);
1170 return;
1171 }
1172
1173 // Check if the nested nthreads array exists
1174 if (!nth_array->nth) {
1175 // Allocate an array of double size
1176 nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
1177 if (nth_array->nth == NULL) {
1178 KMP_FATAL(MemoryAllocFailed);
1179 }
1180 nth_array->size = total * 2;
1181 } else {
1182 if (nth_array->size < total) {
1183 // Increase the array size
1184 do {
1185 nth_array->size *= 2;
1186 } while (nth_array->size < total);
1187
1188 nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
1189 nth_array->nth, sizeof(int) * nth_array->size);
1190 if (nth_array->nth == NULL) {
1191 KMP_FATAL(MemoryAllocFailed);
1192 }
1193 }
1194 }
1195 nth_array->used = total;
1196 int i = 0;
1197
1198 prev_comma = FALSE;
1199 total = 0;
1200 // Save values in the array
1201 for (;;) {
1202 SKIP_WS(scan);
1203 if (*scan == '\0') {
1204 break;
1205 }
1206 // The next character is ','
1207 if (*scan == ',') {
1208 // ',' in the beginning of the list
1209 if (total == 0) {
1210 // The value is supposed to be equal to __kmp_avail_proc but it is
1211 // unknown at the moment.
1212 // So let's put a placeholder (#threads = 0) to correct it later.
1213 nth_array->nth[i++] = 0;
1214 total++;
1215 } else if (prev_comma) {
1216 // Num threads is inherited from the previous level
1217 nth_array->nth[i] = nth_array->nth[i - 1];
1218 i++;
1219 total++;
1220 }
1221 prev_comma = TRUE;
1222 scan++; // skip ','
1223 SKIP_WS(scan);
1224 }
1225 // Next character is a digit
1226 if (*scan >= '0' && *scan <= '9') {
1227 int num;
1228 const char *buf = scan;
1229 char const *msg = NULL;
1230 prev_comma = FALSE;
1231 SKIP_DIGITS(scan);
1232 total++;
1233
1234 num = __kmp_str_to_int(buf, *scan);
1235 if (num < KMP_MIN_NTH) {
1236 msg = KMP_I18N_STR(ValueTooSmall);
1237 num = KMP_MIN_NTH;
1238 } else if (num > __kmp_sys_max_nth) {
1239 msg = KMP_I18N_STR(ValueTooLarge);
1240 num = __kmp_sys_max_nth;
1241 }
1242 if (msg != NULL) {
1243 // Message is not empty. Print warning.
1244 KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1245 KMP_INFORM(Using_int_Value, var, num);
1246 }
1247 nth_array->nth[i++] = num;
1248 }
1249 }
1250}
1251
1252static void __kmp_stg_parse_num_threads(char const *name, char const *value,
1253 void *data) {
1254 // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
1255 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
1256 // The array of 1 element
1257 if (!__kmp_nested_nth.nth) {
1258 __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
1259 __kmp_nested_nth.size = 1;
1260 }
1261 __kmp_nested_nth.used = 1;
1262 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1263 __kmp_xproc;
1264 } else {
1265 __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1266 if (__kmp_nested_nth.nth) {
1267 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1268 if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1269 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1270 }
1271 }
1272 }
1273 K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
1274} // __kmp_stg_parse_num_threads
1275
1276static void __kmp_stg_parse_num_hidden_helper_threads(char const *name,
1277 char const *value,
1278 void *data) {
1279 __kmp_stg_parse_int(name, value, 0, 16, &__kmp_hidden_helper_threads_num);
1280 // If the number of hidden helper threads is zero, we disable hidden helper
1281 // task
1282 if (__kmp_hidden_helper_threads_num == 0) {
1283 __kmp_enable_hidden_helper = FALSE;
1284 } else {
1285 // Since the main thread of hidden helper team does not participate
1286 // in tasks execution let's increment the number of threads by one
1287 // so that requested number of threads do actual job.
1288 __kmp_hidden_helper_threads_num++;
1289 }
1290} // __kmp_stg_parse_num_hidden_helper_threads
1291
1292static void __kmp_stg_print_num_hidden_helper_threads(kmp_str_buf_t *buffer,
1293 char const *name,
1294 void *data) {
1295 if (__kmp_hidden_helper_threads_num == 0) {
1296 __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num);
1297 } else {
1298 KMP_DEBUG_ASSERT(__kmp_hidden_helper_threads_num > 1);
1299 // Let's exclude the main thread of hidden helper team and print
1300 // number of worker threads those do actual job.
1301 __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num - 1);
1302 }
1303} // __kmp_stg_print_num_hidden_helper_threads
1304
1305static void __kmp_stg_parse_use_hidden_helper(char const *name,
1306 char const *value, void *data) {
1307 __kmp_stg_parse_bool(name, value, &__kmp_enable_hidden_helper);
1308#if !KMP_OS_LINUX
1309 __kmp_enable_hidden_helper = FALSE;
1310 K_DIAG(1,
1311 ("__kmp_stg_parse_use_hidden_helper: Disable hidden helper task on "
1312 "non-Linux platform although it is enabled by user explicitly.\n"));
1313#endif
1314} // __kmp_stg_parse_use_hidden_helper
1315
1316static void __kmp_stg_print_use_hidden_helper(kmp_str_buf_t *buffer,
1317 char const *name, void *data) {
1318 __kmp_stg_print_bool(buffer, name, __kmp_enable_hidden_helper);
1319} // __kmp_stg_print_use_hidden_helper
1320
1321static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
1322 void *data) {
1323 if (__kmp_env_format) {
1324 KMP_STR_BUF_PRINT_NAME;
1325 } else {
1326 __kmp_str_buf_print(buffer, " %s", name);
1327 }
1328 if (__kmp_nested_nth.used) {
1329 kmp_str_buf_t buf;
1330 __kmp_str_buf_init(&buf);
1331 for (int i = 0; i < __kmp_nested_nth.used; i++) {
1332 __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
1333 if (i < __kmp_nested_nth.used - 1) {
1334 __kmp_str_buf_print(&buf, ",");
1335 }
1336 }
1337 __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
1338 __kmp_str_buf_free(&buf);
1339 } else {
1340 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1341 }
1342} // __kmp_stg_print_num_threads
1343
1344// -----------------------------------------------------------------------------
1345// OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
1346
1347static void __kmp_stg_parse_tasking(char const *name, char const *value,
1348 void *data) {
1349 __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
1350 (int *)&__kmp_tasking_mode);
1351 // KMP_TASKING=1 (task barrier) doesn't work anymore, change to task_teams (2)
1352 if (__kmp_tasking_mode == tskm_extra_barrier) {
1353 KMP_WARNING(StgInvalidValue, name, value);
1354 __kmp_tasking_mode = tskm_task_teams;
1355 }
1356} // __kmp_stg_parse_tasking
1357
1358static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
1359 void *data) {
1360 __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
1361} // __kmp_stg_print_tasking
1362
1363static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
1364 void *data) {
1365 __kmp_stg_parse_int(name, value, 0, 1,
1366 (int *)&__kmp_task_stealing_constraint);
1367} // __kmp_stg_parse_task_stealing
1368
1369static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1370 char const *name, void *data) {
1371 __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
1372} // __kmp_stg_print_task_stealing
1373
1374static void __kmp_stg_parse_max_active_levels(char const *name,
1375 char const *value, void *data) {
1376 kmp_uint64 tmp_dflt = 0;
1377 char const *msg = NULL;
1378 if (!__kmp_dflt_max_active_levels_set) {
1379 // Don't overwrite __kmp_dflt_max_active_levels if we get an invalid setting
1380 __kmp_str_to_uint(value, &tmp_dflt, &msg);
1381 if (msg != NULL) { // invalid setting; print warning and ignore
1382 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1383 } else if (tmp_dflt > KMP_MAX_ACTIVE_LEVELS_LIMIT) {
1384 // invalid setting; print warning and ignore
1385 msg = KMP_I18N_STR(ValueTooLarge);
1386 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1387 } else { // valid setting
1388 __kmp_type_convert(tmp_dflt, &(__kmp_dflt_max_active_levels));
1389 __kmp_dflt_max_active_levels_set = true;
1390 }
1391 }
1392} // __kmp_stg_parse_max_active_levels
1393
1394static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1395 char const *name, void *data) {
1396 __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
1397} // __kmp_stg_print_max_active_levels
1398
1399// -----------------------------------------------------------------------------
1400// OpenMP 4.0: OMP_DEFAULT_DEVICE
1401static void __kmp_stg_parse_default_device(char const *name, char const *value,
1402 void *data) {
1403 __kmp_default_device = kmp_trait_context::parse_single_device(
1404 value, /*device_num_min=*/0, KMP_MAX_DEFAULT_DEVICE_LIMIT, name);
1405} // __kmp_stg_parse_default_device
1406
1407static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1408 char const *name, void *data) {
1409 __kmp_stg_print_int(buffer, name, __kmp_default_device);
1410} // __kmp_stg_print_default_device
1411
1412// -----------------------------------------------------------------------------
1413// OpenMP 5.0: OMP_TARGET_OFFLOAD
1414static void __kmp_stg_parse_target_offload(char const *name, char const *value,
1415 void *data) {
1416 kmp_trimmed_str_t value_str(value);
1417 const char *scan = value_str.get();
1418 __kmp_target_offload = tgt_default;
1419
1420 if (*scan == '\0')
1421 return;
1422
1423 if (!__kmp_strcasecmp_with_sentinel("mandatory", scan, 0)) {
1424 __kmp_target_offload = tgt_mandatory;
1425 } else if (!__kmp_strcasecmp_with_sentinel("disabled", scan, 0)) {
1426 __kmp_target_offload = tgt_disabled;
1427 } else if (!__kmp_strcasecmp_with_sentinel("default", scan, 0)) {
1428 __kmp_target_offload = tgt_default;
1429 } else {
1430 KMP_WARNING(SyntaxErrorUsing, name, "DEFAULT");
1431 }
1432} // __kmp_stg_parse_target_offload
1433
1434static void __kmp_stg_print_target_offload(kmp_str_buf_t *buffer,
1435 char const *name, void *data) {
1436 const char *value = NULL;
1437 if (__kmp_target_offload == tgt_default)
1438 value = "DEFAULT";
1439 else if (__kmp_target_offload == tgt_mandatory)
1440 value = "MANDATORY";
1441 else if (__kmp_target_offload == tgt_disabled)
1442 value = "DISABLED";
1443 KMP_DEBUG_ASSERT(value);
1444 if (__kmp_env_format) {
1445 KMP_STR_BUF_PRINT_NAME;
1446 } else {
1447 __kmp_str_buf_print(buffer, " %s", name);
1448 }
1449 __kmp_str_buf_print(buffer, "=%s\n", value);
1450} // __kmp_stg_print_target_offload
1451
1452// -----------------------------------------------------------------------------
1453// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
1454static void __kmp_stg_parse_max_task_priority(char const *name,
1455 char const *value, void *data) {
1456 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1457 &__kmp_max_task_priority);
1458} // __kmp_stg_parse_max_task_priority
1459
1460static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1461 char const *name, void *data) {
1462 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
1463} // __kmp_stg_print_max_task_priority
1464
1465// KMP_TASKLOOP_MIN_TASKS
1466// taskloop threshold to switch from recursive to linear tasks creation
1467static void __kmp_stg_parse_taskloop_min_tasks(char const *name,
1468 char const *value, void *data) {
1469 int tmp = 0;
1470 __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1471 __kmp_taskloop_min_tasks = tmp;
1472} // __kmp_stg_parse_taskloop_min_tasks
1473
1474static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
1475 char const *name, void *data) {
1476 __kmp_stg_print_uint64(buffer, name, __kmp_taskloop_min_tasks);
1477} // __kmp_stg_print_taskloop_min_tasks
1478
1479// -----------------------------------------------------------------------------
1480// KMP_DISP_NUM_BUFFERS
1481static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
1482 void *data) {
1483 if (TCR_4(__kmp_init_serial)) {
1484 KMP_WARNING(EnvSerialWarn, name);
1485 return;
1486 } // read value before serial initialization only
1487 __kmp_stg_parse_int(name, value, KMP_MIN_DISP_NUM_BUFF, KMP_MAX_DISP_NUM_BUFF,
1488 &__kmp_dispatch_num_buffers);
1489} // __kmp_stg_parse_disp_buffers
1490
1491static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1492 char const *name, void *data) {
1493 __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
1494} // __kmp_stg_print_disp_buffers
1495
1496// -----------------------------------------------------------------------------
1497// KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
1498
1499static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
1500 void *data) {
1501 if (TCR_4(__kmp_init_parallel)) {
1502 KMP_WARNING(EnvParallelWarn, name);
1503 return;
1504 } // read value before first parallel only
1505 __kmp_stg_parse_int(name, value, 0, 1024, &__kmp_hot_teams_max_level);
1506
1507} // __kmp_stg_parse_hot_teams_level
1508
1509static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1510 char const *name, void *data) {
1511 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
1512} // __kmp_stg_print_hot_teams_level
1513
1514static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
1515 void *data) {
1516 if (TCR_4(__kmp_init_parallel)) {
1517 KMP_WARNING(EnvParallelWarn, name);
1518 return;
1519 } // read value before first parallel only
1520 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1521 &__kmp_hot_teams_mode);
1522} // __kmp_stg_parse_hot_teams_mode
1523
1524static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1525 char const *name, void *data) {
1526 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
1527} // __kmp_stg_print_hot_teams_mode
1528
1529// -----------------------------------------------------------------------------
1530// KMP_HANDLE_SIGNALS
1531
1532#if KMP_HANDLE_SIGNALS
1533
1534static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
1535 void *data) {
1536 __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
1537} // __kmp_stg_parse_handle_signals
1538
1539static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1540 char const *name, void *data) {
1541 __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
1542} // __kmp_stg_print_handle_signals
1543
1544#endif // KMP_HANDLE_SIGNALS
1545
1546// -----------------------------------------------------------------------------
1547// KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
1548
1549#ifdef KMP_DEBUG
1550
1551#define KMP_STG_X_DEBUG(x) \
1552 static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1553 void *data) { \
1554 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1555 } /* __kmp_stg_parse_x_debug */ \
1556 static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1557 char const *name, void *data) { \
1558 __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1559 } /* __kmp_stg_print_x_debug */
1560
1561KMP_STG_X_DEBUG(a)
1562KMP_STG_X_DEBUG(b)
1563KMP_STG_X_DEBUG(c)
1564KMP_STG_X_DEBUG(d)
1565KMP_STG_X_DEBUG(e)
1566KMP_STG_X_DEBUG(f)
1567
1568#undef KMP_STG_X_DEBUG
1569
1570static void __kmp_stg_parse_debug(char const *name, char const *value,
1571 void *data) {
1572 int debug = 0;
1573 __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1574 if (kmp_a_debug < debug) {
1575 kmp_a_debug = debug;
1576 }
1577 if (kmp_b_debug < debug) {
1578 kmp_b_debug = debug;
1579 }
1580 if (kmp_c_debug < debug) {
1581 kmp_c_debug = debug;
1582 }
1583 if (kmp_d_debug < debug) {
1584 kmp_d_debug = debug;
1585 }
1586 if (kmp_e_debug < debug) {
1587 kmp_e_debug = debug;
1588 }
1589 if (kmp_f_debug < debug) {
1590 kmp_f_debug = debug;
1591 }
1592} // __kmp_stg_parse_debug
1593
1594static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
1595 void *data) {
1596 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1597 // !!! TODO: Move buffer initialization of this file! It may works
1598 // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
1599 // KMP_DEBUG_BUF_CHARS.
1600 if (__kmp_debug_buf) {
1601 int i;
1602 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
1603
1604 /* allocate and initialize all entries in debug buffer to empty */
1605 __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
1606 for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1607 __kmp_debug_buffer[i] = '\0';
1608
1609 __kmp_debug_count = 0;
1610 }
1611 K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
1612} // __kmp_stg_parse_debug_buf
1613
1614static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
1615 void *data) {
1616 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
1617} // __kmp_stg_print_debug_buf
1618
1619static void __kmp_stg_parse_debug_buf_atomic(char const *name,
1620 char const *value, void *data) {
1621 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
1622} // __kmp_stg_parse_debug_buf_atomic
1623
1624static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1625 char const *name, void *data) {
1626 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
1627} // __kmp_stg_print_debug_buf_atomic
1628
1629static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
1630 void *data) {
1631 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1632 &__kmp_debug_buf_chars);
1633} // __kmp_stg_debug_parse_buf_chars
1634
1635static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1636 char const *name, void *data) {
1637 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
1638} // __kmp_stg_print_debug_buf_chars
1639
1640static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
1641 void *data) {
1642 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1643 &__kmp_debug_buf_lines);
1644} // __kmp_stg_parse_debug_buf_lines
1645
1646static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1647 char const *name, void *data) {
1648 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
1649} // __kmp_stg_print_debug_buf_lines
1650
1651static void __kmp_stg_parse_diag(char const *name, char const *value,
1652 void *data) {
1653 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
1654} // __kmp_stg_parse_diag
1655
1656static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
1657 void *data) {
1658 __kmp_stg_print_int(buffer, name, kmp_diag);
1659} // __kmp_stg_print_diag
1660
1661#endif // KMP_DEBUG
1662
1663// -----------------------------------------------------------------------------
1664// KMP_ALIGN_ALLOC
1665
1666static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
1667 void *data) {
1668 __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1669 &__kmp_align_alloc, 1);
1670 // Must be power of 2
1671 if (__kmp_align_alloc == 0 || ((__kmp_align_alloc - 1) & __kmp_align_alloc)) {
1672 KMP_WARNING(StgInvalidValue, name, value);
1673 __kmp_align_alloc = CACHE_LINE;
1674 }
1675} // __kmp_stg_parse_align_alloc
1676
1677static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
1678 void *data) {
1679 __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
1680} // __kmp_stg_print_align_alloc
1681
1682// -----------------------------------------------------------------------------
1683// KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
1684
1685// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
1686// parse and print functions, pass required info through data argument.
1687
1688static void __kmp_stg_parse_barrier_branch_bit(char const *name,
1689 char const *value, void *data) {
1690 const char *var;
1691
1692 /* ---------- Barrier branch bit control ------------ */
1693 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1694 var = __kmp_barrier_branch_bit_env_name[i];
1695 if ((strcmp(var, name) == 0) && (value != 0)) {
1696 char *comma;
1697
1698 comma = CCAST(char *, strchr(value, ','));
1699 __kmp_barrier_gather_branch_bits[i] =
1700 (kmp_uint32)__kmp_str_to_int(value, ',');
1701 /* is there a specified release parameter? */
1702 if (comma == NULL) {
1703 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1704 } else {
1705 __kmp_barrier_release_branch_bits[i] =
1706 (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
1707 if (__kmp_barrier_release_branch_bits[i] == 0 ||
1708 __kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1709 __kmp_msg(kmp_ms_warning,
1710 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1711 __kmp_msg_null);
1712 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1713 }
1714 }
1715 if (__kmp_barrier_gather_branch_bits[i] == 0 ||
1716 __kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1717 KMP_WARNING(BarrGatherValueInvalid, name, value);
1718 KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
1719 __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
1720 }
1721 }
1722 K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
1723 __kmp_barrier_gather_branch_bits[i],
1724 __kmp_barrier_release_branch_bits[i]))
1725 }
1726} // __kmp_stg_parse_barrier_branch_bit
1727
1728static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
1729 char const *name, void *data) {
1730 const char *var;
1731 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1732 var = __kmp_barrier_branch_bit_env_name[i];
1733 if (strcmp(var, name) == 0) {
1734 if (__kmp_env_format) {
1735 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
1736 } else {
1737 __kmp_str_buf_print(buffer, " %s='",
1738 __kmp_barrier_branch_bit_env_name[i]);
1739 }
1740 __kmp_str_buf_print(buffer, "%d,%d'\n",
1741 __kmp_barrier_gather_branch_bits[i],
1742 __kmp_barrier_release_branch_bits[i]);
1743 }
1744 }
1745} // __kmp_stg_print_barrier_branch_bit
1746
1747// ----------------------------------------------------------------------------
1748// KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
1749// KMP_REDUCTION_BARRIER_PATTERN
1750
1751// TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
1752// print functions, pass required data to functions through data argument.
1753
1754static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
1755 void *data) {
1756 const char *var;
1757 /* ---------- Barrier method control ------------ */
1758
1759 static int dist_req = 0, non_dist_req = 0;
1760 static bool warn = 1;
1761 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1762 var = __kmp_barrier_pattern_env_name[i];
1763
1764 if ((strcmp(var, name) == 0) && (value != 0)) {
1765 int j;
1766 char *comma = CCAST(char *, strchr(value, ','));
1767
1768 /* handle first parameter: gather pattern */
1769 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1770 if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
1771 ',')) {
1772 if (j == bp_dist_bar) {
1773 dist_req++;
1774 } else {
1775 non_dist_req++;
1776 }
1777 __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
1778 break;
1779 }
1780 }
1781 if (j == bp_last_bar) {
1782 KMP_WARNING(BarrGatherValueInvalid, name, value);
1783 KMP_INFORM(Using_str_Value, name,
1784 __kmp_barrier_pattern_name[bp_linear_bar]);
1785 }
1786
1787 /* handle second parameter: release pattern */
1788 if (comma != NULL) {
1789 for (j = bp_linear_bar; j < bp_last_bar; j++) {
1790 if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
1791 if (j == bp_dist_bar) {
1792 dist_req++;
1793 } else {
1794 non_dist_req++;
1795 }
1796 __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
1797 break;
1798 }
1799 }
1800 if (j == bp_last_bar) {
1801 __kmp_msg(kmp_ms_warning,
1802 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1803 __kmp_msg_null);
1804 KMP_INFORM(Using_str_Value, name,
1805 __kmp_barrier_pattern_name[bp_linear_bar]);
1806 }
1807 }
1808 }
1809 }
1810 if (dist_req != 0) {
1811 // set all barriers to dist
1812 if ((non_dist_req != 0) && warn) {
1813 KMP_INFORM(BarrierPatternOverride, name,
1814 __kmp_barrier_pattern_name[bp_dist_bar]);
1815 warn = 0;
1816 }
1817 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1818 if (__kmp_barrier_release_pattern[i] != bp_dist_bar)
1819 __kmp_barrier_release_pattern[i] = bp_dist_bar;
1820 if (__kmp_barrier_gather_pattern[i] != bp_dist_bar)
1821 __kmp_barrier_gather_pattern[i] = bp_dist_bar;
1822 }
1823 }
1824} // __kmp_stg_parse_barrier_pattern
1825
1826static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
1827 char const *name, void *data) {
1828 const char *var;
1829 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1830 var = __kmp_barrier_pattern_env_name[i];
1831 if (strcmp(var, name) == 0) {
1832 int j = __kmp_barrier_gather_pattern[i];
1833 int k = __kmp_barrier_release_pattern[i];
1834 if (__kmp_env_format) {
1835 KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
1836 } else {
1837 __kmp_str_buf_print(buffer, " %s='",
1838 __kmp_barrier_pattern_env_name[i]);
1839 }
1840 KMP_DEBUG_ASSERT(j < bp_last_bar && k < bp_last_bar);
1841 __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
1842 __kmp_barrier_pattern_name[k]);
1843 }
1844 }
1845} // __kmp_stg_print_barrier_pattern
1846
1847// -----------------------------------------------------------------------------
1848// KMP_ABORT_DELAY
1849
1850static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
1851 void *data) {
1852 // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
1853 // milliseconds.
1854 int delay = __kmp_abort_delay / 1000;
1855 __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
1856 __kmp_abort_delay = delay * 1000;
1857} // __kmp_stg_parse_abort_delay
1858
1859static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
1860 void *data) {
1861 __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
1862} // __kmp_stg_print_abort_delay
1863
1864// -----------------------------------------------------------------------------
1865// KMP_CPUINFO_FILE
1866
1867static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
1868 void *data) {
1869#if KMP_AFFINITY_SUPPORTED
1870 __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
1871 K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
1872#endif
1873} //__kmp_stg_parse_cpuinfo_file
1874
1875static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
1876 char const *name, void *data) {
1877#if KMP_AFFINITY_SUPPORTED
1878 if (__kmp_env_format) {
1879 KMP_STR_BUF_PRINT_NAME;
1880 } else {
1881 __kmp_str_buf_print(buffer, " %s", name);
1882 }
1883 if (__kmp_cpuinfo_file) {
1884 __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
1885 } else {
1886 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1887 }
1888#endif
1889} //__kmp_stg_print_cpuinfo_file
1890
1891// -----------------------------------------------------------------------------
1892// KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
1893
1894static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
1895 void *data) {
1896 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1897 int rc;
1898
1899 rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
1900 if (rc) {
1901 return;
1902 }
1903 if (reduction->force) {
1904 if (value != 0) {
1905 if (__kmp_str_match("critical", 0, value))
1906 __kmp_force_reduction_method = critical_reduce_block;
1907 else if (__kmp_str_match("atomic", 0, value))
1908 __kmp_force_reduction_method = atomic_reduce_block;
1909 else if (__kmp_str_match("tree", 0, value))
1910 __kmp_force_reduction_method = tree_reduce_block;
1911 else {
1912 KMP_FATAL(UnknownForceReduction, name, value);
1913 }
1914 }
1915 } else {
1916 __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
1917 if (__kmp_determ_red) {
1918 __kmp_force_reduction_method = tree_reduce_block;
1919 } else {
1920 __kmp_force_reduction_method = reduction_method_not_defined;
1921 }
1922 }
1923 K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
1924 __kmp_force_reduction_method));
1925} // __kmp_stg_parse_force_reduction
1926
1927static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
1928 char const *name, void *data) {
1929
1930 kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
1931 if (reduction->force) {
1932 if (__kmp_force_reduction_method == critical_reduce_block) {
1933 __kmp_stg_print_str(buffer, name, "critical");
1934 } else if (__kmp_force_reduction_method == atomic_reduce_block) {
1935 __kmp_stg_print_str(buffer, name, "atomic");
1936 } else if (__kmp_force_reduction_method == tree_reduce_block) {
1937 __kmp_stg_print_str(buffer, name, "tree");
1938 } else {
1939 if (__kmp_env_format) {
1940 KMP_STR_BUF_PRINT_NAME;
1941 } else {
1942 __kmp_str_buf_print(buffer, " %s", name);
1943 }
1944 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1945 }
1946 } else {
1947 __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
1948 }
1949
1950} // __kmp_stg_print_force_reduction
1951
1952// -----------------------------------------------------------------------------
1953// KMP_STORAGE_MAP
1954
1955static void __kmp_stg_parse_storage_map(char const *name, char const *value,
1956 void *data) {
1957 if (__kmp_str_match("verbose", 1, value)) {
1958 __kmp_storage_map = TRUE;
1959 __kmp_storage_map_verbose = TRUE;
1960 __kmp_storage_map_verbose_specified = TRUE;
1961
1962 } else {
1963 __kmp_storage_map_verbose = FALSE;
1964 __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
1965 }
1966} // __kmp_stg_parse_storage_map
1967
1968static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
1969 void *data) {
1970 if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
1971 __kmp_stg_print_str(buffer, name, "verbose");
1972 } else {
1973 __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
1974 }
1975} // __kmp_stg_print_storage_map
1976
1977// -----------------------------------------------------------------------------
1978// KMP_ALL_THREADPRIVATE
1979
1980static void __kmp_stg_parse_all_threadprivate(char const *name,
1981 char const *value, void *data) {
1982 __kmp_stg_parse_int(name, value,
1983 __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
1984 __kmp_max_nth, &__kmp_tp_capacity);
1985} // __kmp_stg_parse_all_threadprivate
1986
1987static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
1988 char const *name, void *data) {
1989 __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
1990}
1991
1992// -----------------------------------------------------------------------------
1993// KMP_FOREIGN_THREADS_THREADPRIVATE
1994
1995static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
1996 char const *value,
1997 void *data) {
1998 __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
1999} // __kmp_stg_parse_foreign_threads_threadprivate
2000
2001static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
2002 char const *name,
2003 void *data) {
2004 __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
2005} // __kmp_stg_print_foreign_threads_threadprivate
2006
2007// -----------------------------------------------------------------------------
2008// KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
2009
2010static inline const char *
2011__kmp_hw_get_core_type_keyword(kmp_hw_core_type_t type) {
2012 switch (type) {
2013 case KMP_HW_CORE_TYPE_UNKNOWN:
2014 case KMP_HW_MAX_NUM_CORE_TYPES:
2015 return "unknown";
2016#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2017 case KMP_HW_CORE_TYPE_ATOM:
2018 return "intel_atom";
2019 case KMP_HW_CORE_TYPE_CORE:
2020 return "intel_core";
2021#endif
2022 }
2023 KMP_ASSERT2(false, "Unhandled kmp_hw_core_type_t enumeration");
2024 KMP_BUILTIN_UNREACHABLE;
2025}
2026
2027#if KMP_AFFINITY_SUPPORTED
2028// Parse the proc id list. Return TRUE if successful, FALSE otherwise.
2029static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
2030 const char **nextEnv,
2031 char **proclist) {
2032 const char *scan = env;
2033 const char *next = scan;
2034 int empty = TRUE;
2035
2036 *proclist = NULL;
2037
2038 for (;;) {
2039 int start, end, stride;
2040
2041 SKIP_WS(scan);
2042 next = scan;
2043 if (*next == '\0') {
2044 break;
2045 }
2046
2047 if (*next == '{') {
2048 int num;
2049 next++; // skip '{'
2050 SKIP_WS(next);
2051 scan = next;
2052
2053 // Read the first integer in the set.
2054 if ((*next < '0') || (*next > '9')) {
2055 KMP_WARNING(AffSyntaxError, var);
2056 return FALSE;
2057 }
2058 SKIP_DIGITS(next);
2059 num = __kmp_str_to_int(scan, *next);
2060 KMP_ASSERT(num >= 0);
2061
2062 for (;;) {
2063 // Check for end of set.
2064 SKIP_WS(next);
2065 if (*next == '}') {
2066 next++; // skip '}'
2067 break;
2068 }
2069
2070 // Skip optional comma.
2071 if (*next == ',') {
2072 next++;
2073 }
2074 SKIP_WS(next);
2075
2076 // Read the next integer in the set.
2077 scan = next;
2078 if ((*next < '0') || (*next > '9')) {
2079 KMP_WARNING(AffSyntaxError, var);
2080 return FALSE;
2081 }
2082
2083 SKIP_DIGITS(next);
2084 num = __kmp_str_to_int(scan, *next);
2085 KMP_ASSERT(num >= 0);
2086 }
2087 empty = FALSE;
2088
2089 SKIP_WS(next);
2090 if (*next == ',') {
2091 next++;
2092 }
2093 scan = next;
2094 continue;
2095 }
2096
2097 // Next character is not an integer => end of list
2098 if ((*next < '0') || (*next > '9')) {
2099 if (empty) {
2100 KMP_WARNING(AffSyntaxError, var);
2101 return FALSE;
2102 }
2103 break;
2104 }
2105
2106 // Read the first integer.
2107 SKIP_DIGITS(next);
2108 start = __kmp_str_to_int(scan, *next);
2109 KMP_ASSERT(start >= 0);
2110 SKIP_WS(next);
2111
2112 // If this isn't a range, then go on.
2113 if (*next != '-') {
2114 empty = FALSE;
2115
2116 // Skip optional comma.
2117 if (*next == ',') {
2118 next++;
2119 }
2120 scan = next;
2121 continue;
2122 }
2123
2124 // This is a range. Skip over the '-' and read in the 2nd int.
2125 next++; // skip '-'
2126 SKIP_WS(next);
2127 scan = next;
2128 if ((*next < '0') || (*next > '9')) {
2129 KMP_WARNING(AffSyntaxError, var);
2130 return FALSE;
2131 }
2132 SKIP_DIGITS(next);
2133 end = __kmp_str_to_int(scan, *next);
2134 KMP_ASSERT(end >= 0);
2135
2136 // Check for a stride parameter
2137 stride = 1;
2138 SKIP_WS(next);
2139 if (*next == ':') {
2140 // A stride is specified. Skip over the ':" and read the 3rd int.
2141 int sign = +1;
2142 next++; // skip ':'
2143 SKIP_WS(next);
2144 scan = next;
2145 if (*next == '-') {
2146 sign = -1;
2147 next++;
2148 SKIP_WS(next);
2149 scan = next;
2150 }
2151 if ((*next < '0') || (*next > '9')) {
2152 KMP_WARNING(AffSyntaxError, var);
2153 return FALSE;
2154 }
2155 SKIP_DIGITS(next);
2156 stride = __kmp_str_to_int(scan, *next);
2157 KMP_ASSERT(stride >= 0);
2158 stride *= sign;
2159 }
2160
2161 // Do some range checks.
2162 if (stride == 0) {
2163 KMP_WARNING(AffZeroStride, var);
2164 return FALSE;
2165 }
2166 if (stride > 0) {
2167 if (start > end) {
2168 KMP_WARNING(AffStartGreaterEnd, var, start, end);
2169 return FALSE;
2170 }
2171 } else {
2172 if (start < end) {
2173 KMP_WARNING(AffStrideLessZero, var, start, end);
2174 return FALSE;
2175 }
2176 }
2177 if ((end - start) / stride > 65536) {
2178 KMP_WARNING(AffRangeTooBig, var, end, start, stride);
2179 return FALSE;
2180 }
2181
2182 empty = FALSE;
2183
2184 // Skip optional comma.
2185 SKIP_WS(next);
2186 if (*next == ',') {
2187 next++;
2188 }
2189 scan = next;
2190 }
2191
2192 *nextEnv = next;
2193
2194 {
2195 ptrdiff_t len = next - env;
2196 char *retlist = (char *)KMP_INTERNAL_MALLOC((len + 1) * sizeof(char));
2197 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
2198 retlist[len] = '\0';
2199 *proclist = retlist;
2200 }
2201 return TRUE;
2202}
2203
2204// If KMP_AFFINITY is specified without a type, then
2205// __kmp_affinity_notype should point to its setting.
2206static kmp_setting_t *__kmp_affinity_notype = NULL;
2207
2208static void __kmp_parse_affinity_env(char const *name, char const *value,
2209 kmp_affinity_t *out_affinity) {
2210 char *buffer = NULL; // Copy of env var value.
2211 char *buf = NULL; // Buffer for strtok_r() function.
2212 char *next = NULL; // end of token / start of next.
2213 const char *start; // start of current token (for err msgs)
2214 int count = 0; // Counter of parsed integer numbers.
2215 int number[2]; // Parsed numbers.
2216
2217 // Guards.
2218 int type = 0;
2219 int proclist = 0;
2220 int verbose = 0;
2221 int warnings = 0;
2222 int respect = 0;
2223 int gran = 0;
2224 int dups = 0;
2225 int reset = 0;
2226 bool set = false;
2227
2228 KMP_ASSERT(value != NULL);
2229
2230 if (TCR_4(__kmp_init_middle)) {
2231 KMP_WARNING(EnvMiddleWarn, name);
2232 __kmp_env_toPrint(name, 0);
2233 return;
2234 }
2235 __kmp_env_toPrint(name, 1);
2236
2237 buffer =
2238 __kmp_str_format("%s", value); // Copy env var to keep original intact.
2239 buf = buffer;
2240 SKIP_WS(buf);
2241
2242// Helper macros.
2243
2244// If we see a parse error, emit a warning and scan to the next ",".
2245//
2246// FIXME - there's got to be a better way to print an error
2247// message, hopefully without overwriting peices of buf.
2248#define EMIT_WARN(skip, errlist) \
2249 { \
2250 char ch; \
2251 if (skip) { \
2252 SKIP_TO(next, ','); \
2253 } \
2254 ch = *next; \
2255 *next = '\0'; \
2256 KMP_WARNING errlist; \
2257 *next = ch; \
2258 if (skip) { \
2259 if (ch == ',') \
2260 next++; \
2261 } \
2262 buf = next; \
2263 }
2264
2265#define _set_param(_guard, _var, _val) \
2266 { \
2267 if (_guard == 0) { \
2268 _var = _val; \
2269 } else { \
2270 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2271 } \
2272 ++_guard; \
2273 }
2274
2275#define set_type(val) _set_param(type, out_affinity->type, val)
2276#define set_verbose(val) _set_param(verbose, out_affinity->flags.verbose, val)
2277#define set_warnings(val) \
2278 _set_param(warnings, out_affinity->flags.warnings, val)
2279#define set_respect(val) _set_param(respect, out_affinity->flags.respect, val)
2280#define set_dups(val) _set_param(dups, out_affinity->flags.dups, val)
2281#define set_proclist(val) _set_param(proclist, out_affinity->proclist, val)
2282#define set_reset(val) _set_param(reset, out_affinity->flags.reset, val)
2283
2284#define set_gran(val, levels) \
2285 { \
2286 if (gran == 0) { \
2287 out_affinity->gran = val; \
2288 out_affinity->gran_levels = levels; \
2289 } else { \
2290 EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
2291 } \
2292 ++gran; \
2293 }
2294
2295 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
2296 (__kmp_nested_proc_bind.used > 0));
2297
2298 while (*buf != '\0') {
2299 start = next = buf;
2300
2301 if (__kmp_match_str("none", buf, CCAST(const char **, &next))) {
2302 set_type(affinity_none);
2303 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2304 buf = next;
2305 } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) {
2306 set_type(affinity_scatter);
2307 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2308 buf = next;
2309 } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) {
2310 set_type(affinity_compact);
2311 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2312 buf = next;
2313 } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) {
2314 set_type(affinity_logical);
2315 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2316 buf = next;
2317 } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) {
2318 set_type(affinity_physical);
2319 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2320 buf = next;
2321 } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) {
2322 set_type(affinity_explicit);
2323 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2324 buf = next;
2325 } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) {
2326 set_type(affinity_balanced);
2327 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2328 buf = next;
2329 } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) {
2330 set_type(affinity_disabled);
2331 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2332 buf = next;
2333 } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) {
2334 set_verbose(TRUE);
2335 buf = next;
2336 } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) {
2337 set_verbose(FALSE);
2338 buf = next;
2339 } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) {
2340 set_warnings(TRUE);
2341 buf = next;
2342 } else if (__kmp_match_str("nowarnings", buf,
2343 CCAST(const char **, &next))) {
2344 set_warnings(FALSE);
2345 buf = next;
2346 } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) {
2347 set_respect(TRUE);
2348 buf = next;
2349 } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) {
2350 set_respect(FALSE);
2351 buf = next;
2352 } else if (__kmp_match_str("reset", buf, CCAST(const char **, &next))) {
2353 set_reset(TRUE);
2354 buf = next;
2355 } else if (__kmp_match_str("noreset", buf, CCAST(const char **, &next))) {
2356 set_reset(FALSE);
2357 buf = next;
2358 } else if (__kmp_match_str("duplicates", buf,
2359 CCAST(const char **, &next)) ||
2360 __kmp_match_str("dups", buf, CCAST(const char **, &next))) {
2361 set_dups(TRUE);
2362 buf = next;
2363 } else if (__kmp_match_str("noduplicates", buf,
2364 CCAST(const char **, &next)) ||
2365 __kmp_match_str("nodups", buf, CCAST(const char **, &next))) {
2366 set_dups(FALSE);
2367 buf = next;
2368 } else if (__kmp_match_str("granularity", buf,
2369 CCAST(const char **, &next)) ||
2370 __kmp_match_str("gran", buf, CCAST(const char **, &next))) {
2371 SKIP_WS(next);
2372 if (*next != '=') {
2373 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2374 continue;
2375 }
2376 next++; // skip '='
2377 SKIP_WS(next);
2378
2379 buf = next;
2380
2381 // Have to try core_type and core_efficiency matches first since "core"
2382 // will register as core granularity with "extra chars"
2383 if (__kmp_match_str("core_type", buf, CCAST(const char **, &next))) {
2384 set_gran(KMP_HW_CORE, -1);
2385 out_affinity->flags.core_types_gran = 1;
2386 buf = next;
2387 set = true;
2388 } else if (__kmp_match_str("core_efficiency", buf,
2389 CCAST(const char **, &next)) ||
2390 __kmp_match_str("core_eff", buf,
2391 CCAST(const char **, &next))) {
2392 set_gran(KMP_HW_CORE, -1);
2393 out_affinity->flags.core_effs_gran = 1;
2394 buf = next;
2395 set = true;
2396 }
2397 if (!set) {
2398 // Try any hardware topology type for granularity
2399 KMP_FOREACH_HW_TYPE(type) {
2400 const char *name = __kmp_hw_get_keyword(type);
2401 if (__kmp_match_str(name, buf, CCAST(const char **, &next))) {
2402 set_gran(type, -1);
2403 buf = next;
2404 set = true;
2405 break;
2406 }
2407 }
2408 }
2409 if (!set) {
2410 // Support older names for different granularity layers
2411 if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) {
2412 set_gran(KMP_HW_THREAD, -1);
2413 buf = next;
2414 set = true;
2415 } else if (__kmp_match_str("package", buf,
2416 CCAST(const char **, &next))) {
2417 set_gran(KMP_HW_SOCKET, -1);
2418 buf = next;
2419 set = true;
2420 } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
2421 set_gran(KMP_HW_NUMA, -1);
2422 buf = next;
2423 set = true;
2424#if KMP_GROUP_AFFINITY
2425 } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
2426 set_gran(KMP_HW_PROC_GROUP, -1);
2427 buf = next;
2428 set = true;
2429#endif /* KMP_GROUP AFFINITY */
2430 } else if ((*buf >= '0') && (*buf <= '9')) {
2431 int n;
2432 next = buf;
2433 SKIP_DIGITS(next);
2434 n = __kmp_str_to_int(buf, *next);
2435 KMP_ASSERT(n >= 0);
2436 buf = next;
2437 set_gran(KMP_HW_UNKNOWN, n);
2438 set = true;
2439 } else {
2440 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2441 continue;
2442 }
2443 }
2444 } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
2445 char *temp_proclist;
2446
2447 SKIP_WS(next);
2448 if (*next != '=') {
2449 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2450 continue;
2451 }
2452 next++; // skip '='
2453 SKIP_WS(next);
2454 if (*next != '[') {
2455 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2456 continue;
2457 }
2458 next++; // skip '['
2459 buf = next;
2460 if (!__kmp_parse_affinity_proc_id_list(
2461 name, buf, CCAST(const char **, &next), &temp_proclist)) {
2462 // warning already emitted.
2463 SKIP_TO(next, ']');
2464 if (*next == ']')
2465 next++;
2466 SKIP_TO(next, ',');
2467 if (*next == ',')
2468 next++;
2469 buf = next;
2470 continue;
2471 }
2472 if (*next != ']') {
2473 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2474 continue;
2475 }
2476 next++; // skip ']'
2477 set_proclist(temp_proclist);
2478 } else if ((*buf >= '0') && (*buf <= '9')) {
2479 // Parse integer numbers -- permute and offset.
2480 int n;
2481 next = buf;
2482 SKIP_DIGITS(next);
2483 n = __kmp_str_to_int(buf, *next);
2484 KMP_ASSERT(n >= 0);
2485 buf = next;
2486 if (count < 2) {
2487 number[count] = n;
2488 } else {
2489 KMP_WARNING(AffManyParams, name, start);
2490 }
2491 ++count;
2492 } else {
2493 EMIT_WARN(TRUE, (AffInvalidParam, name, start));
2494 continue;
2495 }
2496
2497 SKIP_WS(next);
2498 if (*next == ',') {
2499 next++;
2500 SKIP_WS(next);
2501 } else if (*next != '\0') {
2502 const char *temp = next;
2503 EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
2504 continue;
2505 }
2506 buf = next;
2507 } // while
2508
2509#undef EMIT_WARN
2510#undef _set_param
2511#undef set_type
2512#undef set_verbose
2513#undef set_warnings
2514#undef set_respect
2515#undef set_granularity
2516#undef set_reset
2517
2518 __kmp_str_free(&buffer);
2519
2520 if (proclist) {
2521 if (!type) {
2522 KMP_WARNING(AffProcListNoType, name);
2523 out_affinity->type = affinity_explicit;
2524 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2525 } else if (out_affinity->type != affinity_explicit) {
2526 KMP_WARNING(AffProcListNotExplicit, name);
2527 KMP_ASSERT(out_affinity->proclist != NULL);
2528 KMP_INTERNAL_FREE(out_affinity->proclist);
2529 out_affinity->proclist = NULL;
2530 }
2531 }
2532 switch (out_affinity->type) {
2533 case affinity_logical:
2534 case affinity_physical: {
2535 if (count > 0) {
2536 out_affinity->offset = number[0];
2537 }
2538 if (count > 1) {
2539 KMP_WARNING(AffManyParamsForLogic, name, number[1]);
2540 }
2541 } break;
2542 case affinity_balanced: {
2543 if (count > 0) {
2544 out_affinity->compact = number[0];
2545 }
2546 if (count > 1) {
2547 out_affinity->offset = number[1];
2548 }
2549
2550 if (__kmp_affinity.gran == KMP_HW_UNKNOWN) {
2551 int verbose = out_affinity->flags.verbose;
2552 int warnings = out_affinity->flags.warnings;
2553#if KMP_MIC_SUPPORTED
2554 if (__kmp_mic_type != non_mic) {
2555 if (verbose || warnings) {
2556 KMP_WARNING(AffGranUsing, out_affinity->env_var, "fine");
2557 }
2558 out_affinity->gran = KMP_HW_THREAD;
2559 } else
2560#endif
2561 {
2562 if (verbose || warnings) {
2563 KMP_WARNING(AffGranUsing, out_affinity->env_var, "core");
2564 }
2565 out_affinity->gran = KMP_HW_CORE;
2566 }
2567 }
2568 } break;
2569 case affinity_scatter:
2570 case affinity_compact: {
2571 if (count > 0) {
2572 out_affinity->compact = number[0];
2573 }
2574 if (count > 1) {
2575 out_affinity->offset = number[1];
2576 }
2577 } break;
2578 case affinity_explicit: {
2579 if (out_affinity->proclist == NULL) {
2580 KMP_WARNING(AffNoProcList, name);
2581 out_affinity->type = affinity_none;
2582 }
2583 if (count > 0) {
2584 KMP_WARNING(AffNoParam, name, "explicit");
2585 }
2586 } break;
2587 case affinity_none: {
2588 if (count > 0) {
2589 KMP_WARNING(AffNoParam, name, "none");
2590 }
2591 } break;
2592 case affinity_disabled: {
2593 if (count > 0) {
2594 KMP_WARNING(AffNoParam, name, "disabled");
2595 }
2596 } break;
2597 case affinity_default: {
2598 if (count > 0) {
2599 KMP_WARNING(AffNoParam, name, "default");
2600 }
2601 } break;
2602 default: {
2603 KMP_ASSERT(0);
2604 }
2605 }
2606} // __kmp_parse_affinity_env
2607
2608static void __kmp_stg_parse_affinity(char const *name, char const *value,
2609 void *data) {
2610 kmp_setting_t **rivals = (kmp_setting_t **)data;
2611 int rc;
2612
2613 rc = __kmp_stg_check_rivals(name, value, rivals);
2614 if (rc) {
2615 return;
2616 }
2617
2618 __kmp_parse_affinity_env(name, value, &__kmp_affinity);
2619
2620} // __kmp_stg_parse_affinity
2621static void __kmp_stg_parse_hh_affinity(char const *name, char const *value,
2622 void *data) {
2623 __kmp_parse_affinity_env(name, value, &__kmp_hh_affinity);
2624 // Warn about unused parts of hidden helper affinity settings if specified.
2625 if (__kmp_hh_affinity.flags.reset) {
2626 KMP_WARNING(AffInvalidParam, name, "reset");
2627 }
2628 if (__kmp_hh_affinity.flags.respect != affinity_respect_mask_default) {
2629 KMP_WARNING(AffInvalidParam, name, "respect");
2630 }
2631}
2632
2633static void __kmp_print_affinity_env(kmp_str_buf_t *buffer, char const *name,
2634 const kmp_affinity_t &affinity) {
2635 bool is_hh_affinity = (&affinity == &__kmp_hh_affinity);
2636 if (__kmp_env_format) {
2637 KMP_STR_BUF_PRINT_NAME_EX(name);
2638 } else {
2639 __kmp_str_buf_print(buffer, " %s='", name);
2640 }
2641 if (affinity.flags.verbose) {
2642 __kmp_str_buf_print(buffer, "%s,", "verbose");
2643 } else {
2644 __kmp_str_buf_print(buffer, "%s,", "noverbose");
2645 }
2646 if (affinity.flags.warnings) {
2647 __kmp_str_buf_print(buffer, "%s,", "warnings");
2648 } else {
2649 __kmp_str_buf_print(buffer, "%s,", "nowarnings");
2650 }
2651 if (KMP_AFFINITY_CAPABLE()) {
2652 // Hidden helper affinity does not affect global reset
2653 // or respect flags. That is still solely controlled by KMP_AFFINITY.
2654 if (!is_hh_affinity) {
2655 if (affinity.flags.respect) {
2656 __kmp_str_buf_print(buffer, "%s,", "respect");
2657 } else {
2658 __kmp_str_buf_print(buffer, "%s,", "norespect");
2659 }
2660 if (affinity.flags.reset) {
2661 __kmp_str_buf_print(buffer, "%s,", "reset");
2662 } else {
2663 __kmp_str_buf_print(buffer, "%s,", "noreset");
2664 }
2665 }
2666 __kmp_str_buf_print(buffer, "granularity=");
2667 if (affinity.flags.core_types_gran)
2668 __kmp_str_buf_print(buffer, "core_type,");
2669 else if (affinity.flags.core_effs_gran) {
2670 __kmp_str_buf_print(buffer, "core_eff,");
2671 } else {
2672 __kmp_str_buf_print(
2673 buffer, "%s,", __kmp_hw_get_keyword(affinity.gran, /*plural=*/false));
2674 }
2675 }
2676 if (!KMP_AFFINITY_CAPABLE()) {
2677 __kmp_str_buf_print(buffer, "%s", "disabled");
2678 } else {
2679 int compact = affinity.compact;
2680 int offset = affinity.offset;
2681 switch (affinity.type) {
2682 case affinity_none:
2683 __kmp_str_buf_print(buffer, "%s", "none");
2684 break;
2685 case affinity_physical:
2686 __kmp_str_buf_print(buffer, "%s,%d", "physical", offset);
2687 break;
2688 case affinity_logical:
2689 __kmp_str_buf_print(buffer, "%s,%d", "logical", offset);
2690 break;
2691 case affinity_compact:
2692 __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", compact, offset);
2693 break;
2694 case affinity_scatter:
2695 __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", compact, offset);
2696 break;
2697 case affinity_explicit:
2698 __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist", affinity.proclist,
2699 "explicit");
2700 break;
2701 case affinity_balanced:
2702 __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced", compact, offset);
2703 break;
2704 case affinity_disabled:
2705 __kmp_str_buf_print(buffer, "%s", "disabled");
2706 break;
2707 case affinity_default:
2708 __kmp_str_buf_print(buffer, "%s", "default");
2709 break;
2710 default:
2711 __kmp_str_buf_print(buffer, "%s", "<unknown>");
2712 break;
2713 }
2714 }
2715 __kmp_str_buf_print(buffer, "'\n");
2716} //__kmp_stg_print_affinity
2717
2718static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
2719 void *data) {
2720 __kmp_print_affinity_env(buffer, name, __kmp_affinity);
2721}
2722static void __kmp_stg_print_hh_affinity(kmp_str_buf_t *buffer, char const *name,
2723 void *data) {
2724 __kmp_print_affinity_env(buffer, name, __kmp_hh_affinity);
2725}
2726
2727#ifdef KMP_GOMP_COMPAT
2728
2729static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
2730 char const *value, void *data) {
2731 const char *next = NULL;
2732 char *temp_proclist;
2733 kmp_setting_t **rivals = (kmp_setting_t **)data;
2734 int rc;
2735
2736 rc = __kmp_stg_check_rivals(name, value, rivals);
2737 if (rc) {
2738 return;
2739 }
2740
2741 if (TCR_4(__kmp_init_middle)) {
2742 KMP_WARNING(EnvMiddleWarn, name);
2743 __kmp_env_toPrint(name, 0);
2744 return;
2745 }
2746
2747 __kmp_env_toPrint(name, 1);
2748
2749 if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
2750 SKIP_WS(next);
2751 if (*next == '\0') {
2752 // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
2753 __kmp_affinity.proclist = temp_proclist;
2754 __kmp_affinity.type = affinity_explicit;
2755 __kmp_affinity.gran = KMP_HW_THREAD;
2756 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
2757 } else {
2758 KMP_WARNING(AffSyntaxError, name);
2759 if (temp_proclist != NULL) {
2760 KMP_INTERNAL_FREE((void *)temp_proclist);
2761 }
2762 }
2763 } else {
2764 // Warning already emitted
2765 __kmp_affinity.type = affinity_none;
2766 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
2767 }
2768} // __kmp_stg_parse_gomp_cpu_affinity
2769
2770#endif /* KMP_GOMP_COMPAT */
2771
2772/*-----------------------------------------------------------------------------
2773The OMP_PLACES proc id list parser. Here is the grammar:
2774
2775place_list := place
2776place_list := place , place_list
2777place := num
2778place := place : num
2779place := place : num : signed
2780place := { subplacelist }
2781place := ! place // (lowest priority)
2782subplace_list := subplace
2783subplace_list := subplace , subplace_list
2784subplace := num
2785subplace := num : num
2786subplace := num : num : signed
2787signed := num
2788signed := + signed
2789signed := - signed
2790-----------------------------------------------------------------------------*/
2791
2792// Return TRUE if successful parse, FALSE otherwise
2793static int __kmp_parse_subplace_list(const char *var, const char **scan) {
2794 const char *next;
2795
2796 for (;;) {
2797 int start, count, stride;
2798
2799 //
2800 // Read in the starting proc id
2801 //
2802 SKIP_WS(*scan);
2803 if ((**scan < '0') || (**scan > '9')) {
2804 return FALSE;
2805 }
2806 next = *scan;
2807 SKIP_DIGITS(next);
2808 start = __kmp_str_to_int(*scan, *next);
2809 KMP_ASSERT(start >= 0);
2810 *scan = next;
2811
2812 // valid follow sets are ',' ':' and '}'
2813 SKIP_WS(*scan);
2814 if (**scan == '}') {
2815 break;
2816 }
2817 if (**scan == ',') {
2818 (*scan)++; // skip ','
2819 continue;
2820 }
2821 if (**scan != ':') {
2822 return FALSE;
2823 }
2824 (*scan)++; // skip ':'
2825
2826 // Read count parameter
2827 SKIP_WS(*scan);
2828 if ((**scan < '0') || (**scan > '9')) {
2829 return FALSE;
2830 }
2831 next = *scan;
2832 SKIP_DIGITS(next);
2833 count = __kmp_str_to_int(*scan, *next);
2834 KMP_ASSERT(count >= 0);
2835 *scan = next;
2836
2837 // valid follow sets are ',' ':' and '}'
2838 SKIP_WS(*scan);
2839 if (**scan == '}') {
2840 break;
2841 }
2842 if (**scan == ',') {
2843 (*scan)++; // skip ','
2844 continue;
2845 }
2846 if (**scan != ':') {
2847 return FALSE;
2848 }
2849 (*scan)++; // skip ':'
2850
2851 // Read stride parameter
2852 int sign = +1;
2853 for (;;) {
2854 SKIP_WS(*scan);
2855 if (**scan == '+') {
2856 (*scan)++; // skip '+'
2857 continue;
2858 }
2859 if (**scan == '-') {
2860 sign *= -1;
2861 (*scan)++; // skip '-'
2862 continue;
2863 }
2864 break;
2865 }
2866 SKIP_WS(*scan);
2867 if ((**scan < '0') || (**scan > '9')) {
2868 return FALSE;
2869 }
2870 next = *scan;
2871 SKIP_DIGITS(next);
2872 stride = __kmp_str_to_int(*scan, *next);
2873 KMP_ASSERT(stride >= 0);
2874 *scan = next;
2875 stride *= sign;
2876
2877 // valid follow sets are ',' and '}'
2878 SKIP_WS(*scan);
2879 if (**scan == '}') {
2880 break;
2881 }
2882 if (**scan == ',') {
2883 (*scan)++; // skip ','
2884 continue;
2885 }
2886 return FALSE;
2887 }
2888 return TRUE;
2889}
2890
2891// Return TRUE if successful parse, FALSE otherwise
2892static int __kmp_parse_place(const char *var, const char **scan) {
2893 const char *next;
2894
2895 // valid follow sets are '{' '!' and num
2896 SKIP_WS(*scan);
2897 if (**scan == '{') {
2898 (*scan)++; // skip '{'
2899 if (!__kmp_parse_subplace_list(var, scan)) {
2900 return FALSE;
2901 }
2902 if (**scan != '}') {
2903 return FALSE;
2904 }
2905 (*scan)++; // skip '}'
2906 } else if (**scan == '!') {
2907 (*scan)++; // skip '!'
2908 return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
2909 } else if ((**scan >= '0') && (**scan <= '9')) {
2910 next = *scan;
2911 SKIP_DIGITS(next);
2912 int proc = __kmp_str_to_int(*scan, *next);
2913 KMP_ASSERT(proc >= 0);
2914 *scan = next;
2915 } else {
2916 return FALSE;
2917 }
2918 return TRUE;
2919}
2920
2921// Return TRUE if successful parse, FALSE otherwise
2922static int __kmp_parse_place_list(const char *var, const char *env,
2923 char **place_list) {
2924 const char *scan = env;
2925 const char *next = scan;
2926
2927 for (;;) {
2928 int count, stride;
2929
2930 if (!__kmp_parse_place(var, &scan)) {
2931 return FALSE;
2932 }
2933
2934 // valid follow sets are ',' ':' and EOL
2935 SKIP_WS(scan);
2936 if (*scan == '\0') {
2937 break;
2938 }
2939 if (*scan == ',') {
2940 scan++; // skip ','
2941 continue;
2942 }
2943 if (*scan != ':') {
2944 return FALSE;
2945 }
2946 scan++; // skip ':'
2947
2948 // Read count parameter
2949 SKIP_WS(scan);
2950 if ((*scan < '0') || (*scan > '9')) {
2951 return FALSE;
2952 }
2953 next = scan;
2954 SKIP_DIGITS(next);
2955 count = __kmp_str_to_int(scan, *next);
2956 KMP_ASSERT(count >= 0);
2957 scan = next;
2958
2959 // valid follow sets are ',' ':' and EOL
2960 SKIP_WS(scan);
2961 if (*scan == '\0') {
2962 break;
2963 }
2964 if (*scan == ',') {
2965 scan++; // skip ','
2966 continue;
2967 }
2968 if (*scan != ':') {
2969 return FALSE;
2970 }
2971 scan++; // skip ':'
2972
2973 // Read stride parameter
2974 int sign = +1;
2975 for (;;) {
2976 SKIP_WS(scan);
2977 if (*scan == '+') {
2978 scan++; // skip '+'
2979 continue;
2980 }
2981 if (*scan == '-') {
2982 sign *= -1;
2983 scan++; // skip '-'
2984 continue;
2985 }
2986 break;
2987 }
2988 SKIP_WS(scan);
2989 if ((*scan < '0') || (*scan > '9')) {
2990 return FALSE;
2991 }
2992 next = scan;
2993 SKIP_DIGITS(next);
2994 stride = __kmp_str_to_int(scan, *next);
2995 KMP_ASSERT(stride >= 0);
2996 scan = next;
2997 stride *= sign;
2998
2999 // valid follow sets are ',' and EOL
3000 SKIP_WS(scan);
3001 if (*scan == '\0') {
3002 break;
3003 }
3004 if (*scan == ',') {
3005 scan++; // skip ','
3006 continue;
3007 }
3008
3009 return FALSE;
3010 }
3011
3012 {
3013 ptrdiff_t len = scan - env;
3014 char *retlist = (char *)KMP_INTERNAL_MALLOC((len + 1) * sizeof(char));
3015 KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
3016 retlist[len] = '\0';
3017 *place_list = retlist;
3018 }
3019 return TRUE;
3020}
3021
3022static inline void __kmp_places_set(enum affinity_type type, kmp_hw_t kind) {
3023 __kmp_affinity.type = type;
3024 __kmp_affinity.gran = kind;
3025 __kmp_affinity.flags.dups = FALSE;
3026 __kmp_affinity.flags.omp_places = TRUE;
3027}
3028
3029static void __kmp_places_syntax_error_fallback(char const *name,
3030 kmp_hw_t kind) {
3031 const char *str = __kmp_hw_get_catalog_string(kind, /*plural=*/true);
3032 KMP_WARNING(SyntaxErrorUsing, name, str);
3033 __kmp_places_set(affinity_compact, kind);
3034 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default)
3035 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3036}
3037
3038static void __kmp_stg_parse_places(char const *name, char const *value,
3039 void *data) {
3040 struct kmp_place_t {
3041 const char *name;
3042 kmp_hw_t type;
3043 };
3044 int count;
3045 bool set = false;
3046 const char *scan = value;
3047 const char *next = scan;
3048 kmp_place_t std_places[] = {{"threads", KMP_HW_THREAD},
3049 {"cores", KMP_HW_CORE},
3050 {"numa_domains", KMP_HW_NUMA},
3051 {"ll_caches", KMP_HW_LLC},
3052 {"sockets", KMP_HW_SOCKET}};
3053 kmp_setting_t **rivals = (kmp_setting_t **)data;
3054 int rc;
3055
3056 rc = __kmp_stg_check_rivals(name, value, rivals);
3057 if (rc) {
3058 return;
3059 }
3060
3061 // Standard choices
3062 for (size_t i = 0; i < sizeof(std_places) / sizeof(std_places[0]); ++i) {
3063 const kmp_place_t &place = std_places[i];
3064 if (__kmp_match_str(place.name, scan, &next)) {
3065 scan = next;
3066 __kmp_places_set(affinity_compact, place.type);
3067 set = true;
3068 // Parse core attribute if it exists
3069 if (KMP_HW_MAX_NUM_CORE_TYPES > 1) {
3070 SKIP_WS(scan);
3071 if (*scan == ':') {
3072 if (place.type != KMP_HW_CORE) {
3073 __kmp_places_syntax_error_fallback(name, place.type);
3074 return;
3075 }
3076 scan++; // skip ':'
3077 SKIP_WS(scan);
3078#if KMP_ARCH_X86 || KMP_ARCH_X86_64
3079 if (__kmp_match_str("intel_core", scan, &next)) {
3080 __kmp_affinity.core_attr_gran.core_type = KMP_HW_CORE_TYPE_CORE;
3081 __kmp_affinity.core_attr_gran.valid = 1;
3082 scan = next;
3083 } else if (__kmp_match_str("intel_atom", scan, &next)) {
3084 __kmp_affinity.core_attr_gran.core_type = KMP_HW_CORE_TYPE_ATOM;
3085 __kmp_affinity.core_attr_gran.valid = 1;
3086 scan = next;
3087 } else
3088#endif
3089 if (__kmp_match_str("eff", scan, &next)) {
3090 int eff;
3091 if (!isdigit(*next)) {
3092 __kmp_places_syntax_error_fallback(name, place.type);
3093 return;
3094 }
3095 scan = next;
3096 SKIP_DIGITS(next);
3097 eff = __kmp_str_to_int(scan, *next);
3098 if (eff < 0) {
3099 __kmp_places_syntax_error_fallback(name, place.type);
3100 return;
3101 }
3102 if (eff >= KMP_HW_MAX_NUM_CORE_EFFS)
3103 eff = KMP_HW_MAX_NUM_CORE_EFFS - 1;
3104 __kmp_affinity.core_attr_gran.core_eff = eff;
3105 __kmp_affinity.core_attr_gran.valid = 1;
3106 scan = next;
3107 }
3108 if (!__kmp_affinity.core_attr_gran.valid) {
3109 __kmp_places_syntax_error_fallback(name, place.type);
3110 return;
3111 }
3112 }
3113 }
3114 break;
3115 }
3116 }
3117 // Implementation choices for OMP_PLACES based on internal types
3118 if (!set) {
3119 KMP_FOREACH_HW_TYPE(type) {
3120 const char *name = __kmp_hw_get_keyword(type, true);
3121 if (__kmp_match_str("unknowns", scan, &next))
3122 continue;
3123 if (__kmp_match_str(name, scan, &next)) {
3124 scan = next;
3125 __kmp_places_set(affinity_compact, type);
3126 set = true;
3127 break;
3128 }
3129 }
3130 }
3131 // Implementation choices for OMP_PLACES based on core attributes
3132 if (!set) {
3133 if (__kmp_match_str("core_types", scan, &next)) {
3134 scan = next;
3135 if (*scan != '\0') {
3136 KMP_WARNING(ParseExtraCharsWarn, name, scan);
3137 }
3138 __kmp_places_set(affinity_compact, KMP_HW_CORE);
3139 __kmp_affinity.flags.core_types_gran = 1;
3140 set = true;
3141 } else if (__kmp_match_str("core_effs", scan, &next) ||
3142 __kmp_match_str("core_efficiencies", scan, &next)) {
3143 scan = next;
3144 if (*scan != '\0') {
3145 KMP_WARNING(ParseExtraCharsWarn, name, scan);
3146 }
3147 __kmp_places_set(affinity_compact, KMP_HW_CORE);
3148 __kmp_affinity.flags.core_effs_gran = 1;
3149 set = true;
3150 }
3151 }
3152 // Explicit place list
3153 if (!set) {
3154 if (__kmp_affinity.proclist != NULL) {
3155 KMP_INTERNAL_FREE((void *)__kmp_affinity.proclist);
3156 __kmp_affinity.proclist = NULL;
3157 }
3158 if (__kmp_parse_place_list(name, value, &__kmp_affinity.proclist)) {
3159 __kmp_places_set(affinity_explicit, KMP_HW_THREAD);
3160 } else {
3161 // Syntax error fallback
3162 __kmp_places_syntax_error_fallback(name, KMP_HW_CORE);
3163 }
3164 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
3165 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3166 }
3167 return;
3168 }
3169
3170 kmp_hw_t gran = __kmp_affinity.gran;
3171 if (__kmp_affinity.gran != KMP_HW_UNKNOWN) {
3172 gran = __kmp_affinity.gran;
3173 } else {
3174 gran = KMP_HW_CORE;
3175 }
3176
3177 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
3178 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3179 }
3180
3181 SKIP_WS(scan);
3182 if (*scan == '\0') {
3183 return;
3184 }
3185
3186 // Parse option count parameter in parentheses
3187 if (*scan != '(') {
3188 __kmp_places_syntax_error_fallback(name, gran);
3189 return;
3190 }
3191 scan++; // skip '('
3192
3193 SKIP_WS(scan);
3194 next = scan;
3195 SKIP_DIGITS(next);
3196 count = __kmp_str_to_int(scan, *next);
3197 KMP_ASSERT(count >= 0);
3198 scan = next;
3199
3200 SKIP_WS(scan);
3201 if (*scan != ')') {
3202 __kmp_places_syntax_error_fallback(name, gran);
3203 return;
3204 }
3205 scan++; // skip ')'
3206
3207 SKIP_WS(scan);
3208 if (*scan != '\0') {
3209 KMP_WARNING(ParseExtraCharsWarn, name, scan);
3210 }
3211 __kmp_affinity_num_places = count;
3212}
3213
3214static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
3215 void *data) {
3216 enum affinity_type type = __kmp_affinity.type;
3217 const char *proclist = __kmp_affinity.proclist;
3218 kmp_hw_t gran = __kmp_affinity.gran;
3219
3220 if (__kmp_env_format) {
3221 KMP_STR_BUF_PRINT_NAME;
3222 } else {
3223 __kmp_str_buf_print(buffer, " %s", name);
3224 }
3225 if ((__kmp_nested_proc_bind.used == 0) ||
3226 (__kmp_nested_proc_bind.bind_types == NULL) ||
3227 (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
3228 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3229 } else if (type == affinity_explicit) {
3230 if (proclist != NULL) {
3231 __kmp_str_buf_print(buffer, "='%s'\n", proclist);
3232 } else {
3233 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3234 }
3235 } else if (type == affinity_compact) {
3236 int num;
3237 if (__kmp_affinity.num_masks > 0) {
3238 num = __kmp_affinity.num_masks;
3239 } else if (__kmp_affinity_num_places > 0) {
3240 num = __kmp_affinity_num_places;
3241 } else {
3242 num = 0;
3243 }
3244 if (gran != KMP_HW_UNKNOWN) {
3245 // If core_types or core_effs, just print and return
3246 if (__kmp_affinity.flags.core_types_gran) {
3247 __kmp_str_buf_print(buffer, "='%s'\n", "core_types");
3248 return;
3249 }
3250 if (__kmp_affinity.flags.core_effs_gran) {
3251 __kmp_str_buf_print(buffer, "='%s'\n", "core_effs");
3252 return;
3253 }
3254
3255 // threads, cores, sockets, cores:<attribute>, etc.
3256 const char *name = __kmp_hw_get_keyword(gran, true);
3257 __kmp_str_buf_print(buffer, "='%s", name);
3258
3259 // Add core attributes if it exists
3260 if (__kmp_affinity.core_attr_gran.valid) {
3261 kmp_hw_core_type_t ct =
3262 (kmp_hw_core_type_t)__kmp_affinity.core_attr_gran.core_type;
3263 int eff = __kmp_affinity.core_attr_gran.core_eff;
3264 if (ct != KMP_HW_CORE_TYPE_UNKNOWN) {
3265 const char *ct_name = __kmp_hw_get_core_type_keyword(ct);
3266 __kmp_str_buf_print(buffer, ":%s", ct_name);
3267 } else if (eff >= 0 && eff < KMP_HW_MAX_NUM_CORE_EFFS) {
3268 __kmp_str_buf_print(buffer, ":eff%d", eff);
3269 }
3270 }
3271
3272 // Add the '(#)' part if it exists
3273 if (num > 0)
3274 __kmp_str_buf_print(buffer, "(%d)", num);
3275 __kmp_str_buf_print(buffer, "'\n");
3276 } else {
3277 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3278 }
3279 } else {
3280 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3281 }
3282}
3283
3284static void __kmp_stg_parse_topology_method(char const *name, char const *value,
3285 void *data) {
3286 if (__kmp_str_match("all", 1, value)) {
3287 __kmp_affinity_top_method = affinity_top_method_all;
3288 }
3289#if KMP_HWLOC_ENABLED
3290 else if (__kmp_str_match("hwloc", 1, value)) {
3291 __kmp_affinity_top_method = affinity_top_method_hwloc;
3292 }
3293#endif // KMP_HWLOC_ENABLED
3294#if KMP_ARCH_X86 || KMP_ARCH_X86_64
3295 else if (__kmp_str_match("cpuid_leaf31", 12, value) ||
3296 __kmp_str_match("cpuid 1f", 8, value) ||
3297 __kmp_str_match("cpuid 31", 8, value) ||
3298 __kmp_str_match("cpuid1f", 7, value) ||
3299 __kmp_str_match("cpuid31", 7, value) ||
3300 __kmp_str_match("leaf 1f", 7, value) ||
3301 __kmp_str_match("leaf 31", 7, value) ||
3302 __kmp_str_match("leaf1f", 6, value) ||
3303 __kmp_str_match("leaf31", 6, value)) {
3304 __kmp_affinity_top_method = affinity_top_method_x2apicid_1f;
3305 } else if (__kmp_str_match("x2apic id", 9, value) ||
3306 __kmp_str_match("x2apic_id", 9, value) ||
3307 __kmp_str_match("x2apic-id", 9, value) ||
3308 __kmp_str_match("x2apicid", 8, value) ||
3309 __kmp_str_match("cpuid leaf 11", 13, value) ||
3310 __kmp_str_match("cpuid_leaf_11", 13, value) ||
3311 __kmp_str_match("cpuid-leaf-11", 13, value) ||
3312 __kmp_str_match("cpuid leaf11", 12, value) ||
3313 __kmp_str_match("cpuid_leaf11", 12, value) ||
3314 __kmp_str_match("cpuid-leaf11", 12, value) ||
3315 __kmp_str_match("cpuidleaf 11", 12, value) ||
3316 __kmp_str_match("cpuidleaf_11", 12, value) ||
3317 __kmp_str_match("cpuidleaf-11", 12, value) ||
3318 __kmp_str_match("cpuidleaf11", 11, value) ||
3319 __kmp_str_match("cpuid 11", 8, value) ||
3320 __kmp_str_match("cpuid_11", 8, value) ||
3321 __kmp_str_match("cpuid-11", 8, value) ||
3322 __kmp_str_match("cpuid11", 7, value) ||
3323 __kmp_str_match("leaf 11", 7, value) ||
3324 __kmp_str_match("leaf_11", 7, value) ||
3325 __kmp_str_match("leaf-11", 7, value) ||
3326 __kmp_str_match("leaf11", 6, value)) {
3327 __kmp_affinity_top_method = affinity_top_method_x2apicid;
3328 } else if (__kmp_str_match("apic id", 7, value) ||
3329 __kmp_str_match("apic_id", 7, value) ||
3330 __kmp_str_match("apic-id", 7, value) ||
3331 __kmp_str_match("apicid", 6, value) ||
3332 __kmp_str_match("cpuid leaf 4", 12, value) ||
3333 __kmp_str_match("cpuid_leaf_4", 12, value) ||
3334 __kmp_str_match("cpuid-leaf-4", 12, value) ||
3335 __kmp_str_match("cpuid leaf4", 11, value) ||
3336 __kmp_str_match("cpuid_leaf4", 11, value) ||
3337 __kmp_str_match("cpuid-leaf4", 11, value) ||
3338 __kmp_str_match("cpuidleaf 4", 11, value) ||
3339 __kmp_str_match("cpuidleaf_4", 11, value) ||
3340 __kmp_str_match("cpuidleaf-4", 11, value) ||
3341 __kmp_str_match("cpuidleaf4", 10, value) ||
3342 __kmp_str_match("cpuid 4", 7, value) ||
3343 __kmp_str_match("cpuid_4", 7, value) ||
3344 __kmp_str_match("cpuid-4", 7, value) ||
3345 __kmp_str_match("cpuid4", 6, value) ||
3346 __kmp_str_match("leaf 4", 6, value) ||
3347 __kmp_str_match("leaf_4", 6, value) ||
3348 __kmp_str_match("leaf-4", 6, value) ||
3349 __kmp_str_match("leaf4", 5, value)) {
3350 __kmp_affinity_top_method = affinity_top_method_apicid;
3351 }
3352#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
3353 else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
3354 __kmp_str_match("cpuinfo", 5, value)) {
3355 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
3356 }
3357#if KMP_GROUP_AFFINITY
3358 else if (__kmp_str_match("group", 1, value)) {
3359 KMP_WARNING(StgDeprecatedValue, name, value, "all");
3360 __kmp_affinity_top_method = affinity_top_method_group;
3361 }
3362#endif /* KMP_GROUP_AFFINITY */
3363 else if (__kmp_str_match("flat", 1, value)) {
3364 __kmp_affinity_top_method = affinity_top_method_flat;
3365 } else {
3366 KMP_WARNING(StgInvalidValue, name, value);
3367 }
3368} // __kmp_stg_parse_topology_method
3369
3370static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
3371 char const *name, void *data) {
3372 char const *value = NULL;
3373
3374 switch (__kmp_affinity_top_method) {
3375 case affinity_top_method_default:
3376 value = "default";
3377 break;
3378
3379 case affinity_top_method_all:
3380 value = "all";
3381 break;
3382
3383#if KMP_ARCH_X86 || KMP_ARCH_X86_64
3384 case affinity_top_method_x2apicid_1f:
3385 value = "x2APIC id leaf 0x1f";
3386 break;
3387
3388 case affinity_top_method_x2apicid:
3389 value = "x2APIC id leaf 0xb";
3390 break;
3391
3392 case affinity_top_method_apicid:
3393 value = "APIC id";
3394 break;
3395#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
3396
3397#if KMP_HWLOC_ENABLED
3398 case affinity_top_method_hwloc:
3399 value = "hwloc";
3400 break;
3401#endif // KMP_HWLOC_ENABLED
3402
3403 case affinity_top_method_cpuinfo:
3404 value = "cpuinfo";
3405 break;
3406
3407#if KMP_GROUP_AFFINITY
3408 case affinity_top_method_group:
3409 value = "group";
3410 break;
3411#endif /* KMP_GROUP_AFFINITY */
3412
3413 case affinity_top_method_flat:
3414 value = "flat";
3415 break;
3416 }
3417
3418 if (value != NULL) {
3419 __kmp_stg_print_str(buffer, name, value);
3420 }
3421} // __kmp_stg_print_topology_method
3422
3423// KMP_TEAMS_PROC_BIND
3424struct kmp_proc_bind_info_t {
3425 const char *name;
3426 kmp_proc_bind_t proc_bind;
3427};
3428static kmp_proc_bind_info_t proc_bind_table[] = {
3429 {"spread", proc_bind_spread},
3430 {"true", proc_bind_spread},
3431 {"close", proc_bind_close},
3432 // teams-bind = false means "replicate the primary thread's affinity"
3433 {"false", proc_bind_primary},
3434 {"primary", proc_bind_primary}};
3435static void __kmp_stg_parse_teams_proc_bind(char const *name, char const *value,
3436 void *data) {
3437 int valid;
3438 const char *end;
3439 valid = 0;
3440 for (size_t i = 0; i < sizeof(proc_bind_table) / sizeof(proc_bind_table[0]);
3441 ++i) {
3442 if (__kmp_match_str(proc_bind_table[i].name, value, &end)) {
3443 __kmp_teams_proc_bind = proc_bind_table[i].proc_bind;
3444 valid = 1;
3445 break;
3446 }
3447 }
3448 if (!valid) {
3449 KMP_WARNING(StgInvalidValue, name, value);
3450 }
3451}
3452static void __kmp_stg_print_teams_proc_bind(kmp_str_buf_t *buffer,
3453 char const *name, void *data) {
3454 const char *value = KMP_I18N_STR(NotDefined);
3455 for (size_t i = 0; i < sizeof(proc_bind_table) / sizeof(proc_bind_table[0]);
3456 ++i) {
3457 if (__kmp_teams_proc_bind == proc_bind_table[i].proc_bind) {
3458 value = proc_bind_table[i].name;
3459 break;
3460 }
3461 }
3462 __kmp_stg_print_str(buffer, name, value);
3463}
3464#endif /* KMP_AFFINITY_SUPPORTED */
3465
3466// OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
3467// OMP_PLACES / place-partition-var is not.
3468static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
3469 void *data) {
3470 kmp_setting_t **rivals = (kmp_setting_t **)data;
3471 int rc;
3472
3473 rc = __kmp_stg_check_rivals(name, value, rivals);
3474 if (rc) {
3475 return;
3476 }
3477
3478 // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
3479 KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
3480 (__kmp_nested_proc_bind.used > 0));
3481
3482 const char *buf = value;
3483 const char *next;
3484
3485 SKIP_WS(buf);
3486
3487 next = buf;
3488 if (__kmp_match_str("disabled", buf, &next)) {
3489 buf = next;
3490 SKIP_WS(buf);
3491#if KMP_AFFINITY_SUPPORTED
3492 __kmp_affinity.type = affinity_disabled;
3493#endif /* KMP_AFFINITY_SUPPORTED */
3494 __kmp_nested_proc_bind.used = 1;
3495 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3496 } else if (__kmp_match_str("false", buf, &next)) {
3497 buf = next;
3498 SKIP_WS(buf);
3499#if KMP_AFFINITY_SUPPORTED
3500 __kmp_affinity.type = affinity_none;
3501#endif /* KMP_AFFINITY_SUPPORTED */
3502 __kmp_nested_proc_bind.used = 1;
3503 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3504 } else if (__kmp_match_str("true", buf, &next)) {
3505 buf = next;
3506 SKIP_WS(buf);
3507 __kmp_nested_proc_bind.used = 1;
3508 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3509 } else {
3510 // Count the number of values in the env var string
3511 const char *scan;
3512 int nelem = 1;
3513 for (scan = buf; *scan != '\0'; scan++) {
3514 if (*scan == ',') {
3515 nelem++;
3516 }
3517 }
3518
3519 // Create / expand the nested proc_bind array as needed
3520 if (__kmp_nested_proc_bind.size < nelem) {
3521 __kmp_nested_proc_bind.bind_types =
3522 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3523 __kmp_nested_proc_bind.bind_types,
3524 sizeof(kmp_proc_bind_t) * nelem);
3525 if (__kmp_nested_proc_bind.bind_types == NULL) {
3526 KMP_FATAL(MemoryAllocFailed);
3527 }
3528 __kmp_nested_proc_bind.size = nelem;
3529 }
3530 __kmp_nested_proc_bind.used = nelem;
3531
3532 if (nelem > 1 && !__kmp_dflt_max_active_levels_set)
3533 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
3534
3535 // Save values in the nested proc_bind array
3536 int i = 0;
3537 for (;;) {
3538 enum kmp_proc_bind_t bind;
3539
3540 if (__kmp_match_str("master", buf, &next) ||
3541 __kmp_match_str("primary", buf, &next)) {
3542 buf = next;
3543 SKIP_WS(buf);
3544 bind = proc_bind_primary;
3545 } else if (__kmp_match_str("close", buf, &next)) {
3546 buf = next;
3547 SKIP_WS(buf);
3548 bind = proc_bind_close;
3549 } else if (__kmp_match_str("spread", buf, &next)) {
3550 buf = next;
3551 SKIP_WS(buf);
3552 bind = proc_bind_spread;
3553 } else {
3554 KMP_WARNING(StgInvalidValue, name, value);
3555 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3556 __kmp_nested_proc_bind.used = 1;
3557 return;
3558 }
3559
3560 __kmp_nested_proc_bind.bind_types[i++] = bind;
3561 if (i >= nelem) {
3562 break;
3563 }
3564 if (*buf != ',') {
3565 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3566 while (*buf != ',')
3567 buf++;
3568 }
3569 buf++;
3570 SKIP_WS(buf);
3571 }
3572 SKIP_WS(buf);
3573 }
3574 if (*buf != '\0') {
3575 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3576 }
3577}
3578
3579static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
3580 void *data) {
3581 int nelem = __kmp_nested_proc_bind.used;
3582 if (__kmp_env_format) {
3583 KMP_STR_BUF_PRINT_NAME;
3584 } else {
3585 __kmp_str_buf_print(buffer, " %s", name);
3586 }
3587 if (nelem == 0) {
3588 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3589 } else {
3590 int i;
3591 __kmp_str_buf_print(buffer, "='", name);
3592 for (i = 0; i < nelem; i++) {
3593 switch (__kmp_nested_proc_bind.bind_types[i]) {
3594 case proc_bind_false:
3595 __kmp_str_buf_print(buffer, "false");
3596 break;
3597
3598 case proc_bind_true:
3599 __kmp_str_buf_print(buffer, "true");
3600 break;
3601
3602 case proc_bind_primary:
3603 __kmp_str_buf_print(buffer, "primary");
3604 break;
3605
3606 case proc_bind_close:
3607 __kmp_str_buf_print(buffer, "close");
3608 break;
3609
3610 case proc_bind_spread:
3611 __kmp_str_buf_print(buffer, "spread");
3612 break;
3613
3614 case proc_bind_intel:
3615 __kmp_str_buf_print(buffer, "intel");
3616 break;
3617
3618 case proc_bind_default:
3619 __kmp_str_buf_print(buffer, "default");
3620 break;
3621 }
3622 if (i < nelem - 1) {
3623 __kmp_str_buf_print(buffer, ",");
3624 }
3625 }
3626 __kmp_str_buf_print(buffer, "'\n");
3627 }
3628}
3629
3630static void __kmp_stg_parse_display_affinity(char const *name,
3631 char const *value, void *data) {
3632 __kmp_stg_parse_bool(name, value, &__kmp_display_affinity);
3633}
3634static void __kmp_stg_print_display_affinity(kmp_str_buf_t *buffer,
3635 char const *name, void *data) {
3636 __kmp_stg_print_bool(buffer, name, __kmp_display_affinity);
3637}
3638static void __kmp_stg_parse_affinity_format(char const *name, char const *value,
3639 void *data) {
3640 size_t length = KMP_STRLEN(value);
3641 __kmp_strncpy_truncate(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, value,
3642 length);
3643}
3644static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer,
3645 char const *name, void *data) {
3646 if (__kmp_env_format) {
3647 KMP_STR_BUF_PRINT_NAME_EX(name);
3648 } else {
3649 __kmp_str_buf_print(buffer, " %s='", name);
3650 }
3651 __kmp_str_buf_print(buffer, "%s'\n", __kmp_affinity_format);
3652}
3653
3654/*-----------------------------------------------------------------------------
3655OMP_ALLOCATOR sets default allocator. Here is the grammar:
3656
3657<allocator> |= <predef-allocator> | <predef-mem-space> |
3658 <predef-mem-space>:<traits>
3659<traits> |= <trait>=<value> | <trait>=<value>,<traits>
3660<predef-allocator> |= omp_default_mem_alloc | omp_large_cap_mem_alloc |
3661 omp_const_mem_alloc | omp_high_bw_mem_alloc |
3662 omp_low_lat_mem_alloc | omp_cgroup_mem_alloc |
3663 omp_pteam_mem_alloc | omp_thread_mem_alloc
3664<predef-mem-space> |= omp_default_mem_space | omp_large_cap_mem_space |
3665 omp_const_mem_space | omp_high_bw_mem_space |
3666 omp_low_lat_mem_space
3667<trait> |= sync_hint | alignment | access | pool_size | fallback |
3668 fb_data | pinned | partition
3669<value> |= one of the allowed values of trait |
3670 non-negative integer | <predef-allocator>
3671-----------------------------------------------------------------------------*/
3672
3673static void __kmp_stg_parse_allocator(char const *name, char const *value,
3674 void *data) {
3675 const char *buf = value;
3676 const char *next, *scan, *start;
3677 char *key;
3678 omp_allocator_handle_t al;
3679 omp_memspace_handle_t ms = omp_default_mem_space;
3680 bool is_memspace = false;
3681 int ntraits = 0, count = 0;
3682
3683 SKIP_WS(buf);
3684 next = buf;
3685 const char *delim = strchr(buf, ':');
3686 const char *predef_mem_space = strstr(buf, "mem_space");
3687
3688 bool is_memalloc = (!predef_mem_space && !delim) ? true : false;
3689
3690 // Count the number of traits in the env var string
3691 if (delim) {
3692 ntraits = 1;
3693 for (scan = buf; *scan != '\0'; scan++) {
3694 if (*scan == ',')
3695 ntraits++;
3696 }
3697 }
3698 omp_alloctrait_t *traits =
3699 (omp_alloctrait_t *)KMP_ALLOCA(ntraits * sizeof(omp_alloctrait_t));
3700
3701// Helper macros
3702#define IS_POWER_OF_TWO(n) (((n) & ((n)-1)) == 0)
3703
3704#define GET_NEXT(sentinel) \
3705 { \
3706 SKIP_WS(next); \
3707 if (*next == sentinel) \
3708 next++; \
3709 SKIP_WS(next); \
3710 scan = next; \
3711 }
3712
3713#define SKIP_PAIR(key) \
3714 { \
3715 char const str_delimiter[] = {',', 0}; \
3716 char *value = __kmp_str_token(CCAST(char *, scan), str_delimiter, \
3717 CCAST(char **, &next)); \
3718 KMP_WARNING(StgInvalidValue, key, value); \
3719 ntraits--; \
3720 SKIP_WS(next); \
3721 scan = next; \
3722 }
3723
3724#define SET_KEY() \
3725 { \
3726 char const str_delimiter[] = {'=', 0}; \
3727 key = __kmp_str_token(CCAST(char *, start), str_delimiter, \
3728 CCAST(char **, &next)); \
3729 scan = next; \
3730 }
3731
3732 scan = next;
3733 while (*next != '\0') {
3734 if (is_memalloc ||
3735 __kmp_match_str("fb_data", scan, &next)) { // allocator check
3736 start = scan;
3737 GET_NEXT('=');
3738 // check HBW and LCAP first as the only non-default supported
3739 if (__kmp_match_str("omp_high_bw_mem_alloc", scan, &next)) {
3740 SKIP_WS(next);
3741 if (is_memalloc) {
3742 if (__kmp_hwloc_available || __kmp_memkind_available) {
3743 __kmp_def_allocator = omp_high_bw_mem_alloc;
3744 return;
3745 } else {
3746 KMP_WARNING(OmpNoAllocator, "omp_high_bw_mem_alloc");
3747 }
3748 } else {
3749 traits[count].key = omp_atk_fb_data;
3750 traits[count].value = RCAST(omp_uintptr_t, omp_high_bw_mem_alloc);
3751 }
3752 } else if (__kmp_match_str("omp_large_cap_mem_alloc", scan, &next)) {
3753 SKIP_WS(next);
3754 if (is_memalloc) {
3755 if (__kmp_hwloc_available || __kmp_memkind_available) {
3756 __kmp_def_allocator = omp_large_cap_mem_alloc;
3757 return;
3758 } else {
3759 KMP_WARNING(OmpNoAllocator, "omp_large_cap_mem_alloc");
3760 }
3761 } else {
3762 traits[count].key = omp_atk_fb_data;
3763 traits[count].value = RCAST(omp_uintptr_t, omp_large_cap_mem_alloc);
3764 }
3765 } else if (__kmp_match_str("omp_default_mem_alloc", scan, &next)) {
3766 // default requested
3767 SKIP_WS(next);
3768 if (!is_memalloc) {
3769 traits[count].key = omp_atk_fb_data;
3770 traits[count].value = RCAST(omp_uintptr_t, omp_default_mem_alloc);
3771 }
3772 } else if (__kmp_match_str("omp_const_mem_alloc", scan, &next)) {
3773 SKIP_WS(next);
3774 if (is_memalloc) {
3775 KMP_WARNING(OmpNoAllocator, "omp_const_mem_alloc");
3776 } else {
3777 traits[count].key = omp_atk_fb_data;
3778 traits[count].value = RCAST(omp_uintptr_t, omp_const_mem_alloc);
3779 }
3780 } else if (__kmp_match_str("omp_low_lat_mem_alloc", scan, &next)) {
3781 SKIP_WS(next);
3782 if (is_memalloc) {
3783 KMP_WARNING(OmpNoAllocator, "omp_low_lat_mem_alloc");
3784 } else {
3785 traits[count].key = omp_atk_fb_data;
3786 traits[count].value = RCAST(omp_uintptr_t, omp_low_lat_mem_alloc);
3787 }
3788 } else if (__kmp_match_str("omp_cgroup_mem_alloc", scan, &next)) {
3789 SKIP_WS(next);
3790 if (is_memalloc) {
3791 KMP_WARNING(OmpNoAllocator, "omp_cgroup_mem_alloc");
3792 } else {
3793 traits[count].key = omp_atk_fb_data;
3794 traits[count].value = RCAST(omp_uintptr_t, omp_cgroup_mem_alloc);
3795 }
3796 } else if (__kmp_match_str("omp_pteam_mem_alloc", scan, &next)) {
3797 SKIP_WS(next);
3798 if (is_memalloc) {
3799 KMP_WARNING(OmpNoAllocator, "omp_pteam_mem_alloc");
3800 } else {
3801 traits[count].key = omp_atk_fb_data;
3802 traits[count].value = RCAST(omp_uintptr_t, omp_pteam_mem_alloc);
3803 }
3804 } else if (__kmp_match_str("omp_thread_mem_alloc", scan, &next)) {
3805 SKIP_WS(next);
3806 if (is_memalloc) {
3807 KMP_WARNING(OmpNoAllocator, "omp_thread_mem_alloc");
3808 } else {
3809 traits[count].key = omp_atk_fb_data;
3810 traits[count].value = RCAST(omp_uintptr_t, omp_thread_mem_alloc);
3811 }
3812 } else {
3813 if (!is_memalloc) {
3814 SET_KEY();
3815 SKIP_PAIR(key);
3816 continue;
3817 }
3818 }
3819 if (is_memalloc) {
3820 __kmp_def_allocator = omp_default_mem_alloc;
3821 if (next == buf || *next != '\0') {
3822 // either no match or extra symbols present after the matched token
3823 KMP_WARNING(StgInvalidValue, name, value);
3824 }
3825 return;
3826 } else {
3827 ++count;
3828 if (count == ntraits)
3829 break;
3830 GET_NEXT(',');
3831 }
3832 } else { // memspace
3833 if (!is_memspace) {
3834 if (__kmp_match_str("omp_default_mem_space", scan, &next)) {
3835 SKIP_WS(next);
3836 ms = omp_default_mem_space;
3837 } else if (__kmp_match_str("omp_large_cap_mem_space", scan, &next)) {
3838 SKIP_WS(next);
3839 ms = omp_large_cap_mem_space;
3840 } else if (__kmp_match_str("omp_const_mem_space", scan, &next)) {
3841 SKIP_WS(next);
3842 ms = omp_const_mem_space;
3843 } else if (__kmp_match_str("omp_high_bw_mem_space", scan, &next)) {
3844 SKIP_WS(next);
3845 ms = omp_high_bw_mem_space;
3846 } else if (__kmp_match_str("omp_low_lat_mem_space", scan, &next)) {
3847 SKIP_WS(next);
3848 ms = omp_low_lat_mem_space;
3849 } else {
3850 __kmp_def_allocator = omp_default_mem_alloc;
3851 if (next == buf || *next != '\0') {
3852 // either no match or extra symbols present after the matched token
3853 KMP_WARNING(StgInvalidValue, name, value);
3854 }
3855 return;
3856 }
3857 is_memspace = true;
3858 }
3859 if (delim) { // traits
3860 GET_NEXT(':');
3861 start = scan;
3862 if (__kmp_match_str("sync_hint", scan, &next)) {
3863 GET_NEXT('=');
3864 traits[count].key = omp_atk_sync_hint;
3865 if (__kmp_match_str("contended", scan, &next)) {
3866 traits[count].value = omp_atv_contended;
3867 } else if (__kmp_match_str("uncontended", scan, &next)) {
3868 traits[count].value = omp_atv_uncontended;
3869 } else if (__kmp_match_str("serialized", scan, &next)) {
3870 traits[count].value = omp_atv_serialized;
3871 } else if (__kmp_match_str("private", scan, &next)) {
3872 traits[count].value = omp_atv_private;
3873 } else {
3874 SET_KEY();
3875 SKIP_PAIR(key);
3876 continue;
3877 }
3878 } else if (__kmp_match_str("alignment", scan, &next)) {
3879 GET_NEXT('=');
3880 if (!isdigit(*next)) {
3881 SET_KEY();
3882 SKIP_PAIR(key);
3883 continue;
3884 }
3885 SKIP_DIGITS(next);
3886 int n = __kmp_str_to_int(scan, ',');
3887 if (n < 0 || !IS_POWER_OF_TWO(n)) {
3888 SET_KEY();
3889 SKIP_PAIR(key);
3890 continue;
3891 }
3892 traits[count].key = omp_atk_alignment;
3893 traits[count].value = n;
3894 } else if (__kmp_match_str("access", scan, &next)) {
3895 GET_NEXT('=');
3896 traits[count].key = omp_atk_access;
3897 if (__kmp_match_str("all", scan, &next)) {
3898 traits[count].value = omp_atv_all;
3899 } else if (__kmp_match_str("cgroup", scan, &next)) {
3900 traits[count].value = omp_atv_cgroup;
3901 } else if (__kmp_match_str("pteam", scan, &next)) {
3902 traits[count].value = omp_atv_pteam;
3903 } else if (__kmp_match_str("thread", scan, &next)) {
3904 traits[count].value = omp_atv_thread;
3905 } else {
3906 SET_KEY();
3907 SKIP_PAIR(key);
3908 continue;
3909 }
3910 } else if (__kmp_match_str("pool_size", scan, &next)) {
3911 GET_NEXT('=');
3912 if (!isdigit(*next)) {
3913 SET_KEY();
3914 SKIP_PAIR(key);
3915 continue;
3916 }
3917 SKIP_DIGITS(next);
3918 int n = __kmp_str_to_int(scan, ',');
3919 if (n < 0) {
3920 SET_KEY();
3921 SKIP_PAIR(key);
3922 continue;
3923 }
3924 traits[count].key = omp_atk_pool_size;
3925 traits[count].value = n;
3926 } else if (__kmp_match_str("fallback", scan, &next)) {
3927 GET_NEXT('=');
3928 traits[count].key = omp_atk_fallback;
3929 if (__kmp_match_str("default_mem_fb", scan, &next)) {
3930 traits[count].value = omp_atv_default_mem_fb;
3931 } else if (__kmp_match_str("null_fb", scan, &next)) {
3932 traits[count].value = omp_atv_null_fb;
3933 } else if (__kmp_match_str("abort_fb", scan, &next)) {
3934 traits[count].value = omp_atv_abort_fb;
3935 } else if (__kmp_match_str("allocator_fb", scan, &next)) {
3936 traits[count].value = omp_atv_allocator_fb;
3937 } else {
3938 SET_KEY();
3939 SKIP_PAIR(key);
3940 continue;
3941 }
3942 } else if (__kmp_match_str("pinned", scan, &next)) {
3943 GET_NEXT('=');
3944 traits[count].key = omp_atk_pinned;
3945 if (__kmp_str_match_true(next)) {
3946 traits[count].value = omp_atv_true;
3947 } else if (__kmp_str_match_false(next)) {
3948 traits[count].value = omp_atv_false;
3949 } else {
3950 SET_KEY();
3951 SKIP_PAIR(key);
3952 continue;
3953 }
3954 } else if (__kmp_match_str("partition", scan, &next)) {
3955 GET_NEXT('=');
3956 traits[count].key = omp_atk_partition;
3957 if (__kmp_match_str("environment", scan, &next)) {
3958 traits[count].value = omp_atv_environment;
3959 } else if (__kmp_match_str("nearest", scan, &next)) {
3960 traits[count].value = omp_atv_nearest;
3961 } else if (__kmp_match_str("blocked", scan, &next)) {
3962 traits[count].value = omp_atv_blocked;
3963 } else if (__kmp_match_str("interleaved", scan, &next)) {
3964 traits[count].value = omp_atv_interleaved;
3965 } else {
3966 SET_KEY();
3967 SKIP_PAIR(key);
3968 continue;
3969 }
3970 } else {
3971 SET_KEY();
3972 SKIP_PAIR(key);
3973 continue;
3974 }
3975 SKIP_WS(next);
3976 ++count;
3977 if (count == ntraits)
3978 break;
3979 GET_NEXT(',');
3980 } // traits
3981 } // memspace
3982 } // while
3983 al = __kmpc_init_allocator(__kmp_get_gtid(), ms, ntraits, traits);
3984 __kmp_def_allocator = (al == omp_null_allocator) ? omp_default_mem_alloc : al;
3985}
3986
3987static void __kmp_stg_print_allocator(kmp_str_buf_t *buffer, char const *name,
3988 void *data) {
3989 if (__kmp_def_allocator == omp_default_mem_alloc) {
3990 __kmp_stg_print_str(buffer, name, "omp_default_mem_alloc");
3991 } else if (__kmp_def_allocator == omp_high_bw_mem_alloc) {
3992 __kmp_stg_print_str(buffer, name, "omp_high_bw_mem_alloc");
3993 } else if (__kmp_def_allocator == omp_large_cap_mem_alloc) {
3994 __kmp_stg_print_str(buffer, name, "omp_large_cap_mem_alloc");
3995 } else if (__kmp_def_allocator == omp_const_mem_alloc) {
3996 __kmp_stg_print_str(buffer, name, "omp_const_mem_alloc");
3997 } else if (__kmp_def_allocator == omp_low_lat_mem_alloc) {
3998 __kmp_stg_print_str(buffer, name, "omp_low_lat_mem_alloc");
3999 } else if (__kmp_def_allocator == omp_cgroup_mem_alloc) {
4000 __kmp_stg_print_str(buffer, name, "omp_cgroup_mem_alloc");
4001 } else if (__kmp_def_allocator == omp_pteam_mem_alloc) {
4002 __kmp_stg_print_str(buffer, name, "omp_pteam_mem_alloc");
4003 } else if (__kmp_def_allocator == omp_thread_mem_alloc) {
4004 __kmp_stg_print_str(buffer, name, "omp_thread_mem_alloc");
4005 }
4006}
4007
4008// -----------------------------------------------------------------------------
4009// OMP_DYNAMIC
4010
4011static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
4012 void *data) {
4013 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
4014} // __kmp_stg_parse_omp_dynamic
4015
4016static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
4017 void *data) {
4018 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
4019} // __kmp_stg_print_omp_dynamic
4020
4021static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
4022 char const *value, void *data) {
4023 if (TCR_4(__kmp_init_parallel)) {
4024 KMP_WARNING(EnvParallelWarn, name);
4025 __kmp_env_toPrint(name, 0);
4026 return;
4027 }
4028#ifdef USE_LOAD_BALANCE
4029 else if (__kmp_str_match("load balance", 2, value) ||
4030 __kmp_str_match("load_balance", 2, value) ||
4031 __kmp_str_match("load-balance", 2, value) ||
4032 __kmp_str_match("loadbalance", 2, value) ||
4033 __kmp_str_match("balance", 1, value)) {
4034 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
4035 }
4036#endif /* USE_LOAD_BALANCE */
4037 else if (__kmp_str_match("thread limit", 1, value) ||
4038 __kmp_str_match("thread_limit", 1, value) ||
4039 __kmp_str_match("thread-limit", 1, value) ||
4040 __kmp_str_match("threadlimit", 1, value) ||
4041 __kmp_str_match("limit", 2, value)) {
4042 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
4043 } else if (__kmp_str_match("random", 1, value)) {
4044 __kmp_global.g.g_dynamic_mode = dynamic_random;
4045 } else {
4046 KMP_WARNING(StgInvalidValue, name, value);
4047 }
4048} //__kmp_stg_parse_kmp_dynamic_mode
4049
4050static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
4051 char const *name, void *data) {
4052#if KMP_DEBUG
4053 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
4054 __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
4055 }
4056#ifdef USE_LOAD_BALANCE
4057 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
4058 __kmp_stg_print_str(buffer, name, "load balance");
4059 }
4060#endif /* USE_LOAD_BALANCE */
4061 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
4062 __kmp_stg_print_str(buffer, name, "thread limit");
4063 } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
4064 __kmp_stg_print_str(buffer, name, "random");
4065 } else {
4066 KMP_ASSERT(0);
4067 }
4068#endif /* KMP_DEBUG */
4069} // __kmp_stg_print_kmp_dynamic_mode
4070
4071#ifdef USE_LOAD_BALANCE
4072
4073// -----------------------------------------------------------------------------
4074// KMP_LOAD_BALANCE_INTERVAL
4075
4076static void __kmp_stg_parse_ld_balance_interval(char const *name,
4077 char const *value, void *data) {
4078 double interval = __kmp_convert_to_double(value);
4079 if (interval >= 0) {
4080 __kmp_load_balance_interval = interval;
4081 } else {
4082 KMP_WARNING(StgInvalidValue, name, value);
4083 }
4084} // __kmp_stg_parse_load_balance_interval
4085
4086static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
4087 char const *name, void *data) {
4088#if KMP_DEBUG
4089 __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
4090 __kmp_load_balance_interval);
4091#endif /* KMP_DEBUG */
4092} // __kmp_stg_print_load_balance_interval
4093
4094#endif /* USE_LOAD_BALANCE */
4095
4096// -----------------------------------------------------------------------------
4097// KMP_INIT_AT_FORK
4098
4099static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
4100 void *data) {
4101 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
4102 if (__kmp_need_register_atfork) {
4103 __kmp_need_register_atfork_specified = TRUE;
4104 }
4105} // __kmp_stg_parse_init_at_fork
4106
4107static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
4108 char const *name, void *data) {
4109 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
4110} // __kmp_stg_print_init_at_fork
4111
4112// -----------------------------------------------------------------------------
4113// KMP_SCHEDULE
4114
4115static void __kmp_stg_parse_schedule(char const *name, char const *value,
4116 void *data) {
4117
4118 if (value != NULL) {
4119 size_t length = KMP_STRLEN(value);
4120 if (length > INT_MAX) {
4121 KMP_WARNING(LongValue, name);
4122 } else {
4123 const char *semicolon;
4124 if (value[length - 1] == '"' || value[length - 1] == '\'')
4125 KMP_WARNING(UnbalancedQuotes, name);
4126 do {
4127 char sentinel;
4128
4129 semicolon = strchr(value, ';');
4130 if (*value && semicolon != value) {
4131 const char *comma = strchr(value, ',');
4132
4133 if (comma) {
4134 ++comma;
4135 sentinel = ',';
4136 } else
4137 sentinel = ';';
4138 if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
4139 if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
4140 __kmp_static = kmp_sch_static_greedy;
4141 continue;
4142 } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
4143 ';')) {
4144 __kmp_static = kmp_sch_static_balanced;
4145 continue;
4146 }
4147 } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
4148 sentinel)) {
4149 if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
4150 __kmp_guided = kmp_sch_guided_iterative_chunked;
4151 continue;
4152 } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
4153 ';')) {
4154 /* analytical not allowed for too many threads */
4155 __kmp_guided = kmp_sch_guided_analytical_chunked;
4156 continue;
4157 }
4158 }
4159 KMP_WARNING(InvalidClause, name, value);
4160 } else
4161 KMP_WARNING(EmptyClause, name);
4162 } while ((value = semicolon ? semicolon + 1 : NULL));
4163 }
4164 }
4165
4166} // __kmp_stg_parse__schedule
4167
4168static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
4169 void *data) {
4170 if (__kmp_env_format) {
4171 KMP_STR_BUF_PRINT_NAME_EX(name);
4172 } else {
4173 __kmp_str_buf_print(buffer, " %s='", name);
4174 }
4175 if (__kmp_static == kmp_sch_static_greedy) {
4176 __kmp_str_buf_print(buffer, "%s", "static,greedy");
4177 } else if (__kmp_static == kmp_sch_static_balanced) {
4178 __kmp_str_buf_print(buffer, "%s", "static,balanced");
4179 }
4180 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
4181 __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
4182 } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
4183 __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
4184 }
4185} // __kmp_stg_print_schedule
4186
4187// -----------------------------------------------------------------------------
4188// OMP_SCHEDULE
4189
4190static inline void __kmp_omp_schedule_restore() {
4191#if KMP_USE_HIER_SCHED
4192 __kmp_hier_scheds.deallocate();
4193#endif
4194 __kmp_chunk = 0;
4195 __kmp_sched = kmp_sch_default;
4196}
4197
4198// if parse_hier = true:
4199// Parse [HW,][modifier:]kind[,chunk]
4200// else:
4201// Parse [modifier:]kind[,chunk]
4202static const char *__kmp_parse_single_omp_schedule(const char *name,
4203 const char *value,
4204 bool parse_hier = false) {
4205 /* get the specified scheduling style */
4206 const char *ptr = value;
4207 const char *delim;
4208 int chunk = 0;
4209 enum sched_type sched = kmp_sch_default;
4210 if (*ptr == '\0')
4211 return NULL;
4212 delim = ptr;
4213 while (*delim != ',' && *delim != ':' && *delim != '\0')
4214 delim++;
4215#if KMP_USE_HIER_SCHED
4216 kmp_hier_layer_e layer = kmp_hier_layer_e::LAYER_THREAD;
4217 if (parse_hier) {
4218 if (*delim == ',') {
4219 if (!__kmp_strcasecmp_with_sentinel("L1", ptr, ',')) {
4220 layer = kmp_hier_layer_e::LAYER_L1;
4221 } else if (!__kmp_strcasecmp_with_sentinel("L2", ptr, ',')) {
4222 layer = kmp_hier_layer_e::LAYER_L2;
4223 } else if (!__kmp_strcasecmp_with_sentinel("L3", ptr, ',')) {
4224 layer = kmp_hier_layer_e::LAYER_L3;
4225 } else if (!__kmp_strcasecmp_with_sentinel("NUMA", ptr, ',')) {
4226 layer = kmp_hier_layer_e::LAYER_NUMA;
4227 }
4228 }
4229 if (layer != kmp_hier_layer_e::LAYER_THREAD && *delim != ',') {
4230 // If there is no comma after the layer, then this schedule is invalid
4231 KMP_WARNING(StgInvalidValue, name, value);
4232 __kmp_omp_schedule_restore();
4233 return NULL;
4234 } else if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4235 ptr = ++delim;
4236 while (*delim != ',' && *delim != ':' && *delim != '\0')
4237 delim++;
4238 }
4239 }
4240#endif // KMP_USE_HIER_SCHED
4241 // Read in schedule modifier if specified
4242 enum sched_type sched_modifier = (enum sched_type)0;
4243 if (*delim == ':') {
4244 if (!__kmp_strcasecmp_with_sentinel("monotonic", ptr, *delim)) {
4246 ptr = ++delim;
4247 while (*delim != ',' && *delim != ':' && *delim != '\0')
4248 delim++;
4249 } else if (!__kmp_strcasecmp_with_sentinel("nonmonotonic", ptr, *delim)) {
4251 ptr = ++delim;
4252 while (*delim != ',' && *delim != ':' && *delim != '\0')
4253 delim++;
4254 } else if (!parse_hier) {
4255 // If there is no proper schedule modifier, then this schedule is invalid
4256 KMP_WARNING(StgInvalidValue, name, value);
4257 __kmp_omp_schedule_restore();
4258 return NULL;
4259 }
4260 }
4261 // Read in schedule kind (required)
4262 if (!__kmp_strcasecmp_with_sentinel("dynamic", ptr, *delim))
4263 sched = kmp_sch_dynamic_chunked;
4264 else if (!__kmp_strcasecmp_with_sentinel("guided", ptr, *delim))
4265 sched = kmp_sch_guided_chunked;
4266 // AC: TODO: probably remove TRAPEZOIDAL (OMP 3.0 does not allow it)
4267 else if (!__kmp_strcasecmp_with_sentinel("auto", ptr, *delim))
4268 sched = kmp_sch_auto;
4269 else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", ptr, *delim))
4270 sched = kmp_sch_trapezoidal;
4271 else if (!__kmp_strcasecmp_with_sentinel("static", ptr, *delim))
4272 sched = kmp_sch_static;
4273#if KMP_STATIC_STEAL_ENABLED
4274 else if (!__kmp_strcasecmp_with_sentinel("static_steal", ptr, *delim)) {
4275 // replace static_steal with dynamic to better cope with ordered loops
4276 sched = kmp_sch_dynamic_chunked;
4278 }
4279#endif
4280 else {
4281 // If there is no proper schedule kind, then this schedule is invalid
4282 KMP_WARNING(StgInvalidValue, name, value);
4283 __kmp_omp_schedule_restore();
4284 return NULL;
4285 }
4286
4287 // Read in schedule chunk size if specified
4288 if (*delim == ',') {
4289 ptr = delim + 1;
4290 SKIP_WS(ptr);
4291 if (!isdigit(*ptr)) {
4292 // If there is no chunk after comma, then this schedule is invalid
4293 KMP_WARNING(StgInvalidValue, name, value);
4294 __kmp_omp_schedule_restore();
4295 return NULL;
4296 }
4297 SKIP_DIGITS(ptr);
4298 // auto schedule should not specify chunk size
4299 if (sched == kmp_sch_auto) {
4300 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, delim),
4301 __kmp_msg_null);
4302 } else {
4303 if (sched == kmp_sch_static)
4304 sched = kmp_sch_static_chunked;
4305 chunk = __kmp_str_to_int(delim + 1, *ptr);
4306 if (chunk < 1) {
4307 chunk = KMP_DEFAULT_CHUNK;
4308 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, delim),
4309 __kmp_msg_null);
4310 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
4311 // AC: next block commented out until KMP_DEFAULT_CHUNK != KMP_MIN_CHUNK
4312 // (to improve code coverage :)
4313 // The default chunk size is 1 according to standard, thus making
4314 // KMP_MIN_CHUNK not 1 we would introduce mess:
4315 // wrong chunk becomes 1, but it will be impossible to explicitly set
4316 // to 1 because it becomes KMP_MIN_CHUNK...
4317 // } else if ( chunk < KMP_MIN_CHUNK ) {
4318 // chunk = KMP_MIN_CHUNK;
4319 } else if (chunk > KMP_MAX_CHUNK) {
4320 chunk = KMP_MAX_CHUNK;
4321 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, delim),
4322 __kmp_msg_null);
4323 KMP_INFORM(Using_int_Value, name, chunk);
4324 }
4325 }
4326 } else {
4327 ptr = delim;
4328 }
4329
4330 SCHEDULE_SET_MODIFIERS(sched, sched_modifier);
4331
4332#if KMP_USE_HIER_SCHED
4333 if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4334 __kmp_hier_scheds.append(sched, chunk, layer);
4335 } else
4336#endif
4337 {
4338 __kmp_chunk = chunk;
4339 __kmp_sched = sched;
4340 }
4341 return ptr;
4342}
4343
4344static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
4345 void *data) {
4346 size_t length;
4347 const char *ptr = value;
4348 if (ptr) {
4349 SKIP_WS(ptr);
4350 length = KMP_STRLEN(value);
4351 if (length) {
4352 if (value[length - 1] == '"' || value[length - 1] == '\'')
4353 KMP_WARNING(UnbalancedQuotes, name);
4354/* get the specified scheduling style */
4355#if KMP_USE_HIER_SCHED
4356 if (!__kmp_strcasecmp_with_sentinel("EXPERIMENTAL", ptr, ' ')) {
4357 SKIP_TOKEN(ptr);
4358 SKIP_WS(ptr);
4359 while ((ptr = __kmp_parse_single_omp_schedule(name, ptr, true))) {
4360 while (*ptr == ' ' || *ptr == '\t' || *ptr == ':')
4361 ptr++;
4362 if (*ptr == '\0')
4363 break;
4364 }
4365 } else
4366#endif
4367 __kmp_parse_single_omp_schedule(name, ptr);
4368 } else
4369 KMP_WARNING(EmptyString, name);
4370 }
4371#if KMP_USE_HIER_SCHED
4372 __kmp_hier_scheds.sort();
4373#endif
4374 K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
4375 K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
4376 K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
4377 K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
4378} // __kmp_stg_parse_omp_schedule
4379
4380static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
4381 char const *name, void *data) {
4382 if (__kmp_env_format) {
4383 KMP_STR_BUF_PRINT_NAME_EX(name);
4384 } else {
4385 __kmp_str_buf_print(buffer, " %s='", name);
4386 }
4387 enum sched_type sched = SCHEDULE_WITHOUT_MODIFIERS(__kmp_sched);
4388 if (SCHEDULE_HAS_MONOTONIC(__kmp_sched)) {
4389 __kmp_str_buf_print(buffer, "monotonic:");
4390 } else if (SCHEDULE_HAS_NONMONOTONIC(__kmp_sched)) {
4391 __kmp_str_buf_print(buffer, "nonmonotonic:");
4392 }
4393 if (__kmp_chunk) {
4394 switch (sched) {
4395 case kmp_sch_dynamic_chunked:
4396 __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
4397 break;
4398 case kmp_sch_guided_iterative_chunked:
4399 case kmp_sch_guided_analytical_chunked:
4400 __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
4401 break;
4402 case kmp_sch_trapezoidal:
4403 __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
4404 break;
4405 case kmp_sch_static:
4406 case kmp_sch_static_chunked:
4407 case kmp_sch_static_balanced:
4408 case kmp_sch_static_greedy:
4409 __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
4410 break;
4411 case kmp_sch_static_steal:
4412 __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
4413 break;
4414 case kmp_sch_auto:
4415 __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
4416 break;
4417 default:
4418 KMP_ASSERT2(false, "Unhandled sched_type enumeration");
4419 KMP_BUILTIN_UNREACHABLE;
4420 break;
4421 }
4422 } else {
4423 switch (sched) {
4424 case kmp_sch_dynamic_chunked:
4425 __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
4426 break;
4427 case kmp_sch_guided_iterative_chunked:
4428 case kmp_sch_guided_analytical_chunked:
4429 __kmp_str_buf_print(buffer, "%s'\n", "guided");
4430 break;
4431 case kmp_sch_trapezoidal:
4432 __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
4433 break;
4434 case kmp_sch_static:
4435 case kmp_sch_static_chunked:
4436 case kmp_sch_static_balanced:
4437 case kmp_sch_static_greedy:
4438 __kmp_str_buf_print(buffer, "%s'\n", "static");
4439 break;
4440 case kmp_sch_static_steal:
4441 __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
4442 break;
4443 case kmp_sch_auto:
4444 __kmp_str_buf_print(buffer, "%s'\n", "auto");
4445 break;
4446 default:
4447 KMP_ASSERT2(false, "Unhandled sched_type enumeration");
4448 KMP_BUILTIN_UNREACHABLE;
4449 break;
4450 }
4451 }
4452} // __kmp_stg_print_omp_schedule
4453
4454#if KMP_USE_HIER_SCHED
4455// -----------------------------------------------------------------------------
4456// KMP_DISP_HAND_THREAD
4457static void __kmp_stg_parse_kmp_hand_thread(char const *name, char const *value,
4458 void *data) {
4459 __kmp_stg_parse_bool(name, value, &(__kmp_dispatch_hand_threading));
4460} // __kmp_stg_parse_kmp_hand_thread
4461
4462static void __kmp_stg_print_kmp_hand_thread(kmp_str_buf_t *buffer,
4463 char const *name, void *data) {
4464 __kmp_stg_print_bool(buffer, name, __kmp_dispatch_hand_threading);
4465} // __kmp_stg_print_kmp_hand_thread
4466#endif
4467
4468// -----------------------------------------------------------------------------
4469// KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE
4470static void __kmp_stg_parse_kmp_force_monotonic(char const *name,
4471 char const *value, void *data) {
4472 __kmp_stg_parse_bool(name, value, &(__kmp_force_monotonic));
4473} // __kmp_stg_parse_kmp_force_monotonic
4474
4475static void __kmp_stg_print_kmp_force_monotonic(kmp_str_buf_t *buffer,
4476 char const *name, void *data) {
4477 __kmp_stg_print_bool(buffer, name, __kmp_force_monotonic);
4478} // __kmp_stg_print_kmp_force_monotonic
4479
4480// -----------------------------------------------------------------------------
4481// KMP_ATOMIC_MODE
4482
4483static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
4484 void *data) {
4485 // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
4486 // compatibility mode.
4487 int mode = 0;
4488 int max = 1;
4489#ifdef KMP_GOMP_COMPAT
4490 max = 2;
4491#endif /* KMP_GOMP_COMPAT */
4492 __kmp_stg_parse_int(name, value, 0, max, &mode);
4493 // TODO; parse_int is not very suitable for this case. In case of overflow it
4494 // is better to use
4495 // 0 rather that max value.
4496 if (mode > 0) {
4497 __kmp_atomic_mode = mode;
4498 }
4499} // __kmp_stg_parse_atomic_mode
4500
4501static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
4502 void *data) {
4503 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
4504} // __kmp_stg_print_atomic_mode
4505
4506// -----------------------------------------------------------------------------
4507// KMP_CONSISTENCY_CHECK
4508
4509static void __kmp_stg_parse_consistency_check(char const *name,
4510 char const *value, void *data) {
4511 if (TCR_4(__kmp_init_serial)) {
4512 KMP_WARNING(EnvSerialWarn, name);
4513 return;
4514 } // read value before serial initialization only
4515 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
4516 // Note, this will not work from kmp_set_defaults because th_cons stack was
4517 // not allocated
4518 // for existed thread(s) thus the first __kmp_push_<construct> will break
4519 // with assertion.
4520 // TODO: allocate th_cons if called from kmp_set_defaults.
4521 __kmp_env_consistency_check = TRUE;
4522 } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
4523 __kmp_env_consistency_check = FALSE;
4524 } else {
4525 KMP_WARNING(StgInvalidValue, name, value);
4526 }
4527} // __kmp_stg_parse_consistency_check
4528
4529static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
4530 char const *name, void *data) {
4531#if KMP_DEBUG
4532 const char *value = NULL;
4533
4534 if (__kmp_env_consistency_check) {
4535 value = "all";
4536 } else {
4537 value = "none";
4538 }
4539
4540 if (value != NULL) {
4541 __kmp_stg_print_str(buffer, name, value);
4542 }
4543#endif /* KMP_DEBUG */
4544} // __kmp_stg_print_consistency_check
4545
4546#if USE_ITT_BUILD
4547// -----------------------------------------------------------------------------
4548// KMP_ITT_PREPARE_DELAY
4549
4550#if USE_ITT_NOTIFY
4551
4552static void __kmp_stg_parse_itt_prepare_delay(char const *name,
4553 char const *value, void *data) {
4554 // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
4555 // iterations.
4556 int delay = 0;
4557 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
4558 __kmp_itt_prepare_delay = delay;
4559} // __kmp_str_parse_itt_prepare_delay
4560
4561static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
4562 char const *name, void *data) {
4563 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
4564
4565} // __kmp_str_print_itt_prepare_delay
4566
4567#endif // USE_ITT_NOTIFY
4568#endif /* USE_ITT_BUILD */
4569
4570// -----------------------------------------------------------------------------
4571// KMP_MALLOC_POOL_INCR
4572
4573static void __kmp_stg_parse_malloc_pool_incr(char const *name,
4574 char const *value, void *data) {
4575 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
4576 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
4577 1);
4578} // __kmp_stg_parse_malloc_pool_incr
4579
4580static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
4581 char const *name, void *data) {
4582 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
4583
4584} // _kmp_stg_print_malloc_pool_incr
4585
4586#ifdef KMP_DEBUG
4587
4588// -----------------------------------------------------------------------------
4589// KMP_PAR_RANGE
4590
4591static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
4592 void *data) {
4593 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
4594 __kmp_par_range_routine, __kmp_par_range_filename,
4595 &__kmp_par_range_lb, &__kmp_par_range_ub);
4596} // __kmp_stg_parse_par_range_env
4597
4598static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
4599 char const *name, void *data) {
4600 if (__kmp_par_range != 0) {
4601 __kmp_stg_print_str(buffer, name, par_range_to_print);
4602 }
4603} // __kmp_stg_print_par_range_env
4604
4605#endif
4606
4607// -----------------------------------------------------------------------------
4608// KMP_GTID_MODE
4609
4610static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
4611 void *data) {
4612 // Modes:
4613 // 0 -- do not change default
4614 // 1 -- sp search
4615 // 2 -- use "keyed" TLS var, i.e.
4616 // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
4617 // 3 -- __declspec(thread) TLS var in tdata section
4618 int mode = 0;
4619 int max = 2;
4620#ifdef KMP_TDATA_GTID
4621 max = 3;
4622#endif /* KMP_TDATA_GTID */
4623 __kmp_stg_parse_int(name, value, 0, max, &mode);
4624 // TODO; parse_int is not very suitable for this case. In case of overflow it
4625 // is better to use 0 rather that max value.
4626 if (mode == 0) {
4627 __kmp_adjust_gtid_mode = TRUE;
4628 } else {
4629 __kmp_gtid_mode = mode;
4630 __kmp_adjust_gtid_mode = FALSE;
4631 }
4632} // __kmp_str_parse_gtid_mode
4633
4634static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
4635 void *data) {
4636 if (__kmp_adjust_gtid_mode) {
4637 __kmp_stg_print_int(buffer, name, 0);
4638 } else {
4639 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
4640 }
4641} // __kmp_stg_print_gtid_mode
4642
4643// -----------------------------------------------------------------------------
4644// KMP_NUM_LOCKS_IN_BLOCK
4645
4646static void __kmp_stg_parse_lock_block(char const *name, char const *value,
4647 void *data) {
4648 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
4649} // __kmp_str_parse_lock_block
4650
4651static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
4652 void *data) {
4653 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
4654} // __kmp_stg_print_lock_block
4655
4656// -----------------------------------------------------------------------------
4657// KMP_LOCK_KIND
4658
4659#if KMP_USE_DYNAMIC_LOCK
4660#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
4661#else
4662#define KMP_STORE_LOCK_SEQ(a)
4663#endif
4664
4665static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
4666 void *data) {
4667 if (__kmp_init_user_locks) {
4668 KMP_WARNING(EnvLockWarn, name);
4669 return;
4670 }
4671
4672 if (__kmp_str_match("tas", 2, value) ||
4673 __kmp_str_match("test and set", 2, value) ||
4674 __kmp_str_match("test_and_set", 2, value) ||
4675 __kmp_str_match("test-and-set", 2, value) ||
4676 __kmp_str_match("test andset", 2, value) ||
4677 __kmp_str_match("test_andset", 2, value) ||
4678 __kmp_str_match("test-andset", 2, value) ||
4679 __kmp_str_match("testand set", 2, value) ||
4680 __kmp_str_match("testand_set", 2, value) ||
4681 __kmp_str_match("testand-set", 2, value) ||
4682 __kmp_str_match("testandset", 2, value)) {
4683 __kmp_user_lock_kind = lk_tas;
4684 KMP_STORE_LOCK_SEQ(tas);
4685 }
4686#if KMP_USE_FUTEX
4687 else if (__kmp_str_match("futex", 1, value)) {
4688 if (__kmp_futex_determine_capable()) {
4689 __kmp_user_lock_kind = lk_futex;
4690 KMP_STORE_LOCK_SEQ(futex);
4691 } else {
4692 KMP_WARNING(FutexNotSupported, name, value);
4693 }
4694 }
4695#endif
4696 else if (__kmp_str_match("ticket", 2, value)) {
4697 __kmp_user_lock_kind = lk_ticket;
4698 KMP_STORE_LOCK_SEQ(ticket);
4699 } else if (__kmp_str_match("queuing", 1, value) ||
4700 __kmp_str_match("queue", 1, value)) {
4701 __kmp_user_lock_kind = lk_queuing;
4702 KMP_STORE_LOCK_SEQ(queuing);
4703 } else if (__kmp_str_match("drdpa ticket", 1, value) ||
4704 __kmp_str_match("drdpa_ticket", 1, value) ||
4705 __kmp_str_match("drdpa-ticket", 1, value) ||
4706 __kmp_str_match("drdpaticket", 1, value) ||
4707 __kmp_str_match("drdpa", 1, value)) {
4708 __kmp_user_lock_kind = lk_drdpa;
4709 KMP_STORE_LOCK_SEQ(drdpa);
4710 }
4711#if KMP_USE_ADAPTIVE_LOCKS
4712 else if (__kmp_str_match("adaptive", 1, value)) {
4713 if (__kmp_cpuinfo.flags.rtm) { // ??? Is cpuinfo available here?
4714 __kmp_user_lock_kind = lk_adaptive;
4715 KMP_STORE_LOCK_SEQ(adaptive);
4716 } else {
4717 KMP_WARNING(AdaptiveNotSupported, name, value);
4718 __kmp_user_lock_kind = lk_queuing;
4719 KMP_STORE_LOCK_SEQ(queuing);
4720 }
4721 }
4722#endif // KMP_USE_ADAPTIVE_LOCKS
4723#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4724 else if (__kmp_str_match("rtm_queuing", 1, value)) {
4725 if (__kmp_cpuinfo.flags.rtm) {
4726 __kmp_user_lock_kind = lk_rtm_queuing;
4727 KMP_STORE_LOCK_SEQ(rtm_queuing);
4728 } else {
4729 KMP_WARNING(AdaptiveNotSupported, name, value);
4730 __kmp_user_lock_kind = lk_queuing;
4731 KMP_STORE_LOCK_SEQ(queuing);
4732 }
4733 } else if (__kmp_str_match("rtm_spin", 1, value)) {
4734 if (__kmp_cpuinfo.flags.rtm) {
4735 __kmp_user_lock_kind = lk_rtm_spin;
4736 KMP_STORE_LOCK_SEQ(rtm_spin);
4737 } else {
4738 KMP_WARNING(AdaptiveNotSupported, name, value);
4739 __kmp_user_lock_kind = lk_tas;
4740 KMP_STORE_LOCK_SEQ(queuing);
4741 }
4742 } else if (__kmp_str_match("hle", 1, value)) {
4743 __kmp_user_lock_kind = lk_hle;
4744 KMP_STORE_LOCK_SEQ(hle);
4745 }
4746#endif
4747 else {
4748 KMP_WARNING(StgInvalidValue, name, value);
4749 }
4750}
4751
4752static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
4753 void *data) {
4754 const char *value = NULL;
4755
4756 switch (__kmp_user_lock_kind) {
4757 case lk_default:
4758 value = "default";
4759 break;
4760
4761 case lk_tas:
4762 value = "tas";
4763 break;
4764
4765#if KMP_USE_FUTEX
4766 case lk_futex:
4767 value = "futex";
4768 break;
4769#endif
4770
4771#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4772 case lk_rtm_queuing:
4773 value = "rtm_queuing";
4774 break;
4775
4776 case lk_rtm_spin:
4777 value = "rtm_spin";
4778 break;
4779
4780 case lk_hle:
4781 value = "hle";
4782 break;
4783#endif
4784
4785 case lk_ticket:
4786 value = "ticket";
4787 break;
4788
4789 case lk_queuing:
4790 value = "queuing";
4791 break;
4792
4793 case lk_drdpa:
4794 value = "drdpa";
4795 break;
4796#if KMP_USE_ADAPTIVE_LOCKS
4797 case lk_adaptive:
4798 value = "adaptive";
4799 break;
4800#endif
4801 }
4802
4803 if (value != NULL) {
4804 __kmp_stg_print_str(buffer, name, value);
4805 }
4806}
4807
4808// -----------------------------------------------------------------------------
4809// KMP_SPIN_BACKOFF_PARAMS
4810
4811// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
4812// for machine pause)
4813static void __kmp_stg_parse_spin_backoff_params(const char *name,
4814 const char *value, void *data) {
4815 const char *next = value;
4816
4817 int total = 0; // Count elements that were set. It'll be used as an array size
4818 int prev_comma = FALSE; // For correct processing sequential commas
4819 int i;
4820
4821 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
4822 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
4823
4824 // Run only 3 iterations because it is enough to read two values or find a
4825 // syntax error
4826 for (i = 0; i < 3; i++) {
4827 SKIP_WS(next);
4828
4829 if (*next == '\0') {
4830 break;
4831 }
4832 // Next character is not an integer or not a comma OR number of values > 2
4833 // => end of list
4834 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
4835 KMP_WARNING(EnvSyntaxError, name, value);
4836 return;
4837 }
4838 // The next character is ','
4839 if (*next == ',') {
4840 // ',' is the first character
4841 if (total == 0 || prev_comma) {
4842 total++;
4843 }
4844 prev_comma = TRUE;
4845 next++; // skip ','
4846 SKIP_WS(next);
4847 }
4848 // Next character is a digit
4849 if (*next >= '0' && *next <= '9') {
4850 int num;
4851 const char *buf = next;
4852 char const *msg = NULL;
4853 prev_comma = FALSE;
4854 SKIP_DIGITS(next);
4855 total++;
4856
4857 const char *tmp = next;
4858 SKIP_WS(tmp);
4859 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4860 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4861 return;
4862 }
4863
4864 num = __kmp_str_to_int(buf, *next);
4865 if (num <= 0) { // The number of retries should be > 0
4866 msg = KMP_I18N_STR(ValueTooSmall);
4867 num = 1;
4868 }
4869 if (msg != NULL) {
4870 // Message is not empty. Print warning.
4871 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4872 KMP_INFORM(Using_int_Value, name, num);
4873 }
4874 if (total == 1) {
4875 max_backoff = num;
4876 } else if (total == 2) {
4877 min_tick = num;
4878 }
4879 }
4880 }
4881 if (total <= 0) {
4882 KMP_WARNING(EnvSyntaxError, name, value);
4883 return;
4884 }
4885 __kmp_spin_backoff_params.max_backoff = max_backoff;
4886 __kmp_spin_backoff_params.min_tick = min_tick;
4887}
4888
4889static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
4890 char const *name, void *data) {
4891 if (__kmp_env_format) {
4892 KMP_STR_BUF_PRINT_NAME_EX(name);
4893 } else {
4894 __kmp_str_buf_print(buffer, " %s='", name);
4895 }
4896 __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
4897 __kmp_spin_backoff_params.min_tick);
4898}
4899
4900#if KMP_USE_ADAPTIVE_LOCKS
4901
4902// -----------------------------------------------------------------------------
4903// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
4904
4905// Parse out values for the tunable parameters from a string of the form
4906// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
4907static void __kmp_stg_parse_adaptive_lock_props(const char *name,
4908 const char *value, void *data) {
4909 int max_retries = 0;
4910 int max_badness = 0;
4911
4912 const char *next = value;
4913
4914 int total = 0; // Count elements that were set. It'll be used as an array size
4915 int prev_comma = FALSE; // For correct processing sequential commas
4916 int i;
4917
4918 // Save values in the structure __kmp_speculative_backoff_params
4919 // Run only 3 iterations because it is enough to read two values or find a
4920 // syntax error
4921 for (i = 0; i < 3; i++) {
4922 SKIP_WS(next);
4923
4924 if (*next == '\0') {
4925 break;
4926 }
4927 // Next character is not an integer or not a comma OR number of values > 2
4928 // => end of list
4929 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
4930 KMP_WARNING(EnvSyntaxError, name, value);
4931 return;
4932 }
4933 // The next character is ','
4934 if (*next == ',') {
4935 // ',' is the first character
4936 if (total == 0 || prev_comma) {
4937 total++;
4938 }
4939 prev_comma = TRUE;
4940 next++; // skip ','
4941 SKIP_WS(next);
4942 }
4943 // Next character is a digit
4944 if (*next >= '0' && *next <= '9') {
4945 int num;
4946 const char *buf = next;
4947 char const *msg = NULL;
4948 prev_comma = FALSE;
4949 SKIP_DIGITS(next);
4950 total++;
4951
4952 const char *tmp = next;
4953 SKIP_WS(tmp);
4954 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4955 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4956 return;
4957 }
4958
4959 num = __kmp_str_to_int(buf, *next);
4960 if (num < 0) { // The number of retries should be >= 0
4961 msg = KMP_I18N_STR(ValueTooSmall);
4962 num = 1;
4963 }
4964 if (msg != NULL) {
4965 // Message is not empty. Print warning.
4966 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4967 KMP_INFORM(Using_int_Value, name, num);
4968 }
4969 if (total == 1) {
4970 max_retries = num;
4971 } else if (total == 2) {
4972 max_badness = num;
4973 }
4974 }
4975 }
4976 if (total <= 0) {
4977 KMP_WARNING(EnvSyntaxError, name, value);
4978 return;
4979 }
4980 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
4981 __kmp_adaptive_backoff_params.max_badness = max_badness;
4982}
4983
4984static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
4985 char const *name, void *data) {
4986 if (__kmp_env_format) {
4987 KMP_STR_BUF_PRINT_NAME_EX(name);
4988 } else {
4989 __kmp_str_buf_print(buffer, " %s='", name);
4990 }
4991 __kmp_str_buf_print(buffer, "%d,%d'\n",
4992 __kmp_adaptive_backoff_params.max_soft_retries,
4993 __kmp_adaptive_backoff_params.max_badness);
4994} // __kmp_stg_print_adaptive_lock_props
4995
4996#if KMP_DEBUG_ADAPTIVE_LOCKS
4997
4998static void __kmp_stg_parse_speculative_statsfile(char const *name,
4999 char const *value,
5000 void *data) {
5001 __kmp_stg_parse_file(name, value, "",
5002 CCAST(char **, &__kmp_speculative_statsfile));
5003} // __kmp_stg_parse_speculative_statsfile
5004
5005static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
5006 char const *name,
5007 void *data) {
5008 if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
5009 __kmp_stg_print_str(buffer, name, "stdout");
5010 } else {
5011 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
5012 }
5013
5014} // __kmp_stg_print_speculative_statsfile
5015
5016#endif // KMP_DEBUG_ADAPTIVE_LOCKS
5017
5018#endif // KMP_USE_ADAPTIVE_LOCKS
5019
5020// -----------------------------------------------------------------------------
5021// KMP_HW_SUBSET (was KMP_PLACE_THREADS)
5022// 2s16c,2t => 2S16C,2T => 2S16C \0 2T
5023
5024// Return KMP_HW_SUBSET preferred hardware type in case a token is ambiguously
5025// short. The original KMP_HW_SUBSET environment variable had single letters:
5026// s, c, t for sockets, cores, threads repsectively.
5027static kmp_hw_t __kmp_hw_subset_break_tie(const kmp_hw_t *possible,
5028 size_t num_possible) {
5029 for (size_t i = 0; i < num_possible; ++i) {
5030 if (possible[i] == KMP_HW_THREAD)
5031 return KMP_HW_THREAD;
5032 else if (possible[i] == KMP_HW_CORE)
5033 return KMP_HW_CORE;
5034 else if (possible[i] == KMP_HW_SOCKET)
5035 return KMP_HW_SOCKET;
5036 }
5037 return KMP_HW_UNKNOWN;
5038}
5039
5040// Return hardware type from string or HW_UNKNOWN if string cannot be parsed
5041// This algorithm is very forgiving to the user in that, the instant it can
5042// reduce the search space to one, it assumes that is the topology level the
5043// user wanted, even if it is misspelled later in the token.
5044static kmp_hw_t __kmp_stg_parse_hw_subset_name(char const *token) {
5045 size_t index, num_possible, token_length;
5046 kmp_hw_t possible[KMP_HW_LAST];
5047 const char *end;
5048
5049 // Find the end of the hardware token string
5050 end = token;
5051 token_length = 0;
5052 while (isalnum(*end) || *end == '_') {
5053 token_length++;
5054 end++;
5055 }
5056
5057 // Set the possibilities to all hardware types
5058 num_possible = 0;
5059 KMP_FOREACH_HW_TYPE(type) { possible[num_possible++] = type; }
5060
5061 // Eliminate hardware types by comparing the front of the token
5062 // with hardware names
5063 // In most cases, the first letter in the token will indicate exactly
5064 // which hardware type is parsed, e.g., 'C' = Core
5065 index = 0;
5066 while (num_possible > 1 && index < token_length) {
5067 size_t n = num_possible;
5068 char token_char = (char)toupper(token[index]);
5069 for (size_t i = 0; i < n; ++i) {
5070 const char *s;
5071 kmp_hw_t type = possible[i];
5072 s = __kmp_hw_get_keyword(type, false);
5073 if (index < KMP_STRLEN(s)) {
5074 char c = (char)toupper(s[index]);
5075 // Mark hardware types for removal when the characters do not match
5076 if (c != token_char) {
5077 possible[i] = KMP_HW_UNKNOWN;
5078 num_possible--;
5079 }
5080 }
5081 }
5082 // Remove hardware types that this token cannot be
5083 size_t start = 0;
5084 for (size_t i = 0; i < n; ++i) {
5085 if (possible[i] != KMP_HW_UNKNOWN) {
5086 kmp_hw_t temp = possible[i];
5087 possible[i] = possible[start];
5088 possible[start] = temp;
5089 start++;
5090 }
5091 }
5092 KMP_ASSERT(start == num_possible);
5093 index++;
5094 }
5095
5096 // Attempt to break a tie if user has very short token
5097 // (e.g., is 'T' tile or thread?)
5098 if (num_possible > 1)
5099 return __kmp_hw_subset_break_tie(possible, num_possible);
5100 if (num_possible == 1)
5101 return possible[0];
5102 return KMP_HW_UNKNOWN;
5103}
5104
5105// The longest observable sequence of items can only be HW_LAST length
5106// The input string is usually short enough, let's use 512 limit for now
5107#define MAX_T_LEVEL KMP_HW_LAST
5108#define MAX_STR_LEN 512
5109static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
5110 void *data) {
5111 // Value example: 1s,5c@3,2T
5112 // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
5113 kmp_setting_t **rivals = (kmp_setting_t **)data;
5114 if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
5115 KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
5116 }
5117 if (__kmp_stg_check_rivals(name, value, rivals)) {
5118 return;
5119 }
5120
5121 char *components[MAX_T_LEVEL];
5122 char const *digits = "0123456789";
5123 char input[MAX_STR_LEN];
5124 size_t len = 0, mlen = MAX_STR_LEN;
5125 int level = 0;
5126 bool absolute = false;
5127 // Canonicalize the string (remove spaces, unify delimiters, etc.)
5128 char *pos = CCAST(char *, value);
5129 while (*pos && mlen) {
5130 if (*pos != ' ') { // skip spaces
5131 if (len == 0 && *pos == ':') {
5132 absolute = true;
5133 } else {
5134 input[len] = (char)(toupper(*pos));
5135 if (input[len] == 'X')
5136 input[len] = ','; // unify delimiters of levels
5137 if (input[len] == 'O' && strchr(digits, *(pos + 1)))
5138 input[len] = '@'; // unify delimiters of offset
5139 len++;
5140 }
5141 }
5142 mlen--;
5143 pos++;
5144 }
5145 if (len == 0 || mlen == 0) {
5146 goto err; // contents is either empty or too long
5147 }
5148 input[len] = '\0';
5149 // Split by delimiter
5150 pos = input;
5151 components[level++] = pos;
5152 while ((pos = strchr(pos, ','))) {
5153 if (level >= MAX_T_LEVEL)
5154 goto err; // too many components provided
5155 *pos = '\0'; // modify input and avoid more copying
5156 components[level++] = ++pos; // expect something after ","
5157 }
5158
5159 __kmp_hw_subset = kmp_hw_subset_t::allocate();
5160 if (absolute)
5161 __kmp_hw_subset->set_absolute();
5162
5163 // Check each component
5164 for (int i = 0; i < level; ++i) {
5165 int core_level = 0;
5166 char *core_components[MAX_T_LEVEL];
5167 // Split possible core components by '&' delimiter
5168 pos = components[i];
5169 core_components[core_level++] = pos;
5170 while ((pos = strchr(pos, '&'))) {
5171 if (core_level >= MAX_T_LEVEL)
5172 goto err; // too many different core types
5173 *pos = '\0'; // modify input and avoid more copying
5174 core_components[core_level++] = ++pos; // expect something after '&'
5175 }
5176
5177 for (int j = 0; j < core_level; ++j) {
5178 char *offset_ptr;
5179 char *attr_ptr;
5180 int offset = 0;
5181 kmp_hw_attr_t attr;
5182 int num;
5183 // components may begin with an optional count of the number of resources
5184 if (isdigit(*core_components[j])) {
5185 num = atoi(core_components[j]);
5186 if (num <= 0) {
5187 goto err; // only positive integers are valid for count
5188 }
5189 pos = core_components[j] + strspn(core_components[j], digits);
5190 } else if (*core_components[j] == '*') {
5191 num = kmp_hw_subset_t::USE_ALL;
5192 pos = core_components[j] + 1;
5193 } else {
5194 num = kmp_hw_subset_t::USE_ALL;
5195 pos = core_components[j];
5196 }
5197
5198 offset_ptr = strchr(core_components[j], '@');
5199 attr_ptr = strchr(core_components[j], ':');
5200
5201 if (offset_ptr) {
5202 offset = atoi(offset_ptr + 1); // save offset
5203 *offset_ptr = '\0'; // cut the offset from the component
5204 }
5205 if (attr_ptr) {
5206 attr.clear();
5207 // save the attribute
5208#if KMP_ARCH_X86 || KMP_ARCH_X86_64
5209 if (__kmp_str_match("intel_core", -1, attr_ptr + 1)) {
5210 attr.set_core_type(KMP_HW_CORE_TYPE_CORE);
5211 } else if (__kmp_str_match("intel_atom", -1, attr_ptr + 1)) {
5212 attr.set_core_type(KMP_HW_CORE_TYPE_ATOM);
5213 } else
5214#endif
5215 if (__kmp_str_match("eff", 3, attr_ptr + 1)) {
5216 const char *number = attr_ptr + 1;
5217 // skip the eff[iciency] token
5218 while (isalpha(*number))
5219 number++;
5220 if (!isdigit(*number)) {
5221 goto err;
5222 }
5223 int efficiency = atoi(number);
5224 attr.set_core_eff(efficiency);
5225 } else {
5226 goto err;
5227 }
5228 *attr_ptr = '\0'; // cut the attribute from the component
5229 }
5230 // detect the component type
5231 kmp_hw_t type = __kmp_stg_parse_hw_subset_name(pos);
5232 if (type == KMP_HW_UNKNOWN) {
5233 goto err;
5234 }
5235 // Only the core type can have attributes
5236 if (attr && type != KMP_HW_CORE)
5237 goto err;
5238 // Must allow core be specified more than once
5239 if (type != KMP_HW_CORE && __kmp_hw_subset->specified(type)) {
5240 goto err;
5241 }
5242 __kmp_hw_subset->push_back(num, type, offset, attr);
5243 }
5244 }
5245 return;
5246err:
5247 KMP_WARNING(AffHWSubsetInvalid, name, value);
5248 if (__kmp_hw_subset) {
5249 kmp_hw_subset_t::deallocate(__kmp_hw_subset);
5250 __kmp_hw_subset = nullptr;
5251 }
5252 return;
5253}
5254
5255static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
5256 void *data) {
5257 kmp_str_buf_t buf;
5258 int depth;
5259 if (!__kmp_hw_subset)
5260 return;
5261 __kmp_str_buf_init(&buf);
5262 if (__kmp_env_format)
5263 KMP_STR_BUF_PRINT_NAME_EX(name);
5264 else
5265 __kmp_str_buf_print(buffer, " %s='", name);
5266
5267 depth = __kmp_hw_subset->get_depth();
5268 for (int i = 0; i < depth; ++i) {
5269 const auto &item = __kmp_hw_subset->at(i);
5270 if (i > 0)
5271 __kmp_str_buf_print(&buf, "%c", ',');
5272 for (int j = 0; j < item.num_attrs; ++j) {
5273 __kmp_str_buf_print(&buf, "%s%d%s", (j > 0 ? "&" : ""), item.num[j],
5274 __kmp_hw_get_keyword(item.type));
5275 if (item.attr[j].is_core_type_valid())
5276 __kmp_str_buf_print(
5277 &buf, ":%s",
5278 __kmp_hw_get_core_type_keyword(item.attr[j].get_core_type()));
5279 if (item.attr[j].is_core_eff_valid())
5280 __kmp_str_buf_print(&buf, ":eff%d", item.attr[j].get_core_eff());
5281 if (item.offset[j])
5282 __kmp_str_buf_print(&buf, "@%d", item.offset[j]);
5283 }
5284 }
5285 __kmp_str_buf_print(buffer, "%s'\n", buf.str);
5286 __kmp_str_buf_free(&buf);
5287}
5288
5289#if USE_ITT_BUILD
5290// -----------------------------------------------------------------------------
5291// KMP_FORKJOIN_FRAMES
5292
5293static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
5294 void *data) {
5295 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
5296} // __kmp_stg_parse_forkjoin_frames
5297
5298static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
5299 char const *name, void *data) {
5300 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
5301} // __kmp_stg_print_forkjoin_frames
5302
5303// -----------------------------------------------------------------------------
5304// KMP_FORKJOIN_FRAMES_MODE
5305
5306static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
5307 char const *value,
5308 void *data) {
5309 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
5310} // __kmp_stg_parse_forkjoin_frames
5311
5312static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
5313 char const *name, void *data) {
5314 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
5315} // __kmp_stg_print_forkjoin_frames
5316#endif /* USE_ITT_BUILD */
5317
5318// -----------------------------------------------------------------------------
5319// KMP_ENABLE_TASK_THROTTLING
5320
5321static void __kmp_stg_parse_task_throttling(char const *name, char const *value,
5322 void *data) {
5323 __kmp_stg_parse_bool(name, value, &__kmp_enable_task_throttling);
5324} // __kmp_stg_parse_task_throttling
5325
5326static void __kmp_stg_print_task_throttling(kmp_str_buf_t *buffer,
5327 char const *name, void *data) {
5328 __kmp_stg_print_bool(buffer, name, __kmp_enable_task_throttling);
5329} // __kmp_stg_print_task_throttling
5330
5331#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5332// -----------------------------------------------------------------------------
5333// KMP_USER_LEVEL_MWAIT
5334
5335static void __kmp_stg_parse_user_level_mwait(char const *name,
5336 char const *value, void *data) {
5337 __kmp_stg_parse_bool(name, value, &__kmp_user_level_mwait);
5338} // __kmp_stg_parse_user_level_mwait
5339
5340static void __kmp_stg_print_user_level_mwait(kmp_str_buf_t *buffer,
5341 char const *name, void *data) {
5342 __kmp_stg_print_bool(buffer, name, __kmp_user_level_mwait);
5343} // __kmp_stg_print_user_level_mwait
5344
5345// -----------------------------------------------------------------------------
5346// KMP_MWAIT_HINTS
5347
5348static void __kmp_stg_parse_mwait_hints(char const *name, char const *value,
5349 void *data) {
5350 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_mwait_hints);
5351} // __kmp_stg_parse_mwait_hints
5352
5353static void __kmp_stg_print_mwait_hints(kmp_str_buf_t *buffer, char const *name,
5354 void *data) {
5355 __kmp_stg_print_int(buffer, name, __kmp_mwait_hints);
5356} // __kmp_stg_print_mwait_hints
5357
5358#endif // KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5359
5360#if KMP_HAVE_UMWAIT
5361// -----------------------------------------------------------------------------
5362// KMP_TPAUSE
5363// 0 = don't use TPAUSE, 1 = use C0.1 state, 2 = use C0.2 state
5364
5365static void __kmp_stg_parse_tpause(char const *name, char const *value,
5366 void *data) {
5367 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_tpause_state);
5368 if (__kmp_tpause_state != 0) {
5369 // The actual hint passed to tpause is: 0 for C0.2 and 1 for C0.1
5370 if (__kmp_tpause_state == 2) // use C0.2
5371 __kmp_tpause_hint = 0; // default was set to 1 for C0.1
5372 }
5373} // __kmp_stg_parse_tpause
5374
5375static void __kmp_stg_print_tpause(kmp_str_buf_t *buffer, char const *name,
5376 void *data) {
5377 __kmp_stg_print_int(buffer, name, __kmp_tpause_state);
5378} // __kmp_stg_print_tpause
5379#endif // KMP_HAVE_UMWAIT
5380
5381// -----------------------------------------------------------------------------
5382// OMP_DISPLAY_ENV
5383
5384static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
5385 void *data) {
5386 if (__kmp_str_match("VERBOSE", 1, value)) {
5387 __kmp_display_env_verbose = TRUE;
5388 } else {
5389 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
5390 }
5391} // __kmp_stg_parse_omp_display_env
5392
5393static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
5394 char const *name, void *data) {
5395 if (__kmp_display_env_verbose) {
5396 __kmp_stg_print_str(buffer, name, "VERBOSE");
5397 } else {
5398 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
5399 }
5400} // __kmp_stg_print_omp_display_env
5401
5402static void __kmp_stg_parse_omp_cancellation(char const *name,
5403 char const *value, void *data) {
5404 if (TCR_4(__kmp_init_parallel)) {
5405 KMP_WARNING(EnvParallelWarn, name);
5406 return;
5407 } // read value before first parallel only
5408 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
5409} // __kmp_stg_parse_omp_cancellation
5410
5411static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
5412 char const *name, void *data) {
5413 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
5414} // __kmp_stg_print_omp_cancellation
5415
5416#if OMPT_SUPPORT
5417int __kmp_tool = 1;
5418
5419static void __kmp_stg_parse_omp_tool(char const *name, char const *value,
5420 void *data) {
5421 __kmp_stg_parse_bool(name, value, &__kmp_tool);
5422} // __kmp_stg_parse_omp_tool
5423
5424static void __kmp_stg_print_omp_tool(kmp_str_buf_t *buffer, char const *name,
5425 void *data) {
5426 if (__kmp_env_format) {
5427 KMP_STR_BUF_PRINT_BOOL_EX(name, __kmp_tool, "enabled", "disabled");
5428 } else {
5429 __kmp_str_buf_print(buffer, " %s=%s\n", name,
5430 __kmp_tool ? "enabled" : "disabled");
5431 }
5432} // __kmp_stg_print_omp_tool
5433
5434char *__kmp_tool_libraries = NULL;
5435
5436static void __kmp_stg_parse_omp_tool_libraries(char const *name,
5437 char const *value, void *data) {
5438 __kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
5439} // __kmp_stg_parse_omp_tool_libraries
5440
5441static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer,
5442 char const *name, void *data) {
5443 if (__kmp_tool_libraries)
5444 __kmp_stg_print_str(buffer, name, __kmp_tool_libraries);
5445 else {
5446 if (__kmp_env_format) {
5447 KMP_STR_BUF_PRINT_NAME;
5448 } else {
5449 __kmp_str_buf_print(buffer, " %s", name);
5450 }
5451 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
5452 }
5453} // __kmp_stg_print_omp_tool_libraries
5454
5455char *__kmp_tool_verbose_init = NULL;
5456
5457static void __kmp_stg_parse_omp_tool_verbose_init(char const *name,
5458 char const *value,
5459 void *data) {
5460 __kmp_stg_parse_str(name, value, &__kmp_tool_verbose_init);
5461} // __kmp_stg_parse_omp_tool_libraries
5462
5463static void __kmp_stg_print_omp_tool_verbose_init(kmp_str_buf_t *buffer,
5464 char const *name,
5465 void *data) {
5466 if (__kmp_tool_verbose_init)
5467 __kmp_stg_print_str(buffer, name, __kmp_tool_verbose_init);
5468 else {
5469 if (__kmp_env_format) {
5470 KMP_STR_BUF_PRINT_NAME;
5471 } else {
5472 __kmp_str_buf_print(buffer, " %s", name);
5473 }
5474 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
5475 }
5476} // __kmp_stg_print_omp_tool_verbose_init
5477
5478#endif
5479
5480// Table.
5481
5482static kmp_setting_t __kmp_stg_table[] = {
5483
5484 {"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
5485 {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
5486 NULL, 0, 0},
5487 {"KMP_USE_YIELD", __kmp_stg_parse_use_yield, __kmp_stg_print_use_yield,
5488 NULL, 0, 0},
5489 {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
5490 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
5491 {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
5492 NULL, 0, 0},
5493 {"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
5494 __kmp_stg_print_device_thread_limit, NULL, 0, 0},
5495#if KMP_USE_MONITOR
5496 {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
5497 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
5498#endif
5499 {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
5500 0, 0},
5501 {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
5502 __kmp_stg_print_stackoffset, NULL, 0, 0},
5503 {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5504 NULL, 0, 0},
5505 {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
5506 0, 0},
5507 {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
5508 0},
5509 {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
5510 0, 0},
5511
5512 {"KMP_NESTING_MODE", __kmp_stg_parse_nesting_mode,
5513 __kmp_stg_print_nesting_mode, NULL, 0, 0},
5514 {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
5515 {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
5516 __kmp_stg_print_num_threads, NULL, 0, 0},
5517 {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5518 NULL, 0, 0},
5519
5520 {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
5521 0},
5522 {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
5523 __kmp_stg_print_task_stealing, NULL, 0, 0},
5524 {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
5525 __kmp_stg_print_max_active_levels, NULL, 0, 0},
5526 {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
5527 __kmp_stg_print_default_device, NULL, 0, 0},
5528 {"OMP_TARGET_OFFLOAD", __kmp_stg_parse_target_offload,
5529 __kmp_stg_print_target_offload, NULL, 0, 0},
5530 {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
5531 __kmp_stg_print_max_task_priority, NULL, 0, 0},
5532 {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
5533 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
5534 {"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
5535 __kmp_stg_print_thread_limit, NULL, 0, 0},
5536 {"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
5537 __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
5538 {"OMP_NUM_TEAMS", __kmp_stg_parse_nteams, __kmp_stg_print_nteams, NULL, 0,
5539 0},
5540 {"OMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_th_limit,
5541 __kmp_stg_print_teams_th_limit, NULL, 0, 0},
5542 {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
5543 __kmp_stg_print_wait_policy, NULL, 0, 0},
5544 {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
5545 __kmp_stg_print_disp_buffers, NULL, 0, 0},
5546 {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
5547 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
5548 {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
5549 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
5550
5551#if KMP_HANDLE_SIGNALS
5552 {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
5553 __kmp_stg_print_handle_signals, NULL, 0, 0},
5554#endif
5555
5556#if KMP_ARCH_X86 || KMP_ARCH_X86_64
5557 {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
5558 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
5559#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
5560
5561#ifdef KMP_GOMP_COMPAT
5562 {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
5563#endif
5564
5565#ifdef KMP_DEBUG
5566 {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
5567 0},
5568 {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
5569 0},
5570 {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
5571 0},
5572 {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
5573 0},
5574 {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
5575 0},
5576 {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
5577 0},
5578 {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
5579 {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
5580 NULL, 0, 0},
5581 {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
5582 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
5583 {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
5584 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
5585 {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
5586 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
5587 {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
5588
5589 {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
5590 __kmp_stg_print_par_range_env, NULL, 0, 0},
5591#endif // KMP_DEBUG
5592
5593 {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
5594 __kmp_stg_print_align_alloc, NULL, 0, 0},
5595
5596 {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5597 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5598 {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5599 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5600 {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5601 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5602 {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5603 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5604#if KMP_FAST_REDUCTION_BARRIER
5605 {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5606 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5607 {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5608 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5609#endif
5610
5611 {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
5612 __kmp_stg_print_abort_delay, NULL, 0, 0},
5613 {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
5614 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
5615 {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
5616 __kmp_stg_print_force_reduction, NULL, 0, 0},
5617 {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
5618 __kmp_stg_print_force_reduction, NULL, 0, 0},
5619 {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
5620 __kmp_stg_print_storage_map, NULL, 0, 0},
5621 {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
5622 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
5623 {"KMP_FOREIGN_THREADS_THREADPRIVATE",
5624 __kmp_stg_parse_foreign_threads_threadprivate,
5625 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
5626
5627#if KMP_AFFINITY_SUPPORTED
5628 {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
5629 0, 0},
5630 {"KMP_HIDDEN_HELPER_AFFINITY", __kmp_stg_parse_hh_affinity,
5631 __kmp_stg_print_hh_affinity, NULL, 0, 0},
5632#ifdef KMP_GOMP_COMPAT
5633 {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
5634 /* no print */ NULL, 0, 0},
5635#endif /* KMP_GOMP_COMPAT */
5636 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5637 NULL, 0, 0},
5638 {"KMP_TEAMS_PROC_BIND", __kmp_stg_parse_teams_proc_bind,
5639 __kmp_stg_print_teams_proc_bind, NULL, 0, 0},
5640 {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
5641 {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
5642 __kmp_stg_print_topology_method, NULL, 0, 0},
5643
5644#else
5645
5646 // KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
5647 // OMP_PROC_BIND and proc-bind-var are supported, however.
5648 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5649 NULL, 0, 0},
5650
5651#endif // KMP_AFFINITY_SUPPORTED
5652 {"OMP_DISPLAY_AFFINITY", __kmp_stg_parse_display_affinity,
5653 __kmp_stg_print_display_affinity, NULL, 0, 0},
5654 {"OMP_AFFINITY_FORMAT", __kmp_stg_parse_affinity_format,
5655 __kmp_stg_print_affinity_format, NULL, 0, 0},
5656 {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
5657 __kmp_stg_print_init_at_fork, NULL, 0, 0},
5658 {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
5659 0, 0},
5660 {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
5661 NULL, 0, 0},
5662#if KMP_USE_HIER_SCHED
5663 {"KMP_DISP_HAND_THREAD", __kmp_stg_parse_kmp_hand_thread,
5664 __kmp_stg_print_kmp_hand_thread, NULL, 0, 0},
5665#endif
5666 {"KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE",
5667 __kmp_stg_parse_kmp_force_monotonic, __kmp_stg_print_kmp_force_monotonic,
5668 NULL, 0, 0},
5669 {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
5670 __kmp_stg_print_atomic_mode, NULL, 0, 0},
5671 {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
5672 __kmp_stg_print_consistency_check, NULL, 0, 0},
5673
5674#if USE_ITT_BUILD && USE_ITT_NOTIFY
5675 {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
5676 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
5677#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
5678 {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
5679 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
5680 {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
5681 NULL, 0, 0},
5682 {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
5683 NULL, 0, 0},
5684 {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
5685 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
5686
5687#ifdef USE_LOAD_BALANCE
5688 {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
5689 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
5690#endif
5691
5692 {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
5693 __kmp_stg_print_lock_block, NULL, 0, 0},
5694 {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
5695 NULL, 0, 0},
5696 {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
5697 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
5698#if KMP_USE_ADAPTIVE_LOCKS
5699 {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
5700 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
5701#if KMP_DEBUG_ADAPTIVE_LOCKS
5702 {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
5703 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
5704#endif
5705#endif // KMP_USE_ADAPTIVE_LOCKS
5706 {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5707 NULL, 0, 0},
5708 {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5709 NULL, 0, 0},
5710#if USE_ITT_BUILD
5711 {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
5712 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
5713 {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
5714 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
5715#endif
5716 {"KMP_ENABLE_TASK_THROTTLING", __kmp_stg_parse_task_throttling,
5717 __kmp_stg_print_task_throttling, NULL, 0, 0},
5718
5719 {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
5720 __kmp_stg_print_omp_display_env, NULL, 0, 0},
5721 {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
5722 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
5723 {"OMP_ALLOCATOR", __kmp_stg_parse_allocator, __kmp_stg_print_allocator,
5724 NULL, 0, 0},
5725 {"LIBOMP_USE_HIDDEN_HELPER_TASK", __kmp_stg_parse_use_hidden_helper,
5726 __kmp_stg_print_use_hidden_helper, NULL, 0, 0},
5727 {"LIBOMP_NUM_HIDDEN_HELPER_THREADS",
5728 __kmp_stg_parse_num_hidden_helper_threads,
5729 __kmp_stg_print_num_hidden_helper_threads, NULL, 0, 0},
5730
5731#if OMPT_SUPPORT
5732 {"OMP_TOOL", __kmp_stg_parse_omp_tool, __kmp_stg_print_omp_tool, NULL, 0,
5733 0},
5734 {"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries,
5735 __kmp_stg_print_omp_tool_libraries, NULL, 0, 0},
5736 {"OMP_TOOL_VERBOSE_INIT", __kmp_stg_parse_omp_tool_verbose_init,
5737 __kmp_stg_print_omp_tool_verbose_init, NULL, 0, 0},
5738#endif
5739
5740#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5741 {"KMP_USER_LEVEL_MWAIT", __kmp_stg_parse_user_level_mwait,
5742 __kmp_stg_print_user_level_mwait, NULL, 0, 0},
5743 {"KMP_MWAIT_HINTS", __kmp_stg_parse_mwait_hints,
5744 __kmp_stg_print_mwait_hints, NULL, 0, 0},
5745#endif
5746
5747#if KMP_HAVE_UMWAIT
5748 {"KMP_TPAUSE", __kmp_stg_parse_tpause, __kmp_stg_print_tpause, NULL, 0, 0},
5749#endif
5750 {"", NULL, NULL, NULL, 0, 0}}; // settings
5751
5752static int const __kmp_stg_count =
5753 sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
5754
5755static inline kmp_setting_t *__kmp_stg_find(char const *name) {
5756
5757 int i;
5758 if (name != NULL) {
5759 for (i = 0; i < __kmp_stg_count; ++i) {
5760 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
5761 return &__kmp_stg_table[i];
5762 }
5763 }
5764 }
5765 return NULL;
5766
5767} // __kmp_stg_find
5768
5769static int __kmp_stg_cmp(void const *_a, void const *_b) {
5770 const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
5771 const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);
5772
5773 // Process KMP_AFFINITY last.
5774 // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
5775 if (strcmp(a->name, "KMP_AFFINITY") == 0) {
5776 if (strcmp(b->name, "KMP_AFFINITY") == 0) {
5777 return 0;
5778 }
5779 return 1;
5780 } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
5781 return -1;
5782 }
5783 return strcmp(a->name, b->name);
5784} // __kmp_stg_cmp
5785
5786static void __kmp_stg_init(void) {
5787
5788 static int initialized = 0;
5789
5790 if (!initialized) {
5791
5792 // Sort table.
5793 qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
5794 __kmp_stg_cmp);
5795
5796 { // Initialize *_STACKSIZE data.
5797 kmp_setting_t *kmp_stacksize =
5798 __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
5799#ifdef KMP_GOMP_COMPAT
5800 kmp_setting_t *gomp_stacksize =
5801 __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
5802#endif
5803 kmp_setting_t *omp_stacksize =
5804 __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
5805
5806 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5807 // !!! Compiler does not understand rivals is used and optimizes out
5808 // assignments
5809 // !!! rivals[ i ++ ] = ...;
5810 static kmp_setting_t *volatile rivals[4];
5811 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
5812#ifdef KMP_GOMP_COMPAT
5813 static kmp_stg_ss_data_t gomp_data = {1024,
5814 CCAST(kmp_setting_t **, rivals)};
5815#endif
5816 static kmp_stg_ss_data_t omp_data = {1024,
5817 CCAST(kmp_setting_t **, rivals)};
5818 int i = 0;
5819
5820 rivals[i++] = kmp_stacksize;
5821#ifdef KMP_GOMP_COMPAT
5822 if (gomp_stacksize != NULL) {
5823 rivals[i++] = gomp_stacksize;
5824 }
5825#endif
5826 rivals[i++] = omp_stacksize;
5827 rivals[i++] = NULL;
5828
5829 kmp_stacksize->data = &kmp_data;
5830#ifdef KMP_GOMP_COMPAT
5831 if (gomp_stacksize != NULL) {
5832 gomp_stacksize->data = &gomp_data;
5833 }
5834#endif
5835 omp_stacksize->data = &omp_data;
5836 }
5837
5838 { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
5839 kmp_setting_t *kmp_library =
5840 __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
5841 kmp_setting_t *omp_wait_policy =
5842 __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
5843
5844 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5845 static kmp_setting_t *volatile rivals[3];
5846 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
5847 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
5848 int i = 0;
5849
5850 rivals[i++] = kmp_library;
5851 if (omp_wait_policy != NULL) {
5852 rivals[i++] = omp_wait_policy;
5853 }
5854 rivals[i++] = NULL;
5855
5856 kmp_library->data = &kmp_data;
5857 if (omp_wait_policy != NULL) {
5858 omp_wait_policy->data = &omp_data;
5859 }
5860 }
5861
5862 { // Initialize KMP_DEVICE_THREAD_LIMIT and KMP_ALL_THREADS
5863 kmp_setting_t *kmp_device_thread_limit =
5864 __kmp_stg_find("KMP_DEVICE_THREAD_LIMIT"); // 1st priority.
5865 kmp_setting_t *kmp_all_threads =
5866 __kmp_stg_find("KMP_ALL_THREADS"); // 2nd priority.
5867
5868 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5869 static kmp_setting_t *volatile rivals[3];
5870 int i = 0;
5871
5872 rivals[i++] = kmp_device_thread_limit;
5873 rivals[i++] = kmp_all_threads;
5874 rivals[i++] = NULL;
5875
5876 kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
5877 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
5878 }
5879
5880 { // Initialize KMP_HW_SUBSET and KMP_PLACE_THREADS
5881 // 1st priority
5882 kmp_setting_t *kmp_hw_subset = __kmp_stg_find("KMP_HW_SUBSET");
5883 // 2nd priority
5884 kmp_setting_t *kmp_place_threads = __kmp_stg_find("KMP_PLACE_THREADS");
5885
5886 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5887 static kmp_setting_t *volatile rivals[3];
5888 int i = 0;
5889
5890 rivals[i++] = kmp_hw_subset;
5891 rivals[i++] = kmp_place_threads;
5892 rivals[i++] = NULL;
5893
5894 kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
5895 kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
5896 }
5897
5898#if KMP_AFFINITY_SUPPORTED
5899 { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
5900 kmp_setting_t *kmp_affinity =
5901 __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
5902 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
5903
5904#ifdef KMP_GOMP_COMPAT
5905 kmp_setting_t *gomp_cpu_affinity =
5906 __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
5907 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
5908#endif
5909
5910 kmp_setting_t *omp_proc_bind =
5911 __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
5912 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
5913
5914 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5915 static kmp_setting_t *volatile rivals[4];
5916 int i = 0;
5917
5918 rivals[i++] = kmp_affinity;
5919
5920#ifdef KMP_GOMP_COMPAT
5921 rivals[i++] = gomp_cpu_affinity;
5922 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
5923#endif
5924
5925 rivals[i++] = omp_proc_bind;
5926 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
5927 rivals[i++] = NULL;
5928
5929 static kmp_setting_t *volatile places_rivals[4];
5930 i = 0;
5931
5932 kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
5933 KMP_DEBUG_ASSERT(omp_places != NULL);
5934
5935 places_rivals[i++] = kmp_affinity;
5936#ifdef KMP_GOMP_COMPAT
5937 places_rivals[i++] = gomp_cpu_affinity;
5938#endif
5939 places_rivals[i++] = omp_places;
5940 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
5941 places_rivals[i++] = NULL;
5942 }
5943#else
5944// KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
5945// OMP_PLACES not supported yet.
5946#endif // KMP_AFFINITY_SUPPORTED
5947
5948 { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
5949 kmp_setting_t *kmp_force_red =
5950 __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
5951 kmp_setting_t *kmp_determ_red =
5952 __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
5953
5954 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5955 static kmp_setting_t *volatile rivals[3];
5956 static kmp_stg_fr_data_t force_data = {1,
5957 CCAST(kmp_setting_t **, rivals)};
5958 static kmp_stg_fr_data_t determ_data = {0,
5959 CCAST(kmp_setting_t **, rivals)};
5960 int i = 0;
5961
5962 rivals[i++] = kmp_force_red;
5963 if (kmp_determ_red != NULL) {
5964 rivals[i++] = kmp_determ_red;
5965 }
5966 rivals[i++] = NULL;
5967
5968 kmp_force_red->data = &force_data;
5969 if (kmp_determ_red != NULL) {
5970 kmp_determ_red->data = &determ_data;
5971 }
5972 }
5973
5974 initialized = 1;
5975 }
5976
5977 // Reset flags.
5978 int i;
5979 for (i = 0; i < __kmp_stg_count; ++i) {
5980 __kmp_stg_table[i].set = 0;
5981 }
5982
5983} // __kmp_stg_init
5984
5985static void __kmp_stg_parse(char const *name, char const *value) {
5986 // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
5987 // really nameless, they are presented in environment block as
5988 // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
5989 if (name[0] == 0) {
5990 return;
5991 }
5992
5993 if (value != NULL) {
5994 kmp_setting_t *setting = __kmp_stg_find(name);
5995 if (setting != NULL) {
5996 setting->parse(name, value, setting->data);
5997 setting->defined = 1;
5998 }
5999 }
6000
6001} // __kmp_stg_parse
6002
6003static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
6004 char const *name, // Name of variable.
6005 char const *value, // Value of the variable.
6006 kmp_setting_t **rivals // List of rival settings (must include current one).
6007) {
6008
6009 if (rivals == NULL) {
6010 return 0;
6011 }
6012
6013 // Loop thru higher priority settings (listed before current).
6014 int i = 0;
6015 for (; strcmp(rivals[i]->name, name) != 0; i++) {
6016 KMP_DEBUG_ASSERT(rivals[i] != NULL);
6017
6018#if KMP_AFFINITY_SUPPORTED
6019 if (rivals[i] == __kmp_affinity_notype) {
6020 // If KMP_AFFINITY is specified without a type name,
6021 // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
6022 continue;
6023 }
6024#endif
6025
6026 if (rivals[i]->set) {
6027 KMP_WARNING(StgIgnored, name, rivals[i]->name);
6028 return 1;
6029 }
6030 }
6031
6032 ++i; // Skip current setting.
6033 return 0;
6034
6035} // __kmp_stg_check_rivals
6036
6037static int __kmp_env_toPrint(char const *name, int flag) {
6038 int rc = 0;
6039 kmp_setting_t *setting = __kmp_stg_find(name);
6040 if (setting != NULL) {
6041 rc = setting->defined;
6042 if (flag >= 0) {
6043 setting->defined = flag;
6044 }
6045 }
6046 return rc;
6047}
6048
6049#if defined(KMP_DEBUG) && KMP_AFFINITY_SUPPORTED
6050static void __kmp_print_affinity_settings(const kmp_affinity_t *affinity) {
6051 K_DIAG(1, ("%s:\n", affinity->env_var));
6052 K_DIAG(1, (" type : %d\n", affinity->type));
6053 K_DIAG(1, (" compact : %d\n", affinity->compact));
6054 K_DIAG(1, (" offset : %d\n", affinity->offset));
6055 K_DIAG(1, (" verbose : %u\n", affinity->flags.verbose));
6056 K_DIAG(1, (" warnings : %u\n", affinity->flags.warnings));
6057 K_DIAG(1, (" respect : %u\n", affinity->flags.respect));
6058 K_DIAG(1, (" reset : %u\n", affinity->flags.reset));
6059 K_DIAG(1, (" dups : %u\n", affinity->flags.dups));
6060 K_DIAG(1, (" gran : %d\n", (int)affinity->gran));
6061 KMP_DEBUG_ASSERT(affinity->type != affinity_default);
6062}
6063#endif
6064
6065// If `base_name` is on the device-scope eligible list, return the value of
6066// `<base_name>_ALL` from `block` (or NULL). Returns NULL for non-eligible
6067// names.
6068static char const *__kmp_aux_env_blk_all_fallback(kmp_env_blk_t *block,
6069 char const *base_name) {
6070 for (int e = 0;; ++e) {
6071 char const *base = __kmp_device_env_eligible_name(e);
6072 if (base == NULL)
6073 return NULL;
6074 if (strcmp(base, base_name) != 0)
6075 continue;
6076 char *all_name = __kmp_str_format("%s_ALL", base_name);
6077 char const *value = __kmp_env_blk_var(block, all_name);
6078 __kmp_str_free(&all_name);
6079 return value;
6080 }
6081}
6082
6083static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
6084
6085 char const *value;
6086
6087 /* OMP_NUM_THREADS */
6088 value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
6089 if (value == NULL)
6090 value = __kmp_aux_env_blk_all_fallback(block, "OMP_NUM_THREADS");
6091 if (value) {
6092 ompc_set_num_threads(__kmp_dflt_team_nth);
6093 }
6094
6095 /* KMP_BLOCKTIME */
6096 value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
6097 if (value) {
6098 int gtid, tid;
6099 kmp_info_t *thread;
6100
6101 gtid = __kmp_entry_gtid();
6102 tid = __kmp_tid_from_gtid(gtid);
6103 thread = __kmp_thread_from_gtid(gtid);
6104 __kmp_aux_set_blocktime(__kmp_dflt_blocktime, thread, tid);
6105 }
6106
6107 /* OMP_NESTED */
6108 value = __kmp_env_blk_var(block, "OMP_NESTED");
6109 if (value) {
6110 ompc_set_nested(__kmp_dflt_max_active_levels > 1);
6111 }
6112
6113 /* OMP_DYNAMIC */
6114 value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
6115 if (value) {
6116 ompc_set_dynamic(__kmp_global.g.g_dynamic);
6117 }
6118}
6119
6120void __kmp_env_initialize(char const *string) {
6121
6122 kmp_env_blk_t block;
6123 int i;
6124
6125 __kmp_stg_init();
6126
6127 // Hack!!!
6128 if (string == NULL) {
6129 // __kmp_max_nth = __kmp_sys_max_nth;
6130 __kmp_threads_capacity =
6131 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
6132 }
6133 __kmp_env_blk_init(&block, string);
6134
6135 // We need to know if blocktime and use_yield were set when processing
6136 // OMP_WAIT_POLICY
6137 blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
6138 use_yield_str = __kmp_env_blk_var(&block, "KMP_USE_YIELD");
6139
6140 // Special case. If we parse environment, not a string, process KMP_WARNINGS
6141 // first.
6142 if (string == NULL) {
6143 char const *name = "KMP_WARNINGS";
6144 char const *value = __kmp_env_blk_var(&block, name);
6145 __kmp_stg_parse(name, value);
6146 }
6147
6148#if KMP_AFFINITY_SUPPORTED
6149 // Special case. KMP_AFFINITY is not a rival to other affinity env vars
6150 // if no affinity type is specified. We want to allow
6151 // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
6152 // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
6153 // affinity mechanism.
6154 __kmp_affinity_notype = NULL;
6155 char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
6156 if (aff_str != NULL) {
6157 // Check if the KMP_AFFINITY type is specified in the string.
6158 // We just search the string for "compact", "scatter", etc.
6159 // without really parsing the string. The syntax of the
6160 // KMP_AFFINITY env var is such that none of the affinity
6161 // type names can appear anywhere other that the type
6162 // specifier, even as substrings.
6163 //
6164 // I can't find a case-insensitive version of strstr on Windows* OS.
6165 // Use the case-sensitive version for now. AIX does the same.
6166
6167#if KMP_OS_WINDOWS || KMP_OS_AIX
6168#define FIND strstr
6169#else
6170#define FIND strcasestr
6171#endif
6172
6173 if ((FIND(aff_str, "none") == NULL) &&
6174 (FIND(aff_str, "physical") == NULL) &&
6175 (FIND(aff_str, "logical") == NULL) &&
6176 (FIND(aff_str, "compact") == NULL) &&
6177 (FIND(aff_str, "scatter") == NULL) &&
6178 (FIND(aff_str, "explicit") == NULL) &&
6179 (FIND(aff_str, "balanced") == NULL) &&
6180 (FIND(aff_str, "disabled") == NULL)) {
6181 __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
6182 } else {
6183 // A new affinity type is specified.
6184 // Reset the affinity flags to their default values,
6185 // in case this is called from kmp_set_defaults().
6186 __kmp_affinity.type = affinity_default;
6187 __kmp_affinity.gran = KMP_HW_UNKNOWN;
6188 __kmp_affinity_top_method = affinity_top_method_default;
6189 __kmp_affinity.flags.respect = affinity_respect_mask_default;
6190 }
6191#undef FIND
6192
6193 // Also reset the affinity flags if OMP_PROC_BIND is specified.
6194 aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
6195 if (aff_str != NULL) {
6196 __kmp_affinity.type = affinity_default;
6197 __kmp_affinity.gran = KMP_HW_UNKNOWN;
6198 __kmp_affinity_top_method = affinity_top_method_default;
6199 __kmp_affinity.flags.respect = affinity_respect_mask_default;
6200 }
6201 }
6202
6203#endif /* KMP_AFFINITY_SUPPORTED */
6204
6205 // Deliberately placed AFTER the KMP_WARNINGS special case above so that any
6206 // warnings the pre-pass emits (MalformedDeviceEnvVar /
6207 // DeviceEnvVarOnGlobalScope) honour the user-requested warning level.
6208 for (i = 0; i < block.count; ++i) {
6209 if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
6210 continue;
6211 }
6212 if (block.vars[i].value == NULL) {
6213 continue;
6214 }
6215 if (__kmp_device_env_record(block.vars[i].name, block.vars[i].value))
6216 continue;
6217
6218 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
6219 if (setting != NULL) {
6220 setting->set = 1;
6221 }
6222 }
6223
6224 // Set up the nested proc bind type vector.
6225 if (__kmp_nested_proc_bind.bind_types == NULL) {
6226 __kmp_nested_proc_bind.bind_types =
6227 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
6228 if (__kmp_nested_proc_bind.bind_types == NULL) {
6229 KMP_FATAL(MemoryAllocFailed);
6230 }
6231 __kmp_nested_proc_bind.size = 1;
6232 __kmp_nested_proc_bind.used = 1;
6233#if KMP_AFFINITY_SUPPORTED
6234 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
6235#else
6236 // default proc bind is false if affinity not supported
6237 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6238#endif
6239 }
6240
6241 // Set up the affinity format ICV
6242 // Grab the default affinity format string from the message catalog
6243 kmp_msg_t m =
6244 __kmp_msg_format(kmp_i18n_msg_AffFormatDefault, "%P", "%i", "%n", "%A");
6245 KMP_DEBUG_ASSERT(KMP_STRLEN(m.str) < KMP_AFFINITY_FORMAT_SIZE);
6246
6247 if (__kmp_affinity_format == NULL) {
6248 __kmp_affinity_format =
6249 (char *)KMP_INTERNAL_MALLOC(sizeof(char) * KMP_AFFINITY_FORMAT_SIZE);
6250 }
6251 KMP_STRCPY_S(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, m.str);
6252 __kmp_str_free(&m.str);
6253
6254 // Now process all of the settings.
6255 for (i = 0; i < block.count; ++i) {
6256 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
6257 }
6258
6259 // Device-scope env-var post-pass: when the current block has `<ENV>_ALL` but
6260 // no unsuffixed `<ENV>`, replay `_ALL` so the host ICV picks it up. We query
6261 // the block (not the registry) so an unrelated kmp_set_defaults does not
6262 // accidentally replay a stale `_ALL`.
6263 for (int e = 0;; ++e) {
6264 char const *base = __kmp_device_env_eligible_name(e);
6265 if (base == NULL)
6266 break;
6267 if (__kmp_env_blk_var(&block, base) != NULL)
6268 continue;
6269 char *all_name = __kmp_str_format("%s_ALL", base);
6270 char const *all_v = __kmp_env_blk_var(&block, all_name);
6271 __kmp_str_free(&all_name);
6272 if (all_v != NULL)
6273 __kmp_stg_parse(base, all_v);
6274 }
6275
6276 // If user locks have been allocated yet, don't reset the lock vptr table.
6277 if (!__kmp_init_user_locks) {
6278 if (__kmp_user_lock_kind == lk_default) {
6279 __kmp_user_lock_kind = lk_queuing;
6280 }
6281#if KMP_USE_DYNAMIC_LOCK
6282 __kmp_init_dynamic_user_locks();
6283#else
6284 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
6285#endif
6286 } else {
6287 KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
6288 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
6289// Binds lock functions again to follow the transition between different
6290// KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
6291// as we do not allow lock kind changes after making a call to any
6292// user lock functions (true).
6293#if KMP_USE_DYNAMIC_LOCK
6294 __kmp_init_dynamic_user_locks();
6295#else
6296 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
6297#endif
6298 }
6299
6300#if KMP_AFFINITY_SUPPORTED
6301
6302 if (!TCR_4(__kmp_init_middle)) {
6303#if KMP_HWLOC_ENABLED
6304 // Force using hwloc when either tiles or numa nodes requested within
6305 // KMP_HW_SUBSET or granularity setting and no other topology method
6306 // is requested
6307 if (__kmp_hw_subset &&
6308 __kmp_affinity_top_method == affinity_top_method_default)
6309 if (__kmp_hw_subset->specified(KMP_HW_NUMA) ||
6310 __kmp_hw_subset->specified(KMP_HW_TILE) ||
6311 __kmp_affinity.gran == KMP_HW_TILE ||
6312 __kmp_affinity.gran == KMP_HW_NUMA)
6313 __kmp_affinity_top_method = affinity_top_method_hwloc;
6314 // Force using hwloc when tiles or numa nodes requested for OMP_PLACES
6315 if (__kmp_affinity.gran == KMP_HW_NUMA ||
6316 __kmp_affinity.gran == KMP_HW_TILE)
6317 __kmp_affinity_top_method = affinity_top_method_hwloc;
6318#endif // KMP_HWLOC_ENABLED
6319 // Determine if the machine/OS is actually capable of supporting
6320 // affinity.
6321 const char *var = "KMP_AFFINITY";
6322 KMPAffinity::pick_api();
6323#if KMP_HWLOC_ENABLED
6324 // If Hwloc topology discovery was requested but affinity was also disabled,
6325 // then tell user that Hwloc request is being ignored and use default
6326 // topology discovery method.
6327 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
6328 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
6329 KMP_WARNING(AffIgnoringHwloc, var);
6330 __kmp_affinity_top_method = affinity_top_method_all;
6331 }
6332#endif // KMP_HWLOC_ENABLED
6333 if (__kmp_affinity.type == affinity_disabled) {
6334 KMP_AFFINITY_DISABLE();
6335 } else if (!KMP_AFFINITY_CAPABLE()) {
6336 __kmp_affinity_dispatch->determine_capable(var);
6337 if (!KMP_AFFINITY_CAPABLE()) {
6338 if (__kmp_affinity.flags.verbose ||
6339 (__kmp_affinity.flags.warnings &&
6340 (__kmp_affinity.type != affinity_default) &&
6341 (__kmp_affinity.type != affinity_none) &&
6342 (__kmp_affinity.type != affinity_disabled))) {
6343 KMP_WARNING(AffNotSupported, var);
6344 }
6345 __kmp_affinity.type = affinity_disabled;
6346 __kmp_affinity.flags.respect = FALSE;
6347 __kmp_affinity.gran = KMP_HW_THREAD;
6348 }
6349 }
6350
6351 if (__kmp_affinity.type == affinity_disabled) {
6352 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6353 } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
6354 // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
6355 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
6356 }
6357
6358 if (KMP_AFFINITY_CAPABLE()) {
6359
6360#if KMP_GROUP_AFFINITY
6361 // This checks to see if the initial affinity mask is equal
6362 // to a single windows processor group. If it is, then we do
6363 // not respect the initial affinity mask and instead, use the
6364 // entire machine.
6365 bool exactly_one_group = false;
6366 if (__kmp_num_proc_groups > 1) {
6367 int group;
6368 bool within_one_group;
6369 // Get the initial affinity mask and determine if it is
6370 // contained within a single group.
6371 kmp_affin_mask_t *init_mask;
6372 KMP_CPU_ALLOC(init_mask);
6373 __kmp_get_system_affinity(init_mask, TRUE);
6374 group = __kmp_get_proc_group(init_mask);
6375 within_one_group = (group >= 0);
6376 // If the initial affinity is within a single group,
6377 // then determine if it is equal to that single group.
6378 if (within_one_group) {
6379 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
6380 DWORD num_bits_in_mask = 0;
6381 for (int bit = init_mask->begin(); bit != init_mask->end();
6382 bit = init_mask->next(bit))
6383 num_bits_in_mask++;
6384 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
6385 }
6386 KMP_CPU_FREE(init_mask);
6387 }
6388
6389 // Handle the Win 64 group affinity stuff if there are multiple
6390 // processor groups, or if the user requested it, and OMP 4.0
6391 // affinity is not in effect.
6392 if (__kmp_num_proc_groups > 1 &&
6393 __kmp_affinity.type == affinity_default &&
6394 __kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
6395 // Do not respect the initial processor affinity mask if it is assigned
6396 // exactly one Windows Processor Group since this is interpreted as the
6397 // default OS assignment. Not respecting the mask allows the runtime to
6398 // use all the logical processors in all groups.
6399 if (__kmp_affinity.flags.respect == affinity_respect_mask_default &&
6400 exactly_one_group) {
6401 __kmp_affinity.flags.respect = FALSE;
6402 }
6403 // Use compact affinity with anticipation of pinning to at least the
6404 // group granularity since threads can only be bound to one group.
6405 if (__kmp_affinity.type == affinity_default) {
6406 __kmp_affinity.type = affinity_compact;
6407 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6408 }
6409 if (__kmp_hh_affinity.type == affinity_default)
6410 __kmp_hh_affinity.type = affinity_compact;
6411 if (__kmp_affinity_top_method == affinity_top_method_default)
6412 __kmp_affinity_top_method = affinity_top_method_all;
6413 if (__kmp_affinity.gran == KMP_HW_UNKNOWN)
6414 __kmp_affinity.gran = KMP_HW_PROC_GROUP;
6415 if (__kmp_hh_affinity.gran == KMP_HW_UNKNOWN)
6416 __kmp_hh_affinity.gran = KMP_HW_PROC_GROUP;
6417 } else
6418
6419#endif /* KMP_GROUP_AFFINITY */
6420
6421 {
6422 if (__kmp_affinity.flags.respect == affinity_respect_mask_default) {
6423#if KMP_GROUP_AFFINITY
6424 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
6425 __kmp_affinity.flags.respect = FALSE;
6426 } else
6427#endif /* KMP_GROUP_AFFINITY */
6428 {
6429 __kmp_affinity.flags.respect = TRUE;
6430 }
6431 }
6432 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
6433 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
6434 if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)
6435 __kmp_affinity.type = affinity_none;
6436 if (__kmp_affinity.type == affinity_default) {
6437 __kmp_affinity.type = affinity_compact;
6438 __kmp_affinity.flags.dups = FALSE;
6439 }
6440 } else if (__kmp_affinity.type == affinity_default) {
6441#if KMP_MIC_SUPPORTED
6442 if (__kmp_mic_type != non_mic) {
6443 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6444 } else
6445#endif
6446 {
6447 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6448 }
6449#if KMP_MIC_SUPPORTED
6450 if (__kmp_mic_type != non_mic) {
6451 __kmp_affinity.type = affinity_scatter;
6452 } else
6453#endif
6454 {
6455 __kmp_affinity.type = affinity_none;
6456 }
6457 }
6458 if (__kmp_hh_affinity.type == affinity_default)
6459 __kmp_hh_affinity.type = affinity_none;
6460 if ((__kmp_affinity.gran == KMP_HW_UNKNOWN) &&
6461 (__kmp_affinity.gran_levels < 0)) {
6462#if KMP_MIC_SUPPORTED
6463 if (__kmp_mic_type != non_mic) {
6464 __kmp_affinity.gran = KMP_HW_THREAD;
6465 } else
6466#endif
6467 {
6468 __kmp_affinity.gran = KMP_HW_CORE;
6469 }
6470 }
6471 if ((__kmp_hh_affinity.gran == KMP_HW_UNKNOWN) &&
6472 (__kmp_hh_affinity.gran_levels < 0)) {
6473#if KMP_MIC_SUPPORTED
6474 if (__kmp_mic_type != non_mic) {
6475 __kmp_hh_affinity.gran = KMP_HW_THREAD;
6476 } else
6477#endif
6478 {
6479 __kmp_hh_affinity.gran = KMP_HW_CORE;
6480 }
6481 }
6482 if (__kmp_affinity_top_method == affinity_top_method_default) {
6483 __kmp_affinity_top_method = affinity_top_method_all;
6484 }
6485 }
6486 } else {
6487 // If affinity is disabled, then still need to assign topology method
6488 // to attempt machine detection and affinity types
6489 if (__kmp_affinity_top_method == affinity_top_method_default)
6490 __kmp_affinity_top_method = affinity_top_method_all;
6491 if (__kmp_affinity.type == affinity_default)
6492 __kmp_affinity.type = affinity_disabled;
6493 if (__kmp_hh_affinity.type == affinity_default)
6494 __kmp_hh_affinity.type = affinity_disabled;
6495 }
6496
6497#ifdef KMP_DEBUG
6498 for (const kmp_affinity_t *affinity : __kmp_affinities)
6499 __kmp_print_affinity_settings(affinity);
6500 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
6501 K_DIAG(1, ("__kmp_nested_proc_bind.bind_types[0] == %d\n",
6502 __kmp_nested_proc_bind.bind_types[0]));
6503#endif
6504 }
6505
6506#endif /* KMP_AFFINITY_SUPPORTED */
6507
6508 // Post-initialization step: some env. vars need their value's further
6509 // processing
6510 if (string != NULL) { // kmp_set_defaults() was called
6511 __kmp_aux_env_initialize(&block);
6512 }
6513
6514 __kmp_env_blk_free(&block);
6515
6516 KMP_MB();
6517
6518} // __kmp_env_initialize
6519
6520void __kmp_env_print() {
6521
6522 kmp_env_blk_t block;
6523 int i;
6524 kmp_str_buf_t buffer;
6525
6526 __kmp_stg_init();
6527 __kmp_str_buf_init(&buffer);
6528
6529 __kmp_env_blk_init(&block, NULL);
6530 __kmp_env_blk_sort(&block);
6531
6532 // Print real environment values.
6533 __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
6534 for (i = 0; i < block.count; ++i) {
6535 char const *name = block.vars[i].name;
6536 char const *value = block.vars[i].value;
6537 if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
6538 strncmp(name, "OMP_", 4) == 0
6539#ifdef KMP_GOMP_COMPAT
6540 || strncmp(name, "GOMP_", 5) == 0
6541#endif // KMP_GOMP_COMPAT
6542 ) {
6543 __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
6544 }
6545 }
6546 __kmp_str_buf_print(&buffer, "\n");
6547
6548 // Print internal (effective) settings.
6549 __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
6550 for (int i = 0; i < __kmp_stg_count; ++i) {
6551 if (__kmp_stg_table[i].print != NULL) {
6552 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6553 __kmp_stg_table[i].data);
6554 }
6555 }
6556
6557 __kmp_printf("%s", buffer.str);
6558
6559 __kmp_env_blk_free(&block);
6560 __kmp_str_buf_free(&buffer);
6561
6562 __kmp_printf("\n");
6563
6564} // __kmp_env_print
6565
6566void __kmp_env_print_2() {
6567 __kmp_display_env_impl(__kmp_display_env, __kmp_display_env_verbose);
6568} // __kmp_env_print_2
6569
6570void __kmp_display_env_impl(int display_env, int display_env_verbose) {
6571 kmp_env_blk_t block;
6572 kmp_str_buf_t buffer;
6573
6574 __kmp_env_format = 1;
6575
6576 __kmp_stg_init();
6577 __kmp_str_buf_init(&buffer);
6578
6579 __kmp_env_blk_init(&block, NULL);
6580 __kmp_env_blk_sort(&block);
6581
6582 __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
6583 __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
6584
6585 for (int i = 0; i < __kmp_stg_count; ++i) {
6586 if (__kmp_stg_table[i].print != NULL &&
6587 ((display_env && strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
6588 display_env_verbose)) {
6589 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6590 __kmp_stg_table[i].data);
6591 }
6592 }
6593
6594 __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
6595 __kmp_str_buf_print(&buffer, "\n");
6596
6597 __kmp_printf("%s", buffer.str);
6598
6599 __kmp_env_blk_free(&block);
6600 __kmp_str_buf_free(&buffer);
6601
6602 __kmp_printf("\n");
6603}
6604
6605#if OMPD_SUPPORT
6606// Dump environment variables for OMPD
6607void __kmp_env_dump() {
6608
6609 kmp_env_blk_t block;
6610 kmp_str_buf_t buffer, env, notdefined;
6611
6612 __kmp_stg_init();
6613 __kmp_str_buf_init(&buffer);
6614 __kmp_str_buf_init(&env);
6615 __kmp_str_buf_init(&notdefined);
6616
6617 __kmp_env_blk_init(&block, NULL);
6618 __kmp_env_blk_sort(&block);
6619
6620 __kmp_str_buf_print(&notdefined, ": %s", KMP_I18N_STR(NotDefined));
6621
6622 for (int i = 0; i < __kmp_stg_count; ++i) {
6623 if (__kmp_stg_table[i].print == NULL)
6624 continue;
6625 __kmp_str_buf_clear(&env);
6626 __kmp_stg_table[i].print(&env, __kmp_stg_table[i].name,
6627 __kmp_stg_table[i].data);
6628 if (env.used < 4) // valid definition must have indents (3) and a new line
6629 continue;
6630 if (strstr(env.str, notdefined.str))
6631 // normalize the string
6632 __kmp_str_buf_print(&buffer, "%s=undefined\n", __kmp_stg_table[i].name);
6633 else
6634 __kmp_str_buf_cat(&buffer, env.str + 3, env.used - 3);
6635 }
6636
6637 ompd_env_block = (char *)__kmp_allocate(buffer.used + 1);
6638 KMP_MEMCPY(ompd_env_block, buffer.str, buffer.used + 1);
6639 ompd_env_block_size = (ompd_size_t)KMP_STRLEN(ompd_env_block);
6640
6641 __kmp_env_blk_free(&block);
6642 __kmp_str_buf_free(&buffer);
6643 __kmp_str_buf_free(&env);
6644 __kmp_str_buf_free(&notdefined);
6645}
6646#endif // OMPD_SUPPORT
6647
6648// end of file
sched_type
Definition: kmp.h:340
@ kmp_sch_auto
Definition: kmp.h:347
@ kmp_sch_static
Definition: kmp.h:343
@ kmp_sch_modifier_monotonic
Definition: kmp.h:428
@ kmp_sch_default
Definition: kmp.h:448
@ kmp_sch_modifier_nonmonotonic
Definition: kmp.h:430
@ kmp_sch_guided_chunked
Definition: kmp.h:345