1 /* Copyright (C) 2005-2017 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. */
30 #include "gomp-constants.h"
32 #ifndef LIBGOMP_OFFLOADED_ONLY
33 #include "libgomp_f.h"
38 #ifdef HAVE_INTTYPES_H
39 # include <inttypes.h> /* For PRIu64. */
41 #ifdef STRING_WITH_STRINGS
48 # ifdef HAVE_STRINGS_H
54 #include "thread-stacksize.h"
57 # define strtoull(ptr, eptr, base) strtoul (ptr, eptr, base)
59 #endif /* LIBGOMP_OFFLOADED_ONLY */
61 struct gomp_task_icv gomp_global_icv
= {
63 .thread_limit_var
= UINT_MAX
,
64 .run_sched_var
= GFS_DYNAMIC
,
65 .run_sched_chunk_size
= 1,
66 .default_device_var
= 0,
69 .bind_var
= omp_proc_bind_false
,
73 unsigned long gomp_max_active_levels_var
= INT_MAX
;
74 bool gomp_cancel_var
= false;
75 int gomp_max_task_priority_var
= 0;
76 #ifndef HAVE_SYNC_BUILTINS
77 gomp_mutex_t gomp_managed_threads_lock
;
79 unsigned long gomp_available_cpus
= 1, gomp_managed_threads
= 1;
80 unsigned long long gomp_spin_count_var
, gomp_throttled_spin_count_var
;
81 unsigned long *gomp_nthreads_var_list
, gomp_nthreads_var_list_len
;
82 char *gomp_bind_var_list
;
83 unsigned long gomp_bind_var_list_len
;
84 void **gomp_places_list
;
85 unsigned long gomp_places_list_len
;
87 unsigned int gomp_num_teams_var
;
88 char *goacc_device_type
;
91 #ifndef LIBGOMP_OFFLOADED_ONLY
93 /* Parse the OMP_SCHEDULE environment variable. */
101 env
= getenv ("OMP_SCHEDULE");
105 while (isspace ((unsigned char) *env
))
107 if (strncasecmp (env
, "static", 6) == 0)
109 gomp_global_icv
.run_sched_var
= GFS_STATIC
;
112 else if (strncasecmp (env
, "dynamic", 7) == 0)
114 gomp_global_icv
.run_sched_var
= GFS_DYNAMIC
;
117 else if (strncasecmp (env
, "guided", 6) == 0)
119 gomp_global_icv
.run_sched_var
= GFS_GUIDED
;
122 else if (strncasecmp (env
, "auto", 4) == 0)
124 gomp_global_icv
.run_sched_var
= GFS_AUTO
;
130 while (isspace ((unsigned char) *env
))
134 gomp_global_icv
.run_sched_chunk_size
135 = gomp_global_icv
.run_sched_var
!= GFS_STATIC
;
140 while (isspace ((unsigned char) *env
))
146 value
= strtoul (env
, &end
, 10);
150 while (isspace ((unsigned char) *end
))
155 if ((int)value
!= value
)
158 if (value
== 0 && gomp_global_icv
.run_sched_var
!= GFS_STATIC
)
160 gomp_global_icv
.run_sched_chunk_size
= value
;
164 gomp_error ("Unknown value for environment variable OMP_SCHEDULE");
168 gomp_error ("Invalid value for chunk size in "
169 "environment variable OMP_SCHEDULE");
173 /* Parse an unsigned long environment variable. Return true if one was
174 present and it was successfully parsed. */
177 parse_unsigned_long (const char *name
, unsigned long *pvalue
, bool allow_zero
)
186 while (isspace ((unsigned char) *env
))
192 value
= strtoul (env
, &end
, 10);
193 if (errno
|| (long) value
<= 0 - allow_zero
)
196 while (isspace ((unsigned char) *end
))
205 gomp_error ("Invalid value for environment variable %s", name
);
209 /* Parse a positive int environment variable. Return true if one was
210 present and it was successfully parsed. */
213 parse_int (const char *name
, int *pvalue
, bool allow_zero
)
216 if (!parse_unsigned_long (name
, &value
, allow_zero
))
220 gomp_error ("Invalid value for environment variable %s", name
);
223 *pvalue
= (int) value
;
227 /* Parse an unsigned long list environment variable. Return true if one was
228 present and it was successfully parsed. */
231 parse_unsigned_long_list (const char *name
, unsigned long *p1stvalue
,
232 unsigned long **pvalues
,
233 unsigned long *pnvalues
)
236 unsigned long value
, *values
= NULL
;
242 while (isspace ((unsigned char) *env
))
248 value
= strtoul (env
, &end
, 10);
249 if (errno
|| (long) value
<= 0)
252 while (isspace ((unsigned char) *end
))
258 unsigned long nvalues
= 0, nalloced
= 0;
263 if (nvalues
== nalloced
)
266 nalloced
= nalloced
? nalloced
* 2 : 16;
267 n
= realloc (values
, nalloced
* sizeof (unsigned long));
271 gomp_error ("Out of memory while trying to parse"
272 " environment variable %s", name
);
277 values
[nvalues
++] = value
;
280 while (isspace ((unsigned char) *env
))
286 value
= strtoul (env
, &end
, 10);
287 if (errno
|| (long) value
<= 0)
290 values
[nvalues
++] = value
;
291 while (isspace ((unsigned char) *end
))
299 *p1stvalue
= values
[0];
312 gomp_error ("Invalid value for environment variable %s", name
);
316 /* Parse environment variable set to a boolean or list of omp_proc_bind_t
317 enum values. Return true if one was present and it was successfully
321 parse_bind_var (const char *name
, char *p1stvalue
,
322 char **pvalues
, unsigned long *pnvalues
)
325 char value
= omp_proc_bind_false
, *values
= NULL
;
327 static struct proc_bind_kinds
331 omp_proc_bind_t kind
;
334 { "false", 5, omp_proc_bind_false
},
335 { "true", 4, omp_proc_bind_true
},
336 { "master", 6, omp_proc_bind_master
},
337 { "close", 5, omp_proc_bind_close
},
338 { "spread", 6, omp_proc_bind_spread
}
345 while (isspace ((unsigned char) *env
))
350 for (i
= 0; i
< 5; i
++)
351 if (strncasecmp (env
, kinds
[i
].name
, kinds
[i
].len
) == 0)
353 value
= kinds
[i
].kind
;
360 while (isspace ((unsigned char) *env
))
366 unsigned long nvalues
= 0, nalloced
= 0;
368 if (value
== omp_proc_bind_false
369 || value
== omp_proc_bind_true
)
375 if (nvalues
== nalloced
)
378 nalloced
= nalloced
? nalloced
* 2 : 16;
379 n
= realloc (values
, nalloced
);
383 gomp_error ("Out of memory while trying to parse"
384 " environment variable %s", name
);
389 values
[nvalues
++] = value
;
392 while (isspace ((unsigned char) *env
))
397 for (i
= 2; i
< 5; i
++)
398 if (strncasecmp (env
, kinds
[i
].name
, kinds
[i
].len
) == 0)
400 value
= kinds
[i
].kind
;
407 values
[nvalues
++] = value
;
408 while (isspace ((unsigned char) *env
))
416 *p1stvalue
= values
[0];
429 gomp_error ("Invalid value for environment variable %s", name
);
434 parse_one_place (char **envp
, bool *negatep
, unsigned long *lenp
,
437 char *env
= *envp
, *start
;
438 void *p
= gomp_places_list
? gomp_places_list
[gomp_places_list_len
] : NULL
;
439 unsigned long len
= 1;
442 bool any_negate
= false;
444 while (isspace ((unsigned char) *env
))
450 while (isspace ((unsigned char) *env
))
456 while (isspace ((unsigned char) *env
))
459 for (pass
= 0; pass
< (any_negate
? 2 : 1); pass
++)
464 unsigned long this_num
, this_len
= 1;
465 long this_stride
= 1;
466 bool this_negate
= (*env
== '!');
469 if (gomp_places_list
)
472 while (isspace ((unsigned char) *env
))
477 this_num
= strtoul (env
, &env
, 10);
480 while (isspace ((unsigned char) *env
))
485 while (isspace ((unsigned char) *env
))
488 this_len
= strtoul (env
, &env
, 10);
489 if (errno
|| this_len
== 0)
491 while (isspace ((unsigned char) *env
))
496 while (isspace ((unsigned char) *env
))
499 this_stride
= strtol (env
, &env
, 10);
502 while (isspace ((unsigned char) *env
))
506 if (this_negate
&& this_len
!= 1)
508 if (gomp_places_list
&& pass
== this_negate
)
512 if (!gomp_affinity_remove_cpu (p
, this_num
))
515 else if (!gomp_affinity_add_cpus (p
, this_num
, this_len
,
529 while (isspace ((unsigned char) *env
))
534 while (isspace ((unsigned char) *env
))
537 len
= strtoul (env
, &env
, 10);
538 if (errno
|| len
== 0 || len
>= 65536)
540 while (isspace ((unsigned char) *env
))
545 while (isspace ((unsigned char) *env
))
548 stride
= strtol (env
, &env
, 10);
551 while (isspace ((unsigned char) *env
))
555 if (*negatep
&& len
!= 1)
564 parse_places_var (const char *name
, bool ignore
)
566 char *env
= getenv (name
), *end
;
567 bool any_negate
= false;
569 unsigned long count
= 0;
573 while (isspace ((unsigned char) *env
))
578 if (strncasecmp (env
, "threads", 7) == 0)
583 else if (strncasecmp (env
, "cores", 5) == 0)
588 else if (strncasecmp (env
, "sockets", 7) == 0)
596 while (isspace ((unsigned char) *env
))
602 while (isspace ((unsigned char) *env
))
606 count
= strtoul (env
, &end
, 10);
610 while (isspace ((unsigned char) *env
))
615 while (isspace ((unsigned char) *env
))
624 return gomp_affinity_init_level (level
, count
, false);
634 if (!parse_one_place (&end
, &negate
, &len
, &stride
))
657 gomp_places_list_len
= 0;
658 gomp_places_list
= gomp_affinity_alloc (count
, false);
659 if (gomp_places_list
== NULL
)
667 gomp_affinity_init_place (gomp_places_list
[gomp_places_list_len
]);
668 if (!parse_one_place (&env
, &negate
, &len
, &stride
))
673 for (count
= 0; count
< gomp_places_list_len
; count
++)
674 if (gomp_affinity_same_place
675 (gomp_places_list
[count
],
676 gomp_places_list
[gomp_places_list_len
]))
678 if (count
== gomp_places_list_len
)
680 gomp_error ("Trying to remove a non-existing place from list "
684 p
= gomp_places_list
[count
];
685 memmove (&gomp_places_list
[count
],
686 &gomp_places_list
[count
+ 1],
687 (gomp_places_list_len
- count
- 1) * sizeof (void *));
688 --gomp_places_list_len
;
689 gomp_places_list
[gomp_places_list_len
] = p
;
692 ++gomp_places_list_len
;
695 for (count
= 0; count
< len
- 1; count
++)
696 if (!gomp_affinity_copy_place
697 (gomp_places_list
[gomp_places_list_len
+ count
+ 1],
698 gomp_places_list
[gomp_places_list_len
+ count
],
701 gomp_places_list_len
+= len
;
709 if (gomp_places_list_len
== 0)
711 gomp_error ("All places have been removed");
714 if (!gomp_affinity_finalize_place_list (false))
719 free (gomp_places_list
);
720 gomp_places_list
= NULL
;
721 gomp_places_list_len
= 0;
722 gomp_error ("Invalid value for environment variable %s", name
);
726 /* Parse the OMP_STACKSIZE environment varible. Return true if one was
727 present and it was successfully parsed. */
730 parse_stacksize (const char *name
, unsigned long *pvalue
)
733 unsigned long value
, shift
= 10;
739 while (isspace ((unsigned char) *env
))
745 value
= strtoul (env
, &end
, 10);
749 while (isspace ((unsigned char) *end
))
753 switch (tolower ((unsigned char) *end
))
770 while (isspace ((unsigned char) *end
))
776 if (((value
<< shift
) >> shift
) != value
)
779 *pvalue
= value
<< shift
;
783 gomp_error ("Invalid value for environment variable %s", name
);
787 /* Parse the GOMP_SPINCOUNT environment varible. Return true if one was
788 present and it was successfully parsed. */
791 parse_spincount (const char *name
, unsigned long long *pvalue
)
794 unsigned long long value
, mult
= 1;
800 while (isspace ((unsigned char) *env
))
805 if (strncasecmp (env
, "infinite", 8) == 0
806 || strncasecmp (env
, "infinity", 8) == 0)
814 value
= strtoull (env
, &end
, 10);
818 while (isspace ((unsigned char) *end
))
822 switch (tolower ((unsigned char) *end
))
828 mult
= 1000LL * 1000LL;
831 mult
= 1000LL * 1000LL * 1000LL;
834 mult
= 1000LL * 1000LL * 1000LL * 1000LL;
841 while (isspace ((unsigned char) *end
))
847 if (value
> ~0ULL / mult
)
856 gomp_error ("Invalid value for environment variable %s", name
);
860 /* Parse a boolean value for environment variable NAME and store the
864 parse_boolean (const char *name
, bool *value
)
872 while (isspace ((unsigned char) *env
))
874 if (strncasecmp (env
, "true", 4) == 0)
879 else if (strncasecmp (env
, "false", 5) == 0)
886 while (isspace ((unsigned char) *env
))
889 gomp_error ("Invalid value for environment variable %s", name
);
892 /* Parse the OMP_WAIT_POLICY environment variable and store the
893 result in gomp_active_wait_policy. */
896 parse_wait_policy (void)
901 env
= getenv ("OMP_WAIT_POLICY");
905 while (isspace ((unsigned char) *env
))
907 if (strncasecmp (env
, "active", 6) == 0)
912 else if (strncasecmp (env
, "passive", 7) == 0)
919 while (isspace ((unsigned char) *env
))
923 gomp_error ("Invalid value for environment variable OMP_WAIT_POLICY");
927 /* Parse the GOMP_CPU_AFFINITY environment varible. Return true if one was
928 present and it was successfully parsed. */
931 parse_affinity (bool ignore
)
933 char *env
, *end
, *start
;
935 unsigned long cpu_beg
, cpu_end
, cpu_stride
;
936 size_t count
= 0, needed
;
938 env
= getenv ("GOMP_CPU_AFFINITY");
943 for (pass
= 0; pass
< 2; pass
++)
951 gomp_places_list_len
= 0;
952 gomp_places_list
= gomp_affinity_alloc (count
, true);
953 if (gomp_places_list
== NULL
)
958 while (isspace ((unsigned char) *env
))
962 cpu_beg
= strtoul (env
, &end
, 0);
963 if (errno
|| cpu_beg
>= 65536)
972 cpu_end
= strtoul (++env
, &end
, 0);
973 if (errno
|| cpu_end
>= 65536 || cpu_end
< cpu_beg
)
980 cpu_stride
= strtoul (++env
, &end
, 0);
981 if (errno
|| cpu_stride
== 0 || cpu_stride
>= 65536)
988 needed
= (cpu_end
- cpu_beg
) / cpu_stride
+ 1;
995 void *p
= gomp_places_list
[gomp_places_list_len
];
996 gomp_affinity_init_place (p
);
997 if (gomp_affinity_add_cpus (p
, cpu_beg
, 1, 0, true))
998 ++gomp_places_list_len
;
999 cpu_beg
+= cpu_stride
;
1003 while (isspace ((unsigned char) *env
))
1008 else if (*env
== '\0')
1014 if (gomp_places_list_len
== 0)
1016 free (gomp_places_list
);
1017 gomp_places_list
= NULL
;
1023 gomp_error ("Invalid value for enviroment variable GOMP_CPU_AFFINITY");
1028 parse_acc_device_type (void)
1030 const char *env
= getenv ("ACC_DEVICE_TYPE");
1032 if (env
&& *env
!= '\0')
1033 goacc_device_type
= strdup (env
);
1035 goacc_device_type
= NULL
;
1039 handle_omp_display_env (unsigned long stacksize
, int wait_policy
)
1042 bool display
= false;
1043 bool verbose
= false;
1046 env
= getenv ("OMP_DISPLAY_ENV");
1050 while (isspace ((unsigned char) *env
))
1052 if (strncasecmp (env
, "true", 4) == 0)
1057 else if (strncasecmp (env
, "false", 5) == 0)
1062 else if (strncasecmp (env
, "verbose", 7) == 0)
1070 while (isspace ((unsigned char) *env
))
1073 gomp_error ("Invalid value for environment variable OMP_DISPLAY_ENV");
1078 fputs ("\nOPENMP DISPLAY ENVIRONMENT BEGIN\n", stderr
);
1080 fputs (" _OPENMP = '201511'\n", stderr
);
1081 fprintf (stderr
, " OMP_DYNAMIC = '%s'\n",
1082 gomp_global_icv
.dyn_var
? "TRUE" : "FALSE");
1083 fprintf (stderr
, " OMP_NESTED = '%s'\n",
1084 gomp_global_icv
.nest_var
? "TRUE" : "FALSE");
1086 fprintf (stderr
, " OMP_NUM_THREADS = '%lu", gomp_global_icv
.nthreads_var
);
1087 for (i
= 1; i
< gomp_nthreads_var_list_len
; i
++)
1088 fprintf (stderr
, ",%lu", gomp_nthreads_var_list
[i
]);
1089 fputs ("'\n", stderr
);
1091 fprintf (stderr
, " OMP_SCHEDULE = '");
1092 switch (gomp_global_icv
.run_sched_var
)
1095 fputs ("RUNTIME", stderr
);
1098 fputs ("STATIC", stderr
);
1101 fputs ("DYNAMIC", stderr
);
1104 fputs ("GUIDED", stderr
);
1107 fputs ("AUTO", stderr
);
1110 fputs ("'\n", stderr
);
1112 fputs (" OMP_PROC_BIND = '", stderr
);
1113 switch (gomp_global_icv
.bind_var
)
1115 case omp_proc_bind_false
:
1116 fputs ("FALSE", stderr
);
1118 case omp_proc_bind_true
:
1119 fputs ("TRUE", stderr
);
1121 case omp_proc_bind_master
:
1122 fputs ("MASTER", stderr
);
1124 case omp_proc_bind_close
:
1125 fputs ("CLOSE", stderr
);
1127 case omp_proc_bind_spread
:
1128 fputs ("SPREAD", stderr
);
1131 for (i
= 1; i
< gomp_bind_var_list_len
; i
++)
1132 switch (gomp_bind_var_list
[i
])
1134 case omp_proc_bind_master
:
1135 fputs (",MASTER", stderr
);
1137 case omp_proc_bind_close
:
1138 fputs (",CLOSE", stderr
);
1140 case omp_proc_bind_spread
:
1141 fputs (",SPREAD", stderr
);
1144 fputs ("'\n", stderr
);
1145 fputs (" OMP_PLACES = '", stderr
);
1146 for (i
= 0; i
< gomp_places_list_len
; i
++)
1148 fputs ("{", stderr
);
1149 gomp_affinity_print_place (gomp_places_list
[i
]);
1150 fputs (i
+ 1 == gomp_places_list_len
? "}" : "},", stderr
);
1152 fputs ("'\n", stderr
);
1154 fprintf (stderr
, " OMP_STACKSIZE = '%lu'\n", stacksize
);
1156 /* GOMP's default value is actually neither active nor passive. */
1157 fprintf (stderr
, " OMP_WAIT_POLICY = '%s'\n",
1158 wait_policy
> 0 ? "ACTIVE" : "PASSIVE");
1159 fprintf (stderr
, " OMP_THREAD_LIMIT = '%u'\n",
1160 gomp_global_icv
.thread_limit_var
);
1161 fprintf (stderr
, " OMP_MAX_ACTIVE_LEVELS = '%lu'\n",
1162 gomp_max_active_levels_var
);
1164 fprintf (stderr
, " OMP_CANCELLATION = '%s'\n",
1165 gomp_cancel_var
? "TRUE" : "FALSE");
1166 fprintf (stderr
, " OMP_DEFAULT_DEVICE = '%d'\n",
1167 gomp_global_icv
.default_device_var
);
1168 fprintf (stderr
, " OMP_MAX_TASK_PRIORITY = '%d'\n",
1169 gomp_max_task_priority_var
);
1173 fputs (" GOMP_CPU_AFFINITY = ''\n", stderr
);
1174 fprintf (stderr
, " GOMP_STACKSIZE = '%lu'\n", stacksize
);
1175 #ifdef HAVE_INTTYPES_H
1176 fprintf (stderr
, " GOMP_SPINCOUNT = '%"PRIu64
"'\n",
1177 (uint64_t) gomp_spin_count_var
);
1179 fprintf (stderr
, " GOMP_SPINCOUNT = '%lu'\n",
1180 (unsigned long) gomp_spin_count_var
);
1184 fputs ("OPENMP DISPLAY ENVIRONMENT END\n", stderr
);
1188 static void __attribute__((constructor
))
1189 initialize_env (void)
1191 unsigned long thread_limit_var
, stacksize
= GOMP_DEFAULT_STACKSIZE
;
1194 /* Do a compile time check that mkomp_h.pl did good job. */
1195 omp_check_defines ();
1198 parse_boolean ("OMP_DYNAMIC", &gomp_global_icv
.dyn_var
);
1199 parse_boolean ("OMP_NESTED", &gomp_global_icv
.nest_var
);
1200 parse_boolean ("OMP_CANCELLATION", &gomp_cancel_var
);
1201 parse_int ("OMP_DEFAULT_DEVICE", &gomp_global_icv
.default_device_var
, true);
1202 parse_int ("OMP_MAX_TASK_PRIORITY", &gomp_max_task_priority_var
, true);
1203 parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var
,
1205 if (parse_unsigned_long ("OMP_THREAD_LIMIT", &thread_limit_var
, false))
1207 gomp_global_icv
.thread_limit_var
1208 = thread_limit_var
> INT_MAX
? UINT_MAX
: thread_limit_var
;
1210 parse_int ("GOMP_DEBUG", &gomp_debug_var
, true);
1211 #ifndef HAVE_SYNC_BUILTINS
1212 gomp_mutex_init (&gomp_managed_threads_lock
);
1214 gomp_init_num_threads ();
1215 gomp_available_cpus
= gomp_global_icv
.nthreads_var
;
1216 if (!parse_unsigned_long_list ("OMP_NUM_THREADS",
1217 &gomp_global_icv
.nthreads_var
,
1218 &gomp_nthreads_var_list
,
1219 &gomp_nthreads_var_list_len
))
1220 gomp_global_icv
.nthreads_var
= gomp_available_cpus
;
1221 bool ignore
= false;
1222 if (parse_bind_var ("OMP_PROC_BIND",
1223 &gomp_global_icv
.bind_var
,
1224 &gomp_bind_var_list
,
1225 &gomp_bind_var_list_len
)
1226 && gomp_global_icv
.bind_var
== omp_proc_bind_false
)
1228 /* Make sure OMP_PLACES and GOMP_CPU_AFFINITY env vars are always
1229 parsed if present in the environment. If OMP_PROC_BIND was set
1230 explictly to false, don't populate places list though. If places
1231 list was successfully set from OMP_PLACES, only parse but don't process
1232 GOMP_CPU_AFFINITY. If OMP_PROC_BIND was not set in the environment,
1233 default to OMP_PROC_BIND=true if OMP_PLACES or GOMP_CPU_AFFINITY
1234 was successfully parsed into a places list, otherwise to
1235 OMP_PROC_BIND=false. */
1236 if (parse_places_var ("OMP_PLACES", ignore
))
1238 if (gomp_global_icv
.bind_var
== omp_proc_bind_false
)
1239 gomp_global_icv
.bind_var
= true;
1242 if (parse_affinity (ignore
))
1244 if (gomp_global_icv
.bind_var
== omp_proc_bind_false
)
1245 gomp_global_icv
.bind_var
= true;
1248 if (gomp_global_icv
.bind_var
!= omp_proc_bind_false
)
1249 gomp_init_affinity ();
1250 wait_policy
= parse_wait_policy ();
1251 if (!parse_spincount ("GOMP_SPINCOUNT", &gomp_spin_count_var
))
1253 /* Using a rough estimation of 100000 spins per msec,
1254 use 5 min blocking for OMP_WAIT_POLICY=active,
1255 3 msec blocking when OMP_WAIT_POLICY is not specificed
1256 and 0 when OMP_WAIT_POLICY=passive.
1257 Depending on the CPU speed, this can be e.g. 5 times longer
1258 or 5 times shorter. */
1259 if (wait_policy
> 0)
1260 gomp_spin_count_var
= 30000000000LL;
1261 else if (wait_policy
< 0)
1262 gomp_spin_count_var
= 300000LL;
1264 /* gomp_throttled_spin_count_var is used when there are more libgomp
1265 managed threads than available CPUs. Use very short spinning. */
1266 if (wait_policy
> 0)
1267 gomp_throttled_spin_count_var
= 1000LL;
1268 else if (wait_policy
< 0)
1269 gomp_throttled_spin_count_var
= 100LL;
1270 if (gomp_throttled_spin_count_var
> gomp_spin_count_var
)
1271 gomp_throttled_spin_count_var
= gomp_spin_count_var
;
1273 /* Not strictly environment related, but ordering constructors is tricky. */
1274 pthread_attr_init (&gomp_thread_attr
);
1275 pthread_attr_setdetachstate (&gomp_thread_attr
, PTHREAD_CREATE_DETACHED
);
1277 if (parse_stacksize ("OMP_STACKSIZE", &stacksize
)
1278 || parse_stacksize ("GOMP_STACKSIZE", &stacksize
)
1279 || GOMP_DEFAULT_STACKSIZE
)
1283 err
= pthread_attr_setstacksize (&gomp_thread_attr
, stacksize
);
1285 #ifdef PTHREAD_STACK_MIN
1288 if (stacksize
< PTHREAD_STACK_MIN
)
1289 gomp_error ("Stack size less than minimum of %luk",
1290 PTHREAD_STACK_MIN
/ 1024ul
1291 + (PTHREAD_STACK_MIN
% 1024 != 0));
1293 gomp_error ("Stack size larger than system limit");
1298 gomp_error ("Stack size change failed: %s", strerror (err
));
1301 handle_omp_display_env (stacksize
, wait_policy
);
1305 if (!parse_int ("ACC_DEVICE_NUM", &goacc_device_num
, true))
1306 goacc_device_num
= 0;
1308 parse_acc_device_type ();
1310 goacc_runtime_initialize ();
1312 #endif /* LIBGOMP_OFFLOADED_ONLY */