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
56 # define strtoull(ptr, eptr, base) strtoul (ptr, eptr, base)
58 #endif /* LIBGOMP_OFFLOADED_ONLY */
60 struct gomp_task_icv gomp_global_icv
= {
62 .thread_limit_var
= UINT_MAX
,
63 .run_sched_var
= GFS_DYNAMIC
,
64 .run_sched_chunk_size
= 1,
65 .default_device_var
= 0,
68 .bind_var
= omp_proc_bind_false
,
72 unsigned long gomp_max_active_levels_var
= INT_MAX
;
73 bool gomp_cancel_var
= false;
74 int gomp_max_task_priority_var
= 0;
75 #ifndef HAVE_SYNC_BUILTINS
76 gomp_mutex_t gomp_managed_threads_lock
;
78 unsigned long gomp_available_cpus
= 1, gomp_managed_threads
= 1;
79 unsigned long long gomp_spin_count_var
, gomp_throttled_spin_count_var
;
80 unsigned long *gomp_nthreads_var_list
, gomp_nthreads_var_list_len
;
81 char *gomp_bind_var_list
;
82 unsigned long gomp_bind_var_list_len
;
83 void **gomp_places_list
;
84 unsigned long gomp_places_list_len
;
86 unsigned int gomp_num_teams_var
;
87 char *goacc_device_type
;
90 #ifndef LIBGOMP_OFFLOADED_ONLY
92 /* Parse the OMP_SCHEDULE environment variable. */
100 env
= getenv ("OMP_SCHEDULE");
104 while (isspace ((unsigned char) *env
))
106 if (strncasecmp (env
, "static", 6) == 0)
108 gomp_global_icv
.run_sched_var
= GFS_STATIC
;
111 else if (strncasecmp (env
, "dynamic", 7) == 0)
113 gomp_global_icv
.run_sched_var
= GFS_DYNAMIC
;
116 else if (strncasecmp (env
, "guided", 6) == 0)
118 gomp_global_icv
.run_sched_var
= GFS_GUIDED
;
121 else if (strncasecmp (env
, "auto", 4) == 0)
123 gomp_global_icv
.run_sched_var
= GFS_AUTO
;
129 while (isspace ((unsigned char) *env
))
133 gomp_global_icv
.run_sched_chunk_size
134 = gomp_global_icv
.run_sched_var
!= GFS_STATIC
;
139 while (isspace ((unsigned char) *env
))
145 value
= strtoul (env
, &end
, 10);
149 while (isspace ((unsigned char) *end
))
154 if ((int)value
!= value
)
157 if (value
== 0 && gomp_global_icv
.run_sched_var
!= GFS_STATIC
)
159 gomp_global_icv
.run_sched_chunk_size
= value
;
163 gomp_error ("Unknown value for environment variable OMP_SCHEDULE");
167 gomp_error ("Invalid value for chunk size in "
168 "environment variable OMP_SCHEDULE");
172 /* Parse an unsigned long environment variable. Return true if one was
173 present and it was successfully parsed. */
176 parse_unsigned_long (const char *name
, unsigned long *pvalue
, bool allow_zero
)
185 while (isspace ((unsigned char) *env
))
191 value
= strtoul (env
, &end
, 10);
192 if (errno
|| (long) value
<= 0 - allow_zero
)
195 while (isspace ((unsigned char) *end
))
204 gomp_error ("Invalid value for environment variable %s", name
);
208 /* Parse a positive int environment variable. Return true if one was
209 present and it was successfully parsed. */
212 parse_int (const char *name
, int *pvalue
, bool allow_zero
)
215 if (!parse_unsigned_long (name
, &value
, allow_zero
))
219 gomp_error ("Invalid value for environment variable %s", name
);
222 *pvalue
= (int) value
;
226 /* Parse an unsigned long list environment variable. Return true if one was
227 present and it was successfully parsed. */
230 parse_unsigned_long_list (const char *name
, unsigned long *p1stvalue
,
231 unsigned long **pvalues
,
232 unsigned long *pnvalues
)
235 unsigned long value
, *values
= NULL
;
241 while (isspace ((unsigned char) *env
))
247 value
= strtoul (env
, &end
, 10);
248 if (errno
|| (long) value
<= 0)
251 while (isspace ((unsigned char) *end
))
257 unsigned long nvalues
= 0, nalloced
= 0;
262 if (nvalues
== nalloced
)
265 nalloced
= nalloced
? nalloced
* 2 : 16;
266 n
= realloc (values
, nalloced
* sizeof (unsigned long));
270 gomp_error ("Out of memory while trying to parse"
271 " environment variable %s", name
);
276 values
[nvalues
++] = value
;
279 while (isspace ((unsigned char) *env
))
285 value
= strtoul (env
, &end
, 10);
286 if (errno
|| (long) value
<= 0)
289 values
[nvalues
++] = value
;
290 while (isspace ((unsigned char) *end
))
298 *p1stvalue
= values
[0];
311 gomp_error ("Invalid value for environment variable %s", name
);
315 /* Parse environment variable set to a boolean or list of omp_proc_bind_t
316 enum values. Return true if one was present and it was successfully
320 parse_bind_var (const char *name
, char *p1stvalue
,
321 char **pvalues
, unsigned long *pnvalues
)
324 char value
= omp_proc_bind_false
, *values
= NULL
;
326 static struct proc_bind_kinds
330 omp_proc_bind_t kind
;
333 { "false", 5, omp_proc_bind_false
},
334 { "true", 4, omp_proc_bind_true
},
335 { "master", 6, omp_proc_bind_master
},
336 { "close", 5, omp_proc_bind_close
},
337 { "spread", 6, omp_proc_bind_spread
}
344 while (isspace ((unsigned char) *env
))
349 for (i
= 0; i
< 5; i
++)
350 if (strncasecmp (env
, kinds
[i
].name
, kinds
[i
].len
) == 0)
352 value
= kinds
[i
].kind
;
359 while (isspace ((unsigned char) *env
))
365 unsigned long nvalues
= 0, nalloced
= 0;
367 if (value
== omp_proc_bind_false
368 || value
== omp_proc_bind_true
)
374 if (nvalues
== nalloced
)
377 nalloced
= nalloced
? nalloced
* 2 : 16;
378 n
= realloc (values
, nalloced
);
382 gomp_error ("Out of memory while trying to parse"
383 " environment variable %s", name
);
388 values
[nvalues
++] = value
;
391 while (isspace ((unsigned char) *env
))
396 for (i
= 2; i
< 5; i
++)
397 if (strncasecmp (env
, kinds
[i
].name
, kinds
[i
].len
) == 0)
399 value
= kinds
[i
].kind
;
406 values
[nvalues
++] = value
;
407 while (isspace ((unsigned char) *env
))
415 *p1stvalue
= values
[0];
428 gomp_error ("Invalid value for environment variable %s", name
);
433 parse_one_place (char **envp
, bool *negatep
, unsigned long *lenp
,
436 char *env
= *envp
, *start
;
437 void *p
= gomp_places_list
? gomp_places_list
[gomp_places_list_len
] : NULL
;
438 unsigned long len
= 1;
441 bool any_negate
= false;
443 while (isspace ((unsigned char) *env
))
449 while (isspace ((unsigned char) *env
))
455 while (isspace ((unsigned char) *env
))
458 for (pass
= 0; pass
< (any_negate
? 2 : 1); pass
++)
463 unsigned long this_num
, this_len
= 1;
464 long this_stride
= 1;
465 bool this_negate
= (*env
== '!');
468 if (gomp_places_list
)
471 while (isspace ((unsigned char) *env
))
476 this_num
= strtoul (env
, &env
, 10);
479 while (isspace ((unsigned char) *env
))
484 while (isspace ((unsigned char) *env
))
487 this_len
= strtoul (env
, &env
, 10);
488 if (errno
|| this_len
== 0)
490 while (isspace ((unsigned char) *env
))
495 while (isspace ((unsigned char) *env
))
498 this_stride
= strtol (env
, &env
, 10);
501 while (isspace ((unsigned char) *env
))
505 if (this_negate
&& this_len
!= 1)
507 if (gomp_places_list
&& pass
== this_negate
)
511 if (!gomp_affinity_remove_cpu (p
, this_num
))
514 else if (!gomp_affinity_add_cpus (p
, this_num
, this_len
,
528 while (isspace ((unsigned char) *env
))
533 while (isspace ((unsigned char) *env
))
536 len
= strtoul (env
, &env
, 10);
537 if (errno
|| len
== 0 || len
>= 65536)
539 while (isspace ((unsigned char) *env
))
544 while (isspace ((unsigned char) *env
))
547 stride
= strtol (env
, &env
, 10);
550 while (isspace ((unsigned char) *env
))
554 if (*negatep
&& len
!= 1)
563 parse_places_var (const char *name
, bool ignore
)
565 char *env
= getenv (name
), *end
;
566 bool any_negate
= false;
568 unsigned long count
= 0;
572 while (isspace ((unsigned char) *env
))
577 if (strncasecmp (env
, "threads", 7) == 0)
582 else if (strncasecmp (env
, "cores", 5) == 0)
587 else if (strncasecmp (env
, "sockets", 7) == 0)
595 while (isspace ((unsigned char) *env
))
601 while (isspace ((unsigned char) *env
))
605 count
= strtoul (env
, &end
, 10);
609 while (isspace ((unsigned char) *env
))
614 while (isspace ((unsigned char) *env
))
623 return gomp_affinity_init_level (level
, count
, false);
633 if (!parse_one_place (&end
, &negate
, &len
, &stride
))
656 gomp_places_list_len
= 0;
657 gomp_places_list
= gomp_affinity_alloc (count
, false);
658 if (gomp_places_list
== NULL
)
666 gomp_affinity_init_place (gomp_places_list
[gomp_places_list_len
]);
667 if (!parse_one_place (&env
, &negate
, &len
, &stride
))
672 for (count
= 0; count
< gomp_places_list_len
; count
++)
673 if (gomp_affinity_same_place
674 (gomp_places_list
[count
],
675 gomp_places_list
[gomp_places_list_len
]))
677 if (count
== gomp_places_list_len
)
679 gomp_error ("Trying to remove a non-existing place from list "
683 p
= gomp_places_list
[count
];
684 memmove (&gomp_places_list
[count
],
685 &gomp_places_list
[count
+ 1],
686 (gomp_places_list_len
- count
- 1) * sizeof (void *));
687 --gomp_places_list_len
;
688 gomp_places_list
[gomp_places_list_len
] = p
;
691 ++gomp_places_list_len
;
694 for (count
= 0; count
< len
- 1; count
++)
695 if (!gomp_affinity_copy_place
696 (gomp_places_list
[gomp_places_list_len
+ count
+ 1],
697 gomp_places_list
[gomp_places_list_len
+ count
],
700 gomp_places_list_len
+= len
;
708 if (gomp_places_list_len
== 0)
710 gomp_error ("All places have been removed");
713 if (!gomp_affinity_finalize_place_list (false))
718 free (gomp_places_list
);
719 gomp_places_list
= NULL
;
720 gomp_places_list_len
= 0;
721 gomp_error ("Invalid value for environment variable %s", name
);
725 /* Parse the OMP_STACKSIZE environment varible. Return true if one was
726 present and it was successfully parsed. */
729 parse_stacksize (const char *name
, unsigned long *pvalue
)
732 unsigned long value
, shift
= 10;
738 while (isspace ((unsigned char) *env
))
744 value
= strtoul (env
, &end
, 10);
748 while (isspace ((unsigned char) *end
))
752 switch (tolower ((unsigned char) *end
))
769 while (isspace ((unsigned char) *end
))
775 if (((value
<< shift
) >> shift
) != value
)
778 *pvalue
= value
<< shift
;
782 gomp_error ("Invalid value for environment variable %s", name
);
786 /* Parse the GOMP_SPINCOUNT environment varible. Return true if one was
787 present and it was successfully parsed. */
790 parse_spincount (const char *name
, unsigned long long *pvalue
)
793 unsigned long long value
, mult
= 1;
799 while (isspace ((unsigned char) *env
))
804 if (strncasecmp (env
, "infinite", 8) == 0
805 || strncasecmp (env
, "infinity", 8) == 0)
813 value
= strtoull (env
, &end
, 10);
817 while (isspace ((unsigned char) *end
))
821 switch (tolower ((unsigned char) *end
))
827 mult
= 1000LL * 1000LL;
830 mult
= 1000LL * 1000LL * 1000LL;
833 mult
= 1000LL * 1000LL * 1000LL * 1000LL;
840 while (isspace ((unsigned char) *end
))
846 if (value
> ~0ULL / mult
)
855 gomp_error ("Invalid value for environment variable %s", name
);
859 /* Parse a boolean value for environment variable NAME and store the
863 parse_boolean (const char *name
, bool *value
)
871 while (isspace ((unsigned char) *env
))
873 if (strncasecmp (env
, "true", 4) == 0)
878 else if (strncasecmp (env
, "false", 5) == 0)
885 while (isspace ((unsigned char) *env
))
888 gomp_error ("Invalid value for environment variable %s", name
);
891 /* Parse the OMP_WAIT_POLICY environment variable and store the
892 result in gomp_active_wait_policy. */
895 parse_wait_policy (void)
900 env
= getenv ("OMP_WAIT_POLICY");
904 while (isspace ((unsigned char) *env
))
906 if (strncasecmp (env
, "active", 6) == 0)
911 else if (strncasecmp (env
, "passive", 7) == 0)
918 while (isspace ((unsigned char) *env
))
922 gomp_error ("Invalid value for environment variable OMP_WAIT_POLICY");
926 /* Parse the GOMP_CPU_AFFINITY environment varible. Return true if one was
927 present and it was successfully parsed. */
930 parse_affinity (bool ignore
)
932 char *env
, *end
, *start
;
934 unsigned long cpu_beg
, cpu_end
, cpu_stride
;
935 size_t count
= 0, needed
;
937 env
= getenv ("GOMP_CPU_AFFINITY");
942 for (pass
= 0; pass
< 2; pass
++)
950 gomp_places_list_len
= 0;
951 gomp_places_list
= gomp_affinity_alloc (count
, true);
952 if (gomp_places_list
== NULL
)
957 while (isspace ((unsigned char) *env
))
961 cpu_beg
= strtoul (env
, &end
, 0);
962 if (errno
|| cpu_beg
>= 65536)
971 cpu_end
= strtoul (++env
, &end
, 0);
972 if (errno
|| cpu_end
>= 65536 || cpu_end
< cpu_beg
)
979 cpu_stride
= strtoul (++env
, &end
, 0);
980 if (errno
|| cpu_stride
== 0 || cpu_stride
>= 65536)
987 needed
= (cpu_end
- cpu_beg
) / cpu_stride
+ 1;
994 void *p
= gomp_places_list
[gomp_places_list_len
];
995 gomp_affinity_init_place (p
);
996 if (gomp_affinity_add_cpus (p
, cpu_beg
, 1, 0, true))
997 ++gomp_places_list_len
;
998 cpu_beg
+= cpu_stride
;
1002 while (isspace ((unsigned char) *env
))
1007 else if (*env
== '\0')
1013 if (gomp_places_list_len
== 0)
1015 free (gomp_places_list
);
1016 gomp_places_list
= NULL
;
1022 gomp_error ("Invalid value for enviroment variable GOMP_CPU_AFFINITY");
1027 parse_acc_device_type (void)
1029 const char *env
= getenv ("ACC_DEVICE_TYPE");
1031 if (env
&& *env
!= '\0')
1032 goacc_device_type
= strdup (env
);
1034 goacc_device_type
= NULL
;
1038 handle_omp_display_env (unsigned long stacksize
, int wait_policy
)
1041 bool display
= false;
1042 bool verbose
= false;
1045 env
= getenv ("OMP_DISPLAY_ENV");
1049 while (isspace ((unsigned char) *env
))
1051 if (strncasecmp (env
, "true", 4) == 0)
1056 else if (strncasecmp (env
, "false", 5) == 0)
1061 else if (strncasecmp (env
, "verbose", 7) == 0)
1069 while (isspace ((unsigned char) *env
))
1072 gomp_error ("Invalid value for environment variable OMP_DISPLAY_ENV");
1077 fputs ("\nOPENMP DISPLAY ENVIRONMENT BEGIN\n", stderr
);
1079 fputs (" _OPENMP = '201511'\n", stderr
);
1080 fprintf (stderr
, " OMP_DYNAMIC = '%s'\n",
1081 gomp_global_icv
.dyn_var
? "TRUE" : "FALSE");
1082 fprintf (stderr
, " OMP_NESTED = '%s'\n",
1083 gomp_global_icv
.nest_var
? "TRUE" : "FALSE");
1085 fprintf (stderr
, " OMP_NUM_THREADS = '%lu", gomp_global_icv
.nthreads_var
);
1086 for (i
= 1; i
< gomp_nthreads_var_list_len
; i
++)
1087 fprintf (stderr
, ",%lu", gomp_nthreads_var_list
[i
]);
1088 fputs ("'\n", stderr
);
1090 fprintf (stderr
, " OMP_SCHEDULE = '");
1091 switch (gomp_global_icv
.run_sched_var
)
1094 fputs ("RUNTIME", stderr
);
1097 fputs ("STATIC", stderr
);
1100 fputs ("DYNAMIC", stderr
);
1103 fputs ("GUIDED", stderr
);
1106 fputs ("AUTO", stderr
);
1109 fputs ("'\n", stderr
);
1111 fputs (" OMP_PROC_BIND = '", stderr
);
1112 switch (gomp_global_icv
.bind_var
)
1114 case omp_proc_bind_false
:
1115 fputs ("FALSE", stderr
);
1117 case omp_proc_bind_true
:
1118 fputs ("TRUE", stderr
);
1120 case omp_proc_bind_master
:
1121 fputs ("MASTER", stderr
);
1123 case omp_proc_bind_close
:
1124 fputs ("CLOSE", stderr
);
1126 case omp_proc_bind_spread
:
1127 fputs ("SPREAD", stderr
);
1130 for (i
= 1; i
< gomp_bind_var_list_len
; i
++)
1131 switch (gomp_bind_var_list
[i
])
1133 case omp_proc_bind_master
:
1134 fputs (",MASTER", stderr
);
1136 case omp_proc_bind_close
:
1137 fputs (",CLOSE", stderr
);
1139 case omp_proc_bind_spread
:
1140 fputs (",SPREAD", stderr
);
1143 fputs ("'\n", stderr
);
1144 fputs (" OMP_PLACES = '", stderr
);
1145 for (i
= 0; i
< gomp_places_list_len
; i
++)
1147 fputs ("{", stderr
);
1148 gomp_affinity_print_place (gomp_places_list
[i
]);
1149 fputs (i
+ 1 == gomp_places_list_len
? "}" : "},", stderr
);
1151 fputs ("'\n", stderr
);
1153 fprintf (stderr
, " OMP_STACKSIZE = '%lu'\n", stacksize
);
1155 /* GOMP's default value is actually neither active nor passive. */
1156 fprintf (stderr
, " OMP_WAIT_POLICY = '%s'\n",
1157 wait_policy
> 0 ? "ACTIVE" : "PASSIVE");
1158 fprintf (stderr
, " OMP_THREAD_LIMIT = '%u'\n",
1159 gomp_global_icv
.thread_limit_var
);
1160 fprintf (stderr
, " OMP_MAX_ACTIVE_LEVELS = '%lu'\n",
1161 gomp_max_active_levels_var
);
1163 fprintf (stderr
, " OMP_CANCELLATION = '%s'\n",
1164 gomp_cancel_var
? "TRUE" : "FALSE");
1165 fprintf (stderr
, " OMP_DEFAULT_DEVICE = '%d'\n",
1166 gomp_global_icv
.default_device_var
);
1167 fprintf (stderr
, " OMP_MAX_TASK_PRIORITY = '%d'\n",
1168 gomp_max_task_priority_var
);
1172 fputs (" GOMP_CPU_AFFINITY = ''\n", stderr
);
1173 fprintf (stderr
, " GOMP_STACKSIZE = '%lu'\n", stacksize
);
1174 #ifdef HAVE_INTTYPES_H
1175 fprintf (stderr
, " GOMP_SPINCOUNT = '%"PRIu64
"'\n",
1176 (uint64_t) gomp_spin_count_var
);
1178 fprintf (stderr
, " GOMP_SPINCOUNT = '%lu'\n",
1179 (unsigned long) gomp_spin_count_var
);
1183 fputs ("OPENMP DISPLAY ENVIRONMENT END\n", stderr
);
1187 static void __attribute__((constructor
))
1188 initialize_env (void)
1190 unsigned long thread_limit_var
, stacksize
;
1193 /* Do a compile time check that mkomp_h.pl did good job. */
1194 omp_check_defines ();
1197 parse_boolean ("OMP_DYNAMIC", &gomp_global_icv
.dyn_var
);
1198 parse_boolean ("OMP_NESTED", &gomp_global_icv
.nest_var
);
1199 parse_boolean ("OMP_CANCELLATION", &gomp_cancel_var
);
1200 parse_int ("OMP_DEFAULT_DEVICE", &gomp_global_icv
.default_device_var
, true);
1201 parse_int ("OMP_MAX_TASK_PRIORITY", &gomp_max_task_priority_var
, true);
1202 parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var
,
1204 if (parse_unsigned_long ("OMP_THREAD_LIMIT", &thread_limit_var
, false))
1206 gomp_global_icv
.thread_limit_var
1207 = thread_limit_var
> INT_MAX
? UINT_MAX
: thread_limit_var
;
1209 parse_int ("GOMP_DEBUG", &gomp_debug_var
, true);
1210 #ifndef HAVE_SYNC_BUILTINS
1211 gomp_mutex_init (&gomp_managed_threads_lock
);
1213 gomp_init_num_threads ();
1214 gomp_available_cpus
= gomp_global_icv
.nthreads_var
;
1215 if (!parse_unsigned_long_list ("OMP_NUM_THREADS",
1216 &gomp_global_icv
.nthreads_var
,
1217 &gomp_nthreads_var_list
,
1218 &gomp_nthreads_var_list_len
))
1219 gomp_global_icv
.nthreads_var
= gomp_available_cpus
;
1220 bool ignore
= false;
1221 if (parse_bind_var ("OMP_PROC_BIND",
1222 &gomp_global_icv
.bind_var
,
1223 &gomp_bind_var_list
,
1224 &gomp_bind_var_list_len
)
1225 && gomp_global_icv
.bind_var
== omp_proc_bind_false
)
1227 /* Make sure OMP_PLACES and GOMP_CPU_AFFINITY env vars are always
1228 parsed if present in the environment. If OMP_PROC_BIND was set
1229 explictly to false, don't populate places list though. If places
1230 list was successfully set from OMP_PLACES, only parse but don't process
1231 GOMP_CPU_AFFINITY. If OMP_PROC_BIND was not set in the environment,
1232 default to OMP_PROC_BIND=true if OMP_PLACES or GOMP_CPU_AFFINITY
1233 was successfully parsed into a places list, otherwise to
1234 OMP_PROC_BIND=false. */
1235 if (parse_places_var ("OMP_PLACES", ignore
))
1237 if (gomp_global_icv
.bind_var
== omp_proc_bind_false
)
1238 gomp_global_icv
.bind_var
= true;
1241 if (parse_affinity (ignore
))
1243 if (gomp_global_icv
.bind_var
== omp_proc_bind_false
)
1244 gomp_global_icv
.bind_var
= true;
1247 if (gomp_global_icv
.bind_var
!= omp_proc_bind_false
)
1248 gomp_init_affinity ();
1249 wait_policy
= parse_wait_policy ();
1250 if (!parse_spincount ("GOMP_SPINCOUNT", &gomp_spin_count_var
))
1252 /* Using a rough estimation of 100000 spins per msec,
1253 use 5 min blocking for OMP_WAIT_POLICY=active,
1254 3 msec blocking when OMP_WAIT_POLICY is not specificed
1255 and 0 when OMP_WAIT_POLICY=passive.
1256 Depending on the CPU speed, this can be e.g. 5 times longer
1257 or 5 times shorter. */
1258 if (wait_policy
> 0)
1259 gomp_spin_count_var
= 30000000000LL;
1260 else if (wait_policy
< 0)
1261 gomp_spin_count_var
= 300000LL;
1263 /* gomp_throttled_spin_count_var is used when there are more libgomp
1264 managed threads than available CPUs. Use very short spinning. */
1265 if (wait_policy
> 0)
1266 gomp_throttled_spin_count_var
= 1000LL;
1267 else if (wait_policy
< 0)
1268 gomp_throttled_spin_count_var
= 100LL;
1269 if (gomp_throttled_spin_count_var
> gomp_spin_count_var
)
1270 gomp_throttled_spin_count_var
= gomp_spin_count_var
;
1272 /* Not strictly environment related, but ordering constructors is tricky. */
1273 pthread_attr_init (&gomp_thread_attr
);
1274 pthread_attr_setdetachstate (&gomp_thread_attr
, PTHREAD_CREATE_DETACHED
);
1276 if (parse_stacksize ("OMP_STACKSIZE", &stacksize
)
1277 || parse_stacksize ("GOMP_STACKSIZE", &stacksize
))
1281 err
= pthread_attr_setstacksize (&gomp_thread_attr
, stacksize
);
1283 #ifdef PTHREAD_STACK_MIN
1286 if (stacksize
< PTHREAD_STACK_MIN
)
1287 gomp_error ("Stack size less than minimum of %luk",
1288 PTHREAD_STACK_MIN
/ 1024ul
1289 + (PTHREAD_STACK_MIN
% 1024 != 0));
1291 gomp_error ("Stack size larger than system limit");
1296 gomp_error ("Stack size change failed: %s", strerror (err
));
1299 handle_omp_display_env (stacksize
, wait_policy
);
1303 if (!parse_int ("ACC_DEVICE_NUM", &goacc_device_num
, true))
1304 goacc_device_num
= 0;
1306 parse_acc_device_type ();
1308 goacc_runtime_initialize ();
1310 #endif /* LIBGOMP_OFFLOADED_ONLY */