LLVM OpenMP* Runtime Library
Loading...
Searching...
No Matches
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_environment.h"
20#include "kmp_i18n.h"
21#include "kmp_io.h"
22#include "kmp_itt.h"
23#include "kmp_lock.h"
24#include "kmp_settings.h"
25#include "kmp_str.h"
26#include "kmp_wrapper_getpid.h"
27#include <ctype.h> // toupper()
28#if OMPD_SUPPORT
29#include "ompd-specific.h"
30#endif
31
32static int __kmp_env_toPrint(char const *name, int flag);
33
34bool __kmp_env_format = 0; // 0 - old format; 1 - new format
35
36// -----------------------------------------------------------------------------
37// Helper string functions. Subject to move to kmp_str.
38
39#ifdef USE_LOAD_BALANCE
40static double __kmp_convert_to_double(char const *s) {
41 double result;
42
43 if (KMP_SSCANF(s, "%lf", &result) < 1) {
44 result = 0.0;
45 }
46
47 return result;
48}
49#endif
50
51#ifdef KMP_DEBUG
52static unsigned int __kmp_readstr_with_sentinel(char *dest, char const *src,
53 size_t len, char sentinel) {
54 unsigned int i;
55 for (i = 0; i < len; i++) {
56 if ((*src == '\0') || (*src == sentinel)) {
57 break;
58 }
59 *(dest++) = *(src++);
60 }
61 *dest = '\0';
62 return i;
63}
64#endif
65
66static int __kmp_match_with_sentinel(char const *a, char const *b, size_t len,
67 char sentinel) {
68 size_t l = 0;
69
70 if (a == NULL)
71 a = "";
72 if (b == NULL)
73 b = "";
74 while (*a && *b && *b != sentinel) {
75 char ca = *a, cb = *b;
76
77 if (ca >= 'a' && ca <= 'z')
78 ca -= 'a' - 'A';
79 if (cb >= 'a' && cb <= 'z')
80 cb -= 'a' - 'A';
81 if (ca != cb)
82 return FALSE;
83 ++l;
84 ++a;
85 ++b;
86 }
87 return l >= len;
88}
89
90// Expected usage:
91// token is the token to check for.
92// buf is the string being parsed.
93// *end returns the char after the end of the token.
94// it is not modified unless a match occurs.
95//
96// Example 1:
97//
98// if (__kmp_match_str("token", buf, *end) {
99// <do something>
100// buf = end;
101// }
102//
103// Example 2:
104//
105// if (__kmp_match_str("token", buf, *end) {
106// char *save = **end;
107// **end = sentinel;
108// <use any of the __kmp*_with_sentinel() functions>
109// **end = save;
110// buf = end;
111// }
112
113static int __kmp_match_str(char const *token, char const *buf,
114 const char **end) {
115
116 KMP_ASSERT(token != NULL);
117 KMP_ASSERT(buf != NULL);
118 KMP_ASSERT(end != NULL);
119
120 while (*token && *buf) {
121 char ct = *token, cb = *buf;
122
123 if (ct >= 'a' && ct <= 'z')
124 ct -= 'a' - 'A';
125 if (cb >= 'a' && cb <= 'z')
126 cb -= 'a' - 'A';
127 if (ct != cb)
128 return FALSE;
129 ++token;
130 ++buf;
131 }
132 if (*token) {
133 return FALSE;
134 }
135 *end = buf;
136 return TRUE;
137}
138
139#if KMP_OS_DARWIN
140static size_t __kmp_round4k(size_t size) {
141 size_t _4k = 4 * 1024;
142 if (size & (_4k - 1)) {
143 size &= ~(_4k - 1);
144 if (size <= KMP_SIZE_T_MAX - _4k) {
145 size += _4k; // Round up if there is no overflow.
146 }
147 }
148 return size;
149} // __kmp_round4k
150#endif
151
152static int __kmp_strcasecmp_with_sentinel(char const *a, char const *b,
153 char sentinel) {
154 if (a == NULL)
155 a = "";
156 if (b == NULL)
157 b = "";
158 while (*a && *b && *b != sentinel) {
159 char ca = *a, cb = *b;
160
161 if (ca >= 'a' && ca <= 'z')
162 ca -= 'a' - 'A';
163 if (cb >= 'a' && cb <= 'z')
164 cb -= 'a' - 'A';
165 if (ca != cb)
166 return (int)(unsigned char)*a - (int)(unsigned char)*b;
167 ++a;
168 ++b;
169 }
170 return *a ? (*b && *b != sentinel)
171 ? (int)(unsigned char)*a - (int)(unsigned char)*b
172 : 1
173 : (*b && *b != sentinel) ? -1
174 : 0;
175}
176
177// =============================================================================
178// Table structures and helper functions.
179
180typedef struct __kmp_setting kmp_setting_t;
181typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
182typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
183typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
184
185typedef void (*kmp_stg_parse_func_t)(char const *name, char const *value,
186 void *data);
187typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer, char const *name,
188 void *data);
189
190struct __kmp_setting {
191 char const *name; // Name of setting (environment variable).
192 kmp_stg_parse_func_t parse; // Parser function.
193 kmp_stg_print_func_t print; // Print function.
194 void *data; // Data passed to parser and printer.
195 int set; // Variable set during this "session"
196 // (__kmp_env_initialize() or kmp_set_defaults() call).
197 int defined; // Variable set in any "session".
198}; // struct __kmp_setting
199
200struct __kmp_stg_ss_data {
201 size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
202 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
203}; // struct __kmp_stg_ss_data
204
205struct __kmp_stg_wp_data {
206 int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
207 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
208}; // struct __kmp_stg_wp_data
209
210struct __kmp_stg_fr_data {
211 int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
212 kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
213}; // struct __kmp_stg_fr_data
214
215static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
216 char const *name, // Name of variable.
217 char const *value, // Value of the variable.
218 kmp_setting_t **rivals // List of rival settings (must include current one).
219);
220
221// Helper struct that trims heading/trailing white spaces
222struct kmp_trimmed_str_t {
223 kmp_str_buf_t buf;
224 kmp_trimmed_str_t(const char *str) {
225 __kmp_str_buf_init(&buf);
226 size_t len = KMP_STRLEN(str);
227 if (len == 0)
228 return;
229 const char *begin = str;
230 const char *end = str + KMP_STRLEN(str) - 1;
231 SKIP_WS(begin);
232 while (begin < end && *end == ' ')
233 end--;
234 __kmp_str_buf_cat(&buf, begin, end - begin + 1);
235 }
236 ~kmp_trimmed_str_t() { __kmp_str_buf_free(&buf); }
237 const char *get() { return buf.str; }
238};
239
240// -----------------------------------------------------------------------------
241// Helper parse functions.
242
243static void __kmp_stg_parse_bool(char const *name, char const *value,
244 int *out) {
245 if (__kmp_str_match_true(value)) {
246 *out = TRUE;
247 } else if (__kmp_str_match_false(value)) {
248 *out = FALSE;
249 } else {
250 __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
251 KMP_HNT(ValidBoolValues), __kmp_msg_null);
252 }
253} // __kmp_stg_parse_bool
254
255// placed here in order to use __kmp_round4k static function
256void __kmp_check_stksize(size_t *val) {
257 // if system stack size is too big then limit the size for worker threads
258 if (*val > KMP_DEFAULT_STKSIZE * 16) // just a heuristics...
259 *val = KMP_DEFAULT_STKSIZE * 16;
260 if (*val < __kmp_sys_min_stksize)
261 *val = __kmp_sys_min_stksize;
262 if (*val > KMP_MAX_STKSIZE)
263 *val = KMP_MAX_STKSIZE; // dead code currently, but may work in future
264#if KMP_OS_DARWIN
265 *val = __kmp_round4k(*val);
266#endif // KMP_OS_DARWIN
267}
268
269static void __kmp_stg_parse_size(char const *name, char const *value,
270 size_t size_min, size_t size_max,
271 int *is_specified, size_t *out,
272 size_t factor) {
273 char const *msg = NULL;
274#if KMP_OS_DARWIN
275 size_min = __kmp_round4k(size_min);
276 size_max = __kmp_round4k(size_max);
277#endif // KMP_OS_DARWIN
278 if (value) {
279 if (is_specified != NULL) {
280 *is_specified = 1;
281 }
282 __kmp_str_to_size(value, out, factor, &msg);
283 if (msg == NULL) {
284 if (*out > size_max) {
285 *out = size_max;
286 msg = KMP_I18N_STR(ValueTooLarge);
287 } else if (*out < size_min) {
288 *out = size_min;
289 msg = KMP_I18N_STR(ValueTooSmall);
290 } else {
291#if KMP_OS_DARWIN
292 size_t round4k = __kmp_round4k(*out);
293 if (*out != round4k) {
294 *out = round4k;
295 msg = KMP_I18N_STR(NotMultiple4K);
296 }
297#endif
298 }
299 } else {
300 // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to
301 // size_max silently.
302 if (*out < size_min) {
303 *out = size_max;
304 } else if (*out > size_max) {
305 *out = size_max;
306 }
307 }
308 if (msg != NULL) {
309 // Message is not empty. Print warning.
310 kmp_str_buf_t buf;
311 __kmp_str_buf_init(&buf);
312 __kmp_str_buf_print_size(&buf, *out);
313 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
314 KMP_INFORM(Using_str_Value, name, buf.str);
315 __kmp_str_buf_free(&buf);
316 }
317 }
318} // __kmp_stg_parse_size
319
320static void __kmp_stg_parse_str(char const *name, char const *value,
321 char **out) {
322 __kmp_str_free(out);
323 *out = __kmp_str_format("%s", value);
324} // __kmp_stg_parse_str
325
326static void __kmp_stg_parse_int(
327 char const
328 *name, // I: Name of environment variable (used in warning messages).
329 char const *value, // I: Value of environment variable to parse.
330 int min, // I: Minimum allowed value.
331 int max, // I: Maximum allowed value.
332 int *out // O: Output (parsed) value.
333) {
334 char const *msg = NULL;
335 kmp_uint64 uint = *out;
336 __kmp_str_to_uint(value, &uint, &msg);
337 if (msg == NULL) {
338 if (uint < (unsigned int)min) {
339 msg = KMP_I18N_STR(ValueTooSmall);
340 uint = min;
341 } else if (uint > (unsigned int)max) {
342 msg = KMP_I18N_STR(ValueTooLarge);
343 uint = max;
344 }
345 } else {
346 // If overflow occurred msg contains error message and uint is very big. Cut
347 // tmp it to INT_MAX.
348 if (uint < (unsigned int)min) {
349 uint = min;
350 } else if (uint > (unsigned int)max) {
351 uint = max;
352 }
353 }
354 if (msg != NULL) {
355 // Message is not empty. Print warning.
356 kmp_str_buf_t buf;
357 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
358 __kmp_str_buf_init(&buf);
359 __kmp_str_buf_print(&buf, "%" KMP_UINT64_SPEC "", uint);
360 KMP_INFORM(Using_uint64_Value, name, buf.str);
361 __kmp_str_buf_free(&buf);
362 }
363 __kmp_type_convert(uint, out);
364} // __kmp_stg_parse_int
365
366#if KMP_DEBUG_ADAPTIVE_LOCKS
367static void __kmp_stg_parse_file(char const *name, char const *value,
368 const char *suffix, char **out) {
369 char buffer[256];
370 char *t;
371 int hasSuffix;
372 __kmp_str_free(out);
373 t = (char *)strrchr(value, '.');
374 hasSuffix = t && __kmp_str_eqf(t, suffix);
375 t = __kmp_str_format("%s%s", value, hasSuffix ? "" : suffix);
376 __kmp_expand_file_name(buffer, sizeof(buffer), t);
377 __kmp_str_free(&t);
378 *out = __kmp_str_format("%s", buffer);
379} // __kmp_stg_parse_file
380#endif
381
382#ifdef KMP_DEBUG
383static char *par_range_to_print = NULL;
384
385static void __kmp_stg_parse_par_range(char const *name, char const *value,
386 int *out_range, char *out_routine,
387 char *out_file, int *out_lb,
388 int *out_ub) {
389 const char *par_range_value;
390 size_t len = KMP_STRLEN(value) + 1;
391 par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
392 KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
393 __kmp_par_range = +1;
394 __kmp_par_range_lb = 0;
395 __kmp_par_range_ub = INT_MAX;
396 for (;;) {
397 unsigned int len;
398 if (!value || *value == '\0') {
399 break;
400 }
401 if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
402 par_range_value = strchr(value, '=') + 1;
403 if (!par_range_value)
404 goto par_range_error;
405 value = par_range_value;
406 len = __kmp_readstr_with_sentinel(out_routine, value,
407 KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
408 if (len == 0) {
409 goto par_range_error;
410 }
411 value = strchr(value, ',');
412 if (value != NULL) {
413 value++;
414 }
415 continue;
416 }
417 if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
418 par_range_value = strchr(value, '=') + 1;
419 if (!par_range_value)
420 goto par_range_error;
421 value = par_range_value;
422 len = __kmp_readstr_with_sentinel(out_file, value,
423 KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
424 if (len == 0) {
425 goto par_range_error;
426 }
427 value = strchr(value, ',');
428 if (value != NULL) {
429 value++;
430 }
431 continue;
432 }
433 if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
434 (!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
435 par_range_value = strchr(value, '=') + 1;
436 if (!par_range_value)
437 goto par_range_error;
438 value = par_range_value;
439 if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
440 goto par_range_error;
441 }
442 *out_range = +1;
443 value = strchr(value, ',');
444 if (value != NULL) {
445 value++;
446 }
447 continue;
448 }
449 if (!__kmp_strcasecmp_with_sentinel("excl_range", value, '=')) {
450 par_range_value = strchr(value, '=') + 1;
451 if (!par_range_value)
452 goto par_range_error;
453 value = par_range_value;
454 if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
455 goto par_range_error;
456 }
457 *out_range = -1;
458 value = strchr(value, ',');
459 if (value != NULL) {
460 value++;
461 }
462 continue;
463 }
464 par_range_error:
465 KMP_WARNING(ParRangeSyntax, name);
466 __kmp_par_range = 0;
467 break;
468 }
469} // __kmp_stg_parse_par_range
470#endif
471
472int __kmp_initial_threads_capacity(int req_nproc) {
473 int nth = 32;
474
475 /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
476 * __kmp_max_nth) */
477 if (nth < (4 * req_nproc))
478 nth = (4 * req_nproc);
479 if (nth < (4 * __kmp_xproc))
480 nth = (4 * __kmp_xproc);
481
482 // If hidden helper task is enabled, we initialize the thread capacity with
483 // extra __kmp_hidden_helper_threads_num.
484 if (__kmp_enable_hidden_helper) {
485 nth += __kmp_hidden_helper_threads_num;
486 }
487
488 if (nth > __kmp_max_nth)
489 nth = __kmp_max_nth;
490
491 return nth;
492}
493
494int __kmp_default_tp_capacity(int req_nproc, int max_nth,
495 int all_threads_specified) {
496 int nth = 128;
497
498 if (all_threads_specified)
499 return max_nth;
500 /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
501 * __kmp_max_nth ) */
502 if (nth < (4 * req_nproc))
503 nth = (4 * req_nproc);
504 if (nth < (4 * __kmp_xproc))
505 nth = (4 * __kmp_xproc);
506
507 if (nth > __kmp_max_nth)
508 nth = __kmp_max_nth;
509
510 return nth;
511}
512
513// -----------------------------------------------------------------------------
514// Helper print functions.
515
516static void __kmp_stg_print_bool(kmp_str_buf_t *buffer, char const *name,
517 int value) {
518 if (__kmp_env_format) {
519 KMP_STR_BUF_PRINT_BOOL;
520 } else {
521 __kmp_str_buf_print(buffer, " %s=%s\n", name, value ? "true" : "false");
522 }
523} // __kmp_stg_print_bool
524
525static void __kmp_stg_print_int(kmp_str_buf_t *buffer, char const *name,
526 int value) {
527 if (__kmp_env_format) {
528 KMP_STR_BUF_PRINT_INT;
529 } else {
530 __kmp_str_buf_print(buffer, " %s=%d\n", name, value);
531 }
532} // __kmp_stg_print_int
533
534static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer, char const *name,
535 kmp_uint64 value) {
536 if (__kmp_env_format) {
537 KMP_STR_BUF_PRINT_UINT64;
538 } else {
539 __kmp_str_buf_print(buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value);
540 }
541} // __kmp_stg_print_uint64
542
543static void __kmp_stg_print_str(kmp_str_buf_t *buffer, char const *name,
544 char const *value) {
545 if (__kmp_env_format) {
546 KMP_STR_BUF_PRINT_STR;
547 } else {
548 __kmp_str_buf_print(buffer, " %s=%s\n", name, value);
549 }
550} // __kmp_stg_print_str
551
552static void __kmp_stg_print_size(kmp_str_buf_t *buffer, char const *name,
553 size_t value) {
554 if (__kmp_env_format) {
555 KMP_STR_BUF_PRINT_NAME_EX(name);
556 __kmp_str_buf_print_size(buffer, value);
557 __kmp_str_buf_print(buffer, "'\n");
558 } else {
559 __kmp_str_buf_print(buffer, " %s=", name);
560 __kmp_str_buf_print_size(buffer, value);
561 __kmp_str_buf_print(buffer, "\n");
562 return;
563 }
564} // __kmp_stg_print_size
565
566// =============================================================================
567// Parse and print functions.
568
569// -----------------------------------------------------------------------------
570// KMP_DEVICE_THREAD_LIMIT, KMP_ALL_THREADS
571
572static void __kmp_stg_parse_device_thread_limit(char const *name,
573 char const *value, void *data) {
574 kmp_setting_t **rivals = (kmp_setting_t **)data;
575 int rc;
576 if (strcmp(name, "KMP_ALL_THREADS") == 0) {
577 KMP_INFORM(EnvVarDeprecated, name, "KMP_DEVICE_THREAD_LIMIT");
578 }
579 rc = __kmp_stg_check_rivals(name, value, rivals);
580 if (rc) {
581 return;
582 }
583 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
584 __kmp_max_nth = __kmp_xproc;
585 __kmp_allThreadsSpecified = 1;
586 } else {
587 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
588 __kmp_allThreadsSpecified = 0;
589 }
590 K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));
591
592} // __kmp_stg_parse_device_thread_limit
593
594static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
595 char const *name, void *data) {
596 __kmp_stg_print_int(buffer, name, __kmp_max_nth);
597} // __kmp_stg_print_device_thread_limit
598
599// -----------------------------------------------------------------------------
600// OMP_THREAD_LIMIT
601static void __kmp_stg_parse_thread_limit(char const *name, char const *value,
602 void *data) {
603 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
604 K_DIAG(1, ("__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));
605
606} // __kmp_stg_parse_thread_limit
607
608static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
609 char const *name, void *data) {
610 __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
611} // __kmp_stg_print_thread_limit
612
613// -----------------------------------------------------------------------------
614// OMP_NUM_TEAMS
615static void __kmp_stg_parse_nteams(char const *name, char const *value,
616 void *data) {
617 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_nteams);
618 K_DIAG(1, ("__kmp_nteams == %d\n", __kmp_nteams));
619} // __kmp_stg_parse_nteams
620
621static void __kmp_stg_print_nteams(kmp_str_buf_t *buffer, char const *name,
622 void *data) {
623 __kmp_stg_print_int(buffer, name, __kmp_nteams);
624} // __kmp_stg_print_nteams
625
626// -----------------------------------------------------------------------------
627// OMP_TEAMS_THREAD_LIMIT
628static void __kmp_stg_parse_teams_th_limit(char const *name, char const *value,
629 void *data) {
630 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth,
631 &__kmp_teams_thread_limit);
632 K_DIAG(1, ("__kmp_teams_thread_limit == %d\n", __kmp_teams_thread_limit));
633} // __kmp_stg_parse_teams_th_limit
634
635static void __kmp_stg_print_teams_th_limit(kmp_str_buf_t *buffer,
636 char const *name, void *data) {
637 __kmp_stg_print_int(buffer, name, __kmp_teams_thread_limit);
638} // __kmp_stg_print_teams_th_limit
639
640// -----------------------------------------------------------------------------
641// KMP_TEAMS_THREAD_LIMIT
642static void __kmp_stg_parse_teams_thread_limit(char const *name,
643 char const *value, void *data) {
644 __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
645} // __kmp_stg_teams_thread_limit
646
647static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
648 char const *name, void *data) {
649 __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
650} // __kmp_stg_print_teams_thread_limit
651
652// -----------------------------------------------------------------------------
653// KMP_USE_YIELD
654static void __kmp_stg_parse_use_yield(char const *name, char const *value,
655 void *data) {
656 __kmp_stg_parse_int(name, value, 0, 2, &__kmp_use_yield);
657 __kmp_use_yield_exp_set = 1;
658} // __kmp_stg_parse_use_yield
659
660static void __kmp_stg_print_use_yield(kmp_str_buf_t *buffer, char const *name,
661 void *data) {
662 __kmp_stg_print_int(buffer, name, __kmp_use_yield);
663} // __kmp_stg_print_use_yield
664
665// -----------------------------------------------------------------------------
666// KMP_BLOCKTIME
667
668static void __kmp_stg_parse_blocktime(char const *name, char const *value,
669 void *data) {
670 const char *buf = value;
671 const char *next;
672 const int ms_mult = 1000;
673 int multiplier = 1;
674 int num;
675
676 // Read integer blocktime value
677 SKIP_WS(buf);
678 if ((*buf >= '0') && (*buf <= '9')) {
679 next = buf;
680 SKIP_DIGITS(next);
681 num = __kmp_basic_str_to_int(buf);
682 KMP_ASSERT(num >= 0);
683 buf = next;
684 SKIP_WS(buf);
685 } else {
686 num = -1;
687 }
688
689 // Read units: note that __kmp_dflt_blocktime units is now us
690 next = buf;
691 if (*buf == '\0' || __kmp_match_str("ms", buf, &next)) {
692 // units are in ms; convert
693 __kmp_dflt_blocktime = ms_mult * num;
694 __kmp_blocktime_units = 'm';
695 multiplier = ms_mult;
696 } else if (__kmp_match_str("us", buf, &next)) {
697 // units are in us
698 __kmp_dflt_blocktime = num;
699 __kmp_blocktime_units = 'u';
700 } else if (__kmp_match_str("infinite", buf, &next) ||
701 __kmp_match_str("infinity", buf, &next)) {
702 // units are in ms
703 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
704 __kmp_blocktime_units = 'm';
705 multiplier = ms_mult;
706 } else {
707 KMP_WARNING(StgInvalidValue, name, value);
708 // default units are in ms
709 __kmp_dflt_blocktime = ms_mult * num;
710 __kmp_blocktime_units = 'm';
711 multiplier = ms_mult;
712 }
713
714 if (num < 0 && __kmp_dflt_blocktime < 0) { // num out of range
715 __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME; // now in us
716 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
717 __kmp_msg_null);
718 // Inform in appropriate units
719 KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime / multiplier);
720 __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
721 } else if (num > 0 && __kmp_dflt_blocktime < 0) { // overflow
722 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
723 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value), __kmp_msg_null);
724 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime / multiplier);
725 __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
726 } else {
727 if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
728 __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
729 __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
730 __kmp_msg_null);
731 KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime / multiplier);
732 } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
733 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
734 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
735 __kmp_msg_null);
736 KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime / multiplier);
737 }
738 __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
739 }
740#if KMP_USE_MONITOR
741 // calculate number of monitor thread wakeup intervals corresponding to
742 // blocktime.
743 __kmp_monitor_wakeups =
744 KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
745 __kmp_bt_intervals =
746 KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
747#endif
748 K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
749 if (__kmp_env_blocktime) {
750 K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
751 }
752} // __kmp_stg_parse_blocktime
753
754static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
755 void *data) {
756 int num = __kmp_dflt_blocktime;
757 if (__kmp_blocktime_units == 'm') {
758 num = num / 1000;
759 }
760 if (__kmp_env_format) {
761 KMP_STR_BUF_PRINT_NAME_EX(name);
762 } else {
763 __kmp_str_buf_print(buffer, " %s=", name);
764 }
765 __kmp_str_buf_print(buffer, "%d", num);
766 __kmp_str_buf_print(buffer, "%cs\n", __kmp_blocktime_units);
767} // __kmp_stg_print_blocktime
768
769// -----------------------------------------------------------------------------
770// KMP_DUPLICATE_LIB_OK
771
772static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
773 char const *value, void *data) {
774 /* actually this variable is not supported, put here for compatibility with
775 earlier builds and for static/dynamic combination */
776 __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
777} // __kmp_stg_parse_duplicate_lib_ok
778
779static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
780 char const *name, void *data) {
781 __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
782} // __kmp_stg_print_duplicate_lib_ok
783
784// -----------------------------------------------------------------------------
785// KMP_INHERIT_FP_CONTROL
786
787#if KMP_ARCH_X86 || KMP_ARCH_X86_64
788
789static void __kmp_stg_parse_inherit_fp_control(char const *name,
790 char const *value, void *data) {
791 __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
792} // __kmp_stg_parse_inherit_fp_control
793
794static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
795 char const *name, void *data) {
796#if KMP_DEBUG
797 __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
798#endif /* KMP_DEBUG */
799} // __kmp_stg_print_inherit_fp_control
800
801#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
802
803// Used for OMP_WAIT_POLICY
804static char const *blocktime_str = NULL;
805
806// -----------------------------------------------------------------------------
807// KMP_LIBRARY, OMP_WAIT_POLICY
808
809static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
810 void *data) {
811
812 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
813 int rc;
814
815 rc = __kmp_stg_check_rivals(name, value, wait->rivals);
816 if (rc) {
817 return;
818 }
819
820 if (wait->omp) {
821 if (__kmp_str_match("ACTIVE", 1, value)) {
822 __kmp_library = library_turnaround;
823 if (blocktime_str == NULL) {
824 // KMP_BLOCKTIME not specified, so set default to "infinite".
825 __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
826 }
827 } else if (__kmp_str_match("PASSIVE", 1, value)) {
828 __kmp_library = library_throughput;
829 __kmp_wpolicy_passive = true; /* allow sleep while active tasking */
830 if (blocktime_str == NULL) {
831 // KMP_BLOCKTIME not specified, so set default to 0.
832 __kmp_dflt_blocktime = 0;
833 }
834 } else {
835 KMP_WARNING(StgInvalidValue, name, value);
836 }
837 } else {
838 if (__kmp_str_match("serial", 1, value)) { /* S */
839 __kmp_library = library_serial;
840 } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
841 __kmp_library = library_throughput;
842 if (blocktime_str == NULL) {
843 // KMP_BLOCKTIME not specified, so set default to 0.
844 __kmp_dflt_blocktime = 0;
845 }
846 } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
847 __kmp_library = library_turnaround;
848 } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
849 __kmp_library = library_turnaround;
850 } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
851 __kmp_library = library_throughput;
852 if (blocktime_str == NULL) {
853 // KMP_BLOCKTIME not specified, so set default to 0.
854 __kmp_dflt_blocktime = 0;
855 }
856 } else {
857 KMP_WARNING(StgInvalidValue, name, value);
858 }
859 }
860} // __kmp_stg_parse_wait_policy
861
862static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
863 void *data) {
864
865 kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
866 char const *value = NULL;
867
868 if (wait->omp) {
869 switch (__kmp_library) {
870 case library_turnaround: {
871 value = "ACTIVE";
872 } break;
873 case library_throughput: {
874 value = "PASSIVE";
875 } break;
876 case library_none:
877 case library_serial: {
878 value = NULL;
879 } break;
880 }
881 } else {
882 switch (__kmp_library) {
883 case library_serial: {
884 value = "serial";
885 } break;
886 case library_turnaround: {
887 value = "turnaround";
888 } break;
889 case library_throughput: {
890 value = "throughput";
891 } break;
892 case library_none: {
893 value = NULL;
894 } break;
895 }
896 }
897 if (value != NULL) {
898 __kmp_stg_print_str(buffer, name, value);
899 }
900
901} // __kmp_stg_print_wait_policy
902
903#if KMP_USE_MONITOR
904// -----------------------------------------------------------------------------
905// KMP_MONITOR_STACKSIZE
906
907static void __kmp_stg_parse_monitor_stacksize(char const *name,
908 char const *value, void *data) {
909 __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
910 NULL, &__kmp_monitor_stksize, 1);
911} // __kmp_stg_parse_monitor_stacksize
912
913static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
914 char const *name, void *data) {
915 if (__kmp_env_format) {
916 if (__kmp_monitor_stksize > 0)
917 KMP_STR_BUF_PRINT_NAME_EX(name);
918 else
919 KMP_STR_BUF_PRINT_NAME;
920 } else {
921 __kmp_str_buf_print(buffer, " %s", name);
922 }
923 if (__kmp_monitor_stksize > 0) {
924 __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
925 } else {
926 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
927 }
928 if (__kmp_env_format && __kmp_monitor_stksize) {
929 __kmp_str_buf_print(buffer, "'\n");
930 }
931} // __kmp_stg_print_monitor_stacksize
932#endif // KMP_USE_MONITOR
933
934// -----------------------------------------------------------------------------
935// KMP_SETTINGS
936
937static void __kmp_stg_parse_settings(char const *name, char const *value,
938 void *data) {
939 __kmp_stg_parse_bool(name, value, &__kmp_settings);
940} // __kmp_stg_parse_settings
941
942static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
943 void *data) {
944 __kmp_stg_print_bool(buffer, name, __kmp_settings);
945} // __kmp_stg_print_settings
946
947// -----------------------------------------------------------------------------
948// KMP_STACKPAD
949
950static void __kmp_stg_parse_stackpad(char const *name, char const *value,
951 void *data) {
952 __kmp_stg_parse_int(name, // Env var name
953 value, // Env var value
954 KMP_MIN_STKPADDING, // Min value
955 KMP_MAX_STKPADDING, // Max value
956 &__kmp_stkpadding // Var to initialize
957 );
958} // __kmp_stg_parse_stackpad
959
960static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
961 void *data) {
962 __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
963} // __kmp_stg_print_stackpad
964
965// -----------------------------------------------------------------------------
966// KMP_STACKOFFSET
967
968static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
969 void *data) {
970 __kmp_stg_parse_size(name, // Env var name
971 value, // Env var value
972 KMP_MIN_STKOFFSET, // Min value
973 KMP_MAX_STKOFFSET, // Max value
974 NULL, //
975 &__kmp_stkoffset, // Var to initialize
976 1);
977} // __kmp_stg_parse_stackoffset
978
979static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
980 void *data) {
981 __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
982} // __kmp_stg_print_stackoffset
983
984// -----------------------------------------------------------------------------
985// KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
986
987static void __kmp_stg_parse_stacksize(char const *name, char const *value,
988 void *data) {
989
990 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
991 int rc;
992
993 rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
994 if (rc) {
995 return;
996 }
997 __kmp_stg_parse_size(name, // Env var name
998 value, // Env var value
999 __kmp_sys_min_stksize, // Min value
1000 KMP_MAX_STKSIZE, // Max value
1001 &__kmp_env_stksize, //
1002 &__kmp_stksize, // Var to initialize
1003 stacksize->factor);
1004
1005} // __kmp_stg_parse_stacksize
1006
1007// This function is called for printing both KMP_STACKSIZE (factor is 1) and
1008// OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
1009// OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
1010// customer request in future.
1011static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
1012 void *data) {
1013 kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
1014 if (__kmp_env_format) {
1015 KMP_STR_BUF_PRINT_NAME_EX(name);
1016 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
1017 ? __kmp_stksize / stacksize->factor
1018 : __kmp_stksize);
1019 __kmp_str_buf_print(buffer, "'\n");
1020 } else {
1021 __kmp_str_buf_print(buffer, " %s=", name);
1022 __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
1023 ? __kmp_stksize / stacksize->factor
1024 : __kmp_stksize);
1025 __kmp_str_buf_print(buffer, "\n");
1026 }
1027} // __kmp_stg_print_stacksize
1028
1029// -----------------------------------------------------------------------------
1030// KMP_VERSION
1031
1032static void __kmp_stg_parse_version(char const *name, char const *value,
1033 void *data) {
1034 __kmp_stg_parse_bool(name, value, &__kmp_version);
1035} // __kmp_stg_parse_version
1036
1037static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
1038 void *data) {
1039 __kmp_stg_print_bool(buffer, name, __kmp_version);
1040} // __kmp_stg_print_version
1041
1042// -----------------------------------------------------------------------------
1043// KMP_WARNINGS
1044
1045static void __kmp_stg_parse_warnings(char const *name, char const *value,
1046 void *data) {
1047 __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
1048 if (__kmp_generate_warnings != kmp_warnings_off) {
1049 // AC: only 0/1 values documented, so reset to explicit to distinguish from
1050 // default setting
1051 __kmp_generate_warnings = kmp_warnings_explicit;
1052 }
1053} // __kmp_stg_parse_warnings
1054
1055static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
1056 void *data) {
1057 // AC: TODO: change to print_int? (needs documentation change)
1058 __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
1059} // __kmp_stg_print_warnings
1060
1061// -----------------------------------------------------------------------------
1062// KMP_NESTING_MODE
1063
1064static void __kmp_stg_parse_nesting_mode(char const *name, char const *value,
1065 void *data) {
1066 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_nesting_mode);
1067#if KMP_AFFINITY_SUPPORTED && KMP_USE_HWLOC
1068 if (__kmp_nesting_mode > 0)
1069 __kmp_affinity_top_method = affinity_top_method_hwloc;
1070#endif
1071} // __kmp_stg_parse_nesting_mode
1072
1073static void __kmp_stg_print_nesting_mode(kmp_str_buf_t *buffer,
1074 char const *name, void *data) {
1075 if (__kmp_env_format) {
1076 KMP_STR_BUF_PRINT_NAME;
1077 } else {
1078 __kmp_str_buf_print(buffer, " %s", name);
1079 }
1080 __kmp_str_buf_print(buffer, "=%d\n", __kmp_nesting_mode);
1081} // __kmp_stg_print_nesting_mode
1082
1083// -----------------------------------------------------------------------------
1084// OMP_NESTED, OMP_NUM_THREADS
1085
1086static void __kmp_stg_parse_nested(char const *name, char const *value,
1087 void *data) {
1088 int nested;
1089 KMP_INFORM(EnvVarDeprecated, name, "OMP_MAX_ACTIVE_LEVELS");
1090 __kmp_stg_parse_bool(name, value, &nested);
1091 if (nested) {
1092 if (!__kmp_dflt_max_active_levels_set)
1093 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1094 } else { // nesting explicitly turned off
1095 __kmp_dflt_max_active_levels = 1;
1096 __kmp_dflt_max_active_levels_set = true;
1097 }
1098} // __kmp_stg_parse_nested
1099
1100static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
1101 void *data) {
1102 if (__kmp_env_format) {
1103 KMP_STR_BUF_PRINT_NAME;
1104 } else {
1105 __kmp_str_buf_print(buffer, " %s", name);
1106 }
1107 __kmp_str_buf_print(buffer, ": deprecated; max-active-levels-var=%d\n",
1108 __kmp_dflt_max_active_levels);
1109} // __kmp_stg_print_nested
1110
1111static void __kmp_parse_nested_num_threads(const char *var, const char *env,
1112 kmp_nested_nthreads_t *nth_array) {
1113 const char *next = env;
1114 const char *scan = next;
1115
1116 int total = 0; // Count elements that were set. It'll be used as an array size
1117 int prev_comma = FALSE; // For correct processing sequential commas
1118
1119 // Count the number of values in the env. var string
1120 for (;;) {
1121 SKIP_WS(next);
1122
1123 if (*next == '\0') {
1124 break;
1125 }
1126 // Next character is not an integer or not a comma => end of list
1127 if (((*next < '0') || (*next > '9')) && (*next != ',')) {
1128 KMP_WARNING(NthSyntaxError, var, env);
1129 return;
1130 }
1131 // The next character is ','
1132 if (*next == ',') {
1133 // ',' is the first character
1134 if (total == 0 || prev_comma) {
1135 total++;
1136 }
1137 prev_comma = TRUE;
1138 next++; // skip ','
1139 SKIP_WS(next);
1140 }
1141 // Next character is a digit
1142 if (*next >= '0' && *next <= '9') {
1143 prev_comma = FALSE;
1144 SKIP_DIGITS(next);
1145 total++;
1146 const char *tmp = next;
1147 SKIP_WS(tmp);
1148 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
1149 KMP_WARNING(NthSpacesNotAllowed, var, env);
1150 return;
1151 }
1152 }
1153 }
1154 if (!__kmp_dflt_max_active_levels_set && total > 1)
1155 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
1156 KMP_DEBUG_ASSERT(total > 0);
1157 if (total <= 0) {
1158 KMP_WARNING(NthSyntaxError, var, env);
1159 return;
1160 }
1161
1162 // Check if the nested nthreads array exists
1163 if (!nth_array->nth) {
1164 // Allocate an array of double size
1165 nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
1166 if (nth_array->nth == NULL) {
1167 KMP_FATAL(MemoryAllocFailed);
1168 }
1169 nth_array->size = total * 2;
1170 } else {
1171 if (nth_array->size < total) {
1172 // Increase the array size
1173 do {
1174 nth_array->size *= 2;
1175 } while (nth_array->size < total);
1176
1177 nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
1178 nth_array->nth, sizeof(int) * nth_array->size);
1179 if (nth_array->nth == NULL) {
1180 KMP_FATAL(MemoryAllocFailed);
1181 }
1182 }
1183 }
1184 nth_array->used = total;
1185 int i = 0;
1186
1187 prev_comma = FALSE;
1188 total = 0;
1189 // Save values in the array
1190 for (;;) {
1191 SKIP_WS(scan);
1192 if (*scan == '\0') {
1193 break;
1194 }
1195 // The next character is ','
1196 if (*scan == ',') {
1197 // ',' in the beginning of the list
1198 if (total == 0) {
1199 // The value is supposed to be equal to __kmp_avail_proc but it is
1200 // unknown at the moment.
1201 // So let's put a placeholder (#threads = 0) to correct it later.
1202 nth_array->nth[i++] = 0;
1203 total++;
1204 } else if (prev_comma) {
1205 // Num threads is inherited from the previous level
1206 nth_array->nth[i] = nth_array->nth[i - 1];
1207 i++;
1208 total++;
1209 }
1210 prev_comma = TRUE;
1211 scan++; // skip ','
1212 SKIP_WS(scan);
1213 }
1214 // Next character is a digit
1215 if (*scan >= '0' && *scan <= '9') {
1216 int num;
1217 const char *buf = scan;
1218 char const *msg = NULL;
1219 prev_comma = FALSE;
1220 SKIP_DIGITS(scan);
1221 total++;
1222
1223 num = __kmp_str_to_int(buf, *scan);
1224 if (num < KMP_MIN_NTH) {
1225 msg = KMP_I18N_STR(ValueTooSmall);
1226 num = KMP_MIN_NTH;
1227 } else if (num > __kmp_sys_max_nth) {
1228 msg = KMP_I18N_STR(ValueTooLarge);
1229 num = __kmp_sys_max_nth;
1230 }
1231 if (msg != NULL) {
1232 // Message is not empty. Print warning.
1233 KMP_WARNING(ParseSizeIntWarn, var, env, msg);
1234 KMP_INFORM(Using_int_Value, var, num);
1235 }
1236 nth_array->nth[i++] = num;
1237 }
1238 }
1239}
1240
1241static void __kmp_stg_parse_num_threads(char const *name, char const *value,
1242 void *data) {
1243 // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
1244 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
1245 // The array of 1 element
1246 __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
1247 __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
1248 __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
1249 __kmp_xproc;
1250 } else {
1251 __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
1252 if (__kmp_nested_nth.nth) {
1253 __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
1254 if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
1255 __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
1256 }
1257 }
1258 }
1259 K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
1260} // __kmp_stg_parse_num_threads
1261
1262#if OMPX_TASKGRAPH
1263static void __kmp_stg_parse_max_tdgs(char const *name, char const *value,
1264 void *data) {
1265 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_max_tdgs);
1266} // __kmp_stg_parse_max_tdgs
1267
1268static void __kmp_std_print_max_tdgs(kmp_str_buf_t *buffer, char const *name,
1269 void *data) {
1270 __kmp_stg_print_int(buffer, name, __kmp_max_tdgs);
1271} // __kmp_std_print_max_tdgs
1272
1273static void __kmp_stg_parse_tdg_dot(char const *name, char const *value,
1274 void *data) {
1275 __kmp_stg_parse_bool(name, value, &__kmp_tdg_dot);
1276} // __kmp_stg_parse_tdg_dot
1277
1278static void __kmp_stg_print_tdg_dot(kmp_str_buf_t *buffer, char const *name,
1279 void *data) {
1280 __kmp_stg_print_bool(buffer, name, __kmp_tdg_dot);
1281} // __kmp_stg_print_tdg_dot
1282#endif
1283
1284static void __kmp_stg_parse_num_hidden_helper_threads(char const *name,
1285 char const *value,
1286 void *data) {
1287 __kmp_stg_parse_int(name, value, 0, 16, &__kmp_hidden_helper_threads_num);
1288 // If the number of hidden helper threads is zero, we disable hidden helper
1289 // task
1290 if (__kmp_hidden_helper_threads_num == 0) {
1291 __kmp_enable_hidden_helper = FALSE;
1292 } else {
1293 // Since the main thread of hidden helper team does not participate
1294 // in tasks execution let's increment the number of threads by one
1295 // so that requested number of threads do actual job.
1296 __kmp_hidden_helper_threads_num++;
1297 }
1298} // __kmp_stg_parse_num_hidden_helper_threads
1299
1300static void __kmp_stg_print_num_hidden_helper_threads(kmp_str_buf_t *buffer,
1301 char const *name,
1302 void *data) {
1303 if (__kmp_hidden_helper_threads_num == 0) {
1304 __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num);
1305 } else {
1306 KMP_DEBUG_ASSERT(__kmp_hidden_helper_threads_num > 1);
1307 // Let's exclude the main thread of hidden helper team and print
1308 // number of worker threads those do actual job.
1309 __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num - 1);
1310 }
1311} // __kmp_stg_print_num_hidden_helper_threads
1312
1313static void __kmp_stg_parse_use_hidden_helper(char const *name,
1314 char const *value, void *data) {
1315 __kmp_stg_parse_bool(name, value, &__kmp_enable_hidden_helper);
1316#if !KMP_OS_LINUX
1317 __kmp_enable_hidden_helper = FALSE;
1318 K_DIAG(1,
1319 ("__kmp_stg_parse_use_hidden_helper: Disable hidden helper task on "
1320 "non-Linux platform although it is enabled by user explicitly.\n"));
1321#endif
1322} // __kmp_stg_parse_use_hidden_helper
1323
1324static void __kmp_stg_print_use_hidden_helper(kmp_str_buf_t *buffer,
1325 char const *name, void *data) {
1326 __kmp_stg_print_bool(buffer, name, __kmp_enable_hidden_helper);
1327} // __kmp_stg_print_use_hidden_helper
1328
1329static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
1330 void *data) {
1331 if (__kmp_env_format) {
1332 KMP_STR_BUF_PRINT_NAME;
1333 } else {
1334 __kmp_str_buf_print(buffer, " %s", name);
1335 }
1336 if (__kmp_nested_nth.used) {
1337 kmp_str_buf_t buf;
1338 __kmp_str_buf_init(&buf);
1339 for (int i = 0; i < __kmp_nested_nth.used; i++) {
1340 __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
1341 if (i < __kmp_nested_nth.used - 1) {
1342 __kmp_str_buf_print(&buf, ",");
1343 }
1344 }
1345 __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
1346 __kmp_str_buf_free(&buf);
1347 } else {
1348 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
1349 }
1350} // __kmp_stg_print_num_threads
1351
1352// -----------------------------------------------------------------------------
1353// OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
1354
1355static void __kmp_stg_parse_tasking(char const *name, char const *value,
1356 void *data) {
1357 __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
1358 (int *)&__kmp_tasking_mode);
1359} // __kmp_stg_parse_tasking
1360
1361static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
1362 void *data) {
1363 __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
1364} // __kmp_stg_print_tasking
1365
1366static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
1367 void *data) {
1368 __kmp_stg_parse_int(name, value, 0, 1,
1369 (int *)&__kmp_task_stealing_constraint);
1370} // __kmp_stg_parse_task_stealing
1371
1372static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
1373 char const *name, void *data) {
1374 __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
1375} // __kmp_stg_print_task_stealing
1376
1377static void __kmp_stg_parse_max_active_levels(char const *name,
1378 char const *value, void *data) {
1379 kmp_uint64 tmp_dflt = 0;
1380 char const *msg = NULL;
1381 if (!__kmp_dflt_max_active_levels_set) {
1382 // Don't overwrite __kmp_dflt_max_active_levels if we get an invalid setting
1383 __kmp_str_to_uint(value, &tmp_dflt, &msg);
1384 if (msg != NULL) { // invalid setting; print warning and ignore
1385 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1386 } else if (tmp_dflt > KMP_MAX_ACTIVE_LEVELS_LIMIT) {
1387 // invalid setting; print warning and ignore
1388 msg = KMP_I18N_STR(ValueTooLarge);
1389 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
1390 } else { // valid setting
1391 __kmp_type_convert(tmp_dflt, &(__kmp_dflt_max_active_levels));
1392 __kmp_dflt_max_active_levels_set = true;
1393 }
1394 }
1395} // __kmp_stg_parse_max_active_levels
1396
1397static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
1398 char const *name, void *data) {
1399 __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
1400} // __kmp_stg_print_max_active_levels
1401
1402// -----------------------------------------------------------------------------
1403// OpenMP 4.0: OMP_DEFAULT_DEVICE
1404static void __kmp_stg_parse_default_device(char const *name, char const *value,
1405 void *data) {
1406 __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
1407 &__kmp_default_device);
1408} // __kmp_stg_parse_default_device
1409
1410static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
1411 char const *name, void *data) {
1412 __kmp_stg_print_int(buffer, name, __kmp_default_device);
1413} // __kmp_stg_print_default_device
1414
1415// -----------------------------------------------------------------------------
1416// OpenMP 5.0: OMP_TARGET_OFFLOAD
1417static void __kmp_stg_parse_target_offload(char const *name, char const *value,
1418 void *data) {
1419 kmp_trimmed_str_t value_str(value);
1420 const char *scan = value_str.get();
1421 __kmp_target_offload = tgt_default;
1422
1423 if (*scan == '\0')
1424 return;
1425
1426 if (!__kmp_strcasecmp_with_sentinel("mandatory", scan, 0)) {
1427 __kmp_target_offload = tgt_mandatory;
1428 } else if (!__kmp_strcasecmp_with_sentinel("disabled", scan, 0)) {
1429 __kmp_target_offload = tgt_disabled;
1430 } else if (!__kmp_strcasecmp_with_sentinel("default", scan, 0)) {
1431 __kmp_target_offload = tgt_default;
1432 } else {
1433 KMP_WARNING(SyntaxErrorUsing, name, "DEFAULT");
1434 }
1435} // __kmp_stg_parse_target_offload
1436
1437static void __kmp_stg_print_target_offload(kmp_str_buf_t *buffer,
1438 char const *name, void *data) {
1439 const char *value = NULL;
1440 if (__kmp_target_offload == tgt_default)
1441 value = "DEFAULT";
1442 else if (__kmp_target_offload == tgt_mandatory)
1443 value = "MANDATORY";
1444 else if (__kmp_target_offload == tgt_disabled)
1445 value = "DISABLED";
1446 KMP_DEBUG_ASSERT(value);
1447 if (__kmp_env_format) {
1448 KMP_STR_BUF_PRINT_NAME;
1449 } else {
1450 __kmp_str_buf_print(buffer, " %s", name);
1451 }
1452 __kmp_str_buf_print(buffer, "=%s\n", value);
1453} // __kmp_stg_print_target_offload
1454
1455// -----------------------------------------------------------------------------
1456// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
1457static void __kmp_stg_parse_max_task_priority(char const *name,
1458 char const *value, void *data) {
1459 __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
1460 &__kmp_max_task_priority);
1461} // __kmp_stg_parse_max_task_priority
1462
1463static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
1464 char const *name, void *data) {
1465 __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
1466} // __kmp_stg_print_max_task_priority
1467
1468// KMP_TASKLOOP_MIN_TASKS
1469// taskloop threshold to switch from recursive to linear tasks creation
1470static void __kmp_stg_parse_taskloop_min_tasks(char const *name,
1471 char const *value, void *data) {
1472 int tmp = 0;
1473 __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
1474 __kmp_taskloop_min_tasks = tmp;
1475} // __kmp_stg_parse_taskloop_min_tasks
1476
1477static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
1478 char const *name, void *data) {
1479 __kmp_stg_print_uint64(buffer, name, __kmp_taskloop_min_tasks);
1480} // __kmp_stg_print_taskloop_min_tasks
1481
1482// -----------------------------------------------------------------------------
1483// KMP_DISP_NUM_BUFFERS
1484static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
1485 void *data) {
1486 if (TCR_4(__kmp_init_serial)) {
1487 KMP_WARNING(EnvSerialWarn, name);
1488 return;
1489 } // read value before serial initialization only
1490 __kmp_stg_parse_int(name, value, KMP_MIN_DISP_NUM_BUFF, KMP_MAX_DISP_NUM_BUFF,
1491 &__kmp_dispatch_num_buffers);
1492} // __kmp_stg_parse_disp_buffers
1493
1494static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
1495 char const *name, void *data) {
1496 __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
1497} // __kmp_stg_print_disp_buffers
1498
1499#if KMP_NESTED_HOT_TEAMS
1500// -----------------------------------------------------------------------------
1501// KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
1502
1503static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
1504 void *data) {
1505 if (TCR_4(__kmp_init_parallel)) {
1506 KMP_WARNING(EnvParallelWarn, name);
1507 return;
1508 } // read value before first parallel only
1509 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1510 &__kmp_hot_teams_max_level);
1511} // __kmp_stg_parse_hot_teams_level
1512
1513static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
1514 char const *name, void *data) {
1515 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
1516} // __kmp_stg_print_hot_teams_level
1517
1518static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
1519 void *data) {
1520 if (TCR_4(__kmp_init_parallel)) {
1521 KMP_WARNING(EnvParallelWarn, name);
1522 return;
1523 } // read value before first parallel only
1524 __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
1525 &__kmp_hot_teams_mode);
1526} // __kmp_stg_parse_hot_teams_mode
1527
1528static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
1529 char const *name, void *data) {
1530 __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
1531} // __kmp_stg_print_hot_teams_mode
1532
1533#endif // KMP_NESTED_HOT_TEAMS
1534
1535// -----------------------------------------------------------------------------
1536// KMP_HANDLE_SIGNALS
1537
1538#if KMP_HANDLE_SIGNALS
1539
1540static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
1541 void *data) {
1542 __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
1543} // __kmp_stg_parse_handle_signals
1544
1545static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
1546 char const *name, void *data) {
1547 __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
1548} // __kmp_stg_print_handle_signals
1549
1550#endif // KMP_HANDLE_SIGNALS
1551
1552// -----------------------------------------------------------------------------
1553// KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
1554
1555#ifdef KMP_DEBUG
1556
1557#define KMP_STG_X_DEBUG(x) \
1558 static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
1559 void *data) { \
1560 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
1561 } /* __kmp_stg_parse_x_debug */ \
1562 static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
1563 char const *name, void *data) { \
1564 __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
1565 } /* __kmp_stg_print_x_debug */
1566
1567KMP_STG_X_DEBUG(a)
1568KMP_STG_X_DEBUG(b)
1569KMP_STG_X_DEBUG(c)
1570KMP_STG_X_DEBUG(d)
1571KMP_STG_X_DEBUG(e)
1572KMP_STG_X_DEBUG(f)
1573
1574#undef KMP_STG_X_DEBUG
1575
1576static void __kmp_stg_parse_debug(char const *name, char const *value,
1577 void *data) {
1578 int debug = 0;
1579 __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
1580 if (kmp_a_debug < debug) {
1581 kmp_a_debug = debug;
1582 }
1583 if (kmp_b_debug < debug) {
1584 kmp_b_debug = debug;
1585 }
1586 if (kmp_c_debug < debug) {
1587 kmp_c_debug = debug;
1588 }
1589 if (kmp_d_debug < debug) {
1590 kmp_d_debug = debug;
1591 }
1592 if (kmp_e_debug < debug) {
1593 kmp_e_debug = debug;
1594 }
1595 if (kmp_f_debug < debug) {
1596 kmp_f_debug = debug;
1597 }
1598} // __kmp_stg_parse_debug
1599
1600static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
1601 void *data) {
1602 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
1603 // !!! TODO: Move buffer initialization of this file! It may works
1604 // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
1605 // KMP_DEBUG_BUF_CHARS.
1606 if (__kmp_debug_buf) {
1607 int i;
1608 int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
1609
1610 /* allocate and initialize all entries in debug buffer to empty */
1611 __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
1612 for (i = 0; i < elements; i += __kmp_debug_buf_chars)
1613 __kmp_debug_buffer[i] = '\0';
1614
1615 __kmp_debug_count = 0;
1616 }
1617 K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
1618} // __kmp_stg_parse_debug_buf
1619
1620static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
1621 void *data) {
1622 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
1623} // __kmp_stg_print_debug_buf
1624
1625static void __kmp_stg_parse_debug_buf_atomic(char const *name,
1626 char const *value, void *data) {
1627 __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
1628} // __kmp_stg_parse_debug_buf_atomic
1629
1630static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
1631 char const *name, void *data) {
1632 __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
1633} // __kmp_stg_print_debug_buf_atomic
1634
1635static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
1636 void *data) {
1637 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
1638 &__kmp_debug_buf_chars);
1639} // __kmp_stg_debug_parse_buf_chars
1640
1641static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
1642 char const *name, void *data) {
1643 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
1644} // __kmp_stg_print_debug_buf_chars
1645
1646static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
1647 void *data) {
1648 __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
1649 &__kmp_debug_buf_lines);
1650} // __kmp_stg_parse_debug_buf_lines
1651
1652static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
1653 char const *name, void *data) {
1654 __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
1655} // __kmp_stg_print_debug_buf_lines
1656
1657static void __kmp_stg_parse_diag(char const *name, char const *value,
1658 void *data) {
1659 __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
1660} // __kmp_stg_parse_diag
1661
1662static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
1663 void *data) {
1664 __kmp_stg_print_int(buffer, name, kmp_diag);
1665} // __kmp_stg_print_diag
1666
1667#endif // KMP_DEBUG
1668
1669// -----------------------------------------------------------------------------
1670// KMP_ALIGN_ALLOC
1671
1672static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
1673 void *data) {
1674 __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
1675 &__kmp_align_alloc, 1);
1676} // __kmp_stg_parse_align_alloc
1677
1678static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
1679 void *data) {
1680 __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
1681} // __kmp_stg_print_align_alloc
1682
1683// -----------------------------------------------------------------------------
1684// KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
1685
1686// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
1687// parse and print functions, pass required info through data argument.
1688
1689static void __kmp_stg_parse_barrier_branch_bit(char const *name,
1690 char const *value, void *data) {
1691 const char *var;
1692
1693 /* ---------- Barrier branch bit control ------------ */
1694 for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
1695 var = __kmp_barrier_branch_bit_env_name[i];
1696 if ((strcmp(var, name) == 0) && (value != 0)) {
1697 char *comma;
1698
1699 comma = CCAST(char *, strchr(value, ','));
1700 __kmp_barrier_gather_branch_bits[i] =
1701 (kmp_uint32)__kmp_str_to_int(value, ',');
1702 /* is there a specified release parameter? */
1703 if (comma == NULL) {
1704 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1705 } else {
1706 __kmp_barrier_release_branch_bits[i] =
1707 (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
1708
1709 if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
1710 __kmp_msg(kmp_ms_warning,
1711 KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
1712 __kmp_msg_null);
1713 __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
1714 }
1715 }
1716 if (__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_allocate((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_allocate((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", name, ct_name);
3267 } else if (eff >= 0 && eff < KMP_HW_MAX_NUM_CORE_EFFS) {
3268 __kmp_str_buf_print(buffer, ":eff%d", name, 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_USE_HWLOC
3290 else if (__kmp_str_match("hwloc", 1, value)) {
3291 __kmp_affinity_top_method = affinity_top_method_hwloc;
3292 }
3293#endif
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_USE_HWLOC
3398 case affinity_top_method_hwloc:
3399 value = "hwloc";
3400 break;
3401#endif
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 int num;
3485 SKIP_WS(buf);
3486 if ((*buf >= '0') && (*buf <= '9')) {
3487 next = buf;
3488 SKIP_DIGITS(next);
3489 num = __kmp_str_to_int(buf, *next);
3490 KMP_ASSERT(num >= 0);
3491 buf = next;
3492 SKIP_WS(buf);
3493 } else {
3494 num = -1;
3495 }
3496
3497 next = buf;
3498 if (__kmp_match_str("disabled", buf, &next)) {
3499 buf = next;
3500 SKIP_WS(buf);
3501#if KMP_AFFINITY_SUPPORTED
3502 __kmp_affinity.type = affinity_disabled;
3503#endif /* KMP_AFFINITY_SUPPORTED */
3504 __kmp_nested_proc_bind.used = 1;
3505 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3506 } else if ((num == (int)proc_bind_false) ||
3507 __kmp_match_str("false", buf, &next)) {
3508 buf = next;
3509 SKIP_WS(buf);
3510#if KMP_AFFINITY_SUPPORTED
3511 __kmp_affinity.type = affinity_none;
3512#endif /* KMP_AFFINITY_SUPPORTED */
3513 __kmp_nested_proc_bind.used = 1;
3514 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3515 } else if ((num == (int)proc_bind_true) ||
3516 __kmp_match_str("true", buf, &next)) {
3517 buf = next;
3518 SKIP_WS(buf);
3519 __kmp_nested_proc_bind.used = 1;
3520 __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
3521 } else {
3522 // Count the number of values in the env var string
3523 const char *scan;
3524 int nelem = 1;
3525 for (scan = buf; *scan != '\0'; scan++) {
3526 if (*scan == ',') {
3527 nelem++;
3528 }
3529 }
3530
3531 // Create / expand the nested proc_bind array as needed
3532 if (__kmp_nested_proc_bind.size < nelem) {
3533 __kmp_nested_proc_bind.bind_types =
3534 (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
3535 __kmp_nested_proc_bind.bind_types,
3536 sizeof(kmp_proc_bind_t) * nelem);
3537 if (__kmp_nested_proc_bind.bind_types == NULL) {
3538 KMP_FATAL(MemoryAllocFailed);
3539 }
3540 __kmp_nested_proc_bind.size = nelem;
3541 }
3542 __kmp_nested_proc_bind.used = nelem;
3543
3544 if (nelem > 1 && !__kmp_dflt_max_active_levels_set)
3545 __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
3546
3547 // Save values in the nested proc_bind array
3548 int i = 0;
3549 for (;;) {
3550 enum kmp_proc_bind_t bind;
3551
3552 if ((num == (int)proc_bind_primary) ||
3553 __kmp_match_str("master", buf, &next) ||
3554 __kmp_match_str("primary", buf, &next)) {
3555 buf = next;
3556 SKIP_WS(buf);
3557 bind = proc_bind_primary;
3558 } else if ((num == (int)proc_bind_close) ||
3559 __kmp_match_str("close", buf, &next)) {
3560 buf = next;
3561 SKIP_WS(buf);
3562 bind = proc_bind_close;
3563 } else if ((num == (int)proc_bind_spread) ||
3564 __kmp_match_str("spread", buf, &next)) {
3565 buf = next;
3566 SKIP_WS(buf);
3567 bind = proc_bind_spread;
3568 } else {
3569 KMP_WARNING(StgInvalidValue, name, value);
3570 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
3571 __kmp_nested_proc_bind.used = 1;
3572 return;
3573 }
3574
3575 __kmp_nested_proc_bind.bind_types[i++] = bind;
3576 if (i >= nelem) {
3577 break;
3578 }
3579 KMP_DEBUG_ASSERT(*buf == ',');
3580 buf++;
3581 SKIP_WS(buf);
3582
3583 // Read next value if it was specified as an integer
3584 if ((*buf >= '0') && (*buf <= '9')) {
3585 next = buf;
3586 SKIP_DIGITS(next);
3587 num = __kmp_str_to_int(buf, *next);
3588 KMP_ASSERT(num >= 0);
3589 buf = next;
3590 SKIP_WS(buf);
3591 } else {
3592 num = -1;
3593 }
3594 }
3595 SKIP_WS(buf);
3596 }
3597 if (*buf != '\0') {
3598 KMP_WARNING(ParseExtraCharsWarn, name, buf);
3599 }
3600}
3601
3602static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
3603 void *data) {
3604 int nelem = __kmp_nested_proc_bind.used;
3605 if (__kmp_env_format) {
3606 KMP_STR_BUF_PRINT_NAME;
3607 } else {
3608 __kmp_str_buf_print(buffer, " %s", name);
3609 }
3610 if (nelem == 0) {
3611 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
3612 } else {
3613 int i;
3614 __kmp_str_buf_print(buffer, "='", name);
3615 for (i = 0; i < nelem; i++) {
3616 switch (__kmp_nested_proc_bind.bind_types[i]) {
3617 case proc_bind_false:
3618 __kmp_str_buf_print(buffer, "false");
3619 break;
3620
3621 case proc_bind_true:
3622 __kmp_str_buf_print(buffer, "true");
3623 break;
3624
3625 case proc_bind_primary:
3626 __kmp_str_buf_print(buffer, "primary");
3627 break;
3628
3629 case proc_bind_close:
3630 __kmp_str_buf_print(buffer, "close");
3631 break;
3632
3633 case proc_bind_spread:
3634 __kmp_str_buf_print(buffer, "spread");
3635 break;
3636
3637 case proc_bind_intel:
3638 __kmp_str_buf_print(buffer, "intel");
3639 break;
3640
3641 case proc_bind_default:
3642 __kmp_str_buf_print(buffer, "default");
3643 break;
3644 }
3645 if (i < nelem - 1) {
3646 __kmp_str_buf_print(buffer, ",");
3647 }
3648 }
3649 __kmp_str_buf_print(buffer, "'\n");
3650 }
3651}
3652
3653static void __kmp_stg_parse_display_affinity(char const *name,
3654 char const *value, void *data) {
3655 __kmp_stg_parse_bool(name, value, &__kmp_display_affinity);
3656}
3657static void __kmp_stg_print_display_affinity(kmp_str_buf_t *buffer,
3658 char const *name, void *data) {
3659 __kmp_stg_print_bool(buffer, name, __kmp_display_affinity);
3660}
3661static void __kmp_stg_parse_affinity_format(char const *name, char const *value,
3662 void *data) {
3663 size_t length = KMP_STRLEN(value);
3664 __kmp_strncpy_truncate(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, value,
3665 length);
3666}
3667static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer,
3668 char const *name, void *data) {
3669 if (__kmp_env_format) {
3670 KMP_STR_BUF_PRINT_NAME_EX(name);
3671 } else {
3672 __kmp_str_buf_print(buffer, " %s='", name);
3673 }
3674 __kmp_str_buf_print(buffer, "%s'\n", __kmp_affinity_format);
3675}
3676
3677/*-----------------------------------------------------------------------------
3678OMP_ALLOCATOR sets default allocator. Here is the grammar:
3679
3680<allocator> |= <predef-allocator> | <predef-mem-space> |
3681 <predef-mem-space>:<traits>
3682<traits> |= <trait>=<value> | <trait>=<value>,<traits>
3683<predef-allocator> |= omp_default_mem_alloc | omp_large_cap_mem_alloc |
3684 omp_const_mem_alloc | omp_high_bw_mem_alloc |
3685 omp_low_lat_mem_alloc | omp_cgroup_mem_alloc |
3686 omp_pteam_mem_alloc | omp_thread_mem_alloc
3687<predef-mem-space> |= omp_default_mem_space | omp_large_cap_mem_space |
3688 omp_const_mem_space | omp_high_bw_mem_space |
3689 omp_low_lat_mem_space
3690<trait> |= sync_hint | alignment | access | pool_size | fallback |
3691 fb_data | pinned | partition
3692<value> |= one of the allowed values of trait |
3693 non-negative integer | <predef-allocator>
3694-----------------------------------------------------------------------------*/
3695
3696static void __kmp_stg_parse_allocator(char const *name, char const *value,
3697 void *data) {
3698 const char *buf = value;
3699 const char *next, *scan, *start;
3700 char *key;
3701 omp_allocator_handle_t al;
3702 omp_memspace_handle_t ms = omp_default_mem_space;
3703 bool is_memspace = false;
3704 int ntraits = 0, count = 0;
3705
3706 SKIP_WS(buf);
3707 next = buf;
3708 const char *delim = strchr(buf, ':');
3709 const char *predef_mem_space = strstr(buf, "mem_space");
3710
3711 bool is_memalloc = (!predef_mem_space && !delim) ? true : false;
3712
3713 // Count the number of traits in the env var string
3714 if (delim) {
3715 ntraits = 1;
3716 for (scan = buf; *scan != '\0'; scan++) {
3717 if (*scan == ',')
3718 ntraits++;
3719 }
3720 }
3721 omp_alloctrait_t *traits =
3722 (omp_alloctrait_t *)KMP_ALLOCA(ntraits * sizeof(omp_alloctrait_t));
3723
3724// Helper macros
3725#define IS_POWER_OF_TWO(n) (((n) & ((n)-1)) == 0)
3726
3727#define GET_NEXT(sentinel) \
3728 { \
3729 SKIP_WS(next); \
3730 if (*next == sentinel) \
3731 next++; \
3732 SKIP_WS(next); \
3733 scan = next; \
3734 }
3735
3736#define SKIP_PAIR(key) \
3737 { \
3738 char const str_delimiter[] = {',', 0}; \
3739 char *value = __kmp_str_token(CCAST(char *, scan), str_delimiter, \
3740 CCAST(char **, &next)); \
3741 KMP_WARNING(StgInvalidValue, key, value); \
3742 ntraits--; \
3743 SKIP_WS(next); \
3744 scan = next; \
3745 }
3746
3747#define SET_KEY() \
3748 { \
3749 char const str_delimiter[] = {'=', 0}; \
3750 key = __kmp_str_token(CCAST(char *, start), str_delimiter, \
3751 CCAST(char **, &next)); \
3752 scan = next; \
3753 }
3754
3755 scan = next;
3756 while (*next != '\0') {
3757 if (is_memalloc ||
3758 __kmp_match_str("fb_data", scan, &next)) { // allocator check
3759 start = scan;
3760 GET_NEXT('=');
3761 // check HBW and LCAP first as the only non-default supported
3762 if (__kmp_match_str("omp_high_bw_mem_alloc", scan, &next)) {
3763 SKIP_WS(next);
3764 if (is_memalloc) {
3765 if (__kmp_memkind_available) {
3766 __kmp_def_allocator = omp_high_bw_mem_alloc;
3767 return;
3768 } else {
3769 KMP_WARNING(OmpNoAllocator, "omp_high_bw_mem_alloc");
3770 }
3771 } else {
3772 traits[count].key = omp_atk_fb_data;
3773 traits[count].value = RCAST(omp_uintptr_t, omp_high_bw_mem_alloc);
3774 }
3775 } else if (__kmp_match_str("omp_large_cap_mem_alloc", scan, &next)) {
3776 SKIP_WS(next);
3777 if (is_memalloc) {
3778 if (__kmp_memkind_available) {
3779 __kmp_def_allocator = omp_large_cap_mem_alloc;
3780 return;
3781 } else {
3782 KMP_WARNING(OmpNoAllocator, "omp_large_cap_mem_alloc");
3783 }
3784 } else {
3785 traits[count].key = omp_atk_fb_data;
3786 traits[count].value = RCAST(omp_uintptr_t, omp_large_cap_mem_alloc);
3787 }
3788 } else if (__kmp_match_str("omp_default_mem_alloc", scan, &next)) {
3789 // default requested
3790 SKIP_WS(next);
3791 if (!is_memalloc) {
3792 traits[count].key = omp_atk_fb_data;
3793 traits[count].value = RCAST(omp_uintptr_t, omp_default_mem_alloc);
3794 }
3795 } else if (__kmp_match_str("omp_const_mem_alloc", scan, &next)) {
3796 SKIP_WS(next);
3797 if (is_memalloc) {
3798 KMP_WARNING(OmpNoAllocator, "omp_const_mem_alloc");
3799 } else {
3800 traits[count].key = omp_atk_fb_data;
3801 traits[count].value = RCAST(omp_uintptr_t, omp_const_mem_alloc);
3802 }
3803 } else if (__kmp_match_str("omp_low_lat_mem_alloc", scan, &next)) {
3804 SKIP_WS(next);
3805 if (is_memalloc) {
3806 KMP_WARNING(OmpNoAllocator, "omp_low_lat_mem_alloc");
3807 } else {
3808 traits[count].key = omp_atk_fb_data;
3809 traits[count].value = RCAST(omp_uintptr_t, omp_low_lat_mem_alloc);
3810 }
3811 } else if (__kmp_match_str("omp_cgroup_mem_alloc", scan, &next)) {
3812 SKIP_WS(next);
3813 if (is_memalloc) {
3814 KMP_WARNING(OmpNoAllocator, "omp_cgroup_mem_alloc");
3815 } else {
3816 traits[count].key = omp_atk_fb_data;
3817 traits[count].value = RCAST(omp_uintptr_t, omp_cgroup_mem_alloc);
3818 }
3819 } else if (__kmp_match_str("omp_pteam_mem_alloc", scan, &next)) {
3820 SKIP_WS(next);
3821 if (is_memalloc) {
3822 KMP_WARNING(OmpNoAllocator, "omp_pteam_mem_alloc");
3823 } else {
3824 traits[count].key = omp_atk_fb_data;
3825 traits[count].value = RCAST(omp_uintptr_t, omp_pteam_mem_alloc);
3826 }
3827 } else if (__kmp_match_str("omp_thread_mem_alloc", scan, &next)) {
3828 SKIP_WS(next);
3829 if (is_memalloc) {
3830 KMP_WARNING(OmpNoAllocator, "omp_thread_mem_alloc");
3831 } else {
3832 traits[count].key = omp_atk_fb_data;
3833 traits[count].value = RCAST(omp_uintptr_t, omp_thread_mem_alloc);
3834 }
3835 } else {
3836 if (!is_memalloc) {
3837 SET_KEY();
3838 SKIP_PAIR(key);
3839 continue;
3840 }
3841 }
3842 if (is_memalloc) {
3843 __kmp_def_allocator = omp_default_mem_alloc;
3844 if (next == buf || *next != '\0') {
3845 // either no match or extra symbols present after the matched token
3846 KMP_WARNING(StgInvalidValue, name, value);
3847 }
3848 return;
3849 } else {
3850 ++count;
3851 if (count == ntraits)
3852 break;
3853 GET_NEXT(',');
3854 }
3855 } else { // memspace
3856 if (!is_memspace) {
3857 if (__kmp_match_str("omp_default_mem_space", scan, &next)) {
3858 SKIP_WS(next);
3859 ms = omp_default_mem_space;
3860 } else if (__kmp_match_str("omp_large_cap_mem_space", scan, &next)) {
3861 SKIP_WS(next);
3862 ms = omp_large_cap_mem_space;
3863 } else if (__kmp_match_str("omp_const_mem_space", scan, &next)) {
3864 SKIP_WS(next);
3865 ms = omp_const_mem_space;
3866 } else if (__kmp_match_str("omp_high_bw_mem_space", scan, &next)) {
3867 SKIP_WS(next);
3868 ms = omp_high_bw_mem_space;
3869 } else if (__kmp_match_str("omp_low_lat_mem_space", scan, &next)) {
3870 SKIP_WS(next);
3871 ms = omp_low_lat_mem_space;
3872 } else {
3873 __kmp_def_allocator = omp_default_mem_alloc;
3874 if (next == buf || *next != '\0') {
3875 // either no match or extra symbols present after the matched token
3876 KMP_WARNING(StgInvalidValue, name, value);
3877 }
3878 return;
3879 }
3880 is_memspace = true;
3881 }
3882 if (delim) { // traits
3883 GET_NEXT(':');
3884 start = scan;
3885 if (__kmp_match_str("sync_hint", scan, &next)) {
3886 GET_NEXT('=');
3887 traits[count].key = omp_atk_sync_hint;
3888 if (__kmp_match_str("contended", scan, &next)) {
3889 traits[count].value = omp_atv_contended;
3890 } else if (__kmp_match_str("uncontended", scan, &next)) {
3891 traits[count].value = omp_atv_uncontended;
3892 } else if (__kmp_match_str("serialized", scan, &next)) {
3893 traits[count].value = omp_atv_serialized;
3894 } else if (__kmp_match_str("private", scan, &next)) {
3895 traits[count].value = omp_atv_private;
3896 } else {
3897 SET_KEY();
3898 SKIP_PAIR(key);
3899 continue;
3900 }
3901 } else if (__kmp_match_str("alignment", scan, &next)) {
3902 GET_NEXT('=');
3903 if (!isdigit(*next)) {
3904 SET_KEY();
3905 SKIP_PAIR(key);
3906 continue;
3907 }
3908 SKIP_DIGITS(next);
3909 int n = __kmp_str_to_int(scan, ',');
3910 if (n < 0 || !IS_POWER_OF_TWO(n)) {
3911 SET_KEY();
3912 SKIP_PAIR(key);
3913 continue;
3914 }
3915 traits[count].key = omp_atk_alignment;
3916 traits[count].value = n;
3917 } else if (__kmp_match_str("access", scan, &next)) {
3918 GET_NEXT('=');
3919 traits[count].key = omp_atk_access;
3920 if (__kmp_match_str("all", scan, &next)) {
3921 traits[count].value = omp_atv_all;
3922 } else if (__kmp_match_str("cgroup", scan, &next)) {
3923 traits[count].value = omp_atv_cgroup;
3924 } else if (__kmp_match_str("pteam", scan, &next)) {
3925 traits[count].value = omp_atv_pteam;
3926 } else if (__kmp_match_str("thread", scan, &next)) {
3927 traits[count].value = omp_atv_thread;
3928 } else {
3929 SET_KEY();
3930 SKIP_PAIR(key);
3931 continue;
3932 }
3933 } else if (__kmp_match_str("pool_size", scan, &next)) {
3934 GET_NEXT('=');
3935 if (!isdigit(*next)) {
3936 SET_KEY();
3937 SKIP_PAIR(key);
3938 continue;
3939 }
3940 SKIP_DIGITS(next);
3941 int n = __kmp_str_to_int(scan, ',');
3942 if (n < 0) {
3943 SET_KEY();
3944 SKIP_PAIR(key);
3945 continue;
3946 }
3947 traits[count].key = omp_atk_pool_size;
3948 traits[count].value = n;
3949 } else if (__kmp_match_str("fallback", scan, &next)) {
3950 GET_NEXT('=');
3951 traits[count].key = omp_atk_fallback;
3952 if (__kmp_match_str("default_mem_fb", scan, &next)) {
3953 traits[count].value = omp_atv_default_mem_fb;
3954 } else if (__kmp_match_str("null_fb", scan, &next)) {
3955 traits[count].value = omp_atv_null_fb;
3956 } else if (__kmp_match_str("abort_fb", scan, &next)) {
3957 traits[count].value = omp_atv_abort_fb;
3958 } else if (__kmp_match_str("allocator_fb", scan, &next)) {
3959 traits[count].value = omp_atv_allocator_fb;
3960 } else {
3961 SET_KEY();
3962 SKIP_PAIR(key);
3963 continue;
3964 }
3965 } else if (__kmp_match_str("pinned", scan, &next)) {
3966 GET_NEXT('=');
3967 traits[count].key = omp_atk_pinned;
3968 if (__kmp_str_match_true(next)) {
3969 traits[count].value = omp_atv_true;
3970 } else if (__kmp_str_match_false(next)) {
3971 traits[count].value = omp_atv_false;
3972 } else {
3973 SET_KEY();
3974 SKIP_PAIR(key);
3975 continue;
3976 }
3977 } else if (__kmp_match_str("partition", scan, &next)) {
3978 GET_NEXT('=');
3979 traits[count].key = omp_atk_partition;
3980 if (__kmp_match_str("environment", scan, &next)) {
3981 traits[count].value = omp_atv_environment;
3982 } else if (__kmp_match_str("nearest", scan, &next)) {
3983 traits[count].value = omp_atv_nearest;
3984 } else if (__kmp_match_str("blocked", scan, &next)) {
3985 traits[count].value = omp_atv_blocked;
3986 } else if (__kmp_match_str("interleaved", scan, &next)) {
3987 traits[count].value = omp_atv_interleaved;
3988 } else {
3989 SET_KEY();
3990 SKIP_PAIR(key);
3991 continue;
3992 }
3993 } else {
3994 SET_KEY();
3995 SKIP_PAIR(key);
3996 continue;
3997 }
3998 SKIP_WS(next);
3999 ++count;
4000 if (count == ntraits)
4001 break;
4002 GET_NEXT(',');
4003 } // traits
4004 } // memspace
4005 } // while
4006 al = __kmpc_init_allocator(__kmp_get_gtid(), ms, ntraits, traits);
4007 __kmp_def_allocator = (al == omp_null_allocator) ? omp_default_mem_alloc : al;
4008}
4009
4010static void __kmp_stg_print_allocator(kmp_str_buf_t *buffer, char const *name,
4011 void *data) {
4012 if (__kmp_def_allocator == omp_default_mem_alloc) {
4013 __kmp_stg_print_str(buffer, name, "omp_default_mem_alloc");
4014 } else if (__kmp_def_allocator == omp_high_bw_mem_alloc) {
4015 __kmp_stg_print_str(buffer, name, "omp_high_bw_mem_alloc");
4016 } else if (__kmp_def_allocator == omp_large_cap_mem_alloc) {
4017 __kmp_stg_print_str(buffer, name, "omp_large_cap_mem_alloc");
4018 } else if (__kmp_def_allocator == omp_const_mem_alloc) {
4019 __kmp_stg_print_str(buffer, name, "omp_const_mem_alloc");
4020 } else if (__kmp_def_allocator == omp_low_lat_mem_alloc) {
4021 __kmp_stg_print_str(buffer, name, "omp_low_lat_mem_alloc");
4022 } else if (__kmp_def_allocator == omp_cgroup_mem_alloc) {
4023 __kmp_stg_print_str(buffer, name, "omp_cgroup_mem_alloc");
4024 } else if (__kmp_def_allocator == omp_pteam_mem_alloc) {
4025 __kmp_stg_print_str(buffer, name, "omp_pteam_mem_alloc");
4026 } else if (__kmp_def_allocator == omp_thread_mem_alloc) {
4027 __kmp_stg_print_str(buffer, name, "omp_thread_mem_alloc");
4028 }
4029}
4030
4031// -----------------------------------------------------------------------------
4032// OMP_DYNAMIC
4033
4034static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
4035 void *data) {
4036 __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
4037} // __kmp_stg_parse_omp_dynamic
4038
4039static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
4040 void *data) {
4041 __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
4042} // __kmp_stg_print_omp_dynamic
4043
4044static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
4045 char const *value, void *data) {
4046 if (TCR_4(__kmp_init_parallel)) {
4047 KMP_WARNING(EnvParallelWarn, name);
4048 __kmp_env_toPrint(name, 0);
4049 return;
4050 }
4051#ifdef USE_LOAD_BALANCE
4052 else if (__kmp_str_match("load balance", 2, value) ||
4053 __kmp_str_match("load_balance", 2, value) ||
4054 __kmp_str_match("load-balance", 2, value) ||
4055 __kmp_str_match("loadbalance", 2, value) ||
4056 __kmp_str_match("balance", 1, value)) {
4057 __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
4058 }
4059#endif /* USE_LOAD_BALANCE */
4060 else if (__kmp_str_match("thread limit", 1, value) ||
4061 __kmp_str_match("thread_limit", 1, value) ||
4062 __kmp_str_match("thread-limit", 1, value) ||
4063 __kmp_str_match("threadlimit", 1, value) ||
4064 __kmp_str_match("limit", 2, value)) {
4065 __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
4066 } else if (__kmp_str_match("random", 1, value)) {
4067 __kmp_global.g.g_dynamic_mode = dynamic_random;
4068 } else {
4069 KMP_WARNING(StgInvalidValue, name, value);
4070 }
4071} //__kmp_stg_parse_kmp_dynamic_mode
4072
4073static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
4074 char const *name, void *data) {
4075#if KMP_DEBUG
4076 if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
4077 __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
4078 }
4079#ifdef USE_LOAD_BALANCE
4080 else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
4081 __kmp_stg_print_str(buffer, name, "load balance");
4082 }
4083#endif /* USE_LOAD_BALANCE */
4084 else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
4085 __kmp_stg_print_str(buffer, name, "thread limit");
4086 } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
4087 __kmp_stg_print_str(buffer, name, "random");
4088 } else {
4089 KMP_ASSERT(0);
4090 }
4091#endif /* KMP_DEBUG */
4092} // __kmp_stg_print_kmp_dynamic_mode
4093
4094#ifdef USE_LOAD_BALANCE
4095
4096// -----------------------------------------------------------------------------
4097// KMP_LOAD_BALANCE_INTERVAL
4098
4099static void __kmp_stg_parse_ld_balance_interval(char const *name,
4100 char const *value, void *data) {
4101 double interval = __kmp_convert_to_double(value);
4102 if (interval >= 0) {
4103 __kmp_load_balance_interval = interval;
4104 } else {
4105 KMP_WARNING(StgInvalidValue, name, value);
4106 }
4107} // __kmp_stg_parse_load_balance_interval
4108
4109static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
4110 char const *name, void *data) {
4111#if KMP_DEBUG
4112 __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
4113 __kmp_load_balance_interval);
4114#endif /* KMP_DEBUG */
4115} // __kmp_stg_print_load_balance_interval
4116
4117#endif /* USE_LOAD_BALANCE */
4118
4119// -----------------------------------------------------------------------------
4120// KMP_INIT_AT_FORK
4121
4122static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
4123 void *data) {
4124 __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
4125 if (__kmp_need_register_atfork) {
4126 __kmp_need_register_atfork_specified = TRUE;
4127 }
4128} // __kmp_stg_parse_init_at_fork
4129
4130static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
4131 char const *name, void *data) {
4132 __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
4133} // __kmp_stg_print_init_at_fork
4134
4135// -----------------------------------------------------------------------------
4136// KMP_SCHEDULE
4137
4138static void __kmp_stg_parse_schedule(char const *name, char const *value,
4139 void *data) {
4140
4141 if (value != NULL) {
4142 size_t length = KMP_STRLEN(value);
4143 if (length > INT_MAX) {
4144 KMP_WARNING(LongValue, name);
4145 } else {
4146 const char *semicolon;
4147 if (value[length - 1] == '"' || value[length - 1] == '\'')
4148 KMP_WARNING(UnbalancedQuotes, name);
4149 do {
4150 char sentinel;
4151
4152 semicolon = strchr(value, ';');
4153 if (*value && semicolon != value) {
4154 const char *comma = strchr(value, ',');
4155
4156 if (comma) {
4157 ++comma;
4158 sentinel = ',';
4159 } else
4160 sentinel = ';';
4161 if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
4162 if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
4163 __kmp_static = kmp_sch_static_greedy;
4164 continue;
4165 } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
4166 ';')) {
4167 __kmp_static = kmp_sch_static_balanced;
4168 continue;
4169 }
4170 } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
4171 sentinel)) {
4172 if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
4173 __kmp_guided = kmp_sch_guided_iterative_chunked;
4174 continue;
4175 } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
4176 ';')) {
4177 /* analytical not allowed for too many threads */
4178 __kmp_guided = kmp_sch_guided_analytical_chunked;
4179 continue;
4180 }
4181 }
4182 KMP_WARNING(InvalidClause, name, value);
4183 } else
4184 KMP_WARNING(EmptyClause, name);
4185 } while ((value = semicolon ? semicolon + 1 : NULL));
4186 }
4187 }
4188
4189} // __kmp_stg_parse__schedule
4190
4191static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
4192 void *data) {
4193 if (__kmp_env_format) {
4194 KMP_STR_BUF_PRINT_NAME_EX(name);
4195 } else {
4196 __kmp_str_buf_print(buffer, " %s='", name);
4197 }
4198 if (__kmp_static == kmp_sch_static_greedy) {
4199 __kmp_str_buf_print(buffer, "%s", "static,greedy");
4200 } else if (__kmp_static == kmp_sch_static_balanced) {
4201 __kmp_str_buf_print(buffer, "%s", "static,balanced");
4202 }
4203 if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
4204 __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
4205 } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
4206 __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
4207 }
4208} // __kmp_stg_print_schedule
4209
4210// -----------------------------------------------------------------------------
4211// OMP_SCHEDULE
4212
4213static inline void __kmp_omp_schedule_restore() {
4214#if KMP_USE_HIER_SCHED
4215 __kmp_hier_scheds.deallocate();
4216#endif
4217 __kmp_chunk = 0;
4218 __kmp_sched = kmp_sch_default;
4219}
4220
4221// if parse_hier = true:
4222// Parse [HW,][modifier:]kind[,chunk]
4223// else:
4224// Parse [modifier:]kind[,chunk]
4225static const char *__kmp_parse_single_omp_schedule(const char *name,
4226 const char *value,
4227 bool parse_hier = false) {
4228 /* get the specified scheduling style */
4229 const char *ptr = value;
4230 const char *delim;
4231 int chunk = 0;
4232 enum sched_type sched = kmp_sch_default;
4233 if (*ptr == '\0')
4234 return NULL;
4235 delim = ptr;
4236 while (*delim != ',' && *delim != ':' && *delim != '\0')
4237 delim++;
4238#if KMP_USE_HIER_SCHED
4239 kmp_hier_layer_e layer = kmp_hier_layer_e::LAYER_THREAD;
4240 if (parse_hier) {
4241 if (*delim == ',') {
4242 if (!__kmp_strcasecmp_with_sentinel("L1", ptr, ',')) {
4243 layer = kmp_hier_layer_e::LAYER_L1;
4244 } else if (!__kmp_strcasecmp_with_sentinel("L2", ptr, ',')) {
4245 layer = kmp_hier_layer_e::LAYER_L2;
4246 } else if (!__kmp_strcasecmp_with_sentinel("L3", ptr, ',')) {
4247 layer = kmp_hier_layer_e::LAYER_L3;
4248 } else if (!__kmp_strcasecmp_with_sentinel("NUMA", ptr, ',')) {
4249 layer = kmp_hier_layer_e::LAYER_NUMA;
4250 }
4251 }
4252 if (layer != kmp_hier_layer_e::LAYER_THREAD && *delim != ',') {
4253 // If there is no comma after the layer, then this schedule is invalid
4254 KMP_WARNING(StgInvalidValue, name, value);
4255 __kmp_omp_schedule_restore();
4256 return NULL;
4257 } else if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4258 ptr = ++delim;
4259 while (*delim != ',' && *delim != ':' && *delim != '\0')
4260 delim++;
4261 }
4262 }
4263#endif // KMP_USE_HIER_SCHED
4264 // Read in schedule modifier if specified
4265 enum sched_type sched_modifier = (enum sched_type)0;
4266 if (*delim == ':') {
4267 if (!__kmp_strcasecmp_with_sentinel("monotonic", ptr, *delim)) {
4269 ptr = ++delim;
4270 while (*delim != ',' && *delim != ':' && *delim != '\0')
4271 delim++;
4272 } else if (!__kmp_strcasecmp_with_sentinel("nonmonotonic", ptr, *delim)) {
4274 ptr = ++delim;
4275 while (*delim != ',' && *delim != ':' && *delim != '\0')
4276 delim++;
4277 } else if (!parse_hier) {
4278 // If there is no proper schedule modifier, then this schedule is invalid
4279 KMP_WARNING(StgInvalidValue, name, value);
4280 __kmp_omp_schedule_restore();
4281 return NULL;
4282 }
4283 }
4284 // Read in schedule kind (required)
4285 if (!__kmp_strcasecmp_with_sentinel("dynamic", ptr, *delim))
4286 sched = kmp_sch_dynamic_chunked;
4287 else if (!__kmp_strcasecmp_with_sentinel("guided", ptr, *delim))
4288 sched = kmp_sch_guided_chunked;
4289 // AC: TODO: probably remove TRAPEZOIDAL (OMP 3.0 does not allow it)
4290 else if (!__kmp_strcasecmp_with_sentinel("auto", ptr, *delim))
4291 sched = kmp_sch_auto;
4292 else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", ptr, *delim))
4293 sched = kmp_sch_trapezoidal;
4294 else if (!__kmp_strcasecmp_with_sentinel("static", ptr, *delim))
4295 sched = kmp_sch_static;
4296#if KMP_STATIC_STEAL_ENABLED
4297 else if (!__kmp_strcasecmp_with_sentinel("static_steal", ptr, *delim)) {
4298 // replace static_steal with dynamic to better cope with ordered loops
4299 sched = kmp_sch_dynamic_chunked;
4301 }
4302#endif
4303 else {
4304 // If there is no proper schedule kind, then this schedule is invalid
4305 KMP_WARNING(StgInvalidValue, name, value);
4306 __kmp_omp_schedule_restore();
4307 return NULL;
4308 }
4309
4310 // Read in schedule chunk size if specified
4311 if (*delim == ',') {
4312 ptr = delim + 1;
4313 SKIP_WS(ptr);
4314 if (!isdigit(*ptr)) {
4315 // If there is no chunk after comma, then this schedule is invalid
4316 KMP_WARNING(StgInvalidValue, name, value);
4317 __kmp_omp_schedule_restore();
4318 return NULL;
4319 }
4320 SKIP_DIGITS(ptr);
4321 // auto schedule should not specify chunk size
4322 if (sched == kmp_sch_auto) {
4323 __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, delim),
4324 __kmp_msg_null);
4325 } else {
4326 if (sched == kmp_sch_static)
4327 sched = kmp_sch_static_chunked;
4328 chunk = __kmp_str_to_int(delim + 1, *ptr);
4329 if (chunk < 1) {
4330 chunk = KMP_DEFAULT_CHUNK;
4331 __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, delim),
4332 __kmp_msg_null);
4333 KMP_INFORM(Using_int_Value, name, __kmp_chunk);
4334 // AC: next block commented out until KMP_DEFAULT_CHUNK != KMP_MIN_CHUNK
4335 // (to improve code coverage :)
4336 // The default chunk size is 1 according to standard, thus making
4337 // KMP_MIN_CHUNK not 1 we would introduce mess:
4338 // wrong chunk becomes 1, but it will be impossible to explicitly set
4339 // to 1 because it becomes KMP_MIN_CHUNK...
4340 // } else if ( chunk < KMP_MIN_CHUNK ) {
4341 // chunk = KMP_MIN_CHUNK;
4342 } else if (chunk > KMP_MAX_CHUNK) {
4343 chunk = KMP_MAX_CHUNK;
4344 __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, delim),
4345 __kmp_msg_null);
4346 KMP_INFORM(Using_int_Value, name, chunk);
4347 }
4348 }
4349 } else {
4350 ptr = delim;
4351 }
4352
4353 SCHEDULE_SET_MODIFIERS(sched, sched_modifier);
4354
4355#if KMP_USE_HIER_SCHED
4356 if (layer != kmp_hier_layer_e::LAYER_THREAD) {
4357 __kmp_hier_scheds.append(sched, chunk, layer);
4358 } else
4359#endif
4360 {
4361 __kmp_chunk = chunk;
4362 __kmp_sched = sched;
4363 }
4364 return ptr;
4365}
4366
4367static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
4368 void *data) {
4369 size_t length;
4370 const char *ptr = value;
4371 SKIP_WS(ptr);
4372 if (value) {
4373 length = KMP_STRLEN(value);
4374 if (length) {
4375 if (value[length - 1] == '"' || value[length - 1] == '\'')
4376 KMP_WARNING(UnbalancedQuotes, name);
4377/* get the specified scheduling style */
4378#if KMP_USE_HIER_SCHED
4379 if (!__kmp_strcasecmp_with_sentinel("EXPERIMENTAL", ptr, ' ')) {
4380 SKIP_TOKEN(ptr);
4381 SKIP_WS(ptr);
4382 while ((ptr = __kmp_parse_single_omp_schedule(name, ptr, true))) {
4383 while (*ptr == ' ' || *ptr == '\t' || *ptr == ':')
4384 ptr++;
4385 if (*ptr == '\0')
4386 break;
4387 }
4388 } else
4389#endif
4390 __kmp_parse_single_omp_schedule(name, ptr);
4391 } else
4392 KMP_WARNING(EmptyString, name);
4393 }
4394#if KMP_USE_HIER_SCHED
4395 __kmp_hier_scheds.sort();
4396#endif
4397 K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
4398 K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
4399 K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
4400 K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
4401} // __kmp_stg_parse_omp_schedule
4402
4403static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
4404 char const *name, void *data) {
4405 if (__kmp_env_format) {
4406 KMP_STR_BUF_PRINT_NAME_EX(name);
4407 } else {
4408 __kmp_str_buf_print(buffer, " %s='", name);
4409 }
4410 enum sched_type sched = SCHEDULE_WITHOUT_MODIFIERS(__kmp_sched);
4411 if (SCHEDULE_HAS_MONOTONIC(__kmp_sched)) {
4412 __kmp_str_buf_print(buffer, "monotonic:");
4413 } else if (SCHEDULE_HAS_NONMONOTONIC(__kmp_sched)) {
4414 __kmp_str_buf_print(buffer, "nonmonotonic:");
4415 }
4416 if (__kmp_chunk) {
4417 switch (sched) {
4418 case kmp_sch_dynamic_chunked:
4419 __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
4420 break;
4421 case kmp_sch_guided_iterative_chunked:
4422 case kmp_sch_guided_analytical_chunked:
4423 __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
4424 break;
4425 case kmp_sch_trapezoidal:
4426 __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
4427 break;
4428 case kmp_sch_static:
4429 case kmp_sch_static_chunked:
4430 case kmp_sch_static_balanced:
4431 case kmp_sch_static_greedy:
4432 __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
4433 break;
4434 case kmp_sch_static_steal:
4435 __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
4436 break;
4437 case kmp_sch_auto:
4438 __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
4439 break;
4440 default:
4441 KMP_ASSERT2(false, "Unhandled sched_type enumeration");
4442 KMP_BUILTIN_UNREACHABLE;
4443 break;
4444 }
4445 } else {
4446 switch (sched) {
4447 case kmp_sch_dynamic_chunked:
4448 __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
4449 break;
4450 case kmp_sch_guided_iterative_chunked:
4451 case kmp_sch_guided_analytical_chunked:
4452 __kmp_str_buf_print(buffer, "%s'\n", "guided");
4453 break;
4454 case kmp_sch_trapezoidal:
4455 __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
4456 break;
4457 case kmp_sch_static:
4458 case kmp_sch_static_chunked:
4459 case kmp_sch_static_balanced:
4460 case kmp_sch_static_greedy:
4461 __kmp_str_buf_print(buffer, "%s'\n", "static");
4462 break;
4463 case kmp_sch_static_steal:
4464 __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
4465 break;
4466 case kmp_sch_auto:
4467 __kmp_str_buf_print(buffer, "%s'\n", "auto");
4468 break;
4469 default:
4470 KMP_ASSERT2(false, "Unhandled sched_type enumeration");
4471 KMP_BUILTIN_UNREACHABLE;
4472 break;
4473 }
4474 }
4475} // __kmp_stg_print_omp_schedule
4476
4477#if KMP_USE_HIER_SCHED
4478// -----------------------------------------------------------------------------
4479// KMP_DISP_HAND_THREAD
4480static void __kmp_stg_parse_kmp_hand_thread(char const *name, char const *value,
4481 void *data) {
4482 __kmp_stg_parse_bool(name, value, &(__kmp_dispatch_hand_threading));
4483} // __kmp_stg_parse_kmp_hand_thread
4484
4485static void __kmp_stg_print_kmp_hand_thread(kmp_str_buf_t *buffer,
4486 char const *name, void *data) {
4487 __kmp_stg_print_bool(buffer, name, __kmp_dispatch_hand_threading);
4488} // __kmp_stg_print_kmp_hand_thread
4489#endif
4490
4491// -----------------------------------------------------------------------------
4492// KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE
4493static void __kmp_stg_parse_kmp_force_monotonic(char const *name,
4494 char const *value, void *data) {
4495 __kmp_stg_parse_bool(name, value, &(__kmp_force_monotonic));
4496} // __kmp_stg_parse_kmp_force_monotonic
4497
4498static void __kmp_stg_print_kmp_force_monotonic(kmp_str_buf_t *buffer,
4499 char const *name, void *data) {
4500 __kmp_stg_print_bool(buffer, name, __kmp_force_monotonic);
4501} // __kmp_stg_print_kmp_force_monotonic
4502
4503// -----------------------------------------------------------------------------
4504// KMP_ATOMIC_MODE
4505
4506static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
4507 void *data) {
4508 // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
4509 // compatibility mode.
4510 int mode = 0;
4511 int max = 1;
4512#ifdef KMP_GOMP_COMPAT
4513 max = 2;
4514#endif /* KMP_GOMP_COMPAT */
4515 __kmp_stg_parse_int(name, value, 0, max, &mode);
4516 // TODO; parse_int is not very suitable for this case. In case of overflow it
4517 // is better to use
4518 // 0 rather that max value.
4519 if (mode > 0) {
4520 __kmp_atomic_mode = mode;
4521 }
4522} // __kmp_stg_parse_atomic_mode
4523
4524static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
4525 void *data) {
4526 __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
4527} // __kmp_stg_print_atomic_mode
4528
4529// -----------------------------------------------------------------------------
4530// KMP_CONSISTENCY_CHECK
4531
4532static void __kmp_stg_parse_consistency_check(char const *name,
4533 char const *value, void *data) {
4534 if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
4535 // Note, this will not work from kmp_set_defaults because th_cons stack was
4536 // not allocated
4537 // for existed thread(s) thus the first __kmp_push_<construct> will break
4538 // with assertion.
4539 // TODO: allocate th_cons if called from kmp_set_defaults.
4540 __kmp_env_consistency_check = TRUE;
4541 } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
4542 __kmp_env_consistency_check = FALSE;
4543 } else {
4544 KMP_WARNING(StgInvalidValue, name, value);
4545 }
4546} // __kmp_stg_parse_consistency_check
4547
4548static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
4549 char const *name, void *data) {
4550#if KMP_DEBUG
4551 const char *value = NULL;
4552
4553 if (__kmp_env_consistency_check) {
4554 value = "all";
4555 } else {
4556 value = "none";
4557 }
4558
4559 if (value != NULL) {
4560 __kmp_stg_print_str(buffer, name, value);
4561 }
4562#endif /* KMP_DEBUG */
4563} // __kmp_stg_print_consistency_check
4564
4565#if USE_ITT_BUILD
4566// -----------------------------------------------------------------------------
4567// KMP_ITT_PREPARE_DELAY
4568
4569#if USE_ITT_NOTIFY
4570
4571static void __kmp_stg_parse_itt_prepare_delay(char const *name,
4572 char const *value, void *data) {
4573 // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
4574 // iterations.
4575 int delay = 0;
4576 __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
4577 __kmp_itt_prepare_delay = delay;
4578} // __kmp_str_parse_itt_prepare_delay
4579
4580static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
4581 char const *name, void *data) {
4582 __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
4583
4584} // __kmp_str_print_itt_prepare_delay
4585
4586#endif // USE_ITT_NOTIFY
4587#endif /* USE_ITT_BUILD */
4588
4589// -----------------------------------------------------------------------------
4590// KMP_MALLOC_POOL_INCR
4591
4592static void __kmp_stg_parse_malloc_pool_incr(char const *name,
4593 char const *value, void *data) {
4594 __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
4595 KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
4596 1);
4597} // __kmp_stg_parse_malloc_pool_incr
4598
4599static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
4600 char const *name, void *data) {
4601 __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
4602
4603} // _kmp_stg_print_malloc_pool_incr
4604
4605#ifdef KMP_DEBUG
4606
4607// -----------------------------------------------------------------------------
4608// KMP_PAR_RANGE
4609
4610static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
4611 void *data) {
4612 __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
4613 __kmp_par_range_routine, __kmp_par_range_filename,
4614 &__kmp_par_range_lb, &__kmp_par_range_ub);
4615} // __kmp_stg_parse_par_range_env
4616
4617static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
4618 char const *name, void *data) {
4619 if (__kmp_par_range != 0) {
4620 __kmp_stg_print_str(buffer, name, par_range_to_print);
4621 }
4622} // __kmp_stg_print_par_range_env
4623
4624#endif
4625
4626// -----------------------------------------------------------------------------
4627// KMP_GTID_MODE
4628
4629static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
4630 void *data) {
4631 // Modes:
4632 // 0 -- do not change default
4633 // 1 -- sp search
4634 // 2 -- use "keyed" TLS var, i.e.
4635 // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
4636 // 3 -- __declspec(thread) TLS var in tdata section
4637 int mode = 0;
4638 int max = 2;
4639#ifdef KMP_TDATA_GTID
4640 max = 3;
4641#endif /* KMP_TDATA_GTID */
4642 __kmp_stg_parse_int(name, value, 0, max, &mode);
4643 // TODO; parse_int is not very suitable for this case. In case of overflow it
4644 // is better to use 0 rather that max value.
4645 if (mode == 0) {
4646 __kmp_adjust_gtid_mode = TRUE;
4647 } else {
4648 __kmp_gtid_mode = mode;
4649 __kmp_adjust_gtid_mode = FALSE;
4650 }
4651} // __kmp_str_parse_gtid_mode
4652
4653static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
4654 void *data) {
4655 if (__kmp_adjust_gtid_mode) {
4656 __kmp_stg_print_int(buffer, name, 0);
4657 } else {
4658 __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
4659 }
4660} // __kmp_stg_print_gtid_mode
4661
4662// -----------------------------------------------------------------------------
4663// KMP_NUM_LOCKS_IN_BLOCK
4664
4665static void __kmp_stg_parse_lock_block(char const *name, char const *value,
4666 void *data) {
4667 __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
4668} // __kmp_str_parse_lock_block
4669
4670static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
4671 void *data) {
4672 __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
4673} // __kmp_stg_print_lock_block
4674
4675// -----------------------------------------------------------------------------
4676// KMP_LOCK_KIND
4677
4678#if KMP_USE_DYNAMIC_LOCK
4679#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
4680#else
4681#define KMP_STORE_LOCK_SEQ(a)
4682#endif
4683
4684static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
4685 void *data) {
4686 if (__kmp_init_user_locks) {
4687 KMP_WARNING(EnvLockWarn, name);
4688 return;
4689 }
4690
4691 if (__kmp_str_match("tas", 2, value) ||
4692 __kmp_str_match("test and set", 2, value) ||
4693 __kmp_str_match("test_and_set", 2, value) ||
4694 __kmp_str_match("test-and-set", 2, value) ||
4695 __kmp_str_match("test andset", 2, value) ||
4696 __kmp_str_match("test_andset", 2, value) ||
4697 __kmp_str_match("test-andset", 2, value) ||
4698 __kmp_str_match("testand set", 2, value) ||
4699 __kmp_str_match("testand_set", 2, value) ||
4700 __kmp_str_match("testand-set", 2, value) ||
4701 __kmp_str_match("testandset", 2, value)) {
4702 __kmp_user_lock_kind = lk_tas;
4703 KMP_STORE_LOCK_SEQ(tas);
4704 }
4705#if KMP_USE_FUTEX
4706 else if (__kmp_str_match("futex", 1, value)) {
4707 if (__kmp_futex_determine_capable()) {
4708 __kmp_user_lock_kind = lk_futex;
4709 KMP_STORE_LOCK_SEQ(futex);
4710 } else {
4711 KMP_WARNING(FutexNotSupported, name, value);
4712 }
4713 }
4714#endif
4715 else if (__kmp_str_match("ticket", 2, value)) {
4716 __kmp_user_lock_kind = lk_ticket;
4717 KMP_STORE_LOCK_SEQ(ticket);
4718 } else if (__kmp_str_match("queuing", 1, value) ||
4719 __kmp_str_match("queue", 1, value)) {
4720 __kmp_user_lock_kind = lk_queuing;
4721 KMP_STORE_LOCK_SEQ(queuing);
4722 } else if (__kmp_str_match("drdpa ticket", 1, value) ||
4723 __kmp_str_match("drdpa_ticket", 1, value) ||
4724 __kmp_str_match("drdpa-ticket", 1, value) ||
4725 __kmp_str_match("drdpaticket", 1, value) ||
4726 __kmp_str_match("drdpa", 1, value)) {
4727 __kmp_user_lock_kind = lk_drdpa;
4728 KMP_STORE_LOCK_SEQ(drdpa);
4729 }
4730#if KMP_USE_ADAPTIVE_LOCKS
4731 else if (__kmp_str_match("adaptive", 1, value)) {
4732 if (__kmp_cpuinfo.flags.rtm) { // ??? Is cpuinfo available here?
4733 __kmp_user_lock_kind = lk_adaptive;
4734 KMP_STORE_LOCK_SEQ(adaptive);
4735 } else {
4736 KMP_WARNING(AdaptiveNotSupported, name, value);
4737 __kmp_user_lock_kind = lk_queuing;
4738 KMP_STORE_LOCK_SEQ(queuing);
4739 }
4740 }
4741#endif // KMP_USE_ADAPTIVE_LOCKS
4742#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4743 else if (__kmp_str_match("rtm_queuing", 1, value)) {
4744 if (__kmp_cpuinfo.flags.rtm) {
4745 __kmp_user_lock_kind = lk_rtm_queuing;
4746 KMP_STORE_LOCK_SEQ(rtm_queuing);
4747 } else {
4748 KMP_WARNING(AdaptiveNotSupported, name, value);
4749 __kmp_user_lock_kind = lk_queuing;
4750 KMP_STORE_LOCK_SEQ(queuing);
4751 }
4752 } else if (__kmp_str_match("rtm_spin", 1, value)) {
4753 if (__kmp_cpuinfo.flags.rtm) {
4754 __kmp_user_lock_kind = lk_rtm_spin;
4755 KMP_STORE_LOCK_SEQ(rtm_spin);
4756 } else {
4757 KMP_WARNING(AdaptiveNotSupported, name, value);
4758 __kmp_user_lock_kind = lk_tas;
4759 KMP_STORE_LOCK_SEQ(queuing);
4760 }
4761 } else if (__kmp_str_match("hle", 1, value)) {
4762 __kmp_user_lock_kind = lk_hle;
4763 KMP_STORE_LOCK_SEQ(hle);
4764 }
4765#endif
4766 else {
4767 KMP_WARNING(StgInvalidValue, name, value);
4768 }
4769}
4770
4771static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
4772 void *data) {
4773 const char *value = NULL;
4774
4775 switch (__kmp_user_lock_kind) {
4776 case lk_default:
4777 value = "default";
4778 break;
4779
4780 case lk_tas:
4781 value = "tas";
4782 break;
4783
4784#if KMP_USE_FUTEX
4785 case lk_futex:
4786 value = "futex";
4787 break;
4788#endif
4789
4790#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
4791 case lk_rtm_queuing:
4792 value = "rtm_queuing";
4793 break;
4794
4795 case lk_rtm_spin:
4796 value = "rtm_spin";
4797 break;
4798
4799 case lk_hle:
4800 value = "hle";
4801 break;
4802#endif
4803
4804 case lk_ticket:
4805 value = "ticket";
4806 break;
4807
4808 case lk_queuing:
4809 value = "queuing";
4810 break;
4811
4812 case lk_drdpa:
4813 value = "drdpa";
4814 break;
4815#if KMP_USE_ADAPTIVE_LOCKS
4816 case lk_adaptive:
4817 value = "adaptive";
4818 break;
4819#endif
4820 }
4821
4822 if (value != NULL) {
4823 __kmp_stg_print_str(buffer, name, value);
4824 }
4825}
4826
4827// -----------------------------------------------------------------------------
4828// KMP_SPIN_BACKOFF_PARAMS
4829
4830// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
4831// for machine pause)
4832static void __kmp_stg_parse_spin_backoff_params(const char *name,
4833 const char *value, void *data) {
4834 const char *next = value;
4835
4836 int total = 0; // Count elements that were set. It'll be used as an array size
4837 int prev_comma = FALSE; // For correct processing sequential commas
4838 int i;
4839
4840 kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
4841 kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
4842
4843 // Run only 3 iterations because it is enough to read two values or find a
4844 // syntax error
4845 for (i = 0; i < 3; i++) {
4846 SKIP_WS(next);
4847
4848 if (*next == '\0') {
4849 break;
4850 }
4851 // Next character is not an integer or not a comma OR number of values > 2
4852 // => end of list
4853 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
4854 KMP_WARNING(EnvSyntaxError, name, value);
4855 return;
4856 }
4857 // The next character is ','
4858 if (*next == ',') {
4859 // ',' is the first character
4860 if (total == 0 || prev_comma) {
4861 total++;
4862 }
4863 prev_comma = TRUE;
4864 next++; // skip ','
4865 SKIP_WS(next);
4866 }
4867 // Next character is a digit
4868 if (*next >= '0' && *next <= '9') {
4869 int num;
4870 const char *buf = next;
4871 char const *msg = NULL;
4872 prev_comma = FALSE;
4873 SKIP_DIGITS(next);
4874 total++;
4875
4876 const char *tmp = next;
4877 SKIP_WS(tmp);
4878 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4879 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4880 return;
4881 }
4882
4883 num = __kmp_str_to_int(buf, *next);
4884 if (num <= 0) { // The number of retries should be > 0
4885 msg = KMP_I18N_STR(ValueTooSmall);
4886 num = 1;
4887 } else if (num > KMP_INT_MAX) {
4888 msg = KMP_I18N_STR(ValueTooLarge);
4889 num = KMP_INT_MAX;
4890 }
4891 if (msg != NULL) {
4892 // Message is not empty. Print warning.
4893 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4894 KMP_INFORM(Using_int_Value, name, num);
4895 }
4896 if (total == 1) {
4897 max_backoff = num;
4898 } else if (total == 2) {
4899 min_tick = num;
4900 }
4901 }
4902 }
4903 KMP_DEBUG_ASSERT(total > 0);
4904 if (total <= 0) {
4905 KMP_WARNING(EnvSyntaxError, name, value);
4906 return;
4907 }
4908 __kmp_spin_backoff_params.max_backoff = max_backoff;
4909 __kmp_spin_backoff_params.min_tick = min_tick;
4910}
4911
4912static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
4913 char const *name, void *data) {
4914 if (__kmp_env_format) {
4915 KMP_STR_BUF_PRINT_NAME_EX(name);
4916 } else {
4917 __kmp_str_buf_print(buffer, " %s='", name);
4918 }
4919 __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
4920 __kmp_spin_backoff_params.min_tick);
4921}
4922
4923#if KMP_USE_ADAPTIVE_LOCKS
4924
4925// -----------------------------------------------------------------------------
4926// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
4927
4928// Parse out values for the tunable parameters from a string of the form
4929// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
4930static void __kmp_stg_parse_adaptive_lock_props(const char *name,
4931 const char *value, void *data) {
4932 int max_retries = 0;
4933 int max_badness = 0;
4934
4935 const char *next = value;
4936
4937 int total = 0; // Count elements that were set. It'll be used as an array size
4938 int prev_comma = FALSE; // For correct processing sequential commas
4939 int i;
4940
4941 // Save values in the structure __kmp_speculative_backoff_params
4942 // Run only 3 iterations because it is enough to read two values or find a
4943 // syntax error
4944 for (i = 0; i < 3; i++) {
4945 SKIP_WS(next);
4946
4947 if (*next == '\0') {
4948 break;
4949 }
4950 // Next character is not an integer or not a comma OR number of values > 2
4951 // => end of list
4952 if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
4953 KMP_WARNING(EnvSyntaxError, name, value);
4954 return;
4955 }
4956 // The next character is ','
4957 if (*next == ',') {
4958 // ',' is the first character
4959 if (total == 0 || prev_comma) {
4960 total++;
4961 }
4962 prev_comma = TRUE;
4963 next++; // skip ','
4964 SKIP_WS(next);
4965 }
4966 // Next character is a digit
4967 if (*next >= '0' && *next <= '9') {
4968 int num;
4969 const char *buf = next;
4970 char const *msg = NULL;
4971 prev_comma = FALSE;
4972 SKIP_DIGITS(next);
4973 total++;
4974
4975 const char *tmp = next;
4976 SKIP_WS(tmp);
4977 if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
4978 KMP_WARNING(EnvSpacesNotAllowed, name, value);
4979 return;
4980 }
4981
4982 num = __kmp_str_to_int(buf, *next);
4983 if (num < 0) { // The number of retries should be >= 0
4984 msg = KMP_I18N_STR(ValueTooSmall);
4985 num = 1;
4986 } else if (num > KMP_INT_MAX) {
4987 msg = KMP_I18N_STR(ValueTooLarge);
4988 num = KMP_INT_MAX;
4989 }
4990 if (msg != NULL) {
4991 // Message is not empty. Print warning.
4992 KMP_WARNING(ParseSizeIntWarn, name, value, msg);
4993 KMP_INFORM(Using_int_Value, name, num);
4994 }
4995 if (total == 1) {
4996 max_retries = num;
4997 } else if (total == 2) {
4998 max_badness = num;
4999 }
5000 }
5001 }
5002 KMP_DEBUG_ASSERT(total > 0);
5003 if (total <= 0) {
5004 KMP_WARNING(EnvSyntaxError, name, value);
5005 return;
5006 }
5007 __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
5008 __kmp_adaptive_backoff_params.max_badness = max_badness;
5009}
5010
5011static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
5012 char const *name, void *data) {
5013 if (__kmp_env_format) {
5014 KMP_STR_BUF_PRINT_NAME_EX(name);
5015 } else {
5016 __kmp_str_buf_print(buffer, " %s='", name);
5017 }
5018 __kmp_str_buf_print(buffer, "%d,%d'\n",
5019 __kmp_adaptive_backoff_params.max_soft_retries,
5020 __kmp_adaptive_backoff_params.max_badness);
5021} // __kmp_stg_print_adaptive_lock_props
5022
5023#if KMP_DEBUG_ADAPTIVE_LOCKS
5024
5025static void __kmp_stg_parse_speculative_statsfile(char const *name,
5026 char const *value,
5027 void *data) {
5028 __kmp_stg_parse_file(name, value, "",
5029 CCAST(char **, &__kmp_speculative_statsfile));
5030} // __kmp_stg_parse_speculative_statsfile
5031
5032static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
5033 char const *name,
5034 void *data) {
5035 if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
5036 __kmp_stg_print_str(buffer, name, "stdout");
5037 } else {
5038 __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
5039 }
5040
5041} // __kmp_stg_print_speculative_statsfile
5042
5043#endif // KMP_DEBUG_ADAPTIVE_LOCKS
5044
5045#endif // KMP_USE_ADAPTIVE_LOCKS
5046
5047// -----------------------------------------------------------------------------
5048// KMP_HW_SUBSET (was KMP_PLACE_THREADS)
5049// 2s16c,2t => 2S16C,2T => 2S16C \0 2T
5050
5051// Return KMP_HW_SUBSET preferred hardware type in case a token is ambiguously
5052// short. The original KMP_HW_SUBSET environment variable had single letters:
5053// s, c, t for sockets, cores, threads repsectively.
5054static kmp_hw_t __kmp_hw_subset_break_tie(const kmp_hw_t *possible,
5055 size_t num_possible) {
5056 for (size_t i = 0; i < num_possible; ++i) {
5057 if (possible[i] == KMP_HW_THREAD)
5058 return KMP_HW_THREAD;
5059 else if (possible[i] == KMP_HW_CORE)
5060 return KMP_HW_CORE;
5061 else if (possible[i] == KMP_HW_SOCKET)
5062 return KMP_HW_SOCKET;
5063 }
5064 return KMP_HW_UNKNOWN;
5065}
5066
5067// Return hardware type from string or HW_UNKNOWN if string cannot be parsed
5068// This algorithm is very forgiving to the user in that, the instant it can
5069// reduce the search space to one, it assumes that is the topology level the
5070// user wanted, even if it is misspelled later in the token.
5071static kmp_hw_t __kmp_stg_parse_hw_subset_name(char const *token) {
5072 size_t index, num_possible, token_length;
5073 kmp_hw_t possible[KMP_HW_LAST];
5074 const char *end;
5075
5076 // Find the end of the hardware token string
5077 end = token;
5078 token_length = 0;
5079 while (isalnum(*end) || *end == '_') {
5080 token_length++;
5081 end++;
5082 }
5083
5084 // Set the possibilities to all hardware types
5085 num_possible = 0;
5086 KMP_FOREACH_HW_TYPE(type) { possible[num_possible++] = type; }
5087
5088 // Eliminate hardware types by comparing the front of the token
5089 // with hardware names
5090 // In most cases, the first letter in the token will indicate exactly
5091 // which hardware type is parsed, e.g., 'C' = Core
5092 index = 0;
5093 while (num_possible > 1 && index < token_length) {
5094 size_t n = num_possible;
5095 char token_char = (char)toupper(token[index]);
5096 for (size_t i = 0; i < n; ++i) {
5097 const char *s;
5098 kmp_hw_t type = possible[i];
5099 s = __kmp_hw_get_keyword(type, false);
5100 if (index < KMP_STRLEN(s)) {
5101 char c = (char)toupper(s[index]);
5102 // Mark hardware types for removal when the characters do not match
5103 if (c != token_char) {
5104 possible[i] = KMP_HW_UNKNOWN;
5105 num_possible--;
5106 }
5107 }
5108 }
5109 // Remove hardware types that this token cannot be
5110 size_t start = 0;
5111 for (size_t i = 0; i < n; ++i) {
5112 if (possible[i] != KMP_HW_UNKNOWN) {
5113 kmp_hw_t temp = possible[i];
5114 possible[i] = possible[start];
5115 possible[start] = temp;
5116 start++;
5117 }
5118 }
5119 KMP_ASSERT(start == num_possible);
5120 index++;
5121 }
5122
5123 // Attempt to break a tie if user has very short token
5124 // (e.g., is 'T' tile or thread?)
5125 if (num_possible > 1)
5126 return __kmp_hw_subset_break_tie(possible, num_possible);
5127 if (num_possible == 1)
5128 return possible[0];
5129 return KMP_HW_UNKNOWN;
5130}
5131
5132// The longest observable sequence of items can only be HW_LAST length
5133// The input string is usually short enough, let's use 512 limit for now
5134#define MAX_T_LEVEL KMP_HW_LAST
5135#define MAX_STR_LEN 512
5136static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
5137 void *data) {
5138 // Value example: 1s,5c@3,2T
5139 // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
5140 kmp_setting_t **rivals = (kmp_setting_t **)data;
5141 if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
5142 KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
5143 }
5144 if (__kmp_stg_check_rivals(name, value, rivals)) {
5145 return;
5146 }
5147
5148 char *components[MAX_T_LEVEL];
5149 char const *digits = "0123456789";
5150 char input[MAX_STR_LEN];
5151 size_t len = 0, mlen = MAX_STR_LEN;
5152 int level = 0;
5153 bool absolute = false;
5154 // Canonicalize the string (remove spaces, unify delimiters, etc.)
5155 char *pos = CCAST(char *, value);
5156 while (*pos && mlen) {
5157 if (*pos != ' ') { // skip spaces
5158 if (len == 0 && *pos == ':') {
5159 absolute = true;
5160 } else {
5161 input[len] = (char)(toupper(*pos));
5162 if (input[len] == 'X')
5163 input[len] = ','; // unify delimiters of levels
5164 if (input[len] == 'O' && strchr(digits, *(pos + 1)))
5165 input[len] = '@'; // unify delimiters of offset
5166 len++;
5167 }
5168 }
5169 mlen--;
5170 pos++;
5171 }
5172 if (len == 0 || mlen == 0) {
5173 goto err; // contents is either empty or too long
5174 }
5175 input[len] = '\0';
5176 // Split by delimiter
5177 pos = input;
5178 components[level++] = pos;
5179 while ((pos = strchr(pos, ','))) {
5180 if (level >= MAX_T_LEVEL)
5181 goto err; // too many components provided
5182 *pos = '\0'; // modify input and avoid more copying
5183 components[level++] = ++pos; // expect something after ","
5184 }
5185
5186 __kmp_hw_subset = kmp_hw_subset_t::allocate();
5187 if (absolute)
5188 __kmp_hw_subset->set_absolute();
5189
5190 // Check each component
5191 for (int i = 0; i < level; ++i) {
5192 int core_level = 0;
5193 char *core_components[MAX_T_LEVEL];
5194 // Split possible core components by '&' delimiter
5195 pos = components[i];
5196 core_components[core_level++] = pos;
5197 while ((pos = strchr(pos, '&'))) {
5198 if (core_level >= MAX_T_LEVEL)
5199 goto err; // too many different core types
5200 *pos = '\0'; // modify input and avoid more copying
5201 core_components[core_level++] = ++pos; // expect something after '&'
5202 }
5203
5204 for (int j = 0; j < core_level; ++j) {
5205 char *offset_ptr;
5206 char *attr_ptr;
5207 int offset = 0;
5208 kmp_hw_attr_t attr;
5209 int num;
5210 // components may begin with an optional count of the number of resources
5211 if (isdigit(*core_components[j])) {
5212 num = atoi(core_components[j]);
5213 if (num <= 0) {
5214 goto err; // only positive integers are valid for count
5215 }
5216 pos = core_components[j] + strspn(core_components[j], digits);
5217 } else if (*core_components[j] == '*') {
5218 num = kmp_hw_subset_t::USE_ALL;
5219 pos = core_components[j] + 1;
5220 } else {
5221 num = kmp_hw_subset_t::USE_ALL;
5222 pos = core_components[j];
5223 }
5224
5225 offset_ptr = strchr(core_components[j], '@');
5226 attr_ptr = strchr(core_components[j], ':');
5227
5228 if (offset_ptr) {
5229 offset = atoi(offset_ptr + 1); // save offset
5230 *offset_ptr = '\0'; // cut the offset from the component
5231 }
5232 if (attr_ptr) {
5233 attr.clear();
5234 // save the attribute
5235#if KMP_ARCH_X86 || KMP_ARCH_X86_64
5236 if (__kmp_str_match("intel_core", -1, attr_ptr + 1)) {
5237 attr.set_core_type(KMP_HW_CORE_TYPE_CORE);
5238 } else if (__kmp_str_match("intel_atom", -1, attr_ptr + 1)) {
5239 attr.set_core_type(KMP_HW_CORE_TYPE_ATOM);
5240 } else
5241#endif
5242 if (__kmp_str_match("eff", 3, attr_ptr + 1)) {
5243 const char *number = attr_ptr + 1;
5244 // skip the eff[iciency] token
5245 while (isalpha(*number))
5246 number++;
5247 if (!isdigit(*number)) {
5248 goto err;
5249 }
5250 int efficiency = atoi(number);
5251 attr.set_core_eff(efficiency);
5252 } else {
5253 goto err;
5254 }
5255 *attr_ptr = '\0'; // cut the attribute from the component
5256 }
5257 // detect the component type
5258 kmp_hw_t type = __kmp_stg_parse_hw_subset_name(pos);
5259 if (type == KMP_HW_UNKNOWN) {
5260 goto err;
5261 }
5262 // Only the core type can have attributes
5263 if (attr && type != KMP_HW_CORE)
5264 goto err;
5265 // Must allow core be specified more than once
5266 if (type != KMP_HW_CORE && __kmp_hw_subset->specified(type)) {
5267 goto err;
5268 }
5269 __kmp_hw_subset->push_back(num, type, offset, attr);
5270 }
5271 }
5272 return;
5273err:
5274 KMP_WARNING(AffHWSubsetInvalid, name, value);
5275 if (__kmp_hw_subset) {
5276 kmp_hw_subset_t::deallocate(__kmp_hw_subset);
5277 __kmp_hw_subset = nullptr;
5278 }
5279 return;
5280}
5281
5282static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
5283 void *data) {
5284 kmp_str_buf_t buf;
5285 int depth;
5286 if (!__kmp_hw_subset)
5287 return;
5288 __kmp_str_buf_init(&buf);
5289 if (__kmp_env_format)
5290 KMP_STR_BUF_PRINT_NAME_EX(name);
5291 else
5292 __kmp_str_buf_print(buffer, " %s='", name);
5293
5294 depth = __kmp_hw_subset->get_depth();
5295 for (int i = 0; i < depth; ++i) {
5296 const auto &item = __kmp_hw_subset->at(i);
5297 if (i > 0)
5298 __kmp_str_buf_print(&buf, "%c", ',');
5299 for (int j = 0; j < item.num_attrs; ++j) {
5300 __kmp_str_buf_print(&buf, "%s%d%s", (j > 0 ? "&" : ""), item.num[j],
5301 __kmp_hw_get_keyword(item.type));
5302 if (item.attr[j].is_core_type_valid())
5303 __kmp_str_buf_print(
5304 &buf, ":%s",
5305 __kmp_hw_get_core_type_keyword(item.attr[j].get_core_type()));
5306 if (item.attr[j].is_core_eff_valid())
5307 __kmp_str_buf_print(&buf, ":eff%d", item.attr[j].get_core_eff());
5308 if (item.offset[j])
5309 __kmp_str_buf_print(&buf, "@%d", item.offset[j]);
5310 }
5311 }
5312 __kmp_str_buf_print(buffer, "%s'\n", buf.str);
5313 __kmp_str_buf_free(&buf);
5314}
5315
5316#if USE_ITT_BUILD
5317// -----------------------------------------------------------------------------
5318// KMP_FORKJOIN_FRAMES
5319
5320static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
5321 void *data) {
5322 __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
5323} // __kmp_stg_parse_forkjoin_frames
5324
5325static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
5326 char const *name, void *data) {
5327 __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
5328} // __kmp_stg_print_forkjoin_frames
5329
5330// -----------------------------------------------------------------------------
5331// KMP_FORKJOIN_FRAMES_MODE
5332
5333static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
5334 char const *value,
5335 void *data) {
5336 __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
5337} // __kmp_stg_parse_forkjoin_frames
5338
5339static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
5340 char const *name, void *data) {
5341 __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
5342} // __kmp_stg_print_forkjoin_frames
5343#endif /* USE_ITT_BUILD */
5344
5345// -----------------------------------------------------------------------------
5346// KMP_ENABLE_TASK_THROTTLING
5347
5348static void __kmp_stg_parse_task_throttling(char const *name, char const *value,
5349 void *data) {
5350 __kmp_stg_parse_bool(name, value, &__kmp_enable_task_throttling);
5351} // __kmp_stg_parse_task_throttling
5352
5353static void __kmp_stg_print_task_throttling(kmp_str_buf_t *buffer,
5354 char const *name, void *data) {
5355 __kmp_stg_print_bool(buffer, name, __kmp_enable_task_throttling);
5356} // __kmp_stg_print_task_throttling
5357
5358#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5359// -----------------------------------------------------------------------------
5360// KMP_USER_LEVEL_MWAIT
5361
5362static void __kmp_stg_parse_user_level_mwait(char const *name,
5363 char const *value, void *data) {
5364 __kmp_stg_parse_bool(name, value, &__kmp_user_level_mwait);
5365} // __kmp_stg_parse_user_level_mwait
5366
5367static void __kmp_stg_print_user_level_mwait(kmp_str_buf_t *buffer,
5368 char const *name, void *data) {
5369 __kmp_stg_print_bool(buffer, name, __kmp_user_level_mwait);
5370} // __kmp_stg_print_user_level_mwait
5371
5372// -----------------------------------------------------------------------------
5373// KMP_MWAIT_HINTS
5374
5375static void __kmp_stg_parse_mwait_hints(char const *name, char const *value,
5376 void *data) {
5377 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_mwait_hints);
5378} // __kmp_stg_parse_mwait_hints
5379
5380static void __kmp_stg_print_mwait_hints(kmp_str_buf_t *buffer, char const *name,
5381 void *data) {
5382 __kmp_stg_print_int(buffer, name, __kmp_mwait_hints);
5383} // __kmp_stg_print_mwait_hints
5384
5385#endif // KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5386
5387#if KMP_HAVE_UMWAIT
5388// -----------------------------------------------------------------------------
5389// KMP_TPAUSE
5390// 0 = don't use TPAUSE, 1 = use C0.1 state, 2 = use C0.2 state
5391
5392static void __kmp_stg_parse_tpause(char const *name, char const *value,
5393 void *data) {
5394 __kmp_stg_parse_int(name, value, 0, INT_MAX, &__kmp_tpause_state);
5395 if (__kmp_tpause_state != 0) {
5396 // The actual hint passed to tpause is: 0 for C0.2 and 1 for C0.1
5397 if (__kmp_tpause_state == 2) // use C0.2
5398 __kmp_tpause_hint = 0; // default was set to 1 for C0.1
5399 }
5400} // __kmp_stg_parse_tpause
5401
5402static void __kmp_stg_print_tpause(kmp_str_buf_t *buffer, char const *name,
5403 void *data) {
5404 __kmp_stg_print_int(buffer, name, __kmp_tpause_state);
5405} // __kmp_stg_print_tpause
5406#endif // KMP_HAVE_UMWAIT
5407
5408// -----------------------------------------------------------------------------
5409// OMP_DISPLAY_ENV
5410
5411static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
5412 void *data) {
5413 if (__kmp_str_match("VERBOSE", 1, value)) {
5414 __kmp_display_env_verbose = TRUE;
5415 } else {
5416 __kmp_stg_parse_bool(name, value, &__kmp_display_env);
5417 }
5418} // __kmp_stg_parse_omp_display_env
5419
5420static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
5421 char const *name, void *data) {
5422 if (__kmp_display_env_verbose) {
5423 __kmp_stg_print_str(buffer, name, "VERBOSE");
5424 } else {
5425 __kmp_stg_print_bool(buffer, name, __kmp_display_env);
5426 }
5427} // __kmp_stg_print_omp_display_env
5428
5429static void __kmp_stg_parse_omp_cancellation(char const *name,
5430 char const *value, void *data) {
5431 if (TCR_4(__kmp_init_parallel)) {
5432 KMP_WARNING(EnvParallelWarn, name);
5433 return;
5434 } // read value before first parallel only
5435 __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
5436} // __kmp_stg_parse_omp_cancellation
5437
5438static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
5439 char const *name, void *data) {
5440 __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
5441} // __kmp_stg_print_omp_cancellation
5442
5443#if OMPT_SUPPORT
5444int __kmp_tool = 1;
5445
5446static void __kmp_stg_parse_omp_tool(char const *name, char const *value,
5447 void *data) {
5448 __kmp_stg_parse_bool(name, value, &__kmp_tool);
5449} // __kmp_stg_parse_omp_tool
5450
5451static void __kmp_stg_print_omp_tool(kmp_str_buf_t *buffer, char const *name,
5452 void *data) {
5453 if (__kmp_env_format) {
5454 KMP_STR_BUF_PRINT_BOOL_EX(name, __kmp_tool, "enabled", "disabled");
5455 } else {
5456 __kmp_str_buf_print(buffer, " %s=%s\n", name,
5457 __kmp_tool ? "enabled" : "disabled");
5458 }
5459} // __kmp_stg_print_omp_tool
5460
5461char *__kmp_tool_libraries = NULL;
5462
5463static void __kmp_stg_parse_omp_tool_libraries(char const *name,
5464 char const *value, void *data) {
5465 __kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
5466} // __kmp_stg_parse_omp_tool_libraries
5467
5468static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer,
5469 char const *name, void *data) {
5470 if (__kmp_tool_libraries)
5471 __kmp_stg_print_str(buffer, name, __kmp_tool_libraries);
5472 else {
5473 if (__kmp_env_format) {
5474 KMP_STR_BUF_PRINT_NAME;
5475 } else {
5476 __kmp_str_buf_print(buffer, " %s", name);
5477 }
5478 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
5479 }
5480} // __kmp_stg_print_omp_tool_libraries
5481
5482char *__kmp_tool_verbose_init = NULL;
5483
5484static void __kmp_stg_parse_omp_tool_verbose_init(char const *name,
5485 char const *value,
5486 void *data) {
5487 __kmp_stg_parse_str(name, value, &__kmp_tool_verbose_init);
5488} // __kmp_stg_parse_omp_tool_libraries
5489
5490static void __kmp_stg_print_omp_tool_verbose_init(kmp_str_buf_t *buffer,
5491 char const *name,
5492 void *data) {
5493 if (__kmp_tool_verbose_init)
5494 __kmp_stg_print_str(buffer, name, __kmp_tool_verbose_init);
5495 else {
5496 if (__kmp_env_format) {
5497 KMP_STR_BUF_PRINT_NAME;
5498 } else {
5499 __kmp_str_buf_print(buffer, " %s", name);
5500 }
5501 __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
5502 }
5503} // __kmp_stg_print_omp_tool_verbose_init
5504
5505#endif
5506
5507// Table.
5508
5509static kmp_setting_t __kmp_stg_table[] = {
5510
5511 {"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
5512 {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
5513 NULL, 0, 0},
5514 {"KMP_USE_YIELD", __kmp_stg_parse_use_yield, __kmp_stg_print_use_yield,
5515 NULL, 0, 0},
5516 {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
5517 __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
5518 {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
5519 NULL, 0, 0},
5520 {"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
5521 __kmp_stg_print_device_thread_limit, NULL, 0, 0},
5522#if KMP_USE_MONITOR
5523 {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
5524 __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
5525#endif
5526 {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
5527 0, 0},
5528 {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
5529 __kmp_stg_print_stackoffset, NULL, 0, 0},
5530 {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5531 NULL, 0, 0},
5532 {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
5533 0, 0},
5534 {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
5535 0},
5536 {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
5537 0, 0},
5538
5539 {"KMP_NESTING_MODE", __kmp_stg_parse_nesting_mode,
5540 __kmp_stg_print_nesting_mode, NULL, 0, 0},
5541 {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
5542 {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
5543 __kmp_stg_print_num_threads, NULL, 0, 0},
5544 {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
5545 NULL, 0, 0},
5546
5547 {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
5548 0},
5549 {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
5550 __kmp_stg_print_task_stealing, NULL, 0, 0},
5551 {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
5552 __kmp_stg_print_max_active_levels, NULL, 0, 0},
5553 {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
5554 __kmp_stg_print_default_device, NULL, 0, 0},
5555 {"OMP_TARGET_OFFLOAD", __kmp_stg_parse_target_offload,
5556 __kmp_stg_print_target_offload, NULL, 0, 0},
5557 {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
5558 __kmp_stg_print_max_task_priority, NULL, 0, 0},
5559 {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
5560 __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
5561 {"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
5562 __kmp_stg_print_thread_limit, NULL, 0, 0},
5563 {"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
5564 __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
5565 {"OMP_NUM_TEAMS", __kmp_stg_parse_nteams, __kmp_stg_print_nteams, NULL, 0,
5566 0},
5567 {"OMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_th_limit,
5568 __kmp_stg_print_teams_th_limit, NULL, 0, 0},
5569 {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
5570 __kmp_stg_print_wait_policy, NULL, 0, 0},
5571 {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
5572 __kmp_stg_print_disp_buffers, NULL, 0, 0},
5573#if KMP_NESTED_HOT_TEAMS
5574 {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
5575 __kmp_stg_print_hot_teams_level, NULL, 0, 0},
5576 {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
5577 __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
5578#endif // KMP_NESTED_HOT_TEAMS
5579
5580#if KMP_HANDLE_SIGNALS
5581 {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
5582 __kmp_stg_print_handle_signals, NULL, 0, 0},
5583#endif
5584
5585#if KMP_ARCH_X86 || KMP_ARCH_X86_64
5586 {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
5587 __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
5588#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
5589
5590#ifdef KMP_GOMP_COMPAT
5591 {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
5592#endif
5593
5594#ifdef KMP_DEBUG
5595 {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
5596 0},
5597 {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
5598 0},
5599 {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
5600 0},
5601 {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
5602 0},
5603 {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
5604 0},
5605 {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
5606 0},
5607 {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
5608 {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
5609 NULL, 0, 0},
5610 {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
5611 __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
5612 {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
5613 __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
5614 {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
5615 __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
5616 {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
5617
5618 {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
5619 __kmp_stg_print_par_range_env, NULL, 0, 0},
5620#endif // KMP_DEBUG
5621
5622 {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
5623 __kmp_stg_print_align_alloc, NULL, 0, 0},
5624
5625 {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5626 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5627 {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5628 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5629 {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5630 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5631 {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5632 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5633#if KMP_FAST_REDUCTION_BARRIER
5634 {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
5635 __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
5636 {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
5637 __kmp_stg_print_barrier_pattern, NULL, 0, 0},
5638#endif
5639
5640 {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
5641 __kmp_stg_print_abort_delay, NULL, 0, 0},
5642 {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
5643 __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
5644 {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
5645 __kmp_stg_print_force_reduction, NULL, 0, 0},
5646 {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
5647 __kmp_stg_print_force_reduction, NULL, 0, 0},
5648 {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
5649 __kmp_stg_print_storage_map, NULL, 0, 0},
5650 {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
5651 __kmp_stg_print_all_threadprivate, NULL, 0, 0},
5652 {"KMP_FOREIGN_THREADS_THREADPRIVATE",
5653 __kmp_stg_parse_foreign_threads_threadprivate,
5654 __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
5655
5656#if KMP_AFFINITY_SUPPORTED
5657 {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
5658 0, 0},
5659 {"KMP_HIDDEN_HELPER_AFFINITY", __kmp_stg_parse_hh_affinity,
5660 __kmp_stg_print_hh_affinity, NULL, 0, 0},
5661#ifdef KMP_GOMP_COMPAT
5662 {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
5663 /* no print */ NULL, 0, 0},
5664#endif /* KMP_GOMP_COMPAT */
5665 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5666 NULL, 0, 0},
5667 {"KMP_TEAMS_PROC_BIND", __kmp_stg_parse_teams_proc_bind,
5668 __kmp_stg_print_teams_proc_bind, NULL, 0, 0},
5669 {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
5670 {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
5671 __kmp_stg_print_topology_method, NULL, 0, 0},
5672
5673#else
5674
5675 // KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
5676 // OMP_PROC_BIND and proc-bind-var are supported, however.
5677 {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
5678 NULL, 0, 0},
5679
5680#endif // KMP_AFFINITY_SUPPORTED
5681 {"OMP_DISPLAY_AFFINITY", __kmp_stg_parse_display_affinity,
5682 __kmp_stg_print_display_affinity, NULL, 0, 0},
5683 {"OMP_AFFINITY_FORMAT", __kmp_stg_parse_affinity_format,
5684 __kmp_stg_print_affinity_format, NULL, 0, 0},
5685 {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
5686 __kmp_stg_print_init_at_fork, NULL, 0, 0},
5687 {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
5688 0, 0},
5689 {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
5690 NULL, 0, 0},
5691#if KMP_USE_HIER_SCHED
5692 {"KMP_DISP_HAND_THREAD", __kmp_stg_parse_kmp_hand_thread,
5693 __kmp_stg_print_kmp_hand_thread, NULL, 0, 0},
5694#endif
5695 {"KMP_FORCE_MONOTONIC_DYNAMIC_SCHEDULE",
5696 __kmp_stg_parse_kmp_force_monotonic, __kmp_stg_print_kmp_force_monotonic,
5697 NULL, 0, 0},
5698 {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
5699 __kmp_stg_print_atomic_mode, NULL, 0, 0},
5700 {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
5701 __kmp_stg_print_consistency_check, NULL, 0, 0},
5702
5703#if USE_ITT_BUILD && USE_ITT_NOTIFY
5704 {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
5705 __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
5706#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
5707 {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
5708 __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
5709 {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
5710 NULL, 0, 0},
5711 {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
5712 NULL, 0, 0},
5713 {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
5714 __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
5715
5716#ifdef USE_LOAD_BALANCE
5717 {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
5718 __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
5719#endif
5720
5721 {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
5722 __kmp_stg_print_lock_block, NULL, 0, 0},
5723 {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
5724 NULL, 0, 0},
5725 {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
5726 __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
5727#if KMP_USE_ADAPTIVE_LOCKS
5728 {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
5729 __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
5730#if KMP_DEBUG_ADAPTIVE_LOCKS
5731 {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
5732 __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
5733#endif
5734#endif // KMP_USE_ADAPTIVE_LOCKS
5735 {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5736 NULL, 0, 0},
5737 {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
5738 NULL, 0, 0},
5739#if USE_ITT_BUILD
5740 {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
5741 __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
5742 {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
5743 __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
5744#endif
5745 {"KMP_ENABLE_TASK_THROTTLING", __kmp_stg_parse_task_throttling,
5746 __kmp_stg_print_task_throttling, NULL, 0, 0},
5747
5748 {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
5749 __kmp_stg_print_omp_display_env, NULL, 0, 0},
5750 {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
5751 __kmp_stg_print_omp_cancellation, NULL, 0, 0},
5752 {"OMP_ALLOCATOR", __kmp_stg_parse_allocator, __kmp_stg_print_allocator,
5753 NULL, 0, 0},
5754 {"LIBOMP_USE_HIDDEN_HELPER_TASK", __kmp_stg_parse_use_hidden_helper,
5755 __kmp_stg_print_use_hidden_helper, NULL, 0, 0},
5756 {"LIBOMP_NUM_HIDDEN_HELPER_THREADS",
5757 __kmp_stg_parse_num_hidden_helper_threads,
5758 __kmp_stg_print_num_hidden_helper_threads, NULL, 0, 0},
5759#if OMPX_TASKGRAPH
5760 {"KMP_MAX_TDGS", __kmp_stg_parse_max_tdgs, __kmp_std_print_max_tdgs, NULL,
5761 0, 0},
5762 {"KMP_TDG_DOT", __kmp_stg_parse_tdg_dot, __kmp_stg_print_tdg_dot, NULL, 0, 0},
5763#endif
5764
5765#if OMPT_SUPPORT
5766 {"OMP_TOOL", __kmp_stg_parse_omp_tool, __kmp_stg_print_omp_tool, NULL, 0,
5767 0},
5768 {"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries,
5769 __kmp_stg_print_omp_tool_libraries, NULL, 0, 0},
5770 {"OMP_TOOL_VERBOSE_INIT", __kmp_stg_parse_omp_tool_verbose_init,
5771 __kmp_stg_print_omp_tool_verbose_init, NULL, 0, 0},
5772#endif
5773
5774#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
5775 {"KMP_USER_LEVEL_MWAIT", __kmp_stg_parse_user_level_mwait,
5776 __kmp_stg_print_user_level_mwait, NULL, 0, 0},
5777 {"KMP_MWAIT_HINTS", __kmp_stg_parse_mwait_hints,
5778 __kmp_stg_print_mwait_hints, NULL, 0, 0},
5779#endif
5780
5781#if KMP_HAVE_UMWAIT
5782 {"KMP_TPAUSE", __kmp_stg_parse_tpause, __kmp_stg_print_tpause, NULL, 0, 0},
5783#endif
5784 {"", NULL, NULL, NULL, 0, 0}}; // settings
5785
5786static int const __kmp_stg_count =
5787 sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
5788
5789static inline kmp_setting_t *__kmp_stg_find(char const *name) {
5790
5791 int i;
5792 if (name != NULL) {
5793 for (i = 0; i < __kmp_stg_count; ++i) {
5794 if (strcmp(__kmp_stg_table[i].name, name) == 0) {
5795 return &__kmp_stg_table[i];
5796 }
5797 }
5798 }
5799 return NULL;
5800
5801} // __kmp_stg_find
5802
5803static int __kmp_stg_cmp(void const *_a, void const *_b) {
5804 const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
5805 const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);
5806
5807 // Process KMP_AFFINITY last.
5808 // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
5809 if (strcmp(a->name, "KMP_AFFINITY") == 0) {
5810 if (strcmp(b->name, "KMP_AFFINITY") == 0) {
5811 return 0;
5812 }
5813 return 1;
5814 } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
5815 return -1;
5816 }
5817 return strcmp(a->name, b->name);
5818} // __kmp_stg_cmp
5819
5820static void __kmp_stg_init(void) {
5821
5822 static int initialized = 0;
5823
5824 if (!initialized) {
5825
5826 // Sort table.
5827 qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
5828 __kmp_stg_cmp);
5829
5830 { // Initialize *_STACKSIZE data.
5831 kmp_setting_t *kmp_stacksize =
5832 __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
5833#ifdef KMP_GOMP_COMPAT
5834 kmp_setting_t *gomp_stacksize =
5835 __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
5836#endif
5837 kmp_setting_t *omp_stacksize =
5838 __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
5839
5840 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5841 // !!! Compiler does not understand rivals is used and optimizes out
5842 // assignments
5843 // !!! rivals[ i ++ ] = ...;
5844 static kmp_setting_t *volatile rivals[4];
5845 static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
5846#ifdef KMP_GOMP_COMPAT
5847 static kmp_stg_ss_data_t gomp_data = {1024,
5848 CCAST(kmp_setting_t **, rivals)};
5849#endif
5850 static kmp_stg_ss_data_t omp_data = {1024,
5851 CCAST(kmp_setting_t **, rivals)};
5852 int i = 0;
5853
5854 rivals[i++] = kmp_stacksize;
5855#ifdef KMP_GOMP_COMPAT
5856 if (gomp_stacksize != NULL) {
5857 rivals[i++] = gomp_stacksize;
5858 }
5859#endif
5860 rivals[i++] = omp_stacksize;
5861 rivals[i++] = NULL;
5862
5863 kmp_stacksize->data = &kmp_data;
5864#ifdef KMP_GOMP_COMPAT
5865 if (gomp_stacksize != NULL) {
5866 gomp_stacksize->data = &gomp_data;
5867 }
5868#endif
5869 omp_stacksize->data = &omp_data;
5870 }
5871
5872 { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
5873 kmp_setting_t *kmp_library =
5874 __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
5875 kmp_setting_t *omp_wait_policy =
5876 __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
5877
5878 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5879 static kmp_setting_t *volatile rivals[3];
5880 static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
5881 static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
5882 int i = 0;
5883
5884 rivals[i++] = kmp_library;
5885 if (omp_wait_policy != NULL) {
5886 rivals[i++] = omp_wait_policy;
5887 }
5888 rivals[i++] = NULL;
5889
5890 kmp_library->data = &kmp_data;
5891 if (omp_wait_policy != NULL) {
5892 omp_wait_policy->data = &omp_data;
5893 }
5894 }
5895
5896 { // Initialize KMP_DEVICE_THREAD_LIMIT and KMP_ALL_THREADS
5897 kmp_setting_t *kmp_device_thread_limit =
5898 __kmp_stg_find("KMP_DEVICE_THREAD_LIMIT"); // 1st priority.
5899 kmp_setting_t *kmp_all_threads =
5900 __kmp_stg_find("KMP_ALL_THREADS"); // 2nd priority.
5901
5902 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5903 static kmp_setting_t *volatile rivals[3];
5904 int i = 0;
5905
5906 rivals[i++] = kmp_device_thread_limit;
5907 rivals[i++] = kmp_all_threads;
5908 rivals[i++] = NULL;
5909
5910 kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
5911 kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
5912 }
5913
5914 { // Initialize KMP_HW_SUBSET and KMP_PLACE_THREADS
5915 // 1st priority
5916 kmp_setting_t *kmp_hw_subset = __kmp_stg_find("KMP_HW_SUBSET");
5917 // 2nd priority
5918 kmp_setting_t *kmp_place_threads = __kmp_stg_find("KMP_PLACE_THREADS");
5919
5920 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5921 static kmp_setting_t *volatile rivals[3];
5922 int i = 0;
5923
5924 rivals[i++] = kmp_hw_subset;
5925 rivals[i++] = kmp_place_threads;
5926 rivals[i++] = NULL;
5927
5928 kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
5929 kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
5930 }
5931
5932#if KMP_AFFINITY_SUPPORTED
5933 { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
5934 kmp_setting_t *kmp_affinity =
5935 __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
5936 KMP_DEBUG_ASSERT(kmp_affinity != NULL);
5937
5938#ifdef KMP_GOMP_COMPAT
5939 kmp_setting_t *gomp_cpu_affinity =
5940 __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
5941 KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
5942#endif
5943
5944 kmp_setting_t *omp_proc_bind =
5945 __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
5946 KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
5947
5948 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5949 static kmp_setting_t *volatile rivals[4];
5950 int i = 0;
5951
5952 rivals[i++] = kmp_affinity;
5953
5954#ifdef KMP_GOMP_COMPAT
5955 rivals[i++] = gomp_cpu_affinity;
5956 gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
5957#endif
5958
5959 rivals[i++] = omp_proc_bind;
5960 omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
5961 rivals[i++] = NULL;
5962
5963 static kmp_setting_t *volatile places_rivals[4];
5964 i = 0;
5965
5966 kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
5967 KMP_DEBUG_ASSERT(omp_places != NULL);
5968
5969 places_rivals[i++] = kmp_affinity;
5970#ifdef KMP_GOMP_COMPAT
5971 places_rivals[i++] = gomp_cpu_affinity;
5972#endif
5973 places_rivals[i++] = omp_places;
5974 omp_places->data = CCAST(kmp_setting_t **, places_rivals);
5975 places_rivals[i++] = NULL;
5976 }
5977#else
5978// KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
5979// OMP_PLACES not supported yet.
5980#endif // KMP_AFFINITY_SUPPORTED
5981
5982 { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
5983 kmp_setting_t *kmp_force_red =
5984 __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
5985 kmp_setting_t *kmp_determ_red =
5986 __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
5987
5988 // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
5989 static kmp_setting_t *volatile rivals[3];
5990 static kmp_stg_fr_data_t force_data = {1,
5991 CCAST(kmp_setting_t **, rivals)};
5992 static kmp_stg_fr_data_t determ_data = {0,
5993 CCAST(kmp_setting_t **, rivals)};
5994 int i = 0;
5995
5996 rivals[i++] = kmp_force_red;
5997 if (kmp_determ_red != NULL) {
5998 rivals[i++] = kmp_determ_red;
5999 }
6000 rivals[i++] = NULL;
6001
6002 kmp_force_red->data = &force_data;
6003 if (kmp_determ_red != NULL) {
6004 kmp_determ_red->data = &determ_data;
6005 }
6006 }
6007
6008 initialized = 1;
6009 }
6010
6011 // Reset flags.
6012 int i;
6013 for (i = 0; i < __kmp_stg_count; ++i) {
6014 __kmp_stg_table[i].set = 0;
6015 }
6016
6017} // __kmp_stg_init
6018
6019static void __kmp_stg_parse(char const *name, char const *value) {
6020 // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
6021 // really nameless, they are presented in environment block as
6022 // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
6023 if (name[0] == 0) {
6024 return;
6025 }
6026
6027 if (value != NULL) {
6028 kmp_setting_t *setting = __kmp_stg_find(name);
6029 if (setting != NULL) {
6030 setting->parse(name, value, setting->data);
6031 setting->defined = 1;
6032 }
6033 }
6034
6035} // __kmp_stg_parse
6036
6037static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
6038 char const *name, // Name of variable.
6039 char const *value, // Value of the variable.
6040 kmp_setting_t **rivals // List of rival settings (must include current one).
6041) {
6042
6043 if (rivals == NULL) {
6044 return 0;
6045 }
6046
6047 // Loop thru higher priority settings (listed before current).
6048 int i = 0;
6049 for (; strcmp(rivals[i]->name, name) != 0; i++) {
6050 KMP_DEBUG_ASSERT(rivals[i] != NULL);
6051
6052#if KMP_AFFINITY_SUPPORTED
6053 if (rivals[i] == __kmp_affinity_notype) {
6054 // If KMP_AFFINITY is specified without a type name,
6055 // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
6056 continue;
6057 }
6058#endif
6059
6060 if (rivals[i]->set) {
6061 KMP_WARNING(StgIgnored, name, rivals[i]->name);
6062 return 1;
6063 }
6064 }
6065
6066 ++i; // Skip current setting.
6067 return 0;
6068
6069} // __kmp_stg_check_rivals
6070
6071static int __kmp_env_toPrint(char const *name, int flag) {
6072 int rc = 0;
6073 kmp_setting_t *setting = __kmp_stg_find(name);
6074 if (setting != NULL) {
6075 rc = setting->defined;
6076 if (flag >= 0) {
6077 setting->defined = flag;
6078 }
6079 }
6080 return rc;
6081}
6082
6083#if defined(KMP_DEBUG) && KMP_AFFINITY_SUPPORTED
6084static void __kmp_print_affinity_settings(const kmp_affinity_t *affinity) {
6085 K_DIAG(1, ("%s:\n", affinity->env_var));
6086 K_DIAG(1, (" type : %d\n", affinity->type));
6087 K_DIAG(1, (" compact : %d\n", affinity->compact));
6088 K_DIAG(1, (" offset : %d\n", affinity->offset));
6089 K_DIAG(1, (" verbose : %u\n", affinity->flags.verbose));
6090 K_DIAG(1, (" warnings : %u\n", affinity->flags.warnings));
6091 K_DIAG(1, (" respect : %u\n", affinity->flags.respect));
6092 K_DIAG(1, (" reset : %u\n", affinity->flags.reset));
6093 K_DIAG(1, (" dups : %u\n", affinity->flags.dups));
6094 K_DIAG(1, (" gran : %d\n", (int)affinity->gran));
6095 KMP_DEBUG_ASSERT(affinity->type != affinity_default);
6096}
6097#endif
6098
6099static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
6100
6101 char const *value;
6102
6103 /* OMP_NUM_THREADS */
6104 value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
6105 if (value) {
6106 ompc_set_num_threads(__kmp_dflt_team_nth);
6107 }
6108
6109 /* KMP_BLOCKTIME */
6110 value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
6111 if (value) {
6112 int gtid, tid;
6113 kmp_info_t *thread;
6114
6115 gtid = __kmp_entry_gtid();
6116 tid = __kmp_tid_from_gtid(gtid);
6117 thread = __kmp_thread_from_gtid(gtid);
6118 __kmp_aux_set_blocktime(__kmp_dflt_blocktime, thread, tid);
6119 }
6120
6121 /* OMP_NESTED */
6122 value = __kmp_env_blk_var(block, "OMP_NESTED");
6123 if (value) {
6124 ompc_set_nested(__kmp_dflt_max_active_levels > 1);
6125 }
6126
6127 /* OMP_DYNAMIC */
6128 value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
6129 if (value) {
6130 ompc_set_dynamic(__kmp_global.g.g_dynamic);
6131 }
6132}
6133
6134void __kmp_env_initialize(char const *string) {
6135
6136 kmp_env_blk_t block;
6137 int i;
6138
6139 __kmp_stg_init();
6140
6141 // Hack!!!
6142 if (string == NULL) {
6143 // __kmp_max_nth = __kmp_sys_max_nth;
6144 __kmp_threads_capacity =
6145 __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
6146 }
6147 __kmp_env_blk_init(&block, string);
6148
6149 // update the set flag on all entries that have an env var
6150 for (i = 0; i < block.count; ++i) {
6151 if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
6152 continue;
6153 }
6154 if (block.vars[i].value == NULL) {
6155 continue;
6156 }
6157 kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
6158 if (setting != NULL) {
6159 setting->set = 1;
6160 }
6161 }
6162
6163 // We need to know if blocktime was set when processing OMP_WAIT_POLICY
6164 blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
6165
6166 // Special case. If we parse environment, not a string, process KMP_WARNINGS
6167 // first.
6168 if (string == NULL) {
6169 char const *name = "KMP_WARNINGS";
6170 char const *value = __kmp_env_blk_var(&block, name);
6171 __kmp_stg_parse(name, value);
6172 }
6173
6174#if KMP_AFFINITY_SUPPORTED
6175 // Special case. KMP_AFFINITY is not a rival to other affinity env vars
6176 // if no affinity type is specified. We want to allow
6177 // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
6178 // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
6179 // affinity mechanism.
6180 __kmp_affinity_notype = NULL;
6181 char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
6182 if (aff_str != NULL) {
6183 // Check if the KMP_AFFINITY type is specified in the string.
6184 // We just search the string for "compact", "scatter", etc.
6185 // without really parsing the string. The syntax of the
6186 // KMP_AFFINITY env var is such that none of the affinity
6187 // type names can appear anywhere other that the type
6188 // specifier, even as substrings.
6189 //
6190 // I can't find a case-insensitive version of strstr on Windows* OS.
6191 // Use the case-sensitive version for now. AIX does the same.
6192
6193#if KMP_OS_WINDOWS || KMP_OS_AIX
6194#define FIND strstr
6195#else
6196#define FIND strcasestr
6197#endif
6198
6199 if ((FIND(aff_str, "none") == NULL) &&
6200 (FIND(aff_str, "physical") == NULL) &&
6201 (FIND(aff_str, "logical") == NULL) &&
6202 (FIND(aff_str, "compact") == NULL) &&
6203 (FIND(aff_str, "scatter") == NULL) &&
6204 (FIND(aff_str, "explicit") == NULL) &&
6205 (FIND(aff_str, "balanced") == NULL) &&
6206 (FIND(aff_str, "disabled") == NULL)) {
6207 __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
6208 } else {
6209 // A new affinity type is specified.
6210 // Reset the affinity flags to their default values,
6211 // in case this is called from kmp_set_defaults().
6212 __kmp_affinity.type = affinity_default;
6213 __kmp_affinity.gran = KMP_HW_UNKNOWN;
6214 __kmp_affinity_top_method = affinity_top_method_default;
6215 __kmp_affinity.flags.respect = affinity_respect_mask_default;
6216 }
6217#undef FIND
6218
6219 // Also reset the affinity flags if OMP_PROC_BIND is specified.
6220 aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
6221 if (aff_str != NULL) {
6222 __kmp_affinity.type = affinity_default;
6223 __kmp_affinity.gran = KMP_HW_UNKNOWN;
6224 __kmp_affinity_top_method = affinity_top_method_default;
6225 __kmp_affinity.flags.respect = affinity_respect_mask_default;
6226 }
6227 }
6228
6229#endif /* KMP_AFFINITY_SUPPORTED */
6230
6231 // Set up the nested proc bind type vector.
6232 if (__kmp_nested_proc_bind.bind_types == NULL) {
6233 __kmp_nested_proc_bind.bind_types =
6234 (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
6235 if (__kmp_nested_proc_bind.bind_types == NULL) {
6236 KMP_FATAL(MemoryAllocFailed);
6237 }
6238 __kmp_nested_proc_bind.size = 1;
6239 __kmp_nested_proc_bind.used = 1;
6240#if KMP_AFFINITY_SUPPORTED
6241 __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
6242#else
6243 // default proc bind is false if affinity not supported
6244 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6245#endif
6246 }
6247
6248 // Set up the affinity format ICV
6249 // Grab the default affinity format string from the message catalog
6250 kmp_msg_t m =
6251 __kmp_msg_format(kmp_i18n_msg_AffFormatDefault, "%P", "%i", "%n", "%A");
6252 KMP_DEBUG_ASSERT(KMP_STRLEN(m.str) < KMP_AFFINITY_FORMAT_SIZE);
6253
6254 if (__kmp_affinity_format == NULL) {
6255 __kmp_affinity_format =
6256 (char *)KMP_INTERNAL_MALLOC(sizeof(char) * KMP_AFFINITY_FORMAT_SIZE);
6257 }
6258 KMP_STRCPY_S(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, m.str);
6259 __kmp_str_free(&m.str);
6260
6261 // Now process all of the settings.
6262 for (i = 0; i < block.count; ++i) {
6263 __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
6264 }
6265
6266 // If user locks have been allocated yet, don't reset the lock vptr table.
6267 if (!__kmp_init_user_locks) {
6268 if (__kmp_user_lock_kind == lk_default) {
6269 __kmp_user_lock_kind = lk_queuing;
6270 }
6271#if KMP_USE_DYNAMIC_LOCK
6272 __kmp_init_dynamic_user_locks();
6273#else
6274 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
6275#endif
6276 } else {
6277 KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
6278 KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
6279// Binds lock functions again to follow the transition between different
6280// KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
6281// as we do not allow lock kind changes after making a call to any
6282// user lock functions (true).
6283#if KMP_USE_DYNAMIC_LOCK
6284 __kmp_init_dynamic_user_locks();
6285#else
6286 __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
6287#endif
6288 }
6289
6290#if KMP_AFFINITY_SUPPORTED
6291
6292 if (!TCR_4(__kmp_init_middle)) {
6293#if KMP_USE_HWLOC
6294 // Force using hwloc when either tiles or numa nodes requested within
6295 // KMP_HW_SUBSET or granularity setting and no other topology method
6296 // is requested
6297 if (__kmp_hw_subset &&
6298 __kmp_affinity_top_method == affinity_top_method_default)
6299 if (__kmp_hw_subset->specified(KMP_HW_NUMA) ||
6300 __kmp_hw_subset->specified(KMP_HW_TILE) ||
6301 __kmp_affinity.gran == KMP_HW_TILE ||
6302 __kmp_affinity.gran == KMP_HW_NUMA)
6303 __kmp_affinity_top_method = affinity_top_method_hwloc;
6304 // Force using hwloc when tiles or numa nodes requested for OMP_PLACES
6305 if (__kmp_affinity.gran == KMP_HW_NUMA ||
6306 __kmp_affinity.gran == KMP_HW_TILE)
6307 __kmp_affinity_top_method = affinity_top_method_hwloc;
6308#endif
6309 // Determine if the machine/OS is actually capable of supporting
6310 // affinity.
6311 const char *var = "KMP_AFFINITY";
6312 KMPAffinity::pick_api();
6313#if KMP_USE_HWLOC
6314 // If Hwloc topology discovery was requested but affinity was also disabled,
6315 // then tell user that Hwloc request is being ignored and use default
6316 // topology discovery method.
6317 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
6318 __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
6319 KMP_WARNING(AffIgnoringHwloc, var);
6320 __kmp_affinity_top_method = affinity_top_method_all;
6321 }
6322#endif
6323 if (__kmp_affinity.type == affinity_disabled) {
6324 KMP_AFFINITY_DISABLE();
6325 } else if (!KMP_AFFINITY_CAPABLE()) {
6326 __kmp_affinity_dispatch->determine_capable(var);
6327 if (!KMP_AFFINITY_CAPABLE()) {
6328 if (__kmp_affinity.flags.verbose ||
6329 (__kmp_affinity.flags.warnings &&
6330 (__kmp_affinity.type != affinity_default) &&
6331 (__kmp_affinity.type != affinity_none) &&
6332 (__kmp_affinity.type != affinity_disabled))) {
6333 KMP_WARNING(AffNotSupported, var);
6334 }
6335 __kmp_affinity.type = affinity_disabled;
6336 __kmp_affinity.flags.respect = FALSE;
6337 __kmp_affinity.gran = KMP_HW_THREAD;
6338 }
6339 }
6340
6341 if (__kmp_affinity.type == affinity_disabled) {
6342 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6343 } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
6344 // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
6345 __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
6346 }
6347
6348 if (KMP_AFFINITY_CAPABLE()) {
6349
6350#if KMP_GROUP_AFFINITY
6351 // This checks to see if the initial affinity mask is equal
6352 // to a single windows processor group. If it is, then we do
6353 // not respect the initial affinity mask and instead, use the
6354 // entire machine.
6355 bool exactly_one_group = false;
6356 if (__kmp_num_proc_groups > 1) {
6357 int group;
6358 bool within_one_group;
6359 // Get the initial affinity mask and determine if it is
6360 // contained within a single group.
6361 kmp_affin_mask_t *init_mask;
6362 KMP_CPU_ALLOC(init_mask);
6363 __kmp_get_system_affinity(init_mask, TRUE);
6364 group = __kmp_get_proc_group(init_mask);
6365 within_one_group = (group >= 0);
6366 // If the initial affinity is within a single group,
6367 // then determine if it is equal to that single group.
6368 if (within_one_group) {
6369 DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
6370 DWORD num_bits_in_mask = 0;
6371 for (int bit = init_mask->begin(); bit != init_mask->end();
6372 bit = init_mask->next(bit))
6373 num_bits_in_mask++;
6374 exactly_one_group = (num_bits_in_group == num_bits_in_mask);
6375 }
6376 KMP_CPU_FREE(init_mask);
6377 }
6378
6379 // Handle the Win 64 group affinity stuff if there are multiple
6380 // processor groups, or if the user requested it, and OMP 4.0
6381 // affinity is not in effect.
6382 if (__kmp_num_proc_groups > 1 &&
6383 __kmp_affinity.type == affinity_default &&
6384 __kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
6385 // Do not respect the initial processor affinity mask if it is assigned
6386 // exactly one Windows Processor Group since this is interpreted as the
6387 // default OS assignment. Not respecting the mask allows the runtime to
6388 // use all the logical processors in all groups.
6389 if (__kmp_affinity.flags.respect == affinity_respect_mask_default &&
6390 exactly_one_group) {
6391 __kmp_affinity.flags.respect = FALSE;
6392 }
6393 // Use compact affinity with anticipation of pinning to at least the
6394 // group granularity since threads can only be bound to one group.
6395 if (__kmp_affinity.type == affinity_default) {
6396 __kmp_affinity.type = affinity_compact;
6397 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6398 }
6399 if (__kmp_hh_affinity.type == affinity_default)
6400 __kmp_hh_affinity.type = affinity_compact;
6401 if (__kmp_affinity_top_method == affinity_top_method_default)
6402 __kmp_affinity_top_method = affinity_top_method_all;
6403 if (__kmp_affinity.gran == KMP_HW_UNKNOWN)
6404 __kmp_affinity.gran = KMP_HW_PROC_GROUP;
6405 if (__kmp_hh_affinity.gran == KMP_HW_UNKNOWN)
6406 __kmp_hh_affinity.gran = KMP_HW_PROC_GROUP;
6407 } else
6408
6409#endif /* KMP_GROUP_AFFINITY */
6410
6411 {
6412 if (__kmp_affinity.flags.respect == affinity_respect_mask_default) {
6413#if KMP_GROUP_AFFINITY
6414 if (__kmp_num_proc_groups > 1 && exactly_one_group) {
6415 __kmp_affinity.flags.respect = FALSE;
6416 } else
6417#endif /* KMP_GROUP_AFFINITY */
6418 {
6419 __kmp_affinity.flags.respect = TRUE;
6420 }
6421 }
6422 if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
6423 (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
6424 if (__kmp_affinity.type == affinity_default) {
6425 __kmp_affinity.type = affinity_compact;
6426 __kmp_affinity.flags.dups = FALSE;
6427 }
6428 } else if (__kmp_affinity.type == affinity_default) {
6429#if KMP_MIC_SUPPORTED
6430 if (__kmp_mic_type != non_mic) {
6431 __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
6432 } else
6433#endif
6434 {
6435 __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
6436 }
6437#if KMP_MIC_SUPPORTED
6438 if (__kmp_mic_type != non_mic) {
6439 __kmp_affinity.type = affinity_scatter;
6440 } else
6441#endif
6442 {
6443 __kmp_affinity.type = affinity_none;
6444 }
6445 }
6446 if (__kmp_hh_affinity.type == affinity_default)
6447 __kmp_hh_affinity.type = affinity_none;
6448 if ((__kmp_affinity.gran == KMP_HW_UNKNOWN) &&
6449 (__kmp_affinity.gran_levels < 0)) {
6450#if KMP_MIC_SUPPORTED
6451 if (__kmp_mic_type != non_mic) {
6452 __kmp_affinity.gran = KMP_HW_THREAD;
6453 } else
6454#endif
6455 {
6456 __kmp_affinity.gran = KMP_HW_CORE;
6457 }
6458 }
6459 if ((__kmp_hh_affinity.gran == KMP_HW_UNKNOWN) &&
6460 (__kmp_hh_affinity.gran_levels < 0)) {
6461#if KMP_MIC_SUPPORTED
6462 if (__kmp_mic_type != non_mic) {
6463 __kmp_hh_affinity.gran = KMP_HW_THREAD;
6464 } else
6465#endif
6466 {
6467 __kmp_hh_affinity.gran = KMP_HW_CORE;
6468 }
6469 }
6470 if (__kmp_affinity_top_method == affinity_top_method_default) {
6471 __kmp_affinity_top_method = affinity_top_method_all;
6472 }
6473 }
6474 } else {
6475 // If affinity is disabled, then still need to assign topology method
6476 // to attempt machine detection and affinity types
6477 if (__kmp_affinity_top_method == affinity_top_method_default)
6478 __kmp_affinity_top_method = affinity_top_method_all;
6479 if (__kmp_affinity.type == affinity_default)
6480 __kmp_affinity.type = affinity_disabled;
6481 if (__kmp_hh_affinity.type == affinity_default)
6482 __kmp_hh_affinity.type = affinity_disabled;
6483 }
6484
6485#ifdef KMP_DEBUG
6486 for (const kmp_affinity_t *affinity : __kmp_affinities)
6487 __kmp_print_affinity_settings(affinity);
6488 KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
6489 K_DIAG(1, ("__kmp_nested_proc_bind.bind_types[0] == %d\n",
6490 __kmp_nested_proc_bind.bind_types[0]));
6491#endif
6492 }
6493
6494#endif /* KMP_AFFINITY_SUPPORTED */
6495
6496 // Post-initialization step: some env. vars need their value's further
6497 // processing
6498 if (string != NULL) { // kmp_set_defaults() was called
6499 __kmp_aux_env_initialize(&block);
6500 }
6501
6502 __kmp_env_blk_free(&block);
6503
6504 KMP_MB();
6505
6506} // __kmp_env_initialize
6507
6508void __kmp_env_print() {
6509
6510 kmp_env_blk_t block;
6511 int i;
6512 kmp_str_buf_t buffer;
6513
6514 __kmp_stg_init();
6515 __kmp_str_buf_init(&buffer);
6516
6517 __kmp_env_blk_init(&block, NULL);
6518 __kmp_env_blk_sort(&block);
6519
6520 // Print real environment values.
6521 __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
6522 for (i = 0; i < block.count; ++i) {
6523 char const *name = block.vars[i].name;
6524 char const *value = block.vars[i].value;
6525 if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
6526 strncmp(name, "OMP_", 4) == 0
6527#ifdef KMP_GOMP_COMPAT
6528 || strncmp(name, "GOMP_", 5) == 0
6529#endif // KMP_GOMP_COMPAT
6530 ) {
6531 __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
6532 }
6533 }
6534 __kmp_str_buf_print(&buffer, "\n");
6535
6536 // Print internal (effective) settings.
6537 __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
6538 for (int i = 0; i < __kmp_stg_count; ++i) {
6539 if (__kmp_stg_table[i].print != NULL) {
6540 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6541 __kmp_stg_table[i].data);
6542 }
6543 }
6544
6545 __kmp_printf("%s", buffer.str);
6546
6547 __kmp_env_blk_free(&block);
6548 __kmp_str_buf_free(&buffer);
6549
6550 __kmp_printf("\n");
6551
6552} // __kmp_env_print
6553
6554void __kmp_env_print_2() {
6555 __kmp_display_env_impl(__kmp_display_env, __kmp_display_env_verbose);
6556} // __kmp_env_print_2
6557
6558void __kmp_display_env_impl(int display_env, int display_env_verbose) {
6559 kmp_env_blk_t block;
6560 kmp_str_buf_t buffer;
6561
6562 __kmp_env_format = 1;
6563
6564 __kmp_stg_init();
6565 __kmp_str_buf_init(&buffer);
6566
6567 __kmp_env_blk_init(&block, NULL);
6568 __kmp_env_blk_sort(&block);
6569
6570 __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
6571 __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
6572
6573 for (int i = 0; i < __kmp_stg_count; ++i) {
6574 if (__kmp_stg_table[i].print != NULL &&
6575 ((display_env && strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
6576 display_env_verbose)) {
6577 __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
6578 __kmp_stg_table[i].data);
6579 }
6580 }
6581
6582 __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
6583 __kmp_str_buf_print(&buffer, "\n");
6584
6585 __kmp_printf("%s", buffer.str);
6586
6587 __kmp_env_blk_free(&block);
6588 __kmp_str_buf_free(&buffer);
6589
6590 __kmp_printf("\n");
6591}
6592
6593#if OMPD_SUPPORT
6594// Dump environment variables for OMPD
6595void __kmp_env_dump() {
6596
6597 kmp_env_blk_t block;
6598 kmp_str_buf_t buffer, env, notdefined;
6599
6600 __kmp_stg_init();
6601 __kmp_str_buf_init(&buffer);
6602 __kmp_str_buf_init(&env);
6603 __kmp_str_buf_init(&notdefined);
6604
6605 __kmp_env_blk_init(&block, NULL);
6606 __kmp_env_blk_sort(&block);
6607
6608 __kmp_str_buf_print(&notdefined, ": %s", KMP_I18N_STR(NotDefined));
6609
6610 for (int i = 0; i < __kmp_stg_count; ++i) {
6611 if (__kmp_stg_table[i].print == NULL)
6612 continue;
6613 __kmp_str_buf_clear(&env);
6614 __kmp_stg_table[i].print(&env, __kmp_stg_table[i].name,
6615 __kmp_stg_table[i].data);
6616 if (env.used < 4) // valid definition must have indents (3) and a new line
6617 continue;
6618 if (strstr(env.str, notdefined.str))
6619 // normalize the string
6620 __kmp_str_buf_print(&buffer, "%s=undefined\n", __kmp_stg_table[i].name);
6621 else
6622 __kmp_str_buf_cat(&buffer, env.str + 3, env.used - 3);
6623 }
6624
6625 ompd_env_block = (char *)__kmp_allocate(buffer.used + 1);
6626 KMP_MEMCPY(ompd_env_block, buffer.str, buffer.used + 1);
6627 ompd_env_block_size = (ompd_size_t)KMP_STRLEN(ompd_env_block);
6628
6629 __kmp_env_blk_free(&block);
6630 __kmp_str_buf_free(&buffer);
6631 __kmp_str_buf_free(&env);
6632 __kmp_str_buf_free(&notdefined);
6633}
6634#endif // OMPD_SUPPORT
6635
6636// end of file
sched_type
Definition kmp.h:369
@ kmp_sch_auto
Definition kmp.h:376
@ kmp_sch_static
Definition kmp.h:372
@ kmp_sch_modifier_monotonic
Definition kmp.h:457
@ kmp_sch_default
Definition kmp.h:477
@ kmp_sch_modifier_nonmonotonic
Definition kmp.h:459
@ kmp_sch_guided_chunked
Definition kmp.h:374