1 /* Copyright (C) 2005-2018 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU Offloading and Multi Processing Library
7 Libgomp is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 /* This file defines the OpenMP internal control variables and arranges
27 for them to be initialized from environment variables at startup. */
31 #include "gomp-constants.h"
33 #ifndef LIBGOMP_OFFLOADED_ONLY
34 #include "libgomp_f.h"
39 #ifdef HAVE_INTTYPES_H
40 # include <inttypes.h> /* For PRIu64. */
42 #ifdef STRING_WITH_STRINGS
49 # ifdef HAVE_STRINGS_H
55 #include "thread-stacksize.h"
58 # define strtoull(ptr, eptr, base) strtoul (ptr, eptr, base)
60 #endif /* LIBGOMP_OFFLOADED_ONLY */
62 #include "secure_getenv.h"
64 struct gomp_task_icv gomp_global_icv
= {
66 .thread_limit_var
= UINT_MAX
,
67 .run_sched_var
= GFS_DYNAMIC
,
68 .run_sched_chunk_size
= 1,
69 .default_device_var
= 0,
72 .bind_var
= omp_proc_bind_false
,
76 unsigned long gomp_max_active_levels_var
= INT_MAX
;
77 bool gomp_cancel_var
= false;
78 int gomp_max_task_priority_var
= 0;
79 #ifndef HAVE_SYNC_BUILTINS
80 gomp_mutex_t gomp_managed_threads_lock
;
82 unsigned long gomp_available_cpus
= 1, gomp_managed_threads
= 1;
83 unsigned long long gomp_spin_count_var
, gomp_throttled_spin_count_var
;
84 unsigned long *gomp_nthreads_var_list
, gomp_nthreads_var_list_len
;
85 char *gomp_bind_var_list
;
86 unsigned long gomp_bind_var_list_len
;
87 void **gomp_places_list
;
88 unsigned long gomp_places_list_len
;
90 unsigned int gomp_num_teams_var
;
91 char *goacc_device_type
;
94 #ifndef LIBGOMP_OFFLOADED_ONLY
96 /* Parse the OMP_SCHEDULE environment variable. */
104 env
= getenv ("OMP_SCHEDULE");
108 while (isspace ((unsigned char) *env
))
110 if (strncasecmp (env
, "static", 6) == 0)
112 gomp_global_icv
.run_sched_var
= GFS_STATIC
;
115 else if (strncasecmp (env
, "dynamic", 7) == 0)
117 gomp_global_icv
.run_sched_var
= GFS_DYNAMIC
;
120 else if (strncasecmp (env
, "guided", 6) == 0)
122 gomp_global_icv
.run_sched_var
= GFS_GUIDED
;
125 else if (strncasecmp (env
, "auto", 4) == 0)
127 gomp_global_icv
.run_sched_var
= GFS_AUTO
;
133 while (isspace ((unsigned char) *env
))
137 gomp_global_icv
.run_sched_chunk_size
138 = gomp_global_icv
.run_sched_var
!= GFS_STATIC
;
143 while (isspace ((unsigned char) *env
))
149 value
= strtoul (env
, &end
, 10);
153 while (isspace ((unsigned char) *end
))
158 if ((int)value
!= value
)
161 if (value
== 0 && gomp_global_icv
.run_sched_var
!= GFS_STATIC
)
163 gomp_global_icv
.run_sched_chunk_size
= value
;
167 gomp_error ("Unknown value for environment variable OMP_SCHEDULE");
171 gomp_error ("Invalid value for chunk size in "
172 "environment variable OMP_SCHEDULE");
176 /* Parse an unsigned long environment variable. Return true if one was
177 present and it was successfully parsed. If SECURE, use secure_getenv to the
178 environment variable. */
181 parse_unsigned_long_1 (const char *name
, unsigned long *pvalue
, bool allow_zero
,
187 env
= (secure
? secure_getenv (name
) : getenv (name
));
191 while (isspace ((unsigned char) *env
))
197 value
= strtoul (env
, &end
, 10);
198 if (errno
|| (long) value
<= 0 - allow_zero
)
201 while (isspace ((unsigned char) *end
))
210 gomp_error ("Invalid value for environment variable %s", name
);
214 /* As parse_unsigned_long_1, but always use getenv. */
217 parse_unsigned_long (const char *name
, unsigned long *pvalue
, bool allow_zero
)
219 return parse_unsigned_long_1 (name
, pvalue
, allow_zero
, false);
222 /* Parse a positive int environment variable. Return true if one was
223 present and it was successfully parsed. If SECURE, use secure_getenv to the
224 environment variable. */
227 parse_int_1 (const char *name
, int *pvalue
, bool allow_zero
, bool secure
)
230 if (!parse_unsigned_long_1 (name
, &value
, allow_zero
, secure
))
234 gomp_error ("Invalid value for environment variable %s", name
);
237 *pvalue
= (int) value
;
241 /* As parse_int_1, but use getenv. */
244 parse_int (const char *name
, int *pvalue
, bool allow_zero
)
246 return parse_int_1 (name
, pvalue
, allow_zero
, false);
249 /* As parse_int_1, but use getenv_secure. */
252 parse_int_secure (const char *name
, int *pvalue
, bool allow_zero
)
254 return parse_int_1 (name
, pvalue
, allow_zero
, true);
257 /* Parse an unsigned long list environment variable. Return true if one was
258 present and it was successfully parsed. */
261 parse_unsigned_long_list (const char *name
, unsigned long *p1stvalue
,
262 unsigned long **pvalues
,
263 unsigned long *pnvalues
)
266 unsigned long value
, *values
= NULL
;
272 while (isspace ((unsigned char) *env
))
278 value
= strtoul (env
, &end
, 10);
279 if (errno
|| (long) value
<= 0)
282 while (isspace ((unsigned char) *end
))
288 unsigned long nvalues
= 0, nalloced
= 0;
293 if (nvalues
== nalloced
)
296 nalloced
= nalloced
? nalloced
* 2 : 16;
297 n
= realloc (values
, nalloced
* sizeof (unsigned long));
301 gomp_error ("Out of memory while trying to parse"
302 " environment variable %s", name
);
307 values
[nvalues
++] = value
;
310 while (isspace ((unsigned char) *env
))
316 value
= strtoul (env
, &end
, 10);
317 if (errno
|| (long) value
<= 0)
320 values
[nvalues
++] = value
;
321 while (isspace ((unsigned char) *end
))
329 *p1stvalue
= values
[0];
342 gomp_error ("Invalid value for environment variable %s", name
);
346 /* Parse environment variable set to a boolean or list of omp_proc_bind_t
347 enum values. Return true if one was present and it was successfully
351 parse_bind_var (const char *name
, char *p1stvalue
,
352 char **pvalues
, unsigned long *pnvalues
)
355 char value
= omp_proc_bind_false
, *values
= NULL
;
357 static struct proc_bind_kinds
361 omp_proc_bind_t kind
;
364 { "false", 5, omp_proc_bind_false
},
365 { "true", 4, omp_proc_bind_true
},
366 { "master", 6, omp_proc_bind_master
},
367 { "close", 5, omp_proc_bind_close
},
368 { "spread", 6, omp_proc_bind_spread
}
375 while (isspace ((unsigned char) *env
))
380 for (i
= 0; i
< 5; i
++)
381 if (strncasecmp (env
, kinds
[i
].name
, kinds
[i
].len
) == 0)
383 value
= kinds
[i
].kind
;
390 while (isspace ((unsigned char) *env
))
396 unsigned long nvalues
= 0, nalloced
= 0;
398 if (value
== omp_proc_bind_false
399 || value
== omp_proc_bind_true
)
405 if (nvalues
== nalloced
)
408 nalloced
= nalloced
? nalloced
* 2 : 16;
409 n
= realloc (values
, nalloced
);
413 gomp_error ("Out of memory while trying to parse"
414 " environment variable %s", name
);
419 values
[nvalues
++] = value
;
422 while (isspace ((unsigned char) *env
))
427 for (i
= 2; i
< 5; i
++)
428 if (strncasecmp (env
, kinds
[i
].name
, kinds
[i
].len
) == 0)
430 value
= kinds
[i
].kind
;
437 values
[nvalues
++] = value
;
438 while (isspace ((unsigned char) *env
))
446 *p1stvalue
= values
[0];
459 gomp_error ("Invalid value for environment variable %s", name
);
464 parse_one_place (char **envp
, bool *negatep
, unsigned long *lenp
,
467 char *env
= *envp
, *start
;
468 void *p
= gomp_places_list
? gomp_places_list
[gomp_places_list_len
] : NULL
;
469 unsigned long len
= 1;
472 bool any_negate
= false;
474 while (isspace ((unsigned char) *env
))
480 while (isspace ((unsigned char) *env
))
486 while (isspace ((unsigned char) *env
))
489 for (pass
= 0; pass
< (any_negate
? 2 : 1); pass
++)
494 unsigned long this_num
, this_len
= 1;
495 long this_stride
= 1;
496 bool this_negate
= (*env
== '!');
499 if (gomp_places_list
)
502 while (isspace ((unsigned char) *env
))
507 this_num
= strtoul (env
, &env
, 10);
510 while (isspace ((unsigned char) *env
))
515 while (isspace ((unsigned char) *env
))
518 this_len
= strtoul (env
, &env
, 10);
519 if (errno
|| this_len
== 0)
521 while (isspace ((unsigned char) *env
))
526 while (isspace ((unsigned char) *env
))
529 this_stride
= strtol (env
, &env
, 10);
532 while (isspace ((unsigned char) *env
))
536 if (this_negate
&& this_len
!= 1)
538 if (gomp_places_list
&& pass
== this_negate
)
542 if (!gomp_affinity_remove_cpu (p
, this_num
))
545 else if (!gomp_affinity_add_cpus (p
, this_num
, this_len
,
559 while (isspace ((unsigned char) *env
))
564 while (isspace ((unsigned char) *env
))
567 len
= strtoul (env
, &env
, 10);
568 if (errno
|| len
== 0 || len
>= 65536)
570 while (isspace ((unsigned char) *env
))
575 while (isspace ((unsigned char) *env
))
578 stride
= strtol (env
, &env
, 10);
581 while (isspace ((unsigned char) *env
))
585 if (*negatep
&& len
!= 1)
594 parse_places_var (const char *name
, bool ignore
)
596 char *env
= getenv (name
), *end
;
597 bool any_negate
= false;
599 unsigned long count
= 0;
603 while (isspace ((unsigned char) *env
))
608 if (strncasecmp (env
, "threads", 7) == 0)
613 else if (strncasecmp (env
, "cores", 5) == 0)
618 else if (strncasecmp (env
, "sockets", 7) == 0)
626 while (isspace ((unsigned char) *env
))
632 while (isspace ((unsigned char) *env
))
636 count
= strtoul (env
, &end
, 10);
640 while (isspace ((unsigned char) *env
))
645 while (isspace ((unsigned char) *env
))
654 return gomp_affinity_init_level (level
, count
, false);
664 if (!parse_one_place (&end
, &negate
, &len
, &stride
))
687 gomp_places_list_len
= 0;
688 gomp_places_list
= gomp_affinity_alloc (count
, false);
689 if (gomp_places_list
== NULL
)
697 gomp_affinity_init_place (gomp_places_list
[gomp_places_list_len
]);
698 if (!parse_one_place (&env
, &negate
, &len
, &stride
))
703 for (count
= 0; count
< gomp_places_list_len
; count
++)
704 if (gomp_affinity_same_place
705 (gomp_places_list
[count
],
706 gomp_places_list
[gomp_places_list_len
]))
708 if (count
== gomp_places_list_len
)
710 gomp_error ("Trying to remove a non-existing place from list "
714 p
= gomp_places_list
[count
];
715 memmove (&gomp_places_list
[count
],
716 &gomp_places_list
[count
+ 1],
717 (gomp_places_list_len
- count
- 1) * sizeof (void *));
718 --gomp_places_list_len
;
719 gomp_places_list
[gomp_places_list_len
] = p
;
722 ++gomp_places_list_len
;
725 for (count
= 0; count
< len
- 1; count
++)
726 if (!gomp_affinity_copy_place
727 (gomp_places_list
[gomp_places_list_len
+ count
+ 1],
728 gomp_places_list
[gomp_places_list_len
+ count
],
731 gomp_places_list_len
+= len
;
739 if (gomp_places_list_len
== 0)
741 gomp_error ("All places have been removed");
744 if (!gomp_affinity_finalize_place_list (false))
749 free (gomp_places_list
);
750 gomp_places_list
= NULL
;
751 gomp_places_list_len
= 0;
752 gomp_error ("Invalid value for environment variable %s", name
);
756 /* Parse the OMP_STACKSIZE environment varible. Return true if one was
757 present and it was successfully parsed. */
760 parse_stacksize (const char *name
, unsigned long *pvalue
)
763 unsigned long value
, shift
= 10;
769 while (isspace ((unsigned char) *env
))
775 value
= strtoul (env
, &end
, 10);
779 while (isspace ((unsigned char) *end
))
783 switch (tolower ((unsigned char) *end
))
800 while (isspace ((unsigned char) *end
))
806 if (((value
<< shift
) >> shift
) != value
)
809 *pvalue
= value
<< shift
;
813 gomp_error ("Invalid value for environment variable %s", name
);
817 /* Parse the GOMP_SPINCOUNT environment varible. Return true if one was
818 present and it was successfully parsed. */
821 parse_spincount (const char *name
, unsigned long long *pvalue
)
824 unsigned long long value
, mult
= 1;
830 while (isspace ((unsigned char) *env
))
835 if (strncasecmp (env
, "infinite", 8) == 0
836 || strncasecmp (env
, "infinity", 8) == 0)
844 value
= strtoull (env
, &end
, 10);
848 while (isspace ((unsigned char) *end
))
852 switch (tolower ((unsigned char) *end
))
858 mult
= 1000LL * 1000LL;
861 mult
= 1000LL * 1000LL * 1000LL;
864 mult
= 1000LL * 1000LL * 1000LL * 1000LL;
871 while (isspace ((unsigned char) *end
))
877 if (value
> ~0ULL / mult
)
886 gomp_error ("Invalid value for environment variable %s", name
);
890 /* Parse a boolean value for environment variable NAME and store the
894 parse_boolean (const char *name
, bool *value
)
902 while (isspace ((unsigned char) *env
))
904 if (strncasecmp (env
, "true", 4) == 0)
909 else if (strncasecmp (env
, "false", 5) == 0)
916 while (isspace ((unsigned char) *env
))
919 gomp_error ("Invalid value for environment variable %s", name
);
922 /* Parse the OMP_WAIT_POLICY environment variable and store the
923 result in gomp_active_wait_policy. */
926 parse_wait_policy (void)
931 env
= getenv ("OMP_WAIT_POLICY");
935 while (isspace ((unsigned char) *env
))
937 if (strncasecmp (env
, "active", 6) == 0)
942 else if (strncasecmp (env
, "passive", 7) == 0)
949 while (isspace ((unsigned char) *env
))
953 gomp_error ("Invalid value for environment variable OMP_WAIT_POLICY");
957 /* Parse the GOMP_CPU_AFFINITY environment varible. Return true if one was
958 present and it was successfully parsed. */
961 parse_affinity (bool ignore
)
963 char *env
, *end
, *start
;
965 unsigned long cpu_beg
, cpu_end
, cpu_stride
;
966 size_t count
= 0, needed
;
968 env
= getenv ("GOMP_CPU_AFFINITY");
973 for (pass
= 0; pass
< 2; pass
++)
981 gomp_places_list_len
= 0;
982 gomp_places_list
= gomp_affinity_alloc (count
, true);
983 if (gomp_places_list
== NULL
)
988 while (isspace ((unsigned char) *env
))
992 cpu_beg
= strtoul (env
, &end
, 0);
993 if (errno
|| cpu_beg
>= 65536)
1002 cpu_end
= strtoul (++env
, &end
, 0);
1003 if (errno
|| cpu_end
>= 65536 || cpu_end
< cpu_beg
)
1010 cpu_stride
= strtoul (++env
, &end
, 0);
1011 if (errno
|| cpu_stride
== 0 || cpu_stride
>= 65536)
1018 needed
= (cpu_end
- cpu_beg
) / cpu_stride
+ 1;
1025 void *p
= gomp_places_list
[gomp_places_list_len
];
1026 gomp_affinity_init_place (p
);
1027 if (gomp_affinity_add_cpus (p
, cpu_beg
, 1, 0, true))
1028 ++gomp_places_list_len
;
1029 cpu_beg
+= cpu_stride
;
1033 while (isspace ((unsigned char) *env
))
1038 else if (*env
== '\0')
1044 if (gomp_places_list_len
== 0)
1046 free (gomp_places_list
);
1047 gomp_places_list
= NULL
;
1053 gomp_error ("Invalid value for enviroment variable GOMP_CPU_AFFINITY");
1058 parse_acc_device_type (void)
1060 const char *env
= getenv ("ACC_DEVICE_TYPE");
1062 if (env
&& *env
!= '\0')
1063 goacc_device_type
= strdup (env
);
1065 goacc_device_type
= NULL
;
1069 handle_omp_display_env (unsigned long stacksize
, int wait_policy
)
1072 bool display
= false;
1073 bool verbose
= false;
1076 env
= getenv ("OMP_DISPLAY_ENV");
1080 while (isspace ((unsigned char) *env
))
1082 if (strncasecmp (env
, "true", 4) == 0)
1087 else if (strncasecmp (env
, "false", 5) == 0)
1092 else if (strncasecmp (env
, "verbose", 7) == 0)
1100 while (isspace ((unsigned char) *env
))
1103 gomp_error ("Invalid value for environment variable OMP_DISPLAY_ENV");
1108 fputs ("\nOPENMP DISPLAY ENVIRONMENT BEGIN\n", stderr
);
1110 fputs (" _OPENMP = '201511'\n", stderr
);
1111 fprintf (stderr
, " OMP_DYNAMIC = '%s'\n",
1112 gomp_global_icv
.dyn_var
? "TRUE" : "FALSE");
1113 fprintf (stderr
, " OMP_NESTED = '%s'\n",
1114 gomp_global_icv
.nest_var
? "TRUE" : "FALSE");
1116 fprintf (stderr
, " OMP_NUM_THREADS = '%lu", gomp_global_icv
.nthreads_var
);
1117 for (i
= 1; i
< gomp_nthreads_var_list_len
; i
++)
1118 fprintf (stderr
, ",%lu", gomp_nthreads_var_list
[i
]);
1119 fputs ("'\n", stderr
);
1121 fprintf (stderr
, " OMP_SCHEDULE = '");
1122 switch (gomp_global_icv
.run_sched_var
)
1125 fputs ("RUNTIME", stderr
);
1128 fputs ("STATIC", stderr
);
1131 fputs ("DYNAMIC", stderr
);
1134 fputs ("GUIDED", stderr
);
1137 fputs ("AUTO", stderr
);
1140 fputs ("'\n", stderr
);
1142 fputs (" OMP_PROC_BIND = '", stderr
);
1143 switch (gomp_global_icv
.bind_var
)
1145 case omp_proc_bind_false
:
1146 fputs ("FALSE", stderr
);
1148 case omp_proc_bind_true
:
1149 fputs ("TRUE", stderr
);
1151 case omp_proc_bind_master
:
1152 fputs ("MASTER", stderr
);
1154 case omp_proc_bind_close
:
1155 fputs ("CLOSE", stderr
);
1157 case omp_proc_bind_spread
:
1158 fputs ("SPREAD", stderr
);
1161 for (i
= 1; i
< gomp_bind_var_list_len
; i
++)
1162 switch (gomp_bind_var_list
[i
])
1164 case omp_proc_bind_master
:
1165 fputs (",MASTER", stderr
);
1167 case omp_proc_bind_close
:
1168 fputs (",CLOSE", stderr
);
1170 case omp_proc_bind_spread
:
1171 fputs (",SPREAD", stderr
);
1174 fputs ("'\n", stderr
);
1175 fputs (" OMP_PLACES = '", stderr
);
1176 for (i
= 0; i
< gomp_places_list_len
; i
++)
1178 fputs ("{", stderr
);
1179 gomp_affinity_print_place (gomp_places_list
[i
]);
1180 fputs (i
+ 1 == gomp_places_list_len
? "}" : "},", stderr
);
1182 fputs ("'\n", stderr
);
1184 fprintf (stderr
, " OMP_STACKSIZE = '%lu'\n", stacksize
);
1186 /* GOMP's default value is actually neither active nor passive. */
1187 fprintf (stderr
, " OMP_WAIT_POLICY = '%s'\n",
1188 wait_policy
> 0 ? "ACTIVE" : "PASSIVE");
1189 fprintf (stderr
, " OMP_THREAD_LIMIT = '%u'\n",
1190 gomp_global_icv
.thread_limit_var
);
1191 fprintf (stderr
, " OMP_MAX_ACTIVE_LEVELS = '%lu'\n",
1192 gomp_max_active_levels_var
);
1194 fprintf (stderr
, " OMP_CANCELLATION = '%s'\n",
1195 gomp_cancel_var
? "TRUE" : "FALSE");
1196 fprintf (stderr
, " OMP_DEFAULT_DEVICE = '%d'\n",
1197 gomp_global_icv
.default_device_var
);
1198 fprintf (stderr
, " OMP_MAX_TASK_PRIORITY = '%d'\n",
1199 gomp_max_task_priority_var
);
1203 fputs (" GOMP_CPU_AFFINITY = ''\n", stderr
);
1204 fprintf (stderr
, " GOMP_STACKSIZE = '%lu'\n", stacksize
);
1205 #ifdef HAVE_INTTYPES_H
1206 fprintf (stderr
, " GOMP_SPINCOUNT = '%"PRIu64
"'\n",
1207 (uint64_t) gomp_spin_count_var
);
1209 fprintf (stderr
, " GOMP_SPINCOUNT = '%lu'\n",
1210 (unsigned long) gomp_spin_count_var
);
1214 fputs ("OPENMP DISPLAY ENVIRONMENT END\n", stderr
);
1218 static void __attribute__((constructor
))
1219 initialize_env (void)
1221 unsigned long thread_limit_var
, stacksize
= GOMP_DEFAULT_STACKSIZE
;
1224 /* Do a compile time check that mkomp_h.pl did good job. */
1225 omp_check_defines ();
1228 parse_boolean ("OMP_DYNAMIC", &gomp_global_icv
.dyn_var
);
1229 parse_boolean ("OMP_NESTED", &gomp_global_icv
.nest_var
);
1230 parse_boolean ("OMP_CANCELLATION", &gomp_cancel_var
);
1231 parse_int ("OMP_DEFAULT_DEVICE", &gomp_global_icv
.default_device_var
, true);
1232 parse_int ("OMP_MAX_TASK_PRIORITY", &gomp_max_task_priority_var
, true);
1233 parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var
,
1235 if (parse_unsigned_long ("OMP_THREAD_LIMIT", &thread_limit_var
, false))
1237 gomp_global_icv
.thread_limit_var
1238 = thread_limit_var
> INT_MAX
? UINT_MAX
: thread_limit_var
;
1240 parse_int_secure ("GOMP_DEBUG", &gomp_debug_var
, true);
1241 #ifndef HAVE_SYNC_BUILTINS
1242 gomp_mutex_init (&gomp_managed_threads_lock
);
1244 gomp_init_num_threads ();
1245 gomp_available_cpus
= gomp_global_icv
.nthreads_var
;
1246 if (!parse_unsigned_long_list ("OMP_NUM_THREADS",
1247 &gomp_global_icv
.nthreads_var
,
1248 &gomp_nthreads_var_list
,
1249 &gomp_nthreads_var_list_len
))
1250 gomp_global_icv
.nthreads_var
= gomp_available_cpus
;
1251 bool ignore
= false;
1252 if (parse_bind_var ("OMP_PROC_BIND",
1253 &gomp_global_icv
.bind_var
,
1254 &gomp_bind_var_list
,
1255 &gomp_bind_var_list_len
)
1256 && gomp_global_icv
.bind_var
== omp_proc_bind_false
)
1258 /* Make sure OMP_PLACES and GOMP_CPU_AFFINITY env vars are always
1259 parsed if present in the environment. If OMP_PROC_BIND was set
1260 explictly to false, don't populate places list though. If places
1261 list was successfully set from OMP_PLACES, only parse but don't process
1262 GOMP_CPU_AFFINITY. If OMP_PROC_BIND was not set in the environment,
1263 default to OMP_PROC_BIND=true if OMP_PLACES or GOMP_CPU_AFFINITY
1264 was successfully parsed into a places list, otherwise to
1265 OMP_PROC_BIND=false. */
1266 if (parse_places_var ("OMP_PLACES", ignore
))
1268 if (gomp_global_icv
.bind_var
== omp_proc_bind_false
)
1269 gomp_global_icv
.bind_var
= true;
1272 if (parse_affinity (ignore
))
1274 if (gomp_global_icv
.bind_var
== omp_proc_bind_false
)
1275 gomp_global_icv
.bind_var
= true;
1278 if (gomp_global_icv
.bind_var
!= omp_proc_bind_false
)
1279 gomp_init_affinity ();
1280 wait_policy
= parse_wait_policy ();
1281 if (!parse_spincount ("GOMP_SPINCOUNT", &gomp_spin_count_var
))
1283 /* Using a rough estimation of 100000 spins per msec,
1284 use 5 min blocking for OMP_WAIT_POLICY=active,
1285 3 msec blocking when OMP_WAIT_POLICY is not specificed
1286 and 0 when OMP_WAIT_POLICY=passive.
1287 Depending on the CPU speed, this can be e.g. 5 times longer
1288 or 5 times shorter. */
1289 if (wait_policy
> 0)
1290 gomp_spin_count_var
= 30000000000LL;
1291 else if (wait_policy
< 0)
1292 gomp_spin_count_var
= 300000LL;
1294 /* gomp_throttled_spin_count_var is used when there are more libgomp
1295 managed threads than available CPUs. Use very short spinning. */
1296 if (wait_policy
> 0)
1297 gomp_throttled_spin_count_var
= 1000LL;
1298 else if (wait_policy
< 0)
1299 gomp_throttled_spin_count_var
= 100LL;
1300 if (gomp_throttled_spin_count_var
> gomp_spin_count_var
)
1301 gomp_throttled_spin_count_var
= gomp_spin_count_var
;
1303 /* Not strictly environment related, but ordering constructors is tricky. */
1304 pthread_attr_init (&gomp_thread_attr
);
1305 pthread_attr_setdetachstate (&gomp_thread_attr
, PTHREAD_CREATE_DETACHED
);
1307 if (parse_stacksize ("OMP_STACKSIZE", &stacksize
)
1308 || parse_stacksize ("GOMP_STACKSIZE", &stacksize
)
1309 || GOMP_DEFAULT_STACKSIZE
)
1313 err
= pthread_attr_setstacksize (&gomp_thread_attr
, stacksize
);
1315 #ifdef PTHREAD_STACK_MIN
1318 if (stacksize
< PTHREAD_STACK_MIN
)
1319 gomp_error ("Stack size less than minimum of %luk",
1320 PTHREAD_STACK_MIN
/ 1024ul
1321 + (PTHREAD_STACK_MIN
% 1024 != 0));
1323 gomp_error ("Stack size larger than system limit");
1328 gomp_error ("Stack size change failed: %s", strerror (err
));
1331 handle_omp_display_env (stacksize
, wait_policy
);
1335 if (!parse_int ("ACC_DEVICE_NUM", &goacc_device_num
, true))
1336 goacc_device_num
= 0;
1338 parse_acc_device_type ();
1340 goacc_runtime_initialize ();
1342 #endif /* LIBGOMP_OFFLOADED_ONLY */